@eliya-oss/agent-diff 0.1.0-alpha.1 → 0.1.0-alpha.100
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/.agents/adr/README.md +3 -0
- package/.agents/prd/README.md +2 -2
- package/CHANGELOG.md +666 -0
- package/README.md +37 -79
- package/bin/adiff.js +80 -2
- package/dist/main.js +17611 -0
- package/package.json +14 -10
- package/skills/adiff/SKILL.md +140 -26
- package/src/cli/catalog.ts +0 -178
- package/src/cli/commands.ts +0 -335
- package/src/cli/error.ts +0 -44
- package/src/cli/index.ts +0 -24
- package/src/cli/parse.ts +0 -31
- package/src/cli/report.ts +0 -96
- package/src/cli/story.ts +0 -223
- package/src/domain/narrative/coverage.ts +0 -54
- package/src/domain/narrative/index.ts +0 -4
- package/src/domain/narrative/model.ts +0 -46
- package/src/domain/narrative/version.ts +0 -63
- package/src/domain/patch/anchor.ts +0 -40
- package/src/domain/patch/index.ts +0 -7
- package/src/domain/patch/model.ts +0 -54
- package/src/domain/patch/parse.ts +0 -106
- package/src/domain/patch/render.ts +0 -48
- package/src/domain/patch/sticky.ts +0 -39
- package/src/domain/review/index.ts +0 -4
- package/src/domain/review/lifecycle.ts +0 -45
- package/src/domain/review/model.ts +0 -23
- package/src/domain/review/vouch.ts +0 -15
- package/src/main.ts +0 -186
- package/src/service/git/error.ts +0 -16
- package/src/service/git/index.ts +0 -3
- package/src/service/git/model.ts +0 -13
- package/src/service/git/run.ts +0 -27
- package/src/service/git/service.ts +0 -133
- package/src/service/store/error.ts +0 -11
- package/src/service/store/index.ts +0 -5
- package/src/service/store/model.ts +0 -33
- package/src/service/store/paths.ts +0 -25
- package/src/service/store/service.ts +0 -154
- package/src/testing/agent-surface.test.ts +0 -92
- package/src/testing/batch.test.ts +0 -93
- package/src/testing/branch-state.test.ts +0 -99
- package/src/testing/chrome-tone.test.ts +0 -57
- package/src/testing/comment-block.test.ts +0 -84
- package/src/testing/comment-walk.test.ts +0 -96
- package/src/testing/compose-box.test.ts +0 -97
- package/src/testing/compose.test.ts +0 -67
- package/src/testing/context.test.ts +0 -77
- package/src/testing/cursor.test.ts +0 -49
- package/src/testing/delivery.test.ts +0 -94
- package/src/testing/domains/agent/driver.ts +0 -50
- package/src/testing/domains/agent/index.ts +0 -2
- package/src/testing/domains/app/driver.ts +0 -168
- package/src/testing/domains/app/index.ts +0 -2
- package/src/testing/domains/branch/driver.ts +0 -51
- package/src/testing/domains/branch/index.ts +0 -3
- package/src/testing/domains/branch/model.ts +0 -39
- package/src/testing/domains/screen/driver.ts +0 -241
- package/src/testing/domains/screen/index.ts +0 -2
- package/src/testing/driver.ts +0 -31
- package/src/testing/escape.test.ts +0 -56
- package/src/testing/focus.test.ts +0 -104
- package/src/testing/footer-chips.test.ts +0 -65
- package/src/testing/footer.test.ts +0 -64
- package/src/testing/gaps.test.ts +0 -47
- package/src/testing/highlight.test.ts +0 -49
- package/src/testing/home-screen.test.ts +0 -51
- package/src/testing/index.ts +0 -4
- package/src/testing/inline-comments.test.ts +0 -131
- package/src/testing/marks.test.ts +0 -49
- package/src/testing/mouse.test.ts +0 -87
- package/src/testing/navigate.test.ts +0 -73
- package/src/testing/palette.test.ts +0 -68
- package/src/testing/pending.test.ts +0 -70
- package/src/testing/pin-align.test.ts +0 -37
- package/src/testing/progress.test.ts +0 -88
- package/src/testing/report.test.ts +0 -83
- package/src/testing/resume.test.ts +0 -39
- package/src/testing/review.test.ts +0 -181
- package/src/testing/roundtrip.test.ts +0 -70
- package/src/testing/scale.test.ts +0 -55
- package/src/testing/scroll-feel.test.ts +0 -81
- package/src/testing/sent-comments.test.ts +0 -106
- package/src/testing/state.ts +0 -55
- package/src/testing/sticky-removed.test.ts +0 -67
- package/src/testing/sticky.test.ts +0 -90
- package/src/testing/story-rail.test.ts +0 -122
- package/src/testing/story.test.ts +0 -183
- package/src/testing/stress.test.ts +0 -74
- package/src/testing/tree-collapse.test.ts +0 -108
- package/src/testing/tree-rows.test.ts +0 -66
- package/src/testing/tree.test.ts +0 -91
- package/src/testing/tui.test.ts +0 -73
- package/src/testing/typing.test.ts +0 -65
- package/src/testing/vouch-next.test.ts +0 -65
- package/src/testing/vouch-tui.test.ts +0 -77
- package/src/testing/wash.test.ts +0 -32
- package/src/testing/width.test.ts +0 -62
- package/src/tui/app.ts +0 -467
- package/src/tui/command.ts +0 -390
- package/src/tui/diffview.ts +0 -333
- package/src/tui/index.ts +0 -9
- package/src/tui/marks.ts +0 -102
- package/src/tui/match.ts +0 -34
- package/src/tui/model.ts +0 -310
- package/src/tui/reduce.ts +0 -305
- package/src/tui/render.ts +0 -897
- package/src/tui/report.ts +0 -74
- package/src/tui/session.ts +0 -32
- package/src/tui/theme.ts +0 -61
- package/src/tui/tree.ts +0 -149
package/src/cli/commands.ts
DELETED
|
@@ -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
|
-
})
|
package/src/cli/error.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
}> {}
|
package/src/cli/index.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
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"
|
package/src/cli/parse.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
})
|
package/src/cli/report.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import type { Options } from "./parse.ts"
|
|
2
|
-
|
|
3
|
-
export const USAGE = 2
|
|
4
|
-
export const NOT_FOUND = 3
|
|
5
|
-
export const FAILED = 1
|
|
6
|
-
|
|
7
|
-
type Advice = { readonly exit: number; readonly suggestion: string; readonly retriable: boolean }
|
|
8
|
-
|
|
9
|
-
const ADVICE: Readonly<Record<string, Advice>> = {
|
|
10
|
-
UnknownCommand: {
|
|
11
|
-
exit: USAGE,
|
|
12
|
-
suggestion: "Run `adiff describe` for the commands this build exposes.",
|
|
13
|
-
retriable: false,
|
|
14
|
-
},
|
|
15
|
-
MissingOption: {
|
|
16
|
-
exit: USAGE,
|
|
17
|
-
suggestion: "Run `adiff describe --command <name>` for the options it requires.",
|
|
18
|
-
retriable: false,
|
|
19
|
-
},
|
|
20
|
-
UnknownBranch: {
|
|
21
|
-
exit: NOT_FOUND,
|
|
22
|
-
suggestion: "Run `adiff branch list` for the branches that have something to review.",
|
|
23
|
-
retriable: false,
|
|
24
|
-
},
|
|
25
|
-
UnknownFile: {
|
|
26
|
-
exit: NOT_FOUND,
|
|
27
|
-
suggestion: "The error lists the files this branch changed. Use one of those paths.",
|
|
28
|
-
retriable: false,
|
|
29
|
-
},
|
|
30
|
-
EmptyReview: {
|
|
31
|
-
exit: USAGE,
|
|
32
|
-
suggestion: "Stage a comment with `adiff comment stage` before submitting the review.",
|
|
33
|
-
retriable: false,
|
|
34
|
-
},
|
|
35
|
-
UnknownWorktree: {
|
|
36
|
-
exit: NOT_FOUND,
|
|
37
|
-
suggestion: "Run `adiff story set` from inside a worktree of the repository under review.",
|
|
38
|
-
retriable: false,
|
|
39
|
-
},
|
|
40
|
-
MalformedStory: {
|
|
41
|
-
exit: USAGE,
|
|
42
|
-
suggestion:
|
|
43
|
-
"A story is {\"summary\":\"…\",\"steps\":[{\"title\":\"…\",\"spans\":[{\"path\":\"…\",\"start\":1,\"end\":9}]}]}.",
|
|
44
|
-
retriable: false,
|
|
45
|
-
},
|
|
46
|
-
NoStory: {
|
|
47
|
-
exit: NOT_FOUND,
|
|
48
|
-
suggestion: "No story has been written for this worktree. Write one with `adiff story set`.",
|
|
49
|
-
retriable: false,
|
|
50
|
-
},
|
|
51
|
-
UnselectableRange: {
|
|
52
|
-
exit: USAGE,
|
|
53
|
-
suggestion: "Those lines are not in the diff. Check --side: new is the working tree, old is the version being replaced.",
|
|
54
|
-
retriable: false,
|
|
55
|
-
},
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const FALLBACK: Advice = {
|
|
59
|
-
exit: FAILED,
|
|
60
|
-
suggestion: "Unexpected failure. Re-run with the same arguments to confirm it reproduces.",
|
|
61
|
-
retriable: true,
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const tagOf = (failure: unknown): string =>
|
|
65
|
-
typeof failure === "object" && failure !== null && "_tag" in failure
|
|
66
|
-
? String((failure as { _tag: unknown })._tag)
|
|
67
|
-
: "Unknown"
|
|
68
|
-
|
|
69
|
-
const project = (value: unknown, fields: ReadonlyArray<string>): unknown => {
|
|
70
|
-
if (Array.isArray(value)) return value.map((item) => project(item, fields))
|
|
71
|
-
if (typeof value !== "object" || value === null) return value
|
|
72
|
-
const source = value as Record<string, unknown>
|
|
73
|
-
return Object.fromEntries(fields.filter((field) => field in source).map((f) => [f, source[f]]))
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export const fieldsOf = (options: Options): ReadonlyArray<string> => {
|
|
77
|
-
const raw = options["fields"]
|
|
78
|
-
return raw === undefined || raw === "true" ? [] : raw.split(",").map((field) => field.trim())
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const narrow = (value: unknown, fields: ReadonlyArray<string>): unknown =>
|
|
82
|
-
fields.length === 0 ? value : project(value, fields)
|
|
83
|
-
|
|
84
|
-
export const failure = (cause: unknown): { readonly line: string; readonly exit: number } => {
|
|
85
|
-
const tag = tagOf(cause)
|
|
86
|
-
const advice = ADVICE[tag] ?? FALLBACK
|
|
87
|
-
const spread = typeof cause === "object" && cause !== null ? { ...cause } : { detail: String(cause) }
|
|
88
|
-
const { _tag: _ignored, ...detail } = spread as Record<string, unknown>
|
|
89
|
-
return {
|
|
90
|
-
line: JSON.stringify({
|
|
91
|
-
ok: false,
|
|
92
|
-
error: { ...detail, type: tag, retriable: advice.retriable, suggestion: advice.suggestion },
|
|
93
|
-
}),
|
|
94
|
-
exit: advice.exit,
|
|
95
|
-
}
|
|
96
|
-
}
|