dsh-config-manager 0.4.3 → 0.6.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 (286) hide show
  1. package/README.md +10 -0
  2. package/README.zh-CN.md +10 -0
  3. package/lib/adapters/mcp.d.ts +9 -0
  4. package/lib/adapters/mcp.js +37 -0
  5. package/lib/adapters/plugins.js +10 -2
  6. package/lib/adapters/pnpm-workspace.js +1 -1
  7. package/lib/adapters/self.d.ts +2 -0
  8. package/lib/adapters/self.js +18 -2
  9. package/lib/adapters/workspaces.js +1 -1
  10. package/lib/cli/restore-resume.js +1 -1
  11. package/lib/cli/web/page.js +2 -2
  12. package/lib/client.d.ts +17 -41
  13. package/lib/client.js +946 -761
  14. package/lib/core/backup.d.ts +11 -0
  15. package/lib/core/backup.js +27 -0
  16. package/lib/core/env-lock-lifecycle.d.ts +17 -3
  17. package/lib/core/env-lock-lifecycle.js +38 -0
  18. package/lib/core/external-failure.d.ts +9 -0
  19. package/lib/core/external-failure.js +50 -0
  20. package/lib/core/local-plugin-host.d.ts +9 -7
  21. package/lib/core/local-plugin-host.js +109 -15
  22. package/lib/core/local-plugin-pack.d.ts +20 -0
  23. package/lib/core/local-plugin-pack.js +18 -3
  24. package/lib/core/mcp-connector-store.d.ts +13 -0
  25. package/lib/core/mcp-connector-store.js +16 -1
  26. package/lib/core/messages-core.d.ts +45 -0
  27. package/lib/core/messages-core.js +92 -0
  28. package/lib/core/messages.d.ts +5 -0
  29. package/lib/core/messages.js +14 -0
  30. package/lib/core/migration-history.d.ts +40 -0
  31. package/lib/core/migration-history.js +55 -0
  32. package/lib/core/model-tool-plans.d.ts +66 -0
  33. package/lib/core/model-tool-plans.js +128 -0
  34. package/lib/core/model-tools.d.ts +96 -8
  35. package/lib/core/model-tools.js +568 -31
  36. package/lib/core/phase3-host.js +10 -2
  37. package/lib/core/plugin-cli.d.ts +5 -0
  38. package/lib/core/plugin-cli.js +11 -3
  39. package/lib/core/plugin-data-registry.d.ts +1 -1
  40. package/lib/core/plugin-data-registry.js +1 -1
  41. package/lib/core/restore-plan-fingerprint.d.ts +2 -0
  42. package/lib/core/restore-plan-fingerprint.js +18 -0
  43. package/lib/core/restore-resume.d.ts +1 -1
  44. package/lib/core/restore-resume.js +1 -1
  45. package/lib/core/restore.d.ts +5 -0
  46. package/lib/core/restore.js +4 -1
  47. package/lib/core/types.d.ts +12 -0
  48. package/lib/foreign/claude-sessions.d.ts +1 -1
  49. package/lib/foreign/claude-sessions.js +1 -1
  50. package/lib/foreign/registry.js +1 -1
  51. package/lib/foreign/types.d.ts +1 -1
  52. package/lib/index.d.ts +19 -15
  53. package/lib/index.js +72 -80
  54. package/lib/market/git-file-writer.js +1 -1
  55. package/lib/market/github-repos.js +1 -1
  56. package/lib/market/market-config.js +1 -1
  57. package/lib/market/messages-market.js +1 -1
  58. package/lib/market/my-repo.js +1 -1
  59. package/lib/market/prepare.js +1 -1
  60. package/lib/market/reader.js +2 -2
  61. package/lib/market/repo-url.d.ts +1 -1
  62. package/lib/market/security.js +2 -2
  63. package/lib/market/star-cache.d.ts +1 -1
  64. package/lib/market/types.d.ts +1 -1
  65. package/lib/market/types.js +1 -1
  66. package/lib/market/url.js +1 -1
  67. package/lib/profiles/dsh-profile-manager.d.ts +1 -1
  68. package/lib/profiles/dsh-profile-manager.js +26 -7
  69. package/lib/profiles/dsh-profile-shared.d.ts +3 -1
  70. package/lib/routes/backup.js +17 -9
  71. package/lib/routes/index.d.ts +1 -1
  72. package/lib/routes/kit.d.ts +2 -2
  73. package/lib/routes/market.d.ts +1 -1
  74. package/lib/routes/market.js +3 -60
  75. package/lib/routes/model-tools-deps.d.ts +41 -0
  76. package/lib/routes/model-tools-deps.js +18 -0
  77. package/lib/routes/recovery.js +5 -3
  78. package/lib/routes/route-support.d.ts +18 -26
  79. package/lib/routes/route-support.js +19 -32
  80. package/lib/routes/snapshots.d.ts +1 -1
  81. package/lib/routes/snapshots.js +4 -40
  82. package/lib/routes/sync.js +40 -28
  83. package/lib/schema/index.d.ts +2 -2
  84. package/lib/schema/index.js +2 -2
  85. package/lib/schema/section-registry.d.ts +5 -3
  86. package/lib/schema/section-registry.js +7 -3
  87. package/lib/security/secret-scanner.js +1 -1
  88. package/lib/sync/apply-bundle.d.ts +50 -0
  89. package/lib/sync/apply-bundle.js +60 -0
  90. package/lib/sync/autosync-scheduler.d.ts +9 -0
  91. package/lib/sync/autosync-scheduler.js +118 -89
  92. package/lib/sync/backup-scheduler.js +5 -4
  93. package/lib/sync/blob-store.d.ts +2 -2
  94. package/lib/sync/git/git-transport.d.ts +12 -0
  95. package/lib/sync/git/git-transport.js +50 -2
  96. package/lib/sync/merge.d.ts +2 -0
  97. package/lib/sync/merge.js +28 -0
  98. package/lib/sync/messages.d.ts +4 -0
  99. package/lib/sync/messages.js +9 -2
  100. package/lib/sync/s3/s3-transport.d.ts +1 -1
  101. package/lib/sync/s3/s3-transport.js +1 -1
  102. package/lib/sync/sync-engine.d.ts +4 -4
  103. package/lib/sync/sync-engine.js +25 -26
  104. package/lib/sync/sync-scope-boot.d.ts +34 -0
  105. package/lib/sync/sync-scope-boot.js +71 -0
  106. package/lib/sync/sync-scope.d.ts +103 -0
  107. package/lib/sync/sync-scope.js +229 -0
  108. package/lib/sync/sync-selection.d.ts +17 -4
  109. package/lib/sync/sync-selection.js +40 -14
  110. package/lib/sync/transport.d.ts +4 -1
  111. package/lib/sync/transport.js +6 -0
  112. package/lib/sync/webdav/webdav-transport.js +1 -1
  113. package/lib/sync/workspace-merge.d.ts +36 -0
  114. package/lib/sync/workspace-merge.js +152 -0
  115. package/lib/ui/backup-schedule.d.ts +13 -2
  116. package/lib/ui/backup-schedule.js +3 -0
  117. package/lib/ui/snapshots-view.d.ts +16 -0
  118. package/lib/ui/snapshots-view.js +21 -0
  119. package/lib/ui/sync-repository-picker.d.ts +21 -0
  120. package/lib/ui/sync-repository-picker.js +18 -0
  121. package/lib/utils/env-lock.d.ts +96 -0
  122. package/lib/utils/env-lock.js +332 -111
  123. package/lib/utils/messages-utils.d.ts +6 -0
  124. package/lib/utils/messages-utils.js +17 -1
  125. package/lib/utils/patch-yaml.js +1 -1
  126. package/lib/utils/remove-tree.d.ts +7 -0
  127. package/lib/utils/remove-tree.js +265 -0
  128. package/lib/utils/zip.js +1 -1
  129. package/package.json +3 -2
  130. package/src/adapters/mcp.test.ts +28 -0
  131. package/src/adapters/mcp.ts +33 -0
  132. package/src/adapters/plugins.test.ts +49 -0
  133. package/src/adapters/plugins.ts +9 -1
  134. package/src/adapters/pnpm-workspace.ts +1 -1
  135. package/src/adapters/self.test.ts +39 -1
  136. package/src/adapters/self.ts +20 -2
  137. package/src/adapters/workspaces.ts +1 -1
  138. package/src/cli/restore-resume.ts +1 -1
  139. package/src/cli/web/page.ts +2 -2
  140. package/src/client/about/AboutPanel.tsx +1 -1
  141. package/src/client/about/about-view.test.ts +1 -1
  142. package/src/client/about/about-view.ts +1 -1
  143. package/src/client/api.ts +1 -6
  144. package/src/client/chat/chat-entry-view.test.ts +1 -1
  145. package/src/client/chat/chat-slots.ts +1 -1
  146. package/src/client/chat/rollback-diff-tab.ts +1 -1
  147. package/src/client/client-types.ts +1 -1
  148. package/src/client/common/routes.ts +1 -5
  149. package/src/client/config-manager.module.css +21 -1
  150. package/src/client/css-scale-guard.test.ts +1 -1
  151. package/src/client/environment/EnvironmentPanel.tsx +2 -2
  152. package/src/client/home/HomePanel.tsx +3 -0
  153. package/src/client/library/ArtifactRow.tsx +14 -2
  154. package/src/client/library/LibraryPanel.tsx +44 -0
  155. package/src/client/locales/overview.ts +10 -2
  156. package/src/client/locales/profiles.ts +2 -0
  157. package/src/client/locales/sessions.ts +3 -0
  158. package/src/client/market/MyConfigsView.tsx +1 -1
  159. package/src/client/market/market-api.ts +2 -14
  160. package/src/client/market/market-locales.ts +1 -1
  161. package/src/client/market/market-view.ts +3 -3
  162. package/src/client/market/my-configs-api.ts +1 -1
  163. package/src/client/market/my-configs-view.ts +1 -1
  164. package/src/client/recovery/recovery-locales.test.ts +1 -1
  165. package/src/client/run-store.ts +1 -1
  166. package/src/client/sync/ChannelConfigDialog.tsx +32 -1
  167. package/src/client/sync/SyncPanel.tsx +11 -30
  168. package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
  169. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
  170. package/src/client/sync/SyncSettingsView.test.ts +32 -0
  171. package/src/client/sync/config-save-state.test.ts +99 -0
  172. package/src/client/sync/config-save-state.ts +69 -0
  173. package/src/client/sync/history-model.test.ts +28 -7
  174. package/src/client/sync/history-model.ts +6 -3
  175. package/src/client/sync/sync-locales.ts +14 -4
  176. package/src/client/sync/sync-view.ts +1 -1
  177. package/src/core/analyzer-cache.test.ts +1 -1
  178. package/src/core/backup.test.ts +45 -1
  179. package/src/core/backup.ts +25 -0
  180. package/src/core/disk-usage.test.ts +2 -0
  181. package/src/core/engine-locale.test.ts +4 -0
  182. package/src/core/env-lock-lifecycle.ts +33 -3
  183. package/src/core/external-failure.test.ts +60 -0
  184. package/src/core/external-failure.ts +54 -0
  185. package/src/core/integrity-extra-entries.test.ts +1 -1
  186. package/src/core/local-plugin-host.test.ts +134 -0
  187. package/src/core/local-plugin-host.ts +122 -17
  188. package/src/core/local-plugin-pack.ts +39 -3
  189. package/src/core/mcp-connector-store.ts +26 -1
  190. package/src/core/messages-core.ts +94 -0
  191. package/src/core/messages.ts +14 -0
  192. package/src/core/migration-history.test.ts +65 -0
  193. package/src/core/migration-history.ts +70 -0
  194. package/src/core/model-tool-plans.test.ts +111 -0
  195. package/src/core/model-tool-plans.ts +170 -0
  196. package/src/core/model-tools.test.ts +212 -12
  197. package/src/core/model-tools.ts +710 -38
  198. package/src/core/phase3-host.ts +10 -2
  199. package/src/core/phase3-production-integration.test.ts +43 -0
  200. package/src/core/plugin-cli.fs.test.ts +30 -3
  201. package/src/core/plugin-cli.ts +11 -3
  202. package/src/core/plugin-data-registry.ts +1 -1
  203. package/src/core/restore-plan-fingerprint.ts +19 -0
  204. package/src/core/restore-resume.ts +1 -1
  205. package/src/core/restore.ts +9 -1
  206. package/src/core/types.ts +12 -0
  207. package/src/foreign/claude-sessions.ts +3 -3
  208. package/src/foreign/registry.ts +1 -1
  209. package/src/foreign/types.ts +1 -1
  210. package/src/index.ts +102 -111
  211. package/src/market/git-file-writer.ts +1 -1
  212. package/src/market/github-repos.test.ts +1 -1
  213. package/src/market/github-repos.ts +1 -1
  214. package/src/market/market-config.ts +1 -1
  215. package/src/market/messages-market.ts +1 -1
  216. package/src/market/my-repo.test.ts +1 -1
  217. package/src/market/my-repo.ts +1 -1
  218. package/src/market/prepare.test.ts +1 -1
  219. package/src/market/prepare.ts +1 -1
  220. package/src/market/reader.ts +2 -2
  221. package/src/market/repo-url.ts +1 -1
  222. package/src/market/security.ts +2 -2
  223. package/src/market/star-cache.ts +1 -1
  224. package/src/market/types.ts +1 -1
  225. package/src/market/url.test.ts +1 -1
  226. package/src/market/url.ts +1 -1
  227. package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
  228. package/src/profiles/dsh-profile-manager.test.ts +20 -0
  229. package/src/profiles/dsh-profile-manager.ts +25 -7
  230. package/src/profiles/dsh-profile-shared.ts +2 -0
  231. package/src/routes/backup.ts +16 -9
  232. package/src/routes/index.ts +1 -1
  233. package/src/routes/kit.ts +2 -2
  234. package/src/routes/market.ts +2 -59
  235. package/src/routes/model-tools-deps.ts +56 -0
  236. package/src/routes/recovery.ts +5 -3
  237. package/src/routes/route-support.ts +49 -36
  238. package/src/routes/snapshots.ts +4 -40
  239. package/src/routes/sync.ts +39 -27
  240. package/src/schema/index.ts +2 -2
  241. package/src/schema/manifest-schema.test.ts +2 -2
  242. package/src/schema/registry.test.ts +1 -1
  243. package/src/schema/section-registry.ts +9 -4
  244. package/src/security/redaction.test.ts +1 -1
  245. package/src/security/secret-scanner.test.ts +2 -2
  246. package/src/security/secret-scanner.ts +1 -1
  247. package/src/sync/apply-bundle.ts +104 -0
  248. package/src/sync/autosync-scheduler.test.ts +180 -6
  249. package/src/sync/autosync-scheduler.ts +132 -92
  250. package/src/sync/backup-scheduler.test.ts +11 -4
  251. package/src/sync/backup-scheduler.ts +5 -4
  252. package/src/sync/blob-store.ts +2 -2
  253. package/src/sync/git/git-transport.test.ts +62 -0
  254. package/src/sync/git/git-transport.ts +54 -3
  255. package/src/sync/merge.ts +29 -0
  256. package/src/sync/messages.ts +9 -2
  257. package/src/sync/s3/s3-transport.ts +1 -1
  258. package/src/sync/sync-engine.test.ts +238 -2
  259. package/src/sync/sync-engine.ts +25 -26
  260. package/src/sync/sync-preview-push.test.ts +2 -1
  261. package/src/sync/sync-scope-boot.ts +87 -0
  262. package/src/sync/sync-scope.test.ts +154 -0
  263. package/src/sync/sync-scope.ts +256 -0
  264. package/src/sync/sync-selection.test.ts +76 -2
  265. package/src/sync/sync-selection.ts +40 -13
  266. package/src/sync/transport.test.ts +21 -1
  267. package/src/sync/transport.ts +12 -0
  268. package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
  269. package/src/sync/webdav/webdav-transport.ts +1 -1
  270. package/src/sync/workspace-merge.test.ts +110 -0
  271. package/src/sync/workspace-merge.ts +180 -0
  272. package/src/ui/backup-schedule.test.ts +5 -0
  273. package/src/ui/backup-schedule.ts +21 -2
  274. package/src/ui/session-issue-labels.ts +1 -1
  275. package/src/ui/snapshots-view.test.ts +32 -0
  276. package/src/ui/snapshots-view.ts +34 -0
  277. package/src/ui/sync-repository-picker.test.ts +34 -1
  278. package/src/ui/sync-repository-picker.ts +24 -0
  279. package/src/utils/env-lock.test.ts +242 -9
  280. package/src/utils/env-lock.ts +247 -13
  281. package/src/utils/messages-utils.ts +17 -1
  282. package/src/utils/patch-yaml.ts +1 -1
  283. package/src/utils/remove-tree.test.ts +120 -0
  284. package/src/utils/remove-tree.ts +239 -0
  285. package/src/utils/zip.ts +1 -1
  286. package/src/client/CLIENT_DEPENDENCIES.md +0 -94
