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