@eliya-oss/agent-diff 0.1.0-alpha.18 → 0.1.0-alpha.180

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/package.json CHANGED
@@ -2,10 +2,12 @@
2
2
  "name": "@eliya-oss/agent-diff",
3
3
  "type": "module",
4
4
  "devDependencies": {
5
- "@effect/vitest": "^4.0.0-beta.102",
5
+ "@effect/tsgo": "^0.31.0",
6
+ "@effect/vitest": "^4.0.0-rc.110",
6
7
  "@types/node": "^26.1.2",
7
- "effect": "^4.0.0-beta.102",
8
- "oxlint": "^1.76.0",
8
+ "effect": "^4.0.0-rc.110",
9
+ "oxlint": "1.77.0",
10
+ "oxlint-tsgolint": "^7.0.2001",
9
11
  "rolldown": "^1.2.1",
10
12
  "vitest": "^4.1.10"
11
13
  },
@@ -21,8 +23,8 @@
21
23
  "bin": {
22
24
  "adiff": "./bin/adiff.js"
23
25
  },
24
- "version": "0.1.0-alpha.18",
25
- "description": "Review agent work across git worktrees like a PR, and hand the comments back to the agent.",
26
+ "version": "0.1.0-alpha.180",
27
+ "description": "Review the work an agent left you without losing the thread: comments live on the lines, the agent answers them, and each point stays open until you settle it.",
26
28
  "license": "MIT",
27
29
  "repository": {
28
30
  "type": "git",
@@ -41,7 +43,8 @@
41
43
  "check": "pnpm run typecheck && pnpm run lint && pnpm run build && pnpm test",
42
44
  "build": "rolldown -c rolldown.config.ts",
43
45
  "typecheck": "tsc --noEmit",
44
- "lint": "oxlint && node scripts/check-style.ts",
46
+ "lint": "oxlint && node scripts/check-rules.ts && node scripts/check-film.ts && node scripts/check-public.ts",
47
+ "check-body": "node --experimental-ffi --disable-warning=ExperimentalWarning scripts/check-public.ts",
45
48
  "test": "NODE_OPTIONS=--experimental-ffi vitest run",
46
49
  "test:watch": "NODE_OPTIONS=--experimental-ffi vitest",
47
50
  "dev": "node --experimental-ffi --disable-warning=ExperimentalWarning src/main.ts",
@@ -51,6 +54,10 @@
51
54
  "sketch": "node --experimental-ffi --disable-warning=ExperimentalWarning scripts/sketch.ts",
52
55
  "watch": "node --experimental-ffi --disable-warning=ExperimentalWarning scripts/watch.ts",
53
56
  "serve": "node --experimental-ffi --disable-warning=ExperimentalWarning scripts/serve.ts",
54
- "play": "node --watch --watch-path=src --watch-path=scripts --experimental-ffi --disable-warning=ExperimentalWarning scripts/play.ts"
57
+ "play": "node --watch --watch-path=src --watch-path=scripts --experimental-ffi --disable-warning=ExperimentalWarning scripts/play.ts",
58
+ "shot": "node --experimental-ffi --disable-warning=ExperimentalWarning scripts/shot.ts",
59
+ "pr-summary": "node scripts/pr-summary.ts",
60
+ "scenario": "node --experimental-ffi --disable-warning=ExperimentalWarning scripts/scenario.ts",
61
+ "record": "node --experimental-ffi --disable-warning=ExperimentalWarning scripts/record.ts"
55
62
  }
56
63
  }
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: adiff
3
- description: Pick up review comments left on this worktree's diff in the adiff terminal, act on them, and write the layers that explains the diff. Use when the user says they left comments, asks you to check adiff, asks you to watch for review feedback, or asks you to hand work over for review.
3
+ description: Pick up review comments left on this worktree's diff in the adiff terminal, act on them, and answer them by id. Use when the user says they left comments, asks you to check adiff, asks you to watch for review feedback, or asks you to hand work over for review.
4
4
  ---
5
5
 
6
6
  # adiff
