feat(mobile): attachments go where the workspace lives; render cloud parts and path tags

Draft
SU
15d ago
+2659-836

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 fileId and 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: WorkspaceScreen tells lib/attachments/upload.ts the 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.upload through the relay; the part names attachmentId. A file over MAX_INLINE_ATTACHMENT_BYTES is refused before anything is sent.
    • cloud, and the box reads parts (hostReadsAttachmentParts(hostVersion)): wait for the uploads, attachFiles, then send parts with fileId only. No importFromCloud.
    • cloud on an older box: the old flow (attachFiles + importFromCloud, so the parts have attachmentId).
    • It sends attachments_sent / attachments_send_failed to PostHog with surface and home. The failure event uses rawErrorMessage.
  • Terminal (PTY) attachments: a host workspace now gets base64 filesystem.writeFile into .superset/attachments/ (create-only .gitignore, collision-probed names; lib/attachments/worktreeWrite.ts). A box keeps storage + materializeIntoWorkspace.
  • Rendering: useAttachmentFile takes a source (fileId or attachmentId). A cloud part resolves through attachment.resolveEach and File.downloadFileAsync into the cache, with no box needed. A host part reads through attachments.read as before. Path tags in a message's text show as file cards (name only, nothing fetched).
  • parseAttachmentTags / formatAttachmentTag moved from desktop's ChatSession/utils/attachmentTags into @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), awaitAttachmentUploads now 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's attachments.upload, workspace.get, filesystem.createDirectory and filesystem.writeFile, which exist on every supported host.
  • fileId-only parts go only to boxes at or above ATTACHMENT_PARTS_MIN_HOST_VERSION.

Testing

  • chatParts.test.ts: a cloud part carries fileId and 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/mobile bun test: 237 pass, 0 fail. packages/chat tests pass (97), including the moved attachmentTags test.
  • apps/mobile typecheck: 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/desktop typecheck passes, and the v2-workspace tests (896) pass after the parser move. bun run check:i18n passes, 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.