dsh-config-manager 0.8.1 → 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.
- package/lib/client.d.ts +18 -1
- package/lib/client.js +626 -571
- package/lib/foreign/read-trae.d.ts +11 -0
- package/lib/foreign/read-trae.js +124 -4
- package/lib/foreign/session-source.d.ts +12 -4
- package/lib/foreign/session-source.js +5 -3
- package/lib/foreign/trae-sqlcipher.d.ts +127 -0
- package/lib/foreign/trae-sqlcipher.js +519 -0
- package/lib/foreign/trae.js +3 -1
- package/lib/foreign/truth-table.js +3 -2
- package/lib/foreign/types.d.ts +9 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/ui/foreign-view.d.ts +19 -0
- package/lib/ui/foreign-view.js +24 -0
- package/lib/ui/i18n.d.ts +5 -0
- package/lib/ui/i18n.js +13 -0
- package/package.json +1 -1
- package/src/client/import/ForeignImportView.tsx +25 -7
- package/src/client/import/foreign-import-view-guard.test.ts +1 -1
- package/src/client/locales/foreign.ts +9 -0
- package/src/foreign/file-budget.test.ts +7 -1
- package/src/foreign/read-trae.ts +117 -5
- package/src/foreign/session-source.ts +15 -5
- package/src/foreign/trae-sqlcipher.test.ts +360 -0
- package/src/foreign/trae-sqlcipher.ts +564 -0
- package/src/foreign/trae.test.ts +188 -0
- package/src/foreign/trae.ts +3 -1
- package/src/foreign/truth-table.ts +4 -2
- package/src/foreign/types.ts +10 -1
- package/src/index.ts +1 -1
- package/src/ui/foreign-view.test.ts +36 -0
- package/src/ui/foreign-view.ts +46 -0
- package/src/ui/i18n.ts +13 -0
package/lib/ui/i18n.js
CHANGED
|
@@ -452,6 +452,13 @@ export const uiZh = {
|
|
|
452
452
|
'foreign.skip.legacy-rules-file': '旧式规则文件:DSH 无对等结构,只报告',
|
|
453
453
|
'foreign.skip.instructions-merged': '多份指令源被合并为一个全局指令文件',
|
|
454
454
|
'foreign.skip.instructions-override-selected': '命中更高优先级的指令文件(override),按它导入',
|
|
455
|
+
// ---------- 2026-11-12(#134):Trae 2.3.x 的加密会话库(SQLCipher)四条可判定失败 ----------
|
|
456
|
+
// 纪律同上:每条都要能被代码逐条证明 —— 只说「什么没搬 / 为什么 / 怎么办」,不承诺修好。
|
|
457
|
+
'foreign.importNothing': '没有可导入的内容:该来源在本机没有可转换的配置或会话',
|
|
458
|
+
'foreign.skip.trae-db-key-invalid': 'Trae 加密会话库的密钥对不上(换版或密钥被覆盖):页面头校验不通过,本次未读出任何会话',
|
|
459
|
+
'foreign.skip.trae-db-too-large': 'Trae 加密会话库超出本来源的体积上限:未解密,未读出任何会话(全局 1 GiB 上限未改动)',
|
|
460
|
+
'foreign.skip.trae-db-decrypt-failed': 'Trae 加密会话库无法解密:文件被截断、不是 SQLCipher 形态或读取失败,本次未读出任何会话',
|
|
461
|
+
'foreign.skip.trae-db-schema-mismatch': 'Trae 加密会话库解密成功但表结构不符(缺 chat_session / history_v2 或必需列):不猜字段,本次未读出任何会话',
|
|
455
462
|
// ---------- 2026-10-18:Claude Code 项目级配置 / 插件 / 权限 / 设置键的如实诊断(8 个新码)----------
|
|
456
463
|
// 纪律:每条都要能被代码逐条证明 —— 只说「什么没搬、为什么、本项是否可补」,
|
|
457
464
|
// 绝不写「已支持 / 完全兼容」这类无法被代码证明的话。
|
|
@@ -930,6 +937,12 @@ export const uiEn = {
|
|
|
930
937
|
'foreign.skip.legacy-rules-file': 'Legacy rules file: DSH has no equivalent, reported only',
|
|
931
938
|
'foreign.skip.instructions-merged': 'Several instruction sources were merged into one global instruction file',
|
|
932
939
|
'foreign.skip.instructions-override-selected': 'A higher-priority instruction file (override) was found and is the one imported',
|
|
940
|
+
// 2026-11-12 (#134): four decidable failures of the Trae 2.3.x encrypted session database (SQLCipher)
|
|
941
|
+
'foreign.importNothing': 'Nothing to import: this source has no convertible configuration or sessions on this machine',
|
|
942
|
+
'foreign.skip.trae-db-key-invalid': 'The Trae encrypted session database key does not match (version change or an overridden key): the page-header checks failed, so no session was read',
|
|
943
|
+
'foreign.skip.trae-db-too-large': 'The Trae encrypted session database exceeds this source size limit: it was not decrypted, so no session was read (the global 1 GiB limit is unchanged)',
|
|
944
|
+
'foreign.skip.trae-db-decrypt-failed': 'The Trae encrypted session database cannot be decrypted: the file is truncated, not in SQLCipher form, or unreadable, so no session was read',
|
|
945
|
+
'foreign.skip.trae-db-schema-mismatch': 'The Trae encrypted session database decrypted but its schema does not match (chat_session / history_v2 or a required column is missing): fields are never guessed, so no session was read',
|
|
933
946
|
// 2026-10-18: honest diagnostics for Claude Code project-level config / plugins / permissions / settings keys (8 new codes)
|
|
934
947
|
'foreign.skip.unsupported-permissions': 'Permission rules (allow/ask/deny) were not migrated: DSH has no equivalent permission-rule file, so they are not in this bundle and will not take effect after import',
|
|
935
948
|
'foreign.skip.unsupported-settings-keys': 'Other unmigrated top-level keys in settings.json: only key names and counts are recorded; values are never read and never enter this bundle',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-config-manager",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Backup, restore, export, import, migrate and sync your DeepSeek Harness (DSH) configuration: settings, plugins, MCP servers, skills, agent presets and workspaces. One-click migration to another machine. DSH 配置一键备份、恢复、导出、导入、迁移与同步插件。",
|
|
6
6
|
"icon": "./icon.svg",
|
|
@@ -28,7 +28,14 @@ import { useEffect, useState } from 'react'
|
|
|
28
28
|
import type { TranslateNS } from '../client-types.ts'
|
|
29
29
|
import type { ConfigManagerApi, ForeignImportResponse } from '../api.ts'
|
|
30
30
|
import type { UiT } from '../../ui/i18n.ts'
|
|
31
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
foreignImportFailure,
|
|
33
|
+
foreignLossyRows,
|
|
34
|
+
foreignPathsText,
|
|
35
|
+
foreignSourcesViewModel,
|
|
36
|
+
type ForeignImportFailure,
|
|
37
|
+
type ForeignSourceRow,
|
|
38
|
+
} from '../../ui/foreign-view.ts'
|
|
32
39
|
import { Badge, Banner, Button, Card, SectionTitle } from '../common/ui.tsx'
|
|
33
40
|
import { SkeletonList } from '../common/Skeleton.tsx'
|
|
34
41
|
import { InfoHint } from '../common/InfoHint.tsx'
|
|
@@ -106,7 +113,13 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
|
|
|
106
113
|
const [loadError, setLoadError] = useState<string | null>(null)
|
|
107
114
|
const [selected, setSelected] = useState<string | null>(null)
|
|
108
115
|
const [importing, setImporting] = useState(false)
|
|
109
|
-
|
|
116
|
+
/**
|
|
117
|
+
* 上一次导入失败(#134):**带机器码**而不是一句 message。
|
|
118
|
+
*
|
|
119
|
+
* 宿主的 400 会带 `code`,字典里早有对应文案(`sessions-not-migrated` 等)——
|
|
120
|
+
* 只显示 err.message 会让用户永远看不到「为什么这里没有会话」。
|
|
121
|
+
*/
|
|
122
|
+
const [importFailure, setImportFailure] = useState<ForeignImportFailure | null>(null)
|
|
110
123
|
/** 最近一次产包结果的跳过项与凭据引用(产包成功后仍显示,供用户在进向导前先看到) */
|
|
111
124
|
const [produced, setProduced] = useState<ForeignImportResponse | null>(null)
|
|
112
125
|
/** F-3:上一次的产包结果因输入变化被作废 —— 重置必须在 UI 上有反馈(绝不静默) */
|
|
@@ -148,7 +161,7 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
|
|
|
148
161
|
const resetProduced = (): void => {
|
|
149
162
|
if (produced !== null) setPreviewReset(true)
|
|
150
163
|
setProduced(null)
|
|
151
|
-
|
|
164
|
+
setImportFailure(null)
|
|
152
165
|
}
|
|
153
166
|
|
|
154
167
|
/** 切换来源:同一个来源重复点击不算输入变化(不重置,免得谎报「已作废」)。 */
|
|
@@ -168,7 +181,7 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
|
|
|
168
181
|
const runImport = async (): Promise<void> => {
|
|
169
182
|
if (selected === null) return
|
|
170
183
|
setImporting(true)
|
|
171
|
-
|
|
184
|
+
setImportFailure(null)
|
|
172
185
|
setProduced(null)
|
|
173
186
|
setPreviewReset(false)
|
|
174
187
|
try {
|
|
@@ -177,7 +190,8 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
|
|
|
177
190
|
// 交给上层 → 写进 runStore.library.pendingZip → 导入面板消费(复用既有通道)
|
|
178
191
|
onReady(result)
|
|
179
192
|
} catch (err) {
|
|
180
|
-
|
|
193
|
+
// 码 → 字典文案(同一本 UiT 字典);翻不出才回落后端 message(绝不吞掉原因)
|
|
194
|
+
setImportFailure(foreignImportFailure(err, uiT))
|
|
181
195
|
} finally {
|
|
182
196
|
setImporting(false)
|
|
183
197
|
}
|
|
@@ -301,8 +315,12 @@ export function ForeignImportView({ api, t, uiT, onReady }: ForeignImportViewPro
|
|
|
301
315
|
</Card>
|
|
302
316
|
)}
|
|
303
317
|
|
|
304
|
-
{
|
|
305
|
-
<Banner kind="error">
|
|
318
|
+
{importFailure !== null && (
|
|
319
|
+
<Banner kind="error">
|
|
320
|
+
{t('foreign.importFailed', { reason: redact(importFailure.text) })}
|
|
321
|
+
{/* 稳定码保留给排查/上报:文案是人话,码是可搜索的锚点(未知码时它就是唯一信息) */}
|
|
322
|
+
{importFailure.code !== null && <span className={css.skipCode}>{importFailure.code}</span>}
|
|
323
|
+
</Banner>
|
|
306
324
|
)}
|
|
307
325
|
|
|
308
326
|
<div className={css.actionRow}>
|
|
@@ -94,7 +94,7 @@ function renderBlocksOf(source: string): { at: number; text: string }[] {
|
|
|
94
94
|
test('F-3:切换来源/重新检测都必须走 resetProduced(清产包结果 + 清失败横幅 + 有可见反馈)', () => {
|
|
95
95
|
const reset = windowOf('const resetProduced = (): void => {', '\n }')
|
|
96
96
|
assert.match(reset, /setProduced\(null\)/, '必须清掉上一次的产包结果')
|
|
97
|
-
assert.match(reset, /
|
|
97
|
+
assert.match(reset, /setImportFailure\(null\)/, '上一次的失败横幅也属于上一次输入,必须一并清掉')
|
|
98
98
|
assert.match(reset, /setPreviewReset\(true\)/, '重置必须留下可见反馈(绝不静默作废)')
|
|
99
99
|
|
|
100
100
|
// 来源行的 onSelect 不得直连 setSelected(那正是 F-3 的原始缺陷形态)
|
|
@@ -95,6 +95,11 @@ export const zh = {
|
|
|
95
95
|
'foreign.skip.legacy-rules-file': '旧式规则文件:DSH 无对等结构,只报告',
|
|
96
96
|
'foreign.skip.instructions-merged': '多份指令源被合并为一个全局指令文件',
|
|
97
97
|
'foreign.skip.instructions-override-selected': '命中更高优先级的指令文件(override),按它导入',
|
|
98
|
+
// 2026-11-12(#134):Trae 2.3.x 加密会话库(SQLCipher)的可判定失败
|
|
99
|
+
'foreign.skip.trae-db-key-invalid': 'Trae 加密会话库的密钥对不上(换版或密钥被覆盖):页面头校验不通过,本次未读出任何会话',
|
|
100
|
+
'foreign.skip.trae-db-too-large': 'Trae 加密会话库超出本来源的体积上限:未解密,未读出任何会话(全局 1 GiB 上限未改动)',
|
|
101
|
+
'foreign.skip.trae-db-decrypt-failed': 'Trae 加密会话库无法解密:文件被截断、不是 SQLCipher 形态或读取失败,本次未读出任何会话',
|
|
102
|
+
'foreign.skip.trae-db-schema-mismatch': 'Trae 加密会话库解密成功但表结构不符(缺 chat_session / history_v2 或必需列):不猜字段,本次未读出任何会话',
|
|
98
103
|
// 冲突语义(用户决策:同 id 不覆盖、跳过并报码)
|
|
99
104
|
'foreign.conflict.policy': '同 id 冲突不覆盖本机内容:跳过并逐条报告',
|
|
100
105
|
} as const;
|
|
@@ -180,5 +185,9 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
180
185
|
'foreign.skip.legacy-rules-file': 'Legacy rules file: DSH has no equivalent, reported only',
|
|
181
186
|
'foreign.skip.instructions-merged': 'Several instruction sources were merged into one global instruction file',
|
|
182
187
|
'foreign.skip.instructions-override-selected': 'A higher-priority instruction file (override) was found and is the one imported',
|
|
188
|
+
'foreign.skip.trae-db-key-invalid': 'The Trae encrypted session database key does not match (version change or an overridden key): the page-header checks failed, so no session was read',
|
|
189
|
+
'foreign.skip.trae-db-too-large': 'The Trae encrypted session database exceeds this source size limit: it was not decrypted, so no session was read (the global 1 GiB limit is unchanged)',
|
|
190
|
+
'foreign.skip.trae-db-decrypt-failed': 'The Trae encrypted session database cannot be decrypted: the file is truncated, not in SQLCipher form, or unreadable, so no session was read',
|
|
191
|
+
'foreign.skip.trae-db-schema-mismatch': 'The Trae encrypted session database decrypted but its schema does not match (chat_session / history_v2 or a required column is missing): fields are never guessed, so no session was read',
|
|
183
192
|
'foreign.conflict.policy': 'Same-id conflicts never overwrite local content: skipped and listed in the report',
|
|
184
193
|
};
|
|
@@ -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',
|
|
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(),
|
package/src/foreign/read-trae.ts
CHANGED
|
@@ -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
|
-
|
|
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: {
|
|
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
|
-
/**
|
|
566
|
-
|
|
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
|
|
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) {
|