@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
package/mcp/agent-identity.mjs
CHANGED
|
@@ -446,30 +446,37 @@ export function readClaudeSubagent(meta, local, { fs = fsMod, home = osMod.homed
|
|
|
446
446
|
return null;
|
|
447
447
|
}
|
|
448
448
|
|
|
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
|
+
|
|
449
454
|
export function readWorkbuddySessionTitle({
|
|
450
455
|
env = process.env,
|
|
456
|
+
home = osMod.homedir(),
|
|
451
457
|
fs = fsMod,
|
|
452
458
|
exec = execFileSync,
|
|
453
459
|
alive = pidAlive,
|
|
454
460
|
meta = null,
|
|
455
461
|
enginePid = null,
|
|
456
462
|
} = {}) {
|
|
457
|
-
const dir =
|
|
463
|
+
const dir = workbuddyConfigDir({ env, home });
|
|
458
464
|
if (!path.isAbsolute(dir)) return null;
|
|
459
465
|
const id =
|
|
460
466
|
workbuddyConversationId(meta) ||
|
|
461
467
|
workbuddyEngineSession(dir, enginePid, { fs }) ||
|
|
462
468
|
workbuddyOnlyLiveSession(dir, { fs, alive });
|
|
463
469
|
if (!id) return null;
|
|
464
|
-
/*
|
|
465
|
-
*
|
|
470
|
+
/* id 会以绑定参数进查询(CLI 退路里才落成字面量,本层有转义兜底)。形状锚
|
|
471
|
+
* CONV_UUID_RE 照旧不许放宽:它是这条链的第一道闸,不是最后一道。 */
|
|
466
472
|
try {
|
|
467
|
-
const
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
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
|
|
471
478
|
);
|
|
472
|
-
return clip(String(
|
|
479
|
+
return clip(String(rows[0] ?? "").trim(), 60);
|
|
473
480
|
} catch {
|
|
474
481
|
return null;
|
|
475
482
|
}
|
|
@@ -610,6 +617,59 @@ export function resetTitleMemo() {
|
|
|
610
617
|
titleMemo.clear();
|
|
611
618
|
dshCwdMemo.clear();
|
|
612
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 === ""));
|
|
613
673
|
}
|
|
614
674
|
|
|
615
675
|
export function zcodeDataDir({ env = process.env, home = osMod.homedir() } = {}) {
|
|
@@ -625,12 +685,12 @@ export function readZcodeSessionTitle(meta, { env = process.env, home = osMod.ho
|
|
|
625
685
|
if (!isMain && !isSub) return null;
|
|
626
686
|
const db = path.join(zcodeDataDir({ env, home }), "cli", "db", "db.sqlite");
|
|
627
687
|
if (!fs.existsSync(db)) return null;
|
|
628
|
-
const sql = isSub
|
|
629
|
-
? `select title from session where id=(select parent_id from session where id='${id}') and title_source in ('generated','custom')`
|
|
630
|
-
: `select title from session where id='${id}' and title_source in ('generated','custom')`;
|
|
631
688
|
return memoTitle(`zcode:${db}:${id}`, () => {
|
|
632
|
-
const
|
|
633
|
-
|
|
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);
|
|
634
694
|
});
|
|
635
695
|
}
|
|
636
696
|
|
|
@@ -795,9 +855,15 @@ export function dshHome({ env = process.env, home = osMod.homedir() } = {}) {
|
|
|
795
855
|
return path.isAbsolute(d) ? d : path.join(home, ".dsh");
|
|
796
856
|
}
|
|
797
857
|
|
|
858
|
+
const DSH_DESKTOP_APP = /DeepSeek Harness\.app[\\/]Contents[\\/]MacOS[\\/]/;
|
|
859
|
+
|
|
798
860
|
export function isDshClient(clientCommand) {
|
|
799
861
|
const s = String(clientCommand || "");
|
|
800
|
-
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
|
+
);
|
|
801
867
|
}
|
|
802
868
|
|
|
803
869
|
export function decodeZstdFrames(buf, { zlib = zlibMod } = {}) {
|
|
@@ -817,13 +883,124 @@ export function decodeZstdFrames(buf, { zlib = zlibMod } = {}) {
|
|
|
817
883
|
|
|
818
884
|
const dshCwdMemo = new Map();
|
|
819
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
|
+
const DSH_TALK_MAX_FRAMES = 8;
|
|
910
|
+
|
|
911
|
+
function dshHasConversation(c, fs = fsMod) {
|
|
912
|
+
let key;
|
|
913
|
+
try {
|
|
914
|
+
const st = fs.statSync(c.file);
|
|
915
|
+
key = `${c.file}:${st.mtimeMs}:${st.size}`;
|
|
916
|
+
} catch {
|
|
917
|
+
return false;
|
|
918
|
+
}
|
|
919
|
+
const hit = dshTalkMemo.get(key);
|
|
920
|
+
if (hit !== undefined) return hit;
|
|
921
|
+
let ok = false;
|
|
922
|
+
try {
|
|
923
|
+
const buf = fs.readFileSync(c.file);
|
|
924
|
+
let i = buf.indexOf(ZSTD_MAGIC);
|
|
925
|
+
for (let frames = 0; i >= 0 && frames < DSH_TALK_MAX_FRAMES; frames++) {
|
|
926
|
+
try {
|
|
927
|
+
const text = zlibMod.zstdDecompressSync(buf.subarray(i)).toString("utf8");
|
|
928
|
+
if (text.includes('"type":"user/message"') || text.includes('"type":"session/title"')) {
|
|
929
|
+
ok = true;
|
|
930
|
+
break;
|
|
931
|
+
}
|
|
932
|
+
} catch {
|
|
933
|
+
}
|
|
934
|
+
i = buf.indexOf(ZSTD_MAGIC, i + 4);
|
|
935
|
+
}
|
|
936
|
+
} catch {
|
|
937
|
+
ok = false;
|
|
938
|
+
}
|
|
939
|
+
if (dshTalkMemo.size >= TITLE_MEMO_MAX) dshTalkMemo.clear();
|
|
940
|
+
dshTalkMemo.set(key, ok);
|
|
941
|
+
return ok;
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
const DSH_SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;
|
|
945
|
+
|
|
946
|
+
function dshLogById(root, id, fs) {
|
|
947
|
+
if (!DSH_SESSION_ID.test(id)) return null;
|
|
948
|
+
let dirs;
|
|
949
|
+
try {
|
|
950
|
+
dirs = fs.readdirSync(root);
|
|
951
|
+
} catch {
|
|
952
|
+
return null;
|
|
953
|
+
}
|
|
954
|
+
for (const d of dirs.slice(0, 500)) {
|
|
955
|
+
const file = dshLogFile(path.join(root, d, id), fs);
|
|
956
|
+
if (file) return { id, file };
|
|
957
|
+
}
|
|
958
|
+
return null;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
const dshHeaderMemo = new Map();
|
|
962
|
+
|
|
963
|
+
function dshHeader(file, fs) {
|
|
964
|
+
const hit = dshHeaderMemo.get(file);
|
|
965
|
+
if (hit !== undefined) return hit;
|
|
966
|
+
let h = null;
|
|
967
|
+
try {
|
|
968
|
+
const first = zlibMod.zstdDecompressSync ? zlibMod.zstdDecompressSync(fs.readFileSync(file)) : null;
|
|
969
|
+
const parsed = first ? JSON.parse(first.toString("utf8").split("\n")[0]) : null;
|
|
970
|
+
if (parsed && parsed.type === "session") h = parsed;
|
|
971
|
+
} catch {}
|
|
972
|
+
if (dshHeaderMemo.size >= TITLE_MEMO_MAX) dshHeaderMemo.clear();
|
|
973
|
+
dshHeaderMemo.set(file, h);
|
|
974
|
+
return h;
|
|
975
|
+
}
|
|
976
|
+
|
|
820
977
|
/*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
978
|
+
* 子任务会话上溯到它所属的主会话。
|
|
979
|
+
*
|
|
980
|
+
* 子会话的头里有 `origin:"subagent"` 和 `parentSession`(dsH 侧写入点见
|
|
981
|
+
* subagent/child-agent.ts 的 childSessionMeta)。**卡片上「会话名」只有一行**,它要回答的
|
|
982
|
+
* 是「这些页属于我哪一段对话」——而子任务的标题就是那段委派提示词的开头,盖上去等于把
|
|
983
|
+
* 用户刚说的话又抄一遍。这条口径与 ZCode 顺着 parent_id 报主会话标题完全一致(那边注释
|
|
984
|
+
* 原话:「拿 subagent 的名字盖掉主会话的名字是显示错,不是少显示」)。
|
|
985
|
+
*
|
|
986
|
+
* 工作区**也一起取主会话的**:子会话虽然继承了父会话的 cwd,但同一条归属链上取回来更硬——
|
|
987
|
+
* 不去依赖「继承」这个实现细节。
|
|
988
|
+
*
|
|
989
|
+
* 父会话解不出来(已被清理、读不动)就停在能解到的那一层:宁可显示子会话,也不显示空。
|
|
823
990
|
*/
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
991
|
+
function dshRootOf(root, start, fs, { maxHops = 8 } = {}) {
|
|
992
|
+
let cur = start;
|
|
993
|
+
for (let i = 0; i < maxHops; i++) {
|
|
994
|
+
const h = dshHeader(cur.file, fs);
|
|
995
|
+
if (!h || (h.origin !== "subagent" && typeof h.parentSession !== "string")) return cur;
|
|
996
|
+
const up = typeof h.parentSession === "string" ? dshLogById(root, h.parentSession, fs) : null;
|
|
997
|
+
if (!up) return cur;
|
|
998
|
+
cur = up;
|
|
999
|
+
}
|
|
1000
|
+
return cur;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
function dshPickLive(root, fs, now) {
|
|
827
1004
|
const live = [];
|
|
828
1005
|
let dirs;
|
|
829
1006
|
try {
|
|
@@ -839,17 +1016,29 @@ export function readDshSession(local, { env = process.env, home = osMod.homedir(
|
|
|
839
1016
|
continue;
|
|
840
1017
|
}
|
|
841
1018
|
for (const s of subs) {
|
|
842
|
-
|
|
843
|
-
|
|
1019
|
+
const file = dshLogFile(path.join(root, d, s), fs);
|
|
1020
|
+
if (!file) continue;
|
|
844
1021
|
try {
|
|
845
1022
|
const st = fs.statSync(file);
|
|
846
1023
|
if (now - st.mtimeMs <= DSH_LIVE_WINDOW_MS) live.push({ id: s, file });
|
|
847
1024
|
} catch {}
|
|
848
|
-
if (live.length > 1) return null;
|
|
849
1025
|
}
|
|
850
1026
|
}
|
|
851
|
-
|
|
852
|
-
|
|
1027
|
+
const talking = live.length === 1 ? live : live.filter((c) => dshHasConversation(c, fs));
|
|
1028
|
+
return talking.length === 1 ? talking[0] : null;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/*
|
|
1032
|
+
* 恰好一个活跃会话时返回 { id, title, cwd };分不出(0 个或多个活跃)就 null。
|
|
1033
|
+
* title 可能暂缺(LLM 标题是首轮之后才生成的)——cwd 先到先用,两者不互相拖累。
|
|
1034
|
+
*/
|
|
1035
|
+
export function readDshSession(local, { env = process.env, home = osMod.homedir(), fs = fsMod, now = Date.now(), meta = null } = {}) {
|
|
1036
|
+
if (!local || !isDshClient(local.clientCommand)) return null;
|
|
1037
|
+
const root = path.join(dshHome({ env, home }), "sessions");
|
|
1038
|
+
const asked = meta && typeof meta === "object" && typeof meta.session_id === "string" ? meta.session_id.trim() : "";
|
|
1039
|
+
const picked = (asked ? dshLogById(root, asked, fs) : null) || dshPickLive(root, fs, now);
|
|
1040
|
+
if (!picked) return null;
|
|
1041
|
+
const { id, file } = dshRootOf(root, picked, fs);
|
|
853
1042
|
|
|
854
1043
|
let cwd = dshCwdMemo.get(id);
|
|
855
1044
|
const title = memoTitle(`dsh:${file}`, () => {
|
|
@@ -898,6 +1087,44 @@ export function readDshSession(local, { env = process.env, home = osMod.homedir(
|
|
|
898
1087
|
return { id, title: title || null, cwd: cwd || null };
|
|
899
1088
|
}
|
|
900
1089
|
|
|
1090
|
+
function dshOwnTitle(file, fs) {
|
|
1091
|
+
return memoTitle(`dsh-own:${file}`, () => {
|
|
1092
|
+
let text;
|
|
1093
|
+
try {
|
|
1094
|
+
text = decodeZstdFrames(fs.readFileSync(file));
|
|
1095
|
+
} catch {
|
|
1096
|
+
return null;
|
|
1097
|
+
}
|
|
1098
|
+
if (!text) return null;
|
|
1099
|
+
let found = null;
|
|
1100
|
+
for (const line of text.split("\n")) {
|
|
1101
|
+
if (!line.includes('"session/title"')) continue;
|
|
1102
|
+
try {
|
|
1103
|
+
const ev = JSON.parse(line);
|
|
1104
|
+
if (ev?.type === "session/title") {
|
|
1105
|
+
const t = clip(ev.data?.title, 60);
|
|
1106
|
+
if (t) found = t;
|
|
1107
|
+
}
|
|
1108
|
+
} catch {}
|
|
1109
|
+
}
|
|
1110
|
+
return found;
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
export function readDshSubagent(meta, local, { env = process.env, home = osMod.homedir(), fs = fsMod } = {}) {
|
|
1115
|
+
if (!local || !isDshClient(local.clientCommand)) return null;
|
|
1116
|
+
const id = meta && typeof meta === "object" && typeof meta.session_id === "string" ? meta.session_id.trim() : "";
|
|
1117
|
+
if (!id) return null;
|
|
1118
|
+
const own = dshLogById(path.join(dshHome({ env, home }), "sessions"), id, fs);
|
|
1119
|
+
if (!own) return null;
|
|
1120
|
+
const h = dshHeader(own.file, fs);
|
|
1121
|
+
if (!h || (h.origin !== "subagent" && typeof h.parentSession !== "string")) return null;
|
|
1122
|
+
const label = dshOwnTitle(own.file, fs);
|
|
1123
|
+
const type = typeof h.agentPreset === "string" && h.agentPreset ? clip(h.agentPreset, 40) : null;
|
|
1124
|
+
if (!label && !type) return null;
|
|
1125
|
+
return { label: label || null, type };
|
|
1126
|
+
}
|
|
1127
|
+
|
|
901
1128
|
/* 会话 id 进路径、SQL 与提取流程前的锚(安全边界,勿放宽):只放行 UUID 形状,`..`、`/`、
|
|
902
1129
|
* 引号一概进不来——id 来自 MCP 调用方给的 _meta,是外部输入。
|
|
903
1130
|
*
|
|
@@ -1059,14 +1286,15 @@ export function readAntigravitySessionTitle(meta, local, { fs = fsMod, home = os
|
|
|
1059
1286
|
try {
|
|
1060
1287
|
if (fs.statSync(`${db}-wal`).size <= AG_DB_MAX) fs.copyFileSync(`${db}-wal`, `${copy}-wal`);
|
|
1061
1288
|
} catch {}
|
|
1062
|
-
const
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1289
|
+
const lines = sqliteColumn(
|
|
1290
|
+
copy,
|
|
1291
|
+
`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}`,
|
|
1292
|
+
[],
|
|
1293
|
+
exec
|
|
1066
1294
|
);
|
|
1067
1295
|
const rows = [];
|
|
1068
|
-
for (const line of
|
|
1069
|
-
const hex = line.trim();
|
|
1296
|
+
for (const line of lines) {
|
|
1297
|
+
const hex = String(line ?? "").trim();
|
|
1070
1298
|
if (hex && /^(?:[0-9a-f]{2})+$/i.test(hex)) rows.push(Buffer.from(hex, "hex"));
|
|
1071
1299
|
}
|
|
1072
1300
|
return agTitleFromRows(rows);
|
|
@@ -1094,45 +1322,61 @@ export function codexThreadId(meta) {
|
|
|
1094
1322
|
return CONV_UUID_RE.test(id) ? id : null;
|
|
1095
1323
|
}
|
|
1096
1324
|
|
|
1097
|
-
export function readCodexSessionTitle(meta, { env = process.env, home = osMod.homedir(), fs = fsMod } = {}) {
|
|
1325
|
+
export function readCodexSessionTitle(meta, { env = process.env, home = osMod.homedir(), fs = fsMod, exec = execFileSync } = {}) {
|
|
1098
1326
|
const id = codexThreadId(meta);
|
|
1099
1327
|
if (!id) return null;
|
|
1100
|
-
const
|
|
1328
|
+
const dir = codexHome({ env, home });
|
|
1329
|
+
const file = path.join(dir, "session_index.jsonl");
|
|
1101
1330
|
return memoTitle(`codex:${file}:${id}`, () => {
|
|
1102
1331
|
let size = 0;
|
|
1103
1332
|
try {
|
|
1104
1333
|
size = fs.statSync(file).size;
|
|
1105
1334
|
} catch {
|
|
1106
|
-
|
|
1335
|
+
size = 0;
|
|
1107
1336
|
}
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
const buf = Buffer.alloc(CODEX_INDEX_TAIL);
|
|
1113
|
-
const n = fs.readSync(fd, buf, 0, CODEX_INDEX_TAIL, size - CODEX_INDEX_TAIL);
|
|
1114
|
-
text = buf.toString("utf8", 0, n);
|
|
1115
|
-
} finally {
|
|
1337
|
+
if (size > 0) {
|
|
1338
|
+
let text;
|
|
1339
|
+
if (size > CODEX_INDEX_MAX && fs.openSync && fs.readSync) {
|
|
1340
|
+
const fd = fs.openSync(file, "r");
|
|
1116
1341
|
try {
|
|
1117
|
-
|
|
1118
|
-
|
|
1342
|
+
const buf = Buffer.alloc(CODEX_INDEX_TAIL);
|
|
1343
|
+
const n = fs.readSync(fd, buf, 0, CODEX_INDEX_TAIL, size - CODEX_INDEX_TAIL);
|
|
1344
|
+
text = buf.toString("utf8", 0, n);
|
|
1345
|
+
} finally {
|
|
1346
|
+
try {
|
|
1347
|
+
fs.closeSync(fd);
|
|
1348
|
+
} catch {}
|
|
1349
|
+
}
|
|
1350
|
+
} else {
|
|
1351
|
+
text = fs.readFileSync(file, "utf8");
|
|
1119
1352
|
}
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1353
|
+
const needle = `"id":"${id}"`;
|
|
1354
|
+
const lines = String(text).split("\n");
|
|
1355
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
1356
|
+
if (!lines[i].includes(needle)) continue;
|
|
1357
|
+
let d = null;
|
|
1358
|
+
try {
|
|
1359
|
+
d = JSON.parse(lines[i]);
|
|
1360
|
+
} catch {
|
|
1361
|
+
continue;
|
|
1362
|
+
}
|
|
1363
|
+
if (!d || d.id !== id) continue;
|
|
1364
|
+
const name = clip(d.thread_name, 60);
|
|
1365
|
+
if (name) return name;
|
|
1366
|
+
break;
|
|
1132
1367
|
}
|
|
1133
|
-
if (!d || d.id !== id) continue;
|
|
1134
|
-
return clip(d.thread_name, 60);
|
|
1135
1368
|
}
|
|
1369
|
+
try {
|
|
1370
|
+
const dbs = fs
|
|
1371
|
+
.readdirSync(dir)
|
|
1372
|
+
.filter((f) => /^state_\d+\.sqlite$/.test(f))
|
|
1373
|
+
.sort((a, b) => Number(b.match(/\d+/)[0]) - Number(a.match(/\d+/)[0]));
|
|
1374
|
+
for (const f of dbs) {
|
|
1375
|
+
const rows = sqliteColumn(path.join(dir, f), "select title from threads where id=?", [id], exec);
|
|
1376
|
+
const title = String(rows[0] ?? "").trim();
|
|
1377
|
+
if (title) return clip(title, 60);
|
|
1378
|
+
}
|
|
1379
|
+
} catch {}
|
|
1136
1380
|
return null;
|
|
1137
1381
|
});
|
|
1138
1382
|
}
|
|
@@ -1228,19 +1472,19 @@ export function readSessionTitle(local, { fs = fsMod, home = osMod.homedir(), en
|
|
|
1228
1472
|
if (tr) return tr;
|
|
1229
1473
|
const ag = readAntigravitySessionTitle(meta, local, { fs, home, exec });
|
|
1230
1474
|
if (ag) return ag;
|
|
1231
|
-
const cx = readCodexSessionTitle(meta, { env, home, fs });
|
|
1475
|
+
const cx = readCodexSessionTitle(meta, { env, home, fs, exec });
|
|
1232
1476
|
if (cx) return cx;
|
|
1233
1477
|
if (isOpencodeClient(local.clientCommand)) {
|
|
1234
1478
|
const oc = opencodeSessionOf(tool, at, { env, home, fs, exec });
|
|
1235
1479
|
if (oc?.title) return oc.title;
|
|
1236
1480
|
}
|
|
1237
|
-
const ds = dsh !== undefined ? dsh : readDshSession(local, { env, home, fs });
|
|
1481
|
+
const ds = dsh !== undefined ? dsh : readDshSession(local, { env, home, fs, meta });
|
|
1238
1482
|
if (ds?.title) return ds.title;
|
|
1239
1483
|
const t = readHostSessionTitle(local.hostSessionId, { fs, home, env });
|
|
1240
1484
|
if (t) return t;
|
|
1241
1485
|
const file = readClientSessionFile(local.clientPid, { fs, home });
|
|
1242
1486
|
if (file && file.nameSource !== "derived") return clip(file.name, 60);
|
|
1243
|
-
const wb = readWorkbuddySessionTitle({ env, fs, exec, alive, meta, enginePid: local.clientPid });
|
|
1487
|
+
const wb = readWorkbuddySessionTitle({ env, home, fs, exec, alive, meta, enginePid: local.clientPid });
|
|
1244
1488
|
if (wb) return wb;
|
|
1245
1489
|
return local.sessionName || null;
|
|
1246
1490
|
}
|
|
@@ -1255,7 +1499,7 @@ export function readSessionTitle(local, { fs = fsMod, home = osMod.homedir(), en
|
|
|
1255
1499
|
*/
|
|
1256
1500
|
export function readSessionIdentity(local, { fs = fsMod, home = osMod.homedir(), env = process.env, exec = execFileSync, alive = pidAlive, meta = null, tmp, tool = null, at = null } = {}) {
|
|
1257
1501
|
if (!local) return { title: null, workspace: null, workspaceKind: null };
|
|
1258
|
-
const ds = readDshSession(local, { env, home, fs });
|
|
1502
|
+
const ds = readDshSession(local, { env, home, fs, meta });
|
|
1259
1503
|
const title = readSessionTitle(local, { fs, home, env, exec, alive, meta, dsh: ds, tool, at });
|
|
1260
1504
|
const agDir = readAntigravityWorkspace(meta, local, { fs, home });
|
|
1261
1505
|
const oc = isOpencodeClient(local.clientCommand) ? opencodeSessionOf(tool, at, { env, home, fs, exec }) : null;
|