harness-reflex 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +266 -2
  3. package/USER_GUIDE.md +639 -0
  4. package/dist/adapters/agy.d.ts +8 -0
  5. package/dist/adapters/agy.js +80 -0
  6. package/dist/adapters/agy.js.map +1 -0
  7. package/dist/adapters/claude.d.ts +13 -0
  8. package/dist/adapters/claude.js +46 -0
  9. package/dist/adapters/claude.js.map +1 -0
  10. package/dist/adapters/codex.d.ts +139 -0
  11. package/dist/adapters/codex.js +368 -0
  12. package/dist/adapters/codex.js.map +1 -0
  13. package/dist/backend/defaults.d.ts +31 -0
  14. package/dist/backend/defaults.js +32 -0
  15. package/dist/backend/defaults.js.map +1 -0
  16. package/dist/backend/factory.d.ts +11 -0
  17. package/dist/backend/factory.js +40 -0
  18. package/dist/backend/factory.js.map +1 -0
  19. package/dist/backend/jev.d.ts +524 -0
  20. package/dist/backend/jev.js +1486 -0
  21. package/dist/backend/jev.js.map +1 -0
  22. package/dist/backend/mock.d.ts +26 -0
  23. package/dist/backend/mock.js +320 -0
  24. package/dist/backend/mock.js.map +1 -0
  25. package/dist/backend/route-prompt.d.ts +37 -0
  26. package/dist/backend/route-prompt.js +42 -0
  27. package/dist/backend/route-prompt.js.map +1 -0
  28. package/dist/backend/simple-jev.d.ts +35 -0
  29. package/dist/backend/simple-jev.js +273 -0
  30. package/dist/backend/simple-jev.js.map +1 -0
  31. package/dist/backend/types.d.ts +270 -0
  32. package/dist/backend/types.js +5 -0
  33. package/dist/backend/types.js.map +1 -0
  34. package/dist/cli/index.d.ts +2 -0
  35. package/dist/cli/index.js +278 -0
  36. package/dist/cli/index.js.map +1 -0
  37. package/dist/core/calibrate.d.ts +56 -0
  38. package/dist/core/calibrate.js +144 -0
  39. package/dist/core/calibrate.js.map +1 -0
  40. package/dist/core/closing.d.ts +90 -0
  41. package/dist/core/closing.js +111 -0
  42. package/dist/core/closing.js.map +1 -0
  43. package/dist/core/evidence.d.ts +119 -0
  44. package/dist/core/evidence.js +209 -0
  45. package/dist/core/evidence.js.map +1 -0
  46. package/dist/core/gate.d.ts +25 -0
  47. package/dist/core/gate.js +114 -0
  48. package/dist/core/gate.js.map +1 -0
  49. package/dist/core/judge.d.ts +221 -0
  50. package/dist/core/judge.js +251 -0
  51. package/dist/core/judge.js.map +1 -0
  52. package/dist/core/ledger.d.ts +67 -0
  53. package/dist/core/ledger.js +173 -0
  54. package/dist/core/ledger.js.map +1 -0
  55. package/dist/core/orchestrate-closing.d.ts +237 -0
  56. package/dist/core/orchestrate-closing.js +250 -0
  57. package/dist/core/orchestrate-closing.js.map +1 -0
  58. package/dist/core/orchestrate-correction.d.ts +209 -0
  59. package/dist/core/orchestrate-correction.js +141 -0
  60. package/dist/core/orchestrate-correction.js.map +1 -0
  61. package/dist/core/orchestrate-host.d.ts +225 -0
  62. package/dist/core/orchestrate-host.js +80 -0
  63. package/dist/core/orchestrate-host.js.map +1 -0
  64. package/dist/core/orchestrate-stagnation.d.ts +259 -0
  65. package/dist/core/orchestrate-stagnation.js +270 -0
  66. package/dist/core/orchestrate-stagnation.js.map +1 -0
  67. package/dist/core/orchestrate.d.ts +357 -0
  68. package/dist/core/orchestrate.js +418 -0
  69. package/dist/core/orchestrate.js.map +1 -0
  70. package/dist/core/policy.d.ts +122 -0
  71. package/dist/core/policy.js +102 -0
  72. package/dist/core/policy.js.map +1 -0
  73. package/dist/core/prune-plan.d.ts +141 -0
  74. package/dist/core/prune-plan.js +390 -0
  75. package/dist/core/prune-plan.js.map +1 -0
  76. package/dist/core/prune.d.ts +30 -0
  77. package/dist/core/prune.js +73 -0
  78. package/dist/core/prune.js.map +1 -0
  79. package/dist/core/route.d.ts +35 -0
  80. package/dist/core/route.js +39 -0
  81. package/dist/core/route.js.map +1 -0
  82. package/dist/core/score.d.ts +40 -0
  83. package/dist/core/score.js +49 -0
  84. package/dist/core/score.js.map +1 -0
  85. package/dist/core/screen.d.ts +22 -0
  86. package/dist/core/screen.js +117 -0
  87. package/dist/core/screen.js.map +1 -0
  88. package/dist/core/stagnation.d.ts +23 -0
  89. package/dist/core/stagnation.js +93 -0
  90. package/dist/core/stagnation.js.map +1 -0
  91. package/dist/core/text.d.ts +36 -0
  92. package/dist/core/text.js +66 -0
  93. package/dist/core/text.js.map +1 -0
  94. package/dist/hook/cli.d.ts +9 -0
  95. package/dist/hook/cli.js +52 -0
  96. package/dist/hook/cli.js.map +1 -0
  97. package/dist/hook/contract.d.ts +125 -0
  98. package/dist/hook/contract.js +159 -0
  99. package/dist/hook/contract.js.map +1 -0
  100. package/dist/hook/decision.d.ts +97 -0
  101. package/dist/hook/decision.js +955 -0
  102. package/dist/hook/decision.js.map +1 -0
  103. package/dist/hook/memory-store.d.ts +81 -0
  104. package/dist/hook/memory-store.js +157 -0
  105. package/dist/hook/memory-store.js.map +1 -0
  106. package/dist/hook/payload.d.ts +55 -0
  107. package/dist/hook/payload.js +129 -0
  108. package/dist/hook/payload.js.map +1 -0
  109. package/dist/hook/run.d.ts +48 -0
  110. package/dist/hook/run.js +218 -0
  111. package/dist/hook/run.js.map +1 -0
  112. package/dist/hook/store-port.d.ts +72 -0
  113. package/dist/hook/store-port.js +2 -0
  114. package/dist/hook/store-port.js.map +1 -0
  115. package/dist/index.d.ts +18 -0
  116. package/dist/index.js +19 -0
  117. package/dist/index.js.map +1 -0
  118. package/dist/mcp/server.d.ts +12 -0
  119. package/dist/mcp/server.js +368 -0
  120. package/dist/mcp/server.js.map +1 -0
  121. package/dist/ports/audit.d.ts +18 -0
  122. package/dist/ports/audit.js +11 -0
  123. package/dist/ports/audit.js.map +1 -0
  124. package/dist/ports/clock.d.ts +14 -0
  125. package/dist/ports/clock.js +11 -0
  126. package/dist/ports/clock.js.map +1 -0
  127. package/dist/ports/decision.d.ts +75 -0
  128. package/dist/ports/decision.js +2 -0
  129. package/dist/ports/decision.js.map +1 -0
  130. package/dist/ports/index.d.ts +14 -0
  131. package/dist/ports/index.js +2 -0
  132. package/dist/ports/index.js.map +1 -0
  133. package/dist/ports/log.d.ts +22 -0
  134. package/dist/ports/log.js +12 -0
  135. package/dist/ports/log.js.map +1 -0
  136. package/dist/ports/state.d.ts +46 -0
  137. package/dist/ports/state.js +13 -0
  138. package/dist/ports/state.js.map +1 -0
  139. package/dist/state/clock.d.ts +40 -0
  140. package/dist/state/clock.js +43 -0
  141. package/dist/state/clock.js.map +1 -0
  142. package/dist/state/file-store.d.ts +340 -0
  143. package/dist/state/file-store.js +849 -0
  144. package/dist/state/file-store.js.map +1 -0
  145. package/dist/state/paths.d.ts +41 -0
  146. package/dist/state/paths.js +73 -0
  147. package/dist/state/paths.js.map +1 -0
  148. package/docs/USER_GUIDE.en.md +721 -0
  149. package/docs/claude-code.md +281 -0
  150. package/docs/design/v0.2.0-harness-plugins.md +381 -0
  151. package/docs/design/v0.3.0-orchestration-unification.md +580 -0
  152. package/docs/dsh-plugin.md +578 -0
  153. package/docs/reflex-ui-regression-2026-10-20.md +34 -0
  154. package/docs/release-checklist-v0.1.0.md +315 -0
  155. package/docs/release-handbook-porting-notes.md +106 -0
  156. package/docs/release-handbook.md +393 -0
  157. package/docs/release-notes-v0.1.0.md +63 -0
  158. package/docs/release-notes-v0.3.0.md +152 -0
  159. package/docs/research/claude-code-harness.md +607 -0
  160. package/docs/research/pi-harness.md +621 -0
  161. package/experiments/data/calibration_sample.json +14 -0
  162. package/experiments/index.ts +29 -0
  163. package/experiments/runner.ts +156 -0
  164. package/package.json +82 -4
