@kontextmind/kxm 0.7.95 → 0.7.97

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 (158) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.kxm/README.md +39 -9
  3. package/CHANGELOG.md +23 -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 +153 -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 +399 -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 +266 -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} +88 -46
  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/examples/workflow-signal.ts +4 -5
  88. package/package.json +1 -1
  89. package/packages/core/tui/README.md +1 -1
  90. package/plugins/kxm/.claude-plugin/plugin.json +1 -1
  91. package/plugins/kxm/README.md +31 -32
  92. package/plugins/kxm/dist/claude-hook.js +11 -1
  93. package/plugins/kxm/dist/cli.js +164 -79
  94. package/plugins/kxm/dist/client.js +3 -1
  95. package/plugins/kxm/dist/core.js +11 -1
  96. package/plugins/kxm/dist/extension.js +45 -13
  97. package/plugins/kxm/dist/mcp-server.js +20 -4
  98. package/plugins/kxm/dist/runtime-supervisor.js +1 -3
  99. package/plugins/kxm/dist/runtime.js +18 -4
  100. package/plugins/kxm/dist/server.js +115 -20
  101. package/plugins/kxm/package.json +1 -1
  102. package/plugins/kxm/skills/kxm/references/protocol.md +3 -1
  103. package/plugins/kxm/skills/kxm-browser-auth/SKILL.md +1 -1
  104. package/plugins/kxm/skills/kxm-browser-diagnostics/SKILL.md +5 -5
  105. package/plugins/kxm/skills/kxm-browser-explore/SKILL.md +2 -2
  106. package/plugins/kxm/skills/kxm-browser-session/SKILL.md +10 -13
  107. package/plugins/kxm/skills/kxm-browser-takeover/SKILL.md +1 -1
  108. package/plugins/kxm/skills/kxm-browser-verify/SKILL.md +1 -1
  109. package/plugins/kxm/skills/kxm-context-memory/SKILL.md +13 -4
  110. package/plugins/kxm/skills/kxm-hub-ops/SKILL.md +3 -1
  111. package/plugins/kxm/skills/kxm-mind-setup/SKILL.md +2 -1
  112. package/plugins/kxm/skills/kxm-project-setup/SKILL.md +31 -54
  113. package/plugins/kxm/skills/kxm-projects/SKILL.md +1 -1
  114. package/plugins/kxm/skills/kxm-protocol/SKILL.md +1 -1
  115. package/plugins/kxm/skills/kxm-routing-improve/SKILL.md +15 -7
  116. package/plugins/kxm/skills/kxm-runs/SKILL.md +11 -5
  117. package/plugins/kxm/skills/kxm-session/SKILL.md +1 -1
  118. package/plugins/kxm/skills/kxm-tasks/SKILL.md +9 -7
  119. package/plugins/kxm/skills/kxm-workflow/SKILL.md +10 -2
  120. package/plugins/kxm/src/cli/system.ts +1 -1
  121. package/plugins/kxm/src/cli/workflows.ts +12 -7
  122. package/plugins/kxm/src/cli.ts +22 -8
  123. package/plugins/kxm/src/client.ts +4 -0
  124. package/plugins/kxm/src/commands.ts +23 -1
  125. package/plugins/kxm/src/extension.ts +20 -14
  126. package/plugins/kxm/src/github-watch.ts +8 -5
  127. package/plugins/kxm/src/hub-env.ts +19 -1
  128. package/plugins/kxm/src/hub.ts +105 -21
  129. package/plugins/kxm/src/improve-sources.ts +2 -7
  130. package/plugins/kxm/src/init-guide-setup.ts +1 -1
  131. package/plugins/kxm/src/mcp-server.ts +9 -2
  132. package/plugins/kxm/src/modes.ts +1 -1
  133. package/plugins/kxm/src/runtime-store.ts +23 -0
  134. package/plugins/kxm/src/workflow.ts +70 -1
  135. package/schemas/README.md +1 -1
  136. package/scripts/smoke-multi-pi.mjs +5 -1
  137. package/docs/agent-communication-envelopes-and-gates.md +0 -553
  138. package/docs/agent-skills.md +0 -198
  139. package/docs/architecture.md +0 -245
  140. package/docs/assignment-runner.md +0 -264
  141. package/docs/browser-automation.md +0 -139
  142. package/docs/configuration.md +0 -437
  143. package/docs/continuous-improvement.md +0 -226
  144. package/docs/getting-started.md +0 -277
  145. package/docs/harness-routing.md +0 -616
  146. package/docs/kb/qa-authentik-authentication.md +0 -97
  147. package/docs/kb/qa-extension-install-and-hub-bootstrap.md +0 -85
  148. package/docs/kb/qa-hub-on-a-public-host.md +0 -48
  149. package/docs/kb/qa-sqlite-vs-duckdb.md +0 -35
  150. package/docs/kb/qa-what-the-hub-stores.md +0 -64
  151. package/docs/kxm-handbook.md +0 -1181
  152. package/docs/operations.md +0 -510
  153. package/docs/operator-pi-packages.md +0 -67
  154. package/docs/provenance-gates.md +0 -295
  155. package/docs/skills.md +0 -47
  156. package/docs/test-matrix.md +0 -132
  157. package/docs/troubleshooting.md +0 -322
  158. package/docs/webhook-workflows.md +0 -240
