dsh-config-manager 0.11.0 → 0.12.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 (122) hide show
  1. package/lib/adapters/attachment-index-cache.d.ts +33 -0
  2. package/lib/adapters/attachment-index-cache.js +114 -0
  3. package/lib/adapters/attachments.d.ts +97 -0
  4. package/lib/adapters/attachments.js +448 -0
  5. package/lib/adapters/index.d.ts +1 -0
  6. package/lib/adapters/index.js +7 -1
  7. package/lib/adapters/sessions.d.ts +18 -1
  8. package/lib/adapters/sessions.js +193 -0
  9. package/lib/adapters/test-helpers.d.ts +7 -0
  10. package/lib/adapters/test-helpers.js +8 -1
  11. package/lib/adapters/workspaces.d.ts +0 -1
  12. package/lib/adapters/workspaces.js +244 -5
  13. package/lib/client.d.ts +119 -1
  14. package/lib/client.js +1537 -828
  15. package/lib/core/analyzer.d.ts +1 -14
  16. package/lib/core/analyzer.js +25 -67
  17. package/lib/core/backup-plan.js +4 -0
  18. package/lib/core/backup.js +3 -0
  19. package/lib/core/host-service.d.ts +12 -0
  20. package/lib/core/host-service.js +12 -0
  21. package/lib/core/host-session-shapes.d.ts +209 -0
  22. package/lib/core/host-session-shapes.js +134 -0
  23. package/lib/core/host-workspace-facade.d.ts +57 -0
  24. package/lib/core/host-workspace-facade.js +127 -0
  25. package/lib/core/import-planning.d.ts +15 -0
  26. package/lib/core/import-planning.js +44 -0
  27. package/lib/core/messages.d.ts +20 -0
  28. package/lib/core/messages.js +40 -0
  29. package/lib/core/session-analyze.d.ts +52 -0
  30. package/lib/core/session-analyze.js +135 -0
  31. package/lib/core/session-compare.d.ts +54 -0
  32. package/lib/core/session-compare.js +154 -0
  33. package/lib/core/session-meta.d.ts +32 -0
  34. package/lib/core/session-meta.js +49 -0
  35. package/lib/core/session-verdict-plan.d.ts +2 -0
  36. package/lib/core/session-verdict-plan.js +33 -0
  37. package/lib/core/types.d.ts +153 -0
  38. package/lib/core/unit-enrichment.d.ts +19 -0
  39. package/lib/core/unit-enrichment.js +39 -0
  40. package/lib/core/workspace-root.d.ts +46 -0
  41. package/lib/core/workspace-root.js +121 -0
  42. package/lib/index.d.ts +2 -112
  43. package/lib/index.js +15 -222
  44. package/lib/schema/section-registry.js +15 -0
  45. package/lib/schema/types.d.ts +17 -1
  46. package/lib/ui/export-flow.js +1 -0
  47. package/lib/ui/i18n.d.ts +1 -0
  48. package/lib/ui/i18n.js +2 -0
  49. package/lib/ui/import-wizard.d.ts +8 -0
  50. package/lib/ui/import-wizard.js +10 -0
  51. package/lib/ui/selection-model.d.ts +60 -0
  52. package/lib/ui/selection-model.js +258 -2
  53. package/lib/ui/session-compare-facts.d.ts +51 -0
  54. package/lib/ui/session-compare-facts.js +82 -0
  55. package/lib/ui/test-helpers.js +2 -2
  56. package/lib/utils/attachment-refs.d.ts +49 -0
  57. package/lib/utils/attachment-refs.js +169 -0
  58. package/package.json +1 -1
  59. package/src/adapters/attachment-index-cache.test.ts +122 -0
  60. package/src/adapters/attachment-index-cache.ts +129 -0
  61. package/src/adapters/attachments.test.ts +358 -0
  62. package/src/adapters/attachments.ts +472 -0
  63. package/src/adapters/index.ts +8 -1
  64. package/src/adapters/sessions.test.ts +140 -0
  65. package/src/adapters/sessions.ts +184 -1
  66. package/src/adapters/test-helpers.ts +8 -1
  67. package/src/adapters/workspaces.test.ts +254 -0
  68. package/src/adapters/workspaces.ts +234 -5
  69. package/src/client/common/ContentPicker.tsx +235 -15
  70. package/src/client/common/section-labels.test.ts +1 -1
  71. package/src/client/common/section-labels.ts +1 -0
  72. package/src/client/common/ui.tsx +17 -1
  73. package/src/client/config-manager.module.css +29 -0
  74. package/src/client/export/ExportView.tsx +15 -2
  75. package/src/client/import/ImportWizardView.tsx +8 -0
  76. package/src/client/import/PathMappingForm.tsx +49 -10
  77. package/src/client/import/import-wizard-steps.tsx +80 -3
  78. package/src/client/import/use-import-wizard-controller.ts +3 -0
  79. package/src/client/locales/common.ts +2 -0
  80. package/src/client/locales/export.ts +5 -0
  81. package/src/client/locales/import.ts +6 -0
  82. package/src/client/locales/sessions.ts +26 -0
  83. package/src/client/run-store-redact.ts +122 -0
  84. package/src/client/run-store.ts +13 -115
  85. package/src/core/analyzer.ts +38 -79
  86. package/src/core/backup-plan.ts +4 -0
  87. package/src/core/backup.ts +3 -0
  88. package/src/core/host-service.ts +17 -0
  89. package/src/core/host-session-shapes.ts +270 -0
  90. package/src/core/host-workspace-facade.ts +153 -0
  91. package/src/core/import-planning.ts +48 -0
  92. package/src/core/messages.ts +40 -0
  93. package/src/core/native-path-picker.test.ts +3 -2
  94. package/src/core/session-analyze.ts +159 -0
  95. package/src/core/session-compare-wiring.test.ts +207 -0
  96. package/src/core/session-compare.test.ts +119 -0
  97. package/src/core/session-compare.ts +185 -0
  98. package/src/core/session-meta.test.ts +25 -2
  99. package/src/core/session-meta.ts +54 -0
  100. package/src/core/session-verdict-plan.test.ts +70 -0
  101. package/src/core/session-verdict-plan.ts +32 -0
  102. package/src/core/types.ts +161 -0
  103. package/src/core/unit-enrichment.ts +46 -0
  104. package/src/core/workspace-root.test.ts +152 -0
  105. package/src/core/workspace-root.ts +146 -0
  106. package/src/foreign/trae-sqlcipher.test.ts +13 -4
  107. package/src/index.ts +25 -355
  108. package/src/schema/manifest-schema.test.ts +1 -1
  109. package/src/schema/registry.test.ts +7 -2
  110. package/src/schema/section-registry.ts +15 -0
  111. package/src/schema/types.ts +23 -2
  112. package/src/sync/transport.test.ts +1 -1
  113. package/src/ui/export-flow.ts +1 -0
  114. package/src/ui/i18n.ts +2 -0
  115. package/src/ui/import-wizard.ts +11 -0
  116. package/src/ui/selection-model.test.ts +265 -3
  117. package/src/ui/selection-model.ts +256 -2
  118. package/src/ui/session-compare-facts.test.ts +67 -0
  119. package/src/ui/session-compare-facts.ts +122 -0
  120. package/src/ui/test-helpers.ts +2 -2
  121. package/src/utils/attachment-refs.test.ts +98 -0
  122. package/src/utils/attachment-refs.ts +177 -0
