knowzcode 0.3.7 → 0.4.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 (79) hide show
  1. package/.claude-plugin/marketplace.json +61 -61
  2. package/.claude-plugin/plugin.json +8 -8
  3. package/LICENSE +121 -121
  4. package/README.md +354 -320
  5. package/agents/analyst.md +114 -114
  6. package/agents/architect.md +200 -200
  7. package/agents/builder.md +104 -104
  8. package/agents/closer.md +177 -177
  9. package/agents/context-scout.md +54 -54
  10. package/agents/knowledge-migrator.md +349 -349
  11. package/agents/knowz-scout.md +83 -83
  12. package/agents/knowz-scribe.md +180 -180
  13. package/agents/microfix-specialist.md +135 -135
  14. package/agents/project-advisor.md +111 -111
  15. package/agents/reviewer.md +172 -172
  16. package/agents/security-officer.md +194 -194
  17. package/agents/test-advisor.md +162 -162
  18. package/agents/update-coordinator.md +394 -394
  19. package/bin/knowzcode.mjs +1199 -956
  20. package/commands/audit.md +328 -328
  21. package/commands/connect-mcp.md +549 -549
  22. package/commands/fix.md +107 -107
  23. package/commands/init.md +500 -439
  24. package/commands/learn.md +332 -332
  25. package/commands/plan.md +272 -272
  26. package/commands/register.md +733 -733
  27. package/commands/status.md +309 -309
  28. package/commands/telemetry-setup.md +368 -368
  29. package/commands/telemetry.md +188 -188
  30. package/commands/work.md +1204 -1202
  31. package/knowzcode/automation_manifest.md +59 -59
  32. package/knowzcode/claude_code_execution.md +431 -420
  33. package/knowzcode/copilot_execution.md +231 -231
  34. package/knowzcode/enterprise/compliance_manifest.md +137 -137
  35. package/knowzcode/enterprise/compliance_status.md +30 -30
  36. package/knowzcode/enterprise/guidelines/code-quality.md +67 -67
  37. package/knowzcode/enterprise/guidelines/security.md +355 -355
  38. package/knowzcode/enterprise/templates/guideline-template.md +55 -55
  39. package/knowzcode/gitignore.template +13 -13
  40. package/knowzcode/knowzcode_architecture.md +51 -51
  41. package/knowzcode/knowzcode_log.md +142 -142
  42. package/knowzcode/knowzcode_loop.md +596 -596
  43. package/knowzcode/knowzcode_orchestration.md +66 -66
  44. package/knowzcode/knowzcode_project.md +48 -48
  45. package/knowzcode/knowzcode_tracker.md +40 -40
  46. package/knowzcode/knowzcode_vaults.md +257 -257
  47. package/knowzcode/mcp_config.md +191 -191
  48. package/knowzcode/planning/Readme.md +6 -6
  49. package/knowzcode/platform_adapters.md +1260 -1047
  50. package/knowzcode/prompts/Execute_Micro_Fix.md +57 -57
  51. package/knowzcode/prompts/Investigate_Codebase.md +227 -227
  52. package/knowzcode/prompts/Migrate_Knowledge.md +301 -301
  53. package/knowzcode/prompts/Refactor_Node.md +72 -72
  54. package/knowzcode/prompts/Spec_Verification_Checkpoint.md +59 -59
  55. package/knowzcode/prompts/[LOOP_1A]__Propose_Change_Set.md +52 -52
  56. package/knowzcode/prompts/[LOOP_1B]__Draft_Specs.md +75 -75
  57. package/knowzcode/prompts/[LOOP_2A]__Implement_Change_Set.md +55 -55
  58. package/knowzcode/prompts/[LOOP_2B]__Verify_Implementation.md +72 -72
  59. package/knowzcode/prompts/[LOOP_3]__Finalize_And_Commit.md +67 -67
  60. package/knowzcode/specs/Readme.md +10 -10
  61. package/knowzcode/telemetry_config.md +89 -89
  62. package/knowzcode/user_preferences.md +120 -120
  63. package/package.json +53 -53
  64. package/skills/alias-resolver.json +1 -1
  65. package/skills/architecture-diff.json +1 -1
  66. package/skills/check-installation-status.json +1 -1
  67. package/skills/continue.md +126 -126
  68. package/skills/environment-guard.json +1 -1
  69. package/skills/generate-workgroup-id.json +1 -1
  70. package/skills/install-knowzcode.json +1 -1
  71. package/skills/load-core-context.json +1 -1
  72. package/skills/log-entry-builder.json +1 -1
  73. package/skills/spec-quality-check.json +1 -1
  74. package/skills/spec-template.json +1 -1
  75. package/skills/spec-validator.json +1 -1
  76. package/skills/start-work.md +224 -224
  77. package/skills/tracker-scan.json +1 -1
  78. package/skills/tracker-update.json +1 -1
  79. package/skills/validate-installation.json +1 -1
