pi-studio 0.11.7 → 0.11.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client/studio.css CHANGED
@@ -2198,6 +2198,91 @@
2198
2198
  height: 15px;
2199
2199
  }
2200
2200
 
2201
+ /* A PDF's More menu, on its card and in its enlarged view, as the REPL pane's (candidate 117). */
2202
+ .studio-pdf-more {
2203
+ position: relative;
2204
+ flex: 0 0 auto;
2205
+ }
2206
+
2207
+ .studio-pdf-more > summary {
2208
+ display: inline-flex;
2209
+ align-items: center;
2210
+ cursor: pointer;
2211
+ user-select: none;
2212
+ list-style: none;
2213
+ padding: 3px 7px;
2214
+ border: 1px solid transparent;
2215
+ border-radius: 7px;
2216
+ color: var(--studio-info-text, var(--muted));
2217
+ font-size: 12px;
2218
+ font-weight: 600;
2219
+ line-height: 1.2;
2220
+ white-space: nowrap;
2221
+ }
2222
+
2223
+ .studio-pdf-more > summary::-webkit-details-marker {
2224
+ display: none;
2225
+ }
2226
+
2227
+ .studio-pdf-more > summary::after {
2228
+ content: "⌄";
2229
+ margin-left: 4px;
2230
+ font-size: 11px;
2231
+ }
2232
+
2233
+ .studio-pdf-more > summary:hover,
2234
+ .studio-pdf-more > summary:focus-visible,
2235
+ .studio-pdf-more[open] > summary {
2236
+ background: var(--panel);
2237
+ border-color: var(--control-border);
2238
+ color: var(--text);
2239
+ outline: none;
2240
+ }
2241
+
2242
+ .studio-pdf-more-menu {
2243
+ position: absolute;
2244
+ top: calc(100% + 6px);
2245
+ right: 0;
2246
+ z-index: 30;
2247
+ display: flex;
2248
+ flex-direction: column;
2249
+ align-items: stretch;
2250
+ gap: 2px;
2251
+ width: max-content;
2252
+ min-width: 160px;
2253
+ padding: 6px;
2254
+ border: 1px solid var(--panel-border);
2255
+ border-radius: 10px;
2256
+ background: var(--panel);
2257
+ box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
2258
+ }
2259
+
2260
+ .studio-pdf-more .studio-pdf-more-menu > .studio-pdf-more-item {
2261
+ display: flex;
2262
+ width: 100%;
2263
+ min-height: 0;
2264
+ justify-content: flex-start;
2265
+ padding: 5px 8px;
2266
+ border: 1px solid transparent;
2267
+ border-radius: 6px;
2268
+ background: transparent;
2269
+ color: var(--text);
2270
+ font-size: 12px;
2271
+ font-weight: 500;
2272
+ line-height: 1.3;
2273
+ text-align: left;
2274
+ text-decoration: none;
2275
+ white-space: nowrap;
2276
+ }
2277
+
2278
+ .studio-pdf-more .studio-pdf-more-menu > .studio-pdf-more-item:not(:disabled):hover,
2279
+ .studio-pdf-more .studio-pdf-more-menu > .studio-pdf-more-item:not(:disabled):focus-visible {
2280
+ background: var(--studio-header-action-hover-bg, var(--panel-2));
2281
+ border-color: transparent;
2282
+ color: var(--text);
2283
+ text-decoration: none;
2284
+ }
2285
+
2201
2286
  .rendered-markdown .studio-pdf-card-caption {
2202
2287
  padding: 8px 10px 0;
2203
2288
  color: var(--studio-info-text, var(--muted));
@@ -4950,7 +5035,6 @@
4950
5035
  }
4951
5036
 
4952
5037
  .repl-journal-header p,
4953
- .repl-journal-description,
4954
5038
  .repl-journal-omitted {
4955
5039
  margin: 1px 0 0;
4956
5040
  color: var(--muted);
@@ -5122,6 +5206,68 @@
5122
5206
  font-style: italic;
5123
5207
  }
5124
5208
 
