@threadbase-sh/scanner 0.15.0 → 0.16.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/dist/cli.js +72 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +71 -6
- 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 +71 -6
- 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.0";
|
|
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;
|
|
@@ -1389,8 +1406,10 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1389
1406
|
contentSnippet: acc.snippetParts.join(" "),
|
|
1390
1407
|
gitBranch: acc.gitBranch,
|
|
1391
1408
|
model: acc.model,
|
|
1392
|
-
isSubagent:
|
|
1409
|
+
isSubagent: acc.isSubagent,
|
|
1410
|
+
// Codex exposes no path-shaped parent, and no per-child id of its own.
|
|
1393
1411
|
parentSessionId: null,
|
|
1412
|
+
parentSessionUuid: acc.parentSessionUuid ?? void 0,
|
|
1394
1413
|
isTeammate: false,
|
|
1395
1414
|
teamName: null,
|
|
1396
1415
|
toolNames: acc.toolNames,
|
|
@@ -1402,6 +1421,17 @@ function finalizeCodexMeta(acc, filePath, account, tier) {
|
|
|
1402
1421
|
function getShortProjectName3(fullPath) {
|
|
1403
1422
|
return fullPath.split("/").filter(Boolean).slice(-3).join("/");
|
|
1404
1423
|
}
|
|
1424
|
+
function isSubagentSource(source) {
|
|
1425
|
+
return typeof source === "object" && source !== null && "subagent" in source;
|
|
1426
|
+
}
|
|
1427
|
+
function parentThreadId(source) {
|
|
1428
|
+
if (!isSubagentSource(source)) return null;
|
|
1429
|
+
const subagent = source.subagent;
|
|
1430
|
+
if (typeof subagent !== "object" || subagent === null) return null;
|
|
1431
|
+
const spawn = subagent.thread_spawn;
|
|
1432
|
+
if (typeof spawn !== "object" || spawn === null) return null;
|
|
1433
|
+
return asString(spawn.parent_thread_id) || null;
|
|
1434
|
+
}
|
|
1405
1435
|
async function parseCodexConversation(filePath, account) {
|
|
1406
1436
|
const log = getLogger();
|
|
1407
1437
|
const messages = [];
|
|
@@ -1655,7 +1685,7 @@ import { mkdirSync } from "fs";
|
|
|
1655
1685
|
import { dirname as dirname3 } from "path";
|
|
1656
1686
|
|
|
1657
1687
|
// src/persistent/schema.ts
|
|
1658
|
-
var SCHEMA_VERSION =
|
|
1688
|
+
var SCHEMA_VERSION = 6;
|
|
1659
1689
|
var SCHEMA_SQL = `
|
|
1660
1690
|
CREATE TABLE IF NOT EXISTS conversation_files (
|
|
1661
1691
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -1730,7 +1760,11 @@ CREATE TABLE IF NOT EXISTS conversations (
|
|
|
1730
1760
|
|
|
1731
1761
|
model TEXT,
|
|
1732
1762
|
is_subagent INTEGER NOT NULL DEFAULT 0,
|
|
1763
|
+
-- The parent's JSONL PATH (matched against source_path), not an id.
|
|
1733
1764
|
parent_session_id TEXT,
|
|
1765
|
+
-- The subagent's own id (Claude agentId), and the parent's session UUID.
|
|
1766
|
+
subagent_id TEXT,
|
|
1767
|
+
parent_session_uuid TEXT,
|
|
1734
1768
|
is_teammate INTEGER NOT NULL DEFAULT 0,
|
|
1735
1769
|
team_name TEXT,
|
|
1736
1770
|
tool_names_json TEXT,
|
|
@@ -1863,6 +1897,29 @@ function runMigrations(db) {
|
|
|
1863
1897
|
}
|
|
1864
1898
|
}
|
|
1865
1899
|
}
|
|
1900
|
+
if (current >= 1 && current < 6 && tableExists(db, "conversations")) {
|
|
1901
|
+
for (const [col, ddl] of [
|
|
1902
|
+
["subagent_id", "ALTER TABLE conversations ADD COLUMN subagent_id TEXT"],
|
|
1903
|
+
["parent_session_uuid", "ALTER TABLE conversations ADD COLUMN parent_session_uuid TEXT"]
|
|
1904
|
+
]) {
|
|
1905
|
+
if (!hasColumn(db, "conversations", col)) db.exec(ddl);
|
|
1906
|
+
}
|
|
1907
|
+
if (tableExists(db, "conversation_files")) {
|
|
1908
|
+
const assignments = [];
|
|
1909
|
+
if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
|
|
1910
|
+
assignments.push("last_indexed_offset = 0");
|
|
1911
|
+
}
|
|
1912
|
+
if (hasColumn(db, "conversation_files", "last_indexed_line")) {
|
|
1913
|
+
assignments.push("last_indexed_line = 0");
|
|
1914
|
+
}
|
|
1915
|
+
if (hasColumn(db, "conversation_files", "reducer_state")) {
|
|
1916
|
+
assignments.push("reducer_state = NULL");
|
|
1917
|
+
}
|
|
1918
|
+
if (assignments.length > 0) {
|
|
1919
|
+
db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
|
|
1920
|
+
}
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1866
1923
|
db.exec(SCHEMA_SQL);
|
|
1867
1924
|
db.pragma(`user_version = ${SCHEMA_VERSION}`);
|
|
1868
1925
|
}
|
|
@@ -2187,6 +2244,8 @@ function rowToMeta(row) {
|
|
|
2187
2244
|
model: row.model,
|
|
2188
2245
|
isSubagent: row.is_subagent === 1,
|
|
2189
2246
|
parentSessionId: row.parent_session_id,
|
|
2247
|
+
subagentId: row.subagent_id ?? void 0,
|
|
2248
|
+
parentSessionUuid: row.parent_session_uuid ?? void 0,
|
|
2190
2249
|
isTeammate: row.is_teammate === 1,
|
|
2191
2250
|
teamName: row.team_name,
|
|
2192
2251
|
toolNames: row.tool_names_json ? JSON.parse(row.tool_names_json) : [],
|
|
@@ -2210,7 +2269,8 @@ var ConversationsRepo = class {
|
|
|
2210
2269
|
account, branch, preview, content_snippet, message_count, page_message_count,
|
|
2211
2270
|
last_message_sender,
|
|
2212
2271
|
timestamp, index_seq, first_sent_at, first_sent_text, last_sent_at, last_sent_text,
|
|
2213
|
-
model, is_subagent, parent_session_id,
|
|
2272
|
+
model, is_subagent, parent_session_id, subagent_id, parent_session_uuid,
|
|
2273
|
+
is_teammate, team_name, tool_names_json,
|
|
2214
2274
|
last_prompt, status, updated_at
|
|
2215
2275
|
) VALUES (
|
|
2216
2276
|
@file_id, @source_path, @provider, @kind, @external_session_id,
|
|
@@ -2220,7 +2280,8 @@ var ConversationsRepo = class {
|
|
|
2220
2280
|
@timestamp,
|
|
2221
2281
|
(SELECT COALESCE(MAX(index_seq), 0) + 1 FROM conversations),
|
|
2222
2282
|
@first_sent_at, @first_sent_text, @last_sent_at, @last_sent_text,
|
|
2223
|
-
@model, @is_subagent, @parent_session_id, @
|
|
2283
|
+
@model, @is_subagent, @parent_session_id, @subagent_id, @parent_session_uuid,
|
|
2284
|
+
@is_teammate, @team_name, @tool_names_json,
|
|
2224
2285
|
@last_prompt, 'active', CURRENT_TIMESTAMP
|
|
2225
2286
|
)
|
|
2226
2287
|
ON CONFLICT(file_id) DO UPDATE SET
|
|
@@ -2247,6 +2308,8 @@ var ConversationsRepo = class {
|
|
|
2247
2308
|
model = excluded.model,
|
|
2248
2309
|
is_subagent = excluded.is_subagent,
|
|
2249
2310
|
parent_session_id = excluded.parent_session_id,
|
|
2311
|
+
subagent_id = excluded.subagent_id,
|
|
2312
|
+
parent_session_uuid = excluded.parent_session_uuid,
|
|
2250
2313
|
is_teammate = excluded.is_teammate,
|
|
2251
2314
|
team_name = excluded.team_name,
|
|
2252
2315
|
tool_names_json = excluded.tool_names_json,
|
|
@@ -2282,6 +2345,8 @@ var ConversationsRepo = class {
|
|
|
2282
2345
|
model: meta.model,
|
|
2283
2346
|
is_subagent: meta.isSubagent ? 1 : 0,
|
|
2284
2347
|
parent_session_id: meta.parentSessionId,
|
|
2348
|
+
subagent_id: meta.subagentId ?? null,
|
|
2349
|
+
parent_session_uuid: meta.parentSessionUuid ?? null,
|
|
2285
2350
|
is_teammate: meta.isTeammate ? 1 : 0,
|
|
2286
2351
|
team_name: meta.teamName,
|
|
2287
2352
|
tool_names_json: JSON.stringify(meta.toolNames),
|