pi-studio 0.11.0 → 0.11.1
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 +7 -0
- package/client/studio-client.js +19 -6
- package/client/studio.css +13 -2
- package/index.ts +15 -65
- package/package.json +1 -1
- package/shared/repl-cursor-column.js +46 -0
- package/shared/repl-m-language.js +26 -17
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@ All notable changes to `pi-studio` are documented here.
|
|
|
4
4
|
|
|
5
5
|
## [Unreleased]
|
|
6
6
|
|
|
7
|
+
## [0.11.1] — 2026-10-22
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- While a prompt runs, the status beside **Stop** shows the elapsed time alone ("0:16"), and "Compacting context…" is now "Compacting…". The status keeps only the room "Starting…" and "Stopping…" need, so the toolbar's tools stay on the first row in narrower windows: with the default split, from about 1,315 px wide, down from about 1,390.
|
|
11
|
+
- The line above a response shows which one you're on at its right end ("9/9"), in the accent colour while an older response is showing. The rest of the line reads "Assistant response · 10:08:28 PM".
|
|
12
|
+
- The REPL pane uses pi-repl 0.10.5's shared helpers to end each send's output and to run Octave and MATLAB, in place of its own copies. Code runs as before.
|
|
13
|
+
|
|
7
14
|
## [0.11.0] — 2026-10-21
|
|
8
15
|
|
|
9
16
|
### Added
|
package/client/studio-client.js
CHANGED
|
@@ -107,6 +107,7 @@
|
|
|
107
107
|
? responseActionsEl.closest(".response-wrap")
|
|
108
108
|
: null;
|
|
109
109
|
const referenceBadgeEl = document.getElementById("referenceBadge");
|
|
110
|
+
const referenceHistoryCountEl = document.getElementById("referenceHistoryCount");
|
|
110
111
|
const editorViewSelect = document.getElementById("editorViewSelect");
|
|
111
112
|
const editorViewSelectWrap = document.getElementById("editorViewSelectWrap");
|
|
112
113
|
const rightViewSelect = document.getElementById("rightViewSelect");
|
|
@@ -950,13 +951,14 @@
|
|
|
950
951
|
const run = studioRuntimeActivity?.run;
|
|
951
952
|
if (wsState === "Disconnected" || wsState === "Connecting") return run ? "Run status unknown · reconnecting…" : "Reconnecting…";
|
|
952
953
|
const stopping = run && (run.stopping || studioStopRequestedRunId === run.id);
|
|
953
|
-
if (stopping) return "Stopping…" + (studioRuntimeActivity.compaction ? " · Compacting
|
|
954
|
-
if (studioRuntimeActivity?.compaction) return "Compacting
|
|
954
|
+
if (stopping) return "Stopping…" + (studioRuntimeActivity.compaction ? " · Compacting…" : "");
|
|
955
|
+
if (studioRuntimeActivity?.compaction) return "Compacting…";
|
|
955
956
|
if (run) {
|
|
956
957
|
if (run.origin === "outside") return "Pi is busy · started outside Studio";
|
|
957
958
|
if (run.origin === "unknown") return "Pi is busy · run origin unknown";
|
|
958
959
|
const seconds = Math.max(0, Math.floor((Date.now() - run.startedAt) / 1000));
|
|
959
|
-
|
|
960
|
+
// Oliver, 22 Oct: the clock alone, beside Stop, so the running row fits narrower windows.
|
|
961
|
+
return Math.floor(seconds / 60) + ":" + String(seconds % 60).padStart(2, "0");
|
|
960
962
|
}
|
|
961
963
|
// Oliver, 14 Oct: a Run waiting for Pi to start says so briefly here, so Queue steering fits
|
|
962
964
|
// beside it and the toolbar doesn't wrap and jump back. The footer keeps the detail.
|
|
@@ -7384,6 +7386,7 @@
|
|
|
7384
7386
|
|
|
7385
7387
|
function updateReferenceBadge() {
|
|
7386
7388
|
if (!referenceBadgeEl) return;
|
|
7389
|
+
if (referenceHistoryCountEl) referenceHistoryCountEl.hidden = true;
|
|
7387
7390
|
const referenceMetaEl = referenceBadgeEl.closest(".reference-meta");
|
|
7388
7391
|
if (rightView === "repl" || (studioUiRefreshUi && rightView === "editor-preview") || (bufferSwitchingEnabled && studioUiRefreshUi && rightView === "files")) {
|
|
7389
7392
|
if (referenceMetaEl instanceof HTMLElement) referenceMetaEl.hidden = true;
|
|
@@ -7490,10 +7493,20 @@
|
|
|
7490
7493
|
const selected = total > 0 && responseHistoryIndex >= 0 && responseHistoryIndex < total
|
|
7491
7494
|
? responseHistoryIndex + 1
|
|
7492
7495
|
: 0;
|
|
7493
|
-
|
|
7496
|
+
// Oliver, 22 Oct: the new layout shows the count on its own at the right, as agent-markdown-preview
|
|
7497
|
+
// does, so it's quick to find, and in the accent colour while an older response is showing.
|
|
7498
|
+
const countAtRight = Boolean(studioUiRefreshUi && referenceHistoryCountEl && total > 0);
|
|
7499
|
+
if (countAtRight) {
|
|
7500
|
+
referenceHistoryCountEl.textContent = selected + "/" + total;
|
|
7501
|
+
referenceHistoryCountEl.title = "Response " + selected + " of " + total + " in this branch's history";
|
|
7502
|
+
referenceHistoryCountEl.classList.toggle("is-older", selected > 0 && selected < total);
|
|
7503
|
+
referenceHistoryCountEl.hidden = false;
|
|
7504
|
+
}
|
|
7505
|
+
const historyPrefix = total > 0 && !countAtRight ? "Branch history " + selected + "/" + total + " · " : "";
|
|
7506
|
+
const label = countAtRight ? responseLabel.charAt(0).toUpperCase() + responseLabel.slice(1) : responseLabel;
|
|
7494
7507
|
referenceBadgeEl.textContent = time
|
|
7495
|
-
? historyPrefix +
|
|
7496
|
-
: historyPrefix +
|
|
7508
|
+
? historyPrefix + label + " · " + time
|
|
7509
|
+
: historyPrefix + label;
|
|
7497
7510
|
}
|
|
7498
7511
|
|
|
7499
7512
|
function normalizeForCompare(text) {
|
package/client/studio.css
CHANGED
|
@@ -7548,8 +7548,12 @@
|
|
|
7548
7548
|
/* Honor existing handler eligibility after controls are regrouped. */
|
|
7549
7549
|
body.studio-ui-refresh [hidden] { display: none !important; }
|
|
7550
7550
|
/* Dogfood workspace: two logical rows, with normal wrapping in small panes. */
|
|
7551
|
-
/* Room for "
|
|
7552
|
-
|
|
7551
|
+
/* Room for "Starting…" and "Stopping…", so nothing moves when a run starts, its clock ticks or it's stopped
|
|
7552
|
+
(Oliver, 14 Oct). Hidden copies in the page's own font set the width. The clock itself, "0:16", is narrower,
|
|
7553
|
+
and the old 13ch reserve for "Running 00:00" pushed the tools onto a second row (Oliver, 22 Oct). */
|
|
7554
|
+
.studio-run-status { color: var(--muted); font-size: 12px; min-width: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
|
|
7555
|
+
.studio-run-status::before { content: "Starting…"; display: block; height: 0; overflow: hidden; visibility: hidden; }
|
|
7556
|
+
.studio-run-status::after { content: "Stopping…"; display: block; height: 0; overflow: hidden; visibility: hidden; }
|
|
7553
7557
|
body.studio-ui-refresh #rightSectionHeader .studio-follow-button {
|
|
7554
7558
|
color: var(--muted); border: 0; border-radius: 0; background: transparent;
|
|
7555
7559
|
}
|
|
@@ -7585,6 +7589,13 @@
|
|
|
7585
7589
|
body.studio-workspace-layout .response-option-select-wrap:not(:has(select)) { display: none; }
|
|
7586
7590
|
body.studio-workspace-layout .reference-meta .source-badge,
|
|
7587
7591
|
body.studio-workspace-layout #historyIndexBadge { border: 0; border-radius: 0; background: transparent; }
|
|
7592
|
+
/* The response count sits at the right of the line, in the text colour, and in the accent colour while an
|
|
7593
|
+
older response is showing (Oliver, 22 Oct). */
|
|
7594
|
+
body.studio-workspace-layout .reference-meta:not([hidden]) { display: flex; align-items: center; gap: 8px; }
|
|
7595
|
+
/* As a row its labels' vertical padding would count, making the line 7 px taller than before (Astra). */
|
|
7596
|
+
body.studio-workspace-layout .reference-meta .source-badge { padding-top: 0; padding-bottom: 0; }
|
|
7597
|
+
body.studio-workspace-layout #rightPane #referenceHistoryCount { margin-left: auto; flex: none; color: var(--text); font-variant-numeric: tabular-nums; }
|
|
7598
|
+
body.studio-workspace-layout #rightPane #referenceHistoryCount.is-older { color: var(--accent); }
|
|
7588
7599
|
body.studio-workspace-layout .studio-refresh-action-line { flex-wrap: wrap; gap: 6px 10px; }
|
|
7589
7600
|
body.studio-workspace-layout .studio-refresh-menu > button { display: block; width: 100%; text-align: left; white-space: normal; }
|
|
7590
7601
|
body.studio-workspace-layout .response-result-row { flex-wrap: wrap; }
|
package/index.ts
CHANGED
|
@@ -88,7 +88,8 @@ import {
|
|
|
88
88
|
cleanupPrivateReplControlFiles,
|
|
89
89
|
createPrivateReplControlFiles,
|
|
90
90
|
} from "./shared/repl-control-files.js";
|
|
91
|
-
import {
|
|
91
|
+
import { CURSOR_COLUMN_QUERY, CURSOR_COLUMN_SUPERVISOR } from "./shared/repl-cursor-column.js";
|
|
92
|
+
import { buildMLanguageControlSource, buildMLanguageDriverSource, mStringLiteral } from "./shared/repl-m-language.js";
|
|
92
93
|
import { buildGnuplotDriverSource, buildGnuplotGuardSource, buildGnuplotSubmissionLine } from "./shared/repl-gnuplot.js";
|
|
93
94
|
import { GNUPLOT_OWNER_ENV, GNUPLOT_OWNER_OPTION } from "./shared/repl-gnuplot-processes.js";
|
|
94
95
|
import { buildCppDriverSource, buildCppRequest, cppInclude, createCppControlCleanup, prepareCppSubmission, readCppCompletion } from "./shared/repl-cpp.js";
|
|
@@ -11671,17 +11672,17 @@ function buildStudioClojureDisplayStatements(display: ReplSubmissionDisplay, ind
|
|
|
11671
11672
|
return display.prefixLines.map((line) => `${indent}(clojure.core/println ${JSON.stringify(line)})`);
|
|
11672
11673
|
}
|
|
11673
11674
|
|
|
11674
|
-
//
|
|
11675
|
-
// 500 ms. A wrapper runs it with Node and ends a line before its
|
|
11676
|
-
// 0. Only the wrapper reads its output, so it never reaches the
|
|
11677
|
-
// outlives its wait can't print after the done file (Sol, Astra,
|
|
11675
|
+
// CURSOR_COLUMN_QUERY (shared with pi-repl) prints the pane's cursor column, or exits
|
|
11676
|
+
// non-zero; tmux gets 500 ms. A wrapper runs it with Node and ends a line before its
|
|
11677
|
+
// footer unless it prints 0. Only the wrapper reads its output, so it never reaches the
|
|
11678
|
+
// pane: a query that outlives its wait can't print after the done file (Sol, Astra,
|
|
11679
|
+
// candidate80).
|
|
11678
11680
|
// process.exit ends Node even if a startup hook in NODE_OPTIONS would keep it running,
|
|
11679
11681
|
// and each wrapper also limits the whole helper to 5 s.
|
|
11680
11682
|
// With the display Off, the footers still end a line that output left open, and add
|
|
11681
11683
|
// nothing else. Otherwise the runtime's prompt follows the output on the same row,
|
|
11682
11684
|
// which the record mistook for a prompt row, and line editors such as gnuplot's then
|
|
11683
11685
|
// redraw the next pasted line wrongly (Astra, candidate90).
|
|
11684
|
-
const STUDIO_CURSOR_COLUMN_QUERY = 'let code = 1; try { require("node:fs").writeSync(1, require("node:child_process").execFileSync("tmux", ["-N", "display-message", "-p", "-t", process.env.TMUX_PANE, "#{cursor_x}"], { encoding: "utf8", timeout: 500, killSignal: "SIGKILL", maxBuffer: 128, stdio: ["ignore", "pipe", "ignore"] }).trim()); code = 0; } catch {} process.exit(code);';
|
|
11685
11686
|
|
|
11686
11687
|
function buildStudioPythonFooter(display: ReplSubmissionDisplay): string[] {
|
|
11687
11688
|
return [
|
|
@@ -11691,7 +11692,7 @@ function buildStudioPythonFooter(display: ReplSubmissionDisplay): string[] {
|
|
|
11691
11692
|
" try:",
|
|
11692
11693
|
" __pi_studio_sys.stdout.flush()",
|
|
11693
11694
|
" __pi_studio_sys.stderr.flush()",
|
|
11694
|
-
` __pi_studio_query = __pi_studio_subprocess.run([${JSON.stringify(process.execPath)}, '-e', ${JSON.stringify(
|
|
11695
|
+
` __pi_studio_query = __pi_studio_subprocess.run([${JSON.stringify(process.execPath)}, '-e', ${JSON.stringify(CURSOR_COLUMN_QUERY)}], stdin=__pi_studio_subprocess.DEVNULL, stdout=__pi_studio_subprocess.PIPE, stderr=__pi_studio_subprocess.DEVNULL, timeout=5)`,
|
|
11695
11696
|
" if __pi_studio_query.returncode == 0:",
|
|
11696
11697
|
" __pi_studio_column = __pi_studio_query.stdout.decode('utf-8', 'replace').strip()",
|
|
11697
11698
|
// run() kills the query on any exception. Ctrl-C here must not skip the done file.
|
|
@@ -11750,7 +11751,7 @@ function buildStudioPythonControlSource(runtime: "python" | "ipython", code: str
|
|
|
11750
11751
|
}
|
|
11751
11752
|
|
|
11752
11753
|
function buildStudioJuliaFooter(display: ReplSubmissionDisplay): string[] {
|
|
11753
|
-
const query = `Cmd([${juliaStringLiteral(process.execPath)}, "-e", ${juliaStringLiteral(
|
|
11754
|
+
const query = `Cmd([${juliaStringLiteral(process.execPath)}, "-e", ${juliaStringLiteral(CURSOR_COLUMN_QUERY)}])`;
|
|
11754
11755
|
return [
|
|
11755
11756
|
' local __pi_studio_column = ""',
|
|
11756
11757
|
" local __pi_studio_query = nothing",
|
|
@@ -11809,7 +11810,7 @@ function buildStudioRFooter(display: ReplSubmissionDisplay): string[] {
|
|
|
11809
11810
|
// system2 quotes the command but not its arguments, and kills it after
|
|
11810
11811
|
// 5 s. A failed query sets a status; an error or Ctrl-C here gives
|
|
11811
11812
|
// NULL, not a lost done file.
|
|
11812
|
-
` .__pi_studio_column <- tryCatch(suppressWarnings(system2(${JSON.stringify(process.execPath)}, c("-e", ${JSON.stringify(shellQuote(
|
|
11813
|
+
` .__pi_studio_column <- tryCatch(suppressWarnings(system2(${JSON.stringify(process.execPath)}, c("-e", ${JSON.stringify(shellQuote(CURSOR_COLUMN_QUERY))}), stdout = TRUE, stderr = FALSE, timeout = 5)), error = function(e) NULL, interrupt = function(e) NULL)`,
|
|
11813
11814
|
' if (!is.null(attr(.__pi_studio_column, "status")) || !identical(trimws(paste(.__pi_studio_column, collapse = "")), "0")) base::cat("\\n")',
|
|
11814
11815
|
...display.suffixLines.map((line) => ` base::cat(${JSON.stringify(`${line}\n`)})`),
|
|
11815
11816
|
];
|
|
@@ -11863,7 +11864,7 @@ function buildStudioGhciControlSource(code: string, doneFile: string, display: R
|
|
|
11863
11864
|
// bounded, and Ctrl+C stops only the query. Empty if the query fails. ${NODE_OPTIONS-}
|
|
11864
11865
|
// because the Shell runtime's footer runs in the user's shell, which may have set -u (Astra).
|
|
11865
11866
|
function buildStudioShellCursorColumn(): string {
|
|
11866
|
-
return `__pi_studio_column=$(NODE_OPTIONS= ${shellQuote(process.execPath)} -e ${shellQuote(
|
|
11867
|
+
return `__pi_studio_column=$(NODE_OPTIONS= ${shellQuote(process.execPath)} -e ${shellQuote(CURSOR_COLUMN_SUPERVISOR)} -- "\${NODE_OPTIONS-}" </dev/null 2>/dev/null) || __pi_studio_column=`;
|
|
11867
11868
|
}
|
|
11868
11869
|
|
|
11869
11870
|
function buildStudioGhciCompletionLine(doneFile: string, display: ReplSubmissionDisplay): string {
|
|
@@ -11875,7 +11876,7 @@ function buildStudioGhciCompletionLine(doneFile: string, display: ReplSubmission
|
|
|
11875
11876
|
}
|
|
11876
11877
|
|
|
11877
11878
|
function buildStudioClojureFooter(display: ReplSubmissionDisplay): string[] {
|
|
11878
|
-
const builder = `(java.lang.ProcessBuilder. ^java.util.List [${JSON.stringify(process.execPath)} "-e" ${JSON.stringify(
|
|
11879
|
+
const builder = `(java.lang.ProcessBuilder. ^java.util.List [${JSON.stringify(process.execPath)} "-e" ${JSON.stringify(CURSOR_COLUMN_QUERY)}])`;
|
|
11879
11880
|
return [
|
|
11880
11881
|
" (try (.flush *out*) (.flush *err*) (catch Throwable _))",
|
|
11881
11882
|
// An interrupt left pending by the code would end the wait at once, so
|
|
@@ -12066,58 +12067,6 @@ function buildStudioJavaDriverSource(sourceFile: string, doneFile: string, displ
|
|
|
12066
12067
|
].join("\n");
|
|
12067
12068
|
}
|
|
12068
12069
|
|
|
12069
|
-
// Octave and MATLAB: pi-repl's shared buildMLanguageDriverSource, with two changes Sol and
|
|
12070
|
-
// Astra held candidate88 on, until pi-repl takes them:
|
|
12071
|
-
// - The column query is STUDIO_CURSOR_COLUMN_QUERY, which exits once it has written, run by
|
|
12072
|
-
// STUDIO_CURSOR_COLUMN_SUPERVISOR, which kills it after 5 s: system() itself has no time
|
|
12073
|
-
// limit. It writes to a private file, not to system()'s pipe, so nothing it leaves running
|
|
12074
|
-
// can hold that pipe open, and the file goes even if the script is interrupted (as in
|
|
12075
|
-
// pi-repl 0.10.1). The script exits 0 or 1: given a status such as 137, MATLAB printed the
|
|
12076
|
-
// command and "Killed" (Astra).
|
|
12077
|
-
// - In Octave, Ctrl+C during a cleanup action ended it before the done file was written.
|
|
12078
|
-
// unwind_protect_cleanup writes it even then. MATLAB finishes a cleanup action despite
|
|
12079
|
-
// Ctrl+C, and has no unwind_protect.
|
|
12080
|
-
// Runs STUDIO_CURSOR_COLUMN_QUERY in a child Node, with the caller's NODE_OPTIONS (its
|
|
12081
|
-
// argument), and kills it after 5 s. The supervisor runs without NODE_OPTIONS, so no startup
|
|
12082
|
-
// hook can stall it, keep it running or catch its timer; SIGKILL can't be caught either. It
|
|
12083
|
-
// signals only its own child, which Node tracks, so never a process ID since reused (Sol). A
|
|
12084
|
-
// preload that catches SIGALRM made perl's alarm wait for its stall (Astra). It ignores Ctrl+C
|
|
12085
|
-
// and hangups, so the deadline holds then too; the query gets the default handling.
|
|
12086
|
-
const STUDIO_CURSOR_COLUMN_SUPERVISOR = `for (const signal of ["SIGINT", "SIGHUP", "SIGTERM"]) process.on(signal, () => {}); const child = require("node:child_process").spawn(process.execPath, ["-e", ${JSON.stringify(STUDIO_CURSOR_COLUMN_QUERY)}], { stdio: ["ignore", "inherit", "ignore"], env: { ...process.env, NODE_OPTIONS: process.argv[1] ?? "" } }); const timer = setTimeout(() => child.kill("SIGKILL"), 5000); child.on("error", () => process.exit(1)); child.on("exit", (code) => { clearTimeout(timer); process.exit(code === 0 ? 0 : 1); });`;
|
|
12087
|
-
|
|
12088
|
-
function buildStudioMLanguageDriverSource(runtime: "octave" | "matlab", sourceFile: string, doneFile: string, display: ReplSubmissionDisplay): string {
|
|
12089
|
-
const query = [
|
|
12090
|
-
// The shell's own messages would reach the pane through system().
|
|
12091
|
-
"exec 2>/dev/null",
|
|
12092
|
-
"f=$(mktemp) || exit 1",
|
|
12093
|
-
`trap 'rm -f "$f"' EXIT`,
|
|
12094
|
-
"trap 'exit 1' HUP INT TERM",
|
|
12095
|
-
// After --, Node takes "$NODE_OPTIONS" as the script's argument, not as its own option.
|
|
12096
|
-
`NODE_OPTIONS= ${shellQuote(process.execPath)} -e ${shellQuote(STUDIO_CURSOR_COLUMN_SUPERVISOR)} -- "$NODE_OPTIONS" >"$f" </dev/null; s=$?`,
|
|
12097
|
-
'cat "$f"',
|
|
12098
|
-
'[ "$s" = 0 ]',
|
|
12099
|
-
].join("; ");
|
|
12100
|
-
const footer = [
|
|
12101
|
-
...(runtime === "octave" ? ["fflush(1);"] : []),
|
|
12102
|
-
"try",
|
|
12103
|
-
// /bin/sh whatever the user's shell is: MATLAB runs system() with $SHELL.
|
|
12104
|
-
` [pi_repl_status,pi_repl_column]=system(${mStringLiteral(`/bin/sh -c ${shellQuote(query)}`)});`,
|
|
12105
|
-
"catch",
|
|
12106
|
-
" pi_repl_status=-1; pi_repl_column='';",
|
|
12107
|
-
"end",
|
|
12108
|
-
"if pi_repl_status~=0 || ~strcmp(strtrim(pi_repl_column),'0'); fprintf(1,'\\n'); end",
|
|
12109
|
-
...display.suffixLines.map((line) => `fprintf(1,'%s\\n',${mStringLiteral(line)});`),
|
|
12110
|
-
];
|
|
12111
|
-
const done = `fclose(fopen(${mStringLiteral(doneFile)},'w'));`;
|
|
12112
|
-
const finish = (runtime === "octave"
|
|
12113
|
-
? ["unwind_protect", ...footer, "unwind_protect_cleanup", done, "end_unwind_protect"]
|
|
12114
|
-
: [...footer, done]).join("\n");
|
|
12115
|
-
// As in pi-repl: parameters give eval its own slots, so no helper variables, ans, cwd or
|
|
12116
|
-
// path changes reach the base workspace, and even clear all can't remove the guard.
|
|
12117
|
-
const cleanup = `onCleanup(@() feval(@(pi_repl_status,pi_repl_column) eval(${mStringLiteral(finish)}),-1,''))`;
|
|
12118
|
-
return `feval(@(pi_repl_error,pi_repl_guard) eval(fileread(${mStringLiteral(sourceFile)})),[],${cleanup});\n`;
|
|
12119
|
-
}
|
|
12120
|
-
|
|
12121
12070
|
function buildStudioShellControlSource(code: string, display: ReplSubmissionDisplay): string {
|
|
12122
12071
|
return [
|
|
12123
12072
|
...display.prefixLines.map((line) => `command printf '%s\\n' ${shellQuote(line)}`),
|
|
@@ -12242,14 +12191,14 @@ function prepareStudioReplSubmission(
|
|
|
12242
12191
|
}
|
|
12243
12192
|
}
|
|
12244
12193
|
if (runtime === "octave" || runtime === "matlab") {
|
|
12245
|
-
// pi-repl's M driver
|
|
12194
|
+
// pi-repl's M driver: the code runs in the base workspace,
|
|
12246
12195
|
// and a function-local onCleanup writes the footer and done file, even after an
|
|
12247
12196
|
// error, return, interrupt or clear all.
|
|
12248
12197
|
try {
|
|
12249
12198
|
const driver = createPrivateReplControlFiles({
|
|
12250
12199
|
...controlOptions,
|
|
12251
12200
|
extension: "m",
|
|
12252
|
-
buildSource: () =>
|
|
12201
|
+
buildSource: () => buildMLanguageDriverSource(runtime, controlFiles.sourceFile, controlFiles.doneFile, display),
|
|
12253
12202
|
});
|
|
12254
12203
|
controlFiles.helpers = [driver];
|
|
12255
12204
|
loader = driver.sourceFile;
|
|
@@ -13526,6 +13475,7 @@ ${cssVarsBlock}
|
|
|
13526
13475
|
</div>
|
|
13527
13476
|
<div class="reference-meta">
|
|
13528
13477
|
<span id="referenceBadge" class="source-badge">Latest response: none</span>
|
|
13478
|
+
<span id="referenceHistoryCount" class="source-badge" hidden></span>
|
|
13529
13479
|
</div>
|
|
13530
13480
|
<div id="critiqueView" class="panel-scroll rendered-markdown"><pre class="plain-markdown">No response yet.</pre></div>
|
|
13531
13481
|
<div class="response-wrap">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-studio",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.1",
|
|
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",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// The Node script a REPL wrapper runs to learn the pane's cursor column, so
|
|
2
|
+
// that it ends a line before its footer only when output stopped mid-line. It
|
|
3
|
+
// prints the column, or exits non-zero; tmux gets 500 ms. process.exit ends
|
|
4
|
+
// Node even if a startup hook in NODE_OPTIONS would keep it running. Only the
|
|
5
|
+
// wrapper reads its output, so it never reaches the pane.
|
|
6
|
+
export const CURSOR_COLUMN_QUERY = 'let code = 1; try { require("node:fs").writeSync(1, require("node:child_process").execFileSync("tmux", ["-N", "display-message", "-p", "-t", process.env.TMUX_PANE, "#{cursor_x}"], { encoding: "utf8", timeout: 500, killSignal: "SIGKILL", maxBuffer: 128, stdio: ["ignore", "pipe", "ignore"] }).trim()); code = 0; } catch {} process.exit(code);';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Runs CURSOR_COLUMN_QUERY in a child Node, with the caller's NODE_OPTIONS
|
|
10
|
+
* (its argument), and kills it after 5 s. The supervisor itself runs without
|
|
11
|
+
* NODE_OPTIONS, so no startup hook can stall it, keep it running or catch its
|
|
12
|
+
* timer, and SIGKILL can't be caught either; a hook that caught perl's SIGALRM
|
|
13
|
+
* held the helper as long as it liked. It signals only its own child, which
|
|
14
|
+
* Node tracks, so never a process ID since reused. It ignores Ctrl-C and
|
|
15
|
+
* hangups, so the deadline holds then too; the query gets the default
|
|
16
|
+
* handling. It exits 0 or 1. From pi-studio 0.11.0.
|
|
17
|
+
*/
|
|
18
|
+
export const CURSOR_COLUMN_SUPERVISOR = `for (const signal of ["SIGINT", "SIGHUP", "SIGTERM"]) process.on(signal, () => {}); const child = require("node:child_process").spawn(process.execPath, ["-e", ${JSON.stringify(CURSOR_COLUMN_QUERY)}], { stdio: ["ignore", "inherit", "ignore"], env: { ...process.env, NODE_OPTIONS: process.argv[1] ?? "" } }); const timer = setTimeout(() => child.kill("SIGKILL"), 5000); child.on("error", () => process.exit(1)); child.on("exit", (code) => { clearTimeout(timer); process.exit(code === 0 ? 0 : 1); });`;
|
|
19
|
+
|
|
20
|
+
const shellQuote = (value) => `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A command that runs the query under /bin/sh, whatever the caller's shell
|
|
24
|
+
* (MATLAB's system() uses $SHELL), for runtimes whose own process call can't
|
|
25
|
+
* be bounded (GHCi's :!, and Octave and MATLAB system()).
|
|
26
|
+
* CURSOR_COLUMN_SUPERVISOR stops it after 5 s. The column passes through a
|
|
27
|
+
* temporary file, so a child the helper leaves behind can't hold the caller's
|
|
28
|
+
* pipe open; the file is removed even when the script is interrupted. The
|
|
29
|
+
* shell's messages are discarded, and it exits only 0 or 1, so the caller
|
|
30
|
+
* never prints a signal status.
|
|
31
|
+
*/
|
|
32
|
+
export function boundedCursorColumnCommand(nodePath) {
|
|
33
|
+
const script = [
|
|
34
|
+
"exec 2>/dev/null",
|
|
35
|
+
"f=$(mktemp) || exit 1",
|
|
36
|
+
// Ctrl-C reaches this shell too; the file goes either way.
|
|
37
|
+
`trap 'rm -f "$f"' EXIT`,
|
|
38
|
+
"trap 'exit 1' HUP INT TERM",
|
|
39
|
+
// After --, Node takes the caller's NODE_OPTIONS as the script's argument, not as its own option.
|
|
40
|
+
`NODE_OPTIONS= ${shellQuote(nodePath)} -e ${shellQuote(CURSOR_COLUMN_SUPERVISOR)} -- "\${NODE_OPTIONS-}" >"$f" </dev/null`,
|
|
41
|
+
"s=$?",
|
|
42
|
+
'cat "$f"',
|
|
43
|
+
'[ "$s" = 0 ]',
|
|
44
|
+
].join("; ");
|
|
45
|
+
return `/bin/sh -c ${shellQuote(script)}`;
|
|
46
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// MATLAB and Octave share the base-workspace protocol, not a process/session.
|
|
2
|
-
|
|
2
|
+
import { boundedCursorColumnCommand } from "./repl-cursor-column.js";
|
|
3
3
|
|
|
4
4
|
export function mStringLiteral(value) {
|
|
5
5
|
// Single-quoted ASCII is compact in the loader. Encode everything else as
|
|
@@ -21,23 +21,32 @@ export function buildMLanguageControlSource(code, display) {
|
|
|
21
21
|
].join("\n");
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* What runs once a submission's code has finished: the footer, then the done
|
|
26
|
+
* file. In Off the footer still ends a line that output left open, and adds
|
|
27
|
+
* nothing else. Ctrl-C during Octave's footer interrupts this cleanup action
|
|
28
|
+
* and skips whatever follows, so for Octave the done file is written by
|
|
29
|
+
* unwind_protect. MATLAB finishes the action, and has no unwind_protect.
|
|
30
|
+
*/
|
|
31
|
+
export function buildMLanguageFinish(runtime, doneFile, display) {
|
|
32
|
+
const footer = [
|
|
33
|
+
...(runtime === "octave" ? ["fflush(1);"] : []),
|
|
34
|
+
"try",
|
|
35
|
+
` [pi_repl_status,pi_repl_column]=system(${mStringLiteral(boundedCursorColumnCommand(process.execPath))});`,
|
|
36
|
+
"catch",
|
|
37
|
+
" pi_repl_status=-1; pi_repl_column='';",
|
|
38
|
+
"end",
|
|
39
|
+
"if pi_repl_status~=0 || ~strcmp(strtrim(pi_repl_column),'0'); fprintf(1,'\\n'); end",
|
|
40
|
+
...display.suffixLines.map((line) => `fprintf(1,'%s\\n',${mStringLiteral(line)});`),
|
|
41
|
+
];
|
|
42
|
+
const done = `fclose(fopen(${mStringLiteral(doneFile)},'w'));`;
|
|
43
|
+
return (runtime === "octave"
|
|
44
|
+
? ["unwind_protect", ...footer, "unwind_protect_cleanup", done, "end_unwind_protect"]
|
|
45
|
+
: [...footer, done]).join("\n");
|
|
46
|
+
}
|
|
47
|
+
|
|
24
48
|
export function buildMLanguageDriverSource(runtime, sourceFile, doneFile, display) {
|
|
25
|
-
const
|
|
26
|
-
'try { process.stdout.write(require("node:child_process").execFileSync("tmux", ["-N", "display-message", "-p", "-t", process.env.TMUX_PANE, "#{cursor_x}"], { encoding: "utf8", timeout: 500, killSignal: "SIGKILL", maxBuffer: 128, stdio: ["ignore", "pipe", "ignore"] }).trim()); } catch { process.exitCode = 1; }',
|
|
27
|
-
].join(" ");
|
|
28
|
-
const finish = [
|
|
29
|
-
...(display.enabled ? [
|
|
30
|
-
...(runtime === "octave" ? ["fflush(1);"] : []),
|
|
31
|
-
"try",
|
|
32
|
-
` [pi_repl_status,pi_repl_column]=system(${mStringLiteral(`${shellQuote(process.execPath)} -e ${shellQuote(query)} 2>/dev/null`)});`,
|
|
33
|
-
"catch",
|
|
34
|
-
" pi_repl_status=-1; pi_repl_column='';",
|
|
35
|
-
"end",
|
|
36
|
-
"if pi_repl_status~=0 || ~strcmp(strtrim(pi_repl_column),'0'); fprintf(1,'\\n'); end",
|
|
37
|
-
...display.suffixLines.map((line) => `fprintf(1,'%s\\n',${mStringLiteral(line)});`),
|
|
38
|
-
] : []),
|
|
39
|
-
`fclose(fopen(${mStringLiteral(doneFile)},'w'));`,
|
|
40
|
-
].join("\n");
|
|
49
|
+
const finish = buildMLanguageFinish(runtime, doneFile, display);
|
|
41
50
|
// Parameters give eval its own slots in MATLAB's static anonymous-function
|
|
42
51
|
// workspace. No helper variables/ans, cwd or path changes enter the base
|
|
43
52
|
// workspace. onCleanup runs on normal completion, return and interruption;
|