@eliya-oss/agent-diff 0.1.0-alpha.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.
Files changed (111) hide show
  1. package/.agents/adr/README.md +33 -0
  2. package/.agents/prd/README.md +74 -0
  3. package/CHANGELOG.md +58 -0
  4. package/README.md +239 -0
  5. package/bin/adiff.js +2 -0
  6. package/package.json +54 -0
  7. package/skills/adiff/SKILL.md +135 -0
  8. package/src/cli/catalog.ts +178 -0
  9. package/src/cli/commands.ts +335 -0
  10. package/src/cli/error.ts +44 -0
  11. package/src/cli/index.ts +24 -0
  12. package/src/cli/parse.ts +31 -0
  13. package/src/cli/report.ts +96 -0
  14. package/src/cli/story.ts +223 -0
  15. package/src/domain/narrative/coverage.ts +54 -0
  16. package/src/domain/narrative/index.ts +4 -0
  17. package/src/domain/narrative/model.ts +46 -0
  18. package/src/domain/narrative/version.ts +63 -0
  19. package/src/domain/patch/anchor.ts +40 -0
  20. package/src/domain/patch/index.ts +7 -0
  21. package/src/domain/patch/model.ts +54 -0
  22. package/src/domain/patch/parse.ts +106 -0
  23. package/src/domain/patch/render.ts +48 -0
  24. package/src/domain/patch/sticky.ts +39 -0
  25. package/src/domain/review/index.ts +4 -0
  26. package/src/domain/review/lifecycle.ts +45 -0
  27. package/src/domain/review/model.ts +23 -0
  28. package/src/domain/review/vouch.ts +15 -0
  29. package/src/main.ts +186 -0
  30. package/src/service/git/error.ts +16 -0
  31. package/src/service/git/index.ts +3 -0
  32. package/src/service/git/model.ts +13 -0
  33. package/src/service/git/run.ts +27 -0
  34. package/src/service/git/service.ts +133 -0
  35. package/src/service/store/error.ts +11 -0
  36. package/src/service/store/index.ts +5 -0
  37. package/src/service/store/model.ts +33 -0
  38. package/src/service/store/paths.ts +25 -0
  39. package/src/service/store/service.ts +154 -0
  40. package/src/testing/agent-surface.test.ts +92 -0
  41. package/src/testing/batch.test.ts +93 -0
  42. package/src/testing/branch-state.test.ts +99 -0
  43. package/src/testing/chrome-tone.test.ts +57 -0
  44. package/src/testing/comment-block.test.ts +84 -0
  45. package/src/testing/comment-walk.test.ts +96 -0
  46. package/src/testing/compose-box.test.ts +97 -0
  47. package/src/testing/compose.test.ts +67 -0
  48. package/src/testing/context.test.ts +77 -0
  49. package/src/testing/cursor.test.ts +49 -0
  50. package/src/testing/delivery.test.ts +94 -0
  51. package/src/testing/domains/agent/driver.ts +50 -0
  52. package/src/testing/domains/agent/index.ts +2 -0
  53. package/src/testing/domains/app/driver.ts +168 -0
  54. package/src/testing/domains/app/index.ts +2 -0
  55. package/src/testing/domains/branch/driver.ts +51 -0
  56. package/src/testing/domains/branch/index.ts +3 -0
  57. package/src/testing/domains/branch/model.ts +39 -0
  58. package/src/testing/domains/screen/driver.ts +241 -0
  59. package/src/testing/domains/screen/index.ts +2 -0
  60. package/src/testing/driver.ts +31 -0
  61. package/src/testing/escape.test.ts +56 -0
  62. package/src/testing/focus.test.ts +104 -0
  63. package/src/testing/footer-chips.test.ts +65 -0
  64. package/src/testing/footer.test.ts +64 -0
  65. package/src/testing/gaps.test.ts +47 -0
  66. package/src/testing/highlight.test.ts +49 -0
  67. package/src/testing/home-screen.test.ts +51 -0
  68. package/src/testing/index.ts +4 -0
  69. package/src/testing/inline-comments.test.ts +131 -0
  70. package/src/testing/marks.test.ts +49 -0
  71. package/src/testing/mouse.test.ts +87 -0
  72. package/src/testing/navigate.test.ts +73 -0
  73. package/src/testing/palette.test.ts +68 -0
  74. package/src/testing/pending.test.ts +70 -0
  75. package/src/testing/pin-align.test.ts +37 -0
  76. package/src/testing/progress.test.ts +88 -0
  77. package/src/testing/report.test.ts +83 -0
  78. package/src/testing/resume.test.ts +39 -0
  79. package/src/testing/review.test.ts +181 -0
  80. package/src/testing/roundtrip.test.ts +70 -0
  81. package/src/testing/scale.test.ts +55 -0
  82. package/src/testing/scroll-feel.test.ts +81 -0
  83. package/src/testing/sent-comments.test.ts +106 -0
  84. package/src/testing/state.ts +55 -0
  85. package/src/testing/sticky-removed.test.ts +67 -0
  86. package/src/testing/sticky.test.ts +90 -0
  87. package/src/testing/story-rail.test.ts +122 -0
  88. package/src/testing/story.test.ts +183 -0
  89. package/src/testing/stress.test.ts +74 -0
  90. package/src/testing/tree-collapse.test.ts +108 -0
  91. package/src/testing/tree-rows.test.ts +66 -0
  92. package/src/testing/tree.test.ts +91 -0
  93. package/src/testing/tui.test.ts +73 -0
  94. package/src/testing/typing.test.ts +65 -0
  95. package/src/testing/vouch-next.test.ts +65 -0
  96. package/src/testing/vouch-tui.test.ts +77 -0
  97. package/src/testing/wash.test.ts +32 -0
  98. package/src/testing/width.test.ts +62 -0
  99. package/src/tui/app.ts +467 -0
  100. package/src/tui/command.ts +390 -0
  101. package/src/tui/diffview.ts +333 -0
  102. package/src/tui/index.ts +9 -0
  103. package/src/tui/marks.ts +102 -0
  104. package/src/tui/match.ts +34 -0
  105. package/src/tui/model.ts +310 -0
  106. package/src/tui/reduce.ts +305 -0
  107. package/src/tui/render.ts +897 -0
  108. package/src/tui/report.ts +74 -0
  109. package/src/tui/session.ts +32 -0
  110. package/src/tui/theme.ts +61 -0
  111. package/src/tui/tree.ts +149 -0
