code-yangzz 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/README.md +102 -0
  2. package/agents/meta-artisan.md +164 -0
  3. package/agents/meta-conductor.md +482 -0
  4. package/agents/meta-genesis.md +165 -0
  5. package/agents/meta-librarian.md +213 -0
  6. package/agents/meta-prism.md +268 -0
  7. package/agents/meta-scout.md +173 -0
  8. package/agents/meta-sentinel.md +161 -0
  9. package/agents/meta-warden.md +304 -0
  10. package/bin/install.js +390 -0
  11. package/bin/lib/utils.js +72 -0
  12. package/bin/lib/watermark.js +176 -0
  13. package/config/CLAUDE.md +363 -0
  14. package/config/settings.json +120 -0
  15. package/hooks/block-dangerous-bash.mjs +36 -0
  16. package/hooks/post-console-log-warn.mjs +27 -0
  17. package/hooks/post-format.mjs +24 -0
  18. package/hooks/post-typecheck.mjs +27 -0
  19. package/hooks/pre-git-push-confirm.mjs +19 -0
  20. package/hooks/stop-completion-guard.mjs +159 -0
  21. package/hooks/stop-console-log-audit.mjs +44 -0
  22. package/hooks/subagent-context.mjs +27 -0
  23. package/hooks/user-prompt-submit.js +233 -0
  24. package/package.json +36 -0
  25. package/prompt-optimizer/prompt-optimizer-meta.md +159 -0
  26. package/skills/agent-teams/SKILL.md +215 -0
  27. package/skills/domains/ai/SKILL.md +34 -0
  28. package/skills/domains/ai/agent-dev.md +242 -0
  29. package/skills/domains/ai/llm-security.md +288 -0
  30. package/skills/domains/ai/prompt-and-eval.md +279 -0
  31. package/skills/domains/ai/rag-system.md +542 -0
  32. package/skills/domains/architecture/SKILL.md +42 -0
  33. package/skills/domains/architecture/api-design.md +225 -0
  34. package/skills/domains/architecture/caching.md +298 -0
  35. package/skills/domains/architecture/cloud-native.md +285 -0
  36. package/skills/domains/architecture/message-queue.md +328 -0
  37. package/skills/domains/architecture/security-arch.md +297 -0
  38. package/skills/domains/data-engineering/SKILL.md +207 -0
  39. package/skills/domains/development/SKILL.md +46 -0
  40. package/skills/domains/development/cpp.md +246 -0
  41. package/skills/domains/development/go.md +323 -0
  42. package/skills/domains/development/java.md +277 -0
  43. package/skills/domains/development/python.md +288 -0
  44. package/skills/domains/development/rust.md +313 -0
  45. package/skills/domains/development/shell.md +313 -0
  46. package/skills/domains/development/typescript.md +277 -0
  47. package/skills/domains/devops/SKILL.md +39 -0
  48. package/skills/domains/devops/cost-optimization.md +271 -0
  49. package/skills/domains/devops/database.md +217 -0
  50. package/skills/domains/devops/devsecops.md +198 -0
  51. package/skills/domains/devops/git-workflow.md +181 -0
  52. package/skills/domains/devops/observability.md +279 -0
  53. package/skills/domains/devops/performance.md +335 -0
  54. package/skills/domains/devops/testing.md +283 -0
  55. package/skills/domains/frontend-design/SKILL.md +38 -0
  56. package/skills/domains/frontend-design/agents/openai.yaml +4 -0
  57. package/skills/domains/frontend-design/claymorphism/SKILL.md +119 -0
  58. package/skills/domains/frontend-design/claymorphism/references/tokens.css +52 -0
  59. package/skills/domains/frontend-design/component-patterns.md +202 -0
  60. package/skills/domains/frontend-design/engineering.md +287 -0
  61. package/skills/domains/frontend-design/glassmorphism/SKILL.md +140 -0
  62. package/skills/domains/frontend-design/glassmorphism/references/tokens.css +32 -0
  63. package/skills/domains/frontend-design/liquid-glass/SKILL.md +137 -0
  64. package/skills/domains/frontend-design/liquid-glass/references/tokens.css +81 -0
  65. package/skills/domains/frontend-design/neubrutalism/SKILL.md +143 -0
  66. package/skills/domains/frontend-design/neubrutalism/references/tokens.css +44 -0
  67. package/skills/domains/frontend-design/state-management.md +680 -0
  68. package/skills/domains/frontend-design/ui-aesthetics.md +110 -0
  69. package/skills/domains/frontend-design/ux-principles.md +156 -0
  70. package/skills/domains/infrastructure/SKILL.md +200 -0
  71. package/skills/domains/mobile/SKILL.md +224 -0
  72. package/skills/domains/orchestration/SKILL.md +29 -0
  73. package/skills/domains/orchestration/multi-agent.md +263 -0
  74. package/skills/domains/security/SKILL.md +72 -0
  75. package/skills/domains/security/blue-team.md +436 -0
  76. package/skills/domains/security/code-audit.md +265 -0
  77. package/skills/domains/security/pentest.md +226 -0
  78. package/skills/domains/security/red-team.md +374 -0
  79. package/skills/domains/security/threat-intel.md +372 -0
  80. package/skills/domains/security/vuln-research.md +369 -0
  81. package/skills/meta-theory/SKILL.md +878 -0
  82. package/skills/meta-theory/references/create-agent.md +248 -0
  83. package/skills/meta-theory/references/dev-governance.md +1108 -0
  84. package/skills/meta-theory/references/intent-amplification.md +190 -0
  85. package/skills/meta-theory/references/meta-theory.md +346 -0
  86. package/skills/meta-theory/references/rhythm-orchestration.md +257 -0
  87. package/skills/meta-theory/references/ten-step-governance.md +285 -0
  88. package/skills/orchestration/multi-agent/SKILL.md +493 -0
  89. package/skills/run_skill.js +128 -0
  90. package/skills/tools/gen-docs/SKILL.md +115 -0
  91. package/skills/tools/gen-docs/agents/openai.yaml +4 -0
  92. package/skills/tools/gen-docs/scripts/doc_generator.js +435 -0
  93. package/skills/tools/lib/shared.js +98 -0
  94. package/skills/tools/override-refusal/SKILL.md +55 -0
  95. package/skills/tools/override-refusal/agents/openai.yaml +4 -0
  96. package/skills/tools/override-refusal/scripts/refusal_rewriter.js +229 -0
  97. package/skills/tools/verify-change/SKILL.md +139 -0
  98. package/skills/tools/verify-change/agents/openai.yaml +4 -0
  99. package/skills/tools/verify-change/scripts/change_analyzer.js +289 -0
  100. package/skills/tools/verify-module/SKILL.md +126 -0
  101. package/skills/tools/verify-module/agents/openai.yaml +4 -0
  102. package/skills/tools/verify-module/scripts/module_scanner.js +171 -0
  103. package/skills/tools/verify-quality/SKILL.md +159 -0
  104. package/skills/tools/verify-quality/agents/openai.yaml +4 -0
  105. package/skills/tools/verify-quality/scripts/quality_checker.js +337 -0
  106. package/skills/tools/verify-security/SKILL.md +142 -0
  107. package/skills/tools/verify-security/agents/openai.yaml +4 -0
  108. package/skills/tools/verify-security/scripts/security_scanner.js +283 -0
