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
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trae 2.3.x 的**加密会话库**通道(SQLCipher 4.x 页面布局)—— issue #134。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要它:Trae 系四个发行版(Trae / Trae CN / TRAE SOLO CN / TRAE SOLO)从 2.3 起把会话从
|
|
5
|
+
* `<User>/globalStorage/state.vscdb` 迁到 `<User>/ModularData/ai-agent/database.db`,**整库
|
|
6
|
+
* SQLCipher 加密**(真机量级约 1.4 GB)。旧通道(read-trae.ts 的 ItemTable)在新版上恒为空 ⇒
|
|
7
|
+
* 用户只看到「nothing to import」,没有任何解释。本模块负责「识别加密库 → 逐页解密出明文库 →
|
|
8
|
+
* 只读读表 → 交出**中性**会话行」;ID/角色/正文的语义映射仍留在 read-trae.ts(口径一处不改)。
|
|
9
|
+
*
|
|
10
|
+
* 页面布局(SQLCipher 4.x,page 4096,每页尾 reserve 80 B = IV(16) + HMAC-SHA512(64)):
|
|
11
|
+
* 第 1 页 [salt 16][cipher 4000][IV 16][HMAC 64] ← 前 16 B 是 salt,不是密文
|
|
12
|
+
* 其余页 [cipher 4016][IV 16][HMAC 64]
|
|
13
|
+
* 解密用 `aes-256-cbc` + `setAutoPadding(false)`(CBC 每块独立,页内无需分组边界对齐);
|
|
14
|
+
* 明文每页可用 4016 B = 4096 − 80,第 1 页明文 `[0,16)` 必须改写成 SQLite 头
|
|
15
|
+
* `SQLite format 3\0`,否则 `node:sqlite` 直接拒开(它只认明文头)。
|
|
16
|
+
*
|
|
17
|
+
* 密钥:raw AES-256(**不是**口令 ⇒ 不做 PBKDF2)。缺省值取参考实现
|
|
18
|
+
* xitula/trae-session-export 公开的常量;环境变量 `DCM_TRAE_DB_KEY`(64 位十六进制)可覆盖。
|
|
19
|
+
* 密钥错/换版必须**可判定**:不校验 HMAC(参考实现同样不校验),而是解密第 1 页后校验明文页头
|
|
20
|
+
* (页大小 / payload 分数 / 保留字节 / 声明页数)—— 错密钥撞过全部判据的概率在 2^-32 量级,
|
|
21
|
+
* 一旦不符即报 `trae-db-key-invalid`,**绝不静默 0 会话**。
|
|
22
|
+
*
|
|
23
|
+
* 三点刻意的取舍(都在 #134 的汇报里写明):
|
|
24
|
+
* ① **不额外复制原库**:按页流式解密、直接写出明文库(原库全程只读)。1.4 GB 复制会让磁盘
|
|
25
|
+
* 峰值翻倍,而解密本身已经是逐页 O(1) 内存。
|
|
26
|
+
* ② 明文只活在本次导入的私有临时目录(`os.tmpdir()/dcm-trae-db-*`),读完即 `rm -rf`;
|
|
27
|
+
* 不落用户可见目录、不进快照、不进日志(本模块**不写日志**,错误只带稳定码与 detail)。
|
|
28
|
+
* ③ 体积上限**按来源独立**(`TRAE_DB_MAX_BYTES`),**不动** sqlite.ts 的全局
|
|
29
|
+
* `DEFAULT_MAX_COPY_BYTES`(1 GiB):那是所有来源共用的兜底,改它会连带放宽别处。
|
|
30
|
+
*
|
|
31
|
+
* 诚实边界:
|
|
32
|
+
* · 表/列名只有 `chat_session` / `history_v2` / `history_v2.messages.raw_messages[]` 有调研
|
|
33
|
+
* 证据;其余元数据列(会话 id 的关联列、cwd、标题、时间)**没有真机样本** ⇒ 一律按候选列名
|
|
34
|
+
* 逐个自证,命中才用,找不到就交给下游落 `session-missing-cwd`(绝不猜语义)。
|
|
35
|
+
* · 加密库的 `-wal` 分帧同样是密文且带独立 salt,本版**不合并 WAL**:实时复制可能漏掉最新
|
|
36
|
+
* 尾部,读不到目标表按 `trae-db-schema-mismatch` 可判定失败,绝不假装读到。
|
|
37
|
+
*/
|
|
38
|
+
import { createDecipheriv } from 'node:crypto';
|
|
39
|
+
import fs from 'node:fs/promises';
|
|
40
|
+
import os from 'node:os';
|
|
41
|
+
import path from 'node:path';
|
|
42
|
+
import { isAbsoluteFor, joinFor } from './platform-paths.js';
|
|
43
|
+
import { statOrNull } from './session-read.js';
|
|
44
|
+
import { cellBytes, cellText, cellTime, openSqliteReadOnlyEx } from './sqlite.js';
|
|
45
|
+
import { isRecord } from '../utils/guards.js';
|
|
46
|
+
/** 加密库相对 `<User>` 的路径段(4 个发行版共用同一命名) */
|
|
47
|
+
export const TRAE_DB_REL_SEGMENTS = ['ModularData', 'ai-agent', 'database.db'];
|
|
48
|
+
/** SQLCipher 4.x 的页大小(该库固定 4096) */
|
|
49
|
+
export const TRAE_DB_PAGE_SIZE = 4096;
|
|
50
|
+
/** 每页尾保留字节:IV(16) + HMAC-SHA512(64) */
|
|
51
|
+
export const TRAE_DB_RESERVE_BYTES = 80;
|
|
52
|
+
/** IV 长度(AES 块大小) */
|
|
53
|
+
export const TRAE_DB_IV_BYTES = 16;
|
|
54
|
+
/** 第 1 页开头的 salt 长度(不是密文,也不参与解密) */
|
|
55
|
+
export const TRAE_DB_SALT_BYTES = 16;
|
|
56
|
+
/** raw AES-256 密钥长度 */
|
|
57
|
+
export const TRAE_DB_KEY_BYTES = 32;
|
|
58
|
+
/**
|
|
59
|
+
* 缺省密钥:参考实现 xitula/trae-session-export 公开的 raw key 常量。
|
|
60
|
+
*
|
|
61
|
+
* **为什么可以内置**:它是产品级的固定 key(不是用户口令),参考实现公开分发;本插件只读、
|
|
62
|
+
* 且不写回任何 Trae 数据。换版后 key 变化 ⇒ 页头校验失败 ⇒ `trae-db-key-invalid`(可判定)。
|
|
63
|
+
*/
|
|
64
|
+
export const TRAE_DB_DEFAULT_KEY = '3605f6691095a993f03d5009c918352ef5be31ae31e8f000212b81ff058da773';
|
|
65
|
+
/** 覆盖密钥的环境变量名(只报键名,绝不回显值) */
|
|
66
|
+
export const TRAE_DB_KEY_ENV = 'DCM_TRAE_DB_KEY';
|
|
67
|
+
/**
|
|
68
|
+
* 加密库的体积上限(**按来源独立**,2 GiB 覆盖 1.4 GB 量级;超限走既有 copy-too-large 语义)。
|
|
69
|
+
* 刻意不碰 sqlite.ts 的 `DEFAULT_MAX_COPY_BYTES`(1 GiB,全局兜底)。
|
|
70
|
+
*/
|
|
71
|
+
export const TRAE_DB_MAX_BYTES = 2 * 1024 * 1024 * 1024;
|
|
72
|
+
/** 会话表(调研确证) */
|
|
73
|
+
export const TRAE_DB_TABLE_SESSION = 'chat_session';
|
|
74
|
+
/** 正文表(调研确证:消息在 `messages` 的 `raw_messages[]`) */
|
|
75
|
+
export const TRAE_DB_TABLE_HISTORY = 'history_v2';
|
|
76
|
+
/** 表结构**最小**签名:只钉确证过的表与列,其余列按候选自证 */
|
|
77
|
+
export const TRAE_DB_REQUIRED_SCHEMA = {
|
|
78
|
+
[TRAE_DB_TABLE_SESSION]: ['id'],
|
|
79
|
+
[TRAE_DB_TABLE_HISTORY]: ['messages'],
|
|
80
|
+
};
|
|
81
|
+
/** 会话上限(与 read-trae 的 MAX_SESSIONS 同量级;由调用方再收窄) */
|
|
82
|
+
export const TRAE_DB_MAX_SESSIONS = 5000;
|
|
83
|
+
/** 真机样本缺失:会话→正文的关联列候选(命中即用) */
|
|
84
|
+
const SESSION_JOIN_COLUMNS = [
|
|
85
|
+
'session_id', 'sessionId', 'chat_session_id', 'chatSessionId', 'conversation_id', 'conversationId',
|
|
86
|
+
];
|
|
87
|
+
/** cwd 候选(与 read-trae 的 CWD_KEYS 同口径:只认语义明确的键,且必须是绝对路径) */
|
|
88
|
+
const SESSION_CWD_COLUMNS = ['cwd', 'workspace', 'workspace_path', 'workspacePath', 'root_path', 'project_path'];
|
|
89
|
+
/** 标题候选 */
|
|
90
|
+
const SESSION_TITLE_COLUMNS = ['title', 'name', 'session_name', 'sessionName'];
|
|
91
|
+
/** 时间候选 */
|
|
92
|
+
const SESSION_TIME_COLUMNS = ['created_at', 'createdAt', 'create_time', 'createTime', 'updated_at', 'updatedAt', 'update_time'];
|
|
93
|
+
/** 正文容器的候选键(`raw_messages` 是调研确证的第一顺位) */
|
|
94
|
+
const MESSAGE_ARRAY_KEYS = ['raw_messages', 'rawMessages', 'messages'];
|
|
95
|
+
/** 明文库头的魔数(16 字节 ASCII,含结尾 NUL) */
|
|
96
|
+
const SQLITE_MAGIC = 'SQLite format 3';
|
|
97
|
+
/** 页大小字段的「1 表示 65536」约定 */
|
|
98
|
+
const PAGE_SIZE_ESCAPE = 1;
|
|
99
|
+
/** 明文页里 payload 分数三连(max / min / leaf),SQLite 恒定 64 / 32 / 32 */
|
|
100
|
+
const PAYLOAD_FRACTION_MAX = 64;
|
|
101
|
+
const PAYLOAD_FRACTION_MIN = 32;
|
|
102
|
+
const PAYLOAD_FRACTION_LEAF = 32;
|
|
103
|
+
/** 一个 `<User>` 根下的加密库位置(**绝不硬编码分隔符**) */
|
|
104
|
+
export function traeDbPathFor(userDir, platform) {
|
|
105
|
+
return joinFor(platform, userDir, ...TRAE_DB_REL_SEGMENTS);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* 解析密钥:环境变量优先,缺省内置常量。
|
|
109
|
+
*
|
|
110
|
+
* 环境变量**设了但不合法**时直接报 `trae-db-key-invalid`(detail=key-format),
|
|
111
|
+
* 绝不悄悄回落到内置 key —— 那会让「我换了密钥但没生效」变成静默 0 会话。
|
|
112
|
+
*/
|
|
113
|
+
export function resolveTraeDbKey(env) {
|
|
114
|
+
const raw = env[TRAE_DB_KEY_ENV];
|
|
115
|
+
const trimmed = typeof raw === 'string' ? raw.trim() : '';
|
|
116
|
+
if (trimmed === '')
|
|
117
|
+
return { key: Buffer.from(TRAE_DB_DEFAULT_KEY, 'hex'), source: 'default' };
|
|
118
|
+
if (!/^[0-9a-fA-F]{64}$/.test(trimmed)) {
|
|
119
|
+
return { problem: { code: 'trae-db-key-invalid', detail: 'key-format' } };
|
|
120
|
+
}
|
|
121
|
+
return { key: Buffer.from(trimmed, 'hex'), source: 'env' };
|
|
122
|
+
}
|
|
123
|
+
/** 一个页的密文区间(第 1 页跳过 salt;其余页从头开始) */
|
|
124
|
+
function cipherRange(index) {
|
|
125
|
+
return { start: index === 0 ? TRAE_DB_SALT_BYTES : 0, end: TRAE_DB_PAGE_SIZE - TRAE_DB_RESERVE_BYTES };
|
|
126
|
+
}
|
|
127
|
+
/** 页尾 IV 的区间(两种页都一样:倒数 80 B 的前 16 B) */
|
|
128
|
+
function ivRange() {
|
|
129
|
+
const start = TRAE_DB_PAGE_SIZE - TRAE_DB_RESERVE_BYTES;
|
|
130
|
+
return { start, end: start + TRAE_DB_IV_BYTES };
|
|
131
|
+
}
|
|
132
|
+
/** 一页的 CBC 解密(关闭填充;异常一律 null —— 调用方转成稳定码,绝不抛出) */
|
|
133
|
+
function decryptBlock(key, iv, block) {
|
|
134
|
+
if (block.length === 0 || block.length % TRAE_DB_IV_BYTES !== 0)
|
|
135
|
+
return null;
|
|
136
|
+
try {
|
|
137
|
+
const decipher = createDecipheriv('aes-256-cbc', key, iv);
|
|
138
|
+
decipher.setAutoPadding(false);
|
|
139
|
+
return Buffer.concat([decipher.update(block), decipher.final()]);
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 校验解密出的第 1 页明文(`plain` = 明文页的 `[16, 4016)`,即文件 offset 16 起的 4000 B)。
|
|
147
|
+
*
|
|
148
|
+
* 返回 null = 通过;返回字符串 = 可判定的失败 detail(一律映射成 `trae-db-key-invalid`)。
|
|
149
|
+
*/
|
|
150
|
+
export function validateTraePageOne(plain, pages) {
|
|
151
|
+
if (plain.length < 16)
|
|
152
|
+
return 'short-first-page';
|
|
153
|
+
const rawPageSize = plain.readUInt16BE(0);
|
|
154
|
+
const pageSize = rawPageSize === PAGE_SIZE_ESCAPE ? 65536 : rawPageSize;
|
|
155
|
+
if (pageSize !== TRAE_DB_PAGE_SIZE)
|
|
156
|
+
return 'page-size-mismatch';
|
|
157
|
+
// 保留字节写在 SQLite 头的 offset 20(明文里的 [4]):SQLCipher 4 为 80;0 也接受(个别库不写)
|
|
158
|
+
const reserve = plain[4] ?? 0;
|
|
159
|
+
if (reserve !== 0 && reserve !== TRAE_DB_RESERVE_BYTES)
|
|
160
|
+
return 'reserve-mismatch';
|
|
161
|
+
if (plain[5] !== PAYLOAD_FRACTION_MAX || plain[6] !== PAYLOAD_FRACTION_MIN || plain[7] !== PAYLOAD_FRACTION_LEAF) {
|
|
162
|
+
return 'payload-fraction-mismatch';
|
|
163
|
+
}
|
|
164
|
+
if (pages !== null) {
|
|
165
|
+
const declared = plain.readUInt32BE(12);
|
|
166
|
+
if (declared !== 0 && declared !== pages)
|
|
167
|
+
return 'page-count-mismatch';
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
/** 读满一页(short read 一律 null,调用方按截断处理) */
|
|
172
|
+
async function readExact(handle, buf, position) {
|
|
173
|
+
let offset = 0;
|
|
174
|
+
while (offset < buf.length) {
|
|
175
|
+
const { bytesRead } = await handle.read(buf, offset, buf.length - offset, position + offset);
|
|
176
|
+
if (bytesRead <= 0)
|
|
177
|
+
return false;
|
|
178
|
+
offset += bytesRead;
|
|
179
|
+
}
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
/** 读文件开头(用于明文魔数探测与单页探测) */
|
|
183
|
+
async function readHead(file, length) {
|
|
184
|
+
let handle = null;
|
|
185
|
+
try {
|
|
186
|
+
handle = await fs.open(file, 'r');
|
|
187
|
+
const buf = Buffer.alloc(length);
|
|
188
|
+
const ok = await readExact(handle, buf, 0);
|
|
189
|
+
return ok ? buf : null;
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
if (handle !== null)
|
|
196
|
+
await handle.close().catch(() => undefined);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/** 库本身是否已经是明文 SQLite(旧版 / 已被第三方解密的形态) */
|
|
200
|
+
async function isPlaintextSqlite(file) {
|
|
201
|
+
const head = await readHead(file, 16);
|
|
202
|
+
return head !== null && head.length === 16 && head.toString('latin1').startsWith(SQLITE_MAGIC);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* 把一个加密库逐页解密成明文库(**覆盖写 `destPath`**,目标不存在才写)。
|
|
206
|
+
*
|
|
207
|
+
* 只读源库;内存占用恒为一页;失败时返回稳定码,**不留半截明文**(由调用方的临时目录统一清理)。
|
|
208
|
+
*/
|
|
209
|
+
export async function decryptTraeDatabase(sourcePath, destPath, key) {
|
|
210
|
+
const stat = await statOrNull(sourcePath);
|
|
211
|
+
if (stat === null || !stat.isFile()) {
|
|
212
|
+
return { ok: false, problem: { code: 'trae-db-decrypt-failed', detail: 'unreadable' } };
|
|
213
|
+
}
|
|
214
|
+
if (stat.size === 0)
|
|
215
|
+
return { ok: false, problem: { code: 'trae-db-decrypt-failed', detail: 'empty-file' } };
|
|
216
|
+
// 对齐检查优先于解密:截断的库按「可判定失败」处理,不拿补 0 的明文去骗 node:sqlite
|
|
217
|
+
if (stat.size % TRAE_DB_PAGE_SIZE !== 0) {
|
|
218
|
+
return { ok: false, problem: { code: 'trae-db-decrypt-failed', detail: 'truncated-database', count: stat.size } };
|
|
219
|
+
}
|
|
220
|
+
const pages = stat.size / TRAE_DB_PAGE_SIZE;
|
|
221
|
+
const reserve = Buffer.alloc(TRAE_DB_RESERVE_BYTES); // 明文页尾不再承载 IV/HMAC ⇒ 全 0
|
|
222
|
+
const page = Buffer.alloc(TRAE_DB_PAGE_SIZE);
|
|
223
|
+
let source = null;
|
|
224
|
+
let dest = null;
|
|
225
|
+
try {
|
|
226
|
+
source = await fs.open(sourcePath, 'r');
|
|
227
|
+
dest = await fs.open(destPath, 'wx');
|
|
228
|
+
let firstPlain = null;
|
|
229
|
+
for (let index = 0; index < pages; index += 1) {
|
|
230
|
+
if (!await readExact(source, page, index * TRAE_DB_PAGE_SIZE)) {
|
|
231
|
+
return { ok: false, problem: { code: 'trae-db-decrypt-failed', detail: 'short-read', count: index } };
|
|
232
|
+
}
|
|
233
|
+
const iv = ivRange();
|
|
234
|
+
const range = cipherRange(index);
|
|
235
|
+
const plain = decryptBlock(key, page.subarray(iv.start, iv.end), page.subarray(range.start, range.end));
|
|
236
|
+
if (plain === null) {
|
|
237
|
+
return { ok: false, problem: { code: 'trae-db-decrypt-failed', detail: 'cipher-rejected', count: index } };
|
|
238
|
+
}
|
|
239
|
+
if (index === 0) {
|
|
240
|
+
firstPlain = plain;
|
|
241
|
+
// 明文页 [0,16) 必须是 SQLite 头(salt 已被丢弃),否则 node:sqlite 拒开
|
|
242
|
+
const first = Buffer.concat([Buffer.from(SQLITE_MAGIC + '\0', 'latin1'), plain]);
|
|
243
|
+
// 我们每页恒留 80 B 保留区 ⇒ 头里的「每页保留字节数」必须声明 80(真实 SQLCipher 明文本就是 80;
|
|
244
|
+
// 个别库不写这个字段,若不归一化,node:sqlite 会把页尾 80 B 当成有效内容而判库损坏)
|
|
245
|
+
first[20] = TRAE_DB_RESERVE_BYTES;
|
|
246
|
+
await dest.write(first);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
await dest.write(plain);
|
|
250
|
+
}
|
|
251
|
+
await dest.write(reserve);
|
|
252
|
+
}
|
|
253
|
+
const mismatch = firstPlain === null ? 'missing-first-page' : validateTraePageOne(firstPlain, pages);
|
|
254
|
+
if (mismatch !== null) {
|
|
255
|
+
return { ok: false, problem: { code: 'trae-db-key-invalid', detail: mismatch } };
|
|
256
|
+
}
|
|
257
|
+
return { ok: true, pages };
|
|
258
|
+
}
|
|
259
|
+
catch (err) {
|
|
260
|
+
return {
|
|
261
|
+
ok: false,
|
|
262
|
+
problem: { code: 'trae-db-decrypt-failed', detail: err instanceof Error ? 'io-error' : 'io-error' },
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
finally {
|
|
266
|
+
if (dest !== null)
|
|
267
|
+
await dest.close().catch(() => undefined);
|
|
268
|
+
if (source !== null)
|
|
269
|
+
await source.close().catch(() => undefined);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* 探测期的**单页**校验(detect 用):只解密第 1 页、只读 4 KB,用来抢在 build 之前把
|
|
274
|
+
* 「密钥错 / 截断 / 超限」这三类可判定失败摆到界面上(#134 的第二半)。
|
|
275
|
+
*
|
|
276
|
+
* 返回 null = 没发现问题(或库不存在 / 已是明文)。
|
|
277
|
+
*/
|
|
278
|
+
export async function probeTraeEncryptedDatabase(sourcePath, options) {
|
|
279
|
+
const stat = await statOrNull(sourcePath);
|
|
280
|
+
if (stat === null || !stat.isFile())
|
|
281
|
+
return null;
|
|
282
|
+
const maxBytes = options.maxBytes ?? TRAE_DB_MAX_BYTES;
|
|
283
|
+
if (stat.size > maxBytes) {
|
|
284
|
+
return { code: 'trae-db-too-large', detail: 'copy-too-large', count: stat.size };
|
|
285
|
+
}
|
|
286
|
+
const resolution = resolveTraeDbKey(options.env);
|
|
287
|
+
if ('problem' in resolution)
|
|
288
|
+
return resolution.problem;
|
|
289
|
+
if (await isPlaintextSqlite(sourcePath))
|
|
290
|
+
return null;
|
|
291
|
+
if (stat.size === 0)
|
|
292
|
+
return { code: 'trae-db-decrypt-failed', detail: 'empty-file' };
|
|
293
|
+
if (stat.size % TRAE_DB_PAGE_SIZE !== 0) {
|
|
294
|
+
return { code: 'trae-db-decrypt-failed', detail: 'truncated-database', count: stat.size };
|
|
295
|
+
}
|
|
296
|
+
const head = await readHead(sourcePath, TRAE_DB_PAGE_SIZE);
|
|
297
|
+
if (head === null)
|
|
298
|
+
return { code: 'trae-db-decrypt-failed', detail: 'unreadable' };
|
|
299
|
+
const iv = ivRange();
|
|
300
|
+
const range = cipherRange(0);
|
|
301
|
+
const plain = decryptBlock(resolution.key, head.subarray(iv.start, iv.end), head.subarray(range.start, range.end));
|
|
302
|
+
if (plain === null)
|
|
303
|
+
return { code: 'trae-db-decrypt-failed', detail: 'cipher-rejected' };
|
|
304
|
+
const mismatch = validateTraePageOne(plain, stat.size / TRAE_DB_PAGE_SIZE);
|
|
305
|
+
return mismatch === null ? null : { code: 'trae-db-key-invalid', detail: mismatch };
|
|
306
|
+
}
|
|
307
|
+
/** 标识符引用(表/列名来自本模块的常量与库自报的列清单,仍按 SQLite 规则转义) */
|
|
308
|
+
function quoteIdent(name) {
|
|
309
|
+
return '"' + name.split('"').join('""') + '"';
|
|
310
|
+
}
|
|
311
|
+
/** 选中列清单(显式列名 ⇒ 缺列不会被动变成 `*`) */
|
|
312
|
+
function selectList(columns) {
|
|
313
|
+
return columns.map(quoteIdent).join(', ');
|
|
314
|
+
}
|
|
315
|
+
/** 候选列里第一个真实存在的列 */
|
|
316
|
+
function firstPresent(actual, candidates) {
|
|
317
|
+
for (const candidate of candidates) {
|
|
318
|
+
if (actual.includes(candidate))
|
|
319
|
+
return candidate;
|
|
320
|
+
}
|
|
321
|
+
return null;
|
|
322
|
+
}
|
|
323
|
+
/** 单元格 → JSON(TEXT 与 BLOB 都试;解析不出 → undefined,绝不伪造) */
|
|
324
|
+
function jsonCell(row, key) {
|
|
325
|
+
const text = cellText(row, key);
|
|
326
|
+
if (text !== undefined && text !== '') {
|
|
327
|
+
try {
|
|
328
|
+
return JSON.parse(text);
|
|
329
|
+
}
|
|
330
|
+
catch {
|
|
331
|
+
// 落到 BLOB 分支再试一次
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const bytes = cellBytes(row, key);
|
|
335
|
+
if (bytes === undefined)
|
|
336
|
+
return undefined;
|
|
337
|
+
try {
|
|
338
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
return undefined;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/** 正文容器 → 消息数组(`raw_messages` 第一顺位;数组本身也接受) */
|
|
345
|
+
export function messageItemsOf(value) {
|
|
346
|
+
if (Array.isArray(value))
|
|
347
|
+
return value;
|
|
348
|
+
if (!isRecord(value))
|
|
349
|
+
return null;
|
|
350
|
+
for (const key of MESSAGE_ARRAY_KEYS) {
|
|
351
|
+
const candidate = value[key];
|
|
352
|
+
if (Array.isArray(candidate))
|
|
353
|
+
return candidate;
|
|
354
|
+
}
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
/** 在一行上取「第一个有内容且是绝对路径」的候选列 */
|
|
358
|
+
function absoluteCellOf(row, column, platform) {
|
|
359
|
+
if (column === null)
|
|
360
|
+
return undefined;
|
|
361
|
+
const value = (cellText(row, column) ?? '').trim();
|
|
362
|
+
if (value === '' || !isAbsoluteFor(platform, value))
|
|
363
|
+
return undefined;
|
|
364
|
+
return value;
|
|
365
|
+
}
|
|
366
|
+
/** 在一行上取第一个有内容的候选列(标题/时间用) */
|
|
367
|
+
function firstCellOf(row, column) {
|
|
368
|
+
if (column === null)
|
|
369
|
+
return undefined;
|
|
370
|
+
const value = (cellText(row, column) ?? '').trim();
|
|
371
|
+
return value === '' ? undefined : value;
|
|
372
|
+
}
|
|
373
|
+
/** 读表并把「会话行 + 正文行」拼成中性会话列表(失败一律稳定码,绝不抛出) */
|
|
374
|
+
function readSchema(db, options) {
|
|
375
|
+
const tables = db.tables();
|
|
376
|
+
if (tables === null)
|
|
377
|
+
return { sessions: [], problem: { code: 'trae-db-schema-mismatch', detail: 'table-list-failed' } };
|
|
378
|
+
for (const [table, columns] of Object.entries(TRAE_DB_REQUIRED_SCHEMA)) {
|
|
379
|
+
if (!tables.includes(table)) {
|
|
380
|
+
return { sessions: [], problem: { code: 'trae-db-schema-mismatch', detail: 'missing-table-' + table } };
|
|
381
|
+
}
|
|
382
|
+
const actual = db.columns(table);
|
|
383
|
+
if (actual === null)
|
|
384
|
+
return { sessions: [], problem: { code: 'trae-db-schema-mismatch', detail: 'column-list-failed-' + table } };
|
|
385
|
+
for (const column of columns) {
|
|
386
|
+
if (!actual.includes(column)) {
|
|
387
|
+
return { sessions: [], problem: { code: 'trae-db-schema-mismatch', detail: 'missing-column-' + table + '.' + column } };
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const sessionCols = db.columns(TRAE_DB_TABLE_SESSION) ?? [];
|
|
392
|
+
const historyCols = db.columns(TRAE_DB_TABLE_HISTORY) ?? [];
|
|
393
|
+
const sessionRows = db.all('SELECT ' + selectList(sessionCols) + ' FROM ' + quoteIdent(TRAE_DB_TABLE_SESSION));
|
|
394
|
+
if (sessionRows === null)
|
|
395
|
+
return { sessions: [], problem: { code: 'trae-db-schema-mismatch', detail: 'session-read-failed' } };
|
|
396
|
+
const historyRows = db.all('SELECT ' + selectList(historyCols) + ' FROM ' + quoteIdent(TRAE_DB_TABLE_HISTORY));
|
|
397
|
+
if (historyRows === null)
|
|
398
|
+
return { sessions: [], problem: { code: 'trae-db-schema-mismatch', detail: 'history-read-failed' } };
|
|
399
|
+
const joinColumn = firstPresent(historyCols, SESSION_JOIN_COLUMNS);
|
|
400
|
+
const itemsByKey = new Map();
|
|
401
|
+
const orderedKeys = [];
|
|
402
|
+
let dropped = 0;
|
|
403
|
+
for (const row of historyRows) {
|
|
404
|
+
const items = messageItemsOf(jsonCell(row, 'messages'));
|
|
405
|
+
if (items === null) {
|
|
406
|
+
dropped += 1;
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
const key = joinColumn === null ? '' : (cellText(row, joinColumn) ?? '');
|
|
410
|
+
const existing = itemsByKey.get(key);
|
|
411
|
+
if (existing === undefined) {
|
|
412
|
+
itemsByKey.set(key, [...items]);
|
|
413
|
+
orderedKeys.push(key);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
existing.push(...items);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
// 没有关联列时**不猜**:只有唯一一个会话行才敢把全部正文归给它(否则=可判定失败)
|
|
420
|
+
let fallbackItems = null;
|
|
421
|
+
if (joinColumn === null) {
|
|
422
|
+
if (sessionRows.length > 1) {
|
|
423
|
+
return { sessions: [], problem: { code: 'trae-db-schema-mismatch', detail: 'session-join-column-missing' }, dropped };
|
|
424
|
+
}
|
|
425
|
+
fallbackItems = orderedKeys.flatMap((key) => itemsByKey.get(key) ?? []);
|
|
426
|
+
}
|
|
427
|
+
const cwdColumn = firstPresent(sessionCols, SESSION_CWD_COLUMNS);
|
|
428
|
+
const titleColumn = firstPresent(sessionCols, SESSION_TITLE_COLUMNS);
|
|
429
|
+
const timeColumn = firstPresent(sessionCols, SESSION_TIME_COLUMNS);
|
|
430
|
+
const maxSessions = options.maxSessions ?? TRAE_DB_MAX_SESSIONS;
|
|
431
|
+
const sessions = [];
|
|
432
|
+
let skipped = 0;
|
|
433
|
+
let truncated = false;
|
|
434
|
+
for (const row of sessionRows) {
|
|
435
|
+
if (sessions.length >= maxSessions) {
|
|
436
|
+
truncated = true;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
const id = (cellText(row, 'id') ?? '').trim();
|
|
440
|
+
if (id === '') {
|
|
441
|
+
skipped += 1;
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
const cwd = absoluteCellOf(row, cwdColumn, options.platform);
|
|
445
|
+
const title = firstCellOf(row, titleColumn);
|
|
446
|
+
const createdAt = timeColumn === null ? undefined : cellTime(row, timeColumn);
|
|
447
|
+
const items = fallbackItems ?? itemsByKey.get(id) ?? [];
|
|
448
|
+
sessions.push({
|
|
449
|
+
id,
|
|
450
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
451
|
+
...(title !== undefined ? { title: title.slice(0, 200) } : {}),
|
|
452
|
+
...(createdAt !== undefined ? { createdAt } : {}),
|
|
453
|
+
items,
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
return { sessions, dropped, skipped, truncated };
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* 读一个加密库:体积上限 → 密钥 → 解密(或明文直读)→ 只读读表 → 删临时明文。
|
|
460
|
+
*
|
|
461
|
+
* **绝不抛出**:所有失败都收成 `problem`(稳定码 + detail),调用方据此推 skip。
|
|
462
|
+
*/
|
|
463
|
+
export async function readTraeEncryptedDatabase(sourcePath, options) {
|
|
464
|
+
const stat = await statOrNull(sourcePath);
|
|
465
|
+
if (stat === null || !stat.isFile()) {
|
|
466
|
+
return { sessions: [], problem: { code: 'trae-db-decrypt-failed', detail: 'missing' } };
|
|
467
|
+
}
|
|
468
|
+
const maxBytes = options.maxBytes ?? TRAE_DB_MAX_BYTES;
|
|
469
|
+
if (stat.size > maxBytes) {
|
|
470
|
+
return { sessions: [], problem: { code: 'trae-db-too-large', detail: 'copy-too-large', count: stat.size } };
|
|
471
|
+
}
|
|
472
|
+
const resolution = resolveTraeDbKey(options.env);
|
|
473
|
+
if ('problem' in resolution)
|
|
474
|
+
return { sessions: [], problem: resolution.problem };
|
|
475
|
+
const plaintextSource = await isPlaintextSqlite(sourcePath);
|
|
476
|
+
const dir = plaintextSource ? null : await fs.mkdtemp(path.join(os.tmpdir(), 'dcm-trae-db-'));
|
|
477
|
+
try {
|
|
478
|
+
let target = sourcePath;
|
|
479
|
+
let pages;
|
|
480
|
+
let mode = 'plaintext';
|
|
481
|
+
if (dir !== null) {
|
|
482
|
+
target = path.join(dir, 'database.plain.db');
|
|
483
|
+
const decrypted = await decryptTraeDatabase(sourcePath, target, resolution.key);
|
|
484
|
+
if (!decrypted.ok)
|
|
485
|
+
return { sessions: [], problem: decrypted.problem };
|
|
486
|
+
pages = decrypted.pages;
|
|
487
|
+
mode = 'decrypted';
|
|
488
|
+
}
|
|
489
|
+
// 明文库是我们自己的临时副本(无 -wal/-shm):上限与加密库同档,避免第二次复制撞全局 1 GiB
|
|
490
|
+
const opened = await openSqliteReadOnlyEx(target, { maxCopyBytes: maxBytes });
|
|
491
|
+
if (opened.db === null) {
|
|
492
|
+
return { sessions: [], problem: { code: 'trae-db-schema-mismatch', detail: 'open-' + String(opened.problem ?? 'failed') } };
|
|
493
|
+
}
|
|
494
|
+
try {
|
|
495
|
+
return { ...readSchema(opened.db, options), pages, mode };
|
|
496
|
+
}
|
|
497
|
+
finally {
|
|
498
|
+
opened.db.close();
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
catch {
|
|
502
|
+
return { sessions: [], problem: { code: 'trae-db-decrypt-failed', detail: 'io-error' } };
|
|
503
|
+
}
|
|
504
|
+
finally {
|
|
505
|
+
// 明文只在本次导入内存在:无论成败都删(失败也不留半截)
|
|
506
|
+
if (dir !== null)
|
|
507
|
+
await fs.rm(dir, { recursive: true, force: true }).catch(() => undefined);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
/** problem → skip(origin 固定 'trae';count 只在有意义时带上) */
|
|
511
|
+
export function traeDbSkipOf(problem) {
|
|
512
|
+
return {
|
|
513
|
+
code: problem.code,
|
|
514
|
+
origin: 'trae',
|
|
515
|
+
detail: problem.detail,
|
|
516
|
+
...(problem.count !== undefined ? { count: problem.count } : {}),
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
//# sourceMappingURL=trae-sqlcipher.js.map
|
package/lib/foreign/trae.js
CHANGED
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
* 真机无 Trae 安装)。
|
|
6
6
|
*/
|
|
7
7
|
import { draftFromTranscript, sessionSourceOf } from './session-source.js';
|
|
8
|
-
import { readTrae, traeProbePaths } from './read-trae.js';
|
|
8
|
+
import { readTrae, traeDetectSkips, traeProbePaths } from './read-trae.js';
|
|
9
9
|
export const traeWiring = {
|
|
10
10
|
id: 'trae',
|
|
11
11
|
evidence: 'fixture',
|
|
12
12
|
probePaths: (opts) => traeProbePaths(opts),
|
|
13
|
+
// detect 期就预告「为什么没有会话」(密钥错 / 超限 / 旧库无候选键),别等 build 的 400
|
|
14
|
+
probeSkips: (opts) => traeDetectSkips(opts),
|
|
13
15
|
read: (opts) => readTrae(opts),
|
|
14
16
|
draftOf: (file) => draftFromTranscript(file.id, file, 'trae'),
|
|
15
17
|
};
|
|
@@ -310,8 +310,9 @@ export const FOREIGN_TRUTH_TABLES = [
|
|
|
310
310
|
envKeys: [{ key: 'XDG_CONFIG_HOME', mode: 'replace', absoluteOnly: true, platforms: ['linux'] }],
|
|
311
311
|
autoRoots: true,
|
|
312
312
|
evidence: 'fixture',
|
|
313
|
-
refs: 'read-vault §10.1 trae 行 + chat-import discovery.mjs:80-93,140,2386(**4 个发行版** × 三分支;$APPDATA
|
|
314
|
-
dynamic: '<User>/
|
|
313
|
+
refs: 'read-vault §10.1 trae 行 + chat-import discovery.mjs:80-93,140,2386(**4 个发行版** × 三分支;$APPDATA 缺失即跳过)+ issue #134(2.3.x 加密库布局与 raw key 见 xitula/trae-session-export;**本机无真机样本,evidence 仍为 fixture**)',
|
|
314
|
+
dynamic: '<User>/ModularData/ai-agent/database.db(2.3.x SQLCipher 4.x 整库加密,page 4096 / reserve 80 = IV16+HMAC512;表 chat_session / history_v2 / chat_message / chat_turn / project,消息在 history_v2.messages 的 raw_messages[])'
|
|
315
|
+
+ ' 与 <User>/{workspaceStorage,globalStorage}/**/state.vscdb(旧通道,SQLite ItemTable;键 memento/icube-ai-agent-storage + 4 回退键);两条并存时按会话 id 只计一份',
|
|
315
316
|
},
|
|
316
317
|
{
|
|
317
318
|
id: 'vibe',
|
package/lib/foreign/types.d.ts
CHANGED
|
@@ -143,7 +143,15 @@ export type ForeignSkipCode =
|
|
|
143
143
|
/** 同名 MCP server 在多处出现(全局 / 项目级 / 插件):先到先得,其余只报告 */
|
|
144
144
|
| 'mcp-server-id-conflict'
|
|
145
145
|
/** 项目级扫描触顶(maxProjects):**不静默**,如实报码 */
|
|
146
|
-
| 'project-scan-truncated'
|
|
146
|
+
| 'project-scan-truncated'
|
|
147
|
+
/** 加密库密钥不符(换版 / 用户覆盖了错误密钥):页头判据不成立,**绝不静默 0 会话** */
|
|
148
|
+
| 'trae-db-key-invalid'
|
|
149
|
+
/** 加密库超出**本来源**的体积上限(copy-too-large 语义;全局 1 GiB 兜底未改) */
|
|
150
|
+
| 'trae-db-too-large'
|
|
151
|
+
/** 加密库解密失败:截断 / 非 SQLCipher 形态 / 页尺寸不符 / IO 错误 */
|
|
152
|
+
| 'trae-db-decrypt-failed'
|
|
153
|
+
/** 解密成功但表结构不符(缺 chat_session / history_v2 或必需列):可判定失败,不猜字段 */
|
|
154
|
+
| 'trae-db-schema-mismatch';
|
|
147
155
|
/**
|
|
148
156
|
* 冲突语义(**契约冻结**,§8.4):同 id 会话恒「不覆盖、跳过并报码」。
|
|
149
157
|
*
|
package/lib/index.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export declare const name = "config-manager";
|
|
|
75
75
|
/** Services required before the engine can mount (present in every profile). */
|
|
76
76
|
export declare const inject: string[];
|
|
77
77
|
/** Plugin version, kept in sync with package.json ("version"). */
|
|
78
|
-
export declare const PLUGIN_VERSION = "0.8.
|
|
78
|
+
export declare const PLUGIN_VERSION = "0.8.2";
|
|
79
79
|
/**
|
|
80
80
|
* Star 引导弹窗指向的 GitHub 仓库(用户引导点 Star 的目标)。
|
|
81
81
|
* 与 package.json 的 repository 字段保持一致;界面不可改(硬编码,参照
|
package/lib/index.js
CHANGED
|
@@ -149,7 +149,7 @@ export const name = 'config-manager';
|
|
|
149
149
|
/** Services required before the engine can mount (present in every profile). */
|
|
150
150
|
export const inject = ['settings', 'credentials'];
|
|
151
151
|
/** Plugin version, kept in sync with package.json ("version"). */
|
|
152
|
-
export const PLUGIN_VERSION = '0.8.
|
|
152
|
+
export const PLUGIN_VERSION = '0.8.2';
|
|
153
153
|
/** Plugin own package name — excluded from its own exported plugins list. */
|
|
154
154
|
const PLUGIN_NAME = 'dsh-config-manager';
|
|
155
155
|
/**
|
package/lib/ui/foreign-view.d.ts
CHANGED
|
@@ -164,3 +164,22 @@ export declare const FOREIGN_LOSSY_KINDS: readonly ForeignLossyKind[];
|
|
|
164
164
|
* · **`prompts` 分区** → `systemPrompt` 由字符串写成 `{ persona }` 对象(bundle-format §7.3)。
|
|
165
165
|
*/
|
|
166
166
|
export declare function foreignLossyRows(sections: readonly string[] | null, t: UiT): readonly ForeignLossyRow[];
|
|
167
|
+
/**
|
|
168
|
+
* 导入失败 → 可见载荷(码 + 后端原话 + 一句人话)。
|
|
169
|
+
*
|
|
170
|
+
* 为什么要有它:宿主把「为什么没东西可导」放在 **400 的 body**(`code` + `skipped`),
|
|
171
|
+
* 而客户端过去只显示 `err.message` —— 于是 `sessions-not-migrated`、
|
|
172
|
+
* `trae-db-key-invalid` 这些**字典里早就有中英文案**的码,用户根本看不到。
|
|
173
|
+
* 现在按同一本字典把码翻成文案(skip 码走冻结映射,`nothing-to-import` 走单独一条键),
|
|
174
|
+
* 翻不出才回落后端 message —— 绝不吞掉原因,也绝不编解释。
|
|
175
|
+
*/
|
|
176
|
+
export interface ForeignImportFailure {
|
|
177
|
+
/** 稳定机器码(后端 400 带的 code;没有则为 null) */
|
|
178
|
+
code: string | null;
|
|
179
|
+
/** 后端原始 message(渲染处再过 redact) */
|
|
180
|
+
message: string;
|
|
181
|
+
/** 展示文案(字典优先;没有就用 message) */
|
|
182
|
+
text: string;
|
|
183
|
+
}
|
|
184
|
+
/** 失败载荷的构造(未知码 → 原样返回 message,绝不猜语义) */
|
|
185
|
+
export declare function foreignImportFailure(err: unknown, t: UiT): ForeignImportFailure;
|
package/lib/ui/foreign-view.js
CHANGED
|
@@ -51,6 +51,11 @@ export const FOREIGN_SKIP_KEY = {
|
|
|
51
51
|
'session-id-mismatch': 'foreign.skip.session-id-mismatch',
|
|
52
52
|
'mcp-server-id-conflict': 'foreign.skip.mcp-server-id-conflict',
|
|
53
53
|
'project-scan-truncated': 'foreign.skip.project-scan-truncated',
|
|
54
|
+
// 2026-11-12(#134):Trae 2.3.x 加密会话库的四条可判定失败 —— 同样是全量 Record 保底
|
|
55
|
+
'trae-db-key-invalid': 'foreign.skip.trae-db-key-invalid',
|
|
56
|
+
'trae-db-too-large': 'foreign.skip.trae-db-too-large',
|
|
57
|
+
'trae-db-decrypt-failed': 'foreign.skip.trae-db-decrypt-failed',
|
|
58
|
+
'trae-db-schema-mismatch': 'foreign.skip.trae-db-schema-mismatch',
|
|
54
59
|
};
|
|
55
60
|
/**
|
|
56
61
|
* 机器码 → 字典键。**未知码(未来版本 / 第三方宿主)回退键名本身**,
|
|
@@ -256,4 +261,23 @@ export function foreignLossyRows(sections, t) {
|
|
|
256
261
|
applicable: applicable[kind],
|
|
257
262
|
}));
|
|
258
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* 非 skip 词表、但同样会作为 400 码出现的导入失败(与 `src/routes/foreign.ts` 同源):
|
|
266
|
+
* `nothing-to-import` 是路由层的码,不在 `ForeignSkipCode` union 里,故单独映射。
|
|
267
|
+
*/
|
|
268
|
+
const IMPORT_FAILURE_KEYS = {
|
|
269
|
+
'nothing-to-import': 'foreign.importNothing',
|
|
270
|
+
};
|
|
271
|
+
/** 失败载荷的构造(未知码 → 原样返回 message,绝不猜语义) */
|
|
272
|
+
export function foreignImportFailure(err, t) {
|
|
273
|
+
const source = typeof err === 'object' && err !== null ? err : null;
|
|
274
|
+
const rawCode = source?.code;
|
|
275
|
+
const code = typeof rawCode === 'string' && rawCode !== '' ? rawCode : null;
|
|
276
|
+
const rawMessage = source?.message;
|
|
277
|
+
const message = typeof rawMessage === 'string' && rawMessage !== '' ? rawMessage : String(err);
|
|
278
|
+
if (code === null)
|
|
279
|
+
return { code, message, text: message };
|
|
280
|
+
const mapped = IMPORT_FAILURE_KEYS[code] ?? (isKnownSkipCode(code) ? FOREIGN_SKIP_KEY[code] : undefined);
|
|
281
|
+
return { code, message, text: mapped === undefined ? message : t(mapped) };
|
|
282
|
+
}
|
|
259
283
|
//# sourceMappingURL=foreign-view.js.map
|
package/lib/ui/i18n.d.ts
CHANGED
|
@@ -427,6 +427,11 @@ export declare const uiZh: {
|
|
|
427
427
|
readonly 'foreign.skip.legacy-rules-file': '旧式规则文件:DSH 无对等结构,只报告';
|
|
428
428
|
readonly 'foreign.skip.instructions-merged': '多份指令源被合并为一个全局指令文件';
|
|
429
429
|
readonly 'foreign.skip.instructions-override-selected': '命中更高优先级的指令文件(override),按它导入';
|
|
430
|
+
readonly 'foreign.importNothing': '没有可导入的内容:该来源在本机没有可转换的配置或会话';
|
|
431
|
+
readonly 'foreign.skip.trae-db-key-invalid': 'Trae 加密会话库的密钥对不上(换版或密钥被覆盖):页面头校验不通过,本次未读出任何会话';
|
|
432
|
+
readonly 'foreign.skip.trae-db-too-large': 'Trae 加密会话库超出本来源的体积上限:未解密,未读出任何会话(全局 1 GiB 上限未改动)';
|
|
433
|
+
readonly 'foreign.skip.trae-db-decrypt-failed': 'Trae 加密会话库无法解密:文件被截断、不是 SQLCipher 形态或读取失败,本次未读出任何会话';
|
|
434
|
+
readonly 'foreign.skip.trae-db-schema-mismatch': 'Trae 加密会话库解密成功但表结构不符(缺 chat_session / history_v2 或必需列):不猜字段,本次未读出任何会话';
|
|
430
435
|
readonly 'foreign.skip.unsupported-permissions': '权限规则(allow/ask/deny)未迁移:DSH 没有权限规则文件的对等结构,这些规则不在本包内,导入后不会生效';
|
|
431
436
|
readonly 'foreign.skip.unsupported-settings-keys': 'settings.json 里其余未迁移的顶层键:只记录键名与条数,键值一律不读取,也不会写进本包';
|
|
432
437
|
readonly 'foreign.skip.unsupported-agents': '.claude/agents/*.md 子代理定义未迁移:DSH 的子代理是运行时 provider 注册制,没有文件级对等结构';
|