@kontextmind/kxm 0.7.94 → 0.7.96

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 (140) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.kxm/README.md +39 -9
  3. package/CHANGELOG.md +1 -1
  4. package/README.md +147 -257
  5. package/SECURITY.md +21 -12
  6. package/docs/README.md +133 -54
  7. package/docs/adr/ADR-0002-browser-automation-steel-doks.md +24 -18
  8. package/docs/adr/ADR-0003-sqlite-only-store.md +100 -0
  9. package/docs/adr/ADR-0004-edge-identity-authentik.md +99 -0
  10. package/docs/adr/README.md +33 -0
  11. package/docs/concepts/architecture.md +262 -0
  12. package/docs/concepts/data-and-storage.md +194 -0
  13. package/docs/concepts/trust-model.md +152 -0
  14. package/docs/contracts/README.md +22 -14
  15. package/docs/contracts/effects-and-recovery.md +3 -0
  16. package/docs/contracts/migration.md +2 -2
  17. package/docs/contracts/routing.md +6 -5
  18. package/docs/contributing/assignment-runner.md +388 -0
  19. package/docs/contributing/ci-and-release.md +231 -0
  20. package/docs/contributing/development.md +362 -0
  21. package/docs/contributing/harness-routing-internals.md +192 -0
  22. package/docs/{packages.md → contributing/packages.md} +13 -15
  23. package/docs/{skills → contributing}/repo-work-delivery.md +20 -21
  24. package/docs/contributing/test-matrix.md +208 -0
  25. package/docs/{tui-components.md → contributing/tui-components.md} +30 -22
  26. package/docs/contributing/writing-docs.md +340 -0
  27. package/docs/glossary.md +471 -0
  28. package/docs/guides/agent-skills.md +137 -0
  29. package/docs/guides/browser-automation.md +160 -0
  30. package/docs/guides/context-and-memory.md +352 -0
  31. package/docs/guides/continuous-improvement.md +228 -0
  32. package/docs/guides/governed-skills.md +173 -0
  33. package/docs/guides/nous-providers.md +186 -0
  34. package/docs/guides/peer-messaging.md +304 -0
  35. package/docs/guides/pi-workers.md +219 -0
  36. package/docs/guides/provenance-gates.md +313 -0
  37. package/docs/guides/webhook-workflows.md +364 -0
  38. package/docs/kb/how-credentials-retrieved-safely.md +38 -12
  39. package/docs/kb/how-to-capture-and-annotate-section.md +15 -13
  40. package/docs/kb/how-to-connect-playwright-to-steel.md +16 -11
  41. package/docs/kb/how-to-recover-expired-session-or-orphan.md +26 -16
  42. package/docs/kb/how-to-resume-after-mfa.md +19 -11
  43. package/docs/kb/how-to-take-over-session.md +17 -13
  44. package/docs/kb/why-authentication-disappeared.md +22 -14
  45. package/docs/kb/why-automation-opened-different-browser.md +23 -14
  46. package/docs/kb/why-session-viewer-cannot-control.md +13 -12
  47. package/docs/operations/backup-and-restore.md +248 -0
  48. package/docs/operations/deploy.md +307 -0
  49. package/docs/operations/monitoring.md +209 -0
  50. package/docs/operations/runtime-sync.md +192 -0
  51. package/docs/operations/troubleshooting.md +265 -0
  52. package/docs/operations/upgrade.md +124 -0
  53. package/docs/prompts/browser-annotate-feedback.md +7 -7
  54. package/docs/prompts/browser-diagnose-recover.md +11 -10
  55. package/docs/prompts/browser-explore.md +7 -7
  56. package/docs/prompts/browser-repro-fix.md +7 -7
  57. package/docs/prompts/browser-start.md +12 -11
  58. package/docs/prompts/browser-takeover.md +8 -8
  59. package/docs/{cli-reference.md → reference/cli-reference.md} +83 -41
  60. package/docs/{config-reference.md → reference/config-reference.md} +159 -148
  61. package/docs/reference/configuration.md +299 -0
  62. package/docs/reference/harness-routing.md +508 -0
  63. package/docs/reference/http-api.md +203 -0
  64. package/docs/reference/tools.md +370 -0
  65. package/docs/{workflow-guide.md → reference/workflow-catalog.md} +92 -153
  66. package/docs/reference/workflow-definitions.md +286 -0
  67. package/docs/start/first-workflow.md +287 -0
  68. package/docs/start/install.md +146 -0
  69. package/docs/start/quickstart-claude-code.md +405 -0
  70. package/docs/start/quickstart-pi.md +213 -0
  71. package/docs/templates/README.md +78 -73
  72. package/docs/templates/adr.md +13 -13
  73. package/docs/templates/architecture.md +55 -71
  74. package/docs/templates/bug-fix.md +13 -16
  75. package/docs/templates/feature.md +14 -19
  76. package/docs/templates/handoff.md +44 -46
  77. package/docs/templates/postmortem.md +30 -43
  78. package/docs/templates/research.md +15 -20
  79. package/docs/templates/review.md +49 -50
  80. package/docs/templates/runbook.md +38 -30
  81. package/docs/templates/test-plan.md +16 -23
  82. package/docs/templates/test-report.md +14 -17
  83. package/examples/README.md +9 -5
  84. package/examples/provenance-workflow.json +1 -1
  85. package/examples/webhook-workflows/jira-development.json +59 -0
  86. package/examples/webhook-workflows/jira-issue-updated.json +12 -0
  87. package/package.json +2 -2
  88. package/packages/core/tui/README.md +1 -1
  89. package/plugins/kxm/.claude-plugin/plugin.json +1 -1
  90. package/plugins/kxm/README.md +31 -32
  91. package/plugins/kxm/dist/cli.js +5 -5
  92. package/plugins/kxm/dist/mcp-server.js +1 -1
  93. package/plugins/kxm/dist/runtime.js +1 -1
  94. package/plugins/kxm/package.json +1 -1
  95. package/plugins/kxm/skills/kxm/references/protocol.md +3 -1
  96. package/plugins/kxm/skills/kxm-browser-auth/SKILL.md +1 -1
  97. package/plugins/kxm/skills/kxm-browser-diagnostics/SKILL.md +5 -5
  98. package/plugins/kxm/skills/kxm-browser-explore/SKILL.md +2 -2
  99. package/plugins/kxm/skills/kxm-browser-session/SKILL.md +10 -13
  100. package/plugins/kxm/skills/kxm-browser-takeover/SKILL.md +1 -1
  101. package/plugins/kxm/skills/kxm-browser-verify/SKILL.md +1 -1
  102. package/plugins/kxm/skills/kxm-context-memory/SKILL.md +13 -4
  103. package/plugins/kxm/skills/kxm-hub-ops/SKILL.md +3 -1
  104. package/plugins/kxm/skills/kxm-mind-setup/SKILL.md +2 -1
  105. package/plugins/kxm/skills/kxm-project-setup/SKILL.md +31 -54
  106. package/plugins/kxm/skills/kxm-projects/SKILL.md +1 -1
  107. package/plugins/kxm/skills/kxm-protocol/SKILL.md +1 -1
  108. package/plugins/kxm/skills/kxm-routing-improve/SKILL.md +15 -7
  109. package/plugins/kxm/skills/kxm-runs/SKILL.md +11 -5
  110. package/plugins/kxm/skills/kxm-session/SKILL.md +1 -1
  111. package/plugins/kxm/skills/kxm-tasks/SKILL.md +9 -7
  112. package/plugins/kxm/skills/kxm-workflow/SKILL.md +10 -2
  113. package/plugins/kxm/src/cli/system.ts +1 -1
  114. package/plugins/kxm/src/cli.ts +3 -3
  115. package/plugins/kxm/src/init-guide-setup.ts +1 -1
  116. package/plugins/kxm/src/mcp-server.ts +1 -1
  117. package/plugins/kxm/src/modes.ts +1 -1
  118. package/schemas/README.md +1 -1
  119. package/docs/agent-communication-envelopes-and-gates.md +0 -553
  120. package/docs/agent-skills.md +0 -198
  121. package/docs/architecture.md +0 -245
  122. package/docs/assignment-runner.md +0 -264
  123. package/docs/browser-automation.md +0 -139
  124. package/docs/configuration.md +0 -437
  125. package/docs/continuous-improvement.md +0 -226
  126. package/docs/getting-started.md +0 -277
  127. package/docs/harness-routing.md +0 -616
  128. package/docs/kb/qa-authentik-authentication.md +0 -97
  129. package/docs/kb/qa-extension-install-and-hub-bootstrap.md +0 -85
  130. package/docs/kb/qa-hub-on-a-public-host.md +0 -48
  131. package/docs/kb/qa-sqlite-vs-duckdb.md +0 -35
  132. package/docs/kb/qa-what-the-hub-stores.md +0 -64
  133. package/docs/kxm-handbook.md +0 -1181
  134. package/docs/operations.md +0 -510
  135. package/docs/operator-pi-packages.md +0 -67
  136. package/docs/provenance-gates.md +0 -295
  137. package/docs/skills.md +0 -47
  138. package/docs/test-matrix.md +0 -132
  139. package/docs/troubleshooting.md +0 -293
  140. package/docs/webhook-workflows.md +0 -240
