--- name: cc-spec description: "(Conductor) Define the problem and generate an approved spec Use when the user asks for /cc-spec or cc-spec." --- > code-conductor: this command was written for Claude Code. Where it names a Claude Code tool (Read, Grep, Glob, Edit, Write, Bash, Skill, Agent), use your closest equivalent. `$ARGUMENTS` and an `ARGUMENTS:` line mean the text the user gave with the command. ## Phase entry - Resume Read Before doing anything else, restore any stored context for the current commit by running `.claude/scripts/resume-read.mjs`. It resolves the current git hash, prefers a valid DB snapshot (`conductor-db get-snapshot`), falls back to the `.claude/memory/session-snapshot.json` handoff file, and prints a `RESUME_HIT` block on a hit / nothing on a miss. Capture its stdout **and** its exit code with the canonical per-platform form (each first probes for `node` and treats its absence as a clean miss, never an error): - **Unix / Git Bash:** ```sh if command -v node >/dev/null 2>&1; then resume_out="$(node .claude/scripts/resume-read.mjs 2>>.conductor/last-write.log)"; resume_rc=$? else resume_rc=3; resume_out=""; fi ``` - **PowerShell:** ```powershell if (Get-Command node -ErrorAction SilentlyContinue) { $__eap = $ErrorActionPreference; $ErrorActionPreference = 'Continue' if (Test-Path variable:PSNativeCommandUseErrorActionPreference) { $__nap = $PSNativeCommandUseErrorActionPreference; $PSNativeCommandUseErrorActionPreference = $false } try { $resume_out = node .claude/scripts/resume-read.mjs 2>> .conductor/last-write.log; $resume_rc = $LASTEXITCODE } catch { $resume_rc = 3; $resume_out = "" } finally { $ErrorActionPreference = $__eap if (Test-Path variable:__nap) { $PSNativeCommandUseErrorActionPreference = $__nap } } } else { $resume_rc = 3; $resume_out = "" } ``` Branch on `resume_rc` - **only `0` and `4` are meaningful; every other code proceeds fresh:** - **`0`** → parse the captured block and adopt it as this phase's starting context, then echo one banner to the user: `> Resumed from stored snapshot @ (phase: )`, appending ` (checkpoint prose available)` when the block reports `prose: available`. Parsing (the command owns normalization): split on `\n`; strip a trailing `\r` from every line; drop leading/trailing wholly-blank lines; require `lines[0].trim() === 'RESUME_HIT'` (anything else = miss); `key: value` lines split on the first `': '` (both sides trimmed); the `pending:` block is every subsequent `^\s*-\s+` line up to the first blank line or EOF, each item trimmed. Unknown keys are ignored. In PowerShell, `node …` binds `string[]` for multi-line output - normalize with `$lines = @($resume_out)`; a `$null`/empty capture with `resume_rc = 3` is a miss. - **`4`** → **operational halt.** Do not run this phase's normal work. Emit exactly: `SNAP_INVALID: corrupt handoff at .claude/memory/session-snapshot.json - inspect or remove it, then re-run.` and enter standby awaiting user action. The corrupt file is left on disk (the script did not delete it). - **`3` or any other code** → **proceed fresh** (clean miss, bypass, degrade, absent `node`, or any unexpected runtime code). Ignore the capture. `resume-read.mjs` writes its own trace lines to `.conductor/last-write.log` via `appendFileSync`; the `2>>` redirect above only sinks the incidental exit-4 halt reason away from the UI - it is not the trace channel. --- ## Phase 0 — Skill activation Before doing anything else, invoke both skills in order: ``` Skill({ skill: "brainstorming", args: "$ARGUMENTS" }) Skill({ skill: "critical-review" }) ``` `brainstorming` explores the problem space and surfaces unknowns. `critical-review` Phase 1 then runs the Pre-Flight Analysis (Happy Path / Failure Points / Boundary Conditions) on the proposed solution before the spec is written. Do not write the spec until both have completed. --- ## Spec Read Budget Before reading any file: 1. Run Grep or Glob to locate relevant files. Skip this step only if the user's prompt names the exact file path. 2. Apply the correct read rule based on file type: **Capped source files** - read the first 30 lines only (`offset` omitted, `limit: 30`). Starting at any offset other than the beginning is forbidden; if the first 30 lines are insufficient, defer the file. Multiple reads of the same file at any offset are forbidden. Extensions: `.ts` `.tsx` `.js` `.jsx` `.mjs` `.cjs` `.py` `.go` `.rs` `.java` `.rb` `.cs` `.cpp` `.c` `.h` `.swift` `.kt` `.php` `.sh` `.html` `.css` `.scss` `.sass` `.less` `.svelte` `.vue` **Exempt files** - may be read in full: Named manifests/config: `package.json` `package-lock.json` `yarn.lock` `pnpm-lock.yaml` `bun.lockb` `go.mod` `go.sum` `Cargo.toml` `Cargo.lock` `pyproject.toml` `requirements.txt` `Pipfile` `Gemfile` `Gemfile.lock` `tsconfig.json` `tsconfig.*.json` `.gitignore` `.eslintrc.*` `.prettierrc.*` `.env.example` `.nvmrc` `.node-version` `.python-version` `.tool-versions` Patterns: `*.yaml` `*.yml` `*.toml` `*.json` (config/manifest root files only - do not apply to data or generated JSON) `*.md` `CLAUDE.md` `Makefile` `Dockerfile` `Dockerfile.*` `*.dockerfile` `Jenkinsfile` `Procfile` `Brewfile` Note: `.env`, `.env.local`, `.env.*` (real values) are **not exempt** - the agent should not read them during spec phase. **Extensionless files** - exempt only when the exact name appears in the Named manifests/config list or Patterns above. All other extensionless files (including unknown dotfiles) default to capped. **Default** - any file not matched by the above rules defaults to capped. **Deferred reads** - if a capped source file cannot be understood from 30 lines, record it in `### Files Requiring Full Read (deferred to /cc-plan)` and move on. Do not slice-read it. --- ## Analyst and UX intake (FEAT-032) Two optional Define-band roles run here, before the questions below. Both are skippable, and both are skipped unless this section says otherwise. `--analyst` and `--ux` are flags, not part of the topic: leave them out of the topic and of the codebase search. Every command runs from the project root, with `S=.claude/scripts; [ -f "$S/orchestrate.mjs" ] || S=scripts`. 1. **A requirements document.** If `$ARGUMENTS` names a path ending in `-requirements.md`, run `node "$S/requirements.mjs" check ''`, with the path in single quotes. - `REQUIREMENTS: complete` (exit 0): the Analyst is skipped. Read the document. Its `## Problem`, `## Users`, `## Constraints` and `## Similar Features` answer questions 1 to 4 below, which are not asked again; ask only what its `## Open Questions` lists. Its `## User Stories` and `## Requirements` become the spec's Behavior and Acceptance Criteria, keeping each `R` id. - Exit 1: show its `- ` lines and continue as if no document were named. 2. **The Analyst (`--analyst`).** Only with `--analyst` in `$ARGUMENTS` and no complete document from step 1: 1. Run `node "$S/orchestrate.mjs" envelope analyst --item `. Only a first stdout line that starts with `installed:` allows the dispatch; otherwise print `analyst not dispatched: ` and continue without it. 2. Dispatch `Agent({ subagent_type: "analyst", description: "write requirements", prompt })`. The brief names the item, the topic, the folder from the envelope's scope, the ticket snapshot `.conductor/ticket/.md` when it exists, and says that `/cc-spec` dispatched the agent outside any run. 3. Show its report and `SNAP_HANDBACK` line, then run `node "$S/orchestrate.mjs" envelope --clear`, also when the agent was denied or ended without a hand-back. 4. Take the path its hand-back lists in `ops.f`, with its `:C`, `:M` or `:D` suffix removed (`:C` is checked as ``). Use it only if it matches `^[A-Za-z0-9._/-]+$`, contains no `..` segment, and matches the envelope's `ops.scope` glob (`/**/*--requirements.md`). Otherwise print `analyst hand-back rejected: ` and continue as if no document were named. Then run step 1 on it, passing the path in single quotes. 3. **The UX agent (`--ux`).** Only with `--ux` in `$ARGUMENTS`, and only when the item changes user-facing UI; a backend-only item never instantiates UX. 1. Run `node "$S/orchestrate.mjs" envelope ux --item `. `ORCH_UX_NO_SKILLS` means no frontend design skill is installed: print `ux skipped: ` and continue without it. Any other refusal is printed as `ux not dispatched: `. 2. Dispatch `Agent({ subagent_type: "ux", description: "UX constraints", prompt })`. The brief names the item, the user-facing change, the files it touches, and says that `/cc-spec` dispatched the agent outside any run. 3. Show its report, then run `node "$S/orchestrate.mjs" envelope --clear`. 4. Copy its `- UX:` lines verbatim into the spec's `## UX Constraints` section. The plan and `code` must honor each one; `audit` reviews the code against them. Search the codebase for existing code related to `$ARGUMENTS` before asking any questions. Run: `grep -r -l -e "" src/ --include="*.{ts,js,py,java,go,rs}" 2>/dev/null | head -20`, where `` is `$ARGUMENTS` without `--analyst`, `--ux` and `--delegate`. Then ask only for missing context. You need to understand: 1. **Problem** — what is broken or missing? 2. **User** — who is affected and what do they expect? 3. **Constraints** — performance, security, backward compatibility? 4. **Similar features** — anything in the codebase to stay consistent with? Generate a spec with these sections: ## Problem [What is broken or missing, from the user's perspective] ## Solution [What will be built, one paragraph] ## Behavior ### Main path [Step-by-step: what happens in the happy path] ### Alternative paths [Edge cases the user might hit] ### Error cases [What happens when things go wrong] ## Acceptance Criteria - [ ] [Testable criterion] - [ ] [Testable criterion] ## UX Constraints [Only when the UX agent ran: its `- UX:` lines, verbatim. Omit this section otherwise.] ## Out of Scope [Explicitly list what this spec does NOT cover] ## System Impact [What existing code will be affected or needs to be reviewed] ### Files Requiring Full Read (deferred to /cc-plan) _None. List any source files that could not be understood within the 30-line cap. /cc-plan will perform full reads of these files before task breakdown._ ## Complexity Estimate [S / M / L — with one sentence justification] --- ## Delegated writing (`--delegate`, FEAT-061) Without `--delegate` in `$ARGUMENTS`, skip this section: this session writes the spec, as above. With it, the `spec` role agent writes the file under its tool mask and Guard 5's scope check. `--delegate` is a flag, not part of the topic: leave it out of the topic and of the codebase search. The search and the questions above still run here first. 1. Install the envelope, from the project root: ```sh S=.claude/scripts; [ -f "$S/orchestrate.mjs" ] || S=scripts node "$S/orchestrate.mjs" envelope spec --item ``` `` is the item's backlog id (for example `FEAT-061`), else `adhoc`. 2. Only a first stdout line that starts with `installed:` allows the dispatch; the envelope's `ops.scope` is the folder the spec goes in. If the verb's stderr says the run `is live in this session`, stop: that run's Define band writes this document; continue with `/cc-orchestrate`, or end the run. On any other non-zero exit or first line, print `spec not dispatched: ` and write the spec in this session, as above. 3. Dispatch `Agent({ subagent_type: "spec", description: "write spec", prompt })`. The brief names the item, the folder from the envelope's scope, the answers gathered above, the requirements document consumed in the intake and the UX constraints when either exists, and the section list above as the content to write. It says that a phase command, not a run, dispatched the agent, and that the envelope is installed at `.claude/memory/band-envelope.json`. 4. Show the agent's report and its `SNAP_HANDBACK` line; do not record the hand-back. A guard denial or a report without a hand-back is shown as it is, never retried another way. 5. Run `node "$S/orchestrate.mjs" envelope --clear`, also when the agent was denied or ended without a hand-back. If it refuses, report the refusal and leave the file alone: a run now owns it. 6. The written spec then goes through the approval wait below, as a spec written in this session would. Wait for explicit approval before proceeding to `/cc-plan`. Once approved, append a summary to `.claude/memory/project.md` under: `## Spec: [name] [YYYY-MM-DD]` Then, in its `## Current State` section, replace the single `- Active spec:` line with that heading text, without its leading `## `, in one Edit. If the section is absent, skip this step: the next `/cc-checkpoint` inserts it. --- ## Phase exit Once the spec is approved and the summary has been appended to `.claude/memory/project.md`, instruct the user: > "Spec complete. Run `/cc-compact` now before starting `/cc-plan`." Do not proceed to plan phase without user confirmation that `/cc-compact` has been run.