Skip to content

feat(worker): read, write, delete and open a thread's files - #499

Merged
M-Zajace merged 3 commits into
devfrom
feat/file-access
Nov 10, 2026
Merged

M-Zajace merged 3 commits into
devfrom
feat/file-access

Conversation

@M-Zajace

@M-Zajace M-Zajace commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Stack 2/3 (base: #513). UI: #498.

Summary

  • Worker commands (non-durable, never from the outbox): ReadFile (222), OpenFile (223), WriteFile (224), DeleteFile (225) with FileRequest; result CommandResult.file (FileContent, field 222). Capability thread_files_v1.
  • Gateway RPCs ReadThreadFile, WriteThreadFile, DeleteThreadFile, OpenThreadFile: owner check, relative paths join threads.cwd (@canopy/domain/thread-files), roots = thread directory + the owner's workspaces on that worker. Read/write/delete are served for linked computers (the thread opens from its home); OpenThreadFile is not, so a file never opens in an app on another machine.
  • Worker adds the thread's attachments dir, expands ~, resolves symlinks, accepts only an existing regular file under a root (FILE_OUTSIDE_ROOTS).
  • Read: up to 2 MiB (truncated), non-UTF-8 → binary without content, SHA-256 of the whole file (chunked). Write/delete require expected_sha256 from the read → FILE_CHANGED instead of overwriting another change.
  • OpenFile: open / explorer.exe / xdg-open (shared with reveal).
  • Docs: docs/protocol.md "Folder i pliki wątku".

Tests

  • apps/worker/src/files/thread-files.test.ts (security): outside roots, .. traversal, symlink escape (skipped where symlinks need a privilege), folder, missing file, hash conflicts on write/delete, binary and truncated reads.
  • Typecheck worker/gateway/web and lint clean.

@M-Zajace
M-Zajace marked this pull request as ready for review November 10, 2026 15:57
@M-Zajace
M-Zajace force-pushed the feat/file-access branch 2 times, most recently from 948115c to bf16b88 Compare November 10, 2026 16:12
@M-Zajace
M-Zajace changed the base branch from dev to fix/reveal-folder November 10, 2026 16:12
Base automatically changed from fix/reveal-folder to dev November 10, 2026 16:26
Adds the non-durable worker commands ReadFile, OpenFile, WriteFile and
DeleteFile (capability thread_files_v1) and the owner-scoped gateway RPCs
ReadThreadFile, WriteThreadFile, DeleteThreadFile and OpenThreadFile.
The gateway names the roots (the thread's directory and the owner's
workspaces on its worker); the worker adds the thread's attachments,
resolves symlinks and accepts only a regular file under a root. Reads
return up to 2 MiB with the file's SHA-256; writes and deletes require
the hash from the read, so an edit never overwrites another change.
The worker copies command outputs into CommandResult field by field; file was missing, so reads came back empty and saves had no hash.
@M-Zajace M-Zajace closed this Nov 10, 2026
@M-Zajace M-Zajace reopened this Nov 10, 2026
@M-Zajace
M-Zajace merged commit 39dd1f2 into dev Nov 10, 2026
11 of 18 checks passed
@M-Zajace
M-Zajace deleted the feat/file-access branch November 10, 2026 16:55
nixuuu added a commit that referenced this pull request Nov 12, 2026
nixuuu added a commit that referenced this pull request Nov 12, 2026
nixuuu added a commit that referenced this pull request Nov 12, 2026
Resolve bare names on the home worker, retain bounded binary bytes, and distinguish lookup failures from deleted files.

Fixes: #499

Related: #514
nixuuu added a commit that referenced this pull request Nov 12, 2026
nixuuu added a commit that referenced this pull request Nov 12, 2026
nixuuu added a commit that referenced this pull request Nov 12, 2026
Loading changes path, hash and loading state. Track only the viewer target so those updates cannot trigger another read and keep the dialog loading.

Fixes: #499
nixuuu added a commit that referenced this pull request Nov 12, 2026
Resolve bare names on the home worker, retain bounded binary bytes, and distinguish lookup failures from deleted files.

Fixes: #499

Related: #514
nixuuu added a commit that referenced this pull request Nov 12, 2026
nixuuu added a commit that referenced this pull request Nov 12, 2026
nixuuu added a commit that referenced this pull request Nov 12, 2026
Loading changes path, hash and loading state. Track only the viewer target so those updates cannot trigger another read and keep the dialog loading.

Fixes: #499
nixuuu added a commit that referenced this pull request Nov 12, 2026
Clicking a bare name such as `violet-bg.jpg` previously tried only the
thread's root and reported a missing file as deleted. Binary bytes were
discarded, so images could not load even with a connected home computer.

This change resolves references on the thread's home worker, including a
separate worktree, and previews text and images on web and mobile.

## Behavior

- Prefer explicit paths mentioned in the source item's turn, then a
direct root file, then an exact basename match from a bounded,
gitignore-aware listing. A unique result opens; multiple matches offer a
path picker. An incomplete search never silently chooses a result.
- Keep reads on the existing computer-link stream with 32 KiB frames and
flow control. Preview bytes are capped at 2 MiB; oversized files have no
mutation hash. Offline/transport errors remain connection errors. The
gateway checks thread ownership before dispatch; workspace traversal and
escaping symlinks are rejected.
- Show raster images with dimensions and size. Hide binary Edit, show a
relative path and home computer below the filename, and use lookup/error
states in place of empty content boxes. Reload, edit and delete use the
resolved path and SHA-256 conflict protection.
- Mobile uses the same recognition, resolution and RPCs with existing
native UI components. It supports path choices, image/text/Markdown
previews, reload, copy, text editing and deletion. Failed saves and
reconnects preserve edits; discarding or closing a dirty draft requires
confirmation. No native code, dependencies, EAS configuration or
lockfile changes.
- Add gateway integration coverage through a real WorkerHost and paired
gateways: nested worktree resolution, ambiguous names and selection,
same-turn hints and isolation, ignored/new files, not found versus
disappeared, linked text/image/other binary transfer, the 2 MiB cap,
owner scoping, traversal/outside paths/escaping symlinks, workspace
aliases, mutation conflicts, and offline worker/link errors.

## Validation

Rebased onto `dev` at `f76cfb2a9453a26e3218c553aad8fcb37e9d55e0`.
Generated contracts were regenerated to preserve the base branch's
additive changes. The independent linked-bot test synchronization
correction was extracted to #561; this branch contains no linked-bot
test or production cache changes.

- Local `bun install` and `bun run gen:check` passed. Focused
`TMPDIR=/var/tmp bun test
tests/integration/thread-file-previews.test.ts` passed on the final
rebased head: 11 tests, 75 assertions, no failures. Web typecheck passed
with zero errors/warnings; changed-file oxfmt and oxlint passed. The
full `check:tmp` was intentionally not repeated locally, as requested;
GitHub CI runs the full shards and required static/build checks.
- Real Chromium review used a disposable paired-gateway fixture and real
home WorkerHost. Confirmed bare-name nested resolution, ambiguous
choices and selection, missing versus deleted after Reload, searched
paths, a 320 × 180 JPG with its 977 B size, no image Edit action, and
workspace-relative path plus home computer subtitles. Checked
short/typical/long paths, image and picker at 1280 px and 390 px, light
and dark, with no horizontal overflow or browser exceptions. The shared
browser disconnected, so review continued in isolated local Chromium.
Screenshots were inspected after transitions completed and with reduced
motion. No browser test suite or artifacts are committed.
- The browser check exposed a Svelte effect repeatedly reading the file
after its own loading/path/hash updates. The effect now tracks only the
viewer target and calls `load()` without tracking mutable viewer state.
The repeated review passed. The final rebase leaves the reviewed
file-viewer and mobile-file components unchanged.
- SDK 58 fingerprints generated through `expo-updates
fingerprint:generate` with `CANOPY_CHANNEL=nightly` are identical for
final head and base, using the same repository path and installed
dependencies: iOS `6ddec9ef559ee0095ac33e94ff9418a942053b17`; Android
`5f6eae3ab278f1cd543e9ed763f923a319b65ec9`. No native code,
dependencies, EAS configuration or lockfile changes.

Fresh CI runs on final head `84b1a71365f817cc104d088cf7fb041100aa6686`;
its result is reported independently of earlier passing runs. All
disposable gateways, worker, database and web processes were stopped
after review; local browser sessions were closed.

## Copy audit — docs/copy.md §8

| Before | After | Reason |
| --- | --- | --- |
| “This file no longer exists.” on an unresolved name | “Couldn't find
{name} in this workspace.” with Reload and “Show searched paths” | Does
not claim deletion without a previous read. |
| Same generic missing-file claim after a previous read | “{name} is no
longer at this path. Check whether it was moved or deleted.” | Reports
the evidence without assuming the cause. |
| No disambiguation | “Several files match this name. Choose a path to
open.” | Names the condition and the next action. |
| No bounded-search status | “The search reached its limit. Open a full
workspace-relative path.” | Makes an incomplete search explicit. |
| Empty image box | “Could not show this image. Reload to try again.” |
Gives an action for image-decoder failure. |
| Dropped binary bytes | “This file exceeds the 2 MB preview limit. Open
a smaller file to preview it.” for truncated binaries | Explains the
bounded preview. |
| Filename repeated in title and subtitle | Filename; workspace-relative
path and computer | Each field adds context; root paths include `./`. |
| “Delete…” | “Delete file” → “Delete file?” | Concrete verb/object;
confirmation names the path/computer and says it cannot be undone. |
| No mobile dirty-editor flow | “Unsaved changes”, “Discard unsaved
changes?”, “Discard changes” | Protects edits and states the action. |

Static audit: English, sentence case, plain glossary terms, verb-led
actions, confirmation verbs agree, and errors explain the event and the
next action. Search diagnostics are disclosed under “Show searched
paths”. Empty states are short and use the existing Reload action.
Title/subtitle supply different information. Computer availability is a
named dependency with reconnect/reload guidance. No humor or ornamental
copy was added. States have text independent of color or icons.

Visual copy audit (§8.9): short, typical and long file names/paths
checked in Chromium at desktop and phone widths, in light and dark.
Titles/subtitles wrap within the dialog, path choices stay compact,
errors show accurate copy and searched-path disclosure, and no overlay
gaps or horizontal overflow appeared. Mobile source copy uses the same
shared lookup messages; no native-device visual review is claimed.

Fixes: #499

Related: #514
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant