dsh-aupdate 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -1
- package/client.js +19 -12
- package/index.js +169 -53
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -154,7 +154,10 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
|
|
|
154
154
|
- **最新的在最上面**:按时间倒序渲染,刚装了什么不用滚到底
|
|
155
155
|
- 时间只到「月-日 时:分:秒」并等宽对齐,省下的宽度留给正文
|
|
156
156
|
- **正文跟着「显示语言」走**:文件里存的是事件码和参数,不是成品句子,所以在中文与
|
|
157
|
-
English 之间切换后,连历史行都会跟着变;0.6.
|
|
157
|
+
English 之间切换后,连历史行都会跟着变;0.6.2 之前写下的旧行是句子,原样保留
|
|
158
|
+
- **原因也是事件**:「上一次」的原因、跳过安装的理由、就地生效的结果都存成
|
|
159
|
+
`{ code, args }`,由同一张模板表渲染,切语言一起变。pnpm 的报错、宿主要求重启、
|
|
160
|
+
锁持有者这类**不是我们写的**自由文本原样透出——翻译它们只会更迷惑
|
|
158
161
|
- 打开「自动刷新」后每 5 秒拉一次,正在排查时开着;关掉就完全不动
|
|
159
162
|
- 读之前会先把待写队列刷下去,所以刚点完检查,那几行马上就在里面
|
|
160
163
|
- 时间戳按本地时区显示,文件超过 1MB 轮转给一句提示,另附总行数
|
|
@@ -405,6 +408,11 @@ Log lines are stored as an event code plus its arguments, not as finished senten
|
|
|
405
408
|
switching **Display language** re-renders history too. Lines written before 0.6.2 are
|
|
406
409
|
sentences and stay exactly as they were.
|
|
407
410
|
|
|
411
|
+
Reasons are events as well: the last run's reason, why a package was skipped, and the
|
|
412
|
+
hot-apply outcome are all stored as `{ code, args }` and rendered from the same template
|
|
413
|
+
tables. Free text that we did not write — pnpm errors, a host-requested restart, the lock
|
|
414
|
+
holder — passes through untranslated, because translating it would only mislead.
|
|
415
|
+
|
|
408
416
|
You can read this file straight from the settings page (see above). Point it
|
|
409
417
|
elsewhere with `DSH_AUTO_UPDATE_LOG`.
|
|
410
418
|
|
package/client.js
CHANGED
|
@@ -336,8 +336,14 @@ window.__ModuleLoader__.load({
|
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
/** 后端按这个参数渲染原因文本(lastRun.reason 等),所以每个请求都要带上。 */
|
|
340
|
+
function langQuery() {
|
|
341
|
+
return '?lang=' + (LANG === 'en' ? 'en' : 'zh')
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
async function getState(lang) {
|
|
345
|
+
const wanted = lang === 'en' ? 'en' : 'zh'
|
|
346
|
+
const response = await fetch(endpoint('state') + '?lang=' + wanted, {
|
|
341
347
|
headers: { accept: 'application/json' },
|
|
342
348
|
cache: 'no-store',
|
|
343
349
|
})
|
|
@@ -357,7 +363,7 @@ window.__ModuleLoader__.load({
|
|
|
357
363
|
}
|
|
358
364
|
|
|
359
365
|
async function saveState(patch) {
|
|
360
|
-
const response = await fetch(endpoint('state'), {
|
|
366
|
+
const response = await fetch(endpoint('state') + langQuery(), {
|
|
361
367
|
method: 'POST',
|
|
362
368
|
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
363
369
|
body: JSON.stringify(patch),
|
|
@@ -367,7 +373,7 @@ window.__ModuleLoader__.load({
|
|
|
367
373
|
}
|
|
368
374
|
|
|
369
375
|
async function rollback(name) {
|
|
370
|
-
const response = await fetch(endpoint('rollback'), {
|
|
376
|
+
const response = await fetch(endpoint('rollback') + langQuery(), {
|
|
371
377
|
method: 'POST',
|
|
372
378
|
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
373
379
|
body: JSON.stringify({ name }),
|
|
@@ -377,7 +383,7 @@ window.__ModuleLoader__.load({
|
|
|
377
383
|
}
|
|
378
384
|
|
|
379
385
|
async function runNow(mode) {
|
|
380
|
-
const response = await fetch(endpoint('run'), {
|
|
386
|
+
const response = await fetch(endpoint('run') + langQuery(), {
|
|
381
387
|
method: 'POST',
|
|
382
388
|
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
383
389
|
body: JSON.stringify({ mode }),
|
|
@@ -616,7 +622,7 @@ window.__ModuleLoader__.load({
|
|
|
616
622
|
const load = useCallback(async () => {
|
|
617
623
|
setPhase('loading')
|
|
618
624
|
try {
|
|
619
|
-
const next = await getState()
|
|
625
|
+
const next = await getState(LANG)
|
|
620
626
|
// 语言先落地再渲染:否则第一屏会先按系统语言画一次,再跳成用户选的。
|
|
621
627
|
applyLang(next?.settings?.lang)
|
|
622
628
|
setState(next)
|
|
@@ -625,7 +631,8 @@ window.__ModuleLoader__.load({
|
|
|
625
631
|
} catch {
|
|
626
632
|
setPhase('error')
|
|
627
633
|
}
|
|
628
|
-
|
|
634
|
+
// LANG 进依赖:切换显示语言后要重新取一次,原因文本才是新语言的。
|
|
635
|
+
}, [LANG])
|
|
629
636
|
|
|
630
637
|
useEffect(() => { void load() }, [load])
|
|
631
638
|
|
|
@@ -694,7 +701,7 @@ window.__ModuleLoader__.load({
|
|
|
694
701
|
}
|
|
695
702
|
// 跑完把状态刷一遍,页面上看到的就是最新结果。
|
|
696
703
|
try {
|
|
697
|
-
const next = await getState()
|
|
704
|
+
const next = await getState(LANG)
|
|
698
705
|
setState(next)
|
|
699
706
|
setDraft((prev) => (prev === null ? next.settings : prev))
|
|
700
707
|
} catch {}
|
|
@@ -720,7 +727,7 @@ window.__ModuleLoader__.load({
|
|
|
720
727
|
const result = await rollback(target)
|
|
721
728
|
setRollHint(result.ok ? T.rollbackDone + ' · ' + target : T.rollbackFailed + ' · ' + (result.payload?.reason ?? ''))
|
|
722
729
|
try {
|
|
723
|
-
const next = await getState()
|
|
730
|
+
const next = await getState(LANG)
|
|
724
731
|
setState(next)
|
|
725
732
|
setDraft((prev) => (prev === null ? next.settings : prev))
|
|
726
733
|
} catch {}
|
|
@@ -956,12 +963,12 @@ window.__ModuleLoader__.load({
|
|
|
956
963
|
let alive = true
|
|
957
964
|
void (async () => {
|
|
958
965
|
try {
|
|
959
|
-
const next = await getState()
|
|
966
|
+
const next = await getState(LANG)
|
|
960
967
|
if (alive) setState(next)
|
|
961
968
|
} catch {}
|
|
962
969
|
})()
|
|
963
970
|
return () => { alive = false }
|
|
964
|
-
}, [])
|
|
971
|
+
}, [LANG])
|
|
965
972
|
const last = state?.lastRun
|
|
966
973
|
const text = state === null
|
|
967
974
|
? '…'
|
|
@@ -1055,7 +1062,7 @@ window.__ModuleLoader__.load({
|
|
|
1055
1062
|
const tick = async () => {
|
|
1056
1063
|
if (stopped) return
|
|
1057
1064
|
try {
|
|
1058
|
-
const state = await getState()
|
|
1065
|
+
const state = await getState(LANG)
|
|
1059
1066
|
if (state?.settings?.notify !== false) {
|
|
1060
1067
|
const updates = Array.isArray(state?.lastRun?.updates) ? state.lastRun.updates : []
|
|
1061
1068
|
if (updates.length > 0) {
|
package/index.js
CHANGED
|
@@ -104,8 +104,16 @@ function flushLog() {
|
|
|
104
104
|
|
|
105
105
|
/** 状态词。运行结果是数据(done/skipped/…),显示成哪种语言由读取侧决定。 */
|
|
106
106
|
const LOG_STATUS = {
|
|
107
|
-
zh: {
|
|
108
|
-
|
|
107
|
+
zh: {
|
|
108
|
+
done: '完成', blocked: '已让开', failed: '失败', skipped: '已跳过', none: '无', ok: '成功',
|
|
109
|
+
partial: '部分完成', busy: '正在跑', unavailable: '不可用', applying: '生效中',
|
|
110
|
+
restart: '需重启', cancelled: '已取消',
|
|
111
|
+
},
|
|
112
|
+
en: {
|
|
113
|
+
done: 'done', blocked: 'held off', failed: 'failed', skipped: 'skipped', none: 'none', ok: 'ok',
|
|
114
|
+
partial: 'partly done', busy: 'busy', unavailable: 'unavailable', applying: 'applying',
|
|
115
|
+
restart: 'restart needed', cancelled: 'cancelled',
|
|
116
|
+
},
|
|
109
117
|
}
|
|
110
118
|
|
|
111
119
|
/** 设置项在日志里的名字:enabled / autoApply 这种字面量不该出现在面板上。 */
|
|
@@ -187,6 +195,102 @@ function makeLogTemplates(lang) {
|
|
|
187
195
|
|
|
188
196
|
const LOG_TEMPLATES = { zh: makeLogTemplates('zh'), en: makeLogTemplates('en') }
|
|
189
197
|
|
|
198
|
+
/**
|
|
199
|
+
* 原因事件。
|
|
200
|
+
*
|
|
201
|
+
* 运行结果里的「为什么没装 / 为什么不动手」以前直接拼成中文句子:写进 lastRun、
|
|
202
|
+
* 拼进 report.reason、再喂给日志。语言一换,这些句子就是不动的中文,跟日志正文
|
|
203
|
+
* 对不上。所以原因也照日志的做法拆成 { code, args },渲染时才决定语言。
|
|
204
|
+
*
|
|
205
|
+
* 自由文本(pnpm 的报错、锁持有者、宿主给的 restart 原因)仍然是字符串:
|
|
206
|
+
* 那些不是我们写的话,翻译不了,原样透出比乱翻更诚实。
|
|
207
|
+
*/
|
|
208
|
+
function makeReasonTemplates(lang) {
|
|
209
|
+
const zh = lang !== 'en'
|
|
210
|
+
const sep = zh ? ';' : '; '
|
|
211
|
+
const ageText = (age) => {
|
|
212
|
+
if (typeof age !== 'number' || !Number.isFinite(age)) return zh ? '刚才' : 'just now'
|
|
213
|
+
return age < 1 ? (zh ? '不到 1' : 'under 1') : String(Math.round(age))
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
raw: (msg) => String(msg ?? ''),
|
|
217
|
+
uncomparable: () => (zh ? '版本号无法比较' : 'Versions are not comparable'),
|
|
218
|
+
latest: () => (zh ? '已经是最新' : 'Already up to date'),
|
|
219
|
+
prerelease: () => (zh ? '是预发布版本,未允许' : 'Prerelease, not allowed'),
|
|
220
|
+
major: (from, to) => (zh ? `跨大版本(${from} -> ${to}),未允许` : `Major version change (${from} -> ${to}), not allowed`),
|
|
221
|
+
noTag: (tag) => (zh ? `没有 ${tag} 标签` : `No ${tag} tag`),
|
|
222
|
+
noInstalled: () => (zh ? '读不到已装版本' : 'Installed version unreadable'),
|
|
223
|
+
suppressed: (stamp) => (zh ? `上次安装失败,${stamp} UTC 前不再重试` : `Install failed before; not retried until ${stamp} UTC`),
|
|
224
|
+
lookupFailed: (msg) => (zh ? `查不到:${msg}` : `Lookup failed: ${msg}`),
|
|
225
|
+
agentsBusy: (n) => (zh ? `${n} 个子任务在跑` : `${n} subagent(s) running`),
|
|
226
|
+
sessionActive: (age) => (zh ? `会话在 ${ageText(age)} 分钟前还在写入` : `Session was written ${ageText(age)} min ago`),
|
|
227
|
+
noDeps: () => (zh ? '这个 profile 里没有可检查的依赖' : 'No dependencies to check in this profile'),
|
|
228
|
+
noUpdates: () => (zh ? '没有可更新的插件' : 'No updatable plugins'),
|
|
229
|
+
checkOnly: () => (zh ? '只查不装' : 'Check only'),
|
|
230
|
+
gated: (reasons) => (zh
|
|
231
|
+
? `${listOf(reasons, sep)},这一轮不安装`
|
|
232
|
+
: `${listOf(reasons, sep)} — not installing this cycle`),
|
|
233
|
+
noCli: () => (zh ? '找不到 dsh 命令行入口,无法安装' : 'dsh CLI entry not found; cannot install'),
|
|
234
|
+
noneInstalled: () => (zh ? '一个包都没装成' : 'No package installed successfully'),
|
|
235
|
+
installedRestart: (n) => (zh ? `已安装 ${n} 个,待重启` : `Installed ${n}; restart pending`),
|
|
236
|
+
installedNoHot: (n) => (zh ? `已安装 ${n} 个,未热生效` : `Installed ${n}; not applied in place`),
|
|
237
|
+
installedWith: (n, reason) => (zh ? `已安装 ${n} 个;${reason}` : `Installed ${n}; ${reason}`),
|
|
238
|
+
reloadUnavailable: () => (zh ? '这里没有能换插件的服务,已装好但要重启才生效' : 'No hot-reload service here; installed, applies after restart'),
|
|
239
|
+
reloadApplying: () => (zh ? '换代码还没结束,稍后再看一次' : 'Hot apply still running; check again shortly'),
|
|
240
|
+
reloadQueued: () => (zh ? '换代码还在排队,稍后再看一次' : 'Hot apply still queued; check again shortly'),
|
|
241
|
+
reloadDone: () => (zh ? '插件已换好,界面没重开' : 'Plugins swapped; page not reloaded'),
|
|
242
|
+
reloadOff: () => (zh ? '装好了,热生效是关的,重启后生效' : 'Installed; in-place apply is off, applies after restart'),
|
|
243
|
+
reloadCancelled: () => (zh ? '安装期间有子任务开跑,这一次不换代码' : 'A subagent started during install; not swapping code'),
|
|
244
|
+
rollbackRestart: () => (zh ? '回滚完成,重启后生效' : 'Rollback done; applies after restart'),
|
|
245
|
+
lockHeld: (holder, age) => (zh
|
|
246
|
+
? `另一个进程正在装(${holder || '看不见持有者'}${typeof age === 'number' ? `,${age} 分钟前` : ''})`
|
|
247
|
+
: `Another process is installing (${holder || 'holder unknown'}${typeof age === 'number' ? `, ${age} min ago` : ''})`),
|
|
248
|
+
lockFailed: (msg) => (zh ? `抢锁失败:${msg}` : `Could not take the install lock: ${msg}`),
|
|
249
|
+
rollbackNoRecord: (name) => (zh ? `没有可回滚的记录:${name}` : `Nothing to roll back: ${name}`),
|
|
250
|
+
runBusy: () => (zh ? '上一轮还没跑完' : 'The previous cycle is still running'),
|
|
251
|
+
neverRun: () => (zh ? '还没跑过' : 'Never run'),
|
|
252
|
+
lastSummary: (at, reason) => (zh ? `上一次:${at};${reason}` : `Last run: ${at}; ${reason}`),
|
|
253
|
+
stateBroken: () => (zh ? '没能完成,插件状态需要核对' : 'Did not finish; plugin state needs a check'),
|
|
254
|
+
alreadyRunning: () => (zh ? '已经有一轮在跑' : 'A cycle is already running'),
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const REASON_TEMPLATES = { zh: makeReasonTemplates('zh'), en: makeReasonTemplates('en') }
|
|
259
|
+
|
|
260
|
+
function listOf(value, sep) {
|
|
261
|
+
if (Array.isArray(value)) return value.filter((item) => item !== '').join(sep)
|
|
262
|
+
return value === undefined || value === null ? '' : String(value)
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** 把参数里的原因对象就地翻成文字;数组要深挖,原因里可能嵌着原因。 */
|
|
266
|
+
function localizeArg(value, lang) {
|
|
267
|
+
if (Array.isArray(value)) return value.map((item) => localizeArg(item, lang))
|
|
268
|
+
if (value !== null && typeof value === 'object') {
|
|
269
|
+
if (typeof value.code === 'string') return renderReason(value, lang)
|
|
270
|
+
return value
|
|
271
|
+
}
|
|
272
|
+
return value
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* 渲染一条原因。字符串原样返回——那是我们翻译不了的自由文本。
|
|
277
|
+
*/
|
|
278
|
+
function renderReason(value, lang) {
|
|
279
|
+
if (value === null || value === undefined) return ''
|
|
280
|
+
if (typeof value === 'string') return value
|
|
281
|
+
if (typeof value !== 'object') return String(value)
|
|
282
|
+
const code = typeof value.code === 'string' ? value.code : ''
|
|
283
|
+
const table = REASON_TEMPLATES[logLangOf(lang)]
|
|
284
|
+
const render = table[code]
|
|
285
|
+
const args = Array.isArray(value.args) ? value.args.map((item) => localizeArg(item, lang)) : []
|
|
286
|
+
if (typeof render !== 'function') return '[' + code + '] ' + args.join(' ')
|
|
287
|
+
try {
|
|
288
|
+
return render(...args)
|
|
289
|
+
} catch {
|
|
290
|
+
return '[' + code + '] ' + args.join(' ')
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
190
294
|
/** 只认 zh / en;其余(含 undefined)按中文渲染。 */
|
|
191
295
|
function logLangOf(choice) {
|
|
192
296
|
return choice === 'en' ? 'en' : 'zh'
|
|
@@ -195,7 +299,8 @@ function logLangOf(choice) {
|
|
|
195
299
|
/** 渲染一条日志。认不出的 code 退化成一串参数,至少不丢信息。 */
|
|
196
300
|
function renderLogEntry(code, args, lang) {
|
|
197
301
|
const table = LOG_TEMPLATES[logLangOf(lang)]
|
|
198
|
-
|
|
302
|
+
// 参数里可能塞着原因对象(例如 skipInstall 的 why),先翻成文字再套模板。
|
|
303
|
+
const values = (Array.isArray(args) ? args : []).map((item) => localizeArg(item, lang))
|
|
199
304
|
const render = table[String(code)]
|
|
200
305
|
if (typeof render !== 'function') return '[' + String(code) + '] ' + values.join(' ')
|
|
201
306
|
try {
|
|
@@ -658,7 +763,10 @@ function readLastRun() {
|
|
|
658
763
|
updates: textList(raw.updates),
|
|
659
764
|
installed: textList(raw.installed),
|
|
660
765
|
reload: typeof raw.reload === 'string' ? raw.reload : 'none',
|
|
661
|
-
|
|
766
|
+
// 0.6.2 及更早存的是句子;0.6.3 起是 { code, args },两种都要能读。
|
|
767
|
+
reason: typeof raw.reason === 'string'
|
|
768
|
+
? raw.reason
|
|
769
|
+
: (raw.reason !== null && typeof raw.reason === 'object' ? raw.reason : ''),
|
|
662
770
|
snapshot: typeof raw.snapshot === 'string' ? raw.snapshot : '',
|
|
663
771
|
}
|
|
664
772
|
}
|
|
@@ -828,15 +936,15 @@ function suppressedUntil(pkgName, version, settings, now) {
|
|
|
828
936
|
function upgradeVerdict(target, current, tag, settings) {
|
|
829
937
|
const a = parseVersion(target)
|
|
830
938
|
const b = parseVersion(current)
|
|
831
|
-
if (a === null || b === null) return { ok: false, why: '
|
|
832
|
-
if (compareVersions(target, current) <= 0) return { ok: false, why: '
|
|
939
|
+
if (a === null || b === null) return { ok: false, code: 'uncomparable', why: { code: 'uncomparable' } }
|
|
940
|
+
if (compareVersions(target, current) <= 0) return { ok: false, code: 'latest', why: { code: 'latest' } }
|
|
833
941
|
// parseVersion 对正式版返回的是空数组而不是 null,判空得看长度。
|
|
834
942
|
if (a.pre.length > 0 && tag !== 'next' && !settings.allowPrerelease) {
|
|
835
|
-
return { ok: false, why: '
|
|
943
|
+
return { ok: false, code: 'prerelease', why: { code: 'prerelease' } }
|
|
836
944
|
}
|
|
837
945
|
// 版本段存在 core 里:core[0] 是主版本。
|
|
838
946
|
if (!settings.allowMajor && a.core[0] !== b.core[0]) {
|
|
839
|
-
return { ok: false, why: '
|
|
947
|
+
return { ok: false, code: 'major', why: { code: 'major', args: [b.core[0], a.core[0]] } }
|
|
840
948
|
}
|
|
841
949
|
return { ok: true }
|
|
842
950
|
}
|
|
@@ -1194,11 +1302,11 @@ function sessionAgeMinutes(now, root = null) {
|
|
|
1194
1302
|
function activityReasons(ctx, now, idleMinutes) {
|
|
1195
1303
|
const reasons = []
|
|
1196
1304
|
const agents = runningSubagents(ctx)
|
|
1197
|
-
if (agents.length > 0) reasons.push(agents.length
|
|
1305
|
+
if (agents.length > 0) reasons.push({ code: 'agentsBusy', args: [agents.length] })
|
|
1198
1306
|
if (!(idleMinutes > 0)) return reasons
|
|
1199
1307
|
const age = sessionAgeMinutes(now)
|
|
1200
1308
|
if (age !== null && age < idleMinutes) {
|
|
1201
|
-
reasons.push(
|
|
1309
|
+
reasons.push({ code: 'sessionActive', args: [age] })
|
|
1202
1310
|
}
|
|
1203
1311
|
return reasons
|
|
1204
1312
|
}
|
|
@@ -1287,7 +1395,7 @@ function takeProfileLock(profileDir, now) {
|
|
|
1287
1395
|
writeFileSync(file, stamp + '\n', { encoding: 'utf8', flag: 'wx' })
|
|
1288
1396
|
return { ok: true, file }
|
|
1289
1397
|
} catch (error) {
|
|
1290
|
-
if (error?.code !== 'EEXIST') return { ok: false, reason: oneLine(error?.message ?? error, 160) }
|
|
1398
|
+
if (error?.code !== 'EEXIST') return { ok: false, reason: { code: 'lockFailed', args: [oneLine(error?.message ?? error, 160)] } }
|
|
1291
1399
|
}
|
|
1292
1400
|
// 锁已存在:只有确认它过期(持有者崩了)才接管,否则老老实实让开。
|
|
1293
1401
|
let ageMinutes = null
|
|
@@ -1299,8 +1407,7 @@ function takeProfileLock(profileDir, now) {
|
|
|
1299
1407
|
if (ageMinutes === null || ageMinutes * 60000 <= LOCK_STALE_MS) {
|
|
1300
1408
|
return {
|
|
1301
1409
|
ok: false,
|
|
1302
|
-
reason:
|
|
1303
|
-
+ (ageMinutes === null ? '' : ',' + ageMinutes + ' 分钟前') + ')',
|
|
1410
|
+
reason: { code: 'lockHeld', args: [lockHolder(file), ageMinutes] },
|
|
1304
1411
|
}
|
|
1305
1412
|
}
|
|
1306
1413
|
try {
|
|
@@ -1311,7 +1418,7 @@ function takeProfileLock(profileDir, now) {
|
|
|
1311
1418
|
writeLog('tookOverLock', [ageMinutes])
|
|
1312
1419
|
return { ok: true, file }
|
|
1313
1420
|
} catch (error) {
|
|
1314
|
-
return { ok: false, reason: '
|
|
1421
|
+
return { ok: false, reason: { code: 'lockFailed', args: [oneLine(error?.message ?? error, 160)] } }
|
|
1315
1422
|
}
|
|
1316
1423
|
}
|
|
1317
1424
|
|
|
@@ -1362,7 +1469,7 @@ function activeEntryIds(ctx) {
|
|
|
1362
1469
|
async function hotApply(ctx, requiredBefore) {
|
|
1363
1470
|
const hmr = serviceOf(ctx, 'hmr')
|
|
1364
1471
|
if (hmr === null || typeof hmr.reconcileProfile !== 'function' || typeof hmr.runExclusive !== 'function') {
|
|
1365
|
-
return { status: 'unavailable', reason: '
|
|
1472
|
+
return { status: 'unavailable', reason: { code: 'reloadUnavailable' } }
|
|
1366
1473
|
}
|
|
1367
1474
|
const context = transactionContext(hmr)
|
|
1368
1475
|
const baseline = requiredBefore.filter((id) => id !== name)
|
|
@@ -1382,14 +1489,14 @@ async function hotApply(ctx, requiredBefore) {
|
|
|
1382
1489
|
for (let attempt = 0; ; attempt += 1) {
|
|
1383
1490
|
try {
|
|
1384
1491
|
result = await Promise.race([run(), timeout])
|
|
1385
|
-
if (timedOut) return { status: 'applying', reason: '
|
|
1492
|
+
if (timedOut) return { status: 'applying', reason: { code: 'reloadApplying' } }
|
|
1386
1493
|
break
|
|
1387
1494
|
} catch (error) {
|
|
1388
1495
|
if (isNestedTransaction(error) && attempt < 9) {
|
|
1389
1496
|
await new Promise((resolvePromise) => {
|
|
1390
1497
|
setTimeout(resolvePromise, 250 * (attempt + 1))
|
|
1391
1498
|
})
|
|
1392
|
-
if (timedOut) return { status: 'applying', reason: '
|
|
1499
|
+
if (timedOut) return { status: 'applying', reason: { code: 'reloadQueued' } }
|
|
1393
1500
|
continue
|
|
1394
1501
|
}
|
|
1395
1502
|
throw error
|
|
@@ -1399,7 +1506,7 @@ async function hotApply(ctx, requiredBefore) {
|
|
|
1399
1506
|
const restartReason = typeof result?.restartReason === 'string' ? result.restartReason : null
|
|
1400
1507
|
if (restartReason !== null) return { status: 'restart', reason: oneLine(restartReason, 400), warnings }
|
|
1401
1508
|
if (warnings.length > 0) return { status: 'blocked', reason: oneLine(warnings[0], 400), warnings }
|
|
1402
|
-
return { status: 'done', reason: '
|
|
1509
|
+
return { status: 'done', reason: { code: 'reloadDone' }, warnings }
|
|
1403
1510
|
} catch (error) {
|
|
1404
1511
|
return { status: 'failed', reason: oneLine(error?.message ?? error, 400) }
|
|
1405
1512
|
}
|
|
@@ -1433,7 +1540,7 @@ async function runCycle(mode, ctxRef) {
|
|
|
1433
1540
|
const deps = dependencyList(profileDir, settings.exclude)
|
|
1434
1541
|
report.checked = deps.length
|
|
1435
1542
|
if (deps.length === 0) {
|
|
1436
|
-
report.reason =
|
|
1543
|
+
report.reason = { code: 'noDeps' }
|
|
1437
1544
|
return report
|
|
1438
1545
|
}
|
|
1439
1546
|
for (let i = 0; i < deps.length; i += FETCH_CONCURRENCY) {
|
|
@@ -1447,12 +1554,12 @@ async function runCycle(mode, ctxRef) {
|
|
|
1447
1554
|
const tags = await registryTags(dep.name)
|
|
1448
1555
|
const tag = distTagFor(dep.name)
|
|
1449
1556
|
const target = typeof tags[tag] === 'string' ? tags[tag] : null
|
|
1450
|
-
if (target === null) return { name: dep.name, current, why:
|
|
1451
|
-
if (current === null) return { name: dep.name, current, why: '
|
|
1557
|
+
if (target === null) return { name: dep.name, current, why: { code: 'noTag', args: [tag] } }
|
|
1558
|
+
if (current === null) return { name: dep.name, current, why: { code: 'noInstalled' } }
|
|
1452
1559
|
const verdict = upgradeVerdict(target, current, tag, settings)
|
|
1453
1560
|
if (!verdict.ok) {
|
|
1454
1561
|
// 「已经是最新」不算异常,不必出现在 skipped 里。
|
|
1455
|
-
if (verdict.
|
|
1562
|
+
if (verdict.code === 'latest') return null
|
|
1456
1563
|
return { name: dep.name, current, target, why: verdict.why }
|
|
1457
1564
|
}
|
|
1458
1565
|
// 这个版本之前装失败过、还在抑制窗口内:这一轮不再试它。
|
|
@@ -1464,12 +1571,12 @@ async function runCycle(mode, ctxRef) {
|
|
|
1464
1571
|
target,
|
|
1465
1572
|
// 这里是服务端拼的纯文本,拿不到浏览器时区,所以显式写 UTC,
|
|
1466
1573
|
// 免得把一个 UTC 时刻当成本地时间读。
|
|
1467
|
-
why: '
|
|
1574
|
+
why: { code: 'suppressed', args: [until.toISOString().slice(0, 16).replace('T', ' ')] },
|
|
1468
1575
|
}
|
|
1469
1576
|
}
|
|
1470
1577
|
return { name: dep.name, current, target, tag }
|
|
1471
1578
|
} catch (error) {
|
|
1472
|
-
return { name: dep.name, current, why: '
|
|
1579
|
+
return { name: dep.name, current, why: { code: 'lookupFailed', args: [oneLine(error?.message ?? error, 120)] } }
|
|
1473
1580
|
}
|
|
1474
1581
|
}))
|
|
1475
1582
|
for (const answer of answers) {
|
|
@@ -1480,7 +1587,7 @@ async function runCycle(mode, ctxRef) {
|
|
|
1480
1587
|
}
|
|
1481
1588
|
writeLog('checked', [report.checked, report.updates.length])
|
|
1482
1589
|
if (report.updates.length === 0) {
|
|
1483
|
-
report.reason = '
|
|
1590
|
+
report.reason = { code: 'noUpdates' }
|
|
1484
1591
|
return report
|
|
1485
1592
|
}
|
|
1486
1593
|
// 单轮上限:装包会一直占着 pnpm 锁,一轮装 20 个能把 profile 占住几十分钟。
|
|
@@ -1491,7 +1598,7 @@ async function runCycle(mode, ctxRef) {
|
|
|
1491
1598
|
writeLog('capped', [settings.maxPerCycle, deferred])
|
|
1492
1599
|
}
|
|
1493
1600
|
if (mode === 'check' || !settings.autoApply) {
|
|
1494
|
-
report.reason = '
|
|
1601
|
+
report.reason = { code: 'checkOnly' }
|
|
1495
1602
|
return report
|
|
1496
1603
|
}
|
|
1497
1604
|
// 空闲门槛:装包会常驻占住 pnpm 并让界面变卡,换代码会把子任务中止。
|
|
@@ -1502,7 +1609,7 @@ async function runCycle(mode, ctxRef) {
|
|
|
1502
1609
|
const why = activityReasons(ctxRef.ctx, new Date(), idleWindow)
|
|
1503
1610
|
if (why.length > 0) {
|
|
1504
1611
|
report.status = 'blocked'
|
|
1505
|
-
report.reason =
|
|
1612
|
+
report.reason = { code: 'gated', args: [why] }
|
|
1506
1613
|
writeLog('skipInstall', [why])
|
|
1507
1614
|
return report
|
|
1508
1615
|
}
|
|
@@ -1510,7 +1617,7 @@ async function runCycle(mode, ctxRef) {
|
|
|
1510
1617
|
const runner = cliRunner()
|
|
1511
1618
|
if (runner === null) {
|
|
1512
1619
|
report.status = 'failed'
|
|
1513
|
-
report.reason =
|
|
1620
|
+
report.reason = { code: 'noCli' }
|
|
1514
1621
|
return report
|
|
1515
1622
|
}
|
|
1516
1623
|
// 进程内的 running 管得住自己的两轮,管不住别的进程;pnpm 的锁是按 profile 算的。
|
|
@@ -1534,7 +1641,7 @@ async function runCycle(mode, ctxRef) {
|
|
|
1534
1641
|
}
|
|
1535
1642
|
} catch (error) {
|
|
1536
1643
|
report.status = 'failed'
|
|
1537
|
-
report.reason = oneLine(error?.message ?? error, 400)
|
|
1644
|
+
report.reason = { code: 'raw', args: [oneLine(error?.message ?? error, 400)] }
|
|
1538
1645
|
writeLog('cycleFailed', [report.reason])
|
|
1539
1646
|
return report
|
|
1540
1647
|
} finally {
|
|
@@ -1584,25 +1691,25 @@ async function applyUpdates(ctxRef, report, settings, runner, profileDir, profil
|
|
|
1584
1691
|
const okCount = report.installed.filter((item) => item.ok).length
|
|
1585
1692
|
if (okCount === 0) {
|
|
1586
1693
|
report.status = 'failed'
|
|
1587
|
-
report.reason = '
|
|
1694
|
+
report.reason = { code: 'noneInstalled' }
|
|
1588
1695
|
return report
|
|
1589
1696
|
}
|
|
1590
1697
|
if (!settings.hotReload) {
|
|
1591
|
-
report.reload = { status: 'skipped', reason: '
|
|
1592
|
-
report.reason =
|
|
1698
|
+
report.reload = { status: 'skipped', reason: { code: 'reloadOff' } }
|
|
1699
|
+
report.reason = { code: 'installedRestart', args: [okCount] }
|
|
1593
1700
|
return report
|
|
1594
1701
|
}
|
|
1595
1702
|
// 装完之后再确认一次:安装可能耗时几分钟,期间可能有人开了子任务。
|
|
1596
1703
|
// 这里只看子任务,不看会话写入——换代码不会打断正在打字的用户,
|
|
1597
1704
|
// 但会因为「刚有写入」就放弃热生效,让装好的东西白等一次重启。
|
|
1598
1705
|
if (settings.idleOnly && runningSubagents(ctxRef.ctx).length > 0) {
|
|
1599
|
-
report.reload = { status: 'cancelled', reason: '
|
|
1600
|
-
report.reason =
|
|
1706
|
+
report.reload = { status: 'cancelled', reason: { code: 'reloadCancelled' } }
|
|
1707
|
+
report.reason = { code: 'installedNoHot', args: [okCount] }
|
|
1601
1708
|
return report
|
|
1602
1709
|
}
|
|
1603
1710
|
report.reload = await hotApply(ctxRef.ctx, requiredBefore)
|
|
1604
1711
|
writeLog('hotApply', [report.reload.status, report.reload.reason ?? ''])
|
|
1605
|
-
report.reason =
|
|
1712
|
+
report.reason = { code: 'installedWith', args: [okCount, report.reload.reason] }
|
|
1606
1713
|
if (report.reload.status === 'failed') report.status = 'failed'
|
|
1607
1714
|
else if (report.reload.status === 'blocked' || report.reload.status === 'restart') report.status = 'partial'
|
|
1608
1715
|
return report
|
|
@@ -1649,11 +1756,11 @@ async function rollbackOne(ctxRef, entryName) {
|
|
|
1649
1756
|
const settings = settingsOf(ctxRef.config)
|
|
1650
1757
|
const rows = readHistory()
|
|
1651
1758
|
const row = pickRollbackTarget(rows, entryName)
|
|
1652
|
-
if (row === undefined) return { ok: false, reason: '
|
|
1759
|
+
if (row === undefined) return { ok: false, reason: { code: 'rollbackNoRecord', args: [entryName] } }
|
|
1653
1760
|
const profileDir = profileDirOf(ctxRef.ctx)
|
|
1654
1761
|
const profileName = basename(profileDir)
|
|
1655
1762
|
const runner = cliRunner()
|
|
1656
|
-
if (runner === null) return { ok: false, reason:
|
|
1763
|
+
if (runner === null) return { ok: false, reason: { code: 'noCli' } }
|
|
1657
1764
|
// 回滚也是一次 pnpm 安装,和定时轮次抢同一把 profile 锁。
|
|
1658
1765
|
// 拿不到就明确告诉用户「有别的进程在装」,而不是让两个 pnpm 撞锁报 EPERM。
|
|
1659
1766
|
const lock = takeProfileLock(profileDir, new Date())
|
|
@@ -1677,7 +1784,7 @@ async function rollbackOne(ctxRef, entryName) {
|
|
|
1677
1784
|
rolledBack: true,
|
|
1678
1785
|
})
|
|
1679
1786
|
saveHistory(next)
|
|
1680
|
-
let reload = { status: 'skipped', reason: '
|
|
1787
|
+
let reload = { status: 'skipped', reason: { code: 'rollbackRestart' } }
|
|
1681
1788
|
if (settings.hotReload) reload = await hotApply(ctxRef.ctx, [])
|
|
1682
1789
|
return { ok: true, name: row.name, to: row.from, reload: reload.status }
|
|
1683
1790
|
}
|
|
@@ -1687,7 +1794,7 @@ function registerTool(ctx, config) {
|
|
|
1687
1794
|
if (tools === null || typeof tools.register !== 'function') return false
|
|
1688
1795
|
const effect = propOf(ctx, 'effect')
|
|
1689
1796
|
if (typeof effect !== 'function') return false
|
|
1690
|
-
const empty = { status: 'busy', reason: '
|
|
1797
|
+
const empty = { status: 'busy', reason: { code: 'runBusy' }, checked: 0, updates: [], installed: [], reload: 'none' }
|
|
1691
1798
|
try {
|
|
1692
1799
|
effect.call(ctx, () => tools.register({
|
|
1693
1800
|
name: 'plugin_updater',
|
|
@@ -1719,17 +1826,22 @@ function registerTool(ctx, config) {
|
|
|
1719
1826
|
required: ['status'],
|
|
1720
1827
|
additionalProperties: false,
|
|
1721
1828
|
},
|
|
1722
|
-
render: (_args, value) => [{
|
|
1829
|
+
render: (_args, value) => [{
|
|
1830
|
+
type: 'text',
|
|
1831
|
+
text: (settingsOf(config).lang === 'en' ? 'Plugin update · ' : '插件更新 · ') + (value?.reason || value?.status || ''),
|
|
1832
|
+
}],
|
|
1723
1833
|
},
|
|
1724
1834
|
execute: async (args) => {
|
|
1725
1835
|
try {
|
|
1836
|
+
// 工具结果是给模型看的,也照设置里的语言出,别让 reason 变成 { code, args } 的裸 JSON。
|
|
1837
|
+
const lang = settingsOf(config).lang
|
|
1726
1838
|
const action = args?.action === 'check' || args?.action === 'update' ? args.action : 'status'
|
|
1727
1839
|
if (action === 'status') {
|
|
1728
1840
|
const seen = lastRun
|
|
1729
|
-
if (seen === null) return { status: 'done', reason: '
|
|
1841
|
+
if (seen === null) return { status: 'done', reason: renderReason({ code: 'neverRun' }, lang), checked: 0, updates: [], installed: [], reload: 'none' }
|
|
1730
1842
|
return {
|
|
1731
1843
|
status: seen.status,
|
|
1732
|
-
reason: '
|
|
1844
|
+
reason: renderReason({ code: 'lastSummary', args: [seen.at, seen.reason || seen.status] }, lang),
|
|
1733
1845
|
checked: seen.checked,
|
|
1734
1846
|
updates: seen.updates,
|
|
1735
1847
|
installed: seen.installed,
|
|
@@ -1737,19 +1849,23 @@ function registerTool(ctx, config) {
|
|
|
1737
1849
|
}
|
|
1738
1850
|
}
|
|
1739
1851
|
const report = await beginningRun(action, { ctx, config })
|
|
1740
|
-
if (report === null) return empty
|
|
1852
|
+
if (report === null) return { ...empty, reason: renderReason(empty.reason, lang) }
|
|
1741
1853
|
return {
|
|
1742
1854
|
status: report.status,
|
|
1743
|
-
reason: report.reason
|
|
1855
|
+
reason: renderReason(report.reason, lang),
|
|
1744
1856
|
checked: report.checked,
|
|
1745
1857
|
updates: report.updates.map((item) => item.name + ' ' + (item.current ?? '?') + ' -> ' + item.target),
|
|
1746
1858
|
installed: report.installed.map((item) => item.name + '@' + item.version + (item.ok ? '' : ' !failed')),
|
|
1747
1859
|
reload: report.reload?.status ?? 'none',
|
|
1748
|
-
skipped: report.skipped.map((item) => item.name + ':' + item.why),
|
|
1860
|
+
skipped: report.skipped.map((item) => item.name + (lang === 'en' ? ': ' : ':') + renderReason(item.why, lang)),
|
|
1749
1861
|
}
|
|
1750
1862
|
} catch (error) {
|
|
1751
1863
|
writeLog('toolFailed', [oneLine(error?.message ?? error, 300)])
|
|
1752
|
-
return {
|
|
1864
|
+
return {
|
|
1865
|
+
status: 'failed',
|
|
1866
|
+
reason: renderReason({ code: 'stateBroken' }, settingsOf(config).lang),
|
|
1867
|
+
checked: 0, updates: [], installed: [], reload: 'none',
|
|
1868
|
+
}
|
|
1753
1869
|
}
|
|
1754
1870
|
},
|
|
1755
1871
|
}), 'dsh-aupdate: plugin_updater')
|
|
@@ -1861,14 +1977,14 @@ function readBody(req) {
|
|
|
1861
1977
|
})
|
|
1862
1978
|
}
|
|
1863
1979
|
|
|
1864
|
-
function settingsSnapshot(config, ctxRef) {
|
|
1980
|
+
function settingsSnapshot(config, ctxRef, lang) {
|
|
1865
1981
|
const settings = settingsOf(config)
|
|
1866
1982
|
return {
|
|
1867
1983
|
settings,
|
|
1868
1984
|
overrides: readOverrides(),
|
|
1869
1985
|
lastRun: lastRun === null ? null : {
|
|
1870
1986
|
status: lastRun.status,
|
|
1871
|
-
reason: lastRun.reason,
|
|
1987
|
+
reason: renderReason(lastRun.reason, lang),
|
|
1872
1988
|
at: lastRun.at,
|
|
1873
1989
|
checked: lastRun.checked,
|
|
1874
1990
|
updates: lastRun.updates,
|
|
@@ -1943,7 +2059,7 @@ function registerRoutes(scope, ctxRef) {
|
|
|
1943
2059
|
const method = req.method ?? 'GET'
|
|
1944
2060
|
if (method === 'GET' || method === 'HEAD') {
|
|
1945
2061
|
if (suffix === '/state') {
|
|
1946
|
-
sendJson(res, 200, settingsSnapshot(ctxRef.config, ctxRef))
|
|
2062
|
+
sendJson(res, 200, settingsSnapshot(ctxRef.config, ctxRef, url.searchParams.get('lang')))
|
|
1947
2063
|
return
|
|
1948
2064
|
}
|
|
1949
2065
|
if (suffix === '/logs') {
|
|
@@ -1972,7 +2088,7 @@ function registerRoutes(scope, ctxRef) {
|
|
|
1972
2088
|
} catch (error) {
|
|
1973
2089
|
writeLog('rescheduleFailed', [oneLine(error?.message ?? error, 200)])
|
|
1974
2090
|
}
|
|
1975
|
-
sendJson(res, 200, settingsSnapshot(ctxRef.config, ctxRef))
|
|
2091
|
+
sendJson(res, 200, settingsSnapshot(ctxRef.config, ctxRef, url.searchParams.get('lang')))
|
|
1976
2092
|
return
|
|
1977
2093
|
}
|
|
1978
2094
|
if (suffix === '/rollback') {
|
|
@@ -1984,7 +2100,7 @@ function registerRoutes(scope, ctxRef) {
|
|
|
1984
2100
|
}
|
|
1985
2101
|
const outcome = await rollbackOne(ctxRef, target)
|
|
1986
2102
|
writeLog('rollbackRequest', [target, outcome.ok === true, outcome.reason ?? ''])
|
|
1987
|
-
sendJson(res, outcome.ok ? 200 : 409, outcome)
|
|
2103
|
+
sendJson(res, outcome.ok ? 200 : 409, { ...outcome, reason: renderReason(outcome.reason, url.searchParams.get('lang')) })
|
|
1988
2104
|
return
|
|
1989
2105
|
}
|
|
1990
2106
|
if (suffix === '/run') {
|
|
@@ -1992,10 +2108,10 @@ function registerRoutes(scope, ctxRef) {
|
|
|
1992
2108
|
const mode = body?.mode === 'check' ? 'check' : 'update'
|
|
1993
2109
|
const report = await beginningRun(mode, ctxRef)
|
|
1994
2110
|
if (report === null) {
|
|
1995
|
-
sendJson(res, 200, { started: false, reason: '
|
|
2111
|
+
sendJson(res, 200, { started: false, reason: renderReason({ code: 'alreadyRunning' }, url.searchParams.get('lang')) })
|
|
1996
2112
|
return
|
|
1997
2113
|
}
|
|
1998
|
-
sendJson(res, 200, { started: true, status: report.status, reason: report.reason })
|
|
2114
|
+
sendJson(res, 200, { started: true, status: report.status, reason: renderReason(report.reason, url.searchParams.get('lang')) })
|
|
1999
2115
|
return
|
|
2000
2116
|
}
|
|
2001
2117
|
sendJson(res, 404, { error: 'unknown endpoint' })
|
package/package.json
CHANGED