dsh-sweeper 1.5.17 → 1.5.19
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.md +2 -0
- package/lib/client.js +8 -5
- package/lib/review.js +5 -2
- package/lib/scan.js +6 -0
- package/lib/trash.js +28 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -278,6 +278,8 @@ node test/browser/check.mjs # 需要本机有 Chrome/Edge,或 CHROME=<p
|
|
|
278
278
|
## 边界与自保
|
|
279
279
|
|
|
280
280
|
- **工具的遍历上限会说出来**:模型自己找文件时走到 400 个条目上限会收到一句「只看了前 400 个」,不会把「没扫完」当成「没有」。
|
|
281
|
+
- **回收站不会为了报一个数字去扫整棵树**:清单损坏的批次靠数文件来报数量,数到 2,000 个就停,页面写「至少 2,000 个文件」,而不是让每次刷新都遍历几万个文件。
|
|
282
|
+
- **清单外文件太多时会说「至少」**:模型复核的清单外文件最多收集 160 个、提交 80 个;命中上限时页面写「清单外文件至少 N 个……磁盘上还有更多没有列出来」,提示词里也会告诉模型这份清单不完整。
|
|
281
283
|
- **清理大目录不会越来越慢**:一次清理每搬一个文件只追加一行 `journal.jsonl`(而不是重写整份清单),搬完再折成一份 `manifest.json`;批次跑到一半崩溃时,`journal.jsonl` 仍是完整的记录,列表和恢复都认得它。
|
|
282
284
|
- **缓存与构建目录也点名**:`node_modules`、`.pnpm-store`、`.gradle`、`.m2`、`.cargo`、`.turbo`、`.next`、`dist` 等 21 个目录不遍历,跳过了多少个会写在结果末尾(「N 个缓存或构建目录没有搜」),免得模型以为整棵树都看过了。
|
|
283
285
|
- **不敢跟的链接、读不到的条目会被数出来**:`list_dir` / `find_files` 遇到符号链接(可能指向工作目录之外)和权限不足的条目时不再静默跳过,而是写「N 个链接未跟随」「N 个条目读不出来」;整目录读不进去时单独写「N 个目录读不出来」,不会把目录说成文件。
|
package/lib/client.js
CHANGED
|
@@ -700,12 +700,15 @@ const STYLE_ID = 'dsh-sweeper-style'
|
|
|
700
700
|
h(Stat, { label: '模型', value: review.model && review.model.model ? review.model.model : '—', sub: (review.model && review.model.provider ? review.model.provider + ' · ' : '') + '耗时 ' + fmtDuration(review.ms) }),
|
|
701
701
|
h(Stat, { label: '本次看过', value: fmtNum(review.reviewed) + ' 条', sub: review.skipped
|
|
702
702
|
? '报告共 ' + fmtNum(review.reviewed + review.skipped) + ' 条,只发送了前 ' + fmtNum(review.reviewed) + ' 条'
|
|
703
|
-
: (extra.hints
|
|
703
|
+
: (extra.hints
|
|
704
|
+
? '另看 ' + fmtNum(extra.hints) + ' 个清单外文件' + (review.hintsCapped ? '(磁盘上还有更多没列)' : '')
|
|
705
|
+
: '编号全部有效') }),
|
|
704
706
|
),
|
|
705
707
|
|
|
706
|
-
review.hintsSkipped
|
|
708
|
+
review.hintsSkipped || review.hintsCapped
|
|
707
709
|
? h('div', { style: { fontSize: 11.5, color: T.faint, marginTop: 6 } },
|
|
708
|
-
'
|
|
710
|
+
'清单外文件' + (review.hintsCapped ? '至少 ' : '共 ') + fmtNum(review.hintsTotal) + ' 个,只提交了前 ' + fmtNum(extra.hints) + ' 个'
|
|
711
|
+
+ (review.hintsCapped ? ';磁盘上还有更多没有列出来。' : '。'))
|
|
709
712
|
: null,
|
|
710
713
|
|
|
711
714
|
moved.length
|
|
@@ -971,8 +974,8 @@ const STYLE_ID = 'dsh-sweeper-style'
|
|
|
971
974
|
b.damaged ? h(Chip, { tone: 'warn' }, '清单损坏') : null),
|
|
972
975
|
h('div', { className: 'sw-num', style: { fontSize: 11, color: T.faint, marginTop: 2 } },
|
|
973
976
|
b.damaged
|
|
974
|
-
? b.count + ' 个文件 · ' + fmtBytes(b.bytes) + ' · 清单读不出来,只能整批删除'
|
|
975
|
-
: b.count + ' 个文件 · ' + fmtBytes(b.bytes))),
|
|
977
|
+
? (b.countCapped ? '至少 ' : '') + fmtNum(b.count) + ' 个文件 · ' + fmtBytes(b.bytes) + ' · 清单读不出来,只能整批删除'
|
|
978
|
+
: fmtNum(b.count) + ' 个文件 · ' + fmtBytes(b.bytes))),
|
|
976
979
|
h('div', { style: { display: 'flex', gap: 6, flex: 'none' } },
|
|
977
980
|
h(Btn, {
|
|
978
981
|
label: '恢复',
|
package/lib/review.js
CHANGED
|
@@ -187,7 +187,9 @@ export async function review(ctx, report, opts = {}) {
|
|
|
187
187
|
? ['A 段 · 候选清单(这些已经被规则筛过一轮):', JSON.stringify(payload), '']
|
|
188
188
|
: ['A 段 · 这次没有候选清单,只回答 B 段。', '']),
|
|
189
189
|
...(hints.length
|
|
190
|
-
? ['B 段 ·
|
|
190
|
+
? ['B 段 · 清单外观察到的文件(在已知临时目录里、但任何会话日志都没提到过;只根据路径和闲置天数判断)'
|
|
191
|
+
+ (report.hintsTruncated ? '(清单外文件很多,这里只列了前 ' + extra.length + ' 个;磁盘上还有更多没有列出来)' : '')
|
|
192
|
+
+ ':', JSON.stringify(extra), '']
|
|
191
193
|
: ['B 段 · 这次没有清单外文件。', '']),
|
|
192
194
|
'请按格式逐行输出判断。',
|
|
193
195
|
].join('\n')
|
|
@@ -234,7 +236,8 @@ export async function review(ctx, report, opts = {}) {
|
|
|
234
236
|
verdict: translated.verdict,
|
|
235
237
|
proposals: translated.proposals,
|
|
236
238
|
hints: hints.length,
|
|
237
|
-
hintsTotal: allHints.length,
|
|
239
|
+
hintsTotal: allHints.length,
|
|
240
|
+
hintsCapped: !!(report && report.hintsTruncated),
|
|
238
241
|
hintsSkipped: allHints.length - hints.length,
|
|
239
242
|
unknownIds: translated.unknown,
|
|
240
243
|
reviewed: items.length,
|
package/lib/scan.js
CHANGED
|
@@ -214,6 +214,9 @@ const HINT_SKIP = new Set(['node_modules', '.git', '.venv', 'venv', 'dist', 'bui
|
|
|
214
214
|
function collectHints(roots, artifacts, cutoff, now) {
|
|
215
215
|
const out = []
|
|
216
216
|
const seen = new Set(artifacts.keys())
|
|
217
|
+
// Stopping at a cap without saying so turns "the first 160 files" into
|
|
218
|
+
// "there are 160 files". Callers read the flag and say what they know.
|
|
219
|
+
let truncated = roots.length > 40
|
|
217
220
|
const queue = roots.slice(0, 40).map((r) => ({ dir: r, depth: 0 }))
|
|
218
221
|
while (queue.length && out.length < HINT_LIMIT) {
|
|
219
222
|
const { dir, depth } = queue.shift()
|
|
@@ -244,7 +247,9 @@ function collectHints(roots, artifacts, cutoff, now) {
|
|
|
244
247
|
})
|
|
245
248
|
}
|
|
246
249
|
}
|
|
250
|
+
if (out.length >= HINT_LIMIT) truncated = true
|
|
247
251
|
out.sort((a, b) => b.size - a.size)
|
|
252
|
+
Object.defineProperty(out, 'truncated', { value: truncated, enumerable: false })
|
|
248
253
|
return out
|
|
249
254
|
}
|
|
250
255
|
|
|
@@ -564,6 +569,7 @@ export async function scan(ctx, opts = {}) {
|
|
|
564
569
|
unreadable,
|
|
565
570
|
items: capped,
|
|
566
571
|
hints,
|
|
572
|
+
hintsTruncated: hints.truncated === true,
|
|
567
573
|
truncated: items.length > capped.length,
|
|
568
574
|
}
|
|
569
575
|
}
|
package/lib/trash.js
CHANGED
|
@@ -179,10 +179,10 @@ export async function listBatches() {
|
|
|
179
179
|
// batch would make the quarantine look empty. Report what is there.
|
|
180
180
|
let files = []
|
|
181
181
|
try { files = await readdir(dir, { withFileTypes: true }) } catch { files = [] }
|
|
182
|
-
const
|
|
182
|
+
const counted = await countFiles(dir)
|
|
183
183
|
let bytes = 0
|
|
184
|
-
for (const f of
|
|
185
|
-
out.push({ id: name, createdAt: 0, kind: 'quarantine', note: '', count:
|
|
184
|
+
for (const f of files) { if (!f.isFile()) continue; try { bytes += (await stat(join(dir, f.name))).size } catch { /* ignore */ } }
|
|
185
|
+
out.push({ id: name, createdAt: 0, kind: 'quarantine', note: '', count: counted.count, countCapped: counted.capped, bytes, damaged: true })
|
|
186
186
|
continue
|
|
187
187
|
}
|
|
188
188
|
const entries = await entriesOf(dir, manifest)
|
|
@@ -355,22 +355,32 @@ export async function restore(id) {
|
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
/**
|
|
359
|
-
|
|
358
|
+
/**
|
|
359
|
+
* Count the files a damaged batch still holds, so the page can state a number.
|
|
360
|
+
* Stops at `cap`: a badly damaged batch with tens of thousands of files must
|
|
361
|
+
* not make every /trash poll walk the whole tree. Callers report "at least".
|
|
362
|
+
*/
|
|
363
|
+
export async function countFiles(dir, cap = 2000) {
|
|
360
364
|
let n = 0
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
365
|
+
const queue = [dir]
|
|
366
|
+
while (queue.length) {
|
|
367
|
+
const cur = queue.shift()
|
|
368
|
+
let names = []
|
|
369
|
+
try { names = await readdir(cur) } catch { continue }
|
|
370
|
+
for (const name of names) {
|
|
371
|
+
if (name === 'manifest.json' || name === 'manifest.json.tmp' || name === JOURNAL) continue
|
|
372
|
+
const full = join(cur, name)
|
|
373
|
+
// lstat, not stat: a symlink inside a batch must not be followed and must
|
|
374
|
+
// not be counted as if it were one of the quarantined files.
|
|
375
|
+
const st = await lstat(full).catch(() => null)
|
|
376
|
+
if (!st || st.isSymbolicLink()) continue
|
|
377
|
+
if (st.isDirectory()) { queue.push(full); continue }
|
|
378
|
+
if (!st.isFile()) continue
|
|
379
|
+
n += 1
|
|
380
|
+
if (n >= cap) return { count: n, capped: true }
|
|
381
|
+
}
|
|
372
382
|
}
|
|
373
|
-
return n
|
|
383
|
+
return { count: n, capped: false }
|
|
374
384
|
}
|
|
375
385
|
|
|
376
386
|
export async function purge(id) {
|
|
@@ -386,7 +396,7 @@ export async function purge(id) {
|
|
|
386
396
|
// An unreadable manifest used to mark the batch as gone, so purging a
|
|
387
397
|
// damaged batch answered 404 "already gone" right after deleting its files.
|
|
388
398
|
if (manifest && Array.isArray(manifest.entries)) count = manifest.entries.length
|
|
389
|
-
else if (existed) count = await countFiles(dir)
|
|
399
|
+
else if (existed) count = (await countFiles(dir)).count
|
|
390
400
|
try {
|
|
391
401
|
await rm(dir, { recursive: true, force: true })
|
|
392
402
|
} catch {
|