dsh-config-manager 0.8.2 → 0.9.0

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 (345) hide show
  1. package/lib/adapters/mcp.js +42 -13
  2. package/lib/adapters/messages.d.ts +1 -0
  3. package/lib/adapters/messages.js +2 -0
  4. package/lib/adapters/patch-key-guard.d.ts +23 -0
  5. package/lib/adapters/patch-key-guard.js +13 -0
  6. package/lib/adapters/plugin-data.d.ts +19 -5
  7. package/lib/adapters/plugin-data.js +76 -22
  8. package/lib/adapters/plugins.d.ts +14 -1
  9. package/lib/adapters/plugins.js +147 -4
  10. package/lib/cli/actions.d.ts +7 -105
  11. package/lib/cli/actions.js +16 -172
  12. package/lib/cli/control-state.d.ts +54 -0
  13. package/lib/cli/control-state.js +107 -0
  14. package/lib/cli/index.js +14 -0
  15. package/lib/cli/write-gates.d.ts +61 -0
  16. package/lib/cli/write-gates.js +110 -0
  17. package/lib/client.d.ts +104 -49
  18. package/lib/client.js +12536 -12006
  19. package/lib/core/backup.d.ts +0 -4
  20. package/lib/core/backup.js +21 -4
  21. package/lib/core/boot-rescue.d.ts +1 -1
  22. package/lib/core/boot-rescue.js +12 -1
  23. package/lib/core/boot-safety.js +37 -2
  24. package/lib/core/conflict-decisions.js +2 -1
  25. package/lib/core/exporter.js +22 -1
  26. package/lib/core/journal.d.ts +54 -4
  27. package/lib/core/journal.js +158 -35
  28. package/lib/core/local-plugin-host.d.ts +29 -0
  29. package/lib/core/local-plugin-host.js +55 -48
  30. package/lib/core/messages.d.ts +7 -0
  31. package/lib/core/messages.js +14 -0
  32. package/lib/core/migration-history.js +16 -9
  33. package/lib/core/model-tools.d.ts +2 -2
  34. package/lib/core/model-tools.js +14 -2
  35. package/lib/core/patch-secret-guard.d.ts +49 -0
  36. package/lib/core/patch-secret-guard.js +164 -0
  37. package/lib/core/reconcile.d.ts +8 -0
  38. package/lib/core/reconcile.js +18 -3
  39. package/lib/core/reinstall.d.ts +2 -0
  40. package/lib/core/reinstall.js +6 -2
  41. package/lib/core/restore.js +31 -6
  42. package/lib/core/section-sanitize.d.ts +32 -0
  43. package/lib/core/section-sanitize.js +13 -0
  44. package/lib/core/snapshot-diff.d.ts +30 -0
  45. package/lib/core/snapshot-diff.js +56 -20
  46. package/lib/core/startup-barrier.js +8 -2
  47. package/lib/core/types.d.ts +22 -0
  48. package/lib/core/update-check.js +51 -2
  49. package/lib/foreign/kernel.js +9 -2
  50. package/lib/foreign/read-claude-plugins.js +29 -11
  51. package/lib/foreign/read-dsh.js +31 -2
  52. package/lib/foreign/session-ir.js +50 -9
  53. package/lib/foreign/session-read.d.ts +8 -0
  54. package/lib/foreign/session-read.js +26 -0
  55. package/lib/index.d.ts +1 -1
  56. package/lib/index.js +1 -1
  57. package/lib/profiles/dsh-profile-io.d.ts +20 -0
  58. package/lib/profiles/dsh-profile-io.js +27 -0
  59. package/lib/profiles/dsh-profile-manager.d.ts +27 -0
  60. package/lib/profiles/dsh-profile-manager.js +45 -4
  61. package/lib/profiles/dsh-profile-runtime.d.ts +5 -1
  62. package/lib/profiles/dsh-profile-runtime.js +16 -3
  63. package/lib/profiles/process-control.d.ts +18 -1
  64. package/lib/profiles/process-control.js +25 -1
  65. package/lib/routes/profiles.js +2 -1
  66. package/lib/routes/sync.js +13 -1
  67. package/lib/schema/types.d.ts +11 -0
  68. package/lib/security/redaction.js +22 -6
  69. package/lib/sync/autosync-repeat.d.ts +27 -0
  70. package/lib/sync/autosync-repeat.js +23 -0
  71. package/lib/sync/autosync-scheduler.d.ts +34 -1
  72. package/lib/sync/autosync-scheduler.js +151 -43
  73. package/lib/sync/baseline-heal.js +7 -0
  74. package/lib/sync/baseline-record.d.ts +67 -0
  75. package/lib/sync/baseline-record.js +74 -0
  76. package/lib/sync/blob-store.js +13 -0
  77. package/lib/sync/content-diff.d.ts +39 -0
  78. package/lib/sync/content-diff.js +46 -0
  79. package/lib/sync/git/git-transport.d.ts +32 -1
  80. package/lib/sync/git/git-transport.js +146 -26
  81. package/lib/sync/github-auth.d.ts +17 -1
  82. package/lib/sync/github-auth.js +37 -1
  83. package/lib/sync/merge-apply-plan.d.ts +38 -0
  84. package/lib/sync/merge-apply-plan.js +76 -0
  85. package/lib/sync/messages.d.ts +1 -0
  86. package/lib/sync/messages.js +2 -0
  87. package/lib/sync/pending-merge.d.ts +34 -0
  88. package/lib/sync/pending-merge.js +53 -0
  89. package/lib/sync/s3/s3-transport.d.ts +14 -2
  90. package/lib/sync/s3/s3-transport.js +72 -48
  91. package/lib/sync/sync-engine.d.ts +23 -40
  92. package/lib/sync/sync-engine.js +115 -132
  93. package/lib/sync/sync-history.d.ts +7 -0
  94. package/lib/sync/sync-state.d.ts +28 -0
  95. package/lib/sync/sync-state.js +20 -0
  96. package/lib/sync/transport.d.ts +12 -3
  97. package/lib/sync/transport.js +13 -4
  98. package/lib/sync/webdav/webdav-transport.d.ts +19 -2
  99. package/lib/sync/webdav/webdav-transport.js +81 -40
  100. package/lib/ui/commands.js +5 -11
  101. package/lib/ui/dsh-profiles-view.d.ts +8 -3
  102. package/lib/ui/dsh-profiles-view.js +9 -5
  103. package/lib/ui/i18n.d.ts +2 -1
  104. package/lib/ui/i18n.js +4 -2
  105. package/lib/ui/menu-placement.js +1 -1
  106. package/lib/ui/migration-consult-view.d.ts +11 -0
  107. package/lib/ui/migration-consult-view.js +15 -0
  108. package/lib/ui/overview-view.d.ts +7 -0
  109. package/lib/ui/overview-view.js +3 -0
  110. package/lib/ui/report.d.ts +9 -0
  111. package/lib/ui/report.js +17 -4
  112. package/lib/ui/selection-model.d.ts +8 -0
  113. package/lib/ui/selection-model.js +16 -0
  114. package/lib/utils/patch-yaml.d.ts +39 -1
  115. package/lib/utils/patch-yaml.js +82 -2
  116. package/lib/utils/paths.d.ts +13 -0
  117. package/lib/utils/paths.js +35 -0
  118. package/lib/utils/workdir-lock.js +18 -3
  119. package/package.json +2 -1
  120. package/src/adapters/mcp.test.ts +29 -0
  121. package/src/adapters/mcp.ts +43 -12
  122. package/src/adapters/messages.ts +2 -0
  123. package/src/adapters/patch-key-guard.ts +29 -0
  124. package/src/adapters/plugin-data.test.ts +126 -0
  125. package/src/adapters/plugin-data.ts +97 -26
  126. package/src/adapters/plugins.test.ts +288 -0
  127. package/src/adapters/plugins.ts +141 -4
  128. package/src/cli/actions.test.ts +74 -1
  129. package/src/cli/actions.ts +27 -246
  130. package/src/cli/control-state.ts +143 -0
  131. package/src/cli/index.ts +18 -0
  132. package/src/cli/web/web.test.ts +27 -0
  133. package/src/cli/write-gates.ts +149 -0
  134. package/src/client/about/AboutPanel.tsx +7 -6
  135. package/src/client/about/release-notes-view.test.ts +17 -0
  136. package/src/client/about/release-notes-view.ts +49 -24
  137. package/src/client/chat/ChatEntryView.tsx +2 -2
  138. package/src/client/chat/rollback-entry-view.ts +6 -1
  139. package/src/client/common/CommandPalette.tsx +6 -3
  140. package/src/client/common/ConfirmDialog.tsx +29 -12
  141. package/src/client/common/ContentPicker.tsx +13 -12
  142. package/src/client/common/Modal.tsx +12 -5
  143. package/src/client/common/MoreMenu.tsx +4 -1
  144. package/src/client/common/RunsCenter.tsx +103 -32
  145. package/src/client/common/Select.tsx +2 -2
  146. package/src/client/common/floating-bounds.ts +1 -1
  147. package/src/client/common/floating-units.test.ts +1 -2
  148. package/src/client/common/plan-text-redaction.test.ts +188 -3
  149. package/src/client/common/runs-center-guard.test.ts +60 -0
  150. package/src/client/common/runs-center-view.test.ts +128 -0
  151. package/src/client/common/runs-center-view.ts +96 -0
  152. package/src/client/common/section-title-action.test.ts +66 -0
  153. package/src/client/common/ui.tsx +93 -30
  154. package/src/client/config-manager.module.css +1507 -272
  155. package/src/client/consult/ConsultCard.tsx +7 -6
  156. package/src/client/environment/EnvironmentPanel.tsx +20 -21
  157. package/src/client/environment/maintenance/DiskUsageCard.tsx +65 -91
  158. package/src/client/environment/profiles-incomplete-ui.test.ts +8 -8
  159. package/src/client/export/ExportView.tsx +7 -16
  160. package/src/client/history/HistoryPanel.tsx +88 -28
  161. package/src/client/history/history-locales.ts +3 -3
  162. package/src/client/home/BackupScheduleCard.tsx +35 -30
  163. package/src/client/home/HomePanel.tsx +45 -10
  164. package/src/client/import/ConflictList.tsx +13 -13
  165. package/src/client/import/ForeignImportView.tsx +7 -6
  166. package/src/client/import/ImportWizardView.tsx +2 -3
  167. package/src/client/import/PathMappingForm.tsx +4 -4
  168. package/src/client/import/PathPickerDialog.tsx +2 -1
  169. package/src/client/import/import-wizard-steps.tsx +51 -39
  170. package/src/client/import/use-import-wizard-controller.test.ts +129 -0
  171. package/src/client/import/use-import-wizard-controller.ts +116 -22
  172. package/src/client/library/ArtifactRow.tsx +2 -2
  173. package/src/client/library/BackupInspectView.tsx +19 -15
  174. package/src/client/library/LibraryActions.tsx +56 -16
  175. package/src/client/library/LibraryPanel.tsx +7 -7
  176. package/src/client/library/RestorePlanView.tsx +13 -8
  177. package/src/client/locales/about.ts +0 -2
  178. package/src/client/locales/backup.ts +10 -12
  179. package/src/client/locales/common.ts +2 -0
  180. package/src/client/locales/export.ts +5 -12
  181. package/src/client/locales/foreign.ts +2 -2
  182. package/src/client/locales/import.ts +3 -2
  183. package/src/client/locales/overview.ts +4 -0
  184. package/src/client/locales/profiles.ts +32 -4
  185. package/src/client/locales/restore.ts +0 -2
  186. package/src/client/locales/sessions.ts +0 -2
  187. package/src/client/locales/shell.ts +2 -2
  188. package/src/client/market/MarketPanel.tsx +38 -20
  189. package/src/client/market/MyConfigsList.tsx +34 -32
  190. package/src/client/market/MyConfigsLoginCard.tsx +12 -15
  191. package/src/client/market/MyConfigsView.tsx +5 -5
  192. package/src/client/market/MyConfigsWizard.tsx +7 -12
  193. package/src/client/market/market-locales.ts +0 -6
  194. package/src/client/market/my-configs-split.test.ts +2 -1
  195. package/src/client/nav-menu-clip-guard.test.ts +52 -0
  196. package/src/client/recovery/IncompleteCopiesSection.tsx +1 -3
  197. package/src/client/recovery/RecoveryPanel.tsx +31 -16
  198. package/src/client/recovery/RollbackCard.tsx +58 -16
  199. package/src/client/recovery/RollbackFileChanges.tsx +40 -27
  200. package/src/client/recovery/SessionHealthCard.tsx +2 -2
  201. package/src/client/recovery/SessionHealthDialog.tsx +5 -7
  202. package/src/client/recovery/SessionLayoutSection.tsx +3 -5
  203. package/src/client/recovery/recovery-locales.ts +12 -8
  204. package/src/client/run-store.test.ts +30 -0
  205. package/src/client/run-store.ts +21 -1
  206. package/src/client/sync/AddChannelCard.tsx +65 -0
  207. package/src/client/sync/AutosyncCard.tsx +182 -108
  208. package/src/client/sync/ChannelClearConfirmDialog.tsx +5 -1
  209. package/src/client/sync/ChannelConfigDialog.tsx +27 -48
  210. package/src/client/sync/MergePreviewView.tsx +3 -5
  211. package/src/client/sync/PushReportSections.tsx +35 -0
  212. package/src/client/sync/SyncChannelEntryCard.tsx +33 -24
  213. package/src/client/sync/SyncConfirmView.tsx +3 -3
  214. package/src/client/sync/SyncLogList.tsx +16 -5
  215. package/src/client/sync/SyncPanel.tsx +153 -159
  216. package/src/client/sync/SyncProbeRow.tsx +5 -7
  217. package/src/client/sync/SyncRepositoryPicker.tsx +17 -4
  218. package/src/client/sync/SyncSecuritySection.tsx +157 -0
  219. package/src/client/sync/SyncSettingsDialog.tsx +304 -0
  220. package/src/client/sync/SyncSettingsView.test.ts +26 -8
  221. package/src/client/sync/WorkDirCard.tsx +2 -4
  222. package/src/client/sync/config-clear-guard.test.ts +94 -0
  223. package/src/client/sync/config-clear-guard.ts +98 -0
  224. package/src/client/sync/config-dirty.test.ts +91 -0
  225. package/src/client/sync/config-dirty.ts +88 -0
  226. package/src/client/sync/history-model.test.ts +2 -0
  227. package/src/client/sync/history-model.ts +3 -0
  228. package/src/client/sync/merge-request.ts +20 -0
  229. package/src/client/sync/sync-api.ts +12 -0
  230. package/src/client/sync/sync-locales.ts +87 -47
  231. package/src/client/sync/sync-panel-clear.test.ts +44 -0
  232. package/src/client/sync/sync-view.test.ts +20 -0
  233. package/src/client/sync/sync-view.ts +42 -4
  234. package/src/core/backup.test.ts +61 -1
  235. package/src/core/backup.ts +21 -4
  236. package/src/core/boot-rescue.test.ts +35 -0
  237. package/src/core/boot-rescue.ts +13 -2
  238. package/src/core/boot-safety.test.ts +25 -0
  239. package/src/core/boot-safety.ts +37 -2
  240. package/src/core/conflict-decisions.ts +2 -1
  241. package/src/core/exporter.ts +21 -1
  242. package/src/core/journal.test.ts +183 -0
  243. package/src/core/journal.ts +163 -25
  244. package/src/core/local-plugin-host.test.ts +68 -2
  245. package/src/core/local-plugin-host.ts +31 -4
  246. package/src/core/messages.ts +14 -0
  247. package/src/core/migration-history.test.ts +27 -0
  248. package/src/core/migration-history.ts +12 -4
  249. package/src/core/model-tools.test.ts +67 -0
  250. package/src/core/model-tools.ts +16 -4
  251. package/src/core/patch-secret-guard.test.ts +110 -0
  252. package/src/core/patch-secret-guard.ts +176 -0
  253. package/src/core/reconcile.ts +32 -4
  254. package/src/core/reinstall.ts +8 -2
  255. package/src/core/restore.ts +32 -7
  256. package/src/core/section-sanitize.ts +37 -0
  257. package/src/core/snapshot-diff.test.ts +73 -1
  258. package/src/core/snapshot-diff.ts +66 -21
  259. package/src/core/startup-barrier.test.ts +64 -0
  260. package/src/core/startup-barrier.ts +8 -2
  261. package/src/core/types.ts +27 -1
  262. package/src/core/update-check.test.ts +40 -0
  263. package/src/core/update-check.ts +53 -2
  264. package/src/foreign/claude-code.test.ts +5 -0
  265. package/src/foreign/claude-plugins.test.ts +57 -0
  266. package/src/foreign/claude-sessions-bytes.test.ts +7 -1
  267. package/src/foreign/dsh.test.ts +23 -0
  268. package/src/foreign/kernel.ts +9 -2
  269. package/src/foreign/read-claude-plugins.ts +32 -11
  270. package/src/foreign/read-dsh.ts +33 -2
  271. package/src/foreign/session-ir.test.ts +67 -0
  272. package/src/foreign/session-ir.ts +54 -14
  273. package/src/foreign/session-read.ts +23 -0
  274. package/src/index.ts +1 -1
  275. package/src/profiles/dsh-profile-copy-rollback.test.ts +58 -4
  276. package/src/profiles/dsh-profile-io.ts +29 -0
  277. package/src/profiles/dsh-profile-manager.test.ts +30 -0
  278. package/src/profiles/dsh-profile-manager.ts +53 -5
  279. package/src/profiles/dsh-profile-runtime.test.ts +29 -7
  280. package/src/profiles/dsh-profile-runtime.ts +17 -3
  281. package/src/profiles/process-control.test.ts +97 -0
  282. package/src/profiles/process-control.ts +28 -1
  283. package/src/routes/profiles.ts +2 -1
  284. package/src/routes/sync.ts +13 -1
  285. package/src/schema/types.ts +16 -1
  286. package/src/security/redaction.test.ts +31 -0
  287. package/src/security/redaction.ts +23 -6
  288. package/src/sync/autosync-repeat.test.ts +58 -0
  289. package/src/sync/autosync-repeat.ts +55 -0
  290. package/src/sync/autosync-scheduler.test.ts +417 -0
  291. package/src/sync/autosync-scheduler.ts +154 -41
  292. package/src/sync/baseline-heal.ts +6 -0
  293. package/src/sync/baseline-record.ts +135 -0
  294. package/src/sync/blob-store.test.ts +16 -0
  295. package/src/sync/blob-store.ts +13 -0
  296. package/src/sync/content-diff.test.ts +95 -0
  297. package/src/sync/content-diff.ts +79 -0
  298. package/src/sync/git/git-transport.test.ts +151 -4
  299. package/src/sync/git/git-transport.ts +143 -27
  300. package/src/sync/github-auth.test.ts +26 -1
  301. package/src/sync/github-auth.ts +37 -1
  302. package/src/sync/merge-apply-plan.ts +117 -0
  303. package/src/sync/messages.ts +2 -0
  304. package/src/sync/pending-merge.ts +77 -0
  305. package/src/sync/s3/s3-delete-and-blob-index.test.ts +249 -0
  306. package/src/sync/s3/s3-transport.ts +76 -42
  307. package/src/sync/sync-config.test.ts +39 -12
  308. package/src/sync/sync-device-identity.test.ts +3 -0
  309. package/src/sync/sync-engine.test.ts +465 -12
  310. package/src/sync/sync-engine.ts +130 -135
  311. package/src/sync/sync-history.ts +7 -0
  312. package/src/sync/sync-state.ts +48 -0
  313. package/src/sync/transport.test.ts +13 -1
  314. package/src/sync/transport.ts +12 -4
  315. package/src/sync/webdav/webdav-delete-and-blob-index.test.ts +249 -0
  316. package/src/sync/webdav/webdav-transport.ts +86 -34
  317. package/src/ui/commands.test.ts +11 -0
  318. package/src/ui/commands.ts +5 -14
  319. package/src/ui/dsh-profiles-view.test.ts +16 -0
  320. package/src/ui/dsh-profiles-view.ts +11 -5
  321. package/src/ui/i18n.ts +4 -2
  322. package/src/ui/menu-placement.ts +1 -1
  323. package/src/ui/migration-consult-view.test.ts +20 -1
  324. package/src/ui/migration-consult-view.ts +17 -0
  325. package/src/ui/overview-view.ts +10 -0
  326. package/src/ui/report.test.ts +25 -1
  327. package/src/ui/report.ts +15 -4
  328. package/src/ui/selection-model.test.ts +15 -1
  329. package/src/ui/selection-model.ts +18 -0
  330. package/src/utils/js-yaml4.d.ts +35 -0
  331. package/src/utils/patch-yaml.test.ts +207 -1
  332. package/src/utils/patch-yaml.ts +98 -2
  333. package/src/utils/paths.test.ts +14 -1
  334. package/src/utils/paths.ts +35 -0
  335. package/src/utils/workdir-lock.test.ts +69 -0
  336. package/src/utils/workdir-lock.ts +17 -3
  337. package/lib/ui/path-mapping.d.ts +0 -38
  338. package/lib/ui/path-mapping.js +0 -75
  339. package/src/client/common/InfoHint.tsx +0 -289
  340. package/src/client/common/info-hint-guard.test.ts +0 -1119
  341. package/src/client/sync/DecryptPasswordCard.tsx +0 -48
  342. package/src/client/sync/SecurityOptionsCard.tsx +0 -97
  343. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -213
  344. package/src/ui/path-mapping.test.ts +0 -67
  345. package/src/ui/path-mapping.ts +0 -103
