# CLI & Configuration `apps/server/cli/` — CLI commands, `apps/server/config/` — workspace configuration, `apps/server/bin/` — entry point. ## Entry Point `apps/server/bin/cw.ts` — hashbang entry that imports and runs the CLI. ## CLI Framework Uses **Commander.js** for command parsing. ## Global Flags - `-s, --server` — Start coordination server in foreground - `-p, --port ` — Server port (default: 3847, env: `CW_PORT`) - `-d, --debug` — Enable debug mode (archive agent workdirs before cleanup) ## Commands ### System | Command | Description | |---------|-------------| | `cw init` | Create `.cwrc` workspace file in current directory | | `cw start` | Start coordination server (see Server Wiring below) | | `cw stop` | Stop running server (reads PID file, sends signal) | | `cw status` | Query server health endpoint | | `cw id [-n count]` | Generate nanoid(s) offline | ### Agent Management (`cw agent`) | Command | Description | |---------|-------------| | `spawn --task [--name] [--provider] [--initiative] [--cwd]` | Spawn agent | | `stop ` | Stop running agent | | `delete ` | Delete agent, clean workdir/branches/logs | | `list` | List all agents with status | | `get ` | Agent details (ID, task, session, worktree, status) | | `resume ` | Resume with JSON answers or single string | | `result ` | Get execution result | ### Task Management (`cw task`) | Command | Description | |---------|-------------| | `list --parent\|--phase\|--initiative ` | List tasks with counts | | `get ` | Task details | | `status ` | Update status | | `add --agent-id [--description ] [--category ]` | Create sibling task in agent's phase | ### Dispatch (`cw dispatch`) | Command | Description | |---------|-------------| | `queue ` | Queue task for dispatch | | `next` | Dispatch next available task | | `status` | Show queue status | | `complete ` | Mark task complete | ### Initiative Management (`cw initiative`) | Command | Description | |---------|-------------| | `create [--project ]` | Create initiative | | `list [-s status]` | List initiatives | | `get ` | Initiative details | | `phases ` | List phases | ### Architect (`cw architect`) | Command | Description | |---------|-------------| | `discuss [-c context]` | Start discussion agent | | `plan [-s summary]` | Start plan agent | | `detail [-t taskName] [-c context]` | Detail phase into tasks | ### Phase (`cw phase`) | Command | Description | |---------|-------------| | `add-dependency --phase --depends-on ` | Add dependency edge | | `dependencies ` | List dependencies | | `queue ` | Queue approved phase | | `dispatch` | Dispatch next phase | | `queue-status` | Show phase queue | ### Merge & Coordination (`cw merge`, `cw coordinate`) | Command | Description | |---------|-------------| | `merge queue ` | Queue task for merge | | `merge status` | Show merge queue | | `merge next` | Show next mergeable task | | `coordinate [-t branch]` | Process all ready merges (default: main) | ### Messages (`cw message`) | Command | Description | |---------|-------------| | `list [--agent ] [--status ]` | List messages | | `read ` | Read full message | | `respond ` | Respond to message | ### Projects (`cw project`) | Command | Description | |---------|-------------| | `register --name --url ` | Register git repo | | `list` | List projects | | `delete ` | Delete project | ### Preview Deployments (`cw preview`) | Command | Description | |---------|-------------| | `start --initiative --project --branch [--phase ]` | Start Docker preview | | `stop ` | Stop and clean up preview | | `list [--initiative ]` | List active previews | | `status ` | Get preview status with service details | ### Inter-Agent Conversation (`cw listen`, `cw ask`, `cw answer`) | Command | Description | |---------|-------------| | `listen --agent-id [--poll-interval ] [--timeout ]` | Poll for pending questions, print JSON, exit | | `ask --from [--agent-id\|--phase-id\|--task-id ] [--poll-interval ] [--timeout ]` | Ask question, block until answered, print answer | | `answer --conversation-id ` | Answer a pending conversation | All three commands output JSON for programmatic agent consumption. ### Errand Sessions (`cw errand`) | Command | Description | |---------|-------------| | `start --project [--base ]` | Start a new errand session (description ≤200 chars) | | `list [--project ] [--status ]` | List errands; status: active\|pending_review\|conflict\|merged\|abandoned | | `chat ` | Deliver a message to the running errand agent | | `diff ` | Print unified git diff between base branch and errand branch | | `complete ` | Mark errand as done and ready for review | | `merge [--target ]` | Merge errand branch into target branch | | `resolve ` | Print worktree path and conflicting files for manual resolution | | `abandon ` | Stop agent, remove worktree and branch, keep DB record as abandoned | | `delete ` | Stop agent, remove worktree, delete branch, and delete DB record | ### Accounts (`cw account`) | Command | Description | |---------|-------------| | `add [--provider] [--email] [--token]` | Auto-discover, manually register, or register with setup token | | `list` | Show accounts with exhaustion status | | `remove ` | Remove account | | `refresh` | Clear expired exhaustion markers | | `extract [--email ]` | Extract current Claude credentials as JSON (no server required) | ## Server Wiring The CLI is the composition root. It creates concrete implementations and passes them as `contextDeps`: ``` ServerContextDeps = Omit ``` This includes all repositories, managers, and the credential manager. The server adds `eventBus`, `serverStartedAt`, and `processCount` at startup. ## Workspace Configuration `apps/server/config/` module: ### .cwrc File JSON file at workspace root that marks a `cw` workspace: ```json { "version": 1 } ``` ### findWorkspaceRoot() Walks up directory tree looking for `.cwrc` file. Returns the directory containing it, or throws if not found. ### Schema Currently `{ version: 1 }` — extend with new top-level keys as needed. ### Files | File | Purpose | |------|---------| | `types.ts` | CwrcConfig type definition | | `cwrc.ts` | findWorkspaceRoot(), readCwrc(), writeCwrc() | | `index.ts` | Public API exports |