@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.js CHANGED
@@ -753,7 +753,8 @@ function initialReducerState() {
753
753
  turnDurations: []
754
754
  };
755
755
  }
756
- function reduceLine(state, entry, tier) {
756
+ function reduceLine(state, rawEntry, tier) {
757
+ const entry = asQueuedPromptUserEntry(rawEntry);
757
758
  if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
758
759
  if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
759
760
  state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
@@ -862,6 +863,18 @@ function getShortProjectName(fullPath) {
862
863
  }
863
864
 
864
865
  // src/parser.ts
866
+ function asQueuedPromptUserEntry(entry) {
867
+ if (entry.type !== "attachment") return entry;
868
+ const att = entry.attachment;
869
+ if (att?.type !== "queued_command" || att.commandMode !== "prompt") return entry;
870
+ if (att.origin?.kind !== "human") return entry;
871
+ return {
872
+ ...entry,
873
+ type: "user",
874
+ attachment: void 0,
875
+ message: { role: "user", content: att.prompt }
876
+ };
877
+ }
865
878
  function turnDurationOf(entry) {
866
879
  if (entry.type !== "system" || entry.subtype !== "turn_duration" || typeof entry.durationMs !== "number") {
867
880
  return null;
@@ -1066,7 +1079,8 @@ function initialConvState() {
1066
1079
  teamInfo: {}
1067
1080
  };
1068
1081
  }
1069
- function reduceConvLine(state, entry) {
1082
+ function reduceConvLine(state, rawEntry) {
1083
+ const entry = asQueuedPromptUserEntry(rawEntry);
1070
1084
  if (entry.cwd && !state.cwd) state.cwd = entry.cwd;
1071
1085
  if (entry.sessionId && !state.sessionId) state.sessionId = entry.sessionId;
1072
1086
  state.nameSlots = applyClaudeNameEntry(state.nameSlots, entry);
@@ -1630,6 +1644,14 @@ import { createInterface as createInterface3 } from "readline";
1630
1644
  var SESSION_START = "session.start";
1631
1645
  var USER_MESSAGE = "user.message";
1632
1646
  var ASSISTANT_MESSAGE = "assistant.message";
1647
+ var TOOL_EXECUTION_COMPLETE = "tool.execution_complete";
1648
+ var PERMISSION_COMPLETED = "permission.completed";
1649
+ var PERMISSION_DECISIONS = {
1650
+ approved: { label: "Approved", isError: false },
1651
+ "approved-for-location": { label: "Approved (and remembered)", isError: false },
1652
+ "denied-interactively-by-user": { label: "Denied", isError: true },
1653
+ cancelled: { label: "Cancelled", isError: true }
1654
+ };
1633
1655
  var CopilotProvider = class {
1634
1656
  name = COPILOT_PROVIDER;
1635
1657
  async discover(roots) {
@@ -1741,8 +1763,37 @@ function copilotEntryToMessage(entry) {
1741
1763
  ...Object.keys(metadata).length > 0 ? { metadata } : {}
1742
1764
  };
1743
1765
  }
1766
+ if (entry.type === TOOL_EXECUTION_COMPLETE) {
1767
+ const toolUseId = asString2(data.toolCallId);
1768
+ if (!toolUseId) return null;
1769
+ const result = asRecord(data.result);
1770
+ const output = asString2(result?.content) || asString2(result?.detailedContent);
1771
+ return toolResultMessage(entry, toolUseId, { output }, data.success === false);
1772
+ }
1773
+ if (entry.type === PERMISSION_COMPLETED) {
1774
+ const toolUseId = asString2(data.toolCallId);
1775
+ const result = asRecord(data.result);
1776
+ const kind = asString2(result?.kind);
1777
+ const decision = Object.hasOwn(PERMISSION_DECISIONS, kind) ? PERMISSION_DECISIONS[kind] : null;
1778
+ if (!toolUseId || !decision) return null;
1779
+ const feedback = kind === "denied-interactively-by-user" ? asString2(result?.feedback).trim() : "";
1780
+ const output = feedback ? `${decision.label}: ${feedback}` : decision.label;
1781
+ return toolResultMessage(entry, toolUseId, { output, permission: kind }, decision.isError);
1782
+ }
1744
1783
  return null;
1745
1784
  }
1785
+ function toolResultMessage(entry, toolUseId, content, isError) {
1786
+ return {
1787
+ role: "user",
1788
+ text: "",
1789
+ timestamp: asString2(entry.timestamp),
1790
+ uuid: asString2(entry.id) || void 0,
1791
+ isToolResult: true,
1792
+ metadata: {
1793
+ toolResults: [{ toolUseId, type: "generic", content, ...isError ? { isError } : {} }]
1794
+ }
1795
+ };
1796
+ }
1746
1797
  function parseCopilotJsonlLine(line) {
1747
1798
  const trimmed = line.trim();
1748
1799
  if (!trimmed) return null;
@@ -3057,7 +3108,7 @@ import { mkdirSync } from "fs";
3057
3108
  import { dirname as dirname6 } from "path";
3058
3109
 
3059
3110
  // src/persistent/schema.ts
3060
- var SCHEMA_VERSION = 11;
3111
+ var SCHEMA_VERSION = 12;
3061
3112
  var SCHEMA_SQL = `
3062
3113
  CREATE TABLE IF NOT EXISTS conversation_files (
3063
3114
  id INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -3389,6 +3440,22 @@ function runMigrations(db) {
3389
3440
  }
3390
3441
  }
3391
3442
  }
3443
+ if (current >= 1 && current < 12 && tableExists(db, "conversation_files")) {
3444
+ if (tableExists(db, "message_checkpoints")) db.exec("DELETE FROM message_checkpoints");
3445
+ const assignments = [];
3446
+ if (hasColumn(db, "conversation_files", "last_indexed_offset")) {
3447
+ assignments.push("last_indexed_offset = 0");
3448
+ }
3449
+ if (hasColumn(db, "conversation_files", "last_indexed_line")) {
3450
+ assignments.push("last_indexed_line = 0");
3451
+ }
3452
+ if (hasColumn(db, "conversation_files", "reducer_state")) {
3453
+ assignments.push("reducer_state = NULL");
3454
+ }
3455
+ if (assignments.length > 0) {
3456
+ db.exec(`UPDATE conversation_files SET ${assignments.join(", ")}`);
3457
+ }
3458
+ }
3392
3459
  db.exec(SCHEMA_SQL);
3393
3460
  db.pragma(`user_version = ${SCHEMA_VERSION}`);
3394
3461
  }