dsh-better-debug 0.2.0 → 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 +20 -8
- package/README.md +19 -8
- package/lib/index.js +38 -4
- package/package.json +3 -5
package/README.en.md
CHANGED
|
@@ -175,13 +175,21 @@ The route is mounted via `ctx.inject(['webServer'], …)` — a **dynamic inject
|
|
|
175
175
|
|
|
176
176
|
## Install
|
|
177
177
|
|
|
178
|
-
**
|
|
178
|
+
**Shortest path (npm registry — published):**
|
|
179
179
|
|
|
180
180
|
```bash
|
|
181
|
-
dsh plugin add
|
|
181
|
+
dsh plugin add dsh-better-debug
|
|
182
182
|
```
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
**Or from the Release tarball (pnpm treats it as a normal package):**
|
|
185
|
+
|
|
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
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
(Both install the same package: the npm tarball is byte-identical to the Release asset.
|
|
191
|
+
Going through npm also lets the market's daily probe backfill the `npm` field into the
|
|
192
|
+
catalog entry, so a click installs straight from the registry.)
|
|
185
193
|
|
|
186
194
|
**Manual link (use this if you want to change the code):**
|
|
187
195
|
|
|
@@ -291,13 +299,13 @@ Not writing a file was the v0.1 default, and the cost was new users installing i
|
|
|
291
299
|
|
|
292
300
|
```bash
|
|
293
301
|
node --check lib/index.js && node --check lib/panel.js && node --check lib/text.js && node --check client.js
|
|
294
|
-
node test/sim.mjs #
|
|
302
|
+
node test/sim.mjs # 46 cases: gate semantics + portability
|
|
295
303
|
node test/panel.mjs # 32 cases: log parsing, aggregation, instrumentation
|
|
296
304
|
npm run test:posix # re-runs both suites under POSIX path semantics
|
|
297
305
|
npm run verify # all of the above (with syntax checks)
|
|
298
306
|
```
|
|
299
307
|
|
|
300
|
-
`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**.
|
|
301
309
|
|
|
302
310
|
Semantics (each with a positive and a negative):
|
|
303
311
|
|
|
@@ -324,10 +332,10 @@ and only ask "does it start at a root" (`isAbsPath`).
|
|
|
324
332
|
|
|
325
333
|
`test/posix` uses a `node --import` resolve hook to swap `node:path` for `node:path/posix`
|
|
326
334
|
and then **re-runs both suites unchanged** — so a Windows dev machine reproduces Linux path
|
|
327
|
-
semantics. CI runs `npm run verify` on ubuntu / windows / macos × node 20 / 22, so this
|
|
328
|
-
cannot quietly regress.
|
|
335
|
+
semantics. CI runs `npm run verify` on ubuntu / windows / macos × node 20 / 22 / 24, so this
|
|
336
|
+
cannot quietly regress. (24 is not padding: the desktop build runs Electron's bundled node 24.)
|
|
329
337
|
|
|
330
|
-
|
|
338
|
+
The rest of the same family, all fixed in v0.2 / v0.2.1 / v0.2.2:
|
|
331
339
|
|
|
332
340
|
| Symptom | Root cause | Now |
|
|
333
341
|
| --- | --- | --- |
|
|
@@ -335,6 +343,10 @@ Three more of the same family, all fixed in v0.2:
|
|
|
335
343
|
| Panel shows four empty cards right after install | default `logFile: ""` wrote nothing | defaults to `$DSH_HOME/logs/better-debug.log` |
|
|
336
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` |
|
|
337
345
|
| Clicking "enable" in the market does nothing | bundle patch carried a `config:` block | patch keeps only `id` + `name` |
|
|
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 |
|
|
338
350
|
|
|
339
351
|
**Case folding is decided per platform** (`CASE_INSENSITIVE`): only on `win32` / `darwin`.
|
|
340
352
|
The cost of folding wrong is asymmetric — not folding when you should under-reports, folding
|
package/README.md
CHANGED
|
@@ -213,14 +213,20 @@ suppress session=… turn=39 reason=done
|
|
|
213
213
|
|
|
214
214
|
## 安装
|
|
215
215
|
|
|
216
|
-
|
|
216
|
+
**最短一条(npm registry,已发布):**
|
|
217
217
|
|
|
218
218
|
```bash
|
|
219
|
-
dsh plugin add
|
|
219
|
+
dsh plugin add dsh-better-debug
|
|
220
220
|
```
|
|
221
221
|
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
**或者从 Release tarball 装(pnpm 会把它当普通包装进 profile):**
|
|
223
|
+
|
|
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
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
(两条装的是同一个包:npm 上的 tarball 与 Release 资产逐字节相同。走 npm 的好处是
|
|
229
|
+
市场每日探测会自动把 `npm` 字段回填进目录条目,用户点一下就走 registry 快路。)
|
|
224
230
|
|
|
225
231
|
**手动 link(要改代码就用这个):**
|
|
226
232
|
|
|
@@ -357,14 +363,14 @@ bundle 层按原样加载」。也就是说:**写了 config,用户点「启
|
|
|
357
363
|
|
|
358
364
|
```bash
|
|
359
365
|
node --check lib/index.js && node --check lib/panel.js && node --check lib/text.js && node --check client.js
|
|
360
|
-
node test/sim.mjs #
|
|
366
|
+
node test/sim.mjs # 46 个用例:闸门语义 + 可移植性
|
|
361
367
|
node test/panel.mjs # 32 个用例:日志解析、聚合、埋点落盘
|
|
362
368
|
npm run test:posix # 把上面两套用 POSIX 路径语义再跑一遍
|
|
363
369
|
npm run verify # 上面全部(含语法检查)
|
|
364
370
|
```
|
|
365
371
|
|
|
366
372
|
`test/sim.mjs` 用假 ctx 复刻 agent-loop 的调用顺序(`emitPlain` / `emitWaterfall`),
|
|
367
|
-
覆盖 **
|
|
373
|
+
覆盖 **46 个用例**。
|
|
368
374
|
|
|
369
375
|
语义层(每条都有正例 + 反例):
|
|
370
376
|
|
|
@@ -393,9 +399,10 @@ npm run verify # 上面全部(含语法检查)
|
|
|
393
399
|
|
|
394
400
|
`test/posix` 用 `node --import` 的 resolve hook 把 `node:path` 换成 `node:path/posix`,
|
|
395
401
|
然后**把两套用例原样再跑一遍**——这样 Windows 开发机也能复现 Linux 的路径语义。CI 在
|
|
396
|
-
ubuntu / windows / macos × node 20 / 22 上跑 `npm run verify`,所以这条不会退回去。
|
|
402
|
+
ubuntu / windows / macos × node 20 / 22 / 24 上跑 `npm run verify`,所以这条不会退回去。
|
|
403
|
+
(24 不是凑数:桌面版 DSH 跑的是 Electron 内置的 node 24。)
|
|
397
404
|
|
|
398
|
-
|
|
405
|
+
同一类问题的其余各处,都在 v0.2 / v0.2.1 / v0.2.2 修掉了:
|
|
399
406
|
|
|
400
407
|
| 症状 | 根因 | 现在 |
|
|
401
408
|
| --- | --- | --- |
|
|
@@ -403,6 +410,10 @@ ubuntu / windows / macos × node 20 / 22 上跑 `npm run verify`,所以这条
|
|
|
403
410
|
| 装完面板四张卡全 0 | 默认 `logFile: ""` 不落盘 | 默认落 `$DSH_HOME/logs/better-debug.log` |
|
|
404
411
|
| 插件静默不加载,无报错无日志 | 静态 `inject: ['skills']` 缺服务时 `apply()` 整个不执行 | `inject = []`,走 `ctx.inject` 动态订阅 |
|
|
405
412
|
| 市场点「启用」没反应 | bundle patch 带 `config:` 块 | patch 只留 `id` + `name` |
|
|
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` 形式,那段路径按目录处理 |
|
|
406
417
|
|
|
407
418
|
**大小写折叠按平台判**(`CASE_INSENSITIVE`):只在 `win32` / `darwin` 上折叠。折叠错了的
|
|
408
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 的事件数据里拔出人能读的错误摘要。 */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-better-debug",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "卡住闸门的代码化:同一文件连续盲改 / 同一操作重复报错 / 改完没有回路又动手,命中就在下一步注入一次提醒,逼出一条几秒能跑的反馈回路。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -42,13 +42,11 @@
|
|
|
42
42
|
"inject": [
|
|
43
43
|
"slots"
|
|
44
44
|
]
|
|
45
|
-
},
|
|
46
|
-
"engines": {
|
|
47
|
-
"dsh": ">=0.2.1-rc.5"
|
|
48
45
|
}
|
|
49
46
|
},
|
|
50
47
|
"engines": {
|
|
51
|
-
"node": ">=20"
|
|
48
|
+
"node": ">=20",
|
|
49
|
+
"dsh": ">=0.2.1-rc.5"
|
|
52
50
|
},
|
|
53
51
|
"scripts": {
|
|
54
52
|
"check": "node --check lib/index.js && node --check lib/panel.js && node --check lib/text.js && node --check client.js && node --check test/sim.mjs && node --check test/panel.mjs && node --check test/posix/register.mjs && node --check test/posix/hooks.mjs && node --check test/posix/path.mjs",
|