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/CHANGELOG.md CHANGED
@@ -1,5 +1,295 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.0.1 — 2026-11-17
4
+
5
+ ### Security
6
+
7
+ - **Every HTTP route now passes the host's own admission fence first.** All 15 registered
8
+ route handlers are wrapped at registration time (`makeFencedHandler`): a request asks
9
+ `ctx.connection.requestRejection(req)` before any route logic runs, so a Host/Origin the
10
+ host does not trust — or a request without the host-issued browser/API credential — is
11
+ answered with the host's `403`/`401` and an empty body. The rejection happens before any
12
+ JSON, file or policy data is read, so nothing leaks; the response still carries the usual
13
+ `nosniff` / `no-referrer` / frame-deny / `no-store` headers.
14
+ - **Compatible degradation, not a new hard dependency.** `connection` is not added to the
15
+ plugin's `inject` list: on a host without the service (older DSH, or before it is available
16
+ during boot), without a `requestRejection` method, or when the call throws, the fence is
17
+ skipped and the routes behave exactly as in 2.0.0. A security fence must never turn the
18
+ panel into a blank page.
19
+ - Write actions keep their own same-origin check on top: `POST /action` requires a JSON
20
+ content type, a non-cross-site `sec-fetch-site`, and a matching `Origin` when one is sent.
21
+ - New tests cover the fence paths: service missing → pass-through, `401`/`403` → handler not
22
+ executed and response ended, `undefined` → pass-through, thrown error → pass-through; the
23
+ registration path is covered route-by-route (15/15 fenced) and the old-host path still answers.
24
+ 11 new tests, `node --test` 207/207 green; `npm run smoke` green.
25
+
26
+ ## 2.0.0 — 2026-11-16
27
+
28
+ The control-plane release: the panel now shows what the next request carries, what can be
29
+ switched off, **and what each item actually says** — with a cross-session trend and a health
30
+ strip that turn the numbers into decisions. Everything new is read-only; switching stays a
31
+ human click.
32
+
33
+ ### Breaking / contract
34
+
35
+ - **HTTP contract is v2.** `GET /summary` now returns `apiVersion: 2`, `healthSummary`
36
+ (`{high, warn, info}`) and an optional `preview` (≤180 chars) on each item. New fields are
37
+ additive, but the panel feature-detects the version: a v2 panel against a v1 server shows a
38
+ dismissible gate card ("this surface needs a v2 host") instead of silently hiding tabs. A v1
39
+ panel against a v2 server keeps working.
40
+ - **Four new read-only GET routes:** `/content`, `/trend`, `/events`, `/health` (same prefix as
41
+ the existing routes). `/content` is the only route that opens a file, and only paths already
42
+ registered by the snapshot collection.
43
+ - **New durable file `events.json`** (`$DSH_HOME/injection-manager/`, version 1, cap 300,
44
+ atomic tmp+rename, dedupe): an append-only feed of policy changes, presets, budget edits,
45
+ imports, undos, compactions and prunes. `stats.json` rows recorded from 2.0.0 on also carry a
46
+ per-channel token split (`channels`); old rows keep `channels: null` on purpose.
47
+ - **Model tool grew a single-item mode.** `context_injection` accepts optional
48
+ `{channel, name}` and then returns just that item's original content (≤32 KB). Calling it
49
+ without arguments still returns the whole snapshot. `/inject health` was added, and the bare
50
+ `/inject` report now ends with one health line.
51
+
52
+ ### Added
53
+
54
+ - **Content drawer.** Press "content" on any row and read the original bytes behind it: prompt
55
+ section text, runtime-context snapshots, a tool's JSON declaration (description / parameter
56
+ table / raw JSON), a skill's `SKILL.md` body or its catalog line, an instruction file. The
57
+ drawer shows the source path, a byte/char/token meta line, line numbers (toggleable), in-content
58
+ search with match highlighting and a per-line match summary, full-text copy and path copy, a
59
+ truncation notice when the 256 KB cap hits, Esc-to-close and focus restoration. Everything is
60
+ rendered as plain text — no `dangerouslySetInnerHTML` anywhere.
61
+ - **Health strip on the manage page.** Deterministic, read-only checks over one snapshot:
62
+ `heavy-suite`, `budget-gap`, `catalog-truncated`, `locked-items`, `unknown-window`, `no-policy`,
63
+ `empty-catalog`. Severity rows with the saved-token delta, up to six visible plus a "more"
64
+ line, and one-click actions that reuse the existing `POST /action` (`switch-group`,
65
+ `set-budget`, `open-content`, `open-tab`). The strip only fetches while the tab is visible.
66
+ - **Insights tab.** Cross-session first-turn trend as stacked channel bars (7 days / 30 days /
67
+ all; hover for values, click to pin, Esc to unpin, ←/→ by keyboard; more than 40 points merge
68
+ into overview buckets; rows whose channel split is unknown are striped), an aggregate band
69
+ (sessions measured, average, peak, cumulative saved), per-session cards (search, sort by
70
+ recent / heaviest / most saved), a cross-session composition ring, the heaviest-suite ranking
71
+ for the current session, the current session's event timeline (12 event kinds, capacity note)
72
+ and a coverage footnote that states what the trend does and does not contain.
73
+ - **Inline previews.** Rows expand a `preview` paragraph without leaving the list; the drawer is
74
+ only for the full content.
75
+ - **Preferences** in the settings tab: content-drawer line numbers and the default insights
76
+ range. They live in this browser and are never written to `policy.json`.
77
+ - **Version card** in the settings tab: plugin version, host version with its tested baseline,
78
+ HTTP api version and the UI language; links to the full DETAIL page in the current language.
79
+ - **Eight-language coverage** for all new strings: +182 keys per locale (zh/en/ja/es/fr/de/ru/pt),
80
+ 372 client keys per language.
81
+
82
+ ### Changed
83
+
84
+ - The middle tab is now **洞察 (Insights)** instead of a plain history list. It still reads
85
+ `stats.json`, but the numbers are aggregated for comparisons and each point states its source
86
+ (measured vs priced from durable log) and coverage.
87
+ - The manage page leads with health → KPI → request strip; the table keeps suite clustering and
88
+ per-switch tri-state, and every row can now reveal its content.
89
+ - `stats.json` history is described the same way everywhere: measured rows plus a durable-log
90
+ backfill that runs in the background (one pass per 60 s, ≤8 sessions), never a replay of every
91
+ session and never a wait on a read.
92
+ - `screenshots.json` lists the v2 screens. README/README.zh are rewritten around the four
93
+ surfaces and the control-plane positioning.
94
+
95
+ ### Fixed
96
+
97
+ - Content reads cannot hang or flood: 2 s per request, 256 KB response cap (32 KB for the model
98
+ tool), UTF-8-safe truncation that never splits a code point, and a whitelist restricted to
99
+ paths the snapshot itself registered.
100
+ - The event feed is crash-safe and idempotent: a suppressed write can never turn a saved policy
101
+ into an error, duplicate keys keep replayed host events from becoming two rows, and params are
102
+ flattened and truncated so prompt text cannot leak into the file.
103
+ - Health checks are reproducible for one snapshot (the only clock value is
104
+ `snapshot.generatedAt`); the two codes this host build cannot observe (`duplicate-skill`,
105
+ `tool-name-collision`) are never emitted rather than invented.
106
+ - **Opening the insights tab no longer waits on the durable-log backfill.** The backfill became a
107
+ background single-flight pass (one per 60 s, ≤8 sessions, 6 s budget) and the read returns the
108
+ already-recorded rows immediately with `backfilling: true`; on a 671-session corpus the old
109
+ synchronous pass made `/trend` take 7.1 s per poll and `/stats` 2.1 s, both now in the
110
+ millisecond range.
111
+ - `trend.points[].scope` is a free string (commonly `startup|clear|route.session|backfill`,
112
+ unknown values pass through, capped at 64 chars) and `policy` accepts `unknown` — the contract
113
+ was revised to fit the honest v1 data instead of rewriting history.
114
+ - An older server now shows a dismissible gate card instead of a tab that silently disappears.
115
+
116
+ ### Migration
117
+
118
+ - Nothing to do for existing installs: `policy.json` keeps its v1 shape, `stats.json` stays
119
+ readable (older rows show an unknown channel split), and `events.json` is created on the first
120
+ event.
121
+ - If you script against `/summary`, accept the new fields — no legacy key was removed. Anything
122
+ that pinned the old tab labels should use the new `管理 / 洞察 / 设置` set.
123
+
124
+ ## 1.14.0 — 2026-11-17
125
+
126
+ - **The panel is three tabs, and the summary moved out of the working list.**
127
+ 管理 is now only what you act on (suite donut, bars, toolbar, table); the KPI
128
+ row, the request strip and the skills card live in 统计 under 当前会话, followed
129
+ by 历史记录. Four tabs (清单/策略/预算/说明) became 管理/统计/设置, with the old
130
+ ones folded into 设置 and stale stored tab ids mapped, so nothing opens blank.
131
+ - **统计 measures real history.** It lists every conversation the host knows about
132
+ (`sessionQuery.listSessions()`, a header-only read) and fills numbers in for the
133
+ ones it can: measured sessions come from this plugin's own snapshots, and older
134
+ ones are priced from their durable log — `request/header` tool declarations plus
135
+ the `system/message` prompt — a bounded 8 sessions per open, cached in
136
+ `$DSH_HOME/injection-manager/stats.json`. The footer states the coverage
137
+ honestly ("N of 664 conversations measured").
138
+ - Skill tokens are shown as "—" for log-derived rows: the skill catalog arrives as a
139
+ pre-step user message whose `source` is null in the durable record, so claiming a
140
+ number there would be a guess.
141
+ - Screenshots and the demo GIF regenerated for the new layout; `screenshots.json`
142
+ now lists panel-stats instead of the retired budget/policy images.
143
+ - 2 new sections and 20 new keys across 8 locales.
144
+
145
+ ## 1.13.1 — 2026-11-17
146
+
147
+ - **The list toolbar got un-crowded.** Nine controls in one row became: scope,
148
+ search, group/flat, a channel `<select>` and three small view toggles. The
149
+ channel chips only appear as a removable "筛选:技能目录 ×" row when a filter is
150
+ actually on, so the idle toolbar is quiet and the active state is still visible.
151
+ - The select and the view toggles collapse at narrow widths instead of wrapping
152
+ into a second line that shoves the table down.
153
+ - 2 new locale keys × 8 languages.
154
+
155
+ ## 1.13.0 — 2026-11-17
156
+
157
+ - **Skills vs MCP tools, side by side.** The skills card now shows all four kinds of
158
+ line item (skills / tool schemas / prompt text / workspace rules) with their
159
+ shares, and one sentence that answers the obvious follow-up: tool schemas are not
160
+ skills — each MCP tool is its own JSON declaration, and on the reference machine
161
+ they outweigh the whole skill catalog by 75.9k to 3.0k.
162
+ - **A closed suite no longer disappears.** The policy removes its rows from the
163
+ assembled prompt, so the list used to have nothing left to show — the suite
164
+ vanished and its switch with it. Closed suites now stay in the list with an
165
+ 已关闭 badge and their remembered size; their switch restores the exact names the
166
+ policy excludes, per channel. A closed row reads "—" instead of a share above
167
+ 100%.
168
+ - **Two explicit scopes.** 默认策略 = what a session created right now would receive
169
+ (the policy view, and the default); 本会话 = what the conversation on screen is
170
+ actually sending, measured by the host. A policy never rewrites a live session, so
171
+ both are true at once — the reader now picks which question they are asking
172
+ instead of guessing from a single mixed table.
173
+ - 7 new locale keys × 8 languages.
174
+
175
+ ## 1.12.0 — 2026-11-16
176
+
177
+ - **The plugin now leads with why people install it: collected skills.** A
178
+ dedicated card sits under the KPI row — how many skills are in the catalog, their
179
+ total tokens and share of the first request, the average per skill, the providers
180
+ they come from and the single heaviest entry. "去管理" filters the list straight
181
+ to that channel, so the answer to "why is my prompt so big" is one click away.
182
+ - The model-facing card gained the same line first ("技能目录:38 个技能共 3.0k
183
+ token,占首轮 3.6%…"), because a user who collected a hundred skills is exactly
184
+ the user whose agent should be able to say that out loud.
185
+ - README now opens with the collection problem before any feature list.
186
+ - New snapshot field `skillsState.{catalogTokens,catalogShare,averageTokens,providers,heaviest,topProviders}`.
187
+ - 7 locale keys × 8 languages; the narrow sidebar stacks the card's header.
188
+
189
+ ## 1.11.1 — 2026-11-16
190
+
191
+ - **The model-facing tool now says what to do with the numbers.** `context_injection`
192
+ gained a "能做什么" block: the biggest switchable suite and what it saves, whether
193
+ this session predates the policy, what compaction already removed (irreversible),
194
+ and the fact that the tool cannot flip switches itself. A model that reads only
195
+ that block can give its user the one action that matters.
196
+ - **README opens with the three facts an agent needs** (what it measures, why it is
197
+ safe, that one suite is usually the whole win) before any screenshot.
198
+ - `docs/DETAIL.md` and `docs/DETAIL.zh.md` are real pages instead of a stray image:
199
+ the two-numbers model, what each channel physically is, when a policy applies,
200
+ and what happens when a piece is missing.
201
+ - npm description rewritten without the mojibake and with `context-window`,
202
+ `compaction`, `occupancy` keywords; awesome-listing draft updated to match.
203
+ - 3 new tests for the advice block — 69 total.
204
+
205
+ ## 1.11.0 — 2026-11-16
206
+
207
+ - **The denominator exists.** Occupancy is now measured, not guessed: the panel
208
+ reads the host's own `contextPressure` projection (the next request's expected
209
+ prompt) and divides it by the model's window, so the strip can say "53% of the
210
+ window, 118k left" instead of leaving the user to compare two absolute numbers.
211
+ The window comes from `request/context`; before the first request it falls back
212
+ to `ctx.llm.resolveModelInfo().context.contextWindow` (cached per route). When
213
+ neither exists the card prints 窗口未知 — it never invents a capacity.
214
+ - **Where the window goes.** A new card stacks the next request as system / tools
215
+ / messages against the window (from the `contextBreakdown` projection), colours
216
+ the bar amber at 70% and red at 90%, and labels the estimate as an estimate.
217
+ - **Compaction receipts.** A `session/event` listener folds `compaction/summary`
218
+ and `compaction/prune` into "压缩 2 次 · 释放 78.4k" — the log already carries
219
+ `shadowedTokenCount`, so this is a fact rather than an inference. Receipts cover
220
+ events since the plugin loaded, and the tooltip says so.
221
+ - KPI cards are four equal columns at an 8px radius; the sparkline spans the card
222
+ and carries an `aria-label` with its min/max; every chart is `role="img"`.
223
+ - **Fixed: every share now uses one denominator.** Closing a suite left the
224
+ largest-suite bars and the table's 占比 column quoting shares of the all-on
225
+ total, so a closed REA row read "390.4%" next to a 17.1k first turn. The bars
226
+ keep their all-on width (a closed giant still looks like a giant) but fill only
227
+ what the policy left on and read 已关闭; rows share the effective total, and an
228
+ off row shows the tag instead of a meaningless percentage.
229
+ - The dock chip shows the window percentage (red past 90%) and falls back to the
230
+ savable share when no window is known.
231
+ - New icon: the same three bands narrowing into one dot, drawn as gradients at
232
+ 36×36 so it survives a 20px sidebar. `assets/icon-512.png` is regenerated from
233
+ the same geometry.
234
+ - **A name, once.** The sidebar entry is now 上下文注入 (was 注入) so it reads as
235
+ a sibling of 上下文洞察; the page heading and the marketplace name stay
236
+ 上下文注入管理, and every locale got the same split between the short entry and
237
+ the full product name.
238
+ - **Less air at the top.** The window card became one strip line — bar, room
239
+ left, system/tools/messages — under four tighter KPI cards; a tall card holding
240
+ a 24%-full bar is gone. In the narrow sidebar the strip reflows to
241
+ label + remaining, a full-width bar, then the legend.
242
+ - The four tabs are a segmented control (a pill track with the active tab
243
+ raised), matching the 分组/平铺 control instead of floating underlined text.
244
+ - 13 new tests (pressure, compaction, window rendering) — 66 total.
245
+
246
+ ## 1.10.9 — 2026-11-16
247
+
248
+ - The Items tab opens with a visual overview: an SVG donut of the per-channel
249
+ composition (center = effective total), the largest suites as proportion bars,
250
+ and a first-turn sparkline in the total KPI. Hand-rolled SVG/CSS, no chart
251
+ dependency — the same technique dsh-context uses for its dashboard.
252
+ - Eight locales gained `topSuites`; screenshots regenerated.
253
+
254
+ ## 1.10.8 — 2026-11-16
255
+
256
+ - Sorting moved into the table headers, like a normal data grid: 条目 / 通道 /
257
+ token / 占比 are clickable, show ▲▼ (or ↕ when inactive) and `aria-sort`.
258
+ The toolbar chips are gone; the choice persists as `key:dir`.
259
+ - Fixed the direction: descending token order was inverted (zero-token suites
260
+ came first). Suites and flat rows share the same comparator.
261
+ - Screenshot fixture now reads `/summary` and `/locale` live, so regenerated
262
+ images cannot ship untranslated keys.
263
+
264
+ ## 1.10.7 — 2026-11-16
265
+
266
+ - Suites are merged by label across channels: REA's 229 MCP tools and its prompt
267
+ section are now one row (`REA · 230 条目 · 多通道 · 66,715`) instead of two rows
268
+ sorted far apart. Toggling it dispatches a new bulk `groups` action, so one
269
+ switch turns the whole suite on or off.
270
+ - The footer now reports effective totals and merged group counts (`27/35 组`).
271
+ - Route test covers the bulk action; the fixture understands `groups`.
272
+
273
+ ## 1.10.6 — 2026-11-16
274
+
275
+ - The top strip now always shows the **policy view**, in real time: 首轮注入 and
276
+ 可关闭 are the composition after the current policy (17.1k / 14.6k when REA is
277
+ off), the bar + legend use the same per-channel numbers, and the third card
278
+ became 全开时 (the un-policied baseline) so the comparison is explicit.
279
+ Previously the strip showed the session's assembled prompt, so closing a suite
280
+ changed only "策略后" and looked like a stale refresh.
281
+ - Footer totals follow the same effective view; snapshots expose
282
+ `effective.channels` / `effective.totals`.
283
+
284
+ ## 1.10.5 — 2026-11-16
285
+
286
+ - First registry release: `npm i dsh-injection-manager` installs 1.10.4 (54 files,
287
+ 894,925 bytes). The npm badge is on both READMEs.
288
+ - Release workflow now publishes through npm **trusted publishing (OIDC)**:
289
+ `id-token: write`, npm upgraded in the job, no `NPM_TOKEN` secret. Configure the
290
+ trusted publisher in the package settings once (repo `IWHBIWHB/dsh-injection-manager`,
291
+ workflow `release.yml`), then a `v*` tag releases with provenance.
292
+
3
293
  ## 1.10.4 — 2026-11-16
4
294
 
5
295
  - When the current session was created before the saved policy, the panel now
package/CONTRIBUTING.md CHANGED
@@ -38,8 +38,8 @@ npm pack --dry-run # 确认 locale/docs/icon 都进包
38
38
  版本号写在 `package.json`,CHANGELOG 加一节,然后:
39
39
 
40
40
  ```powershell
41
- git tag v1.3.2
42
- git push origin v1.3.2
41
+ git tag v2.0.0
42
+ git push origin v2.0.0
43
43
  ```
44
44
 
45
45
  `.github/workflows/release.yml` 会校验 tag 与版本一致、跑测试、`npm pack --dry-run`,最后用仓库 secret `NPM_TOKEN` 发布到 npm。没有该 secret 时发布会失败,其余步骤照常给出信号。