@@ -24,7 +24,22 @@ Each comment carries the code it is about. `snippet` is the exact text the revie
24
24
  `side` says whether the line numbers are in the new file (`new`) or the version being replaced
25
25
  (`old`), and `head` is the commit the diff was read at.
26
26
 
27
- A comment is handed over exactly once. A second `take` returns only what was written since.
27
+ A comment on code one of your layers explains carries `layer`, that layer's title as your latest
28
+ revision has it. The code the layer describes is about to change under your hands, so the layers go
29
+ stale the moment you act on the comment: write a new revision with `adiff layers set` before you
30
+ answer, and say in the answer that you did.
31
+
32
+ A comment keeps coming back until it is answered. A second `take` returns it again, so answer what
33
+ you take. Settling or removing it also retires it: those are the reviewer saying they no longer
34
+ need one.
35
+
36
+ ## A remark is context, a comment is work
37
+
38
+ `adiff remark list --repo . --branch <branch>` reads the remarks left on the branch's pull request.
39
+ They are not yours to act on. A remark is somebody's point about the code, and the reviewer decides
40
+ what happens to it: accepting one writes a comment, and that comment is what reaches you through
41
+ `comment take`. Read remarks when the reviewer asks you to, or to understand a comment that answers
42
+ one. Never act on a remark that has not been accepted, and never accept one yourself.
28
43
 
29
44
  ## Wait for the next one
30
45
 
@@ -35,14 +50,30 @@ adiff comment take --worktree . --wait 300
35
50
  Blocks until a comment arrives or the timeout in seconds elapses, then returns the same envelope.
36
51
  An empty `comments` array means the wait expired with nothing new — that is not an error.
37
52
 
53
+ `--wait` takes a whole number of seconds from 1 to 86400. A value outside that is refused on
54
+ stderr with exit 2, because an instant empty answer would read exactly like a wait that expired:
55
+ if a wait comes back at once, you are not waiting.
56
+
57
+ Arm the wait as the first thing you do in a turn, before the work. A turn that is interrupted
58
+ half-way then still leaves a listener running, and a wait armed at the end of a turn is a wait that
59
+ often never gets armed.
60
+
38
61
  Run the wait in the background, not in the foreground. A foreground wait holds the turn, so you
39
62
  cannot do anything else and the person you are working with cannot talk to you. Backgrounded, the
40
63
  harness brings you back the moment a comment lands.
41
64
 
65
+ Keep one wait per worktree. A second wait returns the same comments as the first, so two of them
66
+ running at once is two of you answering the same comment. Before starting one, check whether one is
67
+ already running.
68
+
42
69
  Re-arm it after each comment you handle, and keep it running while you work. A reviewer reads at
43
70
  their own pace, so comments arrive minutes apart, and the whole point is that they reach you as
44
71
  events rather than by you asking. When you finish a piece of work, say you are still listening.
45
72
 
73
+ A backgrounded wait that is killed rather than expiring is not the reviewer going quiet, and not a
74
+ reason to stop listening. A kill loses whatever the wait would have handed you, so take once
75
+ without `--wait` to collect what landed, then arm a new wait.
76
+
46
77
  ## Answering a comment
47
78
 
48
79
  Say what you did, against the comment you were handed:
@@ -58,15 +89,29 @@ Answer when the change alone does not carry the reasoning: what you did instead
58
89
  what you found while doing it, or why the comment does not apply. A comment that asked a question
59
90
  deserves an answer even when nothing changed.
60
91
 
61
- Add `--asks` when you need the reviewer to decide before you continue:
92
+ Add `--question` when you need the reviewer to decide before you continue:
62
93
 
63
94
  ```bash
64
- adiff comment answer --worktree . --id <id> --asks --body "Drop it, or keep it and map the error?"
95
+ adiff comment answer --worktree . --id <id> --question --body "Drop it, or keep it and map the error?"
65
96
  ```
66
97
 
67
98
  That marks the thread as waiting on them rather than on you. Do not use it to check in; use it when
