diff --git a/.claude/skills/titan-grind/SKILL.md b/.claude/skills/titan-grind/SKILL.md new file mode 100644 index 00000000..77481238 --- /dev/null +++ b/.claude/skills/titan-grind/SKILL.md @@ -0,0 +1,447 @@ +--- +name: titan-grind +description: Adopt extracted helpers — find dead symbols from forge, wire them into consumers, replace duplicated inline patterns, and gate on dead-symbol delta (Titan Paradigm Phase 4.5) +argument-hint: <--dry-run> <--phase N> <--target name> <--yes> +allowed-tools: Bash, Read, Write, Edit, Glob, Grep, Skill, Agent +--- + +# Titan GRIND — Adopt Extracted Helpers + +You are running the **GRIND** phase of the Titan Paradigm. + +Forge shapes the metal. Grind smooths the rough edges. Your goal: find helpers that forge extracted but never wired into consumers, adopt them across the codebase, and gate on a non-positive dead-symbol delta. + +> **Why this phase exists:** Forge decomposes god-functions into smaller helpers, but those helpers are only called within their own file. The dead symbol count inflates with every forge phase because the adoption loop is never closed. Grind closes it. + +> **Context budget:** One forge phase per invocation. Process all targets from one forge phase's commits, then stop. User re-runs for the next phase. + +**Arguments** (from `$ARGUMENTS`): +- No args → process the next unground forge phase +- `--phase N` → process a specific forge phase +- `--target ` → run single target only (for retrying failures) +- `--dry-run` → analyze and report without making changes +- `--yes` → skip confirmation prompt (typically passed by `/titan-run` orchestrator) + +--- + +## Step 0 — Pre-flight + +1. **Worktree check:** + ```bash + git rev-parse --show-toplevel && git worktree list + ``` + If not in a worktree, stop: "Run `/worktree` first." + +2. **Sync with main:** + ```bash + git fetch origin main && git merge origin/main --no-edit + ``` + If merge conflicts → stop: "Merge conflict detected. Resolve and re-run `/titan-grind`." + +3. **Load artifacts.** Read: + - `.codegraph/titan/titan-state.json` — current state (required) + - `.codegraph/titan/sync.json` — execution plan (required) + - `.codegraph/titan/gate-log.ndjson` — gate verdicts (optional) + - `.codegraph/titan/grind-targets.ndjson` — persisted grind analysis (optional, exists on resume) + +4. **Validate state.** Grind runs after forge. Check: + - `titan-state.json → execution` block exists + - `execution.completedPhases` has at least one entry + - If no `execution` block → stop: "No forge execution found. Run `/titan-forge` first." + +5. **Initialize grind state** (if `grind` block doesn't exist in `titan-state.json`). Merge into `titan-state.json`: + ```json + { + "grind": { + "completedPhases": [], + "currentPhase": null, + "currentTarget": null, + "processedTargets": [], + "failedTargets": [], + "adoptions": [], + "removals": [], + "falsePositives": [], + "deadSymbolBaseline": null, + "deadSymbolCurrent": null + } + } + ``` + +6. **Ensure graph is current.** Rebuild if stale: + ```bash + codegraph build + ``` + +7. **Capture dead-symbol baseline** (only if `grind.deadSymbolBaseline` is null): + ```bash + codegraph roles --role dead -T --json | node -e "const d=[];process.stdin.on('data',c=>d.push(c));process.stdin.on('end',()=>{const items=JSON.parse(Buffer.concat(d));console.log(JSON.stringify({total:items.length,byRole:items.reduce((a,i)=>{a[i.role]=(a[i.role]||0)+1;return a},{})}));})" + ``` + Store the total in `grind.deadSymbolBaseline`. Write `titan-state.json` immediately. + +8. **Determine next phase.** Use `--phase N` if provided, otherwise find the lowest forge phase number not in `grind.completedPhases`. + +9. **Update state.** Set `grind.currentPhase` to the target phase number. Write `titan-state.json`. + +10. **Print plan and ask for confirmation** (unless `--yes`): + ``` + GRIND — Phase N: