@wazir-dev/cli 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/CHANGELOG.md +73 -4
  2. package/README.md +6 -6
  3. package/docs/concepts/architecture.md +1 -1
  4. package/docs/concepts/roles-and-workflows.md +2 -0
  5. package/docs/concepts/why-wazir.md +59 -0
  6. package/docs/decisions/2026-03-19-deferred-items.md +564 -0
  7. package/docs/decisions/2026-03-19-enhancement-decisions.md +300 -0
  8. package/docs/readmes/INDEX.md +21 -5
  9. package/docs/readmes/features/expertise/README.md +2 -2
  10. package/docs/readmes/features/exports/README.md +2 -2
  11. package/docs/readmes/features/schemas/README.md +3 -0
  12. package/docs/readmes/features/skills/README.md +17 -0
  13. package/docs/readmes/features/skills/clarifier.md +5 -0
  14. package/docs/readmes/features/skills/claude-cli.md +5 -0
  15. package/docs/readmes/features/skills/codex-cli.md +5 -0
  16. package/docs/readmes/features/skills/dispatching-parallel-agents.md +5 -0
  17. package/docs/readmes/features/skills/executing-plans.md +5 -0
  18. package/docs/readmes/features/skills/executor.md +5 -0
  19. package/docs/readmes/features/skills/finishing-a-development-branch.md +5 -0
  20. package/docs/readmes/features/skills/gemini-cli.md +5 -0
  21. package/docs/readmes/features/skills/humanize.md +5 -0
  22. package/docs/readmes/features/skills/init-pipeline.md +5 -0
  23. package/docs/readmes/features/skills/receiving-code-review.md +5 -0
  24. package/docs/readmes/features/skills/requesting-code-review.md +5 -0
  25. package/docs/readmes/features/skills/reviewer.md +5 -0
  26. package/docs/readmes/features/skills/subagent-driven-development.md +5 -0
  27. package/docs/readmes/features/skills/using-git-worktrees.md +5 -0
  28. package/docs/readmes/features/skills/wazir.md +5 -0
  29. package/docs/readmes/features/skills/writing-skills.md +5 -0
  30. package/docs/readmes/features/workflows/prepare-next.md +1 -1
  31. package/docs/reference/configuration-reference.md +47 -6
  32. package/docs/reference/launch-checklist.md +4 -4
  33. package/docs/reference/review-loop-pattern.md +117 -8
  34. package/docs/reference/roles-reference.md +1 -0
  35. package/docs/reference/skill-tiers.md +147 -0
  36. package/docs/reference/tooling-cli.md +3 -1
  37. package/docs/truth-claims.yaml +12 -0
  38. package/expertise/antipatterns/process/ai-coding-antipatterns.md +97 -1
  39. package/exports/hosts/claude/.claude/settings.json +9 -0
  40. package/exports/hosts/claude/CLAUDE.md +1 -1
  41. package/exports/hosts/claude/export.manifest.json +4 -2
  42. package/exports/hosts/claude/host-package.json +3 -1
  43. package/exports/hosts/codex/AGENTS.md +1 -1
  44. package/exports/hosts/codex/export.manifest.json +4 -2
  45. package/exports/hosts/codex/host-package.json +3 -1
  46. package/exports/hosts/cursor/.cursor/hooks.json +4 -0
  47. package/exports/hosts/cursor/.cursor/rules/wazir-core.mdc +1 -1
  48. package/exports/hosts/cursor/export.manifest.json +4 -2
  49. package/exports/hosts/cursor/host-package.json +3 -1
  50. package/exports/hosts/gemini/GEMINI.md +1 -1
  51. package/exports/hosts/gemini/export.manifest.json +4 -2
  52. package/exports/hosts/gemini/host-package.json +3 -1
  53. package/hooks/context-mode-router +191 -0
  54. package/hooks/definitions/context_mode_router.yaml +19 -0
  55. package/hooks/hooks.json +31 -6
  56. package/hooks/protected-path-write-guard +8 -0
  57. package/hooks/routing-matrix.json +45 -0
  58. package/hooks/session-start +62 -1
  59. package/llms-full.txt +905 -132
  60. package/package.json +2 -3
  61. package/schemas/hook.schema.json +2 -1
  62. package/schemas/phase-report.schema.json +80 -0
  63. package/schemas/usage.schema.json +25 -1
  64. package/schemas/wazir-manifest.schema.json +19 -0
  65. package/skills/brainstorming/SKILL.md +18 -155
  66. package/skills/clarifier/SKILL.md +122 -98
  67. package/skills/claude-cli/SKILL.md +320 -0
  68. package/skills/codex-cli/SKILL.md +260 -0
  69. package/skills/debugging/SKILL.md +13 -0
  70. package/skills/design/SKILL.md +13 -0
  71. package/skills/dispatching-parallel-agents/SKILL.md +13 -0
  72. package/skills/executing-plans/SKILL.md +13 -0
  73. package/skills/executor/SKILL.md +72 -19
  74. package/skills/finishing-a-development-branch/SKILL.md +13 -0
  75. package/skills/gemini-cli/SKILL.md +260 -0
  76. package/skills/humanize/SKILL.md +13 -0
  77. package/skills/init-pipeline/SKILL.md +73 -164
  78. package/skills/prepare-next/SKILL.md +81 -10
  79. package/skills/receiving-code-review/SKILL.md +13 -0
  80. package/skills/requesting-code-review/SKILL.md +13 -0
  81. package/skills/reviewer/SKILL.md +287 -15
  82. package/skills/run-audit/SKILL.md +13 -0
  83. package/skills/scan-project/SKILL.md +13 -0
  84. package/skills/self-audit/SKILL.md +197 -16
  85. package/skills/subagent-driven-development/SKILL.md +13 -0
  86. package/skills/subagent-driven-development/code-quality-reviewer-prompt.md +2 -0
  87. package/skills/subagent-driven-development/implementer-prompt.md +8 -0
  88. package/skills/subagent-driven-development/spec-reviewer-prompt.md +7 -0
  89. package/skills/tdd/SKILL.md +13 -0
  90. package/skills/using-git-worktrees/SKILL.md +13 -0
  91. package/skills/using-skills/SKILL.md +13 -0
  92. package/skills/verification/SKILL.md +13 -0
  93. package/skills/wazir/SKILL.md +194 -377
  94. package/skills/writing-plans/SKILL.md +14 -1
  95. package/skills/writing-skills/SKILL.md +13 -0
  96. package/templates/artifacts/implementation-plan.md +3 -0
  97. package/templates/artifacts/tasks-template.md +133 -0
  98. package/templates/examples/phase-report.example.json +48 -0
  99. package/tooling/src/adapters/composition-engine.js +256 -0
  100. package/tooling/src/adapters/model-router.js +84 -0
  101. package/tooling/src/capture/command.js +24 -1
  102. package/tooling/src/capture/run-config.js +3 -1
  103. package/tooling/src/capture/store.js +24 -0
  104. package/tooling/src/capture/usage.js +106 -0
  105. package/tooling/src/checks/ac-matrix.js +256 -0
  106. package/tooling/src/checks/command-registry.js +12 -0
  107. package/tooling/src/checks/docs-truth.js +1 -1
  108. package/tooling/src/checks/skills.js +111 -0
  109. package/tooling/src/cli.js +9 -0
  110. package/tooling/src/commands/stats.js +161 -0
  111. package/tooling/src/commands/validate.js +5 -1
  112. package/tooling/src/export/compiler.js +33 -37
  113. package/tooling/src/gating/agent.js +145 -0
  114. package/tooling/src/guards/phase-prerequisite-guard.js +127 -0
  115. package/tooling/src/hooks/routing-logic.js +69 -0
  116. package/tooling/src/init/auto-detect.js +260 -0
  117. package/tooling/src/init/command.js +95 -135
  118. package/tooling/src/input/scanner.js +46 -0
  119. package/tooling/src/reports/command.js +103 -0
  120. package/tooling/src/reports/phase-report.js +323 -0
  121. package/tooling/src/state/command.js +160 -0
  122. package/tooling/src/state/db.js +287 -0
  123. package/tooling/src/status/command.js +53 -1
  124. package/wazir.manifest.yaml +26 -14
