dsh-sweeper 1.5.7 → 1.5.9

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
@@ -273,6 +273,8 @@ node test/browser/check.mjs # 需要本机有 Chrome/Edge,或 CHROME=<p
273
273
 
274
274
  ## 边界与自保
275
275
 
276
+ - **没列出来的对话会说明**:每轮最多分析 24 段,超出的段数会写成「另有 N 段没有列出」,而不是装作全都看过。
277
+ - **读不下去的日志会被点名**:会话日志读到一半失败时会计入「N 段日志读不出来」,而不是悄悄从计划里消失。
276
278
  - **失败不会藏在别的页签里**:扫描失败时,四个页签都会看到同一张错误卡与「重试扫描」,不会再出现「等待扫描」却永远等不到的情况。
277
279
  - **读不到运行中的对话就不出报告**:列不出「哪些对话正在跑」时扫描直接失败并说明原因,宁可这次不扫,也不把还在用的文件列成候选。
278
280
  - **模型被预算截断会说出来**:工具调用跑到上限、又没给出任何判定时,会退回单提示词再问一次;有判定但行被截断的行标「· 到工具上限,结论可能不全」,不会伪装成「看过了,很干净」。
package/lib/client.js CHANGED
@@ -851,6 +851,7 @@ window.__ModuleLoader__.load({
851
851
  hint: (plan.skipped
852
852
  ? '超过 ' + plan.week + ' 天未使用的 ' + plan.skipped + ' 段对话里没有留下临时产物,所以不用花 token 去问模型。'
853
853
  : '超过 ' + plan.week + ' 天未使用、且仍然留有临时产物的对话才会出现在这里。')
854
+ + (plan.more ? ' 另有 ' + plan.more + ' 段符合条件的对话没有列出(每轮有上限),下一轮「重新估算」会轮到它们。' : '')
854
855
  + ' 可以点「重新估算」再读一次磁盘。',
855
856
  }) : null,
856
857
 
@@ -858,7 +859,7 @@ window.__ModuleLoader__.load({
858
859
  h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, padding: '11px 14px', background: T.layer, borderBottom: '1px solid ' + T.border } },
859
860
  h('div', { style: { fontSize: 13, fontWeight: 600 } }, job && job.state !== 'running' ? '本次分析' : '待分析对话'),
860
861
  h('span', { className: 'sw-num', style: { fontSize: 11, color: T.faint } },
861
- totalN + ' 段 · ' + (job ? '本次约 ' : '预计约 ') + fmtNum(estimate) + ' tokens' + (plan && plan.skipped ? ' · ' + plan.skipped + ' 段无临时产物已跳过' : '') + (plan && plan.unreadable ? ' · ' + plan.unreadable + ' 段日志读不出来' : '')),
862
+ totalN + ' 段 · ' + (job ? '本次约 ' : '预计约 ') + fmtNum(estimate) + ' tokens' + (plan && plan.skipped ? ' · ' + plan.skipped + ' 段无临时产物已跳过' : '') + (plan && plan.unreadable ? ' · ' + plan.unreadable + ' 段日志读不出来' : '') + (plan && plan.more ? ' · 另有 ' + plan.more + ' 段没有列出(每次最多分析 ' + plan.sessions.length + ' 段)' : '')),
862
863
  h('div', { style: { flex: 1 } }),
863
864
  running ? h('span', { style: { fontSize: 11.5, color: T.accent } }, finished + ' / ' + totalN) : null,
864
865
  ),
