caveat-cli 0.13.0 → 0.14.1

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/caveat.js CHANGED
File without changes
@@ -14626,8 +14626,179 @@ function struggleSearchText(s) {
14626
14626
  return [...s.errorSnippets, ...s.searchQueries].join(" ");
14627
14627
  }
14628
14628
 
14629
+ // ../../packages/core/dist/codexTranscriptSignals.js
14630
+ import { existsSync as existsSync7, readFileSync as readFileSync5 } from "node:fs";
14631
+ var MAX_ERROR_SNIPPETS2 = 10;
14632
+ var MAX_ERROR_SNIPPET_LENGTH2 = 300;
14633
+ var MAX_SEARCH_QUERIES2 = 10;
14634
+ var MAX_SEARCH_QUERY_LENGTH2 = 200;
14635
+ var MAX_FILE_EDIT_ENTRIES2 = 20;
14636
+ function isRecord2(v) {
14637
+ return typeof v === "object" && v !== null && !Array.isArray(v);
14638
+ }
14639
+ function parseTimestamp2(raw) {
14640
+ if (typeof raw !== "string") return void 0;
14641
+ const ms = Date.parse(raw);
14642
+ return Number.isNaN(ms) ? void 0 : ms;
14643
+ }
14644
+ function parseArgs(raw) {
14645
+ if (isRecord2(raw)) return raw;
14646
+ if (typeof raw !== "string" || raw.length === 0) return {};
14647
+ try {
14648
+ const parsed = JSON.parse(raw);
14649
+ return isRecord2(parsed) ? parsed : {};
14650
+ } catch {
14651
+ return {};
14652
+ }
14653
+ }
14654
+ function compactText(text) {
14655
+ return text.replace(/\s+/g, " ").trim();
14656
+ }
14657
+ function extractExitCode(output) {
14658
+ const m = /Process exited with code\s+(-?\d+)/.exec(output);
14659
+ return m ? Number(m[1]) : null;
14660
+ }
14661
+ function extractCommand(name, args) {
14662
+ if (name !== "exec_command" && name !== "Bash") return void 0;
14663
+ const cmd = args.cmd ?? args.command;
14664
+ return typeof cmd === "string" && cmd.length > 0 ? cmd : void 0;
14665
+ }
14666
+ function addEditPath(editCounts, path) {
14667
+ if (typeof path !== "string" || path.length === 0) return;
14668
+ editCounts.set(path, (editCounts.get(path) ?? 0) + 1);
14669
+ }
14670
+ function collectPatchPaths(patch) {
14671
+ const paths = [];
14672
+ for (const line of patch.split("\n")) {
14673
+ const m = /^\*\*\* (?:Add|Update|Delete) File: (.+)$/.exec(line);
14674
+ if (m?.[1]) paths.push(m[1]);
14675
+ }
14676
+ return paths;
14677
+ }
14678
+ function collectSearchQueries(args) {
14679
+ const queries = [];
14680
+ const rawSearch = args.search_query;
14681
+ if (Array.isArray(rawSearch)) {
14682
+ for (const item of rawSearch) {
14683
+ if (isRecord2(item) && typeof item.q === "string") queries.push(item.q);
14684
+ }
14685
+ }
14686
+ if (typeof args.query === "string") queries.push(args.query);
14687
+ if (typeof args.q === "string") queries.push(args.q);
14688
+ return queries;
14689
+ }
14690
+ function addQuery(searchQueries, query) {
14691
+ if (searchQueries.length >= MAX_SEARCH_QUERIES2) return;
14692
+ searchQueries.push(query.slice(0, MAX_SEARCH_QUERY_LENGTH2));
14693
+ }
14694
+ function readCodexSessionSignals(transcriptPath) {
14695
+ if (!transcriptPath || !existsSync7(transcriptPath)) return null;
14696
+ let raw;
14697
+ try {
14698
+ raw = readFileSync5(transcriptPath, "utf-8");
14699
+ } catch {
14700
+ return null;
14701
+ }
14702
+ const editCounts = /* @__PURE__ */ new Map();
14703
+ const bashCounts = /* @__PURE__ */ new Map();
14704
+ const toolCalls = /* @__PURE__ */ new Map();
14705
+ const errorSnippets = [];
14706
+ const searchQueries = [];
14707
+ const failedCallIds = /* @__PURE__ */ new Set();
14708
+ let toolFailureCount = 0;
14709
+ let webSearchCount = 0;
14710
+ let webFetchCount = 0;
14711
+ let firstTs;
14712
+ let lastTs;
14713
+ for (const line of raw.split("\n")) {
14714
+ if (line.length === 0) continue;
14715
+ let parsed;
14716
+ try {
14717
+ parsed = JSON.parse(line);
14718
+ } catch {
14719
+ continue;
14720
+ }
14721
+ const ts = parseTimestamp2(parsed.timestamp);
14722
+ if (ts !== void 0) {
14723
+ if (firstTs === void 0 || ts < firstTs) firstTs = ts;
14724
+ if (lastTs === void 0 || ts > lastTs) lastTs = ts;
14725
+ }
14726
+ if (!isRecord2(parsed.payload)) continue;
14727
+ const payload = parsed.payload;
14728
+ if (parsed.type === "response_item" && payload.type === "function_call") {
14729
+ const name = typeof payload.name === "string" ? payload.name : "";
14730
+ const args = parseArgs(payload.arguments);
14731
+ const callId = typeof payload.call_id === "string" ? payload.call_id : "";
14732
+ const command = extractCommand(name, args);
14733
+ if (callId && name) toolCalls.set(callId, { name, args, command });
14734
+ if (command) bashCounts.set(command, (bashCounts.get(command) ?? 0) + 1);
14735
+ if (name === "apply_patch") {
14736
+ const patch = typeof args.patch === "string" ? args.patch : "";
14737
+ for (const path of collectPatchPaths(patch)) addEditPath(editCounts, path);
14738
+ } else if (name === "edit" || name === "write" || name === "notebook_edit") {
14739
+ addEditPath(editCounts, args.path ?? args.file_path);
14740
+ } else if (name === "web.run") {
14741
+ const queries = collectSearchQueries(args);
14742
+ webSearchCount += queries.length;
14743
+ for (const query of queries) addQuery(searchQueries, query);
14744
+ if (Array.isArray(args.open)) webFetchCount += args.open.length;
14745
+ }
14746
+ continue;
14747
+ }
14748
+ if (parsed.type === "response_item" && payload.type === "web_search_call") {
14749
+ webSearchCount += 1;
14750
+ if (typeof payload.query === "string") addQuery(searchQueries, payload.query);
14751
+ continue;
14752
+ }
14753
+ if (parsed.type === "response_item" && payload.type === "function_call_output") {
14754
+ const callId = typeof payload.call_id === "string" ? payload.call_id : "";
14755
+ const output = typeof payload.output === "string" ? payload.output : "";
14756
+ const exit = extractExitCode(output);
14757
+ if (callId && exit !== null && exit !== 0 && !failedCallIds.has(callId)) {
14758
+ failedCallIds.add(callId);
14759
+ toolFailureCount += 1;
14760
+ const text = compactText(output);
14761
+ if (text && errorSnippets.length < MAX_ERROR_SNIPPETS2) {
14762
+ errorSnippets.push(text.slice(0, MAX_ERROR_SNIPPET_LENGTH2));
14763
+ }
14764
+ }
14765
+ continue;
14766
+ }
14767
+ if (parsed.type === "event_msg" && payload.type === "exec_command_end") {
14768
+ const exit = typeof payload.exit_code === "number" ? payload.exit_code : null;
14769
+ const callId = typeof payload.call_id === "string" ? payload.call_id : "";
14770
+ if (exit !== null && exit !== 0 && (!callId || !failedCallIds.has(callId))) {
14771
+ if (callId) failedCallIds.add(callId);
14772
+ toolFailureCount += 1;
14773
+ const output = typeof payload.output === "string" ? payload.output : "";
14774
+ const text = compactText(output);
14775
+ if (text && errorSnippets.length < MAX_ERROR_SNIPPETS2) {
14776
+ errorSnippets.push(text.slice(0, MAX_ERROR_SNIPPET_LENGTH2));
14777
+ }
14778
+ }
14779
+ }
14780
+ }
14781
+ for (const { command } of toolCalls.values()) {
14782
+ if (!command) continue;
14783
+ if (!bashCounts.has(command)) bashCounts.set(command, 1);
14784
+ }
14785
+ const fileEditCounts = [...editCounts.entries()].filter(([, c3]) => c3 > 1).map(([path, count]) => ({ path, count })).sort((a, b2) => b2.count - a.count).slice(0, MAX_FILE_EDIT_ENTRIES2);
14786
+ const bashRetryCount = [...bashCounts.values()].filter((c3) => c3 > 1).length;
14787
+ const durationMinutes = firstTs !== void 0 && lastTs !== void 0 ? Math.max(0, Math.round((lastTs - firstTs) / 6e4)) : 0;
14788
+ return {
14789
+ toolFailureCount,
14790
+ fileEditCounts,
14791
+ webSearchCount,
14792
+ webFetchCount,
14793
+ bashRetryCount,
14794
+ durationMinutes,
14795
+ errorSnippets,
14796
+ searchQueries
14797
+ };
14798
+ }
14799
+
14629
14800
  // ../../packages/core/dist/pendingReminders.js
