@liang-hz/agent-in-chrome 0.55.1 → 0.55.5
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 +12 -12
- package/README.md +12 -12
- package/docs/AGENTS.md +19 -1
- package/extension/manifest.json +1 -1
- package/extension/sw.js +91 -25
- package/mcp/agent-identity.mjs +576 -49
- package/mcp/cdp/browser-launch.mjs +160 -48
- package/mcp/config.mjs +51 -7
- package/mcp/server.mjs +17 -26
- package/native-host/host.mjs +28 -0
- package/package.json +1 -1
- package/scripts/agents.mjs +11 -0
- package/scripts/borrow-login.mjs +6 -2
- package/scripts/e2e-sweep.mjs +3 -4
- package/scripts/e2e.mjs +81 -37
- package/scripts/install.mjs +73 -7
- package/scripts/launcher-spawn.mjs +22 -0
- package/scripts/pack-crx.mjs +2 -1
- package/scripts/test-agents.mjs +105 -24
- package/scripts/test-config.mjs +94 -4
- package/scripts/test-e2e-sweep.mjs +7 -2
- package/scripts/test-identity.mjs +914 -66
- package/scripts/test-install-skill.mjs +37 -2
- package/scripts/test-protocol.mjs +195 -3
- package/scripts/test-security.mjs +38 -17
- package/scripts/test-sw.mjs +103 -18
- package/skills/install-agent-in-chrome/SKILL.md +2 -2
package/mcp/agent-identity.mjs
CHANGED
|
@@ -70,6 +70,12 @@ export function bundleMatch(command) {
|
|
|
70
70
|
return name ? { name, appDir: `${outerHead}.app` } : null;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
function livesInBundle(command, appDir) {
|
|
74
|
+
if (!appDir) return false;
|
|
75
|
+
const s = String(command || "").trim().replace(/^"/, "");
|
|
76
|
+
return s.startsWith(`${appDir}/`);
|
|
77
|
+
}
|
|
78
|
+
|
|
73
79
|
const bundleVersionMemo = new Map();
|
|
74
80
|
export function readBundleVersion(appDir, { exec = execFileSync } = {}) {
|
|
75
81
|
if (!appDir || typeof appDir !== "string") return null;
|
|
@@ -136,9 +142,13 @@ export function exePathOf(command) {
|
|
|
136
142
|
/*
|
|
137
143
|
* 沿父进程链找形态与品牌的证据,先撞见哪个算哪个:
|
|
138
144
|
*
|
|
139
|
-
* 撞见有终端的进程
|
|
140
|
-
*
|
|
141
|
-
* 一路走到 launchd 都没终端
|
|
145
|
+
* 撞见有终端的进程 → CLI(从命令行起来的)
|
|
146
|
+
* 撞见**客户端自己的** .app → 桌面端,顺带拿到包名当品牌候选
|
|
147
|
+
* 一路走到 launchd 都没终端 → 桌面端(GUI 进程的典型形状,如 ZCode)
|
|
148
|
+
*
|
|
149
|
+
* 第二条的「自己的」是必要条件:链上撞见的 `.app` 未必装着客户端——从桌面端里起的
|
|
150
|
+
* CLI 就会撞见**启动它的那个 app**。这种包不认,就地返回「无证据」,让上层回落到
|
|
151
|
+
* 客户端自报的名字(继续往上走也一样错,上面只有那个 app 的其它进程)。
|
|
142
152
|
*
|
|
143
153
|
* Windows 上三条证据各有对应物,判据不同、结论一模一样:
|
|
144
154
|
*
|
|
@@ -158,6 +168,7 @@ export function walkSurface(startPid, snap, { maxHops = 6, platform = process.pl
|
|
|
158
168
|
const none = { surface: null, brand: null, appDir: null, why: "无证据" };
|
|
159
169
|
let pid = Number(startPid);
|
|
160
170
|
let prev = null;
|
|
171
|
+
const startCommand = snap.get(pid)?.command;
|
|
161
172
|
for (let hop = 0; hop < maxHops; hop++) {
|
|
162
173
|
if (!Number.isInteger(pid) || pid <= 1) break;
|
|
163
174
|
const p = snap.get(pid);
|
|
@@ -166,7 +177,10 @@ export function walkSurface(startPid, snap, { maxHops = 6, platform = process.pl
|
|
|
166
177
|
if (win && isWinTerminal(p.name)) return { surface: "cli", brand: binShimName(p.command), appDir: null, why: `${p.name}@${pid}` };
|
|
167
178
|
if (win && isWinRoot(p.name)) return prev ? guiSurface(prev, `${p.name} 直属@${pid}`) : none;
|
|
168
179
|
const b = bundleMatch(p.command);
|
|
169
|
-
if (b)
|
|
180
|
+
if (b) {
|
|
181
|
+
if (!livesInBundle(startCommand, b.appDir)) return none;
|
|
182
|
+
return { surface: "app", brand: b.name, appDir: b.appDir, why: `${b.name}.app@${pid}` };
|
|
183
|
+
}
|
|
170
184
|
if (!Number.isInteger(p.ppid) || p.ppid <= 1) {
|
|
171
185
|
return { surface: "app", brand: plainName(p.command) || binShimName(p.command), appDir: null, why: `launchd 直属、无终端@${pid}` };
|
|
172
186
|
}
|
|
@@ -432,9 +446,64 @@ export function readClaudeSubagent(meta, local, { fs = fsMod, home = osMod.homed
|
|
|
432
446
|
return null;
|
|
433
447
|
}
|
|
434
448
|
|
|
435
|
-
export function
|
|
436
|
-
const
|
|
449
|
+
export function workbuddyConfigDir({ env = process.env, home = osMod.homedir() } = {}) {
|
|
450
|
+
const d = typeof env.WORKBUDDY_CONFIG_DIR === "string" ? env.WORKBUDDY_CONFIG_DIR.trim() : "";
|
|
451
|
+
return d || path.join(home, ".workbuddy");
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
export function readWorkbuddySessionTitle({
|
|
455
|
+
env = process.env,
|
|
456
|
+
home = osMod.homedir(),
|
|
457
|
+
fs = fsMod,
|
|
458
|
+
exec = execFileSync,
|
|
459
|
+
alive = pidAlive,
|
|
460
|
+
meta = null,
|
|
461
|
+
enginePid = null,
|
|
462
|
+
} = {}) {
|
|
463
|
+
const dir = workbuddyConfigDir({ env, home });
|
|
437
464
|
if (!path.isAbsolute(dir)) return null;
|
|
465
|
+
const id =
|
|
466
|
+
workbuddyConversationId(meta) ||
|
|
467
|
+
workbuddyEngineSession(dir, enginePid, { fs }) ||
|
|
468
|
+
workbuddyOnlyLiveSession(dir, { fs, alive });
|
|
469
|
+
if (!id) return null;
|
|
470
|
+
/* id 会以绑定参数进查询(CLI 退路里才落成字面量,本层有转义兜底)。形状锚
|
|
471
|
+
* CONV_UUID_RE 照旧不许放宽:它是这条链的第一道闸,不是最后一道。 */
|
|
472
|
+
try {
|
|
473
|
+
const rows = sqliteColumn(
|
|
474
|
+
path.join(dir, "workbuddy.db"),
|
|
475
|
+
"select coalesce(custom_title, title) from sessions where id=? and deleted_at is null",
|
|
476
|
+
[id],
|
|
477
|
+
exec
|
|
478
|
+
);
|
|
479
|
+
return clip(String(rows[0] ?? "").trim(), 60);
|
|
480
|
+
} catch {
|
|
481
|
+
return null;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export function workbuddyConversationId(meta) {
|
|
486
|
+
if (!meta || typeof meta !== "object") return null;
|
|
487
|
+
const direct = String(meta["workbuddy.ai/conversationId"] ?? "").trim();
|
|
488
|
+
const m = /(?:^|[,\s])codebuddy\.session_id=([^\s,;]+)/.exec(String(meta.baggage ?? ""));
|
|
489
|
+
const id = direct || (m ? m[1].trim() : "");
|
|
490
|
+
return CONV_UUID_RE.test(id) ? id : null;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
function workbuddyEngineSession(dir, enginePid, { fs = fsMod } = {}) {
|
|
494
|
+
if (!Number.isInteger(enginePid) || enginePid <= 1) return null;
|
|
495
|
+
try {
|
|
496
|
+
const d = JSON.parse(fs.readFileSync(path.join(dir, "sessions", `${enginePid}.json`), "utf8"));
|
|
497
|
+
if (!d || typeof d !== "object" || Number(d.pid) !== enginePid) return null;
|
|
498
|
+
if (d.kind !== "interactive") return null;
|
|
499
|
+
const sid = String(d.sessionId || "");
|
|
500
|
+
return CONV_UUID_RE.test(sid) ? sid : null;
|
|
501
|
+
} catch {
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
function workbuddyOnlyLiveSession(dir, { fs = fsMod, alive = pidAlive } = {}) {
|
|
438
507
|
const live = [];
|
|
439
508
|
try {
|
|
440
509
|
for (const f of fs.readdirSync(path.join(dir, "sessions")).slice(0, 100)) {
|
|
@@ -443,7 +512,7 @@ export function readWorkbuddySessionTitle({ env = process.env, fs = fsMod, exec
|
|
|
443
512
|
const d = JSON.parse(fs.readFileSync(path.join(dir, "sessions", f), "utf8"));
|
|
444
513
|
if (d?.kind !== "interactive") continue;
|
|
445
514
|
const sid = String(d.sessionId || "");
|
|
446
|
-
if (
|
|
515
|
+
if (!CONV_UUID_RE.test(sid)) continue;
|
|
447
516
|
if (!Number.isInteger(d.pid) || d.pid <= 1 || !alive(d.pid)) continue;
|
|
448
517
|
live.push(sid);
|
|
449
518
|
} catch {}
|
|
@@ -451,17 +520,7 @@ export function readWorkbuddySessionTitle({ env = process.env, fs = fsMod, exec
|
|
|
451
520
|
} catch {
|
|
452
521
|
return null;
|
|
453
522
|
}
|
|
454
|
-
|
|
455
|
-
try {
|
|
456
|
-
const out = exec(
|
|
457
|
-
process.platform === "win32" ? "sqlite3" : "/usr/bin/sqlite3",
|
|
458
|
-
["-readonly", path.join(dir, "workbuddy.db"), `select coalesce(custom_title, title) from sessions where id='${live[0]}' and deleted_at is null`],
|
|
459
|
-
{ encoding: "utf8", timeout: 2000 }
|
|
460
|
-
);
|
|
461
|
-
return clip(String(out || "").trim(), 60);
|
|
462
|
-
} catch {
|
|
463
|
-
return null;
|
|
464
|
-
}
|
|
523
|
+
return live.length === 1 ? live[0] : null;
|
|
465
524
|
}
|
|
466
525
|
|
|
467
526
|
export function pidAlive(pid) {
|
|
@@ -527,10 +586,19 @@ const titleMemo = new Map();
|
|
|
527
586
|
const TITLE_MISS_BACKOFF_MS = 20_000;
|
|
528
587
|
const TITLE_MISS_BACKOFF_MAX_MS = 300_000;
|
|
529
588
|
const TITLE_MEMO_MAX = 200;
|
|
530
|
-
function missBackoff(misses) {
|
|
531
|
-
return Math.min(
|
|
589
|
+
function missBackoff(misses, base = TITLE_MISS_BACKOFF_MS) {
|
|
590
|
+
return Math.min(base * 2 ** Math.max(0, misses - 1), TITLE_MISS_BACKOFF_MAX_MS);
|
|
532
591
|
}
|
|
533
|
-
|
|
592
|
+
/*
|
|
593
|
+
* 记忆化。查到的值原样存着(默认是标题字符串,opencode 那条存的是
|
|
594
|
+
* `{title, directory}` 一个小对象——这里只管「命中就不再查」,不管值是什么形状)。
|
|
595
|
+
*
|
|
596
|
+
* `missRetryMs` 只有 opencode 那条路在改:它的「没查到」有两种成因,一种会自己好
|
|
597
|
+
* (对账窗口里那行 part 还没落盘,一两秒后就有了),一种不会(这个客户端根本不是
|
|
598
|
+
* opencode)。默认那套 20s→5min 的指数退避是为后者设计的,用在它身上会把第一种
|
|
599
|
+
* 挡死——而 refreshAgentInfo 的 TTL 只有 5s,退避比 TTL 长等于永远等不到重试。
|
|
600
|
+
*/
|
|
601
|
+
function memoTitle(key, lookup, now = Date.now(), missRetryMs = null) {
|
|
534
602
|
const hit = titleMemo.get(key);
|
|
535
603
|
if (hit && (hit.title || now < hit.nextTryAt)) return hit.title;
|
|
536
604
|
let title = null;
|
|
@@ -541,7 +609,7 @@ function memoTitle(key, lookup, now = Date.now()) {
|
|
|
541
609
|
}
|
|
542
610
|
if (titleMemo.size >= TITLE_MEMO_MAX) titleMemo.clear();
|
|
543
611
|
const misses = title ? 0 : (hit?.misses || 0) + 1;
|
|
544
|
-
titleMemo.set(key, { title, misses, nextTryAt: now + missBackoff(misses) });
|
|
612
|
+
titleMemo.set(key, { title, misses, nextTryAt: now + missBackoff(misses, missRetryMs ?? TITLE_MISS_BACKOFF_MS) });
|
|
545
613
|
return title;
|
|
546
614
|
}
|
|
547
615
|
|
|
@@ -549,6 +617,59 @@ export function resetTitleMemo() {
|
|
|
549
617
|
titleMemo.clear();
|
|
550
618
|
dshCwdMemo.clear();
|
|
551
619
|
agWsMemo.clear();
|
|
620
|
+
dshTalkMemo.clear();
|
|
621
|
+
dshHeaderMemo.clear();
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// 顶层 await:只等一个内置模块的 import(微任务级),之后所有读库函数保持同步——
|
|
625
|
+
// 调用方(每帧的身份刷新)是同步上下文,等不起 promise。
|
|
626
|
+
//
|
|
627
|
+
// import 本身会把 ExperimentalWarning 打上 stderr(首次加载 node:sqlite 时发一次)。
|
|
628
|
+
// server 走 stdio,stderr 是日志的家,一点噪声都会进客户端的日志面板,一条实验
|
|
629
|
+
// 警告都嫌多。警告是经 process.emitWarning 发出来的,只在这一次 import 的窗口里
|
|
630
|
+
// 换上一张只滤这一条的滤网,走完立刻还原;其余警告原样放行。加
|
|
631
|
+
// process.on("warning") 监听压不掉它——默认打印器照跑。
|
|
632
|
+
const NODE_SQLITE = await (async () => {
|
|
633
|
+
const origEmitWarning = process.emitWarning;
|
|
634
|
+
process.emitWarning = function (warning, ...args) {
|
|
635
|
+
const msg = typeof warning === "string" ? warning : warning?.message;
|
|
636
|
+
if (typeof msg === "string" && /^SQLite is an experimental feature/.test(msg)) return;
|
|
637
|
+
return origEmitWarning.call(process, warning, ...args);
|
|
638
|
+
};
|
|
639
|
+
try {
|
|
640
|
+
return (await import("node:sqlite").catch(() => null))?.DatabaseSync ?? null;
|
|
641
|
+
} finally {
|
|
642
|
+
process.emitWarning = origEmitWarning;
|
|
643
|
+
}
|
|
644
|
+
})();
|
|
645
|
+
|
|
646
|
+
/* 只给测试用:换掉读库实现(传 null 恢复默认),让四家读取器不必真库也能验 */
|
|
647
|
+
let sqliteColumnImpl = null;
|
|
648
|
+
export function setSqliteColumn(fn) {
|
|
649
|
+
sqliteColumnImpl = fn;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
export function sqliteColumn(db, sql, params = [], exec = execFileSync) {
|
|
653
|
+
if (sqliteColumnImpl) return sqliteColumnImpl(db, sql, params);
|
|
654
|
+
if (NODE_SQLITE) {
|
|
655
|
+
if (!fsMod.existsSync(db)) throw new Error(`no such db: ${db}`);
|
|
656
|
+
const d = new NODE_SQLITE(db, { readOnly: true });
|
|
657
|
+
try {
|
|
658
|
+
return d.prepare(sql).all(...params).map((row) => Object.values(row)[0]);
|
|
659
|
+
} finally {
|
|
660
|
+
try {
|
|
661
|
+
d.close();
|
|
662
|
+
} catch {}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
const bin = process.platform === "win32" ? "sqlite3" : "/usr/bin/sqlite3";
|
|
666
|
+
let i = 0;
|
|
667
|
+
const literal = sql.replace(/\?/g, () => `'${String(params[i++] ?? "").replace(/'/g, "''")}'`);
|
|
668
|
+
const out = exec(bin, ["-readonly", db, literal], { encoding: "utf8", timeout: 2000, maxBuffer: 16 << 20 });
|
|
669
|
+
return String(out || "")
|
|
670
|
+
.split("\n")
|
|
671
|
+
.map((l) => l.replace(/\r$/, ""))
|
|
672
|
+
.filter((l, idx, arr) => !(idx === arr.length - 1 && l === ""));
|
|
552
673
|
}
|
|
553
674
|
|
|
554
675
|
export function zcodeDataDir({ env = process.env, home = osMod.homedir() } = {}) {
|
|
@@ -564,12 +685,12 @@ export function readZcodeSessionTitle(meta, { env = process.env, home = osMod.ho
|
|
|
564
685
|
if (!isMain && !isSub) return null;
|
|
565
686
|
const db = path.join(zcodeDataDir({ env, home }), "cli", "db", "db.sqlite");
|
|
566
687
|
if (!fs.existsSync(db)) return null;
|
|
567
|
-
const sql = isSub
|
|
568
|
-
? `select title from session where id=(select parent_id from session where id='${id}') and title_source in ('generated','custom')`
|
|
569
|
-
: `select title from session where id='${id}' and title_source in ('generated','custom')`;
|
|
570
688
|
return memoTitle(`zcode:${db}:${id}`, () => {
|
|
571
|
-
const
|
|
572
|
-
|
|
689
|
+
const sql = isSub
|
|
690
|
+
? "select title from session where id=(select parent_id from session where id=?) and title_source in ('generated','custom')"
|
|
691
|
+
: "select title from session where id=? and title_source in ('generated','custom')";
|
|
692
|
+
const rows = sqliteColumn(db, sql, [id], exec);
|
|
693
|
+
return clip(String(rows[0] ?? "").trim(), 60);
|
|
573
694
|
});
|
|
574
695
|
}
|
|
575
696
|
|
|
@@ -734,9 +855,15 @@ export function dshHome({ env = process.env, home = osMod.homedir() } = {}) {
|
|
|
734
855
|
return path.isAbsolute(d) ? d : path.join(home, ".dsh");
|
|
735
856
|
}
|
|
736
857
|
|
|
858
|
+
const DSH_DESKTOP_APP = /DeepSeek Harness\.app[\\/]Contents[\\/]MacOS[\\/]/;
|
|
859
|
+
|
|
737
860
|
export function isDshClient(clientCommand) {
|
|
738
861
|
const s = String(clientCommand || "");
|
|
739
|
-
return
|
|
862
|
+
return (
|
|
863
|
+
/@deepseek-ai[\\/]dsh[\\/]/.test(s) ||
|
|
864
|
+
/[\\/]\.bin[\\/]dsh(\.cmd|\.exe|\.bat)?(\s|$)/.test(s) ||
|
|
865
|
+
DSH_DESKTOP_APP.test(s)
|
|
866
|
+
);
|
|
740
867
|
}
|
|
741
868
|
|
|
742
869
|
export function decodeZstdFrames(buf, { zlib = zlibMod } = {}) {
|
|
@@ -756,13 +883,112 @@ export function decodeZstdFrames(buf, { zlib = zlibMod } = {}) {
|
|
|
756
883
|
|
|
757
884
|
const dshCwdMemo = new Map();
|
|
758
885
|
|
|
886
|
+
const DSH_LOG_NAME = /^session(?:\.v(\d+))?\.jsonl\.zstd$/;
|
|
887
|
+
|
|
888
|
+
function dshLogFile(dir, fs = fsMod) {
|
|
889
|
+
let names;
|
|
890
|
+
try {
|
|
891
|
+
names = fs.readdirSync(dir);
|
|
892
|
+
} catch {
|
|
893
|
+
return null;
|
|
894
|
+
}
|
|
895
|
+
let best = null;
|
|
896
|
+
let bestV = -1;
|
|
897
|
+
for (const n of names) {
|
|
898
|
+
const m = DSH_LOG_NAME.exec(n);
|
|
899
|
+
if (!m) continue;
|
|
900
|
+
const v = m[1] === undefined ? 0 : Number(m[1]);
|
|
901
|
+
if (v <= bestV) continue;
|
|
902
|
+
bestV = v;
|
|
903
|
+
best = path.join(dir, n);
|
|
904
|
+
}
|
|
905
|
+
return best;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
const dshTalkMemo = new Map();
|
|
909
|
+
|
|
910
|
+
function dshHasConversation(c, fs = fsMod) {
|
|
911
|
+
let key;
|
|
912
|
+
try {
|
|
913
|
+
const st = fs.statSync(c.file);
|
|
914
|
+
key = `${c.file}:${st.mtimeMs}:${st.size}`;
|
|
915
|
+
} catch {
|
|
916
|
+
return false;
|
|
917
|
+
}
|
|
918
|
+
const hit = dshTalkMemo.get(key);
|
|
919
|
+
if (hit !== undefined) return hit;
|
|
920
|
+
let ok = false;
|
|
921
|
+
try {
|
|
922
|
+
const text = decodeZstdFrames(fs.readFileSync(c.file));
|
|
923
|
+
ok = typeof text === "string" && (text.includes('"type":"user/message"') || text.includes('"type":"session/title"'));
|
|
924
|
+
} catch {
|
|
925
|
+
ok = false;
|
|
926
|
+
}
|
|
927
|
+
if (dshTalkMemo.size >= TITLE_MEMO_MAX) dshTalkMemo.clear();
|
|
928
|
+
dshTalkMemo.set(key, ok);
|
|
929
|
+
return ok;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
const DSH_SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
933
|
+
|
|
934
|
+
function dshLogById(root, id, fs) {
|
|
935
|
+
if (!DSH_SESSION_ID.test(id)) return null;
|
|
936
|
+
let dirs;
|
|
937
|
+
try {
|
|
938
|
+
dirs = fs.readdirSync(root);
|
|
939
|
+
} catch {
|
|
940
|
+
return null;
|
|
941
|
+
}
|
|
942
|
+
for (const d of dirs.slice(0, 500)) {
|
|
943
|
+
const file = dshLogFile(path.join(root, d, id), fs);
|
|
944
|
+
if (file) return { id, file };
|
|
945
|
+
}
|
|
946
|
+
return null;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
const dshHeaderMemo = new Map();
|
|
950
|
+
|
|
951
|
+
function dshHeader(file, fs) {
|
|
952
|
+
const hit = dshHeaderMemo.get(file);
|
|
953
|
+
if (hit !== undefined) return hit;
|
|
954
|
+
let h = null;
|
|
955
|
+
try {
|
|
956
|
+
const first = zlibMod.zstdDecompressSync ? zlibMod.zstdDecompressSync(fs.readFileSync(file)) : null;
|
|
957
|
+
const parsed = first ? JSON.parse(first.toString("utf8").split("\n")[0]) : null;
|
|
958
|
+
if (parsed && parsed.type === "session") h = parsed;
|
|
959
|
+
} catch {}
|
|
960
|
+
if (dshHeaderMemo.size >= TITLE_MEMO_MAX) dshHeaderMemo.clear();
|
|
961
|
+
dshHeaderMemo.set(file, h);
|
|
962
|
+
return h;
|
|
963
|
+
}
|
|
964
|
+
|
|
759
965
|
/*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
966
|
+
* 子任务会话上溯到它所属的主会话。
|
|
967
|
+
*
|
|
968
|
+
* 子会话的头里有 `origin:"subagent"` 和 `parentSession`(dsH 侧写入点见
|
|
969
|
+
* subagent/child-agent.ts 的 childSessionMeta)。**卡片上「会话名」只有一行**,它要回答的
|
|
970
|
+
* 是「这些页属于我哪一段对话」——而子任务的标题就是那段委派提示词的开头,盖上去等于把
|
|
971
|
+
* 用户刚说的话又抄一遍。这条口径与 ZCode 顺着 parent_id 报主会话标题完全一致(那边注释
|
|
972
|
+
* 原话:「拿 subagent 的名字盖掉主会话的名字是显示错,不是少显示」)。
|
|
973
|
+
*
|
|
974
|
+
* 工作区**也一起取主会话的**:子会话虽然继承了父会话的 cwd,但同一条归属链上取回来更硬——
|
|
975
|
+
* 不去依赖「继承」这个实现细节。
|
|
976
|
+
*
|
|
977
|
+
* 父会话解不出来(已被清理、读不动)就停在能解到的那一层:宁可显示子会话,也不显示空。
|
|
762
978
|
*/
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
979
|
+
function dshRootOf(root, start, fs, { maxHops = 8 } = {}) {
|
|
980
|
+
let cur = start;
|
|
981
|
+
for (let i = 0; i < maxHops; i++) {
|
|
982
|
+
const h = dshHeader(cur.file, fs);
|
|
983
|
+
if (!h || (h.origin !== "subagent" && typeof h.parentSession !== "string")) return cur;
|
|
984
|
+
const up = typeof h.parentSession === "string" ? dshLogById(root, h.parentSession, fs) : null;
|
|
985
|
+
if (!up) return cur;
|
|
986
|
+
cur = up;
|
|
987
|
+
}
|
|
988
|
+
return cur;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
function dshPickLive(root, fs, now) {
|
|
766
992
|
const live = [];
|
|
767
993
|
let dirs;
|
|
768
994
|
try {
|
|
@@ -778,17 +1004,29 @@ export function readDshSession(local, { env = process.env, home = osMod.homedir(
|
|
|
778
1004
|
continue;
|
|
779
1005
|
}
|
|
780
1006
|
for (const s of subs) {
|
|
781
|
-
|
|
782
|
-
|
|
1007
|
+
const file = dshLogFile(path.join(root, d, s), fs);
|
|
1008
|
+
if (!file) continue;
|
|
783
1009
|
try {
|
|
784
1010
|
const st = fs.statSync(file);
|
|
785
1011
|
if (now - st.mtimeMs <= DSH_LIVE_WINDOW_MS) live.push({ id: s, file });
|
|
786
1012
|
} catch {}
|
|
787
|
-
if (live.length > 1) return null;
|
|
788
1013
|
}
|
|
789
1014
|
}
|
|
790
|
-
|
|
791
|
-
|
|
1015
|
+
const talking = live.length === 1 ? live : live.filter((c) => dshHasConversation(c, fs));
|
|
1016
|
+
return talking.length === 1 ? talking[0] : null;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
/*
|
|
1020
|
+
* 恰好一个活跃会话时返回 { id, title, cwd };分不出(0 个或多个活跃)就 null。
|
|
1021
|
+
* title 可能暂缺(LLM 标题是首轮之后才生成的)——cwd 先到先用,两者不互相拖累。
|
|
1022
|
+
*/
|
|
1023
|
+
export function readDshSession(local, { env = process.env, home = osMod.homedir(), fs = fsMod, now = Date.now(), meta = null } = {}) {
|
|
1024
|
+
if (!local || !isDshClient(local.clientCommand)) return null;
|
|
1025
|
+
const root = path.join(dshHome({ env, home }), "sessions");
|
|
1026
|
+
const asked = meta && typeof meta === "object" && typeof meta.session_id === "string" ? meta.session_id.trim() : "";
|
|
1027
|
+
const picked = (asked ? dshLogById(root, asked, fs) : null) || dshPickLive(root, fs, now);
|
|
1028
|
+
if (!picked) return null;
|
|
1029
|
+
const { id, file } = dshRootOf(root, picked, fs);
|
|
792
1030
|
|
|
793
1031
|
let cwd = dshCwdMemo.get(id);
|
|
794
1032
|
const title = memoTitle(`dsh:${file}`, () => {
|
|
@@ -837,9 +1075,52 @@ export function readDshSession(local, { env = process.env, home = osMod.homedir(
|
|
|
837
1075
|
return { id, title: title || null, cwd: cwd || null };
|
|
838
1076
|
}
|
|
839
1077
|
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1078
|
+
function dshOwnTitle(file, fs) {
|
|
1079
|
+
return memoTitle(`dsh-own:${file}`, () => {
|
|
1080
|
+
let text;
|
|
1081
|
+
try {
|
|
1082
|
+
text = decodeZstdFrames(fs.readFileSync(file));
|
|
1083
|
+
} catch {
|
|
1084
|
+
return null;
|
|
1085
|
+
}
|
|
1086
|
+
if (!text) return null;
|
|
1087
|
+
let found = null;
|
|
1088
|
+
for (const line of text.split("\n")) {
|
|
1089
|
+
if (!line.includes('"session/title"')) continue;
|
|
1090
|
+
try {
|
|
1091
|
+
const ev = JSON.parse(line);
|
|
1092
|
+
if (ev?.type === "session/title") {
|
|
1093
|
+
const t = clip(ev.data?.title, 60);
|
|
1094
|
+
if (t) found = t;
|
|
1095
|
+
}
|
|
1096
|
+
} catch {}
|
|
1097
|
+
}
|
|
1098
|
+
return found;
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
export function readDshSubagent(meta, local, { env = process.env, home = osMod.homedir(), fs = fsMod } = {}) {
|
|
1103
|
+
if (!local || !isDshClient(local.clientCommand)) return null;
|
|
1104
|
+
const id = meta && typeof meta === "object" && typeof meta.session_id === "string" ? meta.session_id.trim() : "";
|
|
1105
|
+
if (!id) return null;
|
|
1106
|
+
const own = dshLogById(path.join(dshHome({ env, home }), "sessions"), id, fs);
|
|
1107
|
+
if (!own) return null;
|
|
1108
|
+
const h = dshHeader(own.file, fs);
|
|
1109
|
+
if (!h || (h.origin !== "subagent" && typeof h.parentSession !== "string")) return null;
|
|
1110
|
+
const label = dshOwnTitle(own.file, fs);
|
|
1111
|
+
const type = typeof h.agentPreset === "string" && h.agentPreset ? clip(h.agentPreset, 40) : null;
|
|
1112
|
+
if (!label && !type) return null;
|
|
1113
|
+
return { label: label || null, type };
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
/* 会话 id 进路径、SQL 与提取流程前的锚(安全边界,勿放宽):只放行 UUID 形状,`..`、`/`、
|
|
1117
|
+
* 引号一概进不来——id 来自 MCP 调用方给的 _meta,是外部输入。
|
|
1118
|
+
*
|
|
1119
|
+
* Antigravity 的 conversation_id、Codex 的 thread_id、WorkBuddy 的 conversationId 是同一个
|
|
1120
|
+
* 形状,**共用这一个 RegExp 对象**:三家的 id 分别会被拼进文件路径、sqlite 的 SQL 字符串、
|
|
1121
|
+
* 以及 server.mjs 的 sidFor 拼进扩展侧那张全局 sessions Map 的键。各写一份正则就是
|
|
1122
|
+
* 「将来只改一边,一边收一边不收」。 */
|
|
1123
|
+
const CONV_UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
843
1124
|
|
|
844
1125
|
export function antigravityDataDir(clientCommand, { home = osMod.homedir() } = {}) {
|
|
845
1126
|
const m = /--app_data_dir[ =]([\w.-]+)/.exec(String(clientCommand || ""));
|
|
@@ -853,7 +1134,7 @@ const AG_DB_MAX = 256 << 20;
|
|
|
853
1134
|
|
|
854
1135
|
export function antigravityConversationId(meta) {
|
|
855
1136
|
const id = meta && typeof meta === "object" ? String(meta["antigravity.google/conversation_id"] || "").trim() : "";
|
|
856
|
-
return
|
|
1137
|
+
return CONV_UUID_RE.test(id) ? id : null;
|
|
857
1138
|
}
|
|
858
1139
|
|
|
859
1140
|
function readVarint(buf, i) {
|
|
@@ -924,6 +1205,243 @@ export function readAntigravityWorkspace(meta, local, { fs = fsMod, home = osMod
|
|
|
924
1205
|
return dir;
|
|
925
1206
|
}
|
|
926
1207
|
|
|
1208
|
+
const AG_META_STEP = 23;
|
|
1209
|
+
const AG_META_FIELD = 30;
|
|
1210
|
+
const AG_TITLE_FIELD = 4;
|
|
1211
|
+
const AG_GOAL_FIELD = 19;
|
|
1212
|
+
const AG_TMP_PREFIX = "ag-title-";
|
|
1213
|
+
const AG_STEP_MAX = 64 << 10;
|
|
1214
|
+
const AG_STEP_ROWS = 16;
|
|
1215
|
+
const AG_OUT_MAX = 8 << 20;
|
|
1216
|
+
|
|
1217
|
+
function agLenField(buf, field) {
|
|
1218
|
+
let i = 0;
|
|
1219
|
+
while (i < buf.length) {
|
|
1220
|
+
const tag = readVarint(buf, i);
|
|
1221
|
+
if (!tag) return null;
|
|
1222
|
+
const num = Math.floor(tag.value / 8);
|
|
1223
|
+
const wire = tag.value % 8;
|
|
1224
|
+
if (num === 0) return null;
|
|
1225
|
+
i = tag.next;
|
|
1226
|
+
if (wire === 2) {
|
|
1227
|
+
const len = readVarint(buf, i);
|
|
1228
|
+
if (!len || len.next + len.value > buf.length) return null;
|
|
1229
|
+
if (num === field) return buf.subarray(len.next, len.next + len.value);
|
|
1230
|
+
i = len.next + len.value;
|
|
1231
|
+
} else if (wire === 0) {
|
|
1232
|
+
const v = readVarint(buf, i);
|
|
1233
|
+
if (!v) return null;
|
|
1234
|
+
i = v.next;
|
|
1235
|
+
} else if (wire === 5) {
|
|
1236
|
+
i += 4;
|
|
1237
|
+
} else if (wire === 1) {
|
|
1238
|
+
i += 8;
|
|
1239
|
+
} else {
|
|
1240
|
+
return null;
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
return null;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
function agTitleFromRows(rows) {
|
|
1247
|
+
let fallback = null;
|
|
1248
|
+
for (const row of rows) {
|
|
1249
|
+
const metaMsg = agLenField(row, AG_META_FIELD);
|
|
1250
|
+
if (!metaMsg) continue;
|
|
1251
|
+
const t = agLenField(metaMsg, AG_TITLE_FIELD);
|
|
1252
|
+
if (t) {
|
|
1253
|
+
const s = clip(t.toString("utf8"), 60);
|
|
1254
|
+
if (s) return s;
|
|
1255
|
+
}
|
|
1256
|
+
if (fallback === null) {
|
|
1257
|
+
const g = agLenField(metaMsg, AG_GOAL_FIELD);
|
|
1258
|
+
if (g) fallback = clip(g.toString("utf8"), 60);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
return fallback;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
export function readAntigravitySessionTitle(meta, local, { fs = fsMod, home = osMod.homedir(), exec = execFileSync, tmpdir = osMod.tmpdir } = {}) {
|
|
1265
|
+
const id = antigravityConversationId(meta);
|
|
1266
|
+
if (!id) return null;
|
|
1267
|
+
const db = path.join(antigravityDataDir(local?.clientCommand, { home }), "conversations", `${id}.db`);
|
|
1268
|
+
return memoTitle(`ag:${id}`, () => {
|
|
1269
|
+
if (fs.statSync(db).size > AG_DB_MAX) return null;
|
|
1270
|
+
const dir = fs.mkdtempSync(path.join(tmpdir(), AG_TMP_PREFIX));
|
|
1271
|
+
try {
|
|
1272
|
+
const copy = path.join(dir, "conversation.db");
|
|
1273
|
+
fs.copyFileSync(db, copy);
|
|
1274
|
+
try {
|
|
1275
|
+
if (fs.statSync(`${db}-wal`).size <= AG_DB_MAX) fs.copyFileSync(`${db}-wal`, `${copy}-wal`);
|
|
1276
|
+
} catch {}
|
|
1277
|
+
const lines = sqliteColumn(
|
|
1278
|
+
copy,
|
|
1279
|
+
`select hex(step_payload) from steps where step_type = ${AG_META_STEP} and length(step_payload) <= ${AG_STEP_MAX} order by idx limit ${AG_STEP_ROWS}`,
|
|
1280
|
+
[],
|
|
1281
|
+
exec
|
|
1282
|
+
);
|
|
1283
|
+
const rows = [];
|
|
1284
|
+
for (const line of lines) {
|
|
1285
|
+
const hex = String(line ?? "").trim();
|
|
1286
|
+
if (hex && /^(?:[0-9a-f]{2})+$/i.test(hex)) rows.push(Buffer.from(hex, "hex"));
|
|
1287
|
+
}
|
|
1288
|
+
return agTitleFromRows(rows);
|
|
1289
|
+
} finally {
|
|
1290
|
+
try {
|
|
1291
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
1292
|
+
} catch {}
|
|
1293
|
+
}
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
const CODEX_INDEX_MAX = 16 << 20;
|
|
1298
|
+
const CODEX_INDEX_TAIL = 4 << 20;
|
|
1299
|
+
|
|
1300
|
+
export function codexHome({ env = process.env, home = osMod.homedir() } = {}) {
|
|
1301
|
+
const d = typeof env?.CODEX_HOME === "string" ? env.CODEX_HOME.trim() : "";
|
|
1302
|
+
return d || path.join(home, ".codex");
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
export function codexThreadId(meta) {
|
|
1306
|
+
if (!meta || typeof meta !== "object") return null;
|
|
1307
|
+
const turn = meta["x-codex-turn-metadata"];
|
|
1308
|
+
const nested = turn && typeof turn === "object" ? String(turn.thread_id ?? "").trim() : "";
|
|
1309
|
+
const id = nested || String(meta.threadId ?? "").trim();
|
|
1310
|
+
return CONV_UUID_RE.test(id) ? id : null;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
export function readCodexSessionTitle(meta, { env = process.env, home = osMod.homedir(), fs = fsMod, exec = execFileSync } = {}) {
|
|
1314
|
+
const id = codexThreadId(meta);
|
|
1315
|
+
if (!id) return null;
|
|
1316
|
+
const dir = codexHome({ env, home });
|
|
1317
|
+
const file = path.join(dir, "session_index.jsonl");
|
|
1318
|
+
return memoTitle(`codex:${file}:${id}`, () => {
|
|
1319
|
+
let size = 0;
|
|
1320
|
+
try {
|
|
1321
|
+
size = fs.statSync(file).size;
|
|
1322
|
+
} catch {
|
|
1323
|
+
size = 0;
|
|
1324
|
+
}
|
|
1325
|
+
if (size > 0) {
|
|
1326
|
+
let text;
|
|
1327
|
+
if (size > CODEX_INDEX_MAX && fs.openSync && fs.readSync) {
|
|
1328
|
+
const fd = fs.openSync(file, "r");
|
|
1329
|
+
try {
|
|
1330
|
+
const buf = Buffer.alloc(CODEX_INDEX_TAIL);
|
|
1331
|
+
const n = fs.readSync(fd, buf, 0, CODEX_INDEX_TAIL, size - CODEX_INDEX_TAIL);
|
|
1332
|
+
text = buf.toString("utf8", 0, n);
|
|
1333
|
+
} finally {
|
|
1334
|
+
try {
|
|
1335
|
+
fs.closeSync(fd);
|
|
1336
|
+
} catch {}
|
|
1337
|
+
}
|
|
1338
|
+
} else {
|
|
1339
|
+
text = fs.readFileSync(file, "utf8");
|
|
1340
|
+
}
|
|
1341
|
+
const needle = `"id":"${id}"`;
|
|
1342
|
+
const lines = String(text).split("\n");
|
|
1343
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
1344
|
+
if (!lines[i].includes(needle)) continue;
|
|
1345
|
+
let d = null;
|
|
1346
|
+
try {
|
|
1347
|
+
d = JSON.parse(lines[i]);
|
|
1348
|
+
} catch {
|
|
1349
|
+
continue;
|
|
1350
|
+
}
|
|
1351
|
+
if (!d || d.id !== id) continue;
|
|
1352
|
+
const name = clip(d.thread_name, 60);
|
|
1353
|
+
if (name) return name;
|
|
1354
|
+
break;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
try {
|
|
1358
|
+
const dbs = fs
|
|
1359
|
+
.readdirSync(dir)
|
|
1360
|
+
.filter((f) => /^state_\d+\.sqlite$/.test(f))
|
|
1361
|
+
.sort((a, b) => Number(b.match(/\d+/)[0]) - Number(a.match(/\d+/)[0]));
|
|
1362
|
+
for (const f of dbs) {
|
|
1363
|
+
const rows = sqliteColumn(path.join(dir, f), "select title from threads where id=?", [id], exec);
|
|
1364
|
+
const title = String(rows[0] ?? "").trim();
|
|
1365
|
+
if (title) return clip(title, 60);
|
|
1366
|
+
}
|
|
1367
|
+
} catch {}
|
|
1368
|
+
return null;
|
|
1369
|
+
});
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
export function opencodeDataDir({ env = process.env, home = osMod.homedir() } = {}) {
|
|
1373
|
+
const xdg = typeof env.XDG_DATA_HOME === "string" ? env.XDG_DATA_HOME.trim() : "";
|
|
1374
|
+
return path.join(xdg || path.join(home, ".local", "share"), "opencode");
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
export function isOpencodeClient(clientCommand) {
|
|
1378
|
+
const s = String(clientCommand || "");
|
|
1379
|
+
if (/[\\/]OpenCode\.app[\\/]Contents[\\/]MacOS[\\/]/i.test(s)) return true;
|
|
1380
|
+
return /(^|[\\/\s])opencode(\.exe)?(\s|$)/i.test(s);
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
const OPENCODE_CALL_WINDOW_MS = 3000;
|
|
1384
|
+
const OPENCODE_MISS_RETRY_MS = 2000;
|
|
1385
|
+
const OPENCODE_PART_HEAD = 240;
|
|
1386
|
+
|
|
1387
|
+
function opencodeRealTitle(v) {
|
|
1388
|
+
const s = clip(v, 60);
|
|
1389
|
+
if (!s) return null;
|
|
1390
|
+
return s.startsWith("New session - ") ? null : s;
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
function sameDir(a, b) {
|
|
1394
|
+
const norm = (p) => {
|
|
1395
|
+
const s = path.resolve(String(p || ""));
|
|
1396
|
+
return process.platform === "win32" ? s.toLowerCase() : s;
|
|
1397
|
+
};
|
|
1398
|
+
return norm(a) === norm(b);
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
export function opencodeSessionOf(tool, at, { env = process.env, home = osMod.homedir(), fs = fsMod, exec = execFileSync, cwd = process.cwd() } = {}) {
|
|
1402
|
+
const name = typeof tool === "string" ? tool.trim() : "";
|
|
1403
|
+
const t = Number(at);
|
|
1404
|
+
if (!name || !Number.isFinite(t)) return null;
|
|
1405
|
+
if (!/^[a-z][a-z0-9_]{0,60}$/.test(name)) return null;
|
|
1406
|
+
const db = path.join(opencodeDataDir({ env, home }), "opencode.db");
|
|
1407
|
+
if (!fs.existsSync(db)) return null;
|
|
1408
|
+
return memoTitle(
|
|
1409
|
+
`opencode:${db}:${name}:${t}`,
|
|
1410
|
+
() => {
|
|
1411
|
+
const sql =
|
|
1412
|
+
`select p.session_id as sid, substr(p.data,1,${OPENCODE_PART_HEAD}) as head, ` +
|
|
1413
|
+
"s.title as title, s.directory as dir from part p " +
|
|
1414
|
+
"left join session s on s.id = p.session_id " +
|
|
1415
|
+
`where p.time_created between ${t - OPENCODE_CALL_WINDOW_MS} and ${t + OPENCODE_CALL_WINDOW_MS}`;
|
|
1416
|
+
const out = exec("/usr/bin/sqlite3", ["-readonly", "-cmd", ".mode json", db, sql], {
|
|
1417
|
+
encoding: "utf8",
|
|
1418
|
+
timeout: 2000,
|
|
1419
|
+
});
|
|
1420
|
+
let rows = null;
|
|
1421
|
+
try {
|
|
1422
|
+
rows = JSON.parse(String(out || "").trim() || "[]");
|
|
1423
|
+
} catch {
|
|
1424
|
+
return null;
|
|
1425
|
+
}
|
|
1426
|
+
if (!Array.isArray(rows)) return null;
|
|
1427
|
+
const toolRe = new RegExp('"tool":"[^"]*_' + name + '"');
|
|
1428
|
+
const hits = rows.filter((r) => r && typeof r.head === "string" && toolRe.test(r.head));
|
|
1429
|
+
const sids = [...new Set(hits.map((r) => String(r.sid || "")))].filter(Boolean);
|
|
1430
|
+
if (sids.length !== 1) return null;
|
|
1431
|
+
if (!/^ses_[A-Za-z0-9]+$/.test(sids[0])) return null;
|
|
1432
|
+
const row = hits.find((r) => String(r.sid) === sids[0]);
|
|
1433
|
+
if (!row) return null;
|
|
1434
|
+
const dir = typeof row.dir === "string" && row.dir ? row.dir : null;
|
|
1435
|
+
if (dir && !sameDir(dir, cwd)) return null;
|
|
1436
|
+
const title = opencodeRealTitle(row.title);
|
|
1437
|
+
if (!title && !dir) return null;
|
|
1438
|
+
return { title, directory: dir };
|
|
1439
|
+
},
|
|
1440
|
+
Date.now(),
|
|
1441
|
+
OPENCODE_MISS_RETRY_MS
|
|
1442
|
+
);
|
|
1443
|
+
}
|
|
1444
|
+
|
|
927
1445
|
/*
|
|
928
1446
|
* 现在这一刻的会话标题。
|
|
929
1447
|
*
|
|
@@ -934,19 +1452,27 @@ export function readAntigravityWorkspace(meta, local, { fs = fsMod, home = osMod
|
|
|
934
1452
|
* 分不出是哪段对话时(整个 app 共用一个 MCP 进程、帧里又没有会话身份)一律返回 null,
|
|
935
1453
|
* 不拿时间窗口去猜。
|
|
936
1454
|
*/
|
|
937
|
-
export function readSessionTitle(local, { fs = fsMod, home = osMod.homedir(), env = process.env, exec = execFileSync, alive = pidAlive, meta = null, dsh } = {}) {
|
|
1455
|
+
export function readSessionTitle(local, { fs = fsMod, home = osMod.homedir(), env = process.env, exec = execFileSync, alive = pidAlive, meta = null, dsh, tool = null, at = null } = {}) {
|
|
938
1456
|
if (!local) return null;
|
|
939
1457
|
const zc = readZcodeSessionTitle(meta, { env, home, fs, exec });
|
|
940
1458
|
if (zc) return zc;
|
|
941
1459
|
const tr = readTraeSessionTitle(meta, { fs, dataDir: traeDataDir({ userDataDir: local.userDataDir, appDir: local.brandAppDir, env, fs, home }) });
|
|
942
1460
|
if (tr) return tr;
|
|
943
|
-
const
|
|
1461
|
+
const ag = readAntigravitySessionTitle(meta, local, { fs, home, exec });
|
|
1462
|
+
if (ag) return ag;
|
|
1463
|
+
const cx = readCodexSessionTitle(meta, { env, home, fs, exec });
|
|
1464
|
+
if (cx) return cx;
|
|
1465
|
+
if (isOpencodeClient(local.clientCommand)) {
|
|
1466
|
+
const oc = opencodeSessionOf(tool, at, { env, home, fs, exec });
|
|
1467
|
+
if (oc?.title) return oc.title;
|
|
1468
|
+
}
|
|
1469
|
+
const ds = dsh !== undefined ? dsh : readDshSession(local, { env, home, fs, meta });
|
|
944
1470
|
if (ds?.title) return ds.title;
|
|
945
1471
|
const t = readHostSessionTitle(local.hostSessionId, { fs, home, env });
|
|
946
1472
|
if (t) return t;
|
|
947
1473
|
const file = readClientSessionFile(local.clientPid, { fs, home });
|
|
948
1474
|
if (file && file.nameSource !== "derived") return clip(file.name, 60);
|
|
949
|
-
const wb = readWorkbuddySessionTitle({ env, fs, exec, alive });
|
|
1475
|
+
const wb = readWorkbuddySessionTitle({ env, home, fs, exec, alive, meta, enginePid: local.clientPid });
|
|
950
1476
|
if (wb) return wb;
|
|
951
1477
|
return local.sessionName || null;
|
|
952
1478
|
}
|
|
@@ -959,12 +1485,13 @@ export function readSessionTitle(local, { fs = fsMod, home = osMod.homedir(), en
|
|
|
959
1485
|
* 那份工作区是进程级的、算一次就定死,所以这里另给一条会话级的出口;没有会话级证据的
|
|
960
1486
|
* 客户端返回 null,调用方照用进程级的那份。
|
|
961
1487
|
*/
|
|
962
|
-
export function readSessionIdentity(local, { fs = fsMod, home = osMod.homedir(), env = process.env, exec = execFileSync, alive = pidAlive, meta = null, tmp } = {}) {
|
|
1488
|
+
export function readSessionIdentity(local, { fs = fsMod, home = osMod.homedir(), env = process.env, exec = execFileSync, alive = pidAlive, meta = null, tmp, tool = null, at = null } = {}) {
|
|
963
1489
|
if (!local) return { title: null, workspace: null, workspaceKind: null };
|
|
964
|
-
const ds = readDshSession(local, { env, home, fs });
|
|
965
|
-
const title = readSessionTitle(local, { fs, home, env, exec, alive, meta, dsh: ds });
|
|
1490
|
+
const ds = readDshSession(local, { env, home, fs, meta });
|
|
1491
|
+
const title = readSessionTitle(local, { fs, home, env, exec, alive, meta, dsh: ds, tool, at });
|
|
966
1492
|
const agDir = readAntigravityWorkspace(meta, local, { fs, home });
|
|
967
|
-
const
|
|
1493
|
+
const oc = isOpencodeClient(local.clientCommand) ? opencodeSessionOf(tool, at, { env, home, fs, exec }) : null;
|
|
1494
|
+
const wsDir = ds?.cwd || agDir || oc?.directory;
|
|
968
1495
|
const ws = wsDir ? readWorkspace(wsDir, tmp !== undefined ? { fs, home, tmp } : { fs, home }) : null;
|
|
969
1496
|
return { title, workspace: ws?.name || null, workspaceKind: ws?.kind || null };
|
|
970
1497
|
}
|