diffstalkerd 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,343 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [0.11.0] - 2026-08-06
11
+
12
+ ### Added
13
+
14
+ - **Search file contents across the repo** (Ctrl/⌘+Shift+F, or bare `F`), in the
15
+ web UI. Literal text, not a pattern — `git grep -F`, so there is no regex to
16
+ learn and none to hang the daemon. Results group by file with line numbers;
17
+ Enter opens the file in the Explorer scrolled to the matching line. The corpus
18
+ is the same as the file finder's: tracked plus untracked, never gitignored.
19
+ Bounded server-side — 500 results, 20 per file, 4 MiB, 5 seconds — and it says
20
+ when it hit a limit rather than quietly showing you less.
21
+
22
+ - **Better hunk headers for the languages git ships regexes for.** The
23
+ `@@ ... @@ <context>` text names the function a hunk is inside, but git only
24
+ guesses well when a gitattributes file opts the path into one of its built-in
25
+ drivers, which most repos never set up. diffstalker now supplies that default
26
+ itself, at the lowest priority, so a repo's own `.gitattributes` still wins.
27
+ Python goes from `class Widget:` to `def render(self):`; Java from
28
+ `public class Widget {` to `public void render() {`; Ruby, Go, Rust, C#, PHP
29
+ and the rest likewise. **TypeScript, JavaScript and Vue are unaffected** —
30
+ git ships no driver for them, and borrowing another language's does not work.
31
+
32
+ - **`/` narrows the changed-file list, in the web UI.** Type to hide the rows
33
+ you are not looking at; the diff stack narrows with the list, so it also
34
+ shortens the page. It is a filter, not a search: no syntax, no scopes, and it
35
+ only ever hides rows from the set already on screen. The count always names
36
+ its corpus ("4 of 214 changed files"), a filter matching nothing says so
37
+ rather than looking like a clean tree, and the query resets when the repo
38
+ changes under you (follow mode). Esc clears it.
39
+
40
+ - **`e` expands every large diff at once, in the web UI.** A file past 1500
41
+ changed lines starts behind a "Load diff" gate, which also hides it from the
42
+ browser's own find-in-page. One key mounts all of them, so Ctrl+F then
43
+ reaches the whole changeset. It does nothing when nothing is gated.
44
+
45
+ ### Fixed
46
+
47
+ - **A commit no longer dies mid-hook, and a fetch no longer dies mid-transfer.**
48
+ The idle timeout added alongside the funcname drivers applied to every git
49
+ call, including ones that are legitimately silent for a long time: git only
50
+ writes progress to a terminal, so a pre-commit hook running a test suite, or a
51
+ pack being negotiated, looks identical to a hang. Hook-running and remote
52
+ operations now get a much larger budget; local reads keep the short one. Both
53
+ are still bounded.
54
+ - **Content search no longer 500s on a huge matched line, a NUL, a newline, or a
55
+ very long query.** An over-budget result now returns what it found and says it
56
+ is partial; a query git cannot take literally is refused with a clear message
57
+ instead of surfacing as a server error. Searching also no longer needs git
58
+ 2.38 — the per-file cap is counted locally rather than passed to `git grep`.
59
+ - **diffstalker no longer displaces your own global gitattributes.** The
60
+ generated funcname defaults are only injected when you have no per-user
61
+ attributes of your own; previously they took priority over yours and silently
62
+ dropped every rule you had defined, textconv and merge drivers included.
63
+ - **The terminal UI no longer misses a file-list change that lands mid-fetch.**
64
+ A status change arriving while `/files` was in flight was swallowed by the
65
+ reply that overtook it, leaving the finder showing a list that predated it.
66
+ - **`/` is inert in views that have no filter.** It used to set invisible state
67
+ on Journal, History, Compare and Explorer, which then appeared as an
68
+ already-open filter on returning to Changes.
69
+ - **A hung git command can no longer wedge a request forever.** Every git
70
+ invocation now has an idle timeout — 10 seconds for local reads, 10 minutes
71
+ for anything running your hooks or talking to a remote. Without it a stuck
72
+ credential prompt or an unresponsive remote held its queued operation open
73
+ for the life of the process.
74
+ - **Ctrl+C now quits from the file finder too.** It was the one place in the
75
+ terminal UI where the universal exit did nothing: the finder's text input
76
+ takes over the keyboard and swallows control characters, so the app-level
77
+ binding never saw the key.
78
+ - **The terminal UI no longer refetches the whole file list on every watcher
79
+ tick.** A status change now just marks the list stale, and the finder fetches
80
+ it when it opens. On a busy tree that was one round-trip per tick for a list
81
+ nobody was looking at.
82
+ - **Pressing the finder key repeatedly on a slow daemon no longer stacks up
83
+ finder windows.** The modal slot is now claimed before the file list is
84
+ fetched, not after.
85
+ - **A file whose name contains blessed markup no longer corrupts the finder.**
86
+ Result text is escaped before it is drawn.
87
+ - **The version indicator no longer freezes at whatever was true when the tab
88
+ opened.** It was pulled only when the event stream connected, so a tab left
89
+ open on a second monitor — the way this is meant to be used — never asked
90
+ again and kept reporting "up to date" indefinitely. It now re-asks hourly
91
+ while connected, and stops when the stream closes. The daemon still caches
92
+ npm's answer for six hours, so this costs one local request an hour.
93
+ - **A tab now notices when the daemon under it was restarted on a new
94
+ version.** The web UI ships inside the daemon package, so the daemon's own
95
+ version identifies the bundle: when it changes, the page is older than the
96
+ API it is calling and the status bar says so and asks for a reload. It never
97
+ reloads on its own — this is a tool people leave open to keep looking at
98
+ something.
99
+
100
+ ## [0.10.0] - 2026-08-03
101
+
102
+ ### Added
103
+
104
+ - **Images are shown, in the Explorer and in a diff.** A PNG, JPEG or GIF
105
+ opens as a picture on a checkerboard stage instead of the "Binary file"
106
+ note, with its format and pixel size in the header — plus a frame count
107
+ for an animated GIF — and a `1:1` toggle between shrink-to-fit and actual
108
+ size. In Changes, a changed image renders as a fixed-height card with both
109
+ versions, in **Side by side**, **Swipe** or **Onion** mode (pure CSS, no
110
+ canvas); swipe and onion need two pictures of the same shape, so they fall
111
+ back to side by side when the two sides differ in size. The meta line
112
+ carries what the picture cannot: each side's byte size, its short object id
113
+ (or "working tree" for an uncommitted file), the byte delta when both sides
114
+ exist and differ, and a "may be metadata only" hint when the pixel
115
+ dimensions match but the bytes do not — because two identical-looking
116
+ images can differ in EXIF or ICC and a reviewer must never conclude
117
+ "nothing changed" from the picture alone. Web UI only; the terminal UI
118
+ cannot draw pixels.
119
+ - **Two new daemon endpoints, `GET /repos/:id/blob` and
120
+ `GET /repos/:id/media`**, on every listener. `/media` resolves the old and
121
+ new side of a changed image server-side (renames included) and reports
122
+ bytes, object id, dimensions or a refusal code; `/blob` serves the bytes
123
+ themselves, and only to an `<img>` — a browser that names any other fetch
124
+ destination, or a cross-site one, is refused. **Only PNG, JPEG and GIF are
125
+ served, and the content type comes from magic bytes** re-derived from the
126
+ exact buffer being written, on every request — never from the extension, a
127
+ query parameter, or a cached verdict, because a repo file called
128
+ `logo.png` holding `<svg><script>` is same-origin script the moment we
129
+ agree with its name. Everything else gets zero bytes and a refusal. The
130
+ daemon never decodes, transcodes or strips metadata: validation is
131
+ fixed-offset reads and bounded walks, no image library enters the tree, and
132
+ the browser stays the sandbox. The byte cap is checked before a byte is
133
+ read, the pixel and frame caps before a byte is written — 8 MiB (2 MiB for
134
+ GIF), 8192 px per side, 16 MPix, 256 frames — with the pixel budget as the
135
+ real control, since a 300-byte PNG can declare 60000×60000. A GIF is
136
+ charged frame by frame as well as in total: a frame's rectangle may legally
137
+ be bigger than the picture it composites into, and a decoder allocates the
138
+ rectangle. See `packages/daemon/README.md`.
139
+ - **One daemon serves the terminal UI and the browser at once.** `--socket`
140
+ and `--port` are no longer mutually exclusive: the unix socket is the
141
+ daemon's identity and is always bound (unless `--no-socket`), and `--port`
142
+ adds the browser's transport on top. `diffstalkerd --port 7337` therefore
143
+ gives one process, one git state, and one event stream that both clients
144
+ observe — where previously a port bind replaced the socket, the CLI found
145
+ nothing to attach to, and you ended up running two independent daemons
146
+ whose states never agreed.
147
+ - **Least privilege is now decided per listener rather than per daemon.**
148
+ Each transport gets its own routing table over the shared state, graded by
149
+ how well it is protected: a unix socket (or an inherited activation fd) is
150
+ owner-only at the filesystem layer and carries the full API, while a TCP
151
+ port carries the web subset. Commit, discard, hunk staging and every
152
+ remote/branch route are simply absent from a port's routing table, so a
153
+ dual-bound daemon is still safe to point a browser at. `createDaemon({
154
+ apiMode })` still forces one surface onto every listener, for embedders.
155
+ - **A systemd user service**, installed by the Arch package at
156
+ `/usr/lib/systemd/user/diffstalkerd.service` —
157
+ `systemctl --user enable --now diffstalkerd` and the web UI is at
158
+ `http://diffstalker.localhost:7337/`. A user unit, not a system one: the
159
+ socket lives under `$XDG_RUNTIME_DIR` and git runs as the invoking user.
160
+ Not socket-activated, because a cold activated start overruns the CLI's
161
+ 250 ms health probe and the TUI would race it by spawning a second daemon.
162
+ - `--no-socket` (requires `--port`) for a browser-only daemon, and `--port 0`
163
+ to let the kernel choose a free port — the daemon reports the one it got.
164
+ - **`diffstalkerd` takes repo paths on the command line.** `diffstalkerd
165
+ --port 7337 .` now opens that repo before the daemon starts listening, so
166
+ the browser has something to show the moment it connects instead of an
167
+ empty daemon waiting for someone to POST `/repos`. A path is expanded
168
+ (`~`), resolved against the current directory, and reported as it opens; a
169
+ path that will not open stops the daemon with a message rather than leaving
170
+ a half-set-up socket behind.
171
+ - **`--version` (and `-v`) on both commands.** `diffstalkerd --version`
172
+ prints its version; `diffstalker --version` prints its own plus the
173
+ `diffstalkerd` it would spawn and the runtime it is running under — the
174
+ answer to "which install am I actually using" when npm, the AUR package and
175
+ a `bun link` checkout are all on the same machine. It answers before any
176
+ daemon contact, so it still works when nothing can start.
177
+
178
+ ### Changed
179
+
180
+ - **The Explorer no longer browses the git directory.** `GET /repos/:id/file`
181
+ and `/repos/:id/tree` now refuse any path whose normalized form contains a
182
+ `.git` segment (`.git/config`, `./.git/config`, `src/../.git/config`,
183
+ `.GIT/config`, `worktrees/x/.git/config`) and any path whose real location
184
+ lands at or under this repository's **own** absolute git dir — which also
185
+ catches a symlink pointing into it, the git dir of a linked worktree, and a
186
+ submodule's `.git` file. Only those two rules are enforced: a repository
187
+ committed into the working tree under some other name is still browsable,
188
+ because it is tracked repo content, not the git dir of the repo being
189
+ served. `/tree` drops the git directory from listings even with
190
+ `hidden=true`. This was reachable before and served `.git/config`, which
191
+ carries tokens embedded in remote URLs. The segment check runs on
192
+ `path.relative(root, path.resolve(root, rel))`, over every segment, case
193
+ insensitively and with trailing dots and spaces stripped; a check on the
194
+ raw string's first segment misses all four spellings after the first.
195
+ - **`GET /repos/:id/tree?dir=.` is now a 400.** Path validation refuses a
196
+ path whose normalized form is empty, and only `dir=` (the empty string) is
197
+ special-cased as the repository root. The web UI sends the empty string, so
198
+ nothing in it changes; a REST caller that spells the root as `.` — or as
199
+ anything else that normalizes to it, like `src/..` — must send the empty
200
+ string instead.
201
+ - **A large binary in the Explorer reads as "Binary file", not "File too
202
+ large to display".** The 1 MB cap is the *text* cap, so it used to be
203
+ reported for a 2 MB tarball as if a bigger budget would have shown you
204
+ something — but a tarball was never displayable text. Whether a file over
205
+ the cap is binary is now decided by the same NUL scan every other file
206
+ gets, and only a binary one is called binary. Large *text* files are
207
+ unchanged: a 2 MB README still reads as too large, which is the truth
208
+ about it.
209
+ - **Tighter response headers on every daemon response.** The CSP gains
210
+ `frame-src`, `child-src`, `media-src`, `worker-src` and `form-action`, all
211
+ `'none'`, and `Cross-Origin-Resource-Policy: same-origin` is now set. The
212
+ UI has no iframe, no media element, no worker and no form, so spelling them
213
+ out costs nothing and makes a regression that adds one fail loudly.
214
+ `img-src` stays `'self' data:` — deliberately no `blob:`, since a `blob:`
215
+ URL inherits the page's origin.
216
+ - **An unknown option is now an error, not a repo path.** `diffstalker
217
+ --port 7337` used to treat `--port` and `7337` as paths and try to open
218
+ `./7337` as a repository; the failure named a directory you never
219
+ mentioned. Any unrecognized argument starting with `-` now exits 2 with
220
+ `unknown option`, and `--port` in particular says what to do instead (give
221
+ it to `diffstalkerd`). A second repo path is an error too, instead of being
222
+ silently dropped. `--socket` and `--instance` with no value still fail,
223
+ now with the same message shape and exit code as every other usage error
224
+ (2, was 1).
225
+ - **A relative repo path is refused instead of being resolved against the
226
+ wrong directory.** The daemon used to resolve a path like `../foo` against
227
+ **its own** working directory, which is not yours whenever you attach to a
228
+ daemon that was already running — so it opened a different repository, or
229
+ reported "Not a git repository" about a path you never typed. It now
230
+ requires an absolute path and says so. A leading `~` is expanded first, and
231
+ the not-a-repo message names the expanded path, so `~/code/x` no longer
232
+ fails as the literal directory `~`.
233
+
234
+ ### Fixed
235
+
236
+ - **A named pipe in the working tree no longer freezes the daemon.** Opening a
237
+ FIFO blocks until something opens the other end to write, and the working-tree
238
+ watcher opened whatever appeared. Under `bun` that block lands on the main
239
+ thread, so one pipe created inside a watched repo stopped the daemon answering
240
+ anything at all — `/health` included — while it still looked alive. The
241
+ watcher now skips anything that is not a regular file or a directory. Node
242
+ handles the same path without trouble, so a `diffstalkerd` installed from npm
243
+ was never affected; `bun run dev` and `bun run serve` were.
244
+ - **A host name that merely begins with `127.` is no longer taken for
245
+ loopback.** The daemon checks the `Host` header on every request so that a
246
+ name an attacker owns cannot be pointed at the daemon's port and become
247
+ same-origin with it — a DNS rebinding attack, which would hand a visited
248
+ page the whole API. The check tested `startsWith('127.')`, and
249
+ `127.0.0.1.evil.com` starts with `127.`. Only real loopback names are
250
+ accepted now: an address in `127.0.0.0/8`, `::1`, `localhost`, and names
251
+ under `.localhost`. This is pre-existing behaviour in the shipped daemon,
252
+ not something the image endpoints introduced — it was found while reviewing
253
+ them, and it applies to every route.
254
+ - **A 500 no longer tells the browser what git was asked and what it
255
+ answered.** An error no route classified had its message copied into the
256
+ response body, and a failed git call carries the whole command line and
257
+ git's stderr with it — absolute paths, branch and remote names, object ids.
258
+ An unexpected 500 now says only that the request failed; the detail is the
259
+ daemon's to report, not the browser's to read. Deliberate errors are
260
+ unchanged: a 400, 404, 413 or 415 still says exactly what was wrong,
261
+ because the caller needs that.
262
+ - **A renamed file now says where it came from.** `FileEntry.originalPath` was
263
+ declared and read — the terminal file lists have always had an `← old/path`
264
+ suffix for it — but `getStatus` never populated it, so the suffix never
265
+ appeared and the pre-rename blob had no route back. It is now filled from
266
+ git's own rename/copy record on the index side (the working-tree column
267
+ never carries `R` or `C`, so only the staged entry can carry it). This lets
268
+ a renamed image resolve its old side: HEAD has never heard of the new name.
269
+ - **An untracked binary file no longer renders as mojibake.** A newly added
270
+ PNG is the most common image in a diff, and `getDiffForUntracked` read
271
+ every untracked file as UTF-8 and emitted each line as an addition — so it
272
+ arrived as a wall of replacement characters and never reached the binary
273
+ path. Untracked files are now read as bytes and classified by a NUL scan
274
+ (the same test the Explorer uses), and a binary one gets git's own marker,
275
+ `Binary files /dev/null and b/logo.png differ`. Text files are byte-for-byte
276
+ unchanged.
277
+ - **The AUR package now warns before pacman's "exists in filesystem" abort.**
278
+ Installing over a previous `npm install -g diffstalker` fails because npm's
279
+ prefix on Arch is `/usr`, leaving `/usr/bin/diffstalker` owned by no
280
+ package. Nothing in a package can clear that at install time — the
281
+ file-conflict check gates the transaction ahead of every scriptlet and
282
+ hook — so the PKGBUILD checks at build time instead and prints the exact
283
+ remedy, in `prepare()` and again at the end of `package()`. Detects the
284
+ dangling symlink a stale `npm link` leaves behind, which `test -e` alone
285
+ reports as absent.
286
+ - **Line numbers after "" are right again.** The
287
+ marker is git's note about the line above it, not a line of either file,
288
+ but it was counted as one — so every line after it in the hunk was
289
+ numbered one too high on both sides, and in side-by-side view the left and
290
+ right gutters stopped agreeing. It now takes no number and shifts nothing.
291
+ The two versions of a changed last line also stay on one row again, with
292
+ their word-level highlighting, instead of being split apart by the marker
293
+ standing between them; and the marker is shown on the side it is actually
294
+ about, rather than on both, so it no longer claims a missing newline for
295
+ the file that has one.
296
+ - **A `chmod +x` reads as a mode change instead of two lines of file
297
+ content.** `old mode 100644` / `new mode 100755` were not recognized as
298
+ diff headers, so they were rendered as context lines of the file itself,
299
+ numbered from 0. Renames, copies and dissimilarity headers are recognized
300
+ in the same place now — there were two header lists that had drifted apart,
301
+ and there is one.
302
+ - **A file with merge conflicts is marked as conflicted.** An unmerged path
303
+ used to read as an ordinary modify, add or delete, so nothing told you it
304
+ was the file holding up the merge. It now carries its own status: `U` in
305
+ the file lists and the Explorer, in its own colour, in both the browser and
306
+ the terminal. In the browser its stage/unstage button is disabled and says
307
+ why — `git add` on an unmerged path claims a resolution that has not
308
+ happened, and unstaging throws away the conflict stages.
309
+ - **A huge untracked file no longer claims to be empty, or stalls the file
310
+ list.** Every untracked file was read whole just to count its lines, so a
311
+ 405 MB log was loaded into memory and reported as `+0 −0`. Files over the
312
+ diff size cap (256 KB — the same cap the untracked diff already used) are
313
+ no longer read, and show no line counts at all rather than zeros.
314
+ - **A refused stage or unstage stays on screen.** The message git gave back
315
+ was wiped by the next state change — often within a fraction of a second,
316
+ since staging is exactly what triggers one — so the button appeared to do
317
+ nothing at all. The refusal now names the action and the file (`Could not
318
+ stage a.ts: …`) and stays until it is genuinely over: the file reaches the
319
+ side you asked for, you try again, or a more urgent problem replaces it.
320
+ - **A journal timestamp older than an hour says which day it is.** The
321
+ relative time ("5 minutes ago") freezes into a clock time at an hour old,
322
+ and that clock time was a bare `14:32` whatever day it belonged to.
323
+ Anything not from today now carries its date, and its year when that
324
+ differs too.
325
+
326
+ ### Internal
327
+
328
+ - **The release gate now boots the packed tarballs under Node.** Every step
329
+ before it runs under bun, so nothing ever executed the published Node
330
+ program on the runtime its users have. The new step installs both tarballs
331
+ with npm into a clean directory, starts the daemon, and checks that `GET /`
332
+ is really the web UI and that every asset it references returns 200 — on
333
+ the engines floor (20.19.0) as well as current Node. It also catches a
334
+ daemon tarball built without `build:prod`, which ships without the web
335
+ assets, installs cleanly, and then fails on first run.
336
+ - **The README states the platform.** Linux is what diffstalker is built and
337
+ tested on. macOS needs an explicit `--socket` because it does not set
338
+ `XDG_RUNTIME_DIR`, and native Windows is not supported; use WSL2.
339
+ - **Three CLI test files were never being run.** The test script globbed
340
+ `src/*.test.ts src/**/*.test.ts`, which the shell expands one directory
341
+ deep, so everything under `src/ui/widgets/` was skipped in CI and in the
342
+ pre-push hook. All packages now run `bun test src/`, which lets bun do the
343
+ discovery.
344
+
8
345
  ## [0.9.0] - 2026-07-28
9
346
 
10
347
  ### Fixed
package/README.md CHANGED
@@ -26,12 +26,27 @@ node packages/daemon/dist/index.js # run the compiled daemon
26
26
  packages/daemon/bin/diffstalkerd # same, via the bin wrapper
27
27
  ```
28
28
 
29
+ Arguments:
30
+
31
+ ```
32
+ REPO_PATH... Repository to open on startup, so a client finds it
33
+ already there. Relative paths resolve against the
34
+ current directory and ~ expands; a path that will not
35
+ open stops the daemon before it listens
36
+ ```
37
+
29
38
  Options:
30
39
 
31
40
  ```
32
41
  --socket PATH Bind a unix socket at PATH
42
+ --instance NAME Bind <NAME>.sock in the runtime dir, so several daemons
43
+ can run side by side (clients select it with the same
44
+ name: diffstalker --instance NAME)
33
45
  (default: $XDG_RUNTIME_DIR/diffstalker/diffstalkerd.sock)
34
- --port N Bind TCP port N (loopback only) instead of a unix socket
46
+ --no-socket Do not bind a unix socket (requires --port)
47
+ --port N Also bind TCP port N (loopback only) for the web UI.
48
+ The port serves the web API subset; the unix socket
49
+ keeps the full API
35
50
  --follow-file PATH Hook file to follow (created when missing)
