dsh-sweeper 1.5.12 → 1.5.14

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 CHANGED
@@ -278,6 +278,8 @@ node test/browser/check.mjs # 需要本机有 Chrome/Edge,或 CHROME=<p
278
278
  ## 边界与自保
279
279
 
280
280
  - **工具的遍历上限会说出来**:模型自己找文件时走到 400 个条目上限会收到一句「只看了前 400 个」,不会把「没扫完」当成「没有」。
281
+ - **不敢跟的链接、读不到的条目会被数出来**:`list_dir` / `find_files` 遇到符号链接(可能指向工作目录之外)和权限不足的条目时不再静默跳过,而是写「N 个链接未跟随」「N 个条目读不出来」,免得少列几行就被当成「这里就这些」。
282
+ - **有日志读不出来,就不给「无脑删」**:一份会话日志打不开时,它可能用过任何文件;这一轮所有原本能一键清理的条目都会降到「需要你判断」,并在理由里写明原因。
281
283
  - **看不到的路径会被点名**:权限不足或文件被占用的路径不能判断,会写成「另有 N 个路径读不到」,不会悄悄少列。
282
284
  - **没列出来的对话会说明**:每轮最多分析 24 段,超出的段数会写成「另有 N 段没有列出」,而不是装作全都看过。
283
285
  - **读不下去的日志会被点名**:会话日志读到一半失败时会计入「N 段日志读不出来」,而不是悄悄从计划里消失。
package/lib/client.js CHANGED
@@ -626,7 +626,7 @@ const STYLE_ID = 'dsh-sweeper-style'
626
626
  '· 清理 = rename 进 ' + (report.trashRoot || 'DSH_HOME/plugin-data/dsh-sweeper/trash') + ',可整批恢复;永久删除只发生在你手动点「彻底删除」。', h('br'),
627
627
  '· 复核每个待删路径:绝对路径、无 ..、不在盘符根、不在 ~/.dsh 与 ~/.agents 内、realpath 未穿链接、是普通文件、大小与 mtime 与扫描一致。', h('br'),
628
628
  '· 保护中 ' + fmtNum(report.protected.recent) + '(一周内) · ' + fmtNum(report.protected.live) + '(活跃会话) · ' + fmtNum(report.protected.gone) + '(已消失) · ' + fmtNum(report.protected.unsafe || 0) + '(DSH 内部)',
629
- report.unreadable && report.unreadable.length ? h('div', { style: { color: T.warn, marginTop: 4 } }, '有 ' + report.unreadable.length + ' 个会话读不出来,已整体跳过(fail-closed)。') : null,
629
+ report.unreadable && report.unreadable.length ? h('div', { style: { color: T.warn, marginTop: 4 } }, '有 ' + report.unreadable.length + ' 个会话读不出来,已整体跳过' + (report.stats && report.stats.demoted ? ';本轮 ' + report.stats.demoted + ' 个原本能一键清理的文件已改为「需要你判断」' : '') + '。') : null,
630
630
  )) : null,
631
631
  )
632
632
  }
