@blockrun/franklin 3.15.37 → 3.15.39

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.
@@ -403,6 +403,12 @@ export async function interactiveSession(config, getUserInput, onEvent, onAbortR
403
403
  let turnCount = 0;
404
404
  // Resume: hydrate history from the saved JSONL transcript.
405
405
  // Sanitize to drop any orphaned tool_use / tool_result pairs from a crash.
406
+ // Carry over running totals from prior runs so resume preserves them — see
407
+ // the `let sessionInputTokens` comment below.
408
+ let resumedInputTokens = 0;
409
+ let resumedOutputTokens = 0;
410
+ let resumedCostUsd = 0;
411
+ let resumedSavedVsOpusUsd = 0;
406
412
  if (config.resumeSessionId) {
407
413
  const prior = loadSessionHistory(config.resumeSessionId);
408
414
  if (prior.length > 0) {
@@ -411,6 +417,17 @@ export async function interactiveSession(config, getUserInput, onEvent, onAbortR
411
417
  const meta = loadSessionMeta(config.resumeSessionId);
412
418
  if (meta) {
413
419
  turnCount = meta.turnCount ?? 0;
420
+ // Pre-3.15.38 these fell on the floor — every resume reset the
421
+ // running cost/token totals to zero, then `updateSessionMeta`
422
+ // wrote the new (smaller) numbers back over the historical
423
+ // values. Verified 2026-05-04 from a real session: efd5e412
424
+ // had $2.65 + 200K input tokens accumulated, then a resume
425
+ // rewrote the meta to {costUsd: 0, inputTokens: 0, ...}
426
+ // before the user ran their next turn.
427
+ resumedInputTokens = meta.inputTokens ?? 0;
428
+ resumedOutputTokens = meta.outputTokens ?? 0;
429
+ resumedCostUsd = meta.costUsd ?? 0;
430
+ resumedSavedVsOpusUsd = meta.savedVsOpusUsd ?? 0;
414
431
  }
415
432
  }
416
433
  }
@@ -418,10 +435,14 @@ export async function interactiveSession(config, getUserInput, onEvent, onAbortR
418
435
  let lastSessionActivity = Date.now();
419
436
  let lastRoutedModel = ''; // last model chosen by router (for local elo)
420
437
  let lastRoutedCategory = ''; // last category detected (for local elo)
421
- let sessionInputTokens = 0;
422
- let sessionOutputTokens = 0;
423
- let sessionCostUsd = 0;
424
- let sessionSavedVsOpus = 0;
438
+ // Session-cumulative counters. Seeded from prior session meta on resume so
439
+ // `franklin insights` and the status bar show the *true* session total
440
+ // across every restart, not just what happened since the latest process
441
+ // boot.
442
+ let sessionInputTokens = resumedInputTokens;
443
+ let sessionOutputTokens = resumedOutputTokens;
444
+ let sessionCostUsd = resumedCostUsd;
445
+ let sessionSavedVsOpus = resumedSavedVsOpusUsd;
425
446
  // Per-tool call counts aggregated across every turn. Session-scope, not
426
447
  // per-turn. Counts the *name* of each tool invocation only — no inputs,
427
448
  // outputs, or paths. Fed into opt-in telemetry at session end.
@@ -2,6 +2,7 @@
2
2
  * Bash capability — execute shell commands with timeout and output capture.
3
3
  */
4
4
  import { spawn } from 'node:child_process';
5
+ import fs from 'node:fs';
5
6
  // ─── Smart Output Compression ─────────────────────────────────────────────
6
7
  // Learned from RTK (Rust Token Killer): strip noise before sending to LLM.
7
8
  // Applied after capture, before the 32KB cap — reduces tokens on verbose commands.
@@ -273,7 +274,19 @@ async function execute(input, ctx) {
273
274
  }
274
275
  function executeCommand(command, timeoutMs, ctx) {
275
276
  return new Promise((resolve) => {
276
- const shell = process.env.SHELL || '/bin/bash';
277
+ // Force /bin/bash (not $SHELL) so the tool's behavior matches its name
278
+ // and its tool description. Pre-3.15.39 used `process.env.SHELL ||
279
+ // '/bin/bash'`, which on macOS defaults to zsh — and zsh has
280
+ // semantically different rules (NOMATCH on unmatched globs is fatal,
281
+ // unlike bash's literal-passthrough). Verified 2026-05-04 from a real
282
+ // session: agent ran `rm -f data/etl_out/shard-*.ndjson` expecting
283
+ // bash's "if no match, -f ignores it"; zsh fatal-erred with `no
284
+ // matches found`. Other zsh-vs-bash divergences (process substitution
285
+ // syntax, `[[` bashisms in scripts, parameter expansion edge cases)
286
+ // would silently bite agents that learned bash. /bin/bash exists on
287
+ // every Linux + macOS install we ship to. Fall back to $SHELL only if
288
+ // /bin/bash is somehow missing (NixOS-style stores, exotic Docker).
289
+ const shell = fs.existsSync('/bin/bash') ? '/bin/bash' : (process.env.SHELL || '/bin/sh');
277
290
  let child;
278
291
  try {
279
292
  child = spawn(shell, ['-c', command], {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blockrun/franklin",
3
- "version": "3.15.37",
3
+ "version": "3.15.39",
4
4
  "description": "Franklin — The AI agent with a wallet. Spends USDC autonomously to get real work done. Pay per action, no subscriptions.",
5
5
  "type": "module",
6
6
  "exports": {