dsh-better-debug 0.2.1 → 0.2.2
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 +7 -4
- package/README.md +7 -4
- package/lib/index.js +38 -4
- package/package.json +1 -1
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.
|
|
187
|
+
dsh plugin add https://github.com/Leonlee114514/dsh-better-debug/releases/download/v0.2.2/dsh-better-debug-0.2.2.tgz
|
|
188
188
|
```
|
|
189
189
|
|
|
190
190
|
(Both install the same package: the npm tarball is byte-identical to the Release asset.
|
|
@@ -299,13 +299,13 @@ Not writing a file was the v0.1 default, and the cost was new users installing i
|
|
|
299
299
|
|
|
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
|
-
node test/sim.mjs #
|
|
302
|
+
node test/sim.mjs # 46 cases: gate semantics + portability
|
|
303
303
|
node test/panel.mjs # 32 cases: log parsing, aggregation, 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
|
```
|
|
307
307
|
|
|
308
|
-
`test/sim.mjs` uses a fake ctx that replicates agent-loop call order (`emitPlain` / `emitWaterfall`) and covers **
|
|
308
|
+
`test/sim.mjs` uses a fake ctx that replicates agent-loop call order (`emitPlain` / `emitWaterfall`) and covers **46 cases**.
|
|
309
309
|
|
|
310
310
|
Semantics (each with a positive and a negative):
|
|
311
311
|
|
|
@@ -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
|
-
|
|
338
|
+
The rest of the same family, all fixed in v0.2 / v0.2.1 / v0.2.2:
|
|
339
339
|
|
|
340
340
|
| Symptom | Root cause | Now |
|
|
341
341
|
| --- | --- | --- |
|
|
@@ -344,6 +344,9 @@ Four more of the same family, all fixed in v0.2 / v0.2.1:
|
|
|
344
344
|
| Plugin silently not loaded — no error, no log line | static `inject: ['skills']` makes `apply()` never run when the service is missing | `inject = []`, dynamic `ctx.inject` |
|
|
345
345
|
| Clicking "enable" in the market does nothing | bundle patch carried a `config:` block | patch keeps only `id` + `name` |
|
|
346
346
|
| A too-old host is never rejected | the range lived in `dsh.engines.dsh`, but the host and the market read only top-level `engines.dsh` | moved to top-level `engines.dsh` |
|
|
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
|
+
| `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
|
+
| 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 |
|
|
347
350
|
|
|
348
351
|
**Case folding is decided per platform** (`CASE_INSENSITIVE`): only on `win32` / `darwin`.
|
|
349
352
|
The cost of folding wrong is asymmetric — not folding when you should under-reports, folding
|
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.
|
|
225
|
+
dsh plugin add https://github.com/Leonlee114514/dsh-better-debug/releases/download/v0.2.2/dsh-better-debug-0.2.2.tgz
|
|
226
226
|
```
|
|
227
227
|
|
|
228
228
|
(两条装的是同一个包:npm 上的 tarball 与 Release 资产逐字节相同。走 npm 的好处是
|
|
@@ -363,14 +363,14 @@ bundle 层按原样加载」。也就是说:**写了 config,用户点「启
|
|
|
363
363
|
|
|
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
|
-
node test/sim.mjs #
|
|
366
|
+
node test/sim.mjs # 46 个用例:闸门语义 + 可移植性
|
|
367
367
|
node test/panel.mjs # 32 个用例:日志解析、聚合、埋点落盘
|
|
368
368
|
npm run test:posix # 把上面两套用 POSIX 路径语义再跑一遍
|
|
369
369
|
npm run verify # 上面全部(含语法检查)
|
|
370
370
|
```
|
|
371
371
|
|
|
372
372
|
`test/sim.mjs` 用假 ctx 复刻 agent-loop 的调用顺序(`emitPlain` / `emitWaterfall`),
|
|
373
|
-
覆盖 **
|
|
373
|
+
覆盖 **46 个用例**。
|
|
374
374
|
|
|
375
375
|
语义层(每条都有正例 + 反例):
|
|
376
376
|
|
|
@@ -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
|
-
|
|
405
|
+
同一类问题的其余各处,都在 v0.2 / v0.2.1 / v0.2.2 修掉了:
|
|
406
406
|
|
|
407
407
|
| 症状 | 根因 | 现在 |
|
|
408
408
|
| --- | --- | --- |
|
|
@@ -411,6 +411,9 @@ ubuntu / windows / macos × node 20 / 22 / 24 上跑 `npm run verify`,所以
|
|
|
411
411
|
| 插件静默不加载,无报错无日志 | 静态 `inject: ['skills']` 缺服务时 `apply()` 整个不执行 | `inject = []`,走 `ctx.inject` 动态订阅 |
|
|
412
412
|
| 市场点「启用」没反应 | bundle patch 带 `config:` 块 | patch 只留 `id` + `name` |
|
|
413
413
|
| 宿主版本太旧也不拦 | 版本范围写在 `dsh.engines.dsh`,而宿主与市场只读顶层 `engines.dsh` | 移到顶层 `engines.dsh` |
|
|
414
|
+
| 新项目里一报错就误报「同一个操作重复报错」 | node 的栈是 `file:///C:/...`,路径正则先撞上 scheme 里的 `e:`,每份栈都变成 `"e:///c"` | `stripFileUrl` 先剥 URL 头 |
|
|
415
|
+
| `a1.js` 与 `a2.js` 被当成同一处 | 归一化把路径里每个数字都换成 `<n>`,只该剥行号列号 | 只剥末尾 `(:\d+)+$` |
|
|
416
|
+
| 在兄弟目录跑测试,把这个目录的盲改计数洗白了 | `measureDirs` 把 `cd <dir>` 当文件取父目录(`cd ~/projB` → `~`) | 认 `cd` 形式,那段路径按目录处理 |
|
|
414
417
|
|
|
415
418
|
**大小写折叠按平台判**(`CASE_INSENSITIVE`):只在 `win32` / `darwin` 上折叠。折叠错了的
|
|
416
419
|
后果不对称——该折叠却不折叠是漏报,不该折叠却折叠是**误报**(狼来了),后者才是这道闸门
|
package/lib/index.js
CHANGED
|
@@ -255,6 +255,20 @@ function foldCase(text) {
|
|
|
255
255
|
return CASE_INSENSITIVE ? text.toLowerCase() : text
|
|
256
256
|
}
|
|
257
257
|
|
|
258
|
+
/**
|
|
259
|
+
* 剥掉 `file://` URL 头,把它变回普通路径。
|
|
260
|
+
*
|
|
261
|
+
* node 在 Windows 上抛异常时栈里写的是 `file:///C:/Users/.../a.mjs:12:29`,
|
|
262
|
+
* 在 POSIX 上是 `file:///home/u/.../a.mjs:12:29`。不剥的话,路径正则先撞上
|
|
263
|
+
* scheme 里的 `e:`,`file:///C:/a.mjs` 会被认成目标 `"e:///c"` —— 所有 Windows 栈
|
|
264
|
+
* 就此塌成同一个 episode,B 信号对任何三次不同文件的报错都会误报。
|
|
265
|
+
*/
|
|
266
|
+
function stripFileUrl(text) {
|
|
267
|
+
return String(text ?? '')
|
|
268
|
+
.replace(/file:\/\/\/(?=[A-Za-z]:[\\/])/gi, '')
|
|
269
|
+
.replace(/file:\/\/(?=\/)/gi, '')
|
|
270
|
+
}
|
|
271
|
+
|
|
258
272
|
/** 规整成一个可比对的目录:posix 分隔符、去尾斜杠、按平台折叠大小写。 */
|
|
259
273
|
function normDir(path) {
|
|
260
274
|
const normalized = String(path ?? '').replace(/\\/g, '/').replace(/\/+$/, '')
|
|
@@ -316,7 +330,25 @@ export function measureDirs(args) {
|
|
|
316
330
|
if (workspace.length > 0) dirs.add(workspace)
|
|
317
331
|
const collect = (text) => {
|
|
318
332
|
if (typeof text !== 'string' || text.length === 0) return
|
|
319
|
-
|
|
333
|
+
// `cd <dir> && npm test`:这里那段路径本身就是目录,不能交给 dirOf(会多剥一层,
|
|
334
|
+
// 让 `cd ~/projB` 变成 `~`,于是兄弟目录的测量洗白了 projA 的盲改计数)。
|
|
335
|
+
let rest = text
|
|
336
|
+
for (const match of text.matchAll(/\bcd\s+("[^"]+"|'[^']+'|[^\s&;|]+)/gi)) {
|
|
337
|
+
const raw = match[1].replace(/^["']|["']$/g, '')
|
|
338
|
+
if (raw.length > 0) {
|
|
339
|
+
const expanded = raw.startsWith('~') ? expandHome(raw) : raw
|
|
340
|
+
// `cd src` 这种相对写法要靠 workdir 才能落地;两者都缺就跳过,
|
|
341
|
+
// 否则 `cd ..` 会变成一个恒不匹配的目录名,白占一个候选。
|
|
342
|
+
const dir = isAbsPath(expanded)
|
|
343
|
+
? normDir(expanded)
|
|
344
|
+
: workspace.length > 0
|
|
345
|
+
? normDir(join(workspace, expanded))
|
|
346
|
+
: ''
|
|
347
|
+
if (dir.length > 0) dirs.add(dir)
|
|
348
|
+
}
|
|
349
|
+
rest = rest.split(match[0]).join(' ')
|
|
350
|
+
}
|
|
351
|
+
for (const match of rest.matchAll(/[A-Za-z]:[\\/][^\s"'`;,)]+|\/(?:[\w.-]+\/)+[\w.-]*/g)) {
|
|
320
352
|
dirs.add(dirOf(match[0]))
|
|
321
353
|
}
|
|
322
354
|
}
|
|
@@ -330,7 +362,7 @@ export function measureDirs(args) {
|
|
|
330
362
|
* 报错变的是行号、时间戳、临时路径、内存地址,不变的是异常类和消息骨架。
|
|
331
363
|
*/
|
|
332
364
|
export function errorFingerprint(text) {
|
|
333
|
-
const head =
|
|
365
|
+
const head = stripFileUrl(text)
|
|
334
366
|
.split('\n')
|
|
335
367
|
.slice(0, 6)
|
|
336
368
|
.join('\n')
|
|
@@ -353,11 +385,13 @@ export function errorFingerprint(text) {
|
|
|
353
385
|
* 就被当成「同一个报错吃了两次」)。
|
|
354
386
|
*/
|
|
355
387
|
export function errorTargetOf(text) {
|
|
356
|
-
const match = /(?:[A-Za-z]:[\\/]|(?<![\w.])\.{0,2}\/)[^\s"'
|
|
388
|
+
const match = /(?:[A-Za-z]:[\\/]|(?<![\w.])\.{0,2}\/)[^\s"';)]+/i.exec(stripFileUrl(text))
|
|
357
389
|
if (match === null) return ''
|
|
390
|
+
// 只剥末尾的行号列号(`a.mjs:12:29` → `a.mjs`)。**不要**把路径里每个数字都归一:
|
|
391
|
+
// `a1.js` 与 `a2.js`、`proj1/` 与 `proj2/` 是两个不同位置,归一后会把它们塌成一个 episode。
|
|
358
392
|
// 大小写按平台折叠,和 normDir 同理:在区分大小写的系统上折叠会把 a.js 与 A.js
|
|
359
393
|
// 合成同一个 episode,把两个不同文件各错一次误报成「同一个报错吃了两次」。
|
|
360
|
-
return foldCase(match[0].replace(
|
|
394
|
+
return foldCase(match[0].replace(/(?::\d+)+$/, '').replace(/\\/g, '/'))
|
|
361
395
|
}
|
|
362
396
|
|
|
363
397
|
/** 从 tool/result 的事件数据里拔出人能读的错误摘要。 */
|