Repository navigation
refactor(native-chat): rename the chat visuals folder to the chat scratch folder - #28389
Conversation
A path that doesn't exist yet was authorized by walking up to the nearest existing folder. A dangling symlink fails realpath with ENOENT, so the walk stepped over it and approved the link's own path; the write then followed the link and created its target outside the allowed folders. The walk now continues from the link's target, and returns that real destination.
…atch folder The per-chat folder agents write into is the chat's scratch space, not only a visuals folder. Its root becomes <state>/chat-scratch/<hash> (the hash is unchanged) and the agent variable becomes ORCA_CHAT_SCRATCH_DIR. The old ORCA_CHAT_VISUALS_DIR is never set and is still stripped from what every agent child inherits, Pi included. The visuals skill names the new variable and says the folder is temporary.
…-write' into brennanb2025/cs-rename-chat-scratch
The launch parity snapshot already pins that every agent drops the pre-rename variable.
Following a dangling link by hand resolved relative targets against the lexical parent, not the link's real folder: through a folder link the walk could loop forever or authorize the wrong file. Refuse instead: realpath can't say where a dangling link leads, but a write would follow it.
…-write' into brennanb2025/cs-rename-chat-scratch
…-write' into brennanb2025/cs-rename-chat-scratch
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to
|
ELI5
Each Orca chat gets a private folder where its agent saves the HTML pages it shows inline. The folder and its variable were named "visuals", but the folder is the chat's scratch space and later work also opens, edits and expires files in it. This PR only renames it:
native-chat-visualsbecomeschat-scratch.PR 2 of 6 in the chat-scratch stack. Depends on PR 1 (#28385, never write through a dangling symlink). PR 3 (host serves the scratch folder as a file root) and PR 5 (scratch folders expire after 30 days unused) build on it.
What Changed
The problem. The per-chat folder lived at
<state dir>/native-chat-visuals/<hash>and agents found it throughORCA_CHAT_VISUALS_DIR. The next PRs make it a real folder the user can open, edit and share from, and give it an expiry. Shipping those under a "visuals" name would put the wrong name into a path users see and into what agents are told.User-facing change. Nothing visible yet. One side effect: inline visuals written before this change sit in the old folder, so they show "Visualization unavailable". Native chat has no real users yet, so this only touches dev data.
The one behaviour change beyond the rename: Pi chats no longer inherit the parent's scratch folder. Before, an Orca started from inside another chat passed that chat's folder variable on to every Pi process it launched; Pi gets no folder of its own, so it now drops both the new and the old variable.
Mechanism.
<state dir>/chat-scratch/<first 32 hex of sha256(session id)>. Only the root segment changed; the hash is the same.native-chat-scratch-folder.ts(nativeChatScratchRootFor,nativeChatScratchFolderName,nativeChatScratchFolderFor). Code that renders, delivers or permits visuals keeps its visual names.ORCA_CHAT_SCRATCH_DIR. The oldORCA_CHAT_VISUALS_DIRis never set. It is still removed from what every agent process inherits (Claude, Codex, ACP agents and Pi; on Windows, Claude's strip also ignores letter case, while the others remove the exact upper-case name Orca writes, as on main), because an Orca started from an older chat would otherwise pass that chat's folder on to every agent it launches. Pi gets no folder at all, so both names are removed for it.::orca-visual{file=...}reply line, the skill nameorca-chat-visuals, the packaged plugin folderresources/native-chat-visuals/, folder creation, theme-variable fallbacks, and "a new file name each time".Why
The folder already holds more than visuals once PRs 3–5 land, so "scratch" is the honest name for a temporary per-chat working area, and "scratch" already means a temporary agent area elsewhere in Orca.
Alternatives considered:
chat-storage: "storage" promises keeping things, which contradicts deleting the folder after 30 idle days.agent-session-scratch: matches the otheragent-session-*folders on disk, but the agent-facing variable and skill already say "chat", and the path becomes user-visible in later PRs, so "chat" reads better there.No compatibility code: no alias for the old variable and no reads of the old folder. Old folders only need a way to die, which PR 5 gives them.
Differences from the common pattern: none.
Linked Issue
N/A (maintainer PR, part of the chat-scratch stack).
Visual Proof
N/A: a rename of an internal folder and variable; nothing on screen changes except pre-rename inline visuals now showing "Visualization unavailable".
Testing
Size against PR 1's branch, both measurements:
git diff --numstat(git's default rename detection): production +92 / −66, tests +178 / −126.git diff -M20% --numstat: production +76 / −50, tests +178 / −126.They differ because the moved module (
native-chat-visuals-folder.ts→native-chat-scratch-folder.ts) is only 38% similar (every line names the folder), below git's default 50%, so the default counts it as a whole-file add and delete. The test lines are mechanical renames in existing tests plus the regenerated launch parity snapshot (+90 / −49), where every agent's list of removed variables now names the old one. That puts tests above the plan's ≤45-line estimate and above the production lines; the design panel approved this as an exception for this PR only.Updated the existing launch tests and the launch parity snapshot: every agent's child environment drops both the inherited
ORCA_CHAT_SCRATCH_DIR(when the chat has no folder) and the oldORCA_CHAT_VISUALS_DIR, and Pi now drops both.Native-chat, ACP, Codex, Claude launch, Pi and visual-read test suites pass; node typecheck clean; real Claude CLI tests run.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Agent skill upstream boundary
Notes
Cross-platform: paths built with
path.join; on Windows, Claude's environment strip ignores letter case, while Codex, ACP agents and Pi remove the exact name Orca writes (unchanged from main). SSH/remote: the folder lives on the host that owns the chat, as before. Mobile: unchanged.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)Live QA (M4Air, 2026-10-13)
Hidden Orca rig + a paired headless Orca server on the same Mac, real Claude chats, driven over CDP. Code under test: a local merge of PR 6 (80e42ed) and PR 5 (ec2ac14). All 7 QA rows passed.
<state>/chat-scratch/<32 hex>/fruit-bars-3a9f.html(the folder name is the first 32 hex of sha256 of the session id; nothing was written into the repo), and it renders inline:native-chat-visuals/) shows "Visualization unavailable"; the rest of the chat is unaffected: