@eliya-oss/agent-diff 0.1.0-alpha.1 → 0.1.0-alpha.11

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.
Files changed (111) hide show
  1. package/.agents/prd/README.md +2 -2
  2. package/CHANGELOG.md +70 -0
  3. package/README.md +21 -11
  4. package/bin/adiff.js +76 -2
  5. package/dist/main.js +15086 -0
  6. package/package.json +8 -6
  7. package/skills/adiff/SKILL.md +40 -18
  8. package/src/cli/catalog.ts +0 -178
  9. package/src/cli/commands.ts +0 -335
  10. package/src/cli/error.ts +0 -44
  11. package/src/cli/index.ts +0 -24
  12. package/src/cli/parse.ts +0 -31
  13. package/src/cli/report.ts +0 -96
  14. package/src/cli/story.ts +0 -223
  15. package/src/domain/narrative/coverage.ts +0 -54
  16. package/src/domain/narrative/index.ts +0 -4
  17. package/src/domain/narrative/model.ts +0 -46
  18. package/src/domain/narrative/version.ts +0 -63
  19. package/src/domain/patch/anchor.ts +0 -40
  20. package/src/domain/patch/index.ts +0 -7
  21. package/src/domain/patch/model.ts +0 -54
  22. package/src/domain/patch/parse.ts +0 -106
  23. package/src/domain/patch/render.ts +0 -48
  24. package/src/domain/patch/sticky.ts +0 -39
  25. package/src/domain/review/index.ts +0 -4
  26. package/src/domain/review/lifecycle.ts +0 -45
  27. package/src/domain/review/model.ts +0 -23
  28. package/src/domain/review/vouch.ts +0 -15
  29. package/src/main.ts +0 -186
  30. package/src/service/git/error.ts +0 -16
  31. package/src/service/git/index.ts +0 -3
  32. package/src/service/git/model.ts +0 -13
  33. package/src/service/git/run.ts +0 -27
  34. package/src/service/git/service.ts +0 -133
  35. package/src/service/store/error.ts +0 -11
  36. package/src/service/store/index.ts +0 -5
  37. package/src/service/store/model.ts +0 -33
  38. package/src/service/store/paths.ts +0 -25
  39. package/src/service/store/service.ts +0 -154
  40. package/src/testing/agent-surface.test.ts +0 -92
  41. package/src/testing/batch.test.ts +0 -93
  42. package/src/testing/branch-state.test.ts +0 -99
  43. package/src/testing/chrome-tone.test.ts +0 -57
  44. package/src/testing/comment-block.test.ts +0 -84
  45. package/src/testing/comment-walk.test.ts +0 -96
  46. package/src/testing/compose-box.test.ts +0 -97
  47. package/src/testing/compose.test.ts +0 -67
  48. package/src/testing/context.test.ts +0 -77
  49. package/src/testing/cursor.test.ts +0 -49
  50. package/src/testing/delivery.test.ts +0 -94
  51. package/src/testing/domains/agent/driver.ts +0 -50
  52. package/src/testing/domains/agent/index.ts +0 -2
  53. package/src/testing/domains/app/driver.ts +0 -168
  54. package/src/testing/domains/app/index.ts +0 -2
  55. package/src/testing/domains/branch/driver.ts +0 -51
  56. package/src/testing/domains/branch/index.ts +0 -3
  57. package/src/testing/domains/branch/model.ts +0 -39
  58. package/src/testing/domains/screen/driver.ts +0 -241
  59. package/src/testing/domains/screen/index.ts +0 -2
  60. package/src/testing/driver.ts +0 -31
  61. package/src/testing/escape.test.ts +0 -56
  62. package/src/testing/focus.test.ts +0 -104
  63. package/src/testing/footer-chips.test.ts +0 -65
  64. package/src/testing/footer.test.ts +0 -64
  65. package/src/testing/gaps.test.ts +0 -47
  66. package/src/testing/highlight.test.ts +0 -49
  67. package/src/testing/home-screen.test.ts +0 -51
  68. package/src/testing/index.ts +0 -4
  69. package/src/testing/inline-comments.test.ts +0 -131
  70. package/src/testing/marks.test.ts +0 -49
  71. package/src/testing/mouse.test.ts +0 -87
  72. package/src/testing/navigate.test.ts +0 -73
  73. package/src/testing/palette.test.ts +0 -68
  74. package/src/testing/pending.test.ts +0 -70
  75. package/src/testing/pin-align.test.ts +0 -37
  76. package/src/testing/progress.test.ts +0 -88
  77. package/src/testing/report.test.ts +0 -83
  78. package/src/testing/resume.test.ts +0 -39
  79. package/src/testing/review.test.ts +0 -181
  80. package/src/testing/roundtrip.test.ts +0 -70
  81. package/src/testing/scale.test.ts +0 -55
  82. package/src/testing/scroll-feel.test.ts +0 -81
  83. package/src/testing/sent-comments.test.ts +0 -106
  84. package/src/testing/state.ts +0 -55
  85. package/src/testing/sticky-removed.test.ts +0 -67
  86. package/src/testing/sticky.test.ts +0 -90
  87. package/src/testing/story-rail.test.ts +0 -122
  88. package/src/testing/story.test.ts +0 -183
  89. package/src/testing/stress.test.ts +0 -74
  90. package/src/testing/tree-collapse.test.ts +0 -108
  91. package/src/testing/tree-rows.test.ts +0 -66
  92. package/src/testing/tree.test.ts +0 -91
  93. package/src/testing/tui.test.ts +0 -73
  94. package/src/testing/typing.test.ts +0 -65
  95. package/src/testing/vouch-next.test.ts +0 -65
  96. package/src/testing/vouch-tui.test.ts +0 -77
  97. package/src/testing/wash.test.ts +0 -32
  98. package/src/testing/width.test.ts +0 -62
  99. package/src/tui/app.ts +0 -467
  100. package/src/tui/command.ts +0 -390
  101. package/src/tui/diffview.ts +0 -333
  102. package/src/tui/index.ts +0 -9
  103. package/src/tui/marks.ts +0 -102
  104. package/src/tui/match.ts +0 -34
  105. package/src/tui/model.ts +0 -310
  106. package/src/tui/reduce.ts +0 -305
  107. package/src/tui/render.ts +0 -897
  108. package/src/tui/report.ts +0 -74
  109. package/src/tui/session.ts +0 -32
  110. package/src/tui/theme.ts +0 -61
  111. package/src/tui/tree.ts +0 -149