package/lib/fs-tools.js CHANGED
@@ -37,6 +37,9 @@ function day(ms) {
37
37
  export function makeFsTools(opts) {
38
38
  const roots = (opts.roots || []).filter((root) => typeof root === 'string' && root.length > 0).map((root) => normKey(root))
39
39
  const deny = (opts.deny || []).filter((root) => typeof root === 'string' && root.length > 0).map((root) => normKey(root))
40
+ // Tests inject a stat that fails, so the "could not read this entry" path is
41
+ // exercised on a machine where every file happens to be readable.
42
+ const lstatOf = typeof opts.lstat === 'function' ? opts.lstat : fs.lstatSync
40
43
 
41
44
  /** Resolve and authorise one path, or explain why not. */
42
45
  function allow(raw) {
@@ -77,17 +80,25 @@ export function makeFsTools(opts) {
77
80
  if (!st.isDirectory()) throw new Error('not a directory: ' + input.path)
78
81
  const limit = Math.max(1, Math.min(MAX_ENTRIES, Number(input.limit) || MAX_ENTRIES))
79
82
  const rows = []
83
+ let links = 0
84
+ let unreadable = 0
80
85
  for (const name of fs.readdirSync(ok.real)) {
81
86
  let item
82
- try { item = fs.lstatSync(path.join(ok.real, name)) } catch { continue }
83
- if (item.isSymbolicLink()) continue
87
+ try { item = lstatOf(path.join(ok.real, name)) } catch { unreadable += 1; continue }
88
+ if (item.isSymbolicLink()) { links += 1; continue }
84
89
  rows.push({ name, size: item.isDirectory() ? -1 : item.size, dir: item.isDirectory(), mtime: item.mtimeMs })
85
90
  }
86
91
  rows.sort((a, b) => (b.size - a.size) || a.name.localeCompare(b.name))
87
92
  const total = rows.length
88
93
  const shown = rows.slice(0, limit)
89
94
  const lines = shown.map((row) => (row.dir ? ' dir ' : human(row.size).padStart(9)) + ' ' + day(row.mtime) + ' ' + row.name)
90
- return ok.real + '\n' + lines.join('\n') + (total > shown.length ? '\n… ' + (total - shown.length) + ' more entries not shown' : '')
95
+ // Skipping is fine; skipping silently is not. A listing that hides entries
96
+ // reads as "that is everything in here".
97
+ const notes = []
98
+ if (total > shown.length) notes.push('… ' + (total - shown.length) + ' more entries not shown')
99
+ if (links) notes.push('… ' + links + ' symbolic link' + (links === 1 ? '' : 's') + ' not followed')
100
+ if (unreadable) notes.push('… ' + unreadable + ' entr' + (unreadable === 1 ? 'y' : 'ies') + ' could not be read')
101
+ return ok.real + '\n' + lines.join('\n') + (notes.length ? '\n' + notes.join('\n') : '')
91
102
  },
92
103
  }
93
104
 
@@ -144,18 +155,20 @@ export function makeFsTools(opts) {
144
155
  const found = []
145
156
  let walked = 0
146
157
  let capped = false
158
+ let links = 0
159
+ let unreadable = 0
147
160
  const walk = (dir, level) => {
148
161
  if (level > depth) return
149
162
  if (walked > MAX_WALK) { capped = true; return }
150
163
  let names
151
- try { names = fs.readdirSync(dir) } catch { return }
164
+ try { names = fs.readdirSync(dir) } catch { unreadable += 1; return }
152
165
  for (const name of names) {
153
166
  walked += 1
154
167
  if (walked > MAX_WALK) { capped = true; return }
155
168
  const full = path.join(dir, name)
156
169
  let st
157
- try { st = fs.lstatSync(full) } catch { continue }
158
- if (st.isSymbolicLink()) continue
170
+ try { st = lstatOf(full) } catch { unreadable += 1; continue }
171
+ if (st.isSymbolicLink()) { links += 1; continue }
159
172
  if (st.isDirectory()) {
160
173
  if (SKIP.has(name.toLowerCase())) continue
161
174
  walk(full, level + 1)
@@ -175,12 +188,17 @@ export function makeFsTools(opts) {
175
188
  const cappedNote = capped
176
189
  ? '\n… walked only the first ' + MAX_WALK + ' entries (cap); narrow the path or lower depth to see the rest'
177
190
  : ''
191
+ const skippedNote = [
192
+ links ? '… ' + links + ' symbolic link' + (links === 1 ? '' : 's') + ' not followed' : '',
193
+ unreadable ? '… ' + unreadable + ' entr' + (unreadable === 1 ? 'y' : 'ies') + ' could not be read' : '',
194
+ ].filter(Boolean).join('\n')
195
+ const extra = cappedNote + (skippedNote ? '\n' + skippedNote : '')
178
196
  if (shown.length === 0) {
179
- return ok.real + '\n' + (capped ? 'capped before any match' : 'no file matched') + cappedNote
197
+ return ok.real + '\n' + (capped ? 'capped before any match' : 'no file matched') + extra
180
198
  }
181
199
  return ok.real + '\n' + shown.map((row) => human(row.size).padStart(9) + ' ' + day(row.mtime) + ' ' + row.full).join('\n')
182
200
  + (found.length > shown.length ? '\n… ' + (found.length - shown.length) + ' more matches not shown' : '')
183
- + cappedNote
201
+ + extra
184
202
  },
185
203
  }
186
204
 
package/lib/scan.js CHANGED
@@ -248,6 +248,24 @@ function collectHints(roots, artifacts, cutoff, now) {
248
248
  return out
249
249
  }
250
250
 
251
+ /**
252
+ * Demote every one-click candidate when some conversation logs could not be
253
+ * read: those logs may have used the files, and we cannot tell. The page says
254
+ * "fail-closed" — this is what that has to mean for the split.
255
+ */
256
+ export function guardUnreadable(items, unreadableCount) {
257
+ const holes = Number(unreadableCount) || 0
258
+ if (!holes) return 0
259
+ let moved = 0
260
+ for (const it of items) {
261
+ if (!it || it.tier !== 'safe') continue
262
+ it.tier = 'unsure'
263
+ moved += 1
264
+ it.reasons = (it.reasons || []).concat('有 ' + holes + ' 段会话日志读不出来,无法确认它们有没有用过这个文件')
265
+ }
266
+ return moved
267
+ }
268
+
251
269
  export async function scan(ctx, opts = {}) {
252
270
  const started = Date.now()
253
271
  const now = opts.now ?? Date.now()
@@ -508,6 +526,10 @@ export async function scan(ctx, opts = {}) {
508
526
  })
509
527
  }
510
528
 
529
+ // A log that could not be read is a hole in the evidence; nothing stays in the
530
+ // one-click tier while such a hole exists.
531
+ const demoted = guardUnreadable(items, unreadable.length)
532
+
511
533
  const rootSet = new Set()
512
534
  for (const rec of artifacts.values()) {
513
535
  if (!SCRATCH.test(rec.key)) continue
@@ -535,6 +557,7 @@ export async function scan(ctx, opts = {}) {
535
557
  listed: capped.length,
536
558
  liveSessions: liveIds.size,
537
559
  unreadableSessions: unreadable.length,
560
+ demoted,
538
561
  },
539
562
  protected: protectedCounts,
540
563
  tiers,
@@ -550,4 +573,5 @@ function safeHome() {
550
573
  }
551
574
 
552
575
  export const _internal = {
553
- liveSessionIds, normKey, toks, last2, relKey, SCRATCH, DEEP_TEMP, SPILL, scratchRootOf, collectHints, gitTracked }
576
+ liveSessionIds, normKey, toks, last2, relKey, SCRATCH, DEEP_TEMP, SPILL, scratchRootOf, collectHints, gitTracked,
577
+ guardUnreadable }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sweeper",
3
- "version": "1.5.12",
3
+ "version": "1.5.14",
4
4
  "type": "module",
5
5
  "description": "清理对话留下的临时文件与垃圾,释放磁盘空间;只报告,清理进回收站可恢复 (cleanup junk files conversations leave on disk, free up space)",
6
6
  "keywords": [