pi-studio 0.11.7 → 0.11.9

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
@@ -4,6 +4,27 @@ All notable changes to `pi-studio` are documented here.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.11.9] — 2026-11-03
8
+
9
+ ### Added
10
+ - The REPL pane shows the images and PDFs a record entry's code saved, such as a plot, as agent-markdown-preview's REPL page does. An image shows under the entry's output; click it to open Studio's image viewer. A PDF is a link that opens it in a new tab. A file shows when the entry's code or output names it (a path ending in `.png`, `.jpg`, `.gif`, `.webp`, `.svg` or `.pdf`, relative paths taken from the REPL's current directory) and it was written while the entry ran. A file saved again by a later entry shows under that entry instead. Up to six files show for each of a session's latest 12 entries. Studio serves only those files.
11
+
12
+ ### Changed
13
+ - The REPL pane's record has no description line under its heading.
14
+ - A PDF's header, on its card and in its enlarged view, shows **Auto-refresh** and **More**. More holds **Refresh now**, **Browser tab**, **System viewer**, **Show in folder** and **Copy path**, so the header fits on one line. The card's Enlarge is its icon alone, with Enlarge as its tooltip.
15
+
16
+ ## [0.11.8] — 2026-11-03
17
+
18
+ ### Changed
19
+ - The REPL pane's record says when a session's record directory isn't verified, because the session has no record-directory key yet, so the record shown may not be the one other clients use. When the agent is told of entries from such a session, it's told this too.
20
+
21
+ ### Fixed
22
+ - In a Shell session under zsh, Ctrl+C while your code runs no longer leaves Studio waiting for that send. Before, the session took no further sends until it was closed. bash was already unaffected.
23
+ - When the REPL pane's controls wrap and **More** starts a row, its menu opens inside the pane, not off its left edge.
24
+ - For a session whose shared record Studio won't use from here, **Copy Markdown**, **Export .md** and **Load record into editor** say why, instead of using the page's earlier copy of its entries. With no session selected, the page leaves that session's entries out.
25
+ - **Clear** empties the page's copy of a session's record once Studio has cleared it. If Studio refuses, the page keeps its copy and says why. Before, the page emptied its copy and reported success first.
26
+ - A note's name is checked before Studio shortens a long label, so a name that isn't usable can't be cut into one that is.
27
+
7
28
  ## [0.11.7] — 2026-11-02
8
29
 
9
30
  This release brings the REPL pane up to pi-repl 0.11.7.
