dsh-better-debug 0.0.0-stage → 0.2.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/web/index.html ADDED
@@ -0,0 +1,349 @@
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
+ <title>better-debug 观测面板</title>
7
+ <style>
8
+ :root {
9
+ color-scheme: dark;
10
+ --bg: var(--dsw-alias-bg-base, #0f1115);
11
+ --card: var(--dsw-alias-bg-elevated, #171a20);
12
+ --card-border: var(--dsw-alias-border-subtle, #262b33);
13
+ --fg: var(--dsw-alias-text-primary, #e7ebf0);
14
+ --fg-dim: var(--dsw-alias-text-secondary, #9aa4b2);
15
+ --fg-faint: #6b7480;
16
+ --accent: #4f8cff;
17
+ --good: #35c46a;
18
+ --warn: #ffb020;
19
+ --bad: #ff6b6b;
20
+ --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
21
+ }
22
+ * { box-sizing: border-box; }
23
+ html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
24
+ body {
25
+ font: 13px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
26
+ "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
27
+ padding: 20px 22px 40px;
28
+ }
29
+ h1 { font-size: 19px; font-weight: 650; margin: 0 0 4px; letter-spacing: .2px; }
30
+ .sub { color: var(--fg-dim); font-size: 12px; margin: 0 0 18px; }
31
+ .sub code { font-family: var(--mono); font-size: 11px; color: var(--fg-faint); }
32
+
33
+ .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
34
+ .card {
35
+ background: var(--card); border: 1px solid var(--card-border); border-radius: 10px;
36
+ padding: 16px 18px 14px; min-height: 122px; display: flex; flex-direction: column;
37
+ }
38
+ .card .k { color: var(--fg-dim); font-size: 12px; margin-bottom: 10px; }
39
+ .card .v { font-size: 30px; font-weight: 650; line-height: 1.1; letter-spacing: -.5px; }
40
+ .card .v.good { color: var(--good); }
41
+ .card .v.accent { color: var(--accent); }
42
+ .card .v.muted { color: var(--fg-faint); }
43
+ .card .v small { font-size: 15px; font-weight: 500; color: var(--fg-dim); margin-left: 3px; }
44
+ .card .n { color: var(--fg-faint); font-size: 11.5px; margin-top: auto; padding-top: 10px; line-height: 1.5; }
45
+
46
+ .section { margin-top: 26px; }
47
+ .section > h2 {
48
+ font-size: 13px; font-weight: 600; color: var(--fg-dim);
49
+ margin: 0 0 4px; letter-spacing: .3px;
50
+ }
51
+ .section > .hint { color: var(--fg-faint); font-size: 11.5px; margin: 0 0 10px; }
52
+
53
+ .bars { display: flex; flex-direction: column; gap: 7px; }
54
+ .bar { display: grid; grid-template-columns: 172px 1fr 64px; align-items: center; gap: 10px; }
55
+ .bar .lab { font-size: 12px; color: var(--fg-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
56
+ .bar .track { height: 8px; border-radius: 4px; background: #232833; overflow: hidden; }
57
+ .bar .fill { height: 100%; border-radius: 4px; background: var(--accent); transition: width .25s ease; }
58
+ .bar .fill.a { background: #ff8a5b; }
59
+ .bar .fill.b { background: #ffb020; }
60
+ .bar .fill.c { background: #4f8cff; }
61
+ .bar .fill.d { background: #57d189; }
62
+ .bar .fill.e { background: #b28dff; }
63
+ .bar .num { font-family: var(--mono); font-size: 11px; color: var(--fg-dim); text-align: right; }
64
+
65
+ table { width: 100%; border-collapse: collapse; font-size: 12px; }
66
+ th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--card-border); }
67
+ th { color: var(--fg-faint); font-weight: 500; font-size: 11.5px; }
68
+ td { color: var(--fg-dim); }
69
+ td.mono, th.mono { font-family: var(--mono); font-size: 11px; }
70
+ tr:last-child td { border-bottom: 0; }
71
+ .tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-family: var(--mono); font-size: 10.5px; }
72
+ .tag.A { background: rgba(255,138,91,.16); color: #ff9d78; }
73
+ .tag.B { background: rgba(255,176,32,.16); color: #ffc14d; }
74
+ .tag.C { background: rgba(79,140,255,.16); color: #7ba7ff; }
75
+ .tag.verify { background: rgba(53,196,106,.15); color: #57d189; }
76
+ .tag.search { background: rgba(53,196,106,.15); color: #57d189; }
77
+ .tag.edit { background: rgba(255,107,107,.14); color: #ff8d8d; }
78
+ .tag.shell { background: rgba(255,176,32,.14); color: #ffc14d; }
79
+ .tag.method { background: rgba(178,141,255,.15); color: #c3a6ff; }
80
+ .tag.other { background: rgba(154,164,178,.14); color: var(--fg-dim); }
81
+
82
+ .foot { margin-top: 22px; color: var(--fg-faint); font-size: 11.5px; line-height: 1.65; }
83
+ .foot p { margin: 0 0 6px; }
84
+ .foot b { color: var(--fg-dim); font-weight: 600; }
85
+ .foot code { font-family: var(--mono); font-size: 11px; }
86
+ .empty { color: var(--fg-faint); font-size: 12px; padding: 14px 2px; }
87
+ .err {
88
+ border: 1px solid rgba(255,107,107,.4); background: rgba(255,107,107,.08);
89
+ color: #ffd0d0; padding: 10px 12px; border-radius: 8px; font-size: 12px; margin-bottom: 14px;
90
+ }
91
+ .err code { font-family: var(--mono); }
92
+ </style>
93
+ </head>
94
+ <body>
95
+ <h1>better-debug 观测面板</h1>
96
+ <p class="sub">数据源:<code id="logfile">…</code> · 只读,不改插件行为</p>
97
+
98
+ <div id="error" class="err" hidden></div>
99
+
100
+ <div class="grid">
101
+ <div class="card">
102
+ <div class="k">闸门触发次数</div>
103
+ <div class="v accent" id="injects">—</div>
104
+ <div class="n" id="injects-note">—</div>
105
+ </div>
106
+ <div class="card">
107
+ <div class="k">覆盖会话</div>
108
+ <div class="v" id="sessions">—</div>
109
+ <div class="n" id="sessions-note">—</div>
110
+ </div>
111
+ <div class="card">
112
+ <div class="k">提示后首个动作</div>
113
+ <div class="v" id="first">—</div>
114
+ <div class="n" id="first-note">—</div>
115
+ </div>
116
+ <div class="card">
117
+ <div class="k">测量回路(硬证据)</div>
118
+ <div class="v" id="measures">—</div>
119
+ <div class="n" id="measures-note">—</div>
120
+ </div>
121
+ </div>
122
+
123
+ <div class="section">
124
+ <h2>三条信号各响了多少次</h2>
125
+ <p class="hint">一条注入可能同时命中多个信号,所以三者之和会大于触发次数。</p>
126
+ <div class="bars" id="signal-bars"></div>
127
+ </div>
128
+
129
+ <div class="section">
130
+ <h2>提示之后,模型第一个动作是什么</h2>
131
+ <p class="hint">描述量:只数「下一个动作落在哪一类」,不推断提示是否促成了它。</p>
132
+ <div class="bars" id="outcome-bars"></div>
133
+ </div>
134
+
135
+ <div class="section">
136
+ <h2>窗口内是否真的转去取得新事实</h2>
137
+ <p class="hint">只在注入后固定步数窗口内看,超窗不算。中位步数只从这些「真转向」里算。</p>
138
+ <div class="bars" id="turn-bars"></div>
139
+ <p class="hint" id="turn-note"></p>
140
+ </div>
141
+
142
+ <div class="section">
143
+ <h2>最近触发</h2>
144
+ <table>
145
+ <thead>
146
+ <tr>
147
+ <th>时间</th><th>会话</th><th class="mono">轮/步</th>
148
+ <th>信号</th><th class="mono">最热文件(累计/连续盲改)</th><th class="mono">最热报错</th><th>已搜</th><th>测量</th>
149
+ </tr>
150
+ </thead>
151
+ <tbody id="recent"><tr><td colspan="8" class="empty">暂无记录</td></tr></tbody>
152
+ </table>
153
+ </div>
154
+
155
+ <div class="foot">
156
+ <p><b>每个数字都能逐行数出来。</b>触发次数、覆盖会话、信号分布来自 <code>inject</code> 行;「提示后首个动作」来自紧接着的那条 <code>outcome</code> 行;窗口内转向来自 <code>change</code> 行;测量回路来自 <code>measure</code> 行(它是「有没有反馈回路」的直接证据,跟任何动作分类无关)。<span id="suppressed-note"></span></p>
157
+ <p><b>这些数字不证明什么。</b>「提示后首个动作」只说明提示之后模型做了什么,它不能证明提示促成了这个动作,更不能证明它发现了缺陷——要回答那个问题需要对照组或历史回放。面板也不估算「省掉了多少 token」:那要先假设模型本来会失败,属于编数。</p>
158
+ </div>
159
+
160
+ <script>
161
+ (function () {
162
+ 'use strict'
163
+ var $ = function (id) { return document.getElementById(id) }
164
+
165
+ function fmt(n) {
166
+ if (n === null || n === undefined || Number.isNaN(n)) return '—'
167
+ var v = Number(n)
168
+ if (Math.abs(v) >= 1e9) return (v / 1e9).toFixed(2) + 'B'
169
+ if (Math.abs(v) >= 1e6) return (v / 1e6).toFixed(2) + 'M'
170
+ if (Math.abs(v) >= 1e4) return (v / 1e3).toFixed(1) + 'K'
171
+ return String(Math.round(v))
172
+ }
173
+
174
+ function pct(n) {
175
+ if (n === null || n === undefined) return '—'
176
+ return (n * 100).toFixed(0) + '%'
177
+ }
178
+
179
+ function esc(s) {
180
+ return String(s == null ? '' : s)
181
+ .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
182
+ .replace(/"/g, '&quot;')
183
+ }
184
+
185
+ function shortSession(id) {
186
+ if (!id) return '—'
187
+ return id.length > 16 ? id.slice(0, 12) + '…' : id
188
+ }
189
+
190
+ function bar(label, value, total, cls) {
191
+ var share = total > 0 ? Math.max(2, Math.round((value / total) * 100)) : 0
192
+ return '<div class="bar"><span class="lab">' + esc(label) + '</span>' +
193
+ '<div class="track"><div class="fill ' + (cls || '') + '" style="width:' + share + '%"></div></div>' +
194
+ '<span class="num">' + esc(String(value)) + '</span></div>'
195
+ }
196
+
197
+ // 分类的展示文案:说明这一类「是什么动作」,不带价值判断。
198
+ var CLASS_LABEL = {
199
+ verify: 'verify 测量(判据命中)',
200
+ search: 'search 查外部资料',
201
+ edit: 'edit 继续改代码',
202
+ shell: 'shell 命令但没测量',
203
+ method: 'method 读方法论 / 技能',
204
+ other: 'other 其它'
205
+ }
206
+
207
+ function render(d) {
208
+ var inj = d.injects || {}
209
+ var first = d.firstAction || {}
210
+ var turned = d.turned || {}
211
+ var meas = d.measures || {}
212
+ var lg = d.log || {}
213
+
214
+ $('logfile').textContent = lg.file || '(落盘已关闭:logFile 为空)'
215
+ $('suppressed-note').textContent = lg.suppressed > 0
216
+ ? ' 另有 ' + lg.suppressed + ' 次「交付态主动静默」(suppress reason=done):闸门醒着、判过了、故意不注入,不计入触发。'
217
+ : ''
218
+
219
+ $('injects').textContent = fmt(inj.total || 0)
220
+ var tags = Object.keys(inj.byTag || {})
221
+ .sort(function (a, b) { return inj.byTag[b] - inj.byTag[a] })
222
+ .map(function (k) { return k + '×' + inj.byTag[k] })
223
+ .join(' · ')
224
+ $('injects-note').textContent = tags || '还没有触发过'
225
+
226
+ $('sessions').textContent = fmt(inj.sessions || 0)
227
+ $('sessions-note').textContent =
228
+ (inj.turns || 0) + ' 个轮次 · 注入文本累计 ' + fmt(inj.chars || 0) + ' 字符 · 约 ' +
229
+ fmt(inj.tokens || 0) + ' tok'
230
+
231
+ var reported = first.reported || 0
232
+ if (reported === 0) {
233
+ $('first').textContent = '—'
234
+ $('first').className = 'v muted'
235
+ $('first-note').textContent = (inj.total || 0) > 0
236
+ ? '已注入 ' + inj.total + ' 次,但还没有观察到后续动作(需要下一次工具调用)'
237
+ : '还没有注入,无法统计'
238
+ } else {
239
+ var bc = first.byClass || {}
240
+ var measureShare = ((bc.verify || 0) + (bc.search || 0)) / reported
241
+ $('first').textContent = pct(measureShare)
242
+ $('first').className = 'v good'
243
+ $('first-note').textContent =
244
+ ((bc.verify || 0) + (bc.search || 0)) + '/' + reported + ' 次首个动作是测量或搜索' +
245
+ (first.silent > 0 ? ' · ' + first.silent + ' 次未观察到后续' : '')
246
+ }
247
+
248
+ var mtotal = meas.total || 0
249
+ $('measures').textContent = fmt(mtotal)
250
+ $('measures-note').textContent = mtotal === 0
251
+ ? '还没有命中判据的测量调用'
252
+ : (meas.ok || 0) + ' 次成功 / ' + (meas.failed || 0) + ' 次失败(失败的测量同样算回路)· 累计清掉 ' +
253
+ fmt(meas.cleared || 0) + ' 个文件的盲改计数'
254
+
255
+ var total = Math.max(1, (inj.bySignal && (inj.bySignal.A + inj.bySignal.B + inj.bySignal.C)) || 0)
256
+ $('signal-bars').innerHTML =
257
+ bar('A 同一文件连续盲改', (inj.bySignal && inj.bySignal.A) || 0, total, 'a') +
258
+ bar('B 同一操作重复报错', (inj.bySignal && inj.bySignal.B) || 0, total, 'b') +
259
+ bar('C 改完没有回路又动手', (inj.bySignal && inj.bySignal.C) || 0, total, 'c')
260
+
261
+ var outTotal = Math.max(1, reported)
262
+ $('outcome-bars').innerHTML = reported === 0
263
+ ? '<div class="empty">还没有可统计的后续动作。</div>'
264
+ : ['verify', 'search', 'edit', 'shell', 'method', 'other'].map(function (key, i) {
265
+ return bar(CLASS_LABEL[key], (first.byClass && first.byClass[key]) || 0, outTotal, 'abcde'[i] || 'c')
266
+ }).join('')
267
+
268
+ var observed = Number(turned.observed) || 0
269
+ var tTotal = Math.max(1, observed)
270
+ $('turn-bars').innerHTML = observed === 0
271
+ ? '<div class="empty">这段日志早于 v0.2 埋点,还没有可统计的窗口数据。</div>'
272
+ : bar('窗口内转到 verify', (turned.byClass && turned.byClass.verify) || 0, tTotal, 'd') +
273
+ bar('窗口内转到 search', (turned.byClass && turned.byClass.search) || 0, tTotal, 'd') +
274
+ bar('窗口内没有转向', Math.max(0, observed - (turned.total || 0)), tTotal, 'b')
275
+ $('turn-note').textContent = observed === 0
276
+ ? '埋点上线前的注入不计入(那时还没有 change 行),现在说「没转向」是编数。'
277
+ : (turned.total || 0) + '/' + observed + ' 次在窗口内转去取得新事实' +
278
+ (turned.medianSteps !== null && turned.medianSteps !== undefined
279
+ ? ' · 中位 ' + turned.medianSteps + ' 步' : '')
280
+
281
+ var rows = d.recent || []
282
+ if (rows.length === 0) {
283
+ $('recent').innerHTML = '<tr><td colspan="8" class="empty">暂无记录</td></tr>'
284
+ } else {
285
+ $('recent').innerHTML = rows.slice().reverse().map(function (r) {
286
+ var at = r.at ? new Date(r.at).toLocaleString() : '—'
287
+ var tag = String(r.tag || '?').split('+').map(function (k) {
288
+ return '<span class="tag ' + esc(k) + '">' + esc(k) + '</span>'
289
+ }).join(' ')
290
+ var measured = String(r.measured || '')
291
+ var measuredCell = measured === '' || measured === 'no'
292
+ ? '<span class="num">—</span>'
293
+ : '<span class="tag ' + (measured.indexOf(':ok') > 0 ? 'verify' : 'edit') + '">' +
294
+ esc(measured.replace('yes:', '')) + '</span>'
295
+ return '<tr>' +
296
+ '<td class="mono">' + esc(at) + '</td>' +
297
+ '<td class="mono" title="' + esc(r.session) + '">' + esc(shortSession(r.session)) + '</td>' +
298
+ '<td class="mono">' + esc((r.turn || 0) + '/' + (r.step || 0)) + '</td>' +
299
+ '<td>' + tag + '</td>' +
300
+ '<td class="mono" title="累计 ' + esc(r.worstEdits || 0) + ' 次 · 连续盲改 ' + esc(r.worstStreak || 0) + ' 次">' +
301
+ esc(r.worstEdits > 0 ? '×' + r.worstEdits : '—') +
302
+ (r.worstStreak > 0 ? ' <span class="tag a">盲×' + esc(r.worstStreak) + '</span>' : '') + '</td>' +
303
+ '<td class="mono">' + esc(r.worstErrors > 0 ? '×' + r.worstErrors : '—') + '</td>' +
304
+ '<td>' + (r.searched ? '是' : '否') + '</td>' +
305
+ '<td class="mono">' + measuredCell + '</td>' +
306
+ '</tr>'
307
+ }).join('')
308
+ }
309
+
310
+ if (lg.disabled) {
311
+ $('error').hidden = false
312
+ $('error').textContent = '日志里有 ' + lg.disabled + ' 条 disabled by config —— 插件当前被关闭。'
313
+ } else if (lg.skillFailed) {
314
+ $('error').hidden = false
315
+ $('error').textContent = '自带技能注册失败 ' + lg.skillFailed + ' 次,闸门本身不受影响。'
316
+ } else if (lg.panelFailed) {
317
+ $('error').hidden = false
318
+ $('error').textContent = '面板路由挂载失败 ' + lg.panelFailed + ' 次 —— 闸门可能仍在工作,但读数面板没挂上。'
319
+ }
320
+ }
321
+
322
+ function fail(message) {
323
+ var box = $('error')
324
+ box.hidden = false
325
+ box.innerHTML = '读不到数据:<code>' + esc(message) + '</code><br>可能原因:<code>logFile</code> 指向的目录不可写,或 profile 的 <code>cordis.patch.yml</code> 里 better-debug 这一条被 <code>enabled: false</code> 关掉了。DSH 日志里若有 <code>better-debug: 写不进日志</code> 的 warn,就是前者。'
326
+ }
327
+
328
+ function load() {
329
+ fetch('/better-debug/api', { cache: 'no-store' })
330
+ .then(function (r) {
331
+ if (!r.ok) throw new Error('HTTP ' + r.status)
332
+ return r.json()
333
+ })
334
+ .then(function (d) {
335
+ if (d.ok === false) throw new Error(d.error || 'unknown')
336
+ render(d)
337
+ })
338
+ .catch(function (e) { fail(e && e.message ? e.message : String(e)) })
339
+ }
340
+
341
+ load()
342
+ setInterval(load, 5000)
343
+ document.addEventListener('visibilitychange', function () {
344
+ if (!document.hidden) load()
345
+ })
346
+ })()
347
+ </script>
348
+ </body>
349
+ </html>