@@ -0,0 +1,143 @@
1
+ /**
2
+ * 救急台与 CLI 共用的**只读事实层**:进程存活、心跳实例、SAFE MODE 标记、环境锁状态。
3
+ *
4
+ * 为什么单独成文件:这四件事是「写动作前置门」与首页聚合共同依赖的最小事实集,原先挤在
5
+ * 1600 行的 actions.ts 里(体量棘轮已顶格)。这里**只放读取**,判据仍只由 core/utils 给,
6
+ * 绝不因为「看起来像残留」就自行回收(回收只有显式命令一条路)。
7
+ */
8
+ import fssync from 'node:fs'
9
+ import fsp from 'node:fs/promises'
10
+ import path from 'node:path'
11
+
12
+ import { readSafeModeMarkerSync, safeModeMarkerPath } from '../core/phase3-host.ts'
13
+ import { parseRuntimeRecord, RUNTIME_STALE_MS } from '../profiles/dsh-profile-runtime.ts'
14
+ import { EnvironmentLockManager, OWNERSHIP_FILE } from '../utils/env-lock.ts'
15
+
16
+
17
+ /* ------------------------------------------------------------ 进程/实例事实 */
18
+
19
+ /** 进程是否存活(不发送信号,只探测)。EPERM = 存在但无权限发信号 → 仍算存活。 */
20
+ export function isProcessAlive(pid: number): boolean {
21
+ try {
22
+ process.kill(pid, 0)
23
+ return true
24
+ } catch (error) {
25
+ return (error as NodeJS.ErrnoException).code === 'EPERM'
26
+ }
27
+ }
28
+
29
+ /** 一个在跑的 DSH 实例(来自 `<root>/running/<profile>.json` 心跳)。 */
30
+ export interface RunningInstance {
31
+ name: string
32
+ pid: number
33
+ port: number | null
34
+ startedAt: string
35
+ updatedAt: number
36
+ }
37
+
38
+ /**
39
+ * 读「本机正在跑的 DSH 实例」。
40
+ *
41
+ * **为什么按候选根扫描**:心跳在 `<插件 dataDir>/running/`,而 CLI 的 `--data-dir` 语义是
42
+ * 「快照目录」(缺省 `$DSH_HOME/dsh-config-manager/snapshots`)。旧实现把快照目录当 dataDir 用,
43
+ * 于是缺省路径下**永远找不到心跳** —— 那道「DSH 在跑就别写会话字节」的门形同虚设(fail-open)。
44
+ * 这里改为复用 `resolveControlRoots` 的候选根:显式 `--data-root` 只认它,否则同时看
45
+ * `--data-dir` 本身与它的父目录,再叠加缺省根;多查几处只会更保守。
46
+ */
47
+ export async function readRunningInstances(controlRoots: readonly string[]): Promise<RunningInstance[]> {
48
+ const alive: RunningInstance[] = []
49
+ const seen = new Set<string>()
50
+ const now = Date.now()
51
+ for (const root of controlRoots) {
52
+ const dir = path.join(root, 'running')
53
+ let names: string[]
54
+ try {
55
+ names = (await fsp.readdir(dir)).filter((n) => n.endsWith('.json'))
56
+ } catch {
57
+ continue // 该候选根没有心跳目录:正常情况,不阻断
58
+ }
59
+ for (const name of names) {
60
+ try {
61
+ const record = parseRuntimeRecord(await fsp.readFile(path.join(dir, name), 'utf8'))
62
+ if (record === null) continue
63
+ if (!isProcessAlive(record.pid) || now - record.updatedAt > RUNTIME_STALE_MS) continue
64
+ const key = record.name + '#' + String(record.pid)
65
+ if (seen.has(key)) continue
66
+ seen.add(key)
67
+ alive.push({
68
+ name: record.name,
69
+ pid: record.pid,
70
+ port: record.port,
71
+ startedAt: record.startedAt,
72
+ updatedAt: record.updatedAt,
73
+ })
74
+ } catch {
75
+ // 单条心跳读不出来不阻断(best-effort)
76
+ }
77
+ }
78
+ }
79
+ return alive
80
+ }
81
+
82
+ /* ------------------------------------------------------------ SAFE MODE / 环境锁 */
83
+
84
+ export interface SafeModeReport {
85
+ /** 候选控制面根 */
86
+ root: string
87
+ /** 标记文件绝对路径(写进界面,便于人工核对) */
88
+ marker: string
89
+ /** clear = 明确没有标记;blocked = 有未结案的 transaction;unknown = 读不出来(按阻断处理) */
90
+ state: ReturnType<typeof readSafeModeMarkerSync>
91
+ /**
92
+ * 该候选根下是否已经存在有效的「控制面目录」(dataDir 或 transactions)。
93
+ *
94
+ * 为什么需要:候选根里绝大多数**本来就不存在**(`--data-dir` 的父目录、缺省根都可能没有),
95
+ * 那些根的 'clear' 只是「这里什么都没建」,把它当成「SAFE MODE 未激活」的正面证据是把
96
+ * 「没查」说成「没问题」。界面只在**有效根**上给绿灯,其余如实说「未建立 / 未发现标记」。
97
+ */
98
+ established: boolean
99
+ }
100
+
101
+ /** 逐个候选根读 SAFE MODE 标记(fail-closed 的判定仍在 CLI/core;这里只报事实)。 */
102
+ export function readSafeMode(controlRoots: readonly string[]): SafeModeReport[] {
103
+ return controlRoots.map((root) => ({
104
+ root,
105
+ marker: safeModeMarkerPath(root),
106
+ state: readSafeModeMarkerSync(root),
107
+ established: fssync.existsSync(root) || fssync.existsSync(path.join(root, 'transactions')),
108
+ }))
109
+ }
110
+
111
+ export interface LockReport {
112
+ locksDir: string
113
+ /** 锁文件是否存在(不存在 = 没有活动锁) */
114
+ present: boolean
115
+ /** 没有锁时恒为 'NONE';否则为 inspectLockState 的结论 */
116
+ state: string
117
+ detail?: string
118
+ }
119
+
120
+ /**
121
+ * 读环境锁状态(只读)。
122
+ *
123
+ * 复用宿主/CLI 同一套 `inspectLockState`:**绝不**因为「看起来是残留」就自动回收 ——
124
+ * 回收只有显式命令一条路(`recover-stale-lock`)。
125
+ */
126
+ export async function readLockState(locksDir: string): Promise<LockReport> {
127
+ const present = await pathExists(path.join(locksDir, OWNERSHIP_FILE))
128
+ if (!present) return { locksDir, present: false, state: 'NONE' }
129
+ const lock = new EnvironmentLockManager({ locksDir, op: 'rescue-console-inspect', target: locksDir, lockVersion: '0.1.0' })
130
+ const inspection = await lock.inspectLockState()
131
+ return inspection.detail === undefined
132
+ ? { locksDir, present: true, state: inspection.state }
133
+ : { locksDir, present: true, state: inspection.state, detail: inspection.detail }
134
+ }
135
+
136
+ async function pathExists(target: string): Promise<boolean> {
137
+ try {
138
+ await fsp.stat(target)
139
+ return true
140
+ } catch {
141
+ return false
142
+ }
143
+ }
package/src/cli/index.ts CHANGED
@@ -833,6 +833,19 @@ async function runReinstall(
833
833
  return 1;
834
834
  }
