knowzcode 0.2.1 → 0.3.1

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.
package/commands/work.md CHANGED
@@ -58,6 +58,22 @@ The user MUST see the execution mode announcement before any phase work begins.
58
58
 
59
59
  > **Note:** Agent Teams is experimental and the API may change.
60
60
 
61
+ ## Step 2.4: Load Orchestration Config (Optional)
62
+
63
+ If `knowzcode/knowzcode_orchestration.md` exists, parse its YAML blocks:
64
+
65
+ 1. `MAX_BUILDERS` = `max_builders` value (default: 5, clamp to 1-5)
66
+ 2. `SCOUT_MODE` = `scout_mode` value (default: "full")
67
+ 3. `DEFAULT_SPECIALISTS` = `default_specialists` value (default: [])
68
+ 4. `MCP_AGENTS_ENABLED` = `mcp_agents_enabled` value (default: true)
69
+
70
+ Apply flag overrides (flags win over config):
71
+ - `--max-builders=N` in `$ARGUMENTS` → override `MAX_BUILDERS`
72
+ - `--no-scouts` in `$ARGUMENTS` → override `SCOUT_MODE = "none"`
73
+ - `--no-mcp` in `$ARGUMENTS` → override `MCP_AGENTS_ENABLED = false`
74
+
75
+ If the file doesn't exist, use hardcoded defaults (current behavior).
76
+
61
77
  ## Step 2.5: Autonomous Mode Detection
62
78
 
63
79
  Set `AUTONOMOUS_MODE = true` if ANY of these match:
@@ -78,6 +94,37 @@ If `AUTONOMOUS_MODE = true`, announce after the execution mode announcement:
78
94
  > **Autonomous Mode: ACTIVE** — Gates presented for transparency but auto-approved.
79
95
  > Safety exceptions still pause: critical blockers, HIGH/CRITICAL security findings, >3 same-phase failures, complex architecture discrepancies, >3 gap-fix iterations per partition.
80
96
 
