dsh-agent-control-center 0.5.0 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,42 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0 — 2026-11-29
4
+
5
+ Two things the 0.5.0 report called out as still open: the Tools page first paint, and
6
+ proof that the write path actually writes correctly.
7
+
8
+ ### Changed
9
+
10
+ - **Tools first paint: 5.5 s → 90 ms.** The page now sends two parallel requests
11
+ instead of one: a registry-only `tools.list({includeHistory:false})` that paints
12
+ the list as soon as it arrives (~150 ms server-side), and the history-bearing
13
+ request whose result swaps in when it is ready (~4 s on 357 sessions). Until it
14
+ arrives the page says the call history is still loading instead of holding the
15
+ whole page. Measured with a MutationObserver (grid appeared 90 ms after the nav
16
+ click; history filled at 3,970 ms).
17
+ - A registry-only read must not touch sessions at all: new unit test asserts `listSessions`
18
+ throws and `readSession` is never called on that path.
19
+
20
+ ### Added
21
+
22
+ - `scripts/interaction-regression.py` — the 12-page interaction regression as a
23
+ repeatable script (`--token` / `--base` / `--out`), asserting one or two real
24
+ interactions per page (24 assertions).
25
+ - `scripts/write-regression.py` — the write-path end-to-end regression: save →
26
+ on-disk bytes → backup → stale-hash refusal → restore → exact original bytes.
27
+ It refuses to run on a missing file, so it can never create an instruction file.
28
+ - `docs/15-WRITE-REGRESSION.md` and `docs/16-TOOLS-FIRST-PAINT.md` record what was
29
+ measured, including the part that is **not** covered yet (browser-driven writes).
30
+
31
+ ### Verified
32
+
33
+ - 374 behaviour tests green; `verify: ok`.
34
+ - Write E2E **11/11** on `0.2.3-alpha.3`: 17,855-byte instruction file saved,
35
+ backed up, restored byte-identically (sha256 `4c5ad6e8…`), stale-hash write refused
36
+ with "disk not overwritten", repo left clean.
37
+ - Tools first paint 90 ms (was 4–5.5 s), history fills without blocking, 0 console
38
+ errors.
39
+
3
40
  ## 0.5.0 — 2026-11-29
4
41
 
5
42
  Closes the last gap in the v0.4 objective: the health module can now compare what
package/README.md CHANGED
@@ -25,7 +25,7 @@ Screenshots live in `docs/assets/` and are excluded from the npm tarball.*
25
25
  ## Pages and status
26
26
 
27
27
  Runtime state comes from `GET /__agent-control-center/health`; the table records