68
99
  the work genuinely stops without an answer.
69
100
 
101
+ ## When the reviewer writes back
102
+
103
+ A reviewer can reply to an answer, and the reply arrives through `comment take` like any other
104
+ comment — with an `id` of its own that you answer against, and a `thread` carrying what was said
105
+ before it, oldest first:
106
+
107
+ ```json
108
+ {"body":"the imports","replyTo":"c1","thread":[{"voice":"reviewer","body":"why two of these"},{"voice":"agent","body":"which two did you mean"}]}
109
+ ```
110
+
111
+ Read the thread before answering. A reply is usually short because it is the rest of a sentence you
112
+ already have: "the imports" only means something next to the question it answers. Answer it against
113
+ its own id, not the id of the comment that started the thread.
114
+
70
115
  Settling a thread is the reviewer's to do, not yours. They raised the point, so they decide it is
71
116
  closed.
72
117
 
@@ -76,9 +121,13 @@ Read `snippet` before opening the file: the reviewer commented on the diff, and
76
121
  moved on since. If `head` no longer matches `git rev-parse --short HEAD`, the change you are being
77
122
  asked about may already be gone — say so rather than guessing at what they meant.
78
123
 
79
- Answer the comment by doing the work, not by replying. The reviewer is watching the diff; your
80
- next commit is the reply. When a comment is a question rather than a request, answer it in the
81
- commit message of the change it concerns, or plainly in chat if no change is needed.
124
+ Answer the comment by doing the work, then say what you did with `adiff comment answer`, by id.
125
+ The reviewer is watching the diff, and the diff is read from the working tree, so an edit shows the
126
+ moment they read the branch again: no commit is needed for them to see it. Do not commit once per
127
+ comment. Commit when the work forms a change you would want as a commit anyway, and let one commit
128
+ answer as many comments as it addresses. When a comment is a question rather than a request, answer
129
+ it with `adiff comment answer` too; an answer written into a commit message never reaches the
130
+ reviewer's screen.
82
131
 
83
132
  Handle every comment in the batch before taking again.
84
133
 
@@ -89,15 +138,75 @@ Failures go to **stderr**, never stdout, so stdout is always safe to parse. The
89
138
  what kind of problem it is: `2` the request was malformed, `3` the branch or file does not exist,
90
139
  `1` something unexpected.
91
140
 
141
+ Every command that acts on a review takes either `--worktree <path>` or `--repo <path>` with
142
+ `--branch <name>`. Standing in the worktree, `--worktree .` is always enough.
143
+
92
144
  Read `suggestion` before doing anything else — it names the command that resolves the failure.
93
145
  Retry only when `retriable` is true. `UnknownBranch` means this worktree is not one adiff knows
94
146
  about, because the reviewer has not opened it; report that rather than looping.
95
147
 
96
- ## Handing work over: write the layers
148
+ ## Handing work over
149
+
150
+ Finishing is not a reason to publish anything. Say the work is ready, put the review in front of
151
+ them if they asked for one, and say how to read it. That is the whole handover. A reading order is
152
+ extra work you do on request, and it has its own section further down.
153
+
154
+ ## Put the review in front of them
155
+
156
+ When someone asks you for a review, open it rather than describing how:
157
+
158
+ ```bash
159
+ adiff review pane --repo <repo> --branch <branch>
160
+ ```
161
+
162
+ It splits the pane they are already looking at, so their next move is to look right rather than to
163
+ type. The answer says what happened:
164
+
165
+ ```json
166
+ {"ok":true,"opened":true,"pane":"tmux","command":"adiff review open --repo /work/api --branch add-invitations"}
167
+ ```
168
+
169
+ `opened:false` means nothing could be split, which is ordinary: a terminal without tmux, Zellij,
170
+ WezTerm or kitty has nowhere to put a pane. The answer carries `command` either way, so quote that
171
+ line and let them run it.
172
+
173
+ Open a pane when a review was asked for. Finishing work is not a reason on its own, and taking over
174
+ someone's screen uninvited is worse than a line they have to copy.
175
+
176
+ ## Tell the reviewer how to read it
177
+
178
+ Whether or not a pane opened, say what to do with it. Name the repository they should point at,
179
+ which is the repository the worktree belongs to:
97
180
 