@@ -1,553 +0,0 @@
1
- # Agent Communication Envelopes, Quality Gates, and Workflow Loops
2
-
3
- This guide specifies the standard communication envelopes, quality gates, work loop topologies, and structural components used for deterministic agent-to-agent (A2A) handoffs within KXM.
4
-
5
- ## Table of Contents
6
-
7
- 1. [Architectural Components for Multi-Agent Workflows](#architectural-components-for-multi-agent-workflows)
8
- 2. [Communication Envelopes for Agent Handoffs](#communication-envelopes-for-agent-handoffs)
9
- 3. [Work Loop Topologies](#work-loop-topologies)
10
- 4. [Practical Quality Gate Implementations](#practical-quality-gate-implementations)
11
- 5. [Summary Execution Checklist](#summary-execution-checklist)
12
-
13
- ---
14
-
15
- ## Architectural Components for Multi-Agent Workflows
16
-
17
- A production multi-agent system is composed of five distinct subsystem layers. For area, workflow and role naming conventions, see the [workflow guide](workflow-guide.md).
18
-
19
- ```text
20
- +------------------------------------------------------------------------+
21
- | 1. ORCHESTRATION & STATE |
22
- | Workflow Engine • Finite State Machine (DAG) • Transition Budgets |
23
- +-----------------------------------┬------------------------------------+
24
- |
25
- v
26
- +------------------------------------------------------------------------+
27
- | 2. IDENTITY, ROUTING & CAPABILITIES |
28
- | Agent Registry • Role Profiles • Tool Policies • Provider Diversity |
29
- +-----------------------------------┬------------------------------------+
30
- |
31
- v
32
- +------------------------------------------------------------------------+
33
- | 3. STRUCTURED ENVELOPES & PROVENANCE |
34
- | Assignment Manifests • Content Hashing (SHA256) • Hub Message Queue |
35
- +-----------------------------------┬------------------------------------+
36
- |
37
- v
38
- +------------------------------------------------------------------------+
39
- | 4. DETERMINISTIC QUALITY GATES |
40
- | Code Gates • Oracle Orbits • Dual-Critic Quorum • Policy Filters |
41
- +-----------------------------------┬------------------------------------+
42
- |
43
- v
44
- +------------------------------------------------------------------------+
45
- | 5. OBSERVABILITY & RECOVERY ENGINE |
46
- | Cost Telemetry • Step Attempt Limits • Back-Edge Relief • RCA Log |
47
- +------------------------------------------------------------------------+
48
- ```
49
-
50
- ### Component Responsibility Matrix
51
-
52
- | Component | Responsibility | Failure Mode Prevented |
53
- |---|---|---|
54
- | **Authoritative Coordinator** | Drives the lifecycle DAG, creates attempt-bound steps, and computes plan hashes. | Uncoordinated agent collisions and out-of-order execution. |
55
- | **Workspace Isolation** | Read/write sandboxing per step (e.g., git branch, worktree, or memory space). | Uncontrolled file overwrite and dirty uncommitted state leakage. |
56
- | **Durable Journal** | Append-only event store recording plans, decisions, contradictions, and artifacts. | Context amnesia across agent handoffs and non-reproducible runs. |
57
- | **Routing & Role Policy** | Enforces provider diversity (e.g., Writer != Critic) and cost-tier constraints. | Monoculture bias and assigning expensive frontier models to log parsing. |
58
- | **Transition Budgeter** | Restricts maximum retries and total edge transitions per workflow run. | Infinite retry loops and runaway token billing. |
59
-
60
- ---
61
-
62
- ## Communication Envelopes for Agent Handoffs
63
-
64
- In multi-agent systems and production workflow orchestrators, agent handoffs require structured, validated, and deterministic communication envelopes. Passing unstructured text between agents leads to context loss, untracked spend, unprovable reviews, and broken automation loops.
65
-
66
- ### 1. Task Delegation & Context Assignment Envelope (`kxm.assignment-request.v1`)
67
-
68
- Used by a **Planner / Coordinator** to hand off bounded, non-overlapping work to an **Implementer / Writer Agent**. It encapsulates repository state, strict tool/permission boundaries, and verifiable acceptance criteria.
69
-
70
- ```json
71
- {
72
- "schema": "kxm.assignment-request.v1",
73
- "assignmentId": "asgn_01J7N8K4D9W2X0B6",
74
- "runId": "run_01J7N8J0P4K7M8Q1",
75
- "projectId": "proj_kxm_core",
76
- "stepId": "implement-auth-contracts",
77
- "attempt": 1,
78
- "createdAt": "2026-09-06T22:50:00.000Z",
79
- "expiresAt": "2026-09-06T23:20:00.000Z",
80
- "routing": {
81
- "targetRole": "implementer",
82
- "recommendedModel": "x-ai/grok-4.6",
83
- "harness": "grok",
84
- "reasoningEffort": "medium",
85
- "economicBand": "tier-2"
86
- },
87
- "context": {
88
- "git": {
89
- "branch": "cursor/auth-contracts-82b9",
90
- "baseCommit": "e4d3c2b1a0f9e8d7c6b5a4f3e2d1c0b9a8f7e6d5",
91
- "workingDirectory": "/workspace"
92
- },
93
- "inputs": [
94
- {
95
- "type": "spec",
96
- "path": "docs/specs/auth-protocol-v2.md",
97
- "sha256": "3a7bd3e2360a3d29eea436fcfb7e44c735d117c42d1c1835420b6b9942dd4f1b"
98
- },
99
- {
100
- "type": "interface",
101
- "path": "src/types/auth.ts",
102
- "sha256": "8f4b23c6d123e4a901928bcde98123ef654321ab987654321fe4567890abcdef"
103
- }
104
- ],
105
- "privateHandoffNotes": "Prior attempt failed on TypeScript strict null checks in SessionTokenValidator. Do not relax tsconfig; explicitly guard undefined header payloads."
106
- },
107
- "constraints": {
108
- "maxTokensOut": 4096,
109
- "timeoutMs": 1800000,
110
- "toolPolicy": {
111
- "allowedTools": ["Read", "Write", "StrReplace", "Shell"],
112
- "deniedCommands": ["git push --force", "rm -rf", "npm publish"]
113
- }
114
- },
115
- "acceptanceGate": {
116
- "command": "npm run verify",
117
- "deterministicChecks": ["typecheck", "test", "lint:docs", "check:generated"]
118
- }
119
- }
120
- ```
121
-
122
- ### 2. Standard Worker Result & Execution Envelope (`kxm.worker-result.v1`)
123
-
124
- Emitted by an **Implementer / Gate Worker** back to the orchestrator upon completion. It couples the outcome with artifact references and deterministic verification evidence.
125
-
126
- ```json
127
- {
128
- "schema": "kxm.worker-result.v1",
129
- "worker": {
130
- "schema": "kxm.worker.v1",
131
- "kind": "agent",
132
- "driver": "ai",
133
- "name": "grok-writer-01",
134
- "model": "x-ai/grok-4.6",
135
- "thinking": "medium"
136
- },
137
- "command": "implement-auth-contracts",
138
- "ok": true,
139
- "outcome": "passed",
140
- "createdAt": "2026-09-06T23:04:12.450Z",
141
- "summary": "Implemented W3C DTCG compliant session validation and token refresh logic passing all verification suites.",
142
- "changes": {
143
- "filesModified": [
144
- "src/auth/session-validator.ts",
145
- "test/auth/session-validator.test.ts"
146
- ],
147
- "filesCreated": [
148
- "src/types/session-tokens.ts"
149
- ],
150
- "filesDeleted": []
151
- },
152
- "artifacts": [
153
- {
154
- "name": "unit-test-tap-output",
155
- "path": "artifacts/test-results.tap",
156
- "sha256": "d41d8cd98f00b204e9800998ecf8427e100808a94b5e28a6f3b0e2f5b82a7a4f"
157
- }
158
- ],
159
- "telemetry": {
160
- "tokensIn": 18450,
161
- "tokensOut": 1240,
162
- "cacheReadTokens": 14200,
163
- "durationMs": 14820,
164
- "costUsd": 0.0443
165
- },
166
- "verifierOutcome": {
167
- "gateCommand": "npm run verify",
168
- "exitCode": 0,
169
- "passed": true
170
- }
171
- }
172
- ```
173
-
174
- ### 3. Independent Critic & Quorum Review Envelope (`kxm.review-envelope.v1`)
175
-
176
- Used in multi-agent critic loops (e.g., dual-critic acceptance between **Claude Fable** and **Codex Sol**). It records structured pass/fail decisions, non-negotiable blockers, and rubric criteria.
177
-
178
- ```json
179
- {
180
- "schema": "kxm.review-envelope.v1",
181
- "reviewId": "rev_01J7N93M2P8Q4R6T",
182
- "assignmentId": "asgn_01J7N8K4D9W2X0B6",
183
- "reviewer": {
184
- "agentName": "claude-fable-critic",
185
- "role": "architecture_and_permissions",
186
- "model": "anthropic/claude-fable-5.1"
187
- },
188
- "createdAt": "2026-09-06T23:08:45.100Z",
189
- "verdict": "PASS",
190
- "summary": "Security boundaries, zero-trust token scopes, and fail-closed error handling verified.",
191
- "rubricEvaluation": [
192
- {
193
- "criterion": "permission_isolation",
194
- "status": "passed",
195
- "notes": "Token claims strictly enforce tenant isolation."
196
- },
197
- {
198
- "criterion": "fail_closed_semantics",
199
- "status": "passed",
200
- "notes": "Expired or malformed tokens trigger immediate 401 without stack leakage."
201
- },
202
- {
203
- "criterion": "backward_compatibility_brake",
204
- "status": "passed",
205
- "notes": "Brakes added for legacy header formats; no dual-naming shims introduced."
206
- }
207
- ],
208
- "blockers": [],
209
- "advisoryNotes": [
210
- "Consider adding rate-limiting telemetry to token revocation endpoints in Phase 4."
211
- ]
212
- }
213
- ```
214
-
215
- ### 4. Peer Request & Workflow Message Context Envelope (`kxm.message-record.v1`)
216
-
217
- When agents communicate across a central hub (HTTP/SSE), this envelope ensures message delivery, correlation, hop limits, and cryptographic tie-in to the active workflow stage.
218
-
219
- ```json
220
- {
221
- "id": "msg_01J7N98K12L3M4N5",
222
- "project": "proj_kxm_core",
223
- "from": "agent_coordinator_main",
224
- "fromName": "Lead Orchestrator",
225
- "to": "agent_critic_sol",
226
- "toName": "Codex CLI Critic",
227
- "delivery": "steer",
228
- "status": "queued",
229
- "hops": 1,
230
- "maxHops": 3,
231
- "correlationId": "corr_01J7N98K00AA11BB",
232
- "createdAt": "2026-09-06T23:10:00.000Z",
233
- "expiresAt": "2026-09-07T23:10:00.000Z",
234
- "workflowContext": {
235
- "schema": "pi-mesh.workflow-message-context.v1",
236
- "runId": "run_01J7N8J0P4K7M8Q1",
237
- "stageId": "independent_peer_review",
238
- "requirementKey": "cli_contracts_critic",
239
- "attempt": 1
240
- },
241
- "content": "Please review git diff on branch cursor/auth-contracts-82b9 against OpenAPI 3.1 specifications. Verify schema alignment and CLI argument syntax."
242
- }
243
- ```
244
-
245
- ### 5. Multi-Stage Incident Diagnostic & RCA Envelope (`kxm.diagnostic-handoff.v1`)
246
-
247
- Used in debugging pipelines where Tier-0 ingestion models (e.g., `deepseek-v4-flash`) distill huge telemetry dumps before handing off to deep forensic reasoners (e.g., `openai/o3` or `claude-opus-5`).
248
-
249
- ```json
250
- {
251
- "schema": "kxm.diagnostic-handoff.v1",
252
- "incidentId": "inc_20260906_db_deadlock",
253
- "timestamp": "2026-09-06T23:15:00.000Z",
254
- "triageLevel": "SEV-1",
255
- "ingestionSummary": {
256
- "rawLogSizeMb": 480.5,
257
- "distilledEventCount": 12,
258
- "filterModel": "deepseek/deepseek-v4-flash-0731",
259
- "compressionRatio": "99.2%"
260
- },
261
- "isolatedFaultBoundary": {
262
- "service": "billing-pipeline-worker",
263
- "subsystem": "pg-transaction-pool",
264
- "callSite": "src/transactions/settlement.ts:142",
265
- "exception": "DeadlockDetectedError: Process 41829 waits for ShareLock on transaction 891273"
266
- },
267
- "threadContentionTrace": [
268
- {
269
- "threadId": "worker-pool-8",
270
- "holdingLock": "table:invoices (row id: 8941)",
271
- "waitingOnLock": "table:wallets (row id: 102)"
272
- },
273
- {
274
- "threadId": "worker-pool-14",
275
- "holdingLock": "table:wallets (row id: 102)",
276
- "waitingOnLock": "table:invoices (row id: 8941)"
277
- }
278
- ],
279
- "reproContext": {
280
- "environment": "linux 6.12.94+ / Node 22.19.0",
281
- "isolatedPayload": {
282
- "concurrentBatches": 2,
283
- "settlementIds": ["set_991", "set_992"]
284
- }
285
- },
286
- "forensicDirective": "Determine lock ordering asymmetry between invoice reconciliation and wallet balance deductions, and draft deterministic mutex/locking patch."
287
- }
288
- ```
289
-
290
- ---
291
-
292
- ## Work Loop Topologies
293
-
294
- Agent workflows generally follow one of three operational loop architectures:
295
-
296
- ### Loop Pattern A: The Verification Loop (Plan -> Write -> Gate -> Fix)
297
-
298
- Used for new feature development, code refactoring, and bug patching.
299
-
300
- ```text
301
- +---------------+
302
- | 1. Plan/Spec | (Fable / Architecture Critic)
303
- +-------┬-------+
304
- | [Plan Hash Generated: sha256]
305
- v
306
- +---------------+
307
- +--->| 2. Implement | (Grok 4.6 / Qwen Coder)
308
- | +-------┬-------+
309
- | | [Emits: kxm.worker-result.v1 + Git Commit]
310
- | v
311
- | +---------------+ Passed
312
- | | 3. Code Gate +-------------> [Step Completed]
313
- | +-------┬-------+
314
- | | Failed (Exit Code != 0)
315
- +------------+ (Max 2 Attempts -> Else Back-Edge to Plan)
316
- ```
317
-
318
- #### Workflow Definition Example (`workflow.yaml` snippet)
319
-
320
- ```yaml
321
- steps:
322
- - id: implement-feature
323
- kind: agent
324
- agent: writer-grok
325
- maxAttempts: 2
326
- description: "Write code matching the approved plan specification."
327
- repositories:
328
- backend: write
329
- requiredEvidence:
330
- - key: implementation
331
- kind: assignment-result
332
- on:
333
- passed: verify-gate
334
- failed:
335
- target: $terminal
336
- terminalStatus: failed
337
-
338
- - id: verify-gate
339
- kind: gate
340
- command: "npm run verify"
341
- description: "Execute compiler check, test suites, and documentation linters."
342
- on:
343
- passed: dual-critic-review
344
- failed:
345
- target: implement-feature
346
- backEdgeBudget: 2
347
- ```
348
-
349
- ### Loop Pattern B: Mixture-of-Agents (MOA) Dual-Critic Quorum Loop
350
-
351
- Used for architectural RFCs, high-stakes security patches, and complex multi-repo deliveries.
352
-
353
- ```text
354
- +----------------------+
355
- | 1. Propose Artifact | (Author)
356
- +----------┬-----------+
357
- |
358
- +----------------+----------------+
359
- v v
360
- +-----------------+ +-----------------+
361
- │ Critic A: Fable │ │ Critic B: Sol │
362
- │ (Architecture) │ │ (CLI/Contracts) │
363
- +--------┬--------+ +--------┬--------+
364
- | |
365
- +----------------┬----------------+
366
- | [Hub Derive: 2/2 Passed Quorum]
367
- v
368
- +-----------------+ Quorum Met
369
- | Quorum Join +--------------> [Pass to Delivery]
370
- +--------┬--------+
371
- | Blockers Present (Dissent)
372
- v
373
- +-----------------+
374
- | 2. Remediation | (Author)
375
- +-----------------+
376
- ```
377
-
378
- #### Quorum Policy Configuration (`policy.yaml` snippet)
379
-
380
- ```yaml
381
- joinPolicy:
382
- strategy: quorum
383
- minimumPassed: 2
384
- cancelRemaining: true
385
-
386
- producerPolicy:
387
- minimumProducers: 2
388
- distinctBy:
389
- - provider
390
- - model
391
- eligibleAgents:
392
- - claude-fable-critic
393
- - gpt-sol-critic
394
- acceptedStatuses:
395
- - passed
396
- ```
397
-
398
- ### Loop Pattern C: Repro-Before-Oracle Loop
399
-
400
- Used for production incident triage, race condition diagnosis, and regression repair.
401
-
402
- ```text
403
- +----------------------+
404
- | 1. Incident Telemetry|
405
- +----------┬-----------+
406
- v
407
- +----------------------+
408
- | 2. Reproducer Agent | (Writes isolated test that asserts failure)
409
- +----------┬-----------+
410
- v
411
- +----------------------+ Test Must Fail (Exit != 0)
412
- | 3. Repro Gate Check +--------------+
413
- +----------┬-----------+ |
414
- | Fails to Repro v
415
- | +----------------------+
416
- v | 4. Implement Fix |
417
- [Reject / Re-triage] +----------┬-----------+
418
- |
419
- v
420
- +----------------------+ Test Must Pass (Exit == 0)
421
- | 5. Oracle Gate Check +-------------> [Deliver Patch]
422
- +----------------------+
423
- ```
424
-
425
- ---
426
-
427
- ## Practical Quality Gate Implementations
428
-
429
- A quality gate is a **deterministic barrier** that evaluates evidence against non-negotiable assertions.
430
-
431
- ### Gate 1: The Deterministic Code Gate (Deterministic CLI)
432
-
433
- This gate runs headless in CI/CD or local sandboxes. It executes code linters, typecheckers, unit tests, and generated asset verifiers.
434
-
435
- #### Verification Script (`scripts/verify-gate.mjs`)
436
-
437
- ```javascript
438
- #!/usr/bin/env node
439
- import { execSync } from "node:child_process";
440
- import { writeFileSync } from "node:fs";
441
-
442
- const checks = [
443
- { name: "TypeScript Typecheck", cmd: "npx tsc --noEmit" },
444
- { name: "Documentation Linter", cmd: "npx markdownlint-cli2 '**/*.md' '#node_modules'" },
445
- { name: "Unit & Integration Tests", cmd: "npm test" },
446
- { name: "Generated Artifact Drift", cmd: "npm run check:generated" }
447
- ];
448
-
449
- const results = [];
450
- let gatePassed = true;
451
-
452
- for (const check of checks) {
453
- const start = Date.now();
454
- try {
455
- execSync(check.cmd, { stdio: "pipe", encoding: "utf8" });
456
- results.push({ name: check.name, status: "passed", durationMs: Date.now() - start });
457
- } catch (error) {
458
- gatePassed = false;
459
- results.push({
460
- name: check.name,
461
- status: "failed",
462
- durationMs: Date.now() - start,
463
- errorOutput: error.stderr || error.stdout || error.message
464
- });
465
- break; // Fail-closed immediately
466
- }
467
- }
468
-
469
- const gateResultEnvelope = {
470
- schema: "kxm.worker-result.v1",
471
- worker: { schema: "kxm.worker.v1", kind: "gate", driver: "code", name: "deterministic-verify-gate" },
472
- command: "npm run verify",
473
- ok: gatePassed,
474
- outcome: gatePassed ? "passed" : "failed",
475
- createdAt: new Date().toISOString(),
476
- summary: gatePassed ? "All 4 verification stages passed cleanly." : `Gate failure on stage: ${results.at(-1).name}`,
477
- checks: results
478
- };
479
-
480
- writeFileSync(".kxm/state/gate-result.json", JSON.stringify(gateResultEnvelope, null, 2));
481
- process.exit(gatePassed ? 0 : 1);
482
- ```
483
-
484
- ### Gate 2: The Multi-Agent Quorum Gate (Hub Verification)
485
-
486
- Verifies that required review evidence originates from **eligible independent producers** without relying on self-reported agent summaries.
487
-
488
- #### Quorum Evaluation Logic (`plugins/kxm/src/arbiter.ts` snippet)
489
-
490
- ```typescript
491
- export interface QuorumRequirement {
492
- stageId: string;
493
- minProducers: number;
494
- distinctProviders: boolean;
495
- requiredReviews: Array<{ reviewerId: string; provider: string; verdict: "PASS" | "FAIL" }>;
496
- }
497
-
498
- export function evaluateReviewQuorum(req: QuorumRequirement): { passed: boolean; reason: string } {
499
- const passingReviews = req.requiredReviews.filter(r => r.verdict === "PASS");
500
-
501
- if (passingReviews.length < req.minProducers) {
502
- return {
503
- passed: false,
504
- reason: `Quorum incomplete: received ${passingReviews.length}/${req.minProducers} PASS verdicts.`
505
- };
506
- }
507
-
508
- if (req.distinctProviders) {
509
- const providers = new Set(passingReviews.map(r => r.provider));
510
- if (providers.size < req.minProducers) {
511
- return {
512
- passed: false,
513
- reason: "Provider diversity violation: passing reviews must originate from distinct model providers."
514
- };
515
- }
516
- }
517
-
518
- return { passed: true, reason: "Quorum verified with independent provider consensus." };
519
- }
520
- ```
521
-
522
- ### Gate 3: The Content & Plan Integrity Gate (SHA-256 Oracle)
523
-
524
- Ensures that an implementer or delivery agent has not drifted from the exact specification approved during the planning phase.
525
-
526
- ```typescript
527
- import { createHash } from "node:crypto";
528
- import { readFileSync } from "node:fs";
529
-
530
- export function verifyPlanIntegrity(planFilePath: string, expectedPlanHash: string): boolean {
531
- const fileContent = readFileSync(planFilePath, "utf8");
532
- const actualHash = createHash("sha256").update(fileContent.trim()).digest("hex");
533
-
534
- if (actualHash !== expectedPlanHash) {
535
- throw new Error(
536
- `Plan Integrity Gate Failed: Expected hash ${expectedPlanHash}, but found ${actualHash}. Specification modified without re-approval.`
537
- );
538
- }
539
- return true;
540
- }
541
- ```
542
-
543
- ---
544
-
545
- ## Summary Execution Checklist
546
-
547
- ```text
548
- [ ] 1. Bounded Context: Is the handoff constrained by an immutable commit SHA and plan hash?
549
- [ ] 2. Strict Schemas: Do all input/output payloads validate against strict JSON schemas?
550
- [ ] 3. Provider Independence: Are critics running on different model providers than writers?
551
- [ ] 4. Deterministic Brakes: Is there a code gate (e.g., npm run verify) before any human review?
552
- [ ] 5. Finite Transitions: Are back-edge loops capped to <= 2 retry attempts before escalation?
553
- ```