dsh-better-debug 0.2.2 → 0.2.3

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.en.md CHANGED
@@ -184,7 +184,7 @@ dsh plugin add dsh-better-debug
184
184
  **Or from the Release tarball (pnpm treats it as a normal package):**
185
185
 
186
186
  ```bash
187
- dsh plugin add https://github.com/Leonlee114514/dsh-better-debug/releases/download/v0.2.2/dsh-better-debug-0.2.2.tgz
187
+ dsh plugin add https://github.com/Leonlee114514/dsh-better-debug/releases/download/v0.2.3/dsh-better-debug-0.2.3.tgz
188
188
  ```
189
189
 
190
190
  (Both install the same package: the npm tarball is byte-identical to the Release asset.
@@ -300,7 +300,7 @@ Not writing a file was the v0.1 default, and the cost was new users installing i
300
300
  ```bash
301
301
  node --check lib/index.js && node --check lib/panel.js && node --check lib/text.js && node --check client.js
302
302
  node test/sim.mjs # 46 cases: gate semantics + portability
303
- node test/panel.mjs # 32 cases: log parsing, aggregation, instrumentation
303
+ node test/panel.mjs # 40 cases: log parsing, aggregation, generation scoping, instrumentation
304
304
  npm run test:posix # re-runs both suites under POSIX path semantics
305
305
  npm run verify # all of the above (with syntax checks)
306
306
  ```
@@ -335,7 +335,7 @@ and then **re-runs both suites unchanged** — so a Windows dev machine reproduc
335
335
  semantics. CI runs `npm run verify` on ubuntu / windows / macos × node 20 / 22 / 24, so this
336
336
  cannot quietly regress. (24 is not padding: the desktop build runs Electron's bundled node 24.)
337
337
 
338
- The rest of the same family, all fixed in v0.2 / v0.2.1 / v0.2.2:
338
+ The rest of the same family, all fixed in v0.2 / v0.2.1 / v0.2.2 / v0.2.3:
339
339
 
340
340
  | Symptom | Root cause | Now |
341
341
  | --- | --- | --- |
@@ -347,6 +347,7 @@ The rest of the same family, all fixed in v0.2 / v0.2.1 / v0.2.2:
347
347
  | In a real project every error is reported as "the same operation failed again" | node's stack is `file:///C:/...`, and the path regex hits the `e:` inside the scheme, so every stack becomes `"e:///c"` | `stripFileUrl` removes the URL head first |
348
348
  | `a1.js` and `a2.js` are treated as the same place | normalisation replaced every digit in the path with `<n>`; only line/column should go | only the trailing `(:\d+)+$` is stripped |
349
349
  | Running tests in a sibling directory washed out this directory's blind-edit count | `measureDirs` treated `cd <dir>` as a file and took its parent (`cd ~/projB` → `~`) | `cd` is recognised; that segment is a directory |
350
+ | The panel kept showing "the plugin is currently disabled" while it was clearly running | the banner counted `disabled` / `panel failed` over the **whole log**, so one historical failure counted as "broken now" forever | the banner only reads the generation after the last `apply` (`log.current`); history is reported separately in the footer |
350
351
 
351
352
  **Case folding is decided per platform** (`CASE_INSENSITIVE`): only on `win32` / `darwin`.
352
353
  The cost of folding wrong is asymmetric — not folding when you should under-reports, folding
@@ -354,7 +355,7 @@ when you should not **over-reports** (crying wolf), and over-reporting is the on
354
355
  gate must not make. A case-sensitive APFS volume on macOS under-reports a little, which is
355
356
  still the safe direction.
356
357
 
357
- `test/panel.mjs` covers **32 cases**: quoted and escaped field splitting; six line kinds (`inject` / `outcome` / `change` / `measure` / `arm` / `panel-failed`); zero drift between `charsFor` and the real text length across 6 signal combinations; `worstStreak` preserved along log→parse→aggregate→panel; `suppress` and `arm` lines parsed and not counted as fires; the aggregated `firstAction` / `turned` / `measures`; **assertions that v0.1's field names `changed` / `changedRate` / `outcomes` must not come back**; thresholds from the last `apply`; empty logs and bad lines not throwing; and an end-to-end run that really calls `apply()`, walks one turn, and reads the log back to assert `inject` carries `inj=`, `outcome` carries `before=write`, `measure ok=false exit=1`, and `change` is written and aggregated.
358
+ `test/panel.mjs` covers **40 cases**: quoted and escaped field splitting; six line kinds (`inject` / `outcome` / `change` / `measure` / `arm` / `panel-failed`); zero drift between `charsFor` and the real text length across 6 signal combinations; `worstStreak` preserved along log→parse→aggregate→panel; `suppress` and `arm` lines parsed and not counted as fires; the aggregated `firstAction` / `turned` / `measures`; **assertions that v0.1's field names `changed` / `changedRate` / `outcomes` must not come back**; thresholds from the last `apply`; empty logs and bad lines not throwing; and an end-to-end run that really calls `apply()`, walks one turn, and reads the log back to assert `inject` carries `inj=`, `outcome` carries `before=write`, `measure ok=false exit=1`, and `change` is written and aggregated. Generation scoping has its own group: failures in the history with a clean generation after the last `apply` must leave `log.current` at zero and keep the banner quiet; a failure *after* the last `apply` must light it; a log with no `apply` line at all gives `markers=0`, and the panel says it only has a fragment rather than claiming health. **The page itself is asserted too** — the test reads `web/index.html` and checks the banner consumes `log.current` and no whole-log branch survived.
358
359
 
359
360
  ## Known boundaries
360
361
 
package/README.md CHANGED
@@ -222,7 +222,7 @@ dsh plugin add dsh-better-debug
222
222
  **或者从 Release tarball 装(pnpm 会把它当普通包装进 profile):**
223
223
 
224
224
  ```bash
225
- dsh plugin add https://github.com/Leonlee114514/dsh-better-debug/releases/download/v0.2.2/dsh-better-debug-0.2.2.tgz
225
+ dsh plugin add https://github.com/Leonlee114514/dsh-better-debug/releases/download/v0.2.3/dsh-better-debug-0.2.3.tgz
226
226
  ```
227
227
 
228
228
  (两条装的是同一个包:npm 上的 tarball 与 Release 资产逐字节相同。走 npm 的好处是
@@ -364,7 +364,7 @@ bundle 层按原样加载」。也就是说:**写了 config,用户点「启
364
364
  ```bash
365
365
  node --check lib/index.js && node --check lib/panel.js && node --check lib/text.js && node --check client.js
366
366
  node test/sim.mjs # 46 个用例:闸门语义 + 可移植性
367
- node test/panel.mjs # 32 个用例:日志解析、聚合、埋点落盘
367
+ node test/panel.mjs # 40 个用例:日志解析、聚合、世代判定、埋点落盘
368
368
  npm run test:posix # 把上面两套用 POSIX 路径语义再跑一遍
369
369
  npm run verify # 上面全部(含语法检查)
370
370
  ```
@@ -402,7 +402,7 @@ npm run verify # 上面全部(含语法检查)
402
402
  ubuntu / windows / macos × node 20 / 22 / 24 上跑 `npm run verify`,所以这条不会退回去。
403
403
  (24 不是凑数:桌面版 DSH 跑的是 Electron 内置的 node 24。)
404
404
 
405
- 同一类问题的其余各处,都在 v0.2 / v0.2.1 / v0.2.2 修掉了:
405
+ 同一类问题的其余各处,都在 v0.2 / v0.2.1 / v0.2.2 / v0.2.3 修掉了:
406
406
 
407
407
  | 症状 | 根因 | 现在 |
408
408
  | --- | --- | --- |
@@ -414,12 +414,13 @@ ubuntu / windows / macos × node 20 / 22 / 24 上跑 `npm run verify`,所以
414
414
  | 新项目里一报错就误报「同一个操作重复报错」 | node 的栈是 `file:///C:/...`,路径正则先撞上 scheme 里的 `e:`,每份栈都变成 `"e:///c"` | `stripFileUrl` 先剥 URL 头 |
415
415
  | `a1.js` 与 `a2.js` 被当成同一处 | 归一化把路径里每个数字都换成 `<n>`,只该剥行号列号 | 只剥末尾 `(:\d+)+$` |
416
416
  | 在兄弟目录跑测试,把这个目录的盲改计数洗白了 | `measureDirs` 把 `cd <dir>` 当文件取父目录(`cd ~/projB` → `~`) | 认 `cd` 形式,那段路径按目录处理 |
417
+ | 面板永远红着脸说「插件当前被关闭」,而它明明在跑 | 横幅数的是**整份日志**里的 `disabled` / `panel failed`,历史里挂过一次就永久算「现在坏了」 | 横幅只认最后一次 `apply` 之后(`log.current`),历史单独的个数写在页脚 |
417
418
 
418
419
  **大小写折叠按平台判**(`CASE_INSENSITIVE`):只在 `win32` / `darwin` 上折叠。折叠错了的
419
420
  后果不对称——该折叠却不折叠是漏报,不该折叠却折叠是**误报**(狼来了),后者才是这道闸门
420
421
  最不能犯的错。macOS 上装了区分大小写的 APFS 会少报一点,仍然是安全方向。
421
422
 
422
- `test/panel.mjs` 覆盖 **32 个用例**:带引号与转义的字段切分、六种行型解析(`inject` / `outcome` /
423
+ `test/panel.mjs` 覆盖 **40 个用例**:带引号与转义的字段切分、六种行型解析(`inject` / `outcome` /
423
424
  `change` / `measure` / `arm` / `panel-failed`)、`charsFor` 与真实文案长度零漂移(6 组信号组合)、
424
425
  `worstStreak` 在日志→解析→聚合→面板全链路保留、`suppress` 与 `arm` 行可解析且不计入触发、
425
426
  聚合出的 `firstAction` / `turned` / `measures`、**断言 v0.1 的旧字段名
@@ -427,6 +428,11 @@ ubuntu / windows / macos × node 20 / 22 / 24 上跑 `npm run verify`,所以
427
428
  以及端到端——真跑 `apply()` 走完一个 turn,读回日志断言 `inject` 带 `inj=`、
428
429
  `outcome` 带 `before=write`、`measure ok=false exit=1`、`change` 行都写了且被聚合。
429
430
 
431
+ 世代判定单列一组:历史里有失败、最后一次 `apply` 之后干净 → `log.current` 全 0、横幅不亮;
432
+ `apply` 之后又失败 → `log.current` 必须亮;日志里根本没有 `apply` 行 → `markers=0`,
433
+ 面板明说「读到的只是片段」,不冒充健康。**页面本身也被断言**——直接读 `web/index.html`,
434
+ 确认横幅读的是 `log.current`、没有残留按全量计数判红的老分支。
435
+
430
436
  ## 已知边界
431
437
 
432
438
  - 「同一文件」按**绝对路径**判定。删了重建同名文件也算同一处——这通常是对的(说明在同一个
package/lib/panel.js CHANGED
@@ -272,6 +272,15 @@ export function aggregate(records, options = {}) {
272
272
  let skillFailed = 0
273
273
  let panelFailed = 0
274
274
  let suppressed = 0
275
+ /**
276
+ * 世代计数:只算**最后一次 apply 之后**发生的失败。
277
+ *
278
+ * 为什么必须分两套:`disabled by config` / `panel register failed` 这类行是
279
+ * 「那一刻的状态」,不是「永久事实」。全量计数会让历史里挂过一次的插件
280
+ * 在修好之后仍然永久显示红条 —— 面板说「插件当前被关闭」,而它明明在跑,
281
+ * 这比没有面板更坏。全量留在 log.disabled 等字段里给「历史上出过事」用。
282
+ */
283
+ const current = { disabled: 0, skillFailed: 0, panelFailed: 0, since: '', pid: 0, markers: 0 }
275
284
 
276
285
  for (const record of records) {
277
286
  if (record.kind === 'inject') injects.push(record)
@@ -279,12 +288,33 @@ export function aggregate(records, options = {}) {
279
288
  else if (record.kind === 'change') changes.push(record)
280
289
  else if (record.kind === 'measure') measures.push(record)
281
290
  else if (record.kind === 'arm') arms.push(record)
282
- else if (record.kind === 'apply') applies.push(record)
283
- else if (record.kind === 'skill') skills.push(record)
284
- else if (record.kind === 'disabled') disabled += 1
285
- else if (record.kind === 'skill-failed') skillFailed += 1
286
- else if (record.kind === 'panel-failed') panelFailed += 1
287
- else if (record.kind === 'suppress') suppressed += 1
291
+ else if (record.kind === 'apply') {
292
+ applies.push(record)
293
+ // 新的世代开始:之前那些失败属于上一代,不再代表「现在」。
294
+ current.disabled = 0
295
+ current.skillFailed = 0
296
+ current.panelFailed = 0
297
+ current.since = record.at
298
+ current.pid = record.pid
299
+ current.markers += 1
300
+ } else if (record.kind === 'skill') skills.push(record)
301
+ else if (record.kind === 'disabled') {
302
+ disabled += 1
303
+ // `disabled by config` 之后 apply 不会再写(index.js 里直接 return),
304
+ // 所以它本身就是一次世代分界:这一代的状态就是「关着」。不认这一点的话,
305
+ // 一个真的被关掉的插件会因为「没有 apply 行」被判成「无从判断」。
306
+ current.disabled = 1
307
+ current.skillFailed = 0
308
+ current.panelFailed = 0
309
+ current.since = record.at
310
+ current.markers += 1
311
+ } else if (record.kind === 'skill-failed') {
312
+ skillFailed += 1
313
+ current.skillFailed += 1
314
+ } else if (record.kind === 'panel-failed') {
315
+ panelFailed += 1
316
+ current.panelFailed += 1
317
+ } else if (record.kind === 'suppress') suppressed += 1
288
318
  }
289
319
 
290
320
  const bySignal = { A: 0, B: 0, C: 0 }
@@ -349,7 +379,18 @@ export function aggregate(records, options = {}) {
349
379
  suppressed,
350
380
  arms: arms.length,
351
381
  skills: skills.length,
352
- skillPath: skills.length > 0 ? skills[skills.length - 1].path : ''
382
+ skillPath: skills.length > 0 ? skills[skills.length - 1].path : '',
383
+ // 「现在这一代怎么样」——横幅只看这一段。全量在上面,供事后查历史。
384
+ // markers=0 表示日志里没有任何世代分界(既没有 apply 也没有 disabled),
385
+ // 说明读到的是残缺片段;此时失败仍然照实计入,只是面板没法说「这是哪一次加载之后」。
386
+ current: {
387
+ disabled: current.disabled,
388
+ skillFailed: current.skillFailed,
389
+ panelFailed: current.panelFailed,
390
+ since: current.since,
391
+ pid: current.pid,
392
+ markers: current.markers
393
+ }
353
394
  },
354
395
  thresholds: lastApply !== null && lastApply.thresholds.A > 0
355
396
  ? lastApply.thresholds
@@ -477,7 +518,7 @@ export function registerPanel(ctx, getConfig) {
477
518
  send(
478
519
  200,
479
520
  'application/json; charset=utf-8',
480
- JSON.stringify({ id: 'dsh-better-debug', version: 2 }, null, 2)
521
+ JSON.stringify({ id: 'dsh-better-debug', version: 3 }, null, 2)
481
522
  )
482
523
  return
483
524
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-better-debug",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "卡住闸门的代码化:同一文件连续盲改 / 同一操作重复报错 / 改完没有回路又动手,命中就在下一步注入一次提醒,逼出一条几秒能跑的反馈回路。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
package/web/index.html CHANGED
@@ -154,6 +154,7 @@
154
154
 
155
155
  <div class="foot">
156
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>它只数最后一次 <code>apply</code>(也就是最近一次加载)之后的失败行——那之前的关闭/挂载失败已经被这次加载取代,不代表当下状态,只在这里列个数。<span id="hist-note"></span></p>
157
158
  <p><b>这些数字不证明什么。</b>「提示后首个动作」只说明提示之后模型做了什么,它不能证明提示促成了这个动作,更不能证明它发现了缺陷——要回答那个问题需要对照组或历史回放。面板也不估算「省掉了多少 token」:那要先假设模型本来会失败,属于编数。</p>
158
159
  </div>
159
160
 
@@ -307,16 +308,52 @@
307
308
  }).join('')
308
309
  }
309
310
 
310
- if (lg.disabled) {
311
+ // 横幅只说「现在」:只数最后一次 apply 之后发生的失败。
312
+ // 历史里挂过一次、修好之后仍永久染红,会让面板说「插件当前被关闭」
313
+ // 而它明明在跑 —— 那比没有面板更坏。全量计数仍留在 log.disabled 等字段,
314
+ // 并在页脚如实写成「历史日志里记过」。
315
+ var cur = lg.current || {}
316
+ var curDisabled = Number(cur.disabled) || 0
317
+ var curSkillFailed = Number(cur.skillFailed) || 0
318
+ var curPanelFailed = Number(cur.panelFailed) || 0
319
+ var sincePrefix = cur.since ? '最后一次加载(' + esc(cur.since) + ')之后,' : ''
320
+ // 老 API(没有 current 段)只能退回全量口径:宁可多报,也不把真实故障咽下去。
321
+ if (lg.current === undefined || lg.current === null) {
322
+ curDisabled = Number(lg.disabled) || 0
323
+ curSkillFailed = Number(lg.skillFailed) || 0
324
+ curPanelFailed = Number(lg.panelFailed) || 0
325
+ sincePrefix = '日志里有 '
326
+ }
327
+
328
+ if (curDisabled) {
311
329
  $('error').hidden = false
312
- $('error').textContent = '日志里有 ' + lg.disabled + ' 条 disabled by config —— 插件当前被关闭。'
313
- } else if (lg.skillFailed) {
330
+ $('error').textContent = sincePrefix + '记了 ' + curDisabled + ' 条 disabled by config —— 插件当前被关闭。'
331
+ } else if (curSkillFailed) {
314
332
  $('error').hidden = false
315
- $('error').textContent = '自带技能注册失败 ' + lg.skillFailed + ' 次,闸门本身不受影响。'
316
- } else if (lg.panelFailed) {
333
+ $('error').textContent = sincePrefix + '记了 ' + curSkillFailed + ' 次技能注册失败,闸门本身不受影响。'
334
+ } else if (curPanelFailed) {
317
335
  $('error').hidden = false
318
- $('error').textContent = '面板路由挂载失败 ' + lg.panelFailed + ' 次 —— 闸门可能仍在工作,但读数面板没挂上。'
336
+ $('error').textContent = sincePrefix + '记了 ' + curPanelFailed + ' 次面板路由挂载失败 —— 闸门可能仍在工作,但读数面板没挂上。'
337
+ }
338
+
339
+ // 历史归历史:不染红,但要如实说明它存在,否则「0」会被读成「从来没出过事」。
340
+ var stale = (Number(lg.disabled) || 0) - curDisabled +
341
+ (Number(lg.skillFailed) || 0) - curSkillFailed +
342
+ (Number(lg.panelFailed) || 0) - curPanelFailed
343
+ var notes = []
344
+ if (stale > 0) {
345
+ notes.push('另外,历史日志里还记着 ' + stale + ' 条更早的关闭 / 挂载失败(都在最后一次加载之前),已被当前这次加载取代;它们不代表现在的状态。')
346
+ }
347
+ // markers=0:日志里既没有 apply 也没有 disabled,读到的只是一段片段。
348
+ // 这时候「没有红条」不等于「现在健康」,得说出来,不能默认绿灯。
349
+ if (lg.current === undefined || lg.current === null) {
350
+ // 页面是每次请求现读的,插件模块不是。改完代码但还没重启时,
351
+ // 新页面会拿到旧 API(没有 current 段)—— 说出来,别让它看起来像健康。
352
+ notes.push('这个页面比插件新:API 还没有 <code>log.current</code> 段(插件需要重载才会用上新代码)。上面的红条按老口径判断,可能误报。')
353
+ } else if ((Number(cur.markers) || 0) === 0) {
354
+ notes.push('这份日志里没有 <code>apply</code> 行,认不出是哪一次加载之后的记录 —— 上面这些数字只是读到的片段,不能当作「现在健康」。')
319
355
  }
356
+ $('hist-note').innerHTML = notes.length > 0 ? ' ' + notes.join(' ') : ''
320
357
  }
321
358
 
322
359
  function fail(message) {