@threadbase-sh/scanner 0.24.4 → 0.24.6

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/index.cjs CHANGED
@@ -843,7 +843,8 @@ function initialReducerState() {
843
843
  turnDurations: []
844
844
  };
845
845
  }
846
- function reduceLine(state, entry, tier) {
846
+ function reduceLine(state, rawEntry, tier) {
847
+ const entry = asQueuedPromptUserEntry(rawEntry);
847
848
  if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
848
849
  if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
849
850
  state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
@@ -952,6 +953,18 @@ function getShortProjectName(fullPath) {
952
953
  }
953
954
 
954
955
  // src/parser.ts
956
+ function asQueuedPromptUserEntry(entry) {
957
+ if (entry.type !== "attachment") return entry;
958
+ const att = entry.attachment;
959
+ if (att?.type !== "queued_command" || att.commandMode !== "prompt") return entry;
960
+ if (att.origin?.kind !== "human") return entry;
961
+ return {
962
+ ...entry,
963
+ type: "user",
964
+ attachment: void 0,
965
+ message: { role: "user", content: att.prompt }
966
+ };
967
+ }
955
968
  function turnDurationOf(entry) {
956
969
  if (entry.type !== "system" || entry.subtype !== "turn_duration" || typeof entry.durationMs !== "number") {
957
970
  return null;
@@ -1156,7 +1169,8 @@ function initialConvState() {
1156
1169
  teamInfo: {}
1157
1170
  };
1158
1171
  }
1159
- function reduceConvLine(state, entry) {
1172
+ function reduceConvLine(state, rawEntry) {
1173
+ const entry = asQueuedPromptUserEntry(rawEntry);
1160
1174
  if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
1161
1175
  if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
1162
1176
  state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
@@ -1720,6 +1734,14 @@ var import_readline3 = require("readline");
1720
1734
  var SESSION_START = "session.start";
1721
1735
  var USER_MESSAGE = "user.message";
1722
1736
  var ASSISTANT_MESSAGE = "assistant.message";
1737
+ var TOOL_EXECUTION_COMPLETE = "tool.execution_complete";
1738
+ var PERMISSION_COMPLETED = "permission.completed";
1739
+ var PERMISSION_DECISIONS = {
1740
+ approved: { label: "Approved", isError: false },
1741
+ "approved-for-location": { label: "Approved (and remembered)", isError: false },
1742
+ "denied-interactively-by-user": { label: "Denied", isError: true },
1743
+ cancelled: { label: "Cancelled", isError: true }
1744
+ };
1723
1745
  var CopilotProvider = class {
1724
1746
  name = COPILOT_PROVIDER;
1725
1747
  async discover(roots) {
@@ -1831,8 +1853,37 @@ function copilotEntryToMessage(entry) {
1831
1853
  ...Object.keys(metadata).length > 0 ? { metadata } : {}
1832
1854
  };
1833
1855
  }
1856
+ if (entry.type === TOOL_EXECUTION_COMPLETE) {
1857
+ const toolUseId = asString2(data.toolCallId);
1858
+ if (!toolUseId) return null;
1859
+ const result = asRecord(data.result);
1860
+ const output = asString2(result?.content) || asString2(result?.detailedContent);
1861
+ return toolResultMessage(entry, toolUseId, { output }, data.success === false);
1862
+ }
1863
+ if (entry.type === PERMISSION_COMPLETED) {
1864
+ const toolUseId = asString2(data.toolCallId);
1865
+ const result = asRecord(data.result);
1866
+ const kind = asString2(result?.kind);
1867
+ const decision = Object.hasOwn(PERMISSION_DECISIONS, kind) ? PERMISSION_DECISIONS[kind] : null;
1868
+ if (!toolUseId || !decision) return null;
1869
+ const feedback = kind === "denied-interactively-by-user" ? asString2(result?.feedback).trim() : "";
1870
+ const output = feedback ? `${decision.label}: ${feedback}` : decision.label;
1871
+ return toolResultMessage(entry, toolUseId, { output, permission: kind }, decision.isError);
1872
+ }
1834
1873
  return null;
1835
1874
  }
1875
+ function toolResultMessage(entry, toolUseId, content, isError) {
1876
+ return {
1877
+ role: "user",
1878
+ text: "",
1879
+ timestamp: asString2(entry.timestamp),
1880
+ uuid: asString2(entry.id) || void 0,
1881
+ isToolResult: true,
1882
+ metadata: {
1883
+ toolResults: [{ toolUseId, type: "generic", content, ...isError ? { isError } : {} }]
1884
+ }
1885
+ };
1886
+ }
1836
1887
  function parseCopilotJsonlLine(line) {
1837
1888
  const trimmed = line.trim();
1838
1889
  if (!trimmed) return null;
@@ -3147,7 +3198,7 @@ var import_fs12 = require("fs");
3147
3198
  var import_path11 = require("path");
3148
3199
 
3149
3200
  // src/persistent/schema.ts
3150
- var SCHEMA_VERSION = 11;
3201
+ var SCHEMA_VERSION = 12;
3151
3202
  var SCHEMA_SQL = `
3152
3203
  CREATE TABLE IF NOT EXISTS conversation_files (
3153
3204
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3479,6 +3530,22 @@ function runMigrations(db) {
3479
3530
  }
3480
3531
  }
3481
3532
  }
3533
+ if (current >= 1 && current < 12 && tableExists(db, "conversation_files")) {
3534
+ if (tableExists(db, "message_checkpoints")) db.exec("DELETE FROM message_checkpoints");
3535
+ const assignments = [];
3536
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
3537
+ assignments.push("last_indexed_offset = 0");
3538
+ }
3539
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
3540
+ assignments.push("last_indexed_line = 0");
3541
+ }
3542
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
3543
+ assignments.push("reducer_state = NULL");
3544
+ }
3545
+ if (assignments.length > 0) {
3546
+ db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
3547
+ }
3548
+ }
3482
3549
  db.exec(SCHEMA_SQL);
3483
3550
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
3484
3551
  }