diffstalkerd 0.13.14 → 0.14.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,53 @@ 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
+ ## [0.14.0] - 2026-11-23
9
+
10
+ ### Added
11
+
12
+ - **A Work page for all your unfinished work.** Click the diffstalker
13
+ wordmark. It lists your open PRs, the PRs you are asked to review, and
14
+ the worktrees and branches with work in them, across every watched repo,
15
+ found without bookkeeping. Each row is one line of columns: how far along
16
+ it is (with a colour), its layer in a PR stack, the PR link, review
17
+ state, CI, merge conflicts, local changes, the draft, whose move it is,
18
+ and how long ago something last happened. Group the rows by repository
19
+ and by time, keep only the last day, week or month, and sort by any
20
+ column. A red alert marks what waits on you: changes requested and not
21
+ asked to review again yet, or a review you are asked for. **Track**
22
+ keeps a candidate in view; **Dismiss** hides an item until something
23
+ about it changes. The page catches up when you come back to it and says
24
+ how old each part is. PR state comes from `gh`; without it the page
25
+ shows what git knows.
26
+ - **PR body drafts.** Write the top zone of a PR description per branch,
27
+ in a Work row's fold-out or in Compare. Drafts live in the repo's git
28
+ dir (`diffstalker/pr/<branch>/`), where agents read them and leave a
29
+ suggestion or the AI zone in files of their own. For an open PR the
30
+ editor starts from its text on GitHub. When your words differ from the
31
+ PR, **Take GitHub's text** copies them over, and **Update GitHub**
32
+ replaces only the PR's top zone after asking once more. That button is
33
+ the only change diffstalker makes on GitHub.
34
+ - **Copy for a session** puts a PR's link, branch, head commit and local
35
+ clone on the clipboard, to paste into an agent session.
36
+ - The daemon serves the Work page and the drafts: `/work/*`,
37
+ `/repos/:id/draft`, `/repos/:id/pr`, and `gh` in `GET /health`. See the
38
+ daemon README.
39
+
40
+ ### Changed
41
+
42
+ - **Repo ages in the picker follow commits and checkouts,** not git's
43
+ index file, which a plain `git status` rewrites.
44
+ - **Compare takes any branch as `?head=`.** A branch that is no layer of
45
+ the stack is compared against the trunk.
46
+
47
+ ### Fixed
48
+
49
+ - **A huge change no longer mounts every diff at once.** A repo with
50
+ 15,000 changed files made one Compare tab use 10 to 14 GiB. Files now
51
+ mount while their rows fit in 20,000; the rest wait behind the **Load
52
+ diff** gate, and `e` still loads everything. A compare that refreshes
53
+ keeps every file whose diff did not change.
54
+
8
55
  ## [0.13.14] - 2026-11-11
9
56
 
10
57
  ### Fixed
package/README.md CHANGED
@@ -83,7 +83,8 @@ daemon itself. `GET /` and any unmatched non-API GET path return the SPA's
83
83
  immutable cache. The REST/SSE API always takes precedence over static files,
84
84
  and an unknown path under an API prefix (`/health`, `/version`, `/repos`,
85
85
  `/resolve`, `/worktrees`, `/events`, `/follow`, `/settings`, `/discovered`,
86
- `/browse`) is a JSON 404, never the SPA page.
86
+ `/browse`, `/work`) is a JSON 404, never the SPA page. `/work` alone is the
87
+ exception: it is the web UI's Work page, while `/work/...` is the API.
87
88
 
88
89
  Without `--socket`, the daemon binds a unix socket at
89
90
  `$XDG_RUNTIME_DIR/diffstalker/diffstalkerd.sock`. The directory is created
@@ -217,14 +218,14 @@ when the repo is open but its directory is gone or is no longer a git repo
217
218
  for real failures.
218
219
 
219
220
  Ref-like values (the body fields `name`, `hash`, `branch` and the `base`
220
- query param) must not be empty or start with `-`; such values are rejected
221
+ and `branch` query params) must not be empty or start with `-`; such values are rejected
221
222
  with a 400 so they can never be parsed as git flags.
222
223
 
223
224
  ### Reads
224
225
 
225
226
  | Method | Path | What |
226
227
  | ------ | -------------------------- | ------------------------------------------------ |
227
- | GET | `/health` | `{ok, ready, home, http: {port}, symbols}` — `http.port` is the loopback port a browser reaches the web UI on, or null when only a socket is bound (what `diffstalker link` needs to build a URL at all) |
228
+ | GET | `/health` | `{ok, ready, home, http: {port}, symbols, gh}` — `http.port` is the loopback port a browser reaches the web UI on, or null when only a socket is bound (what `diffstalker link` needs to build a URL at all). `gh` says whether the `gh` binary is on PATH (a PATH lookup, no spawn); see [Work page and PR drafts](#work-page-and-pr-drafts) |
228
229
  | GET | `/version` | `{current, latest, status, install, restart}` — the running version against npm's `latest` dist-tag (`current` \| `outdated` \| `ahead` \| `unknown`). The npm lookup is cached (6h, 5min after a failure) and only ever runs when this endpoint is called; `--no-update-check` skips it, leaving `latest: null`. `install` is `{method, package, command}` — how this daemon was installed (`npm` \| `bun` \| `pnpm` \| `yarn` \| `pacman` \| `unknown`) and the one command that updates it, detected once from where the daemon's own files live. An install nothing owns reports `unknown` with a null command rather than a guess. `restart` is the command that restarts this daemon (`systemctl --user restart diffstalkerd`, or `sudo systemctl restart …` for a system unit), set only when systemd started this very process (`$SYSTEMD_EXEC_PID` is its pid) and `/proc/self/cgroup` names a plain `.service` unit; otherwise null |
229
230
  | GET | `/repos` | List open repos (`id`, `path`, `branch`) |
230
231
  | POST | `/repos` | Open a repo: `{"path": "/abs/path"}` → `{id, path}` (201 created, 200 already open or still kept warm after its release). 400 for a relative path or a directory that is not a git repository, 404 when the path does not exist. One missing last segment under a repo still opens the repo above it (`<repo>/nope` opens `<repo>`); a path missing more than one level deep (`<repo>/nope/deeper`) is a 404 |
@@ -253,12 +254,17 @@ with a 400 so they can never be parsed as git flags.
253
254
  | 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) |
254
255
  | GET | `/repos/:id/files` | All tracked + untracked (not ignored) paths: the fuzzy-finder source |
255
256
  | GET | `/repos/:id/journal?since=` | Append-only edit journal: `{epoch, prunedBefore, entries}`; `since=<seq>` returns only entries with a higher seq (all when omitted) |
256
- | GET | `/repos/:id/events` | SSE: `snapshot` on connect, then `state-change` events from the file watcher and `journal-append {entries}` per journal observation |
257
- | GET | `/events?repo=` | Daemon-scope SSE: `snapshot` (open repos) on connect, then `repo-opened` / `repo-closed` / `follow-change` / `settings-change` / `discovery-change`. With `repo=<id>` the same stream also carries that repo's events — `repo-snapshot` right after the daemon `snapshot`, then `state-change` / `journal-append` as on `/repos/:id/events`. An id that is not open is still a 200: one `repo-missing {id}` follows the snapshot; an empty `repo=` is the same as none. See [One stream per tab](#one-stream-per-tab) |
257
+ | GET | `/repos/:id/draft?branch=` | The branch's PR draft: `{branch, top, suggested, ai, adoptedUnedited, version}` (`PrDraft` in `@diffstalker/core/types/work`), each text null when its file is missing. `version` is the sha256 of `top.md`, or `absent`. 400 for a missing or refused branch name, 422 when a draft file is a link, not a regular file, or over 256 KB |
258
+ | GET | `/repos/:id/pr?branch=` | The cached PR for one branch: `{pr, status, message, checkedAt, viewer}`, matched by the repo's GitHub remotes and the branch name. Answers from the cache and never runs `gh`; `pr` is null before the first refresh |
259
+ | GET | `/repos/:id/events` | SSE: `snapshot` on connect, then `state-change` events from the file watcher, `journal-append {entries}` per journal observation, and `draft-change {branch, prefix}` when a PR draft file changes (no git refresh comes with it) |
260
+ | GET | `/events?repo=` | Daemon-scope SSE: `snapshot` (open repos) on connect, then `repo-opened` / `repo-closed` / `follow-change` / `settings-change` / `discovery-change`. With `repo=<id>` the same stream also carries that repo's events — `repo-snapshot` right after the daemon `snapshot`, then `state-change` / `journal-append` / `draft-change` as on `/repos/:id/events`. An id that is not open is still a 200: one `repo-missing {id}` follows the snapshot; an empty `repo=` is the same as none. See [One stream per tab](#one-stream-per-tab) |
258
261
  | GET | `/follow` | Follow state: `{targetFile, enabled, followedRepoId, followedPath}` |
259
262
  | GET | `/settings` | Daemon settings: `{watchRoots, persisted}`. `persisted: false` means this daemon holds them in memory only (no settings file) |
