pi-studio 0.11.10 → 0.11.12
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 +16 -0
- package/README.md +9 -1
- package/ROADMAP.md +2 -2
- package/client/studio-client.js +99 -63
- package/client/studio.css +5 -0
- package/index.ts +42 -4
- package/package.json +1 -1
- package/shared/studio-buffer-client.js +11 -2
- package/shared/studio-copy-url.js +23 -0
- package/shared/studio-url-file.js +88 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,22 @@ All notable changes to `pi-studio` are documented here.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.11.12] — 2026-11-05
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- **Follow** is one switch. On, a run shows Working while Pi works, then the new response; off, Studio leaves the Prompt's right pane alone. Changing that pane's view yourself during a run turns Follow off, and it stays off until you turn it on again, with the button or Cmd/Ctrl+Option/Alt+A. Turned on during a run, it goes back to Working. "Run paused" is gone. **Document preview**, which shows the Document's preview when you select the Document, is now under View. A saved setting with only Working or only the latest response on counts as on.
|
|
11
|
+
- In Working, a step's sections, such as Input and Output, line up under the step's number rather than its triangle, so they read as the step's.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- In Muxy and other WebKit browsers, a response scrolled to its very bottom no longer moves up a little as you type in the Prompt. Studio kept rewriting the footer, the response's buttons and other labels with the same text, which can make WebKit lay the page out again; it now writes a label only when its text changes.
|
|
15
|
+
- In Muxy and other WebKit browsers, flicking a pane to its top no longer flashes a recovery warning ("Invalid scroll position") in the footer and nudges the panes. WebKit reports a negative position while the pane bounces past its top, and saving it failed; Studio now saves it as the top.
|
|
16
|
+
|
|
17
|
+
## [0.11.11] — 2026-11-04
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
- `/studio --copy-url` copies the running Studio's URL, the one `/studio --status` prints, for a terminal too narrow to show it whole. It uses Pi's own clipboard: the system clipboard and, over SSH, your terminal's too (OSC 52), which works if the terminal allows it. Pi can't confirm the terminal took it, so paste to check. It copies only in Pi's terminal interface; in RPC mode the URL is in Studio's notifications.
|
|
21
|
+
- With `PI_STUDIO_URL_FILE` set to an absolute path, Studio writes the last URL it printed for its main view to that file, so a script, an editor or a container can open Studio without anyone copying the URL out of the terminal ([#7](https://github.com/omaclaren/pi-studio/issues/7)). The file is created readable only by you (on Windows, its folder's permissions apply) and replaced whole. When Studio stops, it tries to remove the file, if it still holds Studio's URL. `/studio --status` names it. Nothing is written unless the variable is set; give each Pi process a file of its own. A file Studio can't write, such as one in a missing folder, gives a warning, and Studio starts as usual.
|
|
22
|
+
|
|
7
23
|
## [0.11.10] — 2026-11-03
|
|
8
24
|
|
|
9
25
|
### Changed
|
package/README.md
CHANGED
|
@@ -16,7 +16,9 @@ Zen mode, in rose-pine-dawn:
|
|
|
16
16
|
|
|
17
17
|

|
|
18
18
|
|
|
19
|
-
Watch the [demo](https://github.com/omaclaren/pi-studio/releases/download/demo-
|
|
19
|
+
Watch the [demo](https://github.com/omaclaren/pi-studio/releases/download/demo-studio/pi-studio-demo.mp4) (68s, real time, no audio, automated typing). It shows a prompt and its rendered answer, a linked note and a PDF figure in the Document, and a selection brought into the Prompt for a follow-up.
|
|
20
|
+
|
|
21
|
+
The screenshots and both demos are also on the [project page](https://omaclaren.github.io/pi-studio/).
|
|
20
22
|
|
|
21
23
|
## Features
|
|
22
24
|
|
|
@@ -65,6 +67,7 @@ Or from GitHub, `pi install https://github.com/omaclaren/pi-studio`, or once wit
|
|
|
65
67
|
| `/studio --port <port>` | Use a fixed port |
|
|
66
68
|
| `/studio --listen-all` | Listen on all interfaces, for containers ([see below](#network-and-ssh)) |
|
|
67
69
|
| `/studio --status`, `--stop` | Show the server's status, or stop it |
|
|
70
|
+
| `/studio --copy-url` | Copy the running Studio's URL, for a terminal too narrow to show it whole. Over SSH, Pi also sends it to your terminal's clipboard (OSC 52), which works if the terminal allows it; set `PI_CLIPBOARD_OSC52=1` where Pi can't tell it's remote, as in some tmux sessions |
|
|
68
71
|
| `/studio-replace` | Replace the open Studio view. In dual editor mode, move it to a new tab here |
|
|
69
72
|
| `/studio-editor-only [file]` | Open an extra editor tab (single editor mode) |
|
|
70
73
|
| `/studio-current <file>` | Load a file into the open Studio tab (single editor mode) |
|
|
@@ -138,6 +141,8 @@ Icons in exported PDFs need Mermaid CLI 11.12+ (`npm install -g @mermaid-js/merm
|
|
|
138
141
|
|
|
139
142
|
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. With pi-repl 0.12.1 or later loaded too, pi-repl tells it about its own `pi-repl-*` sessions, also in Studio's tool results, and Studio about the rest, so nothing is told twice. The record format is in [`shared/REPL_SESSION_RECORD_PROTOCOL.md`](./shared/REPL_SESSION_RECORD_PROTOCOL.md).
|
|
140
143
|
|
|
144
|
+
Watch a [short demo](https://github.com/omaclaren/pi-studio/releases/download/demo-repl/pi-studio-repl-demo.mp4) of Pi, Quick send and Claude Code, through [agent-repl](https://github.com/omaclaren/agent-repl), sharing one Python session (50s, real time, no audio, automated typing).
|
|
145
|
+
|
|
141
146
|
### Side questions
|
|
142
147
|
|
|
143
148
|
**Review → Side question**, or Cmd/Ctrl+Option/Alt+Q, opens a separate thread. It starts from the selection, the section at the cursor or the whole text, and can read the document's folder, the repository or another folder you allow, including PDF, DOCX, ODT and EPUB text. Its tools are read-only. With `BRAVE_API_KEY` set, it can also search the web; queries go to Brave Search. Nothing enters the main conversation unless you choose **Bring to main conversation**.
|
|
@@ -148,6 +153,8 @@ Studio listens on `127.0.0.1` only, and every URL carries a token. Over SSH, for
|
|
|
148
153
|
|
|
149
154
|
For a container, `/studio --no-browser --listen-all --port 4321` listens on all interfaces. Anyone with the full URL can control Studio, including running prompts and reading or writing files, and there's no TLS. Treat the URL like a password, never expose the port to the internet, and bind the host side to loopback (`-p 127.0.0.1:4321:4321`). Quarto previews use a second port, which must be forwarded too.
|
|
150
155
|
|
|
156
|
+
For a script, an editor or a container that opens Studio itself, set `PI_STUDIO_URL_FILE` to an absolute path when you start Pi. Studio writes the last URL it printed for its main view to that file, creating it readable only by you, and removes it when Studio stops; `/studio --status` writes it again and names the file. Studio replaces a file already at that path (though not a link or a folder), so use a file of its own, in a private folder that isn't synced, and give each Pi process its own path. The file holds the same credential as the printed URL. If Pi crashes, or Studio can't remove the file, it's left behind, but its token no longer works. On Windows, who can read it follows its folder's permissions.
|
|
157
|
+
|
|
151
158
|
### Environment variables
|
|
152
159
|
|
|
153
160
|
| Variable | Effect |
|
|
@@ -159,6 +166,7 @@ For a container, `/studio --no-browser --listen-all --port 4321` listens on all
|
|
|
159
166
|
| `PI_STUDIO_REPL_ECHO_MODE` | Default pane echo for `studio_repl_send`: `summary` (the default), `off` or `full` |
|
|
160
167
|
| `PI_REPL_USER_NAME` | The name your REPL sends and notes are recorded under, ahead of the name saved with pi-repl |
|
|
161
168
|
| `PI_REPL_RECORD_ACTIVITY` | Whether the agent is told of new REPL record entries: `on` (the default: at a run's start and in REPL tool results), `send` (in results only) or `off`; unset, it follows `PI_REPL_PANE_ACTIVITY` |
|
|
169
|
+
| `PI_STUDIO_URL_FILE` | An absolute path where Studio writes the last URL it printed for its main view, for a program to read ([see above](#network-and-ssh)); a file of its own for each Pi process |
|
|
162
170
|
| `PI_STUDIO_PANDOC_TIMEOUT_MS`, `PI_STUDIO_LATEX_TIMEOUT_MS`, `PI_STUDIO_MERMAID_TIMEOUT_MS` | Export time limits |
|
|
163
171
|
|
|
164
172
|
Installing pi-studio also adds `pi-studio-dark` and `pi-studio-light` to Pi's themes, without changing your current theme.
|
package/ROADMAP.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
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 (
|
|
5
|
+
## Current status (5 Nov 2026)
|
|
6
6
|
|
|
7
|
-
`0.11.
|
|
7
|
+
`0.11.12` is the current release. Studio is in a feature freeze from `0.11.9`, 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. Each release since has been an approved exception. `0.11.10` works with pi-repl `0.12.1` so that, with both loaded, the agent is told each REPL record entry once. `0.11.11` gets Studio's URL out of a terminal too narrow to show it: `/studio --copy-url` copies it, and `PI_STUDIO_URL_FILE` keeps it in a file for programs ([#7](https://github.com/omaclaren/pi-studio/issues/7)). `0.11.12` makes **Follow** one switch, fixes two WebKit scrolling glitches in Muxy, and lines Working's sections up under their step. 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
8
|
|
|
9
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
10
|
|
package/client/studio-client.js
CHANGED
|
@@ -514,11 +514,11 @@
|
|
|
514
514
|
if (!option) return;
|
|
515
515
|
if (option.dataset?.linkedReaderOption === "1") { option.disabled = true; return; }
|
|
516
516
|
const isQuartoOption = option.value === "editor-quarto-preview";
|
|
517
|
-
if (isWatchedFilePreview && option.value === "editor-preview") option
|
|
517
|
+
if (isWatchedFilePreview && option.value === "editor-preview") setTextIfChanged(option, "Watched preview");
|
|
518
518
|
else if (option.value === "editor-preview" || isQuartoOption) {
|
|
519
519
|
const name = bufferSwitchingEnabled ? (isStudioDocumentBufferView() ? "Document" : "Prompt") : (isEditorOnlyMode ? "Document" : "Editor");
|
|
520
520
|
// New layout: "(Quarto)" keeps the picker as wide as "Response (Preview)" (Oliver, 10 Oct).
|
|
521
|
-
option
|
|
521
|
+
setTextIfChanged(option, name + (isQuartoOption ? (bufferSwitchingEnabled ? " (Quarto)" : " (Quarto Preview)") : " (Preview)"));
|
|
522
522
|
}
|
|
523
523
|
if (isQuartoOption) option.hidden = !quartoRelevant;
|
|
524
524
|
option.disabled = (isWatchedFilePreview && option.value !== "editor-preview")
|
|
@@ -1011,20 +1011,20 @@
|
|
|
1011
1011
|
const ui = studioUiRefreshUi;
|
|
1012
1012
|
if (!ui?.runStatus) return;
|
|
1013
1013
|
const text = getStudioRuntimeStatusText(), rightFocused = paneFocusTarget === "right";
|
|
1014
|
-
ui.runStatus
|
|
1015
|
-
ui.headerRunStatus
|
|
1014
|
+
setTextIfChanged(ui.runStatus, text); ui.runStatus.hidden = !text || rightFocused;
|
|
1015
|
+
setTextIfChanged(ui.headerRunStatus, text); ui.headerRunStatus.hidden = !text || !rightFocused;
|
|
1016
1016
|
if (typeof syncPromptRunIndicator === "function") syncPromptRunIndicator();
|
|
1017
1017
|
const run = studioRuntimeActivity?.run, activeKind = getAbortablePendingKind();
|
|
1018
1018
|
const stopping = run && (run.stopping || studioStopRequestedRunId === run.id);
|
|
1019
1019
|
const ownedRun = run?.origin === "studio" && Boolean(run.requestId && run.kind);
|
|
1020
1020
|
ui.headerStop.hidden = isEditorOnlyMode || !rightFocused || (!activeKind && !stopping && !ownedRun);
|
|
1021
|
-
ui.headerStop
|
|
1021
|
+
setTextIfChanged(ui.headerStop, stopping ? "Stopping…" : "Stop");
|
|
1022
1022
|
ui.headerStop.disabled = Boolean(stopping) || !activeKind;
|
|
1023
1023
|
if (run && sendRunBtn) sendRunBtn.classList.toggle("request-pending", false);
|
|
1024
1024
|
if (run && !isEditorOnlyMode && sendRunBtn) {
|
|
1025
1025
|
const owned = run.origin === "studio" && Boolean(run.requestId && run.kind);
|
|
1026
1026
|
if (owned) {
|
|
1027
|
-
sendRunBtn
|
|
1027
|
+
setTextIfChanged(sendRunBtn, stopping ? "Stopping…" : "Stop");
|
|
1028
1028
|
sendRunBtn.disabled = Boolean(stopping) || !activeKind;
|
|
1029
1029
|
sendRunBtn.classList.toggle("request-stop-active", !stopping);
|
|
1030
1030
|
} else sendRunBtn.disabled = true;
|
|
@@ -3698,9 +3698,16 @@
|
|
|
3698
3698
|
return label.trim();
|
|
3699
3699
|
}
|
|
3700
3700
|
|
|
3701
|
+
// Write a label only when its text changes. Rewriting the same text can make WebKit lay out
|
|
3702
|
+
// again, the likely reason a response scrolled to its very bottom moved up a little as the
|
|
3703
|
+
// footer and the response's controls were redrawn while typing (Muxy; Astra's investigation, 5 Nov).
|
|
3704
|
+
function setTextIfChanged(element, text) {
|
|
3705
|
+
if (element && element.textContent !== text) element.textContent = text;
|
|
3706
|
+
}
|
|
3707
|
+
|
|
3701
3708
|
function setStudioUiRefreshButtonText(buttonEl, text) {
|
|
3702
3709
|
if (!buttonEl) return;
|
|
3703
|
-
buttonEl
|
|
3710
|
+
setTextIfChanged(buttonEl, text);
|
|
3704
3711
|
}
|
|
3705
3712
|
|
|
3706
3713
|
function formatStudioFontSizeLabel(size) {
|
|
@@ -3900,7 +3907,7 @@
|
|
|
3900
3907
|
if (!studioUiRefreshUi || !studioUiRefreshUi.reviewButton) return;
|
|
3901
3908
|
const critiqueIsStop = getAbortablePendingKind() === "critique";
|
|
3902
3909
|
const reviewButton = studioUiRefreshUi.reviewButton;
|
|
3903
|
-
reviewButton
|
|
3910
|
+
setTextIfChanged(reviewButton, critiqueIsStop ? "Stop critique" : "Review");
|
|
3904
3911
|
reviewButton.classList.toggle("request-stop-active", critiqueIsStop);
|
|
3905
3912
|
reviewButton.disabled = critiqueIsStop ? Boolean(critiqueBtn && critiqueBtn.disabled) : false;
|
|
3906
3913
|
reviewButton.title = critiqueIsStop
|
|
@@ -3986,16 +3993,15 @@
|
|
|
3986
3993
|
const dirty = Boolean(path && editorDiffersFromFileBackedBaseline());
|
|
3987
3994
|
// Unsaved text is *Untitled* (italic): a placeholder name, not a file (Oliver, 8 Oct).
|
|
3988
3995
|
const name = path ? basenameForStudioPath(path) : "Untitled";
|
|
3989
|
-
button
|
|
3996
|
+
setTextIfChanged(button, name + (dirty ? " •" : ""));
|
|
3990
3997
|
if (path) button.classList?.remove("is-untitled"); else button.classList?.add("is-untitled");
|
|
3991
3998
|
button.title = path ? path + (dirty ? " · unsaved file edits" : "") + " · File details" : "Not saved to a file · Save As…";
|
|
3992
3999
|
if (studioUiRefreshUi.pathDetails) {
|
|
3993
|
-
studioUiRefreshUi.pathDetails.textContent = path
|
|
3994
|
-
? path + (fileBackedBaselineText === null ? " · File baseline unavailable; disk not rechecked." : (dirty ? " · Unsaved file edits." : " · No edits since loading or saving; disk not rechecked."))
|
|
3995
|
-
: "Not saved to a file.";
|
|
3996
4000
|
const provenance = editorDraftHelpers.normalizeSourceProvenance(sourceState?.provenance);
|
|
3997
4001
|
const summary = editorDraftHelpers.describeSourceProvenance(provenance);
|
|
3998
|
-
|
|
4002
|
+
setTextIfChanged(studioUiRefreshUi.pathDetails, (path
|
|
4003
|
+
? path + (fileBackedBaselineText === null ? " · File baseline unavailable; disk not rechecked." : (dirty ? " · Unsaved file edits." : " · No edits since loading or saving; disk not rechecked."))
|
|
4004
|
+
: "Not saved to a file.") + (summary ? " · " + summary : ""));
|
|
3999
4005
|
studioUiRefreshUi.pathDetails.title = provenance
|
|
4000
4006
|
? ("Response position when loaded: " + (provenance.responseNumber ?? "unavailable") + "\nResponse identity: " + (provenance.responseId ?? "unavailable") + "\nSource information only; not a saved-file receipt.") : "";
|
|
4001
4007
|
}
|
|
@@ -4203,13 +4209,17 @@
|
|
|
4203
4209
|
rightViewMenu = makeStudioUiRefreshMenu(makeStudioUiRefreshElement("button", "", "View"), "right-view", "studio-refresh-right-view-anchor");
|
|
4204
4210
|
appendStudioUiRefreshMenuSection(rightViewMenu.menu, "Display", [responseHighlightSelect, responseFontSizeSelect]);
|
|
4205
4211
|
if (bufferSwitchingEnabled && !isEditorOnlyMode && !isWatchedFilePreview) {
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4212
|
+
// One Follow switch (Oliver, 5 Nov). It sets Working and the latest response together; their
|
|
4213
|
+
// selects stay, hidden, for their state. The Document preview's own switch is under View.
|
|
4214
|
+
followMenu = makeStudioUiRefreshElement("button", "studio-refresh-chip studio-follow-button", "Follow: on");
|
|
4215
|
+
followMenu.type = "button";
|
|
4216
|
+
followMenu.setAttribute("aria-keyshortcuts", "Meta+Alt+A Control+Alt+A");
|
|
4217
|
+
followMenu.addEventListener("click", () => setStudioFollowEnabled(!isStudioFollowEnabled()));
|
|
4218
|
+
const followSettingsEl = makeStudioUiRefreshElement("span", "studio-follow-settings");
|
|
4219
|
+
followSettingsEl.hidden = true;
|
|
4220
|
+
for (const control of [activityTrackingSelect, followSelect]) if (control) followSettingsEl.appendChild(control);
|
|
4221
|
+
followMenu = { button: followMenu, anchor: makeStudioUiRefreshElement("span", "studio-refresh-menu-anchor studio-refresh-follow-anchor") };
|
|
4222
|
+
followMenu.anchor.append(followMenu.button, followSettingsEl);
|
|
4213
4223
|
} else if (!isEditorOnlyMode && !isWatchedFilePreview) appendStudioUiRefreshMenuSection(rightViewMenu.menu, "Response updates", [followSelect]);
|
|
4214
4224
|
rightToolsEl.append(headerRunStatus, headerStop);
|
|
4215
4225
|
if (followMenu) rightToolsEl.appendChild(followMenu.anchor);
|
|
@@ -4267,7 +4277,7 @@
|
|
|
4267
4277
|
if (activityTrackingSelect) activityTrackingSelect.hidden = isEditorOnlyMode || isWatchedFilePreview;
|
|
4268
4278
|
appendStudioUiRefreshMenuSection(viewMenu.menu, "Workspace", [studioPaneLayoutSelect,
|
|
4269
4279
|
(isEditorOnlyMode || isWatchedFilePreview || followMenu) ? null : activityTrackingSelect,
|
|
4270
|
-
|
|
4280
|
+
bufferSwitchingEnabled ? documentPreviewFollowSelect : null]);
|
|
4271
4281
|
appendStudioUiRefreshMenuSection(viewMenu.menu, "Annotations", [annotationModeSelect, insertHeaderBtn, stripAnnotationsBtn, saveAnnotatedBtn]);
|
|
4272
4282
|
// View sits after File in row 1, as the right pane's View sits in its header, so row 2 fits narrower panes (Oliver, 27 Oct).
|
|
4273
4283
|
headerToolsEl.appendChild(viewMenu.anchor);
|
|
@@ -4292,7 +4302,6 @@
|
|
|
4292
4302
|
reviewButton: reviewMenu ? reviewMenu.button : null,
|
|
4293
4303
|
menus: [viewMenu, openMenu]
|
|
4294
4304
|
.concat(rightViewMenu ? [rightViewMenu] : [])
|
|
4295
|
-
.concat(followMenu ? [followMenu] : [])
|
|
4296
4305
|
.concat(responseMenu ? [responseMenu] : [])
|
|
4297
4306
|
.concat(contextMenu ? [contextMenu] : [])
|
|
4298
4307
|
.concat(reviewMenu ? [reviewMenu] : []),
|
|
@@ -5115,9 +5124,9 @@
|
|
|
5115
5124
|
const text = modelText + " · " + terminalText + " · " + contextDisplayText;
|
|
5116
5125
|
const titleText = "Model: " + modelText + " · " + terminalDetailText + " · " + contextTitleText;
|
|
5117
5126
|
if (footerMetaModelEl && footerMetaTerminalEl && footerMetaContextEl) {
|
|
5118
|
-
footerMetaModelEl
|
|
5119
|
-
footerMetaTerminalEl
|
|
5120
|
-
footerMetaContextEl
|
|
5127
|
+
setTextIfChanged(footerMetaModelEl, modelText);
|
|
5128
|
+
setTextIfChanged(footerMetaTerminalEl, terminalText);
|
|
5129
|
+
setTextIfChanged(footerMetaContextEl, contextDisplayText);
|
|
5121
5130
|
footerMetaModelEl.title = "Pi model and thinking: " + modelText;
|
|
5122
5131
|
footerMetaModelEl.setAttribute("aria-haspopup", "menu");
|
|
5123
5132
|
footerMetaModelEl.setAttribute("aria-expanded", footerModelMenuOpen ? "true" : "false");
|
|
@@ -5126,10 +5135,10 @@
|
|
|
5126
5135
|
if (footerMetaTextEl) footerMetaTextEl.title = titleText;
|
|
5127
5136
|
if (footerMetaEl) footerMetaEl.title = titleText;
|
|
5128
5137
|
} else if (footerMetaTextEl) {
|
|
5129
|
-
footerMetaTextEl
|
|
5138
|
+
setTextIfChanged(footerMetaTextEl, text);
|
|
5130
5139
|
footerMetaTextEl.title = titleText;
|
|
5131
5140
|
} else if (footerMetaEl) {
|
|
5132
|
-
footerMetaEl
|
|
5141
|
+
setTextIfChanged(footerMetaEl, text);
|
|
5133
5142
|
footerMetaEl.title = titleText;
|
|
5134
5143
|
}
|
|
5135
5144
|
updateDocumentTitle();
|
|
@@ -5330,10 +5339,11 @@
|
|
|
5330
5339
|
// confirmation; retain a fallback if notice rendering is unavailable.
|
|
5331
5340
|
const operationInNotice = operation && studioOperationNoticesEl?.isConnected && !studioOperationNoticesEl.hidden;
|
|
5332
5341
|
const recoveryIssue = getStudioShownRecoveryIssue();
|
|
5333
|
-
statusEl
|
|
5342
|
+
setTextIfChanged(statusEl, recoveryIssue
|
|
5334
5343
|
? "Recovery: " + recoveryIssue + (bufferRecoveryKeptClosed ? "" : " Save or copy your text before reloading. " + (operationInNotice ? "" : (operation?.message || statusMessage)))
|
|
5335
|
-
: operationInNotice ? "" : operation?.message || statusMessage;
|
|
5336
|
-
|
|
5344
|
+
: operationInNotice ? "" : operation?.message || statusMessage);
|
|
5345
|
+
const statusClass = recoveryIssue ? "warning" : operationInNotice ? "" : operation?.severity || (statusLevel || "");
|
|
5346
|
+
if (statusEl.className !== statusClass) statusEl.className = statusClass;
|
|
5337
5347
|
statusEl.title = recoveryIssue || (!operationInNotice && operation?.message) || "";
|
|
5338
5348
|
if (typeof syncStudioPromptAddUndo === "function") syncStudioPromptAddUndo();
|
|
5339
5349
|
|
|
@@ -5342,9 +5352,9 @@
|
|
|
5342
5352
|
statusLineEl.classList.toggle("with-spinner", spinnerActive);
|
|
5343
5353
|
}
|
|
5344
5354
|
if (statusSpinnerEl) {
|
|
5345
|
-
statusSpinnerEl
|
|
5355
|
+
setTextIfChanged(statusSpinnerEl, spinnerActive
|
|
5346
5356
|
? (BRAILLE_SPINNER_FRAMES[spinnerFrameIndex % BRAILLE_SPINNER_FRAMES.length] || "")
|
|
5347
|
-
: "";
|
|
5357
|
+
: "");
|
|
5348
5358
|
}
|
|
5349
5359
|
|
|
5350
5360
|
updateFooterMeta();
|
|
@@ -5948,16 +5958,32 @@
|
|
|
5948
5958
|
return false;
|
|
5949
5959
|
}
|
|
5950
5960
|
|
|
5961
|
+
// Changing the Prompt's right-pane view yourself during a run turns Follow off, and it stays off
|
|
5962
|
+
// until you turn it on again (Oliver, 5 Nov). The view you chose stays. The classic layout has no
|
|
5963
|
+
// Follow switch, so there the run is paused, as before, and the next run follows again (Astra, candidate 120).
|
|
5951
5964
|
function pauseStudioRunFollowing() {
|
|
5952
5965
|
if (!studioRunFollowingAvailable() || !studioRunFollowing?.active) return;
|
|
5953
|
-
studioRunFollowing.paused = true;
|
|
5954
5966
|
// Hidden Prompt must also lose its temporary Working override. Never
|
|
5955
5967
|
// navigate the currently visible Document on the way out.
|
|
5956
5968
|
const target = getStudioPromptRunView();
|
|
5957
5969
|
relinquishStudioRunWorking(!target?.selected);
|
|
5970
|
+
if (!studioUiRefreshUi?.followButton) studioRunFollowing.paused = true;
|
|
5971
|
+
else if (isStudioFollowEnabled()) setStudioFollowEnabled(false);
|
|
5958
5972
|
syncStudioFollowMenu();
|
|
5959
5973
|
}
|
|
5960
5974
|
|
|
5975
|
+
// One Follow switch in the full workspace (Oliver, 5 Nov): on, a run shows Working and then its
|
|
5976
|
+
// response; off, Studio leaves the Prompt's right pane alone. Turned on during a run, it goes
|
|
5977
|
+
// back to Working. Working is set first, so it takes the pane before the latest response could.
|
|
5978
|
+
function isStudioFollowEnabled() {
|
|
5979
|
+
return activityTrackingEnabled || latestResponseFollowingEnabled !== false;
|
|
5980
|
+
}
|
|
5981
|
+
|
|
5982
|
+
function setStudioFollowEnabled(enabled) {
|
|
5983
|
+
setActivityTrackingEnabled(enabled);
|
|
5984
|
+
setLatestResponseFollowingEnabled(enabled);
|
|
5985
|
+
}
|
|
5986
|
+
|
|
5961
5987
|
function acquireStudioRunWorking() {
|
|
5962
5988
|
const state = studioRunFollowing;
|
|
5963
5989
|
if (!state?.active || state.paused || state.working || !activityTrackingEnabled) return false;
|
|
@@ -6025,9 +6051,12 @@
|
|
|
6025
6051
|
|
|
6026
6052
|
function syncStudioFollowMenu() {
|
|
6027
6053
|
if (!studioUiRefreshUi?.followButton) return;
|
|
6028
|
-
const enabled =
|
|
6029
|
-
setStudioUiRefreshButtonText(
|
|
6030
|
-
|
|
6054
|
+
const enabled = isStudioFollowEnabled(), button = studioUiRefreshUi.followButton;
|
|
6055
|
+
setStudioUiRefreshButtonText(button, "Follow: " + (enabled ? "on" : "off"));
|
|
6056
|
+
button.setAttribute?.("aria-pressed", enabled ? "true" : "false");
|
|
6057
|
+
button.title = enabled
|
|
6058
|
+
? "While Pi runs, this pane shows Working, then the new response. Changing the view yourself turns this off. Click to turn off (Cmd/Ctrl+Option/Alt+A)."
|
|
6059
|
+
: "Studio leaves this pane alone. Click to turn on; during a run, it goes back to Working (Cmd/Ctrl+Option/Alt+A).";
|
|
6031
6060
|
if (activityTrackingSelect) activityTrackingSelect.value = activityTrackingEnabled ? "on" : "off";
|
|
6032
6061
|
if (followSelect) followSelect.value = latestResponseFollowingEnabled === false ? "off" : "on";
|
|
6033
6062
|
if (documentPreviewFollowSelect) documentPreviewFollowSelect.value = documentPreviewFollowingEnabled ? "on" : "off";
|
|
@@ -6652,7 +6681,8 @@
|
|
|
6652
6681
|
setStatus("Follow activity is available only in the main editable Studio workspace.", "warning");
|
|
6653
6682
|
return false;
|
|
6654
6683
|
}
|
|
6655
|
-
|
|
6684
|
+
if (studioUiRefreshUi?.followButton) setStudioFollowEnabled(!isStudioFollowEnabled());
|
|
6685
|
+
else setActivityTrackingEnabled(!activityTrackingEnabled);
|
|
6656
6686
|
return true;
|
|
6657
6687
|
}
|
|
6658
6688
|
|
|
@@ -7473,7 +7503,7 @@
|
|
|
7473
7503
|
? responseHistoryIndex + 1
|
|
7474
7504
|
: 0;
|
|
7475
7505
|
if (historyIndexBadgeEl) {
|
|
7476
|
-
historyIndexBadgeEl
|
|
7506
|
+
setTextIfChanged(historyIndexBadgeEl, "Branch history: " + selected + "/" + total);
|
|
7477
7507
|
}
|
|
7478
7508
|
if (historyPrevBtn) {
|
|
7479
7509
|
historyPrevBtn.disabled = total <= 1 || responseHistoryIndex <= 0;
|
|
@@ -7489,12 +7519,12 @@
|
|
|
7489
7519
|
const hasPrompt = Boolean(selectedItem && typeof selectedItem.prompt === "string" && selectedItem.prompt.trim());
|
|
7490
7520
|
if (loadHistoryPromptBtn) {
|
|
7491
7521
|
loadHistoryPromptBtn.disabled = uiBusy || responseReplacementPending || !hasPrompt || (bufferSwitchingEnabled && isStudioDocumentBufferView());
|
|
7492
|
-
loadHistoryPromptBtn
|
|
7522
|
+
setTextIfChanged(loadHistoryPromptBtn, getHistoryPromptButtonLabel(selectedItem));
|
|
7493
7523
|
loadHistoryPromptBtn.title = getHistoryPromptButtonTitle(selectedItem);
|
|
7494
7524
|
}
|
|
7495
7525
|
if (copyResponsePromptBtn) {
|
|
7496
7526
|
copyResponsePromptBtn.disabled = uiBusy || !hasPrompt;
|
|
7497
|
-
copyResponsePromptBtn
|
|
7527
|
+
setTextIfChanged(copyResponsePromptBtn, hasPrompt ? "Copy response prompt" : "Copy response prompt (unavailable)");
|
|
7498
7528
|
copyResponsePromptBtn.title = getHistoryPromptCopyTitle(selectedItem);
|
|
7499
7529
|
}
|
|
7500
7530
|
syncShowMeButton();
|
|
@@ -17183,23 +17213,23 @@
|
|
|
17183
17213
|
loadCritiqueFullBtn.hidden = !isCritiqueResponse;
|
|
17184
17214
|
|
|
17185
17215
|
loadResponseBtn.disabled = uiBusy || !hasResponse || responseLoaded || isCritiqueResponse || (bufferSwitchingEnabled && isStudioDocumentBufferView());
|
|
17186
|
-
loadResponseBtn
|
|
17216
|
+
setTextIfChanged(loadResponseBtn, responseLoaded ? "Response already in editor" : "Load response");
|
|
17187
17217
|
|
|
17188
17218
|
const annotationWorkspaceReady = responseLoaded
|
|
17189
17219
|
&& editorView === "markdown"
|
|
17190
17220
|
&& rightView === "editor-preview"
|
|
17191
17221
|
&& paneFocusTarget === "off";
|
|
17192
17222
|
annotateResponseBtn.disabled = uiBusy || !hasResponse || isCritiqueResponse || annotationWorkspaceReady || (bufferSwitchingEnabled && isStudioDocumentBufferView());
|
|
17193
|
-
annotateResponseBtn
|
|
17223
|
+
setTextIfChanged(annotateResponseBtn, annotationWorkspaceReady ? "Response ready to annotate" : "Annotate response");
|
|
17194
17224
|
annotateResponseBtn.title = annotationWorkspaceReady
|
|
17195
17225
|
? "The selected response is exactly in the raw editor with Editor Preview open."
|
|
17196
17226
|
: "Load the selected response into the raw editor and show Editor Preview. Ask before replacing unsubmitted or unsaved work. Shortcut: Cmd/Ctrl+Option/Alt+Enter.";
|
|
17197
17227
|
|
|
17198
17228
|
loadCritiqueNotesBtn.disabled = uiBusy || !isCritiqueResponse || !critiqueNotes || critiqueNotesLoaded || (bufferSwitchingEnabled && isStudioDocumentBufferView());
|
|
17199
|
-
loadCritiqueNotesBtn
|
|
17229
|
+
setTextIfChanged(loadCritiqueNotesBtn, critiqueNotesLoaded ? "Critique notes already in editor" : "Load critique notes into editor");
|
|
17200
17230
|
|
|
17201
17231
|
loadCritiqueFullBtn.disabled = uiBusy || !isCritiqueResponse || responseLoaded || (bufferSwitchingEnabled && isStudioDocumentBufferView());
|
|
17202
|
-
loadCritiqueFullBtn
|
|
17232
|
+
setTextIfChanged(loadCritiqueFullBtn, responseLoaded ? "Full critique already in editor" : "Load full critique into editor");
|
|
17203
17233
|
|
|
17204
17234
|
// The Document can show responses, but they load or annotate into the Prompt only (Sol, 8 Oct).
|
|
17205
17235
|
const documentView = bufferSwitchingEnabled && isStudioDocumentBufferView();
|
|
@@ -17210,7 +17240,7 @@
|
|
|
17210
17240
|
if (documentView) annotateResponseBtn.title = "Return to Prompt to load or annotate this response.";
|
|
17211
17241
|
|
|
17212
17242
|
copyResponseBtn.disabled = uiBusy || !hasResponse;
|
|
17213
|
-
copyResponseBtn
|
|
17243
|
+
setTextIfChanged(copyResponseBtn, "Copy response");
|
|
17214
17244
|
|
|
17215
17245
|
const rightPaneShowsPreview = rightView === "preview" || rightView === "editor-preview";
|
|
17216
17246
|
const exportingReplJournal = rightView === "repl";
|
|
@@ -17249,11 +17279,11 @@
|
|
|
17249
17279
|
}
|
|
17250
17280
|
if (exportPdfBtn) {
|
|
17251
17281
|
exportPdfBtn.disabled = exportBusy || !canExportPreview;
|
|
17252
|
-
exportPdfBtn
|
|
17282
|
+
setTextIfChanged(exportPdfBtn, previewExportInProgress
|
|
17253
17283
|
? "Exporting…"
|
|
17254
17284
|
: (sideQuestionMarkdownExportRequest
|
|
17255
17285
|
? "Saving…"
|
|
17256
|
-
: (exportingSideThread ? "Export thread" : (exportingReplJournal ? "Export record" : "Export right preview")));
|
|
17286
|
+
: (exportingSideThread ? "Export thread" : (exportingReplJournal ? "Export record" : "Export right preview"))));
|
|
17257
17287
|
if (rightView === "trace") {
|
|
17258
17288
|
exportPdfBtn.title = "Working view does not support preview export.";
|
|
17259
17289
|
} else if (rightView === "files") {
|
|
@@ -17283,7 +17313,7 @@
|
|
|
17283
17313
|
if (exportSideThreadRenderSeparatorEl) exportSideThreadRenderSeparatorEl.hidden = !exportingSideThread;
|
|
17284
17314
|
if (exportPreviewPdfStudioBtn) {
|
|
17285
17315
|
exportPreviewPdfStudioBtn.disabled = exportBusy || !canExportPreview || isHtmlArtifactPreview || sideThreadRenderTooLarge;
|
|
17286
|
-
exportPreviewPdfStudioBtn
|
|
17316
|
+
setTextIfChanged(exportPreviewPdfStudioBtn, documentHostingEnabled ? "Export PDF and open in browser" : "Export PDF and Open in Studio");
|
|
17287
17317
|
exportPreviewPdfStudioBtn.title = documentHostingEnabled && canExportPreview && !isHtmlArtifactPreview && !sideThreadRenderTooLarge
|
|
17288
17318
|
? "Export as PDF and open it in the browser's PDF viewer."
|
|
17289
17319
|
: sideThreadRenderTooLarge
|
|
@@ -17295,8 +17325,8 @@
|
|
|
17295
17325
|
if (exportPreviewPdfBtn) {
|
|
17296
17326
|
exportPreviewPdfBtn.disabled = exportBusy || !canExportPreview || isHtmlArtifactPreview || sideThreadRenderTooLarge;
|
|
17297
17327
|
// Trial48 finding 7: the same choices, in the same words, for PDF and HTML.
|
|
17298
|
-
if (documentHostingEnabled) exportPreviewPdfBtn
|
|
17299
|
-
if (documentHostingEnabled && exportPreviewHtmlBtn) exportPreviewHtmlBtn
|
|
17328
|
+
if (documentHostingEnabled) setTextIfChanged(exportPreviewPdfBtn, "Export PDF and open in system viewer");
|
|
17329
|
+
if (documentHostingEnabled && exportPreviewHtmlBtn) setTextIfChanged(exportPreviewHtmlBtn, "Export HTML and open in browser");
|
|
17300
17330
|
exportPreviewPdfBtn.title = sideThreadRenderTooLarge
|
|
17301
17331
|
? "This transcript is too large for rendered export; save or copy the Markdown instead."
|
|
17302
17332
|
: (isHtmlArtifactPreview
|
|
@@ -17305,7 +17335,7 @@
|
|
|
17305
17335
|
}
|
|
17306
17336
|
if (exportPreviewHtmlStudioBtn) {
|
|
17307
17337
|
exportPreviewHtmlStudioBtn.disabled = exportBusy || !canExportPreview || sideThreadRenderTooLarge;
|
|
17308
|
-
exportPreviewHtmlStudioBtn
|
|
17338
|
+
setTextIfChanged(exportPreviewHtmlStudioBtn, documentHostingEnabled ? "Export HTML and open in Document" : "Export HTML and Open in Studio");
|
|
17309
17339
|
exportPreviewHtmlStudioBtn.title = documentHostingEnabled
|
|
17310
17340
|
? "Export as HTML and open it as a Document. Existing files are never overwritten."
|
|
17311
17341
|
: sideThreadRenderTooLarge
|
|
@@ -17339,7 +17369,7 @@
|
|
|
17339
17369
|
}
|
|
17340
17370
|
|
|
17341
17371
|
pullLatestBtn.disabled = uiBusy || followLatest;
|
|
17342
|
-
pullLatestBtn
|
|
17372
|
+
setTextIfChanged(pullLatestBtn, queuedLatestResponse ? "Fetch latest response *" : "Fetch latest response");
|
|
17343
17373
|
|
|
17344
17374
|
updateSyncBadge(normalizedEditor);
|
|
17345
17375
|
syncStudioQuartoDirtyUi();
|
|
@@ -17583,7 +17613,7 @@
|
|
|
17583
17613
|
const hasSuggestionForCurrentText = Boolean(completionSuggestionState && sourceTextEl && sourceTextEl.value === completionSuggestionState.baseText);
|
|
17584
17614
|
const editorEmpty = !String(sourceTextEl.value || "").trim();
|
|
17585
17615
|
suggestCompletionBtn.disabled = isWatchedFilePreview || wsState !== "Ready" || (!completionSuggestionInFlight && (uiBusy || (editorEmpty && !isNextPromptEditor())));
|
|
17586
|
-
suggestCompletionBtn
|
|
17616
|
+
setTextIfChanged(suggestCompletionBtn, completionSuggestionInFlight ? "Stop" : (hasSuggestionForCurrentText ? "Try another" : "Suggest"));
|
|
17587
17617
|
suggestCompletionBtn.title = completionSuggestionInFlight
|
|
17588
17618
|
? "Stop the current suggestion request."
|
|
17589
17619
|
: (hasSuggestionForCurrentText
|
|
@@ -17593,7 +17623,7 @@
|
|
|
17593
17623
|
: "Ask for a short completion at the editor cursor. Shortcut: Option/Alt+Tab where available, or Cmd/Ctrl+Shift+Space from the editor."));
|
|
17594
17624
|
if (footerSuggestBtn) {
|
|
17595
17625
|
footerSuggestBtn.disabled = suggestCompletionBtn.disabled;
|
|
17596
|
-
footerSuggestBtn
|
|
17626
|
+
setTextIfChanged(footerSuggestBtn, suggestCompletionBtn.textContent);
|
|
17597
17627
|
footerSuggestBtn.title = suggestCompletionBtn.title;
|
|
17598
17628
|
}
|
|
17599
17629
|
}
|
|
@@ -19947,7 +19977,7 @@
|
|
|
19947
19977
|
function syncCompletionSuggestionContextUi() {
|
|
19948
19978
|
syncCompletionSuggestionModelUi();
|
|
19949
19979
|
if (suggestCompletionOptionsBtn) {
|
|
19950
|
-
suggestCompletionOptionsBtn
|
|
19980
|
+
setTextIfChanged(suggestCompletionOptionsBtn, studioUiRefreshUi?.fileButton ? "File" : "Source & context");
|
|
19951
19981
|
suggestCompletionOptionsBtn.title = studioUiRefreshUi?.fileButton ? (studioUiRefreshUi.reviewButton ? "File actions, details and workspace recovery. Suggestion settings are under Review." : "File actions, details, workspace recovery and suggestion settings.") : "Document source, working directory, status, and suggestion settings.";
|
|
19952
19982
|
suggestCompletionOptionsBtn.setAttribute("aria-label", studioUiRefreshUi?.fileButton ? "File" : suggestCompletionOptionsBtn.title);
|
|
19953
19983
|
}
|
|
@@ -28802,7 +28832,7 @@
|
|
|
28802
28832
|
|
|
28803
28833
|
if (isEditorOnlyMode) {
|
|
28804
28834
|
if (sendRunBtn) {
|
|
28805
|
-
sendRunBtn
|
|
28835
|
+
setTextIfChanged(sendRunBtn, "Run editor text");
|
|
28806
28836
|
sendRunBtn.classList.remove("request-stop-active", "repl-secondary-action");
|
|
28807
28837
|
sendRunBtn.disabled = true;
|
|
28808
28838
|
sendRunBtn.title = "Run is unavailable in editor-only mode.";
|
|
@@ -28818,7 +28848,7 @@
|
|
|
28818
28848
|
sendReplBtn.hidden = !showReplSend;
|
|
28819
28849
|
sendReplBtn.disabled = !showReplSend || wsState === "Disconnected" || uiBusy || replBusy || !hasReplSession;
|
|
28820
28850
|
sendReplBtn.classList.toggle("repl-primary-action", showReplSend);
|
|
28821
|
-
sendReplBtn
|
|
28851
|
+
setTextIfChanged(sendReplBtn, showReplSend ? withStudioShortcutLabel(replSendMode === "literate" ? "Send selection/chunks" : "Send to REPL", "repl-send") : "Send to REPL");
|
|
28822
28852
|
sendReplBtn.title = hasReplSession
|
|
28823
28853
|
? (replSendMode === "literate"
|
|
28824
28854
|
? "Literate send: selection, current fenced code chunk, or all matching chunks if the cursor is outside a chunk. Shortcut: " + replSendShortcut + "."
|
|
@@ -28837,7 +28867,7 @@
|
|
|
28837
28867
|
}
|
|
28838
28868
|
syncReplEchoModeSelect(showReplSend);
|
|
28839
28869
|
if (critiqueBtn) {
|
|
28840
|
-
critiqueBtn
|
|
28870
|
+
setTextIfChanged(critiqueBtn, "Critique text");
|
|
28841
28871
|
critiqueBtn.classList.remove("request-stop-active");
|
|
28842
28872
|
critiqueBtn.disabled = true;
|
|
28843
28873
|
critiqueBtn.title = "Critique is unavailable in editor-only mode.";
|
|
@@ -28852,7 +28882,7 @@
|
|
|
28852
28882
|
}
|
|
28853
28883
|
|
|
28854
28884
|
if (sendRunBtn) {
|
|
28855
|
-
sendRunBtn
|
|
28885
|
+
setTextIfChanged(sendRunBtn, directIsStop ? "Stop" : (documentView ? "Return to Prompt" : (bufferSwitchingEnabled ? "Run Prompt" : (rightView === "repl" ? withStudioShortcutLabel("Run editor text", "run") : "Run editor text"))));
|
|
28856
28886
|
// The new-layout Document has the Prompt tab just above, so no Return to Prompt here (Oliver, 10 Oct).
|
|
28857
28887
|
sendRunBtn.hidden = workspaceLayout && documentView && !directIsStop;
|
|
28858
28888
|
sendRunBtn.classList.toggle("request-stop-active", directIsStop);
|
|
@@ -28891,7 +28921,7 @@
|
|
|
28891
28921
|
sendReplBtn.hidden = !showReplSend;
|
|
28892
28922
|
sendReplBtn.disabled = !showReplSend || wsState === "Disconnected" || uiBusy || replBusy || !hasReplSession;
|
|
28893
28923
|
sendReplBtn.classList.toggle("repl-primary-action", showReplSend && !workspaceLayout);
|
|
28894
|
-
sendReplBtn
|
|
28924
|
+
setTextIfChanged(sendReplBtn, showReplSend ? (workspaceLayout ? studioReplSendLabel() : withStudioShortcutLabel(replSendMode === "literate" ? "Send selection/chunks" : "Send to REPL", "repl-send")) : "Send to REPL");
|
|
28895
28925
|
sendReplBtn.title = hasReplSession
|
|
28896
28926
|
? (workspaceLayout
|
|
28897
28927
|
? (replSendMode === "literate"
|
|
@@ -28915,7 +28945,7 @@
|
|
|
28915
28945
|
syncReplEchoModeSelect(rightView === "repl");
|
|
28916
28946
|
|
|
28917
28947
|
if (critiqueBtn) {
|
|
28918
|
-
critiqueBtn
|
|
28948
|
+
setTextIfChanged(critiqueBtn, critiqueIsStop ? "Stop" : "Critique text");
|
|
28919
28949
|
critiqueBtn.classList.toggle("request-stop-active", critiqueIsStop);
|
|
28920
28950
|
critiqueBtn.disabled = critiqueIsStop ? wsState === "Disconnected" : (uiBusy || canQueueSteering);
|
|
28921
28951
|
critiqueBtn.title = critiqueIsStop
|
|
@@ -28927,7 +28957,7 @@
|
|
|
28927
28957
|
: "Critique text with [an: ...] markers stripped."));
|
|
28928
28958
|
}
|
|
28929
28959
|
if (quizBtn) {
|
|
28930
|
-
quizBtn
|
|
28960
|
+
setTextIfChanged(quizBtn, hasResumableQuiz() ? "Resume quiz" : "Quiz me");
|
|
28931
28961
|
quizBtn.disabled = wsState === "Disconnected" || uiBusy || canQueueSteering;
|
|
28932
28962
|
quizBtn.title = canQueueSteering
|
|
28933
28963
|
? "Quiz is unavailable while Run editor text is active."
|
|
@@ -30985,7 +31015,7 @@
|
|
|
30985
31015
|
if (!editorModeBtn) return;
|
|
30986
31016
|
editorModeBtn.hidden = !studioEditorModeSwitchable;
|
|
30987
31017
|
if (!studioEditorModeSwitchable) return;
|
|
30988
|
-
editorModeBtn
|
|
31018
|
+
setTextIfChanged(editorModeBtn, studioEditorMode === "dual" ? "Switch to single editor" : "Switch to dual editor");
|
|
30989
31019
|
const wait = studioEditorModeAttempt ? "Switching…" : studioEditorModeSwitchWaitReason();
|
|
30990
31020
|
editorModeBtn.disabled = Boolean(wait);
|
|
30991
31021
|
editorModeBtn.title = wait || (studioEditorMode === "dual" ? "Use one editor, as in earlier Studio. Studio restarts and reopens here."
|
|
@@ -33421,6 +33451,12 @@
|
|
|
33421
33451
|
if (getDocumentPreviewFollowOwner()) restoreDocumentFollowScroll(documentPreviewFollowScrolls.get(restoredFollowBuffer.id) ?? 0);
|
|
33422
33452
|
renderSourcePreview();
|
|
33423
33453
|
workspacePersistenceReady = true;
|
|
33454
|
+
// Follow is one switch now (Oliver, 5 Nov): a saved setting from the three-switch menu with only
|
|
33455
|
+
// Working or only the latest response on counts as on.
|
|
33456
|
+
if (studioUiRefreshUi?.followButton) {
|
|
33457
|
+
ensureLatestResponseFollowingPreference();
|
|
33458
|
+
if (activityTrackingEnabled !== (latestResponseFollowingEnabled !== false)) setStudioFollowEnabled(true);
|
|
33459
|
+
}
|
|
33424
33460
|
initializePromptRunIndicator();
|
|
33425
33461
|
syncStudioRunFollowingFromMessage({ type: "initialization" });
|
|
33426
33462
|
// Hosting connects before recovery initialization; no later socket-ready
|
package/client/studio.css
CHANGED
|
@@ -7755,6 +7755,8 @@
|
|
|
7755
7755
|
body.studio-ui-refresh #rightSectionHeader .studio-follow-button:focus-visible {
|
|
7756
7756
|
outline: none; text-decoration: underline; text-underline-offset: 3px;
|
|
7757
7757
|
}
|
|
7758
|
+
/* Follow is a switch, not a menu (Oliver, 5 Nov): no menu caret. */
|
|
7759
|
+
body.studio-ui-refresh #rightSectionHeader .studio-follow-button::after { content: none; }
|
|
7758
7760
|
.studio-operation-notices { padding: 4px 12px; font-size: 12px; color: var(--warn); }
|
|
7759
7761
|
.studio-operation-notice { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 3px 0; overflow-wrap: anywhere; }
|
|
7760
7762
|
.studio-operation-notice button { font-size: 12px; padding: 1px 4px; }
|
|
@@ -7906,6 +7908,9 @@
|
|
|
7906
7908
|
body.studio-workspace-layout details.trace-step { border-color: var(--panel-border); background: var(--panel); box-shadow: none; }
|
|
7907
7909
|
body.studio-workspace-layout details.trace-step > summary.trace-card-header { padding: 9px 14px; }
|
|
7908
7910
|
body.studio-workspace-layout details.trace-step > .trace-step-body { gap: 4px; border-top: 1px solid var(--panel-border); padding: 8px 14px 10px; }
|
|
7911
|
+
/* Oliver, 5 Nov: a step's sections line up under its number, not its triangle, so they read as the step's:
|
|
7912
|
+
the line's padding, then the triangle (1em at 9px) and the line's gap. */
|
|
7913
|
+
body.studio-workspace-layout details.trace-step > .trace-step-body { padding-left: calc(14px + 9px + 7px); }
|
|
7909
7914
|
body.studio-workspace-layout .trace-step .trace-output-wrap,
|
|
7910
7915
|
body.studio-workspace-layout .trace-step .trace-output,
|
|
7911
7916
|
body.studio-workspace-layout .trace-step .trace-tool-fields,
|
package/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentSession, AgentSessionEvent, AgentSessionRuntime, CreateAgentSessionRuntimeFactory, ExtensionAPI, ExtensionCommandContext, ExtensionContext, ResourceLoader, SessionEntry, Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { buildSessionContext, createAgentSession, createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, createExtensionRuntime, defineTool, getAgentDir, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import { buildSessionContext, copyToClipboard, createAgentSession, createAgentSessionFromServices, createAgentSessionRuntime, createAgentSessionServices, createExtensionRuntime, defineTool, getAgentDir, SessionManager } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { type ModelThinkingLevel, type ThinkingLevel } from "@earendil-works/pi-ai";
|
|
4
4
|
import { completeSimple } from "@earendil-works/pi-ai/compat";
|
|
5
5
|
import { Type } from "@sinclair/typebox";
|
|
@@ -133,6 +133,8 @@ import {
|
|
|
133
133
|
} from "./shared/studio-tab-launcher.js";
|
|
134
134
|
import { buildStudioHostingBootstrapState, createStudioBufferServerStore, STUDIO_BUFFER_REQUEST_MAX_BYTES } from "./shared/studio-buffer-server.js";
|
|
135
135
|
import { createStudioTurns, readStudioEditorMode, resolveStudioEditorFlags, writeStudioEditorMode } from "./shared/studio-editor-mode.js";
|
|
136
|
+
import { createStudioUrlFile, STUDIO_URL_FILE_ENV } from "./shared/studio-url-file.js";
|
|
137
|
+
import { copyStudioUrl } from "./shared/studio-copy-url.js";
|
|
136
138
|
import { canonicalStudioDocumentPath, studioDocumentPathsReferToSameFile } from "./shared/studio-document-paths.js";
|
|
137
139
|
import { resolveStudioHostingPage, studioHostingCommandError, studioHostingLocalLinkError } from "./shared/studio-document-entrypoints.js";
|
|
138
140
|
import { systemThemeLacksTrueColor } from "./shared/studio-system-theme.js";
|
|
@@ -14105,7 +14107,7 @@ ${cssVarsBlock}
|
|
|
14105
14107
|
<div><dt>Option/Alt+=</dt><dd>Increase the active pane's text size when not editing text</dd></div>
|
|
14106
14108
|
<div><dt>Option/Alt+-</dt><dd>Decrease the active pane's text size when not editing text</dd></div>
|
|
14107
14109
|
<div><dt>Option/Alt+0</dt><dd>Reset the active pane's text size when not editing text</dd></div>
|
|
14108
|
-
<div class="shortcuts-full-only"><dt>Cmd/Ctrl+Option/Alt+A</dt><dd>
|
|
14110
|
+
<div class="shortcuts-full-only"><dt>Cmd/Ctrl+Option/Alt+A</dt><dd>Turn Follow on or off in the main editable Studio workspace</dd></div>
|
|
14109
14111
|
<div><dt>Cmd/Ctrl+Option/Alt+Shift+R</dt><dd>Refresh the focused or visible PDF preview from disk</dd></div>
|
|
14110
14112
|
</dl>
|
|
14111
14113
|
</section>
|
|
@@ -14248,6 +14250,18 @@ export default function (pi: ExtensionAPI) {
|
|
|
14248
14250
|
let lastHostedFullWorkspaceId: string | null = null;
|
|
14249
14251
|
const currentFullStudioUrl = (state: StudioServerState) => buildStudioUrl(state.port, state.token, "full", undefined, undefined,
|
|
14250
14252
|
STUDIO_DOCUMENT_HOSTING_ENABLED ? { hostedWorkspaceId: studioBufferStateStore.activeHostingWorkspaces("full")[0] || lastHostedFullWorkspaceId || undefined } : undefined);
|
|
14253
|
+
// Issue #7: with PI_STUDIO_URL_FILE set, that file holds the URL Studio last printed for its main
|
|
14254
|
+
// view, written as it's printed, and goes when Studio stops. In dual editor mode a URL without its
|
|
14255
|
+
// workspace doesn't open Studio, so none is written until there is one. A launch that waited for the
|
|
14256
|
+
// browser while Studio was stopped and started again writes nothing: its URL is the old server's (Astra, candidate 119).
|
|
14257
|
+
const studioUrlFile = createStudioUrlFile(process.env);
|
|
14258
|
+
const studioMainUrlReady = () => !STUDIO_DOCUMENT_HOSTING_ENABLED || Boolean(studioBufferStateStore.activeHostingWorkspaces("full")[0] || lastHostedFullWorkspaceId);
|
|
14259
|
+
const publishStudioUrlFile = (url: string, state: StudioServerState, ctx: ExtensionCommandContext | null): boolean => {
|
|
14260
|
+
if (!studioUrlFile || serverState !== state || !studioMainUrlReady()) return false;
|
|
14261
|
+
const result = studioUrlFile.publish(url);
|
|
14262
|
+
if (!result.ok) ctx?.ui.notify(`Studio couldn't write its URL to ${STUDIO_URL_FILE_ENV} (${result.path}): ${result.message}.`, "warning");
|
|
14263
|
+
return result.ok;
|
|
14264
|
+
};
|
|
14251
14265
|
let studioCwd = process.cwd();
|
|
14252
14266
|
let lastCommandCtx: ExtensionCommandContext | null = null;
|
|
14253
14267
|
let latestModelRequestCtx: StudioModelRequestContext | null = null;
|
|
@@ -20502,7 +20516,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
20502
20516
|
const state = await startServerNow(port, listenAll, token);
|
|
20503
20517
|
if (state.token !== token) throw new Error("another Studio server started first");
|
|
20504
20518
|
lastCommandCtx?.ui.notify(`Studio switched to ${label}.`, "info");
|
|
20505
|
-
if (pendingEditorModeLanding)
|
|
20519
|
+
if (pendingEditorModeLanding) {
|
|
20520
|
+
const url = `http://${STUDIO_ADVERTISED_HOST}:${state.port}${pendingEditorModeLanding.path}`;
|
|
20521
|
+
publishStudioUrlFile(url, state, lastCommandCtx);
|
|
20522
|
+
lastCommandCtx?.ui.notify(`Studio URL: ${url}`, "info");
|
|
20523
|
+
}
|
|
20506
20524
|
return state;
|
|
20507
20525
|
} catch (error) {
|
|
20508
20526
|
lastCommandCtx?.ui.notify(`Studio is now in ${label}, but it couldn't restart${port ? ` on port ${port}` : ""}: ${error instanceof Error ? error.message : String(error)}. Run /studio to open it.`, "error");
|
|
@@ -20566,6 +20584,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
20566
20584
|
} catch (error) {
|
|
20567
20585
|
ctx.ui.notify(`Browser opening failed; the workspace is kept: ${error instanceof Error ? error.message : String(error)}`, "warning");
|
|
20568
20586
|
} finally {
|
|
20587
|
+
publishStudioUrlFile(url, state, ctx);
|
|
20569
20588
|
ctx.ui.notify(`Studio URL: ${url}`, "info");
|
|
20570
20589
|
const hint = state.listenAll ? null : buildStudioSshTunnelHint(state.port, url)
|
|
20571
20590
|
?? (flags.noBrowser ? buildStudioForwardingHint(state.port, url, { prefix: "Browser auto-open was skipped because --no-browser was used." }) : null);
|
|
@@ -20601,6 +20620,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
20601
20620
|
|
|
20602
20621
|
const state = serverState;
|
|
20603
20622
|
serverState = null;
|
|
20623
|
+
const urlFile = studioUrlFile?.clear();
|
|
20624
|
+
if (urlFile && !urlFile.ok) lastCommandCtx?.ui.notify(`Studio couldn't remove its URL file (${urlFile.path}): ${urlFile.message}.`, "warning");
|
|
20604
20625
|
|
|
20605
20626
|
await new Promise<void>((resolve) => {
|
|
20606
20627
|
state.wsServer.close(() => resolve());
|
|
@@ -21551,7 +21572,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
21551
21572
|
) => {
|
|
21552
21573
|
if (hasConnectedFullStudioView() && serverState) {
|
|
21553
21574
|
ctx.ui.notify("The existing full Studio was kept. Use its opening controls, or /studio-replace to move it here if you can't find it.", "warning");
|
|
21554
|
-
|
|
21575
|
+
const kept = currentFullStudioUrl(serverState);
|
|
21576
|
+
publishStudioUrlFile(kept, serverState, ctx);
|
|
21577
|
+
ctx.ui.notify(`Studio URL: ${kept}`, "info");
|
|
21555
21578
|
return;
|
|
21556
21579
|
}
|
|
21557
21580
|
// Oliver, 14 Oct: plain /studio reopens the last workspace when its tab is gone, asking to
|
|
@@ -21567,6 +21590,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
21567
21590
|
} catch (error) {
|
|
21568
21591
|
ctx.ui.notify(`Browser opening failed; the workspace is kept: ${error instanceof Error ? error.message : String(error)}`, "warning");
|
|
21569
21592
|
} finally {
|
|
21593
|
+
publishStudioUrlFile(url, state, ctx);
|
|
21570
21594
|
ctx.ui.notify(`Studio URL: ${url}`, "info");
|
|
21571
21595
|
const hint = state.listenAll ? null : buildStudioSshTunnelHint(state.port, url)
|
|
21572
21596
|
?? (flags.noBrowser ? buildStudioForwardingHint(state.port, url, { prefix: "Browser auto-open was skipped because --no-browser was used." }) : null);
|
|
@@ -21614,6 +21638,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
21614
21638
|
} catch (error) {
|
|
21615
21639
|
ctx.ui.notify(`Browser opening failed; the same workspace is retained: ${error instanceof Error ? error.message : String(error)}`, "warning");
|
|
21616
21640
|
} finally {
|
|
21641
|
+
if (owner.mode === "full") publishStudioUrlFile(url, state, ctx);
|
|
21617
21642
|
ctx.ui.notify(`Studio URL: ${url}`, "info");
|
|
21618
21643
|
const hint = state.listenAll ? null : buildStudioSshTunnelHint(state.port, url)
|
|
21619
21644
|
?? (flags.noBrowser ? buildStudioForwardingHint(state.port, url, { prefix: "Browser auto-open was skipped because --no-browser was used." }) : null);
|
|
@@ -21749,6 +21774,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
21749
21774
|
: "A full pi Studio view is already open for this session. Close it first, use /studio-replace for a fresh full Studio view, or use /studio-editor-only for a concurrent editor-only Studio view.", "warning");
|
|
21750
21775
|
if (serverState) {
|
|
21751
21776
|
const url = currentFullStudioUrl(serverState);
|
|
21777
|
+
publishStudioUrlFile(url, serverState, ctx);
|
|
21752
21778
|
ctx.ui.notify(`Studio URL: ${url}`, "info");
|
|
21753
21779
|
const tunnelHint = serverState.listenAll
|
|
21754
21780
|
? null
|
|
@@ -21846,6 +21872,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
21846
21872
|
ctx.ui.notify(`Failed to open browser: ${message}`, "error");
|
|
21847
21873
|
}
|
|
21848
21874
|
} finally {
|
|
21875
|
+
if (launchMode === "full") publishStudioUrlFile(url, state, ctx);
|
|
21849
21876
|
ctx.ui.notify(`Studio URL: ${url}`, "info");
|
|
21850
21877
|
if (tunnelHint) ctx.ui.notify(tunnelHint, "info");
|
|
21851
21878
|
if (state.listenAll) ctx.ui.notify(buildStudioListenAllWarning(state.port, url), "warning");
|
|
@@ -21870,16 +21897,26 @@ export default function (pi: ExtensionAPI) {
|
|
|
21870
21897
|
}
|
|
21871
21898
|
const counts = getStudioClientCounts();
|
|
21872
21899
|
const url = currentFullStudioUrl(serverState);
|
|
21900
|
+
const filed = publishStudioUrlFile(url, serverState, ctx);
|
|
21873
21901
|
ctx.ui.notify(
|
|
21874
21902
|
`Studio running at ${url} (listening on ${serverState.bindHost}:${serverState.port}; busy: ${isStudioBusy() ? "yes" : "no"}; full views: ${counts.full}; editor-only views: ${counts.editorOnly})`,
|
|
21875
21903
|
"info",
|
|
21876
21904
|
);
|
|
21905
|
+
if (filed && studioUrlFile) ctx.ui.notify(`Studio URL file: ${studioUrlFile.path}`, "info");
|
|
21877
21906
|
const sshTunnelHint = serverState.listenAll ? null : buildStudioSshTunnelHint(serverState.port, url);
|
|
21878
21907
|
if (sshTunnelHint) ctx.ui.notify(sshTunnelHint, "info");
|
|
21879
21908
|
if (serverState.listenAll) ctx.ui.notify(buildStudioListenAllWarning(serverState.port, url), "warning");
|
|
21880
21909
|
return;
|
|
21881
21910
|
}
|
|
21882
21911
|
|
|
21912
|
+
// The URL --status prints, on the clipboard: for a terminal too narrow to show it whole.
|
|
21913
|
+
if (trimmed === "copy-url" || trimmed === "--copy-url") {
|
|
21914
|
+
const state = serverState;
|
|
21915
|
+
const result = await copyStudioUrl({ mode: ctx.mode, running: Boolean(state), url: state && studioMainUrlReady() ? currentFullStudioUrl(state) : null, copy: copyToClipboard });
|
|
21916
|
+
ctx.ui.notify(result.message, result.ok ? "info" : "warning");
|
|
21917
|
+
return;
|
|
21918
|
+
}
|
|
21919
|
+
|
|
21883
21920
|
if (trimmed === "help" || trimmed === "--help" || trimmed === "-h") {
|
|
21884
21921
|
ctx.ui.notify(
|
|
21885
21922
|
"Usage: /studio [path|--blank|--last]\n"
|
|
@@ -21893,6 +21930,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
21893
21930
|
+ " /studio --listen-all Explicitly bind to 0.0.0.0 instead of localhost (security-sensitive)\n"
|
|
21894
21931
|
+ " /studio --open-remote Over SSH, open the remote browser anyway\n"
|
|
21895
21932
|
+ " /studio --status Show studio status\n"
|
|
21933
|
+
+ " /studio --copy-url Copy the running Studio's URL to the clipboard\n"
|
|
21896
21934
|
+ " /studio --stop Stop studio server\n"
|
|
21897
21935
|
+ " /studio --single Use single editor mode (one editor), and remember it\n"
|
|
21898
21936
|
+ " /studio --dual Use dual editor mode (Prompt and Document), the default\n"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-studio",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.12",
|
|
4
4
|
"description": "Two-pane browser workspace for pi with prompt/response editing, annotations, critiques, active quiz, prompt/response history, live previews, and tmux-backed REPL/literate REPL workflows",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,6 +8,15 @@ import { createStudioDocumentOpenStorage } from "./studio-document-open-storage.
|
|
|
8
8
|
|
|
9
9
|
const fail = (reason, message) => ({ ok: false, reason, message });
|
|
10
10
|
const same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
11
|
+
// A page's live scroll positions. WebKit reports a negative one while a pane bounces past its top,
|
|
12
|
+
// which is the top; saving it failed as "Invalid scroll position" and flashed a recovery warning
|
|
13
|
+
// (Oliver, Muxy, 5 Nov). The store still refuses a negative position given to it explicitly.
|
|
14
|
+
const LIVE_SCROLL_FIELDS = ["scrollTop", "previewScrollTop", "rightScrollTop"];
|
|
15
|
+
function liveView(view) {
|
|
16
|
+
const next = { ...view };
|
|
17
|
+
for (const field of LIVE_SCROLL_FIELDS) if (typeof next[field] === "number" && Number.isFinite(next[field]) && next[field] < 0) next[field] = 0;
|
|
18
|
+
return next;
|
|
19
|
+
}
|
|
11
20
|
|
|
12
21
|
function literalStudioBufferLabel(source) {
|
|
13
22
|
// Provenance is not a link or a resource/terminal grant. Separate boundary
|
|
@@ -149,10 +158,10 @@ export function createStudioBufferClient(options) {
|
|
|
149
158
|
next = createStudioBuffer({ ...current, text: editor.text, sourceState: editor.sourceState,
|
|
150
159
|
baselineText: editor.sourceState.path ? baselineText : (current.sourceState.path ? null : current.baselineText),
|
|
151
160
|
diskRevision: editor.diskRevision, resourceDir: editor.resourceDir,
|
|
152
|
-
view: { ...current.view, editorView: editor.editorView, rightView: editor.rightView, editorLanguage: editor.editorLanguage,
|
|
161
|
+
view: liveView({ ...current.view, editorView: editor.editorView, rightView: editor.rightView, editorLanguage: editor.editorLanguage,
|
|
153
162
|
followLatest: editor.followLatest, responseHistoryIndex: editor.responseHistoryIndex,
|
|
154
163
|
selectionStart: editor.selectionStart, selectionEnd: editor.selectionEnd, scrollTop: editor.scrollTop,
|
|
155
|
-
...extra.view }, metadata: { ...current.metadata, ...extra.metadata } });
|
|
164
|
+
...extra.view }), metadata: { ...current.metadata, ...extra.metadata } });
|
|
156
165
|
} catch (error) { return fail(error.reason || "invalid-state", error.message); }
|
|
157
166
|
if (current.text === next.text && current.baselineText === next.baselineText && current.diskRevision === next.diskRevision
|
|
158
167
|
&& current.resourceDir === next.resourceDir && same(current.sourceState, next.sourceState)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// /studio --copy-url: the main view's URL on the clipboard, for a terminal too narrow to show it
|
|
2
|
+
// whole. Pi's copyToClipboard writes the system clipboard and, over SSH, also the terminal's own
|
|
3
|
+
// (OSC 52) through standard output, which in RPC, JSON and print modes carries Pi's output: only
|
|
4
|
+
// Pi's terminal interface copies. A Pi that doesn't say its mode copies nothing either; ctx.mode
|
|
5
|
+
// predates the Pi features Studio needs (Astra, candidate 119). RPC clients get the URL in
|
|
6
|
+
// Studio's notifications.
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {{ mode?: string, running: boolean, url: string | null, copy: (text: string) => Promise<void> }} options
|
|
10
|
+
* @returns {Promise<{ ok: boolean, message: string }>}
|
|
11
|
+
*/
|
|
12
|
+
export async function copyStudioUrl({ mode, running, url, copy }) {
|
|
13
|
+
if (mode !== "tui") return { ok: false, message: "Copying the URL needs Pi's terminal interface. /studio --status prints it." };
|
|
14
|
+
if (!running) return { ok: false, message: "Studio isn't running. Run /studio first." };
|
|
15
|
+
if (!url) return { ok: false, message: "Studio has no main view yet. Run /studio first." };
|
|
16
|
+
try {
|
|
17
|
+
await copy(url);
|
|
18
|
+
return { ok: true, message: "Copied Studio's URL." };
|
|
19
|
+
} catch (error) {
|
|
20
|
+
const reason = String(error instanceof Error ? error.message : error).replace(/\.$/, "");
|
|
21
|
+
return { ok: false, message: `Couldn't copy Studio's URL: ${reason}. /studio --status prints it.` };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Studio's URL in a file a program can read, for a script, an editor or a container that opens
|
|
2
|
+
// Studio without anyone copying the URL out of a terminal (issue #7). Opt-in: nothing is written
|
|
3
|
+
// unless PI_STUDIO_URL_FILE names a file, and it comes from Pi's own environment, so each Pi
|
|
4
|
+
// process can be given its own file. The file holds the same credential the terminal prints.
|
|
5
|
+
//
|
|
6
|
+
// Everything here is synchronous: in one process a write and a clear can't overlap, so a stop
|
|
7
|
+
// can't be overtaken by a write that was still on its way. Whether a write's URL is still the
|
|
8
|
+
// running server's is the caller's to check.
|
|
9
|
+
|
|
10
|
+
import { randomBytes } from "node:crypto";
|
|
11
|
+
import * as nodeFs from "node:fs";
|
|
12
|
+
import { basename, dirname, isAbsolute, join } from "node:path";
|
|
13
|
+
|
|
14
|
+
export const STUDIO_URL_FILE_ENV = "PI_STUDIO_URL_FILE";
|
|
15
|
+
|
|
16
|
+
/** @typedef {{ ok: true, path: string } | { ok: false, path: string, message: string }} StudioUrlFileResult */
|
|
17
|
+
|
|
18
|
+
const errorText = (error) => error && typeof error === "object" && typeof error.code === "string"
|
|
19
|
+
? ({ ENOENT: "its folder doesn't exist", EACCES: "permission denied", EPERM: "permission denied", EISDIR: "it's a folder", EROFS: "the file system is read-only" }[error.code] ?? error.code)
|
|
20
|
+
: String(error?.message ?? error);
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The URL file this process writes, or null when PI_STUDIO_URL_FILE isn't set.
|
|
24
|
+
* publish(url) puts the URL there; clear() removes it if it still holds what this process wrote.
|
|
25
|
+
* Neither throws: each returns { ok, path, message? }. Removal is best effort: a crash, or a
|
|
26
|
+
* removal that fails, leaves the file, whose token stops working with its server.
|
|
27
|
+
* options.fs replaces file functions, for tests.
|
|
28
|
+
*/
|
|
29
|
+
export function createStudioUrlFile(env = process.env, options = {}) {
|
|
30
|
+
const path = env?.[STUDIO_URL_FILE_ENV];
|
|
31
|
+
if (typeof path !== "string" || path === "") return null;
|
|
32
|
+
const platform = options.platform ?? process.platform;
|
|
33
|
+
const fs = { ...nodeFs, ...options.fs };
|
|
34
|
+
// What this process last wrote, so it removes only its own URL.
|
|
35
|
+
let written = null;
|
|
36
|
+
/** @returns {StudioUrlFileResult} */
|
|
37
|
+
const fail = (message) => ({ ok: false, path, message });
|
|
38
|
+
/** @returns {StudioUrlFileResult} */
|
|
39
|
+
const done = () => ({ ok: true, path });
|
|
40
|
+
|
|
41
|
+
/** @param {string} url @returns {StudioUrlFileResult} */
|
|
42
|
+
const publish = (url) => {
|
|
43
|
+
if (!isAbsolute(path)) return fail("it isn't an absolute path");
|
|
44
|
+
if (typeof url !== "string" || !url || /[\u0000-\u001f\u007f]/.test(url)) return fail("the URL isn't one line of text");
|
|
45
|
+
try {
|
|
46
|
+
// A link, a folder or a device there isn't replaced.
|
|
47
|
+
if (!fs.lstatSync(path).isFile()) return fail("something other than a file is there");
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error?.code !== "ENOENT") return fail(errorText(error));
|
|
50
|
+
}
|
|
51
|
+
const text = `${url}\n`;
|
|
52
|
+
// Private from its first byte: a new file beside the target, opened only if it doesn't
|
|
53
|
+
// exist, then renamed over the target, so a reader sees the old URL or the new one.
|
|
54
|
+
let temporary = null, descriptor = null;
|
|
55
|
+
try {
|
|
56
|
+
temporary = join(dirname(path), `.${basename(path)}.${process.pid}.${randomBytes(6).toString("hex")}.tmp`);
|
|
57
|
+
descriptor = fs.openSync(temporary, "wx", 0o600);
|
|
58
|
+
if (platform !== "win32") fs.fchmodSync(descriptor, 0o600);
|
|
59
|
+
fs.writeFileSync(descriptor, text, "utf8");
|
|
60
|
+
fs.closeSync(descriptor);
|
|
61
|
+
descriptor = null;
|
|
62
|
+
fs.renameSync(temporary, path);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
if (descriptor !== null) { try { fs.closeSync(descriptor); } catch {} }
|
|
65
|
+
if (temporary !== null) { try { fs.unlinkSync(temporary); } catch {} }
|
|
66
|
+
return fail(errorText(error));
|
|
67
|
+
}
|
|
68
|
+
written = text;
|
|
69
|
+
return done();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** @returns {StudioUrlFileResult} */
|
|
73
|
+
const clear = () => {
|
|
74
|
+
if (written === null) return done();
|
|
75
|
+
const mine = written;
|
|
76
|
+
written = null;
|
|
77
|
+
try {
|
|
78
|
+
// A path given to another process too may hold its URL now: leave it.
|
|
79
|
+
if (!fs.lstatSync(path).isFile() || fs.readFileSync(path, "utf8") !== mine) return done();
|
|
80
|
+
fs.unlinkSync(path);
|
|
81
|
+
return done();
|
|
82
|
+
} catch (error) {
|
|
83
|
+
return error?.code === "ENOENT" ? done() : fail(errorText(error));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return { path, publish, clear };
|
|
88
|
+
}
|