dsh-atc 0.18.0 → 0.23.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/README.md CHANGED
@@ -22,6 +22,20 @@ dsh plugin add dsh-atc
22
22
 
23
23
  同时用 DSH / codex / opencode / WorkBuddy / Trae / MiniMax 时,注意力会被切成 N 份。这个插件把「谁在跑、谁停了、谁在等我」压到一屏。
24
24
 
25
+ ## 只读,且路由有宿主同级的准入检查
26
+
27
+ 插件读的全部是本地会话存储,SQLite 一律 `readOnly` 打开,不写任何 agent 的数据,不联网(除同源自己的那条路由),也不调用模型。
28
+
29
+ 那条路由 `/dsh-atc/data` 在 handler 入口先过宿主的准入检查:
30
+
31
+ ```js
32
+ connection.requestRejection(request) // Host/Origin 围栏 + 要求已认证的 live Peer
33
+ ```
34
+
35
+ 不通过就 403。没有这道检查时,浏览器里任意一个网页都能通过 `http://127.0.0.1:<端口>` 读到本机所有会话的标题和工作区(DNS rebinding / localhost CSRF)——而这个面板恰恰把「谁在干什么」全列出来了。
36
+
37
+ > 这条是市场维护者合并 PR 时提出的,原始描述里被写进了「HTTP 路由没有 DSH 的访问检查」。
38
+
25
39
  ## 数据源
26
40
 
27
41
  | 工具 | 存储 | 读取方式 |
