dsh-any-agent 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/bin/dsh-any-agent.mjs +23 -1
- package/docs/en/reference.md +2 -0
- package/docs/en/security.md +1 -0
- package/docs/en/tests.md +4 -2
- package/docs/en/usage.md +22 -0
- package/docs/zh/live-view-design.md +192 -0
- package/docs/zh/reference.md +2 -0
- package/docs/zh/security.md +1 -0
- package/docs/zh/tests.md +4 -2
- package/docs/zh/usage.md +22 -0
- package/package.json +1 -1
- package/src/config.mjs +25 -0
- package/src/conversation.mjs +121 -7
- package/src/hub.mjs +7 -0
- package/src/live-cli.mjs +115 -0
- package/src/live-dashboard.html +535 -0
- package/src/live-dashboard.mjs +176 -0
- package/src/live-view.mjs +592 -0
- package/src/live.mjs +186 -0
- package/src/mcp.mjs +3 -0
- package/src/residue.mjs +7 -3
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<meta name="referrer" content="no-referrer">
|
|
7
|
+
<title>DSH Live</title>
|
|
8
|
+
<style>
|
|
9
|
+
:root {
|
|
10
|
+
--bg: #f7f7f8; --surface: #ffffff; --sunken: #f1f1f3; --line: #e6e6ea; --line-2: #d9d9df;
|
|
11
|
+
--text: #17171c; --text-2: #55555f; --text-3: #8a8a95;
|
|
12
|
+
--accent: #4f5bd5; --accent-soft: #eceefd;
|
|
13
|
+
--ok: #1a8f5a; --ok-soft: #e5f4ec; --bad: #c8414b; --bad-soft: #fbeaeb;
|
|
14
|
+
--warn: #a8660b; --warn-soft: #fbf1df; --run: #4f5bd5; --run-soft: #eceefd;
|
|
15
|
+
--bar: #c9cdf3; --bar-run: #4f5bd5; --bar-ok: #9fd4b8; --bar-bad: #eba3a8;
|
|
16
|
+
--mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
|
|
17
|
+
--sans: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
|
18
|
+
--r: 8px;
|
|
19
|
+
color-scheme: light;
|
|
20
|
+
}
|
|
21
|
+
@media (prefers-color-scheme: dark) {
|
|
22
|
+
:root:not([data-theme="light"]) {
|
|
23
|
+
--bg: #0e0e11; --surface: #16161a; --sunken: #1c1c21; --line: #26262d; --line-2: #33333c;
|
|
24
|
+
--text: #ececf1; --text-2: #a5a5b1; --text-3: #6f6f7c;
|
|
25
|
+
--accent: #8d96ff; --accent-soft: #1f2140;
|
|
26
|
+
--ok: #4fc58a; --ok-soft: #13271d; --bad: #f07a82; --bad-soft: #2d1619;
|
|
27
|
+
--warn: #e7ae4c; --warn-soft: #2a2112; --run: #8d96ff; --run-soft: #1f2140;
|
|
28
|
+
--bar: #2f3363; --bar-run: #8d96ff; --bar-ok: #24563d; --bar-bad: #6b2b31;
|
|
29
|
+
color-scheme: dark;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
:root[data-theme="dark"] {
|
|
33
|
+
--bg: #0e0e11; --surface: #16161a; --sunken: #1c1c21; --line: #26262d; --line-2: #33333c;
|
|
34
|
+
--text: #ececf1; --text-2: #a5a5b1; --text-3: #6f6f7c;
|
|
35
|
+
--accent: #8d96ff; --accent-soft: #1f2140;
|
|
36
|
+
--ok: #4fc58a; --ok-soft: #13271d; --bad: #f07a82; --bad-soft: #2d1619;
|
|
37
|
+
--warn: #e7ae4c; --warn-soft: #2a2112; --run: #8d96ff; --run-soft: #1f2140;
|
|
38
|
+
--bar: #2f3363; --bar-run: #8d96ff; --bar-ok: #24563d; --bar-bad: #6b2b31;
|
|
39
|
+
color-scheme: dark;
|
|
40
|
+
}
|
|
41
|
+
* { box-sizing: border-box; }
|
|
42
|
+
html, body { margin: 0; height: 100%; }
|
|
43
|
+
body { background: var(--bg); color: var(--text); font: 13.5px/1.5 var(--sans); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
|
|
44
|
+
button { font: inherit; color: inherit; }
|
|
45
|
+
.mono { font-family: var(--mono); font-size: 12px; }
|
|
46
|
+
|
|
47
|
+
/* ── 顶栏 ───────────────────────────────── */
|
|
48
|
+
.top { display: flex; align-items: center; gap: 20px; height: 52px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 3; }
|
|
49
|
+
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 14px; letter-spacing: .1px; white-space: nowrap; }
|
|
50
|
+
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--text); color: var(--surface); display: grid; place-items: center; font: 700 11px/1 var(--mono); }
|
|
51
|
+
.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); font-weight: 400; }
|
|
52
|
+
.conn i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
|
|
53
|
+
.conn.on i { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
|
|
54
|
+
.stats { display: flex; align-items: stretch; height: 100%; margin-left: 4px; }
|
|
55
|
+
.stat { display: flex; flex-direction: column; justify-content: center; padding: 0 16px; border-left: 1px solid var(--line); min-width: 74px; }
|
|
56
|
+
.stat b { font-size: 15px; font-weight: 650; line-height: 1.1; }
|
|
57
|
+
.stat span { font-size: 11px; color: var(--text-3); }
|
|
58
|
+
.stat.hot b { color: var(--run); }
|
|
59
|
+
.stat.warn b { color: var(--warn); }
|
|
60
|
+
.stat.zero b { color: var(--text-3); font-weight: 500; }
|
|
61
|
+
.grow { flex: 1; }
|
|
62
|
+
.search { position: relative; }
|
|
63
|
+
.search input { font: inherit; font-size: 12.5px; height: 30px; width: 240px; padding: 0 10px 0 28px; border: 1px solid var(--line); border-radius: 7px; background: var(--sunken); color: var(--text); outline: none; }
|
|
64
|
+
.search input:focus { border-color: var(--accent); background: var(--surface); }
|
|
65
|
+
.search svg { position: absolute; left: 9px; top: 9px; color: var(--text-3); }
|
|
66
|
+
|
|
67
|
+
/* ── 布局 ───────────────────────────────── */
|
|
68
|
+
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); height: calc(100% - 52px); }
|
|
69
|
+
.rail { border-right: 1px solid var(--line); overflow: auto; background: var(--surface); }
|
|
70
|
+
.main { overflow: auto; }
|
|
71
|
+
|
|
72
|
+
/* ── 左栏 ───────────────────────────────── */
|
|
73
|
+
.grp { padding: 14px 0 6px; }
|
|
74
|
+
.grp + .grp { border-top: 1px solid var(--line); }
|
|
75
|
+
.grp-h { display: flex; align-items: baseline; gap: 8px; padding: 0 16px 6px; }
|
|
76
|
+
.grp-h b { font-size: 12px; font-weight: 600; }
|
|
77
|
+
.grp-h span { font-size: 11px; color: var(--text-3); }
|
|
78
|
+
.grp-h .gone { color: var(--bad); }
|
|
79
|
+
.cv { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; column-gap: 10px; padding: 8px 16px; cursor: pointer; position: relative; outline: none; }
|
|
80
|
+
.cv:hover { background: var(--sunken); }
|
|
81
|
+
.cv:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
|
|
82
|
+
.cv.sel { background: var(--accent-soft); }
|
|
83
|
+
.cv.sel::before { content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 2px; border-radius: 2px; background: var(--accent); }
|
|
84
|
+
.cv .sd { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: var(--line-2); }
|
|
85
|
+
.cv .sd.running { background: var(--run); animation: pulse 1.6s ease-in-out infinite; }
|
|
86
|
+
.cv .sd.queued { background: var(--warn); }
|
|
87
|
+
.cv .ti { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
88
|
+
.cv .ago { font-size: 11px; color: var(--text-3); white-space: nowrap; }
|
|
89
|
+
.cv .sub { grid-column: 2 / 4; font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
90
|
+
.cv .sub .mono { color: var(--text-3); }
|
|
91
|
+
.cv .flag { color: var(--warn); }
|
|
92
|
+
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .35 } }
|
|
93
|
+
|
|
94
|
+
/* ── 主区 ───────────────────────────────── */
|
|
95
|
+
.wrap { max-width: 1080px; padding: 22px 28px 48px; }
|
|
96
|
+
.hd h1 { font-size: 19px; font-weight: 650; margin: 0 0 10px; letter-spacing: -.1px; word-break: break-word; }
|
|
97
|
+
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 24px; padding: 12px 16px; margin: 0 0 24px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
|
|
98
|
+
.fact { min-width: 0; }
|
|
99
|
+
.fact.wide { grid-column: span 2; }
|
|
100
|
+
.fact dt { font-size: 11px; color: var(--text-3); margin: 0 0 2px; }
|
|
101
|
+
.fact dd { margin: 0; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; }
|
|
102
|
+
.fact dd.path { direction: rtl; text-align: left; }
|
|
103
|
+
.sec-h { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; }
|
|
104
|
+
.sec-h h2 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); margin: 0; }
|
|
105
|
+
.sec-h span { font-size: 12px; color: var(--text-3); }
|
|
106
|
+
|
|
107
|
+
/* ── 调用链:回合 ───────────────────────── */
|
|
108
|
+
.turns { position: relative; }
|
|
109
|
+
.turn { position: relative; padding-left: 26px; padding-bottom: 14px; }
|
|
110
|
+
.turn::before { content: ""; position: absolute; left: 7px; top: 22px; bottom: 0; width: 1px; background: var(--line-2); }
|
|
111
|
+
.turn:last-child::before { display: none; }
|
|
112
|
+
.node { position: absolute; left: 1px; top: 13px; width: 13px; height: 13px; border-radius: 50%; background: var(--surface); border: 2px solid var(--line-2); }
|
|
113
|
+
.turn.running .node { border-color: var(--run); background: var(--run); box-shadow: 0 0 0 4px var(--run-soft); }
|
|
114
|
+
.turn.done .node { border-color: var(--ok); }
|
|
115
|
+
.turn.error .node, .turn.interrupted .node { border-color: var(--bad); background: var(--bad); }
|
|
116
|
+
.turn.queued .node { border-color: var(--warn); border-style: dashed; }
|
|
117
|
+
.turn.cancelled .node { border-color: var(--text-3); }
|
|
118
|
+
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
|
|
119
|
+
.turn.running .card { border-color: color-mix(in srgb, var(--run) 35%, var(--line)); }
|
|
120
|
+
.card-h { display: flex; align-items: center; gap: 8px; padding: 9px 12px; cursor: pointer; user-select: none; flex-wrap: wrap; }
|
|
121
|
+
.card-h:hover { background: var(--sunken); }
|
|
122
|
+
.chev { color: var(--text-3); transition: transform .15s ease; flex: none; }
|
|
123
|
+
.collapsed .chev { transform: rotate(-90deg); }
|
|
124
|
+
.tag { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 5px; background: var(--sunken); color: var(--text-2); white-space: nowrap; }
|
|
125
|
+
.tag.running { background: var(--run-soft); color: var(--run); }
|
|
126
|
+
.tag.done { background: var(--ok-soft); color: var(--ok); }
|
|
127
|
+
.tag.error, .tag.interrupted { background: var(--bad-soft); color: var(--bad); }
|
|
128
|
+
.tag.queued, .tag.warn { background: var(--warn-soft); color: var(--warn); }
|
|
129
|
+
.tag.ghost { background: transparent; border: 1px solid var(--line-2); color: var(--text-3); font-weight: 500; }
|
|
130
|
+
.card-h .rid { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); }
|
|
131
|
+
.card-h .right { margin-left: auto; display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--text-3); white-space: nowrap; }
|
|
132
|
+
.card-h .right b { color: var(--text-2); font-weight: 600; }
|
|
133
|
+
.prompt { margin: 0 12px 10px 34px; padding: 6px 10px; border-left: 2px solid var(--line-2); color: var(--text-2); font-size: 13px; word-break: break-word; }
|
|
134
|
+
.errline { margin: 0 12px 10px 34px; padding: 6px 10px; border-radius: 6px; background: var(--bad-soft); color: var(--bad); font: 12px/1.45 var(--mono); word-break: break-word; }
|
|
135
|
+
.collapsed .body { display: none; }
|
|
136
|
+
|
|
137
|
+
/* ── 调用链:工具 / 审批(带时间条) ─────── */
|
|
138
|
+
.spans { border-top: 1px solid var(--line); }
|
|
139
|
+
.span { display: grid; grid-template-columns: 22px 92px minmax(0, 1fr) minmax(120px, 26%) 62px; align-items: center; gap: 10px; padding: 0 12px; height: 32px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
|
|
140
|
+
.span:last-child { border-bottom: 0; }
|
|
141
|
+
.span:hover { background: var(--sunken); }
|
|
142
|
+
.span .st { display: grid; place-items: center; }
|
|
143
|
+
.span .st i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
|
|
144
|
+
.span.ok .st i { background: var(--ok); }
|
|
145
|
+
.span.fail .st i { background: var(--bad); }
|
|
146
|
+
.span.live .st i { background: var(--run); animation: pulse 1.6s ease-in-out infinite; }
|
|
147
|
+
.span .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
148
|
+
.span .kd { font-weight: 400; color: var(--text-3); font-size: 11px; margin-left: 4px; }
|
|
149
|
+
.span .in { font-family: var(--mono); font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
150
|
+
.track { position: relative; height: 8px; border-radius: 4px; background: var(--sunken); overflow: hidden; }
|
|
151
|
+
.track b { position: absolute; top: 0; bottom: 0; min-width: 3px; border-radius: 4px; background: var(--bar); }
|
|
152
|
+
.span.ok .track b { background: var(--bar-ok); }
|
|
153
|
+
.span.fail .track b { background: var(--bar-bad); }
|
|
154
|
+
.span.live .track b { background: var(--bar-run); }
|
|
155
|
+
.span .tm { text-align: right; font-size: 12px; color: var(--text-3); white-space: nowrap; }
|
|
156
|
+
.span.flagged { background: var(--warn-soft); }
|
|
157
|
+
.span.flagged:hover { background: var(--warn-soft); }
|
|
158
|
+
.span.flagged .st { color: var(--warn); font-size: 12px; }
|
|
159
|
+
.span.flagged .nm { color: var(--warn); }
|
|
160
|
+
.span.flagged .tm { color: var(--warn); font-weight: 600; }
|
|
161
|
+
.span.note .st { color: var(--text-3); font-size: 12px; }
|
|
162
|
+
.span.note .nm { color: var(--text-2); font-weight: 500; }
|
|
163
|
+
.span.stop .st, .span.stop .nm { color: var(--bad); }
|
|
164
|
+
.span .esc { font-family: var(--sans); font-size: 11px; font-weight: 600; color: var(--warn); margin-right: 6px; }
|
|
165
|
+
.more { padding: 6px 12px 6px 44px; font-size: 12px; color: var(--text-3); border-bottom: 1px solid var(--line); }
|
|
166
|
+
|
|
167
|
+
/* ── 空状态 ─────────────────────────────── */
|
|
168
|
+
.empty { display: grid; place-items: center; text-align: center; color: var(--text-3); padding: 72px 24px; }
|
|
169
|
+
.empty h3 { margin: 0 0 6px; font-size: 14px; color: var(--text-2); font-weight: 600; }
|
|
170
|
+
.empty p { margin: 0; font-size: 12.5px; max-width: 360px; }
|
|
171
|
+
.empty code { font-family: var(--mono); font-size: 12px; background: var(--sunken); padding: 1px 6px; border-radius: 4px; color: var(--text-2); }
|
|
172
|
+
.rail .empty { padding: 40px 18px; }
|
|
173
|
+
.foot { margin-top: 18px; font-size: 11.5px; color: var(--text-3); }
|
|
174
|
+
|
|
175
|
+
/* ── 窄屏 ───────────────────────────────── */
|
|
176
|
+
@media (max-width: 820px) {
|
|
177
|
+
.top { height: auto; flex-wrap: wrap; gap: 10px 16px; padding: 10px 16px; position: static; }
|
|
178
|
+
.stats { height: 40px; margin-left: 0; order: 3; width: 100%; }
|
|
179
|
+
.stat { flex: 1; min-width: 0; padding: 0 10px; }
|
|
180
|
+
.stat span { white-space: nowrap; }
|
|
181
|
+
.stat:first-child { border-left: 0; padding-left: 0; }
|
|
182
|
+
.search { margin-left: auto; }
|
|
183
|
+
.search input { width: 180px; }
|
|
184
|
+
.layout { grid-template-columns: 1fr; height: auto; }
|
|
185
|
+
.rail { border-right: 0; border-bottom: 1px solid var(--line); max-height: 300px; }
|
|
186
|
+
.wrap { padding: 18px 16px 40px; }
|
|
187
|
+
.span { grid-template-columns: 18px minmax(0, 1fr) 56px; height: auto; padding: 7px 12px; row-gap: 3px; }
|
|
188
|
+
.span .st { grid-row: 1; grid-column: 1; }
|
|
189
|
+
.span .nm { grid-row: 1; grid-column: 2; }
|
|
190
|
+
.span .tm { grid-row: 1; grid-column: 3; }
|
|
191
|
+
.span .in { grid-row: 2; grid-column: 2 / 4; }
|
|
192
|
+
.span .track { grid-row: 3; grid-column: 2 / 4; height: 4px; }
|
|
193
|
+
.prompt, .errline { margin-left: 12px; }
|
|
194
|
+
.card-h .right { margin-left: 0; width: 100%; }
|
|
195
|
+
.fact dd { max-width: 240px; }
|
|
196
|
+
}
|
|
197
|
+
</style>
|
|
198
|
+
</head>
|
|
199
|
+
<body>
|
|
200
|
+
<header class="top">
|
|
201
|
+
<div class="brand"><span class="brand-mark">DS</span>DSH Live <span class="conn" id="conn"><i></i><span>连接中</span></span></div>
|
|
202
|
+
<div class="stats" id="stats"></div>
|
|
203
|
+
<div class="grow"></div>
|
|
204
|
+
<label class="search">
|
|
205
|
+
<svg width="12" height="12" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="7" cy="7" r="5"/><path d="M11 11l4 4"/></svg>
|
|
206
|
+
<input type="search" id="q" placeholder="筛选标题、id、目录" aria-label="筛选会话">
|
|
207
|
+
</label>
|
|
208
|
+
</header>
|
|
209
|
+
<div class="layout">
|
|
210
|
+
<nav class="rail" id="rail" aria-label="会话"></nav>
|
|
211
|
+
<main class="main" id="main" aria-live="polite"></main>
|
|
212
|
+
</div>
|
|
213
|
+
<script>
|
|
214
|
+
(() => {
|
|
215
|
+
'use strict';
|
|
216
|
+
const token = new URLSearchParams(location.search).get('t') || '';
|
|
217
|
+
const $ = (id) => document.getElementById(id);
|
|
218
|
+
const store = {
|
|
219
|
+
get(k) { try { return localStorage.getItem(k); } catch { return null; } },
|
|
220
|
+
set(k, v) { try { localStorage.setItem(k, v); } catch {} },
|
|
221
|
+
};
|
|
222
|
+
let view = null;
|
|
223
|
+
let selected = store.get('dsh-live-sel');
|
|
224
|
+
const collapsed = new Set();
|
|
225
|
+
let q = '';
|
|
226
|
+
|
|
227
|
+
// 只用 textContent 建 DOM:事件内容来自磁盘文件,绝不当 HTML 解析。
|
|
228
|
+
function h(tag, cls, text) {
|
|
229
|
+
const n = document.createElement(tag);
|
|
230
|
+
if (cls) n.className = cls;
|
|
231
|
+
if (text !== undefined && text !== null && text !== '') n.textContent = String(text);
|
|
232
|
+
return n;
|
|
233
|
+
}
|
|
234
|
+
const short = (id) => String(id || '').slice(0, 8);
|
|
235
|
+
const base = (p) => String(p || '').split(/[\\/]/).filter(Boolean).pop() || p || '';
|
|
236
|
+
function dur(v) {
|
|
237
|
+
if (v === null || v === undefined || !isFinite(v)) return '';
|
|
238
|
+
if (v < 1000) return Math.round(v) + 'ms';
|
|
239
|
+
if (v < 60000) return (v / 1000).toFixed(v < 10000 ? 1 : 0) + 's';
|
|
240
|
+
const m = Math.floor(v / 60000);
|
|
241
|
+
return m + 'm' + String(Math.round((v % 60000) / 1000)).padStart(2, '0') + 's';
|
|
242
|
+
}
|
|
243
|
+
function ago(ts) {
|
|
244
|
+
if (!ts) return '';
|
|
245
|
+
const s = Math.max(0, (Date.now() - Date.parse(ts)) / 1000);
|
|
246
|
+
if (s < 45) return '刚刚';
|
|
247
|
+
if (s < 3600) return Math.round(s / 60) + ' 分钟前';
|
|
248
|
+
if (s < 86400) return Math.round(s / 3600) + ' 小时前';
|
|
249
|
+
return Math.round(s / 86400) + ' 天前';
|
|
250
|
+
}
|
|
251
|
+
const t = (ts) => (ts ? Date.parse(ts) : NaN);
|
|
252
|
+
const STATE = { running: '运行中', queued: '排队中', idle: '空闲', closed: '已释放' };
|
|
253
|
+
const RUN = { running: '运行中', queued: '排队', done: '完成', error: '出错', cancelled: '已取消', interrupted: '中断' };
|
|
254
|
+
const VIA = { send: '派活', queue: '排队', interject: '插话' };
|
|
255
|
+
const TOOL = { pending: '等待', in_progress: '进行中', unfinished: '未完成', completed: '完成', failed: '失败' };
|
|
256
|
+
const MODE = { 'auto-allow': '自动放行', 'auto-deny': '自动拒绝', 'read-only-deny': '只读拒绝', ask: '待人工裁决' };
|
|
257
|
+
|
|
258
|
+
function convs() {
|
|
259
|
+
const out = [];
|
|
260
|
+
for (const g of (view && view.groups) || []) for (const c of g.conversations) out.push(c);
|
|
261
|
+
return out;
|
|
262
|
+
}
|
|
263
|
+
const match = (c) => !q || [c.title, c.id, c.cwd, c.client].some((v) => v && String(v).toLowerCase().includes(q));
|
|
264
|
+
|
|
265
|
+
function renderStats() {
|
|
266
|
+
const s = view.totals;
|
|
267
|
+
const box = $('stats');
|
|
268
|
+
box.replaceChildren();
|
|
269
|
+
const stat = (n, label, cls) => {
|
|
270
|
+
const d = h('div', 'stat ' + (n ? cls || '' : 'zero'));
|
|
271
|
+
d.append(h('b', null, String(n)), h('span', null, label));
|
|
272
|
+
box.append(d);
|
|
273
|
+
};
|
|
274
|
+
stat(s.conversations, '会话', '');
|
|
275
|
+
stat(s.running, '运行中', 'hot');
|
|
276
|
+
stat(s.queued, '排队', 'warn');
|
|
277
|
+
stat(s.pending_approvals, '待审批', 'warn');
|
|
278
|
+
stat(s.escalations, '提权', 'warn');
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function renderRail() {
|
|
282
|
+
const rail = $('rail');
|
|
283
|
+
rail.replaceChildren();
|
|
284
|
+
let any = false;
|
|
285
|
+
for (const g of view.groups) {
|
|
286
|
+
const list = g.conversations.filter(match);
|
|
287
|
+
if (!list.length) continue;
|
|
288
|
+
any = true;
|
|
289
|
+
const grp = h('section', 'grp');
|
|
290
|
+
const gh = h('div', 'grp-h');
|
|
291
|
+
gh.append(h('b', null, g.client || '未知客户端'));
|
|
292
|
+
gh.append(h('span', 'mono', 'pid ' + (g.pid || '?')));
|
|
293
|
+
if (!g.alive) gh.append(h('span', 'gone', '已退出'));
|
|
294
|
+
grp.append(gh);
|
|
295
|
+
for (const c of list) {
|
|
296
|
+
const row = h('div', 'cv' + (c.id === selected ? ' sel' : ''));
|
|
297
|
+
row.tabIndex = 0;
|
|
298
|
+
row.setAttribute('role', 'button');
|
|
299
|
+
row.setAttribute('aria-pressed', String(c.id === selected));
|
|
300
|
+
row.append(h('i', 'sd ' + c.state));
|
|
301
|
+
row.append(h('div', 'ti', c.title || '无标题 · ' + short(c.id)));
|
|
302
|
+
row.append(h('div', 'ago', ago(c.last_ts)));
|
|
303
|
+
const sub = h('div', 'sub');
|
|
304
|
+
const active = c.runs.find((r) => r.status === 'running');
|
|
305
|
+
const pend = c.runs.reduce((n, r) => n + r.pending_approvals, 0);
|
|
306
|
+
sub.append(document.createTextNode(active && active.current_tool ? '▸ ' + active.current_tool : STATE[c.state] || c.state));
|
|
307
|
+
if (pend) sub.append(h('span', 'flag', ' · ' + pend + ' 待审批'));
|
|
308
|
+
sub.append(document.createTextNode(' · '));
|
|
309
|
+
const p = h('span', 'mono', base(c.cwd));
|
|
310
|
+
p.title = c.cwd || '';
|
|
311
|
+
sub.append(p);
|
|
312
|
+
row.append(sub);
|
|
313
|
+
const pick = () => { selected = c.id; store.set('dsh-live-sel', c.id); render(); };
|
|
314
|
+
row.addEventListener('click', pick);
|
|
315
|
+
row.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); pick(); } });
|
|
316
|
+
grp.append(row);
|
|
317
|
+
}
|
|
318
|
+
rail.append(grp);
|
|
319
|
+
}
|
|
320
|
+
if (!any) {
|
|
321
|
+
const e = h('div', 'empty');
|
|
322
|
+
if (q) e.append(h('h3', null, '没有匹配的会话'));
|
|
323
|
+
else {
|
|
324
|
+
e.append(h('h3', null, '还没有事件'));
|
|
325
|
+
const p = h('p');
|
|
326
|
+
p.append('用 ', h('code', null, 'dsh_send'), ' 派一次活,调用链会出现在这里。');
|
|
327
|
+
e.append(p);
|
|
328
|
+
}
|
|
329
|
+
rail.append(e);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** 把会话目录前缀去掉,路径显示成相对路径(悬停仍能看到原文)。 */
|
|
334
|
+
function rel(txt, cwd) {
|
|
335
|
+
if (!txt || !cwd) return txt || '';
|
|
336
|
+
const root = String(cwd).replace(/[\\/]+$/, '');
|
|
337
|
+
let out = String(txt);
|
|
338
|
+
for (const sep of ['\\', '/']) out = out.split(root + sep).join('');
|
|
339
|
+
out = out.split(root).join('.');
|
|
340
|
+
return out;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function spanRow(it, run, t0, total, cwd) {
|
|
344
|
+
if (it.kind === 'tool') {
|
|
345
|
+
const st = it.status;
|
|
346
|
+
const cls = st === 'completed' ? 'ok' : st === 'failed' ? 'fail' : st === 'unfinished' ? '' : 'live';
|
|
347
|
+
const row = h('div', 'span ' + cls);
|
|
348
|
+
const s = h('span', 'st'); s.append(h('i')); row.append(s);
|
|
349
|
+
const label = it.name || it.title || 'tool';
|
|
350
|
+
const nm = h('span', 'nm', label);
|
|
351
|
+
if (it.tool_kind && it.tool_kind !== 'other' && it.tool_kind !== label) nm.append(h('span', 'kd', it.tool_kind));
|
|
352
|
+
row.append(nm);
|
|
353
|
+
const raw = it.input_preview || (it.title !== label ? it.title : '') || '';
|
|
354
|
+
const inp = h('span', 'in', rel(raw, cwd)); inp.title = raw; row.append(inp);
|
|
355
|
+
row.append(track(it, run, t0, total));
|
|
356
|
+
row.append(h('span', 'tm', it.elapsed_ms != null ? dur(it.elapsed_ms) : TOOL[st] || st || ''));
|
|
357
|
+
return row;
|
|
358
|
+
}
|
|
359
|
+
if (it.kind === 'approval') {
|
|
360
|
+
const row = h('div', 'span flagged');
|
|
361
|
+
row.append(h('span', 'st', '◆'));
|
|
362
|
+
row.append(h('span', 'nm', '审批'));
|
|
363
|
+
const inp = h('span', 'in');
|
|
364
|
+
if (it.escalation) inp.append(h('span', 'esc', '⚠ ' + it.escalation));
|
|
365
|
+
const txt = it.command_preview || it.title || it.tool || '';
|
|
366
|
+
inp.append(document.createTextNode(rel(txt, cwd)));
|
|
367
|
+
inp.title = (it.escalation ? it.escalation + ' ' : '') + txt;
|
|
368
|
+
row.append(inp);
|
|
369
|
+
const d = it.decided;
|
|
370
|
+
row.append(h('span', 'in', d ? '→ ' + (d.decision || d.effective || '') + (d.by ? '(' + d.by + ')' : '') : MODE[it.mode] || it.mode || ''));
|
|
371
|
+
row.append(h('span', 'tm', it.mode === 'ask' && !d ? '等待' : (MODE[it.mode] ? '' : '')));
|
|
372
|
+
return row;
|
|
373
|
+
}
|
|
374
|
+
const row = h('div', 'span note' + (it.kind === 'interrupt' ? ' stop' : ''));
|
|
375
|
+
row.append(h('span', 'st', it.kind === 'interrupt' ? '■' : '↪'));
|
|
376
|
+
row.append(h('span', 'nm', it.kind === 'interrupt' ? '中断' : '插话' + (it.mode ? ' · ' + it.mode : '')));
|
|
377
|
+
row.append(h('span', 'in', it.text_preview || ''));
|
|
378
|
+
row.append(h('span'));
|
|
379
|
+
row.append(h('span', 'tm', ''));
|
|
380
|
+
return row;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** 时间条:工具在本轮里的起点与时长(类似 trace 瀑布图)。 */
|
|
384
|
+
function track(it, run, t0, total) {
|
|
385
|
+
const tr = h('span', 'track');
|
|
386
|
+
const start = t(it.at);
|
|
387
|
+
if (!isFinite(t0) || !isFinite(start) || !(total > 0)) return tr;
|
|
388
|
+
const end = it.elapsed_ms != null ? start + it.elapsed_ms : run.status === 'running' ? Date.now() : t(it.last_at) || start;
|
|
389
|
+
const left = Math.max(0, Math.min(100, ((start - t0) / total) * 100));
|
|
390
|
+
const width = Math.max(0.8, Math.min(100 - left, ((end - start) / total) * 100));
|
|
391
|
+
const b = h('b');
|
|
392
|
+
b.style.left = left + '%';
|
|
393
|
+
b.style.width = width + '%';
|
|
394
|
+
tr.title = dur(start - t0) + ' 起 · ' + dur(end - start);
|
|
395
|
+
tr.append(b);
|
|
396
|
+
return tr;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function chev() {
|
|
400
|
+
const s = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
401
|
+
s.setAttribute('width', '12'); s.setAttribute('height', '12'); s.setAttribute('viewBox', '0 0 16 16'); s.setAttribute('class', 'chev');
|
|
402
|
+
const p = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
|
403
|
+
p.setAttribute('d', 'M4 6l4 4 4-4'); p.setAttribute('fill', 'none'); p.setAttribute('stroke', 'currentColor'); p.setAttribute('stroke-width', '2');
|
|
404
|
+
s.append(p);
|
|
405
|
+
return s;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
function renderMain() {
|
|
409
|
+
const main = $('main');
|
|
410
|
+
main.replaceChildren();
|
|
411
|
+
const all = convs();
|
|
412
|
+
let c = all.find((x) => x.id === selected);
|
|
413
|
+
if (!c) c = all.find((x) => x.state === 'running') || all[0];
|
|
414
|
+
if (!c) {
|
|
415
|
+
const e = h('div', 'empty');
|
|
416
|
+
e.append(h('h3', null, '等待第一条事件'));
|
|
417
|
+
const p = h('p');
|
|
418
|
+
p.append('这是只读视图。服务端写入 ', h('code', null, 'live/'), ' 事件流后,这里按 客户端 → 会话 → 回合 → 工具 展开调用链。');
|
|
419
|
+
e.append(p);
|
|
420
|
+
main.append(e);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
selected = c.id;
|
|
424
|
+
const wrap = h('div', 'wrap');
|
|
425
|
+
const hd = h('div', 'hd');
|
|
426
|
+
hd.append(h('h1', null, c.title || '无标题会话'));
|
|
427
|
+
const facts = h('dl', 'facts');
|
|
428
|
+
const fact = (k, v, cls, full) => {
|
|
429
|
+
if (!v) return;
|
|
430
|
+
const f = h('div', 'fact' + (cls && cls.includes('path') ? ' wide' : ''));
|
|
431
|
+
f.append(h('dt', null, k));
|
|
432
|
+
const dd = h('dd', cls || null);
|
|
433
|
+
// 路径过长时从左边截断(保留末尾的目录名);用 bdi 包住,避免 rtl 把标点甩到另一头。
|
|
434
|
+
const bdi = document.createElement('bdi');
|
|
435
|
+
bdi.textContent = v;
|
|
436
|
+
dd.append(bdi);
|
|
437
|
+
dd.title = full || v;
|
|
438
|
+
f.append(dd);
|
|
439
|
+
facts.append(f);
|
|
440
|
+
};
|
|
441
|
+
fact('状态', STATE[c.state] || c.state);
|
|
442
|
+
fact('客户端', (c.client || '未知') + ' · pid ' + (c.writer ? String(c.writer).split(':')[0] : '?') + (c.writer_alive ? '' : '(已退出)'));
|
|
443
|
+
fact('权限', [c.permission, c.on_approval].filter(Boolean).join(' · '));
|
|
444
|
+
fact('模型', c.model);
|
|
445
|
+
fact('会话 id', short(c.id), 'mono', c.id);
|
|
446
|
+
fact('目录', c.cwd, 'mono path');
|
|
447
|
+
hd.append(facts);
|
|
448
|
+
wrap.append(hd);
|
|
449
|
+
|
|
450
|
+
const sh = h('div', 'sec-h');
|
|
451
|
+
sh.append(h('h2', null, '调用链'), h('span', null, c.runs.length + ' 个回合 · 最新在上'));
|
|
452
|
+
wrap.append(sh);
|
|
453
|
+
|
|
454
|
+
const turns = h('div', 'turns');
|
|
455
|
+
const runs = [...c.runs].reverse();
|
|
456
|
+
if (!runs.length) {
|
|
457
|
+
const e = h('div', 'empty');
|
|
458
|
+
e.append(h('h3', null, '这个会话还没有派过活'));
|
|
459
|
+
turns.append(e);
|
|
460
|
+
}
|
|
461
|
+
for (const r of runs) {
|
|
462
|
+
const key = c.id + '/' + r.run;
|
|
463
|
+
const turn = h('div', 'turn ' + r.status + (collapsed.has(key) ? ' collapsed' : ''));
|
|
464
|
+
turn.append(h('span', 'node'));
|
|
465
|
+
const card = h('div', 'card');
|
|
466
|
+
const head = h('div', 'card-h');
|
|
467
|
+
head.setAttribute('role', 'button');
|
|
468
|
+
head.tabIndex = 0;
|
|
469
|
+
head.append(chev());
|
|
470
|
+
head.append(h('span', 'tag ' + r.status, RUN[r.status] || r.status));
|
|
471
|
+
if (r.via && !(r.status === 'queued' && r.via === 'queue')) head.append(h('span', 'tag ghost', VIA[r.via] || r.via));
|
|
472
|
+
head.append(h('span', 'rid', (r.turn ? '第 ' + r.turn + ' 轮 · ' : '') + r.run));
|
|
473
|
+
if (r.escalations) head.append(h('span', 'tag warn', '⚠ ' + r.escalations + ' 次提权'));
|
|
474
|
+
if (r.pending_approvals) head.append(h('span', 'tag warn', r.pending_approvals + ' 待审批'));
|
|
475
|
+
const right = h('span', 'right');
|
|
476
|
+
const tools = r.items.filter((x) => x.kind === 'tool').length;
|
|
477
|
+
const n = r.tool_count != null ? r.tool_count : tools;
|
|
478
|
+
const rb = h('span'); rb.append(h('b', null, String(n)), ' 个工具'); right.append(rb);
|
|
479
|
+
const t0 = t(r.started_at);
|
|
480
|
+
const total = r.duration_ms != null ? r.duration_ms : r.status === 'running' && isFinite(t0) ? Date.now() - t0 : null;
|
|
481
|
+
if (total != null) { const d = h('span'); d.append(h('b', null, dur(total))); right.append(d); }
|
|
482
|
+
right.append(h('span', null, ago(r.ended_at || r.started_at || r.queued_at)));
|
|
483
|
+
head.append(right);
|
|
484
|
+
const toggle = () => { if (collapsed.has(key)) collapsed.delete(key); else collapsed.add(key); render(); };
|
|
485
|
+
head.addEventListener('click', toggle);
|
|
486
|
+
head.addEventListener('keydown', (e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggle(); } });
|
|
487
|
+
card.append(head);
|
|
488
|
+
const body = h('div', 'body');
|
|
489
|
+
if (r.prompt_preview) body.append(h('div', 'prompt', r.prompt_preview));
|
|
490
|
+
if (r.error) body.append(h('div', 'errline', r.error));
|
|
491
|
+
if (r.items.length) {
|
|
492
|
+
const spans = h('div', 'spans');
|
|
493
|
+
for (const it of r.items) spans.append(spanRow(it, r, t0, total, c.cwd));
|
|
494
|
+
body.append(spans);
|
|
495
|
+
}
|
|
496
|
+
card.append(body);
|
|
497
|
+
turn.append(card);
|
|
498
|
+
turns.append(turn);
|
|
499
|
+
}
|
|
500
|
+
wrap.append(turns);
|
|
501
|
+
wrap.append(h('div', 'foot', '只读视图 · 数据来自本机 live 事件流 · 思考内容从不写入 · 点击回合标题折叠'));
|
|
502
|
+
main.append(wrap);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function render() {
|
|
506
|
+
if (!view) return;
|
|
507
|
+
const rt = $('rail').scrollTop, mt = $('main').scrollTop, wt = window.scrollY;
|
|
508
|
+
// 先定下选中的会话(没选过 / 已消失时挑正在跑的),左栏高亮和右侧详情才一致。
|
|
509
|
+
const all = convs();
|
|
510
|
+
if (!all.some((x) => x.id === selected)) {
|
|
511
|
+
const pick = all.find((x) => x.state === 'running') || all[0];
|
|
512
|
+
selected = pick ? pick.id : null;
|
|
513
|
+
}
|
|
514
|
+
renderStats();
|
|
515
|
+
renderRail();
|
|
516
|
+
renderMain();
|
|
517
|
+
$('rail').scrollTop = rt; $('main').scrollTop = mt; window.scrollTo(0, wt);
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
$('q').addEventListener('input', (e) => { q = e.target.value.trim().toLowerCase(); render(); });
|
|
521
|
+
|
|
522
|
+
function setConn(on, text) {
|
|
523
|
+
const c = $('conn');
|
|
524
|
+
c.className = 'conn' + (on ? ' on' : '');
|
|
525
|
+
c.lastElementChild.textContent = text;
|
|
526
|
+
}
|
|
527
|
+
const es = new EventSource('/events?t=' + encodeURIComponent(token));
|
|
528
|
+
es.onopen = () => setConn(true, '实时');
|
|
529
|
+
es.onmessage = (e) => { try { view = JSON.parse(e.data); } catch { return; } render(); };
|
|
530
|
+
es.onerror = () => setConn(false, '重连中');
|
|
531
|
+
setInterval(render, 15000);
|
|
532
|
+
})();
|
|
533
|
+
</script>
|
|
534
|
+
</body>
|
|
535
|
+
</html>
|