@@ -1,420 +1,431 @@
1
- # Claude Code Execution Model
2
-
3
- **Purpose:** Defines Agent Teams behavior and inter-agent communication patterns specific to Claude Code. This file supplements the platform-agnostic agent definitions in `agents/`.
4
-
5
- Agents on other platforms should ignore this file — see `knowzcode/platform_adapters.md` for platform-specific execution instructions.
6
-
7
- ---
8
-
9
- ## Agent Teams Overview
10
-
11
- Agent Teams is an **experimental** Claude Code feature for multi-agent coordination. It requires the environment variable `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` to be set in the Claude Code environment.
12
-
13
- > **Status:** Experimental. The API may change in future releases.
14
-
15
- ### Prerequisites
16
-
17
- - Claude Code with Agent Teams support
18
- - Environment variable: `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` (set in `~/.claude/settings.json` env block or shell environment)
19
- - Commands detect Agent Teams at runtime via try-then-fallback: they attempt `TeamCreate()` and fall back to Subagent Delegation if it fails. No manual detection logic is needed in command files.
20
-
21
- > **Windows note:** Split-pane mode (`tmux`) is not supported on Windows Terminal. Agent Teams automatically uses `in-process` mode on Windows (the default `auto` mode handles this correctly). No manual configuration is needed.
22
-
23
- ### Architecture
24
-
25
- Agent Teams uses a **team lead + teammates** model:
26
-
27
- - **Team Lead**: Coordinates workflow, delegates tasks, never codes directly (delegate mode)
28
- - **Teammates**: Specialized agents that receive tasks and report results
29
- - **Shared Task List**: Structured work tracking with dependencies
30
- - **Mailbox**: Ad-hoc inter-agent messaging for coordination
31
-
32
- ### Task Mechanics
33
-
34
- Tasks follow a lifecycle: `pending` -> `in_progress` -> `completed`
35
-
36
- - Tasks can have **dependencies** (task B blocked by task A)
37
- - Tasks can have **blockers** (external impediments)
38
- - The lead creates tasks and assigns to teammates
39
- - Teammates update status and report results
40
-
41
- ### Communication Primitives
42
-
43
- Agent Teams provides two communication mechanisms:
44
-
45
- | Mechanism | Purpose | When to Use |
46
- |-----------|---------|-------------|
47
- | **Task List** | Structured work with status, dependencies, blockers | Phase delegation, quality gates, handoffs |
48
- | **Mailbox** | Ad-hoc coordination between teammates | Clarifications, gap details, scope questions |
49
-
50
- ### Hooks
51
-
52
- Agent Teams supports event-driven coordination via hooks:
53
-
54
- - **`TeammateIdle`**: Fires when a teammate finishes its current task — can auto-assign next work
55
- - **`TaskCompleted`**: Fires when a task is marked complete — can trigger dependent tasks
56
-
57
- ### Plan Approval Handshake (Agent Teams Only)
58
-
59
- When the lead enables plan approval in the spawn prompt (or a teammate has `permissionMode: plan`):
60
-
61
- 1. **Teammate** presents their plan by calling `ExitPlanMode`
62
- 2. **Lead** receives a `plan_approval_request` message with a `request_id`
63
- 3. **Lead** reviews the plan and responds with `SendMessage` type `plan_approval_response`:
64
- - `approve: true` → teammate exits plan mode and proceeds with execution
65
- - `approve: false` + `content: "feedback"` → teammate revises their plan and re-presents
66
- 4. **Teammate** receives the response and acts accordingly
67
-
68
- The lead MUST respond to every `plan_approval_request` — ignoring it will leave the teammate blocked indefinitely.
69
-
70
- #### Autonomous Mode and Plan Approval
71
-
72
- When `AUTONOMOUS_MODE = true`, the lead auto-approves all `plan_approval_request` messages immediately. The plan content is still logged for transparency, but no pause for review occurs.
73
-
74
- **Exception**: Plans that touch >10 files or propose disabling security measures → pause for manual review even in autonomous mode.
75
-
76
- ### Handling Shutdown Requests
77
-
78
- When you receive a `shutdown_request` from the lead:
79
-
80
- 1. Complete or save any in-progress work (update the WorkGroup file if needed)
81
- 2. Mark your current task as `completed` (or leave as `in_progress` if unfinished)
82
- 3. Respond with `SendMessage` type `shutdown_response`:
83
- - `approve: true` → confirms shutdown, your process will terminate
84
- - `approve: false` + `content: "reason"` → if you are mid-critical-operation (e.g., "Completing task, will be ready in a moment")
85
- 4. After approving shutdown, do not take any further actions
86
-
87
- ### Limitations
88
-
89
- - Experimental feature — API may change
90
- - Requires `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` env var
91
- - Not available in all Claude Code environments
92
- - No nested teams — teammates never create teams themselves
93
-
94
- ---
95
-
96
- ## Team Lifecycle
97
-
98
- The team lead manages the full lifecycle of a team. Teammates never create or clean up teams.
99
-
100
- ### Creation
101
-
102
- At the start of a workflow (`/kc:work`, `/kc:plan`, `/kc:audit`), the lead creates a team before spawning any teammates:
103
-
104
- - **`/kc:work`**: Team name `kc-{wgid}` (matches the WorkGroup ID)
105
- - **`/kc:plan`**: Team name `kc-plan-{slug}` (from the research topic)
106
- - **`/kc:audit`**: Team name `kc-audit-{timestamp}`
107
-
108
- Creating a team establishes:
109
- - A shared task list for structured work tracking
110
- - A team config that teammates can read to discover each other
111
- - A coordination namespace for mailbox messaging
112
-
113
- ### Cleanup
114
-
115
- After the workflow completes (or if cancelled), the lead:
116
- 1. Shuts down all active teammates — waits for each to confirm shutdown
117
- 2. Deletes the team — removes team config and task list
118
-
119
- No teammates or team resources should remain after a workflow ends.
120
-
121
- ---
122
-
123
- ## KnowzCode Agent Teams Behavior
124
-
125
- When running as teammates in a Claude Code Agent Teams workflow, all agents follow these conventions:
126
-
127
- ### Task Lifecycle
128
- - Your spawn prompt or DM includes your assigned task ID (e.g., `**Your Task**: #5`)
129
- - Claim immediately: `TaskUpdate(taskId, status: "in_progress")`
130
- - Read context files listed in task description independently (do not duplicate context across agents)
131
- - Report progress by updating task status
132
- - When complete: `TaskUpdate(taskId, status: "completed")` with a summary
133
- - If blocked: keep task in_progress with blocker description
134
- - Do NOT create new tasks for work already assigned to you — use the provided task ID
135
-
136
- ### Plan Approval (architect, builder only)
137
- - **Architect**: Present spec drafts as a plan for lead review before finalizing. Wait for lead approval before writing final specs
138
- - **Builder**: Present implementation plan (approach, file changes, test strategy) for lead review before coding. Wait for lead approval before writing code
139
-
140
- ### Inter-Agent Communication
141
-
142
- > **Note:** In `/kc:work` Parallel Teams mode, teammates coexist within stages: scouts run alongside analysts, builders and reviewers persist through the gap loop. The messaging patterns below are actively used. In Sequential Teams mode (`--sequential`), teammates are spawned one at a time — inter-phase communication goes through the lead via WorkGroup files.
143
-
144
- Use mailbox messaging for coordination between teammates:
145
-
146
- | From | To | When |
147
- |------|-----|------|
148
- | scout | all | Initial context/vault findings (broadcast) |
149
- | scanner | all | Codebase scan findings — affected files, test patterns (broadcast) |
150
- | analyst | architect | `[PRELIMINARY]` NodeID findings during Stage 0 (max 3 DMs), scope clarifications, NodeID overlap with existing specs |
151
- | architect | analyst | Scope adjustments needed |
152
- | architect | builder | Design guidance and spec intent responses |
153
- | builder | analyst | Affected files and dependency questions |
154
- | builder | architect | Spec clarification requests |
155
- | builder | builder | Shared interface changes, dependency coordination |
156
- | reviewer | lead | Gap reports per partition (structured format via task summaries) |
157
- | lead | builder | Gap fix assignments with context (task creation + DM) |
158
- | lead | reviewer | Re-audit requests after gap fixes (task creation + DM) |
159
- | lead | knowz-scribe | Capture messages at quality gates (`"Capture Phase 1A: {wgid}"`, etc.) |
160
- | closer | knowz-scribe | Phase 3 learning capture (`"Capture Phase 3: {wgid}"`) |
161
- | closer | analyst | Change scope for log entry accuracy |
162
- | closer | architect | Spec format and legacy migration |
163
- | security-officer | lead | Structured finding reports at gates (with `[SECURITY-BLOCK]` for CRITICAL/HIGH) |
164
- | security-officer | architect | Security VERIFY criteria needs during Phase 1B |
165
- | security-officer | builder | Security guidance for sensitive partitions (max 2 DMs per builder) |
166
- | security-officer | test-advisor | Cross-cutting: test gaps in security-critical paths (max 2 inter-specialist DMs) |
167
- | test-advisor | lead | Test quality reports at gates |
168
- | test-advisor | architect | VERIFY criteria testability concerns during Phase 1B |
169
- | test-advisor | builder | Specific test improvement feedback (max 2 DMs per builder) |
170
- | test-advisor | security-officer | Cross-cutting: security scenarios needing test coverage (max 2 inter-specialist DMs) |
171
- | project-advisor | lead | Backlog context (Stage 0) and proposals (late Stage 2) |
172
- | project-advisor | knowz-scribe | Idea captures for vault storage |
173
-
174
- ### Gap Communication Flow
175
- In Parallel Teams mode, gap communication goes through the lead:
176
- 1. Reviewer reports gaps in task completion summary (structured format)
177
- 2. Lead creates fix task and pre-assigns to builder:
178
- `TaskCreate("Fix gaps: NodeID-X")` → `TaskUpdate(taskId, owner: "builder-N")`
179
- 3. Lead sends DM to builder with task ID and gap details:
180
- `"**New Task**: #{fix-task-id} — Fix gaps: NodeID-X. {file path, VERIFY criterion, expected vs actual}"`
181
- 4. Builder claims fix task, fixes gaps, marks fix task complete
182
- 5. Lead creates re-audit task and pre-assigns to reviewer:
183
- `TaskCreate("Re-audit: NodeID-X")` → `TaskUpdate(taskId, owner: "reviewer-N")`
184
- 6. Lead sends DM to reviewer with task ID:
185
- `"**New Task**: #{reaudit-task-id} — Re-audit: NodeID-X. {gap list}"`
186
-
187
- In Sequential Teams mode, the lead spawns a new builder with gap context, then a new reviewer for re-audit.
188
-
189
- ---
190
-
191
- ## Parallel Teams Orchestration
192
-
193
- This section defines conventions specific to Parallel Teams mode in `/kc:work`. For the full orchestration flow, see `commands/work.md`.
194
-
195
- ### Lead Responsibilities in Parallel Mode
196
-
197
- - Lead is the **sole WorkGroup file writer** — agents report via task completion summaries, lead consolidates
198
- - Lead manages all agent lifecycles (spawn, shutdown) — agents never self-shutdown
199
- - Lead creates the task graph progressively (not all upfront) based on dependency map
200
- - Lead mediates gap flow: reviewer → lead → builder (not direct reviewer → builder for actionable gaps)
201
- - Lead uses DM messages alongside task creation to provide context and coordinate
202
-
203
- ### Task Assignment Protocol
204
-
205
- When creating a task for a specific agent, the lead MUST thread the task ID:
206
- 1. `TaskCreate(subject, description)` capture returned `{task-id}`
207
- 2. `TaskUpdate(taskId: "{task-id}", owner: "{agent-name}")` — pre-assign
208
- 3. Include the task ID in the agent's context:
209
- - **Spawn prompt** (new agent): Add `**Your Task**: #{task-id}` line
210
- - **DM** (existing agent): Include `**New Task**: #{task-id} — "{subject}"`
211
-
212
- Agents must NOT create new tasks for work already assigned to them via task ID.
213
-
214
- ### Agent Lifecycle
215
-
216
- | Agent | Spawn At | Shut Down At | Purpose While Alive |
217
- |-------|----------|-------------|---------------------|
218
- | context-scout-specs | Stage 0 | After Gate #2 | Spec context lookups |
219
- | context-scout-workgroups | Stage 0 | After Gate #2 | WorkGroup history lookups |
220
- | context-scout-backlog | Stage 0 | After Gate #2 | Tracker/log/architecture lookups |
221
- | scanner-direct | Stage 0 (conditional) | After Stage 1 (analyst done) | Source code scanning — broadcasts affected files and code paths |
222
- | scanner-tests | Stage 0 (conditional) | After Stage 1 (analyst done) | Test discovery — broadcasts test patterns and coverage shape |
223
- | knowz-scout | Stage 0 | After Phase 3 capture | Vault queries (read-only) throughout workflow |
224
- | knowz-scribe | Stage 0 | After Phase 3 capture | Vault writes receives capture messages, handles all `create_knowledge` calls |
225
- | analyst | Stage 0 | Early Stage 2 | Scope questions from builders |
226
- | architect | Stage 0 (pre-load + speculative research) | After Gate #3 | Pre-load speculative research on `[PRELIMINARY]` NodeIDs → spec drafting (+ parallel coordination for 3+ NodeIDs) → design guidance for builders |
227
- | spec-drafter(s) | Stage 1 (Path B, 3+ NodeIDs) | After architect consistency review | Draft specs for assigned NodeID partition |
228
- | builder(s) | Stage 2 | After Gate #3 | Implementation + gap fixes (persistent through gap loop) |
229
- | reviewer(s) | Stage 2 (1 per builder partition) | After Gate #3 | Incremental audit per partition (persistent through gap loop) |
230
- | security-officer | Stage 0 (Group C) | After Gate #3 | Threat modeling + vulnerability scanning (officer can block gates) |
231
- | test-advisor | Stage 0 (Group C) | After Gate #3 | TDD enforcement + test quality review (advisorinformational) |
232
- | project-advisor | Stage 0 (Group C) | Mid-Stage 2 | Backlog curation + idea capture (advisor — informational) |
233
- | closer | Stage 3 | End of workflow | Finalization |
234
-
235
- ### Task Dependency Usage
236
-
237
- All tasks in a workflow use `addBlockedBy` to express the dependency chain:
238
- 1. **Visibility**: `TaskList` shows the workflow graph at any point
239
- 2. **Future automation**: Hooks (`TeammateIdle`, `TaskCompleted`) can auto-assign when dependencies resolve
240
- 3. **Progressive creation**: Lead creates tasks stage-by-stage, not all upfront
241
-
242
- ### Task Graph Patterns
243
-
244
- - Stage 0 tasks: scout + scanner + knowz-scribe + analysis tasks (no deps)
245
- - Stage 1 tasks: spec drafting tasks (blocked by gate approval — lead creates after gate). Path B (3+ NodeIDs): spec-drafter tasks + architect consistency review task
246
- - Stage 2 tasks: implementation subtasks (blocked by spec approval), audit subtasks (blocked by implementation)
247
- - Stage 3 tasks: finalization (blocked by audit approval)
248
-
249
- ### Orchestration Configuration
250
-
251
- Team sizing defaults are configurable via `knowzcode/knowzcode_orchestration.md`:
252
-
253
- | Parameter | Default | Flag Override | Effect |
254
- |-----------|---------|--------------|--------|
255
- | `max_builders` | 5 | `--max-builders=N` | Cap concurrent builders (1-5) |
256
- | `scout_mode` | full | `--no-scouts` | full (3 scouts), minimal (1 scout), none (lead reads context) |
257
- | `default_specialists` | [] | `--specialists`, `--no-specialists` | Project-level specialist defaults |
258
- | `mcp_agents_enabled` | true | `--no-mcp` | Toggle vault agents (knowz-scout, knowz-scribe) |
259
- | `codebase_scanner_enabled` | true | `--no-scanners` | Toggle codebase scanner agents (scanner-direct, scanner-tests) |
260
- | `parallel_spec_threshold` | 3 | `--no-parallel-specs` | NodeID count threshold for parallel spec drafting (Path B) |
261
-
262
- Precedence: hardcoded defaults → orchestration config → per-invocation flags.
263
-
264
- ### Builder Partitioning Rules
265
-
266
- - No two builders touch the same file
267
- - Analyst dependency map determines partitions
268
- - Max `MAX_BUILDERS` concurrent builders (default 5, configurable in `knowzcode_orchestration.md`)
269
- - If all NodeIDs share files single builder with subtask tracking
270
- - Builder-to-builder messages for interface changes affecting other partitions
271
-
272
- ### Persistent Agent Patterns
273
-
274
- In `/kc:work` Parallel Teams mode, agents persist across sub-phases for efficiency:
275
-
276
- #### Build + Audit Loop
277
- During Stage 2, each builder is paired with a dedicated reviewer for its partition:
278
- - One reviewer per builder partition (e.g., builder-1 reviewer-1, builder-2 reviewer-2)
279
- - Each reviewer audits only the NodeIDs in its paired builder's partition
280
- - Gap loops run independently per partition partition A's gap loop does not block partition B's audit
281
- - If gaps found: lead creates fix task for the partition's builder + re-audit task for the partition's reviewer
282
- - All builders and reviewers stay alive through the entire gap loop shut down only after Gate #3
283
-
284
- This eliminates both cold-start overhead (no respawning) and the sequential bottleneck (no single reviewer processing all partitions).
285
-
286
- #### Architect Consultative Persistence
287
- During Stage 2, the architect persists as a read-only consultative resource:
288
- - Responds to builder DMs about spec intent, interface contracts, and design decisions
289
- - Does NOT write code, modify specs, or create tasks
290
- - Lead notifies architect when builders are spawned architect sends intro message to each builder
291
- - Shut down with builders and reviewers after Gate #3
292
-
293
- #### Discovery Pre-loading + Speculative Research
294
- During Stage 0, the architect pre-loads context and conducts speculative research in parallel with analysis:
295
- - **Pre-load phase**: Architect reads architecture docs, existing specs, project config (3-5 turns)
296
- - **Speculative research phase**: After pre-load, architect receives `[PRELIMINARY]` NodeID messages from the analyst (max 3). For each, it reads affected files, checks spec consolidation, and analyzes interface patterns — all read-only, no spec writing
297
- - When Gate #1 is approved, architect already has context + deep research on flagged NodeIDs specs drafted ~80% faster
298
- - If Gate #1 rejected, architect context and research are still useful for the revised analysis cycle
299
- - If no `[PRELIMINARY]` messages arrive (simple 1-NodeID change), architect finishes standard pre-load and waits
300
-
301
- #### Parallel Spec Drafting (Path B — 3+ NodeIDs)
302
- When the approved Change Set contains 3+ NodeIDs (configurable via `PARALLEL_SPEC_THRESHOLD`), spec drafting is parallelized:
303
- - Architect proposes NodeID partitions (1-2 per partition, max 3 partitions)
304
- - Lead spawns spec-drafter agents (using `architect` agent definition) for each partition
305
- - Each drafter receives: its NodeIDs, architect's speculative research findings, cross-NodeID constraints
306
- - After all drafters complete, architect runs a consistency review: cross-spec alignment, naming, VERIFY coverage
307
- - Spec-drafters shut down after consistency review, before Gate #2
308
- - For 1-2 NodeIDs (Path A), architect drafts all specs alone (current behavior, zero overhead)
309
-
310
- #### Specialist Agents (Group C — opt-in via `--specialists`)
311
-
312
- When specialists are enabled, three additional agents spawn at Stage 0 alongside Groups A and B:
313
-
314
- ```
315
- Group A (always): 3 context-scouts + analyst + architect (5 agents)
316
- Group A (if scanners): + scanner-direct + scanner-tests (+2 agents)
317
- Group B (if MCP): knowz-scout + knowz-scribe (2 agents)
318
- Group C (if --specialists): security-officer + test-advisor + project-advisor (3 agents)
319
- ```
320
-
321
- Max Stage 0 concurrent: 5-12 agents depending on orchestration config (scouts, scanners, MCP agents, specialists). Scouts shut down after Gate #2, scanners shut down after Stage 1, so Stage 2 peak is manageable.
322
-
323
- ##### Officer vs Advisor Authority
324
-
325
- | Role | Authority | Gate Impact |
326
- |------|-----------|-------------|
327
- | **Officer** (security-officer) | CRITICAL/HIGH findings block gates | `[SECURITY-BLOCK]` tag pauses autonomous mode |
328
- | **Advisor** (test-advisor, project-advisor) | Informational only | Findings included in gate reports, do not block |
329
-
330
- ##### Direct DM Protocol
331
-
332
- Specialists communicate directly with builders, architect, and each other — no lead bottleneck relay:
333
-
334
- - **security-officer → architect**: Security VERIFY criteria needs during Phase 1B
335
- - **security-officer → builder-N**: Security guidance for sensitive partitions (max 2 DMs per builder)
336
- - **test-advisorarchitect**: VERIFY criteria testability concerns during Phase 1B
337
- - **test-advisor → builder-N**: Specific test improvement feedback (max 2 DMs per builder)
338
- - **project-advisor → knowz-scribe**: Idea captures for vault storage
339
- - **security-officer test-advisor**: Cross-cutting test gaps in security paths (max 2 inter-specialist DMs total)
340
-
341
- ##### Communication Discipline
342
-
343
- - Max 2 DMs to any individual builder from each specialist
344
- - Max 2 inter-specialist DMs per workflow
345
- - Consolidate findings no per-file noise
346
- - project-advisor does NOT DM builders or other specialists (observes via task list only)
347
-
348
- ---
349
-
350
- ## Teammate Initialization Protocol
351
-
352
- ### Agent Teams Mode (spawned as a teammate)
353
-
354
- When spawned as a teammate in an Agent Teams workflow, follow this sequence:
355
-
356
- 1. Read your agent definition file (referenced in your spawn prompt)
357
- 2. Claim your assigned task: `TaskUpdate(taskId: "{task-id from spawn prompt}", status: "in_progress")`
358
- 3. Read this file (`knowzcode/claude_code_execution.md`) for team conventions
359
- 4. Read the WorkGroup file for current state, Change Set, and context
360
- 5. Read context files listed in your task description
361
- 6. Begin your phase work as defined by your role
362
- 7. Update the WorkGroup file with results — prefix all todo entries with `KnowzCode:`
363
- 8. Mark your task as complete with a summary of what was delivered
364
-
365
- ### Subagent Mode (spawned via Task())
366
-
367
- When spawned as a custom subagent type (e.g. `subagent_type: "analyst"`), your agent definition from `agents/*.md` is **auto-loaded as your system prompt**. This means:
368
-
369
- - Step 1 above is already done — your role definition, tools, and constraints are pre-loaded
370
- - Your `tools`, `model`, `permissionMode`, and `maxTurns` from the YAML frontmatter are enforced automatically
371
- - You only need to read the task-specific context provided in the spawn prompt (WorkGroup file, specs, context files)
372
- - Begin your phase work directly
373
-
374
- ### For Both Modes
375
-
376
- If you encounter a blocker, keep the task in `in_progress` status with a description of what is blocking you. Do not mark the task as complete until the work is done.
377
-
378
- ---
379
-
380
- ## Command References
381
-
382
- Agents may reference these Claude Code commands as escalation paths:
383
-
384
- | Command | Used By | Context |
385
- |---------|---------|---------|
386
- | `/kc:work` | microfix-specialist | Redirect when fix exceeds scope gate |
387
- | `/kc:audit security` | reviewer | Full security audit mode |
388
- | `/kc:audit spec` | knowledge-migrator | Post-migration validation |
389
-
390
- On other platforms, these commands translate to running the corresponding phase prompts manually.
391
-
392
- ---
393
-
394
- ## Verification & Troubleshooting
395
-
396
- ### How to verify Agent Teams is working
397
-
398
- 1. Run `/kc:status` check the Agent Teams section for "Enabled" status and agent definitions
399
- 2. Run `/kc:work` confirm a mode announcement appears before Phase 1A (either "Agent Teams" or "Subagent Delegation")
400
- 3. In-process mode: press Shift+Down to see spawned teammates in the panel
401
- 4. Check the WorkGroup file should show phase transitions with timestamps in the Phase History table
402
-
403
- ### Common issues
404
-
405
- | Symptom | Cause | Fix |
406
- |---------|-------|-----|
407
- | No mode announcement | Command didn't run setup step | Verify commands are updated (Step 2 should announce mode) |
408
- | "Subagent Delegation" when expecting Agent Teams | Env var not set or Claude Code not restarted | Add `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` to settings.json `env` block. **Restart Claude Code** — env vars are only loaded on startup. |
409
- | Agents seem generic / no specialization | Agent definitions not loaded | Check `agents/` directory exists with `.md` files for each role |
410
- | No quality gates appearing | Command instructions not followed | Re-run `/kc:work` with an explicit goal description |
411
- | Teammates not visible in panel | Using tmux mode on Windows | Windows uses in-process mode — teammates won't appear in a split pane |
412
-
413
- ### Verifying after a workflow
414
-
415
- Check the WorkGroup file at `knowzcode/workgroups/{wgid}.md`:
416
-
417
- - **Phase History table** should show all phases with timestamps and statuses
418
- - **Change Set** should be populated (Phase 1A output) with NodeIDs and descriptions
419
- - **Todos** should all start with the `KnowzCode:` prefix
420
- - **Status** should show "Closed" after Phase 3 completes
1
+ # Claude Code Execution Model
2
+
3
+ **Purpose:** Defines Agent Teams behavior and inter-agent communication patterns specific to Claude Code. This file supplements the platform-agnostic agent definitions in `agents/`.
4
+
5
+ Agents on other platforms should ignore this file — see `knowzcode/platform_adapters.md` for platform-specific execution instructions.
6
+
7
+ ---
8
+
9
+ ## Agent Teams Overview
10
+
11
+ Agent Teams is an **experimental** Claude Code feature for multi-agent coordination. It requires the environment variable `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` to be set in the Claude Code environment.
12
+
13
+ > **Status:** Experimental. The API may change in future releases.
14
+
15
+ ### Prerequisites
16
+
17
+ - Claude Code with Agent Teams support
18
+ - Environment variable: `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` (set in `~/.claude/settings.json` env block or shell environment)
19
+ - Commands detect Agent Teams at runtime via try-then-fallback: they attempt `TeamCreate()` and fall back to Subagent Delegation if it fails. No manual detection logic is needed in command files.
20
+
21
+ > **Windows note:** Split-pane mode (`tmux`) is not supported on Windows Terminal. Agent Teams automatically uses `in-process` mode on Windows (the default `auto` mode handles this correctly). No manual configuration is needed.
22
+
23
+ ### Architecture
24
+
25
+ Agent Teams uses a **team lead + teammates** model:
26
+
27
+ - **Team Lead**: Coordinates workflow, delegates tasks, never codes directly (delegate mode)
28
+ - **Teammates**: Specialized agents that receive tasks and report results
29
+ - **Shared Task List**: Structured work tracking with dependencies
30
+ - **Mailbox**: Ad-hoc inter-agent messaging for coordination
31
+
32
+ ### Task Mechanics
33
+
34
+ Tasks follow a lifecycle: `pending` -> `in_progress` -> `completed`
35
+
36
+ - Tasks can have **dependencies** (task B blocked by task A)
37
+ - Tasks can have **blockers** (external impediments)
38
+ - The lead creates tasks and assigns to teammates
39
+ - Teammates update status and report results
40
+
41
+ ### Communication Primitives
42
+
43
+ Agent Teams provides two communication mechanisms:
44
+
45
+ | Mechanism | Purpose | When to Use |
46
+ |-----------|---------|-------------|
47
+ | **Task List** | Structured work with status, dependencies, blockers | Phase delegation, quality gates, handoffs |
48
+ | **Mailbox** | Ad-hoc coordination between teammates | Clarifications, gap details, scope questions |
49
+
50
+ ### Hooks
51
+
52
+ Agent Teams supports event-driven coordination via hooks:
53
+
54
+ - **`TeammateIdle`**: Fires when a teammate finishes its current task — can auto-assign next work
55
+ - **`TaskCompleted`**: Fires when a task is marked complete — can trigger dependent tasks
56
+
57
+ ### Plan Approval Handshake (Agent Teams Only)
58
+
59
+ When the lead enables plan approval in the spawn prompt (or a teammate has `permissionMode: plan`):
60
+
61
+ 1. **Teammate** presents their plan by calling `ExitPlanMode`
62
+ 2. **Lead** receives a `plan_approval_request` message with a `request_id`
63
+ 3. **Lead** reviews the plan and responds with `SendMessage` type `plan_approval_response`:
64
+ - `approve: true` → teammate exits plan mode and proceeds with execution
65
+ - `approve: false` + `content: "feedback"` → teammate revises their plan and re-presents
66
+ 4. **Teammate** receives the response and acts accordingly
67
+
68
+ The lead MUST respond to every `plan_approval_request` — ignoring it will leave the teammate blocked indefinitely.
69
+
70
+ #### Autonomous Mode and Plan Approval
71
+
72
+ When `AUTONOMOUS_MODE = true`, the lead auto-approves all `plan_approval_request` messages immediately. The plan content is still logged for transparency, but no pause for review occurs.
73
+
74
+ **Exception**: Plans that touch >10 files or propose disabling security measures → pause for manual review even in autonomous mode.
75
+
76
+ ### Handling Shutdown Requests
77
+
78
+ When you receive a `shutdown_request` from the lead:
79
+
80
+ 1. Complete or save any in-progress work (update the WorkGroup file if needed)
81
+ 2. Mark your current task as `completed` (or leave as `in_progress` if unfinished)
82
+ 3. Respond with `SendMessage` type `shutdown_response`:
83
+ - `approve: true` → confirms shutdown, your process will terminate
84
+ - `approve: false` + `content: "reason"` → if you are mid-critical-operation (e.g., "Completing task, will be ready in a moment")
85
+ 4. After approving shutdown, do not take any further actions
86
+
87
+ ### Limitations
88
+
89
+ - Experimental feature — API may change
90
+ - Requires `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` env var
91
+ - Not available in all Claude Code environments
92
+ - No nested teams — teammates never create teams themselves
93
+
94
+ ---
95
+
96
+ ## Team Lifecycle
97
+
98
+ The team lead manages the full lifecycle of a team. Teammates never create or clean up teams.
99
+
100
+ ### Creation
101
+
102
+ At the start of a workflow (`/kc:work`, `/kc:plan`, `/kc:audit`), the lead creates a team before spawning any teammates:
103
+
104
+ - **`/kc:work`**: Team name `kc-{wgid}` (matches the WorkGroup ID)
105
+ - **`/kc:plan`**: Team name `kc-plan-{slug}` (from the research topic)
106
+ - **`/kc:audit`**: Team name `kc-audit-{timestamp}`
107
+
108
+ Creating a team establishes:
109
+ - A shared task list for structured work tracking
110
+ - A team config that teammates can read to discover each other
111
+ - A coordination namespace for mailbox messaging
112
+
113
+ ### Cleanup
114
+
115
+ After the workflow completes (or if cancelled), the lead:
116
+ 1. Shuts down all active teammates — waits for each to confirm shutdown
117
+ 2. Deletes the team — removes team config and task list
118
+
119
+ No teammates or team resources should remain after a workflow ends.
120
+
121
+ ---
122
+
123
+ ## KnowzCode Agent Teams Behavior
124
+
125
+ When running as teammates in a Claude Code Agent Teams workflow, all agents follow these conventions:
126
+
127
+ ### Task Lifecycle
128
+ - Your spawn prompt or DM includes your assigned task ID (e.g., `**Your Task**: #5`)
129
+ - Claim immediately: `TaskUpdate(taskId, status: "in_progress")`
130
+ - Read context files listed in task description independently (do not duplicate context across agents)
131
+ - Report progress by updating task status
132
+ - When complete: `TaskUpdate(taskId, status: "completed")` with a summary
133
+ - If blocked: keep task in_progress with blocker description
134
+ - Do NOT create new tasks for work already assigned to you — use the provided task ID
135
+
136
+ ### Plan Approval (architect, builder only)
137
+ - **Architect**: Present spec drafts as a plan for lead review before finalizing. Wait for lead approval before writing final specs
138
+ - **Builder**: Present implementation plan (approach, file changes, test strategy) for lead review before coding. Wait for lead approval before writing code
139
+
140
+ ### Inter-Agent Communication
141
+
142
+ > **Note:** In `/kc:work` Parallel Teams mode, teammates coexist within stages: scouts run alongside analysts, builders and reviewers persist through the gap loop. The messaging patterns below are actively used. In Sequential Teams mode (`--sequential`), teammates are spawned one at a time — inter-phase communication goes through the lead via WorkGroup files.
143
+
144
+ Use mailbox messaging for coordination between teammates:
145
+
146
+ | From | To | When |
147
+ |------|-----|------|
148
+ | scout | all | Initial context/vault findings (broadcast) |
149
+ | scanner | all | Codebase scan findings — affected files, test patterns (broadcast) |
150
+ | analyst | architect | `[PRELIMINARY]` NodeID findings during Stage 0 (max 3 DMs), scope clarifications, NodeID overlap with existing specs |
151
+ | architect | analyst | Scope adjustments needed |
152
+ | architect | builder | Design guidance and spec intent responses |
153
+ | builder | analyst | Affected files and dependency questions |
154
+ | builder | architect | Spec clarification requests |
155
+ | builder | builder | Shared interface changes, dependency coordination |
156
+ | reviewer | lead | Gap reports per partition (structured format via task summaries) |
157
+ | lead | builder | Gap fix assignments with context (task creation + DM) |
158
+ | lead | reviewer | Re-audit requests after gap fixes (task creation + DM) |
159
+ | lead | knowz-scribe | Capture messages at quality gates (`"Capture Phase 1A: {wgid}"`, etc.) |
160
+ | closer | knowz-scribe | Phase 3 learning capture (`"Capture Phase 3: {wgid}"`) |
161
+ | closer | analyst | Change scope for log entry accuracy |
162
+ | closer | architect | Spec format and legacy migration |
163
+ | security-officer | lead | Structured finding reports at gates (with `[SECURITY-BLOCK]` for CRITICAL/HIGH) |
164
+ | security-officer | architect | Security VERIFY criteria needs during Phase 1B |
165
+ | security-officer | builder | Security guidance for sensitive partitions (max 2 DMs per builder) |
166
+ | security-officer | test-advisor | Cross-cutting: test gaps in security-critical paths (max 2 inter-specialist DMs) |
167
+ | test-advisor | lead | Test quality reports at gates |
168
+ | test-advisor | architect | VERIFY criteria testability concerns during Phase 1B |
169
+ | test-advisor | builder | Specific test improvement feedback (max 2 DMs per builder) |
170
+ | test-advisor | security-officer | Cross-cutting: security scenarios needing test coverage (max 2 inter-specialist DMs) |
171
+ | project-advisor | lead | Backlog context (Stage 0) and proposals (late Stage 2) |
172
+ | project-advisor | knowz-scribe | Idea captures for vault storage |
173
+
174
+ ### Gap Communication Flow
175
+ In Parallel Teams mode, gap communication goes through the lead:
176
+ 1. Reviewer reports gaps in task completion summary (structured format)
177
+ 2. Lead creates fix task and pre-assigns to builder:
178
+ `TaskCreate("Fix gaps: NodeID-X")` → `TaskUpdate(taskId, owner: "builder-N")`
179
+ 3. Lead sends DM to builder with task ID and gap details:
180
+ `"**New Task**: #{fix-task-id} — Fix gaps: NodeID-X. {file path, VERIFY criterion, expected vs actual}"`
181
+ 4. Builder claims fix task, fixes gaps, marks fix task complete
182
+ 5. Lead creates re-audit task and pre-assigns to reviewer:
183
+ `TaskCreate("Re-audit: NodeID-X")` → `TaskUpdate(taskId, owner: "reviewer-N")`
184
+ 6. Lead sends DM to reviewer with task ID:
185
+ `"**New Task**: #{reaudit-task-id} — Re-audit: NodeID-X. {gap list}"`
186
+
187
+ In Sequential Teams mode, the lead spawns a new builder with gap context, then a new reviewer for re-audit.
188
+
189
+ ---
190
+
191
+ ## Parallel Teams Orchestration
192
+
193
+ This section defines conventions specific to Parallel Teams mode in `/kc:work`. For the full orchestration flow, see `commands/work.md`.
194
+
195
+ ### Lead Responsibilities in Parallel Mode
196
+
197
+ - Lead is the **sole WorkGroup file writer** — agents report via task completion summaries, lead consolidates
198
+ - Lead manages all agent lifecycles (spawn, shutdown) — agents never self-shutdown
199
+ - Lead creates the task graph progressively (not all upfront) based on dependency map
200
+ - Lead mediates gap flow: reviewer → lead → builder (not direct reviewer → builder for actionable gaps)
201
+ - Lead uses DM messages alongside task creation to provide context and coordinate
202
+ - Lead owns progress documentation — at every quality gate, the lead creates scribe capture tasks and sends capture messages (e.g., "Capture Phase 1A: {wgid}"). No other agent initiates gate captures. If the scribe is unavailable, the lead ensures the closer is briefed to handle vault writes at Phase 3.
203
+
204
+ ### Task Assignment Protocol
205
+
206
+ When creating a task for a specific agent, the lead MUST thread the task ID:
207
+ 1. `TaskCreate(subject, description)` → capture returned `{task-id}`
208
+ 2. `TaskUpdate(taskId: "{task-id}", owner: "{agent-name}")` pre-assign
209
+ 3. Include the task ID in the agent's context:
210
+ - **Spawn prompt** (new agent): Add `**Your Task**: #{task-id}` line
211
+ - **DM** (existing agent): Include `**New Task**: #{task-id} — "{subject}"`
212
+
213
+ Agents must NOT create new tasks for work already assigned to them via task ID.
214
+
215
+ ### Agent Lifecycle
216
+
217
+ | Agent | Spawn At | Shut Down At | Purpose While Alive |
218
+ |-------|----------|-------------|---------------------|
219
+ | context-scout-specs | Stage 0 | After Gate #2 | Spec context lookups |
220
+ | context-scout-workgroups | Stage 0 | After Gate #2 | WorkGroup history lookups |
221
+ | context-scout-backlog | Stage 0 | After Gate #2 | Tracker/log/architecture lookups |
222
+ | scanner-direct | Stage 0 (conditional) | After Stage 1 (analyst done) | Source code scanning — broadcasts affected files and code paths |
223
+ | scanner-tests | Stage 0 (conditional) | After Stage 1 (analyst done) | Test discovery broadcasts test patterns and coverage shape |
224
+ | knowz-scout | Stage 0 | After Phase 3 capture | Vault queries (read-only) throughout workflow |
225
+ | knowz-scribe | Stage 0 | After Phase 3 capture | Vault writes receives capture messages, handles all `create_knowledge` calls |
226
+ | analyst | Stage 0 | Early Stage 2 | Scope questions from builders |
227
+ | architect | Stage 0 (pre-load + speculative research) | After Gate #3 | Pre-load speculative research on `[PRELIMINARY]` NodeIDs → spec drafting (+ parallel coordination for 3+ NodeIDs) design guidance for builders |
228
+ | spec-drafter(s) | Stage 1 (Path B, 3+ NodeIDs) | After architect consistency review | Draft specs for assigned NodeID partition |
229
+ | builder(s) | Stage 2 | After Gate #3 | Implementation + gap fixes (persistent through gap loop) |
230
+ | reviewer(s) | Stage 2 (1 per builder partition) | After Gate #3 | Incremental audit per partition (persistent through gap loop) |
231
+ | security-officer | Stage 0 (Group C) | After Gate #3 | Threat modeling + vulnerability scanning (officercan block gates) |
232
+ | test-advisor | Stage 0 (Group C) | After Gate #3 | TDD enforcement + test quality review (advisor — informational) |
233
+ | project-advisor | Stage 0 (Group C) | Mid-Stage 2 | Backlog curation + idea capture (advisor — informational) |
234
+ | closer | Stage 3 | End of workflow | Finalization |
235
+
236
+ ### Task Dependency Usage
237
+
238
+ All tasks in a workflow use `addBlockedBy` to express the dependency chain:
239
+ 1. **Visibility**: `TaskList` shows the workflow graph at any point
240
+ 2. **Future automation**: Hooks (`TeammateIdle`, `TaskCompleted`) can auto-assign when dependencies resolve
241
+ 3. **Progressive creation**: Lead creates tasks stage-by-stage, not all upfront
242
+
243
+ ### Task Graph Patterns
244
+
245
+ - Stage 0 tasks: scout + scanner + knowz-scribe + analysis tasks (no deps)
246
+ - Stage 1 tasks: spec drafting tasks (blocked by gate approval — lead creates after gate). Path B (3+ NodeIDs): spec-drafter tasks + architect consistency review task
247
+ - Stage 2 tasks: implementation subtasks (blocked by spec approval), audit subtasks (blocked by implementation)
248
+ - Stage 3 tasks: finalization (blocked by audit approval)
249
+
250
+ ### Orchestration Configuration
251
+
252
+ Team sizing defaults are configurable via `knowzcode/knowzcode_orchestration.md`:
253
+
254
+ | Parameter | Default | Flag Override | Effect |
255
+ |-----------|---------|--------------|--------|
256
+ | `max_builders` | 5 | `--max-builders=N` | Cap concurrent builders (1-5) |
257
+ | `scout_mode` | full | `--no-scouts` | full (3 scouts), minimal (1 scout), none (lead reads context) |
258
+ | `default_specialists` | [] | `--specialists`, `--no-specialists` | Project-level specialist defaults |
259
+ | `mcp_agents_enabled` | true | `--no-mcp` | Toggle vault agents (knowz-scout, knowz-scribe) |
260
+ | `codebase_scanner_enabled` | true | `--no-scanners` | Toggle codebase scanner agents (scanner-direct, scanner-tests) |
261
+ | `parallel_spec_threshold` | 3 | `--no-parallel-specs` | NodeID count threshold for parallel spec drafting (Path B) |
262
+
263
+ Precedence: hardcoded defaults → orchestration config → per-invocation flags.
264
+
265
+ ### Builder Partitioning Rules
266
+
267
+ - No two builders touch the same file
268
+ - Analyst dependency map determines partitions
269
+ - Max `MAX_BUILDERS` concurrent builders (default 5, configurable in `knowzcode_orchestration.md`)
270
+ - If all NodeIDs share files single builder with subtask tracking
271
+ - Builder-to-builder messages for interface changes affecting other partitions
272
+
273
+ ### Persistent Agent Patterns
274
+
275
+ In `/kc:work` Parallel Teams mode, agents persist across sub-phases for efficiency:
276
+
277
+ #### Build + Audit Loop
278
+ During Stage 2, each builder is paired with a dedicated reviewer for its partition:
279
+ - One reviewer per builder partition (e.g., builder-1 reviewer-1, builder-2 ↔ reviewer-2)
280
+ - Each reviewer audits only the NodeIDs in its paired builder's partition
281
+ - Gap loops run independently per partition partition A's gap loop does not block partition B's audit
282
+ - If gaps found: lead creates fix task for the partition's builder + re-audit task for the partition's reviewer
283
+ - All builders and reviewers stay alive through the entire gap loop — shut down only after Gate #3
284
+
285
+ This eliminates both cold-start overhead (no respawning) and the sequential bottleneck (no single reviewer processing all partitions).
286
+
287
+ #### Architect Consultative Persistence
288
+ During Stage 2, the architect persists as a read-only consultative resource:
289
+ - Responds to builder DMs about spec intent, interface contracts, and design decisions
290
+ - Does NOT write code, modify specs, or create tasks
291
+ - Lead notifies architect when builders are spawned architect sends intro message to each builder
292
+ - Shut down with builders and reviewers after Gate #3
293
+
294
+ #### Discovery Pre-loading + Speculative Research
295
+ During Stage 0, the architect pre-loads context and conducts speculative research in parallel with analysis:
296
+ - **Pre-load phase**: Architect reads architecture docs, existing specs, project config (3-5 turns)
297
+ - **Speculative research phase**: After pre-load, architect receives `[PRELIMINARY]` NodeID messages from the analyst (max 3). For each, it reads affected files, checks spec consolidation, and analyzes interface patterns — all read-only, no spec writing
298
+ - When Gate #1 is approved, architect already has context + deep research on flagged NodeIDs specs drafted ~80% faster
299
+ - If Gate #1 rejected, architect context and research are still useful for the revised analysis cycle
300
+ - If no `[PRELIMINARY]` messages arrive (simple 1-NodeID change), architect finishes standard pre-load and waits
301
+
302
+ #### Parallel Spec Drafting (Path B 3+ NodeIDs)
303
+ When the approved Change Set contains 3+ NodeIDs (configurable via `PARALLEL_SPEC_THRESHOLD`), spec drafting is parallelized:
304
+ - Architect proposes NodeID partitions (1-2 per partition, max 3 partitions)
305
+ - Lead spawns spec-drafter agents (using `architect` agent definition) for each partition
306
+ - Each drafter receives: its NodeIDs, architect's speculative research findings, cross-NodeID constraints
307
+ - After all drafters complete, architect runs a consistency review: cross-spec alignment, naming, VERIFY coverage
308
+ - Spec-drafters shut down after consistency review, before Gate #2
309
+ - For 1-2 NodeIDs (Path A), architect drafts all specs alone (current behavior, zero overhead)
310
+
311
+ #### Specialist Agents (Group C — opt-in via `--specialists`)
312
+
313
+ When specialists are enabled, three additional agents spawn at Stage 0 alongside Groups A and B:
314
+
315
+ ```
316
+ Group A (always): 3 context-scouts + analyst + architect (5 agents)
317
+ Group A (if scanners): + scanner-direct + scanner-tests (+2 agents)
318
+ Group B (if MCP): knowz-scout + knowz-scribe (2 agents)
319
+ Group C (if --specialists): security-officer + test-advisor + project-advisor (3 agents)
320
+ ```
321
+
322
+ Max Stage 0 concurrent: 5-12 agents depending on orchestration config (scouts, scanners, MCP agents, specialists). Scouts shut down after Gate #2, scanners shut down after Stage 1, so Stage 2 peak is manageable.
323
+
324
+ ##### Officer vs Advisor Authority
325
+
326
+ | Role | Authority | Gate Impact |
327
+ |------|-----------|-------------|
328
+ | **Officer** (security-officer) | CRITICAL/HIGH findings block gates | `[SECURITY-BLOCK]` tag pauses autonomous mode |
329
+ | **Advisor** (test-advisor, project-advisor) | Informational only | Findings included in gate reports, do not block |
330
+
331
+ ##### Direct DM Protocol
332
+
333
+ Specialists communicate directly with builders, architect, and each other — no lead bottleneck relay:
334
+
335
+ - **security-officer → architect**: Security VERIFY criteria needs during Phase 1B
336
+ - **security-officerbuilder-N**: Security guidance for sensitive partitions (max 2 DMs per builder)
337
+ - **test-advisor → architect**: VERIFY criteria testability concerns during Phase 1B
338
+ - **test-advisor → builder-N**: Specific test improvement feedback (max 2 DMs per builder)
339
+ - **project-advisor knowz-scribe**: Idea captures for vault storage
340
+ - **security-officer ↔ test-advisor**: Cross-cutting test gaps in security paths (max 2 inter-specialist DMs total)
341
+
342
+ ##### Communication Discipline
343
+
344
+ - Max 2 DMs to any individual builder from each specialist
345
+ - Max 2 inter-specialist DMs per workflow
346
+ - Consolidate findings no per-file noise
347
+ - project-advisor does NOT DM builders or other specialists (observes via task list only)
348
+
349
+ ---
350
+
351
+ ## Lead Responsibilities (All Execution Modes)
352
+
353
+ Regardless of execution mode (Parallel Teams, Sequential Teams, Subagent Delegation), the lead/outer orchestrator is responsible for:
354
+
355
+ 1. **Progress documentation via knowz-scribe**: At every quality gate, the lead triggers knowledge capture. In Parallel Teams, this means creating scribe capture tasks and sending DMs. In Sequential/Subagent modes where the scribe is not spawned, the lead passes MCP status and vault config to the closer's spawn prompt so Phase 3 captures are handled via Direct Write Fallback.
356
+ 2. **MCP status handoff**: The lead performs the MCP probe and communicates the result downstream — either by spawning vault agents (Parallel) or by including `MCP_ACTIVE` and `VAULTS_CONFIGURED` status in the closer's spawn prompt (Sequential/Subagent).
357
+ 3. **Capture completeness verification**: The lead confirms all gate captures completed before shutting down the scribe or proceeding to the next stage.
358
+
359
+ ---
360
+
361
+ ## Teammate Initialization Protocol
362
+
363
+ ### Agent Teams Mode (spawned as a teammate)
364
+
365
+ When spawned as a teammate in an Agent Teams workflow, follow this sequence:
366
+
367
+ 1. Read your agent definition file (referenced in your spawn prompt)
368
+ 2. Claim your assigned task: `TaskUpdate(taskId: "{task-id from spawn prompt}", status: "in_progress")`
369
+ 3. Read this file (`knowzcode/claude_code_execution.md`) for team conventions
370
+ 4. Read the WorkGroup file for current state, Change Set, and context
371
+ 5. Read context files listed in your task description
372
+ 6. Begin your phase work as defined by your role
373
+ 7. Update the WorkGroup file with results — prefix all todo entries with `KnowzCode:`
374
+ 8. Mark your task as complete with a summary of what was delivered
375
+
376
+ ### Subagent Mode (spawned via Task())
377
+
378
+ When spawned as a custom subagent type (e.g. `subagent_type: "analyst"`), your agent definition from `agents/*.md` is **auto-loaded as your system prompt**. This means:
379
+
380
+ - Step 1 above is already done — your role definition, tools, and constraints are pre-loaded
381
+ - Your `tools`, `model`, `permissionMode`, and `maxTurns` from the YAML frontmatter are enforced automatically
382
+ - You only need to read the task-specific context provided in the spawn prompt (WorkGroup file, specs, context files)
383
+ - Begin your phase work directly
384
+
385
+ ### For Both Modes
386
+
387
+ If you encounter a blocker, keep the task in `in_progress` status with a description of what is blocking you. Do not mark the task as complete until the work is done.
388
+
389
+ ---
390
+
391
+ ## Command References
392
+
393
+ Agents may reference these Claude Code commands as escalation paths:
394
+
395
+ | Command | Used By | Context |
396
+ |---------|---------|---------|
397
+ | `/kc:work` | microfix-specialist | Redirect when fix exceeds scope gate |
398
+ | `/kc:audit security` | reviewer | Full security audit mode |
399
+ | `/kc:audit spec` | knowledge-migrator | Post-migration validation |
400
+
401
+ On other platforms, these commands translate to running the corresponding phase prompts manually.
402
+
403
+ ---
404
+
405
+ ## Verification & Troubleshooting
406
+
407
+ ### How to verify Agent Teams is working
408
+
409
+ 1. Run `/kc:status` check the Agent Teams section for "Enabled" status and agent definitions
410
+ 2. Run `/kc:work` confirm a mode announcement appears before Phase 1A (either "Agent Teams" or "Subagent Delegation")
411
+ 3. In-process mode: press Shift+Down to see spawned teammates in the panel
412
+ 4. Check the WorkGroup file — should show phase transitions with timestamps in the Phase History table
413
+
414
+ ### Common issues
415
+
416
+ | Symptom | Cause | Fix |
417
+ |---------|-------|-----|
418
+ | No mode announcement | Command didn't run setup step | Verify commands are updated (Step 2 should announce mode) |
419
+ | "Subagent Delegation" when expecting Agent Teams | Env var not set or Claude Code not restarted | Add `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1` to settings.json `env` block. **Restart Claude Code** env vars are only loaded on startup. |
420
+ | Agents seem generic / no specialization | Agent definitions not loaded | Check `agents/` directory exists with `.md` files for each role |
421
+ | No quality gates appearing | Command instructions not followed | Re-run `/kc:work` with an explicit goal description |
422
+ | Teammates not visible in panel | Using tmux mode on Windows | Windows uses in-process mode — teammates won't appear in a split pane |
423
+
424
+ ### Verifying after a workflow
425
+
426
+ Check the WorkGroup file at `knowzcode/workgroups/{wgid}.md`:
427
+
428
+ - **Phase History table** should show all phases with timestamps and statuses
429
+ - **Change Set** should be populated (Phase 1A output) with NodeIDs and descriptions
430
+ - **Todos** should all start with the `KnowzCode:` prefix
431
+ - **Status** should show "Closed" after Phase 3 completes