feat(mobile): attachments go where the workspace lives; render cloud parts and path tags
Draft
SU
15d ago+2659+2659+0123456789012345678901234567890123456789-836-836-012345678901234567890123456789
Stacked. Draft until its dependencies are merged and released.
- #8704 (now including #8712's
attachment.resolveEach): this branch merges #8704's head.
- #8846 and #8849 (plan PRs 3 and 4): this branch is built on #8849's branch. It needs the relaxed part schema and
hostReadsAttachmentParts.
It does not depend on the desktop PR (#8851). The base is main, so until those merge the diff includes them. This PR's own change is commit bbfa063f22. The API (#8704) must be live before this ships, because rendering a cloud part calls attachment.resolveEach.
Summary
The mobile part of the attachments plan (v6):
- cloud parts carry
fileIdand skip the import call; - the host branch;
- seam 5's cloud branch for rendering;
- path tags shown as badges.
Why
- Mobile uploaded every attachment to our storage when it was attached, then had the host import it, even for a workspace on a machine someone owns. That breaks the plan's goal 2: local images stay off our servers.
- A cloud chat imported every file into the box and sent its host id, so nothing without the box could render it.
- A desktop message's
<attachment path>tags showed as raw text on mobile.
How it works
- Draft home:
WorkspaceScreentellslib/attachments/upload.tsthe home of its workspace draft once the host resolves (setDraftAttachmentHome). A host draft does not upload at attach time. The home-screen draft (NewChatWidget) is unchanged: its host is not chosen yet when files are attached. - Chat send (
lib/attachments/chatParts.ts,chatAttachmentParts):- host: each file is read as base64 and sent with
attachments.uploadthrough the relay; the part namesattachmentId. A file overMAX_INLINE_ATTACHMENT_BYTESis refused before anything is sent. - cloud, and the box reads parts (
hostReadsAttachmentParts(hostVersion)): wait for the uploads,attachFiles, then send parts withfileIdonly. NoimportFromCloud. - cloud on an older box: the old flow (
attachFiles+importFromCloud, so the parts haveattachmentId). - It sends
attachments_sent/attachments_send_failedto PostHog with surface and home. The failure event usesrawErrorMessage.
- host: each file is read as base64 and sent with
- Terminal (PTY) attachments: a host workspace now gets base64
filesystem.writeFileinto.superset/attachments/(create-only.gitignore, collision-probed names;lib/attachments/worktreeWrite.ts). A box keeps storage +materializeIntoWorkspace. - Rendering:
useAttachmentFiletakes asource(fileIdorattachmentId). A cloud part resolves throughattachment.resolveEachandFile.downloadFileAsyncinto the cache, with no box needed. A host part reads throughattachments.readas before. Path tags in a message's text show as file cards (name only, nothing fetched). parseAttachmentTags/formatAttachmentTagmoved from desktop'sChatSession/utils/attachmentTagsinto@superset/chat/core, with their test. Desktop's util index re-exports them, so desktop imports are unchanged.- If a send finds an attachment that never started uploading (attached while the draft's home was unknown),
awaitAttachmentUploadsnow starts it. Before, it failed with "no longer available".
Not in this PR / differs from the plan
- The new-workspace flow (
useCreateTerminalWorkspace, home-screen new chat) still uploads at attach time and imports into the chosen host. The host is not known when files are attached, so a host-workspace launch from the home screen still goes through storage. The plan keeps the modal's cloud branch as it is and does not cover this case for mobile. It is a remaining goal-2 gap. - No Sentry event on a send failure, only PostHog (as on desktop).
- No upload-at-attach for host workspaces, so a large file to a host is read and sent at send time with no progress ring.
tRPC compatibility
- No procedure changes. New client calls:
attachment.resolveEach(API, #8704), and the host'sattachments.upload,workspace.get,filesystem.createDirectoryandfilesystem.writeFile, which exist on every supported host. fileId-only parts go only to boxes at or aboveATTACHMENT_PARTS_MIN_HOST_VERSION.
Testing
chatParts.test.ts: a cloud part carriesfileIdand skips the import; an older box gets the imported copy; a host part goes to the host and never to storage; a host refuses a file over the inline cap before sending.worktreeWrite.test.ts: create-only writes into the worktree, with a suffix around an existing name.apps/mobilebun test: 237 pass, 0 fail.packages/chattests pass (97), including the movedattachmentTagstest.apps/mobiletypecheck: no new errors. The tree has the same baseline errors as main, minus one this PR removes. Many of those baseline errors are "implicitly any" from client types that do not resolve in this sandbox, so mobile typecheck is weaker evidence here than usual.apps/desktoptypecheck passes, and the v2-workspace tests (896) pass after the parser move.bun run check:i18npasses, with translations written for all 16 locales. Biome is clean on the changed files.- Not verified: none of this ran on a simulator or device; this sandbox has no iOS tooling. The plan's manual checks are still open: a photo into a local, a relay-reached and a cloud workspace; desktop and mobile showing each other's images; a cloud image still rendering after its box is recreated.
Known limitations
- A host thumbnail goes back to a card once the host's 30-day sweep removes the file (#8846).
- A box below 1.41.0 still gets imported copies, so its parts render only while the box is alive.