codealmanac 0.2.1 → 0.2.2

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.
@@ -448,7 +448,7 @@ async function run(argv, deps = {}) {
448
448
  if (await tryRunSqliteFreeCommand(argv.slice(2), runSetupFn)) {
449
449
  return;
450
450
  }
451
- const { registerCommands } = await import("./register-commands-DPH4ZWEE.js");
451
+ const { registerCommands } = await import("./register-commands-7QCIENRZ.js");
452
452
  registerCommands(program);
453
453
  configureGroupedHelp(program);
454
454
  await program.parseAsync(argv);
@@ -604,4 +604,4 @@ export {
604
604
  run,
605
605
  tryParseSetupShortcut
606
606
  };
607
- //# sourceMappingURL=cli-MZEXRV6E.js.map
607
+ //# sourceMappingURL=cli-3XAVBTYG.js.map
@@ -59,7 +59,7 @@ if (shouldCheckSqliteAbi(process.argv)) {
59
59
  process.exit(1);
60
60
  }
61
61
  }
62
- var { run } = await import("./cli-MZEXRV6E.js");
62
+ var { run } = await import("./cli-3XAVBTYG.js");
63
63
  run(process.argv).catch((err) => {
64
64
  const message = err instanceof Error ? err.message : String(err);
65
65
  process.stderr.write(`almanac: ${message}
@@ -2044,6 +2044,7 @@ function runJsonlCli(opts) {
2044
2044
  let turns = 0;
2045
2045
  let result = "";
2046
2046
  let sessionId;
2047
+ let usage;
2047
2048
  let success = false;
2048
2049
  let finalSeen = false;
2049
2050
  let error;
@@ -2052,6 +2053,9 @@ function runJsonlCli(opts) {
2052
2053
  if (sessionId === void 0 && typeof msg.session_id === "string" && msg.session_id.length > 0) {
2053
2054
  sessionId = msg.session_id;
2054
2055
  }
2056
+ if (sessionId === void 0 && typeof msg.thread_id === "string" && msg.thread_id.length > 0) {
2057
+ sessionId = msg.thread_id;
2058
+ }
2055
2059
  const final = opts.parseFinal(msg);
2056
2060
  if (final === null) return;
2057
2061
  finalSeen = true;
@@ -2059,6 +2063,7 @@ function runJsonlCli(opts) {
2059
2063
  if (final.turns !== void 0) turns = final.turns;
2060
2064
  if (final.result !== void 0) result = final.result;
2061
2065
  if (final.sessionId !== void 0) sessionId = final.sessionId;
2066
+ if (final.usage !== void 0) usage = final.usage;
2062
2067
  if (final.success !== void 0) success = final.success;
2063
2068
  if (final.error !== void 0) error = final.error;
2064
2069
  };
@@ -2092,6 +2097,7 @@ function runJsonlCli(opts) {
2092
2097
  turns,
2093
2098
  result,
2094
2099
  sessionId,
2100
+ usage,
2095
2101
  error: err.code === "ENOENT" ? `${opts.command} not found on PATH` : err.message
2096
2102
  });
2097
2103
  });
@@ -2104,7 +2110,7 @@ function runJsonlCli(opts) {
2104
2110
  }
2105
2111
  }
2106
2112
  if (code === 0 && finalSeen && success) {
2107
- resolve({ success, cost, turns, result, sessionId });
2113
+ resolve({ success, cost, turns, result, sessionId, usage });
2108
2114
  return;
2109
2115
  }
2110
2116
  const firstStderr = stderr.trim().split("\n")[0];
@@ -2114,6 +2120,7 @@ function runJsonlCli(opts) {
2114
2120
  turns,
2115
2121
  result,
2116
2122
  sessionId,
2123
+ usage,
2117
2124
  error: error ?? (firstStderr !== void 0 && firstStderr.length > 0 ? firstStderr : `${opts.command} exited ${code ?? 1}`)
2118
2125
  });
2119
2126
  });
@@ -2131,7 +2138,7 @@ function parseCodexFinal(msg) {
2131
2138
  return null;
2132
2139
  }
2133
2140
  if (msg.type === "turn.completed") {
2134
- return { success: true };
2141
+ return { success: true, turns: 1, usage: parseUsage(msg.usage) };
2135
2142
  }
2136
2143
  if (msg.type === "turn.failed" || msg.type === "error") {
2137
2144
  return {
@@ -2141,13 +2148,29 @@ function parseCodexFinal(msg) {
2141
2148
  }
2142
2149
  return null;
2143
2150
  }
2151
+ function parseUsage(value) {
2152
+ if (value === null || typeof value !== "object") return void 0;
2153
+ const obj = value;
2154
+ return {
2155
+ inputTokens: numberField(obj, "input_tokens") ?? numberField(obj, "inputTokens"),
2156
+ cachedInputTokens: numberField(obj, "cached_input_tokens") ?? numberField(obj, "cachedInputTokens") ?? numberField(obj, "cacheReadTokens"),
2157
+ outputTokens: numberField(obj, "output_tokens") ?? numberField(obj, "outputTokens"),
2158
+ reasoningOutputTokens: numberField(obj, "reasoning_output_tokens") ?? numberField(obj, "reasoningOutputTokens")
2159
+ };
2160
+ }
2161
+ function numberField(input, key) {
2162
+ const value = input[key];
2163
+ return typeof value === "number" ? value : void 0;
2164
+ }
2144
2165
  function parseCursorFinal(msg) {
2145
2166
  if (msg.type !== "result") return null;
2146
2167
  const isError = msg.is_error === true || msg.subtype !== "success";
2147
2168
  return {
2148
2169
  success: !isError,
2170
+ turns: 1,
2149
2171
  result: typeof msg.result === "string" ? msg.result : "",
2150
2172
  sessionId: typeof msg.session_id === "string" ? msg.session_id : void 0,
2173
+ usage: parseUsage(msg.usage),
2151
2174
  error: isError ? typeof msg.result === "string" ? msg.result : `cursor result: ${String(msg.subtype ?? "error")}` : void 0
2152
2175
  };
2153
2176
  }
@@ -2416,8 +2439,39 @@ async function resolveAgentSelection(args) {
2416
2439
  function formatFinalLine(result, logPath, repoRoot) {
2417
2440
  const status = result.success ? "done" : "failed";
2418
2441
  const rel = relative(repoRoot, logPath);
2419
- const cost = `$${result.cost.toFixed(3)}`;
2420
- return `[${status}] cost: ${cost}, turns: ${result.turns} (transcript: ${rel})`;
2442
+ const usage = formatRunUsage(result);
2443
+ return `[${status}] ${usage} (transcript: ${rel})`;
2444
+ }
2445
+ function formatRunUsage(result) {
2446
+ const parts = [];
2447
+ if (result.cost > 0 || result.usage === void 0) {
2448
+ parts.push(`cost: $${result.cost.toFixed(3)}`);
2449
+ }
2450
+ parts.push(`turns: ${result.turns}`);
2451
+ const usage = result.usage;
2452
+ if (usage !== void 0) {
2453
+ const tokenParts = [];
2454
+ if (usage.inputTokens !== void 0) {
2455
+ tokenParts.push(`${usage.inputTokens.toLocaleString("en-US")} in`);
2456
+ }
2457
+ if (usage.outputTokens !== void 0) {
2458
+ tokenParts.push(`${usage.outputTokens.toLocaleString("en-US")} out`);
2459
+ }
2460
+ if (usage.cachedInputTokens !== void 0) {
2461
+ tokenParts.push(
2462
+ `${usage.cachedInputTokens.toLocaleString("en-US")} cached`
2463
+ );
2464
+ }
2465
+ if (usage.reasoningOutputTokens !== void 0) {
2466
+ tokenParts.push(
2467
+ `${usage.reasoningOutputTokens.toLocaleString("en-US")} reasoning`
2468
+ );
2469
+ }
2470
+ if (tokenParts.length > 0) {
2471
+ parts.push(`tokens: ${tokenParts.join(", ")}`);
2472
+ }
2473
+ }
2474
+ return parts.join(", ");
2421
2475
  }
2422
2476
  async function countMarkdownPages(pagesDir) {
2423
2477
  try {
@@ -2474,14 +2528,16 @@ var StreamingFormatter = class {
2474
2528
  }
2475
2529
  return;
2476
2530
  }
2477
- if (msg.type === "result") {
2478
- const status = msg.subtype === "success" ? "done" : `failed (${msg.subtype})`;
2479
- const cost = typeof msg.total_cost_usd === "number" ? msg.total_cost_usd : 0;
2480
- const turns = typeof msg.num_turns === "number" ? msg.num_turns : 0;
2481
- this.sink.write(
2482
- `[${status}] cost: $${cost.toFixed(3)}, turns: ${turns}
2483
- `
2484
- );
2531
+ if (msg.type === "item.started" && isRecord(msg.item)) {
2532
+ this.handleCodexItemStarted(msg.item);
2533
+ return;
2534
+ }
2535
+ if (msg.type === "item.completed" && isRecord(msg.item)) {
2536
+ this.handleCodexItemCompleted(msg.item);
2537
+ return;
2538
+ }
2539
+ if (msg.type === "tool_call") {
2540
+ this.handleCursorToolCall(msg);
2485
2541
  return;
2486
2542
  }
2487
2543
  }
@@ -2496,6 +2552,33 @@ var StreamingFormatter = class {
2496
2552
  }
2497
2553
  const summary = formatToolSummary(name, input);
2498
2554
  this.sink.write(`[${this.currentAgent}] ${summary}
2555
+ `);
2556
+ }
2557
+ handleCodexItemStarted(item) {
2558
+ if (item.type !== "command_execution") return;
2559
+ const command = stringField(item, "command") ?? "?";
2560
+ this.sink.write(`[${this.currentAgent}] bash ${truncate(command, 80)}
2561
+ `);
2562
+ }
2563
+ handleCodexItemCompleted(item) {
2564
+ if (item.type !== "file_change") return;
2565
+ const changes = Array.isArray(item.changes) ? item.changes : [];
2566
+ for (const change of changes) {
2567
+ if (!isRecord(change)) continue;
2568
+ const rawPath = stringField(change, "path") ?? "?";
2569
+ const kind = stringField(change, "kind") ?? "edit";
2570
+ const verb = kind === "add" ? "writing" : kind === "delete" ? "deleting" : "editing";
2571
+ this.sink.write(
2572
+ `[${this.currentAgent}] ${verb} ${formatCodexPath(rawPath)}
2573
+ `
2574
+ );
2575
+ }
2576
+ }
2577
+ handleCursorToolCall(msg) {
2578
+ if (msg.subtype !== "started" || !isRecord(msg.tool_call)) return;
2579
+ const summary = formatCursorToolSummary(msg.tool_call);
2580
+ if (summary === void 0) return;
2581
+ this.sink.write(`[${this.currentAgent}] ${summary}
2499
2582
  `);
2500
2583
  }
2501
2584
  };
@@ -2539,18 +2622,57 @@ function formatToolSummary(name, input) {
2539
2622
  }
2540
2623
  case "Bash": {
2541
2624
  const command = stringField(input, "command") ?? "?";
2542
- const trimmed = command.length > 80 ? `${command.slice(0, 77)}...` : command;
2543
- return `bash ${trimmed}`;
2625
+ return `bash ${truncate(command, 80)}`;
2544
2626
  }
2545
2627
  default: {
2546
2628
  return name;
2547
2629
  }
2548
2630
  }
2549
2631
  }
2632
+ function formatCursorToolSummary(toolCall) {
2633
+ if (isRecord(toolCall.readToolCall)) {
2634
+ const args = recordField(toolCall.readToolCall, "args");
2635
+ return `reading ${stringField(args, "path") ?? "?"}`;
2636
+ }
2637
+ if (isRecord(toolCall.editToolCall)) {
2638
+ const args = recordField(toolCall.editToolCall, "args");
2639
+ return `editing ${formatCodexPath(stringField(args, "path") ?? "?")}`;
2640
+ }
2641
+ if (isRecord(toolCall.globToolCall)) {
2642
+ const args = recordField(toolCall.globToolCall, "args");
2643
+ return `glob ${stringField(args, "globPattern") ?? "?"}`;
2644
+ }
2645
+ if (isRecord(toolCall.grepToolCall)) {
2646
+ const args = recordField(toolCall.grepToolCall, "args");
2647
+ return `grep ${stringField(args, "pattern") ?? "?"}`;
2648
+ }
2649
+ if (isRecord(toolCall.shellToolCall)) {
2650
+ const args = recordField(toolCall.shellToolCall, "args");
2651
+ const description = stringField(toolCall.shellToolCall, "description");
2652
+ const command = stringField(args, "command") ?? description ?? "?";
2653
+ return `bash ${truncate(command, 80)}`;
2654
+ }
2655
+ return void 0;
2656
+ }
2657
+ function truncate(value, max) {
2658
+ return value.length > max ? `${value.slice(0, max - 3)}...` : value;
2659
+ }
2660
+ function formatCodexPath(value) {
2661
+ const marker = "/.almanac/";
2662
+ const idx = value.indexOf(marker);
2663
+ if (idx !== -1) {
2664
+ return `.almanac/${value.slice(idx + marker.length)}`;
2665
+ }
2666
+ return value;
2667
+ }
2550
2668
  function stringField(input, key) {
2551
2669
  const value = input[key];
2552
2670
  return typeof value === "string" ? value : void 0;
2553
2671
  }
2672
+ function recordField(input, key) {
2673
+ const value = input[key];
2674
+ return isRecord(value) ? value : {};
2675
+ }
2554
2676
  function isRecord(value) {
2555
2677
  return value !== null && typeof value === "object";
2556
2678
  }
@@ -3095,12 +3217,12 @@ function diffSnapshots(before, after) {
3095
3217
  }
3096
3218
  function formatSummary2(result, delta, logPath, repoRoot) {
3097
3219
  const rel = relative3(repoRoot, logPath);
3098
- const cost = `$${result.cost.toFixed(3)}`;
3220
+ const usage = formatRunUsage(result);
3099
3221
  const { created, updated, archived } = delta;
3100
3222
  if (created === 0 && updated === 0 && archived === 0) {
3101
- return `[capture] no new knowledge met the notability bar (0 pages written), cost: ${cost}, turns: ${result.turns} (transcript: ${rel})`;
3223
+ return `[capture] no new knowledge met the notability bar (0 pages written), ${usage} (transcript: ${rel})`;
3102
3224
  }
3103
- return `[done] ${updated} page${updated === 1 ? "" : "s"} updated, ${created} created, ${archived} archived, cost: ${cost}, turns: ${result.turns} (transcript: ${rel})`;
3225
+ return `[done] ${updated} page${updated === 1 ? "" : "s"} updated, ${created} created, ${archived} archived, ${usage} (transcript: ${rel})`;
3104
3226
  }
3105
3227
  function formatTimestamp2(d) {
3106
3228
  const pad = (n) => n.toString().padStart(2, "0");
@@ -3213,4 +3335,4 @@ function registerCommands(program) {
3213
3335
  export {
3214
3336
  registerCommands
3215
3337
  };
3216
- //# sourceMappingURL=register-commands-DPH4ZWEE.js.map
3338
+ //# sourceMappingURL=register-commands-7QCIENRZ.js.map