14630
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, readdirSync as readdirSync4, readFileSync as readFileSync5, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
14801
+ import { existsSync as existsSync8, mkdirSync as mkdirSync2, readdirSync as readdirSync4, readFileSync as readFileSync6, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
14631
14802
  import { join as join5 } from "node:path";
14632
14803
  import { randomBytes } from "node:crypto";
14633
14804
  function sanitizeSessionId(raw) {
@@ -14647,7 +14818,7 @@ function appendPendingReminder(caveatHome, sessionId, text) {
14647
14818
  }
14648
14819
  function drainPendingReminders(caveatHome, sessionId) {
14649
14820
  const dir = pendingDirFor(caveatHome, sessionId);
14650
- if (!existsSync7(dir)) return [];
14821
+ if (!existsSync8(dir)) return [];
14651
14822
  let entries;
14652
14823
  try {
14653
14824
  entries = readdirSync4(dir).filter((f) => f.endsWith(".txt")).sort();
@@ -14658,7 +14829,7 @@ function drainPendingReminders(caveatHome, sessionId) {
14658
14829
  for (const entry of entries) {
14659
14830
  const path = join5(dir, entry);
14660
14831
  try {
14661
- out.push(readFileSync5(path, "utf-8"));
14832
+ out.push(readFileSync6(path, "utf-8"));
14662
14833
  } catch {
14663
14834
  continue;
14664
14835
  }
@@ -14905,7 +15076,7 @@ function generateSourceSession(now = () => /* @__PURE__ */ new Date()) {
14905
15076
  }
14906
15077
 
14907
15078
  // ../../packages/core/dist/writer.js
14908
- import { existsSync as existsSync8, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "node:fs";
15079
+ import { existsSync as existsSync9, mkdirSync as mkdirSync3, writeFileSync as writeFileSync3 } from "node:fs";
14909
15080
  import { dirname as dirname3 } from "node:path";
14910
15081
  function buildEntry(frontmatter, sections) {
14911
15082
  const bodyParts = [];
@@ -14925,7 +15096,7 @@ ${body}${body ? "\n" : ""}`;
14925
15096
  }
14926
15097
  function writeEntryFile(filePath, content) {
14927
15098
  const dir = dirname3(filePath);
14928
- if (!existsSync8(dir)) mkdirSync3(dir, { recursive: true });
15099
+ if (!existsSync9(dir)) mkdirSync3(dir, { recursive: true });
14929
15100
  writeFileSync3(filePath, content, "utf-8");
14930
15101
  }
14931
15102
 
@@ -14997,7 +15168,7 @@ function formatYmd(d) {
14997
15168
  }
14998
15169
 
14999
15170
  // ../../packages/core/dist/update.js
15000
- import { readFileSync as readFileSync6, statSync as statSync4, writeFileSync as writeFileSync4 } from "node:fs";
15171
+ import { readFileSync as readFileSync7, statSync as statSync4, writeFileSync as writeFileSync4 } from "node:fs";
15001
15172
  import { join as join7 } from "node:path";
15002
15173
  var IMMUTABLE_KEYS = /* @__PURE__ */ new Set([
15003
15174
  "id",
@@ -15015,7 +15186,7 @@ function updateEntry(id, patch, opts) {
15015
15186
  }
15016
15187
  const relPath = row.path;
15017
15188
  const filePath = join7(opts.entriesRoot, relPath);
15018
- const raw = readFileSync6(filePath, "utf-8");
15189
+ const raw = readFileSync7(filePath, "utf-8");
15019
15190
  const parsed = parseMarkdown(raw);
15020
15191
  if (patch.frontmatter) {
15021
15192
  for (const key of Object.keys(patch.frontmatter)) {
@@ -15109,6 +15280,7 @@ export {
15109
15280
  readSessionSignals,
15110
15281
  hasAnyStruggleSignal,
15111
15282
  struggleSearchText,
15283
+ readCodexSessionSignals,
15112
15284
  appendPendingReminder,
15113
15285
  drainPendingReminders,
15114
15286
  markHit,
@@ -15140,4 +15312,4 @@ strip-bom-string/index.js:
15140
15312
  js-yaml/dist/js-yaml.mjs:
15141
15313
  (*! js-yaml 4.1.1 https://github.com/nodeca/js-yaml @license MIT *)
15142
15314
  */
15143
- //# sourceMappingURL=chunk-WTHGWCPM.js.map
15315
+ //# sourceMappingURL=chunk-CSXD73IX.js.map