@eliya-oss/agent-diff 0.1.0-alpha.0 → 0.1.0-alpha.2

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 (110) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +21 -0
  3. package/README.md +72 -189
  4. package/bin/adiff.js +1 -1
  5. package/dist/main.js +14467 -0
  6. package/package.json +8 -6
  7. package/src/cli/catalog.ts +0 -178
  8. package/src/cli/commands.ts +0 -335
  9. package/src/cli/error.ts +0 -44
  10. package/src/cli/index.ts +0 -24
  11. package/src/cli/parse.ts +0 -31
  12. package/src/cli/report.ts +0 -96
  13. package/src/cli/story.ts +0 -223
  14. package/src/domain/narrative/coverage.ts +0 -54
  15. package/src/domain/narrative/index.ts +0 -4
  16. package/src/domain/narrative/model.ts +0 -46
  17. package/src/domain/narrative/version.ts +0 -63
  18. package/src/domain/patch/anchor.ts +0 -40
  19. package/src/domain/patch/index.ts +0 -7
  20. package/src/domain/patch/model.ts +0 -54
  21. package/src/domain/patch/parse.ts +0 -106
  22. package/src/domain/patch/render.ts +0 -48
  23. package/src/domain/patch/sticky.ts +0 -39
  24. package/src/domain/review/index.ts +0 -4
  25. package/src/domain/review/lifecycle.ts +0 -45
  26. package/src/domain/review/model.ts +0 -23
  27. package/src/domain/review/vouch.ts +0 -15
  28. package/src/main.ts +0 -186
  29. package/src/service/git/error.ts +0 -16
  30. package/src/service/git/index.ts +0 -3
  31. package/src/service/git/model.ts +0 -13
  32. package/src/service/git/run.ts +0 -27
  33. package/src/service/git/service.ts +0 -133
  34. package/src/service/store/error.ts +0 -11
  35. package/src/service/store/index.ts +0 -5
  36. package/src/service/store/model.ts +0 -33
  37. package/src/service/store/paths.ts +0 -25
  38. package/src/service/store/service.ts +0 -154
  39. package/src/testing/agent-surface.test.ts +0 -92
  40. package/src/testing/batch.test.ts +0 -93
  41. package/src/testing/branch-state.test.ts +0 -99
  42. package/src/testing/chrome-tone.test.ts +0 -57
  43. package/src/testing/comment-block.test.ts +0 -84
  44. package/src/testing/comment-walk.test.ts +0 -96
  45. package/src/testing/compose-box.test.ts +0 -97
  46. package/src/testing/compose.test.ts +0 -67
  47. package/src/testing/context.test.ts +0 -77
  48. package/src/testing/cursor.test.ts +0 -49
  49. package/src/testing/delivery.test.ts +0 -94
  50. package/src/testing/domains/agent/driver.ts +0 -50
  51. package/src/testing/domains/agent/index.ts +0 -2
  52. package/src/testing/domains/app/driver.ts +0 -168
  53. package/src/testing/domains/app/index.ts +0 -2
  54. package/src/testing/domains/branch/driver.ts +0 -51
  55. package/src/testing/domains/branch/index.ts +0 -3
  56. package/src/testing/domains/branch/model.ts +0 -39
  57. package/src/testing/domains/screen/driver.ts +0 -241
  58. package/src/testing/domains/screen/index.ts +0 -2
  59. package/src/testing/driver.ts +0 -31
  60. package/src/testing/escape.test.ts +0 -56
  61. package/src/testing/focus.test.ts +0 -104
  62. package/src/testing/footer-chips.test.ts +0 -65
  63. package/src/testing/footer.test.ts +0 -64
  64. package/src/testing/gaps.test.ts +0 -47
  65. package/src/testing/highlight.test.ts +0 -49
  66. package/src/testing/home-screen.test.ts +0 -51
  67. package/src/testing/index.ts +0 -4
  68. package/src/testing/inline-comments.test.ts +0 -131
  69. package/src/testing/marks.test.ts +0 -49
  70. package/src/testing/mouse.test.ts +0 -87
  71. package/src/testing/navigate.test.ts +0 -73
  72. package/src/testing/palette.test.ts +0 -68
  73. package/src/testing/pending.test.ts +0 -70
  74. package/src/testing/pin-align.test.ts +0 -37
  75. package/src/testing/progress.test.ts +0 -88
  76. package/src/testing/report.test.ts +0 -83
  77. package/src/testing/resume.test.ts +0 -39
  78. package/src/testing/review.test.ts +0 -181
  79. package/src/testing/roundtrip.test.ts +0 -70
  80. package/src/testing/scale.test.ts +0 -55
  81. package/src/testing/scroll-feel.test.ts +0 -81
  82. package/src/testing/sent-comments.test.ts +0 -106
  83. package/src/testing/state.ts +0 -55
  84. package/src/testing/sticky-removed.test.ts +0 -67
  85. package/src/testing/sticky.test.ts +0 -90
  86. package/src/testing/story-rail.test.ts +0 -122
  87. package/src/testing/story.test.ts +0 -183
  88. package/src/testing/stress.test.ts +0 -74
  89. package/src/testing/tree-collapse.test.ts +0 -108
  90. package/src/testing/tree-rows.test.ts +0 -66
  91. package/src/testing/tree.test.ts +0 -91
  92. package/src/testing/tui.test.ts +0 -73
  93. package/src/testing/typing.test.ts +0 -65
  94. package/src/testing/vouch-next.test.ts +0 -65
  95. package/src/testing/vouch-tui.test.ts +0 -77
  96. package/src/testing/wash.test.ts +0 -32
  97. package/src/testing/width.test.ts +0 -62
  98. package/src/tui/app.ts +0 -467
  99. package/src/tui/command.ts +0 -390
  100. package/src/tui/diffview.ts +0 -333
  101. package/src/tui/index.ts +0 -9
  102. package/src/tui/marks.ts +0 -102
  103. package/src/tui/match.ts +0 -34
  104. package/src/tui/model.ts +0 -310
  105. package/src/tui/reduce.ts +0 -305
  106. package/src/tui/render.ts +0 -897
  107. package/src/tui/report.ts +0 -74
  108. package/src/tui/session.ts +0 -32
  109. package/src/tui/theme.ts +0 -61
  110. package/src/tui/tree.ts +0 -149
package/src/tui/reduce.ts DELETED
@@ -1,305 +0,0 @@
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
- })