package/README.md CHANGED
@@ -136,7 +136,7 @@ Icons in exported PDFs need Mermaid CLI 11.12+ (`npm install -g @mermaid-js/merm
136
136
 
137
137
  ### REPL
138
138
 
139
- The REPL pane runs code in tmux sessions. It can start its own, and it shares a record of submissions and output with [pi-repl](https://github.com/omaclaren/pi-repl) when both use the same session. Pane echo sets how much submitted code goes into the raw tmux history, as in pi-repl: up to 20 lines with Summary, the default, up to 40 with Full, and none with Off. Your sends and notes are recorded under your name (**Sending as**, under Quick send). The agent is told of record entries it hasn't seen, such as your sends, other clients' sends and late output, when a run starts and with its REPL tools' results. The record format is in [`shared/REPL_SESSION_RECORD_PROTOCOL.md`](./shared/REPL_SESSION_RECORD_PROTOCOL.md).
139
+ The REPL pane runs code in tmux sessions. It can start its own, and it shares a record of submissions and output with [pi-repl](https://github.com/omaclaren/pi-repl) when both use the same session. Pane echo sets how much submitted code goes into the raw tmux history, as in pi-repl: up to 20 lines with Summary, the default, up to 40 with Full, and none with Off. Your sends and notes are recorded under your name (**Sending as**, under Quick send). An image or PDF an entry's code saved while it ran, such as a plot, shows under it when the code or output names it. The agent is told of record entries it hasn't seen, such as your sends, other clients' sends and late output, when a run starts and with its REPL tools' results. The record format is in [`shared/REPL_SESSION_RECORD_PROTOCOL.md`](./shared/REPL_SESSION_RECORD_PROTOCOL.md).
140
140
 
141
141
  ### Side questions
142
142
 
package/ROADMAP.md CHANGED
@@ -2,9 +2,18 @@
2
2
 
3
3
  This is the current planning source of truth for Studio work. `NEXT-STAGE.md` is historical; `TODO.md` tracks smaller backlog items that are not yet assigned to a release.
4
4
 
5
- ## Current status (14 Oct 2026)
5
+ ## Current status (3 Nov 2026)
6
6
 
7
- `0.10.0` ships the buffer-first workspace as **dual editor mode** (Prompt and Document), on by default, with **single editor mode** one switch away (footer button, `/studio --single`). It went through real course use as private alpha candidates 49–69. The `PI_STUDIO_*` flags described further down are now development overrides only: when any is set it decides, and the mode switch is hidden. Fixes follow in `0.10.x`. The sections below are the history up to this point.
7
+ `0.11.9` is the current release, and Studio is in a feature freeze from it, for use in normal work. Before the freeze, `0.11.9` added the images and PDFs a REPL entry's code saved, shown under the entry, and a PDF header that fits on one line. During the freeze, changes are limited to fixes for failures in normal use, lost data, effects on other people's processes or files, and security. [TODO.md](TODO.md) lists the known limits and what comes after the freeze.
8
+
9
+ `0.10.0` (14 Oct) made the buffer-first workspace the default, as **dual editor mode** (Prompt and Document), with **single editor mode** one switch away (footer button, `/studio --single`). It went through real course use as private alpha candidates 49–69. The `PI_STUDIO_*` flags described further down are development overrides only: when any is set it decides, and the mode switch is hidden.
10
+
11
+ The `0.11` releases brought the REPL pane up to pi-repl `0.11.7`: Ruby, Java, Octave, MATLAB, gnuplot and C++; sends and notes recorded under the sender's name; the record-directory key; and telling the agent what's new in the record. They also brought Working closer to agent-markdown-preview's. The [changelog](CHANGELOG.md) has each release. The sections below are the history up to `0.10.0`.
12
+
13
+ ### Parity at the freeze
14
+
15
+ - **pi-repl `0.11.7` and agent-repl `0.5.0`.** Studio's copies of the shared record, names, protocol, control-file, display, C++, gnuplot and M-language helpers are byte-identical to pi-repl's, and agent-repl carries the same record, names and protocol files. Two helpers differ: pi-repl generalised `repl-session-stop.js` and `repl-gnuplot-processes.js` for LFortran. Studio doesn't run LFortran, and won't paste into pi-repl's LFortran session ("This session takes code only through pi-repl").
16
+ - **pi-markdown-preview `0.26.2` and agent-markdown-preview `0.13.2`.** Their REPL page reads the same records with the same record-directory check. Both show the images and PDFs an entry's code saved, by the same rules: a file shows when the entry names it and it was written in that entry's turn. Studio has them from `0.11.9`; the preview packages' REPL page has its latest rules on an unreleased branch.
8
17
 
9
18
  ## Release approach
10
19
 
@@ -688,8 +688,6 @@
688
688
  error: "",
689
689
  };
690
690
  let replTmuxAvailable = null;
691
- // Whether the agent is told of new record entries ("on", "send" or "off"), from Studio's server.
692
- let replRecordActivity = "off";
693
691
  // The name this page's sends and notes are recorded under: chosen here and kept in this
694
692
  // browser, else the default from Studio's server (PI_REPL_USER_NAME, then pi-repl's saved
695
693
  // name, then "User"). Read once, so another tab choosing a name later leaves this page alone.
@@ -700,6 +698,8 @@
700
698
  let replSenderEditing = false;
701
699
  // What's typed in the name field, kept as it's typed so a redraw by any route keeps it (Sol).
702
700
  let replSenderDraft = "";
701
+ // This page's clears of sessions' records, by request ID, until Studio answers each.
702
+ const replJournalClearRequests = new Map();
703
703
  // After Enter or Esc in the name field, the cursor goes back to ✎.
704
704
  let replSenderReturnFocus = false;
705
705
  let replSessions = [];
@@ -805,10 +805,20 @@
805
805
  beforeTranscript: "",
806
806
  status: typeof entry.status === "string" ? entry.status : "sent",
807
807
  skippedChunks: Math.max(0, Math.floor(Number(entry.skippedChunks) || 0)),
808
+ // Image and PDF files the entry names, as Studio found them when it sent it; not kept.
809
+ files: normalizeReplEntryFiles(entry.files),
808
810
  };
809
811
  return (normalized.code.trim() || normalized.prose.trim() || normalized.output.trim()) ? normalized : null;
810
812
  }
811
813
 
814
+ function normalizeReplEntryFiles(files) {
815
+ if (!Array.isArray(files)) return [];
816
+ return files.filter((file) => file && typeof file === "object" && typeof file.id === "string" && /^[0-9a-f]{64}$/.test(file.id)
817
+ && typeof file.written === "string" && file.written && typeof file.v === "string" && /^[0-9a-f]{16}$/.test(file.v))
818
+ .slice(0, 6)
819
+ .map((file) => ({ id: file.id, written: file.written.slice(0, 1024), image: file.image === true, v: file.v }));
820
+ }
821
+
812
822
  function loadPersistedReplJournalEntries() {
813
823
  try {
814
824
  const raw = window.localStorage ? window.localStorage.getItem("piStudio.replStudioEntries.v1") : null;
@@ -894,6 +904,8 @@
894
904
  let replJournalEntries = loadPersistedReplJournalEntries();
895
905
  let activeReplJournalEntryId = "";
896
906
  const replJournalImportPendingSessions = new Set();
907
+ // Whether the REPL view is kept at its bottom, as of its last draw or scroll, for thumbnails that load later.
908
+ let replViewStuckToBottom = false;
897
909
  let replJournalCollapsed = (() => {
898
910
  try {
899
911
  const stored = window.localStorage ? window.localStorage.getItem("piStudio.replStudioCollapsed") : null;
@@ -1625,6 +1637,8 @@
1625
1637
  source: typeof session.source === "string" ? session.source : "tmux",
1626
1638
  // Why Studio won't use its shared record from here, such as another record directory (pi-repl's P0).
1627
1639
  recordRefusal: typeof session.recordRefusal === "string" ? session.recordRefusal.slice(0, 1000) : "",
1640
+ // It has no record-directory key yet, so its record here may not be the one other clients use.
1641
+ recordUnverified: session.recordUnverified === true,
1628
1642
  };
1629
1643
  }
1630
1644
 
@@ -1907,6 +1921,7 @@
1907
1921
  tmuxSessionId: session.tmuxSessionId,
1908
1922
  tmuxSessionCreatedAt: session.tmuxSessionCreatedAt,
1909
1923
  recordRefusal: session.recordRefusal,
1924
+ recordUnverified: session.recordUnverified,
1910
1925
  })));
1911
1926
  }
1912
1927
 
@@ -2957,6 +2972,11 @@
2957
2972
  }
2958
2973
 
2959
2974
  async function copyReplJournalToClipboard() {
2975
+ const refusal = getActiveReplRecordState().refusal;
2976
+ if (refusal) {
2977
+ setStatus(refusal, "warning");
2978
+ return;
2979
+ }
2960
2980
  const entries = getVisibleReplJournalEntries();
2961
2981
  if (!entries.length) {
2962
2982
  setStatus("No shared REPL record entries to copy for this session yet.", "warning");
@@ -2970,6 +2990,11 @@
2970
2990
  }
2971
2991
 
2972
2992
  function exportReplJournalMarkdown() {
2993
+ const refusal = getActiveReplRecordState().refusal;
2994
+ if (refusal) {
2995
+ setStatus(refusal, "warning");
2996
+ return;
2997
+ }
2973
2998
  const entries = getVisibleReplJournalEntries();
2974
2999
  if (!entries.length) {
2975
3000
  setStatus("No shared REPL record entries to export for this session yet.", "warning");
@@ -2989,23 +3014,33 @@
2989
3014
  setStatus("Exported shared REPL record Markdown.", "success");
2990
3015
  }
2991
3016
 
3017
+ // A session's record is cleared here once Studio has cleared it: Studio can refuse, and then
3018
+ // this page keeps its copy too (pi-repl's P0).
2992
3019
  function clearReplJournal() {
2993
3020
  const sessionName = getActiveReplJournalSessionName();
2994
- if (sessionName) {
2995
- replJournalEntries = replJournalEntries.filter((entry) => entry.sessionName !== sessionName);
2996
- } else {
3021
+ if (!sessionName) {
2997
3022
  replJournalEntries = [];
3023
+ activeReplJournalEntryId = "";
3024
+ persistReplJournalEntries();
3025
+ setStatus("Cleared local REPL record cache.", "success");
3026
+ renderReplViewIfActive({ force: true });
3027
+ return;
2998
3028
  }
2999
- activeReplJournalEntryId = "";
3000
- persistReplJournalEntries();
3001
- if (sessionName) {
3002
- sendMessage({ type: "repl_journal_clear_request", requestId: makeRequestId(), sessionName });
3029
+ const requestId = makeRequestId();
3030
+ if (!sendMessage({ type: "repl_journal_clear_request", requestId, sessionName })) {
3031
+ setStatus("Nothing was cleared: Studio isn't connected.", "warning");
3032
+ return;
3003
3033
  }
3004
- setStatus(sessionName ? "Cleared shared REPL record for this session." : "Cleared local REPL record cache.", "success");
3005
- renderReplViewIfActive({ force: true });
3034
+ replJournalClearRequests.set(requestId, sessionName);
3035
+ setStatus("Clearing the shared REPL record…", "info");
3006
3036
  }
3007
3037
 
3008
3038
  function loadReplJournalIntoEditor() {
3039
+ const refusal = getActiveReplRecordState().refusal;
3040
+ if (refusal) {
3041
+ setStatus(refusal, "warning");
3042
+ return;
3043
+ }
3009
3044
  const entries = getVisibleReplJournalEntries();
3010
3045
  if (!entries.length) {
3011
3046
  setStatus("No shared REPL record entries to load for this session yet.", "warning");
@@ -9661,7 +9696,6 @@
9661
9696
  event.preventDefault();
9662
9697
  event.stopPropagation();
9663
9698
  });
9664
- actions.appendChild(openLink);
9665
9699
 
9666
9700
  const systemViewerBtn = document.createElement("button");
9667
9701
  systemViewerBtn.type = "button";
@@ -9671,7 +9705,6 @@
9671
9705
  systemViewerBtn.addEventListener("click", () => {
9672
9706
  void runStudioPdfLocalAction("system-viewer", studioPdfFocusResourceQuery, systemViewerBtn, { isCurrent: studioPdfFocusIsCurrent });
9673
9707
  });
9674
- actions.appendChild(systemViewerBtn);
9675
9708
 
9676
9709
  const revealBtn = document.createElement("button");
9677
9710
  revealBtn.type = "button";
@@ -9681,7 +9714,6 @@
9681
9714
  revealBtn.addEventListener("click", () => {
9682
9715
  void runStudioPdfLocalAction("reveal", studioPdfFocusResourceQuery, revealBtn, { isCurrent: studioPdfFocusIsCurrent });
9683
9716
  });
9684
- actions.appendChild(revealBtn);
9685
9717
 
9686
9718
  const copyPathBtn = document.createElement("button");
9687
9719
  copyPathBtn.type = "button";
@@ -9691,16 +9723,14 @@
9691
9723
  copyPathBtn.addEventListener("click", () => {
9692
9724
  void copyStudioPdfResourcePath(studioPdfFocusResourceQuery, copyPathBtn, { isCurrent: studioPdfFocusIsCurrent });
9693
9725
  });
9694
- actions.appendChild(copyPathBtn);
9695
9726
 
9696
9727
  const refreshBtn = document.createElement("button");
9697
9728
  refreshBtn.type = "button";
9698
9729
  refreshBtn.className = "studio-pdf-focus-btn studio-pdf-focus-refresh";
9699
- refreshBtn.textContent = "Refresh";
9730
+ refreshBtn.textContent = "Refresh now";
9700
9731
  refreshBtn.title = "Reload this PDF preview from disk. Shortcut: Cmd/Ctrl+Option/Alt+Shift+R.";
9701
9732
  refreshBtn.setAttribute("aria-label", "Refresh PDF preview from disk");
9702
9733
  refreshBtn.addEventListener("click", () => refreshStudioPdfFocusViewer());
9703
- actions.appendChild(refreshBtn);
9704
9734
 
9705
9735
  const autoRefreshBtn = document.createElement("button");
9706
9736
  autoRefreshBtn.type = "button";
@@ -9711,6 +9741,7 @@
9711
9741
  autoRefreshBtn.setAttribute("aria-pressed", "false");
9712
9742
  autoRefreshBtn.addEventListener("click", () => toggleStudioPdfFocusAutoRefresh());
9713
9743
  actions.appendChild(autoRefreshBtn);
9744
+ actions.appendChild(createStudioPdfMoreMenu("focus", [refreshBtn, openLink, systemViewerBtn, revealBtn, copyPathBtn]));
9714
9745
 
9715
9746
  const fullscreenBtn = document.createElement("button");
9716
9747
  fullscreenBtn.type = "button";
@@ -9793,6 +9824,7 @@
9793
9824
  if (studioPdfFocusOpenLinkEl) studioPdfFocusOpenLinkEl.href = src;
9794
9825
  setStudioPdfFocusFrameSource(src, title, sourceFrame);
9795
9826
  if (document.body) document.body.classList.add("studio-pdf-focus-open");
9827
+ closeStudioPdfFocusMoreMenus();
9796
9828
  if (studioPdfFocusOverlayEl) studioPdfFocusOverlayEl.hidden = false;
9797
9829
  syncStudioBufferOpenOperation();
9798
9830
  syncStudioPdfFocusFullscreenButton();
@@ -9814,6 +9846,7 @@
9814
9846
  if (exitResult && typeof exitResult.catch === "function") exitResult.catch(() => {});
9815
9847
  } catch {}
9816
9848
  }
9849
+ closeStudioPdfFocusMoreMenus();
9817
9850
  if (studioPdfFocusOverlayEl) studioPdfFocusOverlayEl.hidden = true;
9818
9851
  restoreStudioPdfFocusMovedFrame();
9819
9852
  if (studioPdfFocusFrameEl) studioPdfFocusFrameEl.src = "about:blank";
@@ -9863,6 +9896,64 @@
9863
9896
  return query;
9864
9897
  }
9865
9898
 
9899
+ // A PDF's less frequent actions, under More as in the REPL pane: a manual refresh beside
9900
+ // Auto-refresh, and the one-off ways to take the PDF elsewhere (Oliver, candidate 117).
9901
+ function createStudioPdfMoreMenu(kind, items) {
9902
+ const details = document.createElement("details");
9903
+ details.className = "studio-pdf-more studio-pdf-" + kind + "-more";
9904
+ const summary = document.createElement("summary");
9905
+ summary.textContent = "More";
9906
+ summary.title = "More ways to refresh or open this PDF.";
9907
+ details.appendChild(summary);
9908
+ const menu = document.createElement("div");
9909
+ menu.className = "studio-pdf-more-menu";
9910
+ items.forEach((item) => {
9911
+ item.classList.add("studio-pdf-more-item");
9912
+ menu.appendChild(item);
9913
+ });
9914
+ // A chosen item closes the menu once its own click has run. The items stop their clicks
9915
+ // from bubbling, so this listens on the way down; the card's items are handled first, on
9916
+ // the document, by handleStudioPreviewMediaActivation, which closes their menu itself.
9917
+ menu.addEventListener("click", (event) => {
9918
+ if (event.target instanceof Element) dismissStudioPdfMoreMenuAfterChoice(event.target);
9919
+ }, true);
9920
+ // Keyboard focus leaving the menu, such as Tab past its last item, closes it, so an open
9921
+ // menu never sits behind a focused control whose Escape belongs to the view (Sol, c117).
9922
+ details.addEventListener("focusout", (event) => {
9923
+ if (details.open && event.relatedTarget instanceof Node && !details.contains(event.relatedTarget)) details.open = false;
9924
+ });
9925
+ // Escape closes the menu, not the view it's in.
9926
+ details.addEventListener("keydown", (event) => {
9927
+ if (event.key !== "Escape" || !details.open) return;
9928
+ event.preventDefault();
9929
+ event.stopPropagation();
9930
+ details.open = false;
9931
+ summary.focus();
9932
+ });
9933
+ details.appendChild(menu);
9934
+ return details;
9935
+ }
9936
+
9937
+ // A chosen item's menu closes once its click has been handled.
9938
+ function dismissStudioPdfMoreMenuAfterChoice(element) {
9939
+ const item = element && typeof element.closest === "function" ? element.closest(".studio-pdf-more-item") : null;
9940
+ const details = item ? item.closest("details.studio-pdf-more") : null;
9941
+ if (details) window.setTimeout(() => { details.open = false; }, 0);
9942
+ }
9943
+
9944
+ // The enlarged view starts and ends with its menu closed.
9945
+ function closeStudioPdfFocusMoreMenus() {
9946
+ if (!studioPdfFocusOverlayEl) return;
9947
+ studioPdfFocusOverlayEl.querySelectorAll("details.studio-pdf-more[open]").forEach((details) => { details.open = false; });
9948
+ }
9949
+
9950
+ // A press outside an open PDF menu closes it.
9951
+ document.addEventListener("pointerdown", (event) => {
9952
+ document.querySelectorAll("details.studio-pdf-more[open]").forEach((details) => {
9953
+ if (!(event.target instanceof Node) || !details.contains(event.target)) details.open = false;
9954
+ });
9955
+ }, true);
9956
+
9866
9957
  function syncStudioPdfAutoRefreshButton(button, enabled, available) {
9867
9958
  if (!button) return;
9868
9959
  const active = Boolean(enabled && available);
@@ -10452,6 +10543,8 @@
10452
10543
  const card = actionBtn.closest(".studio-pdf-card");
10453
10544
  if (!card) return;
10454
10545
  consumeStudioPreviewMediaEvent(event);
10546
+ // The card's More menu would never see this click, which ends here (Sol, Astra, c117).
10547
+ dismissStudioPdfMoreMenuAfterChoice(actionBtn);
10455
10548
  if (!studioPreviewNodeOwnerIsCurrent(actionBtn)) return;
10456
10549
  const interactionContext = buildStudioPreviewInteractionContext(actionBtn);
10457
10550
  if (!studioPreviewInteractionIsCurrent(interactionContext)) return;
@@ -11011,14 +11104,13 @@
11011
11104
  const focusBtn = document.createElement("button");
11012
11105
  focusBtn.type = "button";
11013
11106
  focusBtn.className = "studio-pdf-card-action studio-pdf-card-focus";
11014
- focusBtn.title = "Open this PDF in a larger Studio overlay.";
11107
+ focusBtn.title = "Enlarge";
11015
11108
  focusBtn.setAttribute("aria-label", "Enlarge PDF");
11016
11109
  if (focusBtn.dataset) {
11017
11110
  focusBtn.dataset.studioPdfViewerUrl = viewerUrl;
11018
11111
  focusBtn.dataset.studioPdfTitle = title;
11019
11112
  }
11020
11113
  focusBtn.appendChild(makeStudioUiRefreshIcon("focus"));
11021
- focusBtn.appendChild(document.createTextNode("Enlarge"));
11022
11114
  focusBtn.addEventListener("click", handleStudioPdfFocusButtonClick);
11023
11115
  titleGroup.appendChild(focusBtn);
11024
11116
  }
@@ -11044,7 +11136,6 @@
11044
11136
  event.preventDefault();
11045
11137
  event.stopPropagation();
11046
11138
  });
11047
- actions.appendChild(openLink);
11048
11139
 
11049
11140
  const systemViewerBtn = document.createElement("button");
11050
11141
  systemViewerBtn.type = "button";
@@ -11056,7 +11147,6 @@
11056
11147
  event.stopPropagation();
11057
11148
  void runStudioPdfLocalAction("system-viewer", resourceQuery, systemViewerBtn, { isCurrent });
11058
11149
  });
11059
- actions.appendChild(systemViewerBtn);
11060
11150
 
11061
11151
  const revealBtn = document.createElement("button");
11062
11152
  revealBtn.type = "button";
@@ -11068,7 +11158,6 @@
11068
11158
  event.stopPropagation();
11069
11159
  void runStudioPdfLocalAction("reveal", resourceQuery, revealBtn, { isCurrent });
11070
11160
  });
11071
- actions.appendChild(revealBtn);
11072
11161
 
11073
11162
  const copyPathBtn = document.createElement("button");
11074
11163
  copyPathBtn.type = "button";
@@ -11080,12 +11169,11 @@
11080
11169
  event.stopPropagation();
11081
11170
  void copyStudioPdfResourcePath(resourceQuery, copyPathBtn, { isCurrent });
11082
11171
  });
11083
- actions.appendChild(copyPathBtn);
11084
11172
 
11085
11173
  const refreshBtn = document.createElement("button");
11086
11174
  refreshBtn.type = "button";
11087
11175
  refreshBtn.className = "studio-pdf-card-action studio-pdf-card-refresh";
11088
- refreshBtn.textContent = "Refresh";
11176
+ refreshBtn.textContent = "Refresh now";
11089
11177
  refreshBtn.title = "Reload this PDF preview from disk. Shortcut: Cmd/Ctrl+Option/Alt+Shift+R.";
11090
11178
  refreshBtn.addEventListener("click", (event) => {
11091
11179
  event.preventDefault();
@@ -11093,7 +11181,6 @@
11093
11181
  if (!isCurrent()) return;
11094
11182
  if (!refreshStudioPdfCard(card)) setStatus("Could not refresh this PDF preview.", "warning");
11095
11183
  });
11096
- actions.appendChild(refreshBtn);
11097
11184
 
11098
11185
  const autoRefreshBtn = document.createElement("button");
11099
11186
  autoRefreshBtn.type = "button";
@@ -11114,6 +11201,7 @@
11114
11201
  setStudioPdfCardAutoRefresh(card, !state.enabled);
11115
11202
  });
11116
11203
  actions.appendChild(autoRefreshBtn);
11204
+ actions.appendChild(createStudioPdfMoreMenu("card", [refreshBtn, openLink, systemViewerBtn, revealBtn, copyPathBtn]));
11117
11205
 
11118
11206
  header.appendChild(actions);
11119
11207
  }
@@ -12142,6 +12230,21 @@
12142
12230
  if (!actionBtn) return;
12143
12231
  event.preventDefault();
12144
12232
  const action = actionBtn.getAttribute("data-repl-action") || "";
12233
+ // Looking at a file changes nothing, whichever session the pane was drawn for.
12234
+ if (action === "file-view" || action === "file-open") {
12235
+ const url = actionBtn.getAttribute("data-repl-file-url") || "";
12236
+ if (!/^\/repl-file\?/.test(url)) return;
12237
+ if (action === "file-view") {
12238
+ openStudioImageFocusViewer(url, actionBtn.getAttribute("data-repl-file-name") || "Image");
12239
+ return;
12240
+ }
12241
+ try {
12242
+ openStudioTabDirect(url);
12243
+ } catch (error) {
12244
+ setStatus(error instanceof Error ? error.message : String(error), "warning");
12245
+ }
12246
+ return;
12247
+ }
12145
12248
  // The name isn't the session's, so a pane drawn for another session can still change it.
12146
12249
  if (action === "sender-edit") {
12147
12250
  replSenderEditing = true;
@@ -12286,6 +12389,32 @@
12286
12389
  }
12287
12390
  }
12288
12391
 
12392
+ // The REPL pane's More menu opens right-aligned under More. Where the controls have wrapped
12393
+ // and More starts a row, that runs off the pane's left edge, so the menu is kept inside the
12394
+ // pane, narrower if the pane is.
12395
+ function placeReplMoreMenu(details) {
12396
+ const menu = details.querySelector(".repl-more-menu");
12397
+ const pane = details.closest("#leftPane, #rightPane");
12398
+ if (!(menu instanceof HTMLElement) || !pane) return;
12399
+ menu.style.left = "";
12400
+ menu.style.right = "";
12401
+ menu.style.minWidth = "";
12402
+ menu.style.maxWidth = "";
12403
+ const bounds = pane.getBoundingClientRect();
12404
+ const minLeft = bounds.left + 8;
12405
+ const available = Math.max(0, bounds.right - 8 - minLeft);
12406
+ // The stylesheet's minimum width would win over a smaller maximum (Sol, Astra).
12407
+ if (menu.getBoundingClientRect().width > available) menu.style.minWidth = menu.style.maxWidth = available + "px";
12408
+ if (menu.getBoundingClientRect().left >= minLeft) return;
12409
+ menu.style.right = "auto";
12410
+ menu.style.left = (minLeft - details.getBoundingClientRect().left) + "px";
12411
+ }
12412
+
12413
+ function handleReplMoreToggle(event) {
12414
+ const details = event && event.target;
12415
+ if (details instanceof HTMLDetailsElement && details.open && details.classList.contains("repl-more-controls")) placeReplMoreMenu(details);
12416
+ }
12417
+
12289
12418
  function handleReplPaneFocusIn(event) {
12290
12419
  if (!replQuickFocusRequested || rightView !== "repl") return;
12291
12420
  const target = event && event.target;
@@ -12424,8 +12553,11 @@
12424
12553
  if (!critiqueViewEl) return;
12425
12554
  critiqueViewEl.addEventListener("scroll", handleTracePaneScroll);
12426
12555
  critiqueViewEl.addEventListener("toggle", handleTraceDetailsToggle, true);
12556
+ critiqueViewEl.addEventListener("toggle", handleReplMoreToggle, true);
12427
12557
  critiqueViewEl.addEventListener("click", handleTracePaneClick);
12428
12558
  critiqueViewEl.addEventListener("click", handleReplPaneClick);
12559
+ critiqueViewEl.addEventListener("load", handleReplFileImageLoad, true);
12560
+ critiqueViewEl.addEventListener("scroll", handleReplViewScroll, { passive: true });
12429
12561
  critiqueViewEl.addEventListener("click", handleFilesPaneClick);
12430
12562
  critiqueViewEl.addEventListener("click", handleGitChangesPaneClick);
12431
12563
  critiqueViewEl.addEventListener("click", handleStudioQuartoPreviewClick);
@@ -13948,9 +14080,22 @@
13948
14080
  return String(replActiveSessionName || "").trim();
13949
14081
  }
13950
14082
 
14083
+ // The active session's record as Studio's server reads it (pi-repl's P0): refused, with why, or not verified.
14084
+ function getActiveReplRecordState() {
14085
+ const sessionName = getActiveReplJournalSessionName();
14086
+ const session = sessionName ? replSessions.find((candidate) => candidate.sessionName === sessionName) : null;
14087
+ return { refusal: (session && session.recordRefusal) || "", unverified: Boolean(session && session.recordUnverified) };
14088
+ }
14089
+
13951
14090
  function getVisibleReplJournalEntries() {
13952
14091
  const sessionName = getActiveReplJournalSessionName();
13953
- if (!sessionName) return replJournalEntries;
14092
+ if (!sessionName) {
14093
+ // With no session selected, every session's entries, but not a refused record's (Sol, Astra).
14094
+ const refused = new Set(replSessions.filter((session) => session.recordRefusal).map((session) => session.sessionName));
14095
+ return refused.size ? replJournalEntries.filter((entry) => !refused.has(entry.sessionName)) : replJournalEntries;
14096
+ }
14097
+ // Entries kept from before aren't a refused record's, to show, copy, export or load.
14098
+ if (getActiveReplRecordState().refusal) return [];
13954
14099
  return replJournalEntries.filter((entry) => entry.sessionName === sessionName);
13955
14100
  }
13956
14101
 
@@ -14400,9 +14545,10 @@
14400
14545
 
14401
14546
  function buildReplJournalHtml(transcript) {
14402
14547
  const sessionName = getActiveReplJournalSessionName();
14403
- // A record Studio won't use from here says why, and entries kept from before aren't shown as its record (P0).
14404
- const recordRefusal = (replSessions.find((session) => session.sessionName === sessionName) || {}).recordRefusal || "";
14405
- const visibleEntries = recordRefusal ? [] : getVisibleReplJournalEntries();
14548
+ // A record Studio won't use from here says why; one with no record-directory key yet says so (P0).
14549
+ const recordState = getActiveReplRecordState();
14550
+ const recordRefusal = recordState.refusal;
14551
+ const visibleEntries = getVisibleReplJournalEntries();
14406
14552
  const hasEntries = visibleEntries.length > 0;
14407
14553
  const entryCount = visibleEntries.length;
14408
14554
  const collapsedClass = replJournalCollapsed ? " is-collapsed" : "";
@@ -14448,6 +14594,7 @@
14448
14594
  + prose
14449
14595
  + code
14450
14596
  + output
14597
+ + buildReplEntryFilesHtml(entry)
14451
14598
  + pending
14452
14599
  + "</article>";
14453
14600
  }).join("");
@@ -14460,16 +14607,77 @@
14460
14607
  + (hasEntries ? cards : (recordRefusal ? "" : "<div class='repl-studio-empty'>" + escapeHtml(emptyText) + "</div>"));
14461
14608
  return "<section class='repl-journal'>"
14462
14609
  + "<div class='repl-journal-header'><h3>Shared REPL Record</h3>" + toggleActions + "</div>"
14463
- + "<p class='repl-journal-description'>What Studio and pi-repl have sent to this session."
14464
- + (replRecordActivity === "off" ? "" : " New entries here go to the agent and its model provider.")
14465
- + "</p>"
14466
14610
  + (recordRefusal ? "<p class='repl-journal-omitted'>" + escapeHtml("Not shown: " + recordRefusal) + "</p>" : "")
14611
+ + (!recordRefusal && recordState.unverified ? "<p class='repl-journal-omitted'>Record directory not verified: this session has no record-directory key yet, so the record here may not be the one other clients use.</p>" : "")
14467
14612
  + (omitted ? "<div class='repl-journal-omitted'>Showing latest 12 entries for this session; " + escapeHtml(String(omitted)) + " older entries remain in export.</div>" : "")
14468
14613
  // The prompt column fits the longest prompt, such as gnuplot>, in the prompt's own font.
14469
14614
  + "<div class='repl-journal-list' style='--repl-studio-prompt-chars: " + Math.max(0, ...visibleEntries.map((entry) => getReplStudioPrompt(entry.runtime).length)) + "'>" + terminalContent + "</div>"
14470
14615
  + "</section>";
14471
14616
  }
14472
14617
 
14618
+ function getReplFileUrl(file) {
14619
+ return "/repl-file?" + new URLSearchParams({ token: getToken(), id: file.id, v: file.v }).toString();
14620
+ }
14621
+
14622
+ // Image and PDF files an entry names, such as a saved plot, as pi-markdown-preview's REPL
14623
+ // page shows them: one tile each, images first, named inside the tile, the path as written
14624
+ // in its tooltip. An image opens in Studio's image viewer, a PDF in a new tab.
14625
+ function buildReplEntryFilesHtml(entry) {
14626
+ const files = Array.isArray(entry.files) ? entry.files : [];
14627
+ if (!files.length) return "";
14628
+ const name = (written) => written.split(/[\\/]/).pop() || written;
14629
+ const tiles = [...files.filter((file) => file.image), ...files.filter((file) => !file.image)].map((file) => {
14630
+ const url = getReplFileUrl(file);
14631
+ const attrs = " data-repl-file-url='" + escapeHtml(url) + "' data-repl-file-name='" + escapeHtml(name(file.written)) + "' title='" + escapeHtml(file.written) + "'";
14632
+ if (file.image) {
14633
+ return "<button type='button' class='repl-studio-file' data-repl-action='file-view'" + attrs + ">"
14634
+ + "<img class='repl-studio-file-img' src='" + escapeHtml(url) + "' alt='" + escapeHtml(file.written) + "' data-repl-file-key='" + escapeHtml(url) + "'>"
14635
+ + "<span class='repl-studio-file-name'>" + escapeHtml(name(file.written)) + "</span></button>";
14636
+ }
14637
+ const format = (/\.([^.]+)$/.exec(name(file.written)) || ["", ""])[1].toUpperCase();
14638
+ return "<button type='button' class='repl-studio-file repl-studio-file-other' data-repl-action='file-open'" + attrs + ">"
14639
+ + "<span class='repl-studio-file-format'>" + escapeHtml(format) + "</span>"
14640
+ + "<span class='repl-studio-file-name'>" + escapeHtml(name(file.written)) + "</span></button>";
14641
+ }).join("");
14642
+ return "<div class='repl-studio-files'>" + tiles + "</div>";
14643
+ }
14644
+
14645
+ // A redraw keeps the images already loaded, so a thumbnail doesn't flicker or change
14646
+ // the pane's height each time the record is drawn again.
14647
+ function captureReplFileImages() {
14648
+ const loaded = new Map();
14649
+ if (!critiqueViewEl) return loaded;
14650
+ critiqueViewEl.querySelectorAll("img[data-repl-file-key]").forEach((img) => {
14651
+ const key = img.getAttribute("data-repl-file-key") || "";
14652
+ if (key && img.complete && img.naturalWidth > 0 && !loaded.has(key)) loaded.set(key, img);
14653
+ });
14654
+ return loaded;
14655
+ }
14656
+
14657
+ function restoreReplFileImages(loaded) {
14658
+ if (!critiqueViewEl || !loaded.size) return;
14659
+ critiqueViewEl.querySelectorAll("img[data-repl-file-key]").forEach((img) => {
14660
+ const key = img.getAttribute("data-repl-file-key") || "";
14661
+ const kept = loaded.get(key);
14662
+ if (!kept) return;
14663
+ loaded.delete(key);
14664
+ img.replaceWith(kept);
14665
+ });
14666
+ }
14667
+
14668
+ // A thumbnail that loads while the pane is kept at its bottom keeps it there. Scrolling
14669
+ // decides that as a redraw does, so a load after the person scrolled up leaves them be (Sol).
14670
+ function handleReplViewScroll() {
14671
+ if (rightView === "repl") replViewStuckToBottom = shouldAutoStickReplView();
14672
+ }
14673
+
14674
+ function handleReplFileImageLoad(event) {
14675
+ if (rightView !== "repl" || !replViewStuckToBottom || !critiqueViewEl) return;
14676
+ const target = event.target;
14677
+ if (!(target instanceof Element) || !target.matches("img[data-repl-file-key]")) return;
14678
+ critiqueViewEl.scrollTop = critiqueViewEl.scrollHeight;
14679
+ }
14680
+
14473
14681
  function buildReplMirrorHtml(body, transcript) {
14474
14682
  const hasTranscript = Boolean(String(transcript || "").trim());
14475
14683
  const summary = hasTranscript
@@ -14898,10 +15106,13 @@
14898
15106
  function renderReplView() {
14899
15107
  if (!critiqueViewEl) return;
14900
15108
  const shouldStick = shouldAutoStickReplView();
15109
+ replViewStuckToBottom = shouldStick;
14901
15110
  const previousScrollTop = critiqueViewEl.scrollTop;
14902
15111
  const senderCursor = captureReplSenderCursor();
15112
+ const loadedFiles = captureReplFileImages();
14903
15113
  finishPreviewRender(critiqueViewEl);
14904
15114
  critiqueViewEl.innerHTML = buildReplPanelHtml();
15115
+ restoreReplFileImages(loadedFiles);
14905
15116
  restoreReplSenderCursor(senderCursor);
14906
15117
  critiqueViewEl.classList.remove("response-scroll-resetting");
14907
15118
  if (shouldStick) {
@@ -21076,7 +21287,7 @@
21076
21287
  if (!raw || raw.charAt(0) === "#") return false;
21077
21288
  if (/^\/\//.test(raw)) return false;
21078
21289
  if (/^(?:https?|mailto|tel|data|blob|javascript|about):/i.test(raw)) return false;
21079
- if (/^\/(?:pdf-resource|html-preview-resource|export-pdf|export-html|render-preview|render-math|import-file-copy|resource-grants|local-preview-link|reveal-local-resource|open-local-resource)(?:[?#/]|$)/i.test(raw)) return false;
21290
+ if (/^\/(?:repl-file|pdf-resource|html-preview-resource|export-pdf|export-html|render-preview|render-math|import-file-copy|resource-grants|local-preview-link|reveal-local-resource|open-local-resource)(?:[?#/]|$)/i.test(raw)) return false;
21080
21291
  return true;
21081
21292
  }
21082
21293
 
@@ -29424,7 +29635,6 @@
29424
29635
  noteReplChoiceAnswer(message);
29425
29636
  const present = !isReplChoicePending();
29426
29637
  replTmuxAvailable = typeof message.tmuxAvailable === "boolean" ? message.tmuxAvailable : replTmuxAvailable;
29427
- if (message.recordActivity === "on" || message.recordActivity === "send" || message.recordActivity === "off") replRecordActivity = message.recordActivity;
29428
29638
  const defaultName = validateReplPersonName(message.personName);
29429
29639
  if (!defaultName.error) replPersonNameDefault = defaultName.name;
29430
29640
  if (message.personNameSource === "environment" || message.personNameSource === "setting" || message.personNameSource === "default") replPersonNameSource = message.personNameSource;
@@ -29564,6 +29774,11 @@
29564
29774
  if (message.cleared && sessionName) {
29565
29775
  replJournalEntries = replJournalEntries.filter((entry) => entry.sessionName !== sessionName);
29566
29776
  persistReplJournalEntries();
29777
+ if (replJournalClearRequests.delete(message.requestId)) {
29778
+ // The active entry was this session's only if this session is still the one shown.
29779
+ if (sessionName === getActiveReplJournalSessionName()) activeReplJournalEntryId = "";
29780
+ setStatus("Cleared shared REPL record for " + sessionName + ".", "success");
29781
+ }
29567
29782
  } else {
29568
29783
  mergeReplJournalEntries(message.journalEntries);
29569
29784
  }
@@ -30129,6 +30344,13 @@
30129
30344
  return;
30130
30345
  }
30131
30346
 
30347
+ // This page's clear, refused: only its status changes, and its copy stays.
30348
+ if (message.type === "error" && replJournalClearRequests.delete(message.requestId)) {
30349
+ setStatus(typeof message.message === "string" ? message.message : "Nothing was cleared.", "warning");
30350
+ renderReplViewIfActive({ force: true });
30351
+ return;
30352
+ }
30353
+
30132
30354
  if (message.type === "error") {
30133
30355
  let rejectedSubmission = false;
30134
30356
  clearPiEditorOperations(message.requestId);