28
- what the 0.5.0 acceptance run actually proved (details and evidence levels in
28
+ what the 0.6.0 acceptance run actually proved (details and evidence levels in
29
29
  [docs/05-ACCEPTANCE-EVIDENCE.md](docs/05-ACCEPTANCE-EVIDENCE.md)).
30
30
 
31
31
  | Page | What it gives you | State | Why / data source |
@@ -60,7 +60,7 @@ dsh plugin --profile web add dsh-agent-control-center
60
60
 
61
61
  # 2) from a packed tarball
62
62
  npm pack
63
- dsh plugin --profile web add ./dsh-agent-control-center-0.5.0.tgz
63
+ dsh plugin --profile web add ./dsh-agent-control-center-0.6.0.tgz
64
64
 
65
65
  # 3) from a local checkout
66
66
  dsh plugin --profile web add /absolute/path/to/dsh-agent-control-center
@@ -71,7 +71,7 @@ Then restart the Web GUI (the Host half mounts its HTTP route at boot) and open
71
71
 
72
72
  ```bash
73
73
  curl -s http://127.0.0.1:<gui-port>/__agent-control-center/health
74
- # → {"ok":true,"value":{"version":"0.5.0", …, "modules":[ … 12 entries … ]}}
74
+ # → {"ok":true,"value":{"version":"0.6.0", …, "modules":[ … 12 entries … ]}}
75
75
  ```
76
76
 
77
77
  Uninstall with `dsh plugin --profile web remove dsh-agent-control-center`.
@@ -230,7 +230,7 @@ version cannot land.
230
230
 
231
231
  | Item | Value |
232
232
  |---|---|
233
- | Plugin version | `0.5.0` |
233
+ | Plugin version | `0.6.0` |
234
234
  | DSH range | `>=0.2.1-rc.1 <0.3.0` (`engines.dsh` and `dsh.compatibility.dsh`) |
235
235
  | Verified against | DSH `0.2.2-rc.5` (web profile), Node `v24.22.2`, Linux x86_64 |
236
236
  | Node | `>=22.19` (CI: 22 and 24) |
package/README.zh.md CHANGED
@@ -17,7 +17,7 @@
17
17
 
18
18
  ## 页面与状态
19
19
 
20
- 运行期状态来自 `GET /__agent-control-center/health`;下表记录 0.5.0 验收实际证明了什么
20
+ 运行期状态来自 `GET /__agent-control-center/health`;下表记录 0.6.0 验收实际证明了什么
21
21
  (逐条证据与等级见 [docs/05-ACCEPTANCE-EVIDENCE.md](docs/05-ACCEPTANCE-EVIDENCE.md))。
22
22
 
23
23
  | 页面 | 提供什么 | 状态 | 依据 / 数据来源 |
@@ -49,7 +49,7 @@ dsh plugin --profile web add dsh-agent-control-center
49
49
 
50
50
  # 2) 从打包产物安装
51
51
  npm pack
52
- dsh plugin --profile web add ./dsh-agent-control-center-0.5.0.tgz
52
+ dsh plugin --profile web add ./dsh-agent-control-center-0.6.0.tgz
53
53
 
54
54
  # 3) 从本地 checkout 安装
55
55
  dsh plugin --profile web add /绝对路径/dsh-agent-control-center
@@ -60,7 +60,7 @@ dsh plugin --profile web add /绝对路径/dsh-agent-control-center
60
60
 
61
61
  ```bash
62
62
  curl -s http://127.0.0.1:<GUI端口>/__agent-control-center/health
63
- # → {"ok":true,"value":{"version":"0.5.0", …, "modules":[ … 12 项 … ]}}
63
+ # → {"ok":true,"value":{"version":"0.6.0", …, "modules":[ … 12 项 … ]}}
64
64
  ```
65
65
 
66
66
  卸载:`dsh plugin --profile web remove dsh-agent-control-center`。
@@ -174,7 +174,7 @@ node scripts/release.mjs patch|minor|major [--dry-run] [--notes "text"]
174
174
 
175
175
  | 项 | 值 |
176
176
  |---|---|
177
- | 插件版本 | `0.5.0` |
177
+ | 插件版本 | `0.6.0` |
178
178
  | 宿主区间 | `>=0.2.1-rc.1 <0.3.0`(`engines.dsh` 与 `dsh.compatibility.dsh`) |
179
179
  | 验证环境 | DSH `0.2.2-rc.5`(web profile)、Node `v24.22.2`、Linux x86_64 |
180
180
  | Node | `>=22.19`(CI:22 与 24) |
package/client.js CHANGED
@@ -1,12 +1,12 @@
1
1
  // Generated by scripts/build-client.mjs from src/client/ — do not edit.
2
- // DSH client module: dsh-agent-control-center@0.5.0 (13 i18n fragments, 12 pages)
2
+ // DSH client module: dsh-agent-control-center@0.6.0 (13 i18n fragments, 12 pages)
3
3
  window.__ModuleLoader__.load({
4
4
  id: "dsh-agent-control-center",
5
5
  factory(require) {
6
6
  'use strict'
7
7
  const React = require('react')
8
8
  const h = React.createElement
9
- const ACC_VERSION = "0.5.0"
9
+ const ACC_VERSION = "0.6.0"
10
10
  /* ---- kernel.js ---- */
11
11
  /* ---------------------------------------------------------------------------
12
12
  * ACC kernel — shared runtime attached to every page script.
@@ -3683,6 +3683,7 @@ ACC.addI18n({
3683
3683
  'tools.scanned': '已扫描会话',
3684
3684
  'tools.available': '可用',
3685
3685
  'tools.historyTruncated': '统计已截断',
3686
+ 'tools.historyLoading': '历史调用统计加载中:上面已是注册表实时结果,本块稍后填充(扫描会话需要数秒)',
3686
3687
  'tools.historyEmpty': '扫描窗口内没有任何工具调用记录',
3687
3688
  'tools.truncatedList': '清单已截断',
3688
3689
  'tools.calls': '调用次数',
@@ -3845,6 +3846,7 @@ ACC.addI18n({
3845
3846
  'tools.scanned': 'sessions scanned',
3846
3847
  'tools.available': 'Available',
3847
3848
  'tools.historyTruncated': 'statistics truncated',
3849
+ 'tools.historyLoading': 'Loading call history: the registry above is live; this block fills in after scanning sessions',
3848
3850
  'tools.historyEmpty': 'No tool call events in the scanned window',
3849
3851
  'tools.truncatedList': 'inventory truncated',
3850
3852
  'tools.calls': 'Calls',
@@ -12450,11 +12452,21 @@ const DRIFT_TONE = { 'startup-failed': 'danger', 'enabled-not-running': 'warn',
12450
12452
  // One-shot bypass flags: the first load may use the cache, an explicit
12451
12453
  // Refresh must see fresh host state.
12452
12454
  const forceList = ACC.useRef(false)
12455
+ const forceHistory = ACC.useRef(false)
12453
12456
  const forceDetail = ACC.useRef(false)
12457
+ // The page paints from the registry view, which answers in well under a
12458
+ // second; the history fold scans sessions and takes seconds, so it is a
12459
+ // second request whose result swaps in when it arrives. Both start at once,
12460
+ // so waiting for the history never delays the first paint.
12454
12461
  const list = ACC.useAsync((context) => {
12455
12462
  const refresh = forceList.current
12456
12463
  forceList.current = false
12457
- return ACC.api('tools.list', { days, agentId: agentId.length > 0 ? agentId : undefined, includePresets: true, ...(refresh ? { refresh: true } : {}) }, context)
12464
+ return ACC.api('tools.list', { days, agentId: agentId.length > 0 ? agentId : undefined, includePresets: true, includeHistory: false, ...(refresh ? { refresh: true } : {}) }, context)
12465
+ }, [days, agentId])
12466
+ const historyLoad = ACC.useAsync((context) => {
12467
+ const refresh = forceHistory.current
12468
+ forceHistory.current = false
12469
+ return ACC.api('tools.list', { days, agentId: agentId.length > 0 ? agentId : undefined, includePresets: true, includeHistory: true, ...(refresh ? { refresh: true } : {}) }, context)
12458
12470
  }, [days, agentId])
12459
12471
  const detail = ACC.useAsync(
12460
12472
  (context) => {
@@ -12516,7 +12528,9 @@ const DRIFT_TONE = { 'startup-failed': 'danger', 'enabled-not-running': 'warn',
12516
12528
 
12517
12529
  if (list.status === 'loading') return h(C.Loading, { label: t('common.loading') })
12518
12530
  if (list.status === 'error') return h(C.ErrorBox, { error: list.error, onRetry: list.reload, label: t('tools.loadFailed') })
12519
- const data = list.data
12531
+ const data = historyLoad.status === 'ready' ? historyLoad.data : list.data
12532
+ // A history failure keeps the registry view usable and says why.
12533
+ const historyPending = historyLoad.status === 'loading'
12520
12534
  if (data.available === false) {
12521
12535
  return h(C.Empty, {
12522
12536
  title: t('tools.registryUnavailable'),
@@ -12555,8 +12569,10 @@ const DRIFT_TONE = { 'startup-failed': 'danger', 'enabled-not-running': 'warn',
12555
12569
  key: 'r',
12556
12570
  onClick: () => {
12557
12571
  forceList.current = true
12572
+ forceHistory.current = true
12558
12573
  if (selected.length > 0) forceDetail.current = true
12559
12574
  list.reload()
12575
+ historyLoad.reload()
12560
12576
  if (selected.length > 0) detail.reload()
12561
12577
  },
12562
12578
  ariaLabel: t('tools.refreshList'),
@@ -12639,7 +12655,9 @@ const DRIFT_TONE = { 'startup-failed': 'danger', 'enabled-not-running': 'warn',
12639
12655
  ),
12640
12656
  ),
12641
12657
  h(InfoPanel, { t, items: [t('tools.statusLegend'), t('tools.probeNotice'), t('tools.hostNotesFold')] }),
12642
- history.available === false
12658
+ historyPending
12659
+ ? h(C.Notice, { tone: 'info' }, t('tools.historyLoading'))
12660
+ : history.available === false
12643
12661
  ? h(
12644
12662
  'div',
12645
12663
  { className: 'acc-muted', style: { fontSize: '11px', display: 'flex', flexDirection: 'column', gap: '2px' } },
@@ -39,7 +39,7 @@ dsh-agent-control-center/
39
39
  | HTTP 前缀 | `/__agent-control-center`(GET `/health`,POST `/api`) |
40
40
  | 自有存储 | `$DSH_HOME/dsh-agent-control-center/` |
41
41
  | locale 命名空间 | `acc` |
42
- | 版本 | `0.5.0` |
42
+ | 版本 | `0.6.0` |
43
43
  | 兼容声明 | `dsh.compatibility.dsh = ">=0.2.1-rc.1 <0.3.0"`,`engines.dsh` 同区间 |
44
44
 
45
45
  `package.json` 关键字段(照抄,勿改语义):
@@ -392,3 +392,45 @@ curl -s http://127.0.0.1:38080/__agent-control-center/health
392
392
  「声明」一侧来自 `pluginManager` 与 `configEditor` 的投影,无法覆盖「patch 里写了但
393
393
  Loader 从未见过」的行(两类服务都看不到它们)。
394
394
  - bundle 检查单次 6.6 s,因此默认关闭;页面用按钮显式触发。
395
+
396
+ ---
397
+
398
+ # 附:0.6.0 验收补充(2026-11-29,宿主 0.2.3-alpha.3)
399
+
400
+ 0.6.0 处理 0.5.0 报告里挂着的两项:Tools 首屏 5.5 s,以及写路径的端到端证据。
401
+
402
+ ## 测试
403
+
404
+ - `node --test tests/*.test.mjs` → **374 / 374 pass**(0.5.0 为 373)。
405
+ - 新增 1 个契约用例:注册表视图(`includeHistory:false`)**完全不读会话**——
406
+ 让 `listSessions` 直接抛错并断言 `readSession` 零调用。
407
+
408
+ ## Tools 首屏(真机,357 个会话)
409
+
410
+ | 指标 | 改前 | 改后 |
411
+ |---|---|---|
412
+ | 首屏出现工具行 | 5,561 ms(接受脚本)/ 4,125 ms(轮询测量) | **90 ms**(MutationObserver) |
413
+ | 历史块填充 | 阻塞首屏 | 3,970 ms,不阻塞 |
414
+
415
+ 浏览器侧 0 console error;历史未到达时显示「历史调用统计加载中」而不是整页 Loading。
416
+
417
+ ## 写路径 E2E(真机,脚本 `scripts/write-regression.py`)
418
+
419
+ `11 / 11` 通过,目标为 17,855 字节的既有指令文件:
420
+
421
+ - 保存接受 → 磁盘内容**逐字节**等于提交内容;备份 3 → 4 条;
422
+ - 过期 `expectedHash` 再次保存被拒(`conflict`,提示「磁盘未被覆盖」);
423
+ - 从最新备份恢复 → 17,855 字节、sha256 回到 `4c5ad6e8…`;恢复自身也留下备份;
424
+ - 结束后仓库 `git status` 干净、sha256 与测试前一致。
425
+
426
+ ## 交互回归脚本化
427
+
428
+ `scripts/interaction-regression.py` 固化 12 页 24 条断言(`--token/--base/--out`),
429
+ 0.5.0 的成绩 24/24 可用该脚本复跑;它不进 `verify.mjs`(需要 Playwright + 运行中的宿主)。
430
+
431
+ ## 未验证 / 已知限制
432
+
433
+ - **浏览器驱动的写路径尚未覆盖**:UI 编辑器展示的是组装后视图(实测 41,104 字符 ≠ 文件 17,855 字节),
434
+ 按原文 hash 比对必然失败;这一轮只做到 API 级 E2E。详见 `docs/15-WRITE-REGRESSION.md`。
435
+ - 写路径要求目标是**会话工作目录内的既有指令文件**;`/tmp` fixture 不是会话 cwd 时写入会被拒(既有边界)。
436
+ - Tools 历史块仍需 3.9–5.4 s(冷);本轮只解决了「不阻塞首屏」,没有降低扫描成本。
package/docs/07-GUIDE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 用户指南:从「我想做什么」出发
2
2
 
3
- > 适用版本 **0.5.0**,目标宿主 DSH **0.2.2-rc.5**(兼容区间 `>=0.2.1-rc.1 <0.3.0`)。
3
+ > 适用版本 **0.6.0**,目标宿主 DSH **0.2.2-rc.5**(兼容区间 `>=0.2.1-rc.1 <0.3.0`)。
4
4
  > 本文按**任务**组织,只描述本插件在真实界面上能做什么、失败时看到什么、提示是什么意思。
5
5
  > 安装、权限边界、配置字段和刻意限制见 [README.zh.md](../README.zh.md);
6
6
  > 内部实现(模块、请求流、存储、扩展点)见 [09-ARCHITECTURE.md](09-ARCHITECTURE.md);
@@ -42,7 +42,7 @@ DSH Web GUI (browser)
42
42
 
43
43
  ### 2.1 入口 `index.js`
44
44
 
45
- - 导出:`name`、`VERSION`(`0.5.0`,与 `package.json` 同步)、`HTTP_PREFIX`(`/__agent-control-center`)、`inject = []`、`apply(ctx, rawConfig)`。
45
+ - 导出:`name`、`VERSION`(`0.6.0`,与 `package.json` 同步)、`HTTP_PREFIX`(`/__agent-control-center`)、`inject = []`、`apply(ctx, rawConfig)`。
46
46
  - `inject = []` 是硬约束:**任何宿主服务缺失都不阻止插件激活**,只让对应模块降级为 PARTIAL/BLOCKED。
47
47
  - 启动序列(`apply`):
48
48
  1. `normalizeConfig(rawConfig)`:未知字段/类型错误/越界 → **加载期直接抛错**(fail loud,不做静默兜底);
@@ -0,0 +1,79 @@
1
+ # 逐页交互回归(12 页,v0.5.0,宿主 0.2.3-alpha.3)
2
+
3
+ > 真实 Chrome headless,隔离 profile `accverify`,2026-11-29。脚本逐页执行真实交互并断言页面结果;每个断言记录实际数值。
4
+
5
+ ## 结果:24 / 24 通过
6
+
7
+ | 页面 | 交互 | 结果 | 实际 |
8
+ | --- | --- | --- | --- |
9
+ | Overview | stat tiles render | PASS | 6 tiles |
10
+ | Overview | stat tile navigates | PASS | sessions |
11
+ | AGENTS.md | chain renders | PASS | 1405 chars |
12
+ | AGENTS.md | row selection | PASS | 3 rows |
13
+ | Tools | search narrows | PASS | |
14
+ | Tools | row expands | PASS | 1 open |
15
+ | Tools | Esc collapses row | PASS | |
16
+ | Tools | Esc keeps Settings | PASS | |
17
+ | Sessions | archived tab | PASS | |
18
+ | Sessions | select shows toolbar | PASS | |
19
+ | Usage | date switch re-renders | PASS | |
20
+ | Agent info | presets view | PASS | |
21
+ | Agent info | export view | PASS | |
22
+ | Instruction | session selector | PASS | 51 options |
23
+ | Instruction | session view renders | PASS | |
24
+ | Templates | detail opens | PASS | 1882 -> 1882, dialogs=1 |
25
+ | Diagnostics | filter applied | PASS | |
26
+ | Health | drift tiles | PASS | |
27
+ | Health | drift counts | PASS | |
28
+ | Health | bundle check result | PASS | TY REASONS
29
+ The compatibility layer reported no reasons
30
+ No reasons usually means the current host version passed validation; still check readOnly before writing. |
31
+ | Export | session selected | PASS | |
32
+ | Export | preview produced | PASS | 3433 chars |
33
+ | Restart | scan runs | PASS | 931 chars |
34
+ | global | console errors | PASS | [] |
35
+
36
+ ## 首屏耗时(同一会话,暖缓存)
37
+
38
+ | 页面 | 耗时 | 文本字符 |
39
+ | --- | --- | --- |
40
+ | Overview | 4 ms | 1740 |
41
+ | AGENTS.md | 1080 ms | 1405 |
42
+ | Tools | 5561 ms | 4114 |
43
+ | Sessions | 517 ms | 6573 |
44
+ | Usage | 27 ms | 2606 |
45
+ | Agent info | 508 ms | 1313 |
46
+ | Instruction preview | 1032 ms | 60442 |
47
+ | Templates | 8 ms | 1882 |
48
+ | Diagnostics | 1532 ms | 9907 |
49
+ | Health check | 1544 ms | 23903 |
50
+ | Export | 519 ms | 3434 |
51
+ | Restart & Resume | 6 ms | 931 |
52
+
53
+ ## 覆盖的交互
54
+
55
+ - **Overview**:6 张指标卡渲染;点击一张跳转到对应页(实测跳到 sessions)。
56
+ - **AGENTS.md**:指令链渲染(3 个候选文件);点击文件行选中。
57
+ - **Tools**:搜索框收窄结果;展开行;Esc 收起行**且设置面板不关闭**(v0.4.1 修复项回归通过)。
58
+ - **Sessions**:归档/全部 tab 切换;勾选行出现「已选」工具条。
59
+ - **Usage**:日期控件切换后重新渲染。
60
+ - **Agent info**:Presets 视图;Export 视图(`exportedAt`/声明不含密钥)。
61
+ - **Instruction preview**:By session 视图、51 个会话选项、指令块视图渲染。
62
+ - **Templates**:点击模板打开详情(宿主模态框,`dialogs=1`)。
63
+ - **Diagnostics**:Warning 过滤器生效。
64
+ - **Health check**:漂移块四宫格(225 行 / 222 可寻址 / 222 profile 管辖 / 0 漂移);点「检查 bundle 安装状态」后出现 **2 条真实漂移**(`Declared but not installed`)。
65
+ - **Export**:选择会话、生成预览(3,433 字符)。
66
+ - **Restart & Resume**:扫描按钮执行。
67
+ - **全局**:0 console error / 0 pageerror。
68
+
69
+ ## 在这轮发现并修掉的真问题
70
+
71
+ | 来源 | 问题 | 处理 |
72
+ | --- | --- | --- |
73
+ | 浏览器验收 | 体检页新加的漂移块引用了未定义的 `FLEX_WRAP_STYLE`,整个设置面板白屏 | 补上常量;单测与 i18n 校验都没发现,只有真实浏览器能抓到 |
74
+ | 交互回归脚本 | 5 条「失败」全部是脚本自身断言问题(如浅层渲染的 `No drift` 被当成深层结果、模板详情在宿主模态框内) | 修正断言;修正后 24/24 |
75
+
76
+ ## 已知未覆盖
77
+
78
+ - Tools 首屏 5.5 s(冷历史扫描,25 会话 / 5 s 预算);热读 11 ms。下一轮计划把历史统计从首屏拆出。
79
+ - 编辑器写路径(AGENTS.md 保存、模板应用、恢复)本轮仍未在浏览器里做端到端写测试,只做了只读交互;写路径的证据来自单元测试与 0.2.x 的真机保存记录。
@@ -0,0 +1,43 @@
1
+ # 写路径回归(保存 / 备份 / 乐观并发 / 恢复)
2
+
3
+ > 脚本:`scripts/write-regression.py`(真实 HTTP + 真实文件,需要运行中的实例与一个会话工作目录)。
4
+ > 只读的交互回归见 `scripts/interaction-regression.py` 与 `docs/14-INTERACTION-REGRESSION-0.5.0.md`。
5
+
6
+ ## 为什么写路径必须单独测
7
+
8
+ 只读页面的 bug 最多让人看到错数字;写路径的 bug 会**改掉用户的指令文件**。所以这里不看文案,只验字节:
9
+
10
+ 1. 保存前文件 sha256 → 保存后的磁盘内容必须**逐字节**等于提交内容;
11
+ 2. 保存必须**先**把旧内容写进备份,备份名要能在随后的 `agents.backups` 里读到;
12
+ 3. 用**过期 hash** 再保存必须被拒绝,且磁盘不能被覆盖(乐观并发的核心保证);
13
+ 4. 用最新备份恢复后,文件必须回到原始字节;
14
+ 5. 恢复本身也要留下自己的备份(不然后悔两步就无从回溯)。
15
+
16
+ ## 结果(2026-11-29,accverify,宿主 0.2.3-alpha.3)
17
+
18
+ `11 / 11` 通过,目标文件 17,855 字节:
19
+
20
+ | 步骤 | 结果 |
21
+ |---|---|
22
+ | `agents.summary` | 可用,`cwd=/home/ova/dsh` |
23
+ | `agents.backups` 初读 | 3 条既有备份 |
24
+ | `agents.save`(带正确 `expectedHash`) | 接受,返回 `hash=55f68dd2…`、`backup=2026-11-29T13-56-36-663Z.md` |
25
+ | 磁盘内容与提交内容 | 逐字节一致 |
26
+ | 备份数量 | 3 → 4 |
27
+ | `agents.save`(**过期** `expectedHash`) | `conflict`:`expected=4c5ad6e8… actual=55f68dd2…`,提示「磁盘未被覆盖」 |
28
+ | `agents.restore`(最新备份) | 接受,并生成自己的备份 |
29
+ | 恢复后的磁盘内容 | **17,855 字节,sha256 回到 `4c5ad6e8…`** |
30
+
31
+ 收尾检查:仓库 `git status AGENTS.md` 干净、sha256 与测试前一致;全部测试备份落在插件自己的存储目录(`~/.dsh/dsh-agent-control-center/backups/`),没有散落到别处。
32
+
33
+ ## 已知约束(务必先读)
34
+
35
+ - **目标必须是会话工作目录内的既有指令文件**。插件按宿主会话 cwd 授权写入;`/tmp` 下的 fixture 不是任何会话的 cwd 时会被 `forbidden`(这是 0.2.x 起就有的边界,不是本轮新增)。
36
+ - 脚本拒绝在不存在的文件上运行(保存管线也只更新既有文件),所以它永远不可能「创建」一个指令文件。
37
+ - 脚本会把原始字节存到 `--out/original.bak`;若中途被杀,用这份文件手工还原,并核对 sha256。
38
+
39
+ ## 尚未覆盖:UI 端写路径
40
+
41
+ 尝试过用浏览器驱动编辑器保存(填 `textarea` → 点 Save → 校验磁盘),结果只 5/8:编辑区显示的是**组装后的视图**(实测 41,104 字符),与文件原文(17,855 字节)不是同一份字节,脚本按原文 hash 去比对自然失败;同一轮还留下了一处 28 字节的标记,已用安全副本还原并核对 sha256。
42
+
43
+ 结论:**浏览器写路径尚未被可靠覆盖**。下一步要么先弄清编辑器展示的到底是哪一份内容(组装视图 or 原文),要么把 UI 保存改成走「原文编辑器」再测。在此之前的写路径证据只有上面这份 API 级 E2E + 单元测试。
@@ -0,0 +1,36 @@
1
+ # Tools 页首屏:从 5.5 s 降到 90 ms
2
+
3
+ ## 问题
4
+
5
+ Tools 页首屏要等 `tools.list` 完成,而该调用把两件成本完全不同的事绑在一起:
6
+
7
+ | 部分 | 成本 | 说明 |
8
+ |---|---|---|
9
+ | 注册表视图 | ~150 ms | `tools.getAll()` + agents/presets 视图,纯内存 |
10
+ | 历史调用统计 | 3.9–5.4 s(冷) | 扫 25 个会话的 `tool/call`、`tool/result`,受 5 s 时间预算约束 |
11
+
12
+ 用户看到的却是「整页 Loading 5.5 秒」,尽管列表 150 ms 就能画出来。
13
+
14
+ ## 改法
15
+
16
+ 页面发**两个并行请求**,各自渲染:
17
+
18
+ 1. `tools.list({ includeHistory: false })` → 注册表 + 三层状态(注册/可见/可调用);一到就画。
19
+ 2. `tools.list({ includeHistory: true })` → 历史徽标、错误分布、会话计数;到了再替换内容。
20
+
21
+ 未到达时页面显示一条说明(`tools.historyLoading`),而不是把整页按住。两个请求共享服务端的注册表缓存,历史折叠还有 60 s 记忆化(v0.4.1 起),所以第二个请求基本不重复扫描。
22
+
23
+ ## 实测(accverify,12 模块,357 个会话)
24
+
25
+ | 指标 | 改前 | 改后 |
26
+ |---|---|---|
27
+ | 首屏(出现工具行) | 5,561 ms(接受脚本) / 4,125 ms(MutationObserver) | **90 ms** |
28
+ | 历史块填充 | 同首屏 | 3,970 ms(不阻塞) |
29
+
30
+ 测量方式:`MutationObserver` 记录 `data-acc-page="tools"` 后第一次出现工具行按钮的时间戳,避开了轮询脚本自身的往返开销(此前用 100 ms 轮询测出的 4.1 s 主要是测量误差)。
31
+
32
+ ## 保留的契约
33
+
34
+ - 首屏请求**完全不读会话**:新增单测 `tools.list: the registry view answers without reading sessions at all` 让 `listSessions` 直接抛错、并断言 `readSession` 零调用。
35
+ - 历史不可用时(`includeHistory:false` 或没有 `sessionQuery`)行状态显示 `unavailable`/`unknown`,绝不显示 0。
36
+ - 刷新按钮会同时重取两份数据(`refresh:true` 绕过缓存与历史记忆化)。
package/index.js CHANGED
@@ -15,7 +15,7 @@ import { createRegistry } from './lib/core/registry.js'
15
15
 
16
16
  export const name = 'dsh-agent-control-center'
17
17
  /** Plugin version, mirrored in package.json. */
18
- export const VERSION = '0.5.0'
18
+ export const VERSION = '0.6.0'
19
19
  /** Browser transport prefix. The client fetches it document-relative. */
20
20
  export const HTTP_PREFIX = '/__agent-control-center'
21
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agent-control-center",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "DSH Agent Control Center: AGENTS.md editing with backups, tool inventory, sessions, real token usage, agent metadata, diagnostics and templates in one settings page.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -0,0 +1,278 @@
1
+ #!/usr/bin/env python3
2
+ """Per-page interaction regression for the Agent Control Center settings pages.
3
+
4
+ Drives a real Chrome against a running verification instance and asserts one or
5
+ two concrete interactions per page. It is intentionally not part of
6
+ `node scripts/verify.mjs`: it needs Playwright, a Chrome binary, and a live
7
+ host, so it runs on demand instead of on every gate.
8
+
9
+ Usage:
10
+ python3 scripts/interaction-regression.py --token <web token> [--base http://127.0.0.1:38080] [--out /tmp/acc-interaction]
11
+
12
+ Exit code 0 means every assertion passed; 1 means at least one failed (the JSON
13
+ result file lists them).
14
+ """
15
+ import argparse, json, os, sys, time
16
+
17
+
18
+ def parse_args():
19
+ parser = argparse.ArgumentParser()
20
+ parser.add_argument("--token", required=True)
21
+ parser.add_argument("--base", default="http://127.0.0.1:38080")
22
+ parser.add_argument("--out", default="/tmp/acc-interaction")
23
+ parsed = parser.parse_args()
24
+ os.makedirs(parsed.out, exist_ok=True)
25
+ return parsed
26
+
27
+
28
+ args = parse_args()
29
+
30
+
31
+ results, console = [], []
32
+
33
+ def rec(page, step, ok, detail=""):
34
+ results.append({"page": page, "step": step, "ok": bool(ok), "detail": str(detail)[:300]})
35
+ print(f" {'PASS' if ok else 'FAIL'} {page} / {step}{'' if detail == '' else ' — ' + str(detail)[:120]}")
36
+
37
+ def text(page):
38
+ return page.evaluate("() => document.querySelector('.acc-root')?.innerText || ''")
39
+
40
+ def wait_for(page, needle, seconds=30):
41
+ end = time.time() + seconds
42
+ while time.time() < end:
43
+ if needle in text(page): return True
44
+ page.wait_for_timeout(400)
45
+ return False
46
+
47
+ def nav(page, label):
48
+ item = page.locator(f'.acc-nav-item:has-text("{label}")').first
49
+ item.scroll_into_view_if_needed(timeout=4000)
50
+ item.click(timeout=4000)
51
+ page.wait_for_timeout(600)
52
+
53
+ with sync_playwright() as p:
54
+ b = p.chromium.launch(executable_path="/usr/bin/google-chrome", headless=True, args=["--no-sandbox", "--disable-dev-shm-usage"])
55
+ page = b.new_page(viewport={"width": 1440, "height": 1000}, locale="en-US")
56
+ page.on("console", lambda m: console.append((m.type, m.text[:200]) if m.type in ("error", "warning") else None))
57
+ page.on("pageerror", lambda e: console.append(("pageerror", str(e)[:300])))
58
+ page.goto(f"{args.base}/?token={args.token}", wait_until="domcontentloaded", timeout=60000)
59
+ end = time.time() + 60
60
+ while time.time() < end:
61
+ if page.evaluate("() => document.querySelector('[data-dsh-boot]') === null"): break
62
+ page.wait_for_timeout(400)
63
+ page.wait_for_timeout(2500)
64
+ for _ in range(8):
65
+ if page.evaluate("() => document.querySelectorAll('[role=dialog]').length") == 0: break
66
+ try: page.locator('button:has-text("Continue")').first.click(timeout=1000, force=True); page.wait_for_timeout(500); continue
67
+ except Exception: pass
68
+ try: page.locator('[aria-label="Close"]').first.click(timeout=1000, force=True); page.wait_for_timeout(500); continue
69
+ except Exception: page.keyboard.press("Escape"); page.wait_for_timeout(300)
70
+ for _ in range(3):
71
+ try:
72
+ page.locator('[aria-label="Account menu"]').first.click(timeout=4000, force=True); page.wait_for_timeout(700)
73
+ page.locator('[role=menuitem]:has-text("Settings")').first.click(timeout=4000); page.wait_for_timeout(1200)
74
+ page.get_by_text("Agent Control Center", exact=True).first.click(timeout=6000); page.wait_for_timeout(2200)
75
+ if "Overview" in text(page): break
76
+ except Exception: page.keyboard.press("Escape"); page.wait_for_timeout(400)
77
+
78
+ steps = 0
79
+ def safe(page, label, fn):
80
+ global steps
81
+ try:
82
+ fn()
83
+
84
+ except Exception as exc:
85
+ rec(label, "interaction", False, f"{type(exc).__name__}: {exc}")
86
+ page.keyboard.press("Escape")
87
+
88
+ # --- Overview: click a stat card and expect navigation ---
89
+ def overview_page():
90
+ nav(page, "Overview")
91
+ end = time.time() + 25
92
+ while time.time() < end and page.locator('.acc-root .acc-stat').count() == 0:
93
+ page.wait_for_timeout(500)
94
+ count = page.locator('.acc-root .acc-stat').count()
95
+ rec("Overview", "stat tiles render", count > 0, f"{count} tiles")
96
+ if count == 0: return
97
+ page.locator('.acc-root .acc-stat').first.click(timeout=5000); page.wait_for_timeout(1200)
98
+ rec("Overview", "stat tile navigates", page.evaluate("() => document.querySelector('.acc-root')?.getAttribute('data-acc-page')") != "overview",
99
+ page.evaluate("() => document.querySelector('.acc-root')?.getAttribute('data-acc-page')"))
100
+ safe(page, "Overview", overview_page)
101
+
102
+ # --- AGENTS.md: select a file row ---
103
+ def agents_page():
104
+ nav(page, "AGENTS.md")
105
+ if not wait_for(page, "AGENTS.md"):
106
+ rec("AGENTS.md", "list loaded", False, text(page)[:140]); return
107
+ time.sleep(4)
108
+ rec("AGENTS.md", "chain renders", len(text(page)) > 800, f"{len(text(page))} chars")
109
+ rows = page.locator('.acc-root button:has-text("AGENTS.md")')
110
+ if rows.count() == 0:
111
+ rec("AGENTS.md", "file rows", False, "no rows"); return
112
+ rows.first.click(timeout=5000); page.wait_for_timeout(900)
113
+ rec("AGENTS.md", "row selection", True, f"{rows.count()} rows")
114
+ safe(page, "AGENTS.md", agents_page)
115
+
116
+ # --- Tools: search + expand + Esc keeps Settings ---
117
+ def tools_page():
118
+ nav(page, "Tools")
119
+ if not wait_for(page, "tools", 5): pass
120
+ page.wait_for_timeout(2500)
121
+ search = page.locator('.acc-root input[aria-label="Search tools"]').first
122
+ search.fill("read"); page.wait_for_timeout(700)
123
+ rec("Tools", "search narrows", "read" in text(page).lower())
124
+ expand = page.locator('.acc-root button[aria-label^="Expand detail"]').first
125
+ if expand.count() == 0:
126
+ rec("Tools", "expand row", False, "no expand button"); return
127
+ expand.click(timeout=5000); page.wait_for_timeout(900)
128
+ opened = page.evaluate("() => document.querySelectorAll('.acc-root button[aria-label^=\\'Collapse detail\\']').length")
129
+ rec("Tools", "row expands", opened >= 1, f"{opened} open")
130
+ page.keyboard.press("Escape"); page.wait_for_timeout(700)
131
+ rec("Tools", "Esc collapses row", page.evaluate("() => document.querySelectorAll('.acc-root button[aria-label^=\\'Collapse detail\\']').length") == 0)
132
+ rec("Tools", "Esc keeps Settings", page.evaluate("() => document.querySelector('.acc-root') !== null"))
133
+ search.fill(""); page.wait_for_timeout(500)
134
+ safe(page, "Tools", tools_page)
135
+
136
+ # --- Sessions: archived tab + select + expand ---
137
+ def sessions_page():
138
+ nav(page, "Sessions")
139
+ wait_for(page, "Session list", 20)
140
+ tabs = page.locator('.acc-root button:has-text("Archived")')
141
+ if tabs.count() > 0:
142
+ tabs.first.click(timeout=5000); page.wait_for_timeout(1500)
143
+ rec("Sessions", "archived tab", "Archived" in text(page))
144
+ page.locator('.acc-root button:has-text("All chats")').first.click(timeout=5000); page.wait_for_timeout(1200)
145
+ box = page.locator('.acc-root input[type=checkbox]').first
146
+ if box.count() > 0:
147
+ box.check(timeout=4000, force=True); page.wait_for_timeout(800)
148
+ rec("Sessions", "select shows toolbar", "selected" in text(page).lower())
149
+ safe(page, "Sessions", sessions_page)
150
+
151
+ # --- Usage: date switch ---
152
+ def usage_page():
153
+ nav(page, "Usage")
154
+ wait_for(page, "Usage", 10); page.wait_for_timeout(1200)
155
+ before = text(page)
156
+ sel = page.locator('.acc-root input[type=date], .acc-root select').first
157
+ if sel.count() == 0:
158
+ rec("Usage", "date control", False, "no date control"); return
159
+ try:
160
+ sel.fill("2026-11-01") if page.evaluate("() => document.querySelector('.acc-root input[type=date]') !== null") else sel.select_option(index=1)
161
+ page.wait_for_timeout(1400)
162
+ except Exception: pass
163
+ rec("Usage", "date switch re-renders", len(text(page)) > 500)
164
+ safe(page, "Usage", usage_page)
165
+
166
+ # --- Agent info: presets tab + export tab ---
167
+ def meta_page():
168
+ nav(page, "Agent info")
169
+ wait_for(page, "Agents", 10); page.wait_for_timeout(1200)
170
+ presets = page.locator('.acc-root button:has-text("Presets")').first
171
+ if presets.count() > 0:
172
+ presets.click(timeout=5000); page.wait_for_timeout(1500)
173
+ rec("Agent info", "presets view", "Presets" in text(page))
174
+ export_tab = page.locator('.acc-root button:has-text("Export")').last
175
+ if export_tab.count() > 0:
176
+ export_tab.click(timeout=5000); page.wait_for_timeout(1500)
177
+ rec("Agent info", "export view", "exportedAt" in text(page) or "Export configuration" in text(page))
178
+ safe(page, "Agent info", meta_page)
179
+
180
+ # --- Instruction: session view + compare ---
181
+ def instruction_page():
182
+ nav(page, "Instruction preview")
183
+ wait_for(page, "Instruction chain", 20); page.wait_for_timeout(1500)
184
+ by_session = page.locator('.acc-root button:has-text("By session")').first
185
+ if by_session.count() == 0:
186
+ rec("Instruction", "session tab", False, "no tab"); return
187
+ by_session.click(timeout=5000); page.wait_for_timeout(2500)
188
+ sel = page.locator('.acc-root select').first
189
+ if sel.count() > 0:
190
+ options = sel.locator('option').count()
191
+ rec("Instruction", "session selector", options > 1, f"{options} options")
192
+ rec("Instruction", "session view renders", "Session selection" in text(page) or "session" in text(page).lower())
193
+ safe(page, "Instruction", instruction_page)
194
+
195
+ # --- Templates: open a template detail ---
196
+ def templates_page():
197
+ nav(page, "Templates")
198
+ wait_for(page, "Template center", 15); page.wait_for_timeout(1200)
199
+ cards = page.locator('.acc-root [data-template-id], .acc-root .acc-list-item button, .acc-root button[aria-label]')
200
+ if cards.count() == 0:
201
+ rec("Templates", "list renders", False, text(page)[:120]); return
202
+ before = len(text(page))
203
+ cards.first.click(timeout=5000); page.wait_for_timeout(2500)
204
+ after = text(page)
205
+ # A template detail may render in a host modal (ported outside .acc-root).
206
+ dialog = page.evaluate("() => document.querySelectorAll('[role=dialog]').length")
207
+ rec("Templates", "detail opens", len(after) > before or "Apply" in after or dialog > 0,
208
+ f"{before} -> {len(after)}, dialogs={dialog}")
209
+ safe(page, "Templates", templates_page)
210
+
211
+ # --- Diagnostics: warn filter ---
212
+ def diagnostics_page():
213
+ nav(page, "Diagnostics")
214
+ wait_for(page, "System diagnostics", 20); page.wait_for_timeout(1500)
215
+ warn = page.locator('.acc-root button:has-text("Warning")').first
216
+ if warn.count() == 0:
217
+ rec("Diagnostics", "warning filter", False, "no filter"); return
218
+ warn.click(timeout=5000); page.wait_for_timeout(1200)
219
+ rec("Diagnostics", "filter applied", "Warning" in text(page))
220
+ safe(page, "Diagnostics", diagnostics_page)
221
+
222
+ # --- Health: drift block + bundle button ---
223
+ def health_page():
224
+ nav(page, "Health check")
225
+ got = wait_for(page, "Drift items", 30) or wait_for(page, "Plugin rows", 15)
226
+ rec("Health", "drift tiles", got)
227
+ if not got: return
228
+ rec("Health", "drift counts", "Addressable" in text(page) and "Profile-owned" in text(page))
229
+ btn = page.locator('.acc-root button:has-text("Check bundle installation")')
230
+ if btn.count() == 0:
231
+ rec("Health", "bundle button", False, "missing"); return
232
+ # The button is disabled while the first read is in flight.
233
+ for _ in range(30):
234
+ if not btn.first.is_disabled(): break
235
+ page.wait_for_timeout(500)
236
+ btn.first.scroll_into_view_if_needed(); btn.first.click(timeout=6000)
237
+ # The shallow render already says "No drift", so wait for the deep answer
238
+ # to arrive (its own marker), not for any of the two states.
239
+ end = time.time() + 40
240
+ while time.time() < end:
241
+ if "Declared but not installed" in text(page): break
242
+ page.wait_for_timeout(500)
243
+ rec("Health", "bundle check result", "Declared but not installed" in text(page), text(page)[-160:])
244
+ safe(page, "Health", health_page)
245
+
246
+ # --- Export: select a session and generate ---
247
+ def export_page():
248
+ nav(page, "Export")
249
+ wait_for(page, "Session", 15); page.wait_for_timeout(1500)
250
+ sel = page.locator('.acc-root select').first
251
+ if sel.count() > 0:
252
+ sel.select_option(index=1); page.wait_for_timeout(1500)
253
+ rec("Export", "session selected", True)
254
+ gen = page.locator('.acc-root button:has-text("Generate"), .acc-root button:has-text("Export")').first
255
+ if gen.count() == 0:
256
+ rec("Export", "generate", False, "no button"); return
257
+ gen.click(timeout=6000); page.wait_for_timeout(3000)
258
+ rec("Export", "preview produced", len(text(page)) > 800, f"{len(text(page))} chars")
259
+ safe(page, "Export", export_page)
260
+
261
+ # --- Restart & Resume: scan ---
262
+ def recovery_page():
263
+ nav(page, "Restart & Resume")
264
+ wait_for(page, "Restart", 10); page.wait_for_timeout(1200)
265
+ scan = page.locator('.acc-root button:has-text("Scan"), .acc-root button:has-text("Refresh")').first
266
+ if scan.count() == 0:
267
+ rec("Restart", "scan button", False, "none"); return
268
+ scan.click(timeout=6000); page.wait_for_timeout(2500)
269
+ rec("Restart", "scan runs", len(text(page)) > 300, f"{len(text(page))} chars")
270
+ safe(page, "Restart", recovery_page)
271
+
272
+ page.screenshot(path=f"{args.out}/final.png")
273
+ bad = [c for c in console if c is not None and c[0] in ("error", "pageerror")]
274
+ rec("global", "console errors", len(bad) == 0, json.dumps(bad[:3], ensure_ascii=False)[:240])
275
+ failed = [r for r in results if not r["ok"]]
276
+ print(f"RESULT {len(results) - len(failed)}/{len(results)} passed")
277
+ open(f"{args.out}/results.json", "w").write(json.dumps(results, ensure_ascii=False, indent=1))
278
+ b.close()
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env python3
2
+ """Write-path end-to-end regression: save, backup, optimistic concurrency, restore.
3
+
4
+ Points at ONE existing instruction file inside a directory that is a session
5
+ working directory of the running verification instance. The file is restored to
6
+ its original bytes before the script exits; the caller should check that
7
+ afterwards (the script prints the final sha256).
8
+
9
+ Usage:
10
+ python3 scripts/write-regression.py --token <web token> --cwd <session cwd> --file <instruction file> [--base ...]
11
+
12
+ Refuses to run when the target does not exist so it can never create one.
13
+ """
14
+ import argparse, hashlib, json, os, subprocess, sys, time
15
+
16
+ def parse_args():
17
+ parser = argparse.ArgumentParser()
18
+ parser.add_argument("--token", required=True)
19
+ parser.add_argument("--cwd", required=True, help="a session working directory of the running instance")
20
+ parser.add_argument("--file", required=True, help="absolute path of an existing instruction file")
21
+ parser.add_argument("--base", default="http://127.0.0.1:38080")
22
+ parser.add_argument("--out", default="/tmp/acc-write-regression")
23
+ return parser.parse_args()
24
+
25
+ args = parse_args()
26
+ os.makedirs(args.out, exist_ok=True)
27
+
28
+ results = []
29
+
30
+
31
+ def rec(step, ok, detail=''):
32
+ results.append((step, bool(ok), str(detail)[:200]))
33
+ print(f" {'PASS' if ok else 'FAIL'} {step}{'' if detail == '' else ' — ' + str(detail)[:140]}")
34
+
35
+ def login():
36
+ subprocess.run(['curl', '-sS', '-m', '10', '-c', J, '-o', '/dev/null',
37
+ f'{args.base}/?token={args.token}'], check=False, capture_output=True)
38
+ time.sleep(2)
39
+
40
+
41
+ def api(method, params=None, timeout=120):
42
+ body = json.dumps({'method': method, 'params': params or {}})
43
+ t0 = time.time()
44
+ out = subprocess.run(['curl','-sS','-m',str(timeout),'-b',J,'-H','Content-Type: application/json','-X','POST',f'{B}/api','-d',body], capture_output=True, text=True)
45
+ try: payload = json.loads(out.stdout)
46
+ except Exception: payload = {'ok': False, 'raw': out.stdout[:120]}
47
+ payload['_ms'] = round((time.time()-t0)*1000)
48
+ return payload
49
+
50
+ CWD = args.cwd
51
+ TARGET = args.file
52
+ J = os.path.join(args.out, 'cookies.txt')
53
+ B = args.base.rstrip('/') + '/__agent-control-center'
54
+
55
+
56
+ def content_of(path):
57
+ return open(path, 'rb').read()
58
+
59
+
60
+ original = content_of(TARGET)
61
+ original_hash = hashlib.sha256(original).hexdigest()
62
+ open(os.path.join(args.out, 'original.bak'),'wb').write(original)
63
+ login()
64
+ print('target bytes:', len(original), 'sha256:', original_hash[:16])
65
+
66
+ live_before = content_of(TARGET)
67
+
68
+ # 1) Larger content, then a save through the real pipeline.
69
+ marker = f"\n\n<!-- write-e2e {time.strftime('%H%M%S')} -->\n"
70
+ edited = original.decode('utf-8') + marker
71
+ base = api('agents.summary')
72
+ rec('summary available', base.get('ok') is True, (base.get('value') or {}).get('cwd'))
73
+
74
+ backups_before = api('agents.backups', {'path': TARGET, 'cwd': CWD})
75
+ before_count = len(((backups_before.get('value') or {}).get('items')) or [])
76
+ rec('backups readable', backups_before.get('ok') is True, f'{before_count} existing')
77
+
78
+ save = api('agents.save', {'path': TARGET, 'cwd': CWD, 'content': edited, 'expectedHash': original_hash})
79
+ rec('save accepted', save.get('ok') is True, json.dumps(save.get('error'), ensure_ascii=False)[:120])
80
+ saved_hash = None
81
+ if save.get('ok'):
82
+ saved_hash = (save.get('value') or {}).get('hash')
83
+ rec('saved bytes match', content_of(TARGET).decode('utf-8') == edited, f'hash={saved_hash[:16] if saved_hash else None}')
84
+ rec('backup created', save.get('ok') and (save.get('value') or {}).get('backup') not in (None, ''), json.dumps((save.get('value') or {}).get('backup'))[:80])
85
+
86
+ after = api('agents.backups', {'path': TARGET, 'cwd': CWD})
87
+ after_count = len(((after.get('value') or {}).get('items')) or [])
88
+ rec('backup count grew', after_count > before_count, f'{before_count} -> {after_count}')
89
+
90
+ # 2) Stale-hash save must be refused (optimistic concurrency).
91
+ stale = api('agents.save', {'path': TARGET, 'cwd': CWD, 'content': edited + '\nstale\n', 'expectedHash': original_hash})
92
+ rec('stale hash refused', stale.get('ok') is False and (stale.get('error') or {}).get('code') in ('conflict', 'bad_request'), json.dumps(stale.get('error'), ensure_ascii=False)[:140])
93
+
94
+ # 3) Restore the newest backup and confirm exact bytes.
95
+ newest = ((after.get('value') or {}).get('items') or [{}])[0]
96
+ name = newest.get('name')
97
+ restore = api('agents.restore', {'path': TARGET, 'cwd': CWD, 'name': name})
98
+ rec('restore accepted', restore.get('ok') is True, json.dumps(restore.get('error'), ensure_ascii=False)[:120])
99
+ rec('bytes restored exactly', content_of(TARGET) == original, f'{len(content_of(TARGET))} bytes')
100
+ rec('restore made its own backup', restore.get('ok') and (restore.get('value') or {}).get('backupOfCurrent') not in (None, ''))
101
+ rec('fixture unchanged after restore', content_of(TARGET) == live_before)
102
+
103
+ json.dump([{'step': s, 'ok': o, 'detail': d} for s, o, d in results], open(os.path.join(args.out, 'results.json'),'w'), ensure_ascii=False, indent=1)
104
+ failed = [s for s, o, _ in results if not o]
105
+ print(f"RESULT {len(results)-len(failed)}/{len(results)} passed")
106
+ print('final sha256:', hashlib.sha256(content_of(TARGET)).hexdigest())
107
+ sys.exit(0 if not failed else 1)
@@ -47,6 +47,7 @@ ACC.addI18n({
47
47
  'tools.scanned': '已扫描会话',
48
48
  'tools.available': '可用',
49
49
  'tools.historyTruncated': '统计已截断',
50
+ 'tools.historyLoading': '历史调用统计加载中:上面已是注册表实时结果,本块稍后填充(扫描会话需要数秒)',
50
51
  'tools.historyEmpty': '扫描窗口内没有任何工具调用记录',
51
52
  'tools.truncatedList': '清单已截断',
52
53
  'tools.calls': '调用次数',
@@ -209,6 +210,7 @@ ACC.addI18n({
209
210
  'tools.scanned': 'sessions scanned',
210
211
  'tools.available': 'Available',
211
212
  'tools.historyTruncated': 'statistics truncated',
213
+ 'tools.historyLoading': 'Loading call history: the registry above is live; this block fills in after scanning sessions',
212
214
  'tools.historyEmpty': 'No tool call events in the scanned window',
213
215
  'tools.truncatedList': 'inventory truncated',
214
216
  'tools.calls': 'Calls',
@@ -444,11 +444,21 @@
444
444
  // One-shot bypass flags: the first load may use the cache, an explicit
445
445
  // Refresh must see fresh host state.
446
446
  const forceList = ACC.useRef(false)
447
+ const forceHistory = ACC.useRef(false)
447
448
  const forceDetail = ACC.useRef(false)
449
+ // The page paints from the registry view, which answers in well under a
450
+ // second; the history fold scans sessions and takes seconds, so it is a
451
+ // second request whose result swaps in when it arrives. Both start at once,
452
+ // so waiting for the history never delays the first paint.
448
453
  const list = ACC.useAsync((context) => {
449
454
  const refresh = forceList.current
450
455
  forceList.current = false
451
- return ACC.api('tools.list', { days, agentId: agentId.length > 0 ? agentId : undefined, includePresets: true, ...(refresh ? { refresh: true } : {}) }, context)
456
+ return ACC.api('tools.list', { days, agentId: agentId.length > 0 ? agentId : undefined, includePresets: true, includeHistory: false, ...(refresh ? { refresh: true } : {}) }, context)
457
+ }, [days, agentId])
458
+ const historyLoad = ACC.useAsync((context) => {
459
+ const refresh = forceHistory.current
460
+ forceHistory.current = false
461
+ return ACC.api('tools.list', { days, agentId: agentId.length > 0 ? agentId : undefined, includePresets: true, includeHistory: true, ...(refresh ? { refresh: true } : {}) }, context)
452
462
  }, [days, agentId])
453
463
  const detail = ACC.useAsync(
454
464
  (context) => {
@@ -510,7 +520,9 @@
510
520
 
511
521
  if (list.status === 'loading') return h(C.Loading, { label: t('common.loading') })
512
522
  if (list.status === 'error') return h(C.ErrorBox, { error: list.error, onRetry: list.reload, label: t('tools.loadFailed') })
513
- const data = list.data
523
+ const data = historyLoad.status === 'ready' ? historyLoad.data : list.data
524
+ // A history failure keeps the registry view usable and says why.
525
+ const historyPending = historyLoad.status === 'loading'
514
526
  if (data.available === false) {
515
527
  return h(C.Empty, {
516
528
  title: t('tools.registryUnavailable'),
@@ -549,8 +561,10 @@
549
561
  key: 'r',
550
562
  onClick: () => {
551
563
  forceList.current = true
564
+ forceHistory.current = true
552
565
  if (selected.length > 0) forceDetail.current = true
553
566
  list.reload()
567
+ historyLoad.reload()
554
568
  if (selected.length > 0) detail.reload()
555
569
  },
556
570
  ariaLabel: t('tools.refreshList'),
@@ -633,7 +647,9 @@
633
647
  ),
634
648
  ),
635
649
  h(InfoPanel, { t, items: [t('tools.statusLegend'), t('tools.probeNotice'), t('tools.hostNotesFold')] }),
636
- history.available === false
650
+ historyPending
651
+ ? h(C.Notice, { tone: 'info' }, t('tools.historyLoading'))
652
+ : history.available === false
637
653
  ? h(
638
654
  'div',
639
655
  { className: 'acc-muted', style: { fontSize: '11px', display: 'flex', flexDirection: 'column', gap: '2px' } },