all-for-claudecode 2.10.0 → 2.12.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.
@@ -10,6 +10,7 @@ argument-hint: "[feature description in natural language]"
10
10
  > Tasks are generated automatically at implement start (no separate tasks phase).
11
11
  > Critic Loop runs at each phase with unified safety cap (5). Convergence terminates early when quality is sufficient.
12
12
  > Pre-implementation gates (clarify, TDD pre-gen, blast-radius) run conditionally within the implement phase.
13
+ > **Skill Advisor**: 5 checkpoints (A–E) at phase boundaries dynamically invoke auxiliary skills (ideate, consult, architect, security, analyze, test, qa, learner) based on signal detection. Budget-controlled (max 5 per pipeline).
13
14
 
14
15
  ## Arguments
15
16
 
@@ -35,9 +36,59 @@ If config file is missing:
35
36
 
36
37
  ---
37
38
 
39
+ ## Skill Advisor System
40
+
41
+ > Auxiliary skills (ideate, consult, architect, security, analyze, test, qa, learner) are dynamically invoked at phase boundaries based on **intent-based evaluation**. Each checkpoint uses LLM semantic judgment — not keyword counting — to determine whether auxiliary skills would add value.
42
+
43
+ ### Core Principle: Intent-Based Evaluation
44
+
45
+ Each checkpoint contains a **structured evaluation prompt** that the orchestrator answers by reading the actual artifact content (not scanning for keywords). The evaluation produces a 1–5 score per signal. Score >= 3 triggers the corresponding skill.
46
+
47
+ **Why not keywords**: Keyword matching produces false positives (e.g., "token" in CSS vs auth context) and misses implicit intent (e.g., "user upload feature" implies security concerns without mentioning "XSS"). The orchestrator is an LLM — it should use semantic understanding.
48
+
49
+ ### Execution Modes
50
+
51
+ | Mode | Description | Context cost | Example |
52
+ |------|-------------|-------------|---------|
53
+ | **Transform** | Skill output **replaces or restructures** the next phase's input | High (blocking) | ideate → $ARGUMENTS restructured |
54
+ | **Enrich** | Skill output **appends context** to the next phase's input | Low (fork/Task) | consult → domain constraints section added |
55
+ | **Observe** | Skill output is **metadata only** (logged, flags set) | Low (fork) | qa → quality score recorded |
56
+
57
+ ### Budget Control
58
+
59
+ | Constraint | Limit | Rationale |
60
+ |-----------|-------|-----------|
61
+ | Per checkpoint | max 2 skills | Phase transition delay cap |
62
+ | Pipeline total | max 5 auxiliary invocations | Total execution time cap |
63
+ | Transform mode | max 1 per pipeline | Main context pollution prevention |
64
+ | Concurrent fork | max 3 per checkpoint | Agent resource limit |
65
+
66
+ Track auxiliary invocations in `ADVISOR_COUNT` (starts at 0, increments per invocation). If `ADVISOR_COUNT >= 5`, skip remaining checkpoints. Transform invocations tracked in `ADVISOR_TRANSFORM_USED` (boolean). **Every increment** must persist to pipeline state: `afc_state_write "advisorCount" "$ADVISOR_COUNT"`. On context recovery, restore from state: `ADVISOR_COUNT = afc_state_read "advisorCount"`.
67
+
68
+ ### Expert Agent Routing
69
+
70
+ When a checkpoint determines that domain expertise is needed, route to the appropriate expert agent:
71
+
72
+ | Domain | Agent ID | When to route |
73
+ |--------|----------|---------------|
74
+ | backend | `afc-backend-expert` | API design, database schema, server architecture, auth flows |
75
+ | infra | `afc-infra-expert` | Deployment, CI/CD, cloud infrastructure, containerization, scaling |
76
+ | pm | `afc-pm-expert` | Product decisions, user stories, prioritization, metrics |
77
+ | design | `afc-design-expert` | UI/UX, accessibility, component design, visual hierarchy |
78
+ | marketing | `afc-marketing-expert` | SEO, analytics, growth, conversion optimization |
79
+ | legal | `afc-legal-expert` | Privacy regulations, licensing, compliance, data protection |
80
+ | security | `afc-appsec-expert` | Application security, vulnerability patterns, secure coding |
81
+ | advisor | `afc-tech-advisor` | Technology selection, library comparison, stack decisions |
82
+
83
+ Route based on **what expertise the feature actually needs**, not keyword presence. Consider the project's `{config.architecture}` and tech stack — skip domains irrelevant to the project.
84
+
85
+ **Agent ID lookup**: Use the Agent ID column directly as the `subagent_type` value (e.g., `subagent_type: "afc:afc-backend-expert"`). Do NOT construct agent names from the domain name — `security` maps to `afc-appsec-expert` (not `afc-security-expert`), and `advisor` maps to `afc-tech-advisor` (not `afc-advisor-expert`).
86
+
87
+ ---
88
+
38
89
  ## Critic Loop Rules (common to all phases)
39
90
 
40
- > **Always** read `${CLAUDE_PLUGIN_ROOT}/docs/critic-loop-rules.md` first and follow it.
91
+ > **Always** read `${CLAUDE_SKILL_DIR}/../../docs/critic-loop-rules.md` first and follow it.
41
92
  > Core: minimum 1 concern per criterion + mandatory Adversarial failure scenario each pass + quantitative evidence required. "PASS" as a single word is prohibited. Uses convergence-based termination with 4 verdicts (PASS/FAIL/ESCALATE/DEFER). On ESCALATE: pause and present options to user even in auto mode.
42
93
 
43
94
  ---
@@ -51,20 +102,25 @@ If config file is missing:
51
102
  3. Determine feature name (2-3 keywords → kebab-case)
52
103
  3.5. **Preflight Check**:
53
104
  ```bash
54
- "${CLAUDE_PLUGIN_ROOT}/scripts/afc-preflight-check.sh"
105
+ "${CLAUDE_SKILL_DIR}/../../scripts/afc-preflight-check.sh"
55
106
  ```
56
107
  - If exit 1 (hard failure) → print error and **abort**
57
108
  - If warnings only (exit 0) → print warnings and continue
58
109
  4. **Activate Pipeline Flag** (hook integration):
59
110
  ```bash
60
- "${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" start {feature}
111
+ "${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" start {feature}
61
112
  ```
62
113
  - Safety Snapshot created automatically (`afc/pre-auto` git tag)
63
114
  - Stop Gate Hook activated (blocks response termination on CI failure)
64
115
  - File change tracking started
65
- - Timeline log: `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" log pipeline-start "Auto pipeline: {feature}"`
116
+ - Timeline log: `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" log pipeline-start "Auto pipeline: {feature}"`
66
117
  5. Create `.claude/afc/specs/{feature}/` directory → **record path as `PIPELINE_ARTIFACT_DIR`** (for Clean scope)
67
- 6. Start notification:
118
+ 6. **Initialize Skill Advisor**: `ADVISOR_COUNT = 0`, `ADVISOR_TRANSFORM_USED = false`. Persist to pipeline state for context-loss resilience:
119
+ ```bash
120
+ afc_state_write "advisorCount" "0"
121
+ afc_state_write "advisorTransformUsed" "false"
122
+ ```
123
+ 7. Start notification:
68
124
  ```
69
125
  Auto pipeline started: {feature}
70
126
  ├─ Clarify? → 1/5 Spec → 2/5 Plan → 3/5 Implement → 4/5 Review → 5/5 Clean
@@ -78,7 +134,7 @@ Before investing pipeline resources, evaluate whether the request warrants execu
78
134
  1. **Necessity check**: Explore codebase for existing implementations related to `$ARGUMENTS`.
79
135
  - If the feature substantially exists → ask user via AskUserQuestion:
80
136
  - "This feature appears to already exist at {path}. (1) Enhance existing (2) Replace entirely (3) Abort"
81
- - If user chooses abort → release pipeline flag (`"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" end`), end with: `"Pipeline aborted — feature already exists."`
137
+ - If user chooses abort → release pipeline flag (`"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" end`), end with: `"Pipeline aborted — feature already exists."`
82
138
 
83
139
  2. **Scope check**: Estimate the scope of `$ARGUMENTS`:
84
140
  - If description implies 10+ files or multiple unrelated concerns → warn:
@@ -115,8 +171,8 @@ If all checks pass, proceed to Phase 0.8.
115
171
  3. If change touches > 2 files OR modifies any `.sh` script: **rollback fast-path changes** (`git reset --hard afc/pre-auto`), then restart with full pipeline
116
172
  4. **Checkpoint**:
117
173
  ```bash
