dsh-config-manager 0.8.0 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/lib/adapters/mcp.d.ts +6 -1
  2. package/lib/adapters/mcp.js +22 -4
  3. package/lib/client.d.ts +18 -1
  4. package/lib/client.js +628 -573
  5. package/lib/core/messages.d.ts +2 -0
  6. package/lib/core/messages.js +4 -0
  7. package/lib/core/patch-document.d.ts +65 -0
  8. package/lib/core/patch-document.js +161 -0
  9. package/lib/foreign/read-trae.d.ts +11 -0
  10. package/lib/foreign/read-trae.js +124 -4
  11. package/lib/foreign/session-source.d.ts +12 -4
  12. package/lib/foreign/session-source.js +5 -3
  13. package/lib/foreign/trae-sqlcipher.d.ts +127 -0
  14. package/lib/foreign/trae-sqlcipher.js +519 -0
  15. package/lib/foreign/trae.js +3 -1
  16. package/lib/foreign/truth-table.js +3 -2
  17. package/lib/foreign/types.d.ts +9 -1
  18. package/lib/index.d.ts +3 -1
  19. package/lib/index.js +35 -53
  20. package/lib/ui/foreign-view.d.ts +19 -0
  21. package/lib/ui/foreign-view.js +24 -0
  22. package/lib/ui/i18n.d.ts +5 -0
  23. package/lib/ui/i18n.js +13 -0
  24. package/package.json +1 -1
  25. package/src/adapters/mcp.test.ts +23 -3
  26. package/src/adapters/mcp.ts +24 -4
  27. package/src/client/import/ForeignImportView.tsx +25 -7
  28. package/src/client/import/foreign-import-view-guard.test.ts +1 -1
  29. package/src/client/locales/foreign.ts +9 -0
  30. package/src/core/messages.ts +4 -0
  31. package/src/core/patch-document.test.ts +107 -0
  32. package/src/core/patch-document.ts +194 -0
  33. package/src/foreign/file-budget.test.ts +7 -1
  34. package/src/foreign/read-trae.ts +117 -5
  35. package/src/foreign/session-source.ts +15 -5
  36. package/src/foreign/trae-sqlcipher.test.ts +360 -0
  37. package/src/foreign/trae-sqlcipher.ts +564 -0
  38. package/src/foreign/trae.test.ts +188 -0
  39. package/src/foreign/trae.ts +3 -1
  40. package/src/foreign/truth-table.ts +4 -2
  41. package/src/foreign/types.ts +10 -1
  42. package/src/index.facade.test.ts +83 -1
  43. package/src/index.ts +37 -47
  44. package/src/ui/foreign-view.test.ts +36 -0
  45. package/src/ui/foreign-view.ts +46 -0
  46. package/src/ui/i18n.ts +13 -0
  47. package/src/utils/patch-yaml.test.ts +1 -1
