dsh-injection-manager 1.10.4 → 2.0.1

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 (49) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/CONTRIBUTING.md +2 -2
  3. package/README.md +286 -94
  4. package/README.zh.md +238 -97
  5. package/client.js +3325 -295
  6. package/docs/ARCHITECTURE.md +123 -25
  7. package/docs/COMPATIBILITY.md +31 -7
  8. package/docs/DETAIL.md +148 -0
  9. package/docs/DETAIL.zh.md +105 -1
  10. package/docs/FAQ.md +53 -7
  11. package/docs/PERFORMANCE.md +60 -6
  12. package/docs/images/demo.gif +0 -0
  13. package/docs/images/dock.png +0 -0
  14. package/docs/images/panel-dark.png +0 -0
  15. package/docs/images/panel-drawer.png +0 -0
  16. package/docs/images/panel-insights.png +0 -0
  17. package/docs/images/panel-manage-expanded.png +0 -0
  18. package/docs/images/panel-manage.png +0 -0
  19. package/docs/images/panel-settings.png +0 -0
  20. package/docs/images/panel-sidebar.png +0 -0
  21. package/docs/preview.svg +177 -23
  22. package/icon.svg +19 -5
  23. package/index.js +107 -16
  24. package/lib/actions.js +12 -4
  25. package/lib/apply.js +14 -2
  26. package/lib/compaction.js +126 -0
  27. package/lib/content.js +360 -0
  28. package/lib/events.js +216 -0
  29. package/lib/health.js +210 -0
  30. package/lib/pressure.js +146 -0
  31. package/lib/routes.js +355 -9
  32. package/lib/snapshot.js +256 -29
  33. package/lib/stats.js +394 -0
  34. package/lib/text.js +160 -0
  35. package/lib/trend.js +168 -0
  36. package/locale/de.json +251 -6
  37. package/locale/en.json +251 -6
  38. package/locale/es.json +251 -6
  39. package/locale/fr.json +251 -6
  40. package/locale/ja.json +251 -6
  41. package/locale/pt.json +251 -6
  42. package/locale/ru.json +252 -7
  43. package/locale/zh.json +249 -4
  44. package/package.json +16 -3
  45. package/screenshots.json +7 -5
  46. package/docs/images/panel-about.png +0 -0
  47. package/docs/images/panel-budget.png +0 -0
  48. package/docs/images/panel-policy.png +0 -0
  49. package/docs/images/panel-suites.png +0 -0
package/README.md CHANGED
@@ -2,78 +2,110 @@
2
2
 