118
- "${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase fast-path
119
- "${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" ci-pass
174
+ "${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" phase fast-path
175
+ "${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" ci-pass
120
176
  ```
121
177
  5. Run `/afc:review` logic inline (mini-review only — single Critic pass)
122
178
  6. Run Phase 5 Clean logic (artifact cleanup, CI gate, pipeline flag release)
@@ -131,7 +187,7 @@ If all checks pass, proceed to Phase 0.8.
131
187
 
132
188
  ### Phase 0.5: Auto-Clarify Gate (conditional)
133
189
 
134
- `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase clarify`
190
+ `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" phase clarify`
135
191
 
136
192
  **Trigger condition**: Score `$ARGUMENTS` on 5 ambiguity signals. If score >= 3, trigger clarification.
137
193
 
@@ -152,9 +208,73 @@ If all checks pass, proceed to Phase 0.8.
152
208
 
153
209
  **If score < 3** (clear): skip silently, proceed to Phase 1.
154
210
 
211
+ ### Skill Advisor Checkpoint A (Pre-Spec)
212
+
213
+ > Evaluate auxiliary skill triggers BEFORE entering Phase 1. Budget: max 2 skills, max 1 Transform. Skip all if `ADVISOR_COUNT >= 5`.
214
+
215
+ **Intent evaluation** — Read `$ARGUMENTS` and answer these questions semantically (not by keyword scanning):
216
+
217
+ | # | Question | Score 1–5 | If >= 3 | Skill | Mode |
218
+ |---|----------|-----------|---------|-------|------|
219
+ | A1 | Is this request at the **idea/vision level** rather than a concrete feature? (e.g., "make onboarding better" vs "add email verification to signup flow") Does it lack specific technical scope — no file paths, no API endpoints, no component names? | 1=concrete spec-ready, 5=pure vision | `ideate` | Transform |
220
+ | A2 | Does implementing this feature require **specialized domain knowledge** that a generalist developer wouldn't have? Consider: regulatory requirements, industry-specific patterns, domain-specific anti-patterns, compliance rules. Which domain from the Expert Agent Routing table would add the most value? | 1=general programming, 5=deep domain expertise essential | `consult({domain})` | Enrich (fork) |
221
+
222
+ **If A1 >= 3** (Transform — skip if `ADVISOR_TRANSFORM_USED`):
223
+ 1. Execute `/afc:ideate` inline with `$ARGUMENTS`
224
+ 2. If ideate fails or produces no output:
225
+ - Do NOT set `ADVISOR_TRANSFORM_USED = true`
226
+ - Proceed with original `$ARGUMENTS`
227
+ - Log: `"Skill Advisor [A]: ideate failed, proceeding with original input"`
228
+ 3. On success: read generated `ideate.md` → extract `## Problem Statement` + `## Value Proposition` + `## Core Features (MoSCoW)` sections
229
+ 4. Construct enriched spec input:
230
+ ```
231
+ SPEC_INPUT = "$ARGUMENTS
232
+
233
+ ## Ideation Context (auto-generated)
234
+ {extracted Problem Statement section}
235
+ {extracted Value Proposition section}
236
+ {extracted Core Features (MoSCoW) — Must Have items only}"
237
+ ```
238
+ 5. Replace `$ARGUMENTS` with `SPEC_INPUT` for Phase 1
239
+ 6. Set `ADVISOR_TRANSFORM_USED = true`, increment `ADVISOR_COUNT`, persist: `afc_state_write "advisorCount" "$ADVISOR_COUNT"` and `afc_state_write "advisorTransformUsed" "true"`
240
+ 7. Progress: ` ├─ Skill Advisor [A]: ideate (score: {N}/5, input restructured from idea to structured brief)`
241
+
242
+ **If A2 >= 3** (Enrich):
243
+ 1. Determine which domain from Expert Agent Routing table best matches the **actual expertise gap** (not keyword presence)
244
+ 2. Verify domain relevance: does this project's `{config.architecture}` and tech stack make this domain applicable? (e.g., skip `design` for a CLI tool, skip `infra` if the project has no deployment config)
245
+ 3. Invoke expert agent (look up the agent-id from the Expert Agent Routing table — do NOT construct from domain name):
246
+ ```
247
+ Task("Domain pre-consultation: {domain}", subagent_type: "afc:{agent-id-from-routing-table}",
248
+ prompt: "You are being consulted automatically during pipeline spec preparation.
249
+
250
+ ## Feature Context
251
+ {$ARGUMENTS}
252
+
253
+ ## Why You Were Consulted
254
+ {1-sentence explanation of what domain expertise gap was identified}
255
+
256
+ ## Instructions
257
+ 1. Read your MEMORY.md for prior project context
258
+ 2. Read .claude/afc/project-profile.md if it exists
259
+ 3. Provide domain-specific constraints, regulations, and anti-patterns that MUST be reflected in the spec
260
+ 4. Format your response EXACTLY as:
261
+ ## Domain Constraints ({domain})
262
+ - [MUST] {constraint}: {rationale}
263
+ - [MUST NOT] {anti-pattern}: {risk}
264
+ - [CONSIDER] {best practice}: {benefit}
265
+ 5. Keep to max 10 items. Prioritize by risk severity.
266
+ 6. Update your MEMORY.md with the consultation context")
267
+ ```
268
+ 4. Store output as `DOMAIN_CONSTRAINTS` → injected into Phase 1 spec context
269
+ 5. Spec phase MUST include a `## Domain Constraints` section reflecting these items
270
+ 6. Increment `ADVISOR_COUNT`
271
+ 7. Progress: ` ├─ Skill Advisor [A]: consult({domain}) (score: {N}/5, {M} constraints injected)`
272
+
273
+ **If all scores < 3**: proceed silently to Phase 1.
274
+
155
275
  ### Phase 1: Spec (1/5)
156
276
 
157
- `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase spec`
277
+ `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" phase spec`
158
278
 
159
279
  Execute `/afc:spec` logic inline:
160
280
 
@@ -178,18 +298,100 @@ Execute `/afc:spec` logic inline:
178
298
  - MEASURABILITY: are success criteria measurable, not subjective? **Is quantitative evidence provided for numerical targets?**
179
299
  - INDEPENDENCE: are implementation details (code, library names) absent from the spec?
180
300
  - EDGE_CASES: are at least 2 identified? Any missing boundary conditions?
301
+ - TESTABILITY: Does every System Requirement follow one of the 5 EARS patterns (WHEN/WHILE/IF/WHERE/SHALL)? Does each EARS requirement have a mapped TC (`→ TC: should_...`)? If not → FAIL and auto-fix: rewrite to EARS + generate TC mapping.
181
302
  - FAIL → auto-fix and continue. ESCALATE → pause, present options, resume after response. DEFER → record reason, mark clean.
182
303
  7. **Checkpoint**: phase transition already recorded by `afc-pipeline-manage.sh phase spec` at phase start
183
304
  8. Progress: `✓ 1/5 Spec complete (US: {N}, FR: {N}, researched: {N}, Critic: converged ({N} passes, {M} fixes, {E} escalations))`
184
305
 