@@ -0,0 +1,213 @@
1
+ # Quick start: Pi
2
+
3
+ This tutorial connects two Pi agents through a KXM [hub](../glossary.md#hub) and has one ask the other for a review. It takes about ten minutes once Node.js, Git and Pi are installed. At the end, a planner and a reviewer exchange a durable request, and you can add Claude Code to the same project.
4
+
5
+ ## Before you begin
6
+
7
+ - Node.js 22.19 or newer on the 22.x line, or Node.js 24 or newer, and Git.
8
+ - Pi, signed in to a model provider. Install it with `npm install --global @earendil-works/pi-coding-agent`; the [Pi documentation](https://pi.dev/docs/latest) covers sign-in.
9
+ - A Git repository for the project, and three terminals.
10
+
11
+ Every agent in one project uses the same hub URL, project key and project token, and each needs a unique name. The hub's admin token stays with you, the operator; no agent gets it.
12
+
13
+ ## 1. Install
14
+
15
+ Install the `kxm` CLI with npm, and the KXM package into Pi:
16
+
17
+ ```bash
18
+ npm install --global --omit=peer @kontextmind/kxm
19
+ pi install git:github.com/kontextmind/kxm@main
20
+ kxm --version
21
+ ```
22
+
23
+ `kxm --version` prints the installed version. The Pi package adds the KXM extension and skills to Pi but does not put `kxm` on your `PATH`; only the npm install does. [Install KXM](install.md) covers other options.
24
+
25
+ ## 2. Initialize the project
26
+
27
+ In the first terminal, before you start Pi or a hub in this repository:
28
+
29
+ ```bash
30
+ cd <your-repo>
31
+ kxm init --name "<display-name>"
32
+ printf '%s\n' '.kxm/state/' '.kxm/logs/' '.kxm/backups/' >> .gitignore
33
+ git add .gitignore .kxm
34
+ git commit -m "Add KXM project configuration"
35
+ ```
36
+
37
+ `kxm init` prints `initialized KXM project at <repo-root>`. It writes the project's agents, gates and a default workflow under `.kxm/`, and no ignore rules, so the second command adds them.
38
+
39
+ > [!NOTE]
40
+ > In an interactive terminal, `kxm init` offers to install shell completion and to add workflow-guide agents for the harnesses you have signed in to. Both are safe to decline. Set `KXM_SKIP_COMPLETION_PROMPT=1` and `KXM_SKIP_GUIDE_SETUP_PROMPT=1` to skip them.
41
+
42
+ ## 3. Start the hub
43
+
44
+ In the second terminal, from the repository root, create a token for the project `demo` and start the hub. The commands keep any projects the hub already saved:
45
+
46
+ ```bash
47
+ # The user state root is KXM_STATE_HOME when set; the default below is for macOS.
48
+ # On Linux, use "${XDG_STATE_HOME:-$HOME/.local/state}/kxm/hub-env.json" instead.
49
+ HUB_ENV="${KXM_STATE_HOME:-$HOME/Library/Application Support/KXM}/hub-env.json"
50
+ export KXM_NEW_PROJECT_TOKEN="$(openssl rand -hex 32)"
51
+ export KXM_PROJECT_TOKENS="$(node -e '
52
+ const fs = require("node:fs");
53
+ const [file, project] = process.argv.slice(1);
54
+ const saved = fs.existsSync(file) ? JSON.parse(fs.readFileSync(file, "utf8")).projectTokens ?? {} : {};
55
+ saved[project] = process.env.KXM_NEW_PROJECT_TOKEN;
56
+ process.stdout.write(JSON.stringify(saved));
57
+ ' "$HUB_ENV" demo)"
58
+ kxm hub start
59
+ ```
60
+
61
+ <details><summary>PowerShell</summary>
62
+
63
+ ```powershell
64
+ $bytes = New-Object byte[] 32
65
+ [Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($bytes)
66
+ $env:KXM_NEW_PROJECT_TOKEN = ($bytes | ForEach-Object { $_.ToString('x2') }) -join ''
67
+ $stateRoot = if ($env:KXM_STATE_HOME) { $env:KXM_STATE_HOME } else { Join-Path $env:LOCALAPPDATA 'KXM' }
68
+ $hubEnv = Join-Path $stateRoot 'hub-env.json'
69
+ $env:KXM_PROJECT_TOKENS = node -e "const fs=require('node:fs');const [f,p]=process.argv.slice(1);const s=fs.existsSync(f)?JSON.parse(fs.readFileSync(f,'utf8')).projectTokens??{}:{};s[p]=process.env.KXM_NEW_PROJECT_TOKEN;process.stdout.write(JSON.stringify(s))" $hubEnv 'demo'
70
+ kxm hub start
71
+ ```
72
+
73
+ </details>
74
+
75
+ Expected output:
76
+
77
+ ```text
78
+ kxm hub: using newly generated KXM_AUTH_TOKEN from <state-root>/hub-env.json
79
+ kxm hub listening at http://127.0.0.1:7331; storage=<repo-root>/.kxm/state/kxm.db; auth=token
80
+ ```
81
+
82
+ Keep this terminal open. The hub generates its admin token on the first start and saves it, with the project tokens, in `hub-env.json`. `KXM_PROJECT_TOKENS` replaces the saved project map rather than adding to it, which is why the command starts from the saved map.
83
+
84
+ > [!TIP]
85
+ > The Pi extension can start a hub for you: with the default `hub.autoStart: background`, it reuses a healthy bound hub or starts a detached one. This tutorial starts the hub by hand so that you create the project token yourself.
86
+
87
+ ## 4. Bind this machine to the hub
88
+
89
+ In the first terminal:
90
+
91
+ ```bash
92
+ kxm hub bind http://127.0.0.1:7331
93
+ ```
94
+
95
+ Expected output:
96
+
97
+ ```text
98
+ bound hub http://127.0.0.1:7331 · loopback · health=on
99
+ ```
100
+
101
+ ## 5. Confirm the session
102
+
103
+ ```bash
104
+ kxm hub view
105
+ kxm session status
106
+ ```
107
+
108
+ Expected output:
109
+
110
+ ```text
111
+ hub health=true ready=true · loopback hub
112
+ 1 session claim(s), 0 recovery envelope(s)
113
+ ```
114
+
115
+ The hub is healthy and ready, and its process is the one session claim.
116
+
117
+ ## 6. Start the planner
118
+
119
+ Still in the first terminal, give the agent the project token, which the command reads from `hub-env.json` without printing it, and an identity:
120
+
121
+ ```bash
122
+ HUB_ENV="${KXM_STATE_HOME:-$HOME/Library/Application Support/KXM}/hub-env.json"
123
+ export KXM_AUTH_TOKEN="$(node -e 'process.stdout.write(JSON.parse(require("node:fs").readFileSync(process.argv[1], "utf8")).projectTokens[process.argv[2]] ?? "")' "$HUB_ENV" demo)"
124
+ export KXM_SERVER_URL=http://127.0.0.1:7331
125
+ export KXM_PROJECT=demo
126
+ export KXM_AGENT_NAME=planner
127
+ export KXM_AGENT_PURPOSE="Plans work and coordinates handoffs"
128
+ pi
129
+ ```
130
+
131
+ <details><summary>PowerShell</summary>
132
+
133
+ ```powershell
134
+ $stateRoot = if ($env:KXM_STATE_HOME) { $env:KXM_STATE_HOME } else { Join-Path $env:LOCALAPPDATA 'KXM' }
135
+ $env:KXM_AUTH_TOKEN = (Get-Content -Raw (Join-Path $stateRoot 'hub-env.json') | ConvertFrom-Json).projectTokens.'demo'
136
+ $env:KXM_SERVER_URL = "http://127.0.0.1:7331"
137
+ $env:KXM_PROJECT = "demo"
138
+ $env:KXM_AGENT_NAME = "planner"
139
+ $env:KXM_AGENT_PURPOSE = "Plans work and coordinates handoffs"
140
+ pi
141
+ ```
142
+
143
+ </details>
144
+
145
+ Pi reports `Connected to the KXM hub as planner`. In Pi, run:
146
+
147
+ ```text
148
+ /kxm hub
149
+ ```
150
+
151
+ Expected output:
152
+
153
+ ```text
154
+ kxm hub view: health=ok; planner; 1 online agent(s)
155
+ ```
156
+
157
+ > [!NOTE]
158
+ > Without `KXM_AUTH_TOKEN`, the extension signs in with the project token saved for this project on this machine, and never with the saved admin token. With neither, it reports the fix and stays offline. Set the project token so that each agent holds only its own project's credential.
159
+
160
+ ## 7. Start the reviewer and send a request
161
+
162
+ In the third terminal, run the `HUB_ENV`, `KXM_AUTH_TOKEN`, `KXM_SERVER_URL` and `KXM_PROJECT` lines from step 6, then set a different identity and start Pi:
163
+
164
+ ```bash
165
+ export KXM_AGENT_NAME=reviewer
166
+ export KXM_AGENT_PURPOSE="Reviews plans and code for correctness risks"
167
+ pi
168
+ ```
169
+
170
+ In the planner's Pi session, ask:
171
+
172
+ ```text
173
+ Use the kxm skill. List peers, ask reviewer to examine the current plan for
174
+ its three highest correctness risks, and wait for the response.
175
+ ```
176
+
177
+ The planner calls `kxm_list`, `kxm_send` and `kxm_await`. The reviewer's Pi receives the request as a new turn, and the extension returns that turn's final response as the reply. The planner then shows the reviewer's answer.
178
+
179
+ The hub stores the request as a durable record that moves from `queued` to `delivered` to `replied`, so it survives a hub restart. `kxm_await` waits at most 60 seconds; a slower reply stays pending, and the planner can check it later with `kxm_get`. [Message peer agents](../guides/peer-messaging.md) covers fanout, cancellation and delivery modes.
180
+
181
+ ## 8. Add Claude Code (optional)
182
+
183
+ Claude Code can join the same project. Install the plugin as in [Quick start: Claude Code](quickstart-claude-code.md#5-install-the-plugin), with `project` set to `demo`, a unique `agent_name` such as `claude-reviewer`, and `auth_token` left blank on this machine. Then ask Claude to call `kxm_list`: the planner and the reviewer appear.
184
+
185
+ ## Your first useful topology
186
+
187
+ Start with two or three agents that have clear, separate jobs:
188
+
189
+ | Role | Good responsibilities |
190
+ |---|---|
191
+ | Planner | Break down work, define ownership, collect results |
192
+ | Builder | Implement one bounded change |
193
+ | Reviewer | Check correctness, tests, security or documentation |
194
+
195
+ KXM does not coordinate file ownership. Do not let two agents edit the same files in one checkout: use separate Git worktrees, or give one agent write ownership.
196
+
197
+ ## Troubleshooting
198
+
199
+ | Message or symptom | Cause | Fix |
200
+ |---|---|---|
201
+ | `agent name already active in project: <name>` | Another live Pi agent in the project uses the name | Set a different `KXM_AGENT_NAME` and restart Pi |
202
+ | `/kxm hub` prints `no agent connected` | The extension could not register | Check `KXM_SERVER_URL`, `KXM_PROJECT` and `KXM_AUTH_TOKEN`, then restart Pi |
203
+ | `invalid project authentication token` | `KXM_AUTH_TOKEN` is not the hub's token for `KXM_PROJECT` | Read the token again as in step 6 |
204
+ | `kxm init` prints `legacy state is not migrated by this build` | Pi or a hub ran here before `kxm init` | See [Check the project](quickstart-claude-code.md#check-the-project) |
205
+
206
+ [Troubleshooting](../operations/troubleshooting.md) covers workers, sessions and the hub.
207
+
208
+ ## Next steps
209
+
210
+ - Keep Pi agents running unattended: [Run supervised Pi workers](../guides/pi-workers.md)
211
+ - Run a workflow end to end: [Run your first workflow](first-workflow.md)
212
+ - Send, fan out and cancel requests: [Message peer agents](../guides/peer-messaging.md)
213
+ - Hub and agent settings: [Environment variables and limits](../reference/configuration.md)
@@ -1,95 +1,100 @@
1
- # KXM Documentation Templates & Workflow Integration Guide
2
-
3
- This directory contains standardized Markdown documentation templates adapted for KXM multi-agent orchestration, the 5-layer memory architecture, and the workflow taxonomy defined in [`docs/workflow-guide.md`](../workflow-guide.md).
4
-
5
- ## Core Principles
6
-
7
- 1. **Markdown + YAML Frontmatter + Mermaid:** Standardized metadata for automated indexing by the Context Arbiter, paired with human-readable text and conservative Mermaid diagrams.
8
-
9
- 2. **Separation of Concerns:** Keep **what should happen** (Feature / Architecture / Test Plan), **what was decided** (ADR), and **what actually happened** (Test Report / Witness Receipt / Postmortem) distinct.
10
-
11
- 3. **Immutable Evidence Chains:** Every test or review report must reference an exact commit pin (`git rev-parse HEAD`), deterministic branch (`kxm/run-<id>-<description>`), and content-addressed artifact reference (`artifact:<path>@sha256:<digest>`).
12
-
13
- 4. **Context Arbiter Integration:** Frontmatter fields (`authority`, `confidence`, `summary`, `tags`) inform token budgeting in `kxm.context-packet.v2`: layer pruning plus lexical task-relevance ordering in the arbiter.
14
-
15
- ---
16
-
17
- ## Template Directory
18
-
19
- | Template | File | Primary Workflow Stage | Key Outputs |
20
-
1
+ # Artifact templates
2
+
3
+ These templates give the artifacts a KXM workflow produces a common shape:
4
+ feature specifications, research briefs, bug reports, architecture designs,
5
+ decision records, test plans and reports, reviews, handoffs, runbooks and
6
+ postmortems. Agents and people fill them in during a run. For a human-facing
7
+ docs page, use the page template in
8
+ [Write KXM documentation](../contributing/writing-docs.md) instead.
9
+
10
+ ## Principles
11
+
12
+ 1. **Markdown, YAML frontmatter and Mermaid.** The frontmatter carries metadata
13
+ for indexing, the body stays readable, and diagrams are plain Mermaid.
14
+ 2. **Keep plans, decisions and outcomes apart.** What should happen (feature,
15
+ architecture, test plan), what was decided (ADR), and what actually happened
16
+ (test report, witness receipt, postmortem) are separate artifacts.
17
+ 3. **Pin every piece of evidence.** A test or review report cites an exact
18
+ commit (`git rev-parse HEAD`), a branch such as
19
+ `kxm/run-<run-id>-<description>`, and content-addressed artifacts written as
20
+ `artifact:<path>@sha256:<digest>`.
21
+ 4. **Use the context vocabulary.** The `authority`, `confidence`, `summary` and
22
+ `tags` fields use the same values as KXM context items, so an indexer can
23
+ weigh an artifact. No KXM code reads this frontmatter today, and no JSON
24
+ Schema validates `kxm.doc.v1` yet.
25
+
26
+ ## Templates
27
+
28
+ | Template | Use it for | Stage | Key outputs |
21
29
  |---|---|---|---|
22
- | **Feature Specification** | [`feature.md`](feature.md) | Stage 1: Requirements & Scope | Observable behavior, acceptance criteria table, user flow diagram. |
23
-
24
- | **Research Brief** | [`research.md`](research.md) | Stage 1: Discovery & Spike | Falsifiable hypotheses, evidence register, option comparison matrix. |
25
- | **Bug Investigation & Fix** | [`bug-fix.md`](bug-fix.md) | Stages 1–3: Repro, Fix, Verify | Repro before oracle, sequenceDiagram, exact test command, before/after evidence. |
26
-
27
- | **Architecture Design** | [`architecture.md`](architecture.md) | Stage 1: Architecture & System Design | Trust boundaries, component ownership, runtime scenarios, failure modes. |
28
- | **Architecture Decision Record (ADR)** | [`adr.md`](adr.md) | Ongoing: Technical Decisions | Decision drivers, considered options with pros/cons, consequences, revisit triggers. |
29
-
30
- | **Test Plan** | [`test-plan.md`](test-plan.md) | Stage 2: Verification Design | Risk-to-coverage matrix, test cases, environment prerequisites, entry/exit criteria. |
31
- | **Test Execution Report** | [`test-report.md`](test-report.md) | Stage 3: Witness Verification | Exact build/commit, execution timestamps, case outcomes, coverage diff. |
32
-
33
- | **Dual-Critic Review Report** | [`review.md`](review.md) | Stage 4: Critic Quorum | Independent Fable (arch) and Astra/Sol (CLI) findings, severity, quorum verdict. |
34
- | **Structured Handoff Manifest** | [`handoff.md`](handoff.md) | Inter-stage transitions | `kxm.handoff-manifest.v1` mapping, baseCommit, candidateTreeHash, deliverables. |
35
-
36
- | **Operational Runbook** | [`runbook.md`](runbook.md) | Reliability & Ops | Diagnosis steps, safe mitigation commands, rollback triggers, escalation paths. |
37
- | **Incident Postmortem** | [`postmortem.md`](postmortem.md) | Post-incident Retrospective | Timeline of events, root cause analysis, preventive action items. |
38
-
39
- ---
40
-
41
- ## Workflow Guide Integration Matrix
42
-
43
- The 11 templates map directly across the 7 Areas and 22 Workflows in [`docs/workflow-guide.md`](../workflow-guide.md):
30
+ | [Feature specification](feature.md) | A new capability | Requirements and scope | Observable behavior, acceptance criteria, user flow |
31
+ | [Research brief](research.md) | A spike or evaluation | Discovery | Falsifiable hypotheses, evidence register, option comparison |
32
+ | [Bug investigation and fix](bug-fix.md) | A defect | Reproduce, fix, verify | Failing reproduction first, exact test command, before and after evidence |
33
+ | [Architecture design](architecture.md) | A system or subsystem | Design | Trust boundaries, component ownership, failure modes |
34
+ | [Architecture decision record](adr.md) | A technical decision | Any | Drivers, options with trade-offs, consequences, revisit triggers |
35
+ | [Test plan](test-plan.md) | Verification design | Before implementation | Risk-to-coverage matrix, test cases, entry and exit criteria |
36
+ | [Test execution report](test-report.md) | A witness run | Verification | Exact commit, case outcomes, coverage |
37
+ | [Dual-critic review](review.md) | Independent review | Review | Findings by severity, `PASS` or `BLOCK` per critic |
38
+ | [Handoff manifest](handoff.md) | A stage transition | Between stages | `kxm.handoff-manifest.v1` fields, base commit, deliverables |
39
+ | [Operational runbook](runbook.md) | Diagnosis and mitigation | Operations | Triage steps, safe commands, rollback, escalation |
40
+ | [Incident postmortem](postmortem.md) | A blameless retrospective | After an incident | Timeline, root cause, corrective actions |
41
+
42
+ ## How the templates fit a workflow
43
+
44
+ Planning artifacts feed implementation and testing, which feed verification and
45
+ review; runbooks and postmortems cover operations.
44
46
 
45
47
  ```mermaid
46
48
  flowchart TD
47
- subgraph PlanStage ["1. Planning & Design"]
49
+ subgraph Plan ["1. Plan and design"]
48
50
  F["feature.md"]
49
51
  R["research.md"]
50
52
  A["architecture.md"]
51
53
  ADR["adr.md"]
52
54
  end
53
55
 
54
- subgraph ExecStage ["2. Implementation & Testing"]
56
+ subgraph Build ["2. Implement and test"]
55
57
  B["bug-fix.md"]
56
58
  TP["test-plan.md"]
57
- H1["handoff.md (Plan -> Write)"]
59
+ H1["handoff.md (plan to write)"]
58
60
  end
59
61
 
60
- subgraph VerifyStage ["3. Verification & Review"]
61
- TR["test-report.md (Witness)"]
62
- REV["review.md (Dual Critics)"]
63
- H2["handoff.md (Write -> Critic)"]
62
+ subgraph Verify ["3. Verify and review"]
63
+ TR["test-report.md (witness)"]
64
+ REV["review.md (two critics)"]
65
+ H2["handoff.md (write to review)"]
64
66
  end
65
67
 
66
- subgraph OpsStage ["4. Operations & Maintenance"]
68
+ subgraph Operate ["4. Operate"]
67
69
  RB["runbook.md"]
68
70
  PM["postmortem.md"]
69
71
  end
70
72
 
71
- PlanStage --> ExecStage
72
- ExecStage --> VerifyStage
73
- VerifyStage --> OpsStage
74
-
73
+ Plan -->|approved plan| Build
74
+ Build -->|candidate| Verify
75
+ Verify -->|accepted change| Operate
75
76
  ```
76
77
 
77
- ### Mapping by Area
78
-
79
- 1. **Software Engineering (`software-engineering`)**
80
- - `feature-delivery`: [`feature.md`](feature.md) $\rightarrow$ [`architecture.md`](architecture.md) $\rightarrow$ [`test-plan.md`](test-plan.md) $\rightarrow$ [`review.md`](review.md).
81
- - `bug-investigation`: [`bug-fix.md`](bug-fix.md) with mandatory reproduction test before oracle.
82
- - `refactoring-migration`: [`architecture.md`](architecture.md) + [`adr.md`](adr.md) + [`test-report.md`](test-report.md).
83
-
84
- 2. **Design & Experience (`design-experience`)**
85
- - `ui-ux-design-system`: [`feature.md`](feature.md) (user flows) + [`review.md`](review.md) (a11y audits).
86
-
87
- 3. **Data & Analytics (`data-analytics`)**
88
- - `data-pipeline-etl`: [`architecture.md`](architecture.md) (data flows, contracts) + [`runbook.md`](runbook.md).
89
-
90
- 4. **Research & Strategy (`research-strategy`)**
91
- - `technology-evaluation` / `market-research`: [`research.md`](research.md) with evidence registers and confidence bounds.
92
-
93
- 5. **Security & Reliability (`security-reliability`)**
94
- - `vulnerability-audit`: [`review.md`](review.md) (threat model) + [`bug-fix.md`](bug-fix.md).
95
- - `incident-response`: [`runbook.md`](runbook.md) (triage/mitigation) $\rightarrow$ [`postmortem.md`](postmortem.md) (blameless retrospective).
78
+ ## Templates by workflow
79
+
80
+ The slugs below come from the [workflow catalog](../reference/workflow-catalog.md).
81
+ They are documentation identifiers only; they imply no runtime configuration.
82
+
83
+ | Area | Workflow | Templates |
84
+ |---|---|---|
85
+ | Software engineering | `build-feature` | `feature.md`, then `architecture.md`, `test-plan.md`, `review.md` |
86
+ | Software engineering | `refactor-repair-regressions` | `architecture.md`, `adr.md`, `test-report.md` |
87
+ | Software engineering | `stabilize-flaky-tests` | `bug-fix.md` with a failing reproduction first, then `test-report.md` |
88
+ | Software engineering | `design-software-system` | `architecture.md`, `adr.md` |
89
+ | Software engineering | `maintain-documentation` | `review.md` for the accuracy audit |
90
+ | Design and experience | `build-design-system`, `audit-visual-accessibility` | `feature.md` for user flows, `review.md` for accessibility findings |
91
+ | Data and analytics | `analyze-dataset`, `query-business-intelligence` | `research.md` for the evidence register, `architecture.md` for data flows |
92
+ | Research and strategy | `prepare-decision-brief` | `research.md`, then `adr.md` for the decision |
93
+ | Security and reliability | `patch-vulnerability` | `review.md` for the threat model, `bug-fix.md` for the fix |
94
+ | Security and reliability | `investigate-incident` | `runbook.md` for triage, then `postmortem.md` |
95
+
96
+ ## Related
97
+
98
+ - [Write KXM documentation](../contributing/writing-docs.md): the docs page template and style rules
99
+ - [Workflow catalog](../reference/workflow-catalog.md): workflow and role slugs
100
+ - [Assignment runner](../contributing/assignment-runner.md): witness, critics and acceptance in the KXM repository
@@ -2,7 +2,7 @@
2
2
  schema: "kxm.doc.v1"
3
3
  id: "ADR-0001"
4
4
  type: "adr"
5
- title: "Title of Architecture Decision"
5
+ title: "ADR-<nnnn>: <decision title>"
6
6
  project: "kxm"
7
7
  status: "proposed" # proposed | accepted | superseded | deprecated | rejected
8
8
  owner: "@owner"
@@ -19,13 +19,13 @@ details:
19
19
  superseded_by: null
20
20
  ---
21
21
 
22
- # ADR-0001: <Title of Architecture Decision>
22
+ # ADR-0001: <Title of architecture decision>
23
23
 
24
- ## Context & Problem Statement
24
+ ## Context and problem statement
25
25
 
26
26
  <Describe the technical context, operational dilemma, or architectural friction. What forces are compelling this decision?>
27
27
 
28
- ## Decision Drivers
28
+ ## Decision drivers
29
29
 
30
30
  1. **Driver 1:** <e.g., Eliminate native compilation failures across Node versions>
31
31
 
@@ -33,7 +33,7 @@ details:
33
33
 
34
34
  3. **Driver 3:** <e.g., Maintain fail-closed security invariants without loopback bypasses>
35
35
 
36
- ## Considered Options
36
+ ## Considered options
37
37
 
38
38
  - **Option A:** <Name of Option A>
39
39
 
@@ -41,9 +41,9 @@ details:
41
41
 
42
42
  - **Option C:** <Name of Option C>
43
43
 
44
- ## Evaluation & Tradeoff Matrix
44
+ ## Evaluation and tradeoff matrix
45
45
 
46
- ### Option A: <Name of Option A>
46
+ ### Option A: <name of option A>
47
47
 
48
48
  - **Good, because:** <Advantage 1>
49
49
 
@@ -53,33 +53,33 @@ details:
53
53
 
54
54
  - **Bad, because:** <Drawback 2>
55
55
 
56
- ### Option B: <Name of Option B>
56
+ ### Option B: <name of option B>
57
57
 
58
58
  - **Good, because:** <Advantage 1>
59
59
 
60
60
  - **Bad, because:** <Drawback 1>
61
61
 
62
- ## Decision Outcome
62
+ ## Decision outcome
63
63
 
64
64
  **Chosen Option:** **Option A**, because <comprehensive justification referencing drivers>.
65
65
 
66
- ### Positive Consequences
66
+ ### Positive consequences
67
67
 
68
68
  - <Favorable outcome 1>
69
69
 
70
70
  - <Favorable outcome 2>
71
71
 
72
- ### Negative Consequences & Accepted Tradeoffs
72
+ ### Negative consequences and accepted tradeoffs
73
73
 
74
74
  - <Technical debt, limitation, or operational overhead incurred>
75
75
 
76
- ## Confirmation & Verification Strategy
76
+ ## Confirmation and verification strategy
77
77
 
78
78
  - **Verification Gate:** <Exact test suite or contract check enforcing this decision>
79
79
 
80
80
  - **Enforcement Mechanism:** <Linter, type-check, or CI rule that prevents regressions>
81
81
 
82
- ## Revisit Conditions
82
+ ## Revisit conditions
83
83
 
84
84
  This decision should be formally re-evaluated if:
85
85
 
@@ -2,7 +2,7 @@
2
2
  schema: "kxm.doc.v1"
3
3
  id: "ARCH-0001"
4
4
  type: "architecture"
5
- title: "System / Subsystem Architecture Design"
5
+ title: "Architecture: <system or subsystem>"
6
6
  project: "kxm"
7
7
  status: "draft" # draft | in_review | approved | superseded | archived
8
8
  owner: "@owner"
@@ -18,103 +18,87 @@ details:
18
18
  baseline_commit: "<git-sha>"
19
19
  ---
20
20
 
21
- # Architecture: <System / Subsystem Name>
21
+ # Architecture: <system or subsystem name>
22
22
 
23
- ## Purpose & Scope
23
+ ## Purpose and scope
24
24
 
25
- - **Core Mission:** <What capability does this subsystem deliver?>
25
+ - **Mission:** <What capability does this subsystem deliver?>
26
+ - **Callers:** <Who interacts with it: operators, agents, workers, external webhooks?>
27
+ - **State of this document:** <Current, proposed, or target architecture. Say which.>
26
28
 
27
- - **Audience & Callers:** <Who interacts with this system (interactive operators, workers, external webhooks)?>
28
-
29
- - **Architecture State:** <Explicitly state whether this document reflects current, proposed, or target architecture>
30
-
31
- ## Goals, Quality Attributes & Constraints
32
-
33
- | Goal / Constraint | Business or Technical Driver | Measurement Metric / Hard Boundary |
29
+ ## Goals, quality attributes and constraints
34
30
 
31
+ | Goal or constraint | Driver | Measure or hard boundary |
35
32
  |---|---|---|
36
- | Fail-Closed Security | Prevent privilege escalation | Reject missing tokens; zero loopback bypasses |
33
+ | Fail-closed security | Prevent privilege escalation | Missing or wrong credentials are refused; no loopback bypass |
34
+ | Deterministic replay | Forensic debugging and audit | Folding the event log reproduces the same state |
35
+ | <Latency or throughput goal> | <Operator responsiveness> | <For example, p50 dispatch under 200 ms> |
37
36
 
38
- | Deterministic Replay | Forensic debugging & auditability | Folded event stream produces identical state |
39
- | Low Latency Dispatch | Operator responsiveness | Sub-200ms dispatch P50 |
37
+ ## Context and trust boundaries
40
38
 
41
- ## Context & Trust Boundaries
39
+ External requests pass a credential check before they reach the subsystem, which
40
+ owns its durable state.
42
41
 
43
42
  ```mermaid
44
43
  flowchart TB
45
- subgraph External ["Untrusted External Perimeter"]
46
- Caller["Operator / External Webhook / CI"]
44
+ subgraph External ["Untrusted perimeter"]
45
+ Caller["Operator, webhook sender or CI"]
47
46
  end
48
47
 
49
- subgraph AuthPlane ["Access Control Plane (Trust Boundary)"]
50
- TokenVal["Token Validator (Admin / Session / Attempt)"]
48
+ subgraph Auth ["Trust boundary"]
49
+ Check["Credential check (admin, project or session)"]
51
50
  end
52
51
 
53
- subgraph Internal ["KXM Core Domain"]
54
- Engine["Temporal Workflow Engine"]
55
- Memory["5-Layer Memory & Context Arbiter"]
56
- Store[("SQLite Store: .kxm/state/kxm.db")]
52
+ %% Replace these labels with your own components and store.
53
+ subgraph Internal ["Subsystem"]
54
+ Engine["Core component"]
55
+ Context["Supporting component"]
56
+ Store[("Durable store, for example .kxm/state/kxm.db")]
57
57
  end
58
58
 
59
- Caller -->|Request + Token| TokenVal
60
- TokenVal -->|Authorized Call| Engine
61
- Engine --> Memory
62
- Engine --> Store
63
-
59
+ Caller -->|request and credential| Check
60
+ Check -->|authorized call| Engine
61
+ Engine -->|reads| Context
62
+ Engine -->|writes| Store
64
63
  ```
65
64
 
66
- *Context flow: External requests enter through the Access Control Plane. Authorized calls interact with the Temporal Engine and Context Arbiter, backed by durable SQLite storage.*
67
-
68
- ## Component Responsibilities & Ownership
69
-
70
- | Component | Responsibility | Public Interface / Contract | Owned State / Tables | Team / Role Owner |
71
-
72
- |---|---|---|---|---|
73
- | Workflow Engine | DAG scheduling & loop transitions | `KxmEngine.drive()` | `run_events`, `workflow_runs` | Engine Lead |
74
-
75
- | Context Arbiter | Token budgeting & context compilation | `arbitrate()` | In-memory pool + Git memory | Memory Lead |
76
- | External Effects Ledger | CAS leasing & idempotency | `ExternalEffectsLedger` | `external_effects` | Platform Lead |
77
-
78
- ## Runtime Execution Scenarios
79
-
80
- ### 1. Happy Path Dispatch & Settlement
81
-
82
- 1. Step dispatch compiles `FormalContextPacket` (`kxm.context-packet.v2`).
83
-
84
- 2. Worker executes in isolated branch `kxm/run-<id>-<description>`.
85
-
86
- 3. Worker submits `kxm.handoff-manifest.v1` with witness receipt.
87
-
88
- 4. Engine commits transition and notifies critics.
89
-
90
- ### 2. Failure & Rework Path
91
-
92
- 1. Critic issues structured rejection findings with blocker severity.
93
-
94
- 2. Engine transitions step to `rejected_rework_required`.
95
-
96
- 3. Attempts counter increments; router dispatches to next eligible writer.
65
+ ## Component responsibilities
97
66
 
98
- ## Data Contracts, Storage & Invariants
67
+ | Component | Responsibility | Public interface | Owned state |
68
+ |---|---|---|---|
69
+ | <Runtime engine> | <Schedules steps, attempts and transitions> | <`KxmRunScheduler`> | <`events`, `runs`, `run_state` in the Runtime event store> |
70
+ | <Context arbiter> | <Assembles role-aware packets within a budget> | <`arbitrate()`> | <None; reads context items and Git memory> |
71
+ | <Hub store> | <Messages, workflow runs and leases> | <HTTP API> | <`messages`, `workflow_runs`, `leases` in `kxm.db`> |
99
72
 
100
- - **Source of Truth:** Local-first SQLite (`.kxm/state/kxm.db`) using native `DatabaseSync` (`node:sqlite`).
73
+ ## Runtime scenarios
101
74
 
102
- - **Journal Mode:** WAL mode with `busy_timeout = 5000ms` and `synchronous = NORMAL`.
75
+ ### Happy path
103
76
 
104
- - **Branch Naming Invariant:** `kxm/run-<cleanId>-<slug>` generated deterministically.
77
+ 1. <Step dispatch builds a context packet for the target role.>
78
+ 2. <The worker runs on its own branch, for example `kxm/run-<run-id>-<description>`.>
79
+ 3. <The worker returns a structured result with its witness evidence.>
80
+ 4. <The engine records the transition and hands off to the critics.>
105
81
 
106
- - **Commit Pinning:** Never fall back to mutable `HEAD`; strictly pin `reviewedCommit`.
82
+ ### Failure and rework
107
83
 
108
- ## Security & Isolation
84
+ 1. <How a failed attempt or a critic block is recorded.>
85
+ 2. <Which transition, retry budget, or human action decides what runs next.>
86
+ 3. <What stops the loop: a budget, a terminal status, or an operator.>
109
87
 
110
- - **Token Model:** 3-tier model (AdminToken, SessionToken, AttemptToken).
88
+ ## Data contracts, storage and invariants
111
89
 
112
- - **Process Isolation:** Worker processes run as detached children with bounded stdio frames.
90
+ - **Source of truth:** <store and schema, for example SQLite through `node:sqlite`>
91
+ - **Durability settings:** <for example WAL, a 5-second busy timeout, `synchronous = NORMAL`>
92
+ - **Naming invariants:** <branch, ID, or path conventions the subsystem relies on>
93
+ - **Pinning:** <which revisions are pinned per run, and what is never read from a mutable `HEAD`>
113
94
 
114
- - **Git Worktree Lock:** Concurrent worktree mutations acquire `.git/kxm-worktree.lock`.
95
+ ## Security and isolation
115
96
 
116
- ## Architectural Decisions (ADR Index)
97
+ - **Credentials:** <which credentials the subsystem accepts and what each may do>
98
+ - **Process isolation:** <how child processes are bounded: stdio frames, output caps, process groups>
99
+ - **Concurrency control:** <locks or leases that serialize shared mutations>
100
+ - **Not guaranteed:** <for example exactly-once external effects, or sandboxing>
117
101
 
118
- - [`ADR-0001: SQLite Native node:sqlite Engine`](../decisions/ADR-0001.md)
102
+ ## Architectural decisions
119
103
 
120
- - [`ADR-0002: Deterministic Run Branching`](../decisions/ADR-0002.md)
104
+ - `ADR-<nnnn>: <title>`: link each record in [`docs/adr/`](../adr/README.md).