pi-studio 0.11.6 → 0.11.8

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.
@@ -688,6 +688,22 @@
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
+ // The name this page's sends and notes are recorded under: chosen here and kept in this
694
+ // browser, else the default from Studio's server (PI_REPL_USER_NAME, then pi-repl's saved
695
+ // name, then "User"). Read once, so another tab choosing a name later leaves this page alone.
696
+ const REPL_PERSON_NAME_STORAGE_KEY = "piStudio.replPersonName.v1";
697
+ let replPersonName = loadReplPersonName();
698
+ let replPersonNameDefault = "User";
699
+ let replPersonNameSource = "default";
700
+ let replSenderEditing = false;
701
+ // What's typed in the name field, kept as it's typed so a redraw by any route keeps it (Sol).
702
+ let replSenderDraft = "";
703
+ // This page's clears of sessions' records, by request ID, until Studio answers each.
704
+ const replJournalClearRequests = new Map();
705
+ // After Enter or Esc in the name field, the cursor goes back to ✎.
706
+ let replSenderReturnFocus = false;
691
707
  let replSessions = [];
692
708
  let replActiveSessionName = "";
693
709
  // Studio's selection as this page last adopted it, with its `shown`, and this page's
@@ -1609,6 +1625,10 @@
1609
1625
  runtime: typeof session.runtime === "string" ? session.runtime : "unknown",
1610
1626
  label: typeof session.label === "string" && session.label.trim() ? session.label.trim() : sessionName,
1611
1627
  source: typeof session.source === "string" ? session.source : "tmux",
1628
+ // Why Studio won't use its shared record from here, such as another record directory (pi-repl's P0).
1629
+ recordRefusal: typeof session.recordRefusal === "string" ? session.recordRefusal.slice(0, 1000) : "",
1630
+ // It has no record-directory key yet, so its record here may not be the one other clients use.
1631
+ recordUnverified: session.recordUnverified === true,
1612
1632
  };
1613
1633
  }
1614
1634
 
@@ -1841,9 +1861,10 @@
1841
1861
 
1842
1862
  function reconcileReplQuickPending() {
1843
1863
  if (!replQuickPending) return false;
1844
- const entry = replJournalEntries.find((candidate) => candidate.requestId === replQuickPending.requestId);
1864
+ // By its entry: the record gives a page's send its own request ID (studio:send:).
1865
+ const entry = replJournalEntries.find((candidate) => candidate.id === replQuickPending.journalEntryId);
1845
1866
  if (!entry || entry.status === "sending") return false;
1846
- return settleReplQuickPending(entry.requestId, entry.status !== "error");
1867
+ return settleReplQuickPending(replQuickPending.requestId, entry.status !== "error");
1847
1868
  }
1848
1869
 
1849
1870
  function updateReplQuickComposerActions() {
@@ -1889,6 +1910,8 @@
1889
1910
  target: session.target,
1890
1911
  tmuxSessionId: session.tmuxSessionId,
1891
1912
  tmuxSessionCreatedAt: session.tmuxSessionCreatedAt,
1913
+ recordRefusal: session.recordRefusal,
1914
+ recordUnverified: session.recordUnverified,
1892
1915
  })));
1893
1916
  }
1894
1917
 
@@ -2134,7 +2157,8 @@
2134
2157
  // its frame runs: composing, typing, a drag or focus elsewhere can start in between
2135
2158
  // (Sol, Astra). Composing holds even a forced redraw.
2136
2159
  function replRedrawMustWait(force) {
2137
- return replQuickComposing || (!force && isReplControlFocused() && !canRedrawReplUnderFocus());
2160
+ // Not under the name field while it's open either, even when forced: it would close mid-edit.
2161
+ return replQuickComposing || (replSenderEditing && isReplSenderNameFocused()) || (!force && isReplControlFocused() && !canRedrawReplUnderFocus());
2138
2162
  }
2139
2163
 
2140
2164
  function deferReplRedraw(force) {
@@ -2287,6 +2311,7 @@
2287
2311
  restoreReplQuickComposerCursor(cursor);
2288
2312
  applyReplQuickRefocus();
2289
2313
  if (replQuickFocusRequested) focusReplQuickComposer();
2314
+ focusReplSenderNameIfEditing();
2290
2315
  });
2291
2316
  }
2292
2317
 
@@ -2568,6 +2593,94 @@
2568
2593
  return "… " + formatCompactNumber(value.length - REPL_JOURNAL_OUTPUT_MAX_CHARS) + " earlier chars omitted …\n" + value.slice(value.length - REPL_JOURNAL_OUTPUT_MAX_CHARS);
2569
2594
  }
2570
2595
 