@@ -0,0 +1,1108 @@
1
+ # 开发治理流程 — 完整操作规范
2
+
3
+ > 本文件是 Type C (Development Governance Flow) 的详细操作规范。
4
+ > SKILL.md 中的 Type C 节只包含摘要入口,本文件包含完整操作步骤。
5
+ > Read this file when executing Type C — Development Governance Flow.
6
+
7
+ ## 1. AGENT INVOCATION PRINCIPLE (Non-Negotiable)
8
+
9
+ **Skill is the orchestration layer — never hardcode specific agent names.** At every stage where an agent is needed, follow the Fetch-first pattern:
10
+
11
+ ```
12
+ Need an agent for X → Search who declares "Own X" → Call the best match
13
+ ```
14
+
15
+ **Invocation decision pattern** (applies to every agent call, every stage):
16
+
17
+ | Step | Action |
18
+ |------|--------|
19
+ | 1. Search | `Glob: .claude/agents/*.md` + read global-capabilities.json |
20
+ | 2. Match | Score each agent's "Own" boundary against needed capability (3=perfect / 1-2=partial / 0=none) |
21
+ | 3. Invoke | 3 → invoke directly / 1-2 → invoke + note gaps / 0 → capability gap detected |
22
+
23
+ **⚠️ Iron Rule**: Do NOT write `call code-reviewer` or `call meta-prism` as hardcoded steps. Describe the **capability needed**; let the executor discover **who provides it** at runtime via the Search-Match-Invoke pattern.
24
+
25
+ ### Agent Ownership Rule
26
+
27
+ Every **executable** task must have an explicit **agent owner**.
28
+
29
+ Only a **pure Q / Query** may bypass agent ownership and be answered directly. A task is **not** a pure query if it does any of the following:
30
+ - modifies files / code / configuration
31
+ - triggers commands, network calls, or other external side effects
32
+ - produces a durable artifact for later handoff, review, or verification
33
+ - is expected to feed Evolution writeback into agent / skill / contract assets
34
+
35
+ Rule of thumb:
36
+
37
+ ```
38
+ Pure question → may answer directly
39
+ Anything executable / handoff-able → must have an agent owner
40
+ ```
41
+
42
+ ### Capability Gap Resolution Ladder
43
+
44
+ When Fetch does not find a clean owner, resolve the gap in this order:
45
+
46
+ 1. **Existing owner found** → dispatch to that owner
47
+ 2. **Durable / recurring / project-specific gap** → trigger Type B, create or compose the owner first, then dispatch
48
+ 3. **Emergency or one-off gap** → use a temporary `generalPurpose` owner with explicit justification, then review it again in Evolution
49
+
50
+ **No-owner execution is illegal.** Even a temporary fallback must be named and tracked as an owner, not treated as anonymous direct execution.
51
+
52
+ ### Protocol-First Rule
53
+
54
+ Before Stage 4 starts, Thinking must produce explicit protocol artifacts for the run:
55
+ - `runHeader`
56
+ - `taskClassification`
57
+ - `cardPlanPacket`
58
+ - `dispatchBoard`
59
+ - `workerTaskPackets`
60
+ - `resultMergePlan`
61
+ - `reviewPacketPlan`
62
+ - `verificationPacketPlan`
63
+ - `summaryPacketPlan`
64
+ - `evolutionWritebackPlan`
65
+
66
+ If these protocol artifacts do not exist, the run is not ready for Execution.
67
+
68
+ For `governanceFlow` in `complex_dev` or `meta_analysis`, the machine-validated JSON artifact must also include **`intentPacket`** (`trueUserIntent`, `successCriteria`, `nonGoals`, `intentPacketVersion: v1`) and **`intentGatePacket`** (`ambiguitiesResolved`, `requiresUserChoice`, `defaultAssumptions`, `intentGatePacketVersion: v1`; if `requiresUserChoice` is true, include non-empty `pendingUserChoices[]`) before Execution — see `contracts/workflow-contract.json` (`protocols.intentPacket`, `protocols.intentGatePacket`, `runDiscipline.protocolFirst.intentPacketRequiredWhenGovernanceFlows` / `intentGatePacketRequiredWhenGovernanceFlows`).
69
+
70
+ ---
71
+
72
+ ## 1B. Multi-iteration closure (until gates pass)
73
+
74
+ When work is not done after one pass (open review findings, `verificationPacket.verified !== true`, or `npm run validate:run` fails), treat the run like a **Ralph-style loop** without inventing new stage names:
75
+
76
+ 1. **Execution / Revision** — address the highest-severity open findings; update code or docs as needed.
77
+ 2. **Review** — refresh `reviewPacket` and finding `closeState` transitions (`open` → `fixed_pending_verify` as appropriate).
78
+ 3. **Verification** — refresh `revisionResponses`, `verificationResults`, and `closeFindings` until every finding is `verified_closed` or `accepted_risk`.
79
+ 4. **Summary** — align `summaryPacket` with `contracts/workflow-contract.json` `runDiscipline.publicDisplayRequires` before setting `publicReady=true`.
80
+ 5. **Validate** — run `npm run validate:run -- <artifact.json>`; if it fails, run `npm run prompt:next-iteration -- <artifact.json>` and feed the printed checklist back into the orchestrator.
81
+
82
+ Stop when `validate:run` passes **or** the user explicitly accepts risk with documented `accepted_risk` and honest `publicReady=false`.
83
+
84
+ **Session recovery (API / compact / tool failure):** The governed artifact is the source of truth. After an interrupted session, reload at minimum: `runHeader`, `taskClassification`, `intentPacket`, `intentGatePacket` (when required), `cardPlanPacket`, `dispatchBoard`, `workerTaskPackets` / `workerResultPackets`, `reviewPacket`, `verificationPacket`, `summaryPacket`, `evolutionWritebackPacket`. Re-run `npm run validate:run -- <artifact.json>` before claiming closure. The same packet list is printed by `npm run prompt:next-iteration -- <artifact.json>` under **Minimal context reload**.
85
+
86
+ Optional **soft todo gate** (off by default): set `META_KIM_SOFT_PUBLIC_READY_GATES=1` when running `validate:run`. If `summaryPacket.publicReady` is true, no `workerTaskPacket` may have `taskTodoState: "open"`. Omit `taskTodoState` if not tracking todos. See `contracts/workflow-contract.json` → `runDiscipline.runArtifactValidation.softPublicReadyTodoGate`.
87
+
88
+ Optional **soft comment-review gate**: set `META_KIM_SOFT_COMMENT_REVIEW=1` when running `validate:run`. If `summaryPacket.publicReady` is true, `summaryPacket.commentReviewAcknowledged` must be `true`. See `runDiscipline.runArtifactValidation.softCommentReviewGate`.
89
+
90
+ Optional Claude **Stop hook** (project default off): `META_KIM_STOP_COMPLETION_GUARD=hint` logs a stderr reminder when the last assistant message claims completion without governance cues; `=block` returns `{"decision":"block",...}` so the model continues. See `.claude/hooks/stop-completion-guard.mjs`.
91
+
92
+ **Governance doctor:** `npm run doctor:governance` checks contract readability, Claude hook command set, `npm run check:runtimes`, and `validate:run` on the sample fixture — use before release or when mirrors drift.
93
+
94
+ ---
95
+
96
+ ## 2. CORE 8-STAGE EXECUTION SPINE (Detailed)
97
+
98
+ | Stage | Name | Key Question |
99
+ |-------|------|-------------|
100
+ | 1 | **Critical** | What is the task? Is it clear? |
101
+ | 2 | **Fetch** | Who can do this? |
102
+ | 3 | **Thinking** | How should we approach it? |
103
+ | 4 | **Execution** | Delegate to agents |
104
+ | 5 | **Review** | Is the result correct? |
105
+ | 6 | **Meta-Review** | Are the review standards themselves sound? |
106
+ | 7 | **Verification** | Did the fixes actually solve the issues? |
107
+ | 8 | **Evolution** | What structural learning should carry forward? |
108
+
109
+ ### Hidden Skeleton State Model
110
+
111
+ The 8-stage spine is the **human-readable orchestration surface**. Underneath it, fusion-governance may maintain a **hidden state skeleton** so the run stays governable without turning the system into a visible bureaucracy:
112
+
113
+ | State Layer | Example Values | Primary Owner | Why it exists |
114
+ |-------------|----------------|---------------|---------------|
115
+ | `stageState` | `Critical -> Fetch -> Thinking -> Execution -> Review -> Meta-Review -> Verification -> Evolution` | Conductor | Canonical stage progression |
116
+ | `controlState` | `normal / skip / interrupt / intentional-silence / iteration` | Conductor | Modify stage dealing without inventing new pseudo-stages |
117
+ | `gateState` | `planning-open / planning-passed / review-open / verification-open / verification-closed / synthesis-ready` | Warden + Prism | Separate stage completion from gate clearance |
118
+ | `surfaceState` | `debug-surface / internal-ready / public-ready` | Warden | Prevent dirty runs from being presented as completed/public |
119
+ | `capabilityState` | `covered / partial / gap / escalated` | Scout + Artisan | Keep Fetch results explicit instead of hand-wavy |
120
+ | `agentInvocationState` | `idle / discovered / matched / dispatched / returned / escalated` | meta-theory skill | Track whether the skill delegates to agents or attempts work directly — enforce the dispatcher role |
121
+
122
+ **Rule**: this is an **invisible skeleton only**. The user-facing workflow still speaks in stage language and concrete deliverables. State labels exist to support gates, skips, interrupts, and evolution logging — not to become a second product interface.
123
+
124
+ ### Card Governance Model
125
+
126
+ fusion-governance no longer treats “发牌” as just a metaphor. In engineering terms:
127
+
128
+ - **dealer primary owner**: `meta-conductor`
129
+ - **dealer escalation owner**: `meta-warden`
130
+ - **interrupt signal sources**: `meta-sentinel`, `meta-prism`, `user`, `system`
131
+
132
+ This is intentionally **not** a new agent. It is a protocol role layered on top of Conductor/Warden so the system gains one explicit decision chain:
133
+
134
+ 1. **发不发**: `cardDecision`
135
+ 2. **发给谁**: `cardAudience`
136
+ 3. **什么时候发**: `cardTiming`
137
+ 4. **用什么壳发**: `deliveryShell`
138
+
139
+ ### Card Decision Objects
140
+
141
+ Every real run may emit card decisions through a `cardPlanPacket`. Each card records:
142
+
143
+ - `cardId`
144
+ - `cardType`
145
+ - `cardIntent`
146
+ - `cardDecision`
147
+ - `cardAudience`
148
+ - `cardTiming`
149
+ - `cardShell`
150
+ - `cardPriority`
151
+ - `cardReason`
152
+ - `cardSource`
153
+ - `cardSuppressed`
154
+ - `suppressionReason`
155
+ - `deliveryShellId`
156
+
157
+ Card families:
158
+
159
+ | Card family | Meaning |
160
+ |------------|---------|
161
+ | `info` | information / clarification / status |
162
+ | `action` | route to execution, review, repair, rollback |
163
+ | `risk` | governance or safety intervention |
164
+ | `silence` | intentional no-card / defer / quiet-hold |
165
+ | `default` | preferred next move or default path |
166
+ | `upgrade` | escalation, handoff, or governance raise |
167
+
168
+ ### Silence / No-Card Rule
169
+
170
+ Silence is a first-class decision, not a missing action.
171
+
172
+ Default principle:
173
+
174
+ ```text
175
+ If there is no clear evidence that interruption is better,
176
+ prefer no-card / defer / intentional silence.
177
+ ```
178
+
179
+ Run artifacts must therefore model:
180
+ - `noInterventionPreferred`
181
+ - `silenceDecision`
182
+ - `interruptionJustified`
183
+ - `deferUntil`
184
+ - `reasonForSilence`
185
+
186
+ ### Skip / Interrupt / Override Rule
187
+
188
+ fusion-governance distinguishes:
189
+
190
+ - **skip**: current step is intentionally not dealt because it is already known / already in context / not applicable
191
+ - **interrupt**: a risk or urgent governance signal temporarily inserts a card ahead of the default queue
192
+ - **override**: governance rules change the default path (for example, public display blocked until verification closes)
193
+ - **escalation_insert**: Warden / Sentinel / Prism inserts a governance owner into the chain
194
+
195
+ Every such move must emit a `controlDecision` with:
196
+ - `decisionType`
197
+ - `skipReason`
198
+ - `interruptReason`
199
+ - `overrideReason`
200
+ - `insertedGovernanceOwner`
201
+ - `emergencyGovernanceTriggered`
202
+ - `returnsToStage`
203
+ - `rejoinCondition`
204
+
205
+ ---
206
+
207
+ ## STAGE 1: Critical Analysis (Detailed)
208
+
209
+ ### Task Classification Routing
210
+
211
+ fusion-governance now uses a **two-layer classifier** so trigger decisions are reviewable instead of intuitive:
212
+
213
+ | Layer | Field | Allowed values | Purpose |
214
+ |-------|-------|----------------|---------|
215
+ | Intent layer | `taskClass` | `Q / A / P / S` | Preserve the canonical query / action / planning / strategic split |
216
+ | Runtime layer | `requestClass` | `query / execute / plan / strategy` | Explain what kind of ask the runtime saw |
217
+ | Governance layer | `governanceFlow` | `query / simple_exec / complex_dev / meta_analysis / proposal_review / rhythm` | Decide which execution path and gate set must run |
218
+
219
+ **Classification output fields**:
220
+ - `taskClass`
221
+ - `requestClass`
222
+ - `governanceFlow`
223
+ - `triggerReasons[]`
224
+ - `upgradeReasons[]`
225
+ - `bypassReasons[]`
226
+ - `ownerRequired`
227
+ - `decisionSource`
228
+ - `classifierVersion`
229
+
230
+ ### Canonical Mapping
231
+
232
+ | `taskClass` | `requestClass` | Default `governanceFlow` | Default handling |
233
+ |-------------|----------------|--------------------------|------------------|
234
+ | `Q` | `query` | `query` | Direct answer only when pure-query conditions all hold |
235
+ | `A` | `execute` | `simple_exec` or `complex_dev` | Requires explicit owner; classify complexity before execution |
236
+ | `P` | `plan` | `complex_dev` or `proposal_review` | Plan first, then produce owner-routable packets |
237
+ | `S` | `strategy` | `meta_analysis` or `rhythm` | Warden / Conductor-led governance path |
238
+
239
+ ### Trigger / Upgrade / Bypass Reasons
240
+
241
+ Record concrete reasons, not vibes:
242
+
243
+ - `triggerReasons`: `multi_file`, `cross_module`, `external_side_effect`, `durable_artifact`, `owner_missing`, `cross_runtime_sync`, `security_sensitive`, `verification_required`, `writeback_candidate`, `user_explicit_review`
244
+ - `upgradeReasons`: `cross_system_scope`, `review_or_verify_required`, `owner_creation_required`, `parallel_merge_required`, `business_workflow_upgrade`, `security_gate_required`
245
+ - `bypassReasons`: `pure_query`, `read_only_explanation`, `existing_verified_artifact_reuse`
246
+
247
+ ### No-Agent Exception (strict)
248
+
249
+ The only valid no-agent path is:
250
+
251
+ ```text
252
+ taskClass = Q
253
+ AND requestClass = query
254
+ AND governanceFlow = query
255
+ AND no file/code/config change
256
+ AND no external side effect
257
+ AND no durable artifact/handoff packet required
258
+ ```
259
+
260
+ If any one of those conditions fails, the task must be treated as `A`, `P`, or `S`, and therefore must have an agent owner.
261
+
262
+ ### Skip-Level Self-Reflection Gate
263
+
264
+ > Core question: **Should I be doing this, or should I dispatch it?**
265
+
266
+ Self-check list:
267
+ - [ ] Is the current role an "Execution Layer"? (Yes → Skip-Level suspicion, should dispatch to the corresponding execution agent)
268
+ - [ ] Does the task involve writing code / modifying files? (Yes → must delegate to Execution Layer; meta-theory does not execute directly)
269
+ - [ ] Am I "conveniently" making decisions for the Execution Layer? (Yes → only provide constraints; let the Execution Layer judge implementation details autonomously)
270
+ - [ ] Did the previous round also do a similar task? (Yes → check if a Skip-Level pattern is forming, record Scars)
271
+
272
+ Skip-Level determination:
273
+ ```
274
+ IF self-check has ≥1 hit AND taskClass = A
275
+ → Mark as "should-dispatch task"
276
+ → Assemble task package (context + constraints + deliverables)
277
+ → Hand to Conductor for orchestration → dispatch to Execution Layer
278
+ → Record Scars (if Skip-Level indeed occurred)
279
+ ```
280
+
281
+ ### Escalation Signals (pre-emptive)
282
+
283
+ > Unlike Skip-Level detection (which catches violations after the fact), Escalation Signals let the **dispatched agent itself** recognize it cannot handle the task — before wasting effort.
284
+
285
+ When dispatching to an agent, include this instruction in the task package:
286
+
287
+ ```
288
+ If you detect any of these signals, STOP and report back immediately:
289
+ - Task exceeds your declared "Own" boundary
290
+ - Multiple failed attempts (>2) on the same sub-problem
291
+ - Cross-system dependencies you cannot trace from your context
292
+ - Security-sensitive changes requiring specialized review
293
+ - Irreversible operations (database migrations, production deploys)
294
+ ```
295
+
296
+ Agent escalation response format:
297
+ ```json
298
+ {
299
+ "escalation": true,
300
+ "reason": "why this exceeds my capability",
301
+ "suggestedCapability": "what kind of agent/skill is needed instead",
302
+ "workCompletedSoFar": "what I did manage to do before hitting the wall"
303
+ }
304
+ ```
305
+
306
+ On receiving an escalation signal: re-enter Fetch (Stage 2) to find a more capable agent.
307
+
308
+ ### Clarity Gate
309
+
310
+ | State | Condition | Action |
311
+ |-------|-----------|--------|
312
+ | **Confirmed** | User specified file paths OR ≥2 deliverables OR said "just do this" | → Stage 2 |
313
+ | **Probed** | Needs scope or priority clarification | → Follow-up Probe (max 2 rounds) |
314
+ | **Assumed** | Still vague after 2 rounds | Record assumptions, mark `clarity: "assumed"`, → Stage 2 |
315
+
316
+ **Follow-up Probe Strategy**:
317
+ - Round 1: Ask about **scope** — "Which scenarios need support? Which can be deferred?"
318
+ - Round 2: Ask about **priorities** — "If time is tight, which parts can be cut?"
319
+ - Early Exit: Round 1 already specifies file paths OR ≥2 deliverables → skip Round 2
320
+
321
+ ### Complexity Routing
322
+
323
+ | File Changes | Complexity | Executed Path | Upgrade to 10-Step? |
324
+ |-------------|-----------|---------------|-------------------|
325
+ | 1 file, pure logic/style/comments | Simple | Execution → Review → Verification → Evolution (4 stages, still owner-driven) | No — 8-stage is the minimum; even these 4 stages suffice |
326
+ | 2-5 files, 1 module | Medium | Full 8-stage spine | No — 8-stage is the complete executable chain for medium complexity |
327
+ | >5 files OR cross-system OR multi-team | Complex | Full 8-stage spine, with escalation gates | **Yes** — upgrade to full 10-step governance when: (a) >5 files, (b) cross-system dependencies detected, (c) multi-team handoff required, (d) security-sensitive changes, or (e) business-workflow revision/summary/feedback phases are needed per the run contract |
328
+
329
+ **Upgrade Trigger Conditions** (any one is sufficient):
330
+ - File scope > 5 files
331
+ - Cross-system dependency detected (Stage 3 Thinking identifies shared components across module boundaries)
332
+ - Multi-team handoff required (business department + meta department coordination)
333
+ - Security-sensitive or permission-critical changes
334
+ - Business run contract explicitly requires 10-step phases (direction/planning/execution/review/meta-review/revision/verification/summary/feedback/evolution)
335
+
336
+ **Note**: The 8-stage spine is the **minimum executable chain** regardless of complexity. The 10-step governance is an **upgrade layer** for complex scenarios — the 8 stages still run, but extended with direction refinement, summary, and feedback phases before Evolution.
337
+
338
+ ### Critical Stage Output
339
+
340
+ ```json
341
+ {
342
+ "taskClass": "A",
343
+ "requestClass": "execute",
344
+ "governanceFlow": "complex_dev",
345
+ "triggerReasons": ["multi_file", "durable_artifact"],
346
+ "upgradeReasons": ["review_or_verify_required"],
347
+ "bypassReasons": [],
348
+ "requiresAgentOwner": true,
349
+ "ownerRequired": true,
350
+ "ownerPolicy": "existing-owner | create-owner-first | temporary-fallback-owner",
351
+ "decisionSource": "classifier-v2",
352
+ "classifierVersion": "v2",
353
+ "skipLevel": "should-dispatch",
354
+ "complexity": "medium",
355
+ "clarity": "confirmed",
356
+ "understanding": "one-sentence description of the task as understood",
357
+ "scope": {
358
+ "mustHave": ["item1", "item2"],
359
+ "deferLater": ["item3"]
360
+ }
361
+ }
362
+ ```
363
+
364
+ ---
365
+
366
+ ## STAGE 2: Fetch — Discover Available Agents (Detailed)
367
+
368
+ **Purpose**: Search for agents / skills whose "Own" boundary matches the capability needed.
369
+
370
+ **⚠️ Execute all 5 steps in order — no skipping.**
371
+
372
+ **Step 1 — Local agent scan**:
373
+ ```
374
+ Glob: .claude/agents/*.md
375
+ Read each file, verify it has `name:` YAML frontmatter (valid = registered agent)
376
+ Extract each agent's "Own / Do Not Touch" boundaries
377
+ Score match: does "Own" cover the needed capability?
378
+ ```
379
+
380
+ **Step 2 — Capability index search** (if no perfect local match):
381
+ ```
382
+ IF .claude/capability-index/global-capabilities.json is missing OR stale for the current machine
383
+ → run npm run discover:global first
384
+
385
+ Read .claude/capability-index/global-capabilities.json
386
+ Search for agents declaring the needed capability
387
+ Score match
388
+ ```
389
+
390
+ **Step 3 — External skill discovery** (if the local + indexed baseline still has no perfect match):
391
+ ```
392
+ Invoke the available findskill / find-skills capability
393
+ Search the Skills.sh ecosystem for the missing capability
394
+ Record what was searched and what was found
395
+ ```
396
+
397
+ **Step 4 — Specialist ecosystem fallback** (if the external search still finds no clean winner):
398
+ ```
399
+ Search known specialist ecosystems already integrated by fusion-governance:
400
+ - everything-claude-code agents
401
+ - gstack specialist skills
402
+ - other globally installed runtime-native agents / skills from the capability index
403
+ ```
404
+
405
+ **Step 5 — Owner resolution branch** (if no match found):
406
+ ```
407
+ Mark capabilityGap: "no agent declares Own [capability]"
408
+ IF gap is durable / recurring / project-specific
409
+ → trigger Type B creation pipeline before execution
410
+ ELSE
411
+ → invoke Agent(subagent_type="generalPurpose") as a TEMPORARY owner
412
+ → record justification + require Evolution follow-up
413
+ ```
414
+
415
+ ### Match Scoring
416
+
417
+ | Score | Meaning | Action |
418
+ |-------|---------|--------|
419
+ | 3 | Perfect match — "Own" covers exactly what is needed | Invoke directly |
420
+ | 2 | Partial match — covers most, some gaps | Invoke + note gaps |
421
+ | 1 | Weak match — tangentially related | Invoke + note significant gaps |
422
+ | 0 | No match | Capability gap detected → Step 5 owner-resolution branch |
423
+
424
+ ### Owner Resolution Rules
425
+
426
+ | Situation | Resolution |
427
+ |----------|------------|
428
+ | Existing owner covers the work | Dispatch to that owner |
429
+ | No owner, but gap is recurring / strategic / project-specific | Create or compose the owner first (Type B) |
430
+ | No owner, gap is one-off and low-risk | Use a temporary `generalPurpose` owner and mark it for Evolution review |
431
+
432
+ Temporary fallback is a **transition state**, not a mature architecture state.
433
+
434
+ ### Tier-Aware Routing
435
+
436
+ > Not all tasks need Opus-level agents. Match task complexity to agent weight to optimize context consumption and speed.
437
+
438
+ After scoring candidates, apply tier preference:
439
+
440
+ | Task Complexity | Preferred Tier | Rationale |
441
+ |----------------|---------------|-----------|
442
+ | Simple (1 file, pure logic) | Lightweight agent (e.g., `model: "haiku"`) | Fast, cheap, sufficient |
443
+ | Medium (2-5 files) | Standard agent (default model) | Balanced |
444
+ | Complex (>5 files, cross-layer) | Full-weight agent (e.g., `model: "opus"`) | Deep reasoning needed |
445
+
446
+ Tier selection rule:
447
+ ```
448
+ IF complexity = "simple" AND candidate has lightweight variant
449
+ → Prefer the lightweight variant (saves context, faster)
450
+ ELSE
451
+ → Use the default agent as matched
452
+ ```
453
+
454
+ This is a **preference**, not a hard rule — if the lightweight agent escalates (see Escalation Signals), re-dispatch to the full-weight version.
455
+
456
+ ### Fetch Stage Output
457
+
458
+ ```json
459
+ {
460
+ "capabilityNeeded": "code quality review",
461
+ "searchTrail": [
462
+ "local-agents",
463
+ "global-capability-index",
464
+ "findskill",
465
+ "specialist-ecosystem"
466
+ ],
467
+ "candidates": [
468
+ { "name": "code-reviewer", "source": "global", "score": 3, "matchReason": "Own covers code quality review" }
469
+ ],
470
+ "selected": { "name": "code-reviewer", "score": 3 },
471
+ "capabilityGap": null,
472
+ "ownerMode": "existing-owner",
473
+ "createOwnerRecommended": false,
474
+ "temporaryOwnerJustification": null,
475
+ "fallbackUsed": false
476
+ }
477
+ ```
478
+
479
+ ---
480
+
481
+ ## STAGE 3: Thinking — Plan the Approach (Detailed)
482
+
483
+ **Purpose**: Explore solution paths, identify risks, decompose into sub-tasks. This stage bridges Fetch and Execution.
484
+
485
+ ### Step 1: Option Exploration
486
+ Analyze at least 2 possible solution paths:
487
+
488
+ | Path | Approach | Pros | Cons |
489
+ |------|----------|------|------|
490
+ | A | [approach description] | [reasons] | [reasons] |
491
+ | B | [alternative approach] | [reasons] | [reasons] |
492
+
493
+ ### Step 2: Risk Identification
494
+
495
+ | Signal | Type | Mitigation |
496
+ |--------|------|------------|
497
+ | Shared component modification | Risk Card | Notify user before proceeding |
498
+ | Auth/permission logic involved | Risk Card | Surface immediately |
499
+ | >3 files affected | Cross-contamination risk | Mark for Review |
500
+ | No matching agent found | Capability gap | Record + suggest Type B |
501
+
502
+ ### Step 3: Task Decomposition
503
+
504
+ Break Stage 1's task into independent sub-tasks:
505
+
506
+ ```json
507
+ {
508
+ "subTasks": [
509
+ {
510
+ "id": 1,
511
+ "description": "what specifically to do",
512
+ "owner": "agent name from Stage 2",
513
+ "ownerMode": "existing-owner | create-owner-first | temporary-fallback-owner",
514
+ "parallel": true,
515
+ "parallelGroup": "group-a",
516
+ "dependsOn": [],
517
+ "mergeOwner": "agent responsible for consolidation",
518
+ "taskPacketId": "task-001",
519
+ "fileScope": ["file-or-module-a", "file-or-module-b"],
520
+ "constraints": ["boundary1", "dependency1"]
521
+ }
522
+ ]
523
+ }
524
+ ```
525
+
526
+ ### Step 3.5: Protocol-First Dispatch Artifacts
527
+
528
+ Thinking must lock down the execution protocol before any `Agent` tool invocation begins:
529
+
530
+ ```json
531
+ {
532
+ "taskClassification": {
533
+ "taskClass": "A",
534
+ "requestClass": "execute",
535
+ "governanceFlow": "complex_dev",
536
+ "triggerReasons": ["multi_file", "durable_artifact"],
537
+ "upgradeReasons": ["review_or_verify_required"],
538
+ "bypassReasons": [],
539
+ "ownerRequired": true,
540
+ "decisionSource": "classifier-v2",
541
+ "classifierVersion": "v2"
542
+ },
543
+ "runHeader": {
544
+ "department": "team or department",
545
+ "primaryDeliverable": "single deliverable name",
546
+ "audience": "who the result is for",
547
+ "freshnessRequirement": "freshness rule",
548
+ "visualPolicy": "visual strategy",
549
+ "handoffPlan": "how the chain closes"
550
+ },
551
+ "cardPlanPacket": {
552
+ "dealerOwner": "meta-conductor",
553
+ "dealerMode": "conductor-primary-warden-escalation",
554
+ "cards": [
555
+ {
556
+ "cardId": "card-001",
557
+ "cardType": "action",
558
+ "cardIntent": "execute",
559
+ "cardDecision": "deal",
560
+ "cardAudience": "owner",
561
+ "cardTiming": "next_stage",
562
+ "cardShell": "agent_dispatch",
563
+ "cardPriority": 8,
564
+ "cardReason": "work is ready for owner execution",
565
+ "cardSource": "meta-conductor",
566
+ "cardSuppressed": false,
567
+ "suppressionReason": "",
568
+ "deliveryShellId": "shell-tech-detail"
569
+ }
570
+ ],
571
+ "deliveryShells": [
572
+ {
573
+ "deliveryShellId": "shell-tech-detail",
574
+ "shellType": "technical_detail",
575
+ "presentationMode": "direct",
576
+ "exposureLevel": "internal",
577
+ "interventionForm": "agent_dispatch",
578
+ "audience": "developer-owner",
579
+ "contentBoundary": "implementation packet only"
580
+ }
581
+ ],
582
+ "silenceDecision": {
583
+ "silenceDecision": "defer",
584
+ "noInterventionPreferred": true,
585
+ "interruptionJustified": false,
586
+ "deferUntil": "verification-complete",
587
+ "reasonForSilence": "no additional push is better while verification is pending"
588
+ },
589
+ "controlDecisions": [
590
+ {
591
+ "decisionId": "ctl-001",
592
+ "decisionType": "interrupt",
593
+ "skipReason": "",
594
+ "interruptReason": "security_risk",
595
+ "overrideReason": "",
596
+ "insertedGovernanceOwner": "meta-sentinel",
597
+ "emergencyGovernanceTriggered": true,
598
+ "returnsToStage": "verification",
599
+ "rejoinCondition": "critical risk reviewed"
600
+ }
601
+ ],
602
+ "defaultShellId": "shell-tech-detail"
603
+ },
604
+ "dispatchBoard": {
605
+ "boardId": "dispatch-001",
606
+ "goal": "one sentence goal",
607
+ "ownerResolution": "existing-owner | create-owner-first | temporary-fallback-owner"
608
+ },
609
+ "workerTaskPackets": [
610
+ {
611
+ "packetId": "task-001",
612
+ "owner": "agent name",
613
+ "ownerMode": "existing-owner",
614
+ "dependsOn": [],
615
+ "parallelGroup": "group-a",
616
+ "mergeOwner": "agent name",
617
+ "deliverableLink": "how this packet connects back to the primary deliverable"
618
+ }
619
+ ],
620
+ "resultMergePlan": {
621
+ "mergeOwner": "agent responsible for consolidation",
622
+ "consolidationArtifact": "single deliverable artifact"
623
+ }
624
+ }
625
+ ```
626
+
627
+ Independent work that can be parallelized must be marked with the same `parallelGroup`. Any task that has no declared `owner`, `dependsOn`, and `mergeOwner` is not ready for Execution.
628
+
629
+ ### Step 4: `cardDeck` (stage-card rhythm) + delivery plan
630
+
631
+ Thinking must translate the plan into a **`cardDeck`** — the canonical Stage 3 artifact for stage-card rhythm (sequencing / lanes — not legacy “Planning / Guidance / Direction” card names). Each entry is one **stage-card intent** (priority, lane, skip/interrupt hooks). Conductor owns concrete dealing on the dispatch board; Thinking outputs `cardDeck` constraints and decomposition only.
632
+
633
+ ```json
634
+ {
635
+ "cardDeck": [
636
+ {
637
+ "stage": "Thinking",
638
+ "priority": 8,
639
+ "laneIntent": "decompose-and-surface-risks",
640
+ "skipCondition": "task is simple and already decomposed",
641
+ "interruptTrigger": "security-risk or scope-drift"
642
+ }
643
+ ],
644
+ "deliveryShellPlan": [
645
+ {
646
+ "audience": "user",
647
+ "channel": "conversation",
648
+ "shell": "structured-status"
649
+ }
650
+ ],
651
+ "interruptChannels": [
652
+ { "source": "sentinel", "severity": "critical", "action": "pause and front-load interrupt" },
653
+ { "source": "prism", "severity": "high", "action": "insert before next execution stage" }
654
+ ]
655
+ }
656
+ ```
657
+
658
+ ### Step 5: Decision Record
659
+
660
+ ```json
661
+ {
662
+ "selected": "A",
663
+ "reason": "why this path was chosen over alternatives",
664
+ "rejectedOptions": [{ "path": "B", "reason": "why not chosen" }],
665
+ "risks": [{ "type": "shared-component", "mitigation": "notify user" }]
666
+ }
667
+ ```
668
+
669
+ ### Thinking Stage Output Contract
670
+
671
+ ```json
672
+ {
673
+ "subTasks": [],
674
+ "taskClassification": {},
675
+ "runHeader": {},
676
+ "cardPlanPacket": {},
677
+ "dispatchBoard": {},
678
+ "workerTaskPackets": [],
679
+ "resultMergePlan": {},
680
+ "cardDeck": [],
681
+ "deliveryShellPlan": [],
682
+ "interruptChannels": [],
683
+ "reviewPlan": ["code-quality", "security"],
684
+ "reviewPacketPlan": ["owner-coverage", "protocol-compliance", "quality-findings", "finding-closure-model"],
685
+ "metaReviewGate": "complexity=complex OR abnormal review confidence",
686
+ "verificationGate": "all failed assertions must be re-run with fresh evidence",
687
+ "verificationPacketPlan": ["fixEvidence", "revisionResponses", "verificationResults", "closeFindings", "regressionGuard"],
688
+ "summaryPacketPlan": ["verifyPassed", "summaryClosed", "deliverableChainClosed", "publicReady"],
689
+ "evolutionWritebackPlan": ["writebackDecision", "agent-boundary", "skill", "contract", "scar"],
690
+ "evolutionFocus": ["pattern reuse", "boundary drift", "process bottlenecks"]
691
+ }
692
+ ```
693
+
694
+ ---
695
+
696
+ ## STAGE 4: Execution — Delegate to Agents (Detailed)
697
+
698
+ **⚠️ Core Rule: meta-theory does NOT write code directly.**
699
+
700
+ ### Step 1: Invoke selected agents from Stage 2
701
+
702
+ For each sub-task from Stage 3, invoke the matched agent:
703
+ ```
704
+ Agent(
705
+ subagent_type="<selected agent from Stage 2>",
706
+ prompt="""
707
+ Packet: [workerTaskPacket JSON]
708
+ Task: [sub-task description]
709
+ Constraints: [boundaries from Stage 3]
710
+ Deliverable: [expected output format]
711
+ """
712
+ )
713
+ ```
714
+
715
+ ### Step 2: Parallel/Sequential Decision
716
+ - No dependency edges + non-overlapping file scopes → **must run in parallel**
717
+ - Shared files, explicit dependency edges, or shared consolidation step → **sequential**
718
+ - Every parallel lane must declare a `parallelGroup`
719
+ - Every parallel group must declare one `mergeOwner`
720
+
721
+ ### Step 2.5: Execute in stage order
722
+
723
+ Execution must respect the Stage 3 **`cardDeck`** (stage-card sequence / control interrupts — delegated to Conductor for actual dealing):
724
+ - Run stages in agreed order unless a control interrupt (silence / skip / risk) is active
725
+ - Insert intentional silence when the overload rule is hit
726
+ - Use the selected Delivery Shell when reporting progress or handing off results
727
+
728
+ ### Step 3: Result Aggregation
729
+ - Which files were modified
730
+ - Any conflicts to resolve
731
+ - Any sub-task failures → handle via fault protocol
732
+ - Every result returns through a `WorkerResultPacket`, not free-form orphan output
733
+
734
+ ---
735
+
736
+ ## STAGE 5: Review — Validate the Result (Detailed)
737
+
738
+ **Trigger**: Stage 4 produced code changes or any durable execution artifact. If Stage 4 produced neither, skip to Stage 6.
739
+
740
+ **⚠️ The executor does not self-review. Follow the Agent Invocation Principle.**
741
+
742
+ ### Step 1: Skip-Level Retrospective
743
+
744
+ Check: Did anyone (including myself) do work that should have been dispatched?
745
+ - [ ] Who wrote this round's code? (If meta-theory used Edit/Write directly → Skip-Level)
746
+ - [ ] Were required agents skipped?
747
+ - [ ] Was Stage 1's skip-level result respected?
748
+
749
+ Skip-Level handling:
750
+ ```
751
+ IF Skip-Level detected → Record Scar → Assess impact → IF impact occurred → re-verify with agent
752
+ ```
753
+
754
+ ### Step 1.5: Owner Coverage + Protocol Compliance Review
755
+
756
+ Before content quality review begins, check the execution contract itself:
757
+ - [ ] Did every executable sub-task have an explicit owner?
758
+ - [ ] If temporary fallback owner was used, is the justification explicit?
759
+ - [ ] Do all `WorkerResultPackets` map back to the `dispatchBoard` and primary deliverable?
760
+ - [ ] Is there a declared `mergeOwner` for every parallel group?
761
+ - [ ] Did the run maintain one consolidated deliverable rather than drifting into detached outputs?
762
+
763
+ If any answer is no, the Review packet must record **protocol non-compliance** even if the implementation quality looks good.
764
+
765
+ ### Step 2: Quality Review (dynamic, Fetch-first)
766
+
767
+ Following the **Agent Invocation Principle** (Search → Match → Invoke):
768
+ ```
769
+ → Search: who declares "Own: code quality review"?
770
+ → Match: score candidates
771
+ → Invoke: selected agent
772
+ ```
773
+
774
+ When invoking a code quality agent, specify these check dimensions:
775
+ - **Type safety**: any / implicit any / type assertions
776
+ - **Error handling**: try/catch coverage and fallback strategy
777
+ - **Permission boundaries**: which external APIs / file systems / network requests were called
778
+ - **Code reuse**: duplicate logic, DRY detection
779
+
780
+ ### Step 3: Security Scan (dynamic, Fetch-first)
781
+
782
+ ```
783
+ → Search: who declares "Own: security analysis"?
784
+ → Match: score candidates
785
+ → Invoke: selected agent
786
+ ```
787
+
788
+ When invoking a security agent, specify these check dimensions:
789
+ - **Hardcoded secrets**: API key / token / password
790
+ - **Unvalidated input**: parameter validation
791
+ - **Injection risks**: SQL injection / XSS
792
+
793
+ ### Step 4: UX Review (for UI-related changes)
794
+
795
+ If files involve UI/components:
796
+ - Accessibility (keyboard navigation focus-visible, aria-label, aria-live)
797
+ - Loading states (skeleton screens vs pure spinners)
798
+ - Responsiveness (mobile breakpoints)
799
+
800
+ ### Step 5: AI-Slop Detection (optional — for agent/system definitions)
801
+
802
+ ```
803
+ → Search: who declares "Own: quality forensics, AI-Slop detection"?
804
+ → Invoke if found
805
+ ```
806
+
807
+ ### Review Stage Output
808
+
809
+ ```json
810
+ {
811
+ "skipLevelDetected": false,
812
+ "skipLevelScar": null,
813
+ "ownerCoverage": "PASS",
814
+ "protocolCompliance": "PASS",
815
+ "temporaryOwnerFollowUp": [],
816
+ "reviews": [
817
+ { "type": "code-quality", "agent": "code-reviewer", "result": "PASS", "issues": [] },
818
+ { "type": "security", "agent": "security-reviewer", "result": "FAIL", "issues": ["hardcoded API key in config.ts"] }
819
+ ],
820
+ "findings": [
821
+ {
822
+ "findingId": "rev-001",
823
+ "severity": "high",
824
+ "owner": "security-reviewer",
825
+ "summary": "hardcoded API key in config.ts",
826
+ "requiredAction": "remove secret and load from secure runtime config",
827
+ "fixArtifact": "src/config.ts",
828
+ "verifiedBy": "meta-prism",
829
+ "closeState": "open"
830
+ }
831
+ ],
832
+ "qualityGate": "FAIL",
833
+ "revisionNeeded": true,
834
+ "revisionRound": 1
835
+ }
836
+ ```
837
+
838
+ Every non-pass issue must become a **review finding object**. Free-form issue lists are insufficient once revision and verification start.
839
+
840
+ **Quality Gate rules — Auto-Fix Loop**:
841
+
842
+ ```
843
+ Round 1: Review agent reports issues
844
+ → Auto-dispatch fix to the original execution agent (with issue list as constraints)
845
+ → Re-run Review on the fixed output
846
+ Round 2: If still FAIL → auto-fix again with accumulated context
847
+ → Re-run Review
848
+ Round 3: If still FAIL → STOP, notify user for manual decision
849
+ → Include: all 3 rounds of issues, what was tried, what remains unfixed
850
+ ```
851
+
852
+ Key difference from simple "max 2 rounds": the fix is **automatic** — the Review agent dispatches the fix back to the execution agent without waiting for user input. Only escalate to user after 3 failed auto-fix attempts.
853
+
854
+ ---
855
+
856
+ ## STAGE 6: Meta-Review — Review the Review Standards (Detailed)
857
+
858
+ **Trigger**: Complex tasks, abnormal pass rates, or when the user explicitly asks for stricter governance.
859
+
860
+ Meta-Review does **not** re-review the implementation itself. It reviews whether Stage 5's review criteria were strong enough:
861
+
862
+ | Check Dimension | Question | Fail Action |
863
+ |----------------|----------|-------------|
864
+ | Assertion coverage | Did the review cover all critical dimensions? | Add missing assertions and re-run review |
865
+ | Assertion strength | Could a clearly wrong result still pass? | Tighten weak assertions and re-run review |
866
+ | Criteria consistency | Did standards drift materially from comparable past runs? | Record drift and request Warden arbitration |
867
+
868
+ **Trigger heuristics**:
869
+ - Review pass rate > 0.9 but output still looks suspect
870
+ - Review pass rate < 0.3 but output looks materially sound
871
+ - Security-sensitive or cross-layer changes
872
+
873
+ ---
874
+
875
+ ## STAGE 7: Verification — Confirm the Fixes (Detailed)
876
+
877
+ **Trigger**: Stage 5 or Stage 6 produced revision work.
878
+
879
+ Verification is an independent re-check using fresh evidence, not a trust-based acknowledgment:
880
+
881
+ | Check | Method |
882
+ |------|--------|
883
+ | Issue closure | Re-run the assertion that originally failed |
884
+ | Regression guard | Confirm the fix did not break an adjacent path |
885
+ | Fresh evidence | Cite current files / outputs / logs, not memory of what changed |
886
+
887
+ **Verification output**:
888
+ ```json
889
+ {
890
+ "verified": true,
891
+ "remainingIssues": [],
892
+ "evidence": ["current file or runtime evidence"],
893
+ "fixEvidence": ["commit diff, file path, or test output showing the fix landed"],
894
+ "revisionResponses": [
895
+ {
896
+ "findingId": "rev-001",
897
+ "actionId": "fix-001",
898
+ "owner": "execution-owner",
899
+ "responseType": "code-change",
900
+ "status": "applied",
901
+ "fixArtifact": "src/config.ts",
902
+ "responseSummary": "removed hardcoded key and switched to env lookup"
903
+ }
904
+ ],
905
+ "verificationResults": [
906
+ {
907
+ "findingId": "rev-001",
908
+ "verifiedBy": "meta-prism",
909
+ "result": "pass",
910
+ "evidence": ["src/config.ts now reads process.env.API_KEY"],
911
+ "closeState": "verified_closed"
912
+ }
913
+ ],
914
+ "closeFindings": ["rev-001"]
915
+ }
916
+ ```
917
+
918
+ If verification fails, route back to Execution with the accumulated issue list.
919
+
920
+ **Closure rule**:
921
+ - `review finding -> revision response -> verification result -> closeFindings`
922
+ - Missing any link means the finding stays open
923
+ - `closeFindings` may only contain finding ids that have a matching verification result with fresh evidence
924
+
925
+ ### Rollback Protocol
926
+
927
+ When verification reveals that fixes caused more damage than they solved, or when risk exceeds the original task scope, invoke the rollback protocol:
928
+
929
+ | Rollback Level | Trigger | Action |
930
+ |---------------|---------|--------|
931
+ | **File-level** | Single file regression detected | Restore the specific file from last known good state (`git checkout HEAD~1 -- <file>`) |
932
+ | **Sub-task level** | One sub-task's changes broke adjacent paths | Revert only that sub-task's file set; re-run Review on remaining changes |
933
+ | **Full rollback** | Cross-contamination across >3 files; original task assumptions invalidated | `git stash` all uncommitted changes; return to Stage 1 Critical with a revised scope |
934
+ | **Partial rollback** | Some sub-tasks succeeded, others failed | Keep successful sub-tasks; rollback failed ones; re-enter Stage 3 Thinking to re-decompose the failed portion |
935
+
936
+ **Rollback Decision Flow**:
937
+ ```
938
+ Verification FAIL
939
+ → Count affected files
940
+ → IF 1 file: File-level rollback → Re-run Stage 4 for that file only
941
+ → IF 2-3 files in same sub-task: Sub-task level rollback
942
+ → IF >3 files OR cross-module: Notify user → Full or Partial rollback (user decides)
943
+ ```
944
+
945
+ **Iron Rule**: Rollback is not failure. Rollback is the system demonstrating it knows when to stop making things worse. A system without rollback capability is a system that can only move forward into disaster.
946
+
947
+ ### Summary / Public Display Packet
948
+
949
+ The 8-stage spine has no separate “summary stage”, but business runs still need a structured closure object before anything becomes display-ready.
950
+
951
+ ```json
952
+ {
953
+ "verifyPassed": true,
954
+ "summaryClosed": true,
955
+ "singleDeliverableMaintained": true,
956
+ "deliverableChainClosed": true,
957
+ "consolidatedDeliverablePresent": true,
958
+ "publicReady": true,
959
+ "deliveryShellsUsed": ["shell-tech-detail"],
960
+ "blockedBy": []
961
+ }
962
+ ```
963
+
964
+ Rules:
965
+ - `publicReady = true` only when all public-display conditions are true
966
+ - if any gate is false, `blockedBy` must explain why
967
+ - summary closure is the public shell of the verified run, not a replacement for verification
968
+
969
+ ---
970
+
971
+ ## STAGE 8: Evolution — Extract Learnings (Detailed)
972
+
973
+ Use the **5+1 evolution model** after every task: the canonical 5 structural dimensions, plus Scars codification as an always-on overlay.
974
+
975
+ | Dimension | What to Detect | Amplification Action |
976
+ |-----------|---------------|---------------------|
977
+ | Pattern reuse | Can this solution become a reusable pattern? | Extract as new skill/agent |
978
+ | Agent boundaries | Do boundaries need adjustment? | Trigger split/merge |
979
+ | Rhythm optimization | Can interaction path be shorter? | Tighten stage or control-card trigger conditions (Conductor-owned dealing) |
980
+ | Process bottlenecks | Which step is slowest/error-prone? | Adjust orchestration |
981
+ | Capability coverage | Any new gaps discovered? | Trigger Scout or Type B |
982
+ | **Scars codification** | Skip-Level/Boundary Violation/Process Gap? | Record structured Scar → prevention rule |
983
+
984
+ ### Amplification Operations
985
+
986
+ | Dimension | Detection | Action |
987
+ |-----------|-----------|--------|
988
+ | Pattern reuse | Reusable pattern found | → Extract as skill/template → register |
989
+ | Agent boundaries | Boundaries unreasonable | → Trigger split/merge |
990
+ | Rhythm optimization | Interaction path redundant | → Update stage/control triggers (via Conductor) |
991
+ | Process bottlenecks | Bottleneck found | → Adjust stage-card priority / sequencing (Conductor) |
992
+ | Capability coverage | Gap discovered | → Scout or Type B |
993
+ | Scars | Issue detected | → Record Scar → update Critical checklist |
994
+
995
+ ### Owner Writeback Rule
996
+
997
+ Every completed run must ask:
998
+
999
+ 1. Did an existing owner prove sufficient?
1000
+ 2. Did a temporary fallback owner reveal a recurring capability gap?
1001
+ 3. Should an agent boundary, SOUL, skill loadout, or workflow contract be updated?
1002
+
1003
+ If the run used a temporary owner more than once for the same capability family, Evolution should default to **Type B or owner-boundary adjustment**, not repeated temporary fallback.
1004
+
1005
+ ### Scars Structured Recording
1006
+
1007
+ ```yaml
1008
+ scar:
1009
+ id: "{date}-{type}-{short-desc}"
1010
+ type: overstep | boundary-violation | process-gap | false-positive
1011
+ triggered_by: "{context}"
1012
+ what_happened: "one sentence"
1013
+ root_cause: "why (not surface reason)"
1014
+ impact: none | degraded | recovered | critical
1015
+ prevention_rule: "specific rule for next time"
1016
+ ```
1017
+
1018
+ ### Evolution Writeback Packet
1019
+
1020
+ ```json
1021
+ {
1022
+ "ownerAssessment": "keep-existing | adjust-boundary | create-owner | retire-temporary-fallback",
1023
+ "writebackDecision": "writeback | none",
1024
+ "decisionReason": "why a writeback is required, or why none is acceptable for this run",
1025
+ "writebacks": [
1026
+ { "target": ".claude/agents/<agent>.md", "reason": "boundary drift" },
1027
+ { "target": ".claude/skills/<skill>/SKILL.md", "reason": "reusable execution pattern" },
1028
+ { "target": "contracts/workflow-contract.json", "reason": "protocol or gate refinement" }
1029
+ ],
1030
+ "scarIds": ["2026-04-02-overstep-example"],
1031
+ "syncRequired": true
1032
+ }
1033
+ ```
1034
+
1035
+ **Rule**: Evolution may not silently disappear. Every run must emit either:
1036
+ - `writebackDecision = "writeback"` with concrete targets, or
1037
+ - `writebackDecision = "none"` with a concrete `decisionReason`
1038
+
1039
+ ### Evolution Artifacts Storage
1040
+
1041
+ Evolution outputs must be persisted to specific locations — not left floating in conversation context:
1042
+
1043
+ | Artifact Type | Storage Location | Lifecycle |
1044
+ |--------------|-----------------|-----------|
1045
+ | **Reusable Patterns** | `memory/patterns/{pattern-name}.md` | Permanent; reviewed quarterly by Librarian |
1046
+ | **Scars** | `memory/scars/{scar-id}.yaml` | Permanent; prevention rules feed back into Critical stage checklists |
1047
+ | **New Skills** (extracted) | `.claude/skills/{skill-name}/SKILL.md` | Permanent; created via skill-creator, validated via Type D Review |
1048
+ | **Agent Boundary Adjustments** | `.claude/agents/{agent}.md` (direct edit) | Immediate; triggers `npm run sync:runtimes` |
1049
+ | **Rhythm Optimizations** | Recorded in `contracts/workflow-contract.json` or Conductor's card-deck defaults | Immediate; affects next run's dispatch board |
1050
+ | **Capability Gap Records** | `memory/capability-gaps.md` | Until resolved; Scout monitors and closes when filled |
1051
+
1052
+ **Storage Rule**: If an evolution artifact has no defined storage location, it does not count as "captured". The 5+1 model's amplification actions are only complete when the artifact is written to disk and indexed.
1053
+
1054
+ ### Public Display Discipline
1055
+
1056
+ External-ready output is a **gate state**, not a storytelling choice. Before any run is treated as publicly complete, all of these must hold:
1057
+
1058
+ - `verifyPassed`
1059
+ - `summaryClosed`
1060
+ - `singleDeliverableMaintained`
1061
+ - `deliverableChainClosed`
1062
+ - `consolidatedDeliverablePresent`
1063
+
1064
+ If any one of these is false, the run may produce internal notes, but it must not be framed as the final public deliverable.
1065
+
1066
+ ---
1067
+
1068
+ ## STAGE SPINE VS CONTROL CARDS
1069
+
1070
+ **8-stage spine** (always the backbone): Critical → Fetch → Thinking → Execution → Review → Meta-Review → Verification → Evolution. Business workflow **phase names** in `contracts/workflow-contract.json` (e.g. `direction`, `planning`, `execution`) are a separate vocabulary for department runs — do not relabel spine stages as “Guidance / Direction / Planning cards.”
1071
+
1072
+ **Control / overlay cards** (rhythm and safety — Conductor deals; not a second spine):
1073
+
1074
+ | Card | Trigger Condition | Action |
1075
+ |------|-------------------|--------|
1076
+ | Scope Contraction (范围收缩牌) | Repository too large / duplicate filenames / branching history | Ask which target to change, then proceed |
1077
+ | Risk (风险牌) | Shared components / auth / global interfaces / hot multi-editor areas | Surface; may trigger interrupt path |
1078
+ | Suggestion (建议牌) | User hesitates; interruption costly | Low-cost forward plan or intentional silence |
1079
+ | Silence (留白牌) | ≥3 consecutive high-density push rounds | Pause for digestion |
1080
+ | Skip (跳过牌) | Attention cost > benefit | Simplify or defer |
1081
+ | Interrupt (插队牌) | Emergency or Sentinel-critical | Prioritize and reorder |
1082
+ | Iteration (迭代牌) | Acceptance not closed within agreed rounds | Loop with explicit gate; max 3 iterations, then escalate to Warden |
1083
+ | **Rollback (回滚牌)** | Risk exceeded original scope OR impact scope expanded beyond acceptance | Revert to last stable state; re-enter Stage 3 Thinking to re-decompose |
1084
+
1085
+ **Card naming note**: The English names are used internally; the Chinese names in parentheses (e.g. 范围收缩牌) align with `docs/meta.md` original design. Conductor should use the Chinese names in user-facing outputs.
1086
+
1087
+ Spine coverage reference (what each stage is for — not separate “card” names):
1088
+
1089
+ | Spine stage | Role |
1090
+ |-------------|------|
1091
+ | Critical | Clarity, classification, skip-level checks |
1092
+ | Fetch | Capability discovery (Search–Match–Invoke) |
1093
+ | Thinking | Options, risks, decomposition |
1094
+ | Execution | Delegated work |
1095
+ | Review | Result validation (Fetch-first reviewers) |
1096
+ | Meta-Review | Review-of-review when triggered |
1097
+ | Verification | Fresh-evidence re-check after revisions |
1098
+ | Evolution | Learnings and scars |
1099
+
1100
+ ---
1101
+
1102
+ ## "WHAT IT IS NOT" GUARDRAILS
1103
+
1104
+ - Meta ≠ role naming: calling something "frontend agent" doesn't make it a meta; naming without clear boundaries is just packaging
1105
+ - Meta ≠ Omnipotent Executor Meta: stuffing all responsibilities into one agent isn't strength; clear division of labor is maturity
1106
+ - Organizational Mirror ≠ metadata/ORM: it's not a technical term — it's an architectural design method for collaboration relationships between metas, responsibility boundaries, and who takes the field first
1107
+ - Meta ≠ framework complexity: simple scenarios don't need meta decomposition; direct execution is more efficient — meta is a governance tool, not decoration
1108
+ - Meta ≠ once-and-for-all: meta boundaries need to be adjusted as the system evolves; they aren't defined once and never changed