@@ -5,9 +5,22 @@ description: Run the clarification pipeline — research, clarify scope, brainst
5
5
 
6
6
  # Clarifier
7
7
 
8
- Run Phase 0 (Research) + Phase 1 (Clarify, Brainstorm, Plan) for the current project.
8
+ ## Command Routing
9
+ Follow the Canonical Command Matrix in `hooks/routing-matrix.json`.
10
+ - Large commands (test runners, builds, diffs, dependency trees, linting) → context-mode tools
11
+ - Small commands (git status, ls, pwd, wazir CLI) → native Bash
12
+ - If context-mode unavailable, fall back to native Bash with warning
9
13
 
10
- **Pacing rule:** This skill has mandatory user checkpoints between phases. Do NOT skip checkpoints. Do NOT combine phases. Complete each phase fully, present the output, and wait for explicit user approval before advancing.
14
+ ## Codebase Exploration
15
+ 1. Query `wazir index search-symbols <query>` first
16
+ 2. Use `wazir recall file <path> --tier L1` for targeted reads
17
+ 3. Fall back to direct file reads ONLY for files identified by index queries
18
+ 4. Maximum 10 direct file reads without a justifying index query
19
+ 5. If no index exists: `wazir index build && wazir index summarize --tier all`
20
+
21
+ Run the Clarifier phase — everything from reading input to having an approved execution plan.
22
+
23
+ **Pacing rule:** This skill has mandatory user checkpoints between sub-workflows. Do NOT skip checkpoints. Do NOT combine sub-workflows. Complete each fully, present output, and wait for explicit user approval before advancing.
11
24
 
12
25
  Review loops follow the pattern in `docs/reference/review-loop-pattern.md`. All reviewer invocations use explicit `--mode`.
13
26
 
@@ -17,8 +30,10 @@ Review loops follow the pattern in `docs/reference/review-loop-pattern.md`. All
17
30
 
18
31
  1. Check `.wazir/state/config.json` exists. If not, run `wazir init` first.
19
32
  2. Check `.wazir/input/briefing.md` exists. If not, ask the user what they want to build and save it there.