98
- You know the order the change was built in. The reviewer does not, and rebuilding it by reading
99
- every file is the most expensive way to learn something you already have. When you finish a piece
100
- of work, write a **layers**: an ordered set of layers over the diff, each one a claim about a span of
181
+ > Open it with `adiff review open --repo <repo> --branch <branch>`, which lands on this branch's
182
+ > diff. The sidebar lists the files; `j` and `k` move down the diff, `]` and `[` walk between
183
+ > files, `}` and `{` jump to the next and previous change, `G` goes to the end. Select lines with
184
+ > `v`, write a comment with `c`, and send it with `ctrl+s`. Press `?` for the rest.
185
+
186
+ Fill the repository path and the branch in yourself, so nobody has to compose the command or find
187
+ the branch in a list. `--branch` takes the name `branch list` reports; without it the review opens
188
+ on the worktree list.
189
+
190
+ Say what you want looked at hardest, and where you are unsure. A reviewer who knows which part you
191
+ doubt spends their attention there. Offer a reading order rather than writing one: if the change is
192
+ long enough that the order matters, say you can publish one and let them decide.
193
+
194
+ ## Publishing a reading order, when you are asked for one
195
+
196
+ Only when the reviewer asks. A reading order is a real piece of work, it can be wrong, and one
197
+ nobody wanted spends their attention on your summary rather than on the code.
198
+
199
+ The ask often arrives as a comment. Pressing `L` in the review sends you one of these:
200
+
201
+ - "Please write a reading order for this branch with `adiff layers set` …" — there is none yet.
202
+ - "The reading order on this branch describes an older commit …" — read the diff again from
203
+ scratch. Do not patch the old layers; line numbers have moved.
204
+ - "Please revise the reading order …" — there is one and the reviewer wants it different. Ask what
205
+ is wrong with it if the comment does not say.
206
+
207
+ Answer it like any other comment when you are done.
208
+
209
+ When they do ask, write **layers**: an ordered set over the diff, each one a claim about a span of
101
210
  code. The reviewer then walks the argument instead of the filesystem.
102
211
 
103
212
  ```bash
@@ -133,42 +242,114 @@ Rules that make a layers worth reading:
133
242
  - **A title is a claim, not a file name.** "Add the invitation API", never "changes to
134
243
  src/api/invites.ts".
135
244
  - **Line numbers are the new side of the diff**, the same numbers `adiff comment take` reports.
136
- - **Cover everything.** adiff computes coverage itself and answers with the hunks no layer claims;
137
- those show up for the reviewer under "not in any layer" whatever you do. A layers that quietly
138
- skips a third of the diff is worse than no layers, so put the leftovers in a final layer and say
139
- they are mechanical.
245
+ - **Cover everything.** adiff computes coverage itself and answers with the changed lines no layer
246
+ claims; those show up for the reviewer under "not in any layer" whatever you do. A layer set that
247
+ quietly skips a third of the diff is worse than none, so put the leftovers in a final layer and
248
+ say they are mechanical. Claim the lines you actually read: a span reaching past them counts only
249
+ the changed lines inside it, so padding the range buys nothing.
140
250
 
141
251
  The answer to `layers set` is the honest report — check it before you claim to be done:
142
252
 
143
253
  ```json