@@ -24,6 +24,7 @@ import { OWNERSHIP_FILE, type LockState, type MutationLockContext } from '../uti
24
24
  import { sha256Hex } from '../utils/hashing.ts';
25
25
  import type { JournalStepRecord } from './types.ts';
26
26
  import { engineMsg } from './messages-core.ts';
27
+ import { isLocalOnlyExternalFailure } from './external-failure.ts';
27
28
 
28
29
  /** 存在未收敛的 active transaction → 拒绝创建第二个(active≤1)。 */
29
30
  export class TransactionRecoveryRequiredError extends Error {
@@ -649,8 +650,15 @@ export class Phase3Recovery {
649
650
  await this.store.moveToCompleted(opId).catch(() => undefined);
650
651
  return { operationId: opId, result };
651
652
  } catch (err) {
652
- this.safeModeActive = true;
653
- await this.store.writeSafeMode(true).catch(() => undefined);
653
+ // 本地可修的配置类失败(如本机没设 git 身份)不升全局阻断:它由本机配置直接修好,
654
+ // 也不会让磁盘停在半写状态。无条件升 durable SAFE MODE 会把「本机缺一个 git 用户名」
655
+ // 放大成「全部写入 423,直到手动解除阻断」,而界面还说是「环境锁被占用」——
656
+ // 真机 issue 的链路就是这样(locks 目录为空却报锁,见 core/external-failure.ts)。
657
+ // 除该判据之外的一切失败保持 fail-closed(照旧 durable SAFE MODE,跨重启生效)。
658
+ if (!isLocalOnlyExternalFailure(err)) {
659
+ this.safeModeActive = true;
660
+ await this.store.writeSafeMode(true).catch(() => undefined);
661
+ }
654
662
  const rolledBack = rollbackOutcome.value;
655
663
  if (rolledBack !== null) {
656
664
  // 引擎已就地回滚但随后抛错:终态仍是 ROLLED_BACK —— 不把「已知结论:已回滚」误报成
@@ -23,6 +23,7 @@ import { createSnapshot, FileSnapshotStore, verifySnapshot } from './backup.ts';
23
23
  import type { Snapshot } from './types.ts';
24
24
  import { makeContext } from '../adapters/test-helpers.ts';
25
25
  import type { MutationLockContext } from '../utils/env-lock.ts';
26
+ import { markLocalOnlyExternalFailure } from './external-failure.ts';
26
27
 
27
28
  function tmp(t: test.TestContext): string {
28
29
  const dir = fssync.mkdtempSync(path.join(os.tmpdir(), 'p3prod-'));
@@ -137,6 +138,48 @@ test('P0-A:runExternalIntent 记录 external step + COMMITTED', async (t) => {
137
138
  assert.deepEqual(await recovery.store.scanActive(), []);
138
139
  });
139
140
 
141
+ /* ---- 本地可修失败不升 SAFE MODE(issue:缺 git 身份 ⇒ 全部写入 423,界面还说环境锁被占用) ---- */
142
+
143
+ test('runExternalIntent:localOnly 失败 → NEEDS_ATTENTION,但绝不升 durable SAFE MODE', async (t) => {
144
+ const dir = tmp(t);
145
+ const recovery = await makeRecovery(dir);
146
+ // 「本机没配 git 身份」这类失败:能在本机一步修好,不会让磁盘停在半写状态。
147
+ const err = markLocalOnlyExternalFailure(new Error('fatal: unable to auto-detect email address'), 'git-identity');
148
+ await assert.rejects(
149
+ () => recovery.runExternalIntent({
150
+ operationType: 'sync-push', lockCtx: lk(), intent: { adapter: 'sync', ref: 'git', kind: 'Push' },
151
+ fn: async () => { throw err; },
152
+ }),
153
+ /unable to auto-detect email address/,
154
+ );
155
+ // 交易本身照旧留痕(不掩盖失败)
156
+ const active = await recovery.store.scanActive();
157
+ assert.equal(active.length, 1, '必须留下一条可读的 journal');
158
+ // scanActive() 只回 id 列表(string[]),状态要 loadActive 才拿得到
159
+ const journal = await recovery.store.loadActive(active[0]!);
160
+ assert.ok(journal, 'journal 可读');
161
+ assert.equal(journal!.state, 'NEEDS_ATTENTION');
162
+ assert.match(String(journal!.error ?? ''), /auto-detect email/);
163
+ // 但不连坐全局:此前 catch 无条件写 durable SAFE MODE(跨重启生效),把可修配置问题放大成
164
+ // 「所有写入 423」,用户还得先解除阻断才能重试 —— 真机 issue 的实际链路。
165
+ assert.equal(recovery.safeModeActive, false, '内存 safeModeActive 不得被置位');
166
+ assert.equal(await recovery.store.readSafeMode(), false, 'durable SAFE MODE 标记不得落盘');
167
+ });
168
+
169
+ test('runExternalIntent:未标记的失败照旧升 SAFE MODE(收窄只对 localOnly 生效,其余 fail-closed)', async (t) => {
170
+ const dir = tmp(t);
171
+ const recovery = await makeRecovery(dir);
172
+ await assert.rejects(
173
+ () => recovery.runExternalIntent({
174
+ operationType: 'sync-push', lockCtx: lk(), intent: { adapter: 'sync', ref: 'git', kind: 'Push' },
175
+ fn: async () => { throw new Error('boom: unknown external failure'); },
176
+ }),
177
+ /boom/,
178
+ );
179
+ assert.equal(recovery.safeModeActive, true);
180
+ assert.equal(await recovery.store.readSafeMode(), true, '未知失败必须保持 fail-closed');
181
+ });
182
+
140
183
  // ---------- 真实 child crash:runJournaled fn 中被 SIGKILL → 残留非终态 journal → reconcile ----------
141
184
  test('P0-A:真实 child crash(fn 中 SIGKILL)→ 残留非终态 journal 可 reconcile(不自动恢复)', async (t) => {
142
185
  const dir = tmp(t);
@@ -8,13 +8,13 @@
8
8
  */
9
9
  import test from 'node:test';
10
10
  import assert from 'node:assert/strict';
11
- import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
11
+ import { lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
12
12
  import { tmpdir } from 'node:os';
13
13
  import { join } from 'node:path';
14
14
 
15
15
  import {
16
- isBundlesOnlyEntry, listInstalledPlugins, mergeBundleDeclaration, readInstalled, readInstalledVersion,
17
- reconcileBundles, reconcileBundlesAfterInstall, resolveProfileDir,
16
+ cleanupAbortedInstall, isBundlesOnlyEntry, listInstalledPlugins, mergeBundleDeclaration, readInstalled,
17
+ readInstalledVersion, reconcileBundles, reconcileBundlesAfterInstall, resolveProfileDir,
18
18
  } from './plugin-cli.ts';
19
19
  import { enterRescueMode } from './boot-rescue.ts';
20
20
  import type { PluginInfo } from './types.ts';
@@ -366,3 +366,30 @@ test('issue #95: mergeBundleDeclaration 只追加一个名字;形状不符一
366
366
  'bundles 字段缺省 → null(非空 bundles 会替换默认插件栈,绝不凭空造)',
367
367
  );
368
368
  });
369
+
370
+ test('中止安装清理:包目录是悬空 junction 时也必须删净(fs.rmSync 静默空转的回归)', () => {
371
+ const { profileDir, cleanup } = makeTempProfile({ 'pkg-b': '1.0.0' }, ['pkg-b']);
372
+ try {
373
+ const pkgDir = join(profileDir, 'node_modules', 'pkg-b');
374
+ mkdirSync(join(profileDir, 'node_modules'), { recursive: true });
375
+ // DSH 真实形态:node_modules/<pkg> 直接链到 .dsh-module-fallback;fallback 被宿主升级清掉后即成悬空链接。
376
+ symlinkSync(
377
+ join(profileDir, '.dsh-module-fallback', 'node_modules', 'pkg-b'),
378
+ pkgDir,
379
+ process.platform === 'win32' ? 'junction' : 'dir',
380
+ );
381
+ assert.ok(lstatSync(pkgDir).isSymbolicLink(), '链接条目本身在(existsSync 对悬空链接返回 false,不能当判据)');
382
+
383
+ cleanupAbortedInstall(profileDir, 'pkg-b');
384
+
385
+ assert.throws(() => lstatSync(pkgDir), /ENOENT/, '悬空链接必须被真的删掉,否则「跳过当前插件」留半装残留');
386
+ const manifest = JSON.parse(readFileSync(join(profileDir, 'package.json'), 'utf8')) as {
387
+ dependencies: Record<string, string>;
388
+ dsh: { profile: { bundles: string[] } };
389
+ };
390
+ assert.equal('pkg-b' in manifest.dependencies, false, '依赖行同步摘掉(下次安装不再撞缺包)');
391
+ assert.ok(Array.isArray(manifest.dsh.profile.bundles), 'bundles 形状不变');
392
+ } finally {
393
+ cleanup();
394
+ }
395
+ });
@@ -19,10 +19,11 @@ import { engineMsg } from './messages-core.ts'
19
19
  import { isConcreteVersion } from './validator.ts';
20
20
  import { spawn } from 'node:child_process'
21
21
  import type { ChildProcess, SpawnOptions } from 'node:child_process'
22
- import { readFileSync, rmSync } from 'node:fs'
22
+ import { readFileSync } from 'node:fs'
23
23
  import { basename, dirname, join, resolve } from 'node:path'
24
24
 
25
25
  import { atomicWriteFileSync } from '../utils/atomic-write.ts'
26
+ import { removeTreeSync } from '../utils/remove-tree.ts'
26
27
  import { isDesktopProfile, resolveDesktopCarrier } from '../utils/desktop-carrier.ts'
27
28
  import { isRescueActiveSync } from './boot-rescue.ts'
28
29
  import type { PluginInfo } from './types.ts'
@@ -301,6 +302,11 @@ function isRescueActiveForProfileDir(profileDir: string): boolean {
301
302
  * 直接启动 DSH 会因缺包而失败。本函数把 manifest 恢复为「该插件未安装」的一致状态,
302
303
  * 消除「声明了依赖但没装全」的启动风险。pnpm-lock.yaml 不触碰(运行时不被读取,
303
304
  * 下次安装 pnpm 自行对齐)。尽力而为:任何失败不抛错,由调用方记录告警。
305
+ *
306
+ * 删包目录必须走 removeTreeSync 而不是 fs.rmSync(recursive):包目录常是**链接**(DSH 把
307
+ * node_modules/<pkg> 链到 .dsh-module-fallback),链接目标消失后就是悬空链接,rmSync 遇到
308
+ * 这种树会静默空转(不抛错、一个都不删),于是「跳过当前插件」留下半装残留,下次安装撞缺包。
309
+ * removeTreeSync 只删链接本身(绝不跟进去删 fallback 里的实体)并在删不净时抛错。
304
310
  */
305
311
  export function cleanupAbortedInstall(profileDir: string, pkg: string): void {
306
312
  const manifest = readProfileManifest(profileDir)
@@ -315,9 +321,11 @@ export function cleanupAbortedInstall(profileDir: string, pkg: string): void {
315
321
  reconcileBundles(profileDir)
316
322
  }
317
323
  try {
318
- rmSync(join(profileDir, 'node_modules', pkg), { recursive: true, force: true })
324
+ removeTreeSync(join(profileDir, 'node_modules', pkg))
319
325
  } catch {
320
- // 尽力而为:目录可能不存在或正被占用,忽略
326
+ // 尽力而为:目录可能本来就不存在(正常情况下 removeTreeSync 对缺失目标是不抛的),
327
+ // 剩下的失败只有「真被占用 / 权限不足」——这里仍不打断「用户跳过」的流程,
328
+ // 但绝不再让悬空链接这种可修的形态走到这里。
321
329
  }
322
330
  }
323
331
 
@@ -225,7 +225,7 @@ export function areaOfPath(
225
225
  /**
226
226
  * 解析一个已安装插件 package.json 里的自述声明(dsh.dataDirs)—— 「让别的插件自己适配」的钩子。
227
227
  *
228
- * 契约(对外文档见 docs/spec/plugin-data-declaration.md):
228
+ * 契约(对外文档见 docs/contracts/plugin-data-declaration.md):
229
229
  * { "dsh": { "dataDirs": [ { "path": ".my-plugin", "role": "config", "env": ["MY_PLUGIN_DIR"] } ] } }
230
230
  *
231
231
  * 形状不认识就整条丢弃(返回 null),绝不猜;path 非法(绝对路径 / .. / 空段)同样丢弃。
@@ -0,0 +1,19 @@
1
+ /**
2
+ * 恢复计划指纹 —— 预览与执行之间的**唯一**一致性判据。
3
+ *
4
+ * 只取「动作类型 + 目标 + blob」三列:描述文案、detail、manualHint 这些展示字段不进指纹
5
+ * (改一句文案不该让用户已经做过的确认失效),动作的**集合**才是实质 —— 多一个
6
+ * hostFileRemove / fileRemove,少一个还原,都说明磁盘在预览之后变了,必须重新确认。
7
+ *
8
+ * 为什么必须只有一处实现:GUI 恢复路由(src/routes/snapshots.ts 的 dry-run 与执行)
9
+ * 与 agent 工具(src/core/model-tools.ts 的 config_restore)算的必须是同一个值。
10
+ * 两处各写一份,只要有一处漏了 blobPath 或换了分隔符,「预览时算的」和「执行时验的」
11
+ * 就不是同一个东西 —— 防呆看着在,实际要么永远不触发,要么永远误触发。
12
+ */
13
+ import { createHash } from 'node:crypto'
14
+ import type { RestorePlan } from './restore.ts'
15
+
16
+ export function restorePlanFingerprint(plan: Pick<RestorePlan, 'actions'>): string {
17
+ const lines = plan.actions.map((action) => [action.kind, action.target ?? '', action.blobPath ?? ''].join('\u0000'))
18
+ return createHash('sha256').update(lines.join('\n')).digest('hex')
19
+ }
@@ -16,7 +16,7 @@
16
16
  * 任何 step ⇒ 上次连第一个写都没发生(WAL 预登记在首个写之前)⇒ 可以整笔重跑;
17
17
  * 一旦出现 step 却处在这两个状态,说明 journal 被外部改过(不可信)⇒ 拒绝。
18
18
  * - NEEDS_ATTENTION / ROLLING_BACK / RECOVERING 一律拒绝:那些是「需要人决策」的态,
19
- * 自动续跑会绕过恢复面板的判定(见 docs/decisions/0004)。
19
+ * 自动续跑会绕过恢复面板的判定(见 docs/adr/0004)。
20
20
  * - pluginRemove 是外部副作用(可能只改了 package.json 还没 prune node_modules),
21
21
  * 无指纹可证 ⇒ 含它的恢复**永不自动续跑**,仍交由恢复面板处理。
22
22
  */
@@ -25,7 +25,7 @@ import fssync from 'node:fs';
25
25
  import fs from 'node:fs/promises';
26
26
  import path from 'node:path';
27
27
 
28
- import { normalizeDshVersion, resolveFileTarget, verifySnapshot } from './backup.ts';
28
+ import { normalizeDshVersion, normalizeOriginProfile, resolveFileTarget, verifySnapshot } from './backup.ts';
29
29
  import { isPatchLayerRel } from './patch-layers.ts';
30
30
  import { expectedSessionRefs, sweepGhostSessions } from './ghost-sweep.ts';
31
31
  import { zhMsg } from './messages.ts';
@@ -191,6 +191,11 @@ export interface SnapshotMeta {
191
191
  entryCount: number;
192
192
  hostFileBackupCount: number;
193
193
  beforePluginCount: number;
194
+ /**
195
+ * 来源档案(originProfile):拍这份快照的进程所属 profile 名。
196
+ * 旧快照 / 宿主不暴露 profile 时缺省 —— 界面按「未标注」展示,绝不写 'unknown' 占位。
197
+ */
198
+ originProfile?: string;
194
199
  /** 置顶标记(P1-⑧):置顶快照不参与自动保留清理(最多保留 N 个时的淘汰豁免) */
195
200
  pinned?: boolean;
196
201
  }
@@ -1108,6 +1113,8 @@ export async function listSnapshots(
1108
1113
  if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) continue;
1109
1114
  const snapshot = parsed as Snapshot;
1110
1115
  if (typeof snapshot.id !== 'string' || snapshot.id === '') continue;
1116
+ // 来源档案:旧快照没有该字段是常态 → 缺省(不写占位值,列表照常可读)。
1117
+ const originProfile = normalizeOriginProfile(snapshot.originProfile);
1111
1118
  metas.push({
1112
1119
  id: snapshot.id,
1113
1120
  createdAt: snapshot.createdAt,
@@ -1116,6 +1123,7 @@ export async function listSnapshots(
1116
1123
  entryCount: snapshot.entries?.length ?? 0,
1117
1124
  hostFileBackupCount: snapshot.hostFileBackups?.length ?? 0,
1118
1125
  beforePluginCount: snapshot.beforePlugins?.length ?? 0,
1126
+ ...(originProfile !== undefined ? { originProfile } : {}),
1119
1127
  pinned: snapshot.pinned === true,
1120
1128
  });
1121
1129
  } catch {
package/src/core/types.ts CHANGED
@@ -1043,6 +1043,18 @@ export interface Snapshot {
1043
1043
  * 绝不写 'unknown' 之类的占位值,否则恢复时会拿占位值当「已知版本」误报版本不同。
1044
1044
  */
1045
1045
  dshVersion?: string;
1046
+ /**
1047
+ * 拍这份快照时**所属档案名**(originProfile;可选)。
1048
+ *
1049
+ * 为什么需要:插件数据目录 `$DSH_HOME/dsh-config-manager` 被所有 DSH profile 共用,
1050
+ * 快照库会混进 web / desktop / Test1 等多个档案的条目 —— 不记来源就分不清哪条属于谁。
1051
+ * 三条硬边界(与 dshVersion 同口径):
1052
+ * ① **必须可选**:旧快照没有这个字段是常态,旧快照的列表与恢复路径一字不变;
1053
+ * ② 值只写**能证明的真实档案名**(宿主 `HostContext.profile`);取不到时**不写** ——
1054
+ * 绝不写 'unknown' 之类的占位值,否则界面会把「不知道」当成一个真实档案去分组与筛选;
1055
+ * ③ 只用于**标注与筛选**,绝不参与恢复/保留判定(来自他人档案的快照照样可恢复)。
1056
+ */
1057
+ originProfile?: string;
1046
1058
  /** 置顶标记(P1-⑧):置顶快照在保留清理(自动删最旧)中豁免,需用户手动删除 */
1047
1059
  pinned?: boolean;
1048
1060
  // ---- Phase 4 新增(F1:operation-bound + integrity + readiness)----
@@ -37,7 +37,7 @@
37
37
  * ③ **sessionId 不一致**:`input.recordSessionId` 存在且 ≠ `input.id` → 非致命发现
38
38
  * `session-id-mismatch`(会话 id 仍以文件名 stem 为准,见 `TranscodeResult.findings`)。
39
39
  * ④ **推理块**(Claude Code 的 `thinking` / `redacted_thinking`):共享 IR 没有 reasoning
40
- * 承载位(docs/maintenance/known-gaps.md F-01)→ 计报 `thinking`,**绝不伪装成正文**;非 Claude 原生的
40
+ * 承载位(docs/known-issues/known-gaps.md F-01)→ 计报 `thinking`,**绝不伪装成正文**;非 Claude 原生的
41
41
  * `{type:'reasoning',text:…}` 刻意保持既有口径(理由与切换方式见 `REASONING_BLOCK_TYPES`)。
42
42
  */
43
43
  import type { Stats } from 'node:fs';
@@ -195,7 +195,7 @@ export interface TranscodeResult {
195
195
  interface ParsedBlock {
196
196
  /**
197
197
  * `thinking` = 推理块(Claude Code 的 `thinking` / `redacted_thinking`):共享 IR 的 `IrBlock`
198
- * **没有 reasoning 承载位**(docs/maintenance/known-gaps.md F-01),所以它既不进 IR 也不伪装成正文,
198
+ * **没有 reasoning 承载位**(docs/known-issues/known-gaps.md F-01),所以它既不进 IR 也不伪装成正文,
199
199
  * 只**逐条计数**(ignored['thinking'])。判定口径与「`reasoning` 为何不在此列」见
200
200
  * `REASONING_BLOCK_TYPES` 的注释。
201
201
  */
@@ -219,7 +219,7 @@ function usageField(usage: unknown, key: string): unknown {
219
219
  * 沿「对象带 text 才算文本」的兜底把它变成一个**空文本块** —— 内容静默丢失,且那个空块还会多插入
220
220
  * 一个换行。本仓其余 20+ 来源一律「推理不伪装成正文、只计数」(read-crush / read-opencode /
221
221
  * read-qwen / read-pi / read-openclaw …),这里对齐同一口径;共享 IR 无 reasoning 承载位这件事
222
- * 记在 docs/maintenance/known-gaps.md 的 F-01。
222
+ * 记在 docs/known-issues/known-gaps.md 的 F-01。
223
223
  *
224
224
  * **为什么不把 `{type:'reasoning', text:'…'}` 一并纳入**(如实记明,别当成漏掉):
225
225
  * ① Claude Code 不写这种块(它是别的导出器的归一命名,各来源自己的解析器已各自计报);
@@ -17,7 +17,7 @@
17
17
  * (回退会让用户以为导的是 A、实际导的是 B)。
18
18
  *
19
19
  * 契约正文(六来源路径真值表 / 冲突语义 / 单元 id 向后兼容)见
20
- * docs/design/2026-10-04-foreign-import-v1.md §8。
20
+ * docs/archive/2026-10-04-foreign-import-v1.md §8。
21
21
  */
22
22
  import fs from 'node:fs/promises';
23
23
  import path from 'node:path';
@@ -29,7 +29,7 @@ import type { ParsedTranscript } from './session-source.ts';
29
29
  * (claude → claude-code、dsh/dsh4 → 同源两代次)。
30
30
  *
31
31
  * **取证强度逐来源如实标注**(见 registry.ts 的 ForeignSource.evidence 与
32
- * docs/design/2026-10-04-foreign-import-v1.md §8.2 的真值表):
32
+ * docs/archive/2026-10-04-foreign-import-v1.md §8.2 的真值表):
33
33
  * - measured :本机实测(目录/库确实存在过,且读盘层据此实现)
34
34
  * - fixture :真机未验证,但有**可复现取证方式**(夹具 + 单测端到端跑同一份布局)
35
35
  * - documented:只有四份调研报告的落点(尚未有可复现夹具时**必须**是这个值)