@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.
- package/.agents/adr/README.md +33 -0
- package/.agents/prd/README.md +74 -0
- package/CHANGELOG.md +58 -0
- package/README.md +239 -0
- package/bin/adiff.js +2 -0
- package/package.json +54 -0
- package/skills/adiff/SKILL.md +135 -0
- package/src/cli/catalog.ts +178 -0
- package/src/cli/commands.ts +335 -0
- package/src/cli/error.ts +44 -0
- package/src/cli/index.ts +24 -0
- package/src/cli/parse.ts +31 -0
- package/src/cli/report.ts +96 -0
- package/src/cli/story.ts +223 -0
- package/src/domain/narrative/coverage.ts +54 -0
- package/src/domain/narrative/index.ts +4 -0
- package/src/domain/narrative/model.ts +46 -0
- package/src/domain/narrative/version.ts +63 -0
- package/src/domain/patch/anchor.ts +40 -0
- package/src/domain/patch/index.ts +7 -0
- package/src/domain/patch/model.ts +54 -0
- package/src/domain/patch/parse.ts +106 -0
- package/src/domain/patch/render.ts +48 -0
- package/src/domain/patch/sticky.ts +39 -0
- package/src/domain/review/index.ts +4 -0
- package/src/domain/review/lifecycle.ts +45 -0
- package/src/domain/review/model.ts +23 -0
- package/src/domain/review/vouch.ts +15 -0
- package/src/main.ts +186 -0
- package/src/service/git/error.ts +16 -0
- package/src/service/git/index.ts +3 -0
- package/src/service/git/model.ts +13 -0
- package/src/service/git/run.ts +27 -0
- package/src/service/git/service.ts +133 -0
- package/src/service/store/error.ts +11 -0
- package/src/service/store/index.ts +5 -0
- package/src/service/store/model.ts +33 -0
- package/src/service/store/paths.ts +25 -0
- package/src/service/store/service.ts +154 -0
- package/src/testing/agent-surface.test.ts +92 -0
- package/src/testing/batch.test.ts +93 -0
- package/src/testing/branch-state.test.ts +99 -0
- package/src/testing/chrome-tone.test.ts +57 -0
- package/src/testing/comment-block.test.ts +84 -0
- package/src/testing/comment-walk.test.ts +96 -0
- package/src/testing/compose-box.test.ts +97 -0
- package/src/testing/compose.test.ts +67 -0
- package/src/testing/context.test.ts +77 -0
- package/src/testing/cursor.test.ts +49 -0
- package/src/testing/delivery.test.ts +94 -0
- package/src/testing/domains/agent/driver.ts +50 -0
- package/src/testing/domains/agent/index.ts +2 -0
- package/src/testing/domains/app/driver.ts +168 -0
- package/src/testing/domains/app/index.ts +2 -0
- package/src/testing/domains/branch/driver.ts +51 -0
- package/src/testing/domains/branch/index.ts +3 -0
- package/src/testing/domains/branch/model.ts +39 -0
- package/src/testing/domains/screen/driver.ts +241 -0
- package/src/testing/domains/screen/index.ts +2 -0
- package/src/testing/driver.ts +31 -0
- package/src/testing/escape.test.ts +56 -0
- package/src/testing/focus.test.ts +104 -0
- package/src/testing/footer-chips.test.ts +65 -0
- package/src/testing/footer.test.ts +64 -0
- package/src/testing/gaps.test.ts +47 -0
- package/src/testing/highlight.test.ts +49 -0
- package/src/testing/home-screen.test.ts +51 -0
- package/src/testing/index.ts +4 -0
- package/src/testing/inline-comments.test.ts +131 -0
- package/src/testing/marks.test.ts +49 -0
- package/src/testing/mouse.test.ts +87 -0
- package/src/testing/navigate.test.ts +73 -0
- package/src/testing/palette.test.ts +68 -0
- package/src/testing/pending.test.ts +70 -0
- package/src/testing/pin-align.test.ts +37 -0
- package/src/testing/progress.test.ts +88 -0
- package/src/testing/report.test.ts +83 -0
- package/src/testing/resume.test.ts +39 -0
- package/src/testing/review.test.ts +181 -0
- package/src/testing/roundtrip.test.ts +70 -0
- package/src/testing/scale.test.ts +55 -0
- package/src/testing/scroll-feel.test.ts +81 -0
- package/src/testing/sent-comments.test.ts +106 -0
- package/src/testing/state.ts +55 -0
- package/src/testing/sticky-removed.test.ts +67 -0
- package/src/testing/sticky.test.ts +90 -0
- package/src/testing/story-rail.test.ts +122 -0
- package/src/testing/story.test.ts +183 -0
- package/src/testing/stress.test.ts +74 -0
- package/src/testing/tree-collapse.test.ts +108 -0
- package/src/testing/tree-rows.test.ts +66 -0
- package/src/testing/tree.test.ts +91 -0
- package/src/testing/tui.test.ts +73 -0
- package/src/testing/typing.test.ts +65 -0
- package/src/testing/vouch-next.test.ts +65 -0
- package/src/testing/vouch-tui.test.ts +77 -0
- package/src/testing/wash.test.ts +32 -0
- package/src/testing/width.test.ts +62 -0
- package/src/tui/app.ts +467 -0
- package/src/tui/command.ts +390 -0
- package/src/tui/diffview.ts +333 -0
- package/src/tui/index.ts +9 -0
- package/src/tui/marks.ts +102 -0
- package/src/tui/match.ts +34 -0
- package/src/tui/model.ts +310 -0
- package/src/tui/reduce.ts +305 -0
- package/src/tui/render.ts +897 -0
- package/src/tui/report.ts +74 -0
- package/src/tui/session.ts +32 -0
- package/src/tui/theme.ts +61 -0
- package/src/tui/tree.ts +149 -0
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import type { Patch } from "../domain/patch/index.ts"
|
|
2
|
+
import type { Action } from "./command.ts"
|
|
3
|
+
import { searchCommands } from "./match.ts"
|
|
4
|
+
import {
|
|
5
|
+
crowdedOf,
|
|
6
|
+
directoryOfFile,
|
|
7
|
+
fileOrder,
|
|
8
|
+
hunkStarts,
|
|
9
|
+
onSteps,
|
|
10
|
+
selectedPatch,
|
|
11
|
+
stepFile,
|
|
12
|
+
stepFiles,
|
|
13
|
+
stepHolding,
|
|
14
|
+
type TuiState,
|
|
15
|
+
commentRowsIn,
|
|
16
|
+
filesWithComments,
|
|
17
|
+
} from "./model.ts"
|
|
18
|
+
|
|
19
|
+
const clamp = (value: number, low: number, high: number): number =>
|
|
20
|
+
Math.max(low, Math.min(high, value))
|
|
21
|
+
|
|
22
|
+
const lastRow = (patch: Patch | undefined): number => Math.max(0, (patch?.rows.length ?? 1) - 1)
|
|
23
|
+
|
|
24
|
+
const rowsIn = (state: TuiState): number => selectedPatch(state)?.rows.length ?? 0
|
|
25
|
+
|
|
26
|
+
const withCursorVisible = (state: TuiState): TuiState => {
|
|
27
|
+
const height = Math.max(1, state.viewport)
|
|
28
|
+
const highest = Math.max(0, rowsIn(state) - height)
|
|
29
|
+
const top = state.cursor < state.top ? state.cursor : state.cursor >= state.top + height ? state.cursor - height + 1 : state.top
|
|
30
|
+
return { ...state, top: clamp(top, 0, highest) }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const moveCursor = (state: TuiState, delta: number): TuiState =>
|
|
34
|
+
withCursorVisible({
|
|
35
|
+
...state,
|
|
36
|
+
cursor: clamp(state.cursor + delta, 0, lastRow(selectedPatch(state))),
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
export const scrolled = (state: TuiState, delta: number): TuiState => {
|
|
40
|
+
const highest = Math.max(0, rowsIn(state) - Math.max(1, state.viewport))
|
|
41
|
+
return { ...state, top: clamp(state.top + delta, 0, highest) }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const draggedTo = (state: TuiState, from: number, to: number): TuiState => ({
|
|
45
|
+
...state,
|
|
46
|
+
selecting: true,
|
|
47
|
+
anchorRow: clamp(from, 0, lastRow(selectedPatch(state))),
|
|
48
|
+
cursor: clamp(to, 0, lastRow(selectedPatch(state))),
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const atRow = (state: TuiState, row: number): TuiState =>
|
|
52
|
+
withCursorVisible({ ...state, cursor: clamp(row, 0, lastRow(selectedPatch(state))) })
|
|
53
|
+
|
|
54
|
+
const stepHunk = (state: TuiState, delta: number): TuiState => {
|
|
55
|
+
const starts = hunkStarts(state)
|
|
56
|
+
const target =
|
|
57
|
+
delta > 0
|
|
58
|
+
? starts.find((start) => start > state.cursor)
|
|
59
|
+
: starts.findLast((start) => start < state.cursor)
|
|
60
|
+
return target === undefined ? state : atRow(state, target)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const nextFileWithComments = (state: TuiState, delta: number): number | undefined => {
|
|
64
|
+
const elsewhere = filesWithComments(state).filter((index) => index !== state.patchIndex)
|
|
65
|
+
if (delta > 0) return elsewhere.find((index) => index > state.patchIndex) ?? elsewhere[0]
|
|
66
|
+
return elsewhere.findLast((index) => index < state.patchIndex) ?? elsewhere.at(-1)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const atComment = (state: TuiState, file: number, delta: number): TuiState => {
|
|
70
|
+
const moved = { ...state, patchIndex: file, top: 0, cursor: 0, anchorRow: 0, selecting: false }
|
|
71
|
+
const rows = commentRowsIn(moved, file)
|
|
72
|
+
const landing = delta > 0 ? rows[0] : rows.at(-1)
|
|
73
|
+
return landing === undefined ? moved : atRow(moved, landing)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const stepComment = (state: TuiState, delta: number): TuiState => {
|
|
77
|
+
const here = commentRowsIn(state, state.patchIndex)
|
|
78
|
+
const target =
|
|
79
|
+
delta > 0
|
|
80
|
+
? here.find((row) => row > state.cursor)
|
|
81
|
+
: here.findLast((row) => row < state.cursor)
|
|
82
|
+
if (target !== undefined) return atRow(state, target)
|
|
83
|
+
const file = nextFileWithComments(state, delta)
|
|
84
|
+
if (file !== undefined) return atComment(state, file, delta)
|
|
85
|
+
return here.length > 0 ? state : withNotice(state, "no comments yet")
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const movePending = (state: TuiState, delta: number): TuiState => ({
|
|
89
|
+
...state,
|
|
90
|
+
pendingIndex: clamp(state.pendingIndex + delta, 0, Math.max(0, state.pending.length - 1)),
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const moveStep = (state: TuiState, delta: number): TuiState => {
|
|
94
|
+
const stepIndex = clamp(state.stepIndex + delta, 0, Math.max(0, state.steps.length - 1))
|
|
95
|
+
const landed = { ...state, stepIndex }
|
|
96
|
+
const patchIndex = stepFiles(landed, stepIndex)[0] ?? landed.patchIndex
|
|
97
|
+
return { ...landed, patchIndex, top: 0, cursor: 0, anchorRow: 0, selecting: false }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const inRail = (state: TuiState, delta: number): TuiState =>
|
|
101
|
+
onSteps(state) ? moveStep(state, delta) : moveFile(state, delta)
|
|
102
|
+
|
|
103
|
+
const stepDown = (state: TuiState, delta: number): TuiState =>
|
|
104
|
+
state.focus === "tree" ? inRail(state, delta) : moveCursor(state, delta)
|
|
105
|
+
|
|
106
|
+
const toggleRail = (state: TuiState): TuiState => {
|
|
107
|
+
if (state.steps.length === 0) return withNotice(state, "no story for this branch")
|
|
108
|
+
if (state.rail === "steps") return { ...state, rail: "tree" }
|
|
109
|
+
return { ...state, rail: "steps", stepIndex: stepHolding(state, state.patchIndex) }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const foldDirectory = (state: TuiState, shut: boolean): TuiState => {
|
|
113
|
+
const directory = directoryOfFile(state, state.patchIndex)
|
|
114
|
+
if (directory === undefined) return state
|
|
115
|
+
const closed = state.closed.filter((path) => path !== directory)
|
|
116
|
+
return { ...state, closed: shut ? [...closed, directory] : closed }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const moveBranch = (state: TuiState, delta: number): TuiState => ({
|
|
120
|
+
...state,
|
|
121
|
+
branchIndex: clamp(state.branchIndex + delta, 0, Math.max(0, state.branches.length - 1)),
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
const moveFile = (state: TuiState, delta: number): TuiState => ({
|
|
125
|
+
...state,
|
|
126
|
+
patchIndex: stepFile(state, delta),
|
|
127
|
+
top: 0,
|
|
128
|
+
cursor: 0,
|
|
129
|
+
anchorRow: 0,
|
|
130
|
+
selecting: false,
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
const startSelection = (state: TuiState): TuiState => ({
|
|
134
|
+
...state,
|
|
135
|
+
selecting: true,
|
|
136
|
+
anchorRow: state.cursor,
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
const openCompose = (state: TuiState): TuiState => ({
|
|
140
|
+
...state,
|
|
141
|
+
screen: "compose",
|
|
142
|
+
draft: "",
|
|
143
|
+
anchorRow: state.selecting ? state.anchorRow : state.cursor,
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
const goBack = (state: TuiState): TuiState => {
|
|
147
|
+
if (state.screen === "pending") return { ...state, screen: "review" }
|
|
148
|
+
if (state.screen === "report") return { ...state, screen: state.returnTo, draft: "" }
|
|
149
|
+
if (state.screen === "palette") return { ...state, screen: state.returnTo, query: "" }
|
|
150
|
+
if (state.screen === "compose") return { ...state, screen: "review", draft: "" }
|
|
151
|
+
if (state.selecting) return { ...state, selecting: false, anchorRow: state.cursor }
|
|
152
|
+
return { ...state, screen: "branches", selecting: false }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const openPalette = (state: TuiState): TuiState => ({
|
|
156
|
+
...state,
|
|
157
|
+
screen: "palette",
|
|
158
|
+
returnTo: state.screen,
|
|
159
|
+
query: "",
|
|
160
|
+
paletteIndex: 0,
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const movePalette = (state: TuiState, delta: number): TuiState => ({
|
|
164
|
+
...state,
|
|
165
|
+
paletteIndex: clamp(state.paletteIndex + delta, 0, Math.max(0, paletteMatches(state).length - 1)),
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
export const paletteMatches = (state: TuiState) => searchCommands(state.returnTo, state.query)
|
|
169
|
+
|
|
170
|
+
export const paletteChoice = (state: TuiState): Action | undefined =>
|
|
171
|
+
paletteMatches(state)[state.paletteIndex]?.action
|
|
172
|
+
|
|
173
|
+
const transitions: Record<Action, (state: TuiState) => TuiState> = {
|
|
174
|
+
"branch.next": (state) => moveBranch(state, 1),
|
|
175
|
+
"branch.prev": (state) => moveBranch(state, -1),
|
|
176
|
+
"branch.open": (state) => state,
|
|
177
|
+
"cursor.next": (state) => stepDown(state, 1),
|
|
178
|
+
"cursor.top": (state) => atRow(state, 0),
|
|
179
|
+
"cursor.bottom": (state) => atRow(state, lastRow(selectedPatch(state))),
|
|
180
|
+
"cursor.pageDown": (state) => moveCursor(state, Math.max(1, Math.floor(state.viewport / 2))),
|
|
181
|
+
"cursor.pageUp": (state) => moveCursor(state, -Math.max(1, Math.floor(state.viewport / 2))),
|
|
182
|
+
"context.more": (state) => state,
|
|
183
|
+
"context.less": (state) => state,
|
|
184
|
+
"comment.next": (state) => stepComment(state, 1),
|
|
185
|
+
"comment.prev": (state) => stepComment(state, -1),
|
|
186
|
+
"hunk.next": (state) => stepHunk(state, 1),
|
|
187
|
+
"hunk.prev": (state) => stepHunk(state, -1),
|
|
188
|
+
"cursor.prev": (state) => stepDown(state, -1),
|
|
189
|
+
"file.next": (state) => moveFile(state, 1),
|
|
190
|
+
"file.prev": (state) => moveFile(state, -1),
|
|
191
|
+
"select.start": startSelection,
|
|
192
|
+
"compose.open": openCompose,
|
|
193
|
+
"compose.submit": (state) => state,
|
|
194
|
+
"compose.stage": (state) => state,
|
|
195
|
+
"pending.open": (state) => state,
|
|
196
|
+
"pending.submit": (state) => state,
|
|
197
|
+
"pending.next": (state) => movePending(state, 1),
|
|
198
|
+
"pending.prev": (state) => movePending(state, -1),
|
|
199
|
+
"compose.newline": (state) => ({ ...state, draft: `${state.draft}\n` }),
|
|
200
|
+
"focus.toggle": (state) => ({
|
|
201
|
+
...state,
|
|
202
|
+
focus: state.focus === "diff" ? "tree" : "diff",
|
|
203
|
+
navOpen: true,
|
|
204
|
+
}),
|
|
205
|
+
"nav.zoom": (state) => ({ ...state, navOpen: !state.navOpen, focus: "diff" }),
|
|
206
|
+
"rail.toggle": toggleRail,
|
|
207
|
+
"file.vouch": (state) => state,
|
|
208
|
+
"file.vouch.next": (state) => state,
|
|
209
|
+
"tree.collapse": (state) => foldDirectory(state, true),
|
|
210
|
+
"tree.expand": (state) => foldDirectory(state, false),
|
|
211
|
+
"report.open": (state) => ({ ...state, screen: "report", draft: "", returnTo: state.screen }),
|
|
212
|
+
"report.send": (state) => state,
|
|
213
|
+
"palette.open": openPalette,
|
|
214
|
+
"palette.run": (state) => state,
|
|
215
|
+
back: goBack,
|
|
216
|
+
quit: (state) => state,
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export const reduce = (state: TuiState, action: Action): TuiState => transitions[action](state)
|
|
220
|
+
|
|
221
|
+
export const atFile = (state: TuiState, patchIndex: number): TuiState => ({
|
|
222
|
+
...state,
|
|
223
|
+
patchIndex,
|
|
224
|
+
cursor: 0,
|
|
225
|
+
anchorRow: 0,
|
|
226
|
+
selecting: false,
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
export const withContext = (
|
|
230
|
+
state: TuiState,
|
|
231
|
+
context: number,
|
|
232
|
+
patches: ReadonlyArray<Patch>,
|
|
233
|
+
cursor: number,
|
|
234
|
+
): TuiState => ({ ...state, context, patches, cursor, anchorRow: cursor, selecting: false })
|
|
235
|
+
|
|
236
|
+
export const withPending = (
|
|
237
|
+
state: TuiState,
|
|
238
|
+
pending: TuiState["pending"],
|
|
239
|
+
screen: TuiState["screen"],
|
|
240
|
+
): TuiState => ({ ...state, pending, pendingIndex: 0, staged: pending.length, screen })
|
|
241
|
+
|
|
242
|
+
export const withSent = (state: TuiState, sent: TuiState["sent"]): TuiState => ({ ...state, sent })
|
|
243
|
+
|
|
244
|
+
export const withStory = (state: TuiState, steps: TuiState["steps"]): TuiState => {
|
|
245
|
+
const opened: TuiState = {
|
|
246
|
+
...state,
|
|
247
|
+
steps,
|
|
248
|
+
stepIndex: 0,
|
|
249
|
+
rail: steps.length === 0 ? "tree" : "steps",
|
|
250
|
+
}
|
|
251
|
+
if (steps.length === 0) return opened
|
|
252
|
+
return { ...opened, patchIndex: stepFiles(opened, 0)[0] ?? opened.patchIndex, cursor: 0, top: 0 }
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export const withBranches = (
|
|
256
|
+
state: TuiState,
|
|
257
|
+
branches: TuiState["branches"],
|
|
258
|
+
): TuiState => ({ ...state, branches, branchIndex: Math.min(state.branchIndex, Math.max(0, branches.length - 1)) })
|
|
259
|
+
|
|
260
|
+
export const withSource = (state: TuiState, source: ReadonlyArray<string>): TuiState => ({
|
|
261
|
+
...state,
|
|
262
|
+
source,
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
export const withVouched = (state: TuiState, vouched: ReadonlyArray<string>): TuiState => ({
|
|
266
|
+
...state,
|
|
267
|
+
vouched,
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
export const withPatches = (state: TuiState, patches: ReadonlyArray<Patch>): TuiState => ({
|
|
271
|
+
...state,
|
|
272
|
+
screen: "review",
|
|
273
|
+
patches,
|
|
274
|
+
closed: crowdedOf(patches),
|
|
275
|
+
patchIndex: fileOrder({ ...state, patches, closed: crowdedOf(patches) })[0] ?? 0,
|
|
276
|
+
cursor: 0,
|
|
277
|
+
anchorRow: 0,
|
|
278
|
+
selecting: false,
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
export const typed = (state: TuiState, character: string): TuiState =>
|
|
282
|
+
state.screen === "palette"
|
|
283
|
+
? { ...state, query: `${state.query}${character}`, paletteIndex: 0 }
|
|
284
|
+
: { ...state, draft: `${state.draft}${character}` }
|
|
285
|
+
|
|
286
|
+
export const backspaced = (state: TuiState): TuiState =>
|
|
287
|
+
state.screen === "palette"
|
|
288
|
+
? { ...state, query: state.query.slice(0, -1), paletteIndex: 0 }
|
|
289
|
+
: { ...state, draft: state.draft.slice(0, -1) }
|
|
290
|
+
|
|
291
|
+
export const paletteMoved = (state: TuiState, delta: number): TuiState => movePalette(state, delta)
|
|
292
|
+
|
|
293
|
+
export const paletteClosed = (state: TuiState): TuiState => ({
|
|
294
|
+
...state,
|
|
295
|
+
screen: state.returnTo,
|
|
296
|
+
query: "",
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
export const withNotice = (state: TuiState, notice: string): TuiState => ({
|
|
300
|
+
...state,
|
|
301
|
+
screen: "review",
|
|
302
|
+
draft: "",
|
|
303
|
+
selecting: false,
|
|
304
|
+
notice,
|
|
305
|
+
})
|