144
- {"ok":true,"layers":{"version":1,"stale":false,"covered":7,"total":9,"uncovered":[{"path":"src/api/router.ts","start":40,"end":52}],"vanished":[],"layers":[{"title":"Add the invitation data model","files":["src/db/invites.ts"]}]}}
254
+ {"ok":true,"layers":{"version":1,"stale":false,"covered":7,"partial":1,"total":9,"uncovered":[{"path":"src/api/router.ts","start":40,"end":52}],"vanished":[],"layers":[{"title":"Add the invitation data model","files":["src/db/invites.ts"],"covered":1,"partial":0,"vanished":[]}]}}
255
+
256
+ `covered`, `partial` and `vanished` appear per layer as well as for the document, so you can tell
257
+ which of your own layers is the thin one. `vanished` on a layer names paths it claims that are not
258
+ in the diff — usually a typo or a file that moved.
259
+
260
+ `layers set` refuses a document it cannot use and says which layer is wrong and why: a span that
261
+ ends before it starts, a span starting below line 1, a start or end that is not a whole number, a
262
+ block with no `kind`, a layer with no title. It no longer drops a bad span quietly, so a layer that
263
+ used to cover less than you thought now fails loudly instead.
145
264
  ```
146
265
 
147
- `covered`/`total` count hunks. `uncovered` names the ones no layer claims — claim them and set the
148
- layers again. `vanished` names paths a layer points at that this branch does not change, which
149
- usually means a typo in a path. Read it back at any time with:
266
+ `total` counts hunks. `covered` counts the ones where every changed line sits inside a layer, and
267
+ `partial` the ones a layer explains only some of. `uncovered` names the runs of changed lines no
268
+ layer claims, so it reads as line numbers a reviewer would otherwise have to find alone: claim them
269
+ and set the layers again. Done means `uncovered` is empty and `shared` is zero. `vanished` names
270
+ paths a layer points at that this branch does not change, which usually means a typo in a path. Read
271
+ it back at any time with:
150
272
 
151
273
  ```bash
