dsh-sweeper 0.0.0-stage → 1.4.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/LICENSE +21 -0
- package/README.md +358 -2
- package/cordis.patch.yml +3 -0
- package/icon.svg +5 -0
- package/lib/agent.js +190 -0
- package/lib/client.js +1639 -0
- package/lib/deep-agent.js +131 -0
- package/lib/deep.js +695 -0
- package/lib/fs-tools.js +198 -0
- package/lib/index.js +994 -0
- package/lib/paths.js +83 -0
- package/lib/review.js +336 -0
- package/lib/scan.js +520 -0
- package/lib/trash.js +345 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +72 -4
package/lib/client.js
ADDED
|
@@ -0,0 +1,1639 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-sweeper',
|
|
3
|
+
factory(require) {
|
|
4
|
+
const React = require('react')
|
|
5
|
+
const h = React.createElement
|
|
6
|
+
const { useState, useEffect, useMemo, useRef, useCallback } = React
|
|
7
|
+
|
|
8
|
+
const API = '/plugins/dsh-sweeper'
|
|
9
|
+
const STYLE_ID = 'dsh-sweeper-style'
|
|
10
|
+
|
|
11
|
+
// ── theme ───────────────────────────────────────────────────────────────
|
|
12
|
+
// Everything is expressed with host tokens so light/dark both work; the
|
|
13
|
+
// rgba fallbacks only matter if a token disappears.
|
|
14
|
+
const T = {
|
|
15
|
+
text: 'var(--dsw-alias-label-primary, #1f2328)',
|
|
16
|
+
dim: 'var(--dsw-alias-label-secondary, #5c6672)',
|
|
17
|
+
faint: 'var(--dsw-alias-label-tertiary, #8a929e)',
|
|
18
|
+
border: 'var(--dsw-alias-border-l2, rgba(128,128,128,.22))',
|
|
19
|
+
borderStrong: 'var(--dsw-alias-border-l3, rgba(128,128,128,.4))',
|
|
20
|
+
layer: 'var(--dsw-alias-bg-layer-1, rgba(128,128,128,.06))',
|
|
21
|
+
layer2: 'var(--dsw-alias-bg-layer-2, rgba(128,128,128,.1))',
|
|
22
|
+
hover: 'var(--dsw-alias-interactive-bg-hover, rgba(128,128,128,.12))',
|
|
23
|
+
overlay: 'var(--dsw-alias-bg-overlay, #1c1d20)',
|
|
24
|
+
accent: 'var(--dsw-alias-button-primary-fill, #3b6ef5)',
|
|
25
|
+
onAccent: 'var(--dsw-alias-label-primary-foreground, #fff)',
|
|
26
|
+
success: 'var(--dsw-alias-state-success-primary, #2f9e5f)',
|
|
27
|
+
warn: 'var(--dsw-alias-state-warning-secondary, #b07800)',
|
|
28
|
+
danger: 'var(--dsw-alias-state-error-primary, #d33b3b)',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const CSS = `
|
|
32
|
+
.sw-root{--sw-border:${T.border};--sw-hover:${T.hover};color:${T.text};font-size:13px;line-height:1.55}
|
|
33
|
+
.sw-root *{box-sizing:border-box}
|
|
34
|
+
.sw-root button{font-family:inherit}
|
|
35
|
+
.sw-num{font-variant-numeric:tabular-nums}
|
|
36
|
+
.sw-btn{display:inline-flex;align-items:center;gap:6px;height:30px;padding:0 12px;border-radius:8px;
|
|
37
|
+
border:1px solid var(--sw-border);background:transparent;color:${T.text};font-size:12px;font-weight:500;
|
|
38
|
+
cursor:pointer;white-space:nowrap;transition:background .14s,border-color .14s,opacity .14s,transform .06s}
|
|
39
|
+
.sw-btn:hover:not(:disabled){background:${T.hover}}
|
|
40
|
+
.sw-btn:active:not(:disabled){transform:translateY(.5px)}
|
|
41
|
+
.sw-btn:disabled{opacity:.45;cursor:not-allowed}
|
|
42
|
+
.sw-btn:focus-visible{outline:2px solid ${T.accent};outline-offset:2px}
|
|
43
|
+
.sw-btn[data-kind=primary]{background:${T.accent};border-color:transparent;color:${T.onAccent}}
|
|
44
|
+
.sw-btn[data-kind=primary]:hover:not(:disabled){filter:brightness(1.06)}
|
|
45
|
+
.sw-btn[data-kind=danger]{color:${T.danger};border-color:rgba(211,59,59,.45)}
|
|
46
|
+
.sw-btn[data-kind=danger]:hover:not(:disabled){background:rgba(211,59,59,.1)}
|
|
47
|
+
.sw-btn[data-kind=quiet]{border-color:transparent;color:${T.dim}}
|
|
48
|
+
.sw-btn[data-kind=quiet]:hover:not(:disabled){color:${T.text};background:${T.hover}}
|
|
49
|
+
.sw-iconbtn{width:30px;height:30px;padding:0;justify-content:center}
|
|
50
|
+
.sw-row{display:grid;grid-template-columns:18px minmax(0,1fr) 88px 74px;gap:12px;align-items:center;
|
|
51
|
+
padding:9px 14px;border-top:1px solid var(--sw-border);cursor:pointer;transition:background .12s}
|
|
52
|
+
.sw-row:hover{background:var(--sw-hover)}
|
|
53
|
+
.sw-row[data-on="1"]{background:rgba(59,110,245,.08)}
|
|
54
|
+
.sw-row:first-child{border-top:0}
|
|
55
|
+
.sw-mono{font-family:Consolas,ui-monospace,SFMono-Regular,Menlo,monospace}
|
|
56
|
+
.sw-chip{display:inline-flex;align-items:center;gap:5px;height:20px;padding:0 7px;border-radius:6px;
|
|
57
|
+
background:${T.layer};color:${T.dim};font-size:11px;white-space:nowrap}
|
|
58
|
+
.sw-dot{width:6px;height:6px;border-radius:50%;flex:none}
|
|
59
|
+
.sw-card{border:1px solid var(--sw-border);border-radius:12px;background:${T.layer}}
|
|
60
|
+
.sw-progress{height:3px;background:${T.layer};overflow:hidden}
|
|
61
|
+
.sw-progress-fill{height:100%;background:${T.accent};transition:width .35s ease}
|
|
62
|
+
.sw-tabbar{display:inline-flex;gap:2px;padding:3px;border-radius:10px;background:${T.layer};border:1px solid var(--sw-border)}
|
|
63
|
+
.sw-tab{height:28px;padding:0 12px;border:0;border-radius:8px;background:transparent;color:${T.faint};
|
|
64
|
+
font-size:12px;font-weight:500;cursor:pointer;transition:background .14s,color .14s;white-space:nowrap}
|
|
65
|
+
.sw-tab:hover{color:${T.text}}
|
|
66
|
+
.sw-tab[data-on="1"]{background:${T.layer2};color:${T.text};box-shadow:0 1px 2px rgba(0,0,0,.12)}
|
|
67
|
+
.sw-tab:focus-visible{outline:2px solid ${T.accent};outline-offset:1px}
|
|
68
|
+
.sw-skel{background:linear-gradient(90deg,${T.layer} 25%,${T.layer2} 37%,${T.layer} 63%);
|
|
69
|
+
background-size:400% 100%;animation:sw-shimmer 1.4s ease infinite;border-radius:6px}
|
|
70
|
+
.sw-spin{width:13px;height:13px;border:2px solid ${T.borderStrong};border-top-color:${T.accent};
|
|
71
|
+
border-radius:50%;animation:sw-spin .7s linear infinite;flex:none}
|
|
72
|
+
.sw-toast{animation:sw-toast-in .18s ease-out}
|
|
73
|
+
.sw-modal-in{animation:sw-modal-in .16s ease-out}
|
|
74
|
+
.sw-scroll::-webkit-scrollbar{width:10px;height:10px}
|
|
75
|
+
.sw-scroll::-webkit-scrollbar-thumb{background:${T.borderStrong};border-radius:6px;border:3px solid transparent;background-clip:content-box}
|
|
76
|
+
@keyframes sw-shimmer{0%{background-position:100% 0}100%{background-position:0 0}}
|
|
77
|
+
@keyframes sw-spin{to{transform:rotate(360deg)}}
|
|
78
|
+
@keyframes sw-toast-in{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}
|
|
79
|
+
@keyframes sw-modal-in{from{opacity:0;transform:translateY(8px) scale(.99)}to{opacity:1;transform:none}}
|
|
80
|
+
@media (prefers-reduced-motion:reduce){.sw-root *{animation:none!important;transition:none!important}}
|
|
81
|
+
@media (max-width:720px){.sw-row{grid-template-columns:18px minmax(0,1fr) 74px}.sw-col-age{display:none}}
|
|
82
|
+
`
|
|
83
|
+
|
|
84
|
+
function useStyles() {
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (document.getElementById(STYLE_ID)) return
|
|
87
|
+
const el = document.createElement('style')
|
|
88
|
+
el.id = STYLE_ID
|
|
89
|
+
el.textContent = CSS
|
|
90
|
+
document.head.appendChild(el)
|
|
91
|
+
}, [])
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// ── formatting ──────────────────────────────────────────────────────────
|
|
95
|
+
const fmtBytes = (n) => {
|
|
96
|
+
if (!n || n < 0) return '0 B'
|
|
97
|
+
if (n < 1024) return n + ' B'
|
|
98
|
+
if (n < 1048576) return (n / 1024).toFixed(n < 10240 ? 1 : 0) + ' KB'
|
|
99
|
+
if (n < 1073741824) return (n / 1048576).toFixed(1) + ' MB'
|
|
100
|
+
return (n / 1073741824).toFixed(2) + ' GB'
|
|
101
|
+
}
|
|
102
|
+
const fmtNum = (n) => (typeof n === 'number' ? n.toLocaleString('zh-CN') : String(n == null ? '—' : n))
|
|
103
|
+
const pad = (x) => (x < 10 ? '0' + x : '' + x)
|
|
104
|
+
const fmtDateTime = (ts) => {
|
|
105
|
+
if (!ts) return '—'
|
|
106
|
+
const d = new Date(ts)
|
|
107
|
+
return pad(d.getMonth() + 1) + '-' + pad(d.getDate()) + ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes())
|
|
108
|
+
}
|
|
109
|
+
const fmtDuration = (ms) => (ms == null ? '—' : ms < 1000 ? Math.round(ms) + ' ms' : (ms / 1000).toFixed(1) + ' s')
|
|
110
|
+
// Server messages are written for the API; the page says them in Chinese.
|
|
111
|
+
// Anything unrecognised falls through unchanged, so a new error is never
|
|
112
|
+
// swallowed by this table.
|
|
113
|
+
// Server errors arrive as whole English sentences. Each entry here is a
|
|
114
|
+
// "this message means X" test; the card shows the Chinese sentence only, so
|
|
115
|
+
// no half-translated mixture can reach the user.
|
|
116
|
+
const REASONS = [
|
|
117
|
+
[/report is stale/i, '报告在后台刷新过,请重新扫描再试'],
|
|
118
|
+
[/no report yet/i, '还没有扫描结果,先点右上角「重新扫描」'],
|
|
119
|
+
[/already running/i, '上一次还在跑,等它结束或先点「停止」'],
|
|
120
|
+
[/no deep pass is running/i, '当前没有在跑的深度分析'],
|
|
121
|
+
[/not the current one/i, '这一轮已经被新的分析取代了'],
|
|
122
|
+
[/confirm it explicitly/i, '需要先勾选同意,才会把摘要发给模型'],
|
|
123
|
+
[/no keys selected/i, '没有选中任何文件'],
|
|
124
|
+
[/too many items in one batch/i, '一次最多移入 5000 个文件,请分几批处理'],
|
|
125
|
+
[/confirmation required/i, '这个操作需要二次确认'],
|
|
126
|
+
[/acknowledge/i, '选中的文件里有「需要确认」档,需要单独勾选后才能清理'],
|
|
127
|
+
[/batch is busy/i, '这个批次正在被恢复或删除,稍等一下'],
|
|
128
|
+
[/bad batch id/i, '批次号不合法'],
|
|
129
|
+
[/already gone/i, '这一批已经被删掉了(可能是另一个标签页刚删的)'],
|
|
130
|
+
[/still open by another program/i, '批次里有文件正被别的程序占用,关掉占用它的程序再试'],
|
|
131
|
+
[/no files were moved/i, '这次没有移动任何文件'],
|
|
132
|
+
[/a file already exists there/i, '原位置已经有同名文件,没有覆盖'],
|
|
133
|
+
[/missing from trash/i, '回收站里找不到这个文件了'],
|
|
134
|
+
[/path contains \.\./i, '路径里带 ..,拒绝处理'],
|
|
135
|
+
[/not an absolute path/i, '不是绝对路径,拒绝处理'],
|
|
136
|
+
[/model call cancelled/i, '模型调用被取消了'],
|
|
137
|
+
[/model call timed out/i, '模型调用超时'],
|
|
138
|
+
[/unreadable session log/i, '这段对话的日志读不出来'],
|
|
139
|
+
[/scan failed/i, '扫描时读会话日志失败,可能某个日志正在写入;稍后点「重新扫描」'],
|
|
140
|
+
[/quarantine index/i, '回收站索引读不出来,可能有一次清理被中断;文件仍按原样留在盘上'],
|
|
141
|
+
[/model provider is not reachable/i, '连不上模型服务,检查 DSH 里的模型配置是否可用'],
|
|
142
|
+
[/provider returned (\d+)/i, (m) => '模型服务返回 ' + m[1] + ',稍后再试'],
|
|
143
|
+
[/model review failed/i, '模型复核失败,本次没有移动任何文件'],
|
|
144
|
+
[/the report changed while/i, '模型读的时候报告变了,这次没有移动任何文件;重新扫描后再试'],
|
|
145
|
+
[/^gone$/i, '文件已经不在那个位置了(可能被别的标签页清理过,或你已经还原了)'],
|
|
146
|
+
[/not a regular file/i, '不是普通文件(是目录或链接),插件不动它'],
|
|
147
|
+
[/path crosses a link/i, '路径穿过了链接或目录联接,插件不动它'],
|
|
148
|
+
[/changed since the scan/i, '扫描之后这个文件被改过,插件不动它'],
|
|
149
|
+
[/changed size since the scan/i, '扫描之后文件大小变了,插件不动它'],
|
|
150
|
+
[/modified since the scan/i, '扫描之后这个文件被改过,插件不动它'],
|
|
151
|
+
[/copy was incomplete/i, '复制不完整,已经把文件放回原位'],
|
|
152
|
+
[/^the file is gone$/i, '文件已经不在那个位置了'],
|
|
153
|
+
[/the file changed after the deep plan/i, '深度分析之后文件变过,插件不动它'],
|
|
154
|
+
[/not one of the files the scan observed/i, '这个文件不在这次扫描的记录里,重新扫描后再试'],
|
|
155
|
+
[/not one of the files this conversation produced/i, '这个文件不在该对话记录的产物里'],
|
|
156
|
+
[/outside the workspace this conversation wrote to/i, '这个文件不在该对话的工作目录里,插件不动它'],
|
|
157
|
+
[/^tracked by git$/i, '被 git 跟踪,插件不动它'],
|
|
158
|
+
[/could not confirm whether it is tracked/i, '查不到 git 跟踪状态,按保护处理'],
|
|
159
|
+
[/no idle conversation still owns files/i, '没有闲置对话还留着临时产物,不用花 token 去问模型'],
|
|
160
|
+
[/session service is not available/i, '读不到正在运行的对话列表,分不清哪段是闲置的,这次先不动'],
|
|
161
|
+
[/session service failed while listing live conversations/i, '列正在运行的对话时出错了,分不清哪段是闲置的,这次先不动'],
|
|
162
|
+
[/the deep pass has no results yet/i, '深度分析还没有结果'],
|
|
163
|
+
[/^nothing selected$/i, '没有选中任何文件'],
|
|
164
|
+
[/no model route/i, '没有可用的模型:先在 DSH 里设好默认模型(或在插件那一行配置 provider / model)'],
|
|
165
|
+
[/model returned an empty answer/i, '模型返回了空内容,这次没有移动任何文件'],
|
|
166
|
+
[/model returned no usable line/i, '模型的回答里没有可用的判定行,这次没有移动任何文件'],
|
|
167
|
+
[/^model answer has no decisions/i, '模型的回答里没有判定行'],
|
|
168
|
+
[/^nothing could be moved/i, '一个都没能移动'],
|
|
169
|
+
[/sessionPersistence service is not available/i, '读不到会话服务(sessionPersistence),DSH 可能刚重启'],
|
|
170
|
+
[/host llm service is not available/i, '宿主没有提供模型服务(llm),检查 DSH 的模型配置'],
|
|
171
|
+
[/this list is out of date/i, '这份列表在别处刷新过了,正在重新扫描'],
|
|
172
|
+
[/^bad batch id$/i, '这个批次号不对,页面可能过期了,点「回收站」刷新一下'],
|
|
173
|
+
[/bad manifest entry/i, '回收站清单里这一条坏了,跳过'],
|
|
174
|
+
[/^body too large$/i, '请求体太大,被拒绝'],
|
|
175
|
+
[/^bad JSON$/i, '请求格式不对'],
|
|
176
|
+
[/^POST required$/i, '这个接口只接受 POST'],
|
|
177
|
+
[/missing x-dsh-sweeper header/i, '请求缺少插件标记,被拒绝'],
|
|
178
|
+
[/^request (aborted|closed before the body arrived)$/i, '请求被中断了,这次没有做任何改动'],
|
|
179
|
+
]
|
|
180
|
+
const humanReason = (text) => {
|
|
181
|
+
const raw = String(text == null ? '' : text).trim()
|
|
182
|
+
// The host wraps some failures in its own prefix ("model call failed: …").
|
|
183
|
+
// Strip it, translate what is inside, then put a Chinese wrapper back.
|
|
184
|
+
const WRAP = /^(model call failed|model review failed|deep pass failed|scan failed)\s*:\s*/i
|
|
185
|
+
const wrap = (raw.match(WRAP) || [])[1]
|
|
186
|
+
const body = (wrap ? raw.replace(WRAP, '') : raw).trim()
|
|
187
|
+
const head = !wrap ? ''
|
|
188
|
+
: /review/i.test(wrap) ? '模型复核失败:'
|
|
189
|
+
: /scan/i.test(wrap) ? '扫描失败:'
|
|
190
|
+
: '模型调用失败:'
|
|
191
|
+
const hit = REASONS.find(([re]) => re.test(body))
|
|
192
|
+
if (hit) return head + (typeof hit[1] === 'function' ? hit[1](body.match(hit[0])) : hit[1])
|
|
193
|
+
if (/^HTTP \d+$/.test(body)) return head + '服务返回 ' + body.slice(5) + ',请重试'
|
|
194
|
+
if (/failed to fetch|networkerror|load failed/i.test(body)) return head + '连不上插件服务,DSH 可能刚重启'
|
|
195
|
+
return raw
|
|
196
|
+
}
|
|
197
|
+
const humanError = (err) => humanReason((err && err.message) || err)
|
|
198
|
+
|
|
199
|
+
// Older payloads and fixtures may omit generatedAt; fall back to the age
|
|
200
|
+
// the server already computed, so the chip never shows a bare dash.
|
|
201
|
+
const agoText = (ms) => {
|
|
202
|
+
const s = Math.max(0, Math.round((ms || 0) / 1000))
|
|
203
|
+
if (s < 60) return s + ' 秒前'
|
|
204
|
+
const m = Math.round(s / 60)
|
|
205
|
+
if (m < 60) return m + ' 分钟前'
|
|
206
|
+
const hh = Math.round(m / 60)
|
|
207
|
+
if (hh < 24) return hh + ' 小时前'
|
|
208
|
+
return Math.round(hh / 24) + ' 天前'
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// A batch remembers what moved it; the page names that in Chinese.
|
|
212
|
+
const NOTE_LABELS = {
|
|
213
|
+
scan: '扫描清理',
|
|
214
|
+
'model review': '模型复核',
|
|
215
|
+
'model proposal': '模型建议',
|
|
216
|
+
'deep review': '深度分析',
|
|
217
|
+
'manual selection': '手动清理',
|
|
218
|
+
}
|
|
219
|
+
const noteLabel = (n) => NOTE_LABELS[String(n)] || String(n)
|
|
220
|
+
|
|
221
|
+
function Timer({ start, running, prefix }) {
|
|
222
|
+
const [now, setNow] = useState(Date.now())
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
if (!running) return
|
|
225
|
+
const id = setInterval(() => setNow(Date.now()), 500)
|
|
226
|
+
return () => clearInterval(id)
|
|
227
|
+
}, [running])
|
|
228
|
+
return h('span', { className: 'sw-num' }, (prefix || '') + fmtDuration(running ? Math.max(0, now - start) : 0))
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const splitPath = (p) => {
|
|
232
|
+
const s = String(p || '')
|
|
233
|
+
const i = Math.max(s.lastIndexOf('\\'), s.lastIndexOf('/'))
|
|
234
|
+
return i < 0 ? { dir: '', name: s } : { dir: s.slice(0, i + 1), name: s.slice(i + 1) }
|
|
235
|
+
}
|
|
236
|
+
const extOf = (p) => {
|
|
237
|
+
const { name } = splitPath(p)
|
|
238
|
+
const i = name.lastIndexOf('.')
|
|
239
|
+
return i > 0 ? name.slice(i + 1).toLowerCase().slice(0, 5) : ''
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const fail = (r, data) => {
|
|
243
|
+
const err = new Error((data && data.error) || ('HTTP ' + r.status))
|
|
244
|
+
err.status = r.status
|
|
245
|
+
err.data = data || {}
|
|
246
|
+
return err
|
|
247
|
+
}
|
|
248
|
+
const post = (path, body) => fetch(API + path, {
|
|
249
|
+
method: 'POST',
|
|
250
|
+
headers: { 'content-type': 'application/json', 'x-dsh-sweeper': '1' },
|
|
251
|
+
body: JSON.stringify(body || {}),
|
|
252
|
+
}).then(async (r) => {
|
|
253
|
+
const data = await r.json().catch(() => ({}))
|
|
254
|
+
if (!r.ok) throw fail(r, data)
|
|
255
|
+
return data
|
|
256
|
+
})
|
|
257
|
+
const getJSON = (path) => fetch(API + path, { cache: 'no-store' })
|
|
258
|
+
.then(async (r) => {
|
|
259
|
+
const data = await r.json().catch(() => ({}))
|
|
260
|
+
if (!r.ok) throw fail(r, data)
|
|
261
|
+
return data
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
// ── primitives ──────────────────────────────────────────────────────────
|
|
265
|
+
function Btn({ kind, label, icon, onClick, disabled, title, className }) {
|
|
266
|
+
return h('button', {
|
|
267
|
+
type: 'button',
|
|
268
|
+
className: 'sw-btn' + (className ? ' ' + className : ''),
|
|
269
|
+
'data-kind': kind || 'ghost',
|
|
270
|
+
onClick: disabled ? undefined : onClick,
|
|
271
|
+
disabled: !!disabled,
|
|
272
|
+
title: title || undefined,
|
|
273
|
+
}, icon || null, label || null)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function Icon({ name, size }) {
|
|
277
|
+
const s = size || 16
|
|
278
|
+
const common = { width: s, height: s, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': true }
|
|
279
|
+
const paths = {
|
|
280
|
+
broom: [h('path', { key: 'a', d: 'M14.2 3.2l6.6 6.6-2.6 2.6-6.6-6.6 2.6-2.6z' }), h('path', { key: 'b', d: 'M11.2 13.4l-6.4 6.4a1.5 1.5 0 002.1 2.1l6.4-6.4' }), h('path', { key: 'c', d: 'M9.4 17.2l-1.5 1.5M12.4 20.2l-1.5 1.5' })],
|
|
281
|
+
refresh: [h('path', { key: 'a', d: 'M20 11a8 8 0 10-2.3 5.7' }), h('path', { key: 'b', d: 'M20 5v6h-6' })],
|
|
282
|
+
download: [h('path', { key: 'a', d: 'M12 3v12' }), h('path', { key: 'b', d: 'M7 11l5 5 5-5' }), h('path', { key: 'c', d: 'M4 20h16' })],
|
|
283
|
+
trash: [h('path', { key: 'a', d: 'M4 7h16' }), h('path', { key: 'b', d: 'M9 7V4h6v3' }), h('path', { key: 'c', d: 'M6 7l1 13h10l1-13' })],
|
|
284
|
+
restore: [h('path', { key: 'a', d: 'M4 11a8 8 0 1 1 2.3 5.7' }), h('path', { key: 'b', d: 'M4 5v6h6' })],
|
|
285
|
+
spark: [h('path', { key: 'a', d: 'M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8L12 3z' }), h('path', { key: 'b', d: 'M18.5 15.5l.8 2.2 2.2.8-2.2.8-.8 2.2-.8-2.2-2.2-.8 2.2-.8.8-2.2z' })],
|
|
286
|
+
check: [h('path', { key: 'a', d: 'M4.5 12.5l5 5 10-11' })],
|
|
287
|
+
close: [h('path', { key: 'a', d: 'M6 6l12 12M18 6L6 18' })],
|
|
288
|
+
info: [h('circle', { key: 'a', cx: 12, cy: 12, r: 9 }), h('path', { key: 'b', d: 'M12 11v6M12 7.6v.4' })],
|
|
289
|
+
alert: [h('path', { key: 'a', d: 'M12 3l9.5 17H2.5L12 3z' }), h('path', { key: 'b', d: 'M12 9v5M12 17.2v.3' })],
|
|
290
|
+
box: [h('path', { key: 'a', d: 'M3 8l9-5 9 5-9 5-9-5z' }), h('path', { key: 'b', d: 'M3 8v9l9 5 9-5V8' })],
|
|
291
|
+
shield: [h('path', { key: 'a', d: 'M12 3l8 3v6c0 5-3.6 8.2-8 9-4.4-.8-8-4-8-9V6l8-3z' }), h('path', { key: 'b', d: 'M9 12l2.2 2.2L15.5 10' })],
|
|
292
|
+
chevron: [h('path', { key: 'a', d: 'M9 6l6 6-6 6' })],
|
|
293
|
+
}
|
|
294
|
+
return h('svg', common, paths[name] || null)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function Check({ checked, onChange, disabled, label }) {
|
|
298
|
+
return h('input', {
|
|
299
|
+
type: 'checkbox',
|
|
300
|
+
checked: !!checked,
|
|
301
|
+
disabled: !!disabled,
|
|
302
|
+
'aria-label': label || '选择',
|
|
303
|
+
onChange: (e) => onChange(e.target.checked),
|
|
304
|
+
style: { width: 15, height: 15, margin: 0, cursor: disabled ? 'not-allowed' : 'pointer', accentColor: T.accent },
|
|
305
|
+
})
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function Chip({ children, tone, dot }) {
|
|
309
|
+
const color = tone === 'success' ? T.success : tone === 'warn' ? T.warn : tone === 'danger' ? T.danger : null
|
|
310
|
+
return h('span', {
|
|
311
|
+
className: 'sw-chip',
|
|
312
|
+
style: color ? { color, background: 'transparent', border: '1px solid ' + (tone === 'danger' ? 'rgba(211,59,59,.4)' : tone === 'warn' ? 'rgba(176,120,0,.4)' : 'rgba(47,158,95,.4)') } : undefined,
|
|
313
|
+
}, dot ? h('span', { className: 'sw-dot', style: { background: color || T.faint } }) : null, children)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function Stat({ label, value, sub, tone }) {
|
|
317
|
+
const accent = tone === 'success' ? T.success : tone === 'warn' ? T.warn : null
|
|
318
|
+
return h('div', {
|
|
319
|
+
className: 'sw-card',
|
|
320
|
+
style: { padding: '12px 14px', display: 'flex', flexDirection: 'column', gap: 2, minWidth: 0 },
|
|
321
|
+
},
|
|
322
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, fontSize: 11, color: T.faint } },
|
|
323
|
+
accent ? h('span', { className: 'sw-dot', style: { background: accent } }) : null, label),
|
|
324
|
+
h('div', { className: 'sw-num', style: { fontSize: 20, fontWeight: 600, letterSpacing: '-.01em', color: accent || T.text } }, value),
|
|
325
|
+
h('div', { style: { fontSize: 11, color: T.faint, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, sub || ''),
|
|
326
|
+
)
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function Empty({ icon, title, hint }) {
|
|
330
|
+
return h('div', {
|
|
331
|
+
style: {
|
|
332
|
+
display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 6, padding: '34px 16px',
|
|
333
|
+
border: '1px dashed ' + T.border, borderRadius: 12, color: T.faint, textAlign: 'center',
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
h('div', { style: { width: 38, height: 38, borderRadius: 12, background: T.layer, display: 'grid', placeItems: 'center', marginBottom: 2 } }, h(Icon, { name: icon || 'box', size: 18 })),
|
|
337
|
+
h('div', { style: { fontSize: 13, fontWeight: 500, color: T.dim } }, title),
|
|
338
|
+
hint ? h('div', { style: { fontSize: 12, maxWidth: 420 } }, hint) : null,
|
|
339
|
+
)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function Modal({ title, description, children, confirmLabel, kind, busy, onCancel, onConfirm }) {
|
|
343
|
+
useEffect(() => {
|
|
344
|
+
const onKey = (e) => { if (e.key === 'Escape' && !busy) onCancel() }
|
|
345
|
+
document.addEventListener('keydown', onKey)
|
|
346
|
+
return () => document.removeEventListener('keydown', onKey)
|
|
347
|
+
}, [busy, onCancel])
|
|
348
|
+
return h('div', {
|
|
349
|
+
role: 'presentation',
|
|
350
|
+
onClick: (e) => { if (e.target === e.currentTarget && !busy) onCancel() },
|
|
351
|
+
style: {
|
|
352
|
+
position: 'fixed', inset: 0, zIndex: 3000, padding: 24, display: 'flex', alignItems: 'center', justifyContent: 'center',
|
|
353
|
+
background: 'rgba(8,9,11,.5)', backdropFilter: 'blur(3px)',
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
h('div', {
|
|
357
|
+
role: 'dialog', 'aria-modal': 'true', 'aria-label': title, className: 'sw-modal-in',
|
|
358
|
+
style: {
|
|
359
|
+
width: 460, maxWidth: '100%', maxHeight: '86vh', overflow: 'auto', borderRadius: 14, padding: '20px 20px 16px',
|
|
360
|
+
background: T.overlay, color: T.text, border: '1px solid ' + T.borderStrong, boxShadow: '0 24px 64px rgba(0,0,0,.42)',
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
h('div', { style: { display: 'flex', alignItems: 'flex-start', gap: 10, marginBottom: 10 } },
|
|
364
|
+
h('div', {
|
|
365
|
+
style: {
|
|
366
|
+
width: 32, height: 32, flex: 'none', borderRadius: 10, display: 'grid', placeItems: 'center',
|
|
367
|
+
background: kind === 'danger' ? 'rgba(211,59,59,.12)' : 'rgba(59,110,245,.12)',
|
|
368
|
+
color: kind === 'danger' ? T.danger : T.accent,
|
|
369
|
+
},
|
|
370
|
+
}, h(Icon, { name: kind === 'danger' ? 'alert' : 'trash', size: 16 })),
|
|
371
|
+
h('div', { style: { minWidth: 0 } },
|
|
372
|
+
h('div', { style: { fontSize: 15, fontWeight: 600 } }, title),
|
|
373
|
+
description ? h('div', { style: { fontSize: 12, color: T.faint, marginTop: 2 } }, description) : null),
|
|
374
|
+
),
|
|
375
|
+
h('div', { style: { fontSize: 12.5, color: T.dim, lineHeight: 1.75 } }, children),
|
|
376
|
+
h('div', { style: { display: 'flex', justifyContent: 'flex-end', gap: 8, marginTop: 18 } },
|
|
377
|
+
h(Btn, { label: '取消', kind: 'quiet', onClick: onCancel, disabled: busy }),
|
|
378
|
+
h(Btn, { label: busy ? '处理中…' : confirmLabel, kind: kind === 'danger' ? 'danger' : 'primary', onClick: onConfirm, disabled: busy }),
|
|
379
|
+
),
|
|
380
|
+
),
|
|
381
|
+
)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function Toast({ text, tone }) {
|
|
385
|
+
return h('div', {
|
|
386
|
+
className: 'sw-toast',
|
|
387
|
+
role: 'status',
|
|
388
|
+
style: {
|
|
389
|
+
position: 'fixed', right: 24, bottom: 24, zIndex: 3100, maxWidth: 440, padding: '10px 14px',
|
|
390
|
+
borderRadius: 10, fontSize: 12.5, lineHeight: 1.6,
|
|
391
|
+
background: T.overlay, color: T.text, border: '1px solid ' + T.borderStrong,
|
|
392
|
+
borderLeft: '3px solid ' + (tone === 'danger' ? T.danger : tone === 'warn' ? T.warn : T.success),
|
|
393
|
+
boxShadow: '0 12px 32px rgba(0,0,0,.32)',
|
|
394
|
+
},
|
|
395
|
+
}, text)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function SkeletonRows({ n }) {
|
|
399
|
+
return h('div', { style: { padding: '4px 0' } },
|
|
400
|
+
Array.from({ length: n || 5 }).map((_, i) => h('div', {
|
|
401
|
+
key: i,
|
|
402
|
+
style: { display: 'flex', alignItems: 'center', gap: 12, padding: '11px 14px' },
|
|
403
|
+
},
|
|
404
|
+
h('div', { className: 'sw-skel', style: { width: 15, height: 15, borderRadius: 4 } }),
|
|
405
|
+
h('div', { style: { flex: 1, minWidth: 0 } },
|
|
406
|
+
h('div', { className: 'sw-skel', style: { height: 10, width: (46 + (i * 13) % 34) + '%' } }),
|
|
407
|
+
h('div', { className: 'sw-skel', style: { height: 8, width: (24 + (i * 7) % 20) + '%', marginTop: 6 } })),
|
|
408
|
+
h('div', { className: 'sw-skel', style: { width: 42, height: 10 } }),
|
|
409
|
+
)),
|
|
410
|
+
)
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// ── report rows ─────────────────────────────────────────────────────────
|
|
414
|
+
function FileRow({ item, checked, onToggle }) {
|
|
415
|
+
const { dir, name } = splitPath(item.path)
|
|
416
|
+
const ext = extOf(item.path)
|
|
417
|
+
return h('div', {
|
|
418
|
+
className: 'sw-row',
|
|
419
|
+
'data-on': checked ? '1' : '0',
|
|
420
|
+
onClick: () => onToggle(!checked),
|
|
421
|
+
role: 'checkbox',
|
|
422
|
+
'aria-checked': !!checked,
|
|
423
|
+
tabIndex: 0,
|
|
424
|
+
onKeyDown: (e) => { if (e.key === ' ' || e.key === 'Enter') { e.preventDefault(); onToggle(!checked) } },
|
|
425
|
+
},
|
|
426
|
+
h('div', { style: { display: 'flex' }, onClick: (e) => e.stopPropagation() },
|
|
427
|
+
h(Check, { checked, onChange: onToggle, label: '选择 ' + name })),
|
|
428
|
+
h('div', { style: { minWidth: 0 } },
|
|
429
|
+
h('div', { style: { display: 'flex', alignItems: 'baseline', gap: 6, minWidth: 0 } },
|
|
430
|
+
dir ? h('span', {
|
|
431
|
+
className: 'sw-mono',
|
|
432
|
+
title: item.path,
|
|
433
|
+
style: { fontSize: 11, color: T.faint, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', maxWidth: '42%', flex: '0 1 auto' },
|
|
434
|
+
}, dir) : null,
|
|
435
|
+
h('span', {
|
|
436
|
+
className: 'sw-mono',
|
|
437
|
+
style: { fontSize: 12.5, color: T.text, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', flex: '0 1 auto', fontWeight: 500 },
|
|
438
|
+
}, name),
|
|
439
|
+
ext ? h('span', {
|
|
440
|
+
style: { fontSize: 9.5, letterSpacing: '.04em', color: T.faint, border: '1px solid ' + T.border, borderRadius: 4, padding: '0 3px', lineHeight: '14px', flex: 'none' },
|
|
441
|
+
}, ext.toUpperCase()) : null,
|
|
442
|
+
),
|
|
443
|
+
h('div', {
|
|
444
|
+
style: { fontSize: 11, color: T.faint, marginTop: 2, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' },
|
|
445
|
+
title: (item.reasons || []).join(' · '),
|
|
446
|
+
},
|
|
447
|
+
(item.reasons || []).join(' · '),
|
|
448
|
+
item.session && item.session.title ? h('span', { style: { opacity: .8 } }, ' 来自「' + item.session.title + '」') : null,
|
|
449
|
+
),
|
|
450
|
+
),
|
|
451
|
+
h('div', { className: 'sw-num', style: { fontSize: 12, color: T.dim, textAlign: 'right', whiteSpace: 'nowrap' } }, fmtBytes(item.size)),
|
|
452
|
+
h('div', { className: 'sw-col-age', style: { textAlign: 'right' } },
|
|
453
|
+
h('span', { className: 'sw-num', style: { fontSize: 11, color: T.faint } }, item.ageDays + ' 天')),
|
|
454
|
+
)
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function Section({ tone, title, hint, items, selected, onToggle, onSelectAll, action, emptyTitle, emptyHint, limit }) {
|
|
458
|
+
const [showAll, setShowAll] = useState(false)
|
|
459
|
+
const color = tone === 'safe' ? T.success : T.warn
|
|
460
|
+
const total = items.reduce((s, it) => s + (it.size || 0), 0)
|
|
461
|
+
const all = items.length > 0 && items.every((it) => selected.has(it.key))
|
|
462
|
+
const some = items.some((it) => selected.has(it.key))
|
|
463
|
+
const visible = showAll ? items : items.slice(0, limit || 200)
|
|
464
|
+
const inputRef = useRef(null)
|
|
465
|
+
useEffect(() => { if (inputRef.current) inputRef.current.indeterminate = some && !all }, [some, all])
|
|
466
|
+
|
|
467
|
+
return h('section', { className: 'sw-card', style: { marginTop: 14, overflow: 'hidden' } },
|
|
468
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, padding: '11px 14px', background: T.layer, borderBottom: items.length ? '1px solid ' + T.border : 'none' } },
|
|
469
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 } },
|
|
470
|
+
h('span', { style: { width: 8, height: 8, borderRadius: 3, background: color, flex: 'none' } }),
|
|
471
|
+
h('div', { style: { fontSize: 13, fontWeight: 600, whiteSpace: 'nowrap' } }, title),
|
|
472
|
+
h('span', { className: 'sw-num', style: { fontSize: 11, color: T.faint } }, items.length + ' 项 · ' + fmtBytes(total)),
|
|
473
|
+
),
|
|
474
|
+
h('div', { style: { flex: 1 } }),
|
|
475
|
+
items.length ? h('label', { style: { display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 11, color: T.faint, cursor: 'pointer', marginRight: 4 } },
|
|
476
|
+
h('input', {
|
|
477
|
+
ref: inputRef, type: 'checkbox', checked: all, 'aria-label': '全选 ' + title,
|
|
478
|
+
onChange: (e) => onSelectAll(items, e.target.checked),
|
|
479
|
+
style: { width: 15, height: 15, margin: 0, accentColor: T.accent, cursor: 'pointer' },
|
|
480
|
+
}),
|
|
481
|
+
'全选',
|
|
482
|
+
) : null,
|
|
483
|
+
action ? h(Btn, { label: action.label, kind: action.kind || 'primary', onClick: action.onClick, icon: action.icon ? h(Icon, { name: action.icon, size: 14 }) : null }) : null,
|
|
484
|
+
),
|
|
485
|
+
items.length === 0
|
|
486
|
+
? h('div', { style: { padding: '4px 14px 14px' } }, h(Empty, { icon: tone === 'safe' ? 'check' : 'shield', title: emptyTitle, hint: emptyHint }))
|
|
487
|
+
: h('div', null,
|
|
488
|
+
visible.map((it) => h(FileRow, { key: it.key, item: it, checked: selected.has(it.key), onToggle: (on) => onToggle(it, on) })),
|
|
489
|
+
items.length > visible.length
|
|
490
|
+
? h('button', {
|
|
491
|
+
type: 'button',
|
|
492
|
+
onClick: () => setShowAll(true),
|
|
493
|
+
style: {
|
|
494
|
+
width: '100%', height: 34, border: 0, borderTop: '1px solid ' + T.border, background: 'transparent',
|
|
495
|
+
color: T.dim, fontSize: 12, cursor: 'pointer',
|
|
496
|
+
},
|
|
497
|
+
}, '还有 ' + (items.length - visible.length) + ' 项 · 显示全部')
|
|
498
|
+
: null,
|
|
499
|
+
),
|
|
500
|
+
hint ? h('div', { style: { padding: '8px 14px', borderTop: '1px solid ' + T.border, fontSize: 11, color: T.faint } }, hint) : null,
|
|
501
|
+
)
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// ── panels ──────────────────────────────────────────────────────────────
|
|
505
|
+
function ReportPanel(props) {
|
|
506
|
+
const { report, status, error, selected, setSelected, onScan, onDelete, onExport, scanStartedAt } = props
|
|
507
|
+
const items = (report && report.items) || []
|
|
508
|
+
const [sortBy, setSortBy] = useState('size')
|
|
509
|
+
const safe = useMemo(() => items.filter((it) => it.tier === 'safe'), [items])
|
|
510
|
+
const unsure = useMemo(() => items.filter((it) => it.tier !== 'safe'), [items])
|
|
511
|
+
|
|
512
|
+
const sorter = useCallback((list) => {
|
|
513
|
+
const arr = list.slice()
|
|
514
|
+
if (sortBy === 'age') arr.sort((a, b) => b.ageDays - a.ageDays || b.size - a.size)
|
|
515
|
+
else if (sortBy === 'path') arr.sort((a, b) => String(a.path).localeCompare(String(b.path)))
|
|
516
|
+
else arr.sort((a, b) => b.size - a.size || String(a.path).localeCompare(String(b.path)))
|
|
517
|
+
return arr
|
|
518
|
+
}, [sortBy])
|
|
519
|
+
|
|
520
|
+
const toggle = (it, on) => setSelected((prev) => {
|
|
521
|
+
const next = new Set(prev)
|
|
522
|
+
if (on) next.add(it.key); else next.delete(it.key)
|
|
523
|
+
return next
|
|
524
|
+
})
|
|
525
|
+
const selectAll = (list, on) => setSelected((prev) => {
|
|
526
|
+
const next = new Set(prev)
|
|
527
|
+
for (const it of list) { if (on) next.add(it.key); else next.delete(it.key) }
|
|
528
|
+
return next
|
|
529
|
+
})
|
|
530
|
+
|
|
531
|
+
if (status === 'error') {
|
|
532
|
+
return h('div', { className: 'sw-card', style: { padding: 18, marginTop: 14 } },
|
|
533
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, color: T.danger, fontWeight: 600, fontSize: 13 } },
|
|
534
|
+
h(Icon, { name: 'alert', size: 16 }), '扫描失败'),
|
|
535
|
+
h('div', { style: { marginTop: 6, fontSize: 12, color: T.dim, lineHeight: 1.7, wordBreak: 'break-word' } }, error || '未知错误'),
|
|
536
|
+
h('div', { style: { marginTop: 12 } }, h(Btn, { label: '重试', kind: 'primary', icon: h(Icon, { name: 'refresh', size: 14 }), onClick: onScan })),
|
|
537
|
+
)
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
return h('div', null,
|
|
541
|
+
h('div', { style: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 8, marginTop: 14 } },
|
|
542
|
+
h(Chip, { dot: true, tone: status === 'refreshing' ? 'warn' : 'success' },
|
|
543
|
+
status === 'refreshing'
|
|
544
|
+
? h('span', null, '扫描中 ', h(Timer, { start: scanStartedAt, running: true }))
|
|
545
|
+
: report ? '已扫描 ' + (report.generatedAt ? fmtDateTime(report.generatedAt) : agoText(report.ageMs || 0)) : '尚未扫描'),
|
|
546
|
+
report ? h(Chip, null, fmtNum(report.stats.sessions) + ' 个会话') : null,
|
|
547
|
+
report ? h(Chip, null, fmtNum(report.stats.toolCalls) + ' 次工具调用') : null,
|
|
548
|
+
report ? h(Chip, null, fmtNum(report.stats.events) + ' 条事件') : null,
|
|
549
|
+
report && report.stats.errors ? h(Chip, { tone: 'warn' }, fmtNum(report.stats.errors) + ' 次失败') : null,
|
|
550
|
+
report ? h(Chip, null, '耗时 ' + fmtDuration(report.durationMs)) : null,
|
|
551
|
+
report && report.protected ? h(Chip, null, '保护中 ' + fmtNum(report.protected.recent + report.protected.live + report.protected.tracked)) : null,
|
|
552
|
+
h('div', { style: { flex: 1 } }),
|
|
553
|
+
items.length ? h('label', { style: { display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 11, color: T.faint } },
|
|
554
|
+
'排序',
|
|
555
|
+
h('select', {
|
|
556
|
+
value: sortBy,
|
|
557
|
+
onChange: (e) => setSortBy(e.target.value),
|
|
558
|
+
style: {
|
|
559
|
+
height: 26, borderRadius: 7, border: '1px solid ' + T.border, background: T.layer, color: T.text,
|
|
560
|
+
fontSize: 11.5, padding: '0 6px', cursor: 'pointer',
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
h('option', { value: 'size' }, '体积'),
|
|
564
|
+
h('option', { value: 'age' }, '闲置'),
|
|
565
|
+
h('option', { value: 'path' }, '路径'),
|
|
566
|
+
)) : null,
|
|
567
|
+
),
|
|
568
|
+
|
|
569
|
+
status === 'loading'
|
|
570
|
+
? h('div', { className: 'sw-card', style: { marginTop: 14, overflow: 'hidden' } },
|
|
571
|
+
h('div', { style: { padding: '12px 14px', display: 'flex', alignItems: 'center', gap: 10, borderBottom: '1px solid ' + T.border } },
|
|
572
|
+
h('div', { className: 'sw-spin' }),
|
|
573
|
+
h('div', { style: { fontSize: 12.5 } }, '正在读取会话日志…'),
|
|
574
|
+
h('div', { style: { marginLeft: 'auto', fontSize: 11, color: T.faint } }, h(Timer, { start: scanStartedAt, running: true }))),
|
|
575
|
+
h(SkeletonRows, { n: 6 }))
|
|
576
|
+
: null,
|
|
577
|
+
|
|
578
|
+
// With nothing to clean, two empty sections under a "很干净" card read
|
|
579
|
+
// like the page is contradicting itself; show only the summary.
|
|
580
|
+
report && items.length
|
|
581
|
+
? h('div', null,
|
|
582
|
+
h(Section, {
|
|
583
|
+
tone: 'safe', title: '无脑删',
|
|
584
|
+
hint: '判定依据:位于 .scratch / tmp / __pycache__ / *.bak 等临时目录,或 dsh-spill 系统临时输出;产生后再没被任何工具当文件用过;最后活动早于 ' + report.weekDays + ' 天。',
|
|
585
|
+
items: sorter(safe), selected, onToggle: toggle, onSelectAll: selectAll,
|
|
586
|
+
emptyTitle: '没有可以无脑删的东西',
|
|
587
|
+
emptyHint: '最近 ' + report.weekDays + ' 天没有产生过无引用的临时产物,或者都还在保护期内。',
|
|
588
|
+
action: safe.length ? { label: '一键清理 ' + safe.length + ' 项', icon: 'broom', onClick: () => onDelete(safe) } : null,
|
|
589
|
+
}),
|
|
590
|
+
h(Section, {
|
|
591
|
+
tone: 'unsure', title: '不确定',
|
|
592
|
+
hint: '产生后被工具引用过、产生它的调用失败过(可能是半成品)、或体积超过 1 MB。选中后需要再次确认才会移入回收站。',
|
|
593
|
+
items: sorter(unsure), selected, onToggle: toggle, onSelectAll: selectAll,
|
|
594
|
+
emptyTitle: '没有需要你判断的条目',
|
|
595
|
+
emptyHint: '有疑问的产物都会出现在这里,默认一个都不动。',
|
|
596
|
+
}),
|
|
597
|
+
)
|
|
598
|
+
: null,
|
|
599
|
+
|
|
600
|
+
report && !items.length && status !== 'loading'
|
|
601
|
+
? h('div', { style: { marginTop: 14 } }, h(Empty, {
|
|
602
|
+
icon: 'check', title: '很干净,没有发现对话垃圾',
|
|
603
|
+
hint: '扫描了 ' + fmtNum(report.stats.sessions) + ' 个会话、' + fmtNum(report.stats.toolCalls) + ' 次工具调用,在 ' + report.weekDays + ' 天窗口里没有找到可清理的残留。',
|
|
604
|
+
}))
|
|
605
|
+
: null,
|
|
606
|
+
|
|
607
|
+
report ? h('details', { style: { marginTop: 14, fontSize: 11.5, color: T.faint } },
|
|
608
|
+
h('summary', { style: { cursor: 'pointer', userSelect: 'none', color: T.dim } }, '判定规则与安全边界'),
|
|
609
|
+
h('div', { style: { marginTop: 6, lineHeight: 1.8 } },
|
|
610
|
+
'· 扫描只读会话日志(tool/call、tool/result、job、title),不调用模型、不写任何文件。', h('br'),
|
|
611
|
+
'· 判定时间 = max(最后一次被工具使用, 文件 mtime, 首次产生时间),超过 ' + report.weekDays + ' 天才进入列表。', h('br'),
|
|
612
|
+
'· 清理 = rename 进 ' + (report.trashRoot || 'DSH_HOME/plugin-data/dsh-sweeper/trash') + ',可整批恢复;永久删除只发生在你手动点「彻底删除」。', h('br'),
|
|
613
|
+
'· 复核每个待删路径:绝对路径、无 ..、不在盘符根、不在 ~/.dsh 与 ~/.agents 内、realpath 未穿链接、是普通文件、大小与 mtime 与扫描一致。', h('br'),
|
|
614
|
+
'· 保护中 ' + fmtNum(report.protected.recent) + '(一周内) · ' + fmtNum(report.protected.live) + '(活跃会话) · ' + fmtNum(report.protected.gone) + '(已消失) · ' + fmtNum(report.protected.unsafe || 0) + '(DSH 内部)',
|
|
615
|
+
report.unreadable && report.unreadable.length ? h('div', { style: { color: T.warn, marginTop: 4 } }, '有 ' + report.unreadable.length + ' 个会话读不出来,已整体跳过(fail-closed)。') : null,
|
|
616
|
+
)) : null,
|
|
617
|
+
)
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function ModelPanel(props) {
|
|
621
|
+
const { report, review, reviewing, error, onRun, onAnswer, reviewStartedAt, onGoTrash } = props
|
|
622
|
+
const items = (report && report.items) || []
|
|
623
|
+
const moved = (review && review.moved) || []
|
|
624
|
+
const asks = (review && review.asks) || []
|
|
625
|
+
const unknown = (review && review.unknown) || []
|
|
626
|
+
const extra = (review && review.extra) || { sweep: [], optional: [], rejected: [], hints: 0 }
|
|
627
|
+
const extraSel = props.extraSelected || new Set()
|
|
628
|
+
const safeCount = items.filter((it) => it.tier === 'safe').length
|
|
629
|
+
|
|
630
|
+
const steps = [
|
|
631
|
+
'把扫描出的候选整理成清单:路径、体积、多久没动过、之后有没有被再次引用。',
|
|
632
|
+
'再附上临时目录里日志没提到的文件,让模型自己判断哪些也可以清。',
|
|
633
|
+
'发给 DSH 当前配置的模型,让它逐条回答:删 / 留 / 要问你。',
|
|
634
|
+
'回答按编号对回文件;对不上、文件已变、被 git 跟踪的建议一律作废。',
|
|
635
|
+
'「可以无脑删」那档直接进回收站,其余只做提示,等你点。',
|
|
636
|
+
]
|
|
637
|
+
|
|
638
|
+
return h('div', { style: { marginTop: 14 } },
|
|
639
|
+
h('div', { className: 'sw-card', style: { padding: 16 } },
|
|
640
|
+
h('div', { style: { display: 'flex', gap: 12, alignItems: 'flex-start' } },
|
|
641
|
+
h('div', { style: { width: 36, height: 36, borderRadius: 11, background: 'rgba(59,110,245,.12)', color: T.accent, display: 'grid', placeItems: 'center', flex: 'none' } },
|
|
642
|
+
h(Icon, { name: 'spark', size: 18 })),
|
|
643
|
+
h('div', { style: { minWidth: 0 } },
|
|
644
|
+
h('div', { style: { fontSize: 14, fontWeight: 600 } }, '让模型复核这份清单'),
|
|
645
|
+
h('div', { style: { fontSize: 12, color: T.dim, marginTop: 3, lineHeight: 1.7 } },
|
|
646
|
+
'模型只做选择题:它只能引用清单里的编号,看不到也操作不了其它文件,输出里不会执行任何命令。它的每一条建议都要再经过插件自己的安全校验。'),
|
|
647
|
+
),
|
|
648
|
+
),
|
|
649
|
+
h('div', { style: { display: 'grid', gap: 6, margin: '14px 0 4px' } },
|
|
650
|
+
steps.map((s, i) => h('div', { key: i, style: { display: 'flex', gap: 8, fontSize: 12, color: T.dim, lineHeight: 1.65 } },
|
|
651
|
+
h('span', { className: 'sw-num', style: { width: 16, flex: 'none', color: T.faint } }, (i + 1) + '.'),
|
|
652
|
+
h('span', null, s))),
|
|
653
|
+
h('details', { style: { marginTop: 4 } },
|
|
654
|
+
h('summary', { style: { fontSize: 11, color: T.faint, cursor: 'pointer' } }, '技术细节:模型看到什么、回答什么'),
|
|
655
|
+
h('div', { style: { fontSize: 11, color: T.faint, lineHeight: 1.7, marginTop: 6 } },
|
|
656
|
+
'A 段是最多 100 条候选,回答 D(删)/ K(留)/ Q(要问你);B 段是清单外的临时文件,回答 A(可无脑清)/ S(可选)/ K(留)。发出去的是一段纯文本摘要,不含对话原文。'))),
|
|
657
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginTop: 14, flexWrap: 'wrap' } },
|
|
658
|
+
h(Btn, {
|
|
659
|
+
kind: 'primary',
|
|
660
|
+
icon: reviewing ? h('span', { className: 'sw-spin' }) : h(Icon, { name: 'spark', size: 14 }),
|
|
661
|
+
label: reviewing ? h('span', null, '模型正在看… ', h(Timer, { start: reviewStartedAt, running: true })) : (review ? '再复核一次' : '让模型复核'),
|
|
662
|
+
onClick: onRun,
|
|
663
|
+
disabled: reviewing || !items.length,
|
|
664
|
+
}),
|
|
665
|
+
h('span', { style: { fontSize: 11, color: T.faint } },
|
|
666
|
+
items.length ? '当前 ' + items.length + ' 条候选(其中无脑删 ' + safeCount + ' 条)' : '没有候选:先去「扫描结果」扫描一次'),
|
|
667
|
+
h('div', { style: { flex: 1 } }),
|
|
668
|
+
h('span', { style: { fontSize: 11, color: T.faint } }, '一次几千 token · 10–40 秒'),
|
|
669
|
+
),
|
|
670
|
+
),
|
|
671
|
+
|
|
672
|
+
error ? h('div', {
|
|
673
|
+
className: 'sw-card',
|
|
674
|
+
style: { marginTop: 12, padding: '12px 14px', borderColor: 'rgba(211,59,59,.4)', background: 'rgba(211,59,59,.06)' },
|
|
675
|
+
},
|
|
676
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, color: T.danger, fontSize: 12.5, fontWeight: 600 } },
|
|
677
|
+
h(Icon, { name: 'alert', size: 15 }), '复核没有完成'),
|
|
678
|
+
h('div', { style: { marginTop: 4, fontSize: 12, color: T.dim, lineHeight: 1.7, wordBreak: 'break-word' } }, error),
|
|
679
|
+
h('div', { style: { marginTop: 4, fontSize: 11.5, color: T.faint } }, '此时不会有任何文件被移动。'),
|
|
680
|
+
) : null,
|
|
681
|
+
|
|
682
|
+
review ? h('div', null,
|
|
683
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit,minmax(150px,1fr))', gap: 10, marginTop: 12 } },
|
|
684
|
+
h(Stat, { label: '已移入回收站', value: fmtNum(moved.length) + ' 项', sub: fmtBytes(review.movedBytes || 0) + (review.batch ? ' · 批次 ' + review.batch.id : ''), tone: 'success' }),
|
|
685
|
+
h(Stat, { label: '待你决定', value: fmtNum(asks.length) + ' 项', sub: asks.length ? '模型拿不准,逐条确认' : '没有需要确认的项目', tone: asks.length ? 'warn' : null }),
|
|
686
|
+
h(Stat, { label: '模型', value: review.model && review.model.model ? review.model.model : '—', sub: (review.model && review.model.provider ? review.model.provider + ' · ' : '') + '耗时 ' + fmtDuration(review.ms) }),
|
|
687
|
+
h(Stat, { label: '本次看过', value: fmtNum(review.reviewed) + ' 条', sub: review.skipped
|
|
688
|
+
? '报告共 ' + fmtNum(review.reviewed + review.skipped) + ' 条,只发送了前 ' + fmtNum(review.reviewed) + ' 条'
|
|
689
|
+
: (extra.hints ? '另看 ' + fmtNum(extra.hints) + ' 个清单外文件' : '编号全部有效') }),
|
|
690
|
+
),
|
|
691
|
+
|
|
692
|
+
moved.length
|
|
693
|
+
? h('div', { className: 'sw-card', style: { marginTop: 12, padding: '12px 14px' } },
|
|
694
|
+
h('div', { style: { fontSize: 12.5, fontWeight: 600, marginBottom: 6 } }, '已自动清理'),
|
|
695
|
+
moved.slice(0, 8).map((k) => h('div', { key: k, className: 'sw-mono', style: { fontSize: 11, color: T.faint, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, k)),
|
|
696
|
+
moved.length > 8 ? h('div', { style: { fontSize: 11, color: T.faint, marginTop: 2 } }, '… 其余 ' + (moved.length - 8) + ' 项') : null,
|
|
697
|
+
h('div', { style: { marginTop: 8 } }, h(Btn, { label: '去回收站查看', kind: 'quiet', icon: h(Icon, { name: 'box', size: 14 }), onClick: props.onGoTrash })),
|
|
698
|
+
)
|
|
699
|
+
: null,
|
|
700
|
+
|
|
701
|
+
asks.length
|
|
702
|
+
? h('div', { style: { marginTop: 12 } },
|
|
703
|
+
h('div', { style: { fontSize: 12.5, fontWeight: 600, marginBottom: 8, display: 'flex', alignItems: 'center', gap: 8 } },
|
|
704
|
+
h('span', { style: { width: 8, height: 8, borderRadius: 3, background: T.warn } }), '需要你决定'),
|
|
705
|
+
asks.map((a) => h('div', { key: a.key, className: 'sw-card', style: { padding: '12px 14px', marginBottom: 8, background: 'transparent' } },
|
|
706
|
+
h('div', { style: { display: 'flex', gap: 12, alignItems: 'flex-start' } },
|
|
707
|
+
h('div', { style: { flex: 1, minWidth: 0 } },
|
|
708
|
+
h('div', { className: 'sw-mono', style: { fontSize: 11.5, wordBreak: 'break-all', color: T.text } }, a.path),
|
|
709
|
+
h('div', { style: { display: 'flex', gap: 8, alignItems: 'center', marginTop: 4 } },
|
|
710
|
+
h(Chip, { tone: a.tier === 'safe' ? 'success' : 'warn' }, a.tier === 'safe' ? '无脑删档' : '不确定档'),
|
|
711
|
+
h('span', { className: 'sw-num', style: { fontSize: 11, color: T.faint } }, fmtBytes(a.size))),
|
|
712
|
+
h('div', { style: { fontSize: 12, color: T.dim, marginTop: 6, lineHeight: 1.65 } }, '模型问:' + (a.question || '这个还留着吗?')),
|
|
713
|
+
),
|
|
714
|
+
h('div', { style: { display: 'flex', gap: 6, flex: 'none' } },
|
|
715
|
+
h(Btn, { label: '清理', kind: 'danger', onClick: () => onAnswer(a.key, true) }),
|
|
716
|
+
h(Btn, { label: '留着', kind: 'quiet', onClick: () => onAnswer(a.key, false) })),
|
|
717
|
+
))))
|
|
718
|
+
: null,
|
|
719
|
+
|
|
720
|
+
(extra.sweep || []).length
|
|
721
|
+
? h('div', { className: 'sw-card', style: { marginTop: 12, padding: '12px 14px' } },
|
|
722
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
|
|
723
|
+
h('span', { style: { width: 8, height: 8, borderRadius: 3, background: T.success } }),
|
|
724
|
+
h('div', { style: { fontSize: 12.5, fontWeight: 600 } }, '模型建议 · 可无脑清理'),
|
|
725
|
+
h(Chip, null, fmtNum(extra.sweep.length) + ' 项 · ' + fmtBytes(extra.sweep.reduce((n, x) => n + (x.size || 0), 0))),
|
|
726
|
+
h('div', { style: { flex: 1 } }),
|
|
727
|
+
h(Btn, {
|
|
728
|
+
label: '清理这 ' + extra.sweep.length + ' 项',
|
|
729
|
+
kind: 'danger',
|
|
730
|
+
icon: h(Icon, { name: 'trash', size: 14 }),
|
|
731
|
+
onClick: () => props.onCleanExtra(extra.sweep.map((x) => x.key)),
|
|
732
|
+
})),
|
|
733
|
+
h('div', { style: { fontSize: 11, color: T.faint, marginTop: 4 } }, '这些不在规则候选里,是模型根据清单外观察主动提议的;插件已复核过「文件仍在、没变、不是链接、没被 git 跟踪」。'),
|
|
734
|
+
extra.sweep.slice(0, 6).map((x) => h('div', { key: x.key, style: { display: 'flex', gap: 10, marginTop: 6, fontSize: 11.5 } },
|
|
735
|
+
h('span', { className: 'sw-mono', style: { flex: 1, minWidth: 0, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', color: T.dim } }, x.path),
|
|
736
|
+
h('span', { className: 'sw-num', style: { flex: 'none', color: T.faint } }, fmtBytes(x.size) + ' · ' + x.ageDays + ' 天'))),
|
|
737
|
+
extra.sweep.length > 6 ? h('div', { style: { fontSize: 11, color: T.faint, marginTop: 4 } }, '… 其余 ' + (extra.sweep.length - 6) + ' 项') : null,
|
|
738
|
+
)
|
|
739
|
+
: null,
|
|
740
|
+
|
|
741
|
+
(extra.optional || []).length
|
|
742
|
+
? h('div', { className: 'sw-card', style: { marginTop: 12, padding: '12px 14px' } },
|
|
743
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' } },
|
|
744
|
+
h('span', { style: { width: 8, height: 8, borderRadius: 3, background: T.warn } }),
|
|
745
|
+
h('div', { style: { fontSize: 12.5, fontWeight: 600 } }, '模型建议 · 可选清理'),
|
|
746
|
+
h(Chip, null, fmtNum(extra.optional.length) + ' 项'),
|
|
747
|
+
h('div', { style: { flex: 1 } }),
|
|
748
|
+
h(Btn, {
|
|
749
|
+
label: extraSel.size ? '清理选中 ' + extraSel.size + ' 项' : '清理选中',
|
|
750
|
+
kind: 'quiet',
|
|
751
|
+
disabled: !extraSel.size,
|
|
752
|
+
onClick: () => props.onCleanExtra([...extraSel]),
|
|
753
|
+
})),
|
|
754
|
+
h('div', { style: { fontSize: 11, color: T.faint, marginTop: 4 } }, '模型觉得像垃圾但拿不准,勾选后才会移进回收站。'),
|
|
755
|
+
extra.optional.slice(0, 40).map((x) => h('label', {
|
|
756
|
+
key: x.key,
|
|
757
|
+
className: 'sw-row',
|
|
758
|
+
style: { gridTemplateColumns: '18px minmax(0,1fr) 70px 62px', padding: '7px 0 7px 2px' },
|
|
759
|
+
},
|
|
760
|
+
h(Check, {
|
|
761
|
+
checked: extraSel.has(x.key),
|
|
762
|
+
onChange: () => props.onToggleExtra(x.key),
|
|
763
|
+
label: '选择 ' + x.path,
|
|
764
|
+
}),
|
|
765
|
+
h('span', { className: 'sw-mono', style: { fontSize: 11.5, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', color: T.dim } }, x.path),
|
|
766
|
+
h('span', { className: 'sw-num', style: { fontSize: 11, color: T.faint, textAlign: 'right' } }, fmtBytes(x.size)),
|
|
767
|
+
h('span', { className: 'sw-num', style: { fontSize: 11, color: T.faint, textAlign: 'right' } }, x.ageDays + ' 天'))),
|
|
768
|
+
(extra.optional || []).length > 40 ? h('div', { style: { fontSize: 11, color: T.faint, marginTop: 4 } }, '只显示前 40 项') : null,
|
|
769
|
+
)
|
|
770
|
+
: null,
|
|
771
|
+
|
|
772
|
+
(extra.rejected || []).length
|
|
773
|
+
? h('details', { style: { marginTop: 10, fontSize: 11, color: T.faint } },
|
|
774
|
+
h('summary', { style: { cursor: 'pointer' } }, '另有 ' + extra.rejected.length + ' 条建议没通过安全校验,已丢弃'),
|
|
775
|
+
extra.rejected.slice(0, 8).map((r, i) => h('div', { key: i, style: { marginTop: 3 } }, r.path + ' — ' + r.reason)))
|
|
776
|
+
: null,
|
|
777
|
+
|
|
778
|
+
unknown.length
|
|
779
|
+
? h('div', { style: { marginTop: 10, fontSize: 11, color: T.faint } }, '模型给出 ' + unknown.length + ' 个不在清单里的编号,已全部忽略(fail-closed)。')
|
|
780
|
+
: null,
|
|
781
|
+
review.note ? h('div', { style: { marginTop: 10, fontSize: 11.5, color: T.faint } }, '模型备注:' + review.note) : null,
|
|
782
|
+
) : null,
|
|
783
|
+
)
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// Deep pass: per-conversation model review. One conversation knows what it
|
|
787
|
+
// was doing; the page explains the cost before anything is sent, then shows
|
|
788
|
+
// each conversation's answer as soon as it lands (four in flight at most).
|
|
789
|
+
function DeepPanel(props) {
|
|
790
|
+
const {
|
|
791
|
+
plan, job, busy, error, consent, planning,
|
|
792
|
+
onConsent, onPlan, onStart, onCancel,
|
|
793
|
+
selected, onToggle, onSelectAll, onClean,
|
|
794
|
+
} = props
|
|
795
|
+
const running = !!(job && job.state === 'running')
|
|
796
|
+
const sweep = (job && job.sweep) || []
|
|
797
|
+
const optional = (job && job.optional) || []
|
|
798
|
+
const rejected = (job && job.rejected) || []
|
|
799
|
+
const rows = (job && job.sessions) || (plan && plan.sessions) || []
|
|
800
|
+
const estimate = job ? job.totals.estTokens : (plan ? plan.totalEstTokens : 0)
|
|
801
|
+
const totalN = job ? job.totals.sessions : rows.length
|
|
802
|
+
const finished = job ? job.totals.done + job.totals.failed : 0
|
|
803
|
+
const pct = totalN ? Math.round((finished / totalN) * 100) : 0
|
|
804
|
+
const statusOf = (s) => (s === 'done' ? '完成' : s === 'failed' ? '失败' : s === 'running' ? '分析中…' : s === 'cancelled' ? '已取消' : s === 'lost' ? '已中断' : s === 'queued' ? '排队中' : '待分析')
|
|
805
|
+
const toneOf = (s) => (s === 'done' ? 'success' : s === 'failed' ? 'danger' : s === 'running' ? 'accent' : s === 'cancelled' || s === 'lost' ? 'warn' : 'neutral')
|
|
806
|
+
|
|
807
|
+
return h('div', null,
|
|
808
|
+
h('div', { className: 'sw-card', style: { padding: '14px 16px' } },
|
|
809
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
|
810
|
+
h(Icon, { name: 'spark', size: 16 }),
|
|
811
|
+
h('div', { style: { fontSize: 13.5, fontWeight: 600 } }, '按对话深度清理'),
|
|
812
|
+
h('div', { style: { flex: 1 } }),
|
|
813
|
+
h(Btn, { label: planning ? '读取会话…' : '重新估算', kind: 'quiet', icon: h(Icon, { name: 'refresh', size: 13 }), onClick: () => onPlan(true), disabled: planning || running }),
|
|
814
|
+
),
|
|
815
|
+
h('div', { style: { fontSize: 12, color: T.dim, marginTop: 8, lineHeight: 1.75 } },
|
|
816
|
+
'规则扫描只看得见“文件在什么目录”,看不见“这段对话当时在干什么”,也看不见几百 MB 的产物——那种文件往往没有 write 调用留下路径。这里把闲置超过 ' + (job ? job.week : (plan ? plan.week : 7)) + ' 天的对话的工具执行流摘成说明,并且让模型在工作目录里自己查看:列目录、看大小、按大小找文件,最后给出它认为已无用的路径。',
|
|
817
|
+
),
|
|
818
|
+
h('div', { style: { fontSize: 11.5, color: T.faint, marginTop: 6, lineHeight: 1.7 } },
|
|
819
|
+
'只发送摘要:对话标题、工作目录、工具名与目标路径、开头提问与最后一次回答的节选。不发送原始对话记录,也不会写入任何会话日志。模型能用的工具只有三个,全是只读:列目录、看单个文件、按名称或大小找文件;不能执行命令、不能写、不能删。',
|
|
820
|
+
),
|
|
821
|
+
h('div', { style: { fontSize: 11.5, color: T.faint, marginTop: 6, lineHeight: 1.7 } },
|
|
822
|
+
'它自己找出来的文件一律进「需要你判断」那一档:规则扫描认定的临时目录才算「无脑删」,模型点名的文件要你勾一次,因为它猜错的代价可能是几个 GB。',
|
|
823
|
+
),
|
|
824
|
+
h('div', { style: { display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap', marginTop: 10, fontSize: 11.5, color: T.dim } },
|
|
825
|
+
h(Chip, { tone: 'neutral', dot: true }, '最多 ' + (job ? job.concurrency : (plan ? plan.concurrency : 4)) + ' 段对话同时分析'),
|
|
826
|
+
h(Chip, { tone: 'neutral' }, '谁先返回就先显示'),
|
|
827
|
+
h(Chip, { tone: 'neutral' }, '每段最多 6 轮工具调用'),
|
|
828
|
+
h(Chip, { tone: 'warn' }, '会消耗 token'),
|
|
829
|
+
),
|
|
830
|
+
),
|
|
831
|
+
|
|
832
|
+
plan && !plan.sessions.length && !job ? h(Empty, {
|
|
833
|
+
icon: h(Icon, { name: 'box', size: 22 }),
|
|
834
|
+
title: '没有需要深度分析的对话',
|
|
835
|
+
hint: (plan.skipped
|
|
836
|
+
? '超过 ' + plan.week + ' 天未使用的 ' + plan.skipped + ' 段对话里没有留下临时产物,所以不用花 token 去问模型。'
|
|
837
|
+
: '超过 ' + plan.week + ' 天未使用、且仍然留有临时产物的对话才会出现在这里。')
|
|
838
|
+
+ ' 可以点「重新估算」再读一次磁盘。',
|
|
839
|
+
}) : null,
|
|
840
|
+
|
|
841
|
+
rows.length ? h('div', { className: 'sw-card', style: { marginTop: 14, overflow: 'hidden' } },
|
|
842
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, padding: '11px 14px', background: T.layer, borderBottom: '1px solid ' + T.border } },
|
|
843
|
+
h('div', { style: { fontSize: 13, fontWeight: 600 } }, job && job.state !== 'running' ? '本次分析' : '待分析对话'),
|
|
844
|
+
h('span', { className: 'sw-num', style: { fontSize: 11, color: T.faint } },
|
|
845
|
+
totalN + ' 段 · ' + (job ? '本次约 ' : '预计约 ') + fmtNum(estimate) + ' tokens' + (plan && plan.skipped ? ' · ' + plan.skipped + ' 段无临时产物已跳过' : '') + (plan && plan.unreadable ? ' · ' + plan.unreadable + ' 段日志读不出来' : '')),
|
|
846
|
+
h('div', { style: { flex: 1 } }),
|
|
847
|
+
running ? h('span', { style: { fontSize: 11.5, color: T.accent } }, finished + ' / ' + totalN) : null,
|
|
848
|
+
),
|
|
849
|
+
running ? h('div', { className: 'sw-progress' },
|
|
850
|
+
h('div', { className: 'sw-progress-fill', style: { width: pct + '%' } })) : null,
|
|
851
|
+
h('div', null, rows.map((s) => h('div', {
|
|
852
|
+
key: s.id,
|
|
853
|
+
style: { display: 'flex', alignItems: 'center', gap: 10, padding: '9px 14px', borderTop: '1px solid ' + T.border, fontSize: 12 },
|
|
854
|
+
},
|
|
855
|
+
h('div', { style: { minWidth: 0, flex: 1 } },
|
|
856
|
+
h('div', { style: { whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', fontWeight: 500 } }, s.title || s.id),
|
|
857
|
+
h('div', { className: 'sw-mono', style: { fontSize: 10.5, color: T.faint, marginTop: 2, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } },
|
|
858
|
+
(s.cwd || '(未知目录)') + ' · 闲置 ' + s.ageDays + ' 天 · '
|
|
859
|
+
+ (s.candidates ? fmtNum(s.candidates) + ' 个文件' : (s.tools ? '清单为空,模型会自己查看' : '0 个文件'))
|
|
860
|
+
+ (s.tools && s.candidates ? ' · 模型可用工具查看' : '')
|
|
861
|
+
+ (s.truncated ? ' · 日志过长,只读了前面一部分' : '')
|
|
862
|
+
+ (s.hidden ? '(另有 ' + fmtNum(s.hidden) + ' 个没发送给模型)' : '')),
|
|
863
|
+
),
|
|
864
|
+
s.error ? h('div', { title: s.error, style: { fontSize: 10.5, color: T.danger, maxWidth: 220, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' } }, s.error) : null,
|
|
865
|
+
s.status === 'done' ? h('span', { className: 'sw-num', style: { fontSize: 11, color: T.faint } }, (s.ms ? (s.ms / 1000).toFixed(1) + 's' : '') + (s.calls ? ' · 工具 ' + s.calls + ' 次' : '') + (s.found ? ' · ' + s.found + ' 项' : '')) : null,
|
|
866
|
+
h(Chip, { tone: toneOf(s.status), dot: s.status === 'running' }, statusOf(s.status)),
|
|
867
|
+
))),
|
|
868
|
+
) : null,
|
|
869
|
+
|
|
870
|
+
!running && plan && plan.sessions.length ? h('div', {
|
|
871
|
+
style: { display: 'flex', alignItems: 'center', gap: 12, flexWrap: 'wrap', marginTop: 14, padding: '11px 14px', border: '1px solid ' + T.border, borderRadius: 10, background: T.layer },
|
|
872
|
+
},
|
|
873
|
+
h(Check, { checked: consent, onChange: () => onConsent(!consent), label: '同意把摘要发给模型' }),
|
|
874
|
+
h('div', { style: { fontSize: 11.5, color: T.dim, flex: 1, minWidth: 240 } },
|
|
875
|
+
job && job.state === 'done'
|
|
876
|
+
? '重跑会在模型上再花一次 token;模型只回答编号,最终删什么仍由你勾选决定。'
|
|
877
|
+
: '预计约 ' + fmtNum(estimate) + ' tokens(按字符估算,实际由模型计费)。模型只回答编号,最终删什么仍由你勾选决定。'),
|
|
878
|
+
h(Btn, {
|
|
879
|
+
label: job && job.state === 'done' ? '重新分析' : '开始分析', kind: 'primary', icon: h(Icon, { name: 'spark', size: 14 }),
|
|
880
|
+
onClick: () => onStart(), disabled: !consent || busy,
|
|
881
|
+
}),
|
|
882
|
+
) : null,
|
|
883
|
+
|
|
884
|
+
running ? h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginTop: 14, padding: '11px 14px', border: '1px solid ' + T.border, borderRadius: 10, background: T.layer } },
|
|
885
|
+
h('div', { style: { fontSize: 12, color: T.dim, flex: 1 } }, '正在逐段分析,结果会边返回边显示。已完成的对话可以立刻清理。'),
|
|
886
|
+
h(Btn, { label: '停止', kind: 'quiet', onClick: onCancel }),
|
|
887
|
+
) : null,
|
|
888
|
+
|
|
889
|
+
error ? h('div', {
|
|
890
|
+
style: {
|
|
891
|
+
marginTop: 12, padding: '10px 12px', borderRadius: 8, border: '1px solid ' + T.borderStrong,
|
|
892
|
+
background: T.layer, color: T.danger, fontSize: 12, display: 'flex', alignItems: 'center', gap: 10,
|
|
893
|
+
},
|
|
894
|
+
},
|
|
895
|
+
h('div', { style: { flex: 1, lineHeight: 1.7 } }, error + '(此时不会有任何文件被移动)'),
|
|
896
|
+
h(Btn, {
|
|
897
|
+
label: plan && plan.sessions.length ? '重试分析' : '重新估算', kind: 'quiet',
|
|
898
|
+
icon: h(Icon, { name: 'refresh', size: 13 }),
|
|
899
|
+
onClick: () => (plan && plan.sessions.length ? onStart() : onPlan(true)),
|
|
900
|
+
disabled: busy,
|
|
901
|
+
})) : null,
|
|
902
|
+
|
|
903
|
+
job && job.state === 'done' && !sweep.length && !optional.length ? h('div', { style: { marginTop: 12, padding: '10px 12px', borderRadius: 8, border: '1px solid ' + T.border, fontSize: 12, color: T.dim } },
|
|
904
|
+
'模型看完了 ' + job.totals.done + ' 段对话,没有建议删除任何文件。') : null,
|
|
905
|
+
|
|
906
|
+
sweep.length ? h(Section, {
|
|
907
|
+
tone: 'safe', title: '模型认为可以无脑删', hint: '来自闲置对话的临时产物,模型给出了理由;勾选后移到回收站',
|
|
908
|
+
items: sweep, selected, onToggle, onSelectAll,
|
|
909
|
+
action: { label: '全部清理', kind: 'primary', onClick: () => onClean(sweep.map((it) => it.key)) },
|
|
910
|
+
}) : null,
|
|
911
|
+
|
|
912
|
+
optional.length ? h(Section, {
|
|
913
|
+
tone: 'unsure', title: '模型认为可选清理', hint: '可能是临时产物,但模型给出了不确定的理由;请逐项确认',
|
|
914
|
+
items: optional, selected, onToggle, onSelectAll,
|
|
915
|
+
}) : null,
|
|
916
|
+
|
|
917
|
+
rejected.length ? h('details', { style: { marginTop: 12, fontSize: 11.5, color: T.faint } },
|
|
918
|
+
h('summary', { style: { cursor: 'pointer' } }, '模型提到但没通过校验的 ' + rejected.length + ' 项'),
|
|
919
|
+
h('div', { style: { marginTop: 6, display: 'flex', flexDirection: 'column', gap: 3 } },
|
|
920
|
+
rejected.slice(0, 50).map((r, i) => h('div', { key: i, className: 'sw-mono', style: { wordBreak: 'break-all' } }, r.path + ' — ' + r.reason))),
|
|
921
|
+
) : null,
|
|
922
|
+
|
|
923
|
+
h('div', { style: { marginTop: 16, fontSize: 11, color: T.faint, lineHeight: 1.7 } },
|
|
924
|
+
'校验规则:模型只能引用我们给出的编号;每个编号都要重新核对磁盘(文件仍在、大小没变、不是链接、不在 ~/.dsh 或 ~/.agents 内、git 不跟踪)。不满足的项不会显示,也不会被清理。'),
|
|
925
|
+
)
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function TrashPanel(props) {
|
|
929
|
+
const { batches, root, busy, error, onRestore, onPurge, onRefresh } = props
|
|
930
|
+
return h('div', { style: { marginTop: 14 } },
|
|
931
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, marginBottom: 10 } },
|
|
932
|
+
h('div', { style: { fontSize: 12, color: T.faint, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, root || '回收站'),
|
|
933
|
+
h('div', { style: { flex: 1 } }),
|
|
934
|
+
h(Btn, { label: '刷新', kind: 'quiet', icon: h(Icon, { name: 'refresh', size: 14 }), onClick: onRefresh, disabled: busy }),
|
|
935
|
+
),
|
|
936
|
+
error
|
|
937
|
+
? h('div', { style: { padding: '12px 14px', borderRadius: 10, border: '1px solid ' + T.borderStrong, background: T.layer, fontSize: 12, display: 'flex', alignItems: 'center', gap: 10 } },
|
|
938
|
+
h('div', { style: { flex: 1, color: T.danger, lineHeight: 1.7 } }, '回收站读不出来:' + error + '。文件没有被改动,问题解决后点「刷新」重试。'),
|
|
939
|
+
h(Btn, { label: '重试', kind: 'quiet', icon: h(Icon, { name: 'refresh', size: 13 }), onClick: onRefresh, disabled: busy }))
|
|
940
|
+
: batches.length === 0
|
|
941
|
+
? h(Empty, { icon: 'box', title: '回收站是空的', hint: '被你或模型清理掉的文件会先放在这里,可以整批恢复,也可以彻底删除。' })
|
|
942
|
+
: batches.map((b) => h('div', { key: b.id, className: 'sw-card', style: { padding: '12px 14px', marginBottom: 8, display: 'flex', alignItems: 'center', gap: 12 } },
|
|
943
|
+
h('div', { style: { width: 32, height: 32, borderRadius: 10, background: T.layer2, display: 'grid', placeItems: 'center', color: T.dim, flex: 'none' } },
|
|
944
|
+
h(Icon, { name: 'box', size: 16 })),
|
|
945
|
+
h('div', { style: { flex: 1, minWidth: 0 } },
|
|
946
|
+
h('div', { style: { fontSize: 12.5, display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' } },
|
|
947
|
+
h('span', null, fmtDateTime(b.createdAt)),
|
|
948
|
+
h('span', { className: 'sw-mono', style: { fontSize: 11, color: T.faint } }, b.id),
|
|
949
|
+
b.note ? h(Chip, null, noteLabel(b.note)) : null,
|
|
950
|
+
b.damaged ? h(Chip, { tone: 'warn' }, '清单损坏') : null),
|
|
951
|
+
h('div', { className: 'sw-num', style: { fontSize: 11, color: T.faint, marginTop: 2 } },
|
|
952
|
+
b.damaged
|
|
953
|
+
? b.count + ' 个文件 · ' + fmtBytes(b.bytes) + ' · 清单读不出来,只能整批删除'
|
|
954
|
+
: b.count + ' 个文件 · ' + fmtBytes(b.bytes))),
|
|
955
|
+
h('div', { style: { display: 'flex', gap: 6, flex: 'none' } },
|
|
956
|
+
h(Btn, {
|
|
957
|
+
label: '恢复',
|
|
958
|
+
icon: h(Icon, { name: 'restore', size: 14 }),
|
|
959
|
+
onClick: () => onRestore(b.id),
|
|
960
|
+
disabled: busy || !!b.damaged,
|
|
961
|
+
title: b.damaged ? '清单读不出来,无法确定每个文件的原位置' : undefined,
|
|
962
|
+
}),
|
|
963
|
+
h(Btn, { label: '彻底删除', kind: 'danger', onClick: () => onPurge(b), disabled: busy })),
|
|
964
|
+
)),
|
|
965
|
+
)
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
// ── page ────────────────────────────────────────────────────────────────
|
|
969
|
+
function Page() {
|
|
970
|
+
useStyles()
|
|
971
|
+
const [status, setStatus] = useState('loading')
|
|
972
|
+
const [report, setReport] = useState(null)
|
|
973
|
+
const [error, setError] = useState(null)
|
|
974
|
+
const [selected, setSelected] = useState(() => new Set())
|
|
975
|
+
const trashSeq = useRef(0)
|
|
976
|
+
const [extraSel, setExtraSel] = useState(() => new Set())
|
|
977
|
+
const [tab, setTab] = useState('report')
|
|
978
|
+
const [dialog, setDialog] = useState(null)
|
|
979
|
+
const [busy, setBusy] = useState(false)
|
|
980
|
+
const [toast, setToast] = useState(null)
|
|
981
|
+
const [trash, setTrash] = useState({ batches: [], root: '' })
|
|
982
|
+
const [trashErr, setTrashErr] = useState(null)
|
|
983
|
+
const [review, setReview] = useState(null)
|
|
984
|
+
const [reviewing, setReviewing] = useState(false)
|
|
985
|
+
const [reviewErr, setReviewErr] = useState(null)
|
|
986
|
+
const [deepPlan, setDeepPlan] = useState(null)
|
|
987
|
+
const [deepJob, setDeepJob] = useState(null)
|
|
988
|
+
const [deepPlanning, setDeepPlanning] = useState(false)
|
|
989
|
+
const [deepConsent, setDeepConsent] = useState(false)
|
|
990
|
+
const [deepErr, setDeepErr] = useState(null)
|
|
991
|
+
const [deepSel, setDeepSel] = useState(() => new Set())
|
|
992
|
+
const scanStart = useRef(Date.now())
|
|
993
|
+
const reviewStart = useRef(0)
|
|
994
|
+
const loadSeq = useRef(0)
|
|
995
|
+
const startingRef = useRef(false)
|
|
996
|
+
|
|
997
|
+
const scanning = status === 'loading' || status === 'refreshing'
|
|
998
|
+
|
|
999
|
+
const load = useCallback((force, keepReview) => {
|
|
1000
|
+
// Two quick clicks used to race: the slower response could land last and
|
|
1001
|
+
// replace a newer report with an older one. Only the newest request may
|
|
1002
|
+
// touch state; the others are still awaited by the server's coalescing.
|
|
1003
|
+
const seq = ++loadSeq.current
|
|
1004
|
+
scanStart.current = Date.now()
|
|
1005
|
+
setStatus((s) => (s === 'loading' ? 'loading' : 'refreshing'))
|
|
1006
|
+
setError(null)
|
|
1007
|
+
getJSON('/report' + (force ? '?refresh=1' : ''))
|
|
1008
|
+
.then((data) => {
|
|
1009
|
+
if (seq !== loadSeq.current) return
|
|
1010
|
+
setReport(data)
|
|
1011
|
+
setSelected(new Set())
|
|
1012
|
+
setStatus('ready')
|
|
1013
|
+
// A scan snapshot invalidates the model's verdicts — but the refresh
|
|
1014
|
+
// right after a review must not wipe the result the user is reading.
|
|
1015
|
+
if (!keepReview) {
|
|
1016
|
+
setReview(null)
|
|
1017
|
+
setReviewErr(null)
|
|
1018
|
+
}
|
|
1019
|
+
})
|
|
1020
|
+
.catch((err) => {
|
|
1021
|
+
if (seq !== loadSeq.current) return
|
|
1022
|
+
setError(humanError(err))
|
|
1023
|
+
setStatus('error')
|
|
1024
|
+
})
|
|
1025
|
+
}, [])
|
|
1026
|
+
|
|
1027
|
+
// Same shape as load(): two quick visits to the bin (or a restore that
|
|
1028
|
+
// finishes while the tab is being opened) must not let an older response
|
|
1029
|
+
// land last and overwrite a newer one.
|
|
1030
|
+
const loadTrash = useCallback(() => {
|
|
1031
|
+
const seq = ++trashSeq.current
|
|
1032
|
+
setTrashErr(null)
|
|
1033
|
+
getJSON('/trash')
|
|
1034
|
+
.then((d) => { if (seq === trashSeq.current) setTrash({ batches: d.batches || [], root: d.root || '' }) })
|
|
1035
|
+
.catch((err) => { if (seq === trashSeq.current) setTrashErr(humanError(err)) })
|
|
1036
|
+
}, [])
|
|
1037
|
+
|
|
1038
|
+
const planningRef = useRef(false)
|
|
1039
|
+
|
|
1040
|
+
const loadDeepPlan = useCallback((force) => {
|
|
1041
|
+
if (planningRef.current) return
|
|
1042
|
+
planningRef.current = true
|
|
1043
|
+
setDeepPlanning(true)
|
|
1044
|
+
setDeepErr(null)
|
|
1045
|
+
getJSON('/deep/plan' + (force ? '?refresh=1' : ''))
|
|
1046
|
+
.then((d) => setDeepPlan(d))
|
|
1047
|
+
.catch((err) => setDeepErr(humanError(err)))
|
|
1048
|
+
.finally(() => { planningRef.current = false; setDeepPlanning(false) })
|
|
1049
|
+
}, [])
|
|
1050
|
+
|
|
1051
|
+
useEffect(() => { load(false); loadTrash() }, [load, loadTrash])
|
|
1052
|
+
useEffect(() => {
|
|
1053
|
+
if (!toast) return
|
|
1054
|
+
const id = setTimeout(() => setToast(null), 4200)
|
|
1055
|
+
return () => clearTimeout(id)
|
|
1056
|
+
}, [toast])
|
|
1057
|
+
|
|
1058
|
+
// Deep pass: poll while a job is running so finished conversations paint
|
|
1059
|
+
// immediately instead of waiting for the slowest model call.
|
|
1060
|
+
//
|
|
1061
|
+
// The host forgets jobs when it restarts — which happens every time the
|
|
1062
|
+
// plugin is reloaded. The old code ignored `{ job: null }` and swallowed
|
|
1063
|
+
// every failed poll, so the panel sat on "分析中…" forever with a frozen
|
|
1064
|
+
// progress bar: a dead run that looked alive.
|
|
1065
|
+
useEffect(() => {
|
|
1066
|
+
if (!deepJob || deepJob.state !== 'running') return
|
|
1067
|
+
let stop = false
|
|
1068
|
+
let fails = 0
|
|
1069
|
+
const lose = (text) => {
|
|
1070
|
+
if (stop) return
|
|
1071
|
+
stop = true
|
|
1072
|
+
setDeepJob((j) => (j ? { ...j, state: 'lost' } : j))
|
|
1073
|
+
setDeepErr(text)
|
|
1074
|
+
}
|
|
1075
|
+
const tick = () => {
|
|
1076
|
+
getJSON('/deep/status')
|
|
1077
|
+
.then((d) => {
|
|
1078
|
+
if (stop) return
|
|
1079
|
+
fails = 0
|
|
1080
|
+
if (!d || !d.job) {
|
|
1081
|
+
lose('后台已经没有这次分析的记录了(DSH 可能重启过),返回的结果不会自己回来。')
|
|
1082
|
+
return
|
|
1083
|
+
}
|
|
1084
|
+
setDeepJob(d.job)
|
|
1085
|
+
})
|
|
1086
|
+
.catch(() => {
|
|
1087
|
+
if (stop) return
|
|
1088
|
+
fails += 1
|
|
1089
|
+
if (fails >= 3) lose('连不上后台,这次分析的进度已经看不到了(DSH 可能正在重启)。')
|
|
1090
|
+
})
|
|
1091
|
+
}
|
|
1092
|
+
const id = setInterval(tick, 900)
|
|
1093
|
+
return () => { stop = true; clearInterval(id) }
|
|
1094
|
+
}, [deepJob && deepJob.state, deepJob && deepJob.id])
|
|
1095
|
+
|
|
1096
|
+
// Rows can disappear between polls (cancelled, moved, vetted away). Drop
|
|
1097
|
+
// their keys from the selection so the sticky bar never counts ghosts.
|
|
1098
|
+
useEffect(() => {
|
|
1099
|
+
if (!deepJob) return
|
|
1100
|
+
setDeepSel((prev) => {
|
|
1101
|
+
if (!prev.size) return prev
|
|
1102
|
+
const live = new Set([].concat(deepJob.sweep || [], deepJob.optional || []).map((it) => it.key))
|
|
1103
|
+
let changed = false
|
|
1104
|
+
const next = new Set()
|
|
1105
|
+
for (const key of prev) { if (live.has(key)) next.add(key); else changed = true }
|
|
1106
|
+
return changed ? next : prev
|
|
1107
|
+
})
|
|
1108
|
+
}, [deepJob])
|
|
1109
|
+
|
|
1110
|
+
const items = (report && report.items) || []
|
|
1111
|
+
const chosen = items.filter((it) => selected.has(it.key))
|
|
1112
|
+
const chosenBytes = chosen.reduce((s, it) => s + (it.size || 0), 0)
|
|
1113
|
+
const chosenUnsure = chosen.filter((it) => it.tier !== 'safe').length
|
|
1114
|
+
|
|
1115
|
+
const askDelete = (list) => {
|
|
1116
|
+
const pick = Array.isArray(list) && list.length ? list : chosen
|
|
1117
|
+
if (!pick.length) return
|
|
1118
|
+
setDialog({
|
|
1119
|
+
kind: 'delete',
|
|
1120
|
+
keys: pick.map((it) => it.key),
|
|
1121
|
+
count: pick.length,
|
|
1122
|
+
bytes: pick.reduce((s, it) => s + (it.size || 0), 0),
|
|
1123
|
+
unsure: pick.filter((it) => it.tier !== 'safe').length,
|
|
1124
|
+
})
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
const doDelete = async () => {
|
|
1128
|
+
const d = dialog
|
|
1129
|
+
if (!d) return
|
|
1130
|
+
setBusy(true)
|
|
1131
|
+
try {
|
|
1132
|
+
const res = await post('/delete', {
|
|
1133
|
+
token: report && report.token,
|
|
1134
|
+
keys: d.keys,
|
|
1135
|
+
confirmed: true,
|
|
1136
|
+
acknowledge: d.unsure > 0,
|
|
1137
|
+
})
|
|
1138
|
+
setDialog(null)
|
|
1139
|
+
const moved = (res.batch && res.batch.count) || 0
|
|
1140
|
+
const failed = (res.failed || []).length
|
|
1141
|
+
const refused = (res.refused || []).length
|
|
1142
|
+
// A second tab can clean the same rows first. Those files are simply
|
|
1143
|
+
// gone from where the page thinks they are, and saying only "nothing
|
|
1144
|
+
// was moved" hides why — which is how a stale click looks frozen.
|
|
1145
|
+
const whyRefused = refused ? ',' + refused + ' 项已经不在原位(' + humanReason((res.refused[0] || {}).reason) + ')' : ''
|
|
1146
|
+
const whyFailed = failed ? ',' + failed + ' 个跳过(' + humanReason((res.failed[0] || {}).reason) + ')' : ''
|
|
1147
|
+
setToast({
|
|
1148
|
+
tone: moved ? (failed || refused ? 'warn' : 'success') : 'warn',
|
|
1149
|
+
text: moved
|
|
1150
|
+
? '已移到回收站:' + moved + ' 个文件(' + fmtBytes((res.batch && res.batch.bytes) || 0) + ')' + whyFailed + whyRefused
|
|
1151
|
+
: '没有文件被移动' + whyFailed + whyRefused,
|
|
1152
|
+
})
|
|
1153
|
+
setSelected(new Set())
|
|
1154
|
+
load(!!refused)
|
|
1155
|
+
loadTrash()
|
|
1156
|
+
} catch (err) {
|
|
1157
|
+
setDialog(null)
|
|
1158
|
+
// Refreshed elsewhere: the honest move is to re-read the list rather
|
|
1159
|
+
// than leave the page showing rows that no longer exist.
|
|
1160
|
+
if (err.status === 409 && err.data && err.data.stale) {
|
|
1161
|
+
setToast({ tone: 'warn', text: '这份列表在别处刷新过了,正在重新扫描…' })
|
|
1162
|
+
load(true)
|
|
1163
|
+
} else {
|
|
1164
|
+
setToast({ tone: 'danger', text: '清理失败:' + humanError(err) })
|
|
1165
|
+
}
|
|
1166
|
+
} finally { setBusy(false) }
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
const doRestore = async (id) => {
|
|
1170
|
+
setBusy(true)
|
|
1171
|
+
try {
|
|
1172
|
+
const res = await post('/restore', { batchId: id })
|
|
1173
|
+
setToast({
|
|
1174
|
+
tone: res.failed && res.failed.length ? 'warn' : 'success',
|
|
1175
|
+
text: '已恢复 ' + res.restored + ' 个文件' + (res.failed && res.failed.length ? ',' + res.failed.length + ' 个失败(' + humanReason(res.failed[0].reason) + ')' : ''),
|
|
1176
|
+
})
|
|
1177
|
+
loadTrash()
|
|
1178
|
+
setStatus('refreshing')
|
|
1179
|
+
scanStart.current = Date.now()
|
|
1180
|
+
load(true)
|
|
1181
|
+
} catch (err) {
|
|
1182
|
+
setToast({ tone: 'danger', text: '恢复失败:' + humanError(err) })
|
|
1183
|
+
} finally { setBusy(false) }
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
const doPurge = async () => {
|
|
1187
|
+
const d = dialog
|
|
1188
|
+
if (!d) return
|
|
1189
|
+
setBusy(true)
|
|
1190
|
+
try {
|
|
1191
|
+
await post('/purge', { batchId: d.batchId, confirmed: true })
|
|
1192
|
+
setDialog(null)
|
|
1193
|
+
setToast({ tone: 'success', text: '已彻底删除该批次,无法恢复。' })
|
|
1194
|
+
loadTrash()
|
|
1195
|
+
} catch (err) {
|
|
1196
|
+
// The batch can vanish between the click and the request (another
|
|
1197
|
+
// tab purged it, or the folder was removed by hand). Leaving the
|
|
1198
|
+
// dialog open with the same dead batch is a trap; close it and
|
|
1199
|
+
// refresh the list so the page matches the disk.
|
|
1200
|
+
if (err.status === 404) {
|
|
1201
|
+
setDialog(null)
|
|
1202
|
+
setToast({ tone: 'warn', text: '这一批已经不在回收站里了,正在刷新。' })
|
|
1203
|
+
loadTrash()
|
|
1204
|
+
} else {
|
|
1205
|
+
setToast({ tone: 'danger', text: '删除失败:' + humanError(err) })
|
|
1206
|
+
}
|
|
1207
|
+
} finally { setBusy(false) }
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
const runReview = async () => {
|
|
1211
|
+
if (!report || reviewing) return
|
|
1212
|
+
setReviewing(true)
|
|
1213
|
+
setReviewErr(null)
|
|
1214
|
+
reviewStart.current = Date.now()
|
|
1215
|
+
try {
|
|
1216
|
+
const res = await post('/review', { token: report.token })
|
|
1217
|
+
setReview(res)
|
|
1218
|
+
setExtraSel(new Set())
|
|
1219
|
+
setToast({
|
|
1220
|
+
tone: 'success',
|
|
1221
|
+
text: '模型判定完成:自动清理 ' + (res.moved || []).length + ' 项,待确认 ' + (res.asks || []).length + ' 项',
|
|
1222
|
+
})
|
|
1223
|
+
load(false, true)
|
|
1224
|
+
loadTrash()
|
|
1225
|
+
} catch (err) {
|
|
1226
|
+
setReviewErr(humanError(err))
|
|
1227
|
+
} finally {
|
|
1228
|
+
setReviewing(false)
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
const answerAsk = async (key, clean) => {
|
|
1233
|
+
if (!clean) { setReview((r) => (r ? { ...r, asks: (r.asks || []).filter((a) => a.key !== key) } : r)); return }
|
|
1234
|
+
setBusy(true)
|
|
1235
|
+
try {
|
|
1236
|
+
await post('/delete', { token: report && report.token, keys: [key], confirmed: true, acknowledge: true })
|
|
1237
|
+
setReview((r) => (r ? { ...r, asks: (r.asks || []).filter((a) => a.key !== key), moved: (r.moved || []).concat([key]) } : r))
|
|
1238
|
+
setToast({ tone: 'success', text: '已移到回收站,可在「回收站」里恢复。' })
|
|
1239
|
+
load(false)
|
|
1240
|
+
loadTrash()
|
|
1241
|
+
} catch (err) {
|
|
1242
|
+
setToast({ tone: 'danger', text: '清理失败:' + humanError(err) })
|
|
1243
|
+
} finally { setBusy(false) }
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
const toggleExtra = (key) => {
|
|
1247
|
+
setExtraSel((prev) => {
|
|
1248
|
+
const next = new Set(prev)
|
|
1249
|
+
if (next.has(key)) next.delete(key)
|
|
1250
|
+
else next.add(key)
|
|
1251
|
+
return next
|
|
1252
|
+
})
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
const cleanExtra = async (keys) => {
|
|
1256
|
+
const list = (keys || []).filter(Boolean)
|
|
1257
|
+
if (!list.length || !report) return
|
|
1258
|
+
setBusy(true)
|
|
1259
|
+
try {
|
|
1260
|
+
const res = await post('/delete', { token: report.token, keys: list, confirmed: true, extra: true, acknowledge: true })
|
|
1261
|
+
const gone = new Set(res.moved || [])
|
|
1262
|
+
setReview((r) => {
|
|
1263
|
+
if (!r || !r.extra) return r
|
|
1264
|
+
return {
|
|
1265
|
+
...r,
|
|
1266
|
+
extra: {
|
|
1267
|
+
...r.extra,
|
|
1268
|
+
sweep: (r.extra.sweep || []).filter((x) => !gone.has(x.key)),
|
|
1269
|
+
optional: (r.extra.optional || []).filter((x) => !gone.has(x.key)),
|
|
1270
|
+
},
|
|
1271
|
+
}
|
|
1272
|
+
})
|
|
1273
|
+
setExtraSel((prev) => new Set([...prev].filter((k) => !gone.has(k))))
|
|
1274
|
+
const n = (res.batch && res.batch.count) || 0
|
|
1275
|
+
setToast({
|
|
1276
|
+
tone: n ? 'success' : 'warn',
|
|
1277
|
+
text: n ? '已移到回收站:' + n + ' 个文件' + (res.failed && res.failed.length ? ',' + res.failed.length + ' 个跳过' : '') : '没有文件被移动',
|
|
1278
|
+
})
|
|
1279
|
+
loadTrash()
|
|
1280
|
+
} catch (err) {
|
|
1281
|
+
setToast({ tone: 'danger', text: '清理失败:' + humanError(err) })
|
|
1282
|
+
} finally { setBusy(false) }
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
const startDeep = async () => {
|
|
1286
|
+
if (startingRef.current) return
|
|
1287
|
+
if (!report || (deepJob && deepJob.state === 'running')) return
|
|
1288
|
+
startingRef.current = true
|
|
1289
|
+
setDeepErr(null)
|
|
1290
|
+
setDeepSel(new Set())
|
|
1291
|
+
try {
|
|
1292
|
+
const res = await post('/deep/start', { token: report.token, consent: true })
|
|
1293
|
+
if (!res.jobId) {
|
|
1294
|
+
setToast({ tone: 'warn', text: res.reason || '没有需要分析的对话' })
|
|
1295
|
+
return
|
|
1296
|
+
}
|
|
1297
|
+
setDeepJob({
|
|
1298
|
+
id: res.jobId, state: 'running', week: report.weekDays, concurrency: res.concurrency,
|
|
1299
|
+
totals: { sessions: res.sessions, done: 0, failed: 0, estTokens: res.estTokens, candidates: 0 },
|
|
1300
|
+
sessions: [], sweep: [], optional: [], rejected: [],
|
|
1301
|
+
})
|
|
1302
|
+
const d = await getJSON('/deep/status')
|
|
1303
|
+
if (d && d.job) setDeepJob(d.job)
|
|
1304
|
+
} catch (err) {
|
|
1305
|
+
setDeepErr(humanError(err))
|
|
1306
|
+
} finally {
|
|
1307
|
+
startingRef.current = false
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
const cancelDeep = async () => {
|
|
1312
|
+
if (!deepJob || deepJob.state !== 'running') return
|
|
1313
|
+
try {
|
|
1314
|
+
await post('/deep/cancel', { jobId: deepJob.id })
|
|
1315
|
+
setToast({ tone: 'warn', text: '已停止深度分析,已经返回的结果仍会保留。' })
|
|
1316
|
+
const d = await getJSON('/deep/status')
|
|
1317
|
+
if (d && d.job) setDeepJob(d.job)
|
|
1318
|
+
} catch (err) {
|
|
1319
|
+
setDeepErr(humanError(err))
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
const toggleDeep = (item, on) => {
|
|
1324
|
+
setDeepSel((prev) => {
|
|
1325
|
+
const next = new Set(prev)
|
|
1326
|
+
if (on) next.add(item.key)
|
|
1327
|
+
else next.delete(item.key)
|
|
1328
|
+
return next
|
|
1329
|
+
})
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
const selectDeep = (list, on) => {
|
|
1333
|
+
setDeepSel((prev) => {
|
|
1334
|
+
const next = new Set(prev)
|
|
1335
|
+
for (const it of list) { if (on) next.add(it.key); else next.delete(it.key) }
|
|
1336
|
+
return next
|
|
1337
|
+
})
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
const askDeepClean = (keys) => {
|
|
1341
|
+
const list = (keys || [...deepSel]).filter(Boolean)
|
|
1342
|
+
if (!list.length) return
|
|
1343
|
+
const known = new Map([].concat((deepJob && deepJob.sweep) || [], (deepJob && deepJob.optional) || []).map((it) => [it.key, it]))
|
|
1344
|
+
const picked = list.map((k) => known.get(k)).filter(Boolean)
|
|
1345
|
+
// The list can move under a stale selection (another tab cleaned, a
|
|
1346
|
+
// rescan replaced the job). Opening "move 0 files?" is a dead end, so
|
|
1347
|
+
// say what happened instead.
|
|
1348
|
+
if (!picked.length) {
|
|
1349
|
+
setToast({ tone: 'warn', text: '这些条目已经不在当前结果里了,正在重新估算。' })
|
|
1350
|
+
loadDeepPlan(true)
|
|
1351
|
+
setDeepSel(new Set())
|
|
1352
|
+
return
|
|
1353
|
+
}
|
|
1354
|
+
setDialog({
|
|
1355
|
+
kind: 'deepDelete',
|
|
1356
|
+
keys: list,
|
|
1357
|
+
count: picked.length,
|
|
1358
|
+
bytes: picked.reduce((n, it) => n + (it.size || 0), 0),
|
|
1359
|
+
unsure: picked.filter((it) => it.tier !== 'safe').length,
|
|
1360
|
+
})
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
const doDeepClean = async () => {
|
|
1364
|
+
const d = dialog
|
|
1365
|
+
if (!d) return
|
|
1366
|
+
setBusy(true)
|
|
1367
|
+
try {
|
|
1368
|
+
const res = await post('/delete', {
|
|
1369
|
+
token: report && report.token, keys: d.keys, confirmed: true, deep: true, acknowledge: true,
|
|
1370
|
+
})
|
|
1371
|
+
if (res.deep) setDeepJob(res.deep)
|
|
1372
|
+
setDeepSel((prev) => new Set([...prev].filter((k) => !d.keys.includes(k))))
|
|
1373
|
+
setDialog(null)
|
|
1374
|
+
const n = (res.batch && res.batch.count) || 0
|
|
1375
|
+
setToast({
|
|
1376
|
+
tone: n ? 'success' : 'warn',
|
|
1377
|
+
text: n
|
|
1378
|
+
? '已移到回收站:' + n + ' 个文件(' + fmtBytes((res.batch && res.batch.bytes) || 0) + ')'
|
|
1379
|
+
: '没有文件被移动' + (res.refused && res.refused.length ? ':' + humanReason(res.refused[0].reason) : ''),
|
|
1380
|
+
})
|
|
1381
|
+
loadTrash()
|
|
1382
|
+
} catch (err) {
|
|
1383
|
+
setDialog(null)
|
|
1384
|
+
setToast({ tone: 'danger', text: '清理失败:' + humanError(err) })
|
|
1385
|
+
} finally { setBusy(false) }
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
const exportJSON = () => {
|
|
1389
|
+
try {
|
|
1390
|
+
const blob = new Blob([JSON.stringify(report, null, 2)], { type: 'application/json' })
|
|
1391
|
+
const a = document.createElement('a')
|
|
1392
|
+
a.href = URL.createObjectURL(blob)
|
|
1393
|
+
a.download = 'dsh-sweeper-report-' + new Date().toISOString().slice(0, 10) + '.json'
|
|
1394
|
+
a.click()
|
|
1395
|
+
setTimeout(() => URL.revokeObjectURL(a.href), 5000)
|
|
1396
|
+
setToast({ tone: 'success', text: '报告已导出。' })
|
|
1397
|
+
} catch (e) { setToast({ tone: 'danger', text: '导出失败:' + humanError(e) }) }
|
|
1398
|
+
}
|
|
1399
|
+
|
|
1400
|
+
const deepAll = [].concat((deepJob && deepJob.sweep) || [], (deepJob && deepJob.optional) || [])
|
|
1401
|
+
const deepChosen = deepAll.filter((it) => deepSel.has(it.key))
|
|
1402
|
+
const counts = {
|
|
1403
|
+
report: items.length,
|
|
1404
|
+
review: review ? review.asks.length : null,
|
|
1405
|
+
// Before a run the useful number is how many conversations are waiting;
|
|
1406
|
+
// afterwards it is how many candidates the model found.
|
|
1407
|
+
deep: deepJob ? deepAll.length : (deepPlan ? (deepPlan.sessions || []).length : null),
|
|
1408
|
+
trash: trash.batches.length,
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
const tabs = [
|
|
1412
|
+
{ id: 'report', label: '扫描结果', count: counts.report },
|
|
1413
|
+
{ id: 'review', label: '模型复核', count: counts.review },
|
|
1414
|
+
{ id: 'deep', label: '深度清理', count: counts.deep },
|
|
1415
|
+
{ id: 'trash', label: '回收站', count: counts.trash },
|
|
1416
|
+
]
|
|
1417
|
+
|
|
1418
|
+
return h('div', { className: 'sw-root', style: { padding: '16px 18px 96px', maxWidth: 1000 } },
|
|
1419
|
+
// header
|
|
1420
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 12 } },
|
|
1421
|
+
h('div', {
|
|
1422
|
+
style: {
|
|
1423
|
+
width: 40, height: 40, borderRadius: 12, display: 'grid', placeItems: 'center', flex: 'none',
|
|
1424
|
+
background: 'linear-gradient(160deg, rgba(59,110,245,.18), rgba(59,110,245,.05))',
|
|
1425
|
+
border: '1px solid ' + T.border, color: T.accent,
|
|
1426
|
+
},
|
|
1427
|
+
}, h(Icon, { name: 'broom', size: 20 })),
|
|
1428
|
+
h('div', { style: { minWidth: 0 } },
|
|
1429
|
+
h('div', { style: { fontSize: 17, fontWeight: 650, letterSpacing: '-.01em' } }, '清理对话垃圾'),
|
|
1430
|
+
h('div', { style: { fontSize: 11.5, color: T.faint, marginTop: 1 } },
|
|
1431
|
+
'扫描工具执行流留下的文件 · 模型按对话判断 · 清理进回收站,随时撤销')),
|
|
1432
|
+
h('div', { style: { flex: 1 } }),
|
|
1433
|
+
h(Btn, {
|
|
1434
|
+
label: scanning ? '扫描中…' : '重新扫描',
|
|
1435
|
+
icon: h(Icon, { name: 'refresh', size: 14 }),
|
|
1436
|
+
onClick: () => load(true),
|
|
1437
|
+
disabled: scanning,
|
|
1438
|
+
}),
|
|
1439
|
+
report ? h(Btn, { label: '导出', icon: h(Icon, { name: 'download', size: 14 }), onClick: exportJSON, disabled: scanning }) : null,
|
|
1440
|
+
),
|
|
1441
|
+
|
|
1442
|
+
// stats
|
|
1443
|
+
h('div', { style: { display: 'grid', gridTemplateColumns: 'repeat(auto-fit,minmax(160px,1fr))', gap: 10, marginTop: 16 } },
|
|
1444
|
+
h(Stat, {
|
|
1445
|
+
label: '无脑删', tone: 'success',
|
|
1446
|
+
value: report ? fmtNum(report.tiers.safe.count) + ' 项' : '—',
|
|
1447
|
+
sub: report ? fmtBytes(report.tiers.safe.bytes) + ' · 可直接清理' : '等待扫描',
|
|
1448
|
+
}),
|
|
1449
|
+
h(Stat, {
|
|
1450
|
+
label: '需要确认', tone: 'warn',
|
|
1451
|
+
value: report ? fmtNum(report.tiers.unsure.count) + ' 项' : '—',
|
|
1452
|
+
sub: report ? fmtBytes(report.tiers.unsure.bytes) + ' · 逐项勾选' : '等待扫描',
|
|
1453
|
+
}),
|
|
1454
|
+
h(Stat, {
|
|
1455
|
+
label: '受保护',
|
|
1456
|
+
value: report ? fmtNum(report.protected.recent + report.protected.live + report.protected.tracked + (report.protected.unsafe || 0)) : '—',
|
|
1457
|
+
sub: report ? report.weekDays + ' 天内用过 / 活跃会话 / git 跟踪' : '等待扫描',
|
|
1458
|
+
}),
|
|
1459
|
+
h(Stat, {
|
|
1460
|
+
label: '回收站',
|
|
1461
|
+
value: trashErr ? '—' : trash.batches.length ? fmtNum(trash.batches.reduce((s, b) => s + b.count, 0)) + ' 个文件' : '空',
|
|
1462
|
+
sub: trashErr ? '读取失败,点「回收站」重试' : trash.batches.length ? fmtBytes(trash.batches.reduce((s, b) => s + b.bytes, 0)) + ' · ' + trash.batches.length + ' 个批次' : '没有待恢复的内容',
|
|
1463
|
+
}),
|
|
1464
|
+
),
|
|
1465
|
+
|
|
1466
|
+
// tabs
|
|
1467
|
+
h('div', { style: { display: 'flex', alignItems: 'center', gap: 10, marginTop: 16, flexWrap: 'wrap' } },
|
|
1468
|
+
h('div', { className: 'sw-tabbar', role: 'tablist' },
|
|
1469
|
+
tabs.map((t) => h('button', {
|
|
1470
|
+
key: t.id,
|
|
1471
|
+
type: 'button',
|
|
1472
|
+
role: 'tab',
|
|
1473
|
+
'aria-selected': tab === t.id,
|
|
1474
|
+
className: 'sw-tab',
|
|
1475
|
+
'data-on': tab === t.id ? '1' : '0',
|
|
1476
|
+
onClick: () => {
|
|
1477
|
+
setTab(t.id)
|
|
1478
|
+
if (t.id === 'trash') loadTrash()
|
|
1479
|
+
if (t.id === 'deep' && !deepPlan && !deepPlanning) loadDeepPlan(false)
|
|
1480
|
+
},
|
|
1481
|
+
}, t.label + (t.count ? ' ' + t.count : '')))),
|
|
1482
|
+
h('div', { style: { flex: 1 } }),
|
|
1483
|
+
report && report.truncated ? h('span', { style: { fontSize: 11, color: T.warn } }, '结果超过 2000 条,只列出最大的部分') : null,
|
|
1484
|
+
),
|
|
1485
|
+
|
|
1486
|
+
tab === 'report' ? h(ReportPanel, {
|
|
1487
|
+
report, status, error, selected, setSelected,
|
|
1488
|
+
onScan: () => load(true),
|
|
1489
|
+
onDelete: askDelete,
|
|
1490
|
+
onExport: exportJSON,
|
|
1491
|
+
scanStartedAt: scanStart.current,
|
|
1492
|
+
}) : null,
|
|
1493
|
+
|
|
1494
|
+
tab === 'review' ? h(ModelPanel, {
|
|
1495
|
+
report, review, reviewing, error: reviewErr, reviewStartedAt: reviewStart.current,
|
|
1496
|
+
extraSelected: extraSel, onToggleExtra: toggleExtra, onCleanExtra: cleanExtra,
|
|
1497
|
+
onRun: runReview,
|
|
1498
|
+
onAnswer: answerAsk,
|
|
1499
|
+
onGoTrash: () => { setTab('trash'); loadTrash() },
|
|
1500
|
+
}) : null,
|
|
1501
|
+
|
|
1502
|
+
tab === 'deep' ? h(DeepPanel, {
|
|
1503
|
+
plan: deepPlan, job: deepJob, busy, error: deepErr, consent: deepConsent, planning: deepPlanning,
|
|
1504
|
+
onConsent: setDeepConsent, onPlan: loadDeepPlan, onStart: startDeep, onCancel: cancelDeep,
|
|
1505
|
+
selected: deepSel, onToggle: toggleDeep, onSelectAll: selectDeep, onClean: askDeepClean,
|
|
1506
|
+
}) : null,
|
|
1507
|
+
|
|
1508
|
+
tab === 'trash' ? h(TrashPanel, {
|
|
1509
|
+
batches: trash.batches, root: trash.root, busy, error: trashErr,
|
|
1510
|
+
onRestore: doRestore,
|
|
1511
|
+
onPurge: (b) => setDialog({ kind: 'purge', batchId: b.id, count: b.count, bytes: b.bytes, damaged: !!b.damaged }),
|
|
1512
|
+
onRefresh: loadTrash,
|
|
1513
|
+
}) : null,
|
|
1514
|
+
|
|
1515
|
+
// selection bar
|
|
1516
|
+
tab === 'report' && chosen.length ? h('div', {
|
|
1517
|
+
style: {
|
|
1518
|
+
position: 'sticky', bottom: 14, marginTop: 16, padding: '10px 12px 10px 16px', borderRadius: 12,
|
|
1519
|
+
border: '1px solid ' + T.borderStrong, background: T.overlay,
|
|
1520
|
+
display: 'flex', alignItems: 'center', gap: 10, boxShadow: '0 14px 34px rgba(0,0,0,.3)',
|
|
1521
|
+
},
|
|
1522
|
+
},
|
|
1523
|
+
h('div', { style: { fontSize: 12.5 } },
|
|
1524
|
+
'已选 ', h('b', { className: 'sw-num' }, String(chosen.length)), ' 项 · ', h('span', { className: 'sw-num' }, fmtBytes(chosenBytes)),
|
|
1525
|
+
chosenUnsure ? h('span', { style: { color: T.warn } }, '(含 ' + chosenUnsure + ' 项待确认)') : null),
|
|
1526
|
+
h('div', { style: { flex: 1 } }),
|
|
1527
|
+
h(Btn, { label: '取消选择', kind: 'quiet', onClick: () => setSelected(new Set()) }),
|
|
1528
|
+
h(Btn, { label: '移到回收站', kind: 'primary', icon: h(Icon, { name: 'trash', size: 14 }), onClick: () => askDelete(), disabled: busy }),
|
|
1529
|
+
) : null,
|
|
1530
|
+
|
|
1531
|
+
tab === 'deep' && deepChosen.length ? h('div', {
|
|
1532
|
+
style: {
|
|
1533
|
+
position: 'sticky', bottom: 14, marginTop: 16, padding: '10px 12px 10px 16px', borderRadius: 12,
|
|
1534
|
+
border: '1px solid ' + T.borderStrong, background: T.overlay,
|
|
1535
|
+
display: 'flex', alignItems: 'center', gap: 10, boxShadow: '0 14px 34px rgba(0,0,0,.3)',
|
|
1536
|
+
},
|
|
1537
|
+
},
|
|
1538
|
+
h('div', { style: { fontSize: 12.5 } },
|
|
1539
|
+
'已选 ', h('b', { className: 'sw-num' }, String(deepChosen.length)), ' 项 · ', h('span', { className: 'sw-num' }, fmtBytes(deepChosen.reduce((n, it) => n + (it.size || 0), 0)))),
|
|
1540
|
+
h('div', { style: { flex: 1 } }),
|
|
1541
|
+
h(Btn, { label: '取消选择', kind: 'quiet', onClick: () => setDeepSel(new Set()) }),
|
|
1542
|
+
h(Btn, { label: '移到回收站', kind: 'primary', icon: h(Icon, { name: 'trash', size: 14 }), onClick: () => askDeepClean(), disabled: busy }),
|
|
1543
|
+
) : null,
|
|
1544
|
+
|
|
1545
|
+
toast ? h(Toast, { text: typeof toast === 'string' ? toast : toast.text, tone: toast.tone }) : null,
|
|
1546
|
+
|
|
1547
|
+
dialog && dialog.kind === 'delete' ? h(Modal, {
|
|
1548
|
+
title: '把 ' + dialog.count + ' 个文件移到回收站?',
|
|
1549
|
+
description: fmtBytes(dialog.bytes) + (dialog.unsure ? ' · 其中 ' + dialog.unsure + ' 项属于「不确定」' : ''),
|
|
1550
|
+
confirmLabel: '移到回收站',
|
|
1551
|
+
kind: 'primary',
|
|
1552
|
+
busy,
|
|
1553
|
+
onCancel: () => { if (!busy) setDialog(null) },
|
|
1554
|
+
onConfirm: doDelete,
|
|
1555
|
+
},
|
|
1556
|
+
h('div', { style: { display: 'flex', gap: 8, alignItems: 'center', fontSize: 12, color: T.faint, marginBottom: 8 } },
|
|
1557
|
+
h(Icon, { name: 'shield', size: 14 }),
|
|
1558
|
+
'不是永久删除:文件会被移进插件的回收站,随时可以整批恢复。'),
|
|
1559
|
+
h('div', { className: 'sw-mono', style: { fontSize: 11, color: T.faint, wordBreak: 'break-all', background: T.layer, border: '1px solid ' + T.border, borderRadius: 8, padding: '8px 10px' } },
|
|
1560
|
+
(report && report.trashRoot) || 'DSH_HOME/plugin-data/dsh-sweeper/trash'),
|
|
1561
|
+
dialog.unsure ? h('div', { style: { color: T.warn, marginTop: 8, fontSize: 12 } },
|
|
1562
|
+
'注意:选中的 ' + dialog.unsure + ' 项被引用过,或产生它的调用失败过,可能是你还要用的半成品。') : null,
|
|
1563
|
+
) : null,
|
|
1564
|
+
|
|
1565
|
+
dialog && dialog.kind === 'deepDelete' ? h(Modal, {
|
|
1566
|
+
title: '把 ' + dialog.count + ' 个文件移到回收站?',
|
|
1567
|
+
description: fmtBytes(dialog.bytes) + ' · 模型从闲置对话里挑出来的' + (dialog.unsure ? '(含 ' + dialog.unsure + ' 项可选清理)' : ''),
|
|
1568
|
+
confirmLabel: '移到回收站',
|
|
1569
|
+
kind: 'primary',
|
|
1570
|
+
busy,
|
|
1571
|
+
onCancel: () => { if (!busy) setDialog(null) },
|
|
1572
|
+
onConfirm: doDeepClean,
|
|
1573
|
+
},
|
|
1574
|
+
h('div', { style: { display: 'flex', gap: 8, alignItems: 'center', fontSize: 12, color: T.faint, marginBottom: 8 } },
|
|
1575
|
+
h(Icon, { name: 'shield', size: 14 }),
|
|
1576
|
+
'不是永久删除:文件会被移进插件的回收站,随时可以整批恢复。'),
|
|
1577
|
+
h('div', { style: { fontSize: 11.5, color: T.faint, lineHeight: 1.7 } },
|
|
1578
|
+
'这一步只使用模型给出的结论;文件是否仍然存在、大小是否没变、是否被 git 跟踪,都在点按钮这一刻重新核对过。'),
|
|
1579
|
+
) : null,
|
|
1580
|
+
|
|
1581
|
+
dialog && dialog.kind === 'purge' ? h(Modal, {
|
|
1582
|
+
title: '彻底删除这个批次?',
|
|
1583
|
+
description: (dialog.count || 0) + ' 个文件 · ' + fmtBytes(dialog.bytes || 0),
|
|
1584
|
+
confirmLabel: '永久删除',
|
|
1585
|
+
kind: 'danger',
|
|
1586
|
+
busy,
|
|
1587
|
+
onCancel: () => { if (!busy) setDialog(null) },
|
|
1588
|
+
onConfirm: doPurge,
|
|
1589
|
+
},
|
|
1590
|
+
dialog.damaged
|
|
1591
|
+
? '这一批的清单读不出来,没法再放回原来的位置,只能整批删除。删除后无法恢复。'
|
|
1592
|
+
: '这一批文件会从磁盘上真正删除,无法恢复。如果只是暂时不用,建议关掉这个窗口,让它们继续留在回收站里。',
|
|
1593
|
+
) : null,
|
|
1594
|
+
)
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
// ── error boundary: never leave the settings page blank ─────────────────
|
|
1598
|
+
class Boundary extends React.Component {
|
|
1599
|
+
constructor(props) {
|
|
1600
|
+
super(props)
|
|
1601
|
+
this.state = { error: null }
|
|
1602
|
+
}
|
|
1603
|
+
static getDerivedStateFromError(error) { return { error } }
|
|
1604
|
+
render() {
|
|
1605
|
+
if (!this.state.error) return this.props.children
|
|
1606
|
+
return h('div', { className: 'sw-root', style: { padding: 20, color: T.danger, fontSize: 13 } },
|
|
1607
|
+
h('div', { style: { fontWeight: 600, marginBottom: 6 } }, '页面渲染出错'),
|
|
1608
|
+
h('div', { className: 'sw-mono', style: { fontSize: 11, color: T.faint, whiteSpace: 'pre-wrap' } }, String(this.state.error && this.state.error.message || this.state.error)),
|
|
1609
|
+
h('div', { style: { marginTop: 10 } }, h(Btn, { label: '重新加载', onClick: () => location.reload() })),
|
|
1610
|
+
)
|
|
1611
|
+
}
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
function BroomIcon(props) {
|
|
1615
|
+
const s = (props && props.size) || 16
|
|
1616
|
+
return h('svg', { width: s, height: s, viewBox: '0 0 24 24', fill: 'none', 'aria-hidden': true },
|
|
1617
|
+
h('path', { d: 'M14.2 3.2l6.6 6.6-2.6 2.6-6.6-6.6 2.6-2.6z', stroke: 'currentColor', strokeWidth: 1.7, strokeLinejoin: 'round' }),
|
|
1618
|
+
h('path', { d: 'M11.2 13.4l-6.4 6.4a1.5 1.5 0 002.1 2.1l6.4-6.4', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round' }),
|
|
1619
|
+
h('path', { d: 'M9.4 17.2l-1.5 1.5M12.4 20.2l-1.5 1.5', stroke: 'currentColor', strokeWidth: 1.7, strokeLinecap: 'round' }))
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
return {
|
|
1623
|
+
inject: ['slots'],
|
|
1624
|
+
apply(ctx) {
|
|
1625
|
+
ctx.slots.inject('settings.section', () => ctx.slots.register({
|
|
1626
|
+
name: 'settings.section',
|
|
1627
|
+
id: 'dsh-sweeper',
|
|
1628
|
+
order: 35,
|
|
1629
|
+
label: () => '清理对话垃圾',
|
|
1630
|
+
}, () => h(Boundary, null, h(Page))))
|
|
1631
|
+
|
|
1632
|
+
ctx.slots.inject('settings.section.icon', () => ctx.slots.register({
|
|
1633
|
+
name: 'settings.section.icon',
|
|
1634
|
+
id: 'dsh-sweeper',
|
|
1635
|
+
}, BroomIcon))
|
|
1636
|
+
},
|
|
1637
|
+
}
|
|
1638
|
+
},
|
|
1639
|
+
})
|