dsh-atc 0.19.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 +85 -9
- package/client/client.js +232 -8
- package/lib/capabilities.mjs +70 -0
- package/lib/collect.mjs +169 -205
- package/lib/detail.mjs +136 -0
- package/lib/dsh-frames.mjs +94 -0
- package/lib/focus.mjs +210 -0
- package/lib/index.js +171 -3
- package/lib/openers.mjs +73 -0
- package/lib/rules.mjs +100 -0
- package/lib/tool-calls.mjs +80 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -90,13 +90,28 @@ Agent 空管中心 [本地推断·零 token] 更新于 11:02 [今天|近
|
|
|
90
90
|
```
|
|
91
91
|
|
|
92
92
|
每个会话是一张卡片:标题 + 相对时间、日期、agent / 工作区标签、状态药丸、上下文占用条。
|
|
93
|
-
|
|
93
|
+
右上角有 **ⓘ(详情抽屉)** 和 **☆(标星)**,都在 hover 时浮现;右键有菜单:从看板移除 / 查看详情 / 标星 / 打开。
|
|
94
|
+
在跑的 DSH 卡还会在底部写它在做什么——见下一节。
|
|
94
95
|
|
|
95
96
|
两处刻意的口径:
|
|
96
97
|
|
|
97
98
|
- **顶栏只放行动类数字**。「完成 / 本机会话 / 接入率」是库存,放成一行小字——同一组数字在顶栏、分布条、筛选芯片各报一遍只会稀释注意力。
|
|
98
99
|
- **Agent 分布默认按近 24h 统计**,可切近 7 天 / 全部。「全部」比的是谁历史攒得多——几个主力 agent 常常各占一样的份额,齐刷刷并列,说明不了现在谁在干活。
|
|
99
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)属于卡片详情抽屉,那是下一步。
|
|
100
115
|
## agent 靠图标区分,不靠颜色
|
|
101
116
|
|
|
102
117
|
八个色相装不下九个 agent:总有两个撞在一起,色弱用户则一个都分不出。所以每个 agent 用**自己的品牌图标**(DeepSeek 的鲸鱼、Claude 的花、OpenAI 的 knot…),颜色只做冗余补充。
|
|
@@ -117,11 +132,31 @@ Agent 空管中心 [本地推断·零 token] 更新于 11:02 [今天|近
|
|
|
117
132
|
|
|
118
133
|
状态组只给四个值得筛的状态:**在跑 / 等你 / 失败 / 完成**。`刚动过` 和 `长期无动静` 是兜底桶("最近没动静"),筛它们等于把「更早」那一段再翻一遍,所以不做成胶囊 —— 但卡片上的状态药丸照样显示这两个状态。默认全部时间、全部状态,不藏任何东西;筛完可以「清空筛选」复原。
|
|
119
134
|
|
|
120
|
-
##
|
|
135
|
+
## 点击卡片
|
|
121
136
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
+
- 命令由本地表决定,不接受任何来自请求的可执行名或参数
|
|
158
|
+
|
|
159
|
+
> 卡片底部的状态药丸与相对时间来自宿主推断,不代表工具本身在跑。
|
|
125
160
|
|
|
126
161
|
## 为什么没有花费
|
|
127
162
|
|
|
@@ -229,11 +264,52 @@ turn/end.reason.kind → completed / error / aborted / approval / …
|
|
|
229
264
|
|
|
230
265
|
| 方向 | 要做什么 | 代价 |
|
|
231
266
|
|---|---|---|
|
|
232
|
-
|
|
|
233
|
-
|
|
|
234
|
-
|
|
|
267
|
+
| **更多工具的直开** | opencode 和 codex 现在能在原会话上续接(点卡片开终端)。其余工具缺的是同一件事:一条**核实过**的「按 id 打开」入口。WorkBuddy 是桌面应用,要查它有没有 deep link;gemini / zcode / claude 的 resume 参数没有在本机验证过,不猜 | 小,逐家验 |
|
|
268
|
+
| **更多来源能进抽屉** | 抽屉现在只对 DSH 有内容(只有它记录工具调用)。其它源要么显示最近消息,要么维持“该源不记录调用记录”的说法——前者需要给 opencode / minimax 各写一段消息读取,代码不多,但它们的“调用”概念和 DSH 不同,不假装一样 | 中 |
|
|
269
|
+
| **把标题与详情的决定也收进 spec** | 四个 sqlite 采集器已经共用 `readSqliteSource`(见下),但它们的**查询和行映射**仍是各自写的——每家的 join、子查询、侧表都不同。真正能再收的是「标题取哪一列、详情拼什么」,需要 spec 支持 `titleFallback` / `detail` 这类字段 | 中 |
|
|
235
270
|
| **接入扫描到的候选** | 本机扫描已经能识别 AionUi、GitKrakenCLI 这类「有会话表但没 spec」的库,缺的只是一行 spec | 小 |
|
|
236
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
|
+
|
|
237
313
|
## 开发与发布工具
|
|
238
314
|
|
|
239
315
|
都在 `scripts/` 下,都不需要起 DSH(除 `live-check`):
|
|
@@ -260,7 +336,7 @@ dsh plugin add dsh-atc
|
|
|
260
336
|
装指定版本:
|
|
261
337
|
|
|
262
338
|
```powershell
|
|
263
|
-
dsh plugin add dsh-atc
|
|
339
|
+
dsh plugin add dsh-atc@<版本> # 版本号看 npm view dsh-atc version
|
|
264
340
|
```
|
|
265
341
|
|
|
266
342
|
### 从 GitHub(npm 不可用时)
|
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()
|
|
@@ -1027,10 +1051,10 @@ window.__ModuleLoader__.load({
|
|
|
1027
1051
|
* Session card: title + relative time on top, agent / workspace tags in
|
|
1028
1052
|
* the middle, status and context pressure on the footer.
|
|
1029
1053
|
*/
|
|
1030
|
-
function SessionCard({ item, onOpen, onMenu, starred, onStar }) {
|
|
1054
|
+
function SessionCard({ item, onOpen, onMenu, onDetail, starred, onStar }) {
|
|
1031
1055
|
const status = STATUS[item.status] || STATUS.idle
|
|
1032
1056
|
const color = AGENT_COLOR[item.tool] || PALETTE.slate
|
|
1033
|
-
const clickable = Boolean(item.sessionId)
|
|
1057
|
+
const clickable = Boolean(item.sessionId || item.openLabel)
|
|
1034
1058
|
const ctx = /ctx\s*(\d+)%/.exec(item.detail || '')
|
|
1035
1059
|
const extra = item.detail
|
|
1036
1060
|
? item.detail.replace(/ctx\s*\d+%/, '').replace(/^[·\s]+|[·\s]+$/g, '')
|
|
@@ -1041,7 +1065,11 @@ window.__ModuleLoader__.load({
|
|
|
1041
1065
|
className: `fb-session${clickable ? ' fb-session-clickable' : ''}`,
|
|
1042
1066
|
role: clickable ? 'button' : undefined,
|
|
1043
1067
|
tabIndex: clickable ? 0 : undefined,
|
|
1044
|
-
title:
|
|
1068
|
+
title: item.sessionId
|
|
1069
|
+
? '打开这个会话 · 右键更多操作'
|
|
1070
|
+
: item.openLabel
|
|
1071
|
+
? `${item.openLabel} · 右键更多操作`
|
|
1072
|
+
: `${item.workspace}(点一下复制路径)· 右键更多操作`,
|
|
1045
1073
|
onClick: () => onOpen(item),
|
|
1046
1074
|
onContextMenu: (event) => {
|
|
1047
1075
|
event.preventDefault()
|
|
@@ -1058,6 +1086,20 @@ window.__ModuleLoader__.load({
|
|
|
1058
1086
|
'div',
|
|
1059
1087
|
{ className: 'fb-session-top' },
|
|
1060
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
|
+
),
|
|
1061
1103
|
h(
|
|
1062
1104
|
'button',
|
|
1063
1105
|
{
|
|
@@ -1116,13 +1158,15 @@ window.__ModuleLoader__.load({
|
|
|
1116
1158
|
})()
|
|
1117
1159
|
: extra
|
|
1118
1160
|
? h('span', { className: 'fb-session-detail' }, extra)
|
|
1119
|
-
:
|
|
1161
|
+
: item.doing
|
|
1162
|
+
? h('span', { className: 'fb-session-doing', title: item.doing }, `⧗ ${item.doing}`)
|
|
1163
|
+
: null,
|
|
1120
1164
|
),
|
|
1121
1165
|
)
|
|
1122
1166
|
}
|
|
1123
1167
|
|
|
1124
1168
|
/** Collapsible band of sessions. */
|
|
1125
|
-
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 }) {
|
|
1126
1170
|
const [open, setOpen] = useState(defaultOpen)
|
|
1127
1171
|
// Opening a band of 137 rows is not readable; start with the recent ones
|
|
1128
1172
|
// and let the reader ask for the rest rather than dumping history.
|
|
@@ -1166,7 +1210,7 @@ window.__ModuleLoader__.load({
|
|
|
1166
1210
|
? h(
|
|
1167
1211
|
'div',
|
|
1168
1212
|
{ className: 'fb-session-grid' },
|
|
1169
|
-
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 })),
|
|
1170
1214
|
)
|
|
1171
1215
|
: null,
|
|
1172
1216
|
withheld > 0
|
|
@@ -1219,6 +1263,109 @@ function EmptyState({ board }) {
|
|
|
1219
1263
|
)
|
|
1220
1264
|
}
|
|
1221
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
|
+
|
|
1222
1369
|
/** Loading placeholder that mirrors the KPI grid shape. */
|
|
1223
1370
|
function Skeleton() {
|
|
1224
1371
|
return h(
|
|
@@ -1250,6 +1397,8 @@ function EmptyState({ board }) {
|
|
|
1250
1397
|
// Rows removed from the board. Display-only: nothing on disk is touched.
|
|
1251
1398
|
const [hidden, setHidden] = useState(() => loadHidden())
|
|
1252
1399
|
const [menu, setMenu] = useState(null)
|
|
1400
|
+
// `{ item, loading, data }` while the drawer is open, null when closed.
|
|
1401
|
+
const [detail, setDetail] = useState(null)
|
|
1253
1402
|
const [starred, setStarred] = useState(() => loadStarred())
|
|
1254
1403
|
const [agentScope, setAgentScope] = useState('d1')
|
|
1255
1404
|
const board = state.data
|
|
@@ -1267,17 +1416,51 @@ function EmptyState({ board }) {
|
|
|
1267
1416
|
|
|
1268
1417
|
const onOpen = useCallback(
|
|
1269
1418
|
async (item) => {
|
|
1419
|
+
// A DSH session opens inside the host, no terminal involved.
|
|
1270
1420
|
if (item.sessionId) {
|
|
1271
1421
|
if (openSession(ctx, item.sessionId)) return
|
|
1272
1422
|
flash('宿主没有提供会话跳转接口')
|
|
1273
1423
|
return
|
|
1274
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
|
+
}
|
|
1275
1435
|
const copied = await copyText(item.workspace)
|
|
1276
1436
|
flash(copied ? `已复制工作区路径:${item.workspace}` : `工作区:${item.workspace}`)
|
|
1277
1437
|
},
|
|
1278
1438
|
[ctx, flash],
|
|
1279
1439
|
)
|
|
1280
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
|
+
|
|
1281
1464
|
const hideItem = useCallback(
|
|
1282
1465
|
(item) => {
|
|
1283
1466
|
const next = new Set(hidden)
|
|
@@ -1323,6 +1506,11 @@ function EmptyState({ board }) {
|
|
|
1323
1506
|
hint: '不影响数据',
|
|
1324
1507
|
onSelect: () => hideItem(item),
|
|
1325
1508
|
},
|
|
1509
|
+
{
|
|
1510
|
+
label: '查看详情',
|
|
1511
|
+
icon: 'ⓘ',
|
|
1512
|
+
onSelect: () => openDetail(item),
|
|
1513
|
+
},
|
|
1326
1514
|
{
|
|
1327
1515
|
label: starred.has(itemKey(item)) ? '取消标星' : '标星并置顶',
|
|
1328
1516
|
icon: '★',
|
|
@@ -1330,7 +1518,7 @@ function EmptyState({ board }) {
|
|
|
1330
1518
|
},
|
|
1331
1519
|
{ separator: true },
|
|
1332
1520
|
{
|
|
1333
|
-
label: item.sessionId ? '打开会话' : '复制工作区路径',
|
|
1521
|
+
label: item.sessionId ? '打开会话' : item.openLabel || '复制工作区路径',
|
|
1334
1522
|
icon: '↗',
|
|
1335
1523
|
onSelect: () => onOpen(item),
|
|
1336
1524
|
},
|
|
@@ -1353,7 +1541,7 @@ function EmptyState({ board }) {
|
|
|
1353
1541
|
]
|
|
1354
1542
|
: []),
|
|
1355
1543
|
]
|
|
1356
|
-
}, [menu, hidden, starred, hideItem, restoreHidden, toggleStar, onOpen, flash])
|
|
1544
|
+
}, [menu, hidden, starred, hideItem, restoreHidden, toggleStar, openDetail, onOpen, flash])
|
|
1357
1545
|
|
|
1358
1546
|
const filters = { query, range, status: statusFilter, tool: toolFilter }
|
|
1359
1547
|
const filtered = useMemo(() => {
|
|
@@ -1508,6 +1696,7 @@ function EmptyState({ board }) {
|
|
|
1508
1696
|
),
|
|
1509
1697
|
|
|
1510
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,
|
|
1511
1700
|
|
|
1512
1701
|
state.error && !board
|
|
1513
1702
|
? h('div', { className: 'fb-error' }, `读取失败:${state.error}`)
|
|
@@ -1849,6 +2038,7 @@ function EmptyState({ board }) {
|
|
|
1849
2038
|
defaultOpen: true,
|
|
1850
2039
|
onOpen,
|
|
1851
2040
|
onMenu: openMenu,
|
|
2041
|
+
onDetail: openDetail,
|
|
1852
2042
|
starSet: starred,
|
|
1853
2043
|
onStar: toggleStar,
|
|
1854
2044
|
hint: '你标过的',
|
|
@@ -1859,6 +2049,7 @@ function EmptyState({ board }) {
|
|
|
1859
2049
|
color: STATUS['needs-you'].color,
|
|
1860
2050
|
defaultOpen: true,
|
|
1861
2051
|
onMenu: openMenu,
|
|
2052
|
+
onDetail: openDetail,
|
|
1862
2053
|
starSet: starred,
|
|
1863
2054
|
onStar: toggleStar,
|
|
1864
2055
|
onOpen,
|
|
@@ -1869,6 +2060,7 @@ function EmptyState({ board }) {
|
|
|
1869
2060
|
color: STATUS.running.color,
|
|
1870
2061
|
defaultOpen: true,
|
|
1871
2062
|
onMenu: openMenu,
|
|
2063
|
+
onDetail: openDetail,
|
|
1872
2064
|
starSet: starred,
|
|
1873
2065
|
onStar: toggleStar,
|
|
1874
2066
|
onOpen,
|
|
@@ -1879,6 +2071,7 @@ function EmptyState({ board }) {
|
|
|
1879
2071
|
color: STATUS.done.color,
|
|
1880
2072
|
defaultOpen: false,
|
|
1881
2073
|
onMenu: openMenu,
|
|
2074
|
+
onDetail: openDetail,
|
|
1882
2075
|
starSet: starred,
|
|
1883
2076
|
onStar: toggleStar,
|
|
1884
2077
|
onOpen,
|
|
@@ -1890,6 +2083,7 @@ function EmptyState({ board }) {
|
|
|
1890
2083
|
color: STATUS.recent.color,
|
|
1891
2084
|
defaultOpen: true,
|
|
1892
2085
|
onMenu: openMenu,
|
|
2086
|
+
onDetail: openDetail,
|
|
1893
2087
|
starSet: starred,
|
|
1894
2088
|
onStar: toggleStar,
|
|
1895
2089
|
onOpen,
|
|
@@ -1901,6 +2095,7 @@ function EmptyState({ board }) {
|
|
|
1901
2095
|
color: STATUS.idle.color,
|
|
1902
2096
|
defaultOpen: false,
|
|
1903
2097
|
onMenu: openMenu,
|
|
2098
|
+
onDetail: openDetail,
|
|
1904
2099
|
starSet: starred,
|
|
1905
2100
|
onStar: toggleStar,
|
|
1906
2101
|
onOpen,
|
|
@@ -2073,6 +2268,9 @@ function EmptyState({ board }) {
|
|
|
2073
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}
|
|
2074
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}
|
|
2075
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}
|
|
2076
2274
|
.fb-meter{width:52px;height:4px;border-radius:999px;background:var(--fb-line-soft);overflow:hidden;flex:none;display:inline-block}
|
|
2077
2275
|
.fb-meter i{display:block;height:100%;border-radius:999px;background:#d98324}
|
|
2078
2276
|
.fb-status{display:inline-flex;align-items:center;gap:5px;font-size:11px;padding:2px 9px;border-radius:999px;white-space:nowrap}
|
|
@@ -2084,6 +2282,32 @@ function EmptyState({ board }) {
|
|
|
2084
2282
|
/* The tail of a long band: one quiet row instead of a wall of history. */
|
|
2085
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}
|
|
2086
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
|
+
|
|
2087
2311
|
/* Right-click menu: floats above the board, clamped to the viewport. */
|
|
2088
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}
|
|
2089
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}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IO capabilities: how to get records out of a store, without knowing what a
|
|
3
|
+
* session is.
|
|
4
|
+
*
|
|
5
|
+
* A capability answers exactly one question — "give me rows" — and knows nothing
|
|
6
|
+
* about titles, statuses or workspace labels. That separation is what lets four
|
|
7
|
+
* stores with four different schemas share one read path while each keeps its
|
|
8
|
+
* own query: the query is the store's shape, the read is the same every time.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately not a spec-driven mini-ORM. Lifting the per-store SQL into
|
|
11
|
+
* declarative data would need joins, subqueries, side tables and filters to be
|
|
12
|
+
* expressible, and the four stores disagree on every one of those — the result
|
|
13
|
+
* would be a query builder with four callers, which is worse than four readable
|
|
14
|
+
* queries. See `lib/sources.mjs` for the declarative layer that *is* worth it:
|
|
15
|
+
* deciding whether an unknown store is readable at all.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { existsSync } from 'node:fs'
|
|
19
|
+
|
|
20
|
+
/** Open one SQLite file read-only through the built-in driver. */
|
|
21
|
+
export async function openSqlite(path) {
|
|
22
|
+
const { DatabaseSync } = await import('node:sqlite')
|
|
23
|
+
try {
|
|
24
|
+
return new DatabaseSync(path, { readOnly: true })
|
|
25
|
+
} catch {
|
|
26
|
+
// Pre-existing fallback, kept as-is by this refactor: some stores refuse a
|
|
27
|
+
// read-only open (locking), and the board would rather read them than skip
|
|
28
|
+
// them. It is the one place this plugin opens a database writable, which is
|
|
29
|
+
// why the README's "always readOnly" wording needs fixing separately.
|
|
30
|
+
return new DatabaseSync(path)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Read one SQLite-backed store.
|
|
36
|
+
*
|
|
37
|
+
* The four hand-written SQLite collectors had ~25 lines of identical scaffold
|
|
38
|
+
* each — file check, open, query, count, close, and a catch that reports the
|
|
39
|
+
* failure as one unavailable source. That scaffold is what this function is: the
|
|
40
|
+
* only parts each store keeps are its path, its two queries and its row mapper.
|
|
41
|
+
*
|
|
42
|
+
* @param tool - source id, also the `tool` on every row.
|
|
43
|
+
* @param candidates - database paths, first existing one wins.
|
|
44
|
+
* @param missing - why the source is unavailable when no candidate exists.
|
|
45
|
+
* @param now - current epoch-ms, passed through to `map`.
|
|
46
|
+
* @param conf - tunables; `perSource` caps the rows.
|
|
47
|
+
* @param countSql - one-row query returning the store's total as `n`.
|
|
48
|
+
* @param rowSql - the row query; its last `?` is `conf.perSource`.
|
|
49
|
+
* @param map - row → board item. Receives `{ now, conf }` as the second argument.
|
|
50
|
+
*/
|
|
51
|
+
export async function readSqliteSource({ tool, candidates, missing, now, conf, countSql, rowSql, map }) {
|
|
52
|
+
const path = candidates.find((candidate) => existsSync(candidate))
|
|
53
|
+
if (!path) return { tool, available: false, reason: missing }
|
|
54
|
+
let db
|
|
55
|
+
try {
|
|
56
|
+
db = await openSqlite(path)
|
|
57
|
+
const rows = db.prepare(rowSql).all(conf.perSource)
|
|
58
|
+
const total = db.prepare(countSql).get()?.n ?? rows.length
|
|
59
|
+
const items = rows.map((row) => map(row, { now, conf }))
|
|
60
|
+
return { tool, available: true, count: Number(total), items }
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return { tool, available: false, reason: String(error?.message ?? error) }
|
|
63
|
+
} finally {
|
|
64
|
+
try {
|
|
65
|
+
db?.close()
|
|
66
|
+
} catch {
|
|
67
|
+
/* already gone */
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|