@@ -0,0 +1,721 @@
1
+ # Harness Reflex User Guide (v0.1.0)
2
+
3
+ > This is the complete manual for the **`dsh-harness-reflex` plugin** and the
4
+ > **`harness-reflex` core package**. The same text is embedded into
5
+ > `packages/dsh-harness-reflex/client.js`, so it can be read directly in the DSH
6
+ > settings panel under the **“Guide”** tab (it follows the DSH interface
7
+ > language, Chinese or English).
8
+ > Editing this file therefore requires re-running `npm run build:all`, otherwise
9
+ > the panel keeps the last build (`npm run test:plugin` checks the
10
+ > document digest and fails on drift).
11
+
12
+ ---
13
+
14
+ ## 1. What Harness Reflex is
15
+
16
+ Harness Reflex is a **System One (fast-thinking) decision runtime**: without
17
+ paying for generative System Two reasoning it performs millisecond-scale
18
+ probabilistic judgements — verification gates, context pruning, stagnation
19
+ breaking, model routing and reasoning-effort decisions — and records every
20
+ decision in an auditable ledger.
21
+
22
+ It ships in two forms that share one decision engine but expose **different tool surfaces** (see section 9):
23
+
24
+ | Form | Package | Harness | Transport |
25
+ | --- | --- | --- | --- |
26
+ | stdio MCP server | `harness-reflex` | Claude Code, Codex CLI, AGY | MCP JSON-RPC child process |
27
+ | DSH Host plugin | `dsh-harness-reflex` | DeepSeek Harness (`dsh`) | In-process `ctx.tools` / Cordis hooks |
28
+
29
+ The MCP surface exposes eight tools; the DSH surface registers five switchable
30
+ tools (four by default), while pruning, stagnation detection and the ledger are
31
+ carried by automatic interventions and the `/reflex-ledger` command. See section 9
32
+ and each surface's actual tool definitions for argument and validation boundaries.
33
+
34
+ ---
35
+
36
+ ## 2. Plugin architecture
37
+
38
+ ```text
39
+ ┌──────────────────────────────────────────────────────────────────────┐
40
+ │ Harness Layer │
41
+ │ Claude Code (.mcp.json) · Codex (.codex/config.json) · AGY bundle │
42
+ └───────────────┬──────────────────────────────────┬───────────────────┘
43
+ │ stdio MCP │ in-process DSH Cordis
44
+ ┌───────────────▼──────────────────┐ ┌────────────▼───────────────────┐
45
+ │ harness-reflex core (dist/) │ │ dsh-harness-reflex plugin │
46
+ │ gate · prune · stagnation │◄─┤ src/bridge.ts ReflexRuntime │
47
+ │ route · screen · score │ │ src/tools.ts 5 switchable │
48
+ │ ledger · calibrate │ │ src/router.ts virtual provider│
49
+ └───────────────┬──────────────────┘ │ src/effort.ts effort intercept│
50
+ │ DecisionBackend │ src/panel-* settings + API │
51
+ ┌───────────────▼──────────────────┐ └────────────┬───────────────────┘
52
+ │ mock · simple-jev/vLLM · Jev API │ │ settings.section
53
+ └──────────────────────────────────┘ ┌────────────▼───────────────────┐
54
+ │ client.js browser panel (React) │
55
+ │ Overview / Virtual provider / │
56
+ │ Effort / Backend / Interventions│
57
+ │ Tools / Ledger / Guide │
58
+ └────────────────────────────────┘
59
+ ```
60
+
61
+ Key modules of the plugin:
62
+
63
+ | File | Responsibility |
64
+ | --- | --- |
65
+ | `src/index.ts` | Cordis entry `apply(ctx, config)`; install and teardown inside one `ctx.effect` |
66
+ | `src/bridge.ts` | `ReflexRuntime`: backend / ledger / calibrator / decision services of one activation |
67
+ | `src/tools.ts` | The five switchable `reflex_*` tools, four registered by default (Host `defineTool` validation plus an undeclared-argument fence) |
68
+ | `src/router.ts` | `VirtualModelRouter`: candidate pool → System 1 decision → fallback / fail-closed → audit |
69
+ | `src/virtual-adapter.ts` | `LlmAdapter` surface of the virtual provider plus a dispatch-layer safety net |
70
+ | `src/routing.ts` | `installModelRouting`: registers the virtual provider, hooks `agent/pre-step` and `agent/request` |
71
+ | `src/effort.ts` | `EffortInterceptor`: per-turn reasoning-effort decision, projection and status reporting |
72
+ | `src/session-audit.ts` | Writes/reads `plugin:dsh-reflex/effort` session records without polluting model context |
73
+ | `src/panel-api.ts` | Read-only panel projection and the `/dsh-reflex/api/*` routes (loopback only) |
74
+ | `src/client/*` | Browser half: slot registration, zh/en copy, Markdown renderer, panel views |
75
+
76
+ Activation order: DSH loads the plugin → `apply` resolves the configuration →
77
+ `ReflexRuntime` is built → the virtual provider and request hooks are installed →
78
+ the four default tools (five with `route` switched on) are registered →
79
+ the `/reflex-ledger` command is registered → the panel routes are mounted.
80
+ Unloading unwinds in reverse and is fully reversible.
81
+
82
+ ---
83
+
84
+ ## 3. Install and build
85
+
86
+ ```bash
87
+ # 1) install dependencies and build (root → link host deps → plugin → client bundle)
88
+ npm install
89
+ npm run build:all
90
+
91
+ # 2) configure a target harness (writes .mcp.json / .codex/config.json / the AGY bundle)
92
+ node dist/cli/index.js setup all # or claude | codex | agy
93
+
94
+ # 3) install as a DSH plugin (in-process integration, recommended)
95
+ # release tarball: --force is required to reinstall the same version
96
+ dsh plugin --profile web add --force ./release/dsh-harness-reflex-0.1.0.tgz
97
+ ```
98
+
99
+ Every step of `npm run build:all` is required:
100
+
101
+ 1. `tsc`: root `src/` → `dist/`;
102
+ 2. `node scripts/link-dsh-deps.mjs`: symlinks this machine's `@deepseek-ai/*`
103
+ packages into `packages/dsh-harness-reflex/node_modules/` (fully offline, no registry);
104
+ 3. `tsc -p packages/dsh-harness-reflex/tsconfig.json`: plugin Host half → `packages/dsh-harness-reflex/dist/`;
105
+ 4. `node scripts/embed-user-guide.mjs` + `tsc -p tsconfig.client.json` +
106
+ `node packages/dsh-harness-reflex/dist/client-bundle.js packages/dsh-harness-reflex`:
107
+ embeds this manual into the browser half and emits the single-file `client.js`.
108
+
109
+ > The order is not interchangeable: `client.js` must be built after this
110
+ > document changes, otherwise the panel shows a guide that differs from the
111
+ > repository document.
112
+
113
+ ---
114
+
115
+ ## 4. System 1 backend configuration
116
+
117
+ All three backends share one set of `SYSTEM_ONE_*` environment variables and
118
+ plugin options; resolution order is “plugin config > environment > default mock”.
119
+
120
+ | Backend | Value | Notes |
121
+ | --- | --- | --- |
122
+ | Local heuristics (default) | `mock` | Deterministic, no network, sub-millisecond; for offline dev and tests |
123
+ | Generic logits read-out | `simple-jev` | vLLM / OpenAI-compatible `max_tokens: 1` with next-token logprobs |
124
+ | Official Jev / System One API | `jev` | `POST {BASE_URL}/v1/...`, requires an API key |
125
+
126
+ ```bash
127
+ # Official Jev: only the key is required
128
+ export SYSTEM_ONE_API_KEY="your-api-key"
129
+
130
+ # Self-hosted vLLM (OpenAI compatible): only the endpoint is required
131
+ export SYSTEM_ONE_BASE_URL="http://localhost:8000"
132
+ export SYSTEM_ONE_BACKEND=simple-jev # optional: VLLM_BASE_URL/OPENAI_BASE_URL alone selects simple-jev
133
+ ```
134
+
135
+ With `SYSTEM_ONE_BACKEND` unset the choice is derived: `SYSTEM_ONE_API_KEY`/`JEV_API_KEY` present → `jev`;
136
+ `VLLM_BASE_URL`/`OPENAI_BASE_URL` present → `simple-jev`; neither → `mock`.
137
+
138
+ The other two variables default per backend, so “default mock” says nothing about them:
139
+
140
+ | Variable | `jev` | `simple-jev` |
141
+ | --- | --- | --- |
142
+ | `SYSTEM_ONE_BASE_URL` | `https://api.typesafe.ai/v1/systemone` | `http://localhost:8000` |
143
+ | `SYSTEM_ONE_MODEL` | `jev-latest` | `Qwen/Qwen2.5-7B-Instruct` |
144
+ | `SYSTEM_ONE_API_KEY` | **none** (empty; the service rejects the request) | `dummy` (local servers usually ignore it) |
145
+
146
+ **A connection comes only from the active connection profile** ("Connections" on the
147
+ System 1 backend page). With none active the plugin is **unconfigured**: the panel says
148
+ so, the plugin makes no external request, and decisions fall back to the local
149
+ deterministic heuristics. A mistyped active name is reported and connects nothing — it is
150
+ never silently swapped for another connection.
151
+
152
+ Each connection profile states its own fields (under `systemOne.profiles.<name>` in the
153
+ DSH plugin config):
154
+
155
+ | Option | Default | Notes |
156
+ | --- | --- | --- |
157
+ | `baseUrl` | unset | System 1 endpoint; unset lets the backend use its environment/default |
158
+ | `modelIds` | unset | The **list of model ids** this connection may ask for. `model` is the single-model spelling, identical to a one-entry list |
159
+ | `selectedModel` | first listed id | The **one model in force**: the runtime sends it and the Test button probes it. It must be one of `modelIds`: the save refuses a selection outside the list, and a hand-edited file that still carries one builds **no connection at all** (the panel shows "not configured") instead of asking for a different model |
160
+ | `apiKey` | unset | The secret itself, **write-only**: it is stored on save and never shown again. A **rename does not carry it** — retype it after renaming (see below) |
161
+ | `apiKeyEnv` | unset | Stores the **variable name only**. Unset names nothing and the backend falls back to `SYSTEM_ONE_API_KEY` → `JEV_API_KEY` → `VLLM_API_KEY` → `OPENAI_API_KEY`; naming a variable locks onto it, with no fallback |
162
+ | `timeoutMs` | unset | Per-decision timeout; unset uses the **backend default — 10000 ms for `jev`, 8000 ms for `simple-jev`**, not one shared value |
163
+ | `backend` | unset | Backend implementation for this connection; unset uses the top-level `backend` |
164
+
165
+ The top-level `backend` only decides *which implementation a connection uses when it
166
+ states none* (`auto` derives from the environment; `mock` / `vllm` / `jev` may be pinned).
167
+ It is not a connection by itself. An explicit `backend: mock` still works: that is a
168
+ deliberate choice of the in-process implementation, and needs no profile.
169
+
170
+ **Renames and write-only keys.** A connection's name *is* its settings path, so renaming
171
+ it means writing a different path — and the Host cannot move a stored secret across paths.
172
+ The panel therefore **blocks the save** and names the row, asking you to retype the API
173
+ key (connections whose key comes from an environment variable are unaffected and rename
174
+ normally). Swapping two names, or renaming onto a name another saved profile already
175
+ holds, is refused the same way, with its own explanation.
176
+
177
+ The same-named `baseUrl` / `model` / `apiKeyEnv` / `timeoutMs` keys at the top of
178
+ `systemOne` do not take part in the connection: they are not a connection profile. If a
179
+ document still holds them, the panel neither reads nor rewrites them.
180
+
181
+ Calibration (optional): fit a PAVA/ECE curve with the `calibrate` engine over a
182
+ labelled sample, then point `calibrationPath` at that JSON and the runtime will
183
+ correct over-confident raw probabilities.
184
+
185
+ ---
186
+
187
+ ## 5. Virtual provider and model pools
188
+
189
+ **Concept.** The plugin registers one virtual provider (id `reflex` by default)
190
+ that generates no tokens itself: when a request targets a virtual model such as
191
+ `reflex/reflex-auto`, the `agent/request` hook asks System 1 to pick a real
192
+ `provider/model` from that virtual model's **physical candidate pool**, rewrites
193
+ the request, lets it continue, and appends a `type: model-route` ledger entry.
194
+
195
+ Configuration shape (corresponding YAML):
196
+
197
+ ```yaml
198
+ routing:
199
+ enabled: true
200
+ virtualProvider: reflex
201
+ maxTaskChars: 400 # task-text budget per participating agent
202
+ fallback: deepseek:deepseek-chat # used when no pool can answer
203
+ models:
204
+ reflex-auto: # virtual model id
205
+ - provider: deepseek
206
+ model: deepseek-reasoner
207
+ description: long-horizon reasoning and refactors
208
+ tags: [reasoning, expensive]
209
+ - provider: deepseek
210
+ model: deepseek-chat
211
+ description: everyday chat and quick edits
212
+ tags: [fast, cheap]
213
+ reflex-fast:
214
+ - provider: deepseek
215
+ model: deepseek-chat
216
+ description: latency-sensitive work
217
+ tags: [fast]
218
+ ```
219
+
220
+ **Rules and boundaries.**
221
+
222
+ - `enabled: false`, or an empty `models` map ⇒ no virtual provider is
223
+ registered and behaviour matches an installation without the plugin.
224
+ - An empty pool with no `fallback` ⇒ **fail-closed**: an error instead of a
225
+ random dispatch.
226
+ - `virtualProvider` may not contain `:`; candidate `provider` and `model` may
227
+ not be empty.
228
+ - Primary agents and subagents share the same interception path, and the loop
229
+ identity survives the rewrite unchanged.
230
+ - Candidates, the selection, confidence and latency all reach the ledger, which
231
+ the “Decision ledger” page replays.
232
+
233
+ **Context awareness and session stickiness (cache savings, no gratuitous
234
+ switches).** Changing models invalidates the server-side prompt prefix cache, so
235
+ routing is not “pick again every turn”: by default it **holds the physical model
236
+ the session is already using**.
237
+
238
+ - The plugin accumulates, per agent, the context size it has observed for this
239
+ session (the characters `agent/pre-step` hands it, at roughly 4 characters per
240
+ token) and gives every decision both that number and the **current physical
241
+ model** (`state.currentModel` / `state.contextTokens` / `state.contextChars`).
242
+ - The decision prompt states the policy as well: keeping the current model keeps
243
+ the prompt cache, so switch only when another candidate is **clearly better
244
+ suited**. The current candidate is marked in the list with
245
+ `[current model — keeping it preserves the prompt cache]` and the `current: true`
246
+ flag, so a text-reading backend and a flag-reading backend see one signal.
247
+ - After the backend ranks the pool, a **sticky gate** still applies: a challenger
248
+ must score higher *and* by more than a relative `stickyMargin` (15% by default)
249
+ before the request actually moves. Ties and marginal wins stay put.
250
+ - Every `model-route` entry records `currentModel`, `switched` and
251
+ `contextTokens`, so “why did this turn not switch” is replayable rather than
252
+ guessed.
253
+ - Stickiness only applies **inside one pool**: when the current model is not a
254
+ candidate this turn (say the session moved to another virtual model), the pool’s
255
+ own ranking decides and `switched` is recorded as `true`.
256
+
257
+ **Configuring it in the panel.** Open DSH settings → “Reflex runtime” →
258
+ **Virtual provider**: toggle routing, fill in the provider name, the fallback
259
+ target and the task-text budget, then add virtual models and candidates
260
+ (up/down reorders them) and press **Save** to write the whole group. The panel
261
+ validates through the same Host-side `resolveConfig` used at load time, so an
262
+ invalid document (empty id, duplicate model, cross-group mistake) is rejected
263
+ with a specific message.
264
+
265
+ ---
266
+
267
+ ## 6. Adaptive reasoning effort (`reflex` / `auto`)
268
+
269
+ With the effort policy set to `reflex` (`auto` means the same), the plugin intercepts the
270
+ intent and context before each real API request, asks System 1 for the
271
+ `reasoningEffort` this turn needs, and rewrites the outgoing parameter.
272
+
273
+ | Option | Default | Notes |
274
+ | --- | --- | --- |
275
+ | `effort.reasoningEffort` | unset | `reflex` / `auto` = per-turn adaptive; unset = never intervene, the plugin never touches `reasoningEffort`; a concrete level is chosen in the model selector, and the offered levels follow what the target model declares |
276
+ | `effort.fallback` | `medium` | Deterministic cue vote used when System 1 is unavailable or below the confidence floor |
277
+ | `effort.minConfidence` | `0.3` | Decisions below this confidence go to the fallback instead |
278
+ | `effort.enabled` | `true` | `false` turns the whole layer off: no judgment, no audit, no injected `reflex` level |
279
+
280
+ Configuration answers exactly one question: **should adaptive effort run at all?**
281
+
282
+ - **blank (the default) = never intervene**: the plugin never rewrites
283
+ `reasoningEffort` and produces no decision or audit record, so the request
284
+ behaves exactly as if this feature were not installed;
285
+ - **`reflex` (`auto` means the same) = adaptive**: every turn is decided by System 1;
286
+ - **to fix the thinking depth**: choose a concrete level in the model selector; the
287
+ offered levels follow what the target model declares. Configuration only accepts
288
+ blank or `reflex` (`auto` means the same); any other value is rejected at startup
289
+ with a hint to pick the level in the model selector.
290
+
291
+ **Behaviour contract.**
292
+
293
+ - A concrete `reasoningEffort` chosen explicitly by the caller on the request
294
+ always stays transparent; the plugin never overrides it.
295
+ - A target model that does not support thinking levels degrades safely instead
296
+ of receiving the parameter verbatim.
297
+ - Every turn writes one audit record (`plugin:dsh-reflex/effort`) containing the
298
+ decided level, the confidence and a truncated task excerpt; it never enters
299
+ the model-visible context.
300
+ - The decision is projected to the status line as well; the Overview page shows
301
+ the latest one (for example `reflex: high (confidence 0.82, system-one, 12.4 ms)`).
302
+
303
+ **Turning the whole layer off (`effort.enabled: false`).**
304
+
305
+ `effort.enabled` is a **capability switch**, independent of what the policy is:
306
+ `reasoningEffort: reflex` together with `enabled: false` is a legitimate
307
+ combination whose meaning is "install none of this interception" (the only
308
+ difference being that the policy is still written down). With it off:
309
+
310
+ - **no judgment**: no System 1 call, no cue vote, no judgment cache, and no
311
+ `reflex/effort` status published — the Overview page shows no decision of this
312
+ plugin;
313
+ - **no audit**: no `effort-decision` entry in the ledger and no
314
+ `plugin:dsh-reflex/effort` record in the session log;
315
+ - **no injected level**: the level this plugin injected (`reflex` / `auto`) is
316
+ revoked from the model selector, which keeps only the adapter's own levels and
317
+ its declared default;
318
+ - **concrete levels pass through verbatim**: a `high`, `medium` and so on chosen
319
+ explicitly by the caller on the request is not even aligned onto the routed
320
+ model's vocabulary;
321
+ - **the marker still cannot leak**: if an existing session or a hand-built call still
322
+ carries this plugin's marker, it is **deleted at the physical adapter
323
+ boundary** rather than translated into a level, so the provider's own default
324
+ applies and no plugin marker ever reaches a real provider.
325
+
326
+ It defaults to `true` (omitted means `true`), so not writing this option behaves
327
+ byte-identically to writing `true` explicitly.
328
+
329
+ ---
330
+
331
+ ## 7. Automatic intervention gates (`off` / `observe` / `active`)
332
+
333
+ The plugin can intervene on its own through the Host's native hooks, **without the
334
+ model calling any `reflex_*` tool**. There is exactly one switch, `interventions.mode`, taking `off`,
335
+ `observe` or `active`, and it defaults to `observe`:
336
+
337
+ ```yaml
338
+ interventions:
339
+ mode: observe # off | observe | active
340
+ capabilities: # optional per-capability override; inherit follows mode
341
+ stagnation: inherit
342
+ prune: inherit
343
+ gate: inherit
344
+ closing: inherit
345
+ maxInterventionsPerTurn: 3
346
+ maxJudgmentsPerTurn: 3
347
+ maxJudgmentsPerSession: 20
348
+ ```
349
+
350
+ Each of the four capabilities is **four-state**: `off` / `observe` / `active`
351
+ override `mode` explicitly, while `inherit` (or omitting it) follows `mode`. You
352
+ can therefore keep the gate `active` overall and lower `prune` alone to
353
+ `observe` (accounting only, no rewriting), or set everything to `off` and open
354
+ up `gate` only.
355
+
356
+ | Mode | Behaviour |
357
+ | --- | --- |
358
+ | `off` | No hook listener is registered at all; tool execution is byte-identical to running without the plugin |
359
+ | `observe` (default) | Full detection and judging, accounting only: no content rewriting, no injected message, no refused tool, no steer |
360
+ | `active` | The full chain: a repeated call is refused before it runs, an oversized result is pruned before it enters the context, a repeated failure is rewritten into corrective feedback, and a turn closing on contradicted evidence is objected to |
361
+
362
+ | Capability | Hook | What `active` does |
363
+ | --- | --- | --- |
364
+ | `stagnation` | `tools/pre-execute`, `agent/pre-step` | After a confirmed repetition or oscillation, refuses that call or attaches corrective context to the next step |
365
+ | `prune` | `tools/post-execute` | For a result above the threshold, retains the original first and then rewrites: the original goes into the session log under a locator, and the replacement keeps head and tail and names that locator |
366
+ | `gate` | `tools/post-execute` | Rewrites the result into corrective feedback once one call has failed repeatedly; failure is read from the tool source's structured exit status or the Host's exit badge, never from wording |
367
+ | `closing` | `agent/turn-stopping` | Re-checks the turn's claims against its evidence with `reflex_gate` and steers once when they contradict |
368
+
369
+ ### Why a legitimate wait is never treated as stagnation (the exemption default)
370
+
371
+ Waiting on a background job is legitimate work, so `stagnation` exempts **structurally
372
+ identifiable wait queries**. The decision reads two structured facts only — it never parses a
373
+ tool's description and never reads any output text:
374
+
375
+ 1. **tool identity**: the call is one of the Host's own background-job query tools, `job_output`
376
+ or `job_list` (registered by `@deepseek-ai/dsh-tool-jobs`; the shell tools' background jobs go
377
+ through the same `job_output` verb);
378
+ 2. **call shape**: the arguments carry the job handle in the Host's own declared field — a
379
+ non-empty `job_id` string for `job_output`; `job_list` declares no parameters at all, so its
380
+ shape is the empty argument object.
381
+
382
+ An exempt call is never refused, never gets corrective context, and spends none of the turn's
383
+ intervention or judgment allowance; `observe` and `active` plan exactly the same thing. It is
384
+ still recorded in the detection window, but it does not count as an unproductive repeat — the
385
+ repetition, failing-retry, and oscillation triggers all skip it — so **a real loop does not
386
+ disappear just because the run waited for a job in between**. `job_kill` is deliberately outside
387
+ the exemption: it terminates a job rather than waiting for one. Output text that happens to
388
+ contain `wait`, `sleep`, or `poll` earns nothing. The scope is the two tool names above; this is
389
+ the documented default and needs no extra configuration.
390
+
391
+ ### How to get a pruned original back
392
+
393
+ `active` pruning retains first and replaces second, and that order is not a figure of speech:
394
+
395
+ 1. the replacement is built only after the judgment passed **and** retention succeeded;
396
+ 2. the original is written into the session log as a `plugin:dsh-reflex/pruned-original`
397
+ record (the Host's `appendPluginRecord`); it never enters the model-visible surface, and
398
+ `fork` / `resume` carry it with the rest of the log;
399
+ 3. the replacement names the locator `plugin:dsh-reflex/pruned-original#<digest>` in its
400
+ middle, so the model can always ask for the omitted part;
401
+ 4. when retention fails (no session, a missing log, a failed read-back check) **nothing is
402
+ replaced** and no `actualSavedTokens` is reported — the result stays byte-identical
403
+ (recorded as `retention-failed`; the judgment was really paid for, and is still booked).
404
+
405
+ Retrieval is a read of the session events under that locator:
406
+
407
+ ```ts
408
+ import { readPrunedOriginal } from 'dsh-harness-reflex';
409
+
410
+ const record = readPrunedOriginal(session.ownEvents(), locator);
411
+ record?.text; // the original, byte for byte
412
+ record?.chars; // the size it was retained at
413
+ record?.digest; // the digest the decision was recorded under
414
+ ```
415
+
416
+ The `pruneFloorRatio` floor (0.5 by default) is the **smallest share of the original the
417
+ installed text may keep**: a judged candidate below it is padded with head and tail context
418
+ up to that share, and the middle diagnostics the judgment chose are kept whole — the floor
419
+ never drops them. Retention has boundaries: a payload with fewer than four newlines (under
420
+ five lines) or more than 100 000 characters is not pruned at all (recorded as
421
+ `unsupported-payload` / `retention-too-large`), so single-line output and oversized logs pass
422
+ through untouched; a payload that repeats reuses the copy retained the first time instead of
423
+ writing a second one.
424
+
425
+ ### Cost and traceability
426
+
427
+ - The ledger is split by `mode` and by `capability`: `plans` (decisions taken),
428
+ `applied` (decisions executed), `judgments` / `memoHits`, `judgeTokens`,
429
+ `originalTokens` / `candidateTokens` / `potentialSavedTokens` (what could be
430
+ saved) / `actualSavedTokens` (what really stopped entering the context);
431
+ - `observe` always reports `actualSavedTokens` 0, and its `potentialSavedTokens`
432
+ matches `active` on the same input, item by item;
433
+ - Judging cost is separated: `localLatencyMs` (local arbitration) versus
434
+ `remoteLatencyMs` (backend judgment);
435
+ - Every pruning record carries the replaced original's `digest`, its `turn`/`step` and its
436
+ `originalLocator`; that locator reads the original back byte for byte (see "How to get a
437
+ pruned original back" above);
438
+ - Retention is a precondition of replacement: when it fails nothing is replaced and no
439
+ `actualSavedTokens` is reported, and `plans` does not claim a reduction that never happened;
440
+ - `off` is strictly zero behaviour: no listener, no sampling, no judgment — byte-identical to
441
+ running without the plugin;
442
+ - The judgment cache is keyed by turn plus trailing window: one question costs one
443
+ judgment per turn. `maxJudgmentsPerTurn`, `maxJudgmentsPerSession` and
444
+ `maxInterventionsPerTurn` bound judgments per turn, judgments per session and
445
+ interventions per turn;
446
+ - Interventions for one `(agent, call signature)` are de-duplicated within a turn,
447
+ and the result of a call this plugin refused is never judged a second time;
448
+ - This plugin's own tools are never judged — their output is already the
449
+ optimizer's (four by default, five with `route` on) — so no `reflex_*` payload
450
+ this plugin registers is ever re-judged.
451
+
452
+ ### Safety and rollback
453
+
454
+ - **fail-open**: any judging step that throws hands the downstream result on
455
+ unchanged (recorded as `planning-error`); a tool call never fails because of it;
456
+ - **failure is never inferred from wording**: the structured `exitCode`/`signal` decides, then
457
+ the exit badge the Host appends as the last line; the word "failed" inside an ordinary result
458
+ is not a failure and never blocks a legitimate retry;
459
+ - **Monotonic permission**: `tools/pre-execute` only ever appends a `deny` to a downstream
460
+ `allow`; an `ask`/`deny`/`cancel` from downstream is returned as the same object, with its
461
+ `info` intact — never loosened, never overwritten;
462
+ - **Session isolation**: detection windows, verdict caches and budgets are booked
463
+ per agent and never shared between agents;
464
+ - **No residue**: unloading the plugin detaches every listener and clears the
465
+ engine's state; the ledger stays in memory unless `ledgerPath` is set.
466
+
467
+ ---
468
+
469
+ ## 8. Settings panel (DSH Settings UI)
470
+
471
+ The plugin declares its browser half through `dsh.client` and registers into the
472
+ `settings.section` slot:
473
+
474
+ | Tab | Content |
475
+ | --- | --- |
476
+ | Overview | Decision count, tokens saved, average latency, gate pass/fail, latest adaptive decision |
477
+ | Virtual provider | Routing switch, provider name, pool editing and ordering, fallback target |
478
+ | Reasoning effort | Policy (never intervene / Reflex adaptive), fallback level, minimum confidence, **adaptive-effort switch** |
479
+ | Interventions | Three-state mode (`off`/`observe`/`active`), the four capability overrides, per-turn intervention budget, per-turn judgment budget, per-session judgment budget, repeat threshold, failure threshold, minimum confidence, judgment window size, prune floor ratio; plus the currently effective mode and capabilities (read-only) |
480
+ | Tools | A per-capability switch for each of the five capabilities (four on, `route` off by default), each one stating **what it does / when the agent should call it / whether it is advised to expose it**, plus an "Apply recommended set" button; the currently registered tool names are listed at the end (read-only, follows `toolPrefix`), with a line pointing the ledger at `/reflex-ledger` |
481
+ | System 1 backend | Connection profiles (any number: base URL, model list with one selection, write-only API key, key variable name, timeout), the backend implementation; plus the tool-name prefix, prune threshold, ledger JSONL path and calibration-curve path |
482
+ | Decision ledger | Live metrics, recent-decision table, JSONL sink, clear (confirmed twice) |
483
+ | **Guide** | **A read-only view of this manual, following the DSH interface language** |
484
+
485
+ - Saving validates through the Host and writes **only the paths whose value
486
+ changed** (whole-group pages still write their group whole — see below). The
487
+ System 1 backend page spans the connection rows, `systemOne.active`, `backend`
488
+ and the four runtime fields.
489
+ - When the Host settings document is read-only the page becomes read-only and
490
+ every write control is disabled.
491
+ - Panel routes under `/dsh-reflex/api/*` (`panel` / `health` / `ledger/clear`) accept loopback clients only, and
492
+ clearing the ledger requires an explicit confirmation.
493
+
494
+ ### What each group writes back
495
+
496
+ The panel always shows the **currently effective values**, and saving goes
497
+ through the Host settings document's only write channel (a per-group `set` plus
498
+ the revision check) — there is no second write path. The groups differ in how
499
+ much they write:
500
+
501
+ - **Interventions: whole-group write-back.** Saving that group writes the
502
+ group's **current mode and every budget value in full**, exactly like the
503
+ virtual-provider and reasoning-effort groups, so what the configuration keeps
504
+ is the complete set of values you see, not only the field you edited.
505
+ Capability overrides write only the entries that are **not** `inherit`; the
506
+ rest stay omitted (omitted = follow the mode).
507
+ - **Tools: only departures from the default are written.** A default-on tool
508
+ switched off is written as `false`, the default-off `route` switched on is
509
+ written as `true`, and switching anything back to its default **deletes** the
510
+ key. The recommended set and "the whole group omitted" are therefore
511
+ byte-identical (the default already is four on, one off), and the default
512
+ configuration does not change at all.
513
+ - **The reasoning-effort switch is always written explicitly.** `effort.enabled`
514
+ is saved with the group's current value, so there is no "the panel shows it
515
+ enabled but the configuration actually omits it" ambiguity.
516
+ - **System 1 backend: only the paths that changed.** The Host settings
517
+ document is addressed by **configuration path**, and this page covers
518
+ `backend` (a scalar), the connection rows (`systemOne.profiles.<name>.<field>`),
519
+ `systemOne.active`, and the four top-level fields `toolPrefix`, `ledgerPath`,
520
+ `pruneThreshold` and `calibrationPath`: saving writes the paths whose value
521
+ actually changed and leaves untouched rows and fields alone (a renamed or
522
+ removed row retires its whole old subtree). A **page name is never used as a configuration key** —
523
+ `runtime` is not a field of `Config`, so writing under that name is refused by
524
+ the Host outright and the whole save fails with it. A blank `ledgerPath` or
525
+ `calibrationPath` is written as "unset", which keeps the layer below instead of
526
+ storing an empty string.
527
+
528
+ An illegal value (an unknown tool suffix, a non-boolean, an out-of-range budget,
529
+ an invalid three-state value) is rejected by the same Host-side `resolveConfig`
530
+ validator with a field-level message, and the panel applies nothing partially:
531
+ the whole group passes, or not a byte of it is written.
532
+
533
+ ### Tool switches: two kinds of advice, and the recommended set
534
+
535
+ Every entry on the tools page states three things: **what the capability does**,
536
+ **when the agent should call it**, and one label answering **whether it is advised
537
+ to expose it to the agent**:
538
+
539
+ | Advice | Meaning | Capabilities |
540
+ | --- | --- | --- |
541
+ | Suggested for the agent | The agent genuinely uses it in day-to-day work | `choice`, `score`, `screen`, `gate` |
542
+ | Opt-in | It only pays off when there are many candidates, so it is off by default | `route` |
543
+
544
+ The "**Apply recommended set**" button at the top pre-fills those five switches
545
+ and switches `route` off. **That recommended set is the default**: with
546
+ `tools.enabled` omitted, `choice`, `score`, `screen` and `gate` are on and `route`
547
+ is off, so the DSH plugin exposes four tools by default. The button pre-fills the
548
+ draft only and writes nothing — the group is still saved when you press Save, and
549
+ a draft that already equals the default writes **nothing at all** (there is no
550
+ difference to record).
551
+
552
+ `route` is an optional extra: switching it on (on the page, or with
553
+ `tools: { enabled: { route: true } }`) is what registers `reflex_route`; the main
554
+ flow does not depend on it.
555
+
556
+ Three capabilities are **commands and hooks now** and therefore have no switch here:
557
+ `prune` (result pruning) and `detect_stagnation` (stagnation detection) are driven
558
+ directly by the intervention layer as `observe`/`active` take effect, and the
559
+ ledger summary moved to the `/reflex-ledger` command. A line at the end of the
560
+ page points both out; the stdio MCP side still carries all eight tool names, see
561
+ the next section.
562
+
563
+ ---
564
+
565
+ ## 9. MCP tools ↔ DSH native capabilities
566
+
567
+ The two forms **use different tool sets**: the stdio MCP side still exposes
568
+ the **eight tools frozen since v0.1.0**, while the DSH plugin side registers
569
+ **five switchable capabilities (four by default)** — the other three are carried
570
+ by the automatic intervention layer and by one command instead of occupying the
571
+ model's tool list.
572
+
573
+ | Capability | MCP tool name (`harness-reflex mcp`) | DSH plugin side (`dsh-harness-reflex`) | Main arguments | Advice |
574
+ | --- | --- | --- | --- | --- |
575
+ | Multi-option classification | `reflex_choice` | tool `reflex_choice` | `question`, `options[]`, optional `context` | Suggested for the agent |
576
+ | Continuous rating | `reflex_score` | tool `reflex_score` | `statement`, optional `criteria`, `context` | Suggested for the agent |
577
+ | Prompt-injection screen | `reflex_screen` | tool `reflex_screen` | `content`, optional `source`, `strict` | Suggested for the agent |
578
+ | Claim/evidence gate | `reflex_gate` | tool `reflex_gate` | `assertions[{statement}]`, `evidence`, optional `strictness` | Suggested for the agent |
579
+ | Candidate ranking | `reflex_route` | tool `reflex_route` (**not registered by default**) | `goal`, `candidates[]`, optional `topK` | Opt-in |
580
+ | Subagent delegation | `reflex_delegate` | tool `reflex_delegate` (**only registered after you tick Delegation in the settings panel, and the host delegation tool then declares a reasoning level, i.e. `modelSelection` is on**) | `prompt`, `description`, optional `provider`, `model`, `cwd` | Suggested for the agent |
581
+ | Long-output pruning | `reflex_prune` | no tool: result pruning runs automatically from hooks such as `tools/pre-execute`, following the intervention mode | `rawOutput`, optional `intent`, `shadowMode` | — |
582
+ | Stagnation detection | `reflex_detect_stagnation` | no tool: stagnation detection is part of the automatic intervention layer | optional `recentAction`, `goal`, `history[]` | — |
583
+ | Ledger audit | `reflex_status_ledger` | no tool: use the `/reflex-ledger` command (no arguments) | optional `includeEntries` (returns `summary`, optionally `recentEntries`) | For humans |
584
+
585
+ Ticking **Delegation** is an explicit consent with a side effect outside this plugin: it merges
586
+ `tool-subagent: { modelSelection: true }` into your profile patch (`~/.dsh/profiles/<profile>/cordis.patch.yml`),
587
+ preserving every other byte of it and backing it up first. The host reads that switch at start-up, so the
588
+ panel says **"saved — takes effect after you restart DSH"** rather than pretending it is live. If the capability
589
+ disappears at runtime, the plugin warns, withdraws `reflex_delegate`, and shows the reason — it never writes your
590
+ configuration back on its own.
591
+
592
+ Differences:
593
+
594
+ - The tool-name prefix is configurable (`toolPrefix`, default `reflex_`), so
595
+ `rv_` yields `rv_gate` and friends.
596
+ - On the DSH side argument validation comes from the Host's `defineTool`
597
+ (required/type/enum/nested) plus an undeclared top-level argument fence; on the
598
+ MCP side advertises `inputSchema` for clients but its dispatcher does not run
599
+ generic JSON Schema validation. Passing `claims` instead of `assertions` reaches
600
+ the empty-assertion gate and returns `passed: false`, `needsEscalation: true`,
601
+ `results: []`, not a JSON Schema error. Execution exceptions return a tool result
602
+ with `isError: true`. DSH additionally accepts optional per-assertion `criteria`;
603
+ MCP does not declare that nested field.
604
+ - Reading the ledger on the DSH side **never reaches the model**: `/reflex-ledger`
605
+ is rendered into text by the Host (the summary plus the five most recent
606
+ decisions) and takes no tool arguments; whether the ledger persists depends on
607
+ `ledgerPath` (unset keeps it in memory and never writes into the user's
608
+ project). The MCP side keeps the `reflex_status_ledger` tool with the arguments
609
+ in the table above.
610
+ - DSH-side capabilities can be **switched individually** with `tools.enabled`,
611
+ keyed by **suffix**; only the five current suffixes are accepted:
612
+
613
+ ```yaml
614
+ tools:
615
+ enabled:
616
+ route: true # switch on the candidate ranking, off by default
617
+ gate: false # switch off the gate, on by default; the rest stay available
618
+ ```
619
+
620
+ The suffix is independent of `toolPrefix`: after renaming the prefix to `rv_`,
621
+ `{ gate: false }` still closes `rv_gate`. A closed capability is **not
622
+ registered** into `ctx.tools`, so it is absent from the model-visible tool list
623
+ and from `reflexToolNames()` and its prefix derivation — there is no
624
+ "placeholder tool" and the model never sees a shell that fails on every call.
625
+ With `tools.enabled` omitted the per-suffix default applies
626
+ (`choice`/`score`/`screen`/`gate` on, `route` off); an unknown suffix (say
627
+ `teleport`, or one that has become a command such as
628
+ `prune`/`detect_stagnation`/`status_ledger`) or a non-boolean is rejected by the
629
+ validator at install time instead of being ignored. Writing `false` for all five
630
+ registers no tool at all (routing, reasoning effort and the intervention hooks
631
+ are unaffected).
632
+
633
+ ---
634
+
635
+ ## 10. Decision ledger and audit
636
+
637
+ Every judgement appends one JSONL record (`type` is one of `gate`, `prune`,
638
+ `stagnation`, `route`, `model-route`, `effort`, `choice`) carrying the backend,
639
+ latency, confidence, token-savings estimate and a truncated detail field:
640
+
641
+ ```bash
642
+ node dist/cli/index.js ledger # terminal summary
643
+ ```
644
+
645
+ - **`/reflex-ledger` (inside DSH)**: type the command in a session and the Host
646
+ renders **this activation's** ledger summary into text (total calls, breakdown
647
+ by type, average latency, tokens saved and the estimated cost, gate
648
+ pass/fail, stagnation alerts, and the five most recent decisions). It is a
649
+ command, not a tool: it **costs no model context and opens no model turn**, and
650
+ an empty ledger answers "no records yet" instead of a row of zeroes;
651
+ - `ledgerPath` unset ⇒ memory only, gone with the process (the default, so user
652
+ projects stay untouched);
653
+ - a configured path ⇒ append-only JSONL with replay, and the panel's ledger page
654
+ shows the sink path;
655
+ - clearing the ledger needs two consecutive clicks in the panel; only the second
656
+ one deletes the entries and the JSONL file.
657
+
658
+ ---
659
+
660
+ ## 11. Tests and release
661
+
662
+ ```bash
663
+ npm test # root package: ledger / score / MCP surface / packaging manifest
664
+ npm run test:plugin # DSH plugin: registration, strict validation, tool surface and /reflex-ledger, routing, effort, panel, guide
665
+ npm run test:mutation # negative control: injected faults must be caught by the suite (or the compiler)
666
+ npm run test:all # build:all + both suites
667
+ npm run release # all suites + pack and verify the tarballs in release/
668
+ npm run release:pack # pack and verify only (no tests; run build:all first)
669
+ ```
670
+
671
+ Release artifacts (`release/`):
672
+
673
+ | Artifact | Content |
674
+ | --- | --- |
675
+ | `harness-reflex-<version>.tgz` | Root package: `dist/`, `README.md`, `docs/`, `USER_GUIDE.md`, `experiments/` |
676
+ | `dsh-harness-reflex-<version>.tgz` | Plugin `dsh-harness-reflex` (npm pack naming): `dist/`, `client.js` (with this manual embedded), `cordis.patch.yml`, `locale/` |
677
+ | `SHA256SUMS` | SHA-256 checksums of the two tarballs |
678
+ | `release-report.json` | The per-check packaging audit (entries, dead links, dependency declarations, install smoke) |
679
+ | `RELEASE-<version>.md` | Release notes: install commands, verification checklist, contents |
680
+
681
+ The verifier `scripts/release-pack.mjs` extracts each tarball and asserts: every
682
+ required file is present, no test build or temporary directory ships, the
683
+ `exports`/`bin`/`dsh.bundle.patch` targets really exist, and every relative
684
+ import and source map resolves inside the package (zero dead links). It then
685
+ installs the root tarball into a scratch directory and exercises `import` plus
686
+ stdio MCP `tools/list` for real.
687
+
688
+ ---
689
+
690
+ ## 12. Troubleshooting
691
+
692
+ | Symptom | Cause and fix |
693
+ | --- | --- |
694
+ | No “Reflex runtime” entry in settings | The Host half is not loaded or registered no configuration namespace; re-check `dsh plugin --profile web add` and reload `dsh` |
695
+ | The panel is read-only | The DSH settings document is not writable; disabled writes are expected in that mode |
696
+ | A virtual model errors instead of dispatching | The pool is empty and `routing.fallback` is unset; add candidates or a fallback target |
697
+ | Text is not routed as expected | Check `routing.enabled`, the virtual model id spelling, and whether the agent actually requested that virtual model |
698
+ | Reasoning effort never changes | The policy is unset (no intervention), or the caller chose a concrete `reasoningEffort` explicitly on the request |
699
+ | System 1 decisions always fall back | `timeoutMs` too small, `baseUrl` unreachable, or `minConfidence` too high; check the latest decision and backend state on the Overview page. Note the timeout has **no single default**: unset means 10000 ms for `jev` and 8000 ms for `simple-jev` |
700
+ | The in-panel guide is stale | `USER_GUIDE.md` changed without a rebuild; run `npm run build:all` |
701
+ | A closed tool is still being called | The registry takes effect on the next load; reload the plugin and check that the key is the **suffix** (`gate`, not `reflex_gate`). `prune`/`detect_stagnation`/`status_ledger` are commands now and are refused by the validator |
702
+ | `reflex_route` is missing from the default tool list | Expected: `route` is off by default; switch it on in the Tools page (or set `tools: { enabled: { route: true } }`) |
703
+ | Looking for a `reflex_status_ledger` tool to read the ledger | The ledger is a command now: type `/reflex-ledger` (the stdio MCP side still has the tool of that name) |
704
+ | The model selector still offers `reflex` after adaptive effort was switched off | That level came from a load that injected it; make sure the configuration is in effect and reload the plugin to revoke the injection |
705
+ | Saving the configuration reports that only blank or reflex is supported | The configuration still writes a concrete level; remove it (or use `reflex`). To fix the depth, choose a concrete level in the model selector |
706
+ | Saving Interventions grew the configuration with defaults | Expected: that group is written back whole, so the mode and every budget are saved as shown |
707
+
708
+ ---
709
+
710
+ ## 13. Version and compatibility
711
+
712
+ - Version: `harness-reflex` and `dsh-harness-reflex` ship together at v0.1.0;
713
+ - Node: `>= 18` (root package `engines`); DSH Host dependencies `@deepseek-ai/*@0.2.1-alpha.4`;
714
+ - Host contracts are declared as `peerDependencies`, so the plugin never bundles
715
+ a second copy of Host modules;
716
+ - The eight-tool stdio MCP surface has been frozen since v0.1.0; a Host-side
717
+ change must not silently alter its payloads;
718
+ - The DSH plugin-side tool surface, since v0.1.0, is **five switchable
719
+ capabilities with four registered by default** (`route` is off by default) and
720
+ the ledger is the `/reflex-ledger` command — that side does not promise to
721
+ mirror the MCP side item by item.