5209
+ /* Image and PDF files an entry names, such as a saved plot, as pi-markdown-preview's REPL
5210
+ page shows them: one tile a row, up to 640 by 420 px, named inside the tile. */
5211
+ .repl-studio-files {
5212
+ display: flex;
5213
+ flex-direction: column;
5214
+ align-items: flex-start;
5215
+ gap: 8px;
5216
+ margin: 6px 0 2px calc(var(--repl-studio-prompt-width) + var(--repl-studio-column-gap));
5217
+ }
5218
+
5219
+ .repl-journal-list .repl-studio-file {
5220
+ display: flex;
5221
+ flex-direction: column;
5222
+ gap: 6px;
5223
+ max-width: min(100%, 640px);
5224
+ padding: 8px;
5225
+ border: 1px solid var(--panel-border);
5226
+ border-radius: 8px;
5227
+ background: var(--panel);
5228
+ color: inherit;
5229
+ font-size: 12px;
5230
+ text-align: left;
5231
+ }
5232
+
5233
+ .repl-journal-list .repl-studio-file:not(:disabled):hover {
5234
+ background: var(--panel-2);
5235
+ }
5236
+
5237
+ .repl-studio-file-img {
5238
+ display: block;
5239
+ max-width: 100%;
5240
+ max-height: 420px;
5241
+ object-fit: contain;
5242
+ border-radius: 4px;
5243
+ background: #fff;
5244
+ }
5245
+
5246
+ .repl-studio-file-name {
5247
+ color: var(--muted);
5248
+ overflow-wrap: anywhere;
5249
+ }
5250
+
5251
+ .repl-journal-list .repl-studio-file-other {
5252
+ flex-direction: row;
5253
+ align-items: center;
5254
+ gap: 8px;
5255
+ padding: 8px 10px;
5256
+ }
5257
+
5258
+ .repl-studio-file-other .repl-studio-file-name {
5259
+ color: var(--accent);
5260
+ text-decoration: underline;
5261
+ }
5262
+
5263
+ .repl-studio-file-format {
5264
+ padding: 1px 5px;
5265
+ border: 1px solid var(--panel-border);
5266
+ border-radius: 4px;
5267
+ color: var(--muted);
5268
+ font: 600 11px/1.4 var(--font-ui);
5269
+ }
5270
+
5125
5271
  .repl-journal-card-header,
5126
5272
  .repl-journal-section,
5127
5273
  .repl-journal-label,
package/index.ts CHANGED
@@ -62,6 +62,8 @@ import {
62
62
  buildStudioReplDeadPaneCloseArgs,
63
63
  isStudioGnuplotSession,
64
64
  isStudioReplReadyLine,
65
+ parseStudioReplPaneCwd,
66
+ STUDIO_REPL_PANE_CWD_FORMAT,
65
67
  STUDIO_REPL_PANE_FORMAT,
66
68
  STUDIO_REPL_SESSION_NAME,
67
69
  studioReplSessionTarget,
@@ -100,6 +102,13 @@ import {
100
102
  replEntryVersion,
101
103
  resetReplActivityState,
102
104
  } from "./shared/studio-repl-activity.js";
105
+ import {
106
+ createStudioReplFileRoutes,
107
+ openStudioReplFileRoute,
108
+ resolveStudioReplFiles,
109
+ STUDIO_REPL_FILE_ENTRIES,
110
+ studioReplSessionRunBounds,
111
+ } from "./shared/studio-repl-files.js";
103
112
  import {
104
113
  createReplSubmissionDisplay,
105
114
  normalizeReplSubmissionEchoMode,
@@ -8246,6 +8255,19 @@ function respondStudioDirectoryGrantRequiredJson(res: ServerResponse, error: Stu
8246
8255
  });
8247
8256
  }
8248
8257
 