@@ -0,0 +1,178 @@
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)
@@ -0,0 +1,335 @@
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
+ })
@@ -0,0 +1,44 @@
1
+ import { Data } from "effect"
2
+
3
+ export class UnknownBranch extends Data.TaggedError("UnknownBranch")<{
4
+ readonly repo: string
5
+ readonly branch: string
6
+ readonly known: ReadonlyArray<string>
7
+ }> {}
8
+
9
+ export class UnknownFile extends Data.TaggedError("UnknownFile")<{
10
+ readonly file: string
11
+ readonly known: ReadonlyArray<string>
12
+ }> {}
13
+
14
+ export class UnselectableRange extends Data.TaggedError("UnselectableRange")<{
15
+ readonly file: string
16
+ readonly start: number
17
+ readonly end: number
18
+ }> {}
19
+
20
+ export class UnknownCommand extends Data.TaggedError("UnknownCommand")<{
21
+ readonly name: string
22
+ readonly known: ReadonlyArray<string>
23
+ }> {}
24
+
25
+ export class MissingOption extends Data.TaggedError("MissingOption")<{
26
+ readonly option: string
27
+ }> {}
28
+
29
+ export class EmptyReview extends Data.TaggedError("EmptyReview")<{
30
+ readonly branch: string
31
+ }> {}
32
+
33
+ export class UnknownWorktree extends Data.TaggedError("UnknownWorktree")<{
34
+ readonly worktree: string
35
+ readonly known: ReadonlyArray<string>
36
+ }> {}
37
+
38
+ export class MalformedStory extends Data.TaggedError("MalformedStory")<{
39
+ readonly reason: string
40
+ }> {}
41
+
42
+ export class NoStory extends Data.TaggedError("NoStory")<{
43
+ readonly worktree: string
44
+ }> {}
@@ -0,0 +1,24 @@
1
+ export {
2
+ awaitComments,
3
+ fileSource,
4
+ listBranches,
5
+ listPatches,
6
+ listPending,
7
+ listSent,
8
+ reviewProgress,
9
+ saveReport,
10
+ stageComment,
11
+ submitComment,
12
+ submitReview,
13
+ takeComments,
14
+ toggleVouch,
15
+ } from "./commands.ts"
16
+ export { listStorySteps, setStory, showStory } from "./story.ts"
17
+ export type { StoryReport, StoryStep } from "./story.ts"
18
+ export { numeric, optionsFrom, required } from "./parse.ts"
19
+ export { catalog, commandNames, findCommand } from "./catalog.ts"
20
+ export { failure, fieldsOf, narrow } from "./report.ts"
21
+ export type { CommandSpec, OptionSpec } from "./catalog.ts"
22
+ export { EmptyReview, MalformedStory, MissingOption, NoStory, UnknownBranch, UnknownCommand, UnknownFile, UnknownWorktree, UnselectableRange } from "./error.ts"
23
+ export type { BranchSummary, PendingComment, ProgressReport, CommentRequest, VouchReport, VouchRequest } from "./commands.ts"
24
+ export type { Options } from "./parse.ts"
@@ -0,0 +1,31 @@
1
+ import { Effect, Option } from "effect"
2
+ import { MissingOption } from "./error.ts"
3
+
4
+ export type Options = Readonly<Record<string, string>>
5
+
6
+ export const optionsFrom = (argv: ReadonlyArray<string>): Options => {
7
+ const options: Record<string, string> = {}
8
+ for (let index = 0; index < argv.length; index += 1) {
9
+ const token = argv[index]
10
+ if (token === undefined || !token.startsWith("--")) continue
11
+ const next = argv[index + 1]
12
+ options[token.slice(2)] = next === undefined || next.startsWith("--") ? "true" : next
13
+ }
14
+ return options
15
+ }
16
+
17
+ export const required = Effect.fn("Cli.required")(function* (options: Options, name: string) {
18
+ const value = Option.fromNullishOr(options[name])
19
+ return yield* Option.match(value, {
20
+ onNone: () => new MissingOption({ option: name }),
21
+ onSome: Effect.succeed,
22
+ })
23
+ })
24
+
25
+ export const numeric = Effect.fn("Cli.numeric")(function* (options: Options, name: string) {
26
+ const raw = yield* required(options, name)
27
+ const parsed = Number(raw)
28
+ return yield* Number.isFinite(parsed)
29
+ ? Effect.succeed(parsed)
30
+ : new MissingOption({ option: name })
31
+ })