306
+ ### Skill Advisor Checkpoint B (Post-Spec)
307
+
308
+ > Evaluate auxiliary skill triggers AFTER spec completion, BEFORE plan creation. Budget: max 2 skills. Skip all if `ADVISOR_COUNT >= 5`.
309
+
310
+ **Intent evaluation** — Read the completed spec.md and answer these questions:
311
+
312
+ | # | Question | Score 1–5 | If >= 3 | Skill | Mode |
313
+ |---|----------|-----------|---------|-------|------|
314
+ | B1 | Does this feature **handle, store, or transmit sensitive data or trust boundaries**? Consider: user authentication/authorization, cryptographic operations, PII/financial data processing, external input that reaches internal systems, session/token lifecycle. Judge by the feature's actual behavior, not by whether security-related words appear. | 1=no trust boundary touched, 5=core security feature | `security` | Enrich (fork) |
315
+ | B2 | Does this feature **cross multiple architectural boundaries** or introduce a new structural pattern? Consider: does it touch 3+ layers (e.g., API + service + data + external), create a new component type not seen in the codebase, or require coordination between independently-deployable units? | 1=single-layer change, 5=cross-cutting architectural change | `architect` | Enrich (fork) |
316
+
317
+ **If B1 >= 3** (Enrich):
318
+ 1. Invoke security agent for pre-plan threat modeling:
319
+ ```
320
+ Task("Threat Model: {feature}", subagent_type: "afc:afc-security",
321
+ prompt: "Generate a threat model BEFORE implementation planning begins.
322
+
323
+ ## Spec Summary
324
+ {spec.md FR/NFR/Key Entities — security-relevant items only}
325
+
326
+ ## Why This Was Triggered
327
+ {1-sentence explanation of which trust boundary or sensitive data flow was identified}
328
+
329
+ ## Instructions
330
+ 1. Read your MEMORY.md for known vulnerability patterns in this project
331
+ 2. Identify attack surfaces from the spec requirements
332
+ 3. For each threat, specify the mitigation that MUST appear in the plan
333
+ 4. Format your response EXACTLY as:
334
+ ## Threat Model (pre-scan)
335
+ | Threat | Attack Surface | Mitigation Required | Priority |
336
+ |--------|---------------|-------------------|----------|
337
+ 5. Max 8 threats. Prioritize by exploitability and impact.")
338
+ ```
339
+ 2. Store output as `THREAT_MODEL` → injected into Phase 2 plan context
340
+ 3. Plan phase MUST address each mitigation in its Risk & Mitigation section
341
+ 4. Plan Critic RISK criterion MUST verify: `{M}/{N} threat mitigations addressed`
342
+ 5. Increment `ADVISOR_COUNT`
343
+ 6. Progress: ` ├─ Skill Advisor [B]: security (score: {N}/5, threat model: {M} threats identified)`
344
+
345
+ **If B2 >= 3** (Enrich):
346
+ 1. Invoke architect agent for pre-plan guidance:
347
+ ```
348
+ Task("Architecture Advisory: {feature}", subagent_type: "afc:afc-architect",
349
+ prompt: "Provide architecture guidance BEFORE plan creation.
350
+
351
+ ## Spec Summary
352
+ {spec.md Key Entities + layer analysis from {config.architecture}}
353
+
354
+ ## Why This Was Triggered
355
+ {1-sentence explanation of which architectural boundary crossing was identified}
356
+
357
+ ## Instructions
358
+ 1. Read your MEMORY.md for prior ADRs and architecture patterns
359
+ 2. Recommend: component placement, layer boundaries, interface contracts
360
+ 3. Flag conflicts with existing architecture patterns
361
+ 4. Format your response EXACTLY as:
362
+ ## Architecture Advisory (pre-plan)
363
+ - [PLACE] {component} → {layer/module}: {rationale}
364
+ - [BOUNDARY] {interface}: {contract description}
365
+ - [CONFLICT] {existing} ↔ {new}: {resolution recommendation}
366
+ - [PATTERN] {recommended pattern}: {why it fits}
367
+ 5. Max 10 items.
368
+ 6. Update your MEMORY.md if new patterns are identified")
369
+ ```
370
+ 2. Store output as `ARCH_ADVISORY` → injected into Phase 2 plan context
371
+ 3. Plan Critic ARCHITECTURE criterion MUST validate against this advisory
372
+ 4. Increment `ADVISOR_COUNT`
373
+ 5. Progress: ` ├─ Skill Advisor [B]: architect (score: {N}/5, advisory: {M} recommendations, {K} conflicts)`
374
+
375
+ **If both B1 and B2 >= 3**: launch both agents in a **single message** (parallel fork). Both count toward budget. After both return:
376
+ 1. Apply `THREAT_MODEL` to plan Risk & Mitigation section
377
+ 2. Apply `ARCH_ADVISORY` to plan Architecture Decision section
378
+ 3. If security mitigations conflict with architecture proposals (e.g., "encrypt at rest" vs "use in-memory cache") → **ESCALATE** to user with conflict details
379
+
380
+ **If all scores < 3**: proceed silently to Phase 2.
381
+
185
382
  ### Phase 2: Plan (2/5)
186
383
 
187
- `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase plan`
384
+ `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" phase plan`
188
385
 
189
386
  Execute `/afc:plan` logic inline:
190
387
 
191
388
  1. Load spec.md
192
- 2. If technical uncertainties exist → auto-resolve via WebSearch/code exploration → create research.md
389
+ 2. **Research (ReWOO pattern, if needed)**:
390
+ Extract technical uncertainties from spec.md (libraries/APIs not yet used, unverified performance requirements, unclear integration approach). If no uncertain items: skip.
391
+ If there are uncertain items, follow the 3-step ReWOO flow:
392
+ - **Step 1 — Plan**: List all research topics as a numbered list (NO execution yet): `1. {topic} — {what we need to know}`
393
+ - **Step 2 — Execute**: If topics are independent → launch parallel Task() calls in a **single message**: `Task("Research: {topic1}", subagent_type: "general-purpose")`. If a topic depends on another's result → execute sequentially. For 1-2 topics → resolve directly via WebSearch/codebase exploration (no delegation).
394
+ - **Step 3 — Solve**: Collect all results and record in `.claude/afc/specs/{feature}/research.md` with: Decision, Rationale, Alternatives, Source per topic.
193
395
  3. **Memory loading** (skip gracefully if directories are empty or absent):
194
396
  - **Quality history**: if `.claude/afc/memory/quality-history/*.json` exists, load the **most recent 10 files** (sorted by filename descending) and display trend summary: "Last {N} pipelines: avg critic_fixes {X}, avg ci_failures {Y}, avg escalations {Z}". Use trends to inform plan risk assessment.
195
397
  - **Decisions**: if `.claude/afc/memory/decisions/` exists, load the **most recent 30 files** (sorted by filename descending) and check for conflicts with the current feature's design direction. Flag any contradictions.
@@ -248,35 +450,140 @@ Execute `/afc:plan` logic inline:
248
450
  9. **Checkpoint**: phase transition already recorded by `afc-pipeline-manage.sh phase plan` at phase start
249
451
  10. Progress: `✓ 2/5 Plan complete (Critic: converged ({N} passes, {M} fixes, {E} escalations), files: {N}, ADR: {N} recorded, Implementation Context: {W} words)`
250
452
 
453
+ ### Skill Advisor Checkpoint C (Post-Plan)
454
+
455
+ > Evaluate auxiliary skill triggers AFTER plan completion, BEFORE implementation. Budget: max 2 skills. Skip all if `ADVISOR_COUNT >= 5`.
456
+
457
+ **Intent evaluation** — Read the completed plan.md and answer these questions:
458
+
459
+ | # | Question | Score 1–5 | If >= 3 | Skill | Mode |
460
+ |---|----------|-----------|---------|-------|------|
461
+ | C1 | Is the **implementation risk high enough** that a dependency pre-analysis would catch problems the plan missed? Consider: are there files in the File Change Map that import each other (potential circular dependency)? Are there shared utility files that many other files depend on (high fan-out risk)? Are the declared `Depends On` relationships complete, or could there be hidden coupling? | 1=isolated changes, 5=deeply interconnected change set | dependency analysis (general-purpose fork) | Observe |
462
+ | C2 | Does the plan contain **unresolved domain uncertainties** — items tagged `[UNCERTAIN]`, open questions in Implementation Context, or design decisions that assume domain knowledge the team may not have? | 1=all decisions are well-grounded, 5=critical domain questions remain open | `consult({domain})` expert agent | Enrich (fork) |
463
+
464
+ **If C1 >= 3** (Observe):
465
+ 1. Invoke analysis in fork context:
466
+ ```
467
+ Task("Complexity Analysis: {feature}", subagent_type: "general-purpose",
468
+ prompt: "Analyze the dependency graph of files listed in the plan's File Change Map.
469
+
470
+ ## File Change Map
471
+ {paste File Change Map table from plan.md}
472
+
473
+ ## Instructions
474
+ 1. For each file in the map, check its imports/dependencies in the codebase (Grep for import/require/source patterns)
475
+ 2. Identify:
476
+ - Circular dependencies between planned files
477
+ - High fan-out files (>5 dependents outside the change set)
478
+ - Hidden coupling not captured in the Depends On column
479
+ - Files that are imported by many other files (risk of breakage)
480
+ 3. Format your response EXACTLY as:
481
+ ## Complexity Analysis
482
+ - [CIRCULAR] {file A} ↔ {file B}: {description}
483
+ - [FAN-OUT] {file} → {N} dependents: {list top 5}
484
+ - [COUPLING] {file A} → {file B}: {not in Depends On column}
485
+ - [HIGH-RISK] {file}: {reason — most impactful if broken}
486
+ ## Risk Summary
487
+ Circular: {N}, High fan-out: {N}, Hidden coupling: {N}
488
+ 4. If no issues found, return: '## Complexity Analysis\nNo significant risks detected.'")
489
+ ```
490
+ 2. Store output to `.claude/afc/specs/{feature}/complexity-analysis.md`
491
+ 3. Implement phase reads this file → high-risk files get extra verification after modification
492
+ 4. If circular dependencies found → **ESCALATE** to user (circular deps in implementation plan are a design flaw)
493
+ 5. Increment `ADVISOR_COUNT`
494
+ 6. Progress: ` ├─ Skill Advisor [C]: analyze (score: {N}/5, circular: {C}, fan-out: {F}, coupling: {H})`
495
+
496
+ **If C2 >= 3** (Enrich):
497
+ 1. Determine which domain expert can best resolve the uncertainties (based on the nature of the open questions, not keywords)
498
+ 2. Invoke expert agent (look up the agent-id from the Expert Agent Routing table — do NOT construct from domain name):
499
+ ```
500
+ Task("Domain gap resolution: {domain}", subagent_type: "afc:{agent-id-from-routing-table}",
501
+ prompt: "Resolve domain uncertainties found during planning.
502
+
503
+ ## Uncertain Items
504
+ {extract all [UNCERTAIN] tagged items and open questions from plan.md}
505
+
506
+ ## Plan Context
507
+ {Implementation Context section from plan.md}
508
+
509
+ ## Instructions
510
+ 1. For each uncertain item, provide a definitive answer with rationale
511
+ 2. Format your response EXACTLY as:
512
+ ## Domain Resolutions
513
+ - [RESOLVED] {item}: {answer} — {rationale}
514
+ - [NEEDS-USER] {item}: {why this requires human judgment}
515
+ 3. Update your MEMORY.md with the resolution context")
516
+ ```
517
+ 3. Apply resolutions to plan.md Implementation Context (replace `[UNCERTAIN]` with `[RESOLVED: {answer}]`)
518
+ 4. `[NEEDS-USER]` items → **ESCALATE** to user via AskUserQuestion
519
+ 5. Increment `ADVISOR_COUNT`
520
+ 6. Progress: ` ├─ Skill Advisor [C]: consult({domain}) (score: {N}/5, {M} resolved, {K} needs-user)`
521
+
522
+ **If all scores < 3**: proceed silently to Phase 3.
523
+
251
524
  ### Phase 3: Implement (3/5)
