fix(shared): keep OSC 8 hyperlink metadata out of saved notebook previews #45612
main fromrefs/pull/45612/head·opened View on GitHubProblem#
Saved notebook stdout that contains OSC 8 hyperlinks (for example ls --hyperlink=always from GNU coreutils) shows the escape bytes and the link URL around each label in the notebook preview. terminalOutputPlainText strips only CSI sequences, so the complete OSC 8 open and close wrappers stay in the text. Server attachment extraction has a related leak. Node's stripVTControlCharacters turns \u001b]8;;https://example.com/a(b)\u001b\\label into ttps://example.com/a(b)\u001b\\label.
Deterministic repro on origin/main (7985efcbe7a7ec4b8823be257934037f5279c682): open a .ipynb in the file preview with this content:
{"nbformat":4,"nbformat_minor":5,"metadata":{"language_info":{"name":"python"}},"cells":[{"cell_type":"code","source":["!ls --hyperlink=always"],"metadata":{},"outputs":[{"output_type":"stream","name":"stdout","text":["\u001b]8;;https://example.com\u001b\\visible label\u001b]8;;\u001b\\"]}]}]}
- Observed: the output
<pre>shows␛]8;;https://example.com␛\visible label␛]8;;␛\. CallingopenNotebookdirectly on those bytes returns the text unchanged. - Expected: the output shows only
visible label.
For a scenario, select the output by text, not by [data-notebook-output]: NotebookPreview sets that attribute only on HTML outputs, not on text outputs. Find the pre whose textContent includes visible label and assert that its textContent is exactly visible label.
Change#
terminalOutputPlainText now removes complete OSC 8 wrappers ending in BEL or ESC \ before it removes CSI. The pattern does not let the URL part contain C0 or C1 controls. So an opener that CAN, SUB, a newline or a new ESC interrupts is not matched, and no label or later line can be lost. This one helper is used for stream, text/plain and traceback output in the web notebook worker, which serves both web and desktop. The new terminalOutputStripHyperlinks export now runs before Node's VT stripper in the server's notebook text extraction (documentTextWorker.ts), so attachments sent to agents also keep only the label.
Scope#
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification#
- I added regression cases to
packages/shared/src/notebookOutput.test.ts: an ESC \ wrapper, a BEL wrapper with anid=parameter and a following line, and a cancellation guard (an opener interrupted by CAN, and another by a newline, still keeplabelandnext). On base, the two wrapper cases fail (Received: "␛]8;;https://example.com␛\visible label␛]8;;␛\"). On head, all of them pass. All 106 tests interminalOutput.test.ts,notebookOutput.test.tsanddocumentTextWorker.test.tspass. - I added a case to
apps/server/src/provider/documentTextWorker.test.tswith an ESC \ OSC 8 link tohttps://example.com/a(b). On base,extractDocumentTextreturnsttps://example.com/a(b)\label. On head, it returnslabel. vp run check:changedexited 0 on final headff4c5c935534(format, lint, knip, graphql, typecheck for 38 packages, tests for 4 files). The summary is in the gist transcript.- I ran the production
openNotebookon real GNUls --hyperlink=alwaysoutput. Base returns"\u001b]8;;file://…/a.txt\u001b\\a.txt\u001b]8;;\u001b\\\n"and head returns"a.txt\n". Transcript: https://gist.github.com/saphid/e32703d5f23754534378d0f596afffff - Real
NotebookPreviewrendered in Chromium fromopenNotebookoutput (before / after):
| Before (base) | After (head) |
|---|---|
![]() | ![]() |
Not shown: I could not get a vp run scenarios:prove run on this host. Both base and head, and the existing notebook-shows-visible-saved-output scenario, stay on the splash screen before any assertion runs, so the screenshots above come from a browser-mode render of the real NotebookPreview component, not the full file-preview flow. I did not test the desktop Electron shell or mobile separately. Mobile does not preview .ipynb files through this worker.
Authored by Claude Opus 5.5 (Model Hub); reviewed by GPT-6.2 Sol (Codex).
Not shown#
- scripts/scenarios/notebook-shows-visible-saved-output.e2e.ts:32 — The Chromium captures verify the real component, not the full file-open flow. Keep the disclosed splash-screen limitation; when the scenario runner works, seed the OSC 8 fixture and assert that the output pre contains exactly the label.
- packages/shared/src/terminalOutput.ts:1102 — C1 OSC/ST (U+009D/U+009C) still leak on the no-erase notebook path, although the existing line-edit replay recognizes them. This is unchanged from base; limit the PR claim to ESC-prefixed wrappers ending in BEL or ESC-backslash.
- 1
- 2
Pushed9cde089
The automated pipeline stopped on this pull request and will not merge it:
the proof was not accepted:
- The diff fixes two paths: the web/desktop notebook preview (packages/shared/src/terminalOutput.ts) and server attachment extraction (apps/server/src/provider/documentTextWorker.ts). The captures prove only the preview. The server half is stated as part of the bug ('server notebook extraction can also retain URL fragments') and is never shown failing on base.
- 002-server-extracted-agent-text.png before and after are visually identical and both show clean text ('visible label'). They ran on Node v26.13.1, where util.stripVTControlCharacters already removes the OSC 8 wrapper. apps/server/package.json supports node '^22.16 || ^23.11 || >=24.10'. I checked Node v22.23.2 on this VM: stripVTControlCharacters on the scenario input returns 'ttps://example.com/a(b)\u001b\visible label', so the server leak is real on a supported runtime. It was not exercised, so the documentTextWorker change has no before/after evidence. Rerunning the attachment scenario with the server on Node 22 would close this.
- before-web-command-remainder.png / after-web-command-remainder.png and before-ios-command-output.png / after-ios-command-output.png show the same clean output on both commits. They prove no defect and are coverage only (the capture says so too). The terminalOutputSpans remainder path that the diff touches was already clean on base because output is normalized upstream.
- 002-failure.png (base failure) is byte-identical (md5) to the base 001-saved-notebook-output.png, so it adds nothing.
- Minor: the markdown says the recordings 'omit startup', but both webm files open with roughly 6–10 s of T3 splash frames before the app renders.
It stays open for a person to finish or close.
juliusmarminge added labelstakeover:blocked
juliusmarminge removed labelstakeover:in-progress
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes