@xbghc/warden 0.6.0 → 0.7.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/README.md CHANGED
@@ -6,20 +6,24 @@ with line comments you can copy back to the agent as a prompt.
6
6
  - Runs as a single local process per repository (`127.0.0.1` only, no auth, no database).
7
7
  - Diff sources: working tree, staged, working tree vs HEAD, a branch since it forked off its base (commits and
8
8
  uncommitted work together), any commit, any two refs, and git worktrees.
9
- - Side-by-side **Unstaged** and **Staged** file lists, so staging a hunk in your editor is what marks it reviewed.
9
+ - Side-by-side **Unstaged** and **Staged** file lists: staged means reviewed. Stage from the UI by dragging
10
+ over the lines you have read (or a hunk, or a file), and unstage the same way from the Staged view.
10
11
  - GitHub-style unified / side-by-side diff with syntax highlighting, collapsed file tree, lazy per-file loading, context expansion, virtual scrolling.
11
12
  - Line comments (single line or a dragged range), Markdown, edit / delete.
12
13
  - One click copies all comments as an agent-readable prompt to the clipboard.
13
14
  - Review state (viewed files, comments, local issues, todos, preferences) persists outside the repo and survives restarts.
14
15
  - Comments follow the code: they move with a hunk that gets staged, re-attach after the agent edits the file, and are cleaned up once the change is committed.
15
16
  - Auto-refresh — warden watches the repository and reloads itself when you edit, stage, commit or switch branches.
16
- - Local issues (title, Markdown body, open/closed) that link comments.
17
- - Branch-scoped todos, each copied to the clipboard on its own — one task at a time for the agent.
17
+ - Local issues (title, Markdown body, open/closed) that link comments, and branch-scoped todos, each
18
+ copied to the clipboard on its own — one task at a time for the agent. Both are task lists in the
19
+ manner of Google Tasks: add at the top, Enter for the next one, tick to file it under 已完成, drag
20
+ into your own order, edit in place, 撤消 after a delete.
18
21
  - Commit history browser: grouped by day, branch / tag labels, search by message, sha, author or
19
22
  path (each a `git log` on the server, not a filter over the rows already loaded), and a
20
23
  first-parent view that folds merged branches into their merge commits.
21
24
  - Click a line number to jump to that line in a running nvim instance (WSL2 friendly).
22
- - Read-only with respect to git: only whitelisted read sub-commands are ever executed.
25
+ - Git is touched through whitelisted read sub-commands plus exactly one write, `git apply --cached`, which is
26
+ what the stage / unstage controls run. The working tree and HEAD are never written.
23
27
 
24
28
  ## Install / run
25
29
 
@@ -57,6 +61,10 @@ Several instances on the same repository can run at the same time.
57
61
 
58
62
  Refs accept anything git can resolve (`main`, `v1.2`, `HEAD~3`, a sha). `@` is `HEAD`.
59
63
  Worktrees are discovered with `git worktree list` and share the review state of the main repository.
64
+ One whose directory is gone (git lists it as *prunable*) is not offered, and a remembered target
65
+ inside a removed worktree falls back to the working tree on the next load. The comments and viewed
66
+ flags kept under that worktree's key stay in the state file and come back if a worktree is created
67
+ at the same path again.
60
68
 
61
69
  There is no target switcher in the UI: the sidebar's two blocks *are* the working tree, a commit is
62
70
  picked from the *Commits* panel, and the *Branch vs* and *Range* fields at the top of that panel open
@@ -76,7 +84,10 @@ everything since the branch forked off `<ref>` — the commits plus whatever is
76
84
  untracked. The diff runs against the merge base, so commits that landed on `<ref>` after the fork are
77
85
  not listed as reverted (which is what a plain `git diff <ref>` would do). The *Branch vs* field in the
78
86
  Commits panel suggests the base for you — the main worktree's branch when a sibling worktree is under
79
- review, otherwise `main` or `master` — and takes any ref. Unlike the three local views, `base` keeps its own
87
+ review, otherwise `main` or `master` — and takes any ref. Beside it the panel names the fork point (the
88
+ merge base with that ref, `GET /api/fork-point`) with how many commits the branch is ahead of it and how
89
+ many landed on the base since, and the list marks that commit with a *分叉自* chip and a rule above it:
90
+ what sits above is the branch's own work. Unlike the three local views, `base` keeps its own
80
91
  pool of comments and a commit never deletes them: the round under review is not over when the agent
81
92
  commits, so a comment whose lines changed stays *orphaned*, snippet and all, until you have checked
82
93
  the fix and delete or re-attach it.
@@ -88,8 +99,36 @@ the fix and delete or re-attach it.
88
99
  | `r` | Refresh the current target (file list + open diff, then re-anchor comments) |
89
100
  | `j` / `k` | Next / previous file, walking Unstaged then Staged and switching view at the boundary |
90
101
  | `n` / `p` | Next / previous hunk |
102
+ | `s` | Stage (Unstaged view) or unstage (Staged view) the picked lines |
91
103
  | `Ctrl+Enter` | Save the comment being edited |
92
- | `Esc` | Cancel editing / close a panel / cancel re-attach mode |
104
+ | `Esc` | Drop the picked lines / cancel editing / close a panel / cancel re-attach mode |
105
+
106
+ ## Staging
107
+
108
+ The Staged block is the "reviewed" pile, and warden can move lines into it without a trip to the
109
+ terminal. In the Unstaged view every changed line has a small box at the left edge; press it and drag
110
+ to pick a range inside one hunk (in split view a replacement is one row, so its old and new line go
111
+ together). The picked rows are outlined in ink, a bar at the bottom of the diff says how many lines
112
+ are in, and `s` or the bar's button stages them. Each hunk header has *暂存此 hunk*, the file header
113
+ and the sidebar rows have *暂存文件* / *暂存*. The Staged view has the same controls the other way
114
+ round: *取消暂存* takes lines back out of the index.
115
+
116
+ A partial pick is turned into the patch `git add -p`'s edit mode would want — the unpicked deletions
117
+ stay as context and the unpicked additions are left out (the mirror image when unstaging) — and applied
118
+ with `git apply --cached`. It never touches the working tree, so what you did not pick is still
119
+ there to stage next. Comments on the lines you staged follow them into the Staged view (see
120
+ [Re-anchoring](#re-anchoring)); the file's *viewed* flag is dropped because its diff changed. Every
121
+ page open on the worktree reloads at once.
122
+
123
+ Limits, each reported as a plain error rather than a half-applied patch:
124
+
125
+ - Only the Unstaged and Staged views stage; `all`, `base`, commits and ranges are read-only.
126
+ - Binary files and mode-only changes go whole or not at all; a mode change rides along only with *暂存文件*.
127
+ - A staged deletion can be unstaged whole, not by line: the index has nothing left to put lines back into.
128
+ - A pick that would split a file's missing trailing newline from its neighbours is refused; include them.
129
+ - The request carries the hash of the diff the pick was made on. If the file or the index moved since
130
+ (the agent kept editing), the server answers 409 and the page reloads instead of staging the wrong lines.
131
+ - If another git process holds the index lock the server retries briefly, then gives up with 409.
93
132
 
94
133
  ## Comments and export
95
134
 
@@ -154,8 +193,8 @@ bound to a hash of the file's diff; when the diff changes the flag is dropped an
154
193
 
155
194
  ## Auto-refresh
156
195
 
157
- warden polls the worktree every 1.5 s while the page is open (`git status --porcelain`, HEAD, the
158
- branch name, plus mtime and size of the paths status reports — enough to notice a second edit to an
196
+ warden polls the worktree every 1.5 s while the page is open (`git status --porcelain
197
+ --untracked-files=all`, HEAD, the branch name, plus mtime and size of the paths status reports — enough to notice a second edit to an
159
198
  already-modified file) and pushes a change event over `GET /api/events` (SSE). The page then re-runs
160
199
  the normal refresh: re-anchor, reload both file lists, reload the open diff. Your draft comment,
161
200
  selection, current view and current file are left alone, and the diff is scrolled back to where you
@@ -166,11 +205,28 @@ refreshes by hand.
166
205
 
167
206
  Notes attached to a branch rather than to a line of code, for the things you notice while reviewing
168
207
  that do not belong in a comment. They are not deleted when you commit. They sit in the right-hand
169
- rail next to the comments, under the *Todo* tab: type a title and press Enter to add one, expand a
170
- card to read or edit its Markdown body, filter by status, and switch between the current branch
171
- and all branches.
172
-
173
- Each card has its own *复制* button, and there is deliberately no "copy all": a todo is one task to
208
+ rail next to the comments, under the *Todo* tab, as a task list that works the way Google Tasks does:
209
+
210
+ - *添加 Todo* opens an empty row at the top; type the title and press Enter, and the next row opens
211
+ right under it. Esc or Backspace on an empty row drops it.
212
+ - Titles and details are edited where they are: click into the text. Enter at the end of a title
213
+ starts the next todo under it; Backspace on an emptied title deletes the todo. The details field
214
+ (Markdown) appears while the row is open, and is rendered under the title otherwise.
215
+ - The circle strikes the todo through and files it under *已完成 (N)* at the bottom, collapsed;
216
+ open it to tick one back or *全部删除*.
217
+ - Rows are dragged into your own order by the handle at their left edge. That order is what the state
218
+ file keeps, and new todos go on top.
219
+ - Delete asks nothing; the toast offers *撤消* for a few seconds.
220
+ - The picker at the top is the list selector: the current branch, any other branch that has todos,
221
+ or all of them with the branch on each row. A new todo goes to the branch being shown.
222
+
223
+ Issues (the *Issues* tab in the top bar) are the same list: closing an issue is ticking it, a
224
+ *已关闭* section holds the closed ones, and the comments linked to an issue sit under its open row
225
+ like subtasks, each with *跳转* and *解除关联*. Tick comments in the rail and the *创建 Issue* button
226
+ opens the drawer with the add row ready and the comments attached on creation; for an existing
227
+ issue, open its row and use *关联选中的评论*.
228
+
229
+ Each row has its own *复制* button, and there is deliberately no "copy all": a todo is one task to
174
230
  hand to an agent, and the agent it goes to is already working in that branch. So the clipboard gets
175
231
  the title and the body — no branch, repo, count or numbering:
176
232
 
@@ -221,17 +277,21 @@ move into the matching scope the first time the file is read.
221
277
 
222
278
  ## Security model
223
279
 
224
- Single user, local only. The server binds to `127.0.0.1`, executes git only through
225
- `execFile('git', [...])` with an argument whitelist (`rev-parse`, `diff`, `show`, `log`, `worktree list`,
226
- `ls-files`, `status`, `merge-base`), refuses option-looking refs and any write-capable flag, and never writes into the
227
- repository. Requests that would need anything else get HTTP 400.
280
+ Single user, local only. The server binds to `127.0.0.1` and executes git only through
281
+ `execFile('git', [...])`. Reads go through an argument whitelist (`rev-parse`, `diff`, `show`, `log`,
282
+ `worktree list`, `ls-files`, `status`, `merge-base`, `rev-list`) that refuses option-looking refs and any write-capable
283
+ flag; requests that would need anything else get HTTP 400. The one write is `POST /api/targets/:key/stage`,
284
+ which runs `git apply --cached` (with `--reverse` for the Staged view) on a patch the server itself builds
285
+ from the diff it just produced — the patch is never taken from the request, only the line indices are,
286
+ and they are checked against the diff's hash first. Nothing writes to the working tree, HEAD or the
287
+ refs, and the review state lives outside the repository.
228
288
 
229
289
  ## Development
230
290
 
231
291
  ```sh
232
292
  pnpm install
233
293
  pnpm dev # API server on :4100 (tsx watch) + Vite dev server on :5173 with /api proxied
234
- pnpm test # vitest: diff parser, anchoring, comment scopes, watcher, todos, export, state, HTTP API
294
+ pnpm test # vitest: diff parser, staging patches, anchoring, comment scopes, watcher, todos, export, state, HTTP API
235
295
  pnpm typecheck
236
296
  pnpm build # dist/web (Vite) + dist/cli.js (tsup, zero runtime dependencies)
237
297
  node dist/cli.js path/to/repo
@@ -242,7 +302,7 @@ Layout:
242
302
  ```
243
303
  bin/cli.ts argument parsing, start server, open browser
244
304
  packages/shared types + target key / comment scope helpers (bundled into both sides)
245
- packages/server Hono API, git wrapper, diff parser, targets, anchoring, watcher, state, export, nvim
305
+ packages/server Hono API, git wrapper, diff parser, staging patches, targets, anchoring, watcher, state, export, nvim
246
306
  packages/web React + Vite UI (shiki highlighting, @tanstack/react-virtual, react-markdown)
247
307
  test/ API integration tests on a generated git repository
248
308
  ```