feat: Add global relationships management to GlobalSymbolIndex

- Introduced a new schema version (v2) with a global_relationships table.
- Implemented CRUD operations for file relationships, including update and delete functionalities.
- Added query capabilities for relationships by target and symbols.
- Created migration logic from v1 to v2 schema.
- Enhanced tests for global relationships, covering various scenarios including insertion, querying, and deletion.

docs: Add update-single command for generating module documentation

- Created a new command to generate manual-style documentation (CLAUDE.md) for a single module.
- Detailed execution process and implementation phases for the command.
- Included usage examples and error handling guidelines.

feat: Implement team command for CLI interface

- Added a new team command for logging and retrieving messages in a team message bus.
- Supported subcommands for logging, reading, listing, and checking status of messages.
- Included error handling and JSON output options.

test: Add comprehensive tests for global relationships

- Developed extensive tests for the global_relationships table in GlobalSymbolIndex.
- Covered schema creation, migration, CRUD operations, and performance benchmarks.
- Ensured project isolation and validated query functionalities for relationships.
This commit is contained in:
catlog22
2026-02-13 11:39:53 +08:00
parent e88d552cd1
commit 17f52da4c6
21 changed files with 1587 additions and 127 deletions

View File

@@ -15,6 +15,7 @@ import { hookCommand } from './commands/hook.js';
import { issueCommand } from './commands/issue.js';
import { workflowCommand } from './commands/workflow.js';
import { loopCommand } from './commands/loop.js';
import { teamCommand } from './commands/team.js';
import { readFileSync, existsSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
@@ -318,6 +319,22 @@ export function run(argv: string[]): void {
.option('--session <name>', 'Specify workflow session')
.action((subcommand, args, options) => loopCommand(subcommand, args, options));
// Team command - Team Message Bus CLI interface
program
.command('team [subcommand] [args...]')
.description('Team message bus for Agent Team communication')
.option('--team <name>', 'Team name')
.option('--from <role>', 'Sender role name')
.option('--to <role>', 'Recipient role name')
.option('--type <type>', 'Message type')
.option('--summary <text>', 'One-line summary')
.option('--ref <path>', 'File path reference')
.option('--data <json>', 'JSON structured data')
.option('--id <id>', 'Message ID (for read)')
.option('--last <n>', 'Last N messages (for list)')
.option('--json', 'Output as JSON')
.action((subcommand, args, options) => teamCommand(subcommand, args, options));
// Workflow command - Workflow installation and management
program
.command('workflow [subcommand] [args...]')

179
ccw/src/commands/team.ts Normal file
View File

@@ -0,0 +1,179 @@
/**
* Team Command - CLI interface for Team Message Bus
* Delegates to team-msg.ts handler for JSONL-based persistent messaging
*
* Commands:
* ccw team log --team <name> --from <role> --to <role> --type <type> --summary "..."
* ccw team read --team <name> --id <MSG-NNN>
* ccw team list --team <name> [--from <role>] [--to <role>] [--type <type>] [--last <n>]
* ccw team status --team <name>
* ccw team delete --team <name> --id <MSG-NNN>
* ccw team clear --team <name>
*/
import chalk from 'chalk';
import { handler } from '../tools/team-msg.js';
interface TeamOptions {
team?: string;
from?: string;
to?: string;
type?: string;
summary?: string;
ref?: string;
data?: string;
id?: string;
last?: string;
json?: boolean;
}
export async function teamCommand(
subcommand: string,
args: string | string[],
options: TeamOptions
): Promise<void> {
if (!subcommand) {
printHelp();
return;
}
if (!options.team) {
console.error(chalk.red('Error: --team is required'));
process.exit(1);
}
// Build params for handler
const params: Record<string, unknown> = {
operation: subcommand,
team: options.team,
};
if (options.from) params.from = options.from;
if (options.to) params.to = options.to;
if (options.type) params.type = options.type;
if (options.summary) params.summary = options.summary;
if (options.ref) params.ref = options.ref;
if (options.id) params.id = options.id;
if (options.last) params.last = parseInt(options.last, 10);
// Parse --data as JSON
if (options.data) {
try {
params.data = JSON.parse(options.data);
} catch {
console.error(chalk.red('Error: --data must be valid JSON'));
process.exit(1);
}
}
try {
const result = await handler(params);
if (!result.success) {
console.error(chalk.red(`Error: ${result.error}`));
process.exit(1);
}
// JSON output mode
if (options.json) {
console.log(JSON.stringify(result.result, null, 2));
return;
}
// Formatted output by operation
switch (subcommand) {
case 'log': {
const r = result.result as { id: string; message: string };
console.log(chalk.green(`${r.message}`));
break;
}
case 'read': {
const msg = result.result as { id: string; ts: string; from: string; to: string; type: string; summary: string; ref?: string; data?: unknown };
console.log(chalk.bold(`${msg.id} [${msg.ts}]`));
console.log(` ${chalk.cyan(msg.from)}${chalk.yellow(msg.to)} (${msg.type})`);
console.log(` ${msg.summary}`);
if (msg.ref) console.log(chalk.gray(` ref: ${msg.ref}`));
if (msg.data) console.log(chalk.gray(` data: ${JSON.stringify(msg.data)}`));
break;
}
case 'list': {
const r = result.result as { formatted: string; total: number; showing: number };
console.log(chalk.gray(`Showing ${r.showing} of ${r.total} messages\n`));
console.log(r.formatted);
break;
}
case 'status': {
const r = result.result as { formatted?: string; summary?: string; total_messages?: number };
if (r.summary) {
console.log(chalk.yellow(r.summary));
} else {
console.log(chalk.gray(`Total messages: ${r.total_messages}\n`));
console.log(r.formatted);
}
break;
}
case 'delete': {
const r = result.result as { message: string };
console.log(chalk.green(`${r.message}`));
break;
}
case 'clear': {
const r = result.result as { message: string };
console.log(chalk.green(`${r.message}`));
break;
}
default:
console.error(chalk.red(`Unknown subcommand: ${subcommand}`));
printHelp();
process.exit(1);
}
} catch (error) {
console.error(chalk.red(`Error: ${(error as Error).message}`));
process.exit(1);
}
}
function printHelp(): void {
console.log(chalk.bold.cyan('\n CCW Team Message Bus\n'));
console.log(' CLI interface for team message logging and retrieval.\n');
console.log(' Subcommands:');
console.log(chalk.gray(' log Log a team message'));
console.log(chalk.gray(' read Read a specific message by ID'));
console.log(chalk.gray(' list List recent messages with filters'));
console.log(chalk.gray(' status Show team member activity summary'));
console.log(chalk.gray(' delete Delete a specific message by ID'));
console.log(chalk.gray(' clear Clear all messages for a team'));
console.log();
console.log(' Required:');
console.log(chalk.gray(' --team <name> Team name'));
console.log();
console.log(' Log Options:');
console.log(chalk.gray(' --from <role> Sender role name'));
console.log(chalk.gray(' --to <role> Recipient role name'));
console.log(chalk.gray(' --type <type> Message type (plan_ready, impl_complete, etc.)'));
console.log(chalk.gray(' --summary <text> One-line summary'));
console.log(chalk.gray(' --ref <path> File path reference'));
console.log(chalk.gray(' --data <json> JSON structured data'));
console.log();
console.log(' Read/Delete Options:');
console.log(chalk.gray(' --id <MSG-NNN> Message ID'));
console.log();
console.log(' List Options:');
console.log(chalk.gray(' --from <role> Filter by sender'));
console.log(chalk.gray(' --to <role> Filter by recipient'));
console.log(chalk.gray(' --type <type> Filter by message type'));
console.log(chalk.gray(' --last <n> Number of messages (default: 20)'));
console.log();
console.log(' General:');
console.log(chalk.gray(' --json Output as JSON'));
console.log();
console.log(' Examples:');
console.log(chalk.gray(' ccw team log --team my-team --from executor --to coordinator --type impl_complete --summary "Task done"'));
console.log(chalk.gray(' ccw team list --team my-team --last 5'));
console.log(chalk.gray(' ccw team read --team my-team --id MSG-003'));
console.log(chalk.gray(' ccw team status --team my-team'));
console.log(chalk.gray(' ccw team delete --team my-team --id MSG-003'));
console.log(chalk.gray(' ccw team clear --team my-team'));
console.log(chalk.gray(' ccw team log --team my-team --from planner --to coordinator --type plan_ready --summary "Plan ready" --json'));
console.log();
}

View File

@@ -6,11 +6,13 @@
* - read: Read message(s) by ID
* - list: List recent messages with optional filters (from/to/type/last N)
* - status: Summarize team member activity from message history
* - delete: Delete a specific message by ID
* - clear: Clear all messages for a team
*/
import { z } from 'zod';
import type { ToolSchema, ToolResult } from '../types/tool.js';
import { existsSync, mkdirSync, readFileSync, appendFileSync } from 'fs';
import { existsSync, mkdirSync, readFileSync, appendFileSync, writeFileSync, rmSync } from 'fs';
import { join, dirname } from 'path';
import { getProjectRoot } from '../utils/path-validator.js';
@@ -37,7 +39,7 @@ export interface StatusEntry {
// --- Zod Schema ---
const ParamsSchema = z.object({
operation: z.enum(['log', 'read', 'list', 'status']).describe('Operation to perform'),
operation: z.enum(['log', 'read', 'list', 'status', 'delete', 'clear']).describe('Operation to perform'),
team: z.string().describe('Team name (maps to .workflow/.team-msg/{team}/messages.jsonl)'),
// log params
@@ -69,6 +71,8 @@ Operations:
team_msg(operation="list", team="my-team")
team_msg(operation="list", team="my-team", from="tester", last=5)
team_msg(operation="status", team="my-team")
team_msg(operation="delete", team="my-team", id="MSG-003")
team_msg(operation="clear", team="my-team")
Message types: plan_ready, plan_approved, plan_revision, task_unblocked, impl_complete, impl_progress, test_result, review_result, fix_required, error, shutdown`,
inputSchema: {
@@ -76,8 +80,8 @@ Message types: plan_ready, plan_approved, plan_revision, task_unblocked, impl_co
properties: {
operation: {
type: 'string',
enum: ['log', 'read', 'list', 'status'],
description: 'Operation: log | read | list | status',
enum: ['log', 'read', 'list', 'status', 'delete', 'clear'],
description: 'Operation: log | read | list | status | delete | clear',
},
team: {
type: 'string',
@@ -250,6 +254,37 @@ function opStatus(params: Params): ToolResult {
};
}
function opDelete(params: Params): ToolResult {
if (!params.id) return { success: false, error: 'delete requires "id"' };
const messages = readAllMessages(params.team);
const idx = messages.findIndex(m => m.id === params.id);
if (idx === -1) {
return { success: false, error: `Message ${params.id} not found in team "${params.team}"` };
}
const removed = messages.splice(idx, 1)[0];
const logPath = ensureLogFile(params.team);
writeFileSync(logPath, messages.map(m => JSON.stringify(m)).join('\n') + (messages.length > 0 ? '\n' : ''), 'utf-8');
return { success: true, result: { deleted: removed.id, message: `Deleted ${removed.id}: [${removed.from}${removed.to}] ${removed.summary}` } };
}
function opClear(params: Params): ToolResult {
const logPath = getLogPath(params.team);
const dir = getLogDir(params.team);
if (!existsSync(logPath)) {
return { success: true, result: { message: `Team "${params.team}" has no messages to clear.` } };
}
const count = readAllMessages(params.team).length;
rmSync(dir, { recursive: true, force: true });
return { success: true, result: { cleared: count, message: `Cleared ${count} messages for team "${params.team}".` } };
}
// --- Handler ---
export async function handler(params: Record<string, unknown>): Promise<ToolResult> {
@@ -265,6 +300,8 @@ export async function handler(params: Record<string, unknown>): Promise<ToolResu
case 'read': return opRead(p);
case 'list': return opList(p);
case 'status': return opStatus(p);
case 'delete': return opDelete(p);
case 'clear': return opClear(p);
default:
return { success: false, error: `Unknown operation: ${p.operation}` };
}