package/lib/deep.js CHANGED
@@ -110,7 +110,11 @@ async function readAll(handle, limit = 200_000) {
110
110
  let off = 0
111
111
  for (;;) {
112
112
  let page
113
- try { page = await handle.read(off, PAGE) } catch { return { events, truncated: events.length > 0 } }
113
+ try { page = await handle.read(off, PAGE) } catch {
114
+ // A read that dies is not the end of the log. Callers have to be able to tell
115
+ // "this log is short" from "this log stopped answering halfway".
116
+ return { events, truncated: events.length > 0, failed: true }
117
+ }
114
118
  const list = Array.isArray(page) ? page : (page && page.events) || []
115
119
  if (!list.length) return { events, truncated: false }
116
120
  for (const ev of list) events.push(ev)
@@ -153,6 +157,11 @@ export async function describeSession(ctx, persistence, snapshot) {
153
157
  try { await handle.close() } catch { /* the host may not expose close */ }
154
158
  }
155
159
  const events = read.events
160
+ if (read.failed && !events.length) {
161
+ const e = new Error('unreadable session log: the first page could not be read')
162
+ e.code = 'SWEEPER_UNREADABLE'
163
+ throw e
164
+ }
156
165
  if (!events.length) return null
157
166
 
158
167
  const info = {
@@ -468,7 +477,6 @@ export async function planDeep(ctx, opts = {}) {
468
477
  const sessions = []
469
478
  let skipped = 0
470
479
  let unreadable = 0
471
- let totalEstTokens = 0
472
480
  for (const snap of list) {
473
481
  const id = idOf(snap)
474
482
  if (!id || liveIds.has(String(id))) continue
@@ -488,7 +496,6 @@ export async function planDeep(ctx, opts = {}) {
488
496
  if (!candidates.length && !canLook) { skipped += 1; continue }
489
497
  const digest = buildDigest(info, candidates, now, { canLook })
490
498
  const estTokens = estimateTokens(digest) + (canLook ? 900 : 0)
491
- totalEstTokens += estTokens
492
499
  sessions.push({
493
500
  id, title: info.title || baseOf(info.cwd || '') || id,
494
501
  cwd: info.cwd, createdAt: info.createdAt, lastUsedAt: lastUsed,
@@ -501,10 +508,17 @@ export async function planDeep(ctx, opts = {}) {
501
508
  _info: info,
502
509
  _candidates: candidates,
503
510
  })
504
- if (sessions.length >= (opts.limit || MAX_SESSIONS)) break
505
511
  }
506
- sessions.sort((a, b) => b.candidates - a.candidates)
507
- return { sessions, totalEstTokens, concurrency: CONCURRENCY, week, skipped, unreadable }
512
+ // Rank before capping, and say how many were left out. Breaking out of the loop
513
+ // at the limit used to keep whatever the log listing happened to return first,
514
+ // and the page had no way to tell 24 of 24 from 24 of 40.
515
+ sessions.sort((a, b) => b.candidates - a.candidates || b.hidden - a.hidden || b.ageDays - a.ageDays)
516
+ const limit = opts.limit || MAX_SESSIONS
517
+ const more = Math.max(0, sessions.length - limit)
518
+ const kept = sessions.slice(0, limit)
519
+ // Estimate only what will actually be sent: rows the cap dropped cost nothing.
520
+ const totalEstTokens = kept.reduce((n, s) => n + s.estTokens, 0)
521
+ return { sessions: kept, more, totalEstTokens, concurrency: CONCURRENCY, week, skipped, unreadable }
508
522
  }
509
523
 
510
524
  /**
package/lib/index.js CHANGED
@@ -197,6 +197,7 @@ export function apply(ctx, config = {}) {
197
197
  concurrency: plan.concurrency,
198
198
  totalEstTokens: plan.totalEstTokens,
199
199
  skipped: plan.skipped || 0,
200
+ more: plan.more || 0,
200
201
  unreadable: plan.unreadable || 0,
201
202
  sessions: plan.sessions.map((s) => ({
202
203
  id: s.id, title: s.title, cwd: s.cwd, ageDays: s.ageDays, toolCalls: s.toolCalls,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-sweeper",
3
- "version": "1.5.7",
3
+ "version": "1.5.9",
4
4
  "type": "module",
5
5
  "description": "清理对话留下的临时文件与垃圾,释放磁盘空间;只报告,清理进回收站可恢复 (cleanup junk files conversations leave on disk, free up space)",
6
6
  "keywords": [