@@ -0,0 +1,194 @@
1
+ /**
2
+ * patch 文档的**结构重建**(issue #133)。
3
+ *
4
+ * 为什么需要独立一层:`cordis.patch.yml` 的两种形态语义**不等价**(宿主 dsh-app-boot 的
5
+ * readProfilePatches 合并循环):
6
+ * - 顶层 `- id: X` → 按 id **覆盖**已存在的条目;id 查不到时打 `patch: entry "X" not found` 丢弃;
7
+ * - `- insert:` 块成员 → **新增**条目(`data.push(...clone)`,唯一的新增路径)。
8
+ * 此前重建时把所有行(含 insert 成员)统一输出成顶层行,于是「只能靠 insert 新增」的条目
9
+ * (典型是 MCP server)在 DSH 侧全部失效 —— 一条 update 就够触发。
10
+ *
11
+ * 本模块只做**结构**:不读文件、不碰 YAML(core 层零依赖),输入是已解析的文档 + 变更清单,
12
+ * 输出是重建后的条目数组与两套 id。序列化与自检在宿主门面(DshPatchFileFacade)里做。
13
+ *
14
+ * 三条不变量:
15
+ * ① 原本是 insert 成员的 id,重建后仍在 insert 块里(update 不改变归属);
16
+ * ② 新增条目(`action:'insert'` 且文档里没有)落进 insert 块,而不是顶层行;
17
+ * ③ 任一 id 不得同时出现在顶层与 insert 两处 —— 计划阶段就抛错(防御性,正常路径不可达)。
18
+ */
19
+ export interface PatchLineChange {
20
+ lineId: string;
21
+ raw: unknown;
22
+ action: 'insert' | 'update' | 'remove';
23
+ }
24
+
25
+ export interface PatchDocumentPlan {
26
+ /** 重建后的文档条目(顺序尽量贴原文档:顶层行原位、insert 块原位、新增项追加在尾部) */
27
+ items: unknown[];
28
+ /** 落在 insert 块里的 id(按输出顺序) */
29
+ insertIds: string[];
30
+ /** 落在顶层行里的 id(按输出顺序) */
31
+ topLevelIds: string[];
32
+ }
33
+
34
+ /** 计划会把 insert 成员提升成顶层行:调用方必须放弃这次写入(零写入)。 */
35
+ export class PatchPromoteRefusedError extends Error {
36
+ readonly ids: string[];
37
+ constructor(ids: string[]) {
38
+ super('patch rebuild would promote insert members to top-level rows: ' + ids.join(', '));
39
+ this.name = 'PatchPromoteRefusedError';
40
+ this.ids = ids;
41
+ }
42
+ }
43
+
44
+ interface SlotState {
45
+ raw: unknown;
46
+ inInsert: boolean;
47
+ }
48
+
49
+ type Slot = { kind: 'row'; id: string } | { kind: 'block'; ids: string[] };
50
+
51
+ function entryId(value: unknown): string | null {
52
+ if (value === null || typeof value !== 'object') return null;
53
+ const id = (value as Record<string, unknown>)['id'];
54
+ return typeof id === 'string' && id !== '' ? id : null;
55
+ }
56
+
57
+ function blockMembers(value: unknown): Record<string, unknown>[] | null {
58
+ if (value === null || typeof value !== 'object') return null;
59
+ const insert = (value as Record<string, unknown>)['insert'];
60
+ if (!Array.isArray(insert)) return null;
61
+ return insert.filter((entry): entry is Record<string, unknown> => entry !== null && typeof entry === 'object');
62
+ }
63
+
64
+ /** 读出文档里的 insert 成员 id 与顶层行 id(自检与测试共用;不判重、保持文档顺序)。 */
65
+ export function describePatchDocument(doc: unknown): { insertIds: string[]; topLevelIds: string[] } {
66
+ const insertIds: string[] = [];
67
+ const topLevelIds: string[] = [];
68
+ if (!Array.isArray(doc)) return { insertIds, topLevelIds };
69
+ for (const item of doc) {
70
+ const members = blockMembers(item);
71
+ if (members !== null) {
72
+ for (const member of members) {
73
+ const id = entryId(member);
74
+ if (id !== null) insertIds.push(id);
75
+ }
76
+ continue;
77
+ }
78
+ const id = entryId(item);
79
+ if (id !== null) topLevelIds.push(id);
80
+ }
81
+ return { insertIds, topLevelIds };
82
+ }
83
+
84
+ /**
85
+ * 重建成 patch 文档条目。
86
+ *
87
+ * `doc` 是已解析的原文档(非数组视为空文档);顺序按原布局保留,新增项追加在尾部。
88
+ */
89
+ export function planPatchDocument(doc: unknown, changes: readonly PatchLineChange[]): PatchDocumentPlan {
90
+ const state = new Map<string, SlotState>();
91
+ const layout: Slot[] = [];
92
+
93
+ if (Array.isArray(doc)) {
94
+ for (const item of doc) {
95
+ const members = blockMembers(item);
96
+ if (members !== null) {
97
+ const ids: string[] = [];
98
+ for (const member of members) {
99
+ const id = entryId(member);
100
+ if (id === null) continue;
101
+ ids.push(id);
102
+ if (!state.has(id)) state.set(id, { raw: member, inInsert: true });
103
+ }
104
+ if (ids.length > 0) layout.push({ kind: 'block', ids });
105
+ continue;
106
+ }
107
+ const id = entryId(item);
108
+ if (id === null) continue;
109
+ layout.push({ kind: 'row', id });
110
+ if (!state.has(id)) state.set(id, { raw: item, inInsert: false });
111
+ }
112
+ }
113
+
114
+ for (const change of changes) {
115
+ if (change.action === 'remove') {
116
+ state.delete(change.lineId);
117
+ continue;
118
+ }
119
+ const previous = state.get(change.lineId);
120
+ // 归属只由**原文档**决定:更新一条既有 insert 成员不会把它搬到顶层;新增才按动作分流
121
+ const inInsert = previous !== undefined ? previous.inInsert : change.action === 'insert';
122
+ state.set(change.lineId, { raw: change.raw, inInsert });
123
+ }
124
+
125
+ const items: unknown[] = [];
126
+ const insertIds: string[] = [];
127
+ const topLevelIds: string[] = [];
128
+ const emitted = new Set<string>();
129
+
130
+ const emitRow = (id: string): void => {
131
+ const slot = state.get(id);
132
+ if (slot === undefined || emitted.has(id)) return;
133
+ emitted.add(id);
134
+ items.push(slot.raw);
135
+ topLevelIds.push(id);
136
+ };
137
+ const emitBlock = (ids: string[]): void => {
138
+ const members = ids.filter((id) => {
139
+ const slot = state.get(id);
140
+ return slot !== undefined && slot.inInsert && !emitted.has(id);
141
+ });
142
+ if (members.length === 0) return;
143
+ for (const id of members) emitted.add(id);
144
+ items.push({ insert: members.map((id) => state.get(id)!.raw) });
145
+ insertIds.push(...members);
146
+ };
147
+
148
+ for (const slot of layout) {
149
+ if (slot.kind === 'row') emitRow(slot.id);
150
+ else emitBlock(slot.ids);
151
+ }
152
+
153
+ // 新写入、且原文档布局里没有的 id:insert 动作进块,update 动作保持旧的 upsert 语义(顶层行)
154
+ for (const [id, slot] of state) {
155
+ if (emitted.has(id)) continue;
156
+ if (slot.inInsert) continue;
157
+ emitRow(id);
158
+ }
159
+ emitBlock([...state.keys()].filter((id) => !emitted.has(id)));
160
+
161
+ // 不变量③:同一 id 不得两种身份并存(正常路径不可达;坏了就拒写,别写出一份语义分裂的文件)
162
+ const promoted = insertIds.filter((id) => topLevelIds.includes(id));
163
+ if (promoted.length > 0) throw new PatchPromoteRefusedError(promoted);
164
+
165
+ return { items, insertIds, topLevelIds };
166
+ }
167
+ /**
168
+ * 计划布局与观察到的布局是否一致(写后自检用,issue #133)。
169
+ * 一致返回 `null`;不一致返回一句可直接进错误文案的差异说明(只含 id,不含值)。
170
+ */
171
+ export function describePatchLayoutDrift(
172
+ planned: { insertIds: readonly string[]; topLevelIds: readonly string[] },
173
+ observed: { insertIds: readonly string[]; topLevelIds: readonly string[] },
174
+ ): string | null {
175
+ const same = planned.insertIds.length === observed.insertIds.length
176
+ && planned.topLevelIds.length === observed.topLevelIds.length
177
+ && planned.insertIds.every((id, i) => id === observed.insertIds[i])
178
+ && planned.topLevelIds.every((id, i) => id === observed.topLevelIds[i]);
179
+ if (same) return null;
180
+ const fmt = (label: string, ids: readonly string[]): string => label + '=[' + ids.join(', ') + ']';
181
+ return 'planned ' + fmt('insert', planned.insertIds) + ' ' + fmt('top-level', planned.topLevelIds)
182
+ + '; got ' + fmt('insert', observed.insertIds) + ' ' + fmt('top-level', observed.topLevelIds);
183
+ }
184
+ /**
185
+ * 跨层提升检查(issue #133):`topLevelIds` 里哪些是**另一层文档**的 `- insert:` 成员。
186
+ *
187
+ * 命中就意味着「把新增改写成覆盖」——目标作用域里那条通常不存在,宿主会 `not found` 丢弃。
188
+ * `otherDoc` 读不到或解析不了时调用方传 `undefined`,本函数返回空(守卫只做加强)。
189
+ */
190
+ export function promotedTopLevelIds(otherDoc: unknown, topLevelIds: readonly string[]): string[] {
191
+ if (topLevelIds.length === 0) return [];
192
+ const insertMembers = new Set(describePatchDocument(otherDoc).insertIds);
193
+ return topLevelIds.filter((id) => insertMembers.has(id));
194
+ }
@@ -148,6 +148,8 @@ export const FOREIGN_FS_IMPORT_ALLOWLIST: readonly string[] = [
148
148
  'registry.ts',
149
149
  'session-read.ts',
150
150
  'sqlite.ts',
151
+ // #134:INode 加密库读取层要读写私有临时目录(明文库与逐页解密),故显式放行 node:fs/promises
152
+ 'trae-sqlcipher.ts',
151
153
  ];
