@threadbase-sh/scanner 0.24.5 → 0.24.7

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
@@ -1734,6 +1734,14 @@ var import_readline3 = require("readline");
1734
1734
  var SESSION_START = "session.start";
1735
1735
  var USER_MESSAGE = "user.message";
1736
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
+ };
1737
1745
  var CopilotProvider = class {
1738
1746
  name = COPILOT_PROVIDER;
1739
1747
  async discover(roots) {
@@ -1845,8 +1853,37 @@ function copilotEntryToMessage(entry) {
1845
1853
  ...Object.keys(metadata).length > 0 ? { metadata } : {}
1846
1854
  };
1847
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
+ }
1848
1873
  return null;
1849
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
+ }
1850
1887
  function parseCopilotJsonlLine(line) {
1851
1888
  const trimmed = line.trim();
1852
1889
  if (!trimmed) return null;
@@ -5475,9 +5512,17 @@ var ConversationScanner = class {
5475
5512
  try {
5476
5513
  const fd = (0, import_fs14.openSync)(filePath, "r");
5477
5514
  try {
5478
- const buf = Buffer.alloc(8192);
5479
- const n = (0, import_fs14.readSync)(fd, buf, 0, buf.length, 0);
5480
- sample = buf.subarray(0, n).toString("utf8");
5515
+ const chunks = [];
5516
+ let pos = 0;
5517
+ while (pos < 1024 * 1024) {
5518
+ const chunk = Buffer.alloc(8192);
5519
+ const n = (0, import_fs14.readSync)(fd, chunk, 0, chunk.length, pos);
5520
+ if (n === 0) break;
5521
+ chunks.push(chunk.subarray(0, n));
5522
+ pos += n;
5523
+ if (chunk.subarray(0, n).includes(10)) break;
5524
+ }
5525
+ sample = Buffer.concat(chunks).toString("utf8");
5481
5526
  } finally {
5482
5527
  (0, import_fs14.closeSync)(fd);
5483
5528
  }