835
835
 
836
+ // AGENTS「CLI 与救急台同一道写入门」第三道:DSH 未运行。
837
+ // 清空 settings/plugins/data 会删掉运行中实例的 profiles 与 sessions(审计 P11-5)。
838
+ if (plan.wipeConfig) {
839
+ const runningGate = await checkWriteGates(
840
+ resolveControlRoots({ dataRoot: options.dataRoot, dataDir: options.dataDir }, env),
841
+ { needsDshStopped: true },
842
+ );
843
+ if (!runningGate.ok) {
844
+ io.error(`拒绝执行:${runningGate.reason}`);
845
+ return 1;
846
+ }
847
+ }
848
+
836
849
  // 执行(Phase 2 锁:reinstall 卸载/清扫/重装属 GLOBAL destructive,必须成功获取环境锁)
837
850
  const lockHome = resolveDshHome(env);
838
851
  const lock = new EnvironmentLockManager({
@@ -889,6 +902,11 @@ async function runReinstall(
889
902
  const reason = err instanceof Error ? err.message : String(err);
890
903
  failed.push({ label: step.label, command: step.command, reason });
891
904
  io.error(`✘ ${step.label} — ${reason}`);
905
+ // 备份步(critical)失败时后面的清空没有抢救副本:中止剩余步骤(审计 P11-7)。
906
+ if (step.critical === true) {
907
+ io.error('✘ 兜底备份失败,已中止后续清空步骤(未删除任何 ~/.dsh 数据)/ backup failed, aborting remaining steps');
908
+ return;
909
+ }
892
910
  }
893
911
  }
894
912
  };
