dsh-aupdate 0.6.1 → 0.6.2

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.
Files changed (4) hide show
  1. package/README.md +6 -0
  2. package/client.js +8 -5
  3. package/index.js +172 -60
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -153,6 +153,8 @@ mtime 为准:那是磁盘事实。会话目录整个读不到时返回「不
153
153
  - 可选显示最近 100 / 200 / 500 / 1000 行,默认 200
154
154
  - **最新的在最上面**:按时间倒序渲染,刚装了什么不用滚到底
155
155
  - 时间只到「月-日 时:分:秒」并等宽对齐,省下的宽度留给正文
156
+ - **正文跟着「显示语言」走**:文件里存的是事件码和参数,不是成品句子,所以在中文与
157
+ English 之间切换后,连历史行都会跟着变;0.6.1 之前写下的旧行是句子,原样保留
156
158
  - 打开「自动刷新」后每 5 秒拉一次,正在排查时开着;关掉就完全不动
157
159
  - 读之前会先把待写队列刷下去,所以刚点完检查,那几行马上就在里面
158
160
  - 时间戳按本地时区显示,文件超过 1MB 轮转给一句提示,另附总行数
@@ -399,6 +401,10 @@ live in `~/.dsh/aupdate-settings.json`.
399
401
  The page renders the log newest first, so whatever just happened is at the top of the
400
402
  box instead of at the bottom of a scroll.
401
403
 
404
+ Log lines are stored as an event code plus its arguments, not as finished sentences, so
405
+ switching **Display language** re-renders history too. Lines written before 0.6.2 are
406
+ sentences and stay exactly as they were.
407
+
402
408
  You can read this file straight from the settings page (see above). Point it
403
409
  elsewhere with `DSH_AUTO_UPDATE_LOG`.
404
410
 
