cogpit-memory 0.1.8 → 0.1.9
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 +33 -23
- package/dist/index.js +33 -23
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -951,6 +951,19 @@ function extractSessionMetadata(messages) {
|
|
|
951
951
|
}
|
|
952
952
|
return meta;
|
|
953
953
|
}
|
|
954
|
+
function emptyStats(turnCount) {
|
|
955
|
+
return {
|
|
956
|
+
totalInputTokens: 0,
|
|
957
|
+
totalOutputTokens: 0,
|
|
958
|
+
totalCacheCreationTokens: 0,
|
|
959
|
+
totalCacheReadTokens: 0,
|
|
960
|
+
totalCostUSD: 0,
|
|
961
|
+
toolCallCounts: {},
|
|
962
|
+
errorCount: 0,
|
|
963
|
+
totalDurationMs: 0,
|
|
964
|
+
turnCount
|
|
965
|
+
};
|
|
966
|
+
}
|
|
954
967
|
function parseSession(jsonlText, opts) {
|
|
955
968
|
if (isCodexSessionText(jsonlText)) {
|
|
956
969
|
return parseCodexSession(jsonlText);
|
|
@@ -958,7 +971,7 @@ function parseSession(jsonlText, opts) {
|
|
|
958
971
|
const rawMessages = parseLines(jsonlText);
|
|
959
972
|
const metadata = extractSessionMetadata(rawMessages);
|
|
960
973
|
const turns = buildTurns(rawMessages);
|
|
961
|
-
const stats = opts?.skipStats ?
|
|
974
|
+
const stats = opts?.skipStats ? emptyStats(turns.length) : computeStats(turns);
|
|
962
975
|
return {
|
|
963
976
|
...metadata,
|
|
964
977
|
turns,
|
|
@@ -1038,6 +1051,18 @@ var SearchIndex = class {
|
|
|
1038
1051
|
lastUpdate: this._lastUpdate
|
|
1039
1052
|
};
|
|
1040
1053
|
}
|
|
1054
|
+
/** Index tool call inputs and results under the given location prefix. */
|
|
1055
|
+
insertToolCalls(insert, sessionId, filePath, prefix, toolCalls) {
|
|
1056
|
+
for (const tc of toolCalls) {
|
|
1057
|
+
const inputStr = JSON.stringify(tc.input);
|
|
1058
|
+
if (inputStr && inputStr !== "{}") {
|
|
1059
|
+
insert.run(sessionId, filePath, `${prefix}/toolCall/${tc.id}/input`, truncContent(inputStr));
|
|
1060
|
+
}
|
|
1061
|
+
if (tc.result) {
|
|
1062
|
+
insert.run(sessionId, filePath, `${prefix}/toolCall/${tc.id}/result`, truncContent(tc.result));
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1041
1066
|
/**
|
|
1042
1067
|
* Insert all searchable content from a parsed session into the FTS5 index.
|
|
1043
1068
|
* Shared by both `indexFile` (single-file) and `buildFull` (batch).
|
|
@@ -1058,15 +1083,7 @@ var SearchIndex = class {
|
|
|
1058
1083
|
if (thinkingText) {
|
|
1059
1084
|
insert.run(sessionId, filePath, `${prefix}/thinking`, truncContent(thinkingText));
|
|
1060
1085
|
}
|
|
1061
|
-
|
|
1062
|
-
const inputStr = JSON.stringify(tc.input);
|
|
1063
|
-
if (inputStr && inputStr !== "{}") {
|
|
1064
|
-
insert.run(sessionId, filePath, `${prefix}/toolCall/${tc.id}/input`, truncContent(inputStr));
|
|
1065
|
-
}
|
|
1066
|
-
if (tc.result) {
|
|
1067
|
-
insert.run(sessionId, filePath, `${prefix}/toolCall/${tc.id}/result`, truncContent(tc.result));
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1086
|
+
this.insertToolCalls(insert, sessionId, filePath, prefix, turn.toolCalls);
|
|
1070
1087
|
for (const sa of turn.subAgentActivity) {
|
|
1071
1088
|
const saPrefix = `agent/${sa.agentId}`;
|
|
1072
1089
|
const saText = sa.text.join("\n\n").trim();
|
|
@@ -1077,15 +1094,7 @@ var SearchIndex = class {
|
|
|
1077
1094
|
if (saThinking) {
|
|
1078
1095
|
insert.run(sessionId, filePath, `${saPrefix}/thinking`, truncContent(saThinking));
|
|
1079
1096
|
}
|
|
1080
|
-
|
|
1081
|
-
const inputStr = JSON.stringify(tc.input);
|
|
1082
|
-
if (inputStr && inputStr !== "{}") {
|
|
1083
|
-
insert.run(sessionId, filePath, `${saPrefix}/toolCall/${tc.id}/input`, truncContent(inputStr));
|
|
1084
|
-
}
|
|
1085
|
-
if (tc.result) {
|
|
1086
|
-
insert.run(sessionId, filePath, `${saPrefix}/toolCall/${tc.id}/result`, truncContent(tc.result));
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1097
|
+
this.insertToolCalls(insert, sessionId, filePath, saPrefix, sa.toolCalls);
|
|
1089
1098
|
}
|
|
1090
1099
|
if (turn.compactionSummary) {
|
|
1091
1100
|
insert.run(sessionId, filePath, `${prefix}/compactionSummary`, truncContent(turn.compactionSummary));
|
|
@@ -1132,7 +1141,7 @@ var SearchIndex = class {
|
|
|
1132
1141
|
/**
|
|
1133
1142
|
* Query the FTS5 index and return structured search results.
|
|
1134
1143
|
*
|
|
1135
|
-
* - FTS5
|
|
1144
|
+
* - FTS5 unicode61 tokenizer is case-insensitive by default.
|
|
1136
1145
|
* - When `caseSensitive` is true, a post-filter checks the original query
|
|
1137
1146
|
* against the snippet text (exact case match).
|
|
1138
1147
|
* - When `maxAgeMs` is provided, only files whose mtime in `indexed_files`
|
|
@@ -1303,9 +1312,10 @@ var SearchIndex = class {
|
|
|
1303
1312
|
/**
|
|
1304
1313
|
* Lightweight incremental update for CLI search paths.
|
|
1305
1314
|
*
|
|
1306
|
-
*
|
|
1307
|
-
*
|
|
1308
|
-
*
|
|
1315
|
+
* Still walks and stats all files via `discoverFiles`, but skips DB lookups
|
|
1316
|
+
* for files with mtime <= the high-water mark that are already indexed.
|
|
1317
|
+
* Caps re-indexing to `maxFiles` to prevent blocking on large backlogs
|
|
1318
|
+
* (run `index rebuild` for a full catch-up).
|
|
1309
1319
|
*/
|
|
1310
1320
|
updateRecent(projectsDir, maxFiles = 50) {
|
|
1311
1321
|
this.projectsDir = projectsDir;
|
package/dist/index.js
CHANGED
|
@@ -967,6 +967,19 @@ function extractSessionMetadata(messages) {
|
|
|
967
967
|
}
|
|
968
968
|
return meta;
|
|
969
969
|
}
|
|
970
|
+
function emptyStats(turnCount) {
|
|
971
|
+
return {
|
|
972
|
+
totalInputTokens: 0,
|
|
973
|
+
totalOutputTokens: 0,
|
|
974
|
+
totalCacheCreationTokens: 0,
|
|
975
|
+
totalCacheReadTokens: 0,
|
|
976
|
+
totalCostUSD: 0,
|
|
977
|
+
toolCallCounts: {},
|
|
978
|
+
errorCount: 0,
|
|
979
|
+
totalDurationMs: 0,
|
|
980
|
+
turnCount
|
|
981
|
+
};
|
|
982
|
+
}
|
|
970
983
|
function parseSession(jsonlText, opts) {
|
|
971
984
|
if (isCodexSessionText(jsonlText)) {
|
|
972
985
|
return parseCodexSession(jsonlText);
|
|
@@ -974,7 +987,7 @@ function parseSession(jsonlText, opts) {
|
|
|
974
987
|
const rawMessages = parseLines(jsonlText);
|
|
975
988
|
const metadata = extractSessionMetadata(rawMessages);
|
|
976
989
|
const turns = buildTurns(rawMessages);
|
|
977
|
-
const stats = opts?.skipStats ?
|
|
990
|
+
const stats = opts?.skipStats ? emptyStats(turns.length) : computeStats(turns);
|
|
978
991
|
return {
|
|
979
992
|
...metadata,
|
|
980
993
|
turns,
|
|
@@ -1136,6 +1149,18 @@ var SearchIndex = class {
|
|
|
1136
1149
|
lastUpdate: this._lastUpdate
|
|
1137
1150
|
};
|
|
1138
1151
|
}
|
|
1152
|
+
/** Index tool call inputs and results under the given location prefix. */
|
|
1153
|
+
insertToolCalls(insert, sessionId, filePath, prefix, toolCalls) {
|
|
1154
|
+
for (const tc of toolCalls) {
|
|
1155
|
+
const inputStr = JSON.stringify(tc.input);
|
|
1156
|
+
if (inputStr && inputStr !== "{}") {
|
|
1157
|
+
insert.run(sessionId, filePath, `${prefix}/toolCall/${tc.id}/input`, truncContent(inputStr));
|
|
1158
|
+
}
|
|
1159
|
+
if (tc.result) {
|
|
1160
|
+
insert.run(sessionId, filePath, `${prefix}/toolCall/${tc.id}/result`, truncContent(tc.result));
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1139
1164
|
/**
|
|
1140
1165
|
* Insert all searchable content from a parsed session into the FTS5 index.
|
|
1141
1166
|
* Shared by both `indexFile` (single-file) and `buildFull` (batch).
|
|
@@ -1156,15 +1181,7 @@ var SearchIndex = class {
|
|
|
1156
1181
|
if (thinkingText) {
|
|
1157
1182
|
insert.run(sessionId, filePath, `${prefix}/thinking`, truncContent(thinkingText));
|
|
1158
1183
|
}
|
|
1159
|
-
|
|
1160
|
-
const inputStr = JSON.stringify(tc.input);
|
|
1161
|
-
if (inputStr && inputStr !== "{}") {
|
|
1162
|
-
insert.run(sessionId, filePath, `${prefix}/toolCall/${tc.id}/input`, truncContent(inputStr));
|
|
1163
|
-
}
|
|
1164
|
-
if (tc.result) {
|
|
1165
|
-
insert.run(sessionId, filePath, `${prefix}/toolCall/${tc.id}/result`, truncContent(tc.result));
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1184
|
+
this.insertToolCalls(insert, sessionId, filePath, prefix, turn.toolCalls);
|
|
1168
1185
|
for (const sa of turn.subAgentActivity) {
|
|
1169
1186
|
const saPrefix = `agent/${sa.agentId}`;
|
|
1170
1187
|
const saText = sa.text.join("\n\n").trim();
|
|
@@ -1175,15 +1192,7 @@ var SearchIndex = class {
|
|
|
1175
1192
|
if (saThinking) {
|
|
1176
1193
|
insert.run(sessionId, filePath, `${saPrefix}/thinking`, truncContent(saThinking));
|
|
1177
1194
|
}
|
|
1178
|
-
|
|
1179
|
-
const inputStr = JSON.stringify(tc.input);
|
|
1180
|
-
if (inputStr && inputStr !== "{}") {
|
|
1181
|
-
insert.run(sessionId, filePath, `${saPrefix}/toolCall/${tc.id}/input`, truncContent(inputStr));
|
|
1182
|
-
}
|
|
1183
|
-
if (tc.result) {
|
|
1184
|
-
insert.run(sessionId, filePath, `${saPrefix}/toolCall/${tc.id}/result`, truncContent(tc.result));
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1195
|
+
this.insertToolCalls(insert, sessionId, filePath, saPrefix, sa.toolCalls);
|
|
1187
1196
|
}
|
|
1188
1197
|
if (turn.compactionSummary) {
|
|
1189
1198
|
insert.run(sessionId, filePath, `${prefix}/compactionSummary`, truncContent(turn.compactionSummary));
|
|
@@ -1230,7 +1239,7 @@ var SearchIndex = class {
|
|
|
1230
1239
|
/**
|
|
1231
1240
|
* Query the FTS5 index and return structured search results.
|
|
1232
1241
|
*
|
|
1233
|
-
* - FTS5
|
|
1242
|
+
* - FTS5 unicode61 tokenizer is case-insensitive by default.
|
|
1234
1243
|
* - When `caseSensitive` is true, a post-filter checks the original query
|
|
1235
1244
|
* against the snippet text (exact case match).
|
|
1236
1245
|
* - When `maxAgeMs` is provided, only files whose mtime in `indexed_files`
|
|
@@ -1401,9 +1410,10 @@ var SearchIndex = class {
|
|
|
1401
1410
|
/**
|
|
1402
1411
|
* Lightweight incremental update for CLI search paths.
|
|
1403
1412
|
*
|
|
1404
|
-
*
|
|
1405
|
-
*
|
|
1406
|
-
*
|
|
1413
|
+
* Still walks and stats all files via `discoverFiles`, but skips DB lookups
|
|
1414
|
+
* for files with mtime <= the high-water mark that are already indexed.
|
|
1415
|
+
* Caps re-indexing to `maxFiles` to prevent blocking on large backlogs
|
|
1416
|
+
* (run `index rebuild` for a full catch-up).
|
|
1407
1417
|
*/
|
|
1408
1418
|
updateRecent(projectsDir, maxFiles = 50) {
|
|
1409
1419
|
this.projectsDir = projectsDir;
|
package/package.json
CHANGED