@@ -76,13 +90,28 @@ Agent 空管中心 [本地推断·零 token] 更新于 11:02 [今天|近
76
90
  ```
77
91
 
78
92
  每个会话是一张卡片:标题 + 相对时间、日期、agent / 工作区标签、状态药丸、上下文占用条。
79
- 右键卡片有菜单:从看板移除 / 标星 / 打开会话 / 复制标题。
93
+ 右上角有 **ⓘ(详情抽屉)** 和 **☆(标星)**,都在 hover 时浮现;右键有菜单:从看板移除 / 查看详情 / 标星 / 打开。
94
+ 在跑的 DSH 卡还会在底部写它在做什么——见下一节。
80
95
 
81
96
  两处刻意的口径:
82
97
 
83
98
  - **顶栏只放行动类数字**。「完成 / 本机会话 / 接入率」是库存,放成一行小字——同一组数字在顶栏、分布条、筛选芯片各报一遍只会稀释注意力。
84
99
  - **Agent 分布默认按近 24h 统计**,可切近 7 天 / 全部。「全部」比的是谁历史攒得多——几个主力 agent 常常各占一样的份额,齐刷刷并列,说明不了现在谁在干活。
85
100
 
101
+ ## 在跑的卡会写它正在干什么
102
+
103
+ 卡片底部右侧那块位置,其它源放 `ctx 35%` / `todo 2/5`;DSH 没有这两样,本来是空的。现在它写当前这一步在做什么:
104
+
105
+ ```text
106
+ [在跑] ⧗ pwsh · 量一下最后一条工具调用的开销
107
+ ```
108
+
109
+ - **只对 `在跑` 的行生效。** 已结束的会话显示"上次干了什么"价值很低,142 张卡每张都挂一句也会让整页变吵。
110
+ - **文字来自 agent 自己。** 取 `tool/call` 事件的 `arguments.description` —— agent 给工具写的那句人话;没有才退到 `file_path` / `command` / `pattern`。
111
+ - **放不下就省略号**,完整内容在 hover 提示里。
112
+ - **代价可忽略。** 每个会话多解几帧日志找最后一条 `tool/call`:40 个会话实测 **31 ms**(平均 0.8 ms/会话),所以它留在 5 秒轮询里,不需要单独的按钮。
113
+
114
+ 再往后想看的(最近若干次调用、耗时、token)属于卡片详情抽屉,那是下一步。
86
115
  ## agent 靠图标区分,不靠颜色
87
116
 
88
117
  八个色相装不下九个 agent:总有两个撞在一起,色弱用户则一个都分不出。所以每个 agent 用**自己的品牌图标**(DeepSeek 的鲸鱼、Claude 的花、OpenAI 的 knot…),颜色只做冗余补充。
@@ -103,11 +132,31 @@ Agent 空管中心 [本地推断·零 token] 更新于 11:02 [今天|近
103
132
 
104
133
  状态组只给四个值得筛的状态:**在跑 / 等你 / 失败 / 完成**。`刚动过` 和 `长期无动静` 是兜底桶("最近没动静"),筛它们等于把「更早」那一段再翻一遍,所以不做成胶囊 —— 但卡片上的状态药丸照样显示这两个状态。默认全部时间、全部状态,不藏任何东西;筛完可以「清空筛选」复原。
105
134
 
106
- ## 跳转
135
+ ## 点击卡片
136
+
137
+ 三种行为,取决于那张卡属于谁:
138
+
139
+ | 卡片 | 点一下 |
140
+ |---|---|
141
+ | **DSH** | 在宿主里切到那个会话(`uiWorkspace.openSession`) |
142
+ | **WorkBuddy / ZCode / Trae** | 把那个应用的窗口提到前台 |
143
+ | **opencode / codex** | 先找它们的终端窗口提到前台;没有窗口才开一个新的续接会话(`opencode -s <id>` / `codex resume <id>`) |
144
+ | **其它** | 复制工作区路径 |
145
+
146
+ 先找窗口、再开终端,这个顺序是有意的:那条会话可能正被另一个客户端占着,再起一个只会打架。
147
+
148
+ 窗口匹配(`lib/focus.mjs`)两件事值得知道:
149
+
150
+ - CLI 工具要求窗口进程是**终端宿主**(cmd / conhost / WindowsTerminal / powershell / Code)。之前只按标题匹配,一个标题里带 "OpenCode Console" 的 Edge 标签页把焦点抢走了。
151
+ - `SetForegroundWindow` 对"用户此刻没在交互的进程"是拒绝的,而点卡片正是这种情况。所以这里会依次尝试 attach 前台线程 → `SwitchToThisWindow` → 模拟一次 ALT 键,并且**每次都重新读前台窗口来确认**,不拿 `SetForegroundWindow` 的返回值当结果。
152
+
153
+ 安全上,这条路径只做了三件事:
154
+
155
+ - 走和 `/data` 同一个准入检查(未认证请求一律 403)
156
+ - 会话 id 必须匹配 `[A-Za-z0-9_-]{1,128}`——它要进命令行,不能信任存储里的字符串
157
+ - 命令由本地表决定,不接受任何来自请求的可执行名或参数
107
158
 
108
- - **DSH 卡片**:点一下直接切到那个会话(`uiWorkspace.openSession`)
109
- - **其它卡片**:复制该卡片的工作区路径,方便去对应工具里找
110
- - 卡片底部的状态药丸与相对时间来自宿主推断,不代表工具本身在跑
159
+ > 卡片底部的状态药丸与相对时间来自宿主推断,不代表工具本身在跑。
111
160
 
112
161
  ## 为什么没有花费
113
162
 
@@ -215,11 +264,52 @@ turn/end.reason.kind → completed / error / aborted / approval / …
215
264
 
216
265
  | 方向 | 要做什么 | 代价 |
217
266
  |---|---|---|
218
- | **点卡片直接跳到对应工具** | 现在只有 DSH 行能跳(`uiWorkspace.openSession`),其它 agent 点击是复制工作区路径。目标是每张卡片都落到「那个工具里的这条会话」,例如 opencode 用 `opencode --session <id>`、WorkBuddy 走它的 deep link。缺的是各家「打开某会话」的入口,要逐个确认能不能从外部唤起 | 中 |
219
- | **卡片详情抽屉** | 点开看最近几条消息、tool 调用、耗时。前置是 `tool/call` 事件解析——那同时也是「在跑卡显示正在干什么」的前提,一次做完两件事 | 大 |
220
- | **spec 引擎取代手写 collector** | sqlite 系仍是四个手写采集器,`lib/sources.mjs` 目前只用于匹配。改成走 `lib/generic.mjs` 的通用查询,能删掉约 150 行重复代码 | 中 |
267
+ | **更多工具的直开** | opencode 和 codex 现在能在原会话上续接(点卡片开终端)。其余工具缺的是同一件事:一条**核实过**的「按 id 打开」入口。WorkBuddy 是桌面应用,要查它有没有 deep link;gemini / zcode / claude 的 resume 参数没有在本机验证过,不猜 | 小,逐家验 |
268
+ | **更多来源能进抽屉** | 抽屉现在只对 DSH 有内容(只有它记录工具调用)。其它源要么显示最近消息,要么维持“该源不记录调用记录”的说法——前者需要给 opencode / minimax 各写一段消息读取,代码不多,但它们的“调用”概念和 DSH 不同,不假装一样 | 中 |
269
+ | **把标题与详情的决定也收进 spec** | 四个 sqlite 采集器已经共用 `readSqliteSource`(见下),但它们的**查询和行映射**仍是各自写的——每家的 join、子查询、侧表都不同。真正能再收的是「标题取哪一列、详情拼什么」,需要 spec 支持 `titleFallback` / `detail` 这类字段 | 中 |
221
270
  | **接入扫描到的候选** | 本机扫描已经能识别 AionUi、GitKrakenCLI 这类「有会话表但没 spec」的库,缺的只是一行 spec | 小 |
222
271
 
272
+ ## 采集器怎么分层
273
+
274
+ 三层,各自只负责一件事:
275
+
276
+ ```text
277
+ 能力(lib/capabilities.mjs) 拿到记录:读 SQLite、查行、数总数、失败降级
278
+ 形状(lib/sources.mjs) 判断是不是会话库:表名 + 关键列 → 供发现扫描用
279
+ 规则(lib/rules.mjs) 决定一行说什么:标题取谁、时间戳怎么归一
280
+ ```
281
+
282
+ 四个 SQLite 采集器(opencode / WorkBuddy / ZCode / MiniMax)现在都走 `readSqliteSource`:
283
+ 它们只声明**路径、两条 SQL、行映射**,文件检查 / 打开 / 计数 / 关闭 / 降级这一圈样板由能力负责。
284
+
285
+ **刻意没做的事**:把 SQL 本身改成声明式 spec。四家的 join、子查询、侧表、过滤条件互不相同,
286
+ 要表达它们就得造一个只有四个调用方的查询构造器,比四段可读的 SQL 更糟。
287
+ `lib/sources.mjs` 保持"判断可读性"这一个用途,才站得住。
288
+
289
+ `npm run board-snapshot <out.json>` 是配合重构用的:把看板导成快照,
290
+ 改完再导一次逐行对比,能证明"行为没变"而不是"我觉得没变"。
291
+
292
+ ## 详情抽屉
293
+
294
+ 卡片右上角的 `ⓘ`(或右键「查看详情」)从右侧滑出一个面板,不挡列表——列表本身就是这条详情的上下文。
295
+
296
+ 能看到的东西:
297
+
298
+ | 内容 | 来源 |
299
+ |---|---|
300
+ | 最近 12 次工具调用 | `tool/call` 与 `tool/result` 按 `callId` 配对 |
301
+ | 每次调用的耗时 | `result.time - call.time`;没有 result 就是「进行中」 |
302
+ | 每次调用的目标 | 同卡片那行,取 `arguments.description` 优先 |
303
+ | 结果摘要 | `tool/result` 的文本,截断到 240 字 |
304
+ | 本轮 token | `assistant/message` 的 `usage`(注意它在 `data.usage`,不在 message 里) |
305
+
306
+ **只有 DSH 有这些。** 其它源不记录工具调用,抽屉会直接说「该工具不记录工具调用」,而不是画一条空时间线让人以为什么都没发生。
307
+
308
+ 两句实现上的实话:
309
+
310
+ - **按需读,不进轮询。** 打开抽屉才扫日志(一次约 10–25 ms,日志越大越多,最多 400 帧)。
311
+ - **叫与结果常常落在不同的 zstd 帧里**,而扫描是从最新帧往回走的,所以结果会先于调用被看到。两者分别收进 Map、最后按 `callId` 配对——一边收一边配对的那版,每一行都显示「进行中」。
312
+
223
313
  ## 开发与发布工具
224
314
 
225
315
  都在 `scripts/` 下,都不需要起 DSH(除 `live-check`):
@@ -246,7 +336,7 @@ dsh plugin add dsh-atc
246
336
  装指定版本:
247
337
 
248
338
  ```powershell
249
- dsh plugin add dsh-atc@0.16.0
339
+ dsh plugin add dsh-atc@<版本> # 版本号看 npm view dsh-atc version
250
340
  ```
251
341
 
252
342
  ### 从 GitHub(npm 不可用时)
@@ -283,6 +373,16 @@ cd "$env:USERPROFILE\.dsh\profiles\desktop"
283
373
 
284
374
  左侧栏(和「插件」「自动化任务」并列)会多一行「**空管**」,点开就是面板。图标右上角出现小圆点表示有需要你处理的事。
285
375
 
376
+ ### 侧栏那枚塔按宿主的重量画
377
+
378
+ 侧栏图标不是随手画的。宿主在 16px 画布上用 2px 描边画自己的图标:时钟 75px 墨迹、旋翼 81px、面板 121px,落点都在 14–16px 之间。这枚塔按同一份规格画——占满画布、描边同重、墨迹摊到整个宽度(98px / 16×15)。
379
+
380
+ 早先那版是把画在 24×24 里的塔整体放大 1.42 倍:墨迹全挤成左边 8px 宽的一团,右边两道电波只剩 1px 淡线——所以站在「插件」「自动化任务」旁边就是显小。
381
+
382
+ 16px 下**只留一道电波**:两道同心弧加上塔,描边之间挤不出白缝,会糊成一团;一道粗弧既读得出广播,也撑得住画布右半边。右上角的琥珀小点从 5px 收到 2.7px——之前它比塔本身还抢眼。
383
+
384
+ `scripts/icon-lab.html` 是量这件事的工具:把候选图形按 16px 栅格化,和宿主图标的真实像素并排比墨迹面积与落点。
385
+
286
386
  ## 本地开发
287
387
 
288
388
  ```powershell
package/client/client.js CHANGED
@@ -19,6 +19,8 @@ window.__ModuleLoader__.load({
19
19
 
20
20
  const PANEL_ID = 'atc'
21
21
  const ENDPOINT = '/dsh-atc/data'
22
+ const OPEN_ENDPOINT = '/dsh-atc/open'
23
+ const DETAIL_ENDPOINT = '/dsh-atc/detail'
22
24
  const POLL_MS = 5000
23
25
  const DAY = 86_400_000
24
26
 
@@ -26,6 +28,28 @@ window.__ModuleLoader__.load({
26
28
 
27
29
  const store = { data: null, error: null, at: 0, paused: false, listeners: new Set() }
28
30
 
31
+ /**
32
+ * Ask the host to open this row in its own tool.
33
+ *
34
+ * Resolves true only when a terminal was actually started; anything else
35
+ * (no opener for the tool, an unsupported platform, a bad id) resolves false
36
+ * so the caller can fall back to copying the path.
37
+ */
38
+ async function requestOpen(item) {
39
+ try {
40
+ const response = await fetch(OPEN_ENDPOINT, {
41
+ method: 'POST',
42
+ headers: { 'content-type': 'application/json' },
43
+ body: JSON.stringify({ tool: item.tool, openId: item.openId, cwd: item.cwd }),
44
+ })
45
+ if (!response.ok) return false
46
+ const result = await response.json()
47
+ return result?.ok === true
48
+ } catch {
49
+ return false
50
+ }
51
+ }
52
+
29
53
  function publish(patch) {
30
54
  Object.assign(store, patch)
31
55
  for (const listener of store.listeners) listener()
@@ -824,6 +848,20 @@ window.__ModuleLoader__.load({
824
848
  )
825
849
  }
826
850
 
851
+ /**
852
+ * The panel's sidebar glyph: a control tower broadcasting one arc.
853
+ *
854
+ * The host draws its own sidebar icons on a 16px canvas with a 2px stroke,
855
+ * and its glyphs land at 75–121px of ink over a 14×16 footprint. This one
856
+ * is drawn to the same brief: the drawing fills the viewBox, the strokes
857
+ * carry the host's weight, and the ink spreads across the whole width
858
+ * instead of piling into one blob.
859
+ *
860
+ * A second arc was cut on purpose. At 16px two concentric arcs and a
861
+ * tower cannot keep white space between their strokes, and they merge into
862
+ * a smudge; one bold arc reads as a broadcast and holds the right edge of
863
+ * the canvas.
864
+ */
827
865
  function PanelIcon({ size = 18 }) {
828
866
  const state = useBoard()
829
867
  const attention = state.data ? state.data.attention : 0
@@ -835,31 +873,21 @@ window.__ModuleLoader__.load({
835
873
  viewBox: '0 0 24 24',
836
874
  fill: 'none',
837
875
  stroke: 'currentColor',
838
- // The group below is scaled by 1.42, so this lands on ~1.9 once
839
- // rendered: as heavy as the icons the host draws beside it.
840
- strokeWidth: 1.34,
876
+ strokeWidth: 2.2,
841
877
  strokeLinecap: 'round',
842
878
  strokeLinejoin: 'round',
843
879
  'aria-hidden': 'true',
844
880
  },
845
- // Control tower: mast, cabin, tapered leg, and two outbound sweep arcs.
846
- //
847
- // As authored the drawing filled barely half of the box and sat off to
848
- // the right, so the row read as a smaller icon next to the host's.
849
- // The transform scales it up and centres it in the viewBox.
850
- h(
851
- 'g',
852
- { transform: 'translate(-9.21 -0.91) scale(1.42)' },
853
- h('path', { d: 'M12 2.4v2.6' }),
854
- h('rect', { x: 9, y: 5, width: 6, height: 2.8, rx: 1 }),
855
- h('path', { d: 'M10.2 7.8 9.4 15M13.8 7.8 14.6 15' }),
856
- h('path', { d: 'M8.6 15h6.8' }),
857
- h('path', { d: 'M16.9 6.2a4.2 4.2 0 0 1 0 6.1' }),
858
- h('path', { d: 'M19.1 4.1a7.4 7.4 0 0 1 0 10.3', opacity: 0.55 }),
859
- attention > 0
860
- ? h('circle', { cx: 19.8, cy: 3.8, r: 2.6, fill: 'var(--dsw-alias-state-warn-primary)', stroke: 'none' })
861
- : null,
862
- ),
881
+ // Mast, cabin, tapered body, and the base it stands on.
882
+ h('path', { d: 'M8.6 1.8V4.4' }),
883
+ h('rect', { x: 4.9, y: 4.4, width: 7.4, height: 4.8, rx: 1.4 }),
884
+ h('path', { d: 'M6.3 9.2 4 21M10.9 9.2 13.2 21' }),
885
+ h('path', { d: 'M2 21H15.2' }),
886
+ // The broadcast arc, opening away from the cabin.
887
+ h('path', { d: 'M17.4 5a4.6 4.6 0 0 1 0 9.2' }),
888
+ attention > 0
889
+ ? h('circle', { cx: 20.8, cy: 3.2, r: 2, fill: 'var(--dsw-alias-state-warn-primary)', stroke: 'none' })
890
+ : null,
863
891
  )
864
892
  }
865
893
 
@@ -1023,10 +1051,10 @@ window.__ModuleLoader__.load({
1023
1051
  * Session card: title + relative time on top, agent / workspace tags in
1024
1052
  * the middle, status and context pressure on the footer.
1025
1053
  */
1026
- function SessionCard({ item, onOpen, onMenu, starred, onStar }) {
1054
+ function SessionCard({ item, onOpen, onMenu, onDetail, starred, onStar }) {
1027
1055
  const status = STATUS[item.status] || STATUS.idle
1028
1056
  const color = AGENT_COLOR[item.tool] || PALETTE.slate
1029
- const clickable = Boolean(item.sessionId)
1057
+ const clickable = Boolean(item.sessionId || item.openLabel)
1030
1058
  const ctx = /ctx\s*(\d+)%/.exec(item.detail || '')
1031
1059
  const extra = item.detail
1032
1060
  ? item.detail.replace(/ctx\s*\d+%/, '').replace(/^[·\s]+|[·\s]+$/g, '')
@@ -1037,7 +1065,11 @@ window.__ModuleLoader__.load({
1037
1065
  className: `fb-session${clickable ? ' fb-session-clickable' : ''}`,
1038
1066
  role: clickable ? 'button' : undefined,
1039
1067
  tabIndex: clickable ? 0 : undefined,
1040
- title: clickable ? '打开这个会话 · 右键更多操作' : `${item.workspace}(不支持跳转)· 右键更多操作`,
1068
+ title: item.sessionId
1069
+ ? '打开这个会话 · 右键更多操作'
1070
+ : item.openLabel
1071
+ ? `${item.openLabel} · 右键更多操作`
1072
+ : `${item.workspace}(点一下复制路径)· 右键更多操作`,
1041
1073
  onClick: () => onOpen(item),
1042
1074
  onContextMenu: (event) => {
1043
1075
  event.preventDefault()
@@ -1054,6 +1086,20 @@ window.__ModuleLoader__.load({
1054
1086
  'div',
1055
1087
  { className: 'fb-session-top' },
1056
1088
  h('div', { className: 'fb-session-title' }, item.title),
1089
+ h(
1090
+ 'button',
1091
+ {
1092
+ type: 'button',
1093
+ className: 'fb-detail-btn',
1094
+ title: '查看详情',
1095
+ onClick: (event) => {
1096
+ event.stopPropagation()
1097
+ onDetail(item)
1098
+ },
1099
+ onKeyDown: (event) => event.stopPropagation(),
1100
+ },
1101
+ 'ⓘ',
1102
+ ),
1057
1103
  h(
1058
1104
  'button',
1059
1105
  {
@@ -1112,13 +1158,15 @@ window.__ModuleLoader__.load({
1112
1158
  })()
1113
1159
  : extra
1114
1160
  ? h('span', { className: 'fb-session-detail' }, extra)
1115
- : null,
1161
+ : item.doing
1162
+ ? h('span', { className: 'fb-session-doing', title: item.doing }, `⧗ ${item.doing}`)
1163
+ : null,
1116
1164
  ),
1117
1165
  )
1118
1166
  }
1119
1167
 
1120
1168
  /** Collapsible band of sessions. */
1121
- function Group({ title, items, color, defaultOpen, onOpen, onMenu, starSet, onStar, hint, recentMs }) {
1169
+ function Group({ title, items, color, defaultOpen, onOpen, onMenu, onDetail, starSet, onStar, hint, recentMs }) {
1122
1170
  const [open, setOpen] = useState(defaultOpen)
1123
1171
  // Opening a band of 137 rows is not readable; start with the recent ones
1124
1172
  // and let the reader ask for the rest rather than dumping history.
@@ -1162,7 +1210,7 @@ window.__ModuleLoader__.load({
1162
1210
  ? h(
1163
1211
  'div',
1164
1212
  { className: 'fb-session-grid' },
1165
- shown.map((item) => h(SessionCard, { key: `${item.tool}:${item.key}`, item, onOpen, onMenu, starred: Boolean(starSet && starSet.has(itemKey(item))), onStar })),
1213
+ shown.map((item) => h(SessionCard, { key: `${item.tool}:${item.key}`, item, onOpen, onMenu, onDetail, starred: Boolean(starSet && starSet.has(itemKey(item))), onStar })),
1166
1214
  )
1167
1215
  : null,
1168
1216
  withheld > 0
@@ -1215,6 +1263,109 @@ function EmptyState({ board }) {
1215
1263
  )
1216
1264
  }
1217
1265
 
1266
+ /**
1267
+ * What a session has been doing, turn by turn.
1268
+ *
1269
+ * Slides over the right of the board rather than replacing it: the list is the
1270
+ * context for the detail, and losing it on every click is a reason dashboards
1271
+ * get abandoned. Only DSH records tool calls, so other sources say so instead
1272
+ * of showing an empty timeline that reads like "nothing happened".
1273
+ */
1274
+ function DetailDrawer({ state, onClose }) {
1275
+ const item = state.item
1276
+ const data = state.data
1277
+ useEffect(() => {
1278
+ const onKey = (event) => {
1279
+ if (event.key === 'Escape') onClose()
1280
+ }
1281
+ window.addEventListener('keydown', onKey)
1282
+ return () => window.removeEventListener('keydown', onKey)
1283
+ }, [onClose])
1284
+
1285
+ const calls = data?.calls ?? []
1286
+ const duration = (value) => (value === null || value === undefined ? '—' : `${value} ms`)
1287
+
1288
+ return h(
1289
+ 'div',
1290
+ { className: 'fb-drawer-wrap', onClick: onClose },
1291
+ h(
1292
+ 'aside',
1293
+ {
1294
+ className: 'fb-drawer',
1295
+ role: 'dialog',
1296
+ 'aria-label': '会话详情',
1297
+ onClick: (event) => event.stopPropagation(),
1298
+ },
1299
+ h(
1300
+ 'div',
1301
+ { className: 'fb-drawer-head' },
1302
+ h(
1303
+ 'div',
1304
+ { className: 'fb-drawer-heading' },
1305
+ h('div', { className: 'fb-drawer-title', title: item.title }, item.title),
1306
+ h('div', { className: 'fb-drawer-sub' }, `${item.tool} · ${item.workspace}`),
1307
+ ),
1308
+ h(
1309
+ 'button',
1310
+ { type: 'button', className: 'fb-drawer-close', onClick: onClose, title: '关闭(Esc)' },
1311
+ '✕',
1312
+ ),
1313
+ ),
1314
+
1315
+ state.loading ? h('div', { className: 'fb-drawer-note' }, '读取中…') : null,
1316
+ state.error ? h('div', { className: 'fb-drawer-note' }, `读取失败:${state.error}`) : null,
1317
+ data && data.supported === false
1318
+ ? h('div', { className: 'fb-drawer-note' }, data.reason ?? '该工具不提供调用记录')
1319
+ : null,
1320
+
1321
+ data && data.supported
1322
+ ? h(
1323
+ 'div',
1324
+ { className: 'fb-drawer-body' },
1325
+ h(
1326
+ 'div',
1327
+ { className: 'fb-drawer-stats' },
1328
+ h('span', null, `${data.totalCalls} 次调用`),
1329
+ data.lastTurn
1330
+ ? h('span', null, `最后一轮 ${data.lastTurn.reason || '结束'}`)
1331
+ : null,
1332
+ data.usage
1333
+ ? h('span', { title: '最近一步的 token 用量' }, `本轮 ${data.usage.totalTokens} token`)
1334
+ : null,
1335
+ ),
1336
+ calls.length === 0
1337
+ ? h('div', { className: 'fb-drawer-note' }, '日志里还没有工具调用')
1338
+ : h(
1339
+ 'ol',
1340
+ { className: 'fb-calls' },
1341
+ calls.map((call) =>
1342
+ h(
1343
+ 'li',
1344
+ { className: 'fb-call', key: call.callId },
1345
+ h(
1346
+ 'div',
1347
+ { className: 'fb-call-row' },
1348
+ h('span', { className: 'fb-call-name' }, call.name),
1349
+ h('span', { className: 'fb-call-target', title: call.target }, call.target || '—'),
1350
+ h(
1351
+ 'span',
1352
+ {
1353
+ className: `fb-call-dur${call.finished ? '' : ' fb-call-live'}`,
1354
+ },
1355
+ call.finished ? duration(call.durationMs) : '进行中',
1356
+ ),
1357
+ ),
1358
+ call.snippet ? h('div', { className: 'fb-call-snippet' }, call.snippet) : null,
1359
+ ),
1360
+ ),
1361
+ ),
1362
+ )
1363
+ : null,
1364
+ ),
1365
+ )
1366
+ }
1367
+
1368
+
1218
1369
  /** Loading placeholder that mirrors the KPI grid shape. */
1219
1370
  function Skeleton() {
1220
1371
  return h(
@@ -1246,6 +1397,8 @@ function EmptyState({ board }) {
1246
1397
  // Rows removed from the board. Display-only: nothing on disk is touched.
1247
1398
  const [hidden, setHidden] = useState(() => loadHidden())
1248
1399
  const [menu, setMenu] = useState(null)
1400
+ // `{ item, loading, data }` while the drawer is open, null when closed.
1401
+ const [detail, setDetail] = useState(null)
1249
1402
  const [starred, setStarred] = useState(() => loadStarred())
1250
1403
  const [agentScope, setAgentScope] = useState('d1')
1251
1404
  const board = state.data
@@ -1263,17 +1416,51 @@ function EmptyState({ board }) {
1263
1416
 
1264
1417
  const onOpen = useCallback(
1265
1418
  async (item) => {
1419
+ // A DSH session opens inside the host, no terminal involved.
1266
1420
  if (item.sessionId) {
1267
1421
  if (openSession(ctx, item.sessionId)) return
1268
1422
  flash('宿主没有提供会话跳转接口')
1269
1423
  return
1270
1424
  }
1425
+ // Tools with their own CLI get a terminal running the resume command.
1426
+ if (item.openLabel && item.openId) {
1427
+ if (await requestOpen(item)) {
1428
+ flash(item.openLabel)
1429
+ return
1430
+ }
1431
+ const copied = await copyText(item.workspace)
1432
+ flash(copied ? `${item.tool} 打不开,已复制工作区路径` : `${item.tool} 打不开`)
1433
+ return
1434
+ }
1271
1435
  const copied = await copyText(item.workspace)
1272
1436
  flash(copied ? `已复制工作区路径:${item.workspace}` : `工作区:${item.workspace}`)
1273
1437
  },
1274
1438
  [ctx, flash],
1275
1439
  )
1276
1440
 
1441
+ const openDetail = useCallback(
1442
+ async (item) => {
1443
+ setDetail({ item, loading: true, data: null })
1444
+ try {
1445
+ const query = new URLSearchParams({ tool: item.tool, id: item.key })
1446
+ const response = await fetch(`${DETAIL_ENDPOINT}?${query}`)
1447
+ const data = await response.json()
1448
+ // A response for another card must not overwrite this one: the
1449
+ // drawer can be reopened before the first fetch lands.
1450
+ setDetail((current) =>
1451
+ current && current.item.key === item.key ? { item, loading: false, data } : current,
1452
+ )
1453
+ } catch (error) {
1454
+ setDetail((current) =>
1455
+ current && current.item.key === item.key
1456
+ ? { item, loading: false, error: String(error?.message ?? error) }
1457
+ : current,
1458
+ )
1459
+ }
1460
+ },
1461
+ [],
1462
+ )
1463
+
1277
1464
  const hideItem = useCallback(
1278
1465
  (item) => {
1279
1466
  const next = new Set(hidden)
@@ -1319,6 +1506,11 @@ function EmptyState({ board }) {
1319
1506
  hint: '不影响数据',
1320
1507
  onSelect: () => hideItem(item),
1321
1508
  },
1509
+ {
1510
+ label: '查看详情',
1511
+ icon: 'ⓘ',
1512
+ onSelect: () => openDetail(item),
1513
+ },
1322
1514
  {
1323
1515
  label: starred.has(itemKey(item)) ? '取消标星' : '标星并置顶',
1324
1516
  icon: '★',
@@ -1326,7 +1518,7 @@ function EmptyState({ board }) {
1326
1518
  },
1327
1519
  { separator: true },
1328
1520
  {
1329
- label: item.sessionId ? '打开会话' : '复制工作区路径',
1521
+ label: item.sessionId ? '打开会话' : item.openLabel || '复制工作区路径',
1330
1522
  icon: '↗',
1331
1523
  onSelect: () => onOpen(item),
1332
1524
  },
@@ -1349,7 +1541,7 @@ function EmptyState({ board }) {
1349
1541
  ]
1350
1542
  : []),
1351
1543
  ]
1352
- }, [menu, hidden, starred, hideItem, restoreHidden, toggleStar, onOpen, flash])
1544
+ }, [menu, hidden, starred, hideItem, restoreHidden, toggleStar, openDetail, onOpen, flash])
1353
1545
 
1354
1546
  const filters = { query, range, status: statusFilter, tool: toolFilter }
1355
1547
  const filtered = useMemo(() => {
@@ -1504,6 +1696,7 @@ function EmptyState({ board }) {
1504
1696
  ),
1505
1697
 
1506
1698
  menu ? h(ContextMenu, { at: { x: menu.x, y: menu.y }, items: menuItems, onClose: () => setMenu(null) }) : null,
1699
+ detail ? h(DetailDrawer, { state: detail, onClose: () => setDetail(null) }) : null,
1507
1700
 
1508
1701
  state.error && !board
1509
1702
  ? h('div', { className: 'fb-error' }, `读取失败:${state.error}`)
@@ -1845,6 +2038,7 @@ function EmptyState({ board }) {
1845
2038
  defaultOpen: true,
1846
2039
  onOpen,
1847
2040
  onMenu: openMenu,
2041
+ onDetail: openDetail,
1848
2042
  starSet: starred,
1849
2043
  onStar: toggleStar,
1850
2044
  hint: '你标过的',
@@ -1855,6 +2049,7 @@ function EmptyState({ board }) {
1855
2049
  color: STATUS['needs-you'].color,
1856
2050
  defaultOpen: true,
1857
2051
  onMenu: openMenu,
2052
+ onDetail: openDetail,
1858
2053
  starSet: starred,
1859
2054
  onStar: toggleStar,
1860
2055
  onOpen,
@@ -1865,6 +2060,7 @@ function EmptyState({ board }) {
1865
2060
  color: STATUS.running.color,
1866
2061
  defaultOpen: true,
1867
2062
  onMenu: openMenu,
2063
+ onDetail: openDetail,
1868
2064
  starSet: starred,
1869
2065
  onStar: toggleStar,
1870
2066
  onOpen,
@@ -1875,6 +2071,7 @@ function EmptyState({ board }) {
1875
2071
  color: STATUS.done.color,
1876
2072
  defaultOpen: false,
1877
2073
  onMenu: openMenu,
2074
+ onDetail: openDetail,
1878
2075
  starSet: starred,
1879
2076
  onStar: toggleStar,
1880
2077
  onOpen,
@@ -1886,6 +2083,7 @@ function EmptyState({ board }) {
1886
2083
  color: STATUS.recent.color,
1887
2084
  defaultOpen: true,
1888
2085
  onMenu: openMenu,
2086
+ onDetail: openDetail,
1889
2087
  starSet: starred,
1890
2088
  onStar: toggleStar,
1891
2089
  onOpen,
@@ -1897,6 +2095,7 @@ function EmptyState({ board }) {
1897
2095
  color: STATUS.idle.color,
1898
2096
  defaultOpen: false,
1899
2097
  onMenu: openMenu,
2098
+ onDetail: openDetail,
1900
2099
  starSet: starred,
1901
2100
  onStar: toggleStar,
1902
2101
  onOpen,
@@ -1958,7 +2157,30 @@ function EmptyState({ board }) {
1958
2157
  .fb-kpi-value{font-size:22px;font-weight:650;line-height:1.15;font-variant-numeric:tabular-nums;letter-spacing:-.01em}
1959
2158
  .fb-kpi-label{margin-top:3px;font-size:11.5px;color:var(--fb-text-2)}
1960
2159
  .fb-kpi-note{margin-top:1px;font-size:10.5px;color:var(--fb-text-4);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1961
- .fb-charts{display:grid;grid-template-columns:repeat(auto-fit,minmax(380px,1fr));gap:12px;margin-bottom:12px}
2160
+ /* Always one row: the two charts share the width instead of stacking. They
2161
+ shrink by stepping their internals down (heat cells, name column) rather than
2162
+ by moving to separate lines — a dashboard that reflows into a column loses
2163
+ the at-a-glance comparison it exists for. */
2164
+ .fb-charts{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:12px;margin-bottom:12px}
2165
+ .fb-charts>.fb-card{min-width:0}
2166
+ @media (max-width:980px){
2167
+ .fb-charts{gap:10px}
2168
+ .fb-heat-cell{width:12px;height:12px}
2169
+ .fb-agent-bar-name{width:62px}
2170
+ .fb-card{padding:12px}
2171
+ }
2172
+ @media (max-width:840px){
2173
+ .fb-heat-cell{width:10px;height:10px}
2174
+ .fb-heat-grid{gap:3px}
2175
+ .fb-heat{gap:4px}
2176
+ .fb-agent-bar-name{width:52px}
2177
+ .fb-agent-bar-pct{display:none}
2178
+ }
2179
+ @media (max-width:720px){
2180
+ .fb-heat-cell{width:8px;height:8px}
2181
+ .fb-agent-bar{gap:6px}
2182
+ .fb-agent-bar-name{width:44px;font-size:11px}
2183
+ }
1962
2184
  .fb-card{border:1px solid var(--fb-line);border-radius:var(--fb-r-md);background:var(--fb-surface);padding:14px 16px}
1963
2185
  .fb-card-head{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-bottom:12px;flex-wrap:wrap}
1964
2186
  .fb-card-title{font-size:13px;font-weight:600}
@@ -2046,6 +2268,9 @@ function EmptyState({ board }) {
2046
2268
  .fb-session-foot{margin-top:auto;padding-top:9px;border-top:1px solid var(--fb-line-soft);display:flex;align-items:center;gap:10px}
2047
2269
  .fb-session-ctx{margin-left:auto;display:flex;align-items:center;gap:6px;font-size:10.5px;color:var(--fb-text-3);font-variant-numeric:tabular-nums}
2048
2270
  .fb-session-detail{margin-left:auto;font-size:10.5px;color:var(--fb-text-3);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:52%}
2271
+ /* What a running session is doing right now, in the space the ctx meter uses
2272
+ on other sources. It changes as the agent works, which is the point. */
2273
+ .fb-session-doing{margin-left:auto;min-width:0;font-size:10.5px;color:var(--fb-text-3);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:64%;font-variant-numeric:tabular-nums}
2049
2274
  .fb-meter{width:52px;height:4px;border-radius:999px;background:var(--fb-line-soft);overflow:hidden;flex:none;display:inline-block}
2050
2275
  .fb-meter i{display:block;height:100%;border-radius:999px;background:#d98324}
2051
2276
  .fb-status{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:2px 9px;border-radius:999px;white-space:nowrap}
@@ -2057,6 +2282,32 @@ function EmptyState({ board }) {
2057
2282
  /* The tail of a long band: one quiet row instead of a wall of history. */
2058
2283
  .fb-more{display:block;width:100%;margin-top:8px;padding:9px;border:1px dashed var(--fb-line);border-radius:var(--fb-r-sm);background:none;color:var(--fb-text-3);font-size:11.5px;cursor:pointer;font-family:inherit}
2059
2284
  .fb-more:hover{background:var(--fb-fill);color:var(--fb-text-2)}
2285
+ /* Detail drawer: overlays the right of the board so the list stays readable. */
2286
+ .fb-drawer-wrap{position:fixed;inset:0;z-index:70;background:rgba(15,23,42,.18);display:flex;justify-content:flex-end}
2287
+ .fb-drawer{width:min(420px,86vw);height:100%;background:var(--fb-surface);border-left:1px solid var(--fb-line);box-shadow:-14px 0 40px rgba(15,23,42,.18);display:flex;flex-direction:column;overflow:hidden}
2288
+ .fb-drawer-head{display:flex;align-items:flex-start;gap:10px;padding:14px 16px;border-bottom:1px solid var(--fb-line-soft)}
2289
+ .fb-drawer-heading{min-width:0;flex:1}
2290
+ .fb-drawer-title{font-size:13px;font-weight:600;color:var(--fb-text);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
2291
+ .fb-drawer-sub{margin-top:3px;font-size:11px;color:var(--fb-text-4);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
2292
+ .fb-drawer-close{border:0;background:none;color:var(--fb-text-4);font-size:13px;cursor:pointer;padding:2px 4px;font-family:inherit;line-height:1}
2293
+ .fb-drawer-close:hover{color:var(--fb-text)}
2294
+ .fb-drawer-note{padding:14px 16px;font-size:12px;color:var(--fb-text-3);line-height:1.6}
2295
+ .fb-drawer-body{flex:1;overflow-y:auto;padding:12px 16px 20px}
2296
+ .fb-drawer-stats{display:flex;flex-wrap:wrap;gap:10px;font-size:10.5px;color:var(--fb-text-4);margin-bottom:10px}
2297
+ .fb-calls{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:2px}
2298
+ .fb-call{padding:7px 8px;border-radius:var(--fb-r-xs);border:1px solid transparent}
2299
+ .fb-call:hover{background:var(--fb-fill);border-color:var(--fb-line-soft)}
2300
+ .fb-call-row{display:flex;align-items:baseline;gap:8px;font-size:11.5px}
2301
+ .fb-call-name{font-weight:600;color:var(--fb-text-2);flex:none}
2302
+ .fb-call-target{flex:1;min-width:0;color:var(--fb-text-3);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
2303
+ .fb-call-dur{flex:none;color:var(--fb-text-4);font-variant-numeric:tabular-nums;font-size:10.5px}
2304
+ .fb-call-live{color:var(--dsw-alias-state-success-primary,#2f9e6f)}
2305
+ .fb-call-snippet{margin-top:4px;font-size:10.5px;color:var(--fb-text-4);line-height:1.5;max-height:2.9em;overflow:hidden;word-break:break-all}
2306
+ /* The detail button sits beside the star and shares its hover reveal. */
2307
+ .fb-detail-btn{border:0;background:none;padding:0 2px;font-size:11px;line-height:1;color:var(--fb-text-4);cursor:pointer;opacity:0;transition:opacity .12s ease,color .12s ease;font-family:inherit}
2308
+ .fb-session:hover .fb-detail-btn,.fb-session-clickable:hover .fb-detail-btn{opacity:1}
2309
+ .fb-detail-btn:hover{color:var(--fb-text)}
2310
+
2060
2311
  /* Right-click menu: floats above the board, clamped to the viewport. */
2061
2312
  .fb-menu{position:fixed;z-index:60;padding:6px;background:var(--fb-surface);border:1px solid var(--fb-line);border-radius:var(--fb-r-sm);box-shadow:0 12px 32px rgba(15,23,42,.18);display:flex;flex-direction:column;gap:1px}
2062
2313
  .fb-menu-item{display:flex;align-items:center;gap:8px;width:100%;padding:7px 9px;border:0;border-radius:var(--fb-r-xs);background:none;color:var(--fb-text);font-size:12px;text-align:left;cursor:pointer;font-family:inherit}