pisesh 0.1.9 → 0.1.10

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/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.1.10] — 2026-06-09
6
+
7
+ ### Fixed
8
+ - **Resume no longer crashes on sessions interrupted mid-tool-call.** If a session ended while a tool call was still in flight (e.g. an image generation cut off by a usage limit or a closed window), its transcript held a tool call with no recorded result. On resume, pi would re-fire that dead tool and the spawned process could exit non-zero — surfacing as `pisesh exited with code 1`, repeatedly. `resumeSession` now heals the target session first: every orphaned tool call gets a synthetic `[interrupted]` result injected before pi is spawned, so the resumed history is always well-formed and no dead tool is re-run. Idempotent, never throws, and writes a one-time `.bak-orphanheal` backup of the session before modifying it.
9
+
5
10
  ## [0.1.9] — 2026-06-03
6
11
 
7
12
  ### Fixed
package/bin/pisesh CHANGED
@@ -838,8 +838,62 @@ function tryCopy(text) {
838
838
  }
839
839
 
840
840
  // ── Actions ───────────────────────────────────────────
841
+ // Heal a session before resuming. On resume, pi re-executes (or chokes on) any
842
+ // toolCall that has no recorded toolResult — e.g. an image generation that was
843
+ // interrupted when the prior session hit a usage limit or was closed mid-tool.
844
+ // Left unhealed, the spawned pi crashes (exit 1), which surfaces to the parent
845
+ // as "pisesh exited with code N". We inject a synthetic "[interrupted]"
846
+ // toolResult for every orphaned toolCall so the resumed history is always
847
+ // well-formed and pi never re-fires a dead tool. Idempotent; never throws.
848
+ function healOrphanedToolCalls(file) {
849
+ try {
850
+ const lines = fs.readFileSync(file, 'utf8').split('\n').filter(Boolean);
851
+ const resultIds = new Set();
852
+ for (const l of lines) {
853
+ let o; try { o = JSON.parse(l); } catch { continue; }
854
+ if (o && o.message && o.message.role === 'toolResult') resultIds.add(o.message.toolCallId);
855
+ }
856
+ const rnd = () => Math.random().toString(16).slice(2, 10);
857
+ const out = [];
858
+ let inserted = 0, prevSynthId = null;
859
+ for (const l of lines) {
860
+ let o; try { o = JSON.parse(l); } catch { out.push(l); continue; }
861
+ if (prevSynthId && o && typeof o.parentId !== 'undefined') { o.parentId = prevSynthId; prevSynthId = null; }
862
+ out.push(JSON.stringify(o));
863
+ const c = o && o.message && o.message.content;
864
+ if (o && o.message && o.message.role === 'assistant' && Array.isArray(c)) {
865
+ for (const b of c) {
866
+ if (b && b.type === 'toolCall' && b.id && !resultIds.has(b.id)) {
867
+ const synth = {
868
+ type: 'message', id: rnd(), parentId: o.id,
869
+ timestamp: new Date().toISOString(),
870
+ message: {
871
+ role: 'toolResult', toolCallId: b.id, toolName: b.name,
872
+ content: [{ type: 'text', text: '[tool call interrupted \u2014 the previous session ended before this tool finished (e.g. usage limit reached or session closed); no result was recorded]' }],
873
+ isError: true, timestamp: Date.now(),
874
+ },
875
+ };
876
+ out.push(JSON.stringify(synth));
877
+ resultIds.add(b.id);
878
+ prevSynthId = synth.id;
879
+ inserted++;
880
+ }
881
+ }
882
+ }
883
+ }
884
+ if (inserted > 0) {
885
+ try { const bak = file + '.bak-orphanheal'; if (!fs.existsSync(bak)) fs.copyFileSync(file, bak); } catch {}
886
+ fs.writeFileSync(file, out.join('\n') + '\n');
887
+ }
888
+ return inserted;
889
+ } catch { return 0; }
890
+ }
891
+
841
892
  function resumeSession(s) {
842
893
  if (!s) return;
894
+ // Heal orphaned tool calls before handing off, so resume can't crash the
895
+ // spawned pi (see healOrphanedToolCalls).
896
+ try { healOrphanedToolCalls(s.file); } catch {}
843
897
  // Leave alt screen + show cursor so the spawned pi takes over a clean
844
898
  // main-buffer terminal (it will manage its own alt screen).
845
899
  process.stdout.write(A.exitAlt + A.showC);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pisesh",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Bookmark, search, and resume pi coding-agent sessions with a fast keyboard-driven TUI.",
5
5
  "keywords": [
6
6
  "pi-package",