Skip to content

feat(mobile): preview build files, lockfiles and text data formats - #830

Merged
huichen merged 2 commits into
mainfrom
feat/preview-formats
Sep 25, 2026
Merged

huichen merged 2 commits into
mainfrom
feat/preview-formats

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

Why

The phone decides what it can show from a suffix table plus a fixed MIME map (mobile/src/remote/fileTypes.ts), and the desktop host refuses anything it cannot name (remote_host/files.rs). Two consequences:

  • Anything that identifies itself by name was refused before the transfer even started: Makefile, Dockerfile, .gitignore, Cargo.lock, go.mod, .env.local. A suffix table can never see them.
  • Text the reader can render itself was handed to another app instead (csv, tsv, yaml, xml, jsonl), and a batch of code formats the desktop overlay already reads had no route at all (proto, diff, patch, ndjson, graphql, edn, elm, xhtml, mm, f).

What changed

1. Suffix-less files match on the base name (MOBILE_FILE_NAMES on the phone, CODE_TEXT_NAMES on the host): build entry points (Makefile, Dockerfile, Jenkinsfile, CMakeLists.txt, meson.build, Justfile, Gemfile, Podfile, …), lockfiles and manifests (Cargo.lock, go.mod, go.sum), editor/shell dotfiles (.gitignore, .editorconfig, .npmrc, .bashrc, .envrc, …) and the extension-less licence files (LICENSE, README, CHANGELOG, CODEOWNERS). Names that qualify themselves (Dockerfile.dev, Makefile.am, .env.local) match as prefix / prefix.…. The same rule powers the desktop overlay's own preview list.

2. New formats. .proto, .ipynb (rich JSON reader, since a notebook is one JSON document), .diff, .patch, .ndjson, .graphql, .edn, .elm, .xhtml, .mm, .f, .mk, .cmake, .lock, .plist, .xcconfig, .csproj, .sln, .hcl, .tfvars, .mts, .cts.

3. Text data formats are read in-app — csv / tsv / yaml / yml / xml / jsonl moved from external to the text route, keeping their precise MIME and textFallback so the preview menu can still push them to an installed editor. .html is deliberately unchanged (it still opens in a browser).

4. Two smaller fixes while in there.

  • The type now resolves from the last path segment only, on both sides — a directory that happens to end in a known suffix (notes.md/scratch) no longer classifies the file, and a Windows-style name (C:\w\Makefile) resolves identically.
  • Monospace now follows the file name alone (codeStyleForFile) instead of "a grammar exists". A code or data file Prism/Bundled-Shiki ships no grammar for (Cargo.lock, .csv, meson.build) used to render in the proportional font, which is exactly what makes tabular data unreadable; .txt / .log and the licence files stay prose.

Host-side, this only widens the format gate — file access still goes through ensure_path_allowed, so FutureOS credential files stay blocked, and a file whose bytes are not UTF-8 text still falls back to the exact-original variant (save / share) instead of erroring.

Verification

  • mobile: npx jest --runInBand — 125 suites, 1997 tests pass; tsc --noEmit; eslint on the changed files.
  • desktop: vitest run — 144 files, 1252 tests pass; eslint on the changed files.
  • desktop/src-tauri: cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test --lib remote_host::files (35 tests). The full crate suite passes except instance::tests::excludes_second_owner_and_releases_on_drop, which fails under full-suite parallel load and passes in isolation on this machine (file-lock timing, unrelated to this change).

Tests updated/added on each side assert the name+prefix rule, the new suffixes, the .ipynb size ceiling, the "only the base name decides" rule, and that every mapped suffix and name has a grammar that really colors its source.

Notes for review

  • .env.local / .npmrc style files are now previewable on a paired phone, where they were previously refused outright. .env was already allowed, and a paired phone is a trusted device (it can reach any file through the agent), but this is the one place where the allow-list widening has a security flavour — say the word and I'll drop those two names.
  • Deliberately not in this PR (the long tail from the earlier triage): .pem / .crt / .glsl / .nix / .awk / .sln-style project files of other stacks, template languages (.j2, .erb, .hbs, .ejs, .astro), doc formats (.rst, .adoc, .org) and .mdx. Same mechanism, ~10 lines each, whenever they are wanted.
  • The desktop file-tree icon classification (desktop/src/lib/fileType.ts) still has no notion of these names — a Makefile shows the generic text glyph. Cosmetic, left out to keep the diff on the preview path.

The phone's allow-list was a suffix table plus a fixed MIME map, so anything
that identifies itself by name was refused before the transfer: `Makefile`,
`Dockerfile`, `.gitignore`, `Cargo.lock`, `go.mod`. Text data formats the
reader can render itself (`csv`, `tsv`, `yaml`, `xml`, `jsonl`) were handed to
another app instead, and a batch of code formats the desktop overlay already
reads (`.proto`, `.diff`, `.patch`, `.ndjson`, `.graphql`, `.edn`, `.elm`,
`.xhtml`, `.mm`, `.f`) had no route at all.

- `mobile/src/remote/fileTypes.ts`: match suffix-less files on the whole base
  name (plus `Dockerfile.dev` / `Makefile.am` / `.env.local` style prefixes),
  resolve only the path's last segment, add `.proto` / `.ipynb` (rich JSON) /
  `.diff` / `.patch` / `.ndjson` / `.graphql` / `.edn` / `.elm` / `.xhtml` /
  `.mm` / `.f` / `.mk` / `.cmake` / `.lock` / `.plist` / `.xcconfig` /
  `.csproj` / `.sln` / `.hcl` / `.tfvars` / `.mts` / `.cts`, and move the text
  data formats onto the in-app text route (keeping MIME + `textFallback` so
  the menu can still push them to an installed editor).
- `desktop/src-tauri/src/remote_host/files.rs`: the host carries the same names
  (`CODE_TEXT_NAMES` + prefixes) so it serves exactly what the phone will
  preview, resolves `.ipynb` as JSON, and adds the same suffixes to the text
  list. A name may arrive as a full path, so it is matched on its last segment
  with both platform separators.
- `mobile/src/components/codeHighlight.ts`: grammars by name (`Makefile`,
  `Gemfile`, `.gitignore`, `.bashrc`) and for the new suffixes, and monospace
  now follows the file name alone (`codeStyleForFile`) — `.txt` / `.log` and
  the licence files stay prose, so a code or data file Prism ships no grammar
  for (`Cargo.lock`, `.csv`) still lines up.
- `desktop/src/features/filepreview/previewKind.ts`: the overlay's own list
  gains the same names and an `LANGUAGE_BY_NAME` table, so opening a `Makefile`
  on the desktop is highlighted too.
@huichen
huichen enabled auto-merge (squash) September 25, 2026 10:54
@huichen
huichen merged commit ffd4ab1 into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the feat/preview-formats branch September 25, 2026 11:02
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