You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(mobile): edit and save workspace text files from the Files preview - #51241
On the phone you could read a project's files but not change them. Now a text file in the Files preview has an Edit button. You type, tap Save, and the file on your computer changes. If someone changed the same file on the computer since you opened it, the phone doesn't overwrite it: it tells you and lets you reload the newer version or overwrite it on purpose.
Files
Added
Deleted
Net
Test
1
$\color{#1a7f37}{\Huge{\mathbf{+}}}$19
0
$\color{#1a7f37}{\Huge{\mathbf{+}}}$19
Prod
19
$\color{#1a7f37}{\Huge{\mathbf{+}}}$864
$\color{#cf222e}{\Huge{\mathbf{−}}}$226
$\color{#1a7f37}{\Huge{\mathbf{+}}}$638
What Changed
Before: the Files preview could edit only files an agent printed in a terminal. Workspace files (README, .env, source) were read-only on the phone.
After: a workspace text file shows a pencil in the top bar when its host supports phone writes. Tapping it opens the same editor terminal files use. Save is in the top bar. If disk changed since the file was loaded, a bar at the bottom says "Changed on desktop" (or "Deleted on desktop") with Reload (drop my edits, load disk) and Overwrite (write my edits over the newer file). Files the phone can't round-trip stay read-only: over 512 KB (shown truncated), binary, or not valid UTF-8.
Mechanism:
The phone saves through the host's existing files.writeIfUnchanged, passing the signature of the text it loaded. The host compares disk at write time, so a change made after the phone loaded the file is refused, never overwritten. requireLosslessUtf8 makes the host refuse files whose bytes aren't UTF-8.
Overwrite re-reads disk and writes with that new signature, so a third change made in between is still refused. A deleted file is recreated only when the user taps Overwrite.
The page edits in a <textarea>, which turns every CRLF into LF. The phone now edits LF text and writes the file back with its own dominant line ending, as the desktop editor does. This also fixes terminal-artifact saves, which flattened CRLF files.
files.writeIfUnchanged is added to the phone allowlist on the execution-host route, and hosts advertise files.mobile-write-if-unchanged.v1. The phone shows Edit only when the route's host has it, and on a relayed server only when the desktop relaying it has it too.
The draft store that keeps unsaved edits across a page kill now holds at most one queued write and one queued read behind a stalled store call, encodes a document draft once per write, and drops a closed document's clean record once its reads and writes settle. Opening many files no longer leaves a record per file.
Why
The host already had the right primitive: desktop's editor saves remote files through files.writeIfUnchanged, which compares disk at write time. The phone only lacked permission to call it and a way to know a host accepts it. Reusing it means the phone and desktop share one conflict rule, with no phone copy of it. A phone-side read-then-compare (what terminal artifacts do) leaves a window between the read and the write; the host-side precondition does not.
Desktop's conflict banner offers Reload or keep-my-edits; the phone's bar offers the same two choices in its existing floating-bar style. Line endings follow the desktop editor: one ending per file, the dominant one.
#17580 asks for an edit action on previewed workspace files; this adds editing in place in the preview rather than opening a separate editor tab.
Visual Proof
iOS simulator, Orca 0.0.71 shell, page and host built from this branch (before: page built from main).
Before
After
Dark
Light
Editing (dark), and a save refused because the file changed on the desktop meanwhile (dark and light):
Editing
Conflict, dark
Conflict, light
Disk after Save kept the file's CRLF endings; after the conflict, disk still held the desktop's text until Overwrite.
The conflict as merged: it names the computer whose copy changed, and Reload asks before dropping the phone's draft (Cancel keeps it, Discard loads the latest; Overwrite is unchanged).
Conflict
Reload asks first
Dark
Light
Testing
Phone → desktop → runtime: server, with a throwaway e2e spec on real processes: save over loaded text (CRLF kept on disk), a disk change refused as changed with disk untouched, Overwrite after a re-read, a deleted file refused as missing then recreated, a non-UTF-8 file refused as not-utf8 with its bytes unchanged, and both the server and the relaying desktop advertising the capability.
iOS simulator against a headless serve built from this branch: local git workspace and folder workspace, edit and save, concurrent change refused with Reload / Overwrite, light and dark.
Draft store, real code with a stalled backend: 40 typing pauses behind one stalled write produce two writes (first and latest), 750 loads behind a stalled read produce one read, and a closed clean document's row and slot are released once they settle (and not when reopened first).
mobile-file-preview-line-endings.test.ts covers the line-ending round trip; it fails if the save stops restoring CRLF.
pnpm check:changed passes. Tested on macOS hosts; Windows hosts are covered by the CRLF handling and the host's existing path authorization.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
None at fleet scale, because every new cost is tied to a person tapping or typing on the phone. A save is one request (the write fence is fixed, so no ownership lookups). Opening a file costs one draft-store read and no write when nothing changed. Typing persists at most one draft write per 250 ms pause, and a stalled store keeps one queued write and one queued read instead of one per pause. Closed files no longer leave a draft record behind.
Risk
The riskiest part is writing user files from the phone. The host refuses any save whose disk content differs from what the phone loaded, so the worst case is a refused save with the draft kept. Older hosts and older relaying desktops don't advertise the capability, so the phone keeps the preview read-only there. Older phones never call the method. The draft-store changes touch a shared layer also used by Markdown notes and the chat composer; chat drafts keep their current over-cap behavior (the new clear-over-cap mode is opt-in for document drafts). This is an OTA page change plus host allowlist and capability entries; no store build is needed. A plain revert backs it out.
Level: Medium
AI Disclosure
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
SSH workspaces stay read-only on the phone because the phone's file read only serves local routes.
Follow-up, not in this PR: the host's file resolver walks all worktrees once per save (about a millisecond at 7,500 worktrees).
An unsaved terminal-artifact draft left before this update against a CRLF file offers Copy My Edits instead of Restore once.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
I stated the risk: what could break, for whom, and how to back it out
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
The Files preview could edit only terminal artifacts. Workspace files now get an Edit button when the host allows phone writes; Save goes through files.writeIfUnchanged so a newer change on disk is refused and offered as Reload or Overwrite. Saves keep the file's line endings.
The draft rows that keep unsaved edits now hold one queued write behind a stalled store write, encode a draft once per write, and let a closed document's clean row go.
No actionable comments were generated in the recent review.
Walkthrough
Mobile previews now support editing eligible workspace files as well as terminal artifacts. Workspace saves use a guarded write with a disk baseline and report conflicts or errors. The preview flow adds reload and overwrite actions, shared draft and save state, and line-ending conversion. Durable draft rows now track pending work and defer release until operations settle.
Severity of issue fixed: Medium
Merge Risk: Moderate · up to 90889
SSH workspace files may be editable on the phone despite being intended as read-only, and the conflict warning can name the wrong computer. Resolve the SSH gating before merging.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "feat(mobile): edit and save workspace text files from the Files preview" matches the main change: the mobile Files preview gains in-place editing and saving for workspace text files. The ch…
Description check
The description follows the repository template closely. It has an ELI5, a before/after and mechanism under What Changed, a Why section, a linked issue (Fixes #21513), Visual Proof with before/after i…
Linked Issues check
Objective [#21513] (mobile users can edit workspace files such as README.md and .env): Addressed by PR #51241 alone.
Evidence at head 90889d6, from the whole-PR summary (base 35eb7e7): 1. mobile/src/…
The title "feat(mobile): edit and save workspace text files from the Files preview" matches the main change: the mobile Files preview gains in-place editing and saving for workspace text files. The changeset includes the editor, the save hook, the conflict bar, the host write-if-unchanged route, and the capability flag, all in service of that feature. The title is specific and omits only secondary work such as the draft-store changes.
Full details: Description check
Explanation
The description follows the repository template closely. It has an ELI5, a before/after and mechanism under What Changed, a Why section, a linked issue (Fixes #21513), Visual Proof with before/after images, Testing with the checklist items ticked, a Performance section with a one-line justification, a Risk section with level and revert path, and the Notes and Checklist sections. Gaps: the AI Disclosure section is empty, and the Review section is empty. The unchecked box for pnpm lint, typecheck, test, and build is noted as an open item. The template treats AI Disclosure as optional for internal contributors, so its emptiness does not fail the check.
Resolution
Optional: fill in the empty AI Disclosure and Review sections, and either tick the pnpm lint/typecheck/test/build item or confirm CI will cover it.
Full details: Linked Issues check
Explanation
Objective [#21513] (mobile users can edit workspace files such as README.md and .env): Addressed by PR #51241 alone.
Evidence at head 90889d6, from the whole-PR summary (base 35eb7e7):
mobile/src/files/preview/mobile-worktree-file-save.ts adds saveMobileWorktreeFile. It calls files.writeIfUnchanged through worktreeFileGuardedWrite (mobile-file-preview-operations.ts) with the baseline text, the disk signature, and requireLosslessUtf8. It maps results to saved, conflict, or error.
use-mobile-file-preview-save.ts and MobileFilePreviewScreen.tsx provide the editor, the Save action, and MobileFilePreviewConflictBar with Reload and Overwrite. Overwrite re-reads the baseline before it writes.
src/main/runtime/rpc/server/runtime-rpc-mobile-method-routing.ts adds files.writeIfUnchanged to EXECUTION_HOST_METHODS. MOBILE_FILE_WRITE_RUNTIME_CAPABILITY ('files.mobile-write-if-unchanged.v1') is defined in src/shared/file-write/file-write-disk-precondition.ts and added to FILES_RUNTIME_CAPABILITIES. The phone shows Edit only when the host advertises it.
mobile-file-editability helpers accept ready, non-truncated, non-binary UTF-8 text. README.md and .env are UTF-8 text, so they are editable. Files over 512 KB, binary, or non-UTF-8 stay read-only. The PR states this limit. It does not conflict with the issue.
mobile-file-preview-line-endings.ts and its test keep the file's dominant line ending on save.
Stack: PR #51243 is uncertain (no current review evidence). It was not inspected and is not credited. The objective does not depend on it, because PR #51241 establishes the whole objective.
Limit: the routing and capability entries and the editor flow rest on the supplied file summaries. The summaries were not confirmed by direct source reads in this review. Non-coding checklist items were not assessed.
Full details: Out of Scope Changes check
Explanation
The changes map to the scope of #21513.
Editing core: mobile-worktree-file-save.ts, mobile-file-preview-operations.ts, use-mobile-file-preview-save.ts, MobileFilePreviewScreen.tsx, MobileFilePreviewConflictBar.tsx. These implement the requested edit and save flow.
Host allowlist and capability: runtime-rpc-mobile-method-routing.ts, files-runtime-capabilities.ts, file-write-disk-precondition.ts. These let the phone call files.writeIfUnchanged and detect host support.
Line-ending helpers and test: needed so saves preserve CRLF in existing files.
Editability helpers and locale strings: support the editor UI. mobile-file-preview-editability.ts moved from terminal-artifacts and was extended for workspace files.
Draft store changes (durable-draft-rows.ts, document-edit-draft-rows.ts, use-document-edit-draft.ts, DocumentEditDraftOfferBar.tsx): these persist unsaved edits across page kills, which the new edit flow needs. The PR discloses that they touch a layer shared with Markdown notes and chat drafts. The clear-over-cap mode is opt-in for document drafts, and chat drafts keep their current behavior. This is adjacent hardening, not an unrelated change.
Follow-up items (resolver performance) are explicitly deferred and are not in the diff.
No change was found that is unrelated to editing workspace files. Limit: judgment rests on the supplied file summaries.
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
…he conflict
Reload on a refused save now asks "Discard your changes and load the latest?" before throwing the phone's draft away. The conflict line names the computer whose copy changed (the server for a server workspace) and says "Changed since you opened it" when there is no name.
Files skipped from review as they are similar to previous changes: 1
mobile/src/i18n/locales/en.json
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Functional Correctness · Quick win
SSH workspace files can open the editor despite the read-only requirement.
routeWritesFiles does not exclude SSH workspaces. For an SSH workspace, useRouteRelaysCapability returns true because no server context is present. useRouteCapability then returns only the paired host's own capability result. When that host advertises files.mobile-write-if-unchanged.v1, routeWritesFiles is true. For a ready text file from a workspace source, canEdit is then true, and the Edit control opens the editor. Only terminal artifacts check readOnly, so the read-only state of SSH workspace files is not enforced.
The editability check for workspace file sources needs an SSH exclusion. Use the same execution-host classification that the mobile file-mutation path uses for SSH hosts. SSH workspace files should not be editable on mobile, regardless of the host capability.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Functional Correctness · Quick win
Do not name the paired host for an unnamed server workspace.
If the workspace server has no usable name, this returns the paired host's title. However, useWorkspaceClient uses the server client for that workspace. The warning therefore names the wrong computer.
Keep server presence separate from serverName. If a server exists without a name, return null. Preserve the paired-host fallback only for workspaces without a server.
The PR objectives require unnamed wording when the executing computer's name is unavailable.
…write barrier
A file with classic CR line endings saves with CR again. The preview's draft and saved refs are written with their state, so a save that finishes before the next render can't treat a newer draft as saved. A load() that joins a pending read now waits for the queue's tail, so it still settles after writes queued since that read.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
On the phone you could read a project's files but not change them. Now a text file in the Files preview has an Edit button. You type, tap Save, and the file on your computer changes. If someone changed the same file on the computer since you opened it, the phone doesn't overwrite it: it tells you and lets you reload the newer version or overwrite it on purpose.
What Changed
.env, source) were read-only on the phone.files.writeIfUnchanged, passing the signature of the text it loaded. The host compares disk at write time, so a change made after the phone loaded the file is refused, never overwritten.requireLosslessUtf8makes the host refuse files whose bytes aren't UTF-8.<textarea>, which turns every CRLF into LF. The phone now edits LF text and writes the file back with its own dominant line ending, as the desktop editor does. This also fixes terminal-artifact saves, which flattened CRLF files.files.writeIfUnchangedis added to the phone allowlist on the execution-host route, and hosts advertisefiles.mobile-write-if-unchanged.v1. The phone shows Edit only when the route's host has it, and on a relayed server only when the desktop relaying it has it too.Why
The host already had the right primitive: desktop's editor saves remote files through
files.writeIfUnchanged, which compares disk at write time. The phone only lacked permission to call it and a way to know a host accepts it. Reusing it means the phone and desktop share one conflict rule, with no phone copy of it. A phone-side read-then-compare (what terminal artifacts do) leaves a window between the read and the write; the host-side precondition does not.Desktop's conflict banner offers Reload or keep-my-edits; the phone's bar offers the same two choices in its existing floating-bar style. Line endings follow the desktop editor: one ending per file, the dominant one.
Linked Issue
Fixes #21513
#17580 asks for an edit action on previewed workspace files; this adds editing in place in the preview rather than opening a separate editor tab.
Visual Proof
iOS simulator, Orca 0.0.71 shell, page and host built from this branch (before: page built from
main).Editing (dark), and a save refused because the file changed on the desktop meanwhile (dark and light):
Disk after Save kept the file's CRLF endings; after the conflict, disk still held the desktop's text until Overwrite.
The conflict as merged: it names the computer whose copy changed, and Reload asks before dropping the phone's draft (Cancel keeps it, Discard loads the latest; Overwrite is unchanged).
Testing
Phone → desktop →
runtime:server, with a throwaway e2e spec on real processes: save over loaded text (CRLF kept on disk), a disk change refused aschangedwith disk untouched, Overwrite after a re-read, a deleted file refused asmissingthen recreated, a non-UTF-8 file refused asnot-utf8with its bytes unchanged, and both the server and the relaying desktop advertising the capability.iOS simulator against a headless serve built from this branch: local git workspace and folder workspace, edit and save, concurrent change refused with Reload / Overwrite, light and dark.
Draft store, real code with a stalled backend: 40 typing pauses behind one stalled write produce two writes (first and latest), 750 loads behind a stalled read produce one read, and a closed clean document's row and slot are released once they settle (and not when reopened first).
mobile-file-preview-line-endings.test.tscovers the line-ending round trip; it fails if the save stops restoring CRLF.pnpm check:changedpasses. Tested on macOS hosts; Windows hosts are covered by the CRLF handling and the host's existing path authorization.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
None at fleet scale, because every new cost is tied to a person tapping or typing on the phone. A save is one request (the write fence is fixed, so no ownership lookups). Opening a file costs one draft-store read and no write when nothing changed. Typing persists at most one draft write per 250 ms pause, and a stalled store keeps one queued write and one queued read instead of one per pause. Closed files no longer leave a draft record behind.
Risk
The riskiest part is writing user files from the phone. The host refuses any save whose disk content differs from what the phone loaded, so the worst case is a refused save with the draft kept. Older hosts and older relaying desktops don't advertise the capability, so the phone keeps the preview read-only there. Older phones never call the method. The draft-store changes touch a shared layer also used by Markdown notes and the chat composer; chat drafts keep their current over-cap behavior (the new clear-over-cap mode is opt-in for document drafts). This is an OTA page change plus host allowlist and capability entries; no store build is needed. A plain revert backs it out.
Level: Medium
AI Disclosure
Review
Agent skill upstream boundary
Notes
Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)