152
- adiff layers show --worktree . --fields covered,total,uncovered
274
+ adiff layers show --worktree . --fields covered,partial,total,uncovered
153
275
  ```
154
276
 
155
- Setting a layers again supersedes the previous one and bumps `version`; the layers records the commit
156
- it was written for, and adiff reports it as `stale` once the branch moves past that commit. After
157
- you address a review, write the layers again.
277
+ `uncovered` does not always empty out by claiming lines you can see. A deleted line is counted at
278
+ the number it had in the old file, so a branch that cuts a file from 409 lines to 394 reports an
279
+ uncovered run at 395-409 — line numbers past the end of the file as it now stands. A span over the
280
+ new file cannot reach them; only a span whose `end` runs past the end of the file can. Write one, or
281
+ say the run is unreachable, rather than reading the leftover as a layer you forgot.
158
282
 
159
- ## Tell the reviewer how to read it
283
+ That case aside, claim the runs you explain and nothing more. A span from line 1 to past the end of
284
+ the file covers whatever happens to it, and it is the wrong trade: the terminal scopes a layer to the
285
+ lines it claims, so a layer claiming the whole file draws the whole diff, and eleven layers over one
286
+ file draw it eleven times. Staleness is cheap by comparison — adiff says when a set is stale and the
287
+ reviewer asks for another.
288
+
289
+ `shared` in the answer counts the hunks more than one layer claims. Coverage cannot see this: a
290
+ reading order whose layers each claim the whole diff reports the same `covered` as one whose layers
291
+ each claim their own run. Done means `uncovered` is empty **and** `shared` is zero.
292
+
293
+ Setting layers again supersedes the previous set and bumps `version`; the set records the commit it
294
+ was written for, and adiff reports it as `stale` once the branch moves past that commit. Once a
295
+ reviewer has a reading order, keep it true: write it again after you address their comments.
296
+
297
+ When you have published one, tell them the sidebar now holds it: `s` swaps between the layers and
298
+ the files, each layer shows the files it covers with the ones already reviewed ticked off, and `]`
299
+ and `[` walk those files in the order you put them in — from the last file of one layer into the
300
+ first of the next.
301
+
302
+ ## Helping draft a review of somebody else's pull request
303
+
304
+ Sometimes the reviewer is not reading your work — they are reading a stranger's pull request,
305
+ checked out into this worktree, and want you to think it through with them before they say anything
306
+ on it. You learn that from the comment itself: a comment written on somebody else's pull request
307
+ carries `"theirs": true`. Read it before anything else you do with the comment.
308
+
309
+ ```json
310
+ {"id":"c7","file":"src/retry.ts","start":40,"end":52,"snippet":"…","body":"is this retry loop safe?","theirs":true}
311
+ ```
312
+
313
+ On such a branch the code is not yours to change. **Never edit, commit or push.** A comment that
314
+ reads like a fix request is a point the reviewer wants made to the author: answer it with
315
+ `comment answer`, in prose, and put the wording the author should read in a draft. A comment with
316
+ no `theirs` is your own work, and the rest of this skill applies.
317
+
318
+ A note to the author is **held** as a draft. Nothing reaches the forge until the reviewer sends it.
319
+
320
+ ```bash
321
+ adiff draft list --repo . --branch their-change
322
+ adiff draft add --repo . --branch their-change --file src/api.ts --start 40 --end 52 --body "…"
323
+ adiff draft edit --repo . --branch their-change --id d1 --body "…"
324
+ adiff draft drop --repo . --branch their-change --id d1
325
+ ```
326
+
327
+ `draft add` anchors the same way `comment send` does, so `--side old` is the version being replaced.
328
+ The `id` you pass to `draft edit` and `draft drop` is the one `draft list` reports.
329
+
330
+ A comment can ask you to rewrite one draft in particular. It carries `"draft": "<id>"` beside
331
+ `theirs`, and its body is the instruction:
332
+
333
+ ```json
334
+ {"id":"c8","body":"shorter, and less sure","theirs":true,"draft":"4f1c…"}
335
+ ```
160
336
 
161
- The person you are handing work to has to open the review themselves, so end your reply with the
162
- command and the keys. Name the repository they should point at, which is the repository the
163
- worktree belongs to:
337
+ Rewrite that draft with `draft edit`, then answer the comment by its id, saying what you changed. A
338
+ draft you wrote or rewrote reads as unread in the review until the reviewer opens it, and the review
339
+ will not send while one is unread, so say you rewrote it rather than leaving the reviewer to notice.
164
340
 
165
- > Open it with `adiff review open --repo <repo>`, then press `enter` on this branch. The sidebar
166
- > lists the layers in reading order; `j` and `k` move between them and the diff follows. Inside a
167
- > layer, `]` and `[` walk its files. Select lines with `v`, write a comment with `c`, stage it with
168
- > `ctrl+a`, and send the whole review with `S`. Press `?` for the rest.
341
+ Rules for drafting on somebody else's behalf:
169
342
 
170
- Say what you want looked at hardest, and where you are unsure. A reviewer who knows which layer you
171
- doubt spends their attention there.
343
+ - **You never write to the pull request.** `draft send`, `remark reply` and `remark accept` all do,
344
+ and every one is the reviewer's, not yours. The reviewer signs the review, so the reviewer sends
345
+ it. Anything that must reach the pull request goes through a draft.
346
+ - **Write what the reviewer meant, not what you would say.** They told you the point; your job is
347
+ the wording. If you are not sure what the point is, ask rather than inventing one.
348
+ - **One draft per point.** A held comment that covers three things cannot be dropped in part.
349
+ - **Say what you drafted.** List the drafts back after you write them, so the reviewer can read
350
+ them over rather than discovering them at the moment of sending.
351
+ - **A draft is not a review of the reviewer.** Do not soften a point they meant sharply, or sharpen
352
+ one they meant gently.
172
353
 
173
354
  ## Discovering the rest
174
355
 
@@ -176,8 +357,9 @@ doubt spends their attention there.
176
357
  adiff describe
177
358
  ```
178
359
 
179
- Returns every command with its options, which are required, and where its payload sits. Use it
180
- instead of guessing, and use `--fields` to keep answers small:
360
+ Returns every command with its options, which are required, which part of the loop it belongs to,
361
+ and where its payload sits. `adiff <command> --help` says the same for one command in plain text.
362
+ Use either instead of guessing, and use `--fields` to keep answers small:
181
363
 
182
364
  ```bash
183
365
  adiff branch list --repo . --fields branch,files