package/package.json CHANGED
@@ -4,23 +4,24 @@
4
4
  "devDependencies": {
5
5
  "@effect/vitest": "^4.0.0-beta.102",
6
6
  "@types/node": "^26.1.2",
7
+ "effect": "^4.0.0-beta.102",
7
8
  "oxlint": "^1.76.0",
9
+ "rolldown": "^1.2.1",
8
10
  "vitest": "^4.1.10"
9
11
  },
10
12
  "peerDependencies": {
11
13
  "typescript": "^7.0.2"
12
14
  },
13
15
  "dependencies": {
14
- "@opentui/core": "^0.4.5",
15
- "effect": "^4.0.0-beta.102"
16
+ "@opentui/core": "^0.4.5"
16
17
  },
17
18
  "engines": {
18
- "node": ">=26"
19
+ "node": ">=22"
19
20
  },
20
21
  "bin": {
21
22
  "adiff": "./bin/adiff.js"
22
23
  },
23
- "version": "0.1.0-alpha.1",
24
+ "version": "0.1.0-alpha.11",
24
25
  "description": "Review agent work across git worktrees like a PR, and hand the comments back to the agent.",
25
26
  "license": "MIT",
26
27
  "repository": {
@@ -29,7 +30,7 @@
29
30
  },
30
31
  "files": [
31
32
  "bin",
32
- "src",
33
+ "dist",
33
34
  "skills",
34
35
  "README.md"
35
36
  ],
@@ -37,7 +38,8 @@
37
38
  "access": "public"
38
39
  },