260
263
  | GET | `/discovered` | Repos found under the watch directories: `{roots: [{path, repos: [{path, name, branch, lastActivity}], error, capped}]}`. See [Watch directories](#watch-directories) |
261
264
  | GET | `/browse?path=` | One directory level of the daemon's filesystem, for picking a watch directory: `{path, parent, home, entries: [{name, path, isRepo}]}`. Directory names only — no files, no dot directories. No `path` starts at the daemon's home; 400 for a relative path, 404 for one it cannot read |
265
+ | POST | `/work/repo` | `{"path": "/abs/path"}` → one repo's facts for the Work page: `{path, root, name, worktrees, branches, branchesCapped, identities, drafts}` (`WorkRepoFacts`). A read, but POST: it runs a full git scan, and only a non-GET request gets the CSRF check, so a GET would let any website start scans and time them. The path must be absolute (400) and be a discovered or open repo (404 otherwise); 404 when it is not a git repository, 500 when the scan fails. One scan per path runs at a time; a request while it runs joins it |
266
+ | GET | `/work/prs` | The cached PR list: `{status, message, checkedAt, viewer, prs, capped}` (`PrSnapshot`). Never runs `gh`; `status` is `never` until the first refresh |
267
+ | GET | `/work/marks` | The Work page's marks: `{tracked, dismissed}` |
262
268
 
263
269
  ### Mutations (all respond `{state, result?}`)
264
270
 
@@ -266,6 +272,12 @@ with a 400 so they can never be parsed as git flags.
266
272
  | ------ | -------------------------- | ------------------------------------------------ |
267
273
  | PUT | `/settings` | Replace the settings: `{"watchRoots": ["/abs/dir", "~/projects"]}` → `{watchRoots, persisted}`. Whole document, not a patch. Each path is expanded, made absolute and checked to be an existing directory; a refusal is a 400 naming the path, and nothing is saved |
268
274
  | POST | `/discovered/rescan` | Re-walk every watch directory now and return the new `{roots}` (filesystem only, no git processes) |
275
+ | POST | `/work/prs/refresh` | Run the `gh` query now and return the new `PrSnapshot`. The body is ignored. A refresh while one runs joins it. A `gh` failure is a 200 with its `status`; the last good list and its `checkedAt` stay |
276
+ | PUT | `/work/marks` | `{"key": "...", "action": "track" \| "dismiss" \| "drop" \| "undismiss", "fingerprint"?: "...", "prune"?: ["..."]}` → `{tracked, dismissed}`. `dismiss` needs a `fingerprint`; `prune` keys are dropped from both kinds first. 400 for a bad request or more than 2000 marks of a kind, 500 when the file cannot be written |
277
+ | PUT | `/repos/:id/draft` | `{"branch": "...", "top": "...", "version": "..."}` → `PrDraft`. Saves `top.md` when `version` still matches (409 `Draft changed elsewhere` otherwise). An empty `top` deletes `top.md` and `adopted`, and the branch's directory when nothing else is in it. 413 over 256 KB; 422 when any draft file cannot be read, and then nothing is written |
278
+ | POST | `/repos/:id/draft/adopt` | `{"branch": "...", "version": "..."}` → `PrDraft`. "Start from this": copies `top.suggested.md` into `top.md` and writes its sha256 to `adopted`. 409 when the version moved, `top.md` is not empty, or there is no suggestion; 422 when any draft file cannot be read, and then nothing is written |
279
+ | POST | `/repos/:id/pr/check` | `{"branch": "..."}` → `{pr, status, message, checkedAt, viewer}`. Reads that branch's PR fresh from GitHub (one `gh` call) and puts it in the cached list. 404 when the list has no PR for the branch; 502/503 when `gh` fails |
280
+ | POST | `/repos/:id/pr/top` | `{"branch": "...", "version": "...", "expectedTop": "..."}` → same shape. "Update GitHub": replaces the open PR's top zone with `top.md` and keeps the body from the `---` line on, as GitHub has it. Refuses, writing nothing: 409 when `top.md`'s version moved, the PR is not open, or GitHub's top zone is not `expectedTop`; 422 when `top.md` is empty or has a `{{...}}`; 404 when no PR is known; 502/503 when `gh` fails |
269
281
  | POST | `/repos/:id/stage` | `{"path": "file.txt"}` — stage one file (404 when not in status) |
270
282
  | POST | `/repos/:id/unstage` | `{"path": "file.txt"}` — unstage one file |
271
283
  | POST | `/repos/:id/stage-all` | Stage everything |
@@ -343,7 +355,7 @@ hung. `GET /events?repo=<id>` folds both into ONE stream:
343
355
 
344
356
  - On connect: the daemon `snapshot` first, then the repo's `repo-snapshot`
345
357
  (renamed only because `snapshot` is already taken on this stream). After
346
- that, `state-change` and `journal-append` exactly as on
358
+ that, `state-change`, `journal-append` and `draft-change` exactly as on
347
359
  `/repos/:id/events`, with the same payloads and the same dedup.
348
360
  - An id that is not open (the daemon restarted and the browser's
349
361
  EventSource reconnected before the page re-POSTed `/repos`) is still a
@@ -540,6 +552,61 @@ in the settings and is reported with an `error` — it is never quietly
540
552
  dropped. Both `/settings` and `/discovered` are served on every transport,
541
553
  including a `--port` listener: the settings UI lives in the web client.
542
554
 
555
+ ## Work page and PR drafts
556
+
557
+ See `docs/work-page.md` for the design.
558
+
559
+ PR drafts live in the repo's common git dir, shared by every worktree and
560
+ never committed: `<common>/diffstalker/pr/<branch>/`, with `feature/x`
561
+ nesting as `pr/feature/x/`. The daemon writes only `top.md` (the author's
562
+ words, from the draft panel) and `adopted` (the sha256 of a suggestion the
563
+ author started from). `top.suggested.md` and `ai.md` belong to agents: the
564
+ daemon reads them and never writes or removes them. A branch name is
565
+ checked as a path before any read or write: no empty, `.` or `..` part, no
566
+ part starting with `.` or ending in `.lock`, no part named like a draft
567
+ file, no backslash or control character, and no symlinked directory on the
568
+ way down from the common dir (`diffstalker` and `pr` included). A save
569
+ reads every draft file first, so one it cannot read fails the save before
570
+ anything is written. The Work scan leaves out a draft or directory it
571
+ cannot read, with a warning, and does not fail. Draft files are opened
572
+ without following a link and must be regular files of at most 256 KB. An
573
+ open repo's common-dir watcher also watches `diffstalker/pr/` and sends
574
+ `draft-change {branch, prefix}` on the repo stream, without a git refresh.
575
+ `prefix: true` means a directory changed, so every draft at or below
576
+ `branch` may have changed (`""` is all of them).
577
+
578
+ PR state comes from `gh`: every run is `gh api graphql --input -` with a
579
+ fixed query and its variables as JSON on stdin, so no value, from a request
580
+ or from GitHub, is ever in the argv. A refresh reads, side by side, light
581
+ lists of the author's open PRs and of the open PRs the author is asked to
582
+ review (what shows a change, plus checks, conflicts, the review decision
583
+ and the draft flag, about 1 point each), and the author's closed PRs. Only
584
+ a PR that is new, or whose `updatedAt` or head commit moved, is then read
585
+ whole (body, requested reviewers, threads and recent events), ten per
586
+ request; the others keep what was read before. The closed list is the
587
+ newest 300 on the first refresh, then only the PRs updated since the last
588
+ good refresh (less 10 minutes) are asked for and merged in; it has no date
589
+ window, since an old closed PR is what tells the page a branch is finished.
590
+ At most 300 of each list. The one-PR read (`/pr/check`) and the one write
591
+ (`/pr/top`, "Update GitHub": a PR's top zone, nothing else) go the same
592
+ way, and the write's text is `top.md` from disk, never the request's. It
593
+ runs only on `POST /work/prs/refresh` (POST, so the CSRF guard covers it:
594
+ `gh` sends the author's token), never in the background, with one 20 s
595
+ deadline, and a failed refresh is not retried. The answer is kept in
596
+ memory; `GET /work/prs` and `GET /repos/:id/pr` read it and never run
597
+ `gh`. When `gh` is missing or logged out the status says so, and
598
+ everything from git keeps working.
599
+ `POST /work/repo` is POST too: it runs a full git scan, and the CSRF guard
600
+ covers only non-GET requests.
601
+
602
+ The Work page's marks (track, dismiss) are kept at
603
+ `$XDG_STATE_HOME/diffstalker/work.json`, written atomically like
604
+ `daemon.json`. Every daemon of the user shares the file (the dev daemon of
605
+ `bun run serve` too), so `GET /work/marks` reads it and `PUT` applies its
606
+ change to what is on disk, not to what this daemon remembers. The page
607
+ names the marks whose item is gone (`prune`), since only it knows which
608
+ items exist.
609
+
543
610
  ## Follow mode
544
611
 
545
612
  The daemon owns the truth, clients decide policy. It watches ONE hook file