152
154
 
153
155
  const FS_IMPORT_RE = /(?:^|\n)\s*import\s+(?:type\s+)?[^;\n]*?from\s+'node:fs(?:\/promises)?'/;
@@ -251,7 +253,11 @@ test('C 来源形状:共享模块清单是封闭集合(新模块必须显式
251
253
  /* 2026-10-18 新增:Claude Code 插件/市场读盘层(名字不含来源 id,故不是来源形状模块;
252
254
  它是 claude-code 专属读盘子模块,由 read-claude-code.ts 动态 import)。清单按字母序比较。 */
253
255
  'read-claude-plugins.ts', 'registry.ts', 'session-ir.ts', 'session-read.ts', 'session-source.ts',
254
- 'source-modules.ts', 'sqlite.ts', 'truth-table.ts', 'types.ts',
256
+ 'source-modules.ts', 'sqlite.ts',
257
+ /* #134 新增:Trae 2.3.x 的 SQLCipher 读盘/解密层(名字不含来源 id 之外的前缀,也不是来源装配;
258
+ 由 read-trae.ts 静态 import;只交中性行,语义映射仍留 read-trae)。 */
259
+ 'trae-sqlcipher.ts',
260
+ 'truth-table.ts', 'types.ts',
255
261
  ];
256
262
  assert.deepEqual(
257
263
  shared.sort(),
@@ -21,6 +21,11 @@
21
21
  * · 会话容器的字段级 schema **未取证**:本层用**结构自证**的窄口径(必须有「消息数组 + 至少一条
22
22
  * 带 role/type 的消息」)识别会话,容器必须自带字符串 id(否则铸稳定兜底 id);cwd 只认明文
23
23
  * 绝对路径字段,找不到就交给下游落 session-missing-cwd(**绝不猜 cwd**)。
24
+ *
25
+ * 2.3.x 起多了一条通道(issue #134):会话迁到 `<User>/ModularData/ai-agent/database.db`,
26
+ * **整库 SQLCipher 加密**。解密、临时明文、页头校验都在 trae-sqlcipher.ts(只交出中性行);
27
+ * 本文件只负责「读表结果 → 统一会话形态」的语义映射(role/正文/cwd 口径与旧通道**同一份代码**)。
28
+ * 两条通道按会话 id 去重、**先加密库后旧库**(迁移后的库才是权威),并存时只计一份。
24
29
  */
25
30
  import { isAbsoluteFor, joinFor, normalizePlatform, vscodeUserDataDir } from './platform-paths.ts';
26
31
  import type { ForeignPlatform } from './platform-paths.ts';
@@ -34,6 +39,7 @@ import { msTime } from './read-opencode.ts';
34
39
  import { isRecord } from '../utils/guards.ts';
35
40
  import type { IrBlock, IrTimeMs } from './session-ir.ts';
36
41
  import type { ForeignSkip } from './types.ts';
42
+ import { probeTraeEncryptedDatabase, readTraeEncryptedDatabase, traeDbPathFor, traeDbSkipOf } from './trae-sqlcipher.ts';
37
43
 
38
44
  /** 四个发行版名(顺序 = chat-import traeUserDataDirs 的判定顺序) */
39
45
  export const TRAE_PRODUCTS: readonly string[] = ['Trae', 'Trae CN', 'TRAE SOLO CN', 'TRAE SOLO'];
@@ -397,7 +403,7 @@ export async function traeVscdbPaths(userDir: string, platform: ForeignPlatform)
397
403
  * 而不是静默返回空 —— 那会与「未安装 Trae」混淆(t5 明文要求两者可区分)。
398
404
  */
399
405
  export async function readTrae(
400
- opts: RootProbeOptions & { readonly maxFiles?: number },
406
+ opts: RootProbeOptions & { readonly maxFiles?: number; readonly maxEncryptedDbBytes?: number },
401
407
  ): Promise<SessionReadOutcome<TraeSessionFile>> {
402
408
  const platform = normalizePlatform(opts.platform);
403
409
  const findings: ForeignSkip[] = [];
@@ -414,12 +420,62 @@ export async function readTrae(
414
420
  };
415
421
  }
416
422
 
423
+ const extraSkips: ForeignSkip[] = [];
424
+ let truncated = false;
425
+
426
+ // ① 加密库通道(2.3.x):先读 —— 迁移后的库才是权威,同 id 冲突以它为准
427
+ const encryptedDbs: string[] = [];
428
+ for (const userDir of traeUserDataDirs(opts)) {
429
+ const dbPath = traeDbPathFor(userDir, platform);
430
+ if (await isFile(dbPath)) encryptedDbs.push(dbPath);
431
+ }
432
+ let encryptedSessions = 0;
433
+ for (const dbPath of encryptedDbs) {
434
+ const outcome = await readTraeEncryptedDatabase(dbPath, {
435
+ env: opts.env,
436
+ platform,
437
+ ...(opts.maxEncryptedDbBytes !== undefined ? { maxBytes: opts.maxEncryptedDbBytes } : {}),
438
+ maxSessions: maxFiles,
439
+ });
440
+ // 密钥错/超限/截断/表结构不符 ⇒ 稳定码(绝不静默 0 会话);旧库有货时继续走旧库
441
+ if (outcome.problem !== undefined) {
442
+ extraSkips.push(traeDbSkipOf(outcome.problem));
443
+ continue;
444
+ }
445
+ if (outcome.dropped !== undefined && outcome.dropped > 0) {
446
+ findings.push({ code: 'source-unreadable', origin: 'trae', detail: 'encrypted-row-json-error', count: outcome.dropped });
447
+ }
448
+ if (outcome.skipped !== undefined && outcome.skipped > 0) {
449
+ findings.push({ code: 'source-unreadable', origin: 'trae', detail: 'encrypted-session-without-id', count: outcome.skipped });
450
+ }
451
+ if (outcome.truncated === true) truncated = true;
452
+ for (const session of outcome.sessions) {
453
+ if (files.length >= maxFiles) { truncated = true; break; }
454
+ const id = isSafeIrId(session.id) ? session.id : safeFragment('trae-db-' + session.id);
455
+ if (seen.has(id)) continue;
456
+ const ignored: Record<string, number> = {};
457
+ const parsed = recordsOf(session.items, ignored);
458
+ seen.add(id);
459
+ files.push({
460
+ id,
461
+ cwd: session.cwd,
462
+ createdAt: session.createdAt,
463
+ title: session.title ?? '',
464
+ records: parsed.records,
465
+ raw: parsed.raw,
466
+ bad: 0,
467
+ ignored,
468
+ });
469
+ encryptedSessions += 1;
470
+ }
471
+ }
472
+
473
+ // ② 旧 state.vscdb 通道(保留):同 id 已被加密库计入的不再重复
417
474
  const dbs: string[] = [];
418
475
  for (const userDir of traeUserDataDirs(opts)) {
419
476
  dbs.push(...await traeVscdbPaths(userDir, platform));
420
477
  }
421
478
  let candidateKeys = 0;
422
- let truncated = false;
423
479
  for (const dbPath of dbs) {
424
480
  if (files.length >= maxFiles) { truncated = true; break; }
425
481
  const db = await openSqliteIfShape(dbPath, { ItemTable: ['key'] });
@@ -469,8 +525,8 @@ export async function readTrae(
469
525
  db.close();
470
526
  if (truncated) break;
471
527
  }
472
- const extraSkips: ForeignSkip[] = [];
473
- if (files.length === 0 && candidateKeys === 0 && dbs.length > 0) {
528
+ // 加密库存在时,「旧库没有候选键」不是用户需要的解释(真因已由 trae-db-* 说明)
529
+ if (files.length === 0 && candidateKeys === 0 && dbs.length > 0 && encryptedDbs.length === 0) {
474
530
  extraSkips.push({ code: 'sessions-not-migrated', origin: 'trae', detail: 'chat-storage-key-not-found' });
475
531
  } else if (files.length === 0 && candidateKeys > 0) {
476
532
  extraSkips.push({ code: 'sessions-not-migrated', origin: 'trae', detail: 'no-session-container', count: candidateKeys });
@@ -483,6 +539,62 @@ export async function readTrae(
483
539
  files,
484
540
  readFindings: findings,
485
541
  extraSkips,
486
- extraCounts: { 'trae.vscdb': dbs.length, 'trae.chatStorageKeys': candidateKeys },
542
+ extraCounts: {
543
+ 'trae.vscdb': dbs.length,
544
+ 'trae.chatStorageKeys': candidateKeys,
545
+ 'trae.encryptedDb': encryptedDbs.length,
546
+ 'trae.encryptedSessions': encryptedSessions,
547
+ },
487
548
  };
488
549
  }
550
+
551
+ /**
552
+ * detect 期的**轻量预告**(issue #134 的第二半):让 `/foreign-sources` 在用户点导入前就把
553
+ * 「为什么这里没有会话」摆出来,而不是等 build 的 400 才闪一下。
554
+ *
555
+ * 代价(刻意接受):只读**页头**与 **ItemTable 的 key 列**,绝不读正文、绝不枚举会话 ——
556
+ * 4 个发行版的加密库最多各解密 1 页,旧库只是 `SELECT key`。因此 detect 仍是有界的只读探测。
557
+ */
558
+ export async function traeDetectSkips(
559
+ opts: RootProbeOptions & { readonly maxEncryptedDbBytes?: number },
560
+ ): Promise<ForeignSkip[]> {
561
+ const platform = normalizePlatform(opts.platform);
562
+ const skips: ForeignSkip[] = [];
563
+ let encryptedFound = 0;
564
+ for (const userDir of traeUserDataDirs(opts)) {
565
+ const dbPath = traeDbPathFor(userDir, platform);
566
+ if (!await isFile(dbPath)) continue;
567
+ encryptedFound += 1;
568
+ const problem = await probeTraeEncryptedDatabase(dbPath, {
569
+ env: opts.env,
570
+ ...(opts.maxEncryptedDbBytes !== undefined ? { maxBytes: opts.maxEncryptedDbBytes } : {}),
571
+ });
572
+ if (problem !== null) skips.push(traeDbSkipOf(problem));
573
+ }
574
+ // 加密库在场时不再猜旧库:迁移后旧库多半只是残留,混进「没有候选键」会误导用户
575
+ if (encryptedFound > 0) return skips;
576
+
577
+ const capability = await sqliteCapability();
578
+ if (!capability.available) return skips;
579
+ const dbs: string[] = [];
580
+ for (const userDir of traeUserDataDirs(opts)) {
581
+ dbs.push(...await traeVscdbPaths(userDir, platform));
582
+ }
583
+ if (dbs.length === 0) return skips;
584
+ let candidateKeys = 0;
585
+ for (const dbPath of dbs) {
586
+ const db = await openSqliteIfShape(dbPath, { ItemTable: ['key'] });
587
+ if (db === null) continue;
588
+ const rows = db.all('SELECT key FROM ItemTable');
589
+ db.close();
590
+ if (rows === null) continue;
591
+ for (const row of rows) {
592
+ const key = cellText(row, 'key');
593
+ if (key !== undefined && isTraeChatStorageKey(key)) candidateKeys += 1;
594
+ }
595
+ }
596
+ if (candidateKeys === 0) {
597
+ skips.push({ code: 'sessions-not-migrated', origin: 'trae', detail: 'chat-storage-key-not-found' });
598
+ }
599
+ return skips;
600
+ }
@@ -562,8 +562,16 @@ export interface SessionSourceWiring<TFile extends { id: string }> {
562
562
  readonly probePaths: (opts: RootProbeOptions) => readonly string[];
563
563
  /** 命中即报 source-location-overridden 的环境变量(只报键名,绝不报值) */
564
564
  readonly probeEnvKeys?: readonly string[] | undefined;
565
- /** 探测期的附加提示(如 chatgpt 的「无自动根」) */
566
- readonly probeSkips?: ((opts: RootProbeOptions, probed: readonly string[]) => readonly ForeignSkip[]) | undefined;
565
+ /**
566
+ * 探测期的附加提示(如 chatgpt 的「无自动根」)。
567
+ *
568
+ * 允许返回 Promise:少数来源需要**有界**地读一点内容才能给出可判定的预告(trae 的加密库
569
+ * 只解密第 1 页、旧库只读 key 列)。这类探测必须自证「有界、只读、不枚举会话」,
570
+ * 否则 detect 会被 30 个来源拖慢。
571
+ */
572
+ readonly probeSkips?:
573
+ | ((opts: RootProbeOptions, probed: readonly string[]) => readonly ForeignSkip[] | Promise<readonly ForeignSkip[]>)
574
+ | undefined;
567
575
  readonly read: (opts: SessionSourceHostOptions) => Promise<SessionReadOutcome<TFile>>;
568
576
  readonly draftOf: (file: TFile) => SessionDraft | { readonly skip: { readonly code: ForeignSkipCode; readonly detail?: string } };
569
577
  readonly workspaceIdPrefix?: string | undefined;
@@ -572,8 +580,10 @@ export interface SessionSourceWiring<TFile extends { id: string }> {
572
580
  /**
573
581
  * 把一个会话来源装配成 `ForeignSource`。
574
582
  *
575
- * **detect 只 stat 真值表里的位置**(绝不读内容、绝不枚举会话)—— 界面对 30 个来源各调一次
576
- * detect,任何一处读全文都会把面板拖慢;真正的枚举发生在 build。
583
+ * **detect 默认只 stat 真值表里的位置**(绝不读内容、绝不枚举会话)—— 界面对 30 个来源各调一次
584
+ * detect,任何一处读全文都会把面板拖慢;真正的枚举发生在 build。唯一例外是来源在 `probeSkips`
585
+ * 里显式声明的**有界轻量探测**(trae:加密库只解密第 1 页、旧库只读 key 列),因为它们要回答的
586
+ * 正是「为什么这里没有会话」,而这件事只有看内容才知道。
577
587
  *
578
588
  * platform 的兜底只在**这一处**:`ctx.platform ?? process.platform`(装配层碰运行平台是允许的,
579
589
  * 真值表函数本身一律显式收参)。
@@ -598,7 +608,7 @@ export function sessionSourceOf<TFile extends { id: string }>(
598
608
  for (const key of wiring.probeEnvKeys ?? []) {
599
609
  if (envValue(ctx.env, key) !== undefined) skipped.push({ code: 'source-location-overridden', origin: key });
600
610
  }
601
- skipped.push(...(wiring.probeSkips?.(opts, probed.paths) ?? []));
611
+ skipped.push(...((await wiring.probeSkips?.(opts, probed.paths)) ?? []));
602
612
  return { found: probed.paths.length > 0, paths: [...probed.paths], skipped };
603
613
  },
604
614
  async build(ctx) {