39
40
  "scripts": {
40
- "check": "pnpm run typecheck && pnpm run lint && pnpm test",
41
+ "check": "pnpm run typecheck && pnpm run lint && pnpm run build && pnpm test",
42
+ "build": "rolldown -c rolldown.config.ts",
41
43
  "typecheck": "tsc --noEmit",
42
44
  "lint": "oxlint && node scripts/check-style.ts",
43
45
  "test": "NODE_OPTIONS=--experimental-ffi vitest run",
@@ -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 story 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 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.
4
4
  ---
5
5
 
6
6
  # adiff
@@ -35,6 +35,14 @@ adiff comment take --worktree . --wait 300
35
35
  Blocks until a comment arrives or the timeout in seconds elapses, then returns the same envelope.
36
36
  An empty `comments` array means the wait expired with nothing new — that is not an error.
37
37
 
38
+ Run the wait in the background, not in the foreground. A foreground wait holds the turn, so you
39
+ cannot do anything else and the person you are working with cannot talk to you. Backgrounded, the
40
+ harness brings you back the moment a comment lands.
41
+
42
+ Re-arm it after each comment you handle, and keep it running while you work. A reviewer reads at
43
+ their own pace, so comments arrive minutes apart, and the whole point is that they reach you as
44
+ events rather than by you asking. When you finish a piece of work, say you are still listening.
45
+
38
46
  ## Acting on a comment
39
47
 
40
48
  Read `snippet` before opening the file: the reviewer commented on the diff, and the file may have
@@ -58,21 +66,21 @@ Read `suggestion` before doing anything else — it names the command that resol
58
66
  Retry only when `retriable` is true. `UnknownBranch` means this worktree is not one adiff knows
59
67
  about, because the reviewer has not opened it; report that rather than looping.
60
68
 
61
- ## Handing work over: write the story
69
+ ## Handing work over: write the layers
62
70
 
63
71
  You know the order the change was built in. The reviewer does not, and rebuilding it by reading
64
72
  every file is the most expensive way to learn something you already have. When you finish a piece
65
- of work, write a **story**: an ordered set of steps over the diff, each one a claim about a span of
73
+ of work, write a **layers**: an ordered set of layers over the diff, each one a claim about a span of
66
74
  code. The reviewer then walks the argument instead of the filesystem.
67
75
 
68
76
  ```bash
69
- adiff story set --worktree . --json - <<'JSON'
77
+ adiff layers set --worktree . --json - <<'JSON'
70
78
  {
71
79
  "summary": "Team invitations, end to end",
72
- "steps": [
80
+ "layers": [
73
81
  {
74
82
  "title": "Add the invitation data model",
75
- "note": "The record every later step leans on",
83
+ "note": "The record every later layer leans on",
76
84
  "spans": [{ "path": "src/db/invites.ts", "start": 1, "end": 48 }]
77
85
  },
78
86
  {
@@ -91,35 +99,49 @@ adiff story set --worktree . --json - <<'JSON'
91
99
  JSON
92
100
  ```
93
101
 
94
- Rules that make a story worth reading:
102
+ Rules that make a layers worth reading:
95
103
 
96
- - **Order is the point.** Step 1 is what the reader must understand before step 2 makes sense.
104
+ - **Order is the point.** Layer 1 is what the reader must understand before layer 2 makes sense.
97
105
  Data model, then the code that uses it, then the surface, then the mechanical bits last.
98
106
  - **A title is a claim, not a file name.** "Add the invitation API", never "changes to
99
107
  src/api/invites.ts".
100
108
  - **Line numbers are the new side of the diff**, the same numbers `adiff comment take` reports.
101
- - **Cover everything.** adiff computes coverage itself and answers with the hunks no step claims;
102
- those show up for the reviewer under "not in any step" whatever you do. A story that quietly
103
- skips a third of the diff is worse than no story, so put the leftovers in a final step and say
109
+ - **Cover everything.** adiff computes coverage itself and answers with the hunks no layer claims;
110
+ those show up for the reviewer under "not in any layer" whatever you do. A layers that quietly
111
+ skips a third of the diff is worse than no layers, so put the leftovers in a final layer and say
104
112
  they are mechanical.
105
113
 
106
- The answer to `story set` is the honest report — check it before you claim to be done:
114
+ The answer to `layers set` is the honest report — check it before you claim to be done:
107
115
 
108
116
  ```json
109
- {"ok":true,"story":{"version":1,"stale":false,"covered":7,"total":9,"uncovered":[{"path":"src/api/router.ts","start":40,"end":52}],"vanished":[],"steps":[{"title":"Add the invitation data model","files":["src/db/invites.ts"]}]}}
117
+ {"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"]}]}}
110
118
  ```
111
119
 
112
- `covered`/`total` count hunks. `uncovered` names the ones no step claims — claim them and set the
113
- story again. `vanished` names paths a step points at that this branch does not change, which
120
+ `covered`/`total` count hunks. `uncovered` names the ones no layer claims — claim them and set the
121
+ layers again. `vanished` names paths a layer points at that this branch does not change, which
114
122
  usually means a typo in a path. Read it back at any time with:
115
123
 
116
124
  ```bash
117
- adiff story show --worktree . --fields covered,total,uncovered
125
+ adiff layers show --worktree . --fields covered,total,uncovered
118
126
  ```
119
127
 
120
- Setting a story again supersedes the previous one and bumps `version`; the story records the commit
128
+ Setting a layers again supersedes the previous one and bumps `version`; the layers records the commit
121
129
  it was written for, and adiff reports it as `stale` once the branch moves past that commit. After
122
- you address a review, write the story again.
130
+ you address a review, write the layers again.
131
+
132
+ ## Tell the reviewer how to read it
133
+
134
+ The person you are handing work to has to open the review themselves, so end your reply with the
135
+ command and the keys. Name the repository they should point at, which is the repository the
136
+ worktree belongs to:
137
+
138
+ > Open it with `adiff review open --repo <repo>`, then press `enter` on this branch. The sidebar
139
+ > lists the layers in reading order; `j` and `k` move between them and the diff follows. Inside a
140
+ > layer, `]` and `[` walk its files. Select lines with `v`, write a comment with `c`, stage it with
141
+ > `ctrl+a`, and send the whole review with `S`. Press `?` for the rest.
142
+
143
+ Say what you want looked at hardest, and where you are unsure. A reviewer who knows which layer you
144
+ doubt spends their attention there.
123
145
 
124
146
  ## Discovering the rest
125
147
 
@@ -1,178 +0,0 @@
1
- export type OptionSpec = {
2
- readonly name: string
3
- readonly required: boolean
4
- readonly value: string
5
- readonly about: string
6
- }
7
-
8
- export type CommandSpec = {
9
- readonly name: string
10
- readonly about: string
11
- readonly safety: "read" | "write"
12
- readonly options: ReadonlyArray<OptionSpec>
13
- readonly dataKey: string
14
- readonly example: string
15
- }
16
-
17
- const repo: OptionSpec = {
18
- name: "repo",
19
- required: true,
20
- value: "path",
21
- about: "Repository whose worktrees are reviewed",
22
- }
23
-
24
- const branch: OptionSpec = {
25
- name: "branch",
26
- required: true,
27
- value: "name",
28
- about: "Branch to act on, as reported by `branch list`",
29
- }
30
-
31
- const file: OptionSpec = {
32
- name: "file",
33
- required: true,
34
- value: "path",
35
- about: "File path as it appears in the diff",
36
- }
37
-
38
- export const catalog: ReadonlyArray<CommandSpec> = [
39
- {
40
- name: "branch list",
41
- about: "Branches with changes against their merge base, and how large each is",
42
- safety: "read",
43
- options: [repo],
44
- dataKey: "branches",
45
- example: "adiff branch list --repo . --fields branch,files",
46
- },
47
- {
48
- name: "comment add",
49
- about: "File a comment against a line range, for the agent in that worktree",
50
- safety: "write",
51
- options: [
52
- repo,
53
- branch,
54
- file,
55
- { name: "start", required: true, value: "line", about: "First line of the range" },
56
- { name: "end", required: true, value: "line", about: "Last line of the range" },
57
- { name: "body", required: true, value: "text", about: "What to tell the agent" },
58
- {
59
- name: "side",
60
- required: false,
61
- value: "new|old",
62
- about: "Which version the lines are on. Defaults to new",
63
- },
64
- ],
65
- dataKey: "batch",
66
- example: 'adiff comment add --repo . --branch cdr-1 --file src/api.ts --start 4 --end 5 --body "why"',
67
- },
68
- {
69
- name: "comment stage",
70
- about: "Add a comment to the review without sending it yet",
71
- safety: "write",
72
- options: [
73
- repo,
74
- branch,
75
- file,
76
- { name: "start", required: true, value: "line", about: "First line of the range" },
77
- { name: "end", required: true, value: "line", about: "Last line of the range" },
78
- { name: "body", required: true, value: "text", about: "What to tell the agent" },
79
- {
80
- name: "side",
81
- required: false,
82
- value: "new|old",
83
- about: "Which version the lines are on. Defaults to new",
84
- },
85
- ],
86
- dataKey: "pending",
87
- example: 'adiff comment stage --repo . --branch cdr-1 --file src/api.ts --start 4 --end 4 --body "why"',
88
- },
89
- {
90
- name: "comment take",
91
- about: "Collect the comments this worktree has not been handed yet. Exactly-once",
92
- safety: "write",
93
- options: [
94
- { name: "worktree", required: true, value: "path", about: "The worktree to collect for" },
95
- {
96
- name: "wait",
97
- required: false,
98
- value: "seconds",
99
- about: "Block until a comment arrives or the timeout elapses",
100
- },
101
- ],
102
- dataKey: "comments",
103
- example: "adiff comment take --worktree . --wait 300",
104
- },
105
- {
106
- name: "file vouch",
107
- about: "Toggle a file as reviewed. Lapses on its own when the file changes",
108
- safety: "write",
109
- options: [repo, branch, file],
110
- dataKey: "vouched",
111
- example: "adiff file vouch --repo . --branch cdr-1 --file src/api.ts",
112
- },
113
- {
114
- name: "review submit",
115
- about: "Send every staged comment as one review, so the agent wakes once",
116
- safety: "write",
117
- options: [repo, branch],
118
- dataKey: "submitted",
119
- example: "adiff review submit --repo . --branch cdr-1",
120
- },
121
- {
122
- name: "review progress",
123
- about: "Which files of a branch are still vouched, and how many there are",
124
- safety: "read",
125
- options: [repo, branch],
126
- dataKey: "vouched",
127
- example: "adiff review progress --repo . --branch cdr-1",
128
- },
129
- {
130
- name: "story set",
131
- about: "Write the reading order for this worktree's diff: ordered steps over spans of files",
132
- safety: "write",
133
- options: [
134
- { name: "worktree", required: true, value: "path", about: "The worktree the story is about" },
135
- {
136
- name: "json",
137
- required: true,
138
- value: "file|-",
139
- about: "The story document, as a file path or - to read stdin",
140
- },
141
- ],
142
- dataKey: "story",
143
- example: "adiff story set --worktree . --json -",
144
- },
145
- {
146
- name: "story show",
147
- about: "The story of a worktree, with the hunks no step claims",
148
- safety: "read",
149
- options: [
150
- { name: "worktree", required: true, value: "path", about: "The worktree to read" },
151
- ],
152
- dataKey: "story",
153
- example: "adiff story show --worktree . --fields steps,uncovered",
154
- },
155
- {
156
- name: "review open",
157
- about: "Open the review terminal. The only command that does not answer in JSON",
158
- safety: "read",
159
- options: [repo],
160
- dataKey: "",
161
- example: "adiff review open --repo .",
162
- },
163
- {
164
- name: "describe",
165
- about: "This catalog, as JSON",
166
- safety: "read",
167
- options: [
168
- { name: "command", required: false, value: "name", about: "Describe one command only" },
169
- ],
170
- dataKey: "commands",
171
- example: "adiff describe --command 'comment add'",
172
- },
173
- ]
174
-
175
- export const commandNames: ReadonlyArray<string> = catalog.map((command) => command.name)
176
-
177
- export const findCommand = (name: string): CommandSpec | undefined =>
178
- catalog.find((command) => command.name === name)
@@ -1,335 +0,0 @@
1
- import { realpath } from "node:fs/promises"
2
- import { Effect, Option } from "effect"
3
- import { anchorFor, lineOn, parsePatches, type Patch, type Side } from "../domain/patch/index.ts"
4
- import { Git, type Worktree } from "../service/git/index.ts"
5
- import { commentOn, isVouched, stage, submitAll, vouch } from "../domain/review/index.ts"
6
- import {
7
- Store,
8
- type Batch,
9
- type StoredComment,
10
- type StoreUnreadable,
11
- type StoreUnwritable,
12
- } from "../service/store/index.ts"
13
- import { EmptyReview, UnknownBranch, UnknownFile, UnselectableRange } from "./error.ts"
14
-
15
- const CONTEXT = 3
16
- const POLL = "500 millis"
17
-
18
- export type BranchSummary = {
19
- readonly branch: string
20
- readonly path: string
21
- readonly head: string
22
- readonly files: number
23
- readonly added: number
24
- readonly removed: number
25
- readonly staged: number
26
- readonly unread: number
27
- }
28
-
29
- export type CommentRequest = {
30
- readonly repo: string
31
- readonly branch: string
32
- readonly file: string
33
- readonly start: number
34
- readonly end: number
35
- readonly body: string
36
- readonly side: Side
37
- readonly id: string
38
- readonly at: string
39
- }
40
-
41
- export const findBranch = Effect.fn("Cli.findBranch")(function* (repo: string, branch: string) {
42
- const git = yield* Git
43
- const worktrees = yield* git.worktrees(repo)
44
- const found = worktrees.find((worktree) => worktree.branch === branch)
45
- return yield* found === undefined
46
- ? new UnknownBranch({ repo, branch, known: worktrees.map((w) => w.branch) })
47
- : Effect.succeed(found)
48
- })
49
-
50
- export const patchesOf = Effect.fn("Cli.patchesOf")(function* (worktree: Worktree) {
51
- const git = yield* Git
52
- const raw = yield* git.diff(worktree, CONTEXT)
53
- return parsePatches(raw)
54
- })
55
-
56
- const findPatch = (patches: ReadonlyArray<Patch>, file: string): Option.Option<Patch> =>
57
- Option.fromNullishOr(patches.find((patch) => patch.path === file))
58
-
59
- const rowsCovering = (
60
- patch: Patch,
61
- side: Side,
62
- start: number,
63
- end: number,
64
- ): ReadonlyArray<number> =>
65
- patch.rows
66
- .filter((row) =>
67
- Option.match(lineOn(row, side), {
68
- onNone: () => false,
69
- onSome: (line) => line >= start && line <= end,
70
- }),
71
- )
72
- .map((row) => row.index)
73
-
74
- const waitingOn = Effect.fn("Cli.waitingOn")(function* (worktree: Worktree) {
75
- const store = yield* Store
76
- const state = yield* store.state(worktree.path)
77
- const batches = yield* store.inbox(worktree.path)
78
- return { staged: state.pending.length, unread: Math.max(0, batches.length - state.consumed) }
79
- })
80
-
81
- export const listBranches = Effect.fn("Cli.listBranches")(function* (repo: string) {
82
- const git = yield* Git
83
- const worktrees = yield* git.worktrees(repo)
84
- const summaries: Array<BranchSummary> = []
85
- for (const worktree of worktrees) {
86
- const stat = yield* git.stat(worktree)
87
- const waiting = yield* waitingOn(worktree)
88
- summaries.push({
89
- branch: worktree.branch,
90
- path: worktree.path,
91
- head: worktree.head,
92
- files: stat.files,
93
- added: stat.added,
94
- removed: stat.removed,
95
- staged: waiting.staged,
96
- unread: waiting.unread,
97
- })
98
- }
99
- return summaries.filter((summary) => summary.files > 0)
100
- })
101
-
102
- export type VouchRequest = {
103
- readonly repo: string
104
- readonly branch: string
105
- readonly file: string
106
- }
107
-
108
- export type VouchReport = {
109
- readonly vouched: ReadonlyArray<string>
110
- readonly total: number
111
- }
112
-
113
- export type ProgressReport = VouchReport & { readonly pending: number }
114
-
115
- const blobOf = (patches: ReadonlyArray<Patch>, file: string): Option.Option<string> =>
116
- Option.map(findPatch(patches, file), (patch) => patch.blob)
117
-
118
- export const toggleVouch = Effect.fn("Cli.toggleVouch")(function* (request: VouchRequest) {
119
- const store = yield* Store
120
- const worktree = yield* findBranch(request.repo, request.branch)
121
- const patches = yield* patchesOf(worktree)
122
-
123
- const blob = yield* Option.match(blobOf(patches, request.file), {
124
- onNone: () =>
125
- new UnknownFile({ file: request.file, known: patches.map((patch) => patch.path) }),
126
- onSome: Effect.succeed,
127
- })
128
-
129
- const current = yield* store.state(worktree.path)
130
- const next = vouch(current.vouches, request.file, blob)
131
- yield* store.saveState(worktree.path, { ...current, vouches: next })
132
-
133
- const files = patches.map((patch) => ({ path: patch.path, blob: patch.blob }))
134
- return {
135
- vouched: files.filter((file) => isVouched(next, file.path, file.blob)).map((file) => file.path),
136
- total: patches.length,
137
- } satisfies VouchReport
138
- })
139
-
140
- export const reviewProgress = Effect.fn("Cli.reviewProgress")(function* (
141
- repo: string,
142
- branch: string,
143
- ) {
144
- const store = yield* Store
145
- const worktree = yield* findBranch(repo, branch)
146
- const patches = yield* patchesOf(worktree)
147
- const current = yield* store.state(worktree.path)
148
- const files = patches.map((patch) => ({ path: patch.path, blob: patch.blob }))
149
- return {
150
- vouched: files.filter((file) => isVouched(current.vouches, file.path, file.blob)).map((f) => f.path),
151
- total: patches.length,
152
- pending: current.pending.length,
153
- }
154
- })
155
-
156
- const anchorRequest = Effect.fn("Cli.anchorRequest")(function* (request: CommentRequest) {
157
- const worktree = yield* findBranch(request.repo, request.branch)
158
- const patches = yield* patchesOf(worktree)
159
- const resolved = yield* Option.match(findPatch(patches, request.file), {
160
- onNone: () =>
161
- new UnknownFile({ file: request.file, known: patches.map((candidate) => candidate.path) }),
162
- onSome: Effect.succeed,
163
- })
164
- const rows = rowsCovering(resolved, request.side, request.start, request.end)
165
- const first = rows[0]
166
- const last = rows.at(-1)
167
- const found =
168
- first === undefined || last === undefined ? Option.none() : anchorFor(resolved, first, last)
169
- const anchor = yield* Option.match(found, {
170
- onNone: () =>
171
- new UnselectableRange({ file: request.file, start: request.start, end: request.end }),
172
- onSome: Effect.succeed,
173
- })
174
- return { worktree, anchor }
175
- })
176
-
177
- export const stageComment = Effect.fn("Cli.stageComment")(function* (request: CommentRequest) {
178
- const store = yield* Store
179
- const { worktree, anchor } = yield* anchorRequest(request)
180
- const staged = stage([], commentOn(request.id, anchor, request.body))
181
- const first = staged[0]
182
- const entry: StoredComment = {
183
- id: request.id,
184
- anchor,
185
- body: first === undefined ? request.body : first.body,
186
- }
187
- const pending = yield* store.stage(worktree.path, entry)
188
- return { pending: pending.length }
189
- })
190
-
191
- export const listPending = Effect.fn("Cli.listPending")(function* (repo: string, branch: string) {
192
- const store = yield* Store
193
- const worktree = yield* findBranch(repo, branch)
194
- const current = yield* store.state(worktree.path)
195
- return current.pending.map((entry) => ({
196
- file: entry.anchor.path,
197
- side: entry.anchor.side,
198
- start: entry.anchor.start,
199
- end: entry.anchor.end,
200
- body: entry.body,
201
- })) satisfies ReadonlyArray<Omit<PendingComment, "at" | "head" | "snippet">>
202
- })
203
-
204
- export const listSent = Effect.fn("Cli.listSent")(function* (repo: string, branch: string) {
205
- const store = yield* Store
206
- const worktree = yield* findBranch(repo, branch)
207
- return flatten(yield* store.inbox(worktree.path)).map((comment) => ({
208
- file: comment.file,
209
- side: comment.side,
210
- start: comment.start,
211
- end: comment.end,
212
- body: comment.body,
213
- }))
214
- })
215
-
216
- export const submitReview = Effect.fn("Cli.submitReview")(function* (
217
- repo: string,
218
- branch: string,
219
- id: string,
220
- at: string,
221
- ) {
222
- const store = yield* Store
223
- const worktree = yield* findBranch(repo, branch)
224
- const current = yield* store.state(worktree.path)
225
- if (current.pending.length === 0) return yield* new EmptyReview({ branch })
226
- const comments = submitAll(
227
- current.pending.map((entry) => commentOn(entry.id, entry.anchor, entry.body)),
228
- ).map((comment) => ({ id: comment.id, anchor: comment.anchor, body: comment.body }))
229
- const batch: Batch = { id, at, head: worktree.head, comments }
230
- yield* store.submit(worktree.path, batch)
231
- yield* store.saveState(worktree.path, { ...current, pending: [] })
232
- return { submitted: comments.length }
233
- })
234
-
235
- export const submitComment = Effect.fn("Cli.submitComment")(function* (request: CommentRequest) {
236
- const store = yield* Store
237
- const worktree = yield* findBranch(request.repo, request.branch)
238
- const patches = yield* patchesOf(worktree)
239
- const patch = findPatch(patches, request.file)
240
-
241
- const resolved = yield* Option.match(patch, {
242
- onNone: () =>
243
- new UnknownFile({ file: request.file, known: patches.map((candidate) => candidate.path) }),
244
- onSome: Effect.succeed,
245
- })
246
-
247
- const rows = rowsCovering(resolved, request.side, request.start, request.end)
248
- const first = rows[0]
249
- const last = rows.at(-1)
250
- const anchor =
251
- first === undefined || last === undefined ? Option.none() : anchorFor(resolved, first, last)
252
-
253
- const chosen = yield* Option.match(anchor, {
254
- onNone: () => new UnselectableRange({ file: request.file, start: request.start, end: request.end }),
255
- onSome: Effect.succeed,
256
- })
257
-
258
- const batch: Batch = {
259
- id: request.id,
260
- at: request.at,
261
- head: worktree.head,
262
- comments: [{ id: request.id, anchor: chosen, body: request.body }],
263
- }
264
- yield* store.submit(worktree.path, batch)
265
- return batch
266
- })
267
-
268
- export const listPatches = Effect.fn("Cli.listPatches")(function* (
269
- repo: string,
270
- branch: string,
271
- context = CONTEXT,
272
- ) {
273
- const worktree = yield* findBranch(repo, branch)
274
- const git = yield* Git
275
- return parsePatches(yield* git.diff(worktree, context))
276
- })
277
-
278
- export type PendingComment = {
279
- readonly at: string
280
- readonly head: string
281
- readonly file: string
282
- readonly side: Side
283
- readonly start: number
284
- readonly end: number
285
- readonly snippet: string
286
- readonly body: string
287
- }
288
-
289
- const flatten = (batches: ReadonlyArray<Batch>): ReadonlyArray<PendingComment> =>
290
- batches.flatMap((batch) =>
291
- batch.comments.map((comment) => ({
292
- at: batch.at,
293
- head: batch.head,
294
- file: comment.anchor.path,
295
- side: comment.anchor.side,
296
- start: comment.anchor.start,
297
- end: comment.anchor.end,
298
- snippet: comment.anchor.snippet,
299
- body: comment.body,
300
- })),
301
- )
302
-
303
- export const takeComments = Effect.fn("Cli.takeComments")(function* (worktree: string) {
304
- const store = yield* Store
305
- const resolved = yield* Effect.promise(() => realpath(worktree))
306
- return flatten(yield* store.take(resolved))
307
- })
308
-
309
- export const awaitComments = (
310
- worktree: string,
311
- deadline: number,
312
- ): Effect.Effect<ReadonlyArray<PendingComment>, StoreUnreadable | StoreUnwritable, Store> =>
313
- takeComments(worktree).pipe(
314
- Effect.flatMap((comments) =>
315
- comments.length > 0 || Date.now() >= deadline
316
- ? Effect.succeed(comments)
317
- : Effect.sleep(POLL).pipe(Effect.flatMap(() => awaitComments(worktree, deadline))),
318
- ),
319
- )
320
-
321
- export const saveReport = Effect.fn("Cli.saveReport")(function* (stamp: string, text: string) {
322
- const store = yield* Store
323
- return yield* store.saveReport(stamp, text)
324
- })
325
-
326
- export const fileSource = Effect.fn("Cli.fileSource")(function* (
327
- repo: string,
328
- branch: string,
329
- file: string,
330
- ) {
331
- const git = yield* Git
332
- const worktree = yield* findBranch(repo, branch)
333
- const found = yield* git.source(worktree, file)
334
- return Option.getOrElse(found, (): ReadonlyArray<string> => [])
335
- })