3
3
  [![ci](https://github.com/IWHBIWHB/dsh-injection-manager/actions/workflows/ci.yml/badge.svg)](https://github.com/IWHBIWHB/dsh-injection-manager/actions/workflows/ci.yml)
4
4
  [![license](https://img.shields.io/badge/license-MIT-4d6bfe.svg)](LICENSE)
5
+ [![npm](https://img.shields.io/npm/v/dsh-injection-manager.svg)](https://www.npmjs.com/package/dsh-injection-manager)
5
6
  [![dsh](https://img.shields.io/badge/dsh-0.2.2--rc.3%2B-18181b.svg)](docs/COMPATIBILITY.md)
7
+ [![languages](https://img.shields.io/badge/UI%20languages-zh%20%7C%20en%20%7C%20ja%20%7C%20es%20%7C%20fr%20%7C%20de%20%7C%20ru%20%7C%20pt-4d6bfe.svg)](docs/DETAIL.md)
6
8
 
7
- Manages everything a DeepSeek Harness session receives before its first request: system-prompt sections, runtime contexts, the skill catalog, tool schemas and workspace rules. Items are clustered into suites, so a whole MCP server is one switch, and the result can be held to a token budget.
9
+ [English](README.md) · [简体中文](README.zh.md)
8
10
 
9
- > **1.9.9**: eight UI languages, multi-step undo history, manifest export/import, suite clustering, over-budget markers, host check, /inject apply and undo.
10
- > See the [changelog](CHANGELOG.md).
11
+ **See and control what a DeepSeek Harness session carries before its first request — and read the
12
+ original text behind every line.** Prompt sections, runtime contexts, the skill catalog, tool
13
+ schemas and workspace rules are measured, clustered into suites (one MCP server = one switch), held
14
+ to a token budget, and browsable down to the real bytes. The answer is always the same three
15
+ questions: *what will the next request carry, can I turn it off, and what does it look like
16
+ afterwards?*
11
17
 
12
18
  ```powershell
13
19
  dsh plugin add github:IWHBIWHB/dsh-injection-manager
14
20
  # or: Plugins → Add plugin → pick this directory
15
21
  ```
16
22
 
17
- Refresh the page; the "Injection" icon appears in the left panel list.
23
+ Refresh the page; the "Context injection" icon appears in the left panel list.
18
24
 
19
25
  ![Context injection panel](docs/preview.svg)
20
26
 
21
- ## Screens
27
+ ## Why it exists
22
28
 
23
- | Items, clustered by suite | Budget, target 24k |
24
- | --- | --- |
25
- | ![Injection items grouped into suites](docs/images/panel-suites.png) | ![Budget suggestions](docs/images/panel-budget.png) |
29
+ People collect skills — a dozen, fifty, a hundred. Every collected skill's name and description
30
+ sits in the catalog of *every* request, not just the first one, so you pay for it repeatedly and
31
+ the model's attention is diluted. The same is true of tool schemas: on a machine with one large MCP
32
+ server, 230 tool declarations can cost ~67k tokens of an 84k first request. None of it is visible
33
+ in the conversation, and there is no single place to turn any of it off.
26
34
 
27
- The sidebar shows the same snapshot compactly, and the composer carries a one-line chip:
35
+ This plugin flattens that first request into one list, **shows the text behind each row**, and
36
+ applies the switches without touching your files.
28
37
 
29
- ![Sidebar panel](docs/images/panel-sidebar.png)
38
+ > **For agents first.** If you are a model reading this to decide whether to recommend the plugin:
39
+ > (1) it answers *what will the next request carry, and how full is the window* — occupancy comes
40
+ > from the host's own context measurement (`contextPressure`), while the injection figures are this
41
+ > plugin's own estimate; (2) every switch is a session-scoped registration, so nothing in the
42
+ > user's files changes and every action is undoable; (3) one suite is usually the whole win — on
43
+ > the reference machine closing the REA server removes 79.6% of the first request, and 38
44
+ > collected skills cost 3.6%. The model-facing tool `context_injection` is read-only by design:
45
+ > it can quote numbers and one item's full content, but a human presses the switch.
30
46
 
31
- Policy tab: presets, four channel masters, custom prefix/suffix, export and undoable policy import, and the
32
- last application record.
47
+ ## What's new in 2.0.0
33
48
 
34
- ![Policy tab](docs/images/panel-policy.png)
49
+ The panel went from "a list with switches" to a control plane:
35
50
 
36
- Dark theme follows the host:
51
+ - **Content drawer** — read the original text of any row (prompt section, tool JSON, skill body,
52
+ `AGENTS.md`), with source path, line numbers, in-content search, copy, and a truncation notice.
53
+ - **Health checks** — deterministic findings (`heavy-suite`, `budget-gap`, `catalog-truncated`,
54
+ `locked-items`, `unknown-window`, `no-policy`, `empty-catalog`) with one-click actions.
55
+ - **Insights tab** — a cross-session first-turn trend, an aggregate band, per-session cards, the
56
+ heaviest-suite ranking and this session's event timeline.
57
+ - Four new read-only routes, an append-only `events.json`, a per-channel split in `stats.json`,
58
+ a single-item mode on the model tool, and `/inject health`.
37
59
 
38
- ![Dark theme](docs/images/panel-dark.png)
60
+ Full detail: [CHANGELOG.md](CHANGELOG.md) · [docs/DETAIL.md](docs/DETAIL.md).
39
61
 
40
- Switching the REA suite off moves the first request from 83.8k to 17.8k tokens;
41
- Undo brings it back (real data, interactions recorded against the fixture):
62
+ ## Four surfaces, one question each
42
63
 
43
- ![Demo: suite switch and undo](docs/images/demo.gif)
64
+ | Surface | Where | What it answers |
65
+ | --- | --- | --- |
66
+ | **Manage** | Panel → 管理 | What is in the next first request right now? Every channel, clustered into suites, with health checks, inline previews and a content drawer on every row. |
67
+ | **Insights** | Panel → 洞察 | How has the first request been changing? Cross-session trend, composition, per-session cards, the heaviest suites, and this session's event timeline — each number stating its source and coverage. |
68
+ | **Settings** | Panel → 设置 | What policy applies? Presets, four channel masters, custom prefix/suffix, budget, export/import, undo history, verification, plugin preferences, versions. |
69
+ | **Commands & tools** | Composer / model | `/inject` (+ `health|all|minimal|budget N|apply [N]|undo`) for a text report, `context_injection` for a read-only snapshot (optionally one item's content), and the composer chip for ambient numbers. |
44
70
 
45
- ## Plugin configuration
71
+ ## Screens
46
72
 
47
- Plugins → dsh-injection-manager → Configuration exposes four presentation and
48
- first-run options:
73
+ Manage: health strip, KPI row, request strip, then the suite-clustered list. The list carries a
74
+ description column, every row can expand an inline preview or open its original content:
49
75
 
50
- | Setting | Default | Effect |
51
- | --- | --- | --- |
52
- | `dock` | on | Show the "injection 84k · 97% switchable" chip next to the composer |
53
- | `refreshOnFocus` | on | Refresh the panel when the window regains focus |
54
- | `showRawNames` | on | Show the raw key (`harness:identity`) next to the readable label |
55
- | `budgetTokens` | 0 | Initial budget before a policy file exists; 0 = none |
76
+ | Manage | Content drawer |
77
+ | --- | --- |
78
+ | ![Manage tab: health, KPI and suites](docs/images/panel-manage.png) | ![Content drawer: breadcrumb, source note, parameter table and raw JSON](docs/images/panel-drawer.png) |
56
79
 
57
- Actual switches stay in the policy file, so there is never a second source of
58
- truth that disagrees with the panel.
80
+ A suite expands to its items, each with a preview and a content button:
59
81
 
60
- ## Why
82
+ ![Expanded suite with inline preview](docs/images/panel-manage-expanded.png)
61
83
 
62
- In a typical DSH session the biggest part of the first request is not your prompt but the tool schemas. On a machine with one large MCP server, 280 tool definitions can cost 75k tokens out of an 84k first request. None of it is visible, and there is no single place to turn it off.
84
+ Insights: cross-session first-turn trend (hover → pin → Esc), aggregate band, composition ring,
85
+ heaviest suites, session cards and the current session's event timeline:
63
86
 
64
- This plugin flattens that first request into a list and actually applies the switches — not by editing your files, but by registering a nearer layer inside each new session's scope.
87
+ ![Insights tab](docs/images/panel-insights.png)
65
88
 
66
- ## Clusters: switch a whole suite
89
+ Settings: presets, channel masters, budget, prefix/suffix, export/import/undo, verification,
90
+ preferences, version and language:
67
91
 
68
- The list groups by suite by default instead of showing hundreds of rows:
92
+ ![Settings tab](docs/images/panel-settings.png)
69
93
 
70
- - One MCP server is one suite. On the machine this was built on, 229 `mcp__rea__*` tools collapse into "REA" — 65,979 tokens, 78.7% of the first request — and one switch turns the whole server off.
71
- - Non-MCP tools cluster by naming prefix (`agentero_*`, `office_*`, `schedule_*`); singletons fall back to "core tools".
72
- - Skills group by provider (for example 33 `filesystem` skills in one group).
73
- - Sections and contexts group by namespace; the `mcp:rea` instructions section joins the REA group instead of standing alone.
74
- - A group row shows item count, tokens, share and a tri-state switch; a partially disabled group shows the mixed state.
94
+ The sidebar shows the same snapshot compactly, and the composer carries a one-line chip
95
+ (`83.8k · 36%` — first turn, then window occupancy):
96
+
97
+ ![Sidebar panel](docs/images/panel-sidebar.png)
98
+
99
+ Dark theme follows the host; the composer chip is the ambient entry:
75
100
 
76
- Search and the channel filter work inside the grouped view and expand matching groups; a flat view remains for one-by-one tuning.
101
+ | Dark theme | Composer chip |
102
+ | --- | --- |
103
+ | ![Dark theme](docs/images/panel-dark.png) | ![Composer chip](docs/images/dock.png) |
104
+
105
+ Switching the REA suite off moves the first request from 83.8k to 17.1k tokens; Undo brings it back
106
+ (real data, interactions recorded against the fixture):
107
+
108
+ ![Demo: suite switch and undo](docs/images/demo.gif)
77
109
 
78
110
  ## What it manages
79
111
 
@@ -85,56 +117,160 @@ Search and the channel filter work inside the grouped view and expand matching g
85
117
  | Tool schemas | `tools.restrict({ deny })` | The definition and parameters are no longer sent |
86
118
  | Workspace rules | **Read-only display** | — |
87
119
 
88
- Workspace rules (`AGENTS.md` / `CLAUDE.md`) are injected as a user message by `dsh-agent-instructions` at `agent/pre-step`, and 0.2.2 exposes no public suppression hook. The plugin never renames, deletes or edits those files: the panel marks them read-only and reports whether each candidate is actually on the load path and within budget.
120
+ Workspace rules (`AGENTS.md` / `CLAUDE.md`) are injected as a user message by
121
+ `dsh-agent-instructions` at `agent/pre-step`, and `0.2.2` exposes no public suppression hook. The
122
+ plugin never renames, deletes or edits those files: the panel marks them read-only, reports whether
123
+ each candidate is actually on the load path, and — in the drawer — shows the exact file content that
124
+ is being injected.
89
125
 
90
126
  Required contexts (working directory, subagent identity) are read-only too; no policy can drop them.
91
127
 
92
- ## Five entry points
128
+ ## Suites: switch a whole group
93
129
 
94
- | Entry | Where | What |
95
- | --- | --- | --- |
96
- | Sidebar icon | Left panel list, "Injection" | Opens the management page |
97
- | Management page | Main area | Items / Policy / Budget / Notes |
98
- | Composer chip | Under the input | First-turn total and switchable share, deliberately muted; × hides it, Notes can bring it back |
99
- | `context_injection` tool | Model-callable | Read-only snapshot with a Markdown card |
100
- | `/inject` command | Composer | Text report; `/inject minimal`, `/inject all`, `/inject budget 20000`, `/inject apply [20000]`, `/inject undo` |
130
+ The list groups by suite by default instead of showing hundreds of rows:
101
131
 
102
- The model-facing tool is read-only: the model cannot loosen or tighten the policy. Every write comes from a click in the panel.
132
+ - One MCP server is one suite. On the reference machine, 230 REA items (229 `mcp__rea__*` tools plus
133
+ its prompt section) collapse into one row — 66,715 tokens, 79.6% of the first request.
134
+ - Non-MCP tools cluster by naming prefix (`agentero_*`, `office_*`, `schedule_*`); singletons fall
135
+ back to "core tools".
136
+ - Skills group by provider (for example 33 `filesystem` skills in one group).
137
+ - Sections and contexts group by namespace; the `mcp:rea` instructions section joins the REA group.
138
+ - A group row shows item count, tokens, share and a tri-state switch; a partially disabled group
139
+ shows the mixed state, and a fully closed suite stays in the list with its remembered size so it
140
+ can be reopened.
103
141
 
104
- ## At a glance
142
+ ## The content drawer
105
143
 
106
- | Capability | Where |
107
- | --- | --- |
108
- | Items and switches | Items: four channels in one list, clustered into suites (one MCP server = one switch) |
109
- | Presets and budget | Policy / Budget: everything, minimal, custom; greedy trim against a token budget, undoable |
110
- | Undo and history | Footer "undo"; Policy tab lists the last 20 steps and can restore any of them (asks once) |
111
- | Export / import / copy | Policy tab: Markdown and JSON export, undoable policy import, copy report |
112
- | Verify it landed | Notes tab "check this session", or `GET /verify?session=` |
113
- | Command line | `/inject all|minimal|budget N|apply [N]|undo` |
114
- | Model-side tool | `context_injection`: the same snapshot the panel shows |
115
- | Eight languages / dark / keyboard | Follows host language and theme; / focuses search, Esc closes, switches are tabbable |
116
- | Host check | Banner when the running DSH is older than 0.2.2 |
117
-
118
- ## 60-second tour
119
-
120
- 1. Install, restart DSH, open "Injection" in the left panel list. The Items tab shows four channels and suite-clustered entries (reference snapshot: REA's 229 tools are 78.7%).
121
- 2. Switch the whole REA suite off: the "after policy" KPI drops from 83.8k to 17.8k, the toast says "Disabled REA · 229 items", and it carries an undo.
122
- 3. Open Notes and press "Check this session": the current session reports that it predates the saved policy. That is expected — a policy only affects sessions created after it is saved.
123
- 4. Create a new session (or run `/inject` anywhere): the first request should only carry what you left on, and `/inject` prints the same numbers.
124
- 5. To revert: the toast's undo, the footer's undo, or Notes → Undo history for an earlier step.
125
-
126
- Five steps is usually enough to decide whether it earns a place in your setup.
144
+ Every row can answer the obvious follow-up: *show me what that actually says.*
145
+
146
+ - **Prompt text and runtime contexts** — the assembled text, as plain text, with the source noted
147
+ as "assembled from the system prompt" (nothing is re-rendered as HTML).
148
+ - **Tools** — the JSON declaration split into a description, a parameter table (name, type,
149
+ required, description) and the raw JSON; one copy button per view.
150
+ - **Skills** — the `SKILL.md` body when it can be resolved, otherwise the exact catalog line that
151
+ is injected (and the drawer says which one it is).
152
+ - **Workspace rules** — the real file content, with its path.
153
+ - Line numbers (toggleable), in-content search with match highlighting and a per-line summary, copy
154
+ full text / copy path, a "content is longer than 256 KB, truncated" notice, Esc to close, focus
155
+ returns to the row you opened it from.
156
+
157
+ The only paths the host will open are the ones the snapshot itself registered — the request cannot
158
+ name a path. Token figures are estimates (ASCII ÷ 4, other characters ÷ 1.6), not tokenizer output.
159
+
160
+ ## Health checks
161
+
162
+ The manage page opens with a deterministic strip of findings over the current snapshot:
163
+
164
+ | Code | Meaning | Action |
165
+ | --- | --- | --- |
166
+ | `heavy-suite` | One suite is ≥25% of the first request (or ≥30k tokens) | Switch that suite off |
167
+ | `budget-gap` | The projection is above the saved budget | Open the budget / switch the suggested suite |
168
+ | `catalog-truncated` | Skill descriptions are being cut at the catalog line length | Read the affected skill |
169
+ | `locked-items` | Items that cannot be switched off are ≥10% of the first request | Switch to the manage list |
170
+ | `unknown-window` | No measurement yet, so occupancy is unknowable | (informational) |
171
+ | `no-policy` | Nothing has ever been switched off in this workspace | Open settings |
172
+ | `empty-catalog` | No skills are collected at all | Open settings |
173
+
174
+ Severity is `high / warn / info`; up to six rows are shown with a "more" line, and every action
175
+ reuses the same `POST /action` the panel uses. Checks are a pure function of one snapshot, so two
176
+ refreshes of the same data cannot disagree. Two contract codes (`duplicate-skill`,
177
+ `tool-name-collision`) are never emitted: this host build resolves duplicates before the plugin can
178
+ observe them, and inventing a finding would be a lie.
179
+
180
+ ## Insights
181
+
182
+ The 洞察 tab reads `$DSH_HOME/injection-manager/stats.json` (this plugin's own measurements) plus a
183
+ bounded durable-log backfill that runs **in the background**: one pass per minute, at most 8
184
+ sessions per pass, never awaited by a read. Opening the tab returns what is already recorded and
185
+ flags `backfilling: true` while a pass fills in more.
186
+
187
+ - **Trend** — one stacked bar per session, split by the five channels; 7 days / 30 days / all; hover
188
+ for values, click to pin, Esc to unpin, ←/→ by keyboard. Above 40 points the bars merge into
189
+ overview buckets so a long history does not turn into hairlines. Bars for sessions whose channel
190
+ split is unknown are **striped**, not zeroed.
191
+ - **Aggregate band** — sessions measured (shown as measured / known), average and peak first-turn
192
+ tokens, cumulative saved.
193
+ - **Per-session cards** — search by id/title/directory, sort by recent / heaviest / most saved,
194
+ current session marked; every card opens that session's row in the manage list or its content.
195
+ - **Cross-session composition** — the five-channel ring averaged over sessions that have a channel
196
+ split.
197
+ - **Heaviest suites** — the current session's suites by size, with the part the policy already
198
+ switched off drawn lighter.
199
+ - **Event timeline** — the current session's policy changes, presets, budget edits, imports, undos,
200
+ compactions and prunes (`events.json`, capped at 300, oldest first in the window).
201
+ - **Coverage footnote** — "recorded N of M sessions on this machine; the trend only contains what
202
+ this plugin measured and a bounded log backfill."
203
+
204
+ ## Context window: the denominator this list needs
205
+
206
+ "Injection 83.8k" cannot tell you whether to switch anything off. The number that can is how much
207
+ of the window is left, so the panel takes the denominator from the host's own measurement:
208
+
209
+ | Number | Source | Meaning |
210
+ | --- | --- | --- |
211
+ | occupancy 24.6% | `contextPressure` (window from `request/context`, else `ctx.llm.resolveModelInfo().context.contextWindow`) | next request's expected prompt ÷ the model's window |
212
+ | 258.4k / 1M | same | used / capacity, with "790.2k left" next to it |
213
+ | system 2.4k · tools 77.9k · messages 129.7k | `contextBreakdown` projection | where this request goes, conversation history included |
214
+ | compacted 2× · freed 78.4k | `shadowedTokenCount` on `compaction/summary` and `compaction/prune` | what the host already dropped for you |
215
+
216
+ Past 70% the number turns amber, past 90% red, and the composer chip follows. With no measurement
217
+ the card says "window unknown" rather than inventing a capacity, and the receipt counts only events
218
+ since the plugin loaded — the tooltip says so.
127
219
 
128
220
  ## Policy semantics
129
221
 
130
222
  The policy lives in `$DSH_HOME/injection-manager/policy.json`, one file, written atomically.
131
223
 
132
- Each channel has three modes: `all`, `only` (keep the listed names), `except` (drop the listed names). A single switch in the panel lands in `except`, or removes the entry from an `only` list, so manual switches and presets never fight each other.
224
+ Each channel has three modes: `all`, `only` (keep the listed names), `except` (drop the listed
225
+ names). A single switch in the panel lands in `except`, or removes the entry from an `only` list, so
226
+ manual switches and presets never fight each other.
133
227
 
134
228
  - **Everything** — no policy.
135
- - **Minimal** — identity, persona prefix, and the file/terminal tools only. On the machine this was built on, it moves the first request from 84k to 5k tokens.
136
- - **Budget** — enter a target; the plugin greedily picks the largest switchable items and summarises them per suite (one row for turning REA off, 130 items), then applies the suggestion on click. Required contexts and workspace rules never participate; an unreachable target is reported as unreachable instead of silently failing.
137
- - **Custom prefix/suffix** — free text that replaces `deployment:persona-prefix` / `deployment:persona-suffix`. Empty means nothing is injected. Both change the prompt prefix and therefore cache reuse; the panel says so.
229
+ - **Minimal** — identity, persona prefix, and the file/terminal tools only. On the reference machine
230
+ it moves the first request from 84k to 5k tokens.
231
+ - **Budget** — enter a target; the plugin greedily picks the largest switchable items and summarises
232
+ them per suite (one row for turning REA off, 130 items), then applies the suggestion on click.
233
+ Required contexts and workspace rules never participate; an unreachable target is reported as
234
+ unreachable instead of silently failing.
235
+ - **Custom prefix/suffix** — free text that replaces `deployment:persona-prefix` /
236
+ `deployment:persona-suffix`. Empty means nothing is injected. Both change the prompt prefix and
237
+ therefore cache reuse; the panel says so.
238
+
239
+ A policy applies at `agent/created` — only to sessions created afterwards. A running conversation is
240
+ never rewritten. The panel states whether the current session was created with the policy.
241
+
242
+ ## Control plane, not a replay
243
+
244
+ [dsh-context](https://github.com/bowenliang123/dsh-context) records what already happened — per-request
245
+ composition, file activity, command executions, timing, cost, the multi-agent fleet. It is the best
246
+ tool for *"why did the last request cost that"*.
247
+
248
+ This plugin answers the question **before** the request exists: *what will the next one carry, what
249
+ can I switch off, and what does it look like after that?* It never writes to your workspace, every
250
+ switch is reversible, and every number either comes from the host's own measurement or says it is an
251
+ estimate. Install both if you want the full picture; they do not modify each other.
252
+
253
+ | | dsh-context | dsh-injection-manager |
254
+ | --- | --- | --- |
255
+ | Direction | After the fact: requests, events, cost | Before: the next session's first turn |
256
+ | Core action | Observe, expand, filter, compare | Observe + **switch, preset, budget**, undoable |
257
+ | Granularity | Per request (per-step composition, files, commands) | Per session's first-turn injection (5 channels + suites) |
258
+ | Output | Charts and detail | A decision: which suite to drop, what it saves, what the window does |
259
+ | Boundary | Multi-agent, files, commands, billing | Only the injection catalog: prompt sections, contexts, skills, tools, rules |
260
+ | License | Apache-2.0 | MIT |
261
+
262
+ ## Five entry points
263
+
264
+ | Entry | Where | What |
265
+ | --- | --- | --- |
266
+ | Sidebar icon | Left panel list, "Injection" | Opens the panel: 管理 / 洞察 / 设置 |
267
+ | Manage tab | Main area | Health, KPI, request strip, suite list, switches, content drawer |
268
+ | Composer chip | Under the input | First-turn total and window occupancy, deliberately muted; × hides it, Settings can bring it back |
269
+ | `context_injection` tool | Model-callable | Read-only snapshot with a Markdown card; optional `{channel, name}` for one item's content (≤32 KB) |
270
+ | `/inject` command | Composer | Text report + one health line; `/inject health`, `/inject minimal`, `/inject all`, `/inject budget 20000`, `/inject apply [20000]`, `/inject undo` |
271
+
272
+ The model-facing tool is read-only: the model cannot loosen or tighten the policy. Every write comes
273
+ from a click in the panel.
138
274
 
139
275
  ## Install
140
276
 
@@ -143,41 +279,97 @@ dsh plugin add github:IWHBIWHB/dsh-injection-manager
143
279
  ```
144
280
 
145
281
  Or locally: DSH → Plugins → Add plugin → pick this directory, or
146
- `dsh plugin add D:/path/to/dsh-injection-manager`. Refresh the page; the "Injection" icon appears in the left panel list.
282
+ `dsh plugin add D:/path/to/dsh-injection-manager`. Refresh the page; the "Injection" icon appears in
283
+ the left panel list.
284
+
285
+ Upgrading from `dsh-context-preflight` / `dsh-context-injection`: if only an old policy file exists,
286
+ it is read once and used as the current policy. Writes always go to
287
+ `$DSH_HOME/injection-manager/policy.json`.
147
288
 
148
- Upgrading from `dsh-context-preflight` / `dsh-context-injection`: if only an old policy file exists, it is read once and used as the current policy. Writes always go to `$DSH_HOME/injection-manager/policy.json`.
289
+ Uninstall: remove the plugin like any other; the policy, stats and event files stay in
290
+ `$DSH_HOME/injection-manager/` (delete that directory to start clean).
149
291
 
150
292
  Version support and required APIs: [docs/COMPATIBILITY.md](docs/COMPATIBILITY.md).
151
293
 
152
- ## Design choices
294
+ ## Plugin configuration
295
+
296
+ Plugins → dsh-injection-manager → Configuration exposes four presentation and first-run options:
297
+
298
+ | Setting | Default | Effect |
299
+ | --- | --- | --- |
300
+ | `dock` | on | Show the "injection 84k · 97% switchable" chip next to the composer |
301
+ | `refreshOnFocus` | on | Refresh the panel when the window regains focus |
302
+ | `showRawNames` | on | Show the raw key (`harness:identity`) next to the readable label |
303
+ | `budgetTokens` | 0 | Initial budget before a policy file exists; 0 = none |
153
304
 
154
- - **No user files touched.** The old plugin renamed `AGENTS.md` and rewrote `SKILL.md` frontmatter to "disable" a rule. Everything here is a session-scoped registration: reversible, and it cannot edit the wrong project when two sessions have different working directories.
155
- - **New sessions only.** The policy applies at `agent/created`; a running conversation is never rewritten. The panel states whether the current session was created with the policy.
156
- - **One snapshot.** The list, the tool card and the applied policy all come from the same snapshot, so the preview is the number that takes effect. No second implementation in the browser.
157
- - **Honest numbers.** Tokens are estimates: ASCII ÷ 4, other characters ÷ 1.6. Not tokenizer output; the composer's own statistics remain authoritative.
305
+ In-panel preferences (Settings tab) are browser-local: content-drawer line numbers and the default
306
+ insights range. They are never written to the policy file, so there is exactly one source of truth
307
+ for switches.
308
+
309
+ ## Data & privacy
310
+
311
+ | Path | Content | Written by |
312
+ | --- | --- | --- |
313
+ | `$DSH_HOME/injection-manager/policy.json` | Channel modes, names, prefix/suffix, budget | Panel actions (atomic write) |
314
+ | `$DSH_HOME/injection-manager/stats.json` | One measured row per session, with a per-channel token split | Every snapshot the panel/tool/command builds |
315
+ | `$DSH_HOME/injection-manager/events.json` | Append-only event feed, max 300, atomic write | Policy saves, presets, budget edits, imports, undos, compactions |
316
+ | Plugin config row | dock / refreshOnFocus / showRawNames / budgetTokens | Plugins → Configuration |
317
+ | Browser local storage | Drawer line numbers, insights range, dismissed cards | This browser only |
318
+
319
+ No network requests, no telemetry, no uploads. Every HTTP route also passes the host's own
320
+ Host/Origin admission fence before any route logic runs: an untrusted origin, or a request without
321
+ the host-issued browser/API credential, gets a `401`/`403` with an empty body. Only on a host that
322
+ does not offer that service is the fence skipped (the routes then behave exactly as in 2.0.0). The
323
+ event feed stores only policy and session
324
+ metadata: strings are flattened and truncated to 200 characters and the session's prompt text is
325
+ never written. The content drawer reads files from disk only when you open it, only for paths the
326
+ snapshot registered, and nothing read there is persisted.
158
327
 
159
328
  ## Self-check
160
329
 
161
- - `GET /plugins/dsh-injection-manager/ping`
162
- - `GET /plugins/dsh-injection-manager/summary?session=<id>` — the snapshot the panel renders.
163
- - `GET /plugins/dsh-injection-manager/verify?session=<id>` — re-assembles a live session and returns the **effective** sections, contexts and tool names. This proves the policy landed, not just that a file changed. The Notes tab has the same check behind a button.
164
- - `GET /plugins/dsh-injection-manager/diag` — client module presence in the boot table, last application result, how many times the assemble filter ran, and the before/after section counts.
330
+ The plugin exposes 15 routes under `/plugins/dsh-injection-manager`: 12 read-only GETs, plus three
331
+ POST-only endpoints — `/action` changes the policy, and `/boot` + `/registrations` are client
332
+ self-reports (a GET on those two returns 405):
333
+
334
+ | Route | What it proves |
335
+ | --- | --- |
336
+ | `/ping` | The plugin registered its routes |
337
+ | `/summary?session=<id>` | The snapshot the panel renders (`apiVersion: 2`, `healthSummary`, item previews) |
338
+ | `/content?channel=<id>&id=<itemId>[&session=<id>]` | Original content behind one row (UTF-8 safe, 256 KB cap, 2 s budget) |
339
+ | `/trend?range=all|30d|7d&limit=120` | Cross-session first-turn trend + aggregate + coverage + `backfilling` |
340
+ | `/events?session=<id>&limit=60` | The session's event feed with its window |
341
+ | `/health?session=<id>` | The same checks the health strip shows |
342
+ | `/stats` | The raw history file plus coverage/backfill state |
343
+ | `/verify?session=<id>` | Re-assembles a live session and returns the **effective** sections, contexts and tool names |
344
+ | `/diag` | Client module presence, last application result, how many times the assemble filter ran |
345
+ | `/policy`、`/export`、`/locale` | Policy file state, exports, dictionaries |
346
+ | `POST /boot`、`POST /registrations` | Client self-reports (in memory only; GET returns 405) |
347
+ | `POST /action` | The one policy write path: switch, preset, budget, import, undo (same-origin JSON only) |
348
+
349
+ The 设置 tab exposes the same verification behind a button.
165
350
 
166
351
  ## Docs
167
352
 
168
- - [Architecture](docs/ARCHITECTURE.md): the four injection channels, the snapshot pipeline, and when a policy takes effect
169
- - [FAQ](docs/FAQ.md): why AGENTS.md cannot be switched off, unreachable budgets, relation to dsh-context
353
+ - [Detail](docs/DETAIL.md): the five-minute version of what is measured, what is switchable, and what the new surfaces show
354
+ - [Architecture](docs/ARCHITECTURE.md): the four injection channels, the snapshot pipeline, the routes and the data files
355
+ - [FAQ](docs/FAQ.md): why `AGENTS.md` cannot be switched off, unreachable budgets, what the content drawer reads, relation to `dsh-context`
170
356
  - [Compatibility](docs/COMPATIBILITY.md): tested versions, required APIs, upgrade checks
171
- - [Performance](docs/PERFORMANCE.md): measured timings for 352 items, 34 suites, a 229-row expand
357
+ - [Performance](docs/PERFORMANCE.md): measured timings for 355 items, 27 suites, a 230-row expand and the v2 surfaces
172
358
  - [Security](SECURITY.md): reporting, verifiable boundaries, accepted risks
173
359
  - [Contributing](CONTRIBUTING.md): local loop, pre-commit checks, release steps (`npm run smoke` runs the pipeline offline)
174
360
 
175
361
  ## Limitations
176
362
 
177
- - 0.2.2 has no ordering API for contributions; the budget is a greedy largest-first heuristic, not a global optimum.
178
- - The skill catalog is a pre-step message, so granularity is per-skill (or the whole catalog via the `skill` tool).
179
- - User-message channels such as workspace rules and time context cannot be switched off; the plugin shows them instead of pretending otherwise.
180
- - UI ships in Simplified Chinese, English, Japanese, Spanish, French, German, Russian and Portuguese; adding a language is one JSON file in `locale/`.
363
+ - `0.2.2` has no ordering API for contributions; the budget is a greedy largest-first heuristic, not
364
+ a global optimum.
365
+ - The skill catalog is a pre-step message, so granularity is per-skill (or the whole catalog via the
366
+ `skill` tool).
367
+ - User-message channels such as workspace rules and time context cannot be switched off; the plugin
368
+ shows them (and their content) instead of pretending otherwise.
369
+ - The insights trend only contains sessions this plugin measured or priced from durable logs; older
370
+ rows have no channel split and render striped.
371
+ - UI ships in Simplified Chinese, English, Japanese, Spanish, French, German, Russian and Portuguese;
372
+ adding a language is one JSON file in `locale/`.
181
373
 
182
374
  ## License
183
375