@threadbase-sh/scanner 0.15.0 → 0.16.1
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/dist/cli.js +96 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +95 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +95 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Command } from "commander";
|
|
|
5
5
|
import pino2 from "pino";
|
|
6
6
|
|
|
7
7
|
// package.json
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.16.1";
|
|
9
9
|
|
|
10
10
|
// src/logger.ts
|
|
11
11
|
import pino from "pino";
|
|
@@ -626,6 +626,8 @@ function initialReducerState() {
|
|
|
626
626
|
model: null,
|
|
627
627
|
messageCount: 0,
|
|
628
628
|
lastMessageSender: "user",
|
|
629
|
+
agentId: "",
|
|
630
|
+
isSidechain: false,
|
|
629
631
|
isTeammate: false,
|
|
630
632
|
firstUserSeen: false,
|
|
631
633
|
firstMessage: null,
|
|
@@ -645,6 +647,8 @@ function reduceLine(state, entry, tier) {
|
|
|
645
647
|
if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
|
|
646
648
|
if (entry.slug && !state.sessionName) state.sessionName = entry.slug;
|
|
647
649
|
if (entry.teamName && !state.teamName) state.teamName = entry.teamName;
|
|
650
|
+
if (entry.agentId && !state.agentId) state.agentId = entry.agentId;
|
|
651
|
+
if (entry.isSidechain === true) state.isSidechain = true;
|
|
648
652
|
if (entry.timestamp) {
|
|
649
653
|
const ts = entry.timestamp;
|
|
650
654
|
if (!state.latestTimestamp || ts > state.latestTimestamp) state.latestTimestamp = ts;
|
|
@@ -696,9 +700,11 @@ function reduceLine(state, entry, tier) {
|
|
|
696
700
|
}
|
|
697
701
|
function finalizeMeta(state, filePath, account, tier) {
|
|
698
702
|
if (state.messageCount === 0) return null;
|
|
699
|
-
const
|
|
703
|
+
const isSidechain = state.isSidechain && !!state.agentId;
|
|
704
|
+
const isSubagentPath = SUBAGENT_PATH_RE.test(filePath);
|
|
705
|
+
const isSubagent = isSidechain || isSubagentPath;
|
|
700
706
|
let parentSessionId = null;
|
|
701
|
-
if (
|
|
707
|
+
if (isSubagentPath) {
|
|
702
708
|
const uuidDir = dirname2(dirname2(filePath));
|
|
703
709
|
parentSessionId = join3(dirname2(uuidDir), `${basename(uuidDir)}.jsonl`);
|
|
704
710
|
}
|
|
@@ -721,6 +727,10 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
721
727
|
model: state.model,
|
|
722
728
|
isSubagent,
|
|
723
729
|
parentSessionId,
|
|
730
|
+
subagentId: isSidechain ? state.agentId : void 0,
|
|
731
|
+
// A sidechain line's `sessionId` IS the parent's id — that is exactly the
|
|
732
|
+
// conflation `subagentId` exists to undo, so it is the parent UUID here.
|
|
733
|
+
parentSessionUuid: isSidechain && state.sessionId ? state.sessionId : void 0,
|
|
724
734
|
isTeammate: state.isTeammate,
|
|
725
735
|
teamName: state.teamName || null,
|
|
726
736
|
toolNames: state.toolNames,
|
|
@@ -729,6 +739,7 @@ function finalizeMeta(state, filePath, account, tier) {
|
|
|
729
739
|
lastPrompt: state.lastPrompt || void 0
|
|
730
740
|
};
|
|
731
741
|
}
|
|
742
|
+
var SUBAGENT_PATH_RE = /[\\/]subagents[\\/]/;
|
|
732
743
|
function deriveSessionNameFromFirstMessage(firstMessage) {
|
|
733
744
|
const firstLine = firstMessage?.text.split("\n", 1)[0]?.trim() ?? "";
|
|
734
745
|
return firstLine.slice(0, 80);
|
|
@@ -1279,6 +1290,8 @@ var CodexCliProvider = class {
|
|
|
1279
1290
|
latestTimestamp: "",
|
|
1280
1291
|
messageCount: 0,
|
|
1281
1292
|
lastMessageSender: "user",
|
|
1293
|
+
isSubagent: false,
|
|
1294
|
+
parentSessionUuid: null,
|
|
1282
1295
|
firstUser: null,
|
|
1283
1296
|
lastUser: null,
|
|
1284
1297
|
lastAssistant: null,
|
|
@@ -1330,6 +1343,10 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1330
1343
|
if (!acc.cwd) acc.cwd = asString(payload.cwd);
|
|
1331
1344
|
const git = payload.git;
|
|
1332
1345
|
if (acc.gitBranch === null && git?.branch) acc.gitBranch = asString(git.branch) || null;
|
|
1346
|
+
if (!acc.isSubagent && isSubagentSource(payload.source)) {
|
|
1347
|
+
acc.isSubagent = true;
|
|
1348
|
+
acc.parentSessionUuid = parentThreadId(payload.source);
|
|
1349
|
+
}
|
|
1333
1350
|
return;
|
|
1334
1351
|
}
|
|
1335
1352
|
if (acc.model === null && payload.model) acc.model = asString(payload.model) || null;
|
|
@@ -1345,6 +1362,7 @@ function reduceCodexEntry(acc, entry, tier) {
|
|
|
1345
1362
|
if (role !== "user" && role !== "assistant") return;
|
|
1346
1363
|
const text = extractCodexText(payload.content);
|
|
1347
1364
|
if (!text) return;
|
|
1365
|
+
if (acc.messageCount === 0 && role === "user" && isCodexInjectedContext(text)) return;
|
|
1348
1366
|
const sender = role;
|
|
1349
1367
|
acc.messageCount++;
|
|
1350
1368
|
acc.lastMessageSender = sender;
|
|
@@ -1378,7 +1396,10 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1378
1396
|
kind,
|
|
1379
1397
|
externalSessionId: acc.sessionId || void 0,
|
|
1380
1398
|
sessionId,
|
|
1381
|
-
|
|
1399
|
+
// Mirrors the Claude reducer: a rollout carries no slug, so the opening turn
|
|
1400
|
+
// is the only human-readable name source. Only useful because the injected
|
|
1401
|
+
// AGENTS.md turn is skipped above — otherwise every title would be that blob.
|
|
1402
|
+
sessionName: deriveSessionNameFromFirstMessage(acc.firstUser),
|
|
1382
1403
|
projectPath,
|
|
1383
1404
|
projectName: getShortProjectName3(projectPath),
|
|
1384
1405
|
account,
|
|
@@ -1389,8 +1410,10 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1389
1410
|
contentSnippet: acc.snippetParts.join(" "),
|
|
1390
1411
|
gitBranch: acc.gitBranch,
|
|
1391
1412
|
model: acc.model,
|
|
1392
|
-
isSubagent:
|
|
1413
|
+
isSubagent: acc.isSubagent,
|
|
1414
|
+
// Codex exposes no path-shaped parent, and no per-child id of its own.
|
|
1393
1415
|
parentSessionId: null,
|
|
1416
|
+
parentSessionUuid: acc.parentSessionUuid ?? void 0,
|
|
1394
1417
|
isTeammate: false,
|
|
1395
1418
|
teamName: null,
|
|
1396
1419
|
toolNames: acc.toolNames,
|
|
@@ -1399,9 +1422,24 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1399
1422
|
lastPrompt: acc.lastUser?.text || void 0
|
|
1400
1423
|
};
|
|
1401
1424
|
}
|
|
1425
|
+
function isCodexInjectedContext(text) {
|
|
1426
|
+
if (text.startsWith("# AGENTS.md") || text.includes("<INSTRUCTIONS>")) return true;
|
|
1427
|
+
return text.startsWith("<permissions instructions>") || text.includes("Filesystem sandboxing defines");
|
|
1428
|
+
}
|
|
1402
1429
|
function getShortProjectName3(fullPath) {
|
|
1403
1430
|
return fullPath.split("/").filter(Boolean).slice(-3).join("/");
|
|
1404
1431
|
}
|
|
1432
|
+
function isSubagentSource(source) {
|
|
1433
|
+
return typeof source === "object" && source !== null && "subagent" in source;
|
|
1434
|
+
}
|
|
1435
|
+
function parentThreadId(source) {
|
|
1436
|
+
if (!isSubagentSource(source)) return null;
|
|
1437
|
+
const subagent = source.subagent;
|
|
1438
|
+
if (typeof subagent !== "object" || subagent === null) return null;
|
|
1439
|
+
const spawn = subagent.thread_spawn;
|
|
1440
|
+
if (typeof spawn !== "object" || spawn === null) return null;
|
|
1441
|
+
return asString(spawn.parent_thread_id) || null;
|
|
1442
|
+
}
|
|
1405
1443
|
async function parseCodexConversation(filePath, account) {
|
|
1406
1444
|
const log = getLogger();
|
|
1407
1445
|
const messages = [];
|
|
@@ -1655,7 +1693,7 @@ import { mkdirSync } from "fs";
|
|
|
1655
1693
|
import { dirname as dirname3 } from "path";
|
|
1656
1694
|
|
|
1657
1695
|
// src/persistent/schema.ts
|
|
1658
|
-
var SCHEMA_VERSION =
|
|
1696
|
+
var SCHEMA_VERSION = 7;
|
|
1659
1697
|
var SCHEMA_SQL = `
|
|
1660
1698
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
1661
1699
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -1730,7 +1768,11 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
1730
1768
|
|
|
1731
1769
|
model TEXT,
|
|
1732
1770
|
is_subagent INTEGER NOT NULL DEFAULT 0,
|
|
1771
|
+
-- The parent's JSONL PATH (matched against source_path), not an id.
|
|
1733
1772
|
parent_session_id TEXT,
|
|
1773
|
+
-- The subagent's own id (Claude agentId), and the parent's session UUID.
|
|
1774
|
+
subagent_id TEXT,
|
|
1775
|
+
parent_session_uuid TEXT,
|
|
1734
1776
|
is_teammate INTEGER NOT NULL DEFAULT 0,
|
|
1735
1777
|
team_name TEXT,
|
|
1736
1778
|
tool_names_json TEXT,
|
|
@@ -1863,6 +1905,44 @@ function runMigrations(db) {
|
|
|
1863
1905
|
}
|
|
1864
1906
|
}
|
|
1865
1907
|
}
|
|
1908
|
+
if (current >= 1 && current < 6 && tableExists(db, "conversations")) {
|
|
1909
|
+
for (const [col, ddl] of [
|
|
1910
|
+
["subagent_id", "ALTER TABLE conversations ADD COLUMN subagent_id TEXT"],
|
|
1911
|
+
["parent_session_uuid", "ALTER TABLE conversations ADD COLUMN parent_session_uuid TEXT"]
|
|
1912
|
+
]) {
|
|
1913
|
+
if (!hasColumn(db, "conversations", col)) db.exec(ddl);
|
|
1914
|
+
}
|
|
1915
|
+
if (tableExists(db, "conversation_files")) {
|
|
1916
|
+
const assignments = [];
|
|
1917
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
1918
|
+
assignments.push("last_indexed_offset = 0");
|
|
1919
|
+
}
|
|
1920
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
1921
|
+
assignments.push("last_indexed_line = 0");
|
|
1922
|
+
}
|
|
1923
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
1924
|
+
assignments.push("reducer_state = NULL");
|
|
1925
|
+
}
|
|
1926
|
+
if (assignments.length > 0) {
|
|
1927
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
if (current >= 1 && current < 7 && tableExists(db, "conversation_files")) {
|
|
1932
|
+
const assignments = [];
|
|
1933
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
1934
|
+
assignments.push("last_indexed_offset = 0");
|
|
1935
|
+
}
|
|
1936
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
1937
|
+
assignments.push("last_indexed_line = 0");
|
|
1938
|
+
}
|
|
1939
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
1940
|
+
assignments.push("reducer_state = NULL");
|
|
1941
|
+
}
|
|
1942
|
+
if (assignments.length > 0) {
|
|
1943
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1866
1946
|
db.exec(SCHEMA_SQL);
|
|
1867
1947
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
1868
1948
|
}
|
|
@@ -2187,6 +2267,8 @@ function rowToMeta(row) {
|
|
|
2187
2267
|
model: row.model,
|
|
2188
2268
|
isSubagent: row.is_subagent === 1,
|
|
2189
2269
|
parentSessionId: row.parent_session_id,
|
|
2270
|
+
subagentId: row.subagent_id ?? void 0,
|
|
2271
|
+
parentSessionUuid: row.parent_session_uuid ?? void 0,
|
|
2190
2272
|
isTeammate: row.is_teammate === 1,
|
|
2191
2273
|
teamName: row.team_name,
|
|
2192
2274
|
toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
|
|
@@ -2210,7 +2292,8 @@ var ConversationsRepo = class {
|
|
|
2210
2292
|
account, branch, preview, content_snippet, message_count, page_message_count,
|
|
2211
2293
|
last_message_sender,
|
|
2212
2294
|
timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
|
|
2213
|
-
model, is_subagent, parent_session_id,
|
|
2295
|
+
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
2296
|
+
is_teammate, team_name, tool_names_json,
|
|
2214
2297
|
last_prompt, status, updated_at
|
|
2215
2298
|
) VALUES (
|
|
2216
2299
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
@@ -2220,7 +2303,8 @@ var ConversationsRepo = class {
|
|
|
2220
2303
|
@timestamp,
|
|
2221
2304
|
(SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
2222
2305
|
@first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
|
|
2223
|
-
@model, @is_subagent, @parent_session_id, @
|
|
2306
|
+
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
2307
|
+
@is_teammate, @team_name, @tool_names_json,
|
|
2224
2308
|
@last_prompt, 'active', CURRENT_TIMESTAMP
|
|
2225
2309
|
)
|
|
2226
2310
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
@@ -2247,6 +2331,8 @@ var ConversationsRepo = class {
|
|
|
2247
2331
|
model = excluded.model,
|
|
2248
2332
|
is_subagent = excluded.is_subagent,
|
|
2249
2333
|
parent_session_id = excluded.parent_session_id,
|
|
2334
|
+
subagent_id = excluded.subagent_id,
|
|
2335
|
+
parent_session_uuid = excluded.parent_session_uuid,
|
|
2250
2336
|
is_teammate = excluded.is_teammate,
|
|
2251
2337
|
team_name = excluded.team_name,
|
|
2252
2338
|
tool_names_json = excluded.tool_names_json,
|
|
@@ -2282,6 +2368,8 @@ var ConversationsRepo = class {
|
|
|
2282
2368
|
model: meta.model,
|
|
2283
2369
|
is_subagent: meta.isSubagent ? 1 : 0,
|
|
2284
2370
|
parent_session_id: meta.parentSessionId,
|
|
2371
|
+
subagent_id: meta.subagentId ?? null,
|
|
2372
|
+
parent_session_uuid: meta.parentSessionUuid ?? null,
|
|
2285
2373
|
is_teammate: meta.isTeammate ? 1 : 0,
|
|
2286
2374
|
team_name: meta.teamName,
|
|
2287
2375
|
tool_names_json: JSON.stringify(meta.toolNames),
|