97
+ ## Step 2.6: Specialist Detection
98
+
99
+ Set `SPECIALISTS_ENABLED = []` (empty list).
100
+
101
+ If `DEFAULT_SPECIALISTS` is non-empty (from Step 2.4), initialize:
102
+ `SPECIALISTS_ENABLED = DEFAULT_SPECIALISTS`
103
+
104
+ Determine which specialists to activate (flags and natural language add to or override the baseline):
105
+ - `--specialists` → enable all 3: `[security-officer, test-advisor, project-advisor]`
106
+ - `--specialists=csv` → enable specific subset (comma-separated, e.g., `--specialists=security,test`):
107
+ - `security` → `security-officer`
108
+ - `test` → `test-advisor`
109
+ - `project` → `project-advisor`
110
+ - `--no-specialists` → explicit opt-out, `SPECIALISTS_ENABLED = []`
111
+
112
+ **Natural language detection** (case-insensitive match in `$ARGUMENTS` OR the user's preceding conversation message):
113
+ - All specialists: "with specialists", "with officers", "full specialist panel"
114
+ - security-officer: "security review", "threat model", "vulnerability scan", "pentest"
115
+ - test-advisor: "test quality", "TDD enforcement", "test coverage", "test rigor"
116
+ - project-advisor: "backlog", "future work", "brainstorm", "ideas"
117
+
118
+ **Mode constraints:**
119
+ - Tier 3 Parallel Teams: Full support (Group C)
120
+ - Tier 3 Subagent Delegation: Supported via parallel `Task()` calls
121
+ - Sequential Teams / Tier 2: Not supported — if specialists were detected, announce: `> **Specialists: SKIPPED** — not supported in {Sequential Teams / Tier 2} mode.`
122
+
123
+ Default: `SPECIALISTS_ENABLED = []` (specialists are opt-in).
124
+
125
+ If `SPECIALISTS_ENABLED` is non-empty, announce after the autonomous mode announcement (or after the execution mode announcement if autonomous is not active):
126
+ > **Specialists: ACTIVE** — {comma-separated list of enabled specialists}
127
+
81
128
  ## Step 3: Load Context Files (ONCE)
82
129
 
83
130
  Read these files ONCE (do NOT re-read between phases):
@@ -136,6 +183,9 @@ Assess the goal against the codebase to determine the appropriate workflow tier.
136
183
  - Single file, <50 lines, no ripple effects
137
184
 
138
185
  ### Tier 2: Light (2-phase workflow)
186
+
187
+ > **Note:** Light mode does not use orchestration config — single builder, no scouts, no specialists.
188
+
139
189
  ALL must be true:
140
190
  - ≤3 files touched
141
191
  - Single NodeID (1 new capability)
@@ -293,55 +343,75 @@ When Parallel Teams mode is active, follow these 4 stages instead of spawning on
293
343
  - `MCP_ACTIVE = true` (MCP works regardless of vault creation outcome)
294
344
  - `VAULTS_CONFIGURED = true` if at least 1 vault now has a valid ID, else `false`
295
345
  - Announce: `**MCP Status: Connected — N vault(s) available**` or `**MCP Status: Connected — no vaults configured (knowledge capture disabled)**`
296
- 4. **Spawn Group A** (always — 5 agents):
346
+ 4. **Spawn Group A**:
297
347
  Create tasks first, pre-assign, then spawn with task IDs:
298
- - `TaskCreate("Scout: specs context")` → `TaskUpdate(owner: "context-scout-specs")`
299
- - `TaskCreate("Scout: workgroups context")` → `TaskUpdate(owner: "context-scout-workgroups")`
300
- - `TaskCreate("Scout: backlog context")` → `TaskUpdate(owner: "context-scout-backlog")`
301
- - `TaskCreate("Phase 1A: Impact analysis for {goal}")` → `TaskUpdate(owner: "analyst")`
302
- - `TaskCreate("Pre-load architecture context")` `TaskUpdate(owner: "architect")`
303
- Spawn all 5 agents with their `{task-id}` in the spawn prompt (use spawn prompts from Phase Prompt Reference below).
304
- 5. **Spawn Group B** (MCP agents same turn as Group A): If `VAULTS_CONFIGURED = true`:
348
+ - If `SCOUT_MODE = "full"` (default): spawn 3 context scouts (specs, workgroups, backlog) + analyst + architect (5 agents):
349
+ - `TaskCreate("Scout: specs context")` → `TaskUpdate(owner: "context-scout-specs")`
350
+ - `TaskCreate("Scout: workgroups context")` → `TaskUpdate(owner: "context-scout-workgroups")`
351
+ - `TaskCreate("Scout: backlog context")` → `TaskUpdate(owner: "context-scout-backlog")`
352
+ - If `SCOUT_MODE = "minimal"`: spawn 1 context-scout (combined scan) + analyst + architect (3 agents):
353
+ - `TaskCreate("Scout: combined context")` `TaskUpdate(owner: "context-scout")`
354
+ - If `SCOUT_MODE = "none"`: spawn analyst + architect only (2 agents). Analyst and architect scan the codebase independently without pre-loaded scout context.
355
+ - Always:
356
+ - `TaskCreate("Phase 1A: Impact analysis for {goal}")` → `TaskUpdate(owner: "analyst")`
357
+ - `TaskCreate("Pre-load architecture context")` → `TaskUpdate(owner: "architect")`
358
+ Spawn all Group A agents with their `{task-id}` in the spawn prompt (use spawn prompts from Phase Prompt Reference below).
359
+ 5. **Spawn Group B** (MCP agents — same turn as Group A): If `VAULTS_CONFIGURED = true` AND `MCP_AGENTS_ENABLED = true`:
305
360
  Create tasks first, pre-assign, then spawn with task IDs:
306
361
  - `TaskCreate("Knowz-scout: vault queries")` → `TaskUpdate(owner: "knowz-scout")`
307
362
  - `TaskCreate("Knowz-scribe: listen")` → `TaskUpdate(owner: "knowz-scribe")`
308
363
  Spawn both agents with their `{task-id}` in the spawn prompt.
309
- If `VAULTS_CONFIGURED = false`, skip Group B and log: `Vault agents skipped — no vaults configured.`
310
- 6. **Roster confirmation** lead lists every spawned agent by name to the user. If `VAULTS_CONFIGURED` was true but knowz-scout or knowz-scribe is missing from the roster, STOP and re-spawn the missing agent(s) before continuing.
311
- 7. All 5-7 agents work immediately in parallel (3 context scouts are cheap Sonnet read-only agents; knowz-scribe is a cheap Haiku agent)
312
- 8. Scouts broadcast findings analyst and architect consume as messages
364
+ If `VAULTS_CONFIGURED = false` or `MCP_AGENTS_ENABLED = false`, skip Group B and log: `Vault agents skipped — no vaults configured` or `Vault agents skipped — MCP agents disabled in orchestration config.`
365
+ 6. **Spawn Group C** (specialist agents same turn as Groups A and B): If `SPECIALISTS_ENABLED` is non-empty:
366
+ Create tasks first, pre-assign, then spawn with task IDs:
367
+ - If `security-officer` in list: `TaskCreate("Security officer: initial threat scan")` → `TaskUpdate(owner: "security-officer")`
368
+ - If `test-advisor` in list: `TaskCreate("Test advisor: coverage baseline")` → `TaskUpdate(owner: "test-advisor")`
369
+ - If `project-advisor` in list: `TaskCreate("Project advisor: backlog context")` → `TaskUpdate(owner: "project-advisor")`
370
+ Spawn each enabled specialist with its `{task-id}` in the spawn prompt (use spawn prompts from Specialist Spawn Prompts section below).
371
+ If `SPECIALISTS_ENABLED` is empty, skip Group C.
372
+ 7. **Roster confirmation** — lead lists every spawned agent by name to the user. Include Group C specialists if active. If `VAULTS_CONFIGURED` was true but knowz-scout or knowz-scribe is missing from the roster, STOP and re-spawn the missing agent(s) before continuing.
373
+ 8. All spawned agents work immediately in parallel (context scouts are cheap Sonnet read-only agents; knowz-scribe is a cheap Haiku agent; specialists are Sonnet read-only agents). Agent count depends on orchestration config: 2-10 agents at Stage 0.
374
+ 9. Scouts broadcast findings → analyst and architect consume as messages. Specialists work independently on their Stage 0 tasks.
313
375
 
314
- **Key**: The analyst does NOT wait for scouts to finish. It starts scanning the codebase immediately. Scout findings arrive as messages and enrich the analyst's work as they arrive.
376
+ **Key**: The analyst does NOT wait for scouts or specialists to finish. It starts scanning the codebase immediately. Scout findings arrive as messages and enrich the analyst's work as they arrive. Specialist findings are consumed by the lead at gates.
315
377
 
316
378
  ### Stage 1: Analysis + Specification
317
379
 
318
380
  1. Analyst completes Change Set (includes dependency map — see `agents/analyst.md`)
319
381
  2. Lead reads analyst's task summary
320
- 3. Lead presents **Quality Gate #1** to user:
382
+ 3. **Specialist Change Set reviews** (if `SPECIALISTS_ENABLED` non-empty): Create review tasks blocked on analysis:
383
+ - If `security-officer` active: `TaskCreate("Security officer: Change Set review", addBlockedBy: [analysis-task-id])` → `TaskUpdate(owner: "security-officer")`. DM security-officer: `"**New Task**: #{task-id} — Review Change Set for security risk. Rate each NodeID."`
384
+ - If `test-advisor` active: `TaskCreate("Test advisor: Change Set test strategy", addBlockedBy: [analysis-task-id])` → `TaskUpdate(owner: "test-advisor")`. DM test-advisor: `"**New Task**: #{task-id} — Recommend test types per NodeID."`
385
+ 4. Lead presents **Quality Gate #1** to user:
321
386
  - Change Set with NodeIDs, descriptions, affected files
322
387
  - Dependency map showing which NodeIDs can be implemented in parallel
323
388
  - Risk assessment
324
- 4. User approves (or rejects re-run analyst with feedback)
325
- 5. Lead sends DM to architect with the approved Change Set
326
- 6. Lead creates spec-drafting tasks for architect (1 task per NodeID, `addBlockedBy: [analysis-task-id]`):
389
+ - Specialist Reports (if active see gate template below)
390
+ 5. User approves (or rejects re-run analyst with feedback)
391
+ 6. Lead sends DM to architect with the approved Change Set
392
+ 7. Lead creates spec-drafting tasks for architect (1 task per NodeID, `addBlockedBy: [analysis-task-id]`):
327
393
  - `TaskCreate("Spec: NodeID-X")` → `TaskUpdate(taskId, owner: "architect")`
328
394
  - DM architect with task IDs: `"**New Tasks**: #{id-1} Spec: NodeID-A, #{id-2} Spec: NodeID-B. Approved Change Set: {summary}"`
329
395
  - Architect is already warm (pre-loaded during Stage 0) → specs drafted FAST
330
396
  - If Gate #1 rejected: shut down architect, re-run analyst with feedback, re-spawn architect after
331
- 7. Architect completes specs
332
- 8. Lead presents **Quality Gate #2** to user:
333
- - Spec summaries with VERIFY criteria
334
- 9. User approves (or rejects architect revises)
335
- 10. Pre-implementation commit: `git add knowzcode/ && git commit -m "KnowzCode: Specs approved for {wgid}"`
336
- 11. Shut down context-scouts (no longer needed after specs approved). Keep knowz-scout alive for vault queries during implementation.
337
- 12. Keep analyst alive briefly (available for scope questions during early implementation)
338
- 13. Keep architect alive through Stage 2 (consultative role spec clarifications for builders, no code or spec edits)
397
+ 8. Architect completes specs
398
+ 9. **Test-advisor spec review** (if `test-advisor` in `SPECIALISTS_ENABLED`): After specs drafted, create spec testability review task:
399
+ - `TaskCreate("Test advisor: spec testability review", addBlockedBy: [spec-task-id])` → `TaskUpdate(owner: "test-advisor")`
400
+ - DM test-advisor: `"**New Task**: #{task-id} Review specs for testability. Check VERIFY criteria are automatable."`
401
+ 10. Lead presents **Quality Gate #2** to user:
402
+ - Spec summaries with VERIFY criteria
403
+ - Specialist Reports (if active see gate template below)
404
+ 11. User approves (or rejects architect revises)
405
+ 12. Pre-implementation commit: `git add knowzcode/ && git commit -m "KnowzCode: Specs approved for {wgid}"`
406
+ 13. Shut down context-scouts (no longer needed after specs approved). Keep knowz-scout alive for vault queries during implementation.
407
+ 14. Keep analyst alive briefly (available for scope questions during early implementation)
408
+ 15. Keep architect alive through Stage 2 (consultative role — spec clarifications for builders, no code or spec edits)
339
409
 
340
410
  ### Stage 2: Parallel Implementation + Incremental Review
341
411
 
342
412
  1. Lead examines dependency map from analyst:
343
413
  - Group NodeIDs into independent partitions (no shared files between groups)
344
- - Determine builder count: 1 builder per independent group, max 5
414
+ - Determine builder count: 1 builder per independent group, max `MAX_BUILDERS` (default 5, configurable in `knowzcode_orchestration.md`)
345
415
 
346
416
  2. Create builder tasks and spawn:
347
417
  - `TaskCreate("Implement NodeIDs [A, B]", addBlockedBy: [spec-task-id])` → `TaskUpdate(owner: "builder-1")`
@@ -367,7 +437,20 @@ When Parallel Teams mode is active, follow these 4 stages instead of spawning on
367
437
  Reviewer stays idle until its paired builder marks first NodeID implementation complete.
368
438
  Each reviewer audits incrementally within its partition.
369
439
 
370
- 6. Gap flow (per-partition, parallel persistent agents, DM messaging):
440
+ 6. **Specialist implementation reviews** (if `SPECIALISTS_ENABLED` non-empty): Create specialist review tasks alongside reviewer audit tasks, same `addBlockedBy`:
441
+ - If `security-officer` active — one task per partition (runs parallel to reviewer):
442
+ `TaskCreate("Security officer: review partition {N}", addBlockedBy: [implement-X-task-id])` → `TaskUpdate(owner: "security-officer")`
443
+ DM security-officer: `"**New Task**: #{task-id} — Vulnerability scan for partition {N}. NodeIDs: {list}."`
444
+ - If `test-advisor` active — one task per partition:
445
+ `TaskCreate("Test advisor: review partition {N} tests", addBlockedBy: [implement-X-task-id])` → `TaskUpdate(owner: "test-advisor")`
446
+ DM test-advisor: `"**New Task**: #{task-id} — Test quality review for partition {N}. NodeIDs: {list}."`
447
+ - If `project-advisor` active — one observation task (not per-partition):
448
+ `TaskCreate("Project advisor: observe implementation")` → `TaskUpdate(owner: "project-advisor")`
449
+ DM project-advisor: `"**New Task**: #{task-id} — Observe builder progress, note patterns and ideas. Deliver backlog proposals before gap loop."`
450
+ **Gate #3 is NOT blocked by specialists.** If a specialist hasn't finished, gate shows `[Pending: {specialist}]`. Lead proceeds.
451
+ **Project-advisor early shutdown**: After project-advisor delivers backlog proposals, shut it down (before the gap loop begins).
452
+
453
+ 7. Gap flow (per-partition, parallel — persistent agents, DM messaging):
371
454
  a. Each reviewer marks audit task complete with structured gap report in summary
372
455
  b. Lead creates fix task and pre-assigns:
373
456
  `TaskCreate("Fix gaps: NodeID-A", addBlockedBy: [audit-task-id])` → `TaskUpdate(owner: "builder-N")`
@@ -382,12 +465,12 @@ When Parallel Teams mode is active, follow these 4 stages instead of spawning on
382
465
  g. Each builder-reviewer pair repeats independently until clean — no cross-partition blocking
383
466
  — All builders and reviewers stay alive through the entire gap loop (no respawning)
384
467
 
385
- 7. Enterprise compliance (if enabled):
468
+ 8. Enterprise compliance (if enabled):
386
469
  - Lead creates parallel compliance task for each reviewer (scoped to their partition)
387
470
  - Reviewer checks compliance requirements from knowz-scout findings
388
471
  - Runs alongside ARC audits
389
472
 
390
- 8. Inter-agent communication during Stage 2:
473
+ 9. Inter-agent communication during Stage 2:
391
474
  - builder → architect: Spec clarification requests (direct messages)
392
475
  - architect → builder: Design guidance and spec intent responses (direct messages)
393
476
  - builder ↔ builder: Dependency coordination (direct messages — "I changed the User interface, FYI")
@@ -395,23 +478,31 @@ When Parallel Teams mode is active, follow these 4 stages instead of spawning on
395
478
  - reviewer → lead: Gap reports per partition (structured format via task summaries)
396
479
  - lead → builder: Fix tasks (via task creation + DM)
397
480
  - lead → reviewer: Re-audit requests (via task creation + DM)
398
-
399
- 9. After all NodeIDs implemented + audited across all partitions:
400
- - Lead consolidates audit results from all reviewers
401
- - Lead presents **Quality Gate #3**:
402
- - Per-NodeID ARC completion % (from each partition's reviewer)
403
- - Combined security posture
404
- - Combined integration health
405
- - Enterprise compliance (if applicable)
406
- - User decides: proceed / fix gaps / modify specs / cancel
407
-
408
- 10. Shut down analyst, architect, all builders, and all reviewers
481
+ - security-officer → builder-N: Security guidance for sensitive partitions (max 2 DMs per builder)
482
+ - test-advisor builder-N: Test improvement feedback (max 2 DMs per builder)
483
+ - security-officer test-advisor: Cross-cutting test gaps in security paths (max 2 inter-specialist DMs)
484
+ - project-advisor knowz-scribe: Idea captures for vault storage
485
+ - project-advisor lead: Backlog proposals (before gap loop)
486
+
487
+ 10. After all NodeIDs implemented + audited across all partitions:
488
+ - Lead consolidates audit results from all reviewers
489
+ - Lead consolidates specialist reports (if `SPECIALISTS_ENABLED` non-empty include even if some specialist tasks are still pending, noting `[Pending: {specialist}]`)
490
+ - Lead presents **Quality Gate #3**:
491
+ - Per-NodeID ARC completion % (from each partition's reviewer)
492
+ - Combined security posture
493
+ - Combined integration health
494
+ - Enterprise compliance (if applicable)
495
+ - Specialist Reports (if active — see gate template below)
496
+ - User decides: proceed / fix gaps / modify specs / cancel
497
+
498
+ 11. Shut down analyst, architect, all builders, and all reviewers
409
499
 
410
500
  ### Stage 3: Finalization
411
501
 
412
- 1. `TaskCreate("Phase 3: Finalize {wgid}", addBlockedBy: [last-audit-task-id])` `TaskUpdate(owner: "closer")`
502
+ 1. Shut down remaining specialists (security-officer, test-advisor) if still active. Project-advisor should already be shut down from mid-Stage 2.
503
+ 2. `TaskCreate("Phase 3: Finalize {wgid}", addBlockedBy: [last-audit-task-id])` → `TaskUpdate(owner: "closer")`
413
504
  Spawn `closer` with `{task-id}` in spawn prompt.
414
- 2. Closer tasks (can be parallel subtasks):
505
+ 3. Closer tasks (can be parallel subtasks):
415
506
  - Update all specs to FINAL as-built
416
507
  - Update `knowzcode_tracker.md`: all NodeIDs `[WIP]` → `[VERIFIED]`
417
508
  - Write ARC-Completion log entry
@@ -419,9 +510,9 @@ When Parallel Teams mode is active, follow these 4 stages instead of spawning on
419
510
  - Schedule REFACTOR tasks for tech debt
420
511
  - Send learnings to knowz-scribe (if active): `"Capture Phase 3: {wgid}"`. Knowz-scout remains available for vault queries during finalization.
421
512
  - Create final atomic commit
422
- 3. Lead presents completion summary
423
- 4. Shut down knowz-scout, knowz-scribe (after Phase 3 capture completes), closer, and all remaining agents
424
- 5. Delete team
513
+ 4. Lead presents completion summary
514
+ 5. Shut down knowz-scout, knowz-scribe (after Phase 3 capture completes), closer, and all remaining agents
515
+ 6. Delete team
425
516
 
426
517
  ### WorkGroup File Format (Parallel Mode)
427
518
 
@@ -455,9 +546,18 @@ When creating tasks, model the dependency chain with `addBlockedBy` and pre-assi
455
546
  | Knowz-scribe: listen | (none — persistent) | knowz-scribe |
456
547
  | Phase 1A analysis | (none — scouts enrich via broadcast) | analyst |
457
548
  | Architect pre-load | (none) | architect |
549
+ | Security officer: initial threat scan | (none — Group C) | security-officer |
550
+ | Test advisor: coverage baseline | (none — Group C) | test-advisor |
551
+ | Project advisor: backlog context | (none — Group C) | project-advisor |
552
+ | Security officer: Change Set review | Phase 1A analysis | security-officer |
553
+ | Test advisor: Change Set test strategy | Phase 1A analysis | test-advisor |
458
554
  | Spec: NodeID-X | Phase 1A (gate approval) | architect |
555
+ | Test advisor: spec testability review | Spec: NodeID-X | test-advisor |
459
556
  | Implement: NodeID-X | Spec: NodeID-X | builder-N |
460
557
  | Audit: NodeID-X | Implement: NodeID-X | reviewer-N |
558
+ | Security officer: review partition N | Implement: NodeID-X | security-officer |
559
+ | Test advisor: review partition N tests | Implement: NodeID-X | test-advisor |
560
+ | Project advisor: observe implementation | (none) | project-advisor |
461
561
  | Fix gaps: NodeID-X round N | Audit: NodeID-X (or re-audit N-1) | builder-N |
462
562
  | Re-audit: NodeID-X round N | Fix gaps round N | reviewer-N |
463
563
  | Phase 3 finalization | All audits approved | closer |
@@ -466,6 +566,8 @@ When creating tasks, model the dependency chain with `addBlockedBy` and pre-assi
466
566
 
467
567
  ## Sequential Teams / Subagent Flow (Tier 3 Fallback)
468
568
 
569
+ > **Note:** Sequential Teams does not use orchestration config settings except `MCP_AGENTS_ENABLED`.
570
+
469
571
  When using Sequential Teams (`--sequential`) or Subagent Delegation, follow the traditional one-agent-per-phase flow. For each phase below: spawn the agent, create a task, wait for completion, present quality gate, shut down agent, proceed to next phase.
470
572
 
471
573
  ---
@@ -507,10 +609,25 @@ Three instances of the same agent, each focused on a different local folder grou
507
609
  > **READ-ONLY.** Do NOT modify any files.
508
610
  > **Deliverable**: Broadcast active WIP, REFACTOR tasks, architecture summary, and recent log patterns relevant to goal.
509
611
 
612
+ **context-scout (combined) spawn prompt** (used when `SCOUT_MODE = "minimal"`):
613
+ > You are `context-scout` for WorkGroup `{wgid}`.
614
+ > Read `agents/context-scout.md` for your full role definition.
615
+ > **Your Task**: #{task-id} — claim immediately. Mark completed with summary when done.
616
+ > **Focus area**: ALL local context — `knowzcode/specs/*.md`, `knowzcode/workgroups/*.md`, `knowzcode/knowzcode_tracker.md`, `knowzcode/knowzcode_log.md`, `knowzcode/knowzcode_architecture.md`, `knowzcode/knowzcode_project.md`
617
+ > **Goal**: {goal}
618
+ > **READ-ONLY.** Do NOT modify any files.
619
+ > **Deliverable**: Broadcast consolidated findings covering specs, prior workgroups, active WIP, REFACTOR tasks, and architecture context.
620
+
510
621
  **Dispatch**:
511
- - *Parallel Teams*: All 3 context scouts spawned at Stage 0, no blockedBy. Shut down after Gate #2 (specs approved).
622
+ - *Parallel Teams*:
623
+ - `SCOUT_MODE = "full"`: 3 context scouts spawned at Stage 0. Shut down after Gate #2.
624
+ - `SCOUT_MODE = "minimal"`: 1 context-scout (combined) spawned at Stage 0. Shut down after Gate #2.
625
+ - `SCOUT_MODE = "none"`: No scouts spawned.
512
626
  - *Sequential Teams*: Not applicable (scouts are Parallel Teams only).
513
- - *Subagent*: `Task(subagent_type="context-scout", name="context-scout-specs", ...)`, `Task(subagent_type="context-scout", name="context-scout-workgroups", ...)`, `Task(subagent_type="context-scout", name="context-scout-backlog", ...)`
627
+ - *Subagent*:
628
+ - `SCOUT_MODE = "full"`: 3 parallel `Task()` calls (specs, workgroups, backlog).
629
+ - `SCOUT_MODE = "minimal"`: 1 `Task()` call with combined prompt.
630
+ - `SCOUT_MODE = "none"`: Skip scout tasks.
514
631
 
515
632
  ---
516
633
 
@@ -554,6 +671,61 @@ Three instances of the same agent, each focused on a different local folder grou
554
671
 
555
672
  ---
556
673
 
674
+ ## Specialist Spawn Prompts (Group C — opt-in via `--specialists`)
675
+
676
+ The spawn prompts below are used when `SPECIALISTS_ENABLED` is non-empty. Specialists are spawned at Stage 0 alongside Groups A and B.
677
+
678
+ **Dispatch** (all specialists):
679
+ - *Parallel Teams*: Group C — spawned at Stage 0 if `SPECIALISTS_ENABLED` non-empty, no blockedBy. Security-officer and test-advisor persist through Gate #3. Project-advisor shuts down mid-Stage 2.
680
+ - *Sequential Teams*: Not supported — announce skip reason.
681
+ - *Subagent*: `Task()` calls with spawn prompts below.
682
+
683
+ ### Security Officer
684
+
685
+ **Agent**: `security-officer` | Officer — CRITICAL/HIGH findings block gates
686
+
687
+ **Spawn prompt**:
688
+ > You are the **security-officer** for WorkGroup `{wgid}`.
689
+ > Read `agents/security-officer.md` for your full role definition.
690
+ > **Your Task**: #{task-id} — claim immediately (`TaskUpdate(status: "in_progress")`). Mark completed with summary when done.
691
+ > **Goal**: {goal}
692
+ > **READ-ONLY.** Do NOT modify any files. Bash is for read-only security scanning only.
693
+ > **Stage 0 Deliverable**: Build STRIDE-lite threat model. Scan for auth/PII/crypto/session patterns. Broadcast initial threat assessment.
694
+ > **Authority**: CRITICAL/HIGH findings use `[SECURITY-BLOCK]` tag — lead MUST pause autonomous mode.
695
+ > **Communication**: DM lead at gates. DM architect with security VERIFY criteria needs. DM builders in security-sensitive partitions (max 2 per builder). DM test-advisor for cross-cutting test gaps (max 2).
696
+ > **Enterprise Compliance**: If `knowzcode/enterprise/compliance_manifest.md` exists and `compliance_enabled: true`, read active security guidelines and cross-reference findings with enterprise guideline IDs.
697
+
698
+ ### Test Advisor
699
+
700
+ **Agent**: `test-advisor` | Advisor — informational only
701
+
702
+ **Spawn prompt**:
703
+ > You are the **test-advisor** for WorkGroup `{wgid}`.
704
+ > Read `agents/test-advisor.md` for your full role definition.
705
+ > **Your Task**: #{task-id} — claim immediately (`TaskUpdate(status: "in_progress")`). Mark completed with summary when done.
706
+ > **Goal**: {goal}
707
+ > **READ-ONLY.** Do NOT modify any files. Bash is for read-only operations only (git log, coverage reports).
708
+ > **Stage 0 Deliverable**: Establish test coverage baseline. Glob test files, run coverage if available. Broadcast baseline.
709
+ > **Communication**: DM lead at gates. DM architect if VERIFY criteria aren't testable. DM builders with test improvement feedback (max 2 per builder). DM security-officer for cross-cutting security test gaps (max 2).
710
+ > **Enterprise Compliance**: If `knowzcode/enterprise/compliance_manifest.md` exists and `compliance_enabled: true`, check enterprise ARC criteria for test coverage gaps.
711
+
712
+ ### Project Advisor
713
+
714
+ **Agent**: `project-advisor` | Advisor — informational only
715
+
716
+ **Spawn prompt**:
717
+ > You are the **project-advisor** for WorkGroup `{wgid}`.
718
+ > Read `agents/project-advisor.md` for your full role definition.
719
+ > **Your Task**: #{task-id} — claim immediately (`TaskUpdate(status: "in_progress")`). Mark completed with summary when done.
720
+ > **Goal**: {goal}
721
+ > **READ-ONLY.** Do NOT modify any files.
722
+ > **Stage 0 Deliverable**: Read tracker for existing REFACTOR tasks and backlog context. DM lead with context summary.
723
+ > **Lifecycle**: You shut down mid-Stage 2 after delivering backlog proposals — before the gap loop.
724
+ > **Communication**: DM lead with backlog context and proposals. DM knowz-scribe with idea captures (if active). Do NOT DM builders or other specialists.
725
+ > **Enterprise Compliance**: If `knowzcode/enterprise/compliance_manifest.md` exists, note compliance configuration gaps in backlog proposals.
726
+
727
+ ---
728
+
557
729
  ## Phase 1A: Impact Analysis
558
730
 
559
731
  **Agent**: `analyst` | **Loop.md**: Section 3.1
@@ -591,6 +763,11 @@ Present the Change Set for user approval:
591
763
 
592
764
  **Risk Assessment**: {Low/Medium/High}
593
765
 
766
+ ### Specialist Reports [only when SPECIALISTS_ENABLED non-empty]
767
+ **Security Officer**: {risk assessment per NodeID, attack surface changes, threat model}
768
+ **Architect**: {architecture impact, layer touch points, pattern alignment}
769
+ **Test Advisor**: {coverage baseline, test strategy recommendations per NodeID}
770
+
594
771
  Approve this Change Set to proceed to specification?
595
772
  ```
596
773
 
@@ -643,6 +820,10 @@ Present specs for batch approval:
643
820
  |--------|------|---------------------|
644
821
  | ... | ... | ... |
645
822
 
823
+ ### Specialist Reports [only when SPECIALISTS_ENABLED non-empty]
824
+ **Architect**: {specs align with component map, drift concerns, pattern consistency}
825
+ **Test Advisor**: {spec testability assessment, recommended test types per NodeID}
826
+
646
827
  Review specs and approve to proceed to implementation?
647
828
  ```
648
829
 
@@ -728,13 +909,19 @@ Present audit results:
728
909
  **Security Posture**: {status}
729
910
  **Gaps Found**: {count}
730
911
 
912
+ ### Specialist Reports [only when SPECIALISTS_ENABLED non-empty]
913
+ **Security Officer**: Findings: {N} | Critical: {N} | High: {N} | {details or [Pending]}
914
+ **Architect**: Drift: {Yes/No} | Pattern Violations: {N} | {details}
915
+ **Test Advisor**: TDD Compliance: {%} | Missing Edge Cases: {N} | Quality: {Good/Adequate/Poor} | {details or [Pending]}
916
+ **Project Advisor**: New REFACTOR tasks: {N} | Ideas captured to vault: {N}
917
+
731
918
  **Recommendation**: {proceed / return to implementation}
732
919
 
733
920
  How would you like to proceed?
734
921
  ```
735
922
 
736
923
  **Autonomous Mode**: If `AUTONOMOUS_MODE = true`:
737
- - **Safety check**: If any security finding rated HIGH or CRITICAL → **PAUSE** autonomous mode for this gate. Announce: `> **Autonomous Mode Paused** — HIGH/CRITICAL security finding requires manual review.`
924
+ - **Safety check**: If any security finding rated HIGH or CRITICAL (from reviewer OR security-officer `[SECURITY-BLOCK]`) → **PAUSE** autonomous mode for this gate. Announce: `> **Autonomous Mode Paused** — HIGH/CRITICAL security finding requires manual review.`
738
925
  - **Safety check**: If ARC completion < 50% → **PAUSE** autonomous mode for this gate. Announce: `> **Autonomous Mode Paused** — ARC completion below 50% requires manual review.`
739
926
  - If safety checks pass and gaps found → log `[AUTO-APPROVED] Gate #3 — proceeding to gap loop`, auto-proceed to gap loop.
740
927
  - If safety checks pass and no gaps → log `[AUTO-APPROVED] Gate #3`, auto-proceed to Phase 3.
@@ -159,6 +159,16 @@ Use mailbox messaging for coordination between teammates:
159
159
  | closer | knowz-scribe | Phase 3 learning capture (`"Capture Phase 3: {wgid}"`) |
160
160
  | closer | analyst | Change scope for log entry accuracy |
161
161
  | closer | architect | Spec format and legacy migration |
162
+ | security-officer | lead | Structured finding reports at gates (with `[SECURITY-BLOCK]` for CRITICAL/HIGH) |
163
+ | security-officer | architect | Security VERIFY criteria needs during Phase 1B |
164
+ | security-officer | builder | Security guidance for sensitive partitions (max 2 DMs per builder) |
165
+ | security-officer | test-advisor | Cross-cutting: test gaps in security-critical paths (max 2 inter-specialist DMs) |
166
+ | test-advisor | lead | Test quality reports at gates |
167
+ | test-advisor | architect | VERIFY criteria testability concerns during Phase 1B |
168
+ | test-advisor | builder | Specific test improvement feedback (max 2 DMs per builder) |
169
+ | test-advisor | security-officer | Cross-cutting: security scenarios needing test coverage (max 2 inter-specialist DMs) |
170
+ | project-advisor | lead | Backlog context (Stage 0) and proposals (late Stage 2) |
171
+ | project-advisor | knowz-scribe | Idea captures for vault storage |
162
172
 
163
173
  ### Gap Communication Flow
164
174
  In Parallel Teams mode, gap communication goes through the lead:
@@ -213,6 +223,9 @@ Agents must NOT create new tasks for work already assigned to them via task ID.
213
223
  | architect | Stage 0 (pre-load) | After Gate #3 | Spec clarifications + design guidance for builders throughout Stage 2 |
214
224
  | builder(s) | Stage 2 | After Gate #3 | Implementation + gap fixes (persistent through gap loop) |
215
225
  | reviewer(s) | Stage 2 (1 per builder partition) | After Gate #3 | Incremental audit per partition (persistent through gap loop) |
226
+ | security-officer | Stage 0 (Group C) | After Gate #3 | Threat modeling + vulnerability scanning (officer — can block gates) |
227
+ | test-advisor | Stage 0 (Group C) | After Gate #3 | TDD enforcement + test quality review (advisor — informational) |
228
+ | project-advisor | Stage 0 (Group C) | Mid-Stage 2 | Backlog curation + idea capture (advisor — informational) |
216
229
  | closer | Stage 3 | End of workflow | Finalization |
217
230
 
218
231
  ### Task Dependency Usage
@@ -229,11 +242,24 @@ All tasks in a workflow use `addBlockedBy` to express the dependency chain:
229
242
  - Stage 2 tasks: implementation subtasks (blocked by spec approval), audit subtasks (blocked by implementation)
230
243
  - Stage 3 tasks: finalization (blocked by audit approval)
231
244
 
245
+ ### Orchestration Configuration
246
+
247
+ Team sizing defaults are configurable via `knowzcode/knowzcode_orchestration.md`:
248
+
249
+ | Parameter | Default | Flag Override | Effect |
250
+ |-----------|---------|--------------|--------|
251
+ | `max_builders` | 5 | `--max-builders=N` | Cap concurrent builders (1-5) |
252
+ | `scout_mode` | full | `--no-scouts` | full (3 scouts), minimal (1 scout), none (lead reads context) |
253
+ | `default_specialists` | [] | `--specialists`, `--no-specialists` | Project-level specialist defaults |
254
+ | `mcp_agents_enabled` | true | `--no-mcp` | Toggle vault agents (knowz-scout, knowz-scribe) |
255
+
256
+ Precedence: hardcoded defaults → orchestration config → per-invocation flags.
257
+
232
258
  ### Builder Partitioning Rules
233
259
 
234
260
  - No two builders touch the same file
235
261
  - Analyst dependency map determines partitions
236
- - Max 5 concurrent builders
262
+ - Max `MAX_BUILDERS` concurrent builders (default 5, configurable in `knowzcode_orchestration.md`)
237
263
  - If all NodeIDs share files → single builder with subtask tracking
238
264
  - Builder-to-builder messages for interface changes affecting other partitions
239
265
 
@@ -264,6 +290,43 @@ During Stage 0, the architect pre-loads context in parallel with analysis:
264
290
  - When Gate #1 is approved, architect already has context → specs drafted faster
265
291
  - If Gate #1 rejected, architect context is still useful for the revised analysis cycle
266
292
 
293
+ #### Specialist Agents (Group C — opt-in via `--specialists`)
294
+
295
+ When specialists are enabled, three additional agents spawn at Stage 0 alongside Groups A and B:
296
+
297
+ ```
298
+ Group A (always): 3 context-scouts + analyst + architect (5 agents)
299
+ Group B (if MCP): knowz-scout + knowz-scribe (2 agents)
300
+ Group C (if --specialists): security-officer + test-advisor + project-advisor (3 agents)
301
+ ```
302
+
303
+ Max Stage 0 concurrent: 5-10 agents depending on orchestration config (scouts, MCP agents, specialists). Scouts shut down after Gate #2, so Stage 2 peak is manageable.
304
+
305
+ ##### Officer vs Advisor Authority
306
+
307
+ | Role | Authority | Gate Impact |
308
+ |------|-----------|-------------|
309
+ | **Officer** (security-officer) | CRITICAL/HIGH findings block gates | `[SECURITY-BLOCK]` tag pauses autonomous mode |
310
+ | **Advisor** (test-advisor, project-advisor) | Informational only | Findings included in gate reports, do not block |
311
+
312
+ ##### Direct DM Protocol
313
+
314
+ Specialists communicate directly with builders, architect, and each other — no lead bottleneck relay:
315
+
316
+ - **security-officer → architect**: Security VERIFY criteria needs during Phase 1B
317
+ - **security-officer → builder-N**: Security guidance for sensitive partitions (max 2 DMs per builder)
318
+ - **test-advisor → architect**: VERIFY criteria testability concerns during Phase 1B
319
+ - **test-advisor → builder-N**: Specific test improvement feedback (max 2 DMs per builder)
320
+ - **project-advisor → knowz-scribe**: Idea captures for vault storage
321
+ - **security-officer ↔ test-advisor**: Cross-cutting test gaps in security paths (max 2 inter-specialist DMs total)
322
+
323
+ ##### Communication Discipline
324
+
325
+ - Max 2 DMs to any individual builder from each specialist
326
+ - Max 2 inter-specialist DMs per workflow
327
+ - Consolidate findings — no per-file noise
328
+ - project-advisor does NOT DM builders or other specialists (observes via task list only)
329
+
267
330
  ---
268
331
 
269
332
  ## Teammate Initialization Protocol