@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
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
-
import { TestDriver } from "./index.ts"
|
|
3
|
-
|
|
4
|
-
const NARROW = 80
|
|
5
|
-
const ROOMY = 120
|
|
6
|
-
const HEIGHT = 24
|
|
7
|
-
|
|
8
|
-
const long =
|
|
9
|
-
"export const handler = async (request: IncomingRequest, context: HandlerContext) => request.body"
|
|
10
|
-
|
|
11
|
-
const wordy = {
|
|
12
|
-
files: [
|
|
13
|
-
{
|
|
14
|
-
path: "src/api/incidents/very/deeply/nested/handler-for-incidents.ts",
|
|
15
|
-
before: ["const before = 1"],
|
|
16
|
-
after: ["const before = 1", long, `${long} ${long}`],
|
|
17
|
-
},
|
|
18
|
-
{ path: "docs/notes.md", before: ["one"], after: ["one", "two"] },
|
|
19
|
-
],
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const spilling = (frame: string, width: number): ReadonlyArray<string> =>
|
|
23
|
-
frame.split("\n").filter((line) => line.length > width || line.trimEnd().length >= width)
|
|
24
|
-
|
|
25
|
-
const tour = async (driver: TestDriver): Promise<ReadonlyArray<string>> => {
|
|
26
|
-
const home = await driver.screen.getFrame()
|
|
27
|
-
await driver.screen.pressKeys(["RETURN", "]"])
|
|
28
|
-
const review = await driver.screen.getFrame()
|
|
29
|
-
await driver.screen.pressKeys(["z"])
|
|
30
|
-
const zoomed = await driver.screen.getFrame()
|
|
31
|
-
await driver.screen.pressCtrl("p")
|
|
32
|
-
const commands = await driver.screen.getFrame()
|
|
33
|
-
return [home, review, zoomed, commands]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
describe("fitting the terminal it is given", () => {
|
|
37
|
-
it("draws nothing past the edge of an eighty column window", async () => {
|
|
38
|
-
// ARRANGE
|
|
39
|
-
await using driver = await TestDriver.create()
|
|
40
|
-
await driver.branch.create(wordy)
|
|
41
|
-
await driver.screen.open({ width: NARROW, height: HEIGHT })
|
|
42
|
-
|
|
43
|
-
// ACT
|
|
44
|
-
const shots = await tour(driver)
|
|
45
|
-
|
|
46
|
-
// ASSERT
|
|
47
|
-
expect(shots.flatMap((frame) => spilling(frame, NARROW))).toEqual([])
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it("draws nothing past the edge of a hundred and twenty column window", async () => {
|
|
51
|
-
// ARRANGE
|
|
52
|
-
await using driver = await TestDriver.create()
|
|
53
|
-
await driver.branch.create(wordy)
|
|
54
|
-
await driver.screen.open({ width: ROOMY, height: HEIGHT })
|
|
55
|
-
|
|
56
|
-
// ACT
|
|
57
|
-
const shots = await tour(driver)
|
|
58
|
-
|
|
59
|
-
// ASSERT
|
|
60
|
-
expect(shots.flatMap((frame) => spilling(frame, ROOMY))).toEqual([])
|
|
61
|
-
})
|
|
62
|
-
})
|
package/src/tui/app.ts
DELETED
|
@@ -1,467 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto"
|
|
2
|
-
import { buildReport } from "./report.ts"
|
|
3
|
-
import { createCliRenderer, type CliRenderer, type KeyEvent } from "@opentui/core"
|
|
4
|
-
import { Effect, Option } from "effect"
|
|
5
|
-
import { anchorFor } from "../domain/patch/index.ts"
|
|
6
|
-
import {
|
|
7
|
-
listBranches,
|
|
8
|
-
listPatches,
|
|
9
|
-
fileSource,
|
|
10
|
-
listPending,
|
|
11
|
-
listSent,
|
|
12
|
-
listStorySteps,
|
|
13
|
-
reviewProgress,
|
|
14
|
-
saveReport,
|
|
15
|
-
stageComment,
|
|
16
|
-
submitReview,
|
|
17
|
-
submitComment,
|
|
18
|
-
toggleVouch,
|
|
19
|
-
} from "../cli/index.ts"
|
|
20
|
-
import type { Git } from "../service/git/index.ts"
|
|
21
|
-
import type { Store } from "../service/store/index.ts"
|
|
22
|
-
import { actionFor, takesText, type Action } from "./command.ts"
|
|
23
|
-
import {
|
|
24
|
-
initialState,
|
|
25
|
-
nextUnreviewed,
|
|
26
|
-
rowAtSourceLine,
|
|
27
|
-
sourceLineAt,
|
|
28
|
-
stepContext,
|
|
29
|
-
selectedBranch,
|
|
30
|
-
selectedPatch,
|
|
31
|
-
selectionRange,
|
|
32
|
-
type TuiState,
|
|
33
|
-
} from "./model.ts"
|
|
34
|
-
import {
|
|
35
|
-
atFile,
|
|
36
|
-
backspaced,
|
|
37
|
-
draggedTo,
|
|
38
|
-
paletteChoice,
|
|
39
|
-
paletteClosed,
|
|
40
|
-
paletteMoved,
|
|
41
|
-
reduce,
|
|
42
|
-
scrolled,
|
|
43
|
-
typed,
|
|
44
|
-
withNotice,
|
|
45
|
-
withContext,
|
|
46
|
-
withBranches,
|
|
47
|
-
withPatches,
|
|
48
|
-
withPending,
|
|
49
|
-
withSent,
|
|
50
|
-
withSource,
|
|
51
|
-
withStory,
|
|
52
|
-
withVouched,
|
|
53
|
-
} from "./reduce.ts"
|
|
54
|
-
import { Screen } from "./render.ts"
|
|
55
|
-
import { readSession, sessionOf, writeSession, type Session } from "./session.ts"
|
|
56
|
-
|
|
57
|
-
type Needs = Git | Store
|
|
58
|
-
|
|
59
|
-
export const NOTICE_MS = 2200
|
|
60
|
-
|
|
61
|
-
export type AppOptions = {
|
|
62
|
-
readonly renderer: CliRenderer
|
|
63
|
-
readonly repo: string
|
|
64
|
-
readonly run: <A>(effect: Effect.Effect<A, unknown, Needs>) => Promise<A>
|
|
65
|
-
readonly branches: TuiState["branches"]
|
|
66
|
-
readonly noticeMs?: number | undefined
|
|
67
|
-
readonly sessionPath?: string | undefined
|
|
68
|
-
readonly resume?: Session | undefined
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const PRINTABLE = /^[\S ]$/
|
|
72
|
-
const KEY_HISTORY = 40
|
|
73
|
-
|
|
74
|
-
const copyToClipboard = (text: string): void => {
|
|
75
|
-
const encoded = Buffer.from(text, "utf8").toString("base64")
|
|
76
|
-
process.stdout.write(`\u001B]52;c;${encoded}\u0007`)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const asKey = (name: string): KeyEvent =>
|
|
80
|
-
(name.startsWith("ctrl+")
|
|
81
|
-
? { name: name.slice(5), sequence: name.slice(5), ctrl: true, shift: false }
|
|
82
|
-
: { name, sequence: name, ctrl: false, shift: false }) as KeyEvent
|
|
83
|
-
|
|
84
|
-
const keyName = (key: KeyEvent): string => {
|
|
85
|
-
const base = key.shift && key.name.length === 1 ? key.name.toUpperCase() : key.name
|
|
86
|
-
return key.ctrl ? `ctrl+${base}` : base
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export class App {
|
|
90
|
-
private state: TuiState
|
|
91
|
-
private readonly screen: Screen
|
|
92
|
-
private pending: Promise<void> = Promise.resolve()
|
|
93
|
-
private failure = ""
|
|
94
|
-
|
|
95
|
-
private readonly renderer: CliRenderer
|
|
96
|
-
private readonly repo: string
|
|
97
|
-
private readonly run: <A>(effect: Effect.Effect<A, unknown, Needs>) => Promise<A>
|
|
98
|
-
private readonly noticeMs: number
|
|
99
|
-
private readonly sessionPath: string | undefined
|
|
100
|
-
private remembered = ""
|
|
101
|
-
private readonly keys: Array<string> = []
|
|
102
|
-
private fading: ReturnType<typeof setTimeout> | undefined
|
|
103
|
-
|
|
104
|
-
constructor(options: AppOptions) {
|
|
105
|
-
this.renderer = options.renderer
|
|
106
|
-
this.repo = options.repo
|
|
107
|
-
this.run = options.run
|
|
108
|
-
this.noticeMs = options.noticeMs ?? NOTICE_MS
|
|
109
|
-
this.sessionPath = options.sessionPath
|
|
110
|
-
const { branches, renderer } = options
|
|
111
|
-
this.state = initialState(branches)
|
|
112
|
-
this.screen = new Screen(renderer, options.repo)
|
|
113
|
-
this.screen.update(this.state)
|
|
114
|
-
this.screen.listen({
|
|
115
|
-
onScroll: (delta) => this.commit(scrolled(this.measured(), delta)),
|
|
116
|
-
onDrag: (from, to) => this.commit(draggedTo(this.measured(), from, to)),
|
|
117
|
-
onChip: (key) => this.dispatchTask(() => this.onKey(asKey(key))),
|
|
118
|
-
})
|
|
119
|
-
renderer.keyInput.on("keypress", (key) => this.dispatch(key))
|
|
120
|
-
renderer.on("destroy", () => this.stopFading())
|
|
121
|
-
renderer.on("frame", () => this.syncGeometry())
|
|
122
|
-
const resume = options.resume
|
|
123
|
-
if (resume !== undefined) this.dispatchTask(() => this.resume(resume))
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
private dispatchTask(task: () => Promise<void>): void {
|
|
127
|
-
this.pending = this.pending.then(task).catch((cause: unknown) => this.fail(cause))
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
private async resume(session: Session): Promise<void> {
|
|
131
|
-
const branches = this.state.branches
|
|
132
|
-
if (session.branchIndex >= branches.length) return
|
|
133
|
-
this.state = { ...this.state, branchIndex: session.branchIndex }
|
|
134
|
-
await this.openBranch()
|
|
135
|
-
const patchIndex = Math.min(session.patchIndex, Math.max(0, this.state.patches.length - 1))
|
|
136
|
-
this.commit({ ...this.state, patchIndex, cursor: session.cursor, top: session.top })
|
|
137
|
-
await this.loadSource()
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private rememberPlace(next: TuiState): void {
|
|
141
|
-
if (this.sessionPath === undefined || next.screen !== "review") return
|
|
142
|
-
const session = sessionOf(next)
|
|
143
|
-
const line = JSON.stringify(session)
|
|
144
|
-
if (line === this.remembered) return
|
|
145
|
-
this.remembered = line
|
|
146
|
-
void writeSession(this.sessionPath, session)
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
private dispatch(key: KeyEvent): void {
|
|
150
|
-
this.pending = this.pending
|
|
151
|
-
.then(() => this.onKey(key))
|
|
152
|
-
.catch((cause: unknown) => this.fail(cause))
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
private fail(cause: unknown): void {
|
|
156
|
-
this.failure = cause instanceof Error ? `${cause.message}\n${cause.stack ?? ""}` : String(cause)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
lastFailure(): string {
|
|
160
|
-
return this.failure
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
settled(): Promise<void> {
|
|
164
|
-
return this.pending
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
private syncGeometry(): void {
|
|
168
|
-
const rows = this.screen.viewportRows()
|
|
169
|
-
if (rows === this.state.viewport) return
|
|
170
|
-
this.commit({ ...this.state, viewport: rows })
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
private measured(): TuiState {
|
|
174
|
-
return { ...this.state, viewport: this.screen.viewportRows() }
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
private commit(next: TuiState): void {
|
|
178
|
-
const appeared = next.notice.length > 0 && next.notice !== this.state.notice
|
|
179
|
-
this.state = next
|
|
180
|
-
this.rememberPlace(next)
|
|
181
|
-
this.screen.update(next)
|
|
182
|
-
if (appeared) this.fade()
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
private stopFading(): void {
|
|
186
|
-
if (this.fading === undefined) return
|
|
187
|
-
clearTimeout(this.fading)
|
|
188
|
-
this.fading = undefined
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private fade(): void {
|
|
192
|
-
this.stopFading()
|
|
193
|
-
this.fading = setTimeout(() => {
|
|
194
|
-
this.fading = undefined
|
|
195
|
-
if (this.state.notice.length > 0) this.commit({ ...this.state, notice: "" })
|
|
196
|
-
}, this.noticeMs)
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
private effects(): Readonly<Partial<Record<Action, () => Promise<void> | void>>> {
|
|
200
|
-
return {
|
|
201
|
-
quit: () => this.renderer.destroy(),
|
|
202
|
-
"branch.open": () => this.openBranch(),
|
|
203
|
-
"compose.submit": () => this.send(),
|
|
204
|
-
"compose.stage": () => this.stage(),
|
|
205
|
-
"palette.run": () => this.runChoice(),
|
|
206
|
-
"comment.next": () => this.walkComments(1),
|
|
207
|
-
"comment.prev": () => this.walkComments(-1),
|
|
208
|
-
"file.next": () => this.moveFile(1),
|
|
209
|
-
"file.prev": () => this.moveFile(-1),
|
|
210
|
-
"cursor.next": () => this.commitSynced("cursor.next"),
|
|
211
|
-
"cursor.prev": () => this.commitSynced("cursor.prev"),
|
|
212
|
-
"rail.toggle": () => this.commitSynced("rail.toggle"),
|
|
213
|
-
"file.vouch": () => this.vouch(false),
|
|
214
|
-
"file.vouch.next": () => this.vouch(true),
|
|
215
|
-
"pending.open": () => this.openPending(),
|
|
216
|
-
"pending.submit": () => this.sendReview(),
|
|
217
|
-
"report.open": () => this.commit(reduce(this.measured(), "report.open")),
|
|
218
|
-
back: () => this.goBack(),
|
|
219
|
-
"report.send": () => this.sendReport(),
|
|
220
|
-
"context.more": () => this.expand(1),
|
|
221
|
-
"context.less": () => this.expand(-1),
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private async onKey(key: KeyEvent, forced?: Action): Promise<void> {
|
|
226
|
-
const action = forced ?? actionFor(this.state.screen, keyName(key))
|
|
227
|
-
this.remember(action, key)
|
|
228
|
-
if (action === undefined) return this.onText(key)
|
|
229
|
-
const effect = this.effects()[action]
|
|
230
|
-
if (effect !== undefined) return effect()
|
|
231
|
-
this.commit(reduce(this.measured(), action))
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
private onText(key: KeyEvent): void {
|
|
235
|
-
if (!takesText(this.state.screen)) return
|
|
236
|
-
if (key.name === "backspace") return this.commit(backspaced(this.state))
|
|
237
|
-
if (key.name === "down") return this.commit(paletteMoved(this.state, 1))
|
|
238
|
-
if (key.name === "up") return this.commit(paletteMoved(this.state, -1))
|
|
239
|
-
if (PRINTABLE.test(key.sequence)) this.commit(typed(this.state, key.sequence))
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
private async runChoice(): Promise<void> {
|
|
243
|
-
const chosen = paletteChoice(this.state)
|
|
244
|
-
const closed = paletteClosed(this.state)
|
|
245
|
-
if (chosen === undefined) return this.commit(closed)
|
|
246
|
-
this.state = closed
|
|
247
|
-
await this.onKey({ name: "", ctrl: false, sequence: "" } as KeyEvent, chosen)
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
private async openBranch(): Promise<void> {
|
|
251
|
-
const branch = selectedBranch(this.state)
|
|
252
|
-
if (branch === undefined) return
|
|
253
|
-
const patches = await this.run(listPatches(this.repo, branch.branch))
|
|
254
|
-
const progress = await this.run(reviewProgress(this.repo, branch.branch))
|
|
255
|
-
const pending = await this.run(listPending(this.repo, branch.branch))
|
|
256
|
-
const steps = await this.run(listStorySteps(this.repo, branch.branch))
|
|
257
|
-
const opened = withVouched(withPatches(this.state, patches), progress.vouched)
|
|
258
|
-
const sent = await this.loadSent(branch.branch)
|
|
259
|
-
this.commit(withStory(withSent(withPending(opened, pending, "review"), sent), steps))
|
|
260
|
-
await this.loadSource()
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
private async goBack(): Promise<void> {
|
|
264
|
-
const next = reduce(this.measured(), "back")
|
|
265
|
-
this.commit(next)
|
|
266
|
-
if (next.screen !== "branches") return
|
|
267
|
-
this.commit(withBranches(this.state, await this.run(listBranches(this.repo))))
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
private async walkComments(delta: number): Promise<void> {
|
|
271
|
-
const was = this.state.patchIndex
|
|
272
|
-
this.commit(reduce(this.measured(), delta > 0 ? "comment.next" : "comment.prev"))
|
|
273
|
-
if (this.state.patchIndex !== was) await this.loadSource()
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
private async commitSynced(action: Action): Promise<void> {
|
|
277
|
-
const was = this.state.patchIndex
|
|
278
|
-
this.commit(reduce(this.measured(), action))
|
|
279
|
-
if (this.state.patchIndex !== was) await this.loadSource()
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
private moveFile(delta: number): Promise<void> {
|
|
283
|
-
return this.commitSynced(delta > 0 ? "file.next" : "file.prev")
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
private async vouch(advance: boolean): Promise<void> {
|
|
287
|
-
const branch = selectedBranch(this.state)
|
|
288
|
-
const patch = selectedPatch(this.state)
|
|
289
|
-
if (branch === undefined || patch === undefined) return
|
|
290
|
-
const report = await this.run(
|
|
291
|
-
toggleVouch({ repo: this.repo, branch: branch.branch, file: patch.path }),
|
|
292
|
-
)
|
|
293
|
-
const marked = report.vouched.includes(patch.path)
|
|
294
|
-
const next = withVouched(this.state, report.vouched)
|
|
295
|
-
if (!advance) {
|
|
296
|
-
return this.commit(withNotice(next, marked ? `marked ${patch.path}` : `unmarked ${patch.path}`))
|
|
297
|
-
}
|
|
298
|
-
const target = nextUnreviewed(next, next.patchIndex)
|
|
299
|
-
if (target === undefined) return this.commit(withNotice(next, "every file reviewed"))
|
|
300
|
-
this.commit(withNotice(atFile(next, target), `marked ${patch.path}`))
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
private request(): Parameters<typeof submitComment>[0] | undefined {
|
|
304
|
-
const patch = selectedPatch(this.state)
|
|
305
|
-
const branch = selectedBranch(this.state)
|
|
306
|
-
const [from, to] = selectionRange(this.state)
|
|
307
|
-
if (patch === undefined || branch === undefined || this.state.draft.length === 0) return undefined
|
|
308
|
-
const anchor = anchorFor(patch, from, to)
|
|
309
|
-
if (Option.isNone(anchor)) return undefined
|
|
310
|
-
return {
|
|
311
|
-
repo: this.repo,
|
|
312
|
-
branch: branch.branch,
|
|
313
|
-
file: patch.path,
|
|
314
|
-
side: anchor.value.side,
|
|
315
|
-
start: anchor.value.start,
|
|
316
|
-
end: anchor.value.end,
|
|
317
|
-
body: this.state.draft,
|
|
318
|
-
id: randomUUID(),
|
|
319
|
-
at: new Date().toISOString(),
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
private async stage(): Promise<void> {
|
|
324
|
-
const request = this.request()
|
|
325
|
-
if (request === undefined) return this.commit(withNotice(this.state, "nothing to stage"))
|
|
326
|
-
await this.run(stageComment(request))
|
|
327
|
-
const branch = selectedBranch(this.state)
|
|
328
|
-
const pending =
|
|
329
|
-
branch === undefined ? [] : await this.run(listPending(this.repo, branch.branch))
|
|
330
|
-
const next = withPending(this.state, pending, "review")
|
|
331
|
-
this.commit(withNotice(next, `${pending.length} staged`))
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
private loadSent(branch: string): Promise<TuiState["sent"]> {
|
|
335
|
-
return this.run(listSent(this.repo, branch))
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
private async loadSource(): Promise<void> {
|
|
339
|
-
const branch = selectedBranch(this.state)
|
|
340
|
-
const patch = selectedPatch(this.state)
|
|
341
|
-
if (branch === undefined || patch === undefined) return
|
|
342
|
-
const source = await this.run(fileSource(this.repo, branch.branch, patch.path))
|
|
343
|
-
this.commit(withSource(this.state, source))
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
private async expand(delta: number): Promise<void> {
|
|
347
|
-
const branch = selectedBranch(this.state)
|
|
348
|
-
const next = stepContext(this.state.context, delta)
|
|
349
|
-
if (branch === undefined || next === this.state.context) return
|
|
350
|
-
const line = sourceLineAt(this.state, this.state.cursor)
|
|
351
|
-
const patches = await this.run(listPatches(this.repo, branch.branch, next))
|
|
352
|
-
const patch = patches[this.state.patchIndex]
|
|
353
|
-
const cursor = patch === undefined || line === undefined ? 0 : rowAtSourceLine(patch, line)
|
|
354
|
-
this.commit(withContext(this.state, next, patches, cursor))
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
private async openPending(): Promise<void> {
|
|
358
|
-
const branch = selectedBranch(this.state)
|
|
359
|
-
if (branch === undefined) return
|
|
360
|
-
const pending = await this.run(listPending(this.repo, branch.branch))
|
|
361
|
-
if (pending.length === 0) return this.commit(withNotice(this.state, "nothing staged"))
|
|
362
|
-
this.commit(withPending(this.state, pending, "pending"))
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
private async sendReview(): Promise<void> {
|
|
366
|
-
const branch = selectedBranch(this.state)
|
|
367
|
-
if (branch === undefined) return
|
|
368
|
-
const report = await this.run(
|
|
369
|
-
submitReview(this.repo, branch.branch, randomUUID(), new Date().toISOString()),
|
|
370
|
-
)
|
|
371
|
-
const cleared = withSent(
|
|
372
|
-
withPending(this.state, [], "review"),
|
|
373
|
-
await this.loadSent(branch.branch),
|
|
374
|
-
)
|
|
375
|
-
this.commit(withNotice(cleared, `review sent — ${report.submitted} comment${report.submitted === 1 ? "" : "s"}, one wake-up`))
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
private remember(action: Action | undefined, key: KeyEvent): void {
|
|
379
|
-
if (takesText(this.state.screen) && action === undefined) return
|
|
380
|
-
this.keys.push(action ?? keyName(key))
|
|
381
|
-
if (this.keys.length > KEY_HISTORY) this.keys.shift()
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
private async sendReport(): Promise<void> {
|
|
385
|
-
if (this.state.draft.trim().length === 0) {
|
|
386
|
-
return this.commit(withNotice(this.state, "say what went wrong first"))
|
|
387
|
-
}
|
|
388
|
-
const text = buildReport(this.state, {
|
|
389
|
-
repo: this.repo,
|
|
390
|
-
keys: this.keys,
|
|
391
|
-
failure: this.failure,
|
|
392
|
-
width: this.renderer.width,
|
|
393
|
-
height: this.renderer.height,
|
|
394
|
-
})
|
|
395
|
-
const stamp = new Date().toISOString().replace(/[:.]/g, "-")
|
|
396
|
-
const path = await this.run(saveReport(stamp, text))
|
|
397
|
-
copyToClipboard(text)
|
|
398
|
-
const closed = { ...this.state, screen: this.state.returnTo, draft: "" }
|
|
399
|
-
this.commit(withNotice(closed, `report copied — ${path}`))
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
private async send(): Promise<void> {
|
|
403
|
-
const patch = selectedPatch(this.state)
|
|
404
|
-
const branch = selectedBranch(this.state)
|
|
405
|
-
const [from, to] = selectionRange(this.state)
|
|
406
|
-
if (patch === undefined || branch === undefined || this.state.draft.length === 0) return
|
|
407
|
-
const anchor = anchorFor(patch, from, to)
|
|
408
|
-
if (Option.isNone(anchor)) return this.commit(withNotice(this.state, "nothing selected"))
|
|
409
|
-
await this.run(
|
|
410
|
-
submitComment({
|
|
411
|
-
repo: this.repo,
|
|
412
|
-
branch: branch.branch,
|
|
413
|
-
file: patch.path,
|
|
414
|
-
side: anchor.value.side,
|
|
415
|
-
start: anchor.value.start,
|
|
416
|
-
end: anchor.value.end,
|
|
417
|
-
body: this.state.draft,
|
|
418
|
-
id: randomUUID(),
|
|
419
|
-
at: new Date().toISOString(),
|
|
420
|
-
}),
|
|
421
|
-
)
|
|
422
|
-
const sent = await this.loadSent(branch.branch)
|
|
423
|
-
this.commit(withNotice(withSent(this.state, sent), "sent to the agent"))
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
export const launch = Effect.fn("Tui.launch")(function* (
|
|
428
|
-
repo: string,
|
|
429
|
-
renderer: CliRenderer,
|
|
430
|
-
noticeMs?: number,
|
|
431
|
-
sessionPath?: string,
|
|
432
|
-
) {
|
|
433
|
-
const context = yield* Effect.context<Needs>()
|
|
434
|
-
const branches = yield* listBranches(repo)
|
|
435
|
-
const resume =
|
|
436
|
-
sessionPath === undefined ? undefined : yield* Effect.promise(() => readSession(sessionPath))
|
|
437
|
-
return new App({
|
|
438
|
-
renderer,
|
|
439
|
-
repo,
|
|
440
|
-
run: Effect.runPromiseWith(context),
|
|
441
|
-
branches,
|
|
442
|
-
noticeMs,
|
|
443
|
-
sessionPath,
|
|
444
|
-
resume,
|
|
445
|
-
})
|
|
446
|
-
})
|
|
447
|
-
|
|
448
|
-
const untilDestroyed = (renderer: CliRenderer): Effect.Effect<void> =>
|
|
449
|
-
Effect.callback<void>((resume) => {
|
|
450
|
-
renderer.on("destroy", () => resume(Effect.void))
|
|
451
|
-
})
|
|
452
|
-
|
|
453
|
-
export const runOn = Effect.fn("Tui.runOn")(function* (
|
|
454
|
-
repo: string,
|
|
455
|
-
renderer: CliRenderer,
|
|
456
|
-
sessionPath?: string,
|
|
457
|
-
) {
|
|
458
|
-
yield* launch(repo, renderer, undefined, sessionPath)
|
|
459
|
-
yield* untilDestroyed(renderer)
|
|
460
|
-
})
|
|
461
|
-
|
|
462
|
-
export const runTui = Effect.fn("Tui.run")(function* (repo: string, sessionPath?: string) {
|
|
463
|
-
const renderer = yield* Effect.promise(() => createCliRenderer({ exitOnCtrlC: true }))
|
|
464
|
-
yield* runOn(repo, renderer, sessionPath)
|
|
465
|
-
})
|
|
466
|
-
|
|
467
|
-
export type { Action }
|