@liang-hz/agent-in-chrome 0.55.2 → 0.56.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.
- package/README.en.md +6 -5
- package/README.md +6 -5
- package/extension/manifest.json +1 -1
- package/extension/sw.js +794 -76
- package/mcp/agent-identity.mjs +305 -61
- package/mcp/cdp/browser-launch.mjs +160 -48
- package/mcp/secret-shape.mjs +8 -1
- package/mcp/server.mjs +388 -375
- package/mcp/session-id.mjs +25 -3
- package/mcp/tool-tiers.mjs +1 -0
- package/mcp/trace.mjs +7 -4
- package/native-host/host.mjs +28 -0
- package/package.json +1 -1
- package/scripts/borrow-login.mjs +53 -7
- package/scripts/e2e-sweep.mjs +3 -4
- package/scripts/e2e.mjs +164 -40
- package/scripts/fixture-server.mjs +59 -0
- package/scripts/install.mjs +130 -4
- package/scripts/launcher-spawn.mjs +22 -0
- package/scripts/pack-crx.mjs +2 -1
- package/scripts/test-agents.mjs +89 -22
- package/scripts/test-borrow.mjs +6 -0
- package/scripts/test-config.mjs +21 -1
- package/scripts/test-e2e-sweep.mjs +7 -2
- package/scripts/test-identity.mjs +307 -84
- package/scripts/test-install-skill.mjs +37 -2
- package/scripts/test-protocol.mjs +168 -1
- package/scripts/test-security.mjs +274 -18
- package/scripts/test-sw.mjs +423 -20
- package/skills/agent-in-chrome/SKILL.md +4 -4
- package/skills/agent-in-chrome/references/actions-and-waits.md +6 -5
- package/skills/agent-in-chrome/references/network-debugging.md +2 -0
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
isDshClient,
|
|
16
16
|
decodeZstdFrames,
|
|
17
17
|
readDshSession,
|
|
18
|
+
readDshSubagent,
|
|
18
19
|
antigravityDataDir,
|
|
19
20
|
antigravityConversationId,
|
|
20
21
|
readAntigravityWorkspace,
|
|
@@ -33,6 +34,7 @@ import {
|
|
|
33
34
|
readClientSessionFile,
|
|
34
35
|
readHostSessionTitle,
|
|
35
36
|
readWorkbuddySessionTitle,
|
|
37
|
+
workbuddyConfigDir,
|
|
36
38
|
workbuddyConversationId,
|
|
37
39
|
informativeName,
|
|
38
40
|
composeAgent,
|
|
@@ -44,6 +46,7 @@ import {
|
|
|
44
46
|
userDataDirFrom,
|
|
45
47
|
readTraeSessionTitle,
|
|
46
48
|
resetTitleMemo,
|
|
49
|
+
setSqliteColumn,
|
|
47
50
|
readClaudeSubagent,
|
|
48
51
|
resetSubagentMemo,
|
|
49
52
|
procSource,
|
|
@@ -52,6 +55,10 @@ import {
|
|
|
52
55
|
import { isLauncherFor } from "../mcp/session-id.mjs";
|
|
53
56
|
import { makeWinProcSource } from "../mcp/proc-win.mjs";
|
|
54
57
|
|
|
58
|
+
const NODE_SQLITE_TEST = await import("node:sqlite")
|
|
59
|
+
.then((m) => m.DatabaseSync)
|
|
60
|
+
.catch(() => null);
|
|
61
|
+
|
|
55
62
|
let passed = 0;
|
|
56
63
|
let failed = 0;
|
|
57
64
|
const check = (name, cond, extra = "") => {
|
|
@@ -274,6 +281,7 @@ console.log("\n\x1b[1m会话标题:客户端写在磁盘上的那份\x1b[0m");
|
|
|
274
281
|
console.log("\n\x1b[1mWorkBuddy 的会话标题:协议级 → 引擎进程 → 活会话计数\x1b[0m");
|
|
275
282
|
{
|
|
276
283
|
const wb = fs.mkdtempSync(path.join(os.tmpdir(), "aic-wb-"));
|
|
284
|
+
const wbEmptyHome = fs.mkdtempSync(path.join(os.tmpdir(), "aic-wb0-"));
|
|
277
285
|
fs.mkdirSync(path.join(wb, "sessions"));
|
|
278
286
|
const put = (pid, extra) => fs.writeFileSync(path.join(wb, "sessions", `${pid}.json`), JSON.stringify({ pid, ...extra }));
|
|
279
287
|
const A = "649aa100-f37d-4bff-b8db-7518eef9a95d";
|
|
@@ -287,63 +295,76 @@ console.log("\n\x1b[1mWorkBuddy 的会话标题:协议级 → 引擎进程 →
|
|
|
287
295
|
|
|
288
296
|
const env = { WORKBUDDY_CONFIG_DIR: wb };
|
|
289
297
|
let asked = null;
|
|
290
|
-
const
|
|
291
|
-
asked = {
|
|
292
|
-
return "
|
|
298
|
+
const fakeSql = (db, sql, params) => {
|
|
299
|
+
asked = { db, sql, params };
|
|
300
|
+
return ["查竞品定价"];
|
|
293
301
|
};
|
|
302
|
+
setSqliteColumn(fakeSql);
|
|
294
303
|
const oneLive = (p) => p === 7100;
|
|
295
304
|
|
|
296
|
-
const one = readWorkbuddySessionTitle({ env,
|
|
305
|
+
const one = readWorkbuddySessionTitle({ env, alive: oneLive });
|
|
297
306
|
check("兜底:恰好一个活着的对话时读它的标题", one === "查竞品定价", JSON.stringify(one));
|
|
298
|
-
check("兜底:查库带的是那段对话的 uuid
|
|
307
|
+
check("兜底:查库带的是那段对话的 uuid(先验过形状才进查询)", asked?.params?.[0] === "649aa100-f37d-4bff-b8db-7518eef9a95d", JSON.stringify(asked));
|
|
299
308
|
check("兜底:CLI host / prewarm 的假会话不算对话", one === "查竞品定价");
|
|
300
309
|
check(
|
|
301
310
|
"兜底:两段对话都活着又没有别的证据时仍然不猜",
|
|
302
|
-
readWorkbuddySessionTitle({ env,
|
|
311
|
+
readWorkbuddySessionTitle({ env, alive: () => true }) === null
|
|
303
312
|
);
|
|
304
|
-
check("兜底:对话都结束了就是没有", readWorkbuddySessionTitle({ env,
|
|
305
|
-
check("没有 WORKBUDDY_CONFIG_DIR(别家客户端)一律 null", readWorkbuddySessionTitle({ env: {}, exec: fakeExec }) === null);
|
|
313
|
+
check("兜底:对话都结束了就是没有", readWorkbuddySessionTitle({ env, alive: () => false }) === null);
|
|
306
314
|
check(
|
|
307
|
-
"
|
|
308
|
-
readWorkbuddySessionTitle({ env
|
|
315
|
+
"没有 WORKBUDDY_CONFIG_DIR:回它家默认的 ~/.workbuddy(home 指到空目录时自然没有)",
|
|
316
|
+
readWorkbuddySessionTitle({ env: {}, home: wbEmptyHome, alive: oneLive }) === null
|
|
309
317
|
);
|
|
318
|
+
check("库读不动就不显示,不许编",
|
|
319
|
+
(setSqliteColumn(() => { throw new Error("no db"); }), readWorkbuddySessionTitle({ env, alive: oneLive }) === null)
|
|
320
|
+
);
|
|
321
|
+
setSqliteColumn(fakeSql);
|
|
322
|
+
|
|
323
|
+
{
|
|
324
|
+
const wbHome = fs.mkdtempSync(path.join(os.tmpdir(), "aic-wbfb-"));
|
|
325
|
+
fs.cpSync(wb, path.join(wbHome, ".workbuddy"), { recursive: true });
|
|
326
|
+
asked = null;
|
|
327
|
+
const fb = readWorkbuddySessionTitle({ env: {}, home: wbHome, alive: oneLive });
|
|
328
|
+
check("回落:env 不带 WORKBUDDY_CONFIG_DIR 也读得到(Windows 的常态)", fb === "查竞品定价", JSON.stringify(fb));
|
|
329
|
+
check("回落:读的库就在 <home>/.workbuddy 下", asked?.db === path.join(wbHome, ".workbuddy", "workbuddy.db"), asked?.db);
|
|
330
|
+
fs.rmSync(wbHome, { recursive: true, force: true });
|
|
331
|
+
}
|
|
332
|
+
setSqliteColumn(fakeSql);
|
|
310
333
|
|
|
311
334
|
asked = null;
|
|
312
|
-
const byMeta = readWorkbuddySessionTitle({ env,
|
|
335
|
+
const byMeta = readWorkbuddySessionTitle({ env, alive: () => true, meta: { "workbuddy.ai/conversationId": B } });
|
|
313
336
|
check("协议级:_meta 报的会话 id 优先于活会话计数(多开对话照样归属)", byMeta === "查竞品定价", JSON.stringify(byMeta));
|
|
314
|
-
check("协议级:查的是 _meta 报的那个 uuid,不是「活着的那个」",
|
|
337
|
+
check("协议级:查的是 _meta 报的那个 uuid,不是「活着的那个」", asked?.params?.[0] === B, JSON.stringify(asked));
|
|
315
338
|
|
|
316
339
|
asked = null;
|
|
317
340
|
const byBaggage = readWorkbuddySessionTitle({
|
|
318
341
|
env,
|
|
319
|
-
exec: fakeExec,
|
|
320
342
|
alive: () => true,
|
|
321
343
|
meta: { progressToken: 7, baggage: "codebuddy.session_id=" + A + ",other=1" },
|
|
322
344
|
});
|
|
323
|
-
check("协议级:baggage 里的 codebuddy.session_id 是同一份值的第二处写法", byBaggage === "查竞品定价" &&
|
|
345
|
+
check("协议级:baggage 里的 codebuddy.session_id 是同一份值的第二处写法", byBaggage === "查竞品定价" && asked?.params?.[0] === A, JSON.stringify(asked));
|
|
324
346
|
|
|
325
347
|
asked = null;
|
|
326
348
|
readWorkbuddySessionTitle({
|
|
327
349
|
env,
|
|
328
|
-
exec: fakeExec,
|
|
329
350
|
alive: () => true,
|
|
330
351
|
meta: { "workbuddy.ai/conversationId": B, baggage: "codebuddy.session_id=" + A },
|
|
331
352
|
});
|
|
332
|
-
check("协议级:命名空间键优先于 baggage(两处都带时以前者为准)",
|
|
353
|
+
check("协议级:命名空间键优先于 baggage(两处都带时以前者为准)", asked?.params?.[0] === B, JSON.stringify(asked));
|
|
333
354
|
|
|
334
355
|
check("协议级:形状锚只放行 uuid(不是 uuid 就当没报)", workbuddyConversationId({ "workbuddy.ai/conversationId": "abc" }) === null);
|
|
335
356
|
check("协议级:meta 不是对象时不炸", workbuddyConversationId(null) === null && workbuddyConversationId("x") === null);
|
|
336
357
|
|
|
337
358
|
asked = null;
|
|
338
|
-
const byPid = readWorkbuddySessionTitle({ env,
|
|
339
|
-
check("进程级:引擎 pid 的记录直接给出会话 id(真机上就是它)", byPid === "查竞品定价" &&
|
|
340
|
-
check("进程级:引擎 pid 的文件里 pid 对不上(pid 被复用)就不认", readWorkbuddySessionTitle({ env,
|
|
341
|
-
check("进程级:指向预热池那种非 interactive 的记录不认", readWorkbuddySessionTitle({ env,
|
|
342
|
-
check("进程级:指着一个不存在的 pid 就是没有,不炸", readWorkbuddySessionTitle({ env,
|
|
343
|
-
check("进程级:没给引擎 pid 时这一档整个跳过", readWorkbuddySessionTitle({ env,
|
|
359
|
+
const byPid = readWorkbuddySessionTitle({ env, alive: () => true, enginePid: 7100 });
|
|
360
|
+
check("进程级:引擎 pid 的记录直接给出会话 id(真机上就是它)", byPid === "查竞品定价" && asked?.params?.[0] === A, JSON.stringify(asked));
|
|
361
|
+
check("进程级:引擎 pid 的文件里 pid 对不上(pid 被复用)就不认", readWorkbuddySessionTitle({ env, alive: () => false, enginePid: 7200 }) === null);
|
|
362
|
+
check("进程级:指向预热池那种非 interactive 的记录不认", readWorkbuddySessionTitle({ env, alive: () => false, enginePid: 7102 }) === null);
|
|
363
|
+
check("进程级:指着一个不存在的 pid 就是没有,不炸", readWorkbuddySessionTitle({ env, alive: () => false, enginePid: 7999 }) === null);
|
|
364
|
+
check("进程级:没给引擎 pid 时这一档整个跳过", readWorkbuddySessionTitle({ env, alive: oneLive, enginePid: null }) === "查竞品定价");
|
|
344
365
|
asked = null;
|
|
345
|
-
readWorkbuddySessionTitle({ env,
|
|
346
|
-
check("协议级压过进程级(调用方自己说的那句最硬)",
|
|
366
|
+
readWorkbuddySessionTitle({ env, alive: () => true, enginePid: 7100, meta: { "workbuddy.ai/conversationId": B } });
|
|
367
|
+
check("协议级压过进程级(调用方自己说的那句最硬)", asked?.params?.[0] === B, JSON.stringify(asked));
|
|
347
368
|
|
|
348
369
|
{
|
|
349
370
|
const evil = fs.mkdtempSync(path.join(os.tmpdir(), "aic-wb-evil-"));
|
|
@@ -351,32 +372,36 @@ console.log("\n\x1b[1mWorkBuddy 的会话标题:协议级 → 引擎进程 →
|
|
|
351
372
|
fs.writeFileSync(path.join(evil, "sessions", "8000.json"),
|
|
352
373
|
JSON.stringify({ pid: 8000, kind: "interactive", sessionId: "1' or '1'='1" }));
|
|
353
374
|
const never = () => { throw new Error("绝不该拿注入载荷查库"); };
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
375
|
+
setSqliteColumn(never);
|
|
376
|
+
check("带引号的 sessionId 不进查询(活会话那条路的正则先挡)",
|
|
377
|
+
readWorkbuddySessionTitle({ env: { WORKBUDDY_CONFIG_DIR: evil }, alive: () => true }) === null);
|
|
378
|
+
check("带引号的 _meta.conversationId 不进查询(协议级那条路同样先挡)",
|
|
379
|
+
readWorkbuddySessionTitle({ env: { WORKBUDDY_CONFIG_DIR: evil }, meta: { "workbuddy.ai/conversationId": "1' or '1'='1" } }) === null);
|
|
380
|
+
check("带引号的 baggage 不进查询",
|
|
381
|
+
readWorkbuddySessionTitle({ env: { WORKBUDDY_CONFIG_DIR: evil }, meta: { baggage: "codebuddy.session_id=x' or 1=1--" } }) === null);
|
|
382
|
+
check("带引号的引擎记录同样进不去查询",
|
|
383
|
+
readWorkbuddySessionTitle({ env: { WORKBUDDY_CONFIG_DIR: evil }, enginePid: 8000 }) === null);
|
|
362
384
|
fs.rmSync(evil, { recursive: true, force: true });
|
|
385
|
+
setSqliteColumn(fakeSql);
|
|
363
386
|
}
|
|
364
387
|
|
|
365
|
-
const t = readSessionTitle({ clientPid: 0, hostSessionId: null }, { home: wb, env,
|
|
388
|
+
const t = readSessionTitle({ clientPid: 0, hostSessionId: null }, { home: wb, env, alive: oneLive });
|
|
366
389
|
check("readSessionTitle 兜到 WorkBuddy 这条来源", t === "查竞品定价", JSON.stringify(t));
|
|
367
390
|
const t2 = readSessionTitle(
|
|
368
391
|
{ clientPid: 0, hostSessionId: null },
|
|
369
|
-
{ home: wb, env,
|
|
392
|
+
{ home: wb, env, alive: () => true, meta: { "workbuddy.ai/conversationId": B } }
|
|
370
393
|
);
|
|
371
394
|
check("readSessionTitle 把 _meta 一路传给了 WorkBuddy 这一条(不传的话多开对话就丢会话名)", t2 === "查竞品定价", JSON.stringify(t2));
|
|
372
395
|
asked = null;
|
|
373
396
|
const t3 = readSessionTitle(
|
|
374
397
|
{ clientPid: 7100, hostSessionId: null },
|
|
375
|
-
{ home: wb, env,
|
|
398
|
+
{ home: wb, env, alive: () => true }
|
|
376
399
|
);
|
|
377
|
-
check("readSessionTitle 把 clientPid 当作引擎 pid 传下去", t3 === "查竞品定价" &&
|
|
400
|
+
check("readSessionTitle 把 clientPid 当作引擎 pid 传下去", t3 === "查竞品定价" && asked?.params?.[0] === A, JSON.stringify(asked));
|
|
378
401
|
|
|
402
|
+
setSqliteColumn(null);
|
|
379
403
|
fs.rmSync(wb, { recursive: true, force: true });
|
|
404
|
+
fs.rmSync(wbEmptyHome, { recursive: true, force: true });
|
|
380
405
|
}
|
|
381
406
|
|
|
382
407
|
console.log("\n\x1b[1m拼出显示用的那个对象\x1b[0m");
|
|
@@ -499,60 +524,66 @@ console.log("\n\x1b[1mZCode 的会话标题:_meta.session_id 精确归属\x1b[
|
|
|
499
524
|
fs.writeFileSync(path.join(home, ".zcode", "cli", "db", "db.sqlite"), "");
|
|
500
525
|
const SID = "sess_0a33b40d-8caa-431f-8d42-ca951e3366f4";
|
|
501
526
|
let asked = null;
|
|
502
|
-
const
|
|
503
|
-
asked = {
|
|
504
|
-
return "
|
|
527
|
+
const fakeSql = (db, sql, params) => {
|
|
528
|
+
asked = { db, sql, params };
|
|
529
|
+
return ["接管浏览器标签组并打开谷歌搜索"];
|
|
505
530
|
};
|
|
506
|
-
|
|
531
|
+
setSqliteColumn(fakeSql);
|
|
532
|
+
const at = (meta, sql = fakeSql) => {
|
|
533
|
+
asked = null;
|
|
507
534
|
resetTitleMemo();
|
|
508
|
-
|
|
535
|
+
setSqliteColumn(sql);
|
|
536
|
+
return readZcodeSessionTitle(meta, { home, env: {} });
|
|
509
537
|
};
|
|
510
538
|
|
|
511
539
|
check("主会话:按 _meta.session_id 读它自己的标题", at({ session_id: SID, runtime_scope: "main" }) === "接管浏览器标签组并打开谷歌搜索");
|
|
512
|
-
check("查的是 session 表、只认 generated/custom", /from session where id
|
|
513
|
-
check("
|
|
540
|
+
check("查的是 session 表、只认 generated/custom", /from session where id=\?/.test(asked?.sql || "") && /title_source in \('generated','custom'\)/.test(asked?.sql || ""), asked?.sql);
|
|
541
|
+
check("会话 id 是绑定参数,不是拼进 SQL 的字面量", asked?.params?.[0] === SID, JSON.stringify(asked?.params));
|
|
542
|
+
check("读的库就是它家数据目录里那份", asked?.db === path.join(home, ".zcode", "cli", "db", "db.sqlite"), asked?.db);
|
|
514
543
|
check("没给 runtime_scope 也认(老版本客户端)", at({ session_id: SID }) === "接管浏览器标签组并打开谷歌搜索");
|
|
515
544
|
const SUB = "sess_subagent_agent_a1100314-0000-4000-8000-000000000000";
|
|
516
545
|
check("subagent 的调用报的是主会话的名字", at({ session_id: SUB, runtime_scope: "subagent" }) === "接管浏览器标签组并打开谷歌搜索");
|
|
517
546
|
check(
|
|
518
547
|
"subagent 走的是 parent_id 那一跳,不读它自己那行的 first_input",
|
|
519
|
-
/where id=\(select parent_id from session where id
|
|
520
|
-
/title_source in \('generated','custom'\)/.test(asked?.sql || "")
|
|
521
|
-
|
|
548
|
+
/where id=\(select parent_id from session where id=\?\)/.test(asked?.sql || "") &&
|
|
549
|
+
/title_source in \('generated','custom'\)/.test(asked?.sql || "") &&
|
|
550
|
+
asked?.params?.[0] === SUB,
|
|
551
|
+
JSON.stringify(asked)
|
|
522
552
|
);
|
|
523
553
|
check(
|
|
524
|
-
"subagent 的 id
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
) === null
|
|
554
|
+
"subagent 的 id 形状也要卡死(它同样进查询)",
|
|
555
|
+
at({ session_id: "sess_subagent_agent_a1100314-0000-4000-8000-000000000000' or '1'='1" }, () => {
|
|
556
|
+
throw new Error("绝不该拿注入载荷去查库");
|
|
557
|
+
}) === null
|
|
529
558
|
);
|
|
530
|
-
check("形状不对的 id
|
|
559
|
+
check("形状不对的 id 一律不进查询", at({ session_id: "sess_'; drop table session; --" }) === null);
|
|
531
560
|
for (const bad of [
|
|
532
561
|
"sess_0a33b40d-8caa-431f-8d42-ca951e3366f4'",
|
|
533
562
|
"sess_0a33b40d-8caa-431f-8d42-ca951e3366f4' or '1'='1",
|
|
534
563
|
"sess_0a33b40d-8caa-431f-8d42-ca951e3366f4'--",
|
|
535
564
|
"sess_0a33b40d-8caa-431f-8d42-ca951e3366f4 union select 1",
|
|
536
|
-
"sess_0a33b40d%2d8caa",
|
|
565
|
+
"sess_0a33b40d-8caa-431f-8d42-ca951e3366f4%2d8caa",
|
|
537
566
|
]) {
|
|
538
|
-
check(
|
|
539
|
-
|
|
567
|
+
check(`注入载荷被正则拦下,绝不起查询:${bad.slice(30) || bad}`,
|
|
568
|
+
at({ session_id: bad }, () => { throw new Error("绝不该拿注入载荷去查库"); }) === null);
|
|
540
569
|
}
|
|
541
570
|
check("别家客户端的 _meta(没有 session_id)不认", at({ progressToken: 1 }) === null);
|
|
542
571
|
check("没有 _meta 也不能抛", at(null) === null && at(undefined) === null);
|
|
543
572
|
check("库读不动就不显示,不许编", at({ session_id: SID }, () => { throw new Error("locked"); }) === null);
|
|
544
|
-
check("标题还没生成(查出来是空)就是没有", at({ session_id: SID }, () => "\n") === null);
|
|
573
|
+
check("标题还没生成(查出来是空)就是没有", at({ session_id: SID }, () => ["\n"]) === null);
|
|
545
574
|
|
|
546
575
|
resetTitleMemo();
|
|
547
576
|
let calls = 0;
|
|
548
|
-
|
|
549
|
-
readZcodeSessionTitle({ session_id: SID }, { home, env: {}
|
|
550
|
-
readZcodeSessionTitle({ session_id: SID }, { home, env: {}
|
|
551
|
-
readZcodeSessionTitle({ session_id: SID }, { home, env: {}
|
|
552
|
-
check("
|
|
577
|
+
setSqliteColumn(() => { calls++; return ["标题"]; });
|
|
578
|
+
readZcodeSessionTitle({ session_id: SID }, { home, env: {} });
|
|
579
|
+
readZcodeSessionTitle({ session_id: SID }, { home, env: {} });
|
|
580
|
+
readZcodeSessionTitle({ session_id: SID }, { home, env: {} });
|
|
581
|
+
check("查到过的标题记住,不再重复读库", calls === 1, `读了 ${calls} 次`);
|
|
553
582
|
|
|
554
583
|
const bare = fs.mkdtempSync(path.join(os.tmpdir(), "aic-zc0-"));
|
|
555
|
-
|
|
584
|
+
setSqliteColumn(() => { throw new Error("不该被调用"); });
|
|
585
|
+
check("本机没装 ZCode 就直接不查", readZcodeSessionTitle({ session_id: SID }, { home: bare, env: {} }) === null);
|
|
586
|
+
setSqliteColumn(null);
|
|
556
587
|
fs.rmSync(home, { recursive: true, force: true });
|
|
557
588
|
fs.rmSync(bare, { recursive: true, force: true });
|
|
558
589
|
}
|
|
@@ -710,18 +741,19 @@ console.log("\n\x1b[1m标题的取用顺序:先协议级(_meta),后本
|
|
|
710
741
|
JSON.stringify({ pid: 7003, sessionId: "s", name: "本机取证认到的名字", nameSource: "generated" })
|
|
711
742
|
);
|
|
712
743
|
const local = { clientPid: 7003, hostSessionId: null, sessionName: null };
|
|
713
|
-
const exec = () => "协议级认到的名字\n";
|
|
714
744
|
resetTitleMemo();
|
|
745
|
+
setSqliteColumn(() => ["协议级认到的名字"]);
|
|
715
746
|
check(
|
|
716
747
|
"_meta 报了会话身份时,用它,不用本机取证那条",
|
|
717
|
-
readSessionTitle(local, { home,
|
|
748
|
+
readSessionTitle(local, { home, env: {}, meta: { session_id: "sess_0a33b40d-8caa-431f-8d42-ca951e3366f4" } }) === "协议级认到的名字"
|
|
718
749
|
);
|
|
750
|
+
setSqliteColumn(null);
|
|
719
751
|
resetTitleMemo();
|
|
720
|
-
check("没有 _meta 的客户端行为一字不变", readSessionTitle(local, { home, exec: () => { throw new Error("不该查库"); } }) === "本机取证认到的名字");
|
|
752
|
+
check("没有 _meta 的客户端行为一字不变", readSessionTitle(local, { home, env: {}, exec: () => { throw new Error("不该查库"); } }) === "本机取证认到的名字");
|
|
721
753
|
resetTitleMemo();
|
|
722
754
|
check(
|
|
723
755
|
"Qoder 那种一个 _meta 字段都不发的,走回原来的路(不猜)",
|
|
724
|
-
readSessionTitle(local, { home, exec: () => { throw new Error("不该查库"); }, meta: { progressToken: 1 } }) === "本机取证认到的名字"
|
|
756
|
+
readSessionTitle(local, { home, env: {}, exec: () => { throw new Error("不该查库"); }, meta: { progressToken: 1 } }) === "本机取证认到的名字"
|
|
725
757
|
);
|
|
726
758
|
fs.rmSync(home, { recursive: true, force: true });
|
|
727
759
|
}
|
|
@@ -764,10 +796,11 @@ if (typeof zlib.zstdCompressSync !== "function") {
|
|
|
764
796
|
for (const s of sessions) {
|
|
765
797
|
const dir = path.join(home, ".dsh", "sessions", "--proj--", s.id);
|
|
766
798
|
fs.mkdirSync(dir, { recursive: true });
|
|
767
|
-
const lines = [ev({ type: "session", version: 0, id: s.id, createdAt: 1, cwd: s.cwd, delegationDepth: 0 })];
|
|
799
|
+
const lines = [ev({ type: "session", version: 0, id: s.id, createdAt: 1, cwd: s.cwd, delegationDepth: 0, ...(s.header || {}) })];
|
|
768
800
|
let seq = 10;
|
|
801
|
+
for (const e of s.extra || []) lines.push(ev({ seq: seq++, ...e }));
|
|
769
802
|
for (const [kind, title] of s.titles || []) lines.push(ev({ type: "session/title", seq: seq++, data: { title, source: { kind } } }));
|
|
770
|
-
const f = path.join(dir, "session.jsonl.zstd");
|
|
803
|
+
const f = path.join(dir, s.file || "session.jsonl.zstd");
|
|
771
804
|
fs.writeFileSync(f, frames(lines));
|
|
772
805
|
if (s.ageMs) {
|
|
773
806
|
const t = new Date(Date.now() - s.ageMs);
|
|
@@ -780,6 +813,10 @@ if (typeof zlib.zstdCompressSync !== "function") {
|
|
|
780
813
|
check("isDshClient 认 npx/pnpm 的 bin shim", isDshClient(DSH_CMD));
|
|
781
814
|
check("isDshClient 认包路径(全局装的形态)", isDshClient("node /usr/lib/node_modules/@deepseek-ai/dsh/lib/bin.js web"));
|
|
782
815
|
check("别家的 node 进程不算 dsh", !isDshClient("node /Users/u/.workbuddy/daemon-app-server-entry.js"));
|
|
816
|
+
const DSH_APP_CMD =
|
|
817
|
+
"/Applications/DeepSeek Harness.app/Contents/MacOS/DeepSeek Harness --expose-internals /Applications/DeepSeek Harness.app/Contents/Resources/app.asar";
|
|
818
|
+
check("isDshClient 认桌面端(DeepSeek Harness.app)", isDshClient(DSH_APP_CMD));
|
|
819
|
+
check("别的 Electron .app 不算 dsh", !isDshClient("/Applications/Visual Studio Code.app/Contents/MacOS/Electron"));
|
|
783
820
|
|
|
784
821
|
{
|
|
785
822
|
const parts = frames(['{"a":1}', '{"b":2}', '{"c":3}']);
|
|
@@ -792,11 +829,11 @@ if (typeof zlib.zstdCompressSync !== "function") {
|
|
|
792
829
|
{ id: "session-11111111-1111-1111-1111-111111111111", cwd: "/Users/u/proj-a", titles: [["fallback", "你好"], ["provider", "调研杭州天气"]] },
|
|
793
830
|
]);
|
|
794
831
|
resetTitleMemo();
|
|
795
|
-
const s = readDshSession(localFor(), { home });
|
|
832
|
+
const s = readDshSession(localFor(), { home, env: {} });
|
|
796
833
|
check("一个活跃会话:归属成立,标题是 LLM 生成的那条", s?.title === "调研杭州天气", JSON.stringify(s));
|
|
797
834
|
check("cwd 来自会话日志的 header", s?.cwd === "/Users/u/proj-a", JSON.stringify(s));
|
|
798
835
|
resetTitleMemo();
|
|
799
|
-
check("拉起我们的不是 dsh 时一个字都不读", readDshSession(localFor("node /a/other.js"), { home }) === null);
|
|
836
|
+
check("拉起我们的不是 dsh 时一个字都不读", readDshSession(localFor("node /a/other.js"), { home, env: {} }) === null);
|
|
800
837
|
fs.rmSync(home, { recursive: true, force: true });
|
|
801
838
|
}
|
|
802
839
|
|
|
@@ -805,7 +842,7 @@ if (typeof zlib.zstdCompressSync !== "function") {
|
|
|
805
842
|
{ id: "session-22222222-2222-2222-2222-222222222222", cwd: "/Users/u/proj-b", titles: [["fallback", "帮我看看这个"]] },
|
|
806
843
|
]);
|
|
807
844
|
resetTitleMemo();
|
|
808
|
-
const s = readDshSession(localFor(), { home });
|
|
845
|
+
const s = readDshSession(localFor(), { home, env: {} });
|
|
809
846
|
check("fallback 标题不显示(同 ZCode 拒 first_input 的理由)", s !== null && s.title === null, JSON.stringify(s));
|
|
810
847
|
check("标题缺席不拖累 cwd", s?.cwd === "/Users/u/proj-b", JSON.stringify(s));
|
|
811
848
|
fs.rmSync(home, { recursive: true, force: true });
|
|
@@ -816,7 +853,7 @@ if (typeof zlib.zstdCompressSync !== "function") {
|
|
|
816
853
|
{ id: "session-33333333-3333-3333-3333-333333333333", cwd: "/x", titles: [["provider", "自动名"], ["user", "我改的名"]] },
|
|
817
854
|
]);
|
|
818
855
|
resetTitleMemo();
|
|
819
|
-
check("用户改名后取最后一条", readDshSession(localFor(), { home })?.title === "我改的名");
|
|
856
|
+
check("用户改名后取最后一条", readDshSession(localFor(), { home, env: {} })?.title === "我改的名");
|
|
820
857
|
fs.rmSync(home, { recursive: true, force: true });
|
|
821
858
|
}
|
|
822
859
|
|
|
@@ -826,7 +863,7 @@ if (typeof zlib.zstdCompressSync !== "function") {
|
|
|
826
863
|
{ id: "session-55555555-5555-5555-5555-555555555555", cwd: "/y", titles: [["provider", "乙"]] },
|
|
827
864
|
]);
|
|
828
865
|
resetTitleMemo();
|
|
829
|
-
check("两个活跃会话:null,不猜", readDshSession(localFor(), { home }) === null);
|
|
866
|
+
check("两个活跃会话:null,不猜", readDshSession(localFor(), { home, env: {} }) === null);
|
|
830
867
|
fs.rmSync(home, { recursive: true, force: true });
|
|
831
868
|
}
|
|
832
869
|
|
|
@@ -836,7 +873,161 @@ if (typeof zlib.zstdCompressSync !== "function") {
|
|
|
836
873
|
{ id: "session-77777777-7777-7777-7777-777777777777", cwd: "/y", titles: [["provider", "冷的"]], ageMs: 20 * 60_000 },
|
|
837
874
|
]);
|
|
838
875
|
resetTitleMemo();
|
|
839
|
-
check("超出活跃窗口的旧会话不算,归属落在活的那个", readDshSession(localFor(), { home })?.title === "活的");
|
|
876
|
+
check("超出活跃窗口的旧会话不算,归属落在活的那个", readDshSession(localFor(), { home, env: {} })?.title === "活的");
|
|
877
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
{
|
|
881
|
+
const home = makeDshHome([
|
|
882
|
+
{ id: "11111111-1111-1111-1111-111111111111", cwd: "/Users/u/proj-x", file: "session.v4.jsonl.zstd", titles: [["provider", "桌面端的会话"]] },
|
|
883
|
+
]);
|
|
884
|
+
resetTitleMemo();
|
|
885
|
+
const s = readDshSession(localFor(DSH_APP_CMD), { home, env: {} });
|
|
886
|
+
check(
|
|
887
|
+
"桌面端布局:不带前缀的目录 + session.v4.jsonl.zstd 也读得到",
|
|
888
|
+
s?.title === "桌面端的会话" && s?.cwd === "/Users/u/proj-x",
|
|
889
|
+
JSON.stringify(s)
|
|
890
|
+
);
|
|
891
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
{
|
|
895
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), "aic-dsh-"));
|
|
896
|
+
const dir = path.join(home, ".dsh", "sessions", "--proj--", "session-22222222-2222-2222-2222-222222222222");
|
|
897
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
898
|
+
const head = (cwd) => ev({ type: "session", version: 0, id: "s", createdAt: 1, cwd, delegationDepth: 0 });
|
|
899
|
+
const titled = (title) => ev({ type: "session/title", seq: 1, data: { title, source: { kind: "provider" } } });
|
|
900
|
+
fs.writeFileSync(path.join(dir, "session.v3.jsonl.zstd"), frames([head("/Users/u/old"), titled("旧格式")]));
|
|
901
|
+
fs.writeFileSync(path.join(dir, "session.v4.jsonl.zstd"), frames([head("/Users/u/new"), titled("当前格式")]));
|
|
902
|
+
resetTitleMemo();
|
|
903
|
+
const s = readDshSession(localFor(DSH_APP_CMD), { home, env: {} });
|
|
904
|
+
check("v3/v4 并存取版本号最高的那个", s?.title === "当前格式" && s?.cwd === "/Users/u/new", JSON.stringify(s));
|
|
905
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
{
|
|
909
|
+
const home = makeDshHome([
|
|
910
|
+
{ id: "session-33333333-3333-3333-3333-333333333333", cwd: "/Users/u/proj", titles: [["provider", "真的对话"]] },
|
|
911
|
+
{ id: "44444444-4444-4444-4444-444444444444", cwd: "/Users/u/proj", file: "session.v4.jsonl.zstd", extra: [{ type: "sandbox/mode", data: { mode: "workspace-write" } }] },
|
|
912
|
+
{ id: "55555555-5555-5555-5555-555555555555", cwd: "/Users/u/proj", file: "session.v3.jsonl.zstd", extra: [{ type: "approval/policy", data: { policy: "ask" } }] },
|
|
913
|
+
]);
|
|
914
|
+
resetTitleMemo();
|
|
915
|
+
const s = readDshSession(localFor(DSH_APP_CMD), { home, env: {} });
|
|
916
|
+
check("空壳会话被剔掉,归属落在真对话上", s?.title === "真的对话", JSON.stringify(s));
|
|
917
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
{
|
|
921
|
+
const home = makeDshHome([
|
|
922
|
+
{ id: "session-66666666-6666-6666-6666-666666666666", cwd: "/Users/u/stub", file: "session.v4.jsonl.zstd", extra: [{ type: "sandbox/mode", data: { mode: "workspace-write" } }] },
|
|
923
|
+
{ id: "session-77777777-7777-7777-7777-777777777777", cwd: "/Users/u/fresh", file: "session.v4.jsonl.zstd", extra: [{ type: "user/message", data: { content: [{ type: "text", text: "你好" }], source: { kind: "user" } } }] },
|
|
924
|
+
]);
|
|
925
|
+
resetTitleMemo();
|
|
926
|
+
const s = readDshSession(localFor(DSH_APP_CMD), { home, env: {} });
|
|
927
|
+
check("还没标题但有用户输入的新对话算在对话里,空壳不算", s?.cwd === "/Users/u/fresh" && s?.title === null, JSON.stringify(s));
|
|
928
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
{
|
|
932
|
+
const home = makeDshHome([
|
|
933
|
+
{ id: "session-88888888-8888-8888-8888-888888888888", cwd: "/x", file: "session.v4.jsonl.zstd", titles: [["provider", "甲"]] },
|
|
934
|
+
{ id: "99999999-9999-9999-9999-999999999999", cwd: "/y", file: "session.v4.jsonl.zstd", titles: [["provider", "乙"]] },
|
|
935
|
+
]);
|
|
936
|
+
resetTitleMemo();
|
|
937
|
+
check("两个都在对话:仍然 null,不猜", readDshSession(localFor(DSH_APP_CMD), { home, env: {} }) === null);
|
|
938
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
{
|
|
942
|
+
const home = makeDshHome([
|
|
943
|
+
{ id: "session-aaaa1111-1111-1111-1111-111111111111", cwd: "/Users/u/a", file: "session.v4.jsonl.zstd", titles: [["provider", "甲"]] },
|
|
944
|
+
{ id: "session-bbbb2222-2222-2222-2222-222222222222", cwd: "/Users/u/b", file: "session.v4.jsonl.zstd", titles: [["provider", "乙"]] },
|
|
945
|
+
{ id: "session-cccc3333-3333-3333-3333-333333333333", cwd: "/Users/u/c", file: "session.v4.jsonl.zstd", titles: [["provider", "丙"]] },
|
|
946
|
+
]);
|
|
947
|
+
resetTitleMemo();
|
|
948
|
+
check("三个活跃对话:没有 meta 时老口径仍然是 null", readDshSession(localFor(DSH_APP_CMD), { home, env: {} }) === null);
|
|
949
|
+
resetTitleMemo();
|
|
950
|
+
const s = readDshSession(localFor(DSH_APP_CMD), { home, env: {}, meta: { session_id: "session-bbbb2222-2222-2222-2222-222222222222" } });
|
|
951
|
+
check("_meta.session_id 直接定位,多个活跃也不影响", s?.title === "乙" && s?.cwd === "/Users/u/b", JSON.stringify(s));
|
|
952
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
{
|
|
956
|
+
const home = makeDshHome([
|
|
957
|
+
{ id: "session-dddd4444-4444-4444-4444-444444444444", cwd: "/Users/u/d", file: "session.v4.jsonl.zstd", titles: [["provider", "丁"]] },
|
|
958
|
+
]);
|
|
959
|
+
resetTitleMemo();
|
|
960
|
+
const s = readDshSession(localFor(DSH_APP_CMD), { home, env: {}, meta: { session_id: "../../etc/passwd" } });
|
|
961
|
+
check("带分隔符/走位的 id 不查盘,回落老口径", s?.title === "丁", JSON.stringify(s));
|
|
962
|
+
resetTitleMemo();
|
|
963
|
+
check("绝对路径形状同样拒绝", readDshSession(localFor(DSH_APP_CMD), { home, env: {}, meta: { session_id: "/etc/passwd" } })?.title === "丁");
|
|
964
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
{
|
|
968
|
+
const home = makeDshHome([
|
|
969
|
+
{ id: "session-main1111-1111-1111-1111-111111111111", cwd: "/Users/u/proj", file: "session.v4.jsonl.zstd", titles: [["provider", "主会话的名字"]] },
|
|
970
|
+
{
|
|
971
|
+
id: "session-sub22222-2222-2222-2222-222222222222",
|
|
972
|
+
cwd: "/Users/u/proj",
|
|
973
|
+
file: "session.v4.jsonl.zstd",
|
|
974
|
+
titles: [["provider", "委派提示词的开头四十个字"]],
|
|
975
|
+
header: { origin: "subagent", parentSession: "session-main1111-1111-1111-1111-111111111111", delegationDepth: 1 },
|
|
976
|
+
},
|
|
977
|
+
]);
|
|
978
|
+
resetTitleMemo();
|
|
979
|
+
const s = readDshSession(localFor(DSH_APP_CMD), { home, env: {}, meta: { session_id: "session-sub22222-2222-2222-2222-222222222222" } });
|
|
980
|
+
check(
|
|
981
|
+
"subagent 上溯主会话:报主会话的标题与工作区",
|
|
982
|
+
s?.title === "主会话的名字" && s?.cwd === "/Users/u/proj" && s?.id === "session-main1111-1111-1111-1111-111111111111",
|
|
983
|
+
JSON.stringify(s)
|
|
984
|
+
);
|
|
985
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
{
|
|
989
|
+
const home = makeDshHome([
|
|
990
|
+
{
|
|
991
|
+
id: "session-orphan11-1111-1111-1111-111111111111",
|
|
992
|
+
cwd: "/Users/u/only",
|
|
993
|
+
file: "session.v4.jsonl.zstd",
|
|
994
|
+
titles: [["provider", "孤儿子会话"]] ,
|
|
995
|
+
header: { origin: "subagent", parentSession: "session-gone9999-9999-9999-9999-999999999999", delegationDepth: 1 },
|
|
996
|
+
},
|
|
997
|
+
]);
|
|
998
|
+
resetTitleMemo();
|
|
999
|
+
const s = readDshSession(localFor(DSH_APP_CMD), { home, env: {}, meta: { session_id: "session-orphan11-1111-1111-1111-111111111111" } });
|
|
1000
|
+
check("父会话不见了就停在子会话,不返回空", s?.title === "孤儿子会话" && s?.cwd === "/Users/u/only", JSON.stringify(s));
|
|
1001
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
{
|
|
1005
|
+
const home = makeDshHome([
|
|
1006
|
+
{ id: "session-pmain111-1111-1111-1111-111111111111", cwd: "/Users/u/repo", file: "session.v4.jsonl.zstd", titles: [["provider", "主会话名"]] },
|
|
1007
|
+
{
|
|
1008
|
+
id: "session-psub222-2222-2222-2222-222222222222",
|
|
1009
|
+
cwd: "/Users/u/repo",
|
|
1010
|
+
file: "session.v4.jsonl.zstd",
|
|
1011
|
+
titles: [["fallback", "把标签页列出来"]],
|
|
1012
|
+
header: { origin: "subagent", parentSession: "session-pmain111-1111-1111-1111-111111111111", delegationDepth: 1, agentPreset: "cordis" },
|
|
1013
|
+
},
|
|
1014
|
+
]);
|
|
1015
|
+
resetTitleMemo();
|
|
1016
|
+
const subMeta = { session_id: "session-psub222-2222-2222-2222-222222222222" };
|
|
1017
|
+
const s = readDshSession(localFor(DSH_APP_CMD), { home, env: {}, meta: subMeta });
|
|
1018
|
+
check("会话名那行 = 主会话名", s?.title === "主会话名", JSON.stringify(s));
|
|
1019
|
+
const t = readDshSubagent(subMeta, localFor(DSH_APP_CMD), { home, env: {} });
|
|
1020
|
+
check("task 那行 = 子任务自己的名字(fallback 也认)", t?.label === "把标签页列出来", JSON.stringify(t));
|
|
1021
|
+
check("taskType = 子会话的 preset", t?.type === "cordis", JSON.stringify(t));
|
|
1022
|
+
resetTitleMemo();
|
|
1023
|
+
check(
|
|
1024
|
+
"主会话不发 task 这一行",
|
|
1025
|
+
readDshSubagent({ session_id: "session-pmain111-1111-1111-1111-111111111111" }, localFor(DSH_APP_CMD), { home, env: {} }) === null
|
|
1026
|
+
);
|
|
1027
|
+
resetTitleMemo();
|
|
1028
|
+
check("没有 _meta 就没有 task", readDshSubagent(null, localFor(DSH_APP_CMD), { home, env: {} }) === null);
|
|
1029
|
+
check("不是 dsh 的客户端不查盘", readDshSubagent(subMeta, localFor("node /a/other.js"), { home, env: {} }) === null);
|
|
1030
|
+
check("id 不存在就没有 task", readDshSubagent({ session_id: "session-nope0000-0000-0000-0000-000000000000" }, localFor(DSH_APP_CMD), { home, env: {} }) === null);
|
|
840
1031
|
fs.rmSync(home, { recursive: true, force: true });
|
|
841
1032
|
}
|
|
842
1033
|
|
|
@@ -851,7 +1042,7 @@ if (typeof zlib.zstdCompressSync !== "function") {
|
|
|
851
1042
|
frames([ev({ type: "session", version: 0, id: "s", createdAt: 1, cwd: proj, delegationDepth: 0 }), ev({ type: "session/title", seq: 10, data: { title: "改注册器", source: { kind: "provider" } } })])
|
|
852
1043
|
);
|
|
853
1044
|
resetTitleMemo();
|
|
854
|
-
const idn = readSessionIdentity(localFor(), { home, tmp: path.join(home, "unused-tmp") });
|
|
1045
|
+
const idn = readSessionIdentity(localFor(), { home, env: {}, tmp: path.join(home, "unused-tmp") });
|
|
855
1046
|
check("标题与工作区同源于同一段会话", idn.title === "改注册器" && idn.workspace === "my-cool-repo" && idn.workspaceKind === "git", JSON.stringify(idn));
|
|
856
1047
|
resetTitleMemo();
|
|
857
1048
|
const other = readSessionIdentity({ clientCommand: "node /a/b.js", clientPid: 1, hostSessionId: null, sessionName: null }, { home, env: {} });
|
|
@@ -1079,11 +1270,11 @@ console.log("\n\x1b[1mAntigravity:数据目录自报 + 会话库里的工作
|
|
|
1079
1270
|
fs.mkdirSync(path.join(proj, ".git"), { recursive: true });
|
|
1080
1271
|
writeRaw(home, `${ID}.db`, agBytes(ID, proj));
|
|
1081
1272
|
resetTitleMemo();
|
|
1082
|
-
const idn = readSessionIdentity(localFor(), { home, meta: metaFor(), env: {}, tmp: path.join(home, "unused-tmp") });
|
|
1273
|
+
const idn = readSessionIdentity(localFor(), { home, env: {}, meta: metaFor(), env: {}, tmp: path.join(home, "unused-tmp") });
|
|
1083
1274
|
check("readSessionIdentity 接上了:工作区来自会话库", idn.workspace === "ag-wired" && idn.workspaceKind === "git", JSON.stringify(idn));
|
|
1084
1275
|
check("库里没有 steps 表时标题是 null,工作区照旧", idn.title === null, JSON.stringify(idn));
|
|
1085
1276
|
resetTitleMemo();
|
|
1086
|
-
const bare = readSessionIdentity(localFor(), { home, meta: { progressToken: "p1" }, tmp: path.join(home, "unused-tmp") });
|
|
1277
|
+
const bare = readSessionIdentity(localFor(), { home, env: {}, meta: { progressToken: "p1" }, tmp: path.join(home, "unused-tmp") });
|
|
1087
1278
|
check("同一个客户端、帧里没有会话 id 时不盖工作区", bare.workspace === null, JSON.stringify(bare));
|
|
1088
1279
|
fs.rmSync(home, { recursive: true, force: true });
|
|
1089
1280
|
}
|
|
@@ -1112,12 +1303,25 @@ console.log("\n\x1b[1mAntigravity:数据目录自报 + 会话库里的工作
|
|
|
1112
1303
|
: Buffer.alloc(0),
|
|
1113
1304
|
]);
|
|
1114
1305
|
const writeDb = (file, rows, { wal = false } = {}) => {
|
|
1115
|
-
const
|
|
1116
|
-
wal ? "PRAGMA journal_mode=WAL;" : ""
|
|
1117
|
-
"CREATE TABLE steps (idx INTEGER, step_type INTEGER, status INTEGER, has_subtrajectory INTEGER, metadata BLOB, error_details BLOB, permissions BLOB, task_details BLOB, render_info BLOB, step_payload BLOB, step_format INTEGER);"
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1306
|
+
const ddl =
|
|
1307
|
+
(wal ? "PRAGMA journal_mode=WAL;" : "") +
|
|
1308
|
+
"CREATE TABLE steps (idx INTEGER, step_type INTEGER, status INTEGER, has_subtrajectory INTEGER, metadata BLOB, error_details BLOB, permissions BLOB, task_details BLOB, render_info BLOB, step_payload BLOB, step_format INTEGER);";
|
|
1309
|
+
const inserts = rows.map(
|
|
1310
|
+
([idx, type, payload]) =>
|
|
1311
|
+
`INSERT INTO steps (idx, step_type, step_payload) VALUES (${idx}, ${type}, ${payload ? `x'${payload.toString("hex")}'` : "NULL"});`
|
|
1312
|
+
);
|
|
1313
|
+
if (NODE_SQLITE_TEST) {
|
|
1314
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
1315
|
+
const db = new NODE_SQLITE_TEST(file);
|
|
1316
|
+
try {
|
|
1317
|
+
db.exec(ddl);
|
|
1318
|
+
for (const s of inserts) db.exec(s);
|
|
1319
|
+
} finally {
|
|
1320
|
+
db.close();
|
|
1321
|
+
}
|
|
1322
|
+
return;
|
|
1323
|
+
}
|
|
1324
|
+
execFileSync(SQLITE, [file], { input: `${ddl}\n${inserts.join("\n")}\n`, encoding: "utf8" });
|
|
1121
1325
|
};
|
|
1122
1326
|
const dbPath = (home, id = ID) => path.join(home, ".gemini", "antigravity-ide", "conversations", `${id}.db`);
|
|
1123
1327
|
const titleOf = (home, meta = metaFor(), opts = {}) => {
|
|
@@ -1450,6 +1654,25 @@ console.log("\n\x1b[1mCodex:_meta 的 thread_id 精确归属 + session_index.j
|
|
|
1450
1654
|
fs.rmSync(home, { recursive: true, force: true });
|
|
1451
1655
|
}
|
|
1452
1656
|
|
|
1657
|
+
{
|
|
1658
|
+
if (!NODE_SQLITE_TEST) {
|
|
1659
|
+
check("本机没有 node:sqlite,Codex state 库回落这条在老 Node 上验不了", false, "Node < 22.5");
|
|
1660
|
+
} else {
|
|
1661
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), "aic-cxsd-"));
|
|
1662
|
+
fs.mkdirSync(path.join(home, ".codex"), { recursive: true });
|
|
1663
|
+
const db = new NODE_SQLITE_TEST(path.join(home, ".codex", "state_5.sqlite"));
|
|
1664
|
+
db.exec("CREATE TABLE threads (id TEXT PRIMARY KEY, title TEXT NOT NULL);");
|
|
1665
|
+
db.prepare("INSERT INTO threads (id, title) VALUES (?, ?)").run(ID, "state 库里的线程名");
|
|
1666
|
+
db.close();
|
|
1667
|
+
resetTitleMemo();
|
|
1668
|
+
const t = readCodexSessionTitle(metaFor(), { home, env: {} });
|
|
1669
|
+
check("没有 session_index.jsonl(Windows):从 state 库的 threads.title 认出来", t === "state 库里的线程名", String(t));
|
|
1670
|
+
resetTitleMemo();
|
|
1671
|
+
check("state 库里没有这个 id 就是没有", readCodexSessionTitle(metaFor("00000000-0000-4000-8000-000000000000"), { home, env: {} }) === null);
|
|
1672
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1453
1676
|
{
|
|
1454
1677
|
const long = "标".repeat(80);
|
|
1455
1678
|
const home = cxHome(row(ID, long));
|
|
@@ -1717,7 +1940,7 @@ console.log("\n\x1b[1mopencode:帧里只有 progressToken,靠「这一次调
|
|
|
1717
1940
|
check("同一次调用只查一次盘", c1?.title === "获取浏览器状态原始JSON结果" && c2?.title === c1.title && reads === 1, `查了 ${reads} 次`);
|
|
1718
1941
|
|
|
1719
1942
|
check("默认落在 ~/.local/share/opencode", opencodeDataDir({ env: {}, home: "/h" }) === path.join("/h", ".local", "share", "opencode"));
|
|
1720
|
-
check("XDG_DATA_HOME 覆盖(写死路径会读到另一个安装的库)", opencodeDataDir({ env: { XDG_DATA_HOME: "/x" }, home: "/h" }) === "/x
|
|
1943
|
+
check("XDG_DATA_HOME 覆盖(写死路径会读到另一个安装的库)", opencodeDataDir({ env: { XDG_DATA_HOME: "/x" }, home: "/h" }) === path.join("/x", "opencode"));
|
|
1721
1944
|
|
|
1722
1945
|
check("认 CLI(brew 里那个真身)", isOpencodeClient("/opt/homebrew/Cellar/opencode/1.18.31/bin/opencode"));
|
|
1723
1946
|
check("认桌面端", isOpencodeClient("/Applications/OpenCode.app/Contents/MacOS/OpenCode"));
|