@kontextmind/kxm 0.7.94 → 0.7.96

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