dsh-config-manager 0.4.2 → 0.5.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 (263) hide show
  1. package/README.md +24 -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 +19 -41
  13. package/lib/client.js +863 -722
  14. package/lib/core/access-mode.d.ts +25 -0
  15. package/lib/core/access-mode.js +28 -0
  16. package/lib/core/backup.d.ts +11 -0
  17. package/lib/core/backup.js +27 -0
  18. package/lib/core/env-lock-lifecycle.d.ts +17 -3
  19. package/lib/core/env-lock-lifecycle.js +38 -0
  20. package/lib/core/external-failure.d.ts +9 -0
  21. package/lib/core/external-failure.js +50 -0
  22. package/lib/core/local-plugin-host.d.ts +9 -7
  23. package/lib/core/local-plugin-host.js +109 -15
  24. package/lib/core/local-plugin-pack.d.ts +20 -0
  25. package/lib/core/local-plugin-pack.js +18 -3
  26. package/lib/core/mcp-connector-store.d.ts +13 -0
  27. package/lib/core/mcp-connector-store.js +16 -1
  28. package/lib/core/messages-core.d.ts +45 -0
  29. package/lib/core/messages-core.js +92 -0
  30. package/lib/core/messages.d.ts +1 -0
  31. package/lib/core/messages.js +6 -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-data-registry.d.ts +1 -1
  38. package/lib/core/plugin-data-registry.js +1 -1
  39. package/lib/core/restore-plan-fingerprint.d.ts +2 -0
  40. package/lib/core/restore-plan-fingerprint.js +18 -0
  41. package/lib/core/restore-resume.d.ts +1 -1
  42. package/lib/core/restore-resume.js +1 -1
  43. package/lib/core/restore.d.ts +5 -0
  44. package/lib/core/restore.js +4 -1
  45. package/lib/core/types.d.ts +12 -0
  46. package/lib/foreign/claude-sessions.d.ts +1 -1
  47. package/lib/foreign/claude-sessions.js +1 -1
  48. package/lib/foreign/registry.js +1 -1
  49. package/lib/foreign/types.d.ts +1 -1
  50. package/lib/index.d.ts +15 -15
  51. package/lib/index.js +65 -72
  52. package/lib/market/git-file-writer.js +1 -1
  53. package/lib/market/github-repos.js +1 -1
  54. package/lib/market/market-config.js +1 -1
  55. package/lib/market/messages-market.js +1 -1
  56. package/lib/market/my-repo.js +1 -1
  57. package/lib/market/prepare.js +1 -1
  58. package/lib/market/reader.js +2 -2
  59. package/lib/market/repo-url.d.ts +1 -1
  60. package/lib/market/security.js +2 -2
  61. package/lib/market/star-cache.d.ts +1 -1
  62. package/lib/market/types.d.ts +1 -1
  63. package/lib/market/types.js +1 -1
  64. package/lib/market/url.js +1 -1
  65. package/lib/routes/backup.js +17 -9
  66. package/lib/routes/index.d.ts +1 -1
  67. package/lib/routes/kit.d.ts +42 -3
  68. package/lib/routes/kit.js +43 -3
  69. package/lib/routes/market.d.ts +1 -1
  70. package/lib/routes/market.js +3 -60
  71. package/lib/routes/model-tools-deps.d.ts +41 -0
  72. package/lib/routes/model-tools-deps.js +18 -0
  73. package/lib/routes/recovery.js +5 -3
  74. package/lib/routes/request-trust.d.ts +28 -0
  75. package/lib/routes/request-trust.js +65 -0
  76. package/lib/routes/route-support.d.ts +18 -26
  77. package/lib/routes/route-support.js +19 -32
  78. package/lib/routes/snapshots.d.ts +1 -1
  79. package/lib/routes/snapshots.js +4 -40
  80. package/lib/routes/sync.js +40 -28
  81. package/lib/schema/index.d.ts +2 -2
  82. package/lib/schema/index.js +2 -2
  83. package/lib/schema/section-registry.d.ts +5 -3
  84. package/lib/schema/section-registry.js +7 -3
  85. package/lib/security/secret-scanner.js +1 -1
  86. package/lib/sync/apply-bundle.d.ts +50 -0
  87. package/lib/sync/apply-bundle.js +60 -0
  88. package/lib/sync/autosync-scheduler.d.ts +9 -0
  89. package/lib/sync/autosync-scheduler.js +118 -89
  90. package/lib/sync/backup-scheduler.js +5 -4
  91. package/lib/sync/blob-store.d.ts +2 -2
  92. package/lib/sync/git/git-transport.d.ts +12 -0
  93. package/lib/sync/git/git-transport.js +50 -2
  94. package/lib/sync/merge.d.ts +2 -0
  95. package/lib/sync/merge.js +28 -0
  96. package/lib/sync/messages.d.ts +4 -0
  97. package/lib/sync/messages.js +9 -2
  98. package/lib/sync/s3/s3-transport.d.ts +1 -1
  99. package/lib/sync/s3/s3-transport.js +1 -1
  100. package/lib/sync/sync-engine.d.ts +4 -4
  101. package/lib/sync/sync-engine.js +25 -26
  102. package/lib/sync/sync-scope-boot.d.ts +34 -0
  103. package/lib/sync/sync-scope-boot.js +71 -0
  104. package/lib/sync/sync-scope.d.ts +103 -0
  105. package/lib/sync/sync-scope.js +229 -0
  106. package/lib/sync/sync-selection.d.ts +17 -4
  107. package/lib/sync/sync-selection.js +40 -14
  108. package/lib/sync/transport.d.ts +4 -1
  109. package/lib/sync/transport.js +6 -0
  110. package/lib/sync/webdav/webdav-transport.js +1 -1
  111. package/lib/sync/workspace-merge.d.ts +36 -0
  112. package/lib/sync/workspace-merge.js +152 -0
  113. package/lib/ui/backup-schedule.d.ts +13 -2
  114. package/lib/ui/backup-schedule.js +3 -0
  115. package/lib/ui/snapshots-view.d.ts +16 -0
  116. package/lib/ui/snapshots-view.js +21 -0
  117. package/lib/utils/env-lock.d.ts +96 -0
  118. package/lib/utils/env-lock.js +332 -111
  119. package/lib/utils/messages-utils.d.ts +6 -0
  120. package/lib/utils/messages-utils.js +17 -1
  121. package/lib/utils/patch-yaml.js +1 -1
  122. package/lib/utils/zip.js +1 -1
  123. package/package.json +3 -2
  124. package/src/adapters/mcp.test.ts +28 -0
  125. package/src/adapters/mcp.ts +33 -0
  126. package/src/adapters/plugins.test.ts +49 -0
  127. package/src/adapters/plugins.ts +9 -1
  128. package/src/adapters/pnpm-workspace.ts +1 -1
  129. package/src/adapters/self.test.ts +39 -1
  130. package/src/adapters/self.ts +20 -2
  131. package/src/adapters/workspaces.ts +1 -1
  132. package/src/cli/restore-resume.ts +1 -1
  133. package/src/cli/web/page.ts +2 -2
  134. package/src/client/about/AboutPanel.tsx +8 -1
  135. package/src/client/about/about-view.test.ts +1 -1
  136. package/src/client/about/about-view.ts +1 -1
  137. package/src/client/api.ts +1 -6
  138. package/src/client/chat/chat-entry-view.test.ts +1 -1
  139. package/src/client/chat/chat-slots.ts +1 -1
  140. package/src/client/chat/rollback-diff-tab.ts +1 -1
  141. package/src/client/client-types.ts +1 -1
  142. package/src/client/common/access-mode.ts +21 -0
  143. package/src/client/common/routes.ts +1 -5
  144. package/src/client/css-scale-guard.test.ts +1 -1
  145. package/src/client/home/HomePanel.tsx +34 -6
  146. package/src/client/library/ArtifactRow.tsx +14 -2
  147. package/src/client/library/LibraryPanel.tsx +44 -0
  148. package/src/client/locales/about.ts +6 -0
  149. package/src/client/locales/overview.ts +18 -2
  150. package/src/client/locales/sessions.ts +3 -0
  151. package/src/client/market/MyConfigsView.tsx +1 -1
  152. package/src/client/market/market-api.ts +2 -14
  153. package/src/client/market/market-locales.ts +1 -1
  154. package/src/client/market/market-view.ts +3 -3
  155. package/src/client/market/my-configs-api.ts +1 -1
  156. package/src/client/market/my-configs-view.ts +1 -1
  157. package/src/client/recovery/recovery-locales.test.ts +1 -1
  158. package/src/client/run-store.ts +1 -1
  159. package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
  160. package/src/client/sync/history-model.test.ts +28 -7
  161. package/src/client/sync/history-model.ts +6 -3
  162. package/src/client/sync/sync-locales.ts +10 -4
  163. package/src/client/sync/sync-view.ts +1 -1
  164. package/src/core/access-mode.ts +37 -0
  165. package/src/core/analyzer-cache.test.ts +1 -1
  166. package/src/core/backup.test.ts +45 -1
  167. package/src/core/backup.ts +25 -0
  168. package/src/core/disk-usage.test.ts +2 -0
  169. package/src/core/env-lock-lifecycle.ts +33 -3
  170. package/src/core/external-failure.test.ts +60 -0
  171. package/src/core/external-failure.ts +54 -0
  172. package/src/core/integrity-extra-entries.test.ts +1 -1
  173. package/src/core/local-plugin-host.test.ts +134 -0
  174. package/src/core/local-plugin-host.ts +122 -17
  175. package/src/core/local-plugin-pack.ts +39 -3
  176. package/src/core/mcp-connector-store.ts +26 -1
  177. package/src/core/messages-core.ts +94 -0
  178. package/src/core/messages.ts +6 -0
  179. package/src/core/model-tool-plans.test.ts +111 -0
  180. package/src/core/model-tool-plans.ts +170 -0
  181. package/src/core/model-tools.test.ts +212 -12
  182. package/src/core/model-tools.ts +710 -38
  183. package/src/core/phase3-host.ts +10 -2
  184. package/src/core/phase3-production-integration.test.ts +43 -0
  185. package/src/core/plugin-data-registry.ts +1 -1
  186. package/src/core/restore-plan-fingerprint.ts +19 -0
  187. package/src/core/restore-resume.ts +1 -1
  188. package/src/core/restore.ts +9 -1
  189. package/src/core/types.ts +12 -0
  190. package/src/foreign/claude-sessions.ts +3 -3
  191. package/src/foreign/registry.ts +1 -1
  192. package/src/foreign/types.ts +1 -1
  193. package/src/index.ts +96 -103
  194. package/src/market/git-file-writer.ts +1 -1
  195. package/src/market/github-repos.test.ts +1 -1
  196. package/src/market/github-repos.ts +1 -1
  197. package/src/market/market-config.ts +1 -1
  198. package/src/market/messages-market.ts +1 -1
  199. package/src/market/my-repo.test.ts +1 -1
  200. package/src/market/my-repo.ts +1 -1
  201. package/src/market/prepare.test.ts +1 -1
  202. package/src/market/prepare.ts +1 -1
  203. package/src/market/reader.ts +2 -2
  204. package/src/market/repo-url.ts +1 -1
  205. package/src/market/security.ts +2 -2
  206. package/src/market/star-cache.ts +1 -1
  207. package/src/market/types.ts +1 -1
  208. package/src/market/url.test.ts +1 -1
  209. package/src/market/url.ts +1 -1
  210. package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
  211. package/src/routes/backup.ts +16 -9
  212. package/src/routes/index.ts +1 -1
  213. package/src/routes/kit.ts +71 -5
  214. package/src/routes/market.ts +2 -59
  215. package/src/routes/model-tools-deps.ts +56 -0
  216. package/src/routes/recovery.ts +5 -3
  217. package/src/routes/request-trust.ts +97 -0
  218. package/src/routes/route-support.ts +49 -36
  219. package/src/routes/snapshots.ts +4 -40
  220. package/src/routes/sync.ts +39 -27
  221. package/src/schema/index.ts +2 -2
  222. package/src/schema/manifest-schema.test.ts +2 -2
  223. package/src/schema/registry.test.ts +1 -1
  224. package/src/schema/section-registry.ts +9 -4
  225. package/src/security/redaction.test.ts +1 -1
  226. package/src/security/secret-scanner.test.ts +2 -2
  227. package/src/security/secret-scanner.ts +1 -1
  228. package/src/sync/apply-bundle.ts +104 -0
  229. package/src/sync/autosync-scheduler.test.ts +180 -6
  230. package/src/sync/autosync-scheduler.ts +132 -92
  231. package/src/sync/backup-scheduler.test.ts +11 -4
  232. package/src/sync/backup-scheduler.ts +5 -4
  233. package/src/sync/blob-store.ts +2 -2
  234. package/src/sync/git/git-transport.test.ts +62 -0
  235. package/src/sync/git/git-transport.ts +54 -3
  236. package/src/sync/merge.ts +29 -0
  237. package/src/sync/messages.ts +9 -2
  238. package/src/sync/s3/s3-transport.ts +1 -1
  239. package/src/sync/sync-engine.test.ts +238 -2
  240. package/src/sync/sync-engine.ts +25 -26
  241. package/src/sync/sync-preview-push.test.ts +2 -1
  242. package/src/sync/sync-scope-boot.ts +87 -0
  243. package/src/sync/sync-scope.test.ts +154 -0
  244. package/src/sync/sync-scope.ts +256 -0
  245. package/src/sync/sync-selection.test.ts +76 -2
  246. package/src/sync/sync-selection.ts +40 -13
  247. package/src/sync/transport.test.ts +21 -1
  248. package/src/sync/transport.ts +12 -0
  249. package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
  250. package/src/sync/webdav/webdav-transport.ts +1 -1
  251. package/src/sync/workspace-merge.test.ts +110 -0
  252. package/src/sync/workspace-merge.ts +180 -0
  253. package/src/ui/backup-schedule.test.ts +5 -0
  254. package/src/ui/backup-schedule.ts +21 -2
  255. package/src/ui/session-issue-labels.ts +1 -1
  256. package/src/ui/snapshots-view.test.ts +32 -0
  257. package/src/ui/snapshots-view.ts +34 -0
  258. package/src/utils/env-lock.test.ts +242 -9
  259. package/src/utils/env-lock.ts +247 -13
  260. package/src/utils/messages-utils.ts +17 -1
  261. package/src/utils/patch-yaml.ts +1 -1
  262. package/src/utils/zip.ts +1 -1
  263. 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);
@@ -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:只有四份调研报告的落点(尚未有可复现夹具时**必须**是这个值)