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.
- package/CHANGELOG.md +290 -0
- package/CONTRIBUTING.md +2 -2
- package/README.md +286 -94
- package/README.zh.md +238 -97
- package/client.js +3325 -295
- package/docs/ARCHITECTURE.md +123 -25
- package/docs/COMPATIBILITY.md +31 -7
- package/docs/DETAIL.md +148 -0
- package/docs/DETAIL.zh.md +105 -1
- package/docs/FAQ.md +53 -7
- package/docs/PERFORMANCE.md +60 -6
- package/docs/images/demo.gif +0 -0
- package/docs/images/dock.png +0 -0
- package/docs/images/panel-dark.png +0 -0
- package/docs/images/panel-drawer.png +0 -0
- package/docs/images/panel-insights.png +0 -0
- package/docs/images/panel-manage-expanded.png +0 -0
- package/docs/images/panel-manage.png +0 -0
- package/docs/images/panel-settings.png +0 -0
- package/docs/images/panel-sidebar.png +0 -0
- package/docs/preview.svg +177 -23
- package/icon.svg +19 -5
- package/index.js +107 -16
- package/lib/actions.js +12 -4
- package/lib/apply.js +14 -2
- package/lib/compaction.js +126 -0
- package/lib/content.js +360 -0
- package/lib/events.js +216 -0
- package/lib/health.js +210 -0
- package/lib/pressure.js +146 -0
- package/lib/routes.js +355 -9
- package/lib/snapshot.js +256 -29
- package/lib/stats.js +394 -0
- package/lib/text.js +160 -0
- package/lib/trend.js +168 -0
- package/locale/de.json +251 -6
- package/locale/en.json +251 -6
- package/locale/es.json +251 -6
- package/locale/fr.json +251 -6
- package/locale/ja.json +251 -6
- package/locale/pt.json +251 -6
- package/locale/ru.json +252 -7
- package/locale/zh.json +249 -4
- package/package.json +16 -3
- package/screenshots.json +7 -5
- package/docs/images/panel-about.png +0 -0
- package/docs/images/panel-budget.png +0 -0
- package/docs/images/panel-policy.png +0 -0
- package/docs/images/panel-suites.png +0 -0
package/docs/PERFORMANCE.md
CHANGED
|
@@ -1,19 +1,73 @@
|
|
|
1
1
|
# 性能
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
这份文档只回答一个问题:日常使用会不会卡。数字来自本机一份 355 条目、27 个套件、230 个 REA 条目的真实快照,以及 v2 表面的按需加载策略与接口实测;不是基准测试。
|
|
4
4
|
|
|
5
5
|
环境:Windows 11、Edge 当前版、视口 1200×860、数据来自本机 DSH 0.2.2-rc.3 的真实 `/summary`。
|
|
6
6
|
|
|
7
|
+
## 管理页(v1 基线,v2 不变)
|
|
8
|
+
|
|
7
9
|
| 指标 | 实测 |
|
|
8
10
|
| --- | --- |
|
|
9
11
|
| 页面 `domContentLoaded` | 68–89 ms |
|
|
10
12
|
| 首次内容绘制(FCP) | 88–112 ms |
|
|
11
|
-
|
|
|
12
|
-
| 分组视图行数 |
|
|
13
|
-
| 展开最大套件(
|
|
13
|
+
| 面板可交互(套件行出现) | 240–310 ms |
|
|
14
|
+
| 分组视图行数 | 27 行(全部渲染) |
|
|
15
|
+
| 展开最大套件(230 行)到可见 | 61–120 ms |
|
|
14
16
|
| 搜索「rea」到结果稳定 | 37–54 ms |
|
|
15
17
|
| 搜索后分组数 | 8 |
|
|
16
18
|
|
|
17
|
-
结论:不必引入虚拟列表。列表按套件折叠,展开最大套件时一次性渲染
|
|
19
|
+
结论:不必引入虚拟列表。列表按套件折叠,展开最大套件时一次性渲染 230 行仍在 100 ms 量级;搜索用 `useDeferredValue` 让输入保持响应,过滤本身在 50 ms 内完成。v2 在这一页只加了行内预览与健康条:预览是快照阶段切好的 180 字符纯文本(点击才渲染),健康条是一次 `/health` 请求,且只有管理 tab 可见时才发。
|
|
20
|
+
|
|
21
|
+
## v2 新表面:按需、有界、失败不拖垮别处
|
|
22
|
+
|
|
23
|
+
| 表面 | 何时取数 | 单次规模上限 | 失败时 |
|
|
24
|
+
| --- | --- | --- | --- |
|
|
25
|
+
| 健康检查条 | 管理 tab 可见时,一次 `/health` | 7 类 code,最多 6 条可见 + 「还有 N 条」 | 显示读取失败,不挡列表与开关 |
|
|
26
|
+
| 内容抽屉 | 用户点开某一行时,一次 `/content` | 256KB / 2 秒预算(模型工具 32KB) | 抽屉内显示错误与重试,列表不动 |
|
|
27
|
+
| 洞察趋势 | 切到洞察 tab 时,一次 `/trend` | 最多 120 个点(API 上限 500);>40 点自动合并为总览分组 | 趋势区显示失败 + 重试,其余卡片照常 |
|
|
28
|
+
| 历史回填 | `/trend`、`/stats` 触发的**后台**任务 | 进程内单飞;冷却 60 秒;每轮 ≤8 个会话;单轮预算 6 秒 | 回填失败静默,下一次读再试 |
|
|
29
|
+
| 事件时间线 | 切到洞察 tab 时,一次 `/events` | 最多 60 条(文件上限 300,先显示 4 条,可展开) | 显示读取失败 + 重试 |
|
|
30
|
+
|
|
31
|
+
## 接口延迟(真实实例)
|
|
32
|
+
|
|
33
|
+
先区分冷读与热读:
|
|
34
|
+
|
|
35
|
+
- **冷读**(进程刚起、`stats.json` 缓存未命中):读一次历史文件、按范围聚合后**立即**返回已有行;此时 `coverage.known` 可能为 `null`(后台会话索引还没建好),响应带 `backfilling: true`。
|
|
36
|
+
- **热读**(缓存命中、回填冷却中):只做内存合并,`/trend` 5 ms、`/stats` 22 ms 量级。
|
|
37
|
+
- 无论冷热,读取都**不等待** durable-log 回填——回填是后台单飞任务。
|
|
38
|
+
|
|
39
|
+
稳定路由(5 次采样中位数):
|
|
40
|
+
|
|
41
|
+
| 路由 | 中位数 | 响应体 |
|
|
42
|
+
| --- | --- | --- |
|
|
43
|
+
| `GET /ping` | 1.5 ms | 745 B |
|
|
44
|
+
| `GET /summary` | 25.0 ms | 175 KB |
|
|
45
|
+
| `GET /locale` | 17.5 ms | 161 KB |
|
|
46
|
+
| `GET /health` | 6.6 ms | 647 B |
|
|
47
|
+
| `GET /events` | 1.4 ms | 69 B |
|
|
48
|
+
| `GET /content`(tools) | 2.1 ms | 697 B |
|
|
49
|
+
| `GET /content`(skills) | 5.5 ms | 7.4 KB |
|
|
50
|
+
|
|
51
|
+
趋势与统计(回填改为后台后的单次探针,671 个会话的语料):
|
|
52
|
+
|
|
53
|
+
| 路由 | 实测 | 备注 |
|
|
54
|
+
| --- | --- | --- |
|
|
55
|
+
| `GET /trend` | 5 ms | 33 个点;首读同样立即返回,`backfilling: true` |
|
|
56
|
+
| `GET /stats` | 22 ms | 33 行;`coverage.known` 在后台索引完成前为 `null` |
|
|
57
|
+
|
|
58
|
+
修复前,`/trend` 与 `/stats` 在每次读取里同步跑 durable-log 回填(8 个会话 / 6 秒),在 671 会话的语料上把一次打开拖到 7.1 s / 2.1 s。2.0.0 把回填改成后台单飞任务(冷却 60 秒、每轮 ≤8 个会话、单轮预算 6 秒),读取只做一次 `stats.json` 读取与内存合并,响应带 `backfilling: true` 让 UI 知道还有数据在路上:打开洞察页的等待从「秒」回到「毫秒」,趋势随后台补齐慢慢变多。
|
|
59
|
+
|
|
60
|
+
设计原则:
|
|
61
|
+
|
|
62
|
+
- **一次 tab 切换只发两类请求**(趋势 + 事件),不并发打满;`/health` 只属于管理 tab。
|
|
63
|
+
- **所有响应有界**:`/summary` 的条目文本用 180 字符预览,`/content` 有 256KB 上限,趋势点与事件窗口都有数量上限。
|
|
64
|
+
- **渲染不重算**:浏览器不算 token、不算预览;行内预览是展开时才渲染的一段文本,长列表仍只画行。
|
|
65
|
+
- **抽屉是覆盖层**:打开它不卸载背后的列表,关闭时焦点回到原来的行;搜索在客户端对已取回的文本做高亮,不再发请求。
|
|
66
|
+
- **失败隔离**:任一新表面失败只影响自己那块,管理页的开关、设置页的保存都不依赖它们。
|
|
67
|
+
|
|
68
|
+
## 复现
|
|
69
|
+
|
|
70
|
+
- 管理页基线:`_research/polish-shots.mjs`(离线夹页,同一份真实快照;会顺带截设置页、深色主题)。
|
|
71
|
+
- 三 tab、抽屉、趋势的真实界面:由 `qa` 的临时 profile 实例(`_research/verify/`)截图与探针生成,不碰你的 desktop profile。
|
|
18
72
|
|
|
19
|
-
|
|
73
|
+
如果某天条目涨到四位数或会话历史过万,先看趋势点数(>40 已合并)与列表行数(按套件折叠);这两个是唯一会随数据线性增长的地方。
|
package/docs/images/demo.gif
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/docs/preview.svg
CHANGED
|
@@ -1,24 +1,178 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="
|
|
2
|
-
<rect width="
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<
|
|
6
|
-
<
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
<
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="960" height="420" viewBox="0 0 960 420" role="img" aria-label="dsh-injection-manager 2.0: five injection channels are clustered into switchable suites and shown in a three-tab panel with a content drawer and a cross-session trend">
|
|
2
|
+
<rect width="960" height="420" rx="20" fill="#eef2f8"/>
|
|
3
|
+
|
|
4
|
+
<!-- title -->
|
|
5
|
+
<text x="32" y="40" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="16" font-weight="600" fill="#1f2430">dsh-injection-manager 2.0</text>
|
|
6
|
+
<text x="32" y="60" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="11.5" fill="#5b6472">what the next request carries · what can be switched off · what each item actually says</text>
|
|
7
|
+
|
|
8
|
+
<!-- ============ A. five channels ============ -->
|
|
9
|
+
<rect x="32" y="84" width="250" height="284" rx="12" fill="#ffffff" stroke="#e3e7ef" stroke-width="1"/>
|
|
10
|
+
<text x="48" y="110" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="11" font-weight="600" fill="#5b6472" letter-spacing=".4">FIVE INJECTION CHANNELS</text>
|
|
11
|
+
|
|
12
|
+
<g font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="12" fill="#1f2430">
|
|
13
|
+
<rect x="48" y="126" width="8" height="8" rx="2" fill="#6366f1"/>
|
|
14
|
+
<text x="66" y="135">Prompt sections</text>
|
|
15
|
+
<text x="266" y="135" text-anchor="end" font-size="11" fill="#5b6472">2.4k</text>
|
|
16
|
+
<rect x="48" y="142" width="218" height="5" rx="2.5" fill="#eef2f8"/>
|
|
17
|
+
<rect x="48" y="142" width="6" height="5" rx="2.5" fill="#6366f1"/>
|
|
18
|
+
|
|
19
|
+
<rect x="48" y="164" width="8" height="8" rx="2" fill="#a855f7"/>
|
|
20
|
+
<text x="66" y="173">Runtime contexts</text>
|
|
21
|
+
<text x="266" y="173" text-anchor="end" font-size="11" fill="#5b6472">4.1k</text>
|
|
22
|
+
<rect x="48" y="180" width="218" height="5" rx="2.5" fill="#eef2f8"/>
|
|
23
|
+
<rect x="48" y="180" width="11" height="5" rx="2.5" fill="#a855f7"/>
|
|
24
|
+
|
|
25
|
+
<rect x="48" y="202" width="8" height="8" rx="2" fill="#f97316"/>
|
|
26
|
+
<text x="66" y="211">Skill catalog</text>
|
|
27
|
+
<text x="266" y="211" text-anchor="end" font-size="11" fill="#5b6472">3.0k</text>
|
|
28
|
+
<rect x="48" y="218" width="218" height="5" rx="2.5" fill="#eef2f8"/>
|
|
29
|
+
<rect x="48" y="218" width="8" height="5" rx="2.5" fill="#f97316"/>
|
|
30
|
+
|
|
31
|
+
<rect x="48" y="240" width="8" height="8" rx="2" fill="#f59e0b"/>
|
|
32
|
+
<text x="66" y="249">Tool schemas</text>
|
|
33
|
+
<text x="266" y="249" text-anchor="end" font-size="11" fill="#5b6472">73.4k</text>
|
|
34
|
+
<rect x="48" y="256" width="218" height="5" rx="2.5" fill="#eef2f8"/>
|
|
35
|
+
<rect x="48" y="256" width="191" height="5" rx="2.5" fill="#f59e0b"/>
|
|
36
|
+
|
|
37
|
+
<rect x="48" y="278" width="8" height="8" rx="2" fill="#14b8a6"/>
|
|
38
|
+
<text x="66" y="287">Workspace rules</text>
|
|
39
|
+
<text x="266" y="287" text-anchor="end" font-size="11" fill="#5b6472">0.9k</text>
|
|
40
|
+
<rect x="48" y="294" width="218" height="5" rx="2.5" fill="#eef2f8"/>
|
|
41
|
+
<rect x="48" y="294" width="3" height="5" rx="1.5" fill="#14b8a6"/>
|
|
42
|
+
</g>
|
|
43
|
+
|
|
44
|
+
<line x1="48" y1="318" x2="266" y2="318" stroke="#e3e7ef" stroke-width="1"/>
|
|
45
|
+
<text x="48" y="338" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="12" font-weight="600" fill="#1f2430">83.8k first turn</text>
|
|
46
|
+
<text x="266" y="338" text-anchor="end" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="11" fill="#5b6472">97% switchable</text>
|
|
47
|
+
<text x="48" y="357" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="10.5" fill="#8892a2">estimates: ASCII÷4, else ÷1.6</text>
|
|
48
|
+
|
|
49
|
+
<!-- arrow A -> B -->
|
|
50
|
+
<path d="M288 226h22M302 218l8 8-8 8" fill="none" stroke="#c3ccdb" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
51
|
+
|
|
52
|
+
<!-- ============ B. suites ============ -->
|
|
53
|
+
<rect x="320" y="84" width="192" height="284" rx="12" fill="#ffffff" stroke="#e3e7ef" stroke-width="1"/>
|
|
54
|
+
<text x="336" y="110" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="11" font-weight="600" fill="#5b6472" letter-spacing=".4">SUITES · ONE SWITCH</text>
|
|
55
|
+
|
|
56
|
+
<!-- suite row 1: REA (off) -->
|
|
57
|
+
<g font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif">
|
|
58
|
+
<text x="336" y="136" font-size="12" font-weight="600" fill="#1f2430">REA</text>
|
|
59
|
+
<rect x="456" y="126" width="26" height="14" rx="7" fill="#d7dde8"/>
|
|
60
|
+
<circle cx="468" cy="133" r="5" fill="#ffffff"/>
|
|
61
|
+
<text x="336" y="151" font-size="10.5" fill="#5b6472">230 items · 66.7k · 79.6%</text>
|
|
62
|
+
</g>
|
|
63
|
+
<line x1="336" y1="164" x2="496" y2="164" stroke="#eef2f8" stroke-width="1"/>
|
|
64
|
+
|
|
65
|
+
<!-- suite row 2: core tools (on) -->
|
|
66
|
+
<g font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif">
|
|
67
|
+
<text x="336" y="186" font-size="12" font-weight="600" fill="#1f2430">Core tools</text>
|
|
68
|
+
<rect x="456" y="176" width="26" height="14" rx="7" fill="#4d6bfe"/>
|
|
69
|
+
<circle cx="475" cy="183" r="5" fill="#ffffff"/>
|
|
70
|
+
<text x="336" y="201" font-size="10.5" fill="#5b6472">12 items · 8.1k · 9.7%</text>
|
|
71
|
+
</g>
|
|
72
|
+
<line x1="336" y1="214" x2="496" y2="214" stroke="#eef2f8" stroke-width="1"/>
|
|
73
|
+
|
|
74
|
+
<!-- suite row 3: skills (mixed) -->
|
|
75
|
+
<g font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif">
|
|
76
|
+
<text x="336" y="236" font-size="12" font-weight="600" fill="#1f2430">Skills</text>
|
|
77
|
+
<rect x="456" y="226" width="26" height="14" rx="7" fill="#9db0f7"/>
|
|
78
|
+
<circle cx="465" cy="233" r="5" fill="#ffffff"/>
|
|
79
|
+
<text x="336" y="251" font-size="10.5" fill="#5b6472">38 items · 3.0k · 3.6%</text>
|
|
80
|
+
</g>
|
|
81
|
+
|
|
82
|
+
<text x="336" y="292" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="10.5" fill="#8892a2">one MCP server = one suite</text>
|
|
83
|
+
<text x="336" y="311" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="10.5" fill="#8892a2">closed suites stay listed</text>
|
|
84
|
+
<text x="336" y="330" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="10.5" fill="#8892a2">every switch is reversible</text>
|
|
85
|
+
|
|
86
|
+
<!-- arrow B -> C -->
|
|
87
|
+
<path d="M528 226h22M542 218l8 8-8 8" fill="none" stroke="#c3ccdb" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
88
|
+
|
|
89
|
+
<!-- ============ C. panel mock ============ -->
|
|
90
|
+
<rect x="560" y="84" width="368" height="284" rx="12" fill="#ffffff" stroke="#e3e7ef" stroke-width="1"/>
|
|
91
|
+
|
|
92
|
+
<!-- tabs -->
|
|
93
|
+
<rect x="576" y="98" width="62" height="26" rx="8" fill="#1f2430"/>
|
|
94
|
+
<text x="607" y="115" text-anchor="middle" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="11" font-weight="600" fill="#ffffff">管理</text>
|
|
95
|
+
<text x="656" y="115" text-anchor="middle" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="11" fill="#5b6472">洞察</text>
|
|
96
|
+
<text x="704" y="115" text-anchor="middle" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="11" fill="#5b6472">设置</text>
|
|
97
|
+
<text x="912" y="115" text-anchor="end" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="10" fill="#8892a2">v2.0.0</text>
|
|
98
|
+
|
|
99
|
+
<!-- KPI tiles -->
|
|
100
|
+
<rect x="576" y="136" width="86" height="38" rx="8" fill="#f6f8fc" stroke="#e9edf5" stroke-width="1"/>
|
|
101
|
+
<text x="588" y="152" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="9.5" fill="#5b6472">first turn</text>
|
|
102
|
+
<text x="588" y="167" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="13" font-weight="600" fill="#1f2430">83.8k</text>
|
|
103
|
+
|
|
104
|
+
<rect x="670" y="136" width="86" height="38" rx="8" fill="#f6f8fc" stroke="#e9edf5" stroke-width="1"/>
|
|
105
|
+
<text x="682" y="152" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="9.5" fill="#5b6472">switchable</text>
|
|
106
|
+
<text x="682" y="167" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="13" font-weight="600" fill="#1f2430">97%</text>
|
|
107
|
+
|
|
108
|
+
<rect x="764" y="136" width="86" height="38" rx="8" fill="#f6f8fc" stroke="#e9edf5" stroke-width="1"/>
|
|
109
|
+
<text x="776" y="152" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="9.5" fill="#5b6472">window used</text>
|
|
110
|
+
<text x="776" y="167" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="13" font-weight="600" fill="#1f2430">36%</text>
|
|
111
|
+
|
|
112
|
+
<!-- health strip -->
|
|
113
|
+
<rect x="576" y="184" width="274" height="30" rx="8" fill="#fff8ec" stroke="#f3e2c2" stroke-width="1"/>
|
|
114
|
+
<circle cx="590" cy="199" r="3.5" fill="#f59e0b"/>
|
|
115
|
+
<text x="600" y="202.5" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="10.5" fill="#8a6116">REA = 79.6% of first turn</text>
|
|
116
|
+
<rect x="790" y="189" width="52" height="20" rx="6" fill="#ffffff" stroke="#e6d2ab" stroke-width="1"/>
|
|
117
|
+
<text x="816" y="202.5" text-anchor="middle" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="9.5" fill="#8a6116">turn off</text>
|
|
118
|
+
|
|
119
|
+
<!-- trend mini chart: stacked bars -->
|
|
120
|
+
<line x1="576" y1="302" x2="700" y2="302" stroke="#e3e7ef" stroke-width="1"/>
|
|
121
|
+
<g fill="#f59e0b">
|
|
122
|
+
<rect x="578" y="288" width="9" height="14" rx="1.5"/>
|
|
123
|
+
<rect x="591" y="282" width="9" height="20" rx="1.5"/>
|
|
124
|
+
<rect x="604" y="276" width="9" height="26" rx="1.5"/>
|
|
125
|
+
<rect x="617" y="270" width="9" height="32" rx="1.5"/>
|
|
126
|
+
<rect x="630" y="274" width="9" height="28" rx="1.5"/>
|
|
127
|
+
</g>
|
|
128
|
+
<g fill="#6366f1">
|
|
129
|
+
<rect x="578" y="284" width="9" height="4" rx="1"/>
|
|
130
|
+
<rect x="591" y="278" width="9" height="4" rx="1"/>
|
|
131
|
+
<rect x="604" y="272" width="9" height="4" rx="1"/>
|
|
132
|
+
<rect x="617" y="266" width="9" height="4" rx="1"/>
|
|
133
|
+
<rect x="630" y="270" width="9" height="4" rx="1"/>
|
|
134
|
+
</g>
|
|
135
|
+
<g fill="#14b8a6">
|
|
136
|
+
<rect x="578" y="281" width="9" height="3" rx="1"/>
|
|
137
|
+
<rect x="591" y="275" width="9" height="3" rx="1"/>
|
|
138
|
+
<rect x="604" y="269" width="9" height="3" rx="1"/>
|
|
139
|
+
<rect x="617" y="263" width="9" height="3" rx="1"/>
|
|
140
|
+
<rect x="630" y="267" width="9" height="3" rx="1"/>
|
|
141
|
+
</g>
|
|
142
|
+
<text x="576" y="318" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="9.5" fill="#8892a2">first-turn trend · hover / pin</text>
|
|
143
|
+
|
|
144
|
+
<!-- content drawer overlay (bottom-right, below the health strip) -->
|
|
145
|
+
<rect x="712" y="240" width="200" height="112" rx="10" fill="#fbfcfe" stroke="#dfe5ef" stroke-width="1"/>
|
|
146
|
+
<rect x="712" y="240" width="200" height="26" rx="10" fill="#f3f6fb"/>
|
|
147
|
+
<rect x="712" y="256" width="200" height="10" fill="#f3f6fb"/>
|
|
148
|
+
<text x="724" y="257" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="9.5" font-weight="600" fill="#1f2430">content · tools/read</text>
|
|
149
|
+
<text x="900" y="257" text-anchor="end" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="8.5" fill="#8892a2">342 t</text>
|
|
150
|
+
|
|
151
|
+
<text x="724" y="280" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="8.5" fill="#5b6472">source: session snapshot</text>
|
|
152
|
+
<rect x="724" y="286" width="176" height="36" rx="6" fill="#f6f8fc"/>
|
|
153
|
+
<g fill="#cfd8e6">
|
|
154
|
+
<rect x="730" y="292" width="96" height="4" rx="2"/>
|
|
155
|
+
<rect x="730" y="300" width="120" height="4" rx="2"/>
|
|
156
|
+
<rect x="730" y="308" width="72" height="4" rx="2"/>
|
|
157
|
+
</g>
|
|
158
|
+
<rect x="856" y="292" width="22" height="4" rx="2" fill="#e6edff"/>
|
|
159
|
+
|
|
160
|
+
<rect x="724" y="328" width="54" height="16" rx="5" fill="#eef2f8"/>
|
|
161
|
+
<text x="751" y="339" text-anchor="middle" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="8.5" fill="#5b6472">find…</text>
|
|
162
|
+
<text x="792" y="339" font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="8.5" fill="#8892a2">lines · copy</text>
|
|
163
|
+
<rect x="866" y="328" width="30" height="16" rx="8" fill="#4d6bfe"/>
|
|
164
|
+
<circle cx="888" cy="336" r="5" fill="#ffffff"/>
|
|
165
|
+
|
|
166
|
+
<!-- ============ D. bottom surfaces ============ -->
|
|
167
|
+
<g font-family="-apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif" font-size="10.5" fill="#5b6472">
|
|
168
|
+
<rect x="32" y="384" width="140" height="24" rx="12" fill="#ffffff" stroke="#e3e7ef" stroke-width="1"/>
|
|
169
|
+
<text x="102" y="400" text-anchor="middle">sidebar icon</text>
|
|
170
|
+
<rect x="180" y="384" width="140" height="24" rx="12" fill="#ffffff" stroke="#e3e7ef" stroke-width="1"/>
|
|
171
|
+
<text x="250" y="400" text-anchor="middle">composer chip</text>
|
|
172
|
+
<rect x="328" y="384" width="140" height="24" rx="12" fill="#ffffff" stroke="#e3e7ef" stroke-width="1"/>
|
|
173
|
+
<text x="398" y="400" text-anchor="middle">/inject</text>
|
|
174
|
+
<rect x="476" y="384" width="180" height="24" rx="12" fill="#ffffff" stroke="#e3e7ef" stroke-width="1"/>
|
|
175
|
+
<text x="566" y="400" text-anchor="middle">context_injection (read-only)</text>
|
|
176
|
+
<text x="928" y="400" text-anchor="end" font-size="10" fill="#8892a2">manage · insights · settings</text>
|
|
177
|
+
</g>
|
|
24
178
|
</svg>
|
package/icon.svg
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 36 36" width="36" height="36" fill="none" role="img" aria-label="Context injection manager">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bar-system" x1="4" y1="6" x2="32" y2="13.4" gradientUnits="userSpaceOnUse">
|
|
4
|
+
<stop stop-color="#6BA6FF"/>
|
|
5
|
+
<stop offset="1" stop-color="#3B5BFE"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<linearGradient id="bar-tools" x1="4" y1="15.6" x2="24" y2="23" gradientUnits="userSpaceOnUse">
|
|
8
|
+
<stop stop-color="#3FE0B0"/>
|
|
9
|
+
<stop offset="1" stop-color="#0D9E8C"/>
|
|
10
|
+
</linearGradient>
|
|
11
|
+
<linearGradient id="bar-messages" x1="4" y1="25.2" x2="16" y2="32.6" gradientUnits="userSpaceOnUse">
|
|
12
|
+
<stop stop-color="#AEB9CA"/>
|
|
13
|
+
<stop offset="1" stop-color="#6C7789"/>
|
|
14
|
+
</linearGradient>
|
|
15
|
+
</defs>
|
|
16
|
+
<rect x="4" y="6" width="28" height="7.4" rx="3.7" fill="url(#bar-system)"/>
|
|
17
|
+
<rect x="4" y="15.6" width="20" height="7.4" rx="3.7" fill="url(#bar-tools)"/>
|
|
18
|
+
<rect x="4" y="25.2" width="12" height="7.4" rx="3.7" fill="url(#bar-messages)"/>
|
|
19
|
+
<circle cx="27.4" cy="28.9" r="3.7" fill="#3B5BFE"/>
|
|
6
20
|
</svg>
|
package/index.js
CHANGED
|
@@ -15,13 +15,17 @@ import { createRequire } from 'node:module'
|
|
|
15
15
|
import { homedir } from 'node:os'
|
|
16
16
|
import { join } from 'node:path'
|
|
17
17
|
import { applyPolicyForAgent, releaseAll, savePolicy } from './lib/apply.js'
|
|
18
|
-
import { createRoutes, ROUTES } from './lib/routes.js'
|
|
18
|
+
import { createRoutes, makeFencedHandler, ROUTES } from './lib/routes.js'
|
|
19
19
|
import { buildSnapshot, planBudget, policyFromPlan } from './lib/snapshot.js'
|
|
20
|
+
import { watchCompaction } from './lib/compaction.js'
|
|
21
|
+
import { CONTENT_CHANNELS, TOOL_CONTENT_LIMIT, collectContent } from './lib/content.js'
|
|
22
|
+
import { appendEvent } from './lib/events.js'
|
|
23
|
+
import { buildHealth } from './lib/health.js'
|
|
20
24
|
import { presetPolicy } from './lib/presets.js'
|
|
21
25
|
import { readPolicy } from './lib/policy.js'
|
|
22
26
|
import { setSettings } from './lib/settings.js'
|
|
23
27
|
import { pushUndo, undoLastPolicy } from './lib/actions.js'
|
|
24
|
-
import { renderCard, renderText } from './lib/text.js'
|
|
28
|
+
import { renderCard, renderHealthLine, renderHealthText, renderText } from './lib/text.js'
|
|
25
29
|
|
|
26
30
|
export const name = 'injection-manager'
|
|
27
31
|
|
|
@@ -77,7 +81,9 @@ export const inject = ['tools', 'systemPrompt', 'skills', 'workingDirectory', 'a
|
|
|
77
81
|
const TOOL_NAME = 'context_injection'
|
|
78
82
|
|
|
79
83
|
const TOOL_DESCRIPTION =
|
|
80
|
-
'查看本轮请求将注入给模型的上下文构成:系统提示词段落、运行时上下文、技能目录、工具 schema、工作区规则,各占多少字符与估算 token
|
|
84
|
+
'查看本轮请求将注入给模型的上下文构成:系统提示词段落、运行时上下文、技能目录、工具 schema、工作区规则,各占多少字符与估算 token,以及哪些条目可以关闭。只读:本工具不改策略、不改任何文件;开关在侧栏「上下文注入」面板里。可选参数 {channel, name}:只返回该条目的原文(单条 ≤32KB),不带参数才返回完整清单。'
|
|
85
|
+
|
|
86
|
+
const SINGLE_CONTENT_HINT = 'channel 和 name 必须同时提供(如 {channel:"tools", name:"read"});不带参数调用才返回完整清单。'
|
|
81
87
|
|
|
82
88
|
function resolveAgent(ctx, exec) {
|
|
83
89
|
if (exec?.agent !== undefined) return { agent: exec.agent, source: 'exec.agent' }
|
|
@@ -90,20 +96,68 @@ function resolveAgent(ctx, exec) {
|
|
|
90
96
|
return { agent: undefined, source: 'none' }
|
|
91
97
|
}
|
|
92
98
|
|
|
93
|
-
function createTool(ctx) {
|
|
99
|
+
export function createTool(ctx) {
|
|
94
100
|
return {
|
|
95
101
|
name: TOOL_NAME,
|
|
96
102
|
description: TOOL_DESCRIPTION,
|
|
97
|
-
parameters: {
|
|
103
|
+
parameters: {
|
|
104
|
+
type: 'object',
|
|
105
|
+
properties: {
|
|
106
|
+
channel: {
|
|
107
|
+
type: 'string',
|
|
108
|
+
enum: [...CONTENT_CHANNELS],
|
|
109
|
+
description: '可选:只读查看单条内容所属的通道;必须同时提供 name。',
|
|
110
|
+
},
|
|
111
|
+
name: {
|
|
112
|
+
type: 'string',
|
|
113
|
+
description: '可选:条目名,与 /summary items[].name 一致(段落名 / 上下文名 / 技能名 / 工具名 / 规则文件路径);必须同时提供 channel。',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
additionalProperties: false,
|
|
117
|
+
},
|
|
98
118
|
timeoutMs: 30000,
|
|
99
119
|
output: {
|
|
100
120
|
schema: {},
|
|
101
|
-
render: (_args, value) => [{ type: 'text', text: String(value?.card ?? value?.text ?? '') }],
|
|
121
|
+
render: (_args, value) => [{ type: 'text', text: String(value?.card ?? value?.text ?? value?.content ?? '') }],
|
|
102
122
|
},
|
|
103
|
-
async execute(
|
|
123
|
+
async execute(args, exec) {
|
|
104
124
|
const { agent, source } = resolveAgent(ctx, exec)
|
|
125
|
+
const channel = typeof args?.channel === 'string' && args.channel.length > 0 ? args.channel : undefined
|
|
126
|
+
const name = typeof args?.name === 'string' && args.name.trim().length > 0 ? args.name.trim() : undefined
|
|
127
|
+
if (channel !== undefined || name !== undefined) {
|
|
128
|
+
// Single-item mode: the caller asked to read one row, not the whole
|
|
129
|
+
// snapshot. Hard-capped at 32KB so a page of prompt text cannot flood a
|
|
130
|
+
// model turn; the full snapshot stays behind the no-argument call.
|
|
131
|
+
if (channel === undefined || name === undefined) {
|
|
132
|
+
return { ok: false, error: 'invalid-arguments', message: SINGLE_CONTENT_HINT }
|
|
133
|
+
}
|
|
134
|
+
const result = await collectContent(ctx, agent, channel, name, exec?.signal, { limit: TOOL_CONTENT_LIMIT })
|
|
135
|
+
if (result.ok !== true) {
|
|
136
|
+
return JSON.parse(
|
|
137
|
+
JSON.stringify({ ok: false, error: result.error ?? 'content-failed', message: result.message ?? '', channel, name }),
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
const payload = {
|
|
141
|
+
ok: true,
|
|
142
|
+
item: result.item,
|
|
143
|
+
contentType: result.contentType,
|
|
144
|
+
content: result.content,
|
|
145
|
+
bytes: result.bytes,
|
|
146
|
+
truncated: result.truncated,
|
|
147
|
+
limit: result.limit,
|
|
148
|
+
...(result.sourcePath === undefined ? {} : { sourcePath: result.sourcePath }),
|
|
149
|
+
...(result.note === undefined ? {} : { note: result.note }),
|
|
150
|
+
}
|
|
151
|
+
return JSON.parse(JSON.stringify(payload))
|
|
152
|
+
}
|
|
105
153
|
const snapshot = await buildSnapshot(ctx, agent, source, exec?.signal)
|
|
106
|
-
const payload = {
|
|
154
|
+
const payload = {
|
|
155
|
+
ok: true,
|
|
156
|
+
apiVersion: 2,
|
|
157
|
+
...snapshot,
|
|
158
|
+
text: renderText(snapshot),
|
|
159
|
+
card: renderCard(snapshot),
|
|
160
|
+
}
|
|
107
161
|
// The tool result must be lossless JSON.
|
|
108
162
|
return JSON.parse(JSON.stringify(payload))
|
|
109
163
|
},
|
|
@@ -113,14 +167,23 @@ function createTool(ctx) {
|
|
|
113
167
|
export function createCommand(ctx) {
|
|
114
168
|
return {
|
|
115
169
|
name: 'inject',
|
|
116
|
-
description: '查看首轮上下文注入清单;`/inject minimal|all` 切换预设,`/inject budget 20000` 设定预算。',
|
|
170
|
+
description: '查看首轮上下文注入清单;`/inject health` 看健康检查,`/inject minimal|all` 切换预设,`/inject budget 20000` 设定预算。',
|
|
117
171
|
async handler(invocation) {
|
|
118
172
|
const agent = invocation?.agent
|
|
173
|
+
const sessionId = typeof agent?.id === 'string' && agent.id.length > 0 ? agent.id : undefined
|
|
119
174
|
const raw = typeof invocation?.rawInput === 'string' ? invocation.rawInput.trim() : ''
|
|
120
175
|
const snapshot = await buildSnapshot(ctx, agent, 'command', invocation?.signal)
|
|
121
176
|
try {
|
|
122
177
|
const [command, value] = raw.split(/\s+/).filter((part) => part.length > 0)
|
|
123
|
-
if (command === undefined)
|
|
178
|
+
if (command === undefined) {
|
|
179
|
+
// The full report plus a single health line: the line is the "should I
|
|
180
|
+
// care?" answer, and `/inject health` is the detail behind it.
|
|
181
|
+
return { kind: 'success', text: `${renderText(snapshot)}\n\n${renderHealthLine(buildHealth(snapshot))}` }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (command === 'health') {
|
|
185
|
+
return { kind: 'success', text: renderHealthText(buildHealth(snapshot)) }
|
|
186
|
+
}
|
|
124
187
|
|
|
125
188
|
if (command === 'all' || command === 'minimal') {
|
|
126
189
|
const names = {
|
|
@@ -134,7 +197,7 @@ export function createCommand(ctx) {
|
|
|
134
197
|
const next = presetPolicy(command, names)
|
|
135
198
|
next.prompt = state.policy.prompt
|
|
136
199
|
next.budget = state.policy.budget
|
|
137
|
-
await savePolicy(next)
|
|
200
|
+
await savePolicy(next, { sessionId, kind: 'preset', params: { name: command, via: 'command' } })
|
|
138
201
|
const after = await buildSnapshot(ctx, agent, 'command', invocation?.signal)
|
|
139
202
|
return {
|
|
140
203
|
kind: 'success',
|
|
@@ -149,7 +212,10 @@ export function createCommand(ctx) {
|
|
|
149
212
|
}
|
|
150
213
|
const state = await readPolicy()
|
|
151
214
|
pushUndo(state.policy)
|
|
152
|
-
await savePolicy(
|
|
215
|
+
await savePolicy(
|
|
216
|
+
{ ...state.policy, budget: { tokens: Math.round(tokens) } },
|
|
217
|
+
{ sessionId, kind: 'budget', params: { tokens: Math.round(tokens), via: 'command' } },
|
|
218
|
+
)
|
|
153
219
|
return { kind: 'success', text: `首轮注入预算已设为 ${Math.round(tokens)} token(新会话生效)。` }
|
|
154
220
|
}
|
|
155
221
|
|
|
@@ -167,7 +233,12 @@ export function createCommand(ctx) {
|
|
|
167
233
|
const next = policyFromPlan(state.policy, plan)
|
|
168
234
|
next.prompt = state.policy.prompt
|
|
169
235
|
next.budget = { tokens: plan.target }
|
|
170
|
-
await savePolicy(next
|
|
236
|
+
await savePolicy(next, {
|
|
237
|
+
sessionId,
|
|
238
|
+
kind: 'budget',
|
|
239
|
+
params: { tokens: plan.target, dropped: plan.drop.length, saved: plan.savedTokens, via: 'plan' },
|
|
240
|
+
tokensDelta: -plan.savedTokens,
|
|
241
|
+
})
|
|
171
242
|
const after = await buildSnapshot(ctx, agent, 'command', invocation?.signal)
|
|
172
243
|
const suites = (plan.dropGroups ?? []).map((group) => ` ${group.label} · ${group.count} 项 · ${group.tokens} token`).join('\n')
|
|
173
244
|
return {
|
|
@@ -177,7 +248,7 @@ export function createCommand(ctx) {
|
|
|
177
248
|
}
|
|
178
249
|
|
|
179
250
|
if (command === 'undo') {
|
|
180
|
-
await undoLastPolicy()
|
|
251
|
+
await undoLastPolicy({ sessionId, params: { via: 'command' } })
|
|
181
252
|
const after = await buildSnapshot(ctx, agent, 'command', invocation?.signal)
|
|
182
253
|
return {
|
|
183
254
|
kind: 'success',
|
|
@@ -187,7 +258,7 @@ export function createCommand(ctx) {
|
|
|
187
258
|
|
|
188
259
|
return {
|
|
189
260
|
kind: 'error',
|
|
190
|
-
text: '可用:/inject · /inject all · /inject minimal · /inject budget <token 数> · /inject apply [token 数] · /inject undo',
|
|
261
|
+
text: '可用:/inject · /inject health · /inject all · /inject minimal · /inject budget <token 数> · /inject apply [token 数] · /inject undo',
|
|
191
262
|
}
|
|
192
263
|
} catch (error) {
|
|
193
264
|
return { kind: 'error', text: `注入策略操作失败:${error?.message ?? error}` }
|
|
@@ -206,13 +277,33 @@ export function apply(ctx, config) {
|
|
|
206
277
|
for (const [key, path] of Object.entries(ROUTES)) {
|
|
207
278
|
const handler = routes[key]
|
|
208
279
|
if (typeof handler !== 'function') continue
|
|
209
|
-
|
|
280
|
+
// Every registered route first asks the host's connection service for a
|
|
281
|
+
// Host/Origin (and browser-auth) rejection. A rejected request is answered
|
|
282
|
+
// by the fence itself, before any route logic or file read. Older hosts
|
|
283
|
+
// without the service fall through unchanged (see makeFencedHandler).
|
|
284
|
+
const fenced = makeFencedHandler(ctx, handler)
|
|
285
|
+
ctx.effect(() => ctx.webServer.register({ kind: 'exact', path, handler: fenced }), `injection-manager route ${key}`)
|
|
210
286
|
}
|
|
211
287
|
|
|
212
288
|
// The only moment a policy can still influence the first assemble().
|
|
213
289
|
ctx.on('agent/created', async (payload) => {
|
|
290
|
+
const sessionId = typeof payload?.agent?.id === 'string' ? payload.agent.id : undefined
|
|
291
|
+
// Fire-and-forget: session creation is serial and blocks the first request,
|
|
292
|
+
// so the feed write must not sit in its critical path.
|
|
293
|
+
void appendEvent({
|
|
294
|
+
sessionId,
|
|
295
|
+
kind: 'session-created',
|
|
296
|
+
params: { source: typeof payload?.source === 'string' ? payload.source : 'unknown' },
|
|
297
|
+
})
|
|
214
298
|
await applyPolicyForAgent(ctx, payload?.agent, payload?.source)
|
|
215
299
|
})
|
|
216
300
|
|
|
301
|
+
// Compaction receipts: "it threw away 78k tokens for you" is a durable log
|
|
302
|
+
// fact, not an inference from a shrinking total.
|
|
303
|
+
ctx.effect(() => {
|
|
304
|
+
const dispose = watchCompaction(ctx)
|
|
305
|
+
return typeof dispose === 'function' ? dispose : () => {}
|
|
306
|
+
}, 'injection-manager compaction receipts')
|
|
307
|
+
|
|
217
308
|
ctx.effect(() => () => releaseAll(), 'injection-manager cleanup')
|
|
218
309
|
}
|
package/lib/actions.js
CHANGED
|
@@ -6,19 +6,27 @@ import { popUndo, pushUndo, restoreAt } from './history.js'
|
|
|
6
6
|
import { normalizePolicy } from './policy.js'
|
|
7
7
|
import { savePolicy } from './apply.js'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* `meta` is forwarded to savePolicy so the event feed records an undo as an
|
|
11
|
+
* undo (with its session) instead of a generic policy write.
|
|
12
|
+
*/
|
|
13
|
+
export async function undoLastPolicy(meta = {}) {
|
|
10
14
|
const previous = popUndo()
|
|
11
15
|
if (previous === undefined) throw new Error('nothing-to-undo')
|
|
12
16
|
const restored = normalizePolicy(previous.policy)
|
|
13
|
-
await savePolicy(restored)
|
|
17
|
+
await savePolicy(restored, { ...meta, kind: typeof meta.kind === 'string' ? meta.kind : 'undo' })
|
|
14
18
|
return restored
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
export async function restorePolicyAt(index) {
|
|
21
|
+
export async function restorePolicyAt(index, meta = {}) {
|
|
18
22
|
const entry = restoreAt(index)
|
|
19
23
|
if (entry === undefined) throw new Error('nothing-to-restore')
|
|
20
24
|
const restored = normalizePolicy(entry.policy)
|
|
21
|
-
await savePolicy(restored
|
|
25
|
+
await savePolicy(restored, {
|
|
26
|
+
...meta,
|
|
27
|
+
kind: typeof meta.kind === 'string' ? meta.kind : 'undo',
|
|
28
|
+
params: { index, ...(meta.params !== null && typeof meta.params === 'object' ? meta.params : {}) },
|
|
29
|
+
})
|
|
22
30
|
return restored
|
|
23
31
|
}
|
|
24
32
|
|