@@ -0,0 +1,127 @@
1
+ import { zhMsg } from './messages.js';
2
+ import { readService } from './host-service.js';
3
+ export class DshWorkspaceFacade {
4
+ ctx;
5
+ msg;
6
+ constructor(ctx, msg = zhMsg) {
7
+ this.ctx = ctx;
8
+ this.msg = msg;
9
+ }
10
+ registry() {
11
+ return readService(this.ctx, 'workspaceRegistry');
12
+ }
13
+ async listRecords() {
14
+ const registry = this.registry();
15
+ if (!registry)
16
+ return [];
17
+ return registry.list().map((w) => ({
18
+ id: String(w.id),
19
+ path: w.path,
20
+ title: w.title,
21
+ sessionIds: [...w.sessionIds].map(String),
22
+ createdAt: w.createdAt,
23
+ updatedAt: w.updatedAt,
24
+ }));
25
+ }
26
+ async writeRecord(record) {
27
+ const registry = this.registry();
28
+ if (!registry)
29
+ throw new Error(this.msg('host.workspaceUnavailable'));
30
+ const existing = registry.get(record.id);
31
+ if (existing) {
32
+ // DSH API 没有「整体覆盖」写通道:标题可更新;path/会话由 registry 依真实目录维护
33
+ if (record.title !== undefined && existing.title !== record.title)
34
+ await existing.setTitle(record.title);
35
+ return;
36
+ }
37
+ await registry.create(record.path, record.title);
38
+ }
39
+ async removeRecord(id) {
40
+ const registry = this.registry();
41
+ if (!registry)
42
+ return;
43
+ await registry.delete(id);
44
+ }
45
+ /**
46
+ * 把一个已存储会话登记进工作区(issue #45 会话归位)。
47
+ *
48
+ * 走 DSH `workspaceRegistry` 的实体方法 `attachSession`:
49
+ * - DSH 自己读会话 header 并用 realpath 校验 cwd 必须等于该工作区 path(不匹配直接拒绝);
50
+ * - 写入走 storage domain 的原子 update(内存权威与磁盘同时更新),并按 cwd 剪掉不属于
51
+ * 本工作区的候选 —— 因此**不需要**插件做「注册表合并 / 去重 / 备份回滚」,
52
+ * 更**不得**旁路直写 storages/workspace.json。
53
+ */
54
+ async attachSession(workspaceId, sessionId) {
55
+ const registry = this.registry();
56
+ if (!registry)
57
+ throw new Error(this.msg('host.workspaceUnavailable'));
58
+ const existing = registry.get(workspaceId);
59
+ if (!existing)
60
+ throw new Error(this.msg('host.workspaceMissingTarget', { id: workspaceId }));
61
+ await existing.attachSession(sessionId);
62
+ }
63
+ /**
64
+ * P2:读注册表级归档集。
65
+ *
66
+ * 「宿主没这个能力」与「归档集为空」必须分开:前者返回空数组但不会让导出侧写
67
+ * `archivedSessionIds: []`(导出侧只看能力是否存在决定带不带这个字段)。
68
+ */
69
+ async listArchivedSessionIds() {
70
+ const registry = this.registry();
71
+ // 宿主没暴露 getter ⇒ undefined(「读不到」),**不是**空数组(「确实为空」):
72
+ // 返回 [] 会让导出侧写出 `archivedSessionIds: []`,等于对用户声称「这台机器没有归档会话」。
73
+ if (registry === undefined || registry.archivedSessionIds === undefined)
74
+ return undefined;
75
+ const ids = registry.archivedSessionIds;
76
+ return Array.isArray(ids) ? ids.map(String) : undefined;
77
+ }
78
+ /** P2:归档一个会话;宿主未暴露该能力时显式报错(由调用方降级为告警,绝不静默当成功)。 */
79
+ async archiveSession(sessionId) {
80
+ const registry = this.registry();
81
+ if (!registry || typeof registry.archiveSession !== 'function') {
82
+ throw new Error(this.msg('host.workspaceArchiveUnavailable'));
83
+ }
84
+ await registry.archiveSession(sessionId);
85
+ }
86
+ /**
87
+ * P2-pin:读注册表级置顶集(最近置顶在前)。
88
+ *
89
+ * 与归档集同款边界:`undefined` = 宿主没暴露(导出侧不带字段),**不是**空数组
90
+ * —— 返回 [] 会让导出侧写出 `pinnedSessionIds: []`,等于声称「这台机器没有置顶会话」。
91
+ * 能力在 DSH 0.2.2-rc.5 的 `workspaceRegistry` 上(`pinnedSessionIds` / `pinSession`)。
92
+ */
93
+ async listPinnedSessionIds() {
94
+ const registry = this.registry();
95
+ if (registry === undefined || registry.pinnedSessionIds === undefined)
96
+ return undefined;
97
+ const ids = registry.pinnedSessionIds;
98
+ return Array.isArray(ids) ? ids.map(String) : undefined;
99
+ }
100
+ /** P2-pin:置顶一个会话;宿主未暴露该能力时显式报错(调用方降级为告警,绝不静默当成功)。 */
101
+ async pinSession(sessionId) {
102
+ const registry = this.registry();
103
+ if (!registry || typeof registry.pinSession !== 'function') {
104
+ throw new Error(this.msg('host.workspacePinUnavailable'));
105
+ }
106
+ await registry.pinSession(sessionId);
107
+ }
108
+ /**
109
+ * P2:按目标顺序重排工作区显示顺序。
110
+ *
111
+ * 宿主只给 `insertBefore(id, beforeId)`(DOM 语义),所以「变成目标顺序」由这里推出:
112
+ * 从倒数第二个开始,把每个 id 挪到它后一个 id 前面,逐次收敛即为目标相对顺序。
113
+ * 未知 id 直接过滤(别人删掉的工作区不该让整轮导入报错);宿主没有该原语时静默跳过 ——
114
+ * 顺序不是数据,丢了不影响可用性。
115
+ */
116
+ async reorderWorkspaces(orderedIds) {
117
+ const registry = this.registry();
118
+ if (!registry || typeof registry.insertBefore !== 'function')
119
+ return;
120
+ const known = new Set(registry.list().map((w) => String(w.id)));
121
+ const ids = orderedIds.filter((id) => known.has(id));
122
+ for (let i = ids.length - 2; i >= 0; i -= 1) {
123
+ await registry.insertBefore(ids[i], ids[i + 1]);
124
+ }
125
+ }
126
+ }
127
+ //# sourceMappingURL=host-workspace-facade.js.map
@@ -49,6 +49,11 @@ export declare function rebaseMapping(sourceHome: string | undefined, localHome:
49
49
  * 哪个适配器在消费它(core 也不得 import 会话字节工具)。键空间对齐因此落在计划生成期。
50
50
  */
51
51
  export declare function sessionUnitVersion(byUnit: ReadonlyMap<string, number>, unitId: string): number | undefined;
52
+ /**
53
+ * 同一键空间对齐的泛化版(P3 的逐条比对行、格式探针都用它)。
54
+ * 返回 undefined 表示「两个形态都没命中」——调用方必须把这种情况与「命中但值为空」分开。
55
+ */
56
+ export declare function sessionUnitLookup<T>(byUnit: ReadonlyMap<string, T>, unitId: string): T | undefined;
52
57
  /** 路径映射合并:只保留「已解析」(newPrefix 非空)的映射用于执行期数据改写;
53
58
  * 未解决项(newPrefix 空)保留在 plan.items 里供 UI 提示,但不参与数据映射。 */
54
59
  export declare function mergePathMappings(items: PlanItem[], userMappings: PathMapping[]): PathMapping[];
@@ -61,6 +66,16 @@ export declare function mergePathMappings(items: PlanItem[], userMappings: PathM
61
66
  * 映射在这些分区上**没有任何合法作用**:文件内容存的是字节(`Uint8Array` 叶子),不会被改。
62
67
  */
63
68
  export declare function applyMappingsToSections(sections: Map<SectionId, unknown>, mappings: PathMapping[], fileCollectionIds?: ReadonlySet<string>): void;
69
+ /**
70
+ * P4:由「导入到 <目录>」推导出工作区路径映射(`workspaceRoot` → `PathMapping[]`)。
71
+ *
72
+ * 只产出**已解析**(newPrefix 非空)的映射,且只作用于 workspaces;没有绝对源路径、没有根目录、
73
+ * 或该源路径已被用户手填映射命中时,一律不产出(显式映射优先,不重复给规则)。
74
+ *
75
+ * 为什么放在计划期纯函数里:它只读分析产物(sections 里的 workspaces 载荷)+ 目标平台,
76
+ * 不碰文件系统,因此 Dry Run 与真导入看到的是同一份推导结果。
77
+ */
78
+ export declare function workspaceRootMappings(sections: ReadonlyMap<SectionId, unknown>, rootDir: string | undefined, targetPlatform: string, userMappings: readonly PathMapping[]): PathMapping[];
64
79
  /** 路径形态判定:跨平台盘符/UNIX 冲突 → platformMismatch;其余绝对路径 → missing(需映射) */
65
80
  export declare function detectPathIssues(sourcePlatform: string, targetPlatform: string, sections: Map<SectionId, unknown>): PathIssue[];
66
81
  export declare function judgePath(p: string, sourcePlatform: string, targetPlatform: string): PathIssue;
@@ -14,6 +14,8 @@ import { isFileSection } from '../schema/config.js';
14
14
  import { validateManifest } from '../schema/manifest.js';
15
15
  import { migrateToCurrent } from '../migrations/index.js';
16
16
  import { isTombstoned } from '../schema/tombstones.js';
17
+ import { applyPathMapping } from './path-mapping.js';
18
+ import { deriveWorkspaceMappings } from './workspace-root.js';
17
19
  export async function reportRollbackToJournal(binding, report) {
18
20
  const reporter = binding;
19
21
  await reporter?.recordRollback?.(report);
@@ -90,6 +92,13 @@ export function rebaseMapping(sourceHome, localHome) {
90
92
  * 哪个适配器在消费它(core 也不得 import 会话字节工具)。键空间对齐因此落在计划生成期。
91
93
  */
92
94
  export function sessionUnitVersion(byUnit, unitId) {
95
+ return sessionUnitLookup(byUnit, unitId);
96
+ }
97
+ /**
98
+ * 同一键空间对齐的泛化版(P3 的逐条比对行、格式探针都用它)。
99
+ * 返回 undefined 表示「两个形态都没命中」——调用方必须把这种情况与「命中但值为空」分开。
100
+ */
101
+ export function sessionUnitLookup(byUnit, unitId) {
93
102
  const direct = byUnit.get(unitId);
94
103
  if (direct !== undefined)
95
104
  return direct;
@@ -132,6 +141,41 @@ export function applyMappingsToSections(sections, mappings, fileCollectionIds =
132
141
  sections.set(sectionId, applyPrefixMappings(data, relevant));
133
142
  }
134
143
  }
144
+ /**
145
+ * P4:由「导入到 <目录>」推导出工作区路径映射(`workspaceRoot` → `PathMapping[]`)。
146
+ *
147
+ * 只产出**已解析**(newPrefix 非空)的映射,且只作用于 workspaces;没有绝对源路径、没有根目录、
148
+ * 或该源路径已被用户手填映射命中时,一律不产出(显式映射优先,不重复给规则)。
149
+ *
150
+ * 为什么放在计划期纯函数里:它只读分析产物(sections 里的 workspaces 载荷)+ 目标平台,
151
+ * 不碰文件系统,因此 Dry Run 与真导入看到的是同一份推导结果。
152
+ */
153
+ export function workspaceRootMappings(sections, rootDir, targetPlatform, userMappings) {
154
+ if (rootDir === undefined || rootDir.trim() === '')
155
+ return [];
156
+ const data = sections.get('workspaces');
157
+ if (data === null || typeof data !== 'object')
158
+ return [];
159
+ const records = data.workspaces;
160
+ if (!Array.isArray(records))
161
+ return [];
162
+ const inputs = [];
163
+ for (const raw of records) {
164
+ if (raw === null || typeof raw !== 'object')
165
+ continue;
166
+ const path = raw.path;
167
+ const title = raw.title;
168
+ if (typeof path !== 'string')
169
+ continue;
170
+ inputs.push({ path, title: typeof title === 'string' ? title : undefined });
171
+ }
172
+ // 用户手填映射优先:只把「作用于 workspaces(或未限定分区)」的规则算作已认领
173
+ const claimed = userMappings.filter((m) => m.newPrefix !== '' && (m.appliesTo.length === 0 || m.appliesTo.includes('workspaces')));
174
+ return deriveWorkspaceMappings(inputs, rootDir, {
175
+ platform: targetPlatform,
176
+ isClaimed: (source) => applyPathMapping(source, claimed) !== null,
177
+ });
178
+ }
135
179
  /** 路径形态判定:跨平台盘符/UNIX 冲突 → platformMismatch;其余绝对路径 → missing(需映射) */
136
180
  export function detectPathIssues(sourcePlatform, targetPlatform, sections) {
137
181
  const issues = [];
@@ -26,6 +26,12 @@ export declare const zh: {
26
26
  readonly 'export.vaultRefreshFailed': 'vault 镜像刷新失败(不影响导出): {reason}';
27
27
  readonly 'export.sessionsLimited': '会话按数量筛选:只带最新 {count} 个(共 {total} 个;单位 = 会话目录,同一会话的日志一起走)';
28
28
  readonly 'export.sessionsNone': '会话按数量筛选:本次一个都不带(sessions.limit = 0)';
29
+ readonly 'export.attachmentsReferenced': '附件只带被会话引用过的 {count} 个(本机库共 {total} 个,另有 {missing} 个被引用但已不在本机)';
30
+ readonly 'export.attachmentsNoSessions': '附件分区依赖会话:本次未选中任何会话,故一条附件都不带';
31
+ readonly 'export.attachmentsLimitIgnored': '附件按全部会话的引用收集,未按「最新 N 个」收窄(宁可多带,不静默丢图)';
32
+ readonly 'export.attachmentsScanUnreadable': '读不到会话目录,无法判定哪些附件被引用:本次按整个附件库收集';
33
+ readonly 'export.attachmentsScanFailed': '{count} 个会话日志读不出或解不开,无法判定附件引用:本次按整个附件库收集';
34
+ readonly 'export.attachmentsNoZstd': '当前运行环境没有 zstd 解压能力,无法读取会话日志判定附件引用:本次按整个附件库收集';
29
35
  readonly 'export.sessionsWorkspacesCoupled': '已连带导出 {count} 条与会话相关的工作区记录(会话要在目标机显示出来,必须有工作区指向它的 cwd)';
30
36
  readonly 'export.sessionsDeclaredInWorkspaces': '已把本次导出的 {count} 次会话声明进 {workspaces} 条工作区记录(DSH 工作区 sessionIds 覆盖率很低,漏了这一步目标机就看不见这些对话)';
31
37
  readonly 'export.sessionsWorkspacesCarriedAll': '选中的会话没有登记在任何工作区记录里:已连带导出全部 {count} 条工作区记录(漏带工作区 = 目标机上这些对话看不见)';
@@ -52,6 +58,9 @@ export declare const zh: {
52
58
  readonly 'import.sessionsFormatSampled': '会话格式体检为抽查:本次检查了 {sampled} 条,另有 {skipped} 条未检查';
53
59
  readonly 'import.sessionsFormatAborted': '包内有 {count} 条会话是 v{newer} 格式,高于本机 DSH 支持的 v{target}:按当前处置「中止」,本次导入在计划阶段已停止(未写入任何内容)。请改选「跳过这些会话」或「仅提示引导」,或先把本机 DSH 升级到相同/更新版本';
54
60
  readonly 'import.sessionsNeedRestart': '已写入 {count} 个会话文件:DSH 的会话列表在启动时读取,需要重启 DSH(桌面端:退出应用重开)后这些对话才会出现在工作区列表里';
61
+ readonly 'import.sessionOverwrite': '导入会覆盖掉本机 {units} 条会话里的新消息(共 {events} 条;本次比对 {total} 条会话):这些内容只存在于本机、备份包里没有,恢复后按包为准会被替换 —— 需要留下本机这份请先导出当前状态';
62
+ readonly 'import.sessionAttachmentsMissing': '包内有 {count} 个被对话引用的附件没有随包({ids} …):恢复后这些图片/文件会显示为缺失(多半是导出时未勾选「会话附件」分区)';
63
+ readonly 'import.sessionCompareSampled': '会话逐条比对为抽查:本次比对了 {sampled} 条,另有 {skipped} 条未比对(未比对不代表一致)';
55
64
  readonly 'export.sessionParentsCoupled': '已连带导出 {count} 个父对话(DSH 工作区只在父对话之下显示子代理会话;不带父对话时导入后在工作区里看不到)';
56
65
  readonly 'export.sessionParentsUncoupled': '有 {count} 个子代理会话未能连带其父对话:{detail} —— 只带子会话时,导入后 DSH 工作区里不会显示它们';
57
66
  readonly 'export.sessionChildrenCoupled': '已连带导出 {count} 个子代理会话(DSH 把子对话显示在父对话的树状图下面;只带父对话时那棵树是空的)';
@@ -182,6 +191,17 @@ export declare const zh: {
182
191
  readonly 'host.syncStatusTimeout': '同步状态读取超时(10 秒):DSH 凭据服务或工作副本自检没有在预算内返回,请重试';
183
192
  readonly 'host.workspaceUnavailable': 'workspaceRegistry 服务不可用,无法写入工作区';
184
193
  readonly 'host.workspaceMissingTarget': '目标机不存在工作区 {id}(无法登记会话)';
194
+ readonly 'host.workspaceArchiveUnavailable': '宿主未暴露会话归档能力,归档状态未恢复';
195
+ readonly 'adapter.workspaceArchiveUnreadable': '未能读取会话归档集(本次备份不含归档状态):{msg}';
196
+ readonly 'adapter.workspaceArchiveRestored': '已恢复 {count} 个归档会话';
197
+ readonly 'adapter.workspaceArchiveFailed': '{count} 个归档会话未恢复({ids}):{msg}';
198
+ readonly 'host.workspacePinUnavailable': '宿主未暴露会话置顶能力,置顶状态未恢复';
199
+ readonly 'adapter.workspacePinUnreadable': '未能读取会话置顶集(本次备份不含置顶状态):{msg}';
200
+ readonly 'adapter.workspacePinRestored': '已恢复 {count} 个置顶会话';
201
+ readonly 'adapter.workspacePinFailed': '{count} 个置顶会话未恢复({ids}):{msg}';
202
+ readonly 'adapter.workspaceReorderSkipped': '工作区显示顺序未恢复:包内 {count} 条工作区没能与新机记录对应上(路径与标题都变过?)';
203
+ readonly 'adapter.workspaceReorderFailed': '工作区显示顺序未恢复:{msg}';
204
+ readonly 'export.attachmentsAllSessions': '附件按全部会话计算引用面(未指定会话范围):本机库共 {total} 个对象,其中 {count} 个被引用,{missing} 个已被引用但不在本机';
185
205
  readonly 'host.sessionStoreShapeUnknown': '宿主会话存储列举(sessionPersistence.list())的元素形状无法解析(探测形状 {shape},{count} 个元素全部认不出):父子关系判定放弃,绝不当作「本机没有父子关系」(请升级 DSH,或把该形状反馈给插件)';
186
206
  readonly 'host.sessionStorePurposeReindex': '会话 header 重新索引';
187
207
  readonly 'host.sessionStorePurposeParentRelations': '父子关系判定';
@@ -10,6 +10,12 @@ export const zh = {
10
10
  'export.vaultRefreshFailed': 'vault 镜像刷新失败(不影响导出): {reason}',
11
11
  'export.sessionsLimited': '会话按数量筛选:只带最新 {count} 个(共 {total} 个;单位 = 会话目录,同一会话的日志一起走)',
12
12
  'export.sessionsNone': '会话按数量筛选:本次一个都不带(sessions.limit = 0)',
13
+ 'export.attachmentsReferenced': '附件只带被会话引用过的 {count} 个(本机库共 {total} 个,另有 {missing} 个被引用但已不在本机)',
14
+ 'export.attachmentsNoSessions': '附件分区依赖会话:本次未选中任何会话,故一条附件都不带',
15
+ 'export.attachmentsLimitIgnored': '附件按全部会话的引用收集,未按「最新 N 个」收窄(宁可多带,不静默丢图)',
16
+ 'export.attachmentsScanUnreadable': '读不到会话目录,无法判定哪些附件被引用:本次按整个附件库收集',
17
+ 'export.attachmentsScanFailed': '{count} 个会话日志读不出或解不开,无法判定附件引用:本次按整个附件库收集',
18
+ 'export.attachmentsNoZstd': '当前运行环境没有 zstd 解压能力,无法读取会话日志判定附件引用:本次按整个附件库收集',
13
19
  'export.sessionsWorkspacesCoupled': '已连带导出 {count} 条与会话相关的工作区记录(会话要在目标机显示出来,必须有工作区指向它的 cwd)',
14
20
  'export.sessionsDeclaredInWorkspaces': '已把本次导出的 {count} 次会话声明进 {workspaces} 条工作区记录(DSH 工作区 sessionIds 覆盖率很低,漏了这一步目标机就看不见这些对话)',
15
21
  'export.sessionsWorkspacesCarriedAll': '选中的会话没有登记在任何工作区记录里:已连带导出全部 {count} 条工作区记录(漏带工作区 = 目标机上这些对话看不见)',
@@ -37,6 +43,9 @@ export const zh = {
37
43
  'import.sessionsFormatSampled': '会话格式体检为抽查:本次检查了 {sampled} 条,另有 {skipped} 条未检查',
38
44
  'import.sessionsFormatAborted': '包内有 {count} 条会话是 v{newer} 格式,高于本机 DSH 支持的 v{target}:按当前处置「中止」,本次导入在计划阶段已停止(未写入任何内容)。请改选「跳过这些会话」或「仅提示引导」,或先把本机 DSH 升级到相同/更新版本',
39
45
  'import.sessionsNeedRestart': '已写入 {count} 个会话文件:DSH 的会话列表在启动时读取,需要重启 DSH(桌面端:退出应用重开)后这些对话才会出现在工作区列表里',
46
+ 'import.sessionOverwrite': '导入会覆盖掉本机 {units} 条会话里的新消息(共 {events} 条;本次比对 {total} 条会话):这些内容只存在于本机、备份包里没有,恢复后按包为准会被替换 —— 需要留下本机这份请先导出当前状态',
47
+ 'import.sessionAttachmentsMissing': '包内有 {count} 个被对话引用的附件没有随包({ids} …):恢复后这些图片/文件会显示为缺失(多半是导出时未勾选「会话附件」分区)',
48
+ 'import.sessionCompareSampled': '会话逐条比对为抽查:本次比对了 {sampled} 条,另有 {skipped} 条未比对(未比对不代表一致)',
40
49
  'export.sessionParentsCoupled': '已连带导出 {count} 个父对话(DSH 工作区只在父对话之下显示子代理会话;不带父对话时导入后在工作区里看不到)',
41
50
  'export.sessionParentsUncoupled': '有 {count} 个子代理会话未能连带其父对话:{detail} —— 只带子会话时,导入后 DSH 工作区里不会显示它们',
42
51
  'export.sessionChildrenCoupled': '已连带导出 {count} 个子代理会话(DSH 把子对话显示在父对话的树状图下面;只带父对话时那棵树是空的)',
@@ -171,6 +180,17 @@ export const zh = {
171
180
  'host.syncStatusTimeout': '同步状态读取超时(10 秒):DSH 凭据服务或工作副本自检没有在预算内返回,请重试',
172
181
  'host.workspaceUnavailable': 'workspaceRegistry 服务不可用,无法写入工作区',
173
182
  'host.workspaceMissingTarget': '目标机不存在工作区 {id}(无法登记会话)',
183
+ 'host.workspaceArchiveUnavailable': '宿主未暴露会话归档能力,归档状态未恢复',
184
+ 'adapter.workspaceArchiveUnreadable': '未能读取会话归档集(本次备份不含归档状态):{msg}',
185
+ 'adapter.workspaceArchiveRestored': '已恢复 {count} 个归档会话',
186
+ 'adapter.workspaceArchiveFailed': '{count} 个归档会话未恢复({ids}):{msg}',
187
+ 'host.workspacePinUnavailable': '宿主未暴露会话置顶能力,置顶状态未恢复',
188
+ 'adapter.workspacePinUnreadable': '未能读取会话置顶集(本次备份不含置顶状态):{msg}',
189
+ 'adapter.workspacePinRestored': '已恢复 {count} 个置顶会话',
190
+ 'adapter.workspacePinFailed': '{count} 个置顶会话未恢复({ids}):{msg}',
191
+ 'adapter.workspaceReorderSkipped': '工作区显示顺序未恢复:包内 {count} 条工作区没能与新机记录对应上(路径与标题都变过?)',
192
+ 'adapter.workspaceReorderFailed': '工作区显示顺序未恢复:{msg}',
193
+ 'export.attachmentsAllSessions': '附件按全部会话计算引用面(未指定会话范围):本机库共 {total} 个对象,其中 {count} 个被引用,{missing} 个已被引用但不在本机',
174
194
  'host.sessionStoreShapeUnknown': '宿主会话存储列举(sessionPersistence.list())的元素形状无法解析(探测形状 {shape},{count} 个元素全部认不出):父子关系判定放弃,绝不当作「本机没有父子关系」(请升级 DSH,或把该形状反馈给插件)',
175
195
  'host.sessionStorePurposeReindex': '会话 header 重新索引',
176
196
  'host.sessionStorePurposeParentRelations': '父子关系判定',
@@ -542,6 +562,12 @@ export const en = {
542
562
  'export.vaultRefreshFailed': 'Vault mirror refresh failed (export unaffected): {reason}',
543
563
  'export.sessionsLimited': 'Sessions filtered by count: only the latest {count} are included ({total} total; the unit is a session directory, so all logs of one session travel together)',
544
564
  'export.sessionsNone': 'Sessions filtered by count: none are included this time (sessions.limit = 0)',
565
+ 'export.attachmentsReferenced': 'Attachments: only {count} referenced by sessions are included ({total} in the local store, {missing} referenced ones are already gone from this machine)',
566
+ 'export.attachmentsNoSessions': 'The attachments section depends on sessions: no session was selected, so no attachment is included',
567
+ 'export.attachmentsLimitIgnored': 'Attachments are collected from every session reference, not narrowed by "latest N" (prefer extra bytes over silently losing images)',
568
+ 'export.attachmentsScanUnreadable': 'The sessions directory is unreadable, so referenced attachments cannot be determined: the whole attachment store is collected this time',
569
+ 'export.attachmentsScanFailed': '{count} session logs could not be read or decoded, so attachment references cannot be determined: the whole attachment store is collected this time',
570
+ 'export.attachmentsNoZstd': 'This runtime has no zstd decompression, so session logs cannot be read to determine attachment references: the whole attachment store is collected this time',
545
571
  'export.sessionsWorkspacesCoupled': 'Also exported {count} workspace record(s) that own the selected sessions (a session only shows up when a workspace points at its cwd)',
546
572
  'export.sessionsDeclaredInWorkspaces': 'Declared the {count} exported session(s) in {workspaces} workspace record(s) (DSH workspace sessionIds coverage is very low; without this step those conversations stay invisible on the target machine)',
547
573
  'export.sessionsWorkspacesCarriedAll': 'None of the selected sessions is registered in any workspace record: all {count} workspace record(s) were exported as well (without a workspace those sessions stay invisible on the target machine)',
@@ -569,6 +595,9 @@ export const en = {
569
595
  'import.sessionsFormatSampled': 'Session format check was sampled: {sampled} checked, {skipped} not checked',
570
596
  'import.sessionsFormatAborted': 'This backup carries {count} session log(s) in format v{newer}, newer than this DSH build supports (v{target}): with the current "abort" disposition the import stopped at the planning stage (nothing was written). Choose "skip these sessions" or "guidance only", or upgrade this DSH build to the same or a newer version first',
571
597
  'import.sessionsNeedRestart': 'Wrote {count} session file(s): DSH reads its session list at startup, so those conversations only appear in the workspace list after restarting DSH (Desktop: quit and reopen the app)',
598
+ 'import.sessionOverwrite': 'Import replaces newer messages that exist only on this machine: {units} conversation(s), {events} message(s), compared against {total} conversation(s). Those messages are not in the backup, so restoring makes the bundle authoritative -- export the current state first if you need to keep them',
599
+ 'import.sessionAttachmentsMissing': 'The backup references {count} attachment(s) that are not in the bundle ({ids} ...): those images/files will show as missing after restore (the session attachments section was probably not selected when exporting)',
600
+ 'import.sessionCompareSampled': 'Per-conversation comparison was sampled: {sampled} compared, {skipped} not compared (not compared does not mean identical)',
572
601
  'export.sessionParentsCoupled': 'Carried {count} parent conversation(s) along (DSH only shows subagent sessions underneath their parent; without the parent they stay invisible in the workspace after import)',
573
602
  'export.sessionParentsUncoupled': '{count} subagent session(s) could not carry their parent conversation: {detail} -- the imported child alone never shows up in a DSH workspace',
574
603
  'export.sessionChildrenCoupled': 'Carried {count} subagent conversation(s) along (DSH renders child conversations underneath their parent; the parent alone arrives with an empty tree)',
@@ -703,6 +732,17 @@ export const en = {
703
732
  'host.syncStatusTimeout': 'Sync status timed out (10 s): the DSH credential service or work-copy self-check did not return within budget; please retry',
704
733
  'host.workspaceUnavailable': 'workspaceRegistry service unavailable; cannot write the workspace',
705
734
  'host.workspaceMissingTarget': 'Workspace {id} does not exist on this machine (cannot attach the session)',
735
+ 'host.workspaceArchiveUnavailable': 'This host exposes no session-archive capability; archive state was not restored',
736
+ 'adapter.workspaceArchiveUnreadable': 'Could not read the session archive set (this backup carries no archive state): {msg}',
737
+ 'adapter.workspaceArchiveRestored': 'Restored {count} archived session(s)',
738
+ 'adapter.workspaceArchiveFailed': '{count} archived session(s) were not restored ({ids}): {msg}',
739
+ 'host.workspacePinUnavailable': 'This host exposes no session-pin capability; pin state was not restored',
740
+ 'adapter.workspacePinUnreadable': 'Could not read the session pin set (this backup carries no pin state): {msg}',
741
+ 'adapter.workspacePinRestored': 'Restored {count} pinned session(s)',
742
+ 'adapter.workspacePinFailed': '{count} pinned session(s) were not restored ({ids}): {msg}',
743
+ 'adapter.workspaceReorderSkipped': 'Workspace display order was not restored: {count} workspace(s) in the bundle could not be matched to a record on this machine (path and title both changed?)',
744
+ 'adapter.workspaceReorderFailed': 'Workspace display order was not restored: {msg}',
745
+ 'export.attachmentsAllSessions': 'Attachments are collected against every session (no session scope was given): {count} of {total} objects on this machine are referenced, and {missing} referenced object(s) are no longer present',
706
746
  'host.sessionStoreShapeUnknown': 'Cannot parse the elements returned by the host session store (sessionPersistence.list(); probed shape {shape}, none of the {count} elements is recognizable): parent/child detection is abandoned rather than treated as "no parent relations on this machine" (please upgrade DSH or report this shape to the plugin)',
707
747
  'host.sessionStorePurposeReindex': 'session header re-index',
708
748
  'host.sessionStorePurposeParentRelations': 'parent/child detection',
@@ -0,0 +1,52 @@
1
+ /**
2
+ * 分析期的会话体检:格式版本探针、逐条比对、解析结果告警 —— 从 analyzer.ts 下沉。
3
+ * (计划项标记不在这里:它只写展示字段、属于计划期,见 core/session-verdict-plan.ts。)
4
+ *
5
+ * 为什么独立成模块:analyzer 越过体量棘轮(tests/file-size-ratchet.test.ts),而这些函数的
6
+ * 依赖全部由入参给出(探针、适配器表、文案函数、本机支持版本),搬出来不改变任何调用点的
7
+ * 语义,也不新增对外契约。**判定口径仍只有一处**:纯比对算法在 core/session-compare.ts。
8
+ */
9
+ import type { SectionId } from '../schema/types.ts';
10
+ import type { MsgFunc } from './messages.ts';
11
+ import type { ConfigAdapter, HostContext, SessionCompareSummary, SessionFormatProbeResult } from './types.ts';
12
+ /** 会话格式体检的「已落定」结果(探针 + 本机支持版本;不可判定时整体缺省)。 */
13
+ export interface ResolvedSessionFormats {
14
+ target: number;
15
+ unreadable: {
16
+ unitId: string;
17
+ version: number;
18
+ }[];
19
+ /** 本次体检真正看过的会话条数(解出 header 的 + 解不出的) */
20
+ examined: number;
21
+ /** 因抽样上限未检查的会话条数 */
22
+ skipped: number;
23
+ }
24
+ /**
25
+ * 会话格式体检(探针注入:core 不解析会话格式)。
26
+ *
27
+ * 「包里的版本 > 本机支持的版本」告警;本机版本解析不到时**不猜**(宁可不报,也不谎报兼容)。
28
+ * 不可判定(无探针 / 无 sessions / 本机版本解析不到 / 探针抛错)一律返回 null。
29
+ */
30
+ export declare function resolveSessionFormats(sections: Map<SectionId, unknown>, probe: ((files: readonly {
31
+ relativePath: string;
32
+ data: Uint8Array;
33
+ }[]) => SessionFormatProbeResult) | undefined, target: number | undefined): ResolvedSessionFormats | null;
34
+ export declare function sessionFormatWarnings(result: ResolvedSessionFormats | null, msg: MsgFunc): string[];
35
+ /**
36
+ * 会话逐条比对(包内同名会话 vs **本机**)—— 与格式体检一样**每份归档只跑一次**。
37
+ *
38
+ * 为什么由 sessions adapter 执行而不是这里:解会话日志要用 zstd 帧与首帧能力,那是会话字节
39
+ * 工具(core 不 import 它);纯比对算法在 core/session-compare.ts。此处只负责「找到适配器、
40
+ * 调一次、再补上附件缺口」。
41
+ *
42
+ * 附件缺口是**纯包内判定**(包内会话引用到的 id ∩ 包内实际带上的附件对象),因此不读本机、
43
+ * 也不会因为本机文件被用户删了而误报:它回答的是「按这个包恢复,哪些图会缺」。
44
+ */
45
+ export declare function resolveSessionCompare(sections: Map<SectionId, unknown>, adapters: readonly ConfigAdapter[], ctx: HostContext): Promise<SessionCompareSummary | null>;
46
+ /**
47
+ * 逐条比对的告警(只在**真会丢东西**时说话):
48
+ * - 本机比包内多内容 → 「导入会覆盖掉本机 N 条消息」(这是本功能存在的理由);
49
+ * - 引用了包内没有的附件 → 恢复后图会缺;
50
+ * - 预算截断 → 「另有 N 条未比对」(绝不让用户以为全都比过了)。
51
+ */
52
+ export declare function sessionCompareWarnings(result: SessionCompareSummary | null, msg: MsgFunc): string[];
@@ -0,0 +1,135 @@
1
+ import { attachmentIdOfRelPath } from '../utils/attachment-refs.js';
2
+ import { overwriteExposure } from './session-compare.js';
3
+ /**
4
+ * 会话格式体检(探针注入:core 不解析会话格式)。
5
+ *
6
+ * 「包里的版本 > 本机支持的版本」告警;本机版本解析不到时**不猜**(宁可不报,也不谎报兼容)。
7
+ * 不可判定(无探针 / 无 sessions / 本机版本解析不到 / 探针抛错)一律返回 null。
8
+ */
9
+ export function resolveSessionFormats(sections, probe, target) {
10
+ if (probe === undefined || !sections.has('sessions'))
11
+ return null;
12
+ if (target === undefined)
13
+ return null;
14
+ const rows = sections.get('sessions')?.files;
15
+ if (!Array.isArray(rows))
16
+ return null;
17
+ const files = [];
18
+ for (const row of rows) {
19
+ const item = row;
20
+ if (typeof item.relativePath === 'string' && item.data instanceof Uint8Array) {
21
+ files.push({ relativePath: item.relativePath, data: item.data });
22
+ }
23
+ }
24
+ try {
25
+ const probed = probe(files);
26
+ // 只有明确「版本更高」才算读不了;units 缺省(旧探针实现)时退化为空数组(不猜单元)。
27
+ return {
28
+ target,
29
+ unreadable: (probed.units ?? []).filter((unit) => unit.version > target),
30
+ examined: probed.sampled + probed.unreadable,
31
+ skipped: probed.skipped,
32
+ };
33
+ }
34
+ catch {
35
+ // 体检失败绝不拖垮分析,也绝不因此宣称兼容(本条静默,另有导出报告可核对)。
36
+ return null;
37
+ }
38
+ }
39
+ export function sessionFormatWarnings(result, msg) {
40
+ if (result === null)
41
+ return [];
42
+ const target = result.target;
43
+ const newer = result.unreadable.map((unit) => unit.version);
44
+ if (newer.length === 0)
45
+ return [];
46
+ const warnings = [msg('import.sessionsFormatUnsupported', {
47
+ count: String(newer.length),
48
+ newer: String(Math.max(...newer)),
49
+ target: String(target),
50
+ })];
51
+ if (result.skipped > 0) {
52
+ warnings.push(msg('import.sessionsFormatSampled', {
53
+ sampled: String(result.examined),
54
+ skipped: String(result.skipped),
55
+ }));
56
+ }
57
+ return warnings;
58
+ }
59
+ /**
60
+ * 会话逐条比对(包内同名会话 vs **本机**)—— 与格式体检一样**每份归档只跑一次**。
61
+ *
62
+ * 为什么由 sessions adapter 执行而不是这里:解会话日志要用 zstd 帧与首帧能力,那是会话字节
63
+ * 工具(core 不 import 它);纯比对算法在 core/session-compare.ts。此处只负责「找到适配器、
64
+ * 调一次、再补上附件缺口」。
65
+ *
66
+ * 附件缺口是**纯包内判定**(包内会话引用到的 id ∩ 包内实际带上的附件对象),因此不读本机、
67
+ * 也不会因为本机文件被用户删了而误报:它回答的是「按这个包恢复,哪些图会缺」。
68
+ */
69
+ export async function resolveSessionCompare(sections, adapters, ctx) {
70
+ if (!sections.has('sessions'))
71
+ return null;
72
+ const data = sections.get('sessions');
73
+ if (data === undefined || !Array.isArray(data.files) || data.files.length === 0)
74
+ return null;
75
+ const adapter = adapters.find((candidate) => candidate.id === 'sessions' && typeof candidate.compareSessions === 'function');
76
+ if (adapter?.compareSessions === undefined)
77
+ return null;
78
+ let summary;
79
+ try {
80
+ summary = await adapter.compareSessions(ctx, data);
81
+ }
82
+ catch {
83
+ // 比对失败绝不拖垮分析,也绝不因此宣称「无差异」(本条静默)
84
+ return null;
85
+ }
86
+ if (summary === null)
87
+ return null;
88
+ const present = new Set();
89
+ const attachments = sections.get('attachments');
90
+ if (attachments !== undefined && Array.isArray(attachments.files)) {
91
+ for (const row of attachments.files) {
92
+ const rel = row.relativePath;
93
+ if (typeof rel !== 'string')
94
+ continue;
95
+ const id = attachmentIdOfRelPath(rel);
96
+ if (id !== null)
97
+ present.add(id);
98
+ }
99
+ }
100
+ const missing = summary.attachmentsMissing.filter((id) => !present.has(id));
101
+ return { ...summary, attachmentsMissing: missing };
102
+ }
103
+ /**
104
+ * 逐条比对的告警(只在**真会丢东西**时说话):
105
+ * - 本机比包内多内容 → 「导入会覆盖掉本机 N 条消息」(这是本功能存在的理由);
106
+ * - 引用了包内没有的附件 → 恢复后图会缺;
107
+ * - 预算截断 → 「另有 N 条未比对」(绝不让用户以为全都比过了)。
108
+ */
109
+ export function sessionCompareWarnings(result, msg) {
110
+ if (result === null)
111
+ return [];
112
+ const warnings = [];
113
+ const exposure = overwriteExposure(result.rows);
114
+ if (exposure.units > 0) {
115
+ warnings.push(msg('import.sessionOverwrite', {
116
+ units: String(exposure.units),
117
+ events: String(exposure.events),
118
+ total: String(result.rows.length),
119
+ }));
120
+ }
121
+ if (result.attachmentsMissing.length > 0) {
122
+ warnings.push(msg('import.sessionAttachmentsMissing', {
123
+ count: String(result.attachmentsMissing.length),
124
+ ids: result.attachmentsMissing.slice(0, 3).map((id) => id.slice(0, 19)).join(', '),
125
+ }));
126
+ }
127
+ if (result.skipped > 0) {
128
+ warnings.push(msg('import.sessionCompareSampled', {
129
+ sampled: String(result.rows.length),
130
+ skipped: String(result.skipped),
131
+ }));
132
+ }
133
+ return warnings;
134
+ }
135
+ //# sourceMappingURL=session-analyze.js.map
@@ -0,0 +1,54 @@
1
+ /**
2
+ * 会话逐条比对(P3)—— **纯函数,零 I/O**。
3
+ *
4
+ * 为什么需要它:导入是把包内会话**覆盖**到本机(备份恢复口径,不是增量追加 —— 见 K1:
5
+ * 双机日常同步走远程同步通道)。于是「本机这条对话在导出之后又聊了 40 轮」这件事,
6
+ * 用户在导入前必须看得见:导入会以包为准,那 40 轮会被覆盖掉。此前插件只能告诉用户
7
+ * 「这个文件 Conflict」(文件级 SHA 不同),无法说清**差在哪、会丢多少**。
8
+ *
9
+ * 判据只有「事件序列前缀」这一条(不猜时间、不猜 tokens):
10
+ * - identical:逐条一致(只差 bookkeeping 事件也算一致);
11
+ * - packAhead:本机是包的前缀 → 包里多出 N 条(导入后多 N 条);
12
+ * - localAhead:包是本机的前缀 → 本机多出 N 条(**导入会覆盖掉这 N 条**);
13
+ * - diverged:前缀之后两边都有内容 → 分叉(导入按包为准)。
14
+ *
15
+ * 反序列化口径:事件行按 JSON 规范化后比对(键排序 + `cwd` 归一为 `<cwd>`)。为什么必须
16
+ * 归一 cwd:包内首帧 cwd 是**导出机**的路径,导入时会按映射改写(只改首帧,C1),
17
+ * 不归一会让任何跨机恢复都被判成 diverged —— 那是误报,不是差异。
18
+ */
19
+ import type { SessionCompareRow, SessionVerdict } from './types.ts';
20
+ /** 一行事件 → 比对用的规范形态;空行返回空串(调用方过滤)。 */
21
+ export declare function canonicalEventLine(line: string): string;
22
+ /** 文本(解码后的日志)→ 规范事件行。空行与非对象行照样保留原文,绝不静默丢条。 */
23
+ export declare function canonicalEventLines(text: string): string[];
24
+ /** 两条事件序列的比对结论(不含 unit 信息;聚合见 {@link aggregateSessionRows})。 */
25
+ export interface EventStreamDiff {
26
+ verdict: 'identical' | 'packAhead' | 'localAhead' | 'diverged';
27
+ /** 包内事件条数 */
28
+ packEvents: number;
29
+ /** 本机事件条数 */
30
+ localEvents: number;
31
+ /** 包比本机多出的事件条数(prefix 之后) */
32
+ packAheadBy: number;
33
+ /** 本机比包多出的事件条数(prefix 之后)—— diverged 时 = 会被覆盖掉的条数 */
34
+ localAheadBy: number;
35
+ /** 首个不一致位置(0 起);无差异时缺省 */
36
+ divergedAt?: number;
37
+ }
38
+ export declare function compareEventStreams(pack: readonly string[], local: readonly string[]): EventStreamDiff;
39
+ /**
40
+ * 同一会话单元可能有多份日志(不同 generation)。按文件相对路径逐一比,再取**最严重**的那条:
41
+ * 用户关心的是「这一条导入会不会丢东西」,任一份分叉就必须说成会丢。
42
+ */
43
+ export declare function aggregateSessionRows(unitId: string, diffs: readonly EventStreamDiff[], title?: string): SessionCompareRow;
44
+ /** 汇总计数(UI/报告只看这几个数字,逐条明细在 rows 里)。 */
45
+ export declare function countSessionVerdicts(rows: readonly SessionCompareRow[]): Record<SessionVerdict, number>;
46
+ /**
47
+ * 「导入会覆盖掉本机会话内容」的条数与事件总数(确认页必须把它说出来的那句数字)。
48
+ *
49
+ * 口径:localAhead + diverged 两类 —— 它们的共同点就是**本机有包内没有的内容**。
50
+ */
51
+ export declare function overwriteExposure(rows: readonly SessionCompareRow[]): {
52
+ units: number;
53
+ events: number;
54
+ };