@@ -486,6 +486,33 @@ test('V-F1 写门:存在残留锁时写动作被拒(文档与防线一致)
486
486
  })
487
487
  })
488
488
 
489
+ test('V-F1c 写门:就地修复(POST /sessions/inline-repair)同受环境锁拦截(审计 P11-4)', async () => {
490
+ await withConsole(async (handle, paths) => {
491
+ const { cookie } = await bootstrap(handle)
492
+ // 错位会话 → /sessions 页渲染出确认表单(动作 token 本次控制台通用,从那里取)
493
+ const { encodeZstdFrame } = await import('../../utils/zstd-frame.ts')
494
+ const dir = path.join(paths.homeDir, 'sessions', '--D-Ghost-proj--', 'session-inline')
495
+ await fs.mkdir(dir, { recursive: true })
496
+ await fs.writeFile(path.join(dir, 'session.v3.jsonl.zstd'), Buffer.concat([
497
+ encodeZstdFrame(Buffer.from(JSON.stringify({ version: 3, id: 'session-inline', cwd: 'D:/Real/proj' }) + '\n', 'utf8')),
498
+ encodeZstdFrame(Buffer.from('{"seq":1}\n', 'utf8')),
499
+ ]))
500
+ // stale 锁(ownership 指向不存在的 pid):就地修复此前不传 locksDir ⇒ 照样改写 .zstd 字节
501
+ await fs.mkdir(paths.locksDir, { recursive: true })
502
+ await fs.writeFile(path.join(paths.locksDir, 'environment.lock'), JSON.stringify({
503
+ schemaVersion: 1, op: 'test-op', target: 'x', lockVersion: '0.1.0',
504
+ owner: { instanceId: 'dead-instance', instanceStartedAt: Date.now() - 600_000, pid: 999_999_999, hostname: 'h' },
505
+ createdAt: Date.now() - 600_000,
506
+ }))
507
+ const html = await getPage(handle, cookie!, '/sessions')
508
+ const token = actionTokenOf(html)
509
+ const res = await postForm(handle, cookie!, '/sessions/inline-repair', { 'unit:ghost/session-inline': 'on', token })
510
+ assert.equal(res.status, 409, res.body.slice(0, 300))
511
+ assert.match(res.body, /就地修复未执行(写入门拒绝)/, '被门拒绝(而不是进到逐条执行后的「有未完成项」)')
512
+ assert.match(res.body, /环境锁/)
513
+ })
514
+ })
515
+
489
516
  test('V-F2 读不到 ≠ 没有:快照/导出目录不可读时首页给出横幅,而不是「没有」', async () => {
490
517
  await withConsole(async (handle, paths) => {
491
518
  const { cookie } = await bootstrap(handle)
@@ -0,0 +1,149 @@
1
+ /**
2
+ * 写动作的三道门(SAFE MODE → 残留环境锁 → DSH 未运行),CLI 与救急台网页共用同一实现。
3
+ *
4
+ * 为什么单独成文件:门的判据必须唯一(网页不许自己重写判定),而它依赖的只读事实在
5
+ * control-state.ts;从 1600 行的 actions.ts 里拆出来后,调用点仍经 actions.ts 的 re-export 取用。
6
+ */
7
+ import fssync from 'node:fs'
8
+ import path from 'node:path'
9
+
10
+ import { OWNERSHIP_FILE } from '../utils/env-lock.ts'
11
+ import { readLockState, readRunningInstances, readSafeMode } from './control-state.ts'
12
+
13
+
14
+ export type WriteRefusalCode =
15
+ | 'safe-mode'
16
+ | 'stale-lock'
17
+ | 'dsh-running'
18
+ | 'nothing-to-do'
19
+ | 'io-error'
20
+
21
+ /**
22
+ * SAFE MODE 拒因码的**单点常量**:`src/cli/index.ts` 的源码守卫(P0-11-07)禁止
23
+ * CLI 自带 `'safe-mode'` 字面量,判据必须复用本常量(否则改一处漏一处)。
24
+ */
25
+ export const SAFE_MODE_REFUSAL_CODE: WriteRefusalCode = 'safe-mode'
26
+
27
+ export interface WriteGateRefusal {
28
+ ok: false
29
+ code: WriteRefusalCode
30
+ /** 用户可读原因(页面直接展示) */
31
+ reason: string
32
+ /**
33
+ * 拒因的结构化明细(页面据此给出「怎么解除」的可操作指引,而不是只丢一句 reason)。
34
+ *
35
+ * 为什么要有:`dsh-running` 是最常被撞到的一道门,光给「请先关闭 DSH」用户会问
36
+ * 「关哪个、怎么确认关掉了」。这里把**是谁在跑**(心跳台账里的 profile/pid/端口)
37
+ * 如实带出来 —— 只读事实,不猜、不代关进程。
38
+ */
39
+ detail?: {
40
+ kind: 'dsh-running' | 'stale-lock' | 'safe-mode'
41
+ /** 正在运行的实例(心跳合并视图:本插件启动的 + 手动启动的) */
42
+ instances?: Array<{ name: string; pid: number; port: number | null }>
43
+ /** 环境锁状态(kind = 'stale-lock') */
44
+ lock?: { state: string; locksDir: string }
45
+ /** SAFE MODE 标记文件(kind = 'safe-mode') */
46
+ markers?: string[]
47
+ /** 与 CLI 逐字同源的等价命令(可复制去终端跑) */
48
+ commands: string[]
49
+ }
50
+ }
51
+
52
+ export type WriteGateOutcome = { ok: true } | WriteGateRefusal
53
+
54
+ /**
55
+ * 从控制面候选根派生**环境锁目录**(`<root>/locks`)。
56
+ *
57
+ * 为什么由根派生而不是让每个调用点多传一个参数:`checkWriteGates` 的 `locksDir` 是**可选**的,
58
+ * 「少传一个参数」就静默退化成「不查环境锁」。审计 P11-4 正是这么漏掉的:就地修复(repairSessionLogInline)
59
+ * 不传 locksDir,残留/被持有的环境锁存在时照样改写 `.zstd` 会话字节。
60
+ * 派生顺序与 `resolveControlRoots` 同源:第一个真实持有 `locks/environment.lock` 的候选根;
61
+ * 都没有就退回首个候选的 `locks`(读不到即视为无锁,判据仍只由 readLockState 给)。
62
+ */
63
+ export function locksDirFromControlRoots(controlRoots: readonly string[]): string | undefined {
64
+ const first = controlRoots[0]
65
+ if (first === undefined) return undefined
66
+ for (const root of controlRoots) {
67
+ const candidate = path.join(root, 'locks')
68
+ if (fssync.existsSync(path.join(candidate, OWNERSHIP_FILE))) return candidate
69
+ }
70
+ return path.join(first, 'locks')
71
+ }
72
+
73
+ /**
74
+ * 写动作的前置门(与 CLI `sessions repair --fix` 同一判据)。
75
+ *
76
+ * `needsDshStopped`:**改写/搬动会话字节**的动作(会话布局归位 repairSessions、字节级就地修复
77
+ * repairSessionLogInline)与**快照恢复**(runSnapshotRestore 会覆盖/删除 `$DSH_HOME` 下正在使用的文件)
78
+ * 都要「DSH 已停」这一条;磁盘清理不需要(只碰可重建缓存)。
79
+ */
80
+ export async function checkWriteGates(
81
+ controlRoots: readonly string[],
82
+ options: { needsDshStopped: boolean; locksDir?: string } = { needsDshStopped: true },
83
+ ): Promise<WriteGateOutcome> {
84
+ for (const report of readSafeMode(controlRoots)) {
85
+ if (report.state === 'blocked') {
86
+ return {
87
+ ok: false,
88
+ code: 'safe-mode',
89
+ reason: 'SAFE MODE 已激活(存在未结案的配置 transaction):先处理恢复事项再改磁盘。标记:' + report.marker,
90
+ }
91
+ }
92
+ if (report.state === 'unknown') {
93
+ return {
94
+ ok: false,
95
+ code: 'safe-mode',
96
+ reason: 'SAFE MODE 标记无法判定(按最保守口径处理):先人工核对标记文件。路径:' + report.marker,
97
+ }
98
+ }
99
+ }
100
+ /**
101
+ * ② 环境锁:**存在锁就必须先处理**。
102
+ *
103
+ * 为什么不能跳过:CLI 侧 destructive 入口(restore/reinstall)都要求成功获取 GLOBAL 环境锁,
104
+ * 而残留锁(STALE_LOCK_DETECTED)正是「上次异常退出、别的操作也被挡着」的状态;
105
+ * 这时改磁盘等于在一个已知不一致的状态上继续写。判据与 `recover-stale-lock` 同源(inspectLockState),
106
+ * 所以**不给自动回收**,只如实拒绝并把出口指出来。
107
+ */
108
+ // 环境锁目录**不再由调用点决定是否检查**(审计 P11-10):locksDir 曾经是可选参数,
109
+ // 「少传一个」就静默退化成「不查环境锁」——5 个调用点因此排出 3 种组合、实漏 2 处。
110
+ // 现在缺省一律由控制面根派生(与 locksDirFromControlRoots 同源),调用点只在
111
+ // 「锁目录确实不在 <root>/locks」时才需要显式覆盖。
112
+ const locksDir = options.locksDir ?? locksDirFromControlRoots(controlRoots)
113
+ if (locksDir !== undefined) {
114
+ const lock = await readLockState(locksDir)
115
+ if (lock.present) {
116
+ const stale = lock.state === 'STALE_LOCK_DETECTED'
117
+ return {
118
+ ok: false,
119
+ code: 'stale-lock',
120
+ reason: (stale
121
+ ? '检测到残留的环境锁(持有进程已被确证不存在):先回收它再执行写动作。'
122
+ : '环境锁被持有或状态无法判定(' + lock.state + '):先确认没有其它操作在跑,再执行写动作。')
123
+ + '锁目录:' + lock.locksDir + ';出口:dsh-config-manager recover-stale-lock(本机救急台的「环境锁」页也可回收)。',
124
+ }
125
+ }
126
+ }
127
+ if (options.needsDshStopped) {
128
+ const running = await readRunningInstances(controlRoots)
129
+ if (running.length > 0) {
130
+ return {
131
+ ok: false,
132
+ code: 'dsh-running',
133
+ reason: '检测到 DSH 正在运行(' + running.map((i) => i.name + ' pid=' + String(i.pid)).join('、')
134
+ + '):请先关闭 DSH 再改写会话字节。',
135
+ detail: {
136
+ kind: 'dsh-running',
137
+ instances: running.map((i) => ({ name: i.name, pid: i.pid, port: i.port })),
138
+ commands: [
139
+ // 桌面端独占档案不让普通 CLI 停,如实给出「关窗口」这条唯一通道(见 AGENTS.md 的 desktop 条)
140
+ ...running.filter((i) => i.name === 'desktop').map(() => '桌面端(desktop):直接关闭 DSH 桌面窗口;它不接受命令行停止'),
141
+ ...running.filter((i) => i.name !== 'desktop').map((i) => 'dsh-config-manager stop ' + i.name + ' # 或在「档案与实例」页点「停止 ' + i.name + '」'),
142
+ 'dsh-config-manager web # 停完再回本页点「重新检查」',
143
+ ],
144
+ },
145
+ }
146
+ }
147
+ }
148
+ return { ok: true }
149
+ }
@@ -22,7 +22,6 @@ import type { ConfigManagerApi } from '../api.ts'
22
22
  import { Badge, Banner, Button, Card } from '../common/ui.tsx'
23
23
  import { Skeleton } from '../common/Skeleton.tsx'
24
24
  import { CopyButton } from '../common/CopyButton.tsx'
25
- import { InfoHint } from '../common/InfoHint.tsx'
26
25
  import { ABOUT_CLI, ABOUT_LINKS, ABOUT_META, aboutStatusRows, aboutUpdateView, buildFeedbackSnippet } from './about-view.ts'
27
26
  import type { AboutStatusRows, AboutUpdateView } from './about-view.ts'
28
27
  import { ReleaseNotesDialog } from './ReleaseNotesDialog.tsx'
@@ -134,7 +133,7 @@ export function AboutPanel({ api, t }: AboutPanelProps) {
134
133
  用于自查「装了插件却没被备份识别到」——此前用户完全无从查看。 */}
135
134
  {state.rows?.diagnostics != null && (
136
135
  <div className={css.statRow + ' ' + css.statRowStack}>
137
- <span className={css.groupLabel}>{t('about.diag.label')} <InfoHint text={t('about.diag.hint')} label={t('common.infoHint')} /></span>
136
+ <span className={css.groupLabel} title={t('about.diag.hint')}>{t('about.diag.label')}</span>
138
137
  <span>{t('about.diag.profileDir', { path: state.rows.diagnostics.profileDir })}</span>
139
138
  <span>{t('about.diag.profile', { profile: state.rows.diagnostics.profile })}</span>
140
139
  <span>{t('about.diag.pluginCount', { count: String(state.rows.diagnostics.pluginCount) })}</span>
@@ -148,7 +147,6 @@ export function AboutPanel({ api, t }: AboutPanelProps) {
148
147
  拼接规则是 ./about-view.ts 的纯函数,组件只装配(AGENTS.md §UI 分层铁律)。 */}
149
148
  {state.rows !== null && (
150
149
  <div className={css.actionRow}>
151
- <InfoHint text={t('about.feedbackHint')} label={t('common.infoHint')} />
152
150
  <CopyButton
153
151
  text={buildFeedbackSnippet(state.rows, t)}
154
152
  label={t('about.copyEnv')}
@@ -162,7 +160,7 @@ export function AboutPanel({ api, t }: AboutPanelProps) {
162
160
  为什么放在「关于」页:这是用户唯一会主动查看「我装的是哪一版」的地方;
163
161
  检查失败如实显示原因并允许重试,绝不显示成「已是最新」。 */}
164
162
  <Card>
165
- <span className={css.groupLabel}>{t('about.update.title')} <InfoHint text={t('about.update.offline')} label={t('common.infoHint')} /></span>
163
+ <span className={css.groupLabel} title={t('about.update.offline')}>{t('about.update.title')}</span>
166
164
  <div className={css.statRow}>
167
165
  {state.rows !== null && (
168
166
  <Badge kind="info">{t('about.update.current', { version: state.rows.version })}</Badge>
@@ -216,7 +214,10 @@ export function AboutPanel({ api, t }: AboutPanelProps) {
216
214
  <Card>
217
215
  <span className={css.groupLabel}>{t('about.links')}</span>
218
216
  <div className={css.actionRow}>
219
- <Button variant="primary" href={ABOUT_LINKS.starUrl}>{t('about.star')}</Button>
217
+ {/* 只有一颗 primary 的纪律:本页的 primary 属于「立即更新」(更新卡),
218
+ Star 是外链邀请、与更新抢同一层强调时,用户会先看见「去点赞」而错过更新。
219
+ 2026-11-13 随设计稿落地改为 ghost(0.5px 描边),行为与落点不变。 */}
220
+ <Button href={ABOUT_LINKS.starUrl}>{t('about.star')}</Button>
220
221
  </div>
221
222
  <div className={css.aboutLinkRow}>
222
223
  <Button href={ABOUT_LINKS.repoUrl}>{t('about.repo')}</Button>
@@ -239,7 +240,7 @@ export function AboutPanel({ api, t }: AboutPanelProps) {
239
240
 
240
241
  {/* P1-⑩:CLI 救援工具引导卡(GUI 里唯一能发现 CLI 的地方;独立安装、DSH 挂了也能用) */}
241
242
  <Card>
242
- <span className={css.groupLabel}>{t('about.cli.title')} <InfoHint text={t('about.cli.hint')} label={t('common.infoHint')} /></span>
243
+ <span className={css.groupLabel} title={t('about.cli.hint')}>{t('about.cli.title')}</span>
243
244
  <pre className={css.cliCommand}>{ABOUT_CLI.installCommand}</pre>
244
245
  <ul className={css.reportList}>
245
246
  {ABOUT_CLI.commands.map((c) => (
@@ -152,6 +152,23 @@ test('fetchReleases: 错误处理(403 限流 / 404 / 500)', async () => {
152
152
  assert.equal(res404.hasMore, false);
153
153
  });
154
154
 
155
+ test('fetchReleases: 请求挂住时按超时失败,不会永久停在骨架(审计 P8-4)', async () => {
156
+ let sawSignal = false;
157
+ const hanging = (_url: string, init?: RequestInit) => {
158
+ sawSignal = init?.signal instanceof AbortSignal;
159
+ return new Promise<Response>((_resolve, reject) => {
160
+ init?.signal?.addEventListener('abort', () => {
161
+ reject(new DOMException('This operation was aborted', 'AbortError'));
162
+ });
163
+ });
164
+ };
165
+ await assert.rejects(
166
+ () => fetchReleases('https://github.com/foo/bar', 1, 5, hanging as unknown as typeof fetch, t, 20),
167
+ /超时/,
168
+ );
169
+ assert.equal(sawSignal, true, '必须把 AbortSignal 交给 fetcher,否则超时无从生效');
170
+ });
171
+
155
172
  test('parseMarkdownBlocks: 解析标题、列表、引用、代码块与段落', () => {
156
173
  const md = [
157
174
  '# Release 1.0',
@@ -140,8 +140,19 @@ export function parseReleasesResponse(data: unknown): FormattedRelease[] {
140
140
  return list;
141
141
  }
142
142
 
143
+ /**
144
+ * 单次 GitHub API 请求的上限(ms)。
145
+ *
146
+ * 审计 P8-4:此前没有任何超时 —— 连接被静默丢弃(代理、断网、NAT 超时)时 fetch 既不
147
+ * resolve 也不 reject,更新说明弹窗就永久停在骨架,用户既看不到错也没有可点的重试。
148
+ * 10 s 覆盖移动网络最差的一段交互等待,又不至于让慢但可用的链路被误判。
149
+ */
150
+ const RELEASES_FETCH_TIMEOUT_MS = 10_000;
151
+
143
152
  /**
144
153
  * 分页获取 GitHub Releases。
154
+ *
155
+ * `timeoutMs` 覆盖**整次请求**(含读 body):只有响应头到达、body 挂住同样会卡住弹窗。
145
156
  */
146
157
  export async function fetchReleases(
147
158
  repoUrl: string,
@@ -149,35 +160,49 @@ export async function fetchReleases(
149
160
  perPage = 5,
150
161
  fetcher: typeof fetch = globalThis.fetch,
151
162
  t: TranslateNS<'config-manager'>,
163
+ timeoutMs = RELEASES_FETCH_TIMEOUT_MS,
152
164
  ): Promise<FetchReleasesResult> {
153
165
  const url = buildReleasesApiUrl(repoUrl, page, perPage);
154
- const res = await fetcher(url, {
155
- headers: {
156
- Accept: 'application/vnd.github.v3+json',
157
- },
158
- });
159
-
160
- if (!res.ok) {
161
- if (res.status === 403 || res.status === 429) {
162
- throw new Error(t('about.releaseNotes.rateLimited'));
166
+ const controller = new AbortController();
167
+ const timer = setTimeout(() => { controller.abort() }, timeoutMs);
168
+ try {
169
+ const res = await fetcher(url, {
170
+ headers: {
171
+ Accept: 'application/vnd.github.v3+json',
172
+ },
173
+ signal: controller.signal,
174
+ });
175
+
176
+ if (!res.ok) {
177
+ if (res.status === 403 || res.status === 429) {
178
+ throw new Error(t('about.releaseNotes.rateLimited'));
179
+ }
180
+ if (res.status === 404) {
181
+ return { releases: [], hasMore: false, page };
182
+ }
183
+ throw new Error(t('about.releaseNotes.fetchFailed', { status: String(res.status), statusText: res.statusText }));
163
184
  }
164
- if (res.status === 404) {
165
- return { releases: [], hasMore: false, page };
185
+
186
+ const json: unknown = await res.json();
187
+ const releases = parseReleasesResponse(json);
188
+
189
+ // 如果返回的有效条目数达到 perPage,则推测还有下一页
190
+ const hasMore = Array.isArray(json) && json.length >= perPage;
191
+
192
+ return {
193
+ releases,
194
+ hasMore,
195
+ page,
196
+ };
197
+ } catch (err) {
198
+ // 自己发起的中止 = 超时:给用户一句能照做的原因,而不是把 AbortError 原样抛上去
199
+ if (controller.signal.aborted) {
200
+ throw new Error(t('about.releaseNotes.timeout', { seconds: String(Math.round(timeoutMs / 1000)) }));
166
201
  }
167
- throw new Error(t('about.releaseNotes.fetchFailed', { status: String(res.status), statusText: res.statusText }));
202
+ throw err;
203
+ } finally {
204
+ clearTimeout(timer);
168
205
  }
169
-
170
- const json: unknown = await res.json();
171
- const releases = parseReleasesResponse(json);
172
-
173
- // 如果返回的有效条目数达到 perPage,则推测还有下一页
174
- const hasMore = Array.isArray(json) && json.length >= perPage;
175
-
176
- return {
177
- releases,
178
- hasMore,
179
- page,
180
- };
181
206
  }
182
207
 
183
208
  /* ---------------- 轻量级 Markdown 块解析 ---------------- */
@@ -426,8 +426,8 @@ function ChatEntryBody({ node, sessionId, openFile, openSkill, renderMessageImag
426
426
  <ChatEntryCopyAction text={bubble.text} t={t} />
427
427
  {/* 回退入口:**只有图标**(无文字标签、无边框按钮样式),与时间戳/复制图标同一行同观感 ——
428
428
  2026-10-10 用户第二条要求「回退按钮只有一个 icon 而不是一个按钮」。可见文案退到
429
- aria-label/title;禁用原因是原生 title 里的一句话(InfoHint 的 Portal 钉在插件设置页
430
- 根节点,聊天区不存在)。按钮始终留在原地(禁用而不是消失):入口可见性不随判据漂移。 */}
429
+ aria-label/title;禁用原因是原生 title 里的一句话。按钮始终留在原地(禁用而不是消失):
430
+ 入口可见性不随判据漂移。 */}
431
431
  {/* 开关**关闭时整颗收起**(issue #88 明确要求「入口收起」,不是置灰;2026-10-17 起连登记
432
432
  都会被撤销,整条气泡交回宿主原生渲染,这里只是兜底的那一层)。
433
433
  与上面那条「入口可见性不随判据漂移」不冲突:那说的是**暂时读不到点**这类判据,
@@ -179,9 +179,14 @@ export function chatFileChangeAvailable(files: readonly ChatPreviewFileRow[]): b
179
179
  export function readRollbackPreviewRemovals(workspace: unknown): string[] {
180
180
  const removals = (workspace as { removals?: unknown } | null | undefined)?.removals
181
181
  if (!Array.isArray(removals)) return []
182
+ // 去重集与结果数组分开:此前用 out.includes(item) 线性查重,2 万条路径的回滚预览是
183
+ // O(n²),实测主线程阻塞 2.2 s(审计 P8-3),而这一层每次渲染都会重算。Set 把判重降为 O(1),
184
+ // 输出顺序仍按引擎给的顺序(不受 Set 插入顺序以外的任何影响)。
185
+ const seen = new Set<string>()
182
186
  const out: string[] = []
183
187
  for (const item of removals) {
184
- if (typeof item !== 'string' || item === '' || out.includes(item)) continue
188
+ if (typeof item !== 'string' || item === '' || seen.has(item)) continue
189
+ seen.add(item)
185
190
  out.push(item)
186
191
  }
187
192
  return out
@@ -116,15 +116,18 @@ export function CommandPalette({ open, onClose, commands, ctx, onRun, t }: Comma
116
116
  open={open}
117
117
  onClose={onClose}
118
118
  title={t('palette.label')}
119
- wide
120
- cardStyle={{ maxHeight: 460 }}
119
+ // D-30(2026-11-14):顶部锚定 + 420 宽的单列浮层。原来借用 wide(720px 居中)——
120
+ // 命令面板只有「一条输入 + 一列结果」,撑到 720 会读成一个空表单。
121
+ placement="top"
122
+ cardStyle={{ width: 'min(420px, calc(100vw - 48px))', maxHeight: 460 }}
121
123
  onOpenAutoFocus={(e) => {
122
124
  // 显式把初始焦点给输入框(Radix 默认落在第一个可聚焦元素上,这里指定更稳)
123
125
  e.preventDefault()
124
126
  inputRef.current?.focus()
125
127
  }}
126
128
  >
127
- <Modal.Body>
129
+ {/* Body 走纵向 flex:输入条定高、列表独占剩余空间内滚、提示行吸底(D-30 三段布局)。 */}
130
+ <Modal.Body style={{ display: 'flex', flexDirection: 'column' }}>
128
131
  <input
129
132
  ref={inputRef}
130
133
  className={css.paletteInput}