dsh-sweeper 1.4.4 → 1.5.1
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 +31 -2
- package/lib/client.js +84 -3
- package/lib/index.js +58 -1
- package/lib/review.js +24 -11
- package/lib/scan.js +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -41,6 +41,23 @@ dsh plugin add dsh-sweeper
|
|
|
41
41
|
npm 上这个包喂给官方 `dsh-plugin-catalog` 索引,插件商店里因此能显示版本号;
|
|
42
42
|
Release 与 npm 的内容一致,选哪条都行。
|
|
43
43
|
|
|
44
|
+
### 预览版本
|
|
45
|
+
|
|
46
|
+
合并进 `main` 且改动触及可安装内容(`lib/`、`package.json`、`cordis.patch.yml`、
|
|
47
|
+
`locale/`、`icon.svg`、`screenshots.json`)时,`publish` 会自动发一个快照:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
dsh plugin add dsh-sweeper@preview
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
版本号形如 `0.0.0-preview.123.abc1234`(工作流运行号 + 提交短 SHA),带 provenance,
|
|
54
|
+
`latest` 不受影响。只改测试、文档或 CI 的合并不会发——版本要对应一次真实改动,而不是
|
|
55
|
+
为了让计数器动一下。手工触发:Actions → **publish** → Run workflow → `channel: preview`。
|
|
56
|
+
|
|
57
|
+
另外每天 **09:00(Asia/Singapore)** 有一次兜底:如果当天还没有任何预览版本(`preview`
|
|
58
|
+
标签指向的版本不以当前提交的短 SHA 结尾),就补发一个 `0.0.0-nightly.<日期>.<短SHA>`。
|
|
59
|
+
同一天重复运行会自己跳过,不会重复发版;发版提交(`Release ...`)也跳过。
|
|
60
|
+
|
|
44
61
|
### 发版
|
|
45
62
|
|
|
46
63
|
发版是自动的:在 Actions 里跑 **release**(`gh workflow run release -f bump=patch`),
|
|
@@ -85,6 +102,16 @@ publishing → Add publisher → GitHub Actions**,填
|
|
|
85
102
|
- 一周内**被工具用过**的,不进列表(只在顶部「保护」里计数)。
|
|
86
103
|
- 清理 = `rename` 进 `DSH_HOME/plugin-data/dsh-sweeper/trash/<批次>/`,并写 `manifest.json`;不调用 `unlink` 删用户文件。
|
|
87
104
|
|
|
105
|
+
## 扫描在后台继续(v1.5)
|
|
106
|
+
|
|
107
|
+
一次扫描要读几十上百段会话日志(本机约 10–20 秒)。它**属于宿主进程,不属于这个页面**:切到别的设置页、关掉侧边栏、去干活,扫描都不会停,读完后照样把报告发出来。
|
|
108
|
+
|
|
109
|
+
重新打开时先问 `GET /status`,如果一遍正在跑,就按 `第 1/2 遍 · 12 / 46 个会话` 继续显示进度,而不是从 0 重来;页面每 900 ms 拉一次进度,扫描结束后自动把新报告渲染出来。横幅上写着一句话:「可以离开这个页面,扫描会在后台继续;回来时接着显示进度,不会从头再来。」
|
|
110
|
+
|
|
111
|
+
具体实现只有三处:`lib/scan.js` 在每段会话上报 `onProgress({pass, done, total})`;`lib/index.js` 把它写进 `state.scanJob` 并由 `/status` 暴露;`lib/client.js` 在挂载时先读 `/status`、再决定是显示横幅还是直接读报告。`/report` 本身仍然阻塞到扫描结束(这样它的响应一定是完整的),所以页面必须并行去问 `/status`——否则刷新时只会看到一句「正在读取会话日志」。
|
|
112
|
+
|
|
113
|
+
`test/browser/check.mjs` 用 `?scanning=1` 让回放服务的 `/status` 一直返回「进行中」,断言横幅、计数(`31 / 46`)和那句离开提示都在;`test/harness.js` 另有两个静态状态(`scanning`、`scanningSecondPass`)。
|
|
114
|
+
|
|
88
115
|
## 路由
|
|
89
116
|
|
|
90
117
|
| 方法 | 路径 | 说明 |
|
|
@@ -98,6 +125,7 @@ publishing → Add publisher → GitHub Actions**,填
|
|
|
98
125
|
| POST | `/plugins/dsh-sweeper/deep/start` | `{token, consent:true}`,启动深度分析(最多 4 段并发),立即返回 `jobId`;未带 `consent` 返回 400 |
|
|
99
126
|
| GET | `/plugins/dsh-sweeper/deep/status` | 当前任务进度与已收集结果(客户端每 900ms 拉一次) |
|
|
100
127
|
| POST | `/plugins/dsh-sweeper/deep/cancel` | `{jobId}`,停止派发新的对话,已返回的结果保留 |
|
|
128
|
+
| GET | `/plugins/dsh-sweeper/status` | 正在跑的扫描:`{scanning, job:{pass,done,total,startedAt,finishedAt}, hasReport, ageMs}`;页面靠它显示后台进度 |
|
|
101
129
|
| GET | `/plugins/dsh-sweeper/health` | 扫描状态 |
|
|
102
130
|
|
|
103
131
|
POST 必须带 `x-dsh-sweeper: 1` 头(跨站请求无法携带自定义头,借此挡掉 CSRF);`token` 与最近一次扫描绑定,过期或重扫后失效;选中「不确定」项时必须 `acknowledge: true`。
|
|
@@ -272,8 +300,9 @@ node test/browser/check.mjs # 需要本机有 Chrome/Edge,或 CHROME=<p
|
|
|
272
300
|
- **相对路径也算「用过」**:日志里的 `node .scratch/probe.mjs` 与绝对路径清单做后缀匹配时走平台感知的
|
|
273
301
|
`relKey()`(Windows 拼反斜杠并折大小写,POSIX 拼 `/` 且保留大小写),所以「之后还被用过」在
|
|
274
302
|
macOS/Linux 上同样数得到。
|
|
275
|
-
- **上限会说出来**:模型复核只发送前 100
|
|
276
|
-
|
|
303
|
+
- **上限会说出来**:模型复核只发送前 100 条候选、80 个清单外文件,每段对话只发送前 40 个;页面会把
|
|
304
|
+
没发送的条数写在行内和结果卡片上,而不是让人以为整份报告都被看过一遍。只有清单外文件、没有候选时
|
|
305
|
+
也会照常问模型——「没有候选」不等于「没有东西可看」。
|
|
277
306
|
- **后台重启之后**:DSH 重启会让宿主忘掉正在跑的深度分析。页面不会假装还在分析——连续三次轮询
|
|
278
307
|
失败或后台回 `job: null` 就标成「已中断」,说明原因,并让你重新估算或重跑。
|
|
279
308
|
- **盘上文件变了之后**:报告、扫描中的 epoch、深度计划三份缓存一起失效,所以模型刚清理掉的文件不会在
|
package/lib/client.js
CHANGED
|
@@ -689,6 +689,11 @@ window.__ModuleLoader__.load({
|
|
|
689
689
|
: (extra.hints ? '另看 ' + fmtNum(extra.hints) + ' 个清单外文件' : '编号全部有效') }),
|
|
690
690
|
),
|
|
691
691
|
|
|
692
|
+
review.hintsSkipped
|
|
693
|
+
? h('div', { style: { fontSize: 11.5, color: T.faint, marginTop: 6 } },
|
|
694
|
+
'清单外文件共 ' + fmtNum(review.hintsTotal) + ' 个,只提交了前 ' + fmtNum(extra.hints) + ' 个。')
|
|
695
|
+
: null,
|
|
696
|
+
|
|
692
697
|
moved.length
|
|
693
698
|
? h('div', { className: 'sw-card', style: { marginTop: 12, padding: '12px 14px' } },
|
|
694
699
|
h('div', { style: { fontSize: 12.5, fontWeight: 600, marginBottom: 6 } }, '已自动清理'),
|
|
@@ -989,12 +994,16 @@ window.__ModuleLoader__.load({
|
|
|
989
994
|
const [deepConsent, setDeepConsent] = useState(false)
|
|
990
995
|
const [deepErr, setDeepErr] = useState(null)
|
|
991
996
|
const [deepSel, setDeepSel] = useState(() => new Set())
|
|
997
|
+
// A pass belongs to the host, not to this page: leaving the settings
|
|
998
|
+
// screen does not stop it. This is the one already running when the page
|
|
999
|
+
// opened, so the panel can show its progress instead of a blank skeleton.
|
|
1000
|
+
const [bgScan, setBgScan] = useState(null)
|
|
992
1001
|
const scanStart = useRef(Date.now())
|
|
993
1002
|
const reviewStart = useRef(0)
|
|
994
1003
|
const loadSeq = useRef(0)
|
|
995
1004
|
const startingRef = useRef(false)
|
|
996
1005
|
|
|
997
|
-
const scanning = status === 'loading' || status === 'refreshing'
|
|
1006
|
+
const scanning = status === 'loading' || status === 'refreshing' || !!bgScan
|
|
998
1007
|
|
|
999
1008
|
const load = useCallback((force, keepReview) => {
|
|
1000
1009
|
// Two quick clicks used to race: the slower response could land last and
|
|
@@ -1004,6 +1013,16 @@ window.__ModuleLoader__.load({
|
|
|
1004
1013
|
scanStart.current = Date.now()
|
|
1005
1014
|
setStatus((s) => (s === 'loading' ? 'loading' : 'refreshing'))
|
|
1006
1015
|
setError(null)
|
|
1016
|
+
// /report blocks until the pass finishes, so ask for its progress in
|
|
1017
|
+
// parallel; without this a refresh triggered from the page would show
|
|
1018
|
+
// a bare skeleton for the whole ten seconds.
|
|
1019
|
+
getJSON('/status')
|
|
1020
|
+
.then((d) => {
|
|
1021
|
+
if (seq !== loadSeq.current || !d || !d.scanning) return
|
|
1022
|
+
scanStart.current = (d.job && d.job.startedAt) || Date.now()
|
|
1023
|
+
setBgScan(d.job || { pass: 1, done: 0, total: 0, startedAt: Date.now() })
|
|
1024
|
+
})
|
|
1025
|
+
.catch(() => {})
|
|
1007
1026
|
getJSON('/report' + (force ? '?refresh=1' : ''))
|
|
1008
1027
|
.then((data) => {
|
|
1009
1028
|
if (seq !== loadSeq.current) return
|
|
@@ -1048,7 +1067,47 @@ window.__ModuleLoader__.load({
|
|
|
1048
1067
|
.finally(() => { planningRef.current = false; setDeepPlanning(false) })
|
|
1049
1068
|
}, [])
|
|
1050
1069
|
|
|
1051
|
-
|
|
1070
|
+
// Ask the host whether a pass is already in flight before asking for a
|
|
1071
|
+
// report: /report waits for the running scan, so calling it first would
|
|
1072
|
+
// look like "nothing happens" for the whole duration.
|
|
1073
|
+
const bgKey = bgScan ? bgScan.startedAt + ':' + bgScan.pass : ''
|
|
1074
|
+
useEffect(() => {
|
|
1075
|
+
let stop = false
|
|
1076
|
+
getJSON('/status')
|
|
1077
|
+
.then((d) => {
|
|
1078
|
+
if (stop) return
|
|
1079
|
+
if (d && d.scanning) {
|
|
1080
|
+
scanStart.current = (d.job && d.job.startedAt) || Date.now()
|
|
1081
|
+
setBgScan(d.job || { pass: 1, done: 0, total: 0, startedAt: Date.now() })
|
|
1082
|
+
setStatus('loading')
|
|
1083
|
+
} else {
|
|
1084
|
+
load(false)
|
|
1085
|
+
}
|
|
1086
|
+
})
|
|
1087
|
+
.catch(() => { if (!stop) load(false) })
|
|
1088
|
+
return () => { stop = true }
|
|
1089
|
+
}, [load])
|
|
1090
|
+
|
|
1091
|
+
useEffect(() => { loadTrash() }, [loadTrash])
|
|
1092
|
+
|
|
1093
|
+
// Follow the background pass until it settles, then read the report it
|
|
1094
|
+
// published. 900 ms is slow enough to be invisible, fast enough that the
|
|
1095
|
+
// counter moves while the user watches it.
|
|
1096
|
+
useEffect(() => {
|
|
1097
|
+
if (!bgScan) return
|
|
1098
|
+
let stop = false
|
|
1099
|
+
const tick = () => {
|
|
1100
|
+
getJSON('/status')
|
|
1101
|
+
.then((d) => {
|
|
1102
|
+
if (stop) return
|
|
1103
|
+
if (!d || !d.scanning) { setBgScan(null); load(false); return }
|
|
1104
|
+
setBgScan(d.job || null)
|
|
1105
|
+
})
|
|
1106
|
+
.catch(() => { /* keep the last known progress; the next tick retries */ })
|
|
1107
|
+
}
|
|
1108
|
+
const id = setInterval(tick, 900)
|
|
1109
|
+
return () => { stop = true; clearInterval(id) }
|
|
1110
|
+
}, [bgKey, load])
|
|
1052
1111
|
useEffect(() => {
|
|
1053
1112
|
if (!toast) return
|
|
1054
1113
|
const id = setTimeout(() => setToast(null), 4200)
|
|
@@ -1483,8 +1542,30 @@ window.__ModuleLoader__.load({
|
|
|
1483
1542
|
report && report.truncated ? h('span', { style: { fontSize: 11, color: T.warn } }, '结果超过 2000 条,只列出最大的部分') : null,
|
|
1484
1543
|
),
|
|
1485
1544
|
|
|
1545
|
+
bgScan ? h('div', { className: 'sw-card', style: { marginTop: 12, padding: '12px 14px' } },
|
|
1546
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, flexWrap: 'wrap' } },
|
|
1547
|
+
h('div', { className: 'sw-spin' }),
|
|
1548
|
+
h('div', { style: { fontSize: 12.5, fontWeight: 600 } }, '正在扫描'),
|
|
1549
|
+
h('span', { className: 'sw-num', style: { fontSize: 11.5, color: T.dim } },
|
|
1550
|
+
'第 ' + (bgScan.pass || 1) + '/2 遍 · ' + (bgScan.total
|
|
1551
|
+
? fmtNum(bgScan.done || 0) + ' / ' + fmtNum(bgScan.total) + ' 个会话'
|
|
1552
|
+
: '正在读取会话列表')),
|
|
1553
|
+
h('div', { style: { flex: 1 } }),
|
|
1554
|
+
h('span', { className: 'sw-num', style: { fontSize: 11, color: T.faint } },
|
|
1555
|
+
h(Timer, { start: scanStart.current, running: true }))),
|
|
1556
|
+
h('div', { className: 'sw-progress', style: { marginTop: 8 } },
|
|
1557
|
+
h('div', {
|
|
1558
|
+
className: 'sw-progress-fill',
|
|
1559
|
+
style: { width: Math.max(4, Math.min(100, bgScan.total ? Math.round((bgScan.done / bgScan.total) * 100) : 6)) + '%' },
|
|
1560
|
+
})),
|
|
1561
|
+
h('div', { style: { fontSize: 11, color: T.faint, marginTop: 6 } },
|
|
1562
|
+
'可以离开这个页面,扫描会在后台继续;回来时接着显示进度,不会从头再来。'),
|
|
1563
|
+
) : null,
|
|
1564
|
+
|
|
1486
1565
|
tab === 'report' ? h(ReportPanel, {
|
|
1487
|
-
|
|
1566
|
+
// The banner above already explains a running pass; letting the panel
|
|
1567
|
+
// show its own "reading logs" skeleton too reads like two scans.
|
|
1568
|
+
report, status: bgScan ? 'ready' : status, error, selected, setSelected,
|
|
1488
1569
|
onScan: () => load(true),
|
|
1489
1570
|
onDelete: askDelete,
|
|
1490
1571
|
onExport: exportJSON,
|
package/lib/index.js
CHANGED
|
@@ -91,6 +91,9 @@ export function apply(ctx, config = {}) {
|
|
|
91
91
|
token: null,
|
|
92
92
|
byKey: new Map(),
|
|
93
93
|
running: null,
|
|
94
|
+
// The last scan pass, kept after it settles so a page opened mid-scan (or
|
|
95
|
+
// right after one) can show how far it got instead of a blank skeleton.
|
|
96
|
+
scanJob: null,
|
|
94
97
|
reviewing: false,
|
|
95
98
|
lastError: null,
|
|
96
99
|
// Bumped whenever something moved on disk (delete/restore). A scan that was
|
|
@@ -273,23 +276,32 @@ export function apply(ctx, config = {}) {
|
|
|
273
276
|
// which left a window where a second caller saw no running pass and started
|
|
274
277
|
// its own full scan on top of the one that had just finished.
|
|
275
278
|
if (state.running) return state.running
|
|
279
|
+
const job = { startedAt: Date.now(), pass: 1, done: 0, total: 0, finishedAt: 0 }
|
|
280
|
+
state.scanJob = job
|
|
276
281
|
state.running = (async () => {
|
|
277
282
|
try {
|
|
278
283
|
let epoch = state.epoch
|
|
279
284
|
let report = null
|
|
280
285
|
for (let i = 0; i < 3; i++) {
|
|
281
286
|
state.passes += 1
|
|
282
|
-
report = await scan(ctx, {
|
|
287
|
+
report = await scan(ctx, {
|
|
288
|
+
week: weekDays * DAY,
|
|
289
|
+
// A pass restarts from the first conversation; the page says which
|
|
290
|
+
// pass it is looking at rather than pretending the count reset.
|
|
291
|
+
onProgress: (p) => { job.pass = p.pass; job.done = p.done; job.total = p.total },
|
|
292
|
+
})
|
|
283
293
|
if (state.epoch === epoch) break
|
|
284
294
|
epoch = state.epoch
|
|
285
295
|
}
|
|
286
296
|
state.lastError = null
|
|
297
|
+
job.done = job.total
|
|
287
298
|
return publish(report)
|
|
288
299
|
} catch (err) {
|
|
289
300
|
state.lastError = (err && err.message) || String(err)
|
|
290
301
|
try { ctx.logger && ctx.logger.warn && ctx.logger.warn('[dsh-sweeper] scan failed: %s', state.lastError) } catch { /* ignore */ }
|
|
291
302
|
throw err
|
|
292
303
|
} finally {
|
|
304
|
+
job.finishedAt = Date.now()
|
|
293
305
|
state.running = null
|
|
294
306
|
}
|
|
295
307
|
})()
|
|
@@ -544,6 +556,8 @@ export function apply(ctx, config = {}) {
|
|
|
544
556
|
ms: out.ms,
|
|
545
557
|
reviewed: out.reviewed,
|
|
546
558
|
skipped: out.skipped,
|
|
559
|
+
hintsTotal: out.hintsTotal || 0,
|
|
560
|
+
hintsSkipped: out.hintsSkipped || 0,
|
|
547
561
|
note: out.verdict && out.verdict.note ? out.verdict.note : '',
|
|
548
562
|
auto: plan.auto.map((it) => ({ key: it.key, path: it.path, size: it.size })),
|
|
549
563
|
autoBytes: plan.auto.reduce((n, it) => n + (it.size || 0), 0),
|
|
@@ -749,6 +763,27 @@ export function apply(ctx, config = {}) {
|
|
|
749
763
|
sendJSON(res, 200, gone)
|
|
750
764
|
})
|
|
751
765
|
|
|
766
|
+
// Closing the settings page does not stop a pass; this is how a reopened
|
|
767
|
+
// page finds the one already running instead of starting a second one.
|
|
768
|
+
route(BASE + '/status', async (req, res) => {
|
|
769
|
+
const job = state.scanJob
|
|
770
|
+
const r = state.report
|
|
771
|
+
sendJSON(res, 200, {
|
|
772
|
+
scanning: !!state.running,
|
|
773
|
+
job: job ? {
|
|
774
|
+
pass: job.pass,
|
|
775
|
+
done: job.done,
|
|
776
|
+
total: job.total,
|
|
777
|
+
startedAt: job.startedAt,
|
|
778
|
+
finishedAt: job.finishedAt || 0,
|
|
779
|
+
ms: (job.finishedAt || Date.now()) - job.startedAt,
|
|
780
|
+
} : null,
|
|
781
|
+
hasReport: !!r,
|
|
782
|
+
ageMs: r ? Date.now() - state.publishedAt : null,
|
|
783
|
+
lastError: state.lastError,
|
|
784
|
+
})
|
|
785
|
+
})
|
|
786
|
+
|
|
752
787
|
route(BASE + '/health', async (req, res) => {
|
|
753
788
|
const r = state.report
|
|
754
789
|
sendJSON(res, 200, {
|
|
@@ -842,6 +877,28 @@ export function applySelfTest(ctx) {
|
|
|
842
877
|
const report = JSON.parse(scanOut.body)
|
|
843
878
|
out.scanPasses = ctx.__sweeperState ? ctx.__sweeperState.passes : null
|
|
844
879
|
out.steps.push({ step: 'scan', status: scanOut.status, items: (report.items || []).length, tiers: report.tiers, protected: report.protected, unreadable: (report.unreadable || []).length, truncated: !!report.truncated, scanMs: report.durationMs })
|
|
880
|
+
// The panel shows a pass that is already running, which it learns from
|
|
881
|
+
// /status. Check the bookkeeping: a finished pass must report done ==
|
|
882
|
+
// total and a finish time, otherwise the banner would never clear.
|
|
883
|
+
const idle = JSON.parse((await call('GET', '/plugins/dsh-sweeper/status')).body)
|
|
884
|
+
out.steps.push({
|
|
885
|
+
step: 'status-idle', scanning: !!idle.scanning, hasReport: !!idle.hasReport,
|
|
886
|
+
done: idle.job && idle.job.done, total: idle.job && idle.job.total,
|
|
887
|
+
finished: !!(idle.job && idle.job.finishedAt),
|
|
888
|
+
})
|
|
889
|
+
// Fire a refresh without waiting for it, then look for scanning:true.
|
|
890
|
+
// The pass is short enough to finish first; a miss is reported, not failed.
|
|
891
|
+
const pending = call('GET', '/plugins/dsh-sweeper/report?refresh=1')
|
|
892
|
+
let observed = false
|
|
893
|
+
let total = 0
|
|
894
|
+
for (let i = 0; i < 15 && !observed; i++) {
|
|
895
|
+
await new Promise((r) => setTimeout(r, 100))
|
|
896
|
+
const s = JSON.parse((await call('GET', '/plugins/dsh-sweeper/status')).body)
|
|
897
|
+
if (s.scanning) { observed = true; total = (s.job && s.job.total) || 0 }
|
|
898
|
+
}
|
|
899
|
+
await pending
|
|
900
|
+
out.steps.push({ step: 'status-running', observed, total })
|
|
901
|
+
|
|
845
902
|
const planOut = await call('GET', '/plugins/dsh-sweeper/deep/plan?refresh=1')
|
|
846
903
|
const plan = JSON.parse(planOut.body)
|
|
847
904
|
out.steps.push({ step: 'plan', status: planOut.status, sessions: (plan.sessions || []).length, estTokens: plan.estTokens, concurrency: plan.concurrency })
|
package/lib/review.js
CHANGED
|
@@ -147,9 +147,21 @@ export async function review(ctx, report, opts = {}) {
|
|
|
147
147
|
const llm = typeof ctx.get === 'function' ? ctx.get('llm') : null
|
|
148
148
|
if (!llm || typeof llm.prepareCall !== 'function') throw new Error('the host llm service is not available')
|
|
149
149
|
const route = resolveRoute(ctx, opts.model)
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
150
|
+
const allItems = report.items || []
|
|
151
|
+
const allHints = report.hints || []
|
|
152
|
+
const items = allItems.slice(0, MAX_ITEMS)
|
|
153
|
+
const hints = allHints.slice(0, MAX_HINTS)
|
|
154
|
+
if (!items.length && !hints.length) {
|
|
155
|
+
return {
|
|
156
|
+
model: route,
|
|
157
|
+
verdict: { delete: [], keep: [], ask: [], note: '', matched: 0, ignored: 0 },
|
|
158
|
+
reviewed: 0,
|
|
159
|
+
skipped: 0,
|
|
160
|
+
hints: 0,
|
|
161
|
+
hintsTotal: 0,
|
|
162
|
+
hintsSkipped: 0,
|
|
163
|
+
ms: 0,
|
|
164
|
+
}
|
|
153
165
|
}
|
|
154
166
|
|
|
155
167
|
const payload = items.map((it, i) => ({
|
|
@@ -162,7 +174,6 @@ export async function review(ctx, report, opts = {}) {
|
|
|
162
174
|
u: it.uses,
|
|
163
175
|
f: !!it.failed,
|
|
164
176
|
}))
|
|
165
|
-
const hints = (report.hints || []).slice(0, MAX_HINTS)
|
|
166
177
|
const extra = hints.map((h, i) => ({
|
|
167
178
|
id: 'x' + (i + 1),
|
|
168
179
|
p: h.path,
|
|
@@ -172,12 +183,12 @@ export async function review(ctx, report, opts = {}) {
|
|
|
172
183
|
const user = [
|
|
173
184
|
'字段含义:id=编号(原样复制),p=路径,t=档位(safe=无脑删 / unsure=需确认),k=来源,b=字节数,d=闲置天数,u=产生后被工具使用次数,f=产生它那次调用是否失败。',
|
|
174
185
|
'',
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
186
|
+
...(items.length
|
|
187
|
+
? ['A 段 · 候选清单(这些已经被规则筛过一轮):', JSON.stringify(payload), '']
|
|
188
|
+
: ['A 段 · 这次没有候选清单,只回答 B 段。', '']),
|
|
189
|
+
...(hints.length
|
|
190
|
+
? ['B 段 · 清单外观察到的文件(在已知临时目录里、但任何会话日志都没提到过;只根据路径和闲置天数判断):', JSON.stringify(extra), '']
|
|
191
|
+
: ['B 段 · 这次没有清单外文件。', '']),
|
|
181
192
|
'请按格式逐行输出判断。',
|
|
182
193
|
].join('\n')
|
|
183
194
|
|
|
@@ -223,9 +234,11 @@ export async function review(ctx, report, opts = {}) {
|
|
|
223
234
|
verdict: translated.verdict,
|
|
224
235
|
proposals: translated.proposals,
|
|
225
236
|
hints: hints.length,
|
|
237
|
+
hintsTotal: allHints.length,
|
|
238
|
+
hintsSkipped: allHints.length - hints.length,
|
|
226
239
|
unknownIds: translated.unknown,
|
|
227
240
|
reviewed: items.length,
|
|
228
|
-
skipped:
|
|
241
|
+
skipped: allItems.length - items.length,
|
|
229
242
|
ms: Date.now() - started,
|
|
230
243
|
answerChars: text.length,
|
|
231
244
|
raw: String(text || '').slice(0, 6000),
|
package/lib/scan.js
CHANGED
|
@@ -250,6 +250,15 @@ export async function scan(ctx, opts = {}) {
|
|
|
250
250
|
const unreadable = []
|
|
251
251
|
const stats = { sessions: 0, events: 0, toolCalls: 0, errors: 0, openJobs: 0 }
|
|
252
252
|
|
|
253
|
+
const onProgress = typeof opts.onProgress === 'function' ? opts.onProgress : null
|
|
254
|
+
const total = list.length
|
|
255
|
+
// Reporting a pass is best effort: a throwing listener must never abort a
|
|
256
|
+
// scan, and a slow one must never be awaited.
|
|
257
|
+
const tick = (pass, done) => {
|
|
258
|
+
if (!onProgress) return
|
|
259
|
+
try { onProgress({ pass, done, total }) } catch { /* progress is cosmetic */ }
|
|
260
|
+
}
|
|
261
|
+
|
|
253
262
|
const titleOf = new Map()
|
|
254
263
|
const addArtifact = (raw, producer) => {
|
|
255
264
|
const key = normKey(raw)
|
|
@@ -273,7 +282,10 @@ export async function scan(ctx, opts = {}) {
|
|
|
273
282
|
}
|
|
274
283
|
|
|
275
284
|
// ── pass 1: producers, spill paths, job bookkeeping ─────────────────────
|
|
285
|
+
let passOne = 0
|
|
276
286
|
for (const snap of list) {
|
|
287
|
+
tick(1, passOne++)
|
|
288
|
+
|
|
277
289
|
const id = idOf(snap)
|
|
278
290
|
if (!id) continue
|
|
279
291
|
let handle
|
|
@@ -343,7 +355,10 @@ export async function scan(ctx, opts = {}) {
|
|
|
343
355
|
}
|
|
344
356
|
|
|
345
357
|
// ── pass 2: references (any later text that names a known path) ─────────
|
|
358
|
+
let passTwo = 0
|
|
346
359
|
for (const snap of list) {
|
|
360
|
+
tick(2, passTwo++)
|
|
361
|
+
|
|
347
362
|
const id = idOf(snap)
|
|
348
363
|
if (!id || unreadable.includes(String(id))) continue
|
|
349
364
|
let handle
|