dsh-sweeper 1.5.18 → 1.5.20
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 +2 -2
- package/lib/index.js +1 -0
- package/lib/trash.js +28 -18
- package/package.json +3 -2
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
|
+
- **页面读的字段,路由一定发**:新增 `test/route-fields.mjs`,从 `lib/client.js` 抽出所有 `review.*` 字段,逐条核对 `/review` 的响应里确实有——本轮就是它抓到 `hintsCapped` 只写进了提示词、没写进响应。
|
|
282
|
+
- **回收站不会为了报一个数字去扫整棵树**:清单损坏的批次靠数文件来报数量,数到 2,000 个就停,页面写「至少 2,000 个文件」,而不是让每次刷新都遍历几万个文件。
|
|
281
283
|
- **清单外文件太多时会说「至少」**:模型复核的清单外文件最多收集 160 个、提交 80 个;命中上限时页面写「清单外文件至少 N 个……磁盘上还有更多没有列出来」,提示词里也会告诉模型这份清单不完整。
|
|
282
284
|
- **清理大目录不会越来越慢**:一次清理每搬一个文件只追加一行 `journal.jsonl`(而不是重写整份清单),搬完再折成一份 `manifest.json`;批次跑到一半崩溃时,`journal.jsonl` 仍是完整的记录,列表和恢复都认得它。
|
|
283
285
|
- **缓存与构建目录也点名**:`node_modules`、`.pnpm-store`、`.gradle`、`.m2`、`.cargo`、`.turbo`、`.next`、`dist` 等 21 个目录不遍历,跳过了多少个会写在结果末尾(「N 个缓存或构建目录没有搜」),免得模型以为整棵树都看过了。
|
package/lib/client.js
CHANGED
|
@@ -974,8 +974,8 @@ const STYLE_ID = 'dsh-sweeper-style'
|
|
|
974
974
|
b.damaged ? h(Chip, { tone: 'warn' }, '清单损坏') : null),
|
|
975
975
|
h('div', { className: 'sw-num', style: { fontSize: 11, color: T.faint, marginTop: 2 } },
|
|
976
976
|
b.damaged
|
|
977
|
-
? b.count + ' 个文件 · ' + fmtBytes(b.bytes) + ' · 清单读不出来,只能整批删除'
|
|
978
|
-
: b.count + ' 个文件 · ' + fmtBytes(b.bytes))),
|
|
977
|
+
? (b.countCapped ? '至少 ' : '') + fmtNum(b.count) + ' 个文件 · ' + fmtBytes(b.bytes) + ' · 清单读不出来,只能整批删除'
|
|
978
|
+
: fmtNum(b.count) + ' 个文件 · ' + fmtBytes(b.bytes))),
|
|
979
979
|
h('div', { style: { display: 'flex', gap: 6, flex: 'none' } },
|
|
980
980
|
h(Btn, {
|
|
981
981
|
label: '恢复',
|
package/lib/index.js
CHANGED
|
@@ -561,6 +561,7 @@ export function apply(ctx, config = {}) {
|
|
|
561
561
|
skipped: out.skipped,
|
|
562
562
|
hintsTotal: out.hintsTotal || 0,
|
|
563
563
|
hintsSkipped: out.hintsSkipped || 0,
|
|
564
|
+
hintsCapped: out.hintsCapped === true,
|
|
564
565
|
note: out.verdict && out.verdict.note ? out.verdict.note : '',
|
|
565
566
|
auto: plan.auto.map((it) => ({ key: it.key, path: it.path, size: it.size })),
|
|
566
567
|
autoBytes: plan.auto.reduce((n, it) => n + (it.size || 0), 0),
|
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 {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-sweeper",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "清理对话留下的临时文件与垃圾,释放磁盘空间;只报告,清理进回收站可恢复 (cleanup junk files conversations leave on disk, free up space)",
|
|
6
6
|
"keywords": [
|
|
@@ -69,6 +69,7 @@
|
|
|
69
69
|
"contract": "node test/contract.mjs",
|
|
70
70
|
"messages": "node test/messages.mjs",
|
|
71
71
|
"listing": "node test/market-listing.mjs",
|
|
72
|
-
"shots": "node test/screenshots.mjs"
|
|
72
|
+
"shots": "node test/screenshots.mjs",
|
|
73
|
+
"fields": "node test/route-fields.mjs"
|
|
73
74
|
}
|
|
74
75
|
}
|