package/client.js CHANGED
@@ -345,8 +345,10 @@ window.__ModuleLoader__.load({
345
345
  return response.json()
346
346
  }
347
347
 
348
- async function getLogs(lines) {
349
- const response = await fetch(endpoint('logs') + '?lines=' + encodeURIComponent(String(lines)), {
348
+ async function getLogs(lines, lang) {
349
+ // 日志在磁盘上存的是 code + 参数,正文由后端按这里要的语言渲染。
350
+ const wanted = lang === 'en' ? 'en' : 'zh'
351
+ const response = await fetch(endpoint('logs') + '?lines=' + encodeURIComponent(String(lines)) + '&lang=' + wanted, {
350
352
  headers: { accept: 'application/json' },
351
353
  cache: 'no-store',
352
354
  })
@@ -883,15 +885,16 @@ window.__ModuleLoader__.load({
883
885
 
884
886
  const refresh = useCallback(async () => {
885
887
  try {
886
- const next = await getLogs(lines)
888
+ // LANG 进依赖:切换显示语言时这一栏要重新取,否则日志正文还是旧语言。
889
+ const next = await getLogs(lines, LANG)
887
890
  setData(next)
888
891
  setPhase(next?.exists === false ? 'missing' : 'ready')
889
892
  } catch {
890
893
  setPhase('missing')
891
894
  }
892
- }, [lines])
895
+ }, [lines, LANG])
893
896
 
894
- // lines 变了要立刻重取;tick 是自动刷新用来触发同一段逻辑的。
897
+ // lines 或语言变了要立刻重取;tick 是自动刷新用来触发同一段逻辑的。
895
898
  useEffect(() => { void refresh() }, [refresh, tick])
896
899
 
897
900
  useEffect(() => {
package/index.js CHANGED
@@ -91,37 +91,134 @@ function flushLog() {
91
91
  }
92
92
  }
93
93
 
94
- /** 日志里的状态词翻译成人话——面板是给人看的,不留英文状态码。 */
95
- const STATUS_TEXT = { done: '完成', blocked: '已让开', failed: '失败', skipped: '已跳过', none: '无', ok: '成功' }
96
-
97
- function statusText(value) {
98
- return STATUS_TEXT[String(value ?? '')] ?? String(value ?? '')
99
- }
100
-
101
- /** 设置页提交的键名,日志里不该出现 enabled,autoApply 这种字面量。 */
102
- const FIELD_LABELS = {
103
- enabled: '定时检查', autoApply: '自动安装', hotReload: '就地生效', checkOnStart: '启动先查',
104
- idleOnly: '忙时不动手', notify: '更新提醒', intervalMinutes: '检查间隔',
105
- firstDelayMinutes: '首次延迟', exclude: '不更新的包', allowMajor: '跨大版本',
106
- allowPrerelease: '预发布', scheduleMode: '调度方式', dailyAt: '每天时刻',
107
- everyHours: '每几小时', everyDays: '每几天', suppressHours: '失败抑制',
108
- maxPerCycle: '单轮上限', sessionIdleMinutes: '会话静默',
109
- }
94
+ /**
95
+ * 结构化日志。
96
+ *
97
+ * 0.6.1 及以前是把成品句子写进文件:中文环境下写中文,那一刻语言就钉死了,
98
+ * 之后在设置页切成 English,历史行仍然全是中文。要让日志跟着语言走,落盘的内容
99
+ * 就不能是句子——这里改成写 code + 参数(一行一个 JSON 数组),等到读取时
100
+ * 才按请求的语言渲染。想加一种语言只是多一张模板表。
101
+ *
102
+ * 兼容:旧格式的行是成品句子,解析失败就原样显示,不丢历史。
103
+ */
110
104
 
111
- function fieldLabel(key) {
112
- return FIELD_LABELS[key] ?? String(key)
105
+ /** 状态词。运行结果是数据(done/skipped/…),显示成哪种语言由读取侧决定。 */
106
+ const LOG_STATUS = {
107
+ zh: { done: '完成', blocked: '已让开', failed: '失败', skipped: '已跳过', none: '无', ok: '成功' },
108
+ en: { done: 'done', blocked: 'held off', failed: 'failed', skipped: 'skipped', none: 'none', ok: 'ok' },
109
+ }
110
+
111
+ /** 设置项在日志里的名字:enabled / autoApply 这种字面量不该出现在面板上。 */
112
+ const LOG_FIELD_LABELS = {
113
+ zh: {
114
+ lang: '显示语言', enabled: '定时检查', autoApply: '自动安装', hotReload: '就地生效',
115
+ checkOnStart: '启动先查', idleOnly: '忙时不动手', notify: '更新提醒',
116
+ intervalMinutes: '检查间隔', firstDelayMinutes: '首次延迟', exclude: '不更新的包',
117
+ allowMajor: '跨大版本', allowPrerelease: '预发布', scheduleMode: '调度方式',
118
+ dailyAt: '每天时刻', everyHours: '每几小时', everyDays: '每几天',
119
+ suppressHours: '失败抑制', maxPerCycle: '单轮上限', sessionIdleMinutes: '会话静默',
120
+ },
121
+ en: {
122
+ lang: 'display language', enabled: 'scheduled check', autoApply: 'auto-install',
123
+ hotReload: 'apply in place', checkOnStart: 'check on start', idleOnly: 'hold while busy',
124
+ notify: 'update notices', intervalMinutes: 'check interval', firstDelayMinutes: 'first delay',
125
+ exclude: 'never-update list', allowMajor: 'major upgrades', allowPrerelease: 'prereleases',
126
+ scheduleMode: 'schedule', dailyAt: 'time of day', everyHours: 'every N hours',
127
+ everyDays: 'every N days', suppressHours: 'failure suppression', maxPerCycle: 'per-cycle cap',
128
+ sessionIdleMinutes: 'session idle',
129
+ },
113
130
  }
114
131
 
115
- function yesNo(value) {
116
- return value === true ? '开' : '关'
132
+ function makeLogTemplates(lang) {
133
+ const S = LOG_STATUS[lang] ?? LOG_STATUS.zh
134
+ const labels = LOG_FIELD_LABELS[lang] ?? LOG_FIELD_LABELS.zh
135
+ const zh = lang !== 'en'
136
+ const sep = zh ? '、' : ', '
137
+ const status = (value) => S[String(value ?? '')] ?? String(value ?? '')
138
+ const list = (value) => (Array.isArray(value) ? value.join(sep) : String(value ?? ''))
139
+ const onOff = (value) => (zh ? (value === true ? '开' : '关') : (value === true ? 'on' : 'off'))
140
+ return {
141
+ raw: (text) => String(text ?? ''),
142
+ checked: (n, u) => (zh ? `检查 ${n} 个插件,${u} 个可更新` : `Checked ${n} plugin(s), ${u} update(s) available`),
143
+ capped: (max, left) => (zh ? `本轮限量装 ${max} 个,剩下 ${left} 个下一轮再装` : `Capped at ${max} install(s) this cycle; ${left} left for the next round`),
144
+ skipInstall: (why) => (zh ? `跳过安装:${list(why)}` : `Skipped installing: ${list(why)}`),
145
+ snapshotTaken: (dir, files) => (zh ? `已留快照 ${dir}(${list(files)})` : `Snapshot saved to ${dir} (${list(files)})`),
146
+ snapshotFailed: (msg) => (zh ? `留快照失败:${msg}` : `Snapshot failed: ${msg}`),
147
+ tookOverLock: (minutes) => (zh ? `接管了一个已挂 ${minutes} 分钟的安装锁` : `Took over an install lock left for ${minutes} min`),
148
+ install: (name, target, ok, detail) => (zh
149
+ ? `安装 ${name}@${target} → ${ok ? '成功' : '失败:' + (detail || '')}`
150
+ : `Installed ${name}@${target} → ${ok ? 'ok' : 'failed: ' + (detail || '')}`),
151
+ hotApply: (state, reason) => (zh
152
+ ? `就地生效 → ${status(state)}${reason ? ':' + reason : ''}`
153
+ : `Hot apply → ${status(state)}${reason ? ': ' + reason : ''}`),
154
+ cycle: (mode, state, reason) => (zh
155
+ ? `本轮${mode === 'check' ? '检查' : '更新'} → ${status(state)}:${reason}`
156
+ : `Cycle ${mode === 'check' ? 'check' : 'update'} → ${status(state)}: ${reason}`),
157
+ cycleFailed: (reason) => (zh ? `本轮失败:${reason}` : `Cycle failed: ${reason}`),
158
+ cycleThrew: (msg) => (zh ? `本轮抛错:${msg}` : `Cycle threw: ${msg}`),
159
+ rollback: (name, from, to, ok, detail) => (zh
160
+ ? `回滚 ${name} ${to} → ${from} → ${ok ? '成功' : '失败:' + (detail || '')}`
161
+ : `Rolled back ${name} ${to} → ${from} → ${ok ? 'ok' : 'failed: ' + (detail || '')}`),
162
+ rollbackRequest: (name, ok, reason) => (zh
163
+ ? `收到回滚请求 ${name} → ${ok ? '成功' : '失败:' + (reason || '')}`
164
+ : `Rollback requested for ${name} → ${ok ? 'ok' : 'failed: ' + (reason || '')}`),
165
+ settingsChanged: (keys) => (zh
166
+ ? `设置页改了:${list((Array.isArray(keys) ? keys : []).map((key) => labels[key] ?? String(key)))}`
167
+ : `Settings changed: ${list((Array.isArray(keys) ? keys : []).map((key) => labels[key] ?? String(key)))}`),
168
+ rescheduleFailed: (msg) => (zh ? `重排定时失败:${msg}` : `Rescheduling failed: ${msg}`),
169
+ toolFailed: (msg) => (zh ? `工具调用失败:${msg}` : `Tool call failed: ${msg}`),
170
+ toolUnavailable: (msg) => (zh ? `无法提供工具:${msg}` : `Could not offer the tool: ${msg}`),
171
+ toolRegistered: (ok) => (zh ? `工具注册:${ok ? '成功' : '失败'}` : `Tool registered: ${ok ? 'ok' : 'failed'}`),
172
+ toolRegisterThrew: (msg) => (zh ? `注册工具时抛错:${msg}` : `Tool registration threw: ${msg}`),
173
+ routeFailed: (msg) => (zh ? `接口处理出错:${msg}` : `Route failed: ${msg}`),
174
+ routeReady: (prefix) => (zh ? `设置接口已就绪:${prefix}` : `Settings route ready: ${prefix}`),
175
+ routeReadyNoScope: (prefix) => (zh ? `设置接口已就绪(没有 effect 作用域):${prefix}` : `Settings route ready (no effect scope): ${prefix}`),
176
+ routeRegisterFailed: (msg) => (zh ? `无法注册设置接口:${msg}` : `Could not register the settings route: ${msg}`),
177
+ routeRegisterThrew: (msg) => (zh ? `注册设置接口时抛错:${msg}` : `Route registration threw: ${msg}`),
178
+ webServerMissing: () => (zh ? '没有 webServer 服务,设置页会显示不可用' : 'No webServer service; the settings page will report it'),
179
+ toolScopeEnded: (msg) => (zh ? `工具作用域已结束:${msg}` : `Tool scope ended: ${msg}`),
180
+ disabledBySettings: () => (zh ? '设置里已关闭自动更新,定时器待命' : 'Auto-update is off in settings; scheduler parked'),
181
+ disabledByConfig: () => (zh ? '配置里已关闭自动更新,定时器待命,设置页仍然可用' : 'Auto-update is off in config; scheduler parked, settings page stays live'),
182
+ ready: (minutes, autoApply, hotReload) => (zh
183
+ ? `已就绪:每 ${minutes} 分钟检查一次,自动安装=${onOff(autoApply)},就地生效=${onOff(hotReload)}`
184
+ : `Ready: every ${minutes} min, autoApply=${onOff(autoApply)}, hotReload=${onOff(hotReload)}`),
185
+ }
186
+ }
187
+
188
+ const LOG_TEMPLATES = { zh: makeLogTemplates('zh'), en: makeLogTemplates('en') }
189
+
190
+ /** 只认 zh / en;其余(含 undefined)按中文渲染。 */
191
+ function logLangOf(choice) {
192
+ return choice === 'en' ? 'en' : 'zh'
193
+ }
194
+
195
+ /** 渲染一条日志。认不出的 code 退化成一串参数,至少不丢信息。 */
196
+ function renderLogEntry(code, args, lang) {
197
+ const table = LOG_TEMPLATES[logLangOf(lang)]
198
+ const values = Array.isArray(args) ? args : []
199
+ const render = table[String(code)]
200
+ if (typeof render !== 'function') return '[' + String(code) + '] ' + values.join(' ')
201
+ try {
202
+ return render(...values)
203
+ } catch {
204
+ return '[' + String(code) + '] ' + values.join(' ')
205
+ }
117
206
  }
118
207
 
119
- function writeLog(message) {
208
+ /**
209
+ * 写一条日志。
210
+ *
211
+ * @param code 模板名(见 makeLogTemplates),不是成品句子。
212
+ * @param args 模板参数;自由文本走 raw。
213
+ */
214
+ function writeLog(code, args = []) {
215
+ const values = Array.isArray(args) ? args : []
120
216
  try {
121
- console.log('[dsh-aupdate] ' + oneLine(message, 400))
217
+ // 控制台固定中文:那是给开发者看的,跟界面语言无关。
218
+ console.log('[dsh-aupdate] ' + oneLine(renderLogEntry(code, values, 'zh'), 400))
122
219
  } catch {}
123
220
  try {
124
- logQueue.push('[' + new Date().toISOString() + '] ' + oneLine(message) + '\n')
221
+ logQueue.push('[' + new Date().toISOString() + '] ' + oneLine(JSON.stringify([String(code), ...values])) + '\n')
125
222
  // 队列异常长说明写盘一直失败,直接丢掉最老的,避免吃内存。
126
223
  if (logQueue.length > 500) logQueue = logQueue.slice(-500)
127
224
  if (!logFlushing) {
@@ -149,7 +246,7 @@ const LOG_TAIL_MAX_LINES = 1000
149
246
  * 面板里却没有这一行」——差的就是 setImmediate 那一拍。
150
247
  * 读不到不算错误:可能从没跑过检查,也可能用户把文件删了。
151
248
  */
152
- function readLogTail(limit) {
249
+ function readLogTail(limit, lang) {
153
250
  try {
154
251
  flushLogNow()
155
252
  } catch {}
@@ -165,9 +262,24 @@ function readLogTail(limit) {
165
262
  // 每个进程都会补换行,split 后末尾必然多一个空串。
166
263
  if (all.length > 0 && all[all.length - 1] === '') all.pop()
167
264
  const rows = []
265
+ const wanted = logLangOf(lang)
168
266
  for (const line of all.slice(-want)) {
169
267
  const match = /^\[([^\]]+)\] ([\s\S]*)$/u.exec(line)
170
- rows.push(match === null ? { at: '', text: line } : { at: match[1], text: match[2] })
268
+ if (match === null) {
269
+ rows.push({ at: '', text: line })
270
+ continue
271
+ }
272
+ const body = match[2]
273
+ // 新格式是 JSON 数组;0.6.1 及更早写的是成品句子,解析不出就原样显示。
274
+ let parsed = null
275
+ if (body.startsWith('[')) {
276
+ try { parsed = JSON.parse(body) } catch {}
277
+ }
278
+ if (Array.isArray(parsed) && typeof parsed[0] === 'string') {
279
+ rows.push({ at: match[1], text: renderLogEntry(parsed[0], parsed.slice(1), wanted) })
280
+ } else {
281
+ rows.push({ at: match[1], text: body })
282
+ }
171
283
  }
172
284
  let size = 0
173
285
  try {
@@ -1137,7 +1249,7 @@ function snapshotProfile(profileDir, now) {
1137
1249
  return { dir, files: saved }
1138
1250
  } catch (error) {
1139
1251
  // 留底失败不该拦住更新本身:它只是事后证据,不是前置条件。
1140
- writeLog('留快照失败:' + oneLine(error?.message ?? error, 200))
1252
+ writeLog('snapshotFailed', [oneLine(error?.message ?? error, 200)])
1141
1253
  return null
1142
1254
  }
1143
1255
  }
@@ -1196,7 +1308,7 @@ function takeProfileLock(profileDir, now) {
1196
1308
  } catch {}
1197
1309
  try {
1198
1310
  writeFileSync(file, stamp + '\n', { encoding: 'utf8', flag: 'wx' })
1199
- writeLog('接管了一个已挂 ' + ageMinutes + ' 分钟的安装锁')
1311
+ writeLog('tookOverLock', [ageMinutes])
1200
1312
  return { ok: true, file }
1201
1313
  } catch (error) {
1202
1314
  return { ok: false, reason: '抢锁失败:' + oneLine(error?.message ?? error, 160) }
@@ -1366,7 +1478,7 @@ async function runCycle(mode, ctxRef) {
1366
1478
  else report.skipped.push(answer)
1367
1479
  }
1368
1480
  }
1369
- writeLog('检查 ' + report.checked + ' 个插件,' + report.updates.length + ' 个可更新')
1481
+ writeLog('checked', [report.checked, report.updates.length])
1370
1482
  if (report.updates.length === 0) {
1371
1483
  report.reason = '没有可更新的插件'
1372
1484
  return report
@@ -1376,7 +1488,7 @@ async function runCycle(mode, ctxRef) {
1376
1488
  const deferred = settings.maxPerCycle > 0 ? report.updates.length - settings.maxPerCycle : 0
1377
1489
  if (deferred > 0) {
1378
1490
  report.updates = report.updates.slice(0, settings.maxPerCycle)
1379
- writeLog('本轮限量装 ' + settings.maxPerCycle + ' 个,剩下 ' + deferred + ' 个下一轮再装')
1491
+ writeLog('capped', [settings.maxPerCycle, deferred])
1380
1492
  }
1381
1493
  if (mode === 'check' || !settings.autoApply) {
1382
1494
  report.reason = '只查不装'
@@ -1391,7 +1503,7 @@ async function runCycle(mode, ctxRef) {
1391
1503
  if (why.length > 0) {
1392
1504
  report.status = 'blocked'
1393
1505
  report.reason = why.join(';') + ',这一轮不安装'
1394
- writeLog('跳过安装:' + why.join(';'))
1506
+ writeLog('skipInstall', [why])
1395
1507
  return report
1396
1508
  }
1397
1509
  }
@@ -1406,7 +1518,7 @@ async function runCycle(mode, ctxRef) {
1406
1518
  if (!lock.ok) {
1407
1519
  report.status = 'blocked'
1408
1520
  report.reason = lock.reason
1409
- writeLog('跳过安装:' + lock.reason)
1521
+ writeLog('skipInstall', [lock.reason])
1410
1522
  return report
1411
1523
  }
1412
1524
  try {
@@ -1414,7 +1526,7 @@ async function runCycle(mode, ctxRef) {
1414
1526
  const snapshot = snapshotProfile(profileDir, new Date())
1415
1527
  if (snapshot !== null) {
1416
1528
  report.snapshot = snapshot.dir
1417
- writeLog('已留快照 ' + snapshot.dir + '(' + snapshot.files.join('、') + ')')
1529
+ writeLog('snapshotTaken', [snapshot.dir, snapshot.files])
1418
1530
  }
1419
1531
  return await applyUpdates(ctxRef, report, settings, runner, profileDir, profileName)
1420
1532
  } finally {
@@ -1423,7 +1535,7 @@ async function runCycle(mode, ctxRef) {
1423
1535
  } catch (error) {
1424
1536
  report.status = 'failed'
1425
1537
  report.reason = oneLine(error?.message ?? error, 400)
1426
- writeLog('本轮失败:' + report.reason)
1538
+ writeLog('cycleFailed', [report.reason])
1427
1539
  return report
1428
1540
  } finally {
1429
1541
  report.finishedAt = new Date().toISOString()
@@ -1432,7 +1544,7 @@ async function runCycle(mode, ctxRef) {
1432
1544
  at: report.finishedAt,
1433
1545
  checked: report.checked,
1434
1546
  updates: report.updates.map((item) => item.name + ' ' + (item.current ?? '?') + ' -> ' + item.target),
1435
- installed: report.installed.map((item) => item.name + '@' + item.version + (item.ok ? '' : ' 失败')),
1547
+ installed: report.installed.map((item) => item.name + '@' + item.version + (item.ok ? '' : ' !failed')),
1436
1548
  reload: report.reload?.status ?? 'none',
1437
1549
  reason: report.reason,
1438
1550
  snapshot: report.snapshot,
@@ -1452,7 +1564,7 @@ async function applyUpdates(ctxRef, report, settings, runner, profileDir, profil
1452
1564
  for (const update of ordered) {
1453
1565
  const outcome = await installOne(runner, profileName, profileDir, update.name, update.target)
1454
1566
  report.installed.push(outcome)
1455
- writeLog('安装 ' + update.name + '@' + update.target + ' → ' + (outcome.ok ? '成功' : '失败:' + outcome.detail))
1567
+ writeLog('install', [update.name, update.target, outcome.ok === true, outcome.detail ?? ''])
1456
1568
  if (outcome.ok) {
1457
1569
  clearFailure(update.name, update.target)
1458
1570
  appendHistory({
@@ -1489,7 +1601,7 @@ async function applyUpdates(ctxRef, report, settings, runner, profileDir, profil
1489
1601
  return report
1490
1602
  }
1491
1603
  report.reload = await hotApply(ctxRef.ctx, requiredBefore)
1492
- writeLog('就地生效 → ' + statusText(report.reload.status) + (report.reload.reason ? ':' + report.reload.reason : ''))
1604
+ writeLog('hotApply', [report.reload.status, report.reload.reason ?? ''])
1493
1605
  report.reason = '已安装 ' + okCount + ' 个;' + (report.reload.reason ?? '')
1494
1606
  if (report.reload.status === 'failed') report.status = 'failed'
1495
1607
  else if (report.reload.status === 'blocked' || report.reload.status === 'restart') report.status = 'partial'
@@ -1552,7 +1664,7 @@ async function rollbackOne(ctxRef, entryName) {
1552
1664
  } finally {
1553
1665
  releaseProfileLock(lock)
1554
1666
  }
1555
- writeLog('回滚 ' + row.name + ' ' + row.to + ' → ' + row.from + ' → ' + (outcome.ok ? '成功' : '失败:' + outcome.detail))
1667
+ writeLog('rollback', [row.name, row.from, row.to, outcome.ok === true, outcome.detail ?? ''])
1556
1668
  if (!outcome.ok) return { ok: false, reason: outcome.detail }
1557
1669
  const next = rows.slice()
1558
1670
  next.unshift({
@@ -1631,19 +1743,19 @@ function registerTool(ctx, config) {
1631
1743
  reason: report.reason || '',
1632
1744
  checked: report.checked,
1633
1745
  updates: report.updates.map((item) => item.name + ' ' + (item.current ?? '?') + ' -> ' + item.target),
1634
- installed: report.installed.map((item) => item.name + '@' + item.version + (item.ok ? '' : ' 失败')),
1746
+ installed: report.installed.map((item) => item.name + '@' + item.version + (item.ok ? '' : ' !failed')),
1635
1747
  reload: report.reload?.status ?? 'none',
1636
1748
  skipped: report.skipped.map((item) => item.name + ':' + item.why),
1637
1749
  }
1638
1750
  } catch (error) {
1639
- writeLog('工具调用失败:' + oneLine(error?.message ?? error, 300))
1751
+ writeLog('toolFailed', [oneLine(error?.message ?? error, 300)])
1640
1752
  return { status: 'failed', reason: '没能完成,插件状态需要核对', checked: 0, updates: [], installed: [], reload: 'none' }
1641
1753
  }
1642
1754
  },
1643
1755
  }), 'dsh-aupdate: plugin_updater')
1644
1756
  return true
1645
1757
  } catch (error) {
1646
- writeLog('无法提供工具:' + oneLine(error?.message ?? error, 300))
1758
+ writeLog('toolUnavailable', [oneLine(error?.message ?? error, 300)])
1647
1759
  return false
1648
1760
  }
1649
1761
  }
@@ -1835,7 +1947,7 @@ function registerRoutes(scope, ctxRef) {
1835
1947
  return
1836
1948
  }
1837
1949
  if (suffix === '/logs') {
1838
- sendJson(res, 200, readLogTail(url.searchParams.get('lines')))
1950
+ sendJson(res, 200, readLogTail(url.searchParams.get('lines'), url.searchParams.get('lang')))
1839
1951
  return
1840
1952
  }
1841
1953
  sendJson(res, 404, { error: 'unknown endpoint' })
@@ -1853,12 +1965,12 @@ function registerRoutes(scope, ctxRef) {
1853
1965
  sendJson(res, 500, { error: result.error })
1854
1966
  return
1855
1967
  }
1856
- writeLog('设置页改了:' + Object.keys(body).map(fieldLabel).join('、'))
1968
+ writeLog('settingsChanged', [Object.keys(body)])
1857
1969
  // 改完立刻按新设置重排,否则要等下一次触发才换节奏。
1858
1970
  try {
1859
1971
  if (typeof ctxRef.reschedule === 'function') ctxRef.reschedule()
1860
1972
  } catch (error) {
1861
- writeLog('重排定时失败:' + oneLine(error?.message ?? error, 200))
1973
+ writeLog('rescheduleFailed', [oneLine(error?.message ?? error, 200)])
1862
1974
  }
1863
1975
  sendJson(res, 200, settingsSnapshot(ctxRef.config, ctxRef))
1864
1976
  return
@@ -1871,7 +1983,7 @@ function registerRoutes(scope, ctxRef) {
1871
1983
  return
1872
1984
  }
1873
1985
  const outcome = await rollbackOne(ctxRef, target)
1874
- writeLog('收到回滚请求 ' + target + ' → ' + (outcome.ok ? '成功' : '失败:' + outcome.reason))
1986
+ writeLog('rollbackRequest', [target, outcome.ok === true, outcome.reason ?? ''])
1875
1987
  sendJson(res, outcome.ok ? 200 : 409, outcome)
1876
1988
  return
1877
1989
  }
@@ -1891,7 +2003,7 @@ function registerRoutes(scope, ctxRef) {
1891
2003
  }
1892
2004
  sendJson(res, 405, { error: 'method not allowed' })
1893
2005
  } catch (error) {
1894
- writeLog('接口处理出错:' + oneLine(error?.message ?? error, 300))
2006
+ writeLog('routeFailed', [oneLine(error?.message ?? error, 300)])
1895
2007
  try { sendJson(res, 500, { error: 'internal' }) } catch {}
1896
2008
  }
1897
2009
  }
@@ -1900,14 +2012,14 @@ function registerRoutes(scope, ctxRef) {
1900
2012
  const register = () => webServer.register({ kind: 'prefix', path: ROUTE_PREFIX, handler })
1901
2013
  if (typeof effect === 'function') {
1902
2014
  effect.call(scope, register, 'dsh-aupdate: settings routes')
1903
- writeLog('设置接口已就绪:' + ROUTE_PREFIX)
2015
+ writeLog('routeReady', [ROUTE_PREFIX])
1904
2016
  return true
1905
2017
  }
1906
2018
  register()
1907
- writeLog('设置接口已就绪(没有 effect 作用域):' + ROUTE_PREFIX)
2019
+ writeLog('routeReadyNoScope', [ROUTE_PREFIX])
1908
2020
  return true
1909
2021
  } catch (error) {
1910
- writeLog('无法注册设置接口:' + oneLine(error?.message ?? error, 300))
2022
+ writeLog('routeRegisterFailed', [oneLine(error?.message ?? error, 300)])
1911
2023
  return false
1912
2024
  }
1913
2025
  }
@@ -1926,15 +2038,15 @@ export function apply(ctx, config) {
1926
2038
  try {
1927
2039
  const tools = serviceOf(scope, 'tools')
1928
2040
  if (tools === null || typeof tools.register !== 'function') {
1929
- writeLog('工具注册失败')
2041
+ writeLog('toolRegistered', [false])
1930
2042
  return
1931
2043
  }
1932
2044
  if (toolService === tools) return
1933
2045
  toolService = tools
1934
2046
  const ok = registerTool(scope, config)
1935
- writeLog('工具注册:' + (ok ? '成功' : '失败'))
2047
+ writeLog('toolRegistered', [ok === true])
1936
2048
  } catch (error) {
1937
- writeLog('注册工具时抛错:' + oneLine(error?.message ?? error, 300))
2049
+ writeLog('toolRegisterThrew', [oneLine(error?.message ?? error, 300)])
1938
2050
  }
1939
2051
  }
1940
2052
  // 路由和工具是同一类问题:apply 执行时 webServer 可能还没就绪,
@@ -1944,14 +2056,14 @@ export function apply(ctx, config) {
1944
2056
  try {
1945
2057
  const webServer = serviceOf(scope, 'webServer')
1946
2058
  if (webServer === null || typeof webServer.register !== 'function') {
1947
- writeLog('没有 webServer 服务,设置页会显示不可用')
2059
+ writeLog('webServerMissing', [])
1948
2060
  return
1949
2061
  }
1950
2062
  if (routeService === webServer) return
1951
2063
  const ok = registerRoutes(scope, ctxRef)
1952
2064
  if (ok) routeService = webServer
1953
2065
  } catch (error) {
1954
- writeLog('注册设置接口时抛错:' + oneLine(error?.message ?? error, 300))
2066
+ writeLog('routeRegisterThrew', [oneLine(error?.message ?? error, 300)])
1955
2067
  }
1956
2068
  }
1957
2069
  const inject = propOf(ctx, 'inject')
@@ -1965,10 +2077,10 @@ export function apply(ctx, config) {
1965
2077
  offerRoutes(scope)
1966
2078
  })
1967
2079
  Promise.resolve(fiber).catch((error) => {
1968
- writeLog('工具作用域已结束:' + oneLine(error?.message ?? error, 300))
2080
+ writeLog('toolScopeEnded', [oneLine(error?.message ?? error, 300)])
1969
2081
  })
1970
2082
  } catch (error) {
1971
- writeLog('无法提供工具:' + oneLine(error?.message ?? error, 300))
2083
+ writeLog('toolUnavailable', [oneLine(error?.message ?? error, 300)])
1972
2084
  offerTool(ctx)
1973
2085
  offerRoutes(ctx)
1974
2086
  }
@@ -1981,9 +2093,9 @@ export function apply(ctx, config) {
1981
2093
  const go = async () => {
1982
2094
  try {
1983
2095
  const report = await beginningRun(mode, ctxRef)
1984
- if (report !== null) writeLog('本轮' + (mode === 'check' ? '检查' : '更新') + ' → ' + statusText(report.status) + ':' + report.reason)
2096
+ if (report !== null) writeLog('cycle', [mode, report.status, report.reason])
1985
2097
  } catch (error) {
1986
- writeLog('本轮抛错:' + oneLine(error?.message ?? error, 300))
2098
+ writeLog('cycleThrew', [oneLine(error?.message ?? error, 300)])
1987
2099
  }
1988
2100
  }
1989
2101
  void go()
@@ -2018,7 +2130,7 @@ export function apply(ctx, config) {
2018
2130
  clearScheduled()
2019
2131
  const live = settingsOf(ctxRef.config)
2020
2132
  if (!live.enabled) {
2021
- writeLog('设置里已关闭自动更新,定时器待命')
2133
+ writeLog('disabledBySettings', [])
2022
2134
  return
2023
2135
  }
2024
2136
  // 启动后第一次仍然只看 firstDelayMinutes,之后按当前调度模式算。
@@ -2052,7 +2164,7 @@ export function apply(ctx, config) {
2052
2164
 
2053
2165
  // 设置页要能读到运行状态并改设置,所以路由最后注册、且与 enabled 无关:
2054
2166
  // 关掉定时检查之后,用户仍然要能看到这一页并把它重新打开。
2055
- if (!settings.enabled) writeLog('配置里已关闭自动更新,定时器待命,设置页仍然可用')
2167
+ if (!settings.enabled) writeLog('disabledByConfig', [])
2056
2168
 
2057
2169
  const stop = () => {
2058
2170
  for (const off of timers.splice(0)) {
@@ -2068,7 +2180,7 @@ export function apply(ctx, config) {
2068
2180
  } catch {}
2069
2181
  }
2070
2182
 
2071
- writeLog('已就绪:每 ' + settings.intervalMinutes + ' 分钟检查一次,自动安装=' + yesNo(settings.autoApply) + ',就地生效=' + yesNo(settings.hotReload))
2183
+ writeLog('ready', [settings.intervalMinutes, settings.autoApply === true, settings.hotReload === true])
2072
2184
  }
2073
2185
 
2074
2186
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-aupdate",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "type": "module",
5
5
  "description": "定时检查 DSH 插件更新,串行安装后就地生效,不重启;支持多种调度节奏、失败抑制、按包回滚,并在动手前留快照、忙时自动让开;不更新/只更新哪些插件改成勾选,发现更新在右下角提醒,日志最新在最上面,并在「设置 → 插件更新」里有独立一页。",
6
6
  "license": "MIT",