8258
+ // An inline Content-Disposition for any file name: an ASCII fallback, and the name itself as
8259
+ // UTF-8 (RFC 6266), since Node refuses a header with characters such as Δ or 測 (Sol, Astra, c116).
8260
+ function studioInlineContentDisposition(name: string, fallback: string): string {
8261
+ const ascii = name.replace(/[^\x20-\x7e]/g, "_").replace(/[;"\\]/g, "_").trim() || fallback;
8262
+ let encoded = "";
8263
+ try {
8264
+ encoded = encodeURIComponent(name).replace(/['()*]/g, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
8265
+ } catch {
8266
+ // A name that isn't well-formed Unicode keeps only its fallback.
8267
+ }
8268
+ return encoded && encoded !== ascii ? `inline; filename="${ascii}"; filename*=UTF-8''${encoded}` : `inline; filename="${ascii}"`;
8269
+ }
8270
+
8249
8271
  function respondPdfFile(req: IncomingMessage, res: ServerResponse, filePath: string): void {
8250
8272
  const method = (req.method ?? "GET").toUpperCase();
8251
8273
  if (method !== "GET" && method !== "HEAD") {
@@ -8263,7 +8285,7 @@ function respondPdfFile(req: IncomingMessage, res: ServerResponse, filePath: str
8263
8285
  ].map((value) => Number(value).toString(16)).join("-")}"`;
8264
8286
  const commonHeaders = {
8265
8287
  "Content-Type": "application/pdf",
8266
- "Content-Disposition": `inline; filename="${basename(filePath).replace(/["\\]/g, "") || "document.pdf"}"`,
8288
+ "Content-Disposition": studioInlineContentDisposition(basename(filePath), "document.pdf"),
8267
8289
  "Referrer-Policy": "no-referrer",
8268
8290
  "Cache-Control": "no-store",
8269
8291
  "X-Content-Type-Options": "nosniff",
@@ -8299,6 +8321,24 @@ function respondHtmlPreviewResourceJson(req: IncomingMessage, res: ServerRespons
8299
8321
  });
8300
8322
  }
8301
8323
 
8324
+ // An image a REPL record entry names, as itself, for the pane's thumbnail and the image viewer.
8325
+ // Opened on its own, an SVG can't run scripts or load other files: the page is sandboxed.
8326
+ function respondStudioReplFileImage(req: IncomingMessage, res: ServerResponse, filePath: string, mimeType: string): void {
8327
+ const method = (req.method ?? "GET").toUpperCase();
8328
+ if (method !== "GET" && method !== "HEAD") { res.setHeader("Allow", "GET, HEAD"); respondText(res, 405, "Use GET or HEAD."); return; }
8329
+ const image = method === "HEAD" ? undefined : readFileSync(filePath);
8330
+ res.writeHead(200, {
8331
+ "Content-Type": mimeType,
8332
+ "Content-Length": String(image ? image.length : statSync(filePath).size),
8333
+ "Cache-Control": "no-store",
8334
+ "X-Content-Type-Options": "nosniff",
8335
+ "Referrer-Policy": "no-referrer",
8336
+ "Cross-Origin-Resource-Policy": "same-origin",
8337
+ "Content-Security-Policy": "sandbox; default-src 'none'; img-src data:; style-src 'unsafe-inline'",
8338
+ });
8339
+ res.end(image);
8340
+ }
8341
+
8302
8342
  function respondStudioReadOnlyImage(req: IncomingMessage, res: ServerResponse, filePath: string, mimeType: string): void {
8303
8343
  const method = (req.method ?? "GET").toUpperCase();
8304
8344
  if (method !== "GET" && method !== "HEAD") { res.setHeader("Allow", "GET, HEAD"); respondText(res, 405, "Use GET or HEAD."); return; }
@@ -10229,15 +10269,18 @@ function parseStudioReplJournalEntryInput(value: unknown): Partial<StudioReplJou
10229
10269
  const prose = typeof entry.prose === "string" ? entry.prose.slice(0, 80_000) : "";
10230
10270
  const output = typeof entry.output === "string" ? entry.output.slice(0, 200_000) : "";
10231
10271
  if (!code.trim() && !prose.trim() && !output.trim()) return null;
10272
+ // The request ID as it's kept, which decides whether the label is a person's name (Sol).
10273
+ const requestId = typeof entry.requestId === "string" ? entry.requestId.slice(0, 300) : undefined;
10232
10274
  return {
10233
10275
  id: typeof entry.id === "string" ? entry.id.slice(0, 240) : undefined,
10234
- requestId: typeof entry.requestId === "string" ? entry.requestId.slice(0, 300) : undefined,
10276
+ requestId,
10235
10277
  createdAt: typeof entry.createdAt === "number" && Number.isFinite(entry.createdAt) ? entry.createdAt : undefined,
10236
10278
  updatedAt: typeof entry.updatedAt === "number" && Number.isFinite(entry.updatedAt) ? entry.updatedAt : undefined,
10237
10279
  completedAt: typeof entry.completedAt === "number" && Number.isFinite(entry.completedAt) ? entry.completedAt : null,
10238
10280
  runtime: normalizeStudioReplRuntime(entry.runtime) || "unknown",
10239
10281
  origin: entry.origin === "pi-repl" ? "pi-repl" : "pi-studio",
10240
- label: typeof entry.label === "string" ? entry.label.slice(0, 240) : undefined,
10282
+ // A person's name is checked as sent (checkStudioReplPersonEntry), so cutting it can't make it usable (Sol, Astra).
10283
+ label: typeof entry.label === "string" ? (isStudioReplPersonRequestId(requestId) ? entry.label : entry.label.slice(0, 240)) : undefined,
10241
10284
  mode: normalizeStudioReplJournalMode(entry.mode),
10242
10285
  prose,
10243
10286
  code,
@@ -10247,12 +10290,16 @@ function parseStudioReplJournalEntryInput(value: unknown): Partial<StudioReplJou
10247
10290
  };
10248
10291
  }
10249
10292
 
10293
+ // Whether a request ID is under Studio's person prefix (studio:send:, studio:note:), read as the
10294
+ // shared record will keep it, without line breaks or NULs and trimmed (Sol).
10295
+ function isStudioReplPersonRequestId(requestId: unknown): boolean {
10296
+ return typeof requestId === "string" && requestId.replace(/[\r\n\0]+/g, "").trim().startsWith("studio:");
10297
+ }
10298
+
10250
10299
  // A note under Studio's person prefix (studio:note:) records a name as its label, checked
10251
- // as pi-repl checks names. An unusable one is an error, so it isn't shown as a name. The
10252
- // request ID is read as the shared record will keep it, without line breaks or NULs and
10253
- // trimmed (Sol).
10300
+ // as pi-repl checks names. An unusable one is an error, so it isn't shown as a name.
10254
10301
  function checkStudioReplPersonEntry(entry: Partial<StudioReplJournalEntry>): { entry: Partial<StudioReplJournalEntry>; error?: string } {
10255
- if (!String(entry.requestId || "").replace(/[\r\n\0]+/g, "").trim().startsWith("studio:")) return { entry };
10302
+ if (!isStudioReplPersonRequestId(entry.requestId)) return { entry };
10256
10303
  const person = validatePersonName(entry.label);
10257
10304
  return person.error ? { entry, error: person.error } : { entry: { ...entry, label: person.name } };
10258
10305
  }
@@ -12380,7 +12427,16 @@ function buildStudioReplSubmissionLine(runtime: StudioReplRuntime, sourceFile: s
12380
12427
  if (runtime === "octave" || runtime === "matlab") return `eval(fileread(${mStringLiteral(sourceFile)}));`;
12381
12428
  if (runtime === "gnuplot") return buildGnuplotSubmissionLine(sourceFile);
12382
12429
  if (runtime === "cpp") return cppInclude(sourceFile);
12383
- if (runtime === "shell") return `. ${shellQuote(sourceFile)}; touch ${shellQuote(doneFile)}`;
12430
+ // zsh ends the whole command line when Ctrl+C stops a command in the code, so there the done
12431
+ // file is written in an always block, which runs however the code ends; bash goes on to the
12432
+ // end of the file and to the touch. The shell that reads the line chooses, since a pane's
12433
+ // foreground command can be a child that won't read it (Sol). zsh's form is in eval, which
12434
+ // other shells don't parse, and keeps its separators for sh emulation (Sol).
12435
+ if (runtime === "shell") {
12436
+ return `__pi_studio_source=${shellQuote(sourceFile)}; __pi_studio_done=${shellQuote(doneFile)}; `
12437
+ + `case "\${ZSH_VERSION-}" in "") . "$__pi_studio_source"; touch "$__pi_studio_done";; `
12438
+ + `*) eval '{ . "$__pi_studio_source"; } always { touch "$__pi_studio_done"; }';; esac`;
12439
+ }
12384
12440
  return `exec(open(${quotedPath}, encoding="utf-8").read(), globals())`;
12385
12441
  }
12386
12442
 
@@ -12740,6 +12796,11 @@ function recordStudioReplJournalEntry(
12740
12796
  }
12741
12797
 
12742
12798
  function getStudioReplJournalEntries(sessionName: string | null | undefined): StudioReplJournalEntry[] {
12799
+ return readStudioReplJournal(sessionName).entries;
12800
+ }
12801
+
12802
+ /** A session's record entries, or every session's, with the sessions they were read from. */
12803
+ function readStudioReplJournal(sessionName: string | null | undefined): { entries: StudioReplJournalEntry[]; sessions: StudioReplSessionInfo[] } {
12743
12804
  const normalizedSessionName = String(sessionName || "").trim();
12744
12805
  const sessions = normalizedSessionName
12745
12806
  ? [inspectStudioReplSession(normalizedSessionName)].filter((session): session is StudioReplSessionInfo => Boolean(session))
@@ -12772,10 +12833,60 @@ function getStudioReplJournalEntries(sessionName: string | null | undefined): St
12772
12833
  const entries = (normalizedSessionName
12773
12834
  ? studioReplJournalEntries.filter((entry) => entry.sessionName === normalizedSessionName)
12774
12835
  : studioReplJournalEntries).filter((entry) => !refused.has(entry.sessionName));
12775
- return entries.slice(-STUDIO_REPL_JOURNAL_MAX_ENTRIES).map((entry) => ({
12776
- ...entry,
12777
- sharedSynced: !studioReplUnsyncedJournalEntryIds.has(entry.id) && entry.sharedSynced === true,
12778
- }));
12836
+ return {
12837
+ entries: entries.slice(-STUDIO_REPL_JOURNAL_MAX_ENTRIES).map((entry) => ({
12838
+ ...entry,
12839
+ sharedSynced: !studioReplUnsyncedJournalEntryIds.has(entry.id) && entry.sharedSynced === true,
12840
+ })),
12841
+ sessions,
12842
+ };
12843
+ }
12844
+
12845
+ type StudioReplFileRoutes = ReturnType<typeof createStudioReplFileRoutes>;
12846
+
12847
+ // A pane's current directory, asked of tmux by pane ID (studio-repl-tmux.js says why not in the listing).
12848
+ function readStudioReplPaneCwd(paneId: string): string | undefined {
12849
+ if (!/^%\d+$/.test(paneId)) return undefined;
12850
+ const result = runStudioTmux(["display-message", "-p", "-t", paneId, STUDIO_REPL_PANE_CWD_FORMAT], { timeout: 3_000 });
12851
+ return result.ok ? parseStudioReplPaneCwd(result.stdout) || undefined : undefined;
12852
+ }
12853
+
12854
+ /**
12855
+ * Entries for the page, each of a session's latest STUDIO_REPL_FILE_ENTRIES with the image and
12856
+ * PDF files it names (studio-repl-files.js): `{ id, written, image, v }`, `id` naming its route
12857
+ * and `v` the file's version. A relative path resolves against the session's first pane's
12858
+ * current directory, asked of tmux once a session and only when an entry needs it.
12859
+ */
12860
+ function attachStudioReplEntryFiles(entries: StudioReplJournalEntry[], sessions: StudioReplSessionInfo[], routes: StudioReplFileRoutes | undefined) {
12861
+ if (!routes) return entries;
12862
+ const panes = new Map(sessions.map((session) => [session.sessionName, session.target]));
12863
+ const cwds = new Map<string, string | undefined>();
12864
+ const cwdOf = (sessionName: string) => () => {
12865
+ if (!cwds.has(sessionName)) {
12866
+ const paneId = panes.get(sessionName);
12867
+ cwds.set(sessionName, paneId ? readStudioReplPaneCwd(paneId) : undefined);
12868
+ }
12869
+ return cwds.get(sessionName);
12870
+ };
12871
+ // Each entry's own turn in its session, so a file the next one wrote isn't this one's.
12872
+ const bounds = studioReplSessionRunBounds(entries);
12873
+ const looked = new Set<string>();
12874
+ const counts = new Map<string, number>();
12875
+ for (let index = entries.length - 1; index >= 0; index--) {
12876
+ const sessionName = entries[index].sessionName;
12877
+ const count = counts.get(sessionName) ?? 0;
12878
+ if (count >= STUDIO_REPL_FILE_ENTRIES) continue;
12879
+ counts.set(sessionName, count + 1);
12880
+ looked.add(entries[index].id);
12881
+ }
12882
+ return entries.map((entry) => {
12883
+ if (!looked.has(entry.id)) return entry;
12884
+ const files = resolveStudioReplFiles(entry, cwdOf(entry.sessionName), { bounds: bounds.get(entry.id) });
12885
+ return files.length ? {
12886
+ ...entry,
12887
+ files: files.map((file) => ({ id: routes.add(file), written: file.written, image: file.contentType !== "application/pdf", v: file.version })),
12888
+ } : entry;
12889
+ });
12779
12890
  }
12780
12891
 
12781
12892
  function updateStudioReplJournalEntryOutput(
@@ -12996,6 +13107,8 @@ type StudioReplActivityObservation =
12996
13107
  record: Awaited<ReturnType<typeof readReplRecordInert>> & {};
12997
13108
  runtime: string;
12998
13109
  runtimeLabel: string;
13110
+ // No record-directory key yet: this may not be the record other clients use (P0).
13111
+ unverified: boolean;
12999
13112
  }
13000
13113
  | { sessionName: string; ok: false; problem?: string };
13001
13114
 
@@ -13016,9 +13129,10 @@ async function observeStudioReplActivity(sessionNames: string[]): Promise<Studio
13016
13129
  if (!pane || pane.sessionName !== sessionName || !isValidReplSessionRecordId(pane.recordId)) return null;
13017
13130
  const identity = { recordId: pane.recordId, tmuxSessionId: pane.sessionId, tmuxSessionCreatedAt: Math.max(0, Math.floor(Number(pane.createdAt) || 0)) };
13018
13131
  let record: Awaited<ReturnType<typeof readReplRecordInert>>;
13132
+ let state: ReturnType<typeof classifyReplSessionRecordRoot>;
13019
13133
  try {
13020
13134
  // Only a record in the directory the session's key names, or one with no key yet (P0).
13021
- const state = classifyReplSessionRecordRoot(pane.rootKey || undefined);
13135
+ state = classifyReplSessionRecordRoot(pane.rootKey || undefined);
13022
13136
  if (state === "different" || state === "malformed") return { sessionName, ok: false, problem: studioReplRecordRootRefusal(state, sessionName) };
13023
13137
  record = await readReplRecordInert(getReplSessionRecordPath(pane.recordId), { ...identity, sessionName });
13024
13138
  } catch (error) {
@@ -13026,7 +13140,7 @@ async function observeStudioReplActivity(sessionNames: string[]): Promise<Studio
13026
13140
  }
13027
13141
  if (!record) return null;
13028
13142
  const runtime = normalizeStudioReplRuntime(pane.runtime) || inferStudioReplSessionRuntime(sessionName).runtime;
13029
- return { sessionName, ok: true, identity, record, runtime, runtimeLabel: runtime === "unknown" ? "unknown runtime" : STUDIO_REPL_RUNTIME_LABELS[runtime] };
13143
+ return { sessionName, ok: true, identity, record, runtime, runtimeLabel: runtime === "unknown" ? "unknown runtime" : STUDIO_REPL_RUNTIME_LABELS[runtime], unverified: state === "unverified" };
13030
13144
  };
13031
13145
  try {
13032
13146
  const observed = await Promise.all(sessionNames.map((sessionName) => Promise.race([
@@ -14077,6 +14191,19 @@ ${cssVarsBlock}
14077
14191
 
14078
14192
  export default function (pi: ExtensionAPI) {
14079
14193
  let serverState: StudioServerState | null = null;
14194
+ // Routes for the files the REPL pane shows, made anew for each server's token.
14195
+ let studioReplFiles: { token: string; routes: StudioReplFileRoutes } | null = null;
14196
+ const getStudioReplFileRoutes = (): StudioReplFileRoutes | undefined => {
14197
+ const token = serverState?.token;
14198
+ if (!token) return undefined;
14199
+ if (studioReplFiles?.token !== token) studioReplFiles = { token, routes: createStudioReplFileRoutes(token) };
14200
+ return studioReplFiles.routes;
14201
+ };
14202
+ // Record entries as the page gets them, with the files they name.
14203
+ const getStudioReplPageEntries = (sessionName: string | null | undefined): StudioReplJournalEntry[] => {
14204
+ const { entries, sessions } = readStudioReplJournal(sessionName);
14205
+ return attachStudioReplEntryFiles(entries, sessions, getStudioReplFileRoutes());
14206
+ };
14080
14207
  const studioWorkspaceStateStore = createStudioWorkspaceStateStore();
14081
14208
  // Hosting-capable unless the env flags turned hosting off; single editor mode doesn't use it.
14082
14209
  const studioBufferStateStore = createStudioBufferServerStore({ legacyState: (id: string) => studioWorkspaceStateStore.get(id),
@@ -14551,7 +14678,7 @@ export default function (pi: ExtensionAPI) {
14551
14678
  sharedSynced: journalEntry.sharedSynced === true,
14552
14679
  completed,
14553
14680
  timedOut: Boolean(sent.controlFiles?.doneFile && !completed),
14554
- journalEntries: getStudioReplJournalEntries(selected.session.sessionName),
14681
+ journalEntries: getStudioReplPageEntries(selected.session.sessionName),
14555
14682
  select,
14556
14683
  ...(select ? {
14557
14684
  session: currentSession,
@@ -15429,7 +15556,7 @@ export default function (pi: ExtensionAPI) {
15429
15556
  activeSessionName: active?.sessionName ?? null,
15430
15557
  activeRuntime: studioReplSelection.runtime,
15431
15558
  shown: studioReplSelection.shown,
15432
- journalEntries: getStudioReplJournalEntries(active?.sessionName ?? null),
15559
+ journalEntries: getStudioReplPageEntries(active?.sessionName ?? null),
15433
15560
  recordActivity: replActivityMode,
15434
15561
  // What the page sends as when it hasn't chosen a name.
15435
15562
  personName: person.name,
@@ -15465,7 +15592,7 @@ export default function (pi: ExtensionAPI) {
15465
15592
  shown: studioReplSelection.shown,
15466
15593
  transcript: captured.transcript,
15467
15594
  capturedAt: Date.now(),
15468
- journalEntries: getStudioReplJournalEntries(captured.session.sessionName),
15595
+ journalEntries: getStudioReplPageEntries(captured.session.sessionName),
15469
15596
  ...extra,
15470
15597
  });
15471
15598
  };
@@ -15480,13 +15607,13 @@ export default function (pi: ExtensionAPI) {
15480
15607
  session: captured.session,
15481
15608
  transcript: captured.transcript,
15482
15609
  capturedAt: Date.now(),
15483
- journalEntries: getStudioReplJournalEntries(captured.session.sessionName),
15610
+ journalEntries: getStudioReplPageEntries(captured.session.sessionName),
15484
15611
  } : {
15485
15612
  type: "repl_capture",
15486
15613
  observation: true,
15487
15614
  sessionName,
15488
15615
  captureError: captured.message,
15489
- journalEntries: getStudioReplJournalEntries(sessionName),
15616
+ journalEntries: getStudioReplPageEntries(sessionName),
15490
15617
  });
15491
15618
  };
15492
15619
 
@@ -15502,7 +15629,7 @@ export default function (pi: ExtensionAPI) {
15502
15629
  sendReplSelectionToClient(client, extra);
15503
15630
  return;
15504
15631
  }
15505
- sendReplStateToClient(client, { journalEntries: getStudioReplJournalEntries(sessionName), ...extra });
15632
+ sendReplStateToClient(client, { journalEntries: getStudioReplPageEntries(sessionName), ...extra });
15506
15633
  };
15507
15634
 
15508
15635
  const emitDebugEvent = (event: string, details?: Record<string, unknown>) => {
@@ -17768,7 +17895,7 @@ export default function (pi: ExtensionAPI) {
17768
17895
  requestId: msg.requestId,
17769
17896
  sessionName: msg.sessionName,
17770
17897
  message: sent.message,
17771
- journalEntries: getStudioReplJournalEntries(msg.sessionName),
17898
+ journalEntries: getStudioReplPageEntries(msg.sessionName),
17772
17899
  });
17773
17900
  const timeoutMs = STUDIO_REPL_SEND_DEFAULT_TIMEOUT_MS;
17774
17901
  let completed = false;
@@ -17855,7 +17982,7 @@ export default function (pi: ExtensionAPI) {
17855
17982
  type: "repl_journal_ack",
17856
17983
  requestId: msg.requestId,
17857
17984
  sessionName: msg.sessionName,
17858
- journalEntries: getStudioReplJournalEntries(msg.sessionName),
17985
+ journalEntries: getStudioReplPageEntries(msg.sessionName),
17859
17986
  });
17860
17987
  } catch (error) {
17861
17988
  sendToClient(client, { type: "error", requestId: msg.requestId, message: error instanceof Error ? error.message : String(error) });
@@ -17885,7 +18012,7 @@ export default function (pi: ExtensionAPI) {
17885
18012
  type: "repl_journal_ack",
17886
18013
  requestId: msg.requestId,
17887
18014
  sessionName: msg.sessionName,
17888
- journalEntries: getStudioReplJournalEntries(msg.sessionName),
18015
+ journalEntries: getStudioReplPageEntries(msg.sessionName),
17889
18016
  });
17890
18017
  } catch (error) {
17891
18018
  sendToClient(client, { type: "error", requestId: msg.requestId, message: error instanceof Error ? error.message : String(error) });
@@ -19911,6 +20038,27 @@ export default function (pi: ExtensionAPI) {
19911
20038
  return;
19912
20039
  }
19913
20040
 
20041
+ // A file a REPL record entry names, by the route the page was given for it.
20042
+ if (requestUrl.pathname === "/repl-file") {
20043
+ const token = requestUrl.searchParams.get("token") ?? "";
20044
+ if (token !== serverState.token) {
20045
+ respondText(res, 403, "Invalid or expired studio token. Re-run /studio.");
20046
+ return;
20047
+ }
20048
+ const opened = openStudioReplFileRoute(getStudioReplFileRoutes()?.get(requestUrl.searchParams.get("id") ?? ""));
20049
+ if (!opened.ok) {
20050
+ respondText(res, opened.status, opened.message);
20051
+ return;
20052
+ }
20053
+ try {
20054
+ if (opened.contentType === "application/pdf") respondPdfFile(req, res, opened.filePath);
20055
+ else respondStudioReplFileImage(req, res, opened.filePath, opened.contentType);
20056
+ } catch {
20057
+ if (!res.headersSent) respondText(res, 404, "Studio couldn't read this file.");
20058
+ }
20059
+ return;
20060
+ }
20061
+
19914
20062
  if (requestUrl.pathname === "/pdf-resource") {
19915
20063
  const token = requestUrl.searchParams.get("token") ?? "";
19916
20064
  if (token !== serverState.token) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-studio",
3
- "version": "0.11.7",
3
+ "version": "0.11.9",
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",
@@ -1,6 +1,6 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
2
  import { lstat, readFile } from "node:fs/promises";
3
- import { isValidReplSessionRecordId, normalizeReplSessionRecordEntry, REPL_SESSION_RECORD_MAX_BYTES, REPL_SESSION_RECORD_PROTOCOL, REPL_SESSION_RECORD_VERSION } from "./repl-session-record.js";
3
+ import { describeReplSessionRecordRoot, isValidReplSessionRecordId, normalizeReplSessionRecordEntry, REPL_SESSION_RECORD_MAX_BYTES, REPL_SESSION_RECORD_PROTOCOL, REPL_SESSION_RECORD_VERSION } from "./repl-session-record.js";
4
4
 
5
5
  /*
6
6
  * What Studio's agent is told of shared REPL record entries it hasn't been shown: at the start
@@ -261,6 +261,9 @@ function describeObservedSession(state, observed, exclude) {
261
261
  if (known?.considered === version) continue;
262
262
  session.candidates.push({ entry, version, session, updated: Boolean(known?.told) });
263
263
  }
264
+ // A record from a session with no record-directory key yet says so with its entries, not on
265
+ // its own: it would otherwise be told at every look (pi-repl's P0).
266
+ if (observed.unverified && session.candidates.length) notes.push(describeReplSessionRecordRoot("unverified", name));
264
267
  return session;
265
268
  }
266
269
 
@@ -269,7 +272,7 @@ const sessionBlock = (session) => [session.heading, ...session.notes].join("\n\n
269
272
  /**
270
273
  * The report for these observations, and what to mark once it reaches the model. Each
271
274
  * observation is a session that was checked: `{ sessionName, runtime, runtimeLabel, ok: true,
272
- * identity, record }`, or `{ sessionName, ok: false, problem? }` when it couldn't be checked in
275
+ * identity, record, unverified? }`, or `{ sessionName, ok: false, problem? }` when it couldn't be checked in
273
276
  * time, or its record couldn't be read. Entries in `exclude` (the agent's own send) aren't
274
277
  * reported; `own` marks them as told once the text of their own result reaches the model.
275
278
  *