@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,1090 @@
1
+ # KXM Handbook
2
+
3
+ > Installation, configuration, CLI, Pi, Claude Code, durable workflows, gates, session isolation, observability, and recovery.
4
+
5
+ ## Contents
6
+
7
+ 1. [What KXM is](#what-kxm-is)
8
+ 2. [Requirements and installation](#requirements-and-installation)
9
+ 3. [Five-minute setup](#five-minute-setup)
10
+ 4. [Workspace layout](#workspace-layout)
11
+ 5. [Authentication and configuration](#authentication-and-configuration)
12
+ 6. [Complete CLI guide](#complete-cli-guide)
13
+ 7. [Pi integration](#pi-integration)
14
+ 8. [Workflow-specific Pi sessions](#workflow-specific-pi-sessions)
15
+ 9. [Claude Code integration](#claude-code-integration)
16
+ 10. [Hub tools](#hub-tools)
17
+ 11. [Durable workflows](#durable-workflows)
18
+ 12. [Evidence gates and external callbacks](#evidence-gates-and-external-callbacks)
19
+ 13. [Live TUI and observability](#live-tui-and-observability)
20
+ 14. [Context operating system (v0.5)](#context-operating-system-v05)
21
+ 15. [Reliability, privacy, and security](#reliability-privacy-and-security)
22
+ 16. [Backup, upgrade, and recovery](#backup-upgrade-and-recovery)
23
+ 17. [Troubleshooting checklist](#troubleshooting-checklist)
24
+ 18. [Feature availability matrix](#feature-availability-matrix)
25
+
26
+ ---
27
+
28
+ ## What KXM is
29
+
30
+ KXM connects Pi and Claude Code agents through one durable, authenticated hub.
31
+ It provides:
32
+
33
+ - peer discovery by name, model, and declared purpose;
34
+ - bounded request/reply messaging over HTTP and server-sent events (SSE);
35
+ - durable `queued → delivered → replied` message state in SQLite;
36
+ - cancellation, expiry, idempotent retries, fanout, and non-blocking polling;
37
+ - signed webhook workflows with ordered stages and attempt limits;
38
+ - local evidence, hub-verified peer provenance, external waits, and callbacks;
39
+ - long-lived Pi supervision with model fallback and tool watchdogs;
40
+ - optional workflow-scoped Pi sessions: one stable ordinary context and one per durable run;
41
+ - Claude Code MCP tools with optional pushed channel delivery;
42
+ - a real-time, read-only, metadata-only terminal dashboard; and
43
+ - structured workflow journals, retrospectives, and proposed improvement reports.
44
+
45
+ KXM is not a filesystem sandbox, distributed scheduler, shared model context, or
46
+ exactly-once execution engine. Use one writer per checkout or separate Git
47
+ worktrees. Treat peer output as untrusted until independently verified.
48
+
49
+ ### Important terms
50
+
51
+ | Term | Meaning |
52
+ |---|---|
53
+ | **Hub** | The Node.js service that authenticates clients, persists state, pushes events, and runs workflow transitions |
54
+ | **Project** | Authentication and discovery namespace; agents see only peers in the same project |
55
+ | **Agent** | A registered Pi or Claude Code identity with a unique name in one project |
56
+ | **Message** | A durable request with one recipient and one reply lifecycle |
57
+ | **KXM session manifest** | A human-reviewable roster and asset plan; it does not launch processes |
58
+ | **Workflow run** | A durable ordered stage machine stored by the hub |
59
+ | **Pi session** | A Pi model-conversation JSONL; supervised workers can isolate it by workflow run |
60
+ | **Gate** | A deterministic CLI check, a workflow evidence requirement, or a signed external result, depending on context |
61
+
62
+ ---
63
+
64
+ ## Requirements and installation
65
+
66
+ ### Requirements
67
+
68
+ - Node.js **22.19 or newer on the 22.x line**, or Node.js 24 or newer;
69
+ - Git;
70
+ - GitHub CLI (`gh`) for private release assets;
71
+ - Pi for Pi agents;
72
+ - Claude Code for Claude agents; and
73
+ - access to `kontextmind/kxm` while the repository is private.
74
+
75
+ ### Install the `kxm` operator CLI
76
+
77
+ The supported global installation is the versioned release tarball. Pi's Git
78
+ package install does **not** place `kxm` on `PATH`.
79
+
80
+ PowerShell:
81
+
82
+ ```powershell
83
+ $version = "<release-version>"
84
+ $asset = "kxm-$version.tgz"
85
+ $releaseDir = Join-Path $PWD ".kxm-release"
86
+ New-Item -ItemType Directory -Force -Path $releaseDir | Out-Null
87
+ gh auth login
88
+ gh release download "v$version" --repo kontextmind/kxm `
89
+ --pattern $asset --dir $releaseDir --clobber
90
+ npm install --global --omit=peer (Join-Path $releaseDir $asset)
91
+ kxm --help
92
+ ```
93
+
94
+ Bash:
95
+
96
+ ```bash
97
+ version='<release-version>'
98
+ asset="kxm-${version}.tgz"
99
+ mkdir -p .kxm-release
100
+ gh auth login
101
+ gh release download "v${version}" --repo kontextmind/kxm \
102
+ --pattern "$asset" --dir .kxm-release --clobber
103
+ npm install --global --omit=peer ".kxm-release/$asset"
104
+ kxm --help
105
+ ```
106
+
107
+ Do not use `npx kxm` or a global `git+https` npm install.
108
+
109
+ ### Run from a source checkout
110
+
111
+ ```bash
112
+ git clone <authorized-kxm-url>
113
+ cd kxm
114
+ npm ci
115
+ npm run check
116
+ node scripts/kxm.mjs --help
117
+ ```
118
+
119
+ Use `node scripts/kxm.mjs` wherever this handbook shows `kxm`. The source
120
+ wrapper runs the committed generated CLI, so maintainers must run `npm run build`
121
+ after changing CLI source.
122
+
123
+ ### Install in Pi
124
+
125
+ From Pi:
126
+
127
+ ```text
128
+ pi install git:github.com/kontextmind/kxm@main
129
+ ```
130
+
131
+ This installs the Pi extension and the `kxm` Agent Skill. Restart Pi after
132
+ installation or package updates.
133
+
134
+ ### Install in Claude Code
135
+
136
+ From Claude Code:
137
+
138
+ ```text
139
+ /plugin marketplace add kontextmind/kxm
140
+ /plugin install kxm
141
+ /reload-plugins
142
+ ```
143
+
144
+ The Claude plugin includes the bundled MCP runtime and shared skill.
145
+
146
+ ---
147
+
148
+ ## Five-minute setup
149
+
150
+ ### 1. Initialize the project
151
+
152
+ From the project directory:
153
+
154
+ ```text
155
+ kxm init
156
+ ```
157
+
158
+ ### 2. Start the hub in another terminal
159
+
160
+ `kxm hub start` is foreground. Keep that terminal running. Use a high-entropy
161
+ administrative token for hub operations and a different project token for
162
+ agents. Never pass either token on a command line.
163
+
164
+ PowerShell:
165
+
166
+ ```powershell
167
+ $env:KXM_HOST = "127.0.0.1"
168
+ $env:KXM_PORT = "7331"
169
+ $env:KXM_AUTH_TOKEN = "<admin-token>"
170
+ $env:KXM_PROJECT_TOKENS = '{"product":"<project-token>"}'
171
+ kxm hub start
172
+ ```
173
+
174
+ Bash:
175
+
176
+ ```bash
177
+ export KXM_HOST=127.0.0.1
178
+ export KXM_PORT=7331
179
+ export KXM_AUTH_TOKEN='<admin-token>'
180
+ export KXM_PROJECT_TOKENS='{"product":"<project-token>"}'
181
+ kxm hub start
182
+ ```
183
+
184
+ Store service values in an ACL-protected, gitignored environment file or secret
185
+ manager. If using Node's `--env-file`, keep the file path—not its contents—on
186
+ the command line.
187
+
188
+ ### 3. Bind, then confirm the session
189
+
190
+ ```text
191
+ kxm hub bind http://127.0.0.1:7331
192
+ kxm session brief
193
+ ```
194
+
195
+ PowerShell health check:
196
+
197
+ ```powershell
198
+ kxm hub view
199
+ Invoke-RestMethod http://127.0.0.1:7331/ready
200
+ ```
201
+
202
+ Bash:
203
+
204
+ ```bash
205
+ kxm hub view
206
+ curl --fail http://127.0.0.1:7331/ready
207
+ ```
208
+
209
+ ### 4. Start a supervised Pi worker
210
+
211
+ Use only the project token in the worker environment:
212
+
213
+ ```powershell
214
+ $env:KXM_SERVER_URL = "http://127.0.0.1:7331"
215
+ $env:KXM_AUTH_TOKEN = "<project-token>"
216
+ $env:KXM_PROJECT = "product"
217
+ $env:KXM_WORKDIR = "C:\work\product"
218
+ kxm agent worker --name coordinator --project product `
219
+ --model provider/model --session-isolation workflow
220
+ ```
221
+
222
+ ```bash
223
+ export KXM_SERVER_URL=http://127.0.0.1:7331
224
+ export KXM_AUTH_TOKEN='<project-token>'
225
+ export KXM_PROJECT=product
226
+ export KXM_WORKDIR=/work/product
227
+ kxm agent worker --name coordinator --project product \
228
+ --model provider/model --session-isolation workflow
229
+ ```
230
+
231
+ ### 5. Connect another Pi or Claude peer
232
+
233
+ Give it the same hub URL, project token, and project, but a different agent name.
234
+ Call `kxm_list` to verify discovery, then send one focused request with
235
+ `kxm_send`.
236
+
237
+ ---
238
+
239
+ ## Workspace layout
240
+
241
+ ```text
242
+ .kxm/
243
+ ├── config/ # reviewable configuration; no secret values
244
+ │ ├── agents.json # optional roster used by session manifests
245
+ │ ├── gates.json # optional documented gate roster
246
+ │ ├── env.example # variable names and safe placeholders
247
+ │ └── workflows/*.json # active workflow definition candidates
248
+ ├── logs/ # ignored runtime logs and telemetry
249
+ │ ├── kxm-hub.jsonl
250
+ │ ├── kxm-worker-*.jsonl
251
+ │ ├── pi-agent-*.log # raw Pi output; may be sensitive
252
+ │ └── telemetry.jsonl
253
+ ├── assets/ # intentional human-reviewable inputs/outputs
254
+ │ ├── sessions/<id>/session.json
255
+ │ ├── workflows/<definition>/...
256
+ │ └── retrospectives/<runId>.{json,md}
257
+ └── state/ # ignored runtime state; protect with OS ACLs
258
+ ├── kxm.db
259
+ ├── hub.pid / worker-*.pid
260
+ ├── worker-recovery-*.json
261
+ ├── worker-session-binding-*.json
262
+ └── pi-sessions/<workerKey>/
263
+ ├── default/
264
+ └── runs/<runId>/
265
+ ```
266
+
267
+ Commit reviewed configuration and intentional reusable assets. Do not commit
268
+ runtime state, credentials, raw model logs, generated secrets, or SQLite files.
269
+ Workflow stages and evidence live in `kxm.db`; important implementation results
270
+ should also live in Git or another system of record.
271
+
272
+ ---
273
+
274
+ ## Authentication and configuration
275
+
276
+ ### Credential roles
277
+
278
+ | Credential | Give it to | Capabilities |
279
+ |---|---|---|
280
+ | `KXM_AUTH_TOKEN` administrative token | Hub and trusted operator terminal | Operations snapshot/SSE, metrics where protected, quorum degradation, and fallback project access |
281
+ | Entry in `KXM_PROJECT_TOKENS` | Hub only | Maps one project to its worker credential |
282
+ | Project token | Pi and Claude agents in that project | Registration, discovery, messaging, and assigned workflow operations only |
283
+ | Workflow start secret | Hub and webhook sender/operator | HMAC-signs a new workflow delivery |
284
+ | Workflow signal secret | Hub and callback sender/operator | HMAC-signs an external result; may fall back to the start secret if the definition omits it |
285
+ | Agent key | Returned and rotated internally | Authorizes one resumed agent identity; never configure manually |
286
+
287
+ A project token cannot call administrative operations endpoints or approve quorum
288
+ degradation. All holders of one project credential are inside the same
289
+ provenance trust domain.
290
+
291
+ ### Core hub variables
292
+
293
+ | Variable | Default | Purpose |
294
+ |---|---:|---|
295
+ | `KXM_HOST` | `127.0.0.1` | Bind interface |
296
+ | `KXM_PORT` | `7331` | Hub port; `0` chooses a free port |
297
+ | `KXM_AUTH_TOKEN` | none | Administrative bearer token |
298
+ | `KXM_PROJECT_TOKENS` | none | JSON object of project-to-token mappings |
299
+ | `KXM_WORKSPACE_DIR` | `.kxm` | Workspace root |
300
+ | `KXM_DATA_PATH` | `.kxm/state/kxm.db` | SQLite path |
301
+ | `KXM_MESSAGE_TTL_MS` | `86400000` | Default request lifetime |
302
+ | `KXM_MESSAGE_RETENTION_MS` | `604800000` | Terminal-message retention |
303
+ | `KXM_RATE_LIMIT_MAX` | `600` | Requests per bucket/window |
304
+ | `KXM_RATE_LIMIT_WINDOW_MS` | `60000` | Rate-limit window |
305
+ | `KXM_WEBHOOK_WORKFLOWS_FILE` | none | One active JSON workflow-definition file |
306
+ | `KXM_WEBHOOK_WORKFLOWS` | none | Inline alternative; never set with the file variable |
307
+
308
+ A non-loopback bind requires an administrative token. Use TLS termination and
309
+ network controls before allowing remote access.
310
+
311
+ ### Agent variables
312
+
313
+ | Variable | Default | Purpose |
314
+ |---|---:|---|
315
+ | `KXM_SERVER_URL` | `http://127.0.0.1:7331` | Hub URL |
316
+ | `KXM_AUTH_TOKEN` | none | Project token for agents |
317
+ | `KXM_PROJECT` | current directory name | Discovery/authentication namespace |
318
+ | `KXM_AGENT_NAME` | harness-derived | Unique live name in the project |
319
+ | `KXM_AGENT_PURPOSE` | general-purpose | Capability shown during peer discovery |
320
+
321
+ ### Supervised Pi variables
322
+
323
+ | Variable | Default | Purpose |
324
+ |---|---:|---|
325
+ | `KXM_WORKDIR` | current directory | Repository used by Pi |
326
+ | `KXM_PI_COMMAND` | `pi` / `pi.cmd` | Explicit Pi executable |
327
+ | `KXM_WORKER_MODEL` | Pi default | Primary model selector |
328
+ | `KXM_WORKER_FALLBACK_MODELS` | none | Up to eight ordered fallback models |
329
+ | `KXM_WORKER_TOOLS` | Pi defaults | Comma-separated Pi tool allowlist |
330
+ | `KXM_WORKER_CONTINUE` | `true` | Allow active-session resume |
331
+ | `KXM_WORKER_INITIAL_CONTINUE` | same | Set `false` for a fresh first child only |
332
+ | `KXM_WORKER_SESSION_ISOLATION` | `off` for upgrade compatibility | Set `workflow` to enable stable-default plus per-run contexts |
333
+ | `KXM_WORKER_MAX_RUN_SESSIONS` | `128` | Retained workflow-specific sessions, range `1`–`1024` |
334
+ | `KXM_WORKER_TOOL_TIMEOUT_MS` | `1860000` | Tool watchdog; `0` disables it |
335
+ | `KXM_WORKER_ACTIVATION_TIMEOUT_MS` | `60000` | Delivered-message turn-start watchdog |
336
+ | `KXM_WORKER_PROVIDER_RETRY_MS` | `60000` | Delay when provider fallbacks are exhausted |
337
+ | `KXM_WORKER_DRAIN_MS` | `15000` | Graceful child shutdown window |
338
+ | `KXM_WORKER_MAX_RESTARTS` | unlimited | Optional supervisor retry ceiling |
339
+ | `KXM_WORKER_EXTENSION_PATHS` | discovery | Exact extension files, separated by the platform path delimiter |
340
+ | `KXM_WORKER_SKILL_PATHS` | discovery | Exact skill files/directories, same delimiter |
341
+
342
+ When exact extension or skill paths are supplied, automatic discovery is
343
+ disabled only for that category. Review those paths as executable dependencies.
344
+
345
+ The complete variable reference, limits, and examples are in
346
+ [Configuration](configuration.md).
347
+
348
+ ---
349
+
350
+ ## Complete CLI guide
351
+
352
+ Global options can appear on the root or a command group:
353
+
354
+ ```text
355
+ --workspace <dir> Select the .kxm workspace
356
+ --json Machine-readable output
357
+ --dry-run Plan without applying changes
358
+ -h, --help Contextual help
359
+ ```
360
+
361
+ ### Agent commands
362
+
363
+ | Command | What it does |
364
+ |---|---|
365
+ | `kxm agent worker --name <n> --project <p>` | Starts one always-on supervised Pi RPC worker |
366
+ | `--model <provider/model>` | Selects the primary Pi model |
367
+ | `--fallback-models <a,b>` | Supplies ordered provider fallback models |
368
+ | `--tools <a,b>` | Restricts available Pi tool names |
369
+ | `--fresh-start` | Skips only the first resume; later recoveries may continue |
370
+ | `--no-continue` | Disables all Pi session resume |
371
+ | `--session-isolation <mode>` | Uses `workflow` for per-run contexts or `off` for the upgrade-compatible shared context (default) |
372
+
373
+ The worker does not read model, tool, role, or ownership values from
374
+ `agents.json`; pass operational settings explicitly.
375
+
376
+ ### Session commands
377
+
378
+ | Command | What it does | Important limit |
379
+ |---|---|---|
380
+ | `kxm session start --id <id> --mix <names>` | Resolves roster names and writes a `kxm.session.v1` manifest | Does not start a process |
381
+ | `kxm session start --id <id> --workflow <definition>` | Creates manifest and workflow asset directories | Records the whole roster; does not dispatch a workflow |
382
+ | `kxm session brief [--status]` | Lists recent hub tasks and plans; `--status` is the one-line footer | Does not start a hub or a run |
383
+ | `kxm session status` | Lists PID claims and recovery envelopes in local state | Does not read session manifests |
384
+ | `kxm session stop [--wait-ms <n>]` | Requests managed process shutdown | Global workspace stop, identical in scope to `kxm hub stop` |
385
+
386
+ ### Workflow commands
387
+
388
+ | Command | What it does |
389
+ |---|---|
390
+ | `kxm workflow list` | Lists runs from the local workspace SQLite database |
391
+ | `kxm workflow get <runId>` | Shows one local run, stages, evidence, waits, and journal |
392
+ | `kxm workflow start [definitionId] --payload <value> [--delivery-id <id>] [--event <name>]` | Posts one signed, deduplicated workflow-start webhook; payload is a JSON object or `@file` |
393
+ | `kxm workflow export <runId> [--input <snapshot>] [--out-dir <assets-dir>]` | Writes proposed Markdown and JSON retrospectives |
394
+
395
+ `list`, `get`, and the default `export` are local hub-host operations; they do
396
+ not query a remote hub database.
397
+
398
+ ### Gate commands
399
+
400
+ | Command | What it does |
401
+ |---|---|
402
+ | `kxm gate validate [--file <path>]` | Parses the same single file/inline source contract as the hub without printing secrets |
403
+ | `kxm gate artifacts-exist --path <asset>` | Verifies a non-empty regular file remains inside the workspace asset root |
404
+ | `kxm gate degrade <runId> <stageId> --requirement <key> --reason <text>` | Admin-only approval of a policy-declared lower peer minimum for the current attempt |
405
+ | `kxm gate signal <runId> <signalKey> <status> <summary> [key=value...]` | Posts a signed, deduplicated `passed`, `warning`, or `failed` callback |
406
+ | `kxm gate github watch --run-id ... --stage-id ... --signal-key ... --repo owner/name --pr n --required a,b` | Polls required GitHub checks and posts the signed result |
407
+
408
+ `gate signal --delivery-id <id>` makes retries of one unchanged callback explicit. `gate github watch` also accepts `--timeout-ms`, `--interval-ms`, and `--delivery-id` in addition to its run, stage, signal, repository, pull request, and required-check options.
409
+
410
+ There is no generic `kxm gate run <name>`. Names in `gates.json` are descriptive
411
+ unless one of the implemented commands above executes them. `github watch`
412
+ posts an exact failed signal and exits `4` on timeout.
413
+
414
+ ### Hub and session commands
415
+
416
+ | Command | What it does |
417
+ |---|---|
418
+ | `kxm init` | Creates or validates a project; never copies package dogfood configuration |
419
+ | `kxm hub start` | Starts the hub in the foreground and opens the local SQLite store |
420
+ | `kxm hub bind <url>` | Binds this machine to a running hub |
421
+ | `kxm hub unbind` | Removes this machine's hub binding |
422
+ | `kxm hub view` | Checks `/health` and `/ready` |
423
+ | `kxm hub stop [--wait-ms <n>]` | Requests generation-matched hub and worker shutdown |
424
+ | `kxm dash` | Opens the real-time read-only metadata dashboard; prints one plain snapshot without a TTY |
425
+ | `kxm session brief` | Prints the hub-local session snapshot |
426
+
427
+ ### Improvement command
428
+
429
+ ```text
430
+ kxm improve [--target cli|project]
431
+ ```
432
+
433
+ This groups redacted `.kxm/logs/telemetry.jsonl` records into a proposed-only
434
+ report. Named project/workflow activity is classified as `project`; unscoped
435
+ operator activity is `cli`. `KXM_IMPROVE_TARGET=cli|project` explicitly
436
+ overrides that classification. The command does not automatically modify code,
437
+ configuration, gates, or the workflow journal.
438
+
439
+ ### Context commands
440
+
441
+ | Command | What it does |
442
+ |---|---|
443
+ | `kxm context get <project> --role <role> --task <task>` | Assembles a role-aware context packet |
444
+ | `kxm context recall <project>` | Searches durable context records (metadata only) |
445
+ | `kxm context state <project> <key>` | Current or historical value for one state key (`--as-of`) |
446
+ | `kxm context episode <project>` | Episodic learning records from workflow journals |
447
+ | `kxm context promote <project> <proposalId> --evidence <refs>` | Promotes an approved state proposal (control plane) |
448
+ | `kxm context explain <project> <itemId>` | Explains which evidence and lineage back a context item |
449
+ | `kxm context wiki-compile <project>` | Compiles the knowledge wiki for review |
450
+ | `kxm context wiki-lint <project>` | Lints a compiled wiki for broken refs, orphans, and stale state |
451
+ | `kxm skills` | Governed skill candidate lifecycle |
452
+
453
+ Agents use the same surfaces through Pi/MCP tools `kxm_context`, `kxm_recall`,
454
+ `kxm_state`, `kxm_episode`, and `kxm_promote`. There is no `kxm_explain` tool;
455
+ lineage is an operator CLI query.
456
+
457
+ ---
458
+
459
+ ## Pi integration
460
+
461
+ ### Interactive Pi
462
+
463
+ Set the agent variables before starting Pi:
464
+
465
+ ```powershell
466
+ $env:KXM_SERVER_URL = "http://127.0.0.1:7331"
467
+ $env:KXM_AUTH_TOKEN = "<project-token>"
468
+ $env:KXM_PROJECT = "product"
469
+ $env:KXM_AGENT_NAME = "reviewer"
470
+ $env:KXM_AGENT_PURPOSE = "Independent correctness reviewer"
471
+ pi
472
+ ```
473
+
474
+ Use `/kxm hub` to display the current identity and hub connection. Ask Pi to use
475
+ the `kxm` skill before delegating complex work.
476
+
477
+ ### Always-on Pi workers
478
+
479
+ `kxm agent worker` launches `pi --mode rpc`, captures its output, supervises
480
+ restarts, and stays online after every individual inference. The hub is the only
481
+ durable queue. The extension activates one message at a time and immediately
482
+ selects the next item after settlement.
483
+
484
+ Delivery priority is:
485
+
486
+ 1. `steer` at the next safe turn boundary;
487
+ 2. `followUp` for ordinary work; and
488
+ 3. `nextTurn`, normalized to a triggered follow-up for autonomous workers.
489
+
490
+ A steer changes course; it does not abort an in-flight atomic write. Waiting
491
+ work remains `queued`. Only work entering a model turn becomes `delivered`.
492
+
493
+ ### Tool and write boundaries
494
+
495
+ `--tools` restricts tool names, not filesystem paths. A review-only worker can
496
+ use:
497
+
498
+ ```text
499
+ --tools read,grep,find,ls,kxm_list,kxm_send,kxm_get,kxm_await
500
+ ```
501
+
502
+ A writer needs only the mutation and shell tools required by its assignment.
503
+ Roster `roles` and `ownership` fields are documentation, not runtime policy.
504
+ Use separate OS users, read-only worktrees, or containers for stronger
505
+ boundaries.
506
+
507
+ ### Provider and tool recovery
508
+
509
+ - Pi's own transient retries finish first.
510
+ - A final quota/provider failure leaves the hub message recoverable, records
511
+ bounded metadata, closes Pi cleanly, and selects the next unused fallback.
512
+ - A long-running tool beyond the watchdog follows the same recovery path without
513
+ rotating models.
514
+ - An invalid `--continue` history retries fresh in the same binding and records a
515
+ recovery envelope.
516
+ - Raw provider/model output remains in the protected `pi-agent-*.log`; structured
517
+ lifecycle logs contain only bounded metadata.
518
+
519
+ ---
520
+
521
+ ## Workflow-specific Pi sessions
522
+
523
+ This feature prevents one long-lived Pi worker from mixing unrelated workflow
524
+ histories.
525
+
526
+ ### Routing model
527
+
528
+ | Message kind | Pi session binding |
529
+ |---|---|
530
+ | Ordinary peer/operator work | Stable `{agent, default}` session |
531
+ | Root workflow prompt | `{agent, workflowRunId}` |
532
+ | Signed callback resume or timeout notification | Same workflow binding |
533
+ | Peer request with authorized `workflowContext` | Same workflow binding |
534
+ | Message with only `correlationId: run_*` | No workflow affinity; correlation is not authorization |
535
+
536
+ The hub adds a canonical, hub-owned `workflowRunId` to every workflow-origin
537
+ message. Run IDs must match `run_` plus 32 lowercase hexadecimal characters.
538
+
539
+ ### Safe switch lifecycle
540
+
541
+ 1. The extension examines the next queued message before acknowledgement.
542
+ 2. If its binding matches, the extension acknowledges it and starts one turn.
543
+ 3. If it differs, the message remains queued.
544
+ 4. The extension atomically writes a metadata-only, generation-bound route
545
+ request and asks the current Pi child to shut down.
546
+ 5. The supervisor waits for the child's `close` event, updates the binding
547
+ manifest, and starts exactly one replacement with the target `--session-dir`.
548
+ 6. The destination extension reconnects and receives the same queued message ID.
549
+
550
+ No request/reply body is written to a routing file. A route request includes only
551
+ identity, supervisor generation, child incarnation, source and destination
552
+ bindings, Pi session ID, message ID, and timestamp. The supervisor also rejects symbolic-link/junction aliases
553
+ for its scoped session roots and verifies canonical containment. A malformed, stale, wrong-owner, or wrong-source request is
554
+ rejected without changing scope.
555
+
556
+ ### Durability and retention
557
+
558
+ Bindings live in `.kxm/state/worker-session-binding-<workerKey>.json`. Restarting
559
+ the supervisor reloads the active binding and continues only when that session
560
+ directory has Pi JSONL history. Inactive workflow sessions are retained up to
561
+ `KXM_WORKER_MAX_RUN_SESSIONS`; least-recently-used inactive entries and
562
+ directories are deleted when the bound is reached.
563
+
564
+ A corrupt binding manifest is quarantined with a `.corrupt-<timestamp>` suffix.
565
+ The supervisor does not guess a run; it creates a safe default binding. The hub
566
+ workflow run, journal, messages, assets, and Git remain the recovery authority.
567
+
568
+ ### Enablement and compatibility
569
+
570
+ The upgrade-compatible default is one shared Pi history:
571
+
572
+ ```text
573
+ kxm agent worker ... --session-isolation off
574
+ ```
575
+
576
+ Enable scoped histories explicitly:
577
+
578
+ ```text
579
+ kxm agent worker ... --session-isolation workflow
580
+ ```
581
+
582
+ The first isolated start uses fresh scoped storage. KXM does not copy the old
583
+ shared `--continue` history because one shared directory may contain sessions
584
+ from several workers and cannot be attributed safely. Both the CLI and low-level
585
+ supervisor default to `off` during this compatibility release.
586
+
587
+ ---
588
+
589
+ ## Claude Code integration
590
+
591
+ ### Configure the plugin
592
+
593
+ Provide these plugin settings:
594
+
595
+ | Setting | Example |
596
+ |---|---|
597
+ | KXM server URL | `http://127.0.0.1:7331` |
598
+ | Authentication token | Project token, never the admin token |
599
+ | Agent name | `claude-reviewer` or `fable` |
600
+ | Agent purpose | `Independent review and UI/UX criticism` |
601
+ | Project | `product` |
602
+
603
+ Restart Claude Code after changing settings. Use `/mcp` to confirm the bundled
604
+ `kxm` MCP server connected, then call `kxm_list`.
605
+
606
+ KXM does not choose the Claude model. Select the required Claude CLI/model
607
+ profile separately; the hub identity and model session remain different
608
+ concepts.
609
+
610
+ ### Pushed channel mode
611
+
612
+ During the Claude channel research preview, explicitly trust the community
613
+ channel:
614
+
615
+ ```text
616
+ claude --dangerously-load-development-channels plugin:kxm
617
+ ```
618
+
619
+ If the organization has approved it through `allowedChannelPlugins`:
620
+
621
+ ```text
622
+ claude --channels plugin:kxm
623
+ ```
624
+
625
+ Inbound work arrives as `<channel source="kxm" ...>` events. Process one
626
+ request, call `kxm_reply`, and keep the Claude session open for the next event.
627
+
628
+ ### MCP pull mode
629
+
630
+ Without channels, Claude retains full outbound and workflow capability. For
631
+ inbound work:
632
+
633
+ 1. call `kxm_inbox`;
634
+ 2. process one durable request;
635
+ 3. call `kxm_reply` with its message ID; and
636
+ 4. repeat with bounded backoff while the inbox is empty.
637
+
638
+ Do not describe pull mode as push-driven liveness.
639
+
640
+ ### Claude and Pi context differences
641
+
642
+ Per-workflow automatic Pi session routing applies to the supervised Pi worker,
643
+ not to Claude Code. A Claude operator who needs strict run isolation should use
644
+ a separate Claude session/agent identity per run or an external Claude
645
+ supervisor. Workflow authority still comes from `kxm_workflow_get`, the hub
646
+ journal, evidence, and assets—not from either harness's context window.
647
+
648
+ ---
649
+
650
+ ## Hub tools
651
+
652
+ ### Shared outbound and workflow tools
653
+
654
+ These tools are available in Pi and Claude MCP:
655
+
656
+ | Tool | Purpose |
657
+ |---|---|
658
+ | `kxm_list` | List online peers, purposes, and models |
659
+ | `kxm_send` | Send one focused request; returns a durable message ID |
660
+ | `kxm_fanout` | Send the same independent request to one through three peers |
661
+ | `kxm_get` | Inspect a request without blocking |
662
+ | `kxm_await` | Wait only when the response blocks progress |
663
+ | `kxm_cancel` | Cancel queued/delivered work owned by the sender |
664
+ | `kxm_workflow_list` | List durable workflow runs assigned to this coordinator |
665
+ | `kxm_workflow_get` | Read stages, evidence policies, waits, and journal |
666
+ | `kxm_workflow_checkpoint` | Submit a stage result with keyed evidence and verified message references |
667
+ | `kxm_workflow_wait` | Save evidence and pause until an authenticated callback |
668
+ | `kxm_workflow_record` | Record a plan, decision, contradiction, error, or lesson |
669
+ | `kxm_improvement_report` | Summarize learning by improvement area |
670
+
671
+ Claude MCP also exposes:
672
+
673
+ | Tool | Purpose |
674
+ |---|---|
675
+ | `kxm_inbox` | Reconcile and list durable inbound work in pull mode |
676
+ | `kxm_reply` | Reply to one inbound request |
677
+
678
+ ### Messaging rules
679
+
680
+ - Use `followUp` by default; reserve `steer` for an active blocker.
681
+ - Supply an idempotency key when a send may be retried.
682
+ - A local `kxm_await` or fanout timeout does not cancel the durable message.
683
+ - Use `kxm_get` or repeat the exact idempotent operation; do not invent a new
684
+ request while the first remains pending.
685
+ - Cancellation cannot undo filesystem or external side effects.
686
+ - Never put credentials or unnecessary private data in a hub message.
687
+ - Keep one task and one owner per request.
688
+
689
+ ---
690
+
691
+ ## Durable workflows
692
+
693
+ ### Configure the active definition source
694
+
695
+ Set exactly one of:
696
+
697
+ ```text
698
+ KXM_WEBHOOK_WORKFLOWS_FILE=.kxm/config/workflows/product.json
699
+ ```
700
+
701
+ or:
702
+
703
+ ```text
704
+ KXM_WEBHOOK_WORKFLOWS=[...inline JSON...]
705
+ ```
706
+
707
+ The hub loads only that source for its current boot. A workflow definition
708
+ contains an ID, source/provider, project, target coordinator, secret environment
709
+ variable names, filters, delivery mode, prompt template, ordered stages,
710
+ required evidence, attempt limits, and optional peer policies.
711
+
712
+ Validate before restart:
713
+
714
+ ```powershell
715
+ kxm gate validate --file .kxm/config/workflows/product.json
716
+ ```
717
+
718
+ Secrets belong in environment variables named by `secretEnv` and
719
+ `signalSecretEnv`, never in definition JSON.
720
+
721
+ ### Start and inspect
722
+
723
+ ```powershell
724
+ kxm workflow start product-workflow `
725
+ --payload '@.kxm/assets/workflows/product/inputs/request.json' `
726
+ --delivery-id 'ticket-123-attempt-1'
727
+ kxm workflow list
728
+ kxm workflow get run_<32-hex-characters>
729
+ ```
730
+
731
+ The stable delivery ID deduplicates identical provider retries. Reusing it with
732
+ a conflicting body fails.
733
+
734
+ ### Coordinator procedure
735
+
736
+ For every active stage:
737
+
738
+ 1. call `kxm_workflow_get`;
739
+ 2. follow only `currentStage`;
740
+ 3. record material plans, decisions, contradictions, errors, and lessons;
741
+ 4. gather exact required evidence;
742
+ 5. send peer-policy work with exact `workflowContext` when required;
743
+ 6. checkpoint or enter an external wait; and
744
+ 7. correct warnings/failures until passed or attempts are exhausted.
745
+
746
+ Settling while a run is still `running` without a valid checkpoint fails the
747
+ run. Settling after a successful `kxm_workflow_wait` is expected and releases
748
+ compute until the callback creates a fresh message.
749
+
750
+ ### Workflow journal categories
751
+
752
+ | Category | Use |
753
+ |---|---|
754
+ | `plan` | Intended execution and ownership |
755
+ | `decision` | Selected option and rationale |
756
+ | `contradiction` | Incompatible evidence, claims, requirements, or tests |
757
+ | `error` | Failed tools, assumptions, integrations, or gates |
758
+ | `lesson` | Evidence-supported reusable improvement |
759
+
760
+ Areas are `harness`, `gates`, `implementation`, `workflow`, `documentation`,
761
+ `security`, or `other`.
762
+
763
+ ---
764
+
765
+ ## Evidence gates and external callbacks
766
+
767
+ ### Ordinary evidence
768
+
769
+ Every `requiredEvidence` key needs a non-empty string under the exact normalized
770
+ key. Extra evidence cannot substitute for a missing requirement.
771
+
772
+ ### Peer-reply evidence
773
+
774
+ A `peer-reply` policy requires durable replies from eligible stable agent IDs.
775
+ The coordinator must send or fan out with:
776
+
777
+ ```json
778
+ {
779
+ "workflowContext": {
780
+ "runId": "run_<32-hex>",
781
+ "stageId": "review",
782
+ "requirementKey": "independent review",
783
+ "attempt": 1
784
+ }
785
+ }
786
+ ```
787
+
788
+ Then cite the replied message IDs under the exact requirement in
789
+ `evidenceRefs`. The hub verifies sender, recipient, project, run, stage,
790
+ requirement, attempt, lifecycle, and eligible producer. Quorum counts unique
791
+ producers. Caller-authored text, correlation IDs, idempotency keys, and copied
792
+ result envelopes never satisfy peer provenance.
793
+
794
+ The coordinator is never an eligible producer for its own run. Peer provenance
795
+ proves durable routing inside the shared project-token trust boundary—not truth,
796
+ model identity, non-collusion, independence, or human approval.
797
+
798
+ ### Explicit degradation
799
+
800
+ Only a human/operator with the administrative token can approve a lower minimum,
801
+ and only when the policy declared one:
802
+
803
+ ```powershell
804
+ kxm gate --dry-run --json degrade <runId> <stageId> `
805
+ --requirement "independent review" --reason "documented incident"
806
+ kxm gate --json degrade <runId> <stageId> `
807
+ --requirement "independent review" --reason "documented incident"
808
+ ```
809
+
810
+ Approval is journaled and bound to the current attempt. It does not pass the
811
+ stage; the coordinator must still provide the approved minimum references.
812
+
813
+ ### External waits and signals
814
+
815
+ The coordinator calls `kxm_workflow_wait` with a stable signal key, expected
816
+ result, timeout, and any already verified evidence. A separate operator or
817
+ integration posts:
818
+
819
+ ```powershell
820
+ kxm gate signal <runId> github-pr-42-checks passed "CI passed" `
821
+ "github.check:ci=https://ci.example/pr/42"
822
+ ```
823
+
824
+ Callbacks are HMAC-signed, context-checked, deduplicated, and accumulated with
825
+ saved evidence. A failed callback consumes the attempt; re-enter the wait before
826
+ sending a new result.
827
+
828
+ ---
829
+
830
+ ## Live TUI and observability
831
+
832
+ Start the dashboard with the administrative credential:
833
+
834
+ ```powershell
835
+ kxm --workspace C:\work\product\.kxm dash
836
+ ```
837
+
838
+ The TUI uses `@earendil-works/pi-tui`. It subscribes to authenticated
839
+ metadata-only `/v1/ops/events` and refreshes `/v1/ops/snapshot`. It never loads
840
+ or renders request/reply bodies. If admin operations access is unavailable, it
841
+ honestly labels and uses a hub-enforced presence-only SSE stream plus local
842
+ metadata. It refuses an older/unmarked stream that cannot guarantee this mode. Synthetic TUI observers
843
+ are excluded from the dashboard's own agent table and displayed counts, while
844
+ remaining ordinary authenticated hub identities during fallback.
845
+
846
+ | Key | Action |
847
+ |---|---|
848
+ | `1`–`6` | Agents, Tasks, Workflows, Plans, Inbox, or Procs |
849
+ | `Tab` / `]` | Next tab |
850
+ | `[` | Previous tab |
851
+ | `←` / `→` | List pane / detail pane |
852
+ | `↑` / `↓` | Select |
853
+ | `PgUp` / `PgDn` | Scroll |
854
+ | `h` | Toggle help |
855
+ | `q` | Quit |
856
+
857
+ Without a TTY, the command prints one ANSI-free snapshot. Use
858
+ `kxm hub view --json` for a health result intended for automation.
859
+
860
+ ### Health and operations endpoints
861
+
862
+ | Endpoint | Authentication | Content |
863
+ |---|---|---|
864
+ | `GET /health` | none | Liveness and online-agent count |
865
+ | `GET /ready` | none | Storage readiness |
866
+ | `GET /metrics` | admin outside loopback | Prometheus metrics |
867
+ | `GET /v1/ops/snapshot?project=<p>` | admin | Project-scoped metadata, no bodies |
868
+ | `GET /v1/ops/events?project=<p>` | admin | Metadata-only SSE wakeups |
869
+
870
+ Structured hub and worker logs omit message bodies. Raw `pi-agent-*.log` files
871
+ may contain model output and must be protected accordingly.
872
+
873
+ ---
874
+
875
+ ## Context operating system (v0.5)
876
+
877
+ The `kxm context` command group exposes KXM's context operating system:
878
+ role-aware packets, temporal project state, episodic learning, a compiled
879
+ knowledge wiki, and a governed skill lifecycle. Agents use the same features
880
+ through `kxm_context`, `kxm_recall`, `kxm_state`, `kxm_episode`, and
881
+ `kxm_promote` (Pi and MCP); provider-specific memory APIs are never exposed.
882
+
883
+ ### Role-aware packets, recall, episodes, and explain
884
+
885
+ `kxm context get <project> --role <role> --task <task>` assembles a
886
+ token-budgeted packet. Roles shape selection: repro agents get prior
887
+ reproductions and incidents; planners get state and decisions; critics get
888
+ contradictions and failed approaches; implementers get the approved plan and
889
+ skills; verifiers get acceptance evidence. Superseded and rejected records
890
+ are excluded by default, and every packet is project-isolated.
891
+
892
+ `kxm context recall <project> --query <text>` searches durable context records
893
+ and returns metadata only. `kxm context episode <project>` lists episodic
894
+ learning records from workflow journals (`--run` limits to one run).
895
+ `kxm context explain <project> <itemId>` explains which evidence and lineage
896
+ back a context item.
897
+
898
+ ### Temporal state and promotion
899
+
900
+ State keys follow a `proposed → current → superseded` lifecycle with
901
+ deterministic historical queries (`--as-of`). Agents may propose changes;
902
+ promotion requires durable evidence and an authorized control-plane decision:
903
+
904
+ ```bash
905
+ kxm context promote <project> <proposalId> --evidence "receipt:run_9/verify"
906
+ ```
907
+
908
+ ### Compiled knowledge wiki
909
+
910
+ `kxm context wiki-compile` renders `.kxm/knowledge/wiki/` from reviewed
911
+ records; every claim links its evidence, superseded state stays visible, and
912
+ open contradictions are never silently resolved. `kxm context wiki-lint`
913
+ checks broken refs, orphan pages, stale state links, and unsurfaced
914
+ contradictions.
915
+
916
+ ### Governed skills
917
+
918
+ `kxm skills` turns verified episodes into candidates, gates them behind
919
+ static, sandbox, functional, and safety evaluations, and pins promoted skills
920
+ with content hashes. See `docs/skills.md` for the full lifecycle.
921
+
922
+ ### Reference /fix workflow
923
+
924
+ `.kxm/config/workflows/fix.json` implements the reference bug-fix flow:
925
+ read-only exploration, a tests-only reproduction draft, independent two-critic
926
+ `repro-review` that captures the immutable oracle (a sibling API is invalid),
927
+ plan review by independent critics, a human approval gate, bounded rework
928
+ through typed transitions, and a ready-for-human-acceptance end state.
929
+ Delivery never auto-merges. After `repro_invalidated`, rewrite against the
930
+ named seam; `new DbContext()` is not grounds for `blocked`.
931
+
932
+ ## Reliability, privacy, and security
933
+
934
+ ### Delivery guarantees
935
+
936
+ - SQLite is the durable source for agents, messages, runs, and journals.
937
+ - Queued and delivered messages replay after hub or agent restart.
938
+ - Delivery is at-least-once, not exactly-once.
939
+ - Make external side effects idempotent and use stable delivery/message keys.
940
+ - Terminal messages expire after the configured retention window.
941
+
942
+ ### Privacy contract
943
+
944
+ - The TUI and operations SSE are metadata-only.
945
+ - Structured logs include actors, project, delivery, status, model, and state,
946
+ but not prompt/reply bodies.
947
+ - SQLite stores message bodies as sent and is not application-encrypted.
948
+ - Raw Pi logs may contain model/tool output.
949
+ - Routing manifests and requests contain no message or reply bodies.
950
+
951
+ Protect `.kxm/state` and `.kxm/logs` with OS permissions and encrypted storage
952
+ where required.
953
+
954
+ ### Security boundaries
955
+
956
+ - Bind to loopback by default.
957
+ - Use distinct high-entropy admin and project credentials.
958
+ - Give workers only project tokens.
959
+ - Terminate TLS at a trusted proxy for remote access and disable SSE buffering.
960
+ - Protect workflow HMAC secrets separately from hub tokens.
961
+ - Treat plugin extension paths and skills as executable privileged inputs.
962
+ - Do not rely on prompts, roster roles, or ownership fields as a sandbox.
963
+ - Do not expose the hub directly to the public internet.
964
+
965
+ Session isolation prevents accidental model-context mixing; it is not a sandbox
966
+ against a hostile process running under the same OS account. A shell-capable
967
+ agent can reach files and routing environment values available to that account.
968
+ Use separate accounts, containers, read-only worktrees, or stricter tool sets
969
+ when the agent itself is outside the trust boundary.
970
+
971
+ ---
972
+
973
+ ## Backup, upgrade, and recovery
974
+
975
+ ### Backup
976
+
977
+ SQLite uses WAL mode. The simplest safe backup is:
978
+
979
+ 1. stop the hub gracefully;
980
+ 2. copy `.kxm/state/kxm.db` to protected storage;
981
+ 3. record the package version and reviewed configuration; and
982
+ 4. restart and verify `/ready`.
983
+
984
+ For online backup, use a SQLite-aware backup tool or capture the database,
985
+ `-wal`, and `-shm` consistently.
986
+
987
+ Pi session directories are supplementary model history, not authoritative
988
+ workflow state. Include them only if your recovery policy needs local model
989
+ context.
990
+
991
+ ### Upgrade
992
+
993
+ 1. back up SQLite;
994
+ 2. install the target release;
995
+ 3. stop the old hub and workers cleanly;
996
+ 4. start the new hub against the same database;
997
+ 5. verify health, readiness, operations SSE, and one request/reply; and
998
+ 6. restart workers so they use the matching extension and supervisor release.
999
+
1000
+ ### Session-state recovery
1001
+
1002
+ | Event | Meaning | Action |
1003
+ |---|---|---|
1004
+ | `worker_session_routed` | Expected clean child swap to another binding | No action unless repeated for one message |
1005
+ | `worker_session_evicted` | Inactive LRU run history removed at the configured bound | Preserve workflow facts in journal/assets/Git |
1006
+ | `worker_session_state_recovered` | Invalid manifest quarantined; safe default created | Inspect `.corrupt-*`, hub run state, and disk/concurrency health |
1007
+ | `worker_session_request_rejected` | Route request failed identity/schema/source checks | Check release match, generation, permissions, and duplicate supervisors |
1008
+ | `worker_continue_fallback` | Pi history could not continue; same binding starts fresh | Read recovery journal and durable message state |
1009
+
1010
+ Never repair a live route by editing state files. Stop the exact worker first,
1011
+ preserve evidence, and recover from hub-owned workflow state.
1012
+
1013
+ ---
1014
+
1015
+ ## Troubleshooting checklist
1016
+
1017
+ 1. Confirm `kxm hub start` is running.
1018
+ 2. Check `/health`, then `/ready`.
1019
+ 3. Compare URL, project, and project token on both agents.
1020
+ 4. Confirm unique live names.
1021
+ 5. Run `/kxm hub` in Pi or `kxm_list` in Pi/Claude.
1022
+ 6. Inspect structured logs without copying secrets or raw model content.
1023
+ 7. For queued workflow work, look for the one expected session route swap.
1024
+ 8. For a delivered message, inspect the recipient and activation/tool watchdogs;
1025
+ do not send duplicates.
1026
+ 9. For a workflow, call `kxm_workflow_get` and use the exact active stage,
1027
+ requirement keys, attempt, wait key, and coordinator.
1028
+ 10. For Claude, inspect `/mcp`; if channel push is unavailable, use
1029
+ `kxm_inbox`/`kxm_reply`.
1030
+
1031
+ Common causes:
1032
+
1033
+ | Symptom | Likely cause |
1034
+ |---|---|
1035
+ | `kxm` not found | Only the Pi package was installed; install the release CLI or use the source wrapper |
1036
+ | Pi shows `hub:off` | URL/token/project mismatch, duplicate live name, missing extension, or unreachable hub |
1037
+ | Claude tools missing | Plugin not reloaded, MCP bundle unavailable, or unsupported Node version |
1038
+ | Request stays queued | Recipient offline/SSE unavailable, or one safe Pi session swap is in progress |
1039
+ | Request stays delivered | Agent turn, approval, tool, provider, or settlement is still active |
1040
+ | Fanout returns pending | Local wait expired; use returned message IDs, not replacement sends |
1041
+ | Workflow cannot advance | Missing exact evidence, wrong attempt/context, insufficient verified producers, or exhausted attempts |
1042
+ | Admin route returns 401/403 | Project token used where the distinct admin token is required |
1043
+ | Degradation returns 503 | Hub has no configured administrative credential |
1044
+ | Shared workflow memory appears | Worker is using the upgrade-compatible isolation `off` default; restart explicitly with `--session-isolation workflow` |
1045
+
1046
+ See [Troubleshooting](troubleshooting.md) for error-specific recovery.
1047
+
1048
+ ---
1049
+
1050
+ ## Feature availability matrix
1051
+
1052
+ | Feature | Operator CLI | Pi | Claude Code |
1053
+ |---|---:|---:|---:|
1054
+ | Start/stop hub and workers | Yes | No | No |
1055
+ | Initialize workspace | Yes | No | No |
1056
+ | Peer discovery | Status/TUI only | `kxm_list` | `kxm_list` |
1057
+ | Send, poll, wait, cancel | No | Yes | Yes |
1058
+ | Fanout to 1–3 peers | No | Yes | Yes |
1059
+ | Pushed inbound turns | N/A | Native extension | Optional channel |
1060
+ | Pull inbox and explicit reply | N/A | Extension owns queue | `kxm_inbox`, `kxm_reply` |
1061
+ | Always-on worker supervision | Starts Pi worker | Yes | External Claude supervision required |
1062
+ | Workflow-specific model sessions | Configures mode | Automatic for supervised Pi | Use separate Claude sessions externally |
1063
+ | Workflow list/get | Local SQLite CLI | Hub tools | Hub tools |
1064
+ | Start signed workflow | Yes | No | No |
1065
+ | Checkpoint/wait/journal | No | Yes | Yes |
1066
+ | Peer provenance context/references | No | Yes | Yes |
1067
+ | Admin quorum degradation | Yes | Forbidden | Forbidden |
1068
+ | Signed external signal | Yes | No | No |
1069
+ | GitHub check watcher | Yes | No | No |
1070
+ | Artifact existence gate | Yes | Can invoke CLI if shell is allowed | Can invoke CLI if shell is allowed |
1071
+ | Retrospective export | Yes | Can record source evidence | Can record source evidence |
1072
+ | Proposed telemetry improvement report | Yes | `kxm_improvement_report` covers workflow journal separately | Same |
1073
+ | Context packets, recall, state, episodes, explain | Yes | `kxm_context`, `kxm_recall`, `kxm_state`, `kxm_episode` | Same MCP tools |
1074
+ | Promote state proposals | Yes | `kxm_promote` | `kxm_promote` |
1075
+ | Governed skills | Yes | No | No |
1076
+ | Live metadata-only TUI | Yes | No | No |
1077
+
1078
+ ---
1079
+
1080
+ ## Related pages
1081
+
1082
+ - [Getting started](getting-started.md)
1083
+ - [Configuration reference](configuration.md)
1084
+ - [Architecture](architecture.md)
1085
+ - [Operations guide](operations.md)
1086
+ - [Webhook workflows](webhook-workflows.md)
1087
+ - [Peer provenance and quorum gates](provenance-gates.md)
1088
+ - [Troubleshooting](troubleshooting.md)
1089
+ - [Test matrix](test-matrix.md)
1090
+ - [Changelog](../CHANGELOG.md)