@kontextmind/kxm 0.6.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 (227) hide show
  1. package/.claude-plugin/marketplace.json +19 -0
  2. package/.kxm/README.md +14 -0
  3. package/.kxm/assets/README.md +5 -0
  4. package/.kxm/assets/retrospectives/README.md +5 -0
  5. package/.kxm/config/README.md +5 -0
  6. package/.kxm/config/agents.json +43 -0
  7. package/.kxm/config/env.example +56 -0
  8. package/.kxm/config/update.example.yaml +9 -0
  9. package/.kxm/config/workflows/fix.json +160 -0
  10. package/.kxm/config/workflows/jira-development.json +116 -0
  11. package/.kxm/config/workflows/provenance-quorum.json +150 -0
  12. package/.kxm/config/workflows/v04-dogfood.json +72 -0
  13. package/CHANGELOG.md +465 -0
  14. package/LICENSE +21 -0
  15. package/README.md +306 -0
  16. package/SECURITY.md +72 -0
  17. package/docs/README.md +48 -0
  18. package/docs/agent-communication-envelopes-and-gates.md +553 -0
  19. package/docs/architecture.md +242 -0
  20. package/docs/assignment-runner.md +241 -0
  21. package/docs/configuration.md +361 -0
  22. package/docs/continuous-improvement.md +114 -0
  23. package/docs/getting-started.md +253 -0
  24. package/docs/kxm-handbook.md +1090 -0
  25. package/docs/operations.md +205 -0
  26. package/docs/provenance-gates.md +291 -0
  27. package/docs/skills.md +45 -0
  28. package/docs/templates/README.md +95 -0
  29. package/docs/templates/adr.md +88 -0
  30. package/docs/templates/architecture.md +120 -0
  31. package/docs/templates/bug-fix.md +109 -0
  32. package/docs/templates/feature.md +108 -0
  33. package/docs/templates/handoff.md +72 -0
  34. package/docs/templates/postmortem.md +77 -0
  35. package/docs/templates/research.md +100 -0
  36. package/docs/templates/review.md +85 -0
  37. package/docs/templates/runbook.md +73 -0
  38. package/docs/templates/test-plan.md +87 -0
  39. package/docs/templates/test-report.md +72 -0
  40. package/docs/test-matrix.md +121 -0
  41. package/docs/troubleshooting.md +249 -0
  42. package/docs/vnext/README.md +62 -0
  43. package/docs/vnext/architecture.md +185 -0
  44. package/docs/vnext/effects-and-recovery.md +172 -0
  45. package/docs/vnext/lifecycles.md +235 -0
  46. package/docs/vnext/migration.md +220 -0
  47. package/docs/vnext/routing.md +184 -0
  48. package/docs/vnext/synchronization.md +172 -0
  49. package/docs/vnext/terminology.md +240 -0
  50. package/docs/vnext/validation.md +335 -0
  51. package/docs/webhook-workflows.md +240 -0
  52. package/docs/workflow-guide.md +1150 -0
  53. package/examples/README.md +102 -0
  54. package/examples/provenance-workflow.json +40 -0
  55. package/examples/requester.ts +30 -0
  56. package/examples/reviewer-agent.ts +29 -0
  57. package/examples/roundtrip.ts +46 -0
  58. package/examples/vnext/.kxm/agents/coordinator.yaml +16 -0
  59. package/examples/vnext/.kxm/agents/critic-1.yaml +16 -0
  60. package/examples/vnext/.kxm/agents/critic-2.yaml +15 -0
  61. package/examples/vnext/.kxm/agents/critic-3.yaml +15 -0
  62. package/examples/vnext/.kxm/agents/implementer.yaml +15 -0
  63. package/examples/vnext/.kxm/agents/planner.yaml +13 -0
  64. package/examples/vnext/.kxm/agents/reproducer.yaml +15 -0
  65. package/examples/vnext/.kxm/agents/reviewer.yaml +15 -0
  66. package/examples/vnext/.kxm/gates.yaml +8 -0
  67. package/examples/vnext/.kxm/models/critic-claude.yaml +11 -0
  68. package/examples/vnext/.kxm/models/critic-gemini.yaml +11 -0
  69. package/examples/vnext/.kxm/models/critic-grok.yaml +12 -0
  70. package/examples/vnext/.kxm/models/implementation.yaml +14 -0
  71. package/examples/vnext/.kxm/models/primary.yaml +17 -0
  72. package/examples/vnext/.kxm/prices.yaml +111 -0
  73. package/examples/vnext/.kxm/project/env.yaml +7 -0
  74. package/examples/vnext/.kxm/project.yaml +32 -0
  75. package/examples/vnext/.kxm/repo/repo.yaml +8 -0
  76. package/examples/vnext/.kxm/workflows/default.yaml +92 -0
  77. package/examples/vnext/.kxm/workflows/fix.yaml +376 -0
  78. package/examples/vnext/.kxm/workflows/improve.yaml +57 -0
  79. package/examples/vnext/README.md +53 -0
  80. package/examples/vnext/records/assignment-result-recorded.json +63 -0
  81. package/examples/vnext/records/assignment-result.json +46 -0
  82. package/examples/vnext/records/context-candidate.json +42 -0
  83. package/examples/vnext/records/delivery-manifest.json +66 -0
  84. package/examples/vnext/records/effect-uncertainty-resolved-sync.json +67 -0
  85. package/examples/vnext/records/effect-uncertainty-resolved.json +62 -0
  86. package/examples/vnext/records/run-created.json +54 -0
  87. package/examples/vnext/records/sync-event.json +65 -0
  88. package/examples/vnext/repositories/api/.kxm/repo/env.yaml +7 -0
  89. package/examples/vnext/repositories/api/.kxm/repo/repo.yaml +8 -0
  90. package/examples/vnext/repositories/web/.kxm/repo/repo.yaml +8 -0
  91. package/examples/workflow-signal.ts +63 -0
  92. package/package.json +129 -0
  93. package/plugins/kxm/.claude-plugin/plugin.json +73 -0
  94. package/plugins/kxm/.mcp.json +19 -0
  95. package/plugins/kxm/README.md +93 -0
  96. package/plugins/kxm/dist/cli.js +42853 -0
  97. package/plugins/kxm/dist/client.js +416 -0
  98. package/plugins/kxm/dist/core.js +1823 -0
  99. package/plugins/kxm/dist/extension.js +3797 -0
  100. package/plugins/kxm/dist/mcp-server.js +17104 -0
  101. package/plugins/kxm/dist/runtime.js +23361 -0
  102. package/plugins/kxm/dist/server.js +13640 -0
  103. package/plugins/kxm/dist/vnext-runtime-supervisor.js +21109 -0
  104. package/plugins/kxm/package.json +12 -0
  105. package/plugins/kxm/skills/kxm/SKILL.md +97 -0
  106. package/plugins/kxm/skills/kxm/references/protocol.md +103 -0
  107. package/plugins/kxm/skills/kxm-session/SKILL.md +53 -0
  108. package/plugins/kxm/src/arbiter.ts +355 -0
  109. package/plugins/kxm/src/artifacts-exist.ts +62 -0
  110. package/plugins/kxm/src/autocomplete.ts +236 -0
  111. package/plugins/kxm/src/cli.ts +3707 -0
  112. package/plugins/kxm/src/client.ts +614 -0
  113. package/plugins/kxm/src/commands.ts +1063 -0
  114. package/plugins/kxm/src/config.ts +290 -0
  115. package/plugins/kxm/src/context/providers.ts +101 -0
  116. package/plugins/kxm/src/context-packet.ts +332 -0
  117. package/plugins/kxm/src/context.ts +499 -0
  118. package/plugins/kxm/src/core.ts +6 -0
  119. package/plugins/kxm/src/database.ts +563 -0
  120. package/plugins/kxm/src/diagnostics.ts +184 -0
  121. package/plugins/kxm/src/envelope.ts +118 -0
  122. package/plugins/kxm/src/extension.ts +895 -0
  123. package/plugins/kxm/src/external-effects.ts +299 -0
  124. package/plugins/kxm/src/github-watch.ts +255 -0
  125. package/plugins/kxm/src/hub-binding.ts +160 -0
  126. package/plugins/kxm/src/hub.ts +2502 -0
  127. package/plugins/kxm/src/improve.ts +383 -0
  128. package/plugins/kxm/src/inbox.ts +10 -0
  129. package/plugins/kxm/src/kxm-install-kind.ts +113 -0
  130. package/plugins/kxm/src/kxm-update-config.ts +39 -0
  131. package/plugins/kxm/src/kxm-update.ts +238 -0
  132. package/plugins/kxm/src/local-snapshot.ts +406 -0
  133. package/plugins/kxm/src/logger.ts +198 -0
  134. package/plugins/kxm/src/mcp-server.ts +143 -0
  135. package/plugins/kxm/src/memory.ts +385 -0
  136. package/plugins/kxm/src/nous-pi.ts +287 -0
  137. package/plugins/kxm/src/nous-provider.ts +729 -0
  138. package/plugins/kxm/src/price-calc.ts +87 -0
  139. package/plugins/kxm/src/prices.ts +121 -0
  140. package/plugins/kxm/src/protocol.ts +172 -0
  141. package/plugins/kxm/src/recovery.ts +211 -0
  142. package/plugins/kxm/src/redact.ts +26 -0
  143. package/plugins/kxm/src/retrospective.ts +400 -0
  144. package/plugins/kxm/src/routing.ts +830 -0
  145. package/plugins/kxm/src/runtime.ts +9 -0
  146. package/plugins/kxm/src/server.ts +117 -0
  147. package/plugins/kxm/src/session-work.ts +571 -0
  148. package/plugins/kxm/src/session.ts +184 -0
  149. package/plugins/kxm/src/skills.ts +535 -0
  150. package/plugins/kxm/src/state.ts +326 -0
  151. package/plugins/kxm/src/store.ts +637 -0
  152. package/plugins/kxm/src/studio-layout.ts +268 -0
  153. package/plugins/kxm/src/suggest.ts +162 -0
  154. package/plugins/kxm/src/task-manager.ts +244 -0
  155. package/plugins/kxm/src/telemetry.ts +116 -0
  156. package/plugins/kxm/src/tui.ts +1046 -0
  157. package/plugins/kxm/src/vnext-bindings.ts +403 -0
  158. package/plugins/kxm/src/vnext-config.ts +1646 -0
  159. package/plugins/kxm/src/vnext-engine-artifacts.ts +86 -0
  160. package/plugins/kxm/src/vnext-engine-command.ts +533 -0
  161. package/plugins/kxm/src/vnext-engine-compile.ts +722 -0
  162. package/plugins/kxm/src/vnext-engine-evidence.ts +273 -0
  163. package/plugins/kxm/src/vnext-engine-fold.ts +1400 -0
  164. package/plugins/kxm/src/vnext-engine-gate-records.ts +583 -0
  165. package/plugins/kxm/src/vnext-engine-plan.ts +717 -0
  166. package/plugins/kxm/src/vnext-engine.ts +2458 -0
  167. package/plugins/kxm/src/vnext-gate-hash.ts +10 -0
  168. package/plugins/kxm/src/vnext-harness.ts +1142 -0
  169. package/plugins/kxm/src/vnext-init.ts +430 -0
  170. package/plugins/kxm/src/vnext-migrate.ts +1848 -0
  171. package/plugins/kxm/src/vnext-oneshot-producer.ts +424 -0
  172. package/plugins/kxm/src/vnext-permission.ts +936 -0
  173. package/plugins/kxm/src/vnext-pi-producer.ts +628 -0
  174. package/plugins/kxm/src/vnext-repair.ts +1094 -0
  175. package/plugins/kxm/src/vnext-runtime-owner.ts +320 -0
  176. package/plugins/kxm/src/vnext-runtime-store.ts +1560 -0
  177. package/plugins/kxm/src/vnext-runtime-supervisor.ts +586 -0
  178. package/plugins/kxm/src/vnext-runtime.ts +663 -0
  179. package/plugins/kxm/src/vnext-template.ts +247 -0
  180. package/plugins/kxm/src/wiki.ts +313 -0
  181. package/plugins/kxm/src/workflow.ts +1548 -0
  182. package/schemas/vnext/README.md +46 -0
  183. package/schemas/vnext/agent.schema.json +40 -0
  184. package/schemas/vnext/assignment-result.schema.json +66 -0
  185. package/schemas/vnext/backup-manifest.schema.json +89 -0
  186. package/schemas/vnext/candidate.schema.json +109 -0
  187. package/schemas/vnext/common.schema.json +422 -0
  188. package/schemas/vnext/context-candidate.schema.json +76 -0
  189. package/schemas/vnext/context-packet.schema.json +192 -0
  190. package/schemas/vnext/delivery-manifest.schema.json +159 -0
  191. package/schemas/vnext/environment.schema.json +66 -0
  192. package/schemas/vnext/gate-registry.schema.json +109 -0
  193. package/schemas/vnext/handoff-manifest.schema.json +146 -0
  194. package/schemas/vnext/init-operation.schema.json +61 -0
  195. package/schemas/vnext/local-repository-bindings.schema.json +30 -0
  196. package/schemas/vnext/memory-record.schema.json +45 -0
  197. package/schemas/vnext/migration-decision.schema.json +26 -0
  198. package/schemas/vnext/migration-plan.schema.json +123 -0
  199. package/schemas/vnext/migration-receipt.schema.json +52 -0
  200. package/schemas/vnext/model.schema.json +42 -0
  201. package/schemas/vnext/permission-diff.schema.json +57 -0
  202. package/schemas/vnext/prices.schema.json +115 -0
  203. package/schemas/vnext/project.schema.json +85 -0
  204. package/schemas/vnext/repository.schema.json +24 -0
  205. package/schemas/vnext/run-event.schema.json +460 -0
  206. package/schemas/vnext/session-brief.schema.json +153 -0
  207. package/schemas/vnext/sync-event.schema.json +234 -0
  208. package/schemas/vnext/template-provenance.schema.json +38 -0
  209. package/schemas/vnext/workflow.schema.json +248 -0
  210. package/scripts/assignment-run.d.mts +354 -0
  211. package/scripts/assignment-run.mjs +4451 -0
  212. package/scripts/build-runtime.mjs +56 -0
  213. package/scripts/check-generated.mjs +77 -0
  214. package/scripts/check-versions.mjs +34 -0
  215. package/scripts/emit-codex-artifacts.d.mts +9 -0
  216. package/scripts/emit-codex-artifacts.mjs +91 -0
  217. package/scripts/harness-run.d.mts +83 -0
  218. package/scripts/harness-run.mjs +2095 -0
  219. package/scripts/kxm-hub.mjs +105 -0
  220. package/scripts/kxm-publish-npm.mjs +327 -0
  221. package/scripts/kxm-release-github.mjs +472 -0
  222. package/scripts/kxm-runtime-supervisor.mjs +7 -0
  223. package/scripts/kxm-worker.mjs +1127 -0
  224. package/scripts/kxm.mjs +27 -0
  225. package/scripts/roster-policy.d.mts +20 -0
  226. package/scripts/roster-policy.mjs +161 -0
  227. package/scripts/smoke-multi-pi.mjs +479 -0
@@ -0,0 +1,88 @@
1
+ ---
2
+ schema: "kxm.doc.v1"
3
+ id: "ADR-0001"
4
+ type: "adr"
5
+ title: "Title of Architecture Decision"
6
+ project: "kxm"
7
+ status: "proposed" # proposed | accepted | superseded | deprecated | rejected
8
+ owner: "@owner"
9
+ created: "2026-09-08"
10
+ updated: "2026-09-08"
11
+ authority: "instruction"
12
+ confidence: "verified"
13
+ summary: "Short decision summary and primary technical consequence."
14
+ tags: ["architecture", "decision"]
15
+ related: []
16
+ details:
17
+ decision_drivers: ["concurrency-safety", "dependency-minimization"]
18
+ supersedes: null
19
+ superseded_by: null
20
+ ---
21
+
22
+ # ADR-0001: <Title of Architecture Decision>
23
+
24
+ ## Context & Problem Statement
25
+
26
+ <Describe the technical context, operational dilemma, or architectural friction. What forces are compelling this decision?>
27
+
28
+ ## Decision Drivers
29
+
30
+ 1. **Driver 1:** <e.g., Eliminate native compilation failures across Node versions>
31
+
32
+ 2. **Driver 2:** <e.g., Enforce deterministic replay without external network calls>
33
+
34
+ 3. **Driver 3:** <e.g., Maintain fail-closed security invariants without loopback bypasses>
35
+
36
+ ## Considered Options
37
+
38
+ - **Option A:** <Name of Option A>
39
+
40
+ - **Option B:** <Name of Option B>
41
+
42
+ - **Option C:** <Name of Option C>
43
+
44
+ ## Evaluation & Tradeoff Matrix
45
+
46
+ ### Option A: <Name of Option A>
47
+
48
+ - **Good, because:** <Advantage 1>
49
+
50
+ - **Good, because:** <Advantage 2>
51
+
52
+ - **Bad, because:** <Drawback 1>
53
+
54
+ - **Bad, because:** <Drawback 2>
55
+
56
+ ### Option B: <Name of Option B>
57
+
58
+ - **Good, because:** <Advantage 1>
59
+
60
+ - **Bad, because:** <Drawback 1>
61
+
62
+ ## Decision Outcome
63
+
64
+ **Chosen Option:** **Option A**, because <comprehensive justification referencing drivers>.
65
+
66
+ ### Positive Consequences
67
+
68
+ - <Favorable outcome 1>
69
+
70
+ - <Favorable outcome 2>
71
+
72
+ ### Negative Consequences & Accepted Tradeoffs
73
+
74
+ - <Technical debt, limitation, or operational overhead incurred>
75
+
76
+ ## Confirmation & Verification Strategy
77
+
78
+ - **Verification Gate:** <Exact test suite or contract check enforcing this decision>
79
+
80
+ - **Enforcement Mechanism:** <Linter, type-check, or CI rule that prevents regressions>
81
+
82
+ ## Revisit Conditions
83
+
84
+ This decision should be formally re-evaluated if:
85
+
86
+ 1. <Condition 1, e.g., Upstream Node.js deprecates the built-in API>
87
+
88
+ 2. <Condition 2, e.g., Telemetry reveals unresolvable lock contention under 100+ concurrent workers>
@@ -0,0 +1,120 @@
1
+ ---
2
+ schema: "kxm.doc.v1"
3
+ id: "ARCH-0001"
4
+ type: "architecture"
5
+ title: "System / Subsystem Architecture Design"
6
+ project: "kxm"
7
+ status: "draft" # draft | in_review | approved | superseded | archived
8
+ owner: "@owner"
9
+ created: "2026-09-08"
10
+ updated: "2026-09-08"
11
+ authority: "instruction"
12
+ confidence: "verified"
13
+ summary: "System boundaries, component responsibilities, and runtime invariants."
14
+ tags: []
15
+ related: []
16
+ details:
17
+ describes: "proposed" # current | proposed | target
18
+ baseline_commit: "<git-sha>"
19
+ ---
20
+
21
+ # Architecture: <System / Subsystem Name>
22
+
23
+ ## Purpose & Scope
24
+
25
+ - **Core Mission:** <What capability does this subsystem deliver?>
26
+
27
+ - **Audience & Callers:** <Who interacts with this system (interactive operators, workers, external webhooks)?>
28
+
29
+ - **Architecture State:** <Explicitly state whether this document reflects current, proposed, or target architecture>
30
+
31
+ ## Goals, Quality Attributes & Constraints
32
+
33
+ | Goal / Constraint | Business or Technical Driver | Measurement Metric / Hard Boundary |
34
+
35
+ |---|---|---|
36
+ | Fail-Closed Security | Prevent privilege escalation | Reject missing tokens; zero loopback bypasses |
37
+
38
+ | Deterministic Replay | Forensic debugging & auditability | Folded event stream produces identical state |
39
+ | Low Latency Dispatch | Operator responsiveness | Sub-200ms dispatch P50 |
40
+
41
+ ## Context & Trust Boundaries
42
+
43
+ ```mermaid
44
+ flowchart TB
45
+ subgraph External ["Untrusted External Perimeter"]
46
+ Caller["Operator / External Webhook / CI"]
47
+ end
48
+
49
+ subgraph AuthPlane ["Access Control Plane (Trust Boundary)"]
50
+ TokenVal["Token Validator (Admin / Session / Attempt)"]
51
+ end
52
+
53
+ subgraph Internal ["KXM Core Domain"]
54
+ Engine["Temporal Workflow Engine"]
55
+ Memory["5-Layer Memory & Context Arbiter"]
56
+ Store[("SQLite Store: .kxm/state/kxm.db")]
57
+ end
58
+
59
+ Caller -->|Request + Token| TokenVal
60
+ TokenVal -->|Authorized Call| Engine
61
+ Engine --> Memory
62
+ Engine --> Store
63
+
64
+ ```
65
+
66
+ *Context flow: External requests enter through the Access Control Plane. Authorized calls interact with the Temporal Engine and Context Arbiter, backed by durable SQLite storage.*
67
+
68
+ ## Component Responsibilities & Ownership
69
+
70
+ | Component | Responsibility | Public Interface / Contract | Owned State / Tables | Team / Role Owner |
71
+
72
+ |---|---|---|---|---|
73
+ | Workflow Engine | DAG scheduling & loop transitions | `VnextEngine.drive()` | `run_events`, `workflow_runs` | Engine Lead |
74
+
75
+ | Context Arbiter | Token budgeting & context compilation | `arbitrate()` | In-memory pool + Git memory | Memory Lead |
76
+ | External Effects Ledger | CAS leasing & idempotency | `ExternalEffectsLedger` | `external_effects` | Platform Lead |
77
+
78
+ ## Runtime Execution Scenarios
79
+
80
+ ### 1. Happy Path Dispatch & Settlement
81
+
82
+ 1. Step dispatch compiles `FormalContextPacket` (`kxm.context-packet.v2`).
83
+
84
+ 2. Worker executes in isolated branch `kxm/run-<id>-<description>`.
85
+
86
+ 3. Worker submits `kxm.handoff-manifest.v1` with witness receipt.
87
+
88
+ 4. Engine commits transition and notifies critics.
89
+
90
+ ### 2. Failure & Rework Path
91
+
92
+ 1. Critic issues structured rejection findings with blocker severity.
93
+
94
+ 2. Engine transitions step to `rejected_rework_required`.
95
+
96
+ 3. Attempts counter increments; router dispatches to next eligible writer.
97
+
98
+ ## Data Contracts, Storage & Invariants
99
+
100
+ - **Source of Truth:** Local-first SQLite (`.kxm/state/kxm.db`) using native `DatabaseSync` (`node:sqlite`).
101
+
102
+ - **Journal Mode:** WAL mode with `busy_timeout = 5000ms` and `synchronous = NORMAL`.
103
+
104
+ - **Branch Naming Invariant:** `kxm/run-<cleanId>-<slug>` generated deterministically.
105
+
106
+ - **Commit Pinning:** Never fall back to mutable `HEAD`; strictly pin `reviewedCommit`.
107
+
108
+ ## Security & Isolation
109
+
110
+ - **Token Model:** 3-tier model (AdminToken, SessionToken, AttemptToken).
111
+
112
+ - **Process Isolation:** Worker processes run as detached children with bounded stdio frames.
113
+
114
+ - **Git Worktree Lock:** Concurrent worktree mutations acquire `.git/kxm-worktree.lock`.
115
+
116
+ ## Architectural Decisions (ADR Index)
117
+
118
+ - [`ADR-0001: SQLite Native node:sqlite Engine`](../decisions/ADR-0001.md)
119
+
120
+ - [`ADR-0002: Deterministic Run Branching`](../decisions/ADR-0002.md)
@@ -0,0 +1,109 @@
1
+ ---
2
+ schema: "kxm.doc.v1"
3
+ id: "BUG-0001"
4
+ type: "bug"
5
+ title: "Observable Failure / Defect Summary"
6
+ project: "kxm"
7
+ status: "draft" # draft | in_review | approved | superseded | archived
8
+ owner: "@owner"
9
+ created: "2026-09-08"
10
+ updated: "2026-09-08"
11
+ authority: "instruction"
12
+ confidence: "verified"
13
+ summary: "Expected behavior, observed failure, and scope of regression."
14
+ tags: []
15
+ related: []
16
+ details:
17
+ fix_status: "triaged" # triaged | repro_confirmed | in_progress | verified | closed
18
+ severity: "high" # critical | high | medium | low
19
+ reproducibility: "always" # always | intermittent | environment_specific
20
+ ---
21
+
22
+ # Bug: <Observable Failure / Defect Summary>
23
+
24
+ ## Impact & Affected Scope
25
+
26
+ - **User / Operator Impact:** <What fails, crashes, or produces incorrect outputs?>
27
+
28
+ - **Affected Commands / APIs:** <Specific CLI commands, endpoints, or workflows>
29
+
30
+ - **Workaround:** <Temporary safe mitigation if available>
31
+
32
+ ## Expected vs. Actual Behavior
33
+
34
+ - **Expected:** <Precise, observable contract expectation>
35
+
36
+ - **Actual:** <Exact error message, stack trace, or wrong output>
37
+
38
+ ## Environment & Baseline State
39
+
40
+ - **Baseline Commit:** `<git-sha-before-fix>`
41
+
42
+ - **Node / Runtime Version:** `Node 22.19.0 / Node 24.15.0`
43
+
44
+ - **Active Harness / Model:** `<Harness and model if relevant>`
45
+
46
+ - **OS:** `macOS / Linux`
47
+
48
+ ## Mandatory Repro Before Fix (Oracle Invariant)
49
+
50
+ To prevent phantom fixes, a failing reproduction test MUST be established before modifying production code:
51
+
52
+ - **Failing Test File:** `test/core/<bug-name>.test.ts`
53
+
54
+ - **Reproduction Command:** `node --test test/core/<bug-name>.test.ts`
55
+
56
+ - **Baseline Observed Result:** `FAIL` (exit code 1)
57
+
58
+ - **Repro Failure Receipt:** `artifact:.kxm/assets/repro-fail.log@sha256:...`
59
+
60
+ ## Failure Path Sequence
61
+
62
+ ```mermaid
63
+ sequenceDiagram
64
+ participant C as Caller / CLI
65
+ participant H as Hub / Engine
66
+ participant S as Store / Provider
67
+
68
+ C->>H: Execute Action (e.g. claimEffect)
69
+ H->>S: Mutate State Without Lock
70
+ S-->>H: SQLite Lock Contention / Collision
71
+ H-->>C: Unhandled Crash (Expected: Graceful Retry)
72
+
73
+ ```
74
+
75
+ *Failure sequence: Unhandled contention leads to ungraceful crash instead of deterministic retry or clean fail-closed error.*
76
+
77
+ ## Root Cause Analysis
78
+
79
+ - **Immediate Cause:** <What line or condition directly triggered the symptom?>
80
+
81
+ - **Systemic Cause:** <Why did earlier tests, linters, or reviews miss this bug?>
82
+
83
+ - **Rejected Hypotheses:** <What initial assumptions were investigated and ruled out?>
84
+
85
+ ## Proposed Fix & Contract Changes
86
+
87
+ - **Code Changes:** <Summary of modifications to code or schemas>
88
+
89
+ - **Compatibility Impact:** <Does this break existing state or require a database migration?>
90
+
91
+ - **Security / Isolation:** <Does the fix maintain fail-closed invariants?>
92
+
93
+ ## Verification Witness Matrix
94
+
95
+ | Verification Check | Target Commit / Tree | Expected Result | Actual Result | Witness Artifact |
96
+
97
+ |---|---|---|---|---|
98
+ | Repro Test (Before Fix) | `<baseline-commit>` | FAIL | FAIL | `artifact:...@sha256` |
99
+
100
+ | Repro Test (After Fix) | `<candidate-commit>` | PASS | PASS | `artifact:...@sha256` |
101
+ | Full Core Test Suite | `<candidate-commit>` | 100% PASS | 100% PASS | `npm run test:core` |
102
+
103
+ | Full Verify Gate | `<candidate-commit>` | PASS | PASS | `npm run verify` |
104
+
105
+ ## Regression Prevention
106
+
107
+ - **Automated Gate Added:** <New unit test or lint check preventing recurrence>
108
+
109
+ - **Documentation Updated:** <Link to updated architecture or runbook doc>
@@ -0,0 +1,108 @@
1
+ ---
2
+ schema: "kxm.doc.v1"
3
+ id: "FEAT-0001"
4
+ type: "feature"
5
+ title: "Feature Name"
6
+ project: "kxm"
7
+ status: "draft" # draft | in_review | approved | superseded | archived
8
+ owner: "@owner"
9
+ created: "2026-09-08"
10
+ updated: "2026-09-08"
11
+ authority: "instruction" # policy | instruction | evidence | hypothesis
12
+ confidence: "verified" # verified | probable | uncertain
13
+ summary: "One-sentence problem statement and intended observable outcome."
14
+ tags: []
15
+ related: []
16
+ details:
17
+ delivery_status: "proposed"
18
+ target_workflow: "feature-delivery"
19
+ ---
20
+
21
+ # Feature: <Feature Name>
22
+
23
+ ## Problem & Users
24
+
25
+ - **Who needs this:** <Describe primary user persona or operator role>
26
+
27
+ - **Current Behavior:** <What happens today without this feature>
28
+
29
+ - **Evidence / Driver:** <User friction, issue link, or performance data demonstrating the need>
30
+
31
+ ## Goals & Non-Goals
32
+
33
+ - **Goals:**
34
+ - <Measurable outcome 1>
35
+ - <Measurable outcome 2>
36
+
37
+ - **Non-Goals:**
38
+ - <Explicitly excluded behavior or deferred capability>
39
+
40
+ ## Requirements & Acceptance Criteria
41
+
42
+ | ID | Requirement | Acceptance Criterion (Given / When / Then) | Verification Kind |
43
+
44
+ |---|---|---|---|
45
+ | REQ-01 | <Observable behavior> | Given ..., when ..., then ... | gate / witness |
46
+
47
+ | REQ-02 | <Error or permission boundary> | Given invalid input, when submitted, then fail closed with ... | gate / witness |
48
+
49
+ ## User & Execution Flow
50
+
51
+ ```mermaid
52
+ flowchart LR
53
+ User[User / Operator Action] --> Validate{Input & Access Valid?}
54
+ Validate -->|Yes| Execute[Perform Operation]
55
+ Validate -->|No| Error[Return Actionable Fail-Closed Error]
56
+ Execute --> Witness[Run Witness Verification]
57
+ Witness --> Result[Render Outcome]
58
+
59
+ ```
60
+
61
+ *Flow description: The request is validated against permissions and schema before execution. Invalid calls fail closed with actionable errors.*
62
+
63
+ ## Behavior & Interface Contracts
64
+
65
+ - **Inputs & CLI Flags:** <Specify syntax and types>
66
+
67
+ - **Outputs & Schema:** <JSON schema or return contract>
68
+
69
+ - **Error Modes:** <List specific error codes and exit status>
70
+
71
+ - **Concurrency & Idempotency:** <Timeout limits, lock keys, and duplicate dispatch protection>
72
+
73
+ ## Quality & Resource Budgets
74
+
75
+ | Dimension | Target Budget | Measurement Condition | Verification Method |
76
+
77
+ |---|---|---|---|
78
+ | Latency P50 | < e.g., 200ms | Local CLI dispatch | Benchmark test |
79
+
80
+ | Token Budget | < e.g., 8,000 tokens | Context packet compilation | Context Arbiter log |
81
+ | Test Coverage | >= 92% lines, >= 80% branches | `npm run test:core` | Vitest / Node test runner |
82
+
83
+ ## Dependencies & Risks
84
+
85
+ | Dependency / Risk | Potential Impact | Mitigation Strategy | Owner |
86
+
87
+ |---|---|---|---|
88
+ | <Dependency> | <Failure mode> | <Fallback or isolation> | <Role> |
89
+
90
+ ## Validation & Verification Gates
91
+
92
+ - **Unit / Core Suite:** `npm run test:core`
93
+
94
+ - **Lint & Docs Gate:** `npm run check`
95
+
96
+ - **Combined Commit Gate:** `npm run verify`
97
+
98
+ ## Rollout & Rollback
99
+
100
+ - **Rollout Strategy:** <Staged feature flag, CLI release, or workflow gate>
101
+
102
+ - **Rollback Triggers:** <Observed error spikes, broken witnesses, or test regressions>
103
+
104
+ - **Rollback Action:** <Git revert or toggle flag>
105
+
106
+ ## Open Questions
107
+
108
+ 1. <Unresolved design question, assigned owner, and target decision milestone>
@@ -0,0 +1,72 @@
1
+ ---
2
+ schema: "kxm.doc.v1"
3
+ id: "HND-0001"
4
+ type: "handoff"
5
+ title: "Structured Agent / Stage Handoff Manifest"
6
+ project: "kxm"
7
+ status: "approved"
8
+ owner: "@source_role"
9
+ created: "2026-09-08"
10
+ updated: "2026-09-08"
11
+ authority: "evidence"
12
+ confidence: "verified"
13
+ summary: "Formal handoff from <source_role> to <target_role> for workflow <workflow_id>."
14
+ tags: ["handoff", "workflow", "stage-transition"]
15
+ related: []
16
+ details:
17
+ workflow_run_id: "run-01928abc"
18
+ handoff_manifest_id: "hnd_01928abcde12"
19
+ intent: "request_review" # continue | request_review | reject_rework_required | complete
20
+ ---
21
+
22
+ # Structured Handoff Manifest
23
+
24
+ ## Stage Transition Provenance
25
+
26
+ - **Workflow Run ID:** `run-01928abc`
27
+
28
+ - **Task ID:** `task-127`
29
+
30
+ - **Source Role:** `writer` (Harness: `grok`, Model: `grok-4.6`)
31
+
32
+ - **Target Role:** `reviewer-arch` (Harness: `claude`, Model: `claude-fable-5-1`)
33
+
34
+ - **Intent:** `request_review`
35
+
36
+ ## Repository & Branch Anchors
37
+
38
+ - **Base Commit:** `44a7b50f9a2b6e14d3c2a1e09876543210abcdef`
39
+
40
+ - **Candidate Commit:** `88b6c40a12e34f56789abcdef0123456789abcde`
41
+
42
+ - **Candidate Tree Hash:** `789abcdef0123456789abcdef0123456789abcde`
43
+
44
+ - **Deterministic Branch:** `kxm/run-01928abc-fix-issue-127-memory-arbiter`
45
+
46
+ ## Deliverables & Evidence
47
+
48
+ ### 1. Artifacts Created
49
+
50
+ - `artifact:.kxm/assets/changes.patch@sha256:abc...`
51
+
52
+ - `artifact:.kxm/assets/witness.log@sha256:def...`
53
+
54
+ ### 2. Witness Receipt
55
+
56
+ - **Command:** `npm run verify`
57
+
58
+ - **Exit Code:** `0`
59
+
60
+ - **Receipt Hash:** `sha256:fedcba0987654321...`
61
+
62
+ ## Transferred Context & Decisions
63
+
64
+ - **Settled Decisions:**
65
+ - Used SQLite `external_effects` table for CAS leasing.
66
+ - Implemented descriptive branch slugification with de-duplication.
67
+
68
+ - **Assumptions:**
69
+ - Remote repository branch protection requires PR merge.
70
+
71
+ - **Open Questions / Notes for Target Role:**
72
+ - Please verify memory revision hash changes deterministically when files in `.kxm/memory/` are touched.
@@ -0,0 +1,77 @@
1
+ ---
2
+ schema: "kxm.doc.v1"
3
+ id: "PM-0001"
4
+ type: "postmortem"
5
+ title: "Incident Postmortem: <Incident Title>"
6
+ project: "kxm"
7
+ status: "approved"
8
+ owner: "@incident-lead"
9
+ created: "2026-09-08"
10
+ updated: "2026-09-08"
11
+ authority: "evidence"
12
+ confidence: "verified"
13
+ summary: "Blameless analysis, timeline, root cause, and action items for <incident>."
14
+ tags: ["incident", "postmortem", "reliability"]
15
+ related: []
16
+ details:
17
+ incident_date: "2026-09-08"
18
+ severity: "sev-2" # sev-1 | sev-2 | sev-3
19
+ time_to_detect_minutes: 5
20
+ time_to_mitigate_minutes: 20
21
+ ---
22
+
23
+ # Incident Postmortem: <Incident Title>
24
+
25
+ ## Executive Summary
26
+
27
+ - **Incident Period:** `2026-09-08 14:10 UTC` to `2026-09-08 14:35 UTC` (25 minutes)
28
+
29
+ - **User Impact:** <Number of workflow runs blocked or delayed>
30
+
31
+ - **Root Cause:** <One-sentence summary of failure mechanism>
32
+
33
+ ## Incident Timeline (UTC)
34
+
35
+ | Time | Event Description | Detected By |
36
+
37
+ |---|---|---|
38
+ | 14:10 | AI worker crashed during git push; CAS effect left in `dispatched` state | Log watcher |
39
+
40
+ | 14:15 | Subsequent retry attempts blocked due to unexpired CAS lease | `kxm dash` operator |
41
+ | 14:22 | Operator pressed `d` (degrade) to inspect worktree manually | Interactive TUI |
42
+
43
+ | 14:30 | Fix committed; lease expiration policy patched | Operator |
44
+ | 14:35 | Hub restarted; all queued workflow runs completed | Verifier |
45
+
46
+ ## Root Cause Analysis (5 Whys)
47
+
48
+ 1. **Why did the retry fail?** Because the CAS effect lease was locked in `dispatched` state.
49
+
50
+ 2. **Why was it still locked?** Because the previous worker process exited abnormally without calling abort.
51
+
52
+ 3. **Why did the lease not expire?** Because the lease had no automated heartbeat timeout.
53
+
54
+ 4. **Why was there no timeout?** Because CAS leasing was assumed to be synchronous.
55
+
56
+ 5. **Systemic Root Cause:** Missing failure recovery watchdog for unconfirmed external side-effect leases.
57
+
58
+ ## What Went Well / What Went Wrong
59
+
60
+ ### What Went Well
61
+
62
+ - The database remained consistent; zero duplicate PRs were created on GitHub.
63
+
64
+ - Degrade-to-human hotkey (`d`) allowed the operator to take over immediately.
65
+
66
+ ### What Went Wrong
67
+
68
+ - The error message in `kxm dash` did not explicitly indicate how to force-release an abandoned lease.
69
+
70
+ ## Corrective & Preventive Action Items
71
+
72
+ | Action Item | Type | Owner | Target Date | Issue Reference |
73
+
74
+ |---|---|---|---|---|
75
+ | Add 300s automated lease timeout to `ExternalEffectsLedger` | Prevent | Platform Lead | 2026-09-10 | #165 |
76
+
77
+ | Add `kxm routing unquarantine` CLI command | Mitigate | CLI Lead | 2026-09-12 | #166 |
@@ -0,0 +1,100 @@
1
+ ---
2
+ schema: "kxm.doc.v1"
3
+ id: "RES-0001"
4
+ type: "research"
5
+ title: "Research Topic / Spike Question"
6
+ project: "kxm"
7
+ status: "draft" # draft | in_review | approved | superseded | archived
8
+ owner: "@owner"
9
+ created: "2026-09-08"
10
+ updated: "2026-09-08"
11
+ authority: "hypothesis" # policy | instruction | evidence | hypothesis
12
+ confidence: "uncertain" # verified | probable | uncertain
13
+ summary: "The specific architectural or operational decision this research enables."
14
+ tags: []
15
+ related: []
16
+ details:
17
+ research_status: "planned"
18
+ target_decision_date: "2026-09-15"
19
+ ---
20
+
21
+ # Research: <Research Topic / Spike Question>
22
+
23
+ ## Decision to Enable
24
+
25
+ - **Pending Decision:** <What exact architectural, model routing, or product decision depends on this investigation?>
26
+
27
+ - **Decision Owner:** <Who has authority to accept or reject the findings?>
28
+
29
+ - **Constraints & Guardrails:** <Budget limits, latency thresholds, security boundaries>
30
+
31
+ ## Questions & Falsifiable Hypotheses
32
+
33
+ - **Primary Question:** <What are we trying to discover or prove?>
34
+
35
+ - **Hypothesis 1:** <Clear assertion that can be empirically verified or falsified>
36
+
37
+ - **Falsification Condition:** <What exact result or metric will prove this hypothesis wrong?>
38
+
39
+ ## Methodology & Verification Setup
40
+
41
+ ```mermaid
42
+ flowchart LR
43
+ Define[Define Hypotheses] --> Bounds[Set Cost & Scope Bounds]
44
+ Bounds --> Collect[Gather Empirical Evidence]
45
+ Collect --> Trial[Run Controlled Side-by-Side Trials]
46
+ Trial --> Evaluate[Analyze Telemetry & Rework]
47
+ Evaluate --> Recommend[Produce Actionable Recommendation]
48
+
49
+ ```
50
+
51
+ *Methodology flow: Establish bounds, execute reproducible trials, analyze telemetry metrics, and recommend concrete next actions.*
52
+
53
+ - **Harness & Model Arms:** <List evaluated routes, e.g. Grok native vs Pi wrapper vs Claude Fable>
54
+
55
+ - **Test Fixture / Workload:** <Exact repository task or test suite executed>
56
+
57
+ - **Budget Ceiling:** <Maximum dollar or token limit for this spike>
58
+
59
+ ## Evidence Register
60
+
61
+ | Evidence ID | Claim / Finding | Source Artifact / Telemetry Run | Version / Date | Confidence |
62
+
63
+ |---|---|---|---|---|
64
+ | EV-01 | <Empirical claim> | `artifact:.kxm/logs/telemetry.jsonl@sha256:...` | 2026-09-08 | verified |
65
+
66
+ | EV-02 | <Model behavior observation> | `run-01928abc` transcript | 2026-09-08 | probable |
67
+
68
+ ## Option Comparison Matrix
69
+
70
+ | Evaluation Criterion | Weight | Option A (e.g., Native) | Option B (e.g., Wrapper) | Measured Evidence |
71
+
72
+ |---|---|---|---|---|
73
+ | Verification Pass Rate | High | 84.0% | 40.0% | EV-01 |
74
+
75
+ | Latency P50 | Medium | 187s | 284s | EV-01 |
76
+ | Cost per Successful Run | High | $0.20 | $1.03 | EV-01 |
77
+
78
+ | Rework Rate | High | 68% | 100% | EV-01 |
79
+
80
+ ## Findings & Distinctions
81
+
82
+ ### Verified Observations (Backed by Evidence IDs)
83
+
84
+ - <Direct observation referencing EV-xx>
85
+
86
+ ### Inferences & Working Hypotheses
87
+
88
+ - <Reasoning or extrapolation; clearly separated from hard evidence>
89
+
90
+ ### Unresolved Unknowns
91
+
92
+ - <Gaps that remain uncertain or could not be measured>
93
+
94
+ ## Recommendation & Revisit Conditions
95
+
96
+ - **Recommended Course of Action:** <Specific choice or architectural pattern>
97
+
98
+ - **Rationale:** <Direct connection between evidence and decision>
99
+
100
+ - **Revisit When:** <Trigger conditions, such as new vendor model release, 20% price drop, or quota exhaustion>