2596
+ // pi-repl's rule for a person's name (shared/repl-person.js): trimmed, at most 80
2597
+ // characters, nothing that could break or disguise it where it's shown.
2598
+ function validateReplPersonName(value) {
2599
+ if (typeof value !== "string") return { error: "a name must be text" };
2600
+ const name = value.trim();
2601
+ if (!name) return { error: "the name is empty" };
2602
+ if ([...name].length > 80) return { error: "the name is longer than 80 characters" };
2603
+ if (/[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}]/u.test(name)) return { error: "the name has control characters" };
2604
+ return { name };
2605
+ }
2606
+
2607
+ function loadReplPersonName() {
2608
+ try {
2609
+ const checked = validateReplPersonName(window.localStorage ? window.localStorage.getItem(REPL_PERSON_NAME_STORAGE_KEY) : null);
2610
+ return checked.error ? "" : checked.name;
2611
+ } catch {
2612
+ return "";
2613
+ }
2614
+ }
2615
+
2616
+ function getReplSenderName() {
2617
+ return replPersonName || replPersonNameDefault || "User";
2618
+ }
2619
+
2620
+ // What sends and notes are recorded under: the name on screen, since a redraw that would
2621
+ // show a new default can be waiting (Astra, Sol). Without the row on screen, the name now.
2622
+ function getShownReplSenderName() {
2623
+ const row = rightView === "repl" && critiqueViewEl ? critiqueViewEl.querySelector("[data-repl-sender-shown]") : null;
2624
+ const shown = row ? validateReplPersonName(row.getAttribute("data-repl-sender-shown")) : null;
2625
+ return shown && !shown.error ? shown.name : getReplSenderName();
2626
+ }
2627
+
2628
+ // A blank name goes back to the default.
2629
+ function chooseReplPersonName(value) {
2630
+ const trimmed = String(value || "").trim();
2631
+ const checked = trimmed ? validateReplPersonName(trimmed) : { name: "" };
2632
+ if (checked.error) return checked;
2633
+ replPersonName = checked.name;
2634
+ try {
2635
+ if (window.localStorage) {
2636
+ if (replPersonName) window.localStorage.setItem(REPL_PERSON_NAME_STORAGE_KEY, replPersonName);
2637
+ else window.localStorage.removeItem(REPL_PERSON_NAME_STORAGE_KEY);
2638
+ }
2639
+ } catch {
2640
+ // The name still applies to this page.
2641
+ }
2642
+ return { name: getReplSenderName() };
2643
+ }
2644
+
2645
+ // A version 4 UUID. getRandomValues, since randomUUID needs a secure context and Studio
2646
+ // can be opened over the network.
2647
+ function makeReplPersonUuid() {
2648
+ const bytes = window.crypto.getRandomValues(new Uint8Array(16));
2649
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
2650
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
2651
+ const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
2652
+ return hex.slice(0, 8) + "-" + hex.slice(8, 12) + "-" + hex.slice(12, 16) + "-" + hex.slice(16, 20) + "-" + hex.slice(20);
2653
+ }
2654
+
2655
+ // A person's request ID under Studio's channel prefix (studio:send: or studio:note:).
2656
+ function makeReplPersonRequestId(kind) {
2657
+ return "studio:" + kind + ":" + makeReplPersonUuid();
2658
+ }
2659
+
2660
+ // This page's send, recorded under studio:send: and the send's request ID.
2661
+ function isReplEntryOfRequest(entry, requestId) {
2662
+ return Boolean(requestId) && (entry.requestId === requestId || entry.requestId === "studio:send:" + requestId);
2663
+ }
2664
+
2665
+ // Who sent an entry, as the shared protocol's readers show it and as Studio tells its
2666
+ // agent (describeReplEntrySender in shared/studio-repl-activity.js): an agent's label; a
2667
+ // name under a person's prefix on its matching origin; otherwise "User".
2668
+ function describeReplEntrySender(entry) {
2669
+ const oneLine = (value) => {
2670
+ const text = String(value == null ? "" : value).replace(/[\u0000-\u001f\u007f-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]+/g, " ").replace(/\s+/g, " ").trim();
2671
+ return [...text].length > 80 ? [...text].slice(0, 79).join("") + "…" : text;
2672
+ };
2673
+ if (entry.mode === "agent") return oneLine(entry.label) || "Agent";
2674
+ const channels = [
2675
+ { prefix: /^pi:(?:send|env):/, origin: "pi-repl", channel: "Pi" },
2676
+ { prefix: /^cli:(?:send|env):/, origin: "pi-repl", channel: "terminal" },
2677
+ { prefix: /^studio:(?:send|note):/, origin: "pi-studio", channel: "Pi Studio" },
2678
+ ];
2679
+ const person = channels.find((candidate) => candidate.origin === entry.origin && candidate.prefix.test(entry.requestId || ""));
2680
+ if (person) return (oneLine(entry.label) || "User") + " · via " + person.channel;
2681
+ return entry.origin === "pi-studio" ? "User · via Pi Studio" : "User";
2682
+ }
2683
+
2571
2684
  function createReplJournalEntry(details) {
2572
2685
  const sharedSynced = details.sharedSynced === true;
2573
2686
  return {
@@ -2849,6 +2962,11 @@
2849
2962
  }
2850
2963
 
2851
2964
  async function copyReplJournalToClipboard() {
2965
+ const refusal = getActiveReplRecordState().refusal;
2966
+ if (refusal) {
2967
+ setStatus(refusal, "warning");
2968
+ return;
2969
+ }
2852
2970
  const entries = getVisibleReplJournalEntries();
2853
2971
  if (!entries.length) {
2854
2972
  setStatus("No shared REPL record entries to copy for this session yet.", "warning");
@@ -2862,6 +2980,11 @@
2862
2980
  }
2863
2981
 
2864
2982
  function exportReplJournalMarkdown() {
2983
+ const refusal = getActiveReplRecordState().refusal;
2984
+ if (refusal) {
2985
+ setStatus(refusal, "warning");
2986
+ return;
2987
+ }
2865
2988
  const entries = getVisibleReplJournalEntries();
2866
2989
  if (!entries.length) {
2867
2990
  setStatus("No shared REPL record entries to export for this session yet.", "warning");
@@ -2881,23 +3004,33 @@
2881
3004
  setStatus("Exported shared REPL record Markdown.", "success");
2882
3005
  }
2883
3006
 
3007
+ // A session's record is cleared here once Studio has cleared it: Studio can refuse, and then
3008
+ // this page keeps its copy too (pi-repl's P0).
2884
3009
  function clearReplJournal() {
2885
3010
  const sessionName = getActiveReplJournalSessionName();
2886
- if (sessionName) {
2887
- replJournalEntries = replJournalEntries.filter((entry) => entry.sessionName !== sessionName);
2888
- } else {
3011
+ if (!sessionName) {
2889
3012
  replJournalEntries = [];
3013
+ activeReplJournalEntryId = "";
3014
+ persistReplJournalEntries();
3015
+ setStatus("Cleared local REPL record cache.", "success");
3016
+ renderReplViewIfActive({ force: true });
3017
+ return;
2890
3018
  }
2891
- activeReplJournalEntryId = "";
2892
- persistReplJournalEntries();
2893
- if (sessionName) {
2894
- sendMessage({ type: "repl_journal_clear_request", requestId: makeRequestId(), sessionName });
3019
+ const requestId = makeRequestId();
3020
+ if (!sendMessage({ type: "repl_journal_clear_request", requestId, sessionName })) {
3021
+ setStatus("Nothing was cleared: Studio isn't connected.", "warning");
3022
+ return;
2895
3023
  }
2896
- setStatus(sessionName ? "Cleared shared REPL record for this session." : "Cleared local REPL record cache.", "success");
2897
- renderReplViewIfActive({ force: true });
3024
+ replJournalClearRequests.set(requestId, sessionName);
3025
+ setStatus("Clearing the shared REPL record…", "info");
2898
3026
  }
2899
3027
 
2900
3028
  function loadReplJournalIntoEditor() {
3029
+ const refusal = getActiveReplRecordState().refusal;
3030
+ if (refusal) {
3031
+ setStatus(refusal, "warning");
3032
+ return;
3033
+ }
2901
3034
  const entries = getVisibleReplJournalEntries();
2902
3035
  if (!entries.length) {
2903
3036
  setStatus("No shared REPL record entries to load for this session yet.", "warning");
@@ -2920,7 +3053,8 @@
2920
3053
  return;
2921
3054
  }
2922
3055
  const entry = addReplJournalEntry({
2923
- label: "note",
3056
+ requestId: makeReplPersonRequestId("note"),
3057
+ label: getShownReplSenderName(),
2924
3058
  prose: note,
2925
3059
  status: "note",
2926
3060
  mode: "literate",
@@ -2949,7 +3083,8 @@
2949
3083
  if (payload.noteOnly) {
2950
3084
  if (String(payload.prose || "").trim()) {
2951
3085
  const entry = addReplJournalEntry({
2952
- label: payload.label || "note",
3086
+ requestId: makeReplPersonRequestId("note"),
3087
+ label: getShownReplSenderName(),
2953
3088
  prose: payload.prose,
2954
3089
  status: "note",
2955
3090
  mode: payload.mode || "literate",
@@ -2970,12 +3105,14 @@
2970
3105
  setStatus("REPL submission is empty.", "warning");
2971
3106
  return null;
2972
3107
  }
2973
- const requestId = makeRequestId();
3108
+ // Recorded under the name shown, as studio:send: and this request's ID, here and by the
3109
+ // server, so the card shows the name while the send waits.
3110
+ const requestId = makeReplPersonUuid();
2974
3111
  const journalEntry = addReplJournalEntry({
2975
- requestId,
3112
+ requestId: "studio:send:" + requestId,
2976
3113
  sessionName: session.sessionName,
2977
3114
  runtime: getActiveReplRuntime(),
2978
- label: payload.label,
3115
+ label: getShownReplSenderName(),
2979
3116
  mode: payload.mode,
2980
3117
  prose: payload.prose,
2981
3118
  code: text,
@@ -2999,6 +3136,7 @@
2999
3136
  journalEntryId: journalEntry.id,
3000
3137
  createdAt: journalEntry.createdAt,
3001
3138
  label: journalEntry.label,
3139
+ personName: journalEntry.label,
3002
3140
  mode: journalEntry.mode,
3003
3141
  prose: journalEntry.prose,
3004
3142
  skippedChunks: journalEntry.skippedChunks,
@@ -3057,7 +3195,7 @@
3057
3195
  skippedChunks: 0,
3058
3196
  });
3059
3197
  if (!requestId) return false;
3060
- replQuickPending = { requestId, key, text };
3198
+ replQuickPending = { requestId, key, text, journalEntryId: activeReplJournalEntryId };
3061
3199
  const activeEl = document.activeElement;
3062
3200
  replQuickRefocus = activeEl instanceof Element && activeEl.closest(".repl-quick-composer") ? { requestId, settled: false } : null;
3063
3201
  renderReplViewIfActive({ force: true });
@@ -12029,6 +12167,13 @@
12029
12167
  if (!actionBtn) return;
12030
12168
  event.preventDefault();
12031
12169
  const action = actionBtn.getAttribute("data-repl-action") || "";
12170
+ // The name isn't the session's, so a pane drawn for another session can still change it.
12171
+ if (action === "sender-edit") {
12172
+ replSenderEditing = true;
12173
+ replSenderDraft = replPersonName || getReplSenderName();
12174
+ renderReplViewIfActive({ force: true });
12175
+ return;
12176
+ }
12032
12177
  if (isReplPaneStale(actionBtn)) {
12033
12178
  refuseStaleReplPaneAction(action === "quick-send" ? "The REPL session changed, so nothing was sent." : "The REPL session changed, so nothing was done.");
12034
12179
  return;
@@ -12166,6 +12311,32 @@
12166
12311
  }
12167
12312
  }
12168
12313
 
12314
+ // The REPL pane's More menu opens right-aligned under More. Where the controls have wrapped
12315
+ // and More starts a row, that runs off the pane's left edge, so the menu is kept inside the
12316
+ // pane, narrower if the pane is.
12317
+ function placeReplMoreMenu(details) {
12318
+ const menu = details.querySelector(".repl-more-menu");
12319
+ const pane = details.closest("#leftPane, #rightPane");
12320
+ if (!(menu instanceof HTMLElement) || !pane) return;
12321
+ menu.style.left = "";
12322
+ menu.style.right = "";
12323
+ menu.style.minWidth = "";
12324
+ menu.style.maxWidth = "";
12325
+ const bounds = pane.getBoundingClientRect();
12326
+ const minLeft = bounds.left + 8;
12327
+ const available = Math.max(0, bounds.right - 8 - minLeft);
12328
+ // The stylesheet's minimum width would win over a smaller maximum (Sol, Astra).
12329
+ if (menu.getBoundingClientRect().width > available) menu.style.minWidth = menu.style.maxWidth = available + "px";
12330
+ if (menu.getBoundingClientRect().left >= minLeft) return;
12331
+ menu.style.right = "auto";
12332
+ menu.style.left = (minLeft - details.getBoundingClientRect().left) + "px";
12333
+ }
12334
+
12335
+ function handleReplMoreToggle(event) {
12336
+ const details = event && event.target;
12337
+ if (details instanceof HTMLDetailsElement && details.open && details.classList.contains("repl-more-controls")) placeReplMoreMenu(details);
12338
+ }
12339
+
12169
12340
  function handleReplPaneFocusIn(event) {
12170
12341
  if (!replQuickFocusRequested || rightView !== "repl") return;
12171
12342
  const target = event && event.target;
@@ -12175,7 +12346,13 @@
12175
12346
  }
12176
12347
 
12177
12348
  // A redraw that waited for a control runs once focus has left it.
12178
- function handleReplPaneFocusOut() {
12349
+ function handleReplPaneFocusOut(event) {
12350
+ const target = event && event.target;
12351
+ // Leaving the name field keeps what's in it; a redraw that removed it doesn't count.
12352
+ if (target instanceof HTMLInputElement && target.hasAttribute("data-repl-sender-name") && target.isConnected) {
12353
+ finishReplSenderEdit(true);
12354
+ return;
12355
+ }
12179
12356
  if (!replRedrawDeferred) return;
12180
12357
  window.setTimeout(replayDeferredReplRedraw, 0);
12181
12358
  }
@@ -12205,6 +12382,10 @@
12205
12382
  function handleReplPaneInput(event) {
12206
12383
  if (rightView !== "repl") return;
12207
12384
  const target = event && event.target;
12385
+ if (target instanceof HTMLInputElement && target.hasAttribute("data-repl-sender-name")) {
12386
+ replSenderDraft = target.value;
12387
+ return;
12388
+ }
12208
12389
  if (!(target instanceof HTMLTextAreaElement) || !target.hasAttribute("data-repl-quick-draft")) return;
12209
12390
  replQuickLastInputAt = Date.now();
12210
12391
  // The text belongs to the session the box was drawn for, even if another is selected
@@ -12219,6 +12400,15 @@
12219
12400
  function handleReplPaneKeydown(event) {
12220
12401
  if (rightView !== "repl" || !event || event.isComposing) return;
12221
12402
  const target = event.target;
12403
+ if (target instanceof HTMLInputElement && target.hasAttribute("data-repl-sender-name")) {
12404
+ if (event.key !== "Enter" && event.key !== "Escape") return;
12405
+ event.preventDefault();
12406
+ event.stopPropagation();
12407
+ replSenderReturnFocus = true;
12408
+ finishReplSenderEdit(event.key === "Enter");
12409
+ if (replSenderEditing) replSenderReturnFocus = false;
12410
+ return;
12411
+ }
12222
12412
  if (!(target instanceof HTMLTextAreaElement) || !target.hasAttribute("data-repl-quick-draft")) return;
12223
12413
  const submitShortcut = event.key === "Enter"
12224
12414
  && (event.metaKey || event.ctrlKey)
@@ -12285,6 +12475,7 @@
12285
12475
  if (!critiqueViewEl) return;
12286
12476
  critiqueViewEl.addEventListener("scroll", handleTracePaneScroll);
12287
12477
  critiqueViewEl.addEventListener("toggle", handleTraceDetailsToggle, true);
12478
+ critiqueViewEl.addEventListener("toggle", handleReplMoreToggle, true);
12288
12479
  critiqueViewEl.addEventListener("click", handleTracePaneClick);
12289
12480
  critiqueViewEl.addEventListener("click", handleReplPaneClick);
12290
12481
  critiqueViewEl.addEventListener("click", handleFilesPaneClick);
@@ -13809,9 +14000,22 @@
13809
14000
  return String(replActiveSessionName || "").trim();
13810
14001
  }
13811
14002
 
14003
+ // The active session's record as Studio's server reads it (pi-repl's P0): refused, with why, or not verified.
14004
+ function getActiveReplRecordState() {
14005
+ const sessionName = getActiveReplJournalSessionName();
14006
+ const session = sessionName ? replSessions.find((candidate) => candidate.sessionName === sessionName) : null;
14007
+ return { refusal: (session && session.recordRefusal) || "", unverified: Boolean(session && session.recordUnverified) };
14008
+ }
14009
+
13812
14010
  function getVisibleReplJournalEntries() {
13813
14011
  const sessionName = getActiveReplJournalSessionName();
13814
- if (!sessionName) return replJournalEntries;
14012
+ if (!sessionName) {
14013
+ // With no session selected, every session's entries, but not a refused record's (Sol, Astra).
14014
+ const refused = new Set(replSessions.filter((session) => session.recordRefusal).map((session) => session.sessionName));
14015
+ return refused.size ? replJournalEntries.filter((entry) => !refused.has(entry.sessionName)) : replJournalEntries;
14016
+ }
14017
+ // Entries kept from before aren't a refused record's, to show, copy, export or load.
14018
+ if (getActiveReplRecordState().refusal) return [];
13815
14019
  return replJournalEntries.filter((entry) => entry.sessionName === sessionName);
13816
14020
  }
13817
14021
 
@@ -14206,8 +14410,9 @@
14206
14410
  function buildReplStudioMeta(entry) {
14207
14411
  const parts = [];
14208
14412
  const kind = getReplStudioEntryKind(entry);
14209
- if (kind !== "Raw") parts.push(kind);
14210
- if (entry.origin) parts.push(entry.origin);
14413
+ // An agent's entry is named by who sent it.
14414
+ if (kind !== "Raw" && kind !== "Pi") parts.push(kind);
14415
+ parts.push(describeReplEntrySender(entry));
14211
14416
  const time = formatReferenceTime(entry.createdAt);
14212
14417
  if (time) parts.push(time);
14213
14418
  if (entry.skippedChunks) parts.push("skipped " + String(entry.skippedChunks));
@@ -14259,10 +14464,13 @@
14259
14464
  }
14260
14465
 
14261
14466
  function buildReplJournalHtml(transcript) {
14467
+ const sessionName = getActiveReplJournalSessionName();
14468
+ // A record Studio won't use from here says why; one with no record-directory key yet says so (P0).
14469
+ const recordState = getActiveReplRecordState();
14470
+ const recordRefusal = recordState.refusal;
14262
14471
  const visibleEntries = getVisibleReplJournalEntries();
14263
14472
  const hasEntries = visibleEntries.length > 0;
14264
14473
  const entryCount = visibleEntries.length;
14265
- const sessionName = getActiveReplJournalSessionName();
14266
14474
  const collapsedClass = replJournalCollapsed ? " is-collapsed" : "";
14267
14475
  const toggleButton = "<button type='button' data-repl-action='journal-toggle' aria-expanded='" + (replJournalCollapsed ? "false" : "true") + "'>" + (replJournalCollapsed ? "Show record" : "Hide record") + "</button>";
14268
14476
  const toggleActions = "<div class='repl-journal-actions'>" + toggleButton + "</div>";
@@ -14300,8 +14508,9 @@
14300
14508
  const pending = !output && entry.status === "sending"
14301
14509
  ? "<div class='repl-studio-pending'>Running…</div>"
14302
14510
  : "";
14511
+ // Who sent it shows; the rest, such as the time, is in its tooltip.
14303
14512
  return "<article class='repl-journal-card repl-studio-entry'>"
14304
- + (meta ? "<div class='repl-studio-entry-meta'>" + escapeHtml(meta) + "</div>" : "")
14513
+ + (meta ? "<div class='repl-studio-entry-meta' title='" + escapeHtml(meta) + "'>" + escapeHtml(describeReplEntrySender(entry)) + "</div>" : "")
14305
14514
  + prose
14306
14515
  + code
14307
14516
  + output
@@ -14314,10 +14523,14 @@
14314
14523
  : "No compatible-client record entries yet. Send code from pi-repl or Studio, or use More → Add note (Literate send) to record prose.")
14315
14524
  : "No compatible-client record entries yet. Send code from pi-repl or Studio, or use More → Add note (Literate send) to record prose.";
14316
14525
  const terminalContent = banner
14317
- + (hasEntries ? cards : "<div class='repl-studio-empty'>" + escapeHtml(emptyText) + "</div>");
14526
+ + (hasEntries ? cards : (recordRefusal ? "" : "<div class='repl-studio-empty'>" + escapeHtml(emptyText) + "</div>"));
14318
14527
  return "<section class='repl-journal'>"
14319
14528
  + "<div class='repl-journal-header'><h3>Shared REPL Record</h3>" + toggleActions + "</div>"
14320
- + "<p class='repl-journal-description'>What Studio and pi-repl have sent to this session.</p>"
14529
+ + "<p class='repl-journal-description'>What Studio and pi-repl have sent to this session."
14530
+ + (replRecordActivity === "off" ? "" : " New entries here go to the agent and its model provider.")
14531
+ + "</p>"
14532
+ + (recordRefusal ? "<p class='repl-journal-omitted'>" + escapeHtml("Not shown: " + recordRefusal) + "</p>" : "")
14533
+ + (!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>" : "")
14321
14534
  + (omitted ? "<div class='repl-journal-omitted'>Showing latest 12 entries for this session; " + escapeHtml(String(omitted)) + " older entries remain in export.</div>" : "")
14322
14535
  // The prompt column fits the longest prompt, such as gnuplot>, in the prompt's own font.
14323
14536
  + "<div class='repl-journal-list' style='--repl-studio-prompt-chars: " + Math.max(0, ...visibleEntries.map((entry) => getReplStudioPrompt(entry.runtime).length)) + "'>" + terminalContent + "</div>"
@@ -14352,6 +14565,77 @@
14352
14565
  return "tmux attach -t " + String(session.sessionName || "");
14353
14566
  }
14354
14567
 
14568
+ // "Sending as …": the name this page's sends and notes are recorded under, and its editor.
14569
+ function buildReplSenderHtml() {
14570
+ const name = getReplSenderName();
14571
+ if (replSenderEditing) {
14572
+ return "<span class='repl-quick-sender'><label>Sending as <input data-repl-sender-name type='text' value='" + escapeHtml(replSenderDraft) + "' placeholder='" + escapeHtml(replPersonNameDefault || "User") + "' aria-label='Name your sends and notes are recorded under' title='Enter to keep, Esc to cancel. Leave it empty for " + escapeHtml(replPersonNameDefault || "User") + ".'></label></span>";
14573
+ }
14574
+ const from = replPersonName
14575
+ ? "Chosen in this browser."
14576
+ : (replPersonNameSource === "environment"
14577
+ ? "From PI_REPL_USER_NAME."
14578
+ : (replPersonNameSource === "setting" ? "The name saved with /repl name or agent-repl name." : "No name is set."));
14579
+ return "<span class='repl-quick-sender' data-repl-sender-shown='" + escapeHtml(name) + "' title='Your sends and notes are recorded under this name. " + escapeHtml(from) + "'>Sending as <strong>" + escapeHtml(name) + "</strong>"
14580
+ + "<button type='button' class='repl-quick-sender-edit' data-repl-action='sender-edit' aria-label='Change the name your sends and notes are recorded under' title='Change name'>✎</button></span>";
14581
+ }
14582
+
14583
+ function isReplSenderNameFocused() {
14584
+ const activeEl = document.activeElement;
14585
+ return activeEl instanceof HTMLInputElement && activeEl.hasAttribute("data-repl-sender-name");
14586
+ }
14587
+
14588
+ function focusReplSenderNameIfEditing() {
14589
+ if (!critiqueViewEl) return;
14590
+ if (!replSenderEditing) {
14591
+ const button = replSenderReturnFocus ? critiqueViewEl.querySelector("[data-repl-action='sender-edit']") : null;
14592
+ replSenderReturnFocus = false;
14593
+ if (button instanceof HTMLElement) button.focus({ preventScroll: true });
14594
+ return;
14595
+ }
14596
+ if (isReplSenderNameFocused()) return;
14597
+ const input = critiqueViewEl.querySelector("[data-repl-sender-name]");
14598
+ if (!(input instanceof HTMLInputElement)) return;
14599
+ input.focus({ preventScroll: true });
14600
+ input.select();
14601
+ }
14602
+
14603
+ // Where the cursor is in the name field, so a redraw by any route puts it back: a response
14604
+ // can redraw the pane without waiting for the field (Sol).
14605
+ function captureReplSenderCursor() {
14606
+ if (!replSenderEditing || !isReplSenderNameFocused()) return null;
14607
+ const input = document.activeElement;
14608
+ return { start: input.selectionStart, end: input.selectionEnd, direction: input.selectionDirection };
14609
+ }
14610
+
14611
+ function restoreReplSenderCursor(cursor) {
14612
+ if (!cursor || !replSenderEditing || !critiqueViewEl) return;
14613
+ const input = critiqueViewEl.querySelector("[data-repl-sender-name]");
14614
+ if (!(input instanceof HTMLInputElement)) return;
14615
+ input.focus({ preventScroll: true });
14616
+ try {
14617
+ input.setSelectionRange(cursor.start, cursor.end, cursor.direction || "none");
14618
+ } catch {}
14619
+ }
14620
+
14621
+ // Enter or leaving the field keeps the name; Esc doesn't.
14622
+ function finishReplSenderEdit(keep) {
14623
+ if (!replSenderEditing) return;
14624
+ const input = critiqueViewEl ? critiqueViewEl.querySelector("[data-repl-sender-name]") : null;
14625
+ if (keep && input instanceof HTMLInputElement) {
14626
+ const before = getReplSenderName();
14627
+ const chosen = chooseReplPersonName(input.value);
14628
+ if (chosen.error) {
14629
+ setStatus("Name not changed: " + chosen.error + ".", "warning");
14630
+ if (document.activeElement === input) return;
14631
+ } else if (chosen.name !== before) {
14632
+ setStatus("Sending as " + chosen.name + ".", "success");
14633
+ }
14634
+ }
14635
+ replSenderEditing = false;
14636
+ renderReplViewIfActive({ force: true });
14637
+ }
14638
+
14355
14639
  function buildReplQuickComposerHtml(activeSession, canSendToActiveSession) {
14356
14640
  const key = getReplQuickDraftKey(activeSession);
14357
14641
  const draft = getReplQuickDraft(activeSession);
@@ -14368,7 +14652,7 @@
14368
14652
  + "<div class='repl-quick-header'><div><strong id='replQuickComposerTitle'>Quick send</strong><button type='button' class='repl-quick-target' data-repl-action='jump-controls' title='Target: " + escapeHtml(targetDetails) + ". Jump to REPL session controls.' aria-label='Target: " + escapeHtml(targetDetails) + ". Jump to REPL session controls.'><span class='repl-quick-target-label'>" + escapeHtml(visibleTargetLabel) + "</span><span class='repl-quick-target-arrow' aria-hidden='true'>↑</span></button></div>"
14369
14653
  + "<span class='repl-quick-hint'>Enter adds a line · Cmd/Ctrl+Enter sends</span></div>"
14370
14654
  + "<textarea data-repl-quick-draft data-repl-quick-lifetime='" + escapeHtml(encodeURIComponent(key)) + "'" + (replQuickBoxHeight ? " style='height: " + replQuickBoxHeight + "'" : "") + " rows='3' maxlength='" + REPL_QUICK_DRAFT_MAX_CHARS + "' aria-label='Quick code for " + escapeHtml(targetDetails) + "' aria-keyshortcuts='Meta+Enter Control+Enter' placeholder='" + (activeSession ? (key ? "Type a short command or snippet…" : "Exact tmux identity unavailable; refresh the session list") : "Start or select a REPL session first") + "'" + (inputDisabled ? " disabled" : "") + ">" + escapeHtml(draft) + "</textarea>"
14371
- + "<div class='repl-quick-actions'><span></span><div>"
14655
+ + "<div class='repl-quick-actions'>" + buildReplSenderHtml() + "<div>"
14372
14656
  + "<button type='button' data-repl-action='quick-clear'" + (pending || !draft ? " disabled" : "") + ">Clear</button>"
14373
14657
  + "<button class='repl-quick-send-btn' type='button' data-repl-action='quick-send'" + (sendDisabled ? " disabled" : "") + ">" + (pending ? "Sending…" : "Send") + "</button>"
14374
14658
  + "</div></div></section>";
@@ -14682,8 +14966,10 @@
14682
14966
  if (!critiqueViewEl) return;
14683
14967
  const shouldStick = shouldAutoStickReplView();
14684
14968
  const previousScrollTop = critiqueViewEl.scrollTop;
14969
+ const senderCursor = captureReplSenderCursor();
14685
14970
  finishPreviewRender(critiqueViewEl);
14686
14971
  critiqueViewEl.innerHTML = buildReplPanelHtml();
14972
+ restoreReplSenderCursor(senderCursor);
14687
14973
  critiqueViewEl.classList.remove("response-scroll-resetting");
14688
14974
  if (shouldStick) {
14689
14975
  critiqueViewEl.scrollTop = critiqueViewEl.scrollHeight;
@@ -17927,6 +18213,10 @@
17927
18213
  if (!current()) throw new Error("The editor changed. Current work was kept.");
17928
18214
  captureStudioBufferTransientState(); persistWorkspaceStateNow(); await bufferRecoveryClient.settled();
17929
18215
  const ready = await prepareDocumentHostingReplacement(bufferId, current);
18216
+ // The persistence timer can resend an unchanged checkpoint during that request; the open's gate refuses
18217
+ // while any save is in flight, so let it land first. A real change meanwhile still fails the check below
18218
+ // (c73's intermittent refusal after a reload, 30 Oct).
18219
+ await bufferRecoveryClient.settled();
17930
18220
  if (!ready()) throw new Error("The owning checkpoint changed before opening.");
17931
18221
  },
17932
18222
  capture: () => { captureStudioBufferTransientState(); persistWorkspaceStateNow(); },
@@ -29195,11 +29485,16 @@
29195
29485
  const settlesPendingRequest = Boolean(responseRequestId && responseRequestId === replPendingRequestId);
29196
29486
  const previousActiveLifetimeKey = getReplQuickDraftKey(getActiveReplSession());
29197
29487
  const previousRuntime = replRuntime;
29488
+ const previousSender = getReplSenderName() + "\u001e" + replPersonNameSource;
29198
29489
  // Every repl_state states Studio's selection; while this page's own choice is
29199
29490
  // unanswered, only that choice's reply changes what the page shows.
29200
29491
  noteReplChoiceAnswer(message);
29201
29492
  const present = !isReplChoicePending();
29202
29493
  replTmuxAvailable = typeof message.tmuxAvailable === "boolean" ? message.tmuxAvailable : replTmuxAvailable;
29494
+ if (message.recordActivity === "on" || message.recordActivity === "send" || message.recordActivity === "off") replRecordActivity = message.recordActivity;
29495
+ const defaultName = validateReplPersonName(message.personName);
29496
+ if (!defaultName.error) replPersonNameDefault = defaultName.name;
29497
+ if (message.personNameSource === "environment" || message.personNameSource === "setting" || message.personNameSource === "default") replPersonNameSource = message.personNameSource;
29203
29498
  const sessionsChanged = setReplSessions(message.sessions);
29204
29499
  if (present) adoptReplSelection(message);
29205
29500
  const journalChanged = mergeReplJournalEntries(message.journalEntries);
@@ -29225,6 +29520,7 @@
29225
29520
  || previousError !== replError
29226
29521
  || previousMessage !== replMessage
29227
29522
  || journalChanged
29523
+ || previousSender !== getReplSenderName() + "\u001e" + replPersonNameSource
29228
29524
  || (!previousCapturedAt && replCapturedAt);
29229
29525
  if (viewChanged) renderReplViewIfActive({ force: activeSessionIdentityChanged });
29230
29526
  updateReferenceBadge();
@@ -29335,6 +29631,11 @@
29335
29631
  if (message.cleared && sessionName) {
29336
29632
  replJournalEntries = replJournalEntries.filter((entry) => entry.sessionName !== sessionName);
29337
29633
  persistReplJournalEntries();
29634
+ if (replJournalClearRequests.delete(message.requestId)) {
29635
+ // The active entry was this session's only if this session is still the one shown.
29636
+ if (sessionName === getActiveReplJournalSessionName()) activeReplJournalEntryId = "";
29637
+ setStatus("Cleared shared REPL record for " + sessionName + ".", "success");
29638
+ }
29338
29639
  } else {
29339
29640
  mergeReplJournalEntries(message.journalEntries);
29340
29641
  }
@@ -29351,7 +29652,7 @@
29351
29652
  if (responseRequestId) settleReplQuickPending(responseRequestId, true);
29352
29653
  mergeReplJournalEntries(message.journalEntries);
29353
29654
  if (typeof message.requestId === "string") {
29354
- replJournalEntries = replJournalEntries.map((entry) => entry.requestId === message.requestId ? { ...entry, status: "sent", updatedAt: Date.now() } : entry);
29655
+ replJournalEntries = replJournalEntries.map((entry) => isReplEntryOfRequest(entry, message.requestId) ? { ...entry, status: "sent", updatedAt: Date.now() } : entry);
29355
29656
  persistReplJournalEntries();
29356
29657
  }
29357
29658
  setStatus("Sent to REPL.", "success");
@@ -29900,6 +30201,13 @@
29900
30201
  return;
29901
30202
  }
29902
30203
 
30204
+ // This page's clear, refused: only its status changes, and its copy stays.
30205
+ if (message.type === "error" && replJournalClearRequests.delete(message.requestId)) {
30206
+ setStatus(typeof message.message === "string" ? message.message : "Nothing was cleared.", "warning");
30207
+ renderReplViewIfActive({ force: true });
30208
+ return;
30209
+ }
30210
+
29903
30211
  if (message.type === "error") {
29904
30212
  let rejectedSubmission = false;
29905
30213
  clearPiEditorOperations(message.requestId);
@@ -29930,7 +30238,7 @@
29930
30238
  replError = typeof message.message === "string" ? message.message : "REPL request failed.";
29931
30239
  settleReplQuickPending(failedReplRequestId, false);
29932
30240
  if (typeof message.requestId === "string") {
29933
- replJournalEntries = replJournalEntries.map((entry) => entry.requestId === message.requestId ? { ...entry, status: "error", output: replError, updatedAt: Date.now() } : entry);
30241
+ replJournalEntries = replJournalEntries.map((entry) => isReplEntryOfRequest(entry, message.requestId) ? { ...entry, status: "error", output: replError, updatedAt: Date.now() } : entry);
29934
30242
  persistReplJournalEntries();
29935
30243
  }
29936
30244
  renderReplViewIfActive({ force: true });