Repository navigation
feat(runtime-files): the host serves a chat's scratch folder as a file root - #28397
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.
…e root File commands accept `path:<this host's chat-scratch root>/<32 hex>` and resolve it only when it names this host's own folder, at the file-commands seam so the selector never reaches chat placement. They authorize against the project roots plus the chat-scratch root, refuse files.open/openDiff for the folder, and agentSession.readVisual's ok results carry the file's absolute path so a client can build the selector.
…-write' into brennanb2025/cs-rename-chat-scratch
…SQLite store, under Node
…-write' into brennanb2025/cs-rename-chat-scratch
… root so only the selector refuses it
…tch' into brennanb2025/cs-host-serves-scratch
…serves-scratch # Conflicts: # src/main/runtime/rpc/methods/structured-agent-session-visual.test.ts
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
47e95a4b-1bb9-415e-8044-9079430aaefe
📒 Files selected for processing: 14
config/scripts/vitest-node-runtime-files.mjssrc/main/ipc/filesystem-auth.tssrc/main/native-chat/native-chat-visual-file-read.test.tssrc/main/native-chat/native-chat-visual-file-read.tssrc/main/runtime/orca-runtime-file-commands.tssrc/main/runtime/orca-runtime-files-terminal-link-host-translation.test.tssrc/main/runtime/rpc/methods/structured-agent-session-visual.test.tssrc/main/runtime/runtime-chat-scratch-file-root.tssrc/main/runtime/runtime-file-command-target.tssrc/main/runtime/runtime-file-commands-assert-remote-terminal-file-grant-path-still-canonical.tssrc/main/runtime/runtime-file-commands-create-file-explorer-dir-no-clobber.tssrc/main/runtime/runtime-file-commands-read-file-explorer-preview.tssrc/main/runtime/runtime-file-commands-terminal-file-paths.tssrc/shared/rpc-contract/agent-session-visual-params.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Bind scratch selectors to the authenticated chat. · runtime-chat-scratch-file-root.ts:30-49
src/main/runtime/runtime-chat-scratch-file-root.ts:30-49
🔒 Security & Privacy | 🟠 Major | 🏗️ Heavy liftBind scratch selectors to the authenticated chat.
agentSession.readVisualreturns the visual's absolute path, and its caller supplies thesessionId. The scratch folder name is a deterministic hash of that ID. A caller can therefore obtain or construct a siblingpath:selector.
resolveChatScratchSelectorFolderchecks only the host root, the 32-hex name, and directory existence. The file-command boundary has no caller-session check. The selector then reaches file reads, writes, previews, directory reads, and watcher setup. One chat can read or modify another chat's scratch files.Pass the authenticated caller session into this boundary and reject selectors that do not resolve to that session's
nativeChatScratchFolderFor(...)folder. Add a sibling-folder regression test.
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
0d971fa2-874d-4225-b7aa-68e0aef33748
📒 Files selected for processing: 1
src/main/runtime/rpc/methods/structured-agent-session-visual.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
…serves-scratch # Conflicts: # src/main/runtime/orca-runtime-file-commands.ts
…serves-scratch # Conflicts: # src/main/runtime/files/file-reads.ts # src/main/runtime/files/file-target.ts # src/main/runtime/files/watch/file-watches.ts # src/main/runtime/runtime-file-commands-create-file-explorer-dir-no-clobber.ts # src/main/runtime/runtime-file-commands-terminal-file-paths.ts
ELI5
Each Orca chat has a private scratch folder on the machine that runs it, where the agent saves the HTML pages it shows inline. Today the app can only show those pages inside the chat; it can't open, edit or preview them like ordinary files, because Orca's file commands only work on workspaces, and the scratch folder isn't one. This PR lets the machine that owns a chat serve that chat's scratch folder through the normal file commands, so the next PR can open a chat visual like any other file.
PR 3 of 6 in the chat-scratch stack. Depends on PR 2 (#28389, the folder is renamed to
chat-scratch), which depends on PR 1 (#28385, never write through a dangling symlink). PR 4 (open a chat visual like any file) builds on this one.What Changed
The problem. To open, edit or preview a file, the app asks the machine that holds it, naming a workspace and a relative path. A chat's scratch folder sits in Orca's own state directory, not in any workspace, so no request could name it, and path authorization would refuse it anyway because it isn't under a project root. The inline visual reader also never said where the file lives, so the app had nothing to point a file command at.
User-facing change. None yet. PR 4 uses this for "Open in new tab", edits saved on the chat's machine, and the document preview of a remote chat's visual.
Mechanism.
path:workspace selector:path:<this machine's chat-scratch folder>/<32-hex folder name>. The machine answers only when that is exactly its own scratch root plus a 32-hex name, and the folder is a real directory, not a symlink. A folder with the same name under some other directory falls through to the normal workspace lookup and fails as an unknown workspace.orca-runtime-file-commands.ts), not in the general workspace resolver. That resolver also decides where a new chat runs, and a scratch folder must never become a chat's workspace. Git, terminals and chat creation never see this selector.resolveRuntimeAuthorizedPath) used where they authorize: the file provider (read, write, stat and so on), preview and chunk reads, the mobile file read, the folder watch and the upload commit. Symlinks that lead out of the scratch folder are refused as they are everywhere else; PR 1 covers dangling links.files.openandfiles.openDifffor a scratch folder fail withchat_scratch_not_openable, because they would hand the desktop a workspace id it has no row for.agentSession.readVisual(the full page, and "unchanged since your copy") now includepath, the file's absolute path on that machine, spelled under the same folder the selector check expects. It is a new optional field on an existing result; nothing else about the call changes.Why
The scratch folder has no workspace row, so something must name it. Reusing the existing
path:selector with an exact equality check keeps it to one branch: no new selector syntax, no new RPC, and no workspace row that other features (Git, terminals, chat placement) would then have to learn to ignore.Alternatives considered:
chat-scratch/<hex>: two different folders with the same ending would map to one name, so a tab could read or save a file other than the one it names. Exact equality with this machine's own folder rules that out.No compatibility code: no capability check and no fallback. An older machine simply omits
path, which PR 4 treats as "can't open".Differences from the common pattern:
Linked Issue
N/A (maintainer PR, part of the chat-scratch stack).
Visual Proof
N/A: plumbing for PR 4; nothing on screen changes.
Testing
One test of the whole contract (
structured-agent-session-visual.test.ts):readVisualreturnspathon both successful answers;path:<its folder>then writes, reads and document-previews the file through the real file commands;files.openis refused; a same-named folder at a different path inside the allowed root is refused by the selector alone; a link from the scratch folder to outside it is refused. Removing the scratch root from authorization makes it fail at the write.orca-ci-checks: 22 of 23 pass; the one failure is the known local-onlytypecheck:ci"Script not found check" (the plain typecheck step passes).Size against PR 2's branch: production +96 / −18 (one of those lines registers the contract test, which opens a real SQLite store, to run under Node), tests +58 / −5.
Agent skill upstream boundary
Notes
path.dirname/path.joinspelling, so Windows and POSIX hosts each match what they themselves returned fromreadVisual.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.