36
51
  (default: ~/.cache/diffstalker/target)
37
52
  --no-follow Disable follow mode (no hook-file watcher)
@@ -40,11 +55,24 @@ Options:
40
55
  package ships it there. Missing dir → API-only, non-fatal)
41
56
  --no-update-check Never ask npm which version is latest; GET /version
42
57
  then reports the running version only
58
+ --version, -v Print the running version and exit
43
59
  --help, -h Show this help
44
60
  ```
45
61
 
46
- `--socket` and `--port` are mutually exclusive; so are `--follow-file` and
47
- `--no-follow`.
62
+ `--socket` and `--port` are **not** mutually exclusive — binding both is the
63
+ normal deployment. The unix socket is the daemon's identity (one per user) and
64
+ is always bound unless `--no-socket`; `--port` adds the browser's transport on
65
+ top, over the same git state. `--follow-file` and `--no-follow` are exclusive,
66
+ as are `--socket` and `--no-socket`.
67
+
68
+ ```bash
69
+ diffstalkerd --port 7337 # socket for the TUI + :7337 for the browser
70
+ ```
71
+
72
+ That single daemon is what both clients talk to: `diffstalker` finds the socket
73
+ and attaches instead of spawning its own, so the TUI and the browser observe one
74
+ state over one event stream. Binding only a port (`--no-socket --port N`) leaves
75
+ the CLI nothing to attach to, and it will start a second, separate daemon.
48
76
 
49
77
  A browser can only reach the daemon over TCP (`--port`), not a unix socket, and
50
78
  the daemon sends no CORS headers — so the web UI is served same-origin from the
@@ -52,11 +80,17 @@ daemon itself. `GET /` and any unmatched non-API GET path return the SPA's
52
80
  `index.html` (client-side routing); hashed `/assets/*` are served with a long
53
81
  immutable cache. The REST/SSE API always takes precedence over static files.
54
82
 
55
- Without `--socket`/`--port`, the daemon binds a unix socket at
83
+ Without `--socket`, the daemon binds a unix socket at
56
84
  `$XDG_RUNTIME_DIR/diffstalker/diffstalkerd.sock`. The directory is created
57
85
  with mode `0700` and the socket is chmod'd to `0600` (owner only). If
58
86
  `XDG_RUNTIME_DIR` is unset, the daemon refuses to start — there is
59
87
  deliberately no `/tmp` fallback. Pass `--socket PATH` explicitly instead.
88
+ (With a `--port` to fall back on, an unset `XDG_RUNTIME_DIR` is a warning
89
+ rather than a failure: the web UI still works, only the CLI transport is
90
+ missing.)
91
+
92
+ `--port 0` asks the kernel to pick a free port; the daemon prints the one it
93
+ actually got.
60
94
 
61
95
  If a live daemon already answers on the socket path, startup fails; a stale
62
96
  socket file (nothing listening) is removed and reused.
@@ -75,12 +109,23 @@ headers (`X-Content-Type-Options`, `X-Frame-Options: DENY`,
75
109
  SPA). To reach the daemon from another machine, forward the port over SSH
76
110
  (`ssh -L`). See `SECURITY.md` at the repo root.
77
111
 
78
- A `--port` daemon also exposes a **reduced API** (least privilege): only the
79
- endpoints the web UI uses — reads, `POST`/`DELETE /repos`, and
80
- `POST /repos/:id/stage`/`unstage`. The CLI-only mutations (commit, discard,
81
- hunk staging, `PUT /compare/base`, and every remote/branch operation) are
82
- not routed on a port; they exist only over the unix socket. Requesting one
83
- on a port returns `404 Unknown route`.
112
+ The API surface is chosen **per listener**, by how well that transport is
113
+ protected — not per daemon. A unix socket (or an inherited activation fd) is
114
+ owner-only at the filesystem layer and carries the **full** API. A TCP port is
115
+ reachable by any process on the host and carries a **reduced** API (least
116
+ privilege): only the endpoints the web UI uses — reads, `POST`/`DELETE /repos`,
117
+ and `POST /repos/:id/stage`/`unstage`. The CLI-only mutations (commit, discard,
118
+ hunk staging, `PUT /compare/base`, and every remote/branch operation) are not
119
+ routed on a port at all; requesting one there returns `404 Unknown route`.
120
+
121
+ So a daemon bound to both transports simultaneously is still safe to expose to a
122
+ browser: the write-capable surface stays behind `0600` file permissions, and no
123
+ origin-guard bypass can reach it, because those routes are not in the port's
124
+ routing table to begin with. Each listener gets its own routing table over one
125
+ shared registry, SSE hub and follow controller.
126
+
127
+ Embedders can override this with `createDaemon({ apiMode })`, which forces one
128
+ surface onto every listener regardless of transport.
84
129
 
85
130
  ## Environment
86
131
 
@@ -91,7 +136,37 @@ on a port returns `404 Unknown route`.
91
136
  - `LISTEN_FDS` / `LISTEN_PID` — systemd socket activation. When systemd hands
92
137
  the process a pre-bound socket (`LISTEN_PID` matches and `LISTEN_FDS >= 1`),
93
138
  the daemon listens on the inherited fd (fd 3) and does not create, chmod, or
94
- unlink any socket file. Explicit `--socket`/`--port` takes precedence.
139
+ unlink any socket file. An explicit `--socket` (or `--no-socket`) takes
140
+ precedence; `--port` does not suppress it, since the port is additive.
141
+ Only fd 3 is used — a `.socket` unit with several `ListenStream=` entries
142
+ would have all but the first ignored.
143
+
144
+ ## systemd (user service)
145
+
146
+ The Arch package installs a **user** unit at
147
+ `/usr/lib/systemd/user/diffstalkerd.service`:
148
+
149
+ ```bash
150
+ systemctl --user enable --now diffstalkerd
151
+ # web UI at http://diffstalker.localhost:7337/
152
+ ```
153
+
154
+ It runs `diffstalkerd --port 7337`, which binds the default unix socket *and*
155
+ the port — so the terminal UI attaches to the same daemon the browser is
156
+ talking to, and `systemctl --user status diffstalkerd` is the whole story.
157
+
158
+ A **user** unit, never a system one: the socket lives under `$XDG_RUNTIME_DIR`
159
+ (per-user, `0700`), and every git call runs as the invoking user with their
160
+ config, ssh keys and worktrees. A system service would be the wrong uid for
161
+ all three.
162
+
163
+ Deliberately **not** socket-activated, even though the daemon implements the
164
+ `sd_listen_fds` protocol. The CLI health-probes the socket with a 250 ms budget
165
+ before falling back to spawning its own daemon; a cold activated start overruns
166
+ that, so the TUI would try to spawn a second daemon and hit `already running`.
167
+ An always-warm service answers the probe immediately. The daemon also has no
168
+ idle timeout — it holds watchers on open repos and is meant to stay warm for
169
+ the session — so lazy activation buys little here.
95
170
 
96
171
  ## API
97
172
 
@@ -127,6 +202,7 @@ values are rejected with a 400 so they can never be parsed as git flags.
127
202
  | GET | `/repos/:id/status` | Shared state: status, hunk counts, stash list, in-progress operation, error, working-file mtimes (path → mtimeMs; what browser clients build mtime-based auto mode on) |
128
203
  | GET | `/repos/:id/diff?path=&staged=` | Diff; whole tree without `path`, staged side with `staged=true`. Per-file cap: a file's diff over 256 KB or 5,000 lines is withheld — its headers are kept and its body becomes one `Large file — diff not shown (…)` line, the same shape git uses for `Binary files … differ`. Applies to every diff-bearing response (compare, commit diffs, journal) |
129
204
  | GET | `/repos/:id/history?count=` | Commit history (`CommitInfo[]`, default 100, ISO dates) |
205
+ | GET | `/repos/:id/commits/:hash` | One commit by hash or short hash (404 on unknown) — what a link to a commit outside a client's loaded log resolves through |
130
206
  | GET | `/repos/:id/commits/:hash/diff` | Diff introduced by one commit (404 on unknown hash; merge and `--allow-empty` commits are 200 with an empty diff, matching the CLI) |
131
207
  | GET | `/repos/:id/head-message` | HEAD commit message for amend prefill: `{message}` (`""` when the repo has no commits) |
132
208
  | GET | `/repos/:id/branches` | Local branches (`name`, `current`, `tracking`) |
@@ -134,8 +210,10 @@ values are rejected with a 400 so they can never be parsed as git flags.
134
210
  | GET | `/repos/:id/compare/base` | Effective compare base: `{base}` (persisted choice or discovered default, null when none) |
135
211
  | PUT | `/repos/:id/compare/base` | Persist the compare base: `{"branch": "origin/main"}` → `{base}`; the ref is validated first (400 on an unknown ref, nothing persisted) |
136
212
  | GET | `/repos/:id/compare?base=&uncommitted=` | Base-vs-HEAD `CompareDiff` (three-dot); base defaults to the effective base — a stale persisted base falls back to the discovered default, 422 when nothing usable resolves; an explicit unknown `base` is a 400; a base with no common history is a 422; `uncommitted=true` merges working-tree changes |
137
- | GET | `/repos/:id/tree?dir=&hidden=&ignored=` | One directory level (`name`, `path`, `type`), gitignored/hidden filtered by default (`hidden=true` / `ignored=true` include them, mirroring the TUI toggles), files annotated with `gitStatus` + `staged`, changed dirs with `hasChanges` (400 outside the repo root or on a file, 404 unknown dir) |
138
- | GET | `/repos/:id/file?path=` | File content for display with flags: `{content, binary, truncated, tooLarge, size, totalLines}` — binary/oversized come back with empty content and the flag set, never prose; 400 for anything that is not a regular file (directory, FIFO, device) or resolves outside the repo root |
213
+ | GET | `/repos/:id/tree?dir=&hidden=&ignored=` | One directory level (`name`, `path`, `type`), gitignored/hidden filtered by default (`hidden=true` / `ignored=true` include them, mirroring the TUI toggles), files annotated with `gitStatus` + `staged`, changed dirs with `hasChanges` (400 outside the repo root, on a file, or on the git directory, 404 unknown dir). The git directory is never listed, even with `hidden=true` |
214
+ | GET | `/repos/:id/file?path=` | File content for display with flags: `{content, binary, truncated, tooLarge, size, totalLines, media?}` — binary/oversized come back with empty content and the flag set, never prose; `media` carries the image verdict (`{image, refusal, version}`) when the bytes say something about it; 400 for anything that is not a regular file (directory, FIFO, device), resolves outside the repo root, or addresses the git directory |
215
+ | GET | `/repos/:id/media?path=&staged=` | Image metadata for one changed file, both sides resolved server-side (renames included): `{old, new}`, each side `{path, side, bytes, oid, image, refusal, version}` or `null` when the file does not exist there. `staged` must be spelled `0` or `1`. 404 when the path is not in status. See [Image bytes](#image-bytes) |
216
+ | GET | `/repos/:id/blob?path=&side=&v=` | Raw image bytes for `<img src>`; `side` is `worktree` \| `index` \| `head`, `v` is an ignored cache key. Only PNG/JPEG/GIF, typed from magic bytes. Status-independent (no `git status`), so a clean committed image is reachable. See [Image bytes](#image-bytes) |
139
217
  | GET | `/repos/:id/files` | All tracked + untracked (not ignored) paths: the fuzzy-finder source |
140
218
  | GET | `/repos/:id/journal?since=` | Append-only edit journal: `{epoch, prunedBefore, entries}`; `since=<seq>` returns only entries with a higher seq (all when omitted) |
141
219
  | GET | `/repos/:id/events` | SSE: `snapshot` on connect, then `state-change` events from the file watcher and `journal-append {entries}` per journal observation |
@@ -210,6 +288,109 @@ repo's last client (a browser F5) disposes the manager but keeps the
210
288
  store, so a reopen resumes the same chronology under the same epoch.
211
289
  Stores are LRU-capped daemon-wide; an open repo's store is never evicted.
212
290
 
291
+ ## Image bytes
292
+
293
+ `GET /repos/:id/blob` is the only endpoint that hands raw repository bytes to a
294
+ browser, and `GET /repos/:id/media` is the metadata that tells the web UI which
295
+ bytes to ask for. Both are routed on **every** listener (the socket and the
296
+ port), because the web UI is what needs them.
297
+
298
+ The rule the whole design rests on: **what we say a file is comes from its
299
+ magic bytes**, re-derived from the exact buffer the route is about to write, on
300
+ every request. Never from the extension, never from a query parameter, never
301
+ from a verdict an earlier `/file` or `/media` response cached. A repo file
302
+ called `logo.png` holding `<svg><script>` is same-origin script the moment we
303
+ agree with its name, so it gets zero bytes and a 415.
304
+
305
+ ### Allow-list
306
+
307
+ Three formats, and nothing else is ever served:
308
+
309
+ | Format | Content-Type | Structural gate |
310
+ | ------ | ------------ | --------------- |
311
+ | PNG (still) | `image/png` | PNG signature, `IHDR` dimensions, a legal bit-depth/colour-type pair, a bounded walk to the first `IDAT`. An `acTL` chunk (APNG) is refused — it is a second animation decoder |
312
+ | JPEG (baseline / progressive) | `image/jpeg` | SOI plus a legal marker, a bounded segment walk to the first SOF; **SOF0/SOF1/SOF2 only** (lossless, arithmetic and hierarchical SOFs are refused) |
313
+ | GIF (still or animated) | `image/gif` | `GIF87a`/`GIF89a`, a walk over the whole block stream counting image descriptors. Validated only with the entire file in hand, which is what `MAX_GIF_BYTES` bounds |
314
+
315
+ Everything else is refused by default: SVG, HTML/XML, PDF, WebP, AVIF/HEIC,
316
+ TIFF, BMP, ICO, JPEG XL, fonts, wasm/ELF/PE, archives, video and audio, and
317
+ anything unrecognized or recognized-but-invalid. The daemon **never decodes,
318
+ transcodes, re-encodes or strips metadata** — validation is fixed-offset
319
+ integer reads and bounded walks. No image library (sharp, jimp, canvas,
320
+ libvips) is a dependency of any package, and the browser stays the sandbox.
321
+
322
+ ### Caps
323
+
324
+ Enforced before any byte is written, and again on the buffer being written:
325
+
326
+ ```
327
+ MAX_IMAGE_BYTES = 8 MiB any allowed format
328
+ MAX_GIF_BYTES = 2 MiB GIF only, bounds the frame walk
329
+ MAX_IMAGE_DIMENSION = 8192 px per side
330
+ MAX_IMAGE_PIXELS = 16 MPix width * height, and any one GIF frame rect
331
+ MAX_GIF_FRAMES = 256
332
+ MAX_ANIMATED_PIXELS = 32 MPix frames * screen, and the sum of the frame rects
333
+ MAX_ICC_BYTES = 64 KiB PNG iCCP / JPEG APP2 run
334
+ ```
335
+
336
+ The **pixel budget, not the byte cap, is the real control**: compression ratio
337
+ is unbounded, so a 300-byte PNG can declare 60000×60000 and cost the renderer
338
+ gigabytes of RGBA. `MAX_FILE_SIZE` (1 MiB) is untouched — that is the *text*
339
+ cap for `/file`.
340
+
341
+ A GIF declares its dimensions twice — the logical screen in the header, and a
342
+ rectangle on every frame's image descriptor — and a rect may legally be bigger
343
+ than the screen it composites into. So both are charged: every rect against the
344
+ per-side and per-image caps a still image gets, and the sum of the rects against
345
+ the animated cap on top. Checking the header alone would let a 1×1 GIF carry an
346
+ 8000×4000 frame.
347
+
348
+ Concurrency is bounded too: 4 requests in flight per daemon with a queue of 64
349
+ waiters, then 503. One budget for the whole daemon, shared by every listener
350
+ **and by both endpoints** — `/media` inspects up to two sides, so it costs the
351
+ same spawns and the same buffers as `/blob` and takes the same slot. One
352
+ changed binary file costs up to three of those requests: a `/media` for the
353
+ verdict plus a `/blob` per side.
354
+
355
+ A slot is held until the response is finished on the socket, not just until the
356
+ read is done: the bytes stay resident while the client drains them, so an
357
+ earlier release would bound reads and leave memory unbounded. The release is
358
+ wired to the request **and** the response, because the two runtimes report the
359
+ end differently — node destroys the response when a client aborts, while bun
360
+ signals the abort only on the request. Every path either ends the response or
361
+ destroys the request, so the slot always comes back.
362
+
363
+ The two endpoints read different amounts, but they always reach the **same
364
+ verdict** about what a file is. `/media` only reports that verdict, so it reads
365
+ the window that decides the file and no more — a 64 KiB header for PNG and
366
+ JPEG, the whole file for a GIF, whose frame walk spans it. When that window is
367
+ inconclusive (a JPEG whose frame header sits behind a maximal EXIF segment, say)
368
+ the read is extended to the whole blob, which `MAX_IMAGE_BYTES` already bounds,
369
+ so `/media` never refuses a file `/blob` would serve. Only `/blob` reads the
370
+ bytes it is going to write.
371
+
372
+ ### Refusals
373
+
374
+ | Status | Cause |
375
+ | ------ | ----- |
376
+ | 400 | empty/NUL path, a leading `-` (git option) or `:` (pathspec magic), traversal, a symlink escaping the root, any `.git` path, a non-regular file (directory, symlink, gitlink, FIFO), a bad `side`, a `staged` that is not `0`/`1` |
377
+ | 403 | `Sec-Fetch-Site` present and cross-site, or `Sec-Fetch-Dest` present and not `image` (`/blob` only — `/media` is JSON and the SPA's own `fetch` sends `Sec-Fetch-Dest: empty`). Both absent passes, so `curl` and the Node client are unaffected |
378
+ | 404 | unknown repo, or the path does not exist on that side. `/media` also 404s a path with no status entry |
379
+ | 413 | over the byte, dimension, pixel or frame cap |
380
+ | 415 | not allow-listed, or the signature matched and the structure failed. An APNG lands here too: it is not over any budget, it is a format we refuse |
381
+ | 421 | non-loopback `Host` (the global origin guard) |
382
+ | 503 | the blob queue overflowed |
383
+
384
+ Every refusal writes **zero bytes** and a plain `{"error": "..."}` body.
385
+
386
+ A 200 carries the magic-derived `content-type`, `content-disposition: inline`
387
+ with **no** `filename` parameter (a repo-supplied string is never interpolated
388
+ into a header), a re-asserted `x-content-type-options: nosniff`,
389
+ `cross-origin-resource-policy: same-origin`, `vary: sec-fetch-site,
390
+ sec-fetch-dest`, and either `cache-control: no-store` (`side=worktree`, whose
391
+ bytes can change under us) or `cache-control: private, no-cache` plus an
392
+ `etag` of the object id (`side=index|head`, which are immutable).
393
+
213
394
  ## Follow mode
214
395
 
215
396
  The daemon owns the truth, clients decide policy. It watches ONE hook file