252
525
 
253
- `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase implement`
526
+ `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" phase implement`
254
527
 
255
528
  **Session context reload**: At implement start, read `.claude/afc/specs/{feature}/context.md` if it exists. This restores key decisions and constraints from Plan phase (resilient to context compaction).
256
529
 
257
- Execute `/afc:implement` logic inline **follow all orchestration rules defined in `commands/implement.md`** (task generation, mode selection, batch/swarm execution, failure recovery, task execution pattern). The implement command is the single source of truth for orchestration details.
530
+ **Advisor context reload**: If Checkpoint C produced `.claude/afc/specs/{feature}/complexity-analysis.md`, read it and flag high-risk files (circular dependencies, high fan-out) for extra verification after modification during task execution.
531
+
532
+ Execute `/afc:implement` logic inline — **follow all orchestration rules defined in `skills/implement/SKILL.md`** (task generation, mode selection, batch/swarm execution, failure recovery, task execution pattern). The implement skill is the single source of truth for orchestration details.
258
533
 
259
534
  **Auto-specific additions** (beyond implement.md):
260
535
 
261
536
  #### Step 3.1: Task Generation + Validation
262
537
 
263
- 1. Generate tasks.md from plan.md File Change Map (as defined in implement.md Step 1.3)
538
+ 1. Generate tasks.md from plan.md File Change Map using the following format and principles:
539
+
540
+ **Task Format** (required):
541
+ ```markdown
542
+ - [ ] T{NNN} {[P]} {[US*]} {description} `{file path}` {depends: [TXXX, TXXX]}
543
+ ```
544
+ | Component | Required | Description |
545
+ |-----------|----------|-------------|
546
+ | `T{NNN}` | Yes | 3-digit sequential ID (T001, T002, ...) |
547
+ | `[P]` | No | **Mandatory parallel execution** — task MUST run in parallel with other [P] tasks in the same phase. Requires no file overlap. |
548
+ | `[US*]` | No | User Story label from spec.md |
549
+ | description | Yes | Clear task description (start with a verb) |
550
+ | file path | Yes | Primary target file (wrapped in backticks) |
551
+ | `depends:` | No | Explicit dependency list — task cannot start until all listed complete |
552
+
553
+ **Decomposition Principles**:
554
+ - **1 task = 1 file** principle (where possible)
555
+ - **Same file = sequential**, **different files = [P] candidate**
556
+ - **Explicit dependencies**: Use `depends: [T001, T002]` for blocking dependencies
557
+ - **Test tasks**: Include a verification task for each testable unit
558
+ - **Phase gate**: Add a `{config.gate}` validation task at the end of each Phase
559
+
560
+ **Phase Structure**: Group tasks by Phase (Setup → Core → UI → Integration & Polish)
561
+
562
+ **Coverage Mapping** (append after tasks):
563
+ ```markdown
564
+ ## Coverage Mapping
565
+ | Requirement | Tasks |
566
+ |-------------|-------|
567
+ | FR-001 | T003, T007 |
568
+ ```
569
+ Every FR-*/NFR-* must be mapped to at least one task.
570
+
264
571
  2. **Retrospective check**: if `.claude/afc/memory/retrospectives/` exists, load the **most recent 10 files** (sorted by filename descending) and check:
265
572
  - Were there previous parallel conflict issues ([P] file overlaps)? Flag similar file patterns.
266
573
  - Were there tasks that were over-decomposed or under-decomposed? Adjust granularity.
267
- 3. Script validation (DAG + parallel overlap) — no critic loop, script-based only
268
- 4. Progress: ` ├─ Tasks generated: {N} ({P} parallelizable)`
574
+ 3. **Script validation**: Run DAG validation (`afc-dag-validate.sh`) and parallel overlap validation (`afc-parallel-validate.sh`) — no critic loop, script-based only. Fix any conflicts before proceeding.
575
+ 4. Progress: ` ├─ Tasks generated: {N} ({P} parallelizable), Coverage: FR {M}%, NFR {K}%`
269
576
 
270
577
  #### Step 3.2: TDD Pre-Generation (conditional)
271
578
 
272
- `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase test-pre-gen`
579
+ `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" phase test-pre-gen`
273
580
 
274
581
  **Trigger condition**: tasks.md contains at least 1 task targeting a `.sh` file in `scripts/`.
275
582
 
276
583
  **If triggered**:
277
584
  1. Run the test pre-generation script:
278
585
  ```bash
279
- "${CLAUDE_PLUGIN_ROOT}/scripts/afc-test-pre-gen.sh" ".claude/afc/specs/{feature}/tasks.md" "spec/"
586
+ "${CLAUDE_SKILL_DIR}/../../scripts/afc-test-pre-gen.sh" ".claude/afc/specs/{feature}/tasks.md" "spec/"
280
587
  ```
281
588
  2. Review generated skeleton files — verify they are parseable:
282
589
  ```bash
@@ -291,14 +598,14 @@ Execute `/afc:implement` logic inline — **follow all orchestration rules defin
291
598
 
292
599
  #### Step 3.3: Blast Radius Analysis (conditional)
293
600
 
294
- `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase blast-radius`
601
+ `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" phase blast-radius`
295
602
 
296
603
  **Trigger condition**: plan.md File Change Map lists >= 3 files to change.
297
604
 
298
605
  **If triggered**:
299
606
  1. Run the blast radius analysis:
300
607
  ```bash
301
- "${CLAUDE_PLUGIN_ROOT}/scripts/afc-blast-radius.sh" ".claude/afc/specs/{feature}/plan.md" "${CLAUDE_PROJECT_DIR}"
608
+ "${CLAUDE_SKILL_DIR}/../../scripts/afc-blast-radius.sh" ".claude/afc/specs/{feature}/plan.md" "${CLAUDE_PROJECT_DIR}"
302
609
  ```
303
610
  2. If exit 1 (cycle detected): **ESCALATE** — present the cycle to user with options:
304
611
  - Option 1: Refactor plan to break the cycle
@@ -314,11 +621,11 @@ Execute `/afc:implement` logic inline — **follow all orchestration rules defin
314
621
  0. **Baseline test** (follows implement.md Step 1, item 5): if `{config.test}` is non-empty, run `{config.test}` before starting task execution. On failure, report pre-existing test failures to user and ask: "(1) Proceed anyway (2) Fix first (3) Abort". On pass or empty config, continue.
315
622
  1. Execute tasks phase by phase using implement.md orchestration rules (sequential/batch/swarm based on [P] count)
316
623
  2. **Implementation Context injection**: Every sub-agent prompt includes the `## Implementation Context` section from plan.md **and relevant FR/AC items from spec.md** (ensures spec intent propagates to workers)
317
- 3. Perform **3-step gate** on each Implementation Phase completion — **always** read `${CLAUDE_PLUGIN_ROOT}/docs/phase-gate-protocol.md` first. Cannot advance to next phase without passing the gate.
318
- - On gate pass: create phase rollback point `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase-tag {phase_number}`
624
+ 3. Perform **3-4 step gate** on each Implementation Phase completion — **always** read `${CLAUDE_SKILL_DIR}/../../docs/phase-gate-protocol.md` first. Cannot advance to next phase without passing the gate.
625
+ - On gate pass: create phase rollback point `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" phase-tag {phase_number}`
319
626
  4. Real-time `[x]` updates in tasks.md
320
627
  5. After full completion, run `{config.ci}` final verification
321
- - On pass: `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" ci-pass` (releases Stop Gate)
628
+ - On pass: `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" ci-pass` (releases Stop Gate)
322
629
  - **On fail: Debug-based RCA** (replaces blind retry):
323
630
  1. Execute `/afc:debug` logic inline with the CI error output as input
324
631
  2. Debug performs RCA: error trace → data flow → hypothesis → targeted fix
@@ -349,7 +656,7 @@ Execute `/afc:implement` logic inline — **follow all orchestration rules defin
349
656
 
350
657
  #### Step 3.6: Implement Critic Loop
351
658
 
352
- > **Always** read `${CLAUDE_PLUGIN_ROOT}/docs/critic-loop-rules.md` first and follow it.
659
+ > **Always** read `${CLAUDE_SKILL_DIR}/../../docs/critic-loop-rules.md` first and follow it.
353
660
 
354
661
  **Critic Loop until convergence** (safety cap: 5, follow Critic Loop rules):
355
662
  - **SCOPE_ADHERENCE**: Compare `git diff` changed files against plan.md File Change Map. Flag any file modified that is NOT in the plan. Flag any planned file NOT modified. Provide "M of N files match" count.
@@ -367,77 +674,338 @@ Execute `/afc:implement` logic inline — **follow all orchestration rules defin
367
674
  7. **Checkpoint**: phase transition already recorded by `afc-pipeline-manage.sh phase implement` at phase start
368
675
  8. Progress: `✓ 3/5 Implement complete ({completed}/{total} tasks, CI: ✓, Critic: converged ({N} passes, {M} fixes, {E} escalations))`
369
676
 
370
- ### Phase 4: Review (4/5)
677
+ ### Skill Advisor Checkpoint D (Post-Implement)
371
678
 
372
- `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase review`
679
+ > Evaluate auxiliary skill triggers AFTER implementation, BEFORE review. Budget: max 2 skills. Skip all if `ADVISOR_COUNT >= 5`.
373
680
 
374
- Execute `/afc:review` logic inline **follow all review perspectives defined in `commands/review.md`** (A through H). The review command is the single source of truth for review criteria.
681
+ **Intent evaluation**Examine the implementation results and answer these questions:
375
682
 
376
- **Context reload**: Re-read `.claude/afc/specs/{feature}/context.md` (contains full AC) and `.claude/afc/specs/{feature}/spec.md` to ensure spec context is available for SPEC_ALIGNMENT validation (these may have been compacted since Phase 1).
683
+ | # | Question | Score 1–5 | If >= 3 | Skill | Mode |
684
+ |---|----------|-----------|---------|-------|------|
685
+ | D1 | Were **testable source files changed without corresponding test coverage**? Look at `git diff --name-only` — for each changed source file, does a test file covering its behavior also appear in the diff? Consider the project's test convention and whether the changed files contain logic that should be tested (skip config files, types-only files, static assets). Only evaluate if `{config.test}` is non-empty. | 1=all changes have test coverage, 5=critical logic changed with zero tests | test generation (general-purpose fork) | Enrich |
686
+ | D2 | Based on **past pipeline quality data**, is there reason to believe this implementation has hidden quality issues? Check `.claude/afc/memory/quality-history/*.json` (if exists) — have recent pipelines shown elevated critical findings? Are there recurring problem categories that this feature's changed files might be susceptible to? | 1=clean history or no history, 5=strong pattern of recurring issues in similar areas | pre-review QA (general-purpose fork) | Observe |
377
687
 
378
- 1. Review implemented changed files (`git diff HEAD`)
379
- 2. **Specialist agent delegation** (parallel, perspectives B and C):
380
- Launch architect and security agents in a **single message** to leverage their persistent memory:
688
+ **If D1 >= 3 AND `{config.test}` is non-empty** (Enrich — skip if no test framework configured):
689
+ 1. Identify which changed source files lack test coverage — focus on files with meaningful logic (not config, not types, not assets):
381
690
  ```
382
- Task("Architecture Review: {feature}", subagent_type: "afc:afc-architect",
383
- prompt: "Review the following changed files for architecture compliance.
384
-
385
- ## Changed Files
386
- {list of changed files from git diff}
691
+ For each changed source file:
692
+ - Does the project have a test file for it? (check test directory patterns)
693
+ - Was that test file also modified in this diff?
694
+ - Does the source file contain testable exports? (functions, classes, handlers)
695
+ List files that have testable logic but no test coverage in this diff
696
+ ```
697
+ 2. Invoke test generation (fork):
698
+ ```
699
+ Task("Coverage boost: {feature}", subagent_type: "general-purpose",
700
+ prompt: "Generate missing tests for recently implemented files.
387
701
 
388
- ## Architecture Rules
389
- {config.architecture}
702
+ ## Uncovered Files (testable logic, no test changes in this diff)
703
+ {list of uncovered source files with their full paths}
390
704
 
391
705
  ## Instructions
392
- 1. Read your MEMORY.md for prior architecture patterns and ADRs
393
- 2. Check each file against architecture rules (layer boundaries, naming, placement)
394
- 3. Cross-reference with ADRs recorded during Plan phase — any violations?
395
- 4. Return findings as: severity (Critical/Warning/Info), file:line, issue, suggested fix
396
- 5. Update your MEMORY.md with any new architecture patterns discovered")
706
+ 1. Read each uncovered file to understand its exports and behavior
707
+ 2. Read existing test files in the project for pattern reference
708
+ 3. Generate unit tests targeting:
709
+ - Exported functions/classes
710
+ - Edge cases and error paths
711
+ - Integration points (if the file calls other changed files)
712
+ 4. Follow the project's test framework: {config.test framework}
713
+ 5. Place test files following project convention
714
+ 6. Run {config.test} to verify tests pass
715
+ 7. Return: files created, test count, pass/fail status")
716
+ ```
717
+ 3. New test files automatically enter review scope (Phase 4)
718
+ 4. Increment `ADVISOR_COUNT`
719
+ 5. Progress: ` ├─ Skill Advisor [D]: test (score: {N}/5, {M} uncovered files → {K} test files generated)`
397
720
 
