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:
Lukas May
2026-03-06 22:22:49 +01:00
parent 6482960c6f
commit e199188670
5 changed files with 101 additions and 1 deletions

View File

@@ -33,7 +33,7 @@
1. **tRPC procedure** calls `agentManager.spawn(options)`
2. Manager generates alias (adjective-animal), creates DB record. Appends inter-agent communication and preview instructions unless `skipPromptExtras: true` (used by conflict-resolution agents to keep prompts lean).
3. `AgentProcessManager.createProjectWorktrees()` — creates git worktrees at `agent-workdirs/<alias>/<project>/`. After creation, each project subdirectory is verified to exist; missing worktrees throw immediately to prevent agents running in the wrong directory.
4. `file-io.writeInputFiles()` — writes `.cw/input/` with assignment files (initiative, pages, phase, task) and read-only context dirs (`context/phases/`, `context/tasks/`)
4. `file-io.writeInputFiles()` — writes `.cw/input/` with assignment files (initiative, pages, phase, task) and read-only context dirs (`context/phases/`, `context/tasks/`). Before flushing writes, replaces `{AGENT_ID}` and `{AGENT_NAME}` placeholders in all content with the agent's real ID and name.
5. Provider config builds spawn command via `buildSpawnCommand()`
6. `spawnDetached()` — launches detached child process with file output redirection
7. `FileTailer` watches output file, fires `onEvent` (parsed stream events) and `onRawContent` (raw JSONL chunks) callbacks
@@ -271,3 +271,14 @@ Examples within mode-specific tags use `<examples>` > `<example label="good">` /
### Execute Prompt Dispatch
`buildExecutePrompt(taskDescription?)` accepts an optional task description wrapped in a `<task>` tag. The dispatch manager (`apps/server/dispatch/manager.ts`) wraps `task.description || task.name` in `buildExecutePrompt()` so execute agents receive full system context alongside their task. The `<workspace>` and `<inter_agent_communication>` blocks are appended by the agent manager at spawn time.
## Prompt Placeholders
`writeInputFiles()` replaces these tokens in all input file content before writing:
| Placeholder | Replaced With |
|-------------|---------------|
| `{AGENT_ID}` | The agent's database ID |
| `{AGENT_NAME}` | The agent's human-readable name |
Use in phase detail text or task descriptions to give agents self-referential context, e.g.: *"Report issues via `cw task add --agent-id {AGENT_ID}`"*

View File

@@ -44,6 +44,7 @@ Uses **Commander.js** for command parsing.
| `list --parent\|--phase\|--initiative <id>` | List tasks with counts |
| `get <taskId>` | Task details |
| `status <taskId> <status>` | Update status |
| `add <name> --agent-id <id> [--description <desc>] [--category <cat>]` | Create sibling task in agent's phase |
### Dispatch (`cw dispatch`)
| Command | Description |