feat: cw task add CLI command + {AGENT_ID} prompt placeholder
- Add `createTaskForAgent` tRPC mutation: resolves agent → task → phase, creates sibling task
- Add `cw task add <name> --agent-id <id>` CLI command
- Replace `{AGENT_ID}` and `{AGENT_NAME}` placeholders in writeInputFiles() before flushing
- Update docs/agent.md and docs/cli-config.md
This commit is contained in:
@@ -282,6 +282,17 @@ export async function writeInputFiles(options: WriteInputFilesOptions): Promise<
|
||||
});
|
||||
}
|
||||
|
||||
// Replace agent placeholders in all content before writing
|
||||
const placeholders: Record<string, string> = {
|
||||
'{AGENT_ID}': options.agentId ?? '',
|
||||
'{AGENT_NAME}': options.agentName ?? '',
|
||||
};
|
||||
for (const w of writes) {
|
||||
for (const [token, value] of Object.entries(placeholders)) {
|
||||
w.content = w.content.replaceAll(token, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Flush all file writes in parallel — yields the event loop between I/O ops
|
||||
await Promise.all(writes.map(w => writeFile(w.path, w.content, 'utf-8')));
|
||||
|
||||
|
||||
@@ -426,6 +426,32 @@ export function createCli(serverHandler?: (port?: number) => Promise<void>): Com
|
||||
}
|
||||
});
|
||||
|
||||
// cw task add <name> --agent-id <agentId>
|
||||
taskCommand
|
||||
.command('add <name>')
|
||||
.description('Create a sibling task in the agent\'s current phase')
|
||||
.requiredOption('--agent-id <agentId>', 'Agent ID creating the task')
|
||||
.option('--description <description>', 'Task description')
|
||||
.option('--category <category>', 'Task category (execute, research, verify, ...)')
|
||||
.action(async (name: string, options: { agentId: string; description?: string; category?: string }) => {
|
||||
try {
|
||||
const client = createDefaultTrpcClient();
|
||||
const task = await client.createTaskForAgent.mutate({
|
||||
agentId: options.agentId,
|
||||
name,
|
||||
description: options.description,
|
||||
category: options.category as 'execute' | undefined,
|
||||
});
|
||||
console.log(`Created task: ${task.name}`);
|
||||
console.log(` ID: ${task.id}`);
|
||||
console.log(` Phase: ${task.phaseId}`);
|
||||
console.log(` Status: ${task.status}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to create task:', (error as Error).message);
|
||||
process.exit(1);
|
||||
}
|
||||
});
|
||||
|
||||
// Message command group
|
||||
const messageCommand = program
|
||||
.command('message')
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
requirePhaseRepository,
|
||||
requireDispatchManager,
|
||||
requireChangeSetRepository,
|
||||
requireAgentManager,
|
||||
} from './_helpers.js';
|
||||
|
||||
export function taskProcedures(publicProcedure: ProcedureBuilder) {
|
||||
@@ -213,5 +214,55 @@ export function taskProcedures(publicProcedure: ProcedureBuilder) {
|
||||
return edges;
|
||||
}),
|
||||
|
||||
createTaskForAgent: publicProcedure
|
||||
.input(z.object({
|
||||
agentId: z.string().min(1),
|
||||
name: z.string().min(1),
|
||||
description: z.string().optional(),
|
||||
category: z.enum(['execute', 'research', 'discuss', 'plan', 'detail', 'refine', 'verify', 'merge', 'review']).optional(),
|
||||
}))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const agentManager = requireAgentManager(ctx);
|
||||
const taskRepository = requireTaskRepository(ctx);
|
||||
|
||||
const agent = await agentManager.get(input.agentId);
|
||||
if (!agent) {
|
||||
throw new TRPCError({
|
||||
code: 'NOT_FOUND',
|
||||
message: `Agent '${input.agentId}' not found`,
|
||||
});
|
||||
}
|
||||
if (!agent.taskId) {
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: `Agent '${agent.name}' has no assigned task`,
|
||||
});
|
||||
}
|
||||
|
||||
const agentTask = await taskRepository.findById(agent.taskId);
|
||||
if (!agentTask) {
|
||||
throw new TRPCError({
|
||||
code: 'NOT_FOUND',
|
||||
message: `Agent's task '${agent.taskId}' not found`,
|
||||
});
|
||||
}
|
||||
if (!agentTask.phaseId) {
|
||||
throw new TRPCError({
|
||||
code: 'BAD_REQUEST',
|
||||
message: `Agent's task has no phase — cannot create sibling task`,
|
||||
});
|
||||
}
|
||||
|
||||
return taskRepository.create({
|
||||
phaseId: agentTask.phaseId,
|
||||
initiativeId: agentTask.initiativeId,
|
||||
name: input.name,
|
||||
description: input.description ?? null,
|
||||
category: input.category ?? 'execute',
|
||||
type: 'auto',
|
||||
status: 'pending',
|
||||
});
|
||||
}),
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user