398
- Task("Security Review: {feature}", subagent_type: "afc:afc-security",
399
- prompt: "Scan the following changed files for security vulnerabilities.
721
+ **If D2 >= 3** (Observe):
722
+ 1. Load `.claude/afc/memory/quality-history/*.json` (most recent 3 files, sorted by filename descending)
723
+ 2. Identify recurring problem categories and which changed files are most at risk:
724
+ ```
725
+ Task("Pre-review QA: {feature}", subagent_type: "general-purpose",
726
+ prompt: "Perform a pre-review quality audit focused on historically problematic areas.
400
727
 
401
728
  ## Changed Files
402
- {list of changed files from git diff}
729
+ {git diff --name-only}
730
+
731
+ ## Quality History Context
732
+ {summary of patterns from recent quality-history reports — categories, frequencies, affected file types}
403
733
 
404
734
  ## Instructions
405
- 1. Read your MEMORY.md for known vulnerability patterns and false positives
406
- 2. Check for: command injection, path traversal, unvalidated input, sensitive data exposure
407
- 3. Skip patterns recorded as false positives in your memory
408
- 4. Return findings as: severity (Critical/Warning/Info), file:line, issue, suggested fix
409
- 5. Update your MEMORY.md with new patterns or confirmed false positives")
410
- ```
411
- - Collect agent outputs and merge into the consolidated review
412
- - Agent findings inherit their severity classification directly
413
- 3. Check across **8 perspectives** (A-H as defined in review.md):
414
- - A. Code Quality `{config.code_style}` compliance (direct review)
415
- - B. Architecture **delegated to afc-architect agent** (persistent memory, ADR-aware)
416
- - C. Security — **delegated to afc-security agent** (persistent memory, false-positive-aware)
417
- - D. Performance framework-specific patterns from Project Context (direct review)
418
- - E. Project Pattern Compliance — conventions and idioms (direct review)
419
- - **F. Reusability** DRY, shared utilities, abstraction level (direct review)
420
- - **G. Maintainability** — AI/human comprehension, naming clarity, self-contained files (direct review)
421
- - **H. Extensibility** extension points, OCP, future modification cost (direct review)
422
- 4. **Auto-resolved validation**: Check all `[AUTO-RESOLVED]` items from spec phase — does the implementation match the guess? Flag mismatches as Critical.
423
- 5. **Past reviews check**: if `.claude/afc/memory/reviews/` exists, load the **most recent 15 files** (sorted by filename descending) and scan for recurring finding patterns across past review reports. Prioritize those areas.
424
- 6. **Retrospective check**: if `.claude/afc/memory/retrospectives/` exists, load the **most recent 10 files** (sorted by filename descending) and check:
735
+ 1. Focus on the recurring problem categories identified above
736
+ 2. Check: error handling completeness, input validation, resource cleanup
737
+ 3. Format your response EXACTLY as:
738
+ ## Pre-Review QA Findings
739
+ - [{severity}] {file}:{line} {issue}: {suggested fix}
740
+ ## Priority Hints for Review
741
+ - {file}: focus on {area} (historically problematic)
742
+ 4. Read-only do NOT modify any files")
743
+ ```
744
+ 3. Store output as `QA_FINDINGS` injected into Phase 4 review context
745
+ 4. Review phase uses "Priority Hints" to focus attention
746
+ 5. Increment `ADVISOR_COUNT`
747
+ 6. Progress: ` ├─ Skill Advisor [D]: qa (score: {N}/5, {M} priority hints for review)`
748
+
749
+ **If all scores < 3**: proceed silently to Phase 4.
750
+
751
+ ### Phase 4: Review (4/5)
752
+
753
+ `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" phase review`
754
+
755
+ Execute `/afc:review` logic inline — **follow all review perspectives defined in `skills/review/SKILL.md`** (A through H). The review skill is the single source of truth for review criteria.
756
+
757
+ **Context reload**: Re-read `.claude/afc/specs/{feature}/context.md` (contains full AC) and `.claude/afc/specs/{feature}/spec.md` to ensure spec context is available for SPEC_ALIGNMENT validation (these may have been compacted since Phase 1).
758
+
759
+ #### Step 4.1: Collect Review Targets
760
+
761
+ 1. Collect changed files via `git diff HEAD`
762
+ 2. Read **full content** of each changed file (not just the diff — full context needed for review)
763
+
764
+ #### Step 4.2: Reverse Impact Analysis
765
+
766
+ Before reviewing, identify **files affected by the changes** (not just the changed files themselves):
767
+
768
+ 1. **For each changed file**, find files that depend on it:
769
+ - **LSP (preferred)**: `LSP(findReferences)` on exported symbols — tracks type references, function calls, re-exports
770
+ - **Grep (fallback)**: `Grep` for `import.*{filename}`, `require.*{filename}`, `source.*{filename}` patterns across the codebase
771
+ - LSP and Grep are complementary — use both when LSP is available
772
+
773
+ 2. **Build impact map**:
774
+ ```
775
+ Impact Map:
776
+ ├─ src/auth/login.ts (changed)
777
+ │ └─ affected: src/pages/LoginPage.tsx, src/middleware/auth.ts
778
+ └─ Total: {N} changed files → {M} affected files
779
+ ```
780
+
781
+ 3. **Scope decision**: Affected files are NOT full review targets. Include them as **cross-reference context** in review and cross-boundary verification. If an affected file has >3 references to a changed symbol → flag for closer inspection.
782
+
783
+ 4. **Limitations** (include in review output):
784
+ > ⚠ Dynamic dependencies not covered: runtime dispatch, reflection, cross-language calls, config/env-driven branching.
785
+
786
+ #### Step 4.3: Scaled Review Orchestration
787
+
788
+ Choose review orchestration based on the number of changed files:
789
+
790
+ **Pre-scan: Call Chain Context** (for Parallel Batch and Review Swarm modes only):
791
+ Before distributing files to review agents, collect cross-boundary context:
792
+ 1. For each changed file, identify **outbound calls** to other changed files (imports + function calls)
793
+ 2. For each outbound call target, extract: function signature + 1-line side-effect summary
794
+ 3. Include the **Impact Map** from Step 4.2 — each agent receives the list of affected files
795
+ 4. Include this context in each review agent's prompt as `## Cross-File Context`
796
+
797
+ For Direct review mode (≤5 files): skip pre-scan — orchestrator already has full context.
798
+
799
+ **5 or fewer files**: Direct review — review all files directly in the current context (no delegation).
800
+
801
+ **6–10 files**: Parallel Batch — distribute to parallel review agents (2–3 files per agent) in a **single message**:
802
+ ```
803
+ Task("Review: {file1, file2}", subagent_type: "general-purpose")
804
+ Task("Review: {file3, file4}", subagent_type: "general-purpose")
805
+ ```
806
+
807
+ **11+ files**: Review Swarm — group files into batches (2-3 per worker), spawn N review workers in a **single message** (N = min(5, file count / 2)). Review is read-only — no write race conditions.
808
+
809
+ #### Step 4.4: Specialist Agent Delegation (parallel, perspectives B and C)
810
+
811
+ Launch architect and security agents in a **single message** to leverage their persistent memory:
812
+ ```
813
+ Task("Architecture Review: {feature}", subagent_type: "afc:afc-architect",
814
+ prompt: "Review the following changed files for architecture compliance.
815
+
816
+ ## Changed Files
817
+ {list of changed files from git diff}
818
+
819
+ ## Architecture Rules
820
+ {config.architecture}
821
+
822
+ ## Instructions
823
+ 1. Read your MEMORY.md for prior architecture patterns and ADRs
824
+ 2. Check each file against architecture rules (layer boundaries, naming, placement)
825
+ 3. Cross-reference with ADRs recorded during Plan phase — any violations?
826
+ 4. Return findings as: severity (Critical/Warning/Info), file:line, issue, suggested fix
827
+ 5. Update your MEMORY.md with any new architecture patterns discovered")
828
+
829
+ Task("Security Review: {feature}", subagent_type: "afc:afc-security",
830
+ prompt: "Scan the following changed files for security vulnerabilities.
831
+
832
+ ## Changed Files
833
+ {list of changed files from git diff}
834
+
835
+ ## Instructions
836
+ 1. Read your MEMORY.md for known vulnerability patterns and false positives
837
+ 2. Check for: command injection, path traversal, unvalidated input, sensitive data exposure
838
+ 3. Skip patterns recorded as false positives in your memory
839
+ 4. Return findings as: severity (Critical/Warning/Info), file:line, issue, suggested fix
840
+ 5. Include any new vulnerability patterns or confirmed false positives in your response (orchestrator will record them)")
841
+ ```
842
+ - Collect agent outputs and merge into the consolidated review
843
+ - Agent findings inherit their severity classification directly
844
+
845
+ #### Step 4.5: Perform Review (8 perspectives)
846
+
847
+ Check across **8 perspectives** (A-H as defined in `skills/review/SKILL.md`):
848
+ - A. Code Quality — `{config.code_style}` compliance (direct review)
849
+ - B. Architecture — **delegated to afc-architect agent** (persistent memory, ADR-aware)
850
+ - C. Security — **delegated to afc-security agent** (persistent memory, false-positive-aware)
851
+ - D. Performance — framework-specific patterns from Project Context (direct review)
852
+ - E. Project Pattern Compliance — conventions and idioms (direct review)
853
+ - **F. Reusability** — DRY, shared utilities, abstraction level (direct review)
854
+ - **G. Maintainability** — AI/human comprehension, naming clarity, self-contained files (direct review)
855
+ - **H. Extensibility** — extension points, OCP, future modification cost (direct review)
856
+
857
+ #### Step 4.6: Cross-Boundary Verification (MANDATORY)
858
+
859
+ After individual/parallel reviews and specialist agents complete, the **orchestrator** MUST perform a cross-boundary check. This is a required step, not optional — skipping it is a review defect.
860
+
861
+ **For High complexity (Review Swarm) reviews**: This is especially critical because individual review agents cannot see cross-file interactions. The orchestrator MUST read callee implementations directly.
862
+
863
+ 0. **Impact Map integration**: Use the Impact Map from Step 4.2 to prioritize verification. Affected files with significant coupling to changed symbols (behavioral call references, not just type imports, especially in critical code paths) should be read and checked for breakage — even if no finding was raised against them.
864
+
865
+ 1. **Filter**: From all collected findings, select those involving:
866
+ - Call order changes (function A now calls B before C)
867
+ - Error handling modifications (try/catch scope changes, error propagation changes)
868
+ - State mutation changes (new writes to shared state, removed cleanup)
869
+
870
+ 2. **Verify**: For each behavioral finding rated Critical or Warning:
871
+ - **Read the callee's implementation** (the function/method being called) — this read is mandatory, not optional
872
+ - **Skip external dependencies**: If the callee is in `node_modules/`, `vendor/`, or other third-party directories, verify against type definitions or documented API contract instead. Note: "verified against types/docs, not source"
873
+ - Check: does the callee's internal behavior (side effects, state changes, return values) actually conflict with the change?
874
+ - If no conflict → downgrade: Critical → Info, Warning → Info (append "verified: no cross-boundary impact")
875
+ - If confirmed conflict → keep severity, enrich description with callee behavior details
876
+
877
+ 3. **False positive reference** (security-related findings only): Check `afc-security` agent's MEMORY.md `## False Positives` section if it exists. Known false positive patterns should be noted in findings.
878
+
879
+ 4. **Output**: Append verification summary before Review Output:
880
+ ```
881
+ Cross-Boundary Check: {N} behavioral findings verified
882
+ ├─ Confirmed: {M} (severity kept)
883
+ ├─ Downgraded: {K} (false positive — callee compatible)
884
+ └─ Skipped: {J} (no behavioral change)
885
+ ```
886
+
887
+ This step runs in the orchestrator context (not delegated), as it requires reading code across file boundaries.
888
+
889
+ #### Step 4.7: Inject Advisor Context
890
+
891
+ If Checkpoint D produced outputs, inject them into the review context:
892
+ - **`QA_FINDINGS`** (from D2): read the stored findings and include as "Priority Hints for Review" — focus review attention on historically problematic areas and pre-identified quality concerns.
893
+ - **New test files** (from D1): include in the review scope alongside implementation changes.
894
+
895
+ #### Step 4.8: Auto-specific Validations
896
+
897
+ 1. **Auto-resolved validation**: Check all `[AUTO-RESOLVED]` items from spec phase — does the implementation match the guess? Flag mismatches as Critical.
898
+ 2. **Past reviews check**: if `.claude/afc/memory/reviews/` exists, load the **most recent 15 files** (sorted by filename descending) and scan for recurring finding patterns across past review reports. Prioritize those areas.
899
+ 3. **Retrospective check**: if `.claude/afc/memory/retrospectives/` exists, load the **most recent 10 files** (sorted by filename descending) and check:
425
900
  - Were there recurring Critical finding categories in past reviews? Prioritize those perspectives.
426
901
  - Were there false positives that wasted effort? Reduce sensitivity for those patterns.
427
- 7. **Critic Loop until convergence** (safety cap: 5, follow Critic Loop rules):
428
- - COMPLETENESS: were all changed files reviewed across all 8 perspectives (A-H)?
429
- - SPEC_ALIGNMENT: cross-check implementation against spec.md — (1) every SC verified with `{M}/{N}` count, (2) every acceptance scenario (GWT) has corresponding code path, (3) no spec constraint is violated
430
- - PRECISION: are there unnecessary changes? Are there out-of-scope modifications?
431
- - FAIL → auto-fix and continue. ESCALATE → pause, present options, resume after response. DEFER → record reason, mark clean.
432
- 8. **Handling SC shortfalls**:
433
- - Fixable attempt auto-fix re-run `{config.ci}` verification
434
- - Not fixable state in final report with reason (no post-hoc rationalization; record as Plan-phase target-setting error)
435
- 9. **Checkpoint**: phase transition already recorded by `afc-pipeline-manage.sh phase review` at phase start
436
- 10. Progress: `✓ 4/5 Review complete (Critical:{N} Warning:{N} Info:{N}, SC shortfalls: {N})`
902
+
903
+ #### Step 4.9: Critic Loop
904
+
905
+ > **Always** read `${CLAUDE_SKILL_DIR}/../../docs/critic-loop-rules.md` first and follow it.
906
+
907
+ **Critic Loop until convergence** (safety cap: 5, follow Critic Loop rules):
908
+ - COMPLETENESS: were all changed files reviewed across all 8 perspectives (A-H)?
909
+ - SPEC_ALIGNMENT: cross-check implementation against spec.md (1) every SC verified with `{M}/{N}` count, (2) every acceptance scenario (GWT) has corresponding code path, (3) no spec constraint is violated
910
+ - SIDE_EFFECT_AWARENESS: For findings involving call order changes, error handling modifications, or state mutation changes: did the reviewer verify the callee's internal behavior? If a Critical finding assumes a side effect without reading the target implementation → auto-downgrade to Info with note "cross-boundary unverified". Provide "{M} of {N} behavioral findings verified" count.
911
+ - PRECISION: are there unnecessary changes? Are there out-of-scope modifications? Are findings actual issues, not false positives?
912
+ - FAIL → auto-fix and continue. ESCALATE → pause, present options, resume after response. DEFER → record reason, mark clean.
913
+
914
+ #### Step 4.10: Handling SC shortfalls
915
+
916
+ - Fixable → attempt auto-fix → re-run `{config.ci}` verification
917
+ - Not fixable → state in final report with reason (no post-hoc rationalization; record as Plan-phase target-setting error)
918
+
919
+ #### Step 4.11: Retrospective Entry (if new pattern found)
920
+
921
+ If this review reveals a recurring pattern not previously documented in `.claude/afc/memory/retrospectives/`:
922
+
923
+ Append to `.claude/afc/memory/retrospectives/{YYYY-MM-DD}.md`:
924
+ ```markdown
925
+ ## Pattern: {category}
926
+ **What happened**: {concrete description}
927
+ **Root cause**: {why this keeps occurring}
928
+ **Prevention rule**: {actionable rule — usable in future plan/implement phases}
929
+ **Severity**: Critical | Warning
930
+ ```
931
+
932
+ Only write if the pattern is new and actionable. Generic observations are prohibited.
933
+
934
+ #### Step 4.12: Archive Review Report
935
+
936
+ Persist the review results for memory:
937
+
938
+ 1. Write full review output (Summary table + Impact Analysis + Detailed Findings + Positives + Cross-Boundary Check) to `.claude/afc/specs/{feature}/review-report.md`
939
+ 2. Include metadata header:
940
+ ```markdown
941
+ # Review Report: {feature name}
942
+ > Date: {YYYY-MM-DD}
943
+ > Files reviewed: {count}
944
+ > Findings: Critical {N} / Warning {N} / Info {N}
945
+ ```
946
+ 3. This file is copied to `.claude/afc/memory/reviews/{feature}-{date}.md` during Clean phase before .claude/afc/specs/ deletion.
947
+
948
+ #### Step 4.12: Checkpoint & Progress
949
+
950
+ - **Checkpoint**: phase transition already recorded by `afc-pipeline-manage.sh phase review` at phase start
951
+ - Progress: `✓ 4/5 Review complete (Critical:{N} Warning:{N} Info:{N}, Cross-boundary: {M} verified, SC shortfalls: {N})`
952
+
953
+ ### Skill Advisor Checkpoint E (Post-Review)
954
+
955
+ > Evaluate auxiliary skill triggers AFTER review, BEFORE clean. Budget: max 1 skill. Skip all if `ADVISOR_COUNT >= 5`.
956
+
957
+ **Intent evaluation** — Examine review findings and retrospective history:
958
+
959
+ | # | Question | Score 1–5 | If >= 3 | Skill | Mode |
960
+ |---|----------|-----------|---------|-------|------|
961
+ | E1 | Are there **recurring problem patterns** across this and past pipelines that should be codified as project rules? Check `.claude/afc/memory/retrospectives/` — do the same types of issues (e.g., "missing error handling in hooks", "forgotten spec file updates") keep appearing? Also consider: did this pipeline's review reveal issues that match past retrospective patterns? | 1=no retrospective history or no patterns, 5=same issue type recurred 3+ times and is not yet a project rule | pattern promotion (general-purpose fork, with learner guardrails) | Observe |
962
+
963
+ **If E1 >= 3** (Observe):
964
+ 1. Read retrospective files and identify recurring pattern categories:
965
+ - What types of issues keep recurring?
966
+ - Are they already covered by existing rules in `.claude/rules/afc-learned.md`?
967
+ - Would a project rule have prevented the recurrence?
968
+ 2. Invoke learner:
969
+ ```
970
+ Task("Pattern promotion: {feature}", subagent_type: "general-purpose",
971
+ prompt: "Review recurring patterns for potential promotion to project rules.
972
+
973
+ ## Recurring Patterns
974
+ {list each pattern with: category, occurrence count, concrete examples from retrospective entries}
975
+
976
+ ## Current Review Findings
977
+ {summary of this pipeline's review findings that match retrospective patterns}
978
+
979
+ ## Current Rules
980
+ {read .claude/rules/afc-learned.md if it exists, else 'No learned rules yet'}
981
+
982
+ ## Instructions
983
+ 1. For each recurring pattern, evaluate:
984
+ - Is it actionable? (specific enough to enforce)
985
+ - Is it already covered by existing rules?
986
+ - Would enforcing it have prevented the recurrence?
987
+ 2. For patterns worth promoting, write a rule in this format:
988
+ ### {Category}
989
+ - **Rule**: {concise, enforceable statement}
990
+ - **Rationale**: {why — based on {N} occurrences across pipelines}
991
+ - **Enforcement**: {how to check — linter, review criterion, or convention}
992
+ 3. **Safety guardrails** (mandatory):
993
+ - Do NOT create rules about: permissions, security policies, hook behavior, tool access
994
+ - Do NOT create rules that contradict existing CLAUDE.md or .claude/rules/ content
995
+ - Each rule must be scoped to code conventions only (naming, style, workflow, testing, architecture)
996
+ - Verify no duplicate or contradictory rule exists before appending
997
+ 4. Append new rules to .claude/rules/afc-learned.md (create if absent)
998
+ 5. Do NOT duplicate existing rules
999
+ 6. Return: {N} patterns evaluated, {M} promoted, {K} already covered")
1000
+ ```
1001
+ 3. Increment `ADVISOR_COUNT`
1002
+ 4. Progress: ` ├─ Skill Advisor [E]: learner (score: {N}/5, {M} patterns evaluated, {K} promoted to rules)`
1003
+
1004
+ **If score < 3**: proceed silently to Phase 5.
437
1005
 
438
1006
  ### Phase 5: Clean (5/5)
439
1007
 
440
- `"${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" phase clean`
1008
+ `"${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" phase clean`
441
1009
 
442
1010
  Artifact cleanup and codebase hygiene check after implementation and review:
443
1011
 
@@ -460,23 +1028,24 @@ Artifact cleanup and codebase hygiene check after implementation and review:
460
1028
  - **If retrospective.md exists** → record as patterns missed by the Plan phase Critic Loop in `.claude/afc/memory/retrospectives/` (reuse as RISK checklist items in future runs)
461
1029
  - **If review-report.md exists** → copy to `.claude/afc/memory/reviews/{feature}-{date}.md` before .claude/afc/specs/ deletion
462
1030
  - **If research.md exists** and was not already persisted in Plan phase → copy to `.claude/afc/memory/research/{feature}.md`
463
- - **Agent memory consolidation**: architect and security agents have already updated their persistent MEMORY.md during Review phase. **Size enforcement**: check each agent's MEMORY.md line count if either exceeds 100 lines, invoke the respective agent to self-prune:
1031
+ - **Agent memory consolidation**: Check each agent's MEMORY.md for bloat if it contains redundant, obsolete, or superseded entries that reduce signal-to-noise ratio, invoke the agent to self-prune:
464
1032
  ```
465
1033
  Task("Memory cleanup: afc-architect", subagent_type: "afc:afc-architect",
466
- prompt: "Your MEMORY.md exceeds 100 lines. Read it, prune old/redundant entries, and rewrite to under 100 lines following your size limit rules.")
1034
+ prompt: "Review your MEMORY.md. Read it, identify and prune old/redundant/obsolete entries, and rewrite it keeping only entries that are still relevant and non-overlapping.")
467
1035
  ```
468
- (Same pattern for afc-security if needed. Skip if both are under 100 lines.)
469
- - **Memory rotation**: for each memory subdirectory, check file count and prune oldest files if over threshold:
470
- | Directory | Threshold | Action |
471
- |-----------|-----------|--------|
472
- | `quality-history/` | 30 files | Delete oldest files beyond threshold |
473
- | `reviews/` | 40 files | Delete oldest files beyond threshold |
474
- | `retrospectives/` | 30 files | Delete oldest files beyond threshold |
475
- | `research/` | 50 files | Delete oldest files beyond threshold |
476
- | `decisions/` | 60 files | Delete oldest files beyond threshold |
477
- - Sort by filename ascending (oldest first), delete excess
1036
+ Use semantic assessment (are entries still relevant? do entries overlap?) rather than a line-count threshold. (Same pattern for afc-security if needed.)
1037
+ - **Memory rotation**: For each memory subdirectory, assess whether the oldest files still provide value. Prune files that are superseded by newer entries, reference features/code that no longer exists, or overlap with other files. As a practical guideline, keep the most recent and relevant entries — if a directory has grown large enough that scanning it would be slow (roughly 30+ files), prioritize pruning the least relevant entries:
1038
+ | Directory | Pruning Intent | Soft Guideline |
1039
+ |-----------|---------------|----------------|
1040
+ | `quality-history/` | Remove superseded or redundant quality records | ~30 files |
1041
+ | `reviews/` | Remove reviews for features no longer in the codebase | ~40 files |
1042
+ | `retrospectives/` | Remove retrospectives whose learnings are already captured elsewhere | ~30 files |
1043
+ | `research/` | Remove research for libraries/patterns no longer used | ~50 files |
1044
+ | `decisions/` | Remove decisions that have been reversed or are no longer relevant | ~60 files |
1045
+ - These numbers are soft guidelines, not hard cutoffs — use judgment based on relevance
1046
+ - Sort by filename ascending (oldest first) when pruning by recency
478
1047
  - Log: `"Memory rotation: {dir} pruned {N} files"`
479
- - Skip directories that do not exist or are under threshold
1048
+ - Skip directories that do not exist or clearly do not need pruning
480
1049
  5. **Quality report** (structured pipeline metrics):
481
1050
  - Generate `.claude/afc/memory/quality-history/{feature}-{date}.json` with the following structure:
482
1051
  ```json
@@ -509,11 +1078,11 @@ Artifact cleanup and codebase hygiene check after implementation and review:
509
1078
  - Clear `.claude/afc/memory/checkpoint.md` **and** `~/.claude/projects/{ENCODED_PATH}/memory/checkpoint.md` (pipeline complete = session goal achieved, dual-delete prevents stale checkpoint in either location; `ENCODED_PATH` = project path with `/` replaced by `-`)
510
1079
  7. **Timeline finalize**:
511
1080
  ```bash
512
- "${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" log pipeline-end "Pipeline complete: {feature}"
1081
+ "${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" log pipeline-end "Pipeline complete: {feature}"
513
1082
  ```
514
1083
  8. **Release Pipeline Flag** (hook integration):
515
1084
  ```bash
516
- "${CLAUDE_PLUGIN_ROOT}/scripts/afc-pipeline-manage.sh" end
1085
+ "${CLAUDE_SKILL_DIR}/../../scripts/afc-pipeline-manage.sh" end
517
1086
  ```
518
1087
  - Stop Gate Hook deactivated
519
1088
  - Change tracking log deleted
@@ -536,6 +1105,8 @@ Auto pipeline complete: {feature}
536
1105
  │ ├─ Perspectives: Quality, Architecture*, Security*, Performance, Patterns, Reusability, Maintainability, Extensibility
537
1106
  │ └─ (* = delegated to persistent-memory agent)
538
1107
  ├─ 5/5 Clean: {N} artifacts deleted, {N} dead code removed
1108
+ ├─ Skill Advisor: {ADVISOR_COUNT} auxiliary skills invoked
1109
+ │ {for each invoked: ├─ [{checkpoint}] {skill}: {summary}}
539
1110
  ├─ Changed files: {N}
540
1111
  ├─ Auto-resolved: {N} ({M} validated in review)
541
1112
  ├─ Agent memory: architect {updated/skipped}, security {updated/skipped}