20
- 3. Read config for `default_depth`, `default_intent`, `team_mode`, and `multi_tool` settings.
21
- 4. Create a run directory if one doesn't exist:
33
+ 3. Scan `input/` (project-level) and `.wazir/input/` (state-level) for additional input files. Present what's found.
34
+ 4. Read config for `default_depth` and `multi_tool` settings.
35
+ 5. **Load accepted learnings:** Glob `memory/learnings/accepted/*.md`. For each accepted learning, read scope tags. Inject learnings whose scope matches the current run's intent/stack into context. Limit: top 10 by confidence, most recent first. This is how prior run insights improve future runs.
36
+ 6. Create a run directory if one doesn't exist:
22
37
  ```bash
23
38
  mkdir -p .wazir/runs/run-YYYYMMDD-HHMMSS/{sources,tasks,artifacts,reviews,clarified}
24
39
  ln -sfn run-YYYYMMDD-HHMMSS .wazir/runs/latest
@@ -26,30 +41,39 @@ Review loops follow the pattern in `docs/reference/review-loop-pattern.md`. All
26
41
 
27
42
  ---
28
43
 
29
- ## Phase 0: Research (delegated)
44
+ ## Context-Mode Usage
45
+
46
+ Read `context_mode` from `.wazir/state/config.json`:
47
+
48
+ - **If `context_mode.enabled: true`:** Use `fetch_and_index` for URL fetching, `search` for follow-up queries on indexed content. Use `execute` or `execute_file` for large outputs instead of Bash.
49
+ - **If `context_mode.enabled: false`:** Fall back to `WebFetch` for URLs and `Bash` for commands.
50
+
51
+ ---
52
+
53
+ ## Sub-Workflow 1: Research (discover workflow)
30
54
 
31
55
  Delegate to the discover workflow (`workflows/discover.md`):
32
56
 
33
- 1. The **researcher role** produces the research artifact
34
- (codebase scan, external sources, source manifest, research brief).
35
- 2. The **reviewer role** runs the research-review loop
36
- using research dimensions with `--mode research-review`
37
- (see `docs/reference/review-loop-pattern.md`).
38
- 3. The researcher resolves findings from each pass.
39
- 4. Loop runs for `pass_counts[depth]` passes.
40
- 5. Research artifact flows back to the clarifier for Checkpoint 0.
57
+ 1. **Keyword extraction:** Read the briefing and extract concepts/terms that are vague, reference external standards, or use unfamiliar terminology.
58
+ - **When to research:** concept references an external standard by name, uses a tool/library not seen in the codebase, or is ambiguous enough that two agents could interpret it differently.
59
+ - **When NOT to research:** concept is fully defined in the input, or it's a well-known programming concept.
60
+ 2. **Fetch sources:** For each concept needing research:
61
+ - Use `fetch_and_index` (if context-mode available) or `WebFetch` to fetch the source.
62
+ - Save fetched content to `.wazir/runs/latest/sources/`.
63
+ - Track each fetch in `sources/manifest.json`.
64
+ 3. **Error handling:** 404/unreachable log failure, continue. Research is best-effort.
65
+ 4. The **researcher role** produces the research artifact.
66
+ 5. The **reviewer role** runs the research-review loop with `--mode research-review`.
67
+ 6. Loop runs for `pass_counts[depth]` passes.
41
68
 
42
69
  Save result to `.wazir/runs/latest/clarified/research-brief.md`.
43
70
 
44
- ### Checkpoint 0: Research Review
45
-
46
- Present the research brief to the user:
71
+ ### Checkpoint: Research Review
47
72
 
48
73
  > **Research complete. Here's what I found:**
49
74
  >
50
- > [Summary of existing codebase state, relevant architecture, external context]
75
+ > [Summary of codebase state, relevant architecture, external context]
51
76
  >
52
- > **Does this match your understanding? Anything to add or correct?**
53
77
  > 1. **Looks good, continue** (Recommended)
54
78
  > 2. **Missing context** — let me add more information
55
79
  > 3. **Wrong direction** — let me clarify the intent
@@ -58,162 +82,162 @@ Present the research brief to the user:
58
82
 
59
83
  ---
60
84
 
61
- ## Phase 1A: Clarify (autonomous, then review, then checkpoint)
85
+ ## Sub-Workflow 2: Clarify (clarify workflow)
86
+
87
+ ### Input Preservation (before producing clarification)
88
+
89
+ 1. Glob `.wazir/input/tasks/*.md`. If files exist:
90
+ - Adopt those specs as the starting point — copy content verbatim into the clarification's item descriptions.
91
+ - Enhance with codebase scan + research findings. **Never remove detail — only add.**
92
+ - Every acceptance criterion from input must appear verbatim.
93
+ - Every API endpoint, color hex code, and UI dimension from input must appear in the relevant item section.
94
+ 2. If `.wazir/input/tasks/` is empty or missing, synthesize from `briefing.md` alone.
95
+
96
+ ### Clarification Production
62
97
 
63
98
  Read the briefing, research brief, and codebase context. Produce:
64
99
 
65
- - **What** we're building — concrete deliverables, not vague descriptions
100
+ - **What** we're building — concrete deliverables
66
101
  - **Why** — the motivation and business value
67
102
  - **Constraints** — technical, timeline, dependencies
68
- - **Assumptions** — what we're taking as given (explicitly stated)
103
+ - **Assumptions** — what we're taking as given
69
104
  - **Scope boundaries** — what's IN and what's explicitly OUT
70
- - **Unresolved questions** — anything ambiguous that could change architecture or acceptance criteria
105
+ - **Unresolved questions** — anything ambiguous
71
106
 
72
107
  Save to `.wazir/runs/latest/clarified/clarification.md`.
73
108
 
74
- Invoke the review loop for the clarification artifact using spec/clarification dimensions with `--mode clarification-review`. The **reviewer role** runs the loop (see `docs/reference/review-loop-pattern.md`). Resolve any findings before presenting to user.
109
+ Invoke `wz:reviewer --mode clarification-review`. Resolve findings before presenting to user.
75
110
 
76
- ### Checkpoint 1A: Clarification Review
77
-
78
- Present the full clarification to the user:
111
+ ### Checkpoint: Clarification Review
79
112
 
80
113
  > **Here's the clarified scope:**
81
114
  >
82
- > [Full clarification with what/why/constraints/assumptions/scope/questions]
115
+ > [Full clarification]
83
116
  >
84
- > **Are there any corrections, missing context, or open questions to resolve?**
85
- > 1. **Approved — continue to spec hardening**
117
+ > 1. **Approved continue to spec hardening** (Recommended)
86
118
  > 2. **Needs changes** — [user provides corrections]
87
119
  > 3. **Missing important context** — [user adds information]
88
120
 
89
- **Wait for user response. If the user provides corrections, update the clarification and re-present.**
121
+ **Wait for user response.** Route feedback: plan corrections `user-feedback.md`, new requirements → `briefing.md`.
90
122
 
91
123
  ---
92
124
 
93
- ## Phase 1A+: Spec Harden (delegated, then checkpoint)
125
+ ## Sub-Workflow 3: Spec Harden (specify + spec-challenge workflows)
94
126
 
95
127
  Delegate to the specify workflow (`workflows/specify.md`):
96
128
 
97
- 1. The **specifier role** produces a measurable spec from the clarification
98
- and research artifacts.
99
- 2. The **reviewer role** runs the spec-challenge loop
100
- (`workflows/spec-challenge.md`) with `--mode spec-challenge`.
101
- 3. The specifier resolves findings from each pass.
102
- 4. Loop runs for `pass_counts[depth]` passes.
129
+ 1. The **specifier role** produces a measurable spec from clarification + research.
130
+ 2. Invoke `wz:reviewer --mode spec-challenge`.
131
+ 3. Loop runs for `pass_counts[depth]` passes.
103
132
 
104
133
  Save result to `.wazir/runs/latest/clarified/spec-hardened.md`.
105
134
 
106
- ### Checkpoint 1A+: Hardened Spec Review
135
+ ### Content-Author Detection
136
+
137
+ After spec hardening, scan the spec for content needs. Auto-enable the `author` workflow if the spec mentions any of:
138
+ - Database seeding, seed data, fixtures, sample records
139
+ - Sample content, placeholder text, demo data
140
+ - Test fixtures, mock API responses, test data files
141
+ - Translations, i18n strings, localization
142
+ - Copy (button labels, error messages, onboarding text)
143
+ - Documentation content, user guides, API docs
144
+ - Email templates, notification text
107
145
 
108
- Present the changes made during hardening:
146
+ If detected, set `workflow_policy.author.enabled = true` in the run config and note:
147
+ > **Content needs detected.** The content-author workflow will run after design approval to produce: [list detected content types].
148
+
149
+ ### Checkpoint: Hardened Spec Review
109
150
 
110
151
  > **Spec hardened. Changes made:**
111
152
  >
112
- > [List of each gap found and how it was tightened]
153
+ > [List of gaps found and how they were tightened]
113
154
  >
114
- > **Review the hardened spec. Approve or adjust?**
115
155
  > 1. **Approved — continue to brainstorming** (Recommended)
116
156
  > 2. **Disagree with a change** — [user specifies]
117
157
  > 3. **Found more gaps** — [user adds]
118
158
 
119
- **Wait for user response before continuing.**
159
+ **Wait for user response.**
120
160
 
121
161
  ---
122
162
 
123
- ## Phase 1B: Brainstorm (interactive always pauses)
163
+ ## Sub-Workflow 4: Brainstorm (design + design-review workflows)
124
164
 
125
- Invoke the `brainstorming` skill (`wz:brainstorming`) and follow it.
165
+ Invoke the `brainstorming` skill (`wz:brainstorming`):
126
166
 
127
- This phase explores design approaches:
128
167
  1. Propose 2-3 viable approaches with explicit trade-offs
129
168
  2. For each approach: effort estimate, risk assessment, what it enables/prevents
130
169
  3. Recommend one approach with rationale
131
170
 
132
- If `team_mode: parallel` in config, the brainstorming skill activates its
133
- **Agent Teams Structured Dialogue** mode:
134
-
135
- 1. Checks that `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` is enabled (falls back
136
- to single-agent brainstorming if not)
137
- 2. Creates a team via `TeamCreate` (`wazir-brainstorm-<concept-slug>`)
138
- 3. Spawns three teammates via `Agent` with `team_name`:
139
- - **Free Thinker** — proposes creative directions via `SendMessage`
140
- - **Grounder** — challenges each direction with practical concerns via `SendMessage`
141
- - **Synthesizer** — observes silently, writes the design document on convergence
142
- 4. You (the Arbiter) coordinate the dialogue, signal convergence, and clean up
143
- with `TeamDelete`
144
-
145
- See `skills/brainstorming/SKILL.md` "Team Mode: Agent Teams Structured Dialogue"
146
- for full spawn prompts, convergence criteria, and constraints.
171
+ ### Checkpoint: Design Approval
147
172
 
148
- ### Checkpoint 1B: Design Approval
149
-
150
- > **Proposed design approaches:**
151
- >
152
- > [Approaches with trade-offs, recommendation]
153
- >
154
173
  > **Which approach should we implement?**
155
- > 1. **Approach A** — [one-line summary]
174
+ >
175
+ > 1. **Approach A** — [one-line summary] (Recommended)
156
176
  > 2. **Approach B** — [one-line summary]
157
177
  > 3. **Approach C** — [one-line summary]
158
178
  > 4. **Modify an approach** — [user specifies changes]
159
179
 
160
- **This is the most important checkpoint. Do NOT proceed without explicit design approval.**
180
+ **Wait for user response.** This is the most important checkpoint.
161
181
 
162
182
  Save approved design to `.wazir/runs/latest/clarified/design.md`.
163
183
 
164
- ### Design Review
165
-
166
- After the user approves the design concept, invoke the design-review loop with `--mode design-review`. The **reviewer role** validates the design against the approved spec using the canonical design-review dimensions:
167
-
168
- - Spec coverage
169
- - Design-spec consistency
170
- - Accessibility
171
- - Visual consistency
172
- - Exported-code fidelity
173
-
174
- See `workflows/design-review.md` and `docs/reference/review-loop-pattern.md`. The designer resolves findings. Proceed to planning only after all design-review passes complete.
184
+ After approval: design-review loop with `--mode design-review` (5 canonical dimensions: spec coverage, design-spec consistency, accessibility, visual consistency, exported-code fidelity).
175
185
 
176
186
  ---
177
187
 
178
- ## Phase 1C: Plan (delegated, then checkpoint)
188
+ ## Sub-Workflow 5: Plan (plan + plan-review workflows)
179
189
 
180
190
  Delegate to `wz:writing-plans`:
181
191
 
182
- 1. `wz:writing-plans` (using **planner role**) produces the execution plan
183
- and task specs.
184
- 2. The **reviewer role** runs the plan-review loop
185
- (`workflows/plan-review.md`) with `--mode plan-review`.
186
- 3. The planner resolves findings from each pass.
187
- 4. Loop runs for `pass_counts[depth]` passes.
192
+ 1. Planner produces a SINGLE execution plan at `.wazir/runs/latest/clarified/execution-plan.md` in spec-kit format.
193
+ 2. **Gap analysis exit gate:** Compare original input against plan. Invoke `wz:reviewer --mode plan-review`.
194
+ 3. Loop until clean or cap reached.
188
195
 
189
- ### Checkpoint 1C: Plan Review
196
+ ### Checkpoint: Plan Review
190
197
 
191
198
  > **Implementation plan: [N] tasks**
192
199
  >
193
200
  > | # | Task | Complexity | Dependencies | Description |
194
201
  > |---|------|-----------|--------------|-------------|
195
- > | 1 | ... | S | none | ... |
196
- > | 2 | ... | M | task-1 | ... |
197
202
  >
198
- > **Review the plan. Approve or adjust?**
199
203
  > 1. **Approved — ready for execution** (Recommended)
200
- > 2. **Reorder or split tasks** — [user specifies]
201
- > 3. **Missing tasks** — [user adds]
202
- > 4. **Too granular / too coarse** — [user adjusts scope]
204
+ > 2. **Reorder or split tasks**
205
+ > 3. **Missing tasks**
206
+ > 4. **Too granular / too coarse**
207
+
208
+ **Wait for user response.**
209
+
210
+ ---
211
+
212
+ ### Scope Coverage Gate (Hard Gate)
213
+
214
+ Before presenting the plan to the user, verify ALL input items are covered:
215
+
216
+ 1. Count distinct items/deliverables in the input briefing (`.wazir/input/briefing.md` + any `input/*.md` files)
217
+ 2. Count tasks in the execution plan
218
+ 3. **If `tasks_in_plan < items_in_input`:** STOP and present:
219
+
220
+ > **Scope reduction detected.** The input contains [N] items but the plan only covers [M].
221
+ >
222
+ > Missing items: [list]
223
+ >
224
+ > 1. **Add missing items to the plan** (Required)
225
+ > 2. **User explicitly approves reduced scope** — only if user confirms
226
+
227
+ **The clarifier MUST NOT autonomously drop items into "future tiers", "deferred", or "out of scope" without explicit user approval. This is a hard rule.**
203
228
 
204
- **Wait for user response before completing.**
229
+ Invariant: `items_in_plan >= items_in_input` unless user explicitly approves reduction.
205
230
 
206
231
  ---
207
232
 
208
233
  ## Done
209
234
 
210
- When the plan is approved, present:
235
+ When the plan is approved:
211
236
 
212
- > **Clarification complete.**
237
+ > **Clarifier phase complete.**
213
238
  >
214
239
  > - Spec: `.wazir/runs/latest/clarified/spec-hardened.md`
215
240
  > - Design: `.wazir/runs/latest/clarified/design.md`
216
- > - Tasks: [count] tasks in `.wazir/runs/latest/tasks/`
217
241
  > - Plan: `.wazir/runs/latest/clarified/execution-plan.md`
218
242
  >
219
- > **Next:** Run `/wazir:executor` to execute the plan.
243
+ > **Next:** Run `/executor` to implement the plan.
@@ -0,0 +1,320 @@
1
+ ---
2
+ name: wz:claude-cli
3
+ description: How to use Claude Code CLI programmatically for reviews, automation, and non-interactive operations within Wazir pipelines.
4
+ ---
5
+
6
+ # Claude Code CLI Integration
7
+
8
+ ## Command Routing
9
+ Follow the Canonical Command Matrix in `hooks/routing-matrix.json`.
10
+ - Large commands (test runners, builds, diffs, dependency trees, linting) → context-mode tools
11
+ - Small commands (git status, ls, pwd, wazir CLI) → native Bash
12
+ - If context-mode unavailable, fall back to native Bash with warning
13
+
14
+ ## Codebase Exploration
15
+ 1. Query `wazir index search-symbols <query>` first
16
+ 2. Use `wazir recall file <path> --tier L1` for targeted reads
17
+ 3. Fall back to direct file reads ONLY for files identified by index queries
18
+ 4. Maximum 10 direct file reads without a justifying index query
19
+ 5. If no index exists: `wazir index build && wazir index summarize --tier all`
20
+
21
+ Reference for using the Claude Code CLI (Anthropic's official CLI for Claude) in Wazir pipelines. Claude Code is an agentic coding tool that operates in your terminal with access to tools like file operations, search, and bash execution.
22
+
23
+ ## Commands
24
+
25
+ ### claude (interactive)
26
+
27
+ Launch the interactive TUI for ad-hoc work.
28
+
29
+ ```bash
30
+ claude
31
+ claude "Fix the failing test in src/auth.ts"
32
+ ```
33
+
34
+ ### Print Mode (non-interactive)
35
+
36
+ The `-p` (or `--print`) flag is the primary mode for Wazir automation. It runs Claude Code non-interactively, outputs the result to stdout, and exits.
37
+
38
+ ```bash
39
+ # Basic non-interactive prompt
40
+ claude -p "Explain the architecture of this project"
41
+
42
+ # Pipe data from stdin (avoids command-line length limits)
43
+ git diff main | claude -p "Review this diff for bugs"
44
+
45
+ # Chain with other tools
46
+ claude -p "List all exported functions" --output-format json | jq '.result'
47
+
48
+ # Save output to file
49
+ claude -p "Summarize the test coverage" > summary.md
50
+ ```
51
+
52
+ **Key flags (all work with `-p`):**
53
+
54
+ | Flag | Description |
55
+ |------|-------------|
56
+ | `-p, --print` | Run non-interactively; print response to stdout and exit |
57
+ | `--model <MODEL>` | Select model: `opus`, `sonnet`, `haiku`, or full name (e.g., `claude-opus-4-6`) |
58
+ | `--fallback-model <MODEL>` | Fallback model when the primary is overloaded (print mode) |
59
+ | `--output-format <FORMAT>` | Output format: `text` (default), `json`, `stream-json` |
60
+ | `--json-schema <SCHEMA>` | Enforce structured output conforming to a JSON schema (requires `--output-format json`) |
61
+ | `--allowedTools <TOOLS...>` | Pre-approve specific tools without prompting (space-separated) |
62
+ | `--disallowedTools <TOOLS...>` | Block specific tools from being used |
63
+ | `--max-turns <N>` | Limit agentic turns in a session |
64
+ | `--append-system-prompt <TEXT>` | Add custom instructions while keeping default capabilities (safe choice) |
65
+ | `--system-prompt <TEXT>` | Replace the entire system prompt (removes all defaults; use with caution) |
66
+ | `--dangerously-skip-permissions` | Bypass all permission barriers (CI/CD and dev containers only) |
67
+ | `--verbose` | Enable verbose output for debugging |
68
+ | `--input-format <FORMAT>` | Input format: `text` (default) |
69
+
70
+ ### Session Management
71
+
72
+ ```bash
73
+ # Continue most recent session in current directory
74
+ claude -c
75
+
76
+ # Resume a specific session by ID
77
+ claude -r <SESSION_ID>
78
+
79
+ # Resume from a PR
80
+ claude --from-pr <NUMBER>
81
+
82
+ # Fork a session into a new thread
83
+ claude --fork-session <SESSION_ID>
84
+
85
+ # Set a custom session ID
86
+ claude --session-id <ID>
87
+ ```
88
+
89
+ ### Subcommands
90
+
91
+ | Subcommand | Description |
92
+ |------------|-------------|
93
+ | `claude mcp add` | Add an MCP server (`--transport http\|stdio`, `-s` for scope, `-e` for env vars) |
94
+ | `claude mcp serve` | Expose Claude Code itself as an MCP server |
95
+ | `claude agents` | List all configured agents |
96
+ | `claude config` | Manage configuration settings |
97
+ | `claude remote-control` | Serve your local environment for external builds |
98
+
99
+ ## Model Selection
100
+
101
+ | Model | Best For | Notes |
102
+ |-------|----------|-------|
103
+ | `opus` / `claude-opus-4-6` | Complex reasoning, architecture, multi-step tasks | Most capable, highest cost |
104
+ | `sonnet` / `claude-sonnet-4-6` | Daily coding, balanced performance | Recommended default |
105
+ | `haiku` / `claude-haiku-4-5` | Quick tasks, fast responses, high volume | Lowest cost, fastest |
106
+
107
+ **Select via:**
108
+ - CLI flag: `--model opus` or `--model claude-opus-4-6`
109
+ - Interactive: `/model` slash command
110
+ - Environment variable: `CLAUDE_MODEL`
111
+ - Settings: `.claude/settings.json`
112
+
113
+ **Fallback:** Use `--fallback-model haiku` with `-p` to auto-switch when the primary model is overloaded.
114
+
115
+ ## Permission Management
116
+
117
+ ### allowedTools
118
+
119
+ Pre-approve tools to avoid interactive permission prompts. Critical for non-interactive automation.
120
+
121
+ ```bash
122
+ # Allow specific tools
123
+ claude -p --allowedTools "Read" "Grep" "Glob" "Bash(npm run test:*)" \
124
+ "Review the test suite"
125
+
126
+ # Allow all tools (equivalent to dangerously-skip-permissions but scoped)
127
+ claude -p --allowedTools "Read" "Write" "Edit" "Bash" "Grep" "Glob" \
128
+ "Fix the bug in auth.ts"
129
+ ```
130
+
131
+ **Tool name patterns:**
132
+ - Exact: `"Read"`, `"Write"`, `"Edit"`, `"Bash"`, `"Grep"`, `"Glob"`
133
+ - Scoped: `"Bash(npm run test:*)"` allows only matching bash commands
134
+ - MCP tools: `"mcp__servername__toolname"`
135
+
136
+ ### disallowedTools
137
+
138
+ Block specific tools:
139
+
140
+ ```bash
141
+ claude -p --disallowedTools "Write" "Edit" "Bash" \
142
+ "Analyze this codebase for security issues"
143
+ ```
144
+
145
+ ### Project permissions
146
+
147
+ Store permanent permissions in `.claude/settings.json`:
148
+
149
+ ```json
150
+ {
151
+ "permissions": {
152
+ "allowedTools": ["Read", "Grep", "Glob"],
153
+ "deny": ["Bash(rm *)"]
154
+ }
155
+ }
156
+ ```
157
+
158
+ ## Non-Interactive Usage
159
+
160
+ ### Piping data
161
+
162
+ ```bash
163
+ # Pipe a diff for review
164
+ git diff main | claude -p "Review this diff for correctness"
165
+
166
+ # Pipe file content
167
+ cat src/auth.ts | claude -p "Find potential bugs"
168
+
169
+ # Pipe combined context
170
+ { echo "## Spec"; cat spec.md; echo "## Code"; cat src/main.ts; } | \
171
+ claude -p "Does the code match the spec?"
172
+ ```
173
+
174
+ ### Structured output
175
+
176
+ ```bash
177
+ # JSON output with full metadata (tool calls, token usage)
178
+ claude -p --output-format json "List all API endpoints"
179
+
180
+ # Streaming JSONL (real-time events)
181
+ claude -p --output-format stream-json "Analyze the codebase"
182
+
183
+ # Schema-enforced structured output
184
+ claude -p --output-format json --json-schema '{"type":"object","properties":{"findings":{"type":"array"},"summary":{"type":"string"}}}' \
185
+ "Review this code and return findings"
186
+ ```
187
+
188
+ ### System prompt customization
189
+
190
+ ```bash
191
+ # Append instructions (keeps default Claude Code capabilities)
192
+ claude -p --append-system-prompt "You are a security auditor. Focus only on vulnerabilities." \
193
+ "Review src/auth.ts"
194
+
195
+ # Full override (removes all defaults; use when you need a clean slate)
196
+ claude -p --system-prompt "You are a JSON-only responder. Return only valid JSON." \
197
+ --output-format json "List all functions in this file"
198
+ ```
199
+
200
+ ## MCP Server Integration
201
+
202
+ Claude Code supports MCP (Model Context Protocol) servers for extended capabilities.
203
+
204
+ ### Adding MCP servers
205
+
206
+ ```bash
207
+ # stdio transport
208
+ claude mcp add github -- npx -y @modelcontextprotocol/server-github
209
+
210
+ # HTTP transport
211
+ claude mcp add api --transport http https://api.example.com
212
+
213
+ # With scope (project vs user)
214
+ claude mcp add myserver -s project -- node server.js
215
+
216
+ # With environment variables
217
+ claude mcp add myserver -e API_KEY=xxx -- node server.js
218
+ ```
219
+
220
+ ### Using MCP tools in automation
221
+
222
+ ```bash
223
+ # Allow specific MCP tools in print mode
224
+ claude -p --allowedTools "mcp__github__create_pull_request" "mcp__github__list_issues" \
225
+ "Create a PR for the current changes"
226
+ ```
227
+
228
+ ### Claude Code as MCP server
229
+
230
+ ```bash
231
+ # Expose Claude Code as an MCP server for other tools
232
+ claude mcp serve
233
+ ```
234
+
235
+ **Tool Search (lazy loading):** Since early 2026, Claude Code uses Tool Search for MCP tools by default, loading tool schemas on demand rather than all at once. This reduces context usage by ~95%.
236
+
237
+ ## Built-in Slash Commands
238
+
239
+ | Command | Description |
240
+ |---------|-------------|
241
+ | `/model` | Switch model |
242
+ | `/cost` | Show token usage and cost |
243
+ | `/clear` | Clear conversation context |
244
+ | `/compact` | Compress conversation to save tokens |
245
+ | `/help` | Display available commands |
246
+ | `/review` | Review current changes |
247
+ | `/debug` | Debug a failing test or error |
248
+ | `/effort` | Set reasoning effort level |
249
+
250
+ ## Wazir Integration Patterns
251
+
252
+ ### Secondary Review (used by wz:reviewer)
253
+
254
+ ```bash
255
+ CLAUDE_MODEL=$(jq -r '.multi_tool.claude.model // empty' .wazir/state/config.json 2>/dev/null)
256
+ CLAUDE_MODEL=${CLAUDE_MODEL:-sonnet}
257
+
258
+ # Review uncommitted changes
259
+ git diff | claude -p --model "$CLAUDE_MODEL" \
260
+ --allowedTools "Read" "Grep" "Glob" \
261
+ "Review this diff against these acceptance criteria: <criteria>" \
262
+ 2>&1 | tee .wazir/runs/latest/reviews/claude-review.md
263
+
264
+ # Review a spec or design artifact
265
+ cat artifact.md | claude -p --model "$CLAUDE_MODEL" \
266
+ "Review this spec against these criteria: <criteria>" \
267
+ 2>&1 | tee .wazir/runs/latest/reviews/claude-review.md
268
+ ```
269
+
270
+ ### Structured Review Output
271
+
272
+ ```bash
273
+ claude -p --model "$CLAUDE_MODEL" --output-format json \
274
+ --json-schema '{"type":"object","properties":{"findings":{"type":"array","items":{"type":"object","properties":{"severity":{"type":"string"},"description":{"type":"string"},"location":{"type":"string"}}}},"summary":{"type":"string"}}}' \
275
+ "Review the changes in src/auth/" \
276
+ > .wazir/runs/latest/reviews/claude-review.json
277
+ ```
278
+
279
+ ### Parallel Execution as External Validator
280
+
281
+ ```bash
282
+ # Run Claude review in background
283
+ git diff main | claude -p --model haiku \
284
+ --allowedTools "Read" "Grep" \
285
+ "Quick security scan of this diff" \
286
+ > .wazir/runs/latest/reviews/claude-security.md 2>&1 &
287
+ ```
288
+
289
+ ### Multi-Turn Programmatic Sessions
290
+
291
+ For complex automation requiring multiple turns:
292
+
293
+ ```bash
294
+ # Limit turns to prevent runaway sessions
295
+ claude -p --max-turns 5 --allowedTools "Read" "Grep" "Bash(npm test)" \
296
+ "Run the tests, analyze any failures, and suggest fixes"
297
+ ```
298
+
299
+ ## Error Handling
300
+
301
+ | Error | Handling |
302
+ |-------|----------|
303
+ | **Non-zero exit** (auth/rate-limit/transport) | Log full stderr, mark pass as `claude-unavailable`, use self-review only. Next pass re-attempts. |
304
+ | **Timeout** | Wrap with `timeout 120 claude -p ...`. Treat timeout as `claude-unavailable`. |
305
+ | **Model overloaded** | `--fallback-model haiku` auto-switches. Without it, retry after backoff. |
306
+ | **Permission denied** | Add required tools to `--allowedTools` or use `--dangerously-skip-permissions` in CI. |
307
+ | **Max turns reached** | Increase `--max-turns` or break the task into smaller prompts. |
308
+
309
+ ## Configuration
310
+
311
+ Claude Code reads configuration from (highest to lowest precedence):
312
+ 1. CLI flags (`--model`, `--allowedTools`, etc.)
313
+ 2. Environment variables (`CLAUDE_MODEL`, `ANTHROPIC_API_KEY`)
314
+ 3. `.claude/settings.json` (project-level)
315
+ 4. `~/.claude/settings.json` (user-level)
316
+ 5. `.claude/rules/` directory (modular rule files)
317
+ 6. `CLAUDE.md` (project instructions)
318
+ 7. Auto Memory (persisted learnings)
319
+
320
+ Key config fields in `settings.json`: `model`, `maxTokens`, `permissions.allowedTools`, `permissions.deny`, `env`.