@eliya-oss/agent-diff 0.1.0-alpha.1 → 0.1.0-alpha.10
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/prd/README.md +2 -2
- package/CHANGELOG.md +64 -0
- package/README.md +21 -11
- package/bin/adiff.js +76 -2
- package/dist/main.js +15039 -0
- package/package.json +8 -6
- package/skills/adiff/SKILL.md +40 -18
- 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/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
|
-
}
|
package/src/cli/story.ts
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { realpath } from "node:fs/promises"
|
|
2
|
-
import { Effect, Option } from "effect"
|
|
3
|
-
import {
|
|
4
|
-
codeBlocks,
|
|
5
|
-
statusOf,
|
|
6
|
-
withFullCoverage,
|
|
7
|
-
type Span,
|
|
8
|
-
type Step,
|
|
9
|
-
type Story,
|
|
10
|
-
type StoryBlock,
|
|
11
|
-
} from "../domain/narrative/index.ts"
|
|
12
|
-
import type { Patch } from "../domain/patch/index.ts"
|
|
13
|
-
import { Git, type Worktree } from "../service/git/index.ts"
|
|
14
|
-
import { Store, type StoredStory } from "../service/store/index.ts"
|
|
15
|
-
import { findBranch, patchesOf } from "./commands.ts"
|
|
16
|
-
import { MalformedStory, NoStory, UnknownWorktree } from "./error.ts"
|
|
17
|
-
|
|
18
|
-
export type StoryStep = {
|
|
19
|
-
readonly title: string
|
|
20
|
-
readonly files: ReadonlyArray<string>
|
|
21
|
-
readonly spans: ReadonlyArray<Span>
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export type StoryReport = {
|
|
25
|
-
readonly version: number
|
|
26
|
-
readonly parent: number | undefined
|
|
27
|
-
readonly head: string
|
|
28
|
-
readonly branchHead: string
|
|
29
|
-
readonly stale: boolean
|
|
30
|
-
readonly written: string
|
|
31
|
-
readonly summary: string
|
|
32
|
-
readonly covered: number
|
|
33
|
-
readonly total: number
|
|
34
|
-
readonly uncovered: ReadonlyArray<Span>
|
|
35
|
-
readonly vanished: ReadonlyArray<string>
|
|
36
|
-
readonly steps: ReadonlyArray<StoryStep>
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type StepInput = {
|
|
40
|
-
readonly title?: unknown
|
|
41
|
-
readonly note?: unknown
|
|
42
|
-
readonly blocks?: unknown
|
|
43
|
-
readonly spans?: unknown
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const unique = (paths: ReadonlyArray<string>): ReadonlyArray<string> => [...new Set(paths)]
|
|
47
|
-
|
|
48
|
-
const spansOfStep = (step: Step): ReadonlyArray<Span> =>
|
|
49
|
-
codeBlocks(step).map(({ path, start, end }) => ({ path, start, end }))
|
|
50
|
-
|
|
51
|
-
const isSpan = (value: unknown): value is Span => {
|
|
52
|
-
const span = value as Partial<Span> | undefined
|
|
53
|
-
return (
|
|
54
|
-
typeof span?.path === "string" &&
|
|
55
|
-
typeof span.start === "number" &&
|
|
56
|
-
typeof span.end === "number"
|
|
57
|
-
)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const isBlock = (value: unknown): value is StoryBlock => {
|
|
61
|
-
const block = value as { kind?: unknown; markdown?: unknown } | undefined
|
|
62
|
-
if (block?.kind === "prose") return typeof block.markdown === "string"
|
|
63
|
-
return block?.kind === "code" && isSpan(value)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const codeBlockOf = (span: Span): StoryBlock => ({
|
|
67
|
-
kind: "code",
|
|
68
|
-
path: span.path,
|
|
69
|
-
start: span.start,
|
|
70
|
-
end: span.end,
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
const blocksOf = (step: StepInput): ReadonlyArray<StoryBlock> => {
|
|
74
|
-
if (Array.isArray(step.blocks)) return step.blocks.filter(isBlock)
|
|
75
|
-
const note = typeof step.note === "string" ? [{ kind: "prose" as const, markdown: step.note }] : []
|
|
76
|
-
const spans = Array.isArray(step.spans) ? step.spans.filter(isSpan) : []
|
|
77
|
-
return [...note, ...spans.map(codeBlockOf)]
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const stepOf = (value: unknown): Option.Option<Step> => {
|
|
81
|
-
const step = value as StepInput | undefined
|
|
82
|
-
const title = typeof step?.title === "string" ? step.title.trim() : ""
|
|
83
|
-
if (step === undefined || title.length === 0) return Option.none()
|
|
84
|
-
const blocks = blocksOf(step)
|
|
85
|
-
return blocks.length === 0 ? Option.none() : Option.some({ title, blocks })
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const parsed = (text: string): Option.Option<Record<string, unknown>> => {
|
|
89
|
-
try {
|
|
90
|
-
const value: unknown = JSON.parse(text)
|
|
91
|
-
return typeof value === "object" && value !== null
|
|
92
|
-
? Option.some(value as Record<string, unknown>)
|
|
93
|
-
: Option.none()
|
|
94
|
-
} catch {
|
|
95
|
-
return Option.none()
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export const readStory = Effect.fn("Cli.readStory")(function* (text: string) {
|
|
100
|
-
const document = yield* Option.match(parsed(text), {
|
|
101
|
-
onNone: () => new MalformedStory({ reason: "the story is not a JSON object" }),
|
|
102
|
-
onSome: Effect.succeed,
|
|
103
|
-
})
|
|
104
|
-
const raw = document["steps"]
|
|
105
|
-
const steps = (Array.isArray(raw) ? raw : []).flatMap((entry) =>
|
|
106
|
-
Option.match(stepOf(entry), { onNone: (): ReadonlyArray<Step> => [], onSome: (step) => [step] }),
|
|
107
|
-
)
|
|
108
|
-
if (steps.length === 0) {
|
|
109
|
-
return yield* new MalformedStory({
|
|
110
|
-
reason: "every step needs a title and at least one span or block",
|
|
111
|
-
})
|
|
112
|
-
}
|
|
113
|
-
const summary = document["summary"]
|
|
114
|
-
return { summary: typeof summary === "string" ? summary : "", steps }
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
const fromStored = (stored: StoredStory): Story => ({
|
|
118
|
-
...stored,
|
|
119
|
-
parent: Option.fromNullishOr(stored.parent),
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
const toStored = (story: Story): StoredStory => ({
|
|
123
|
-
...story,
|
|
124
|
-
parent: Option.getOrUndefined(story.parent),
|
|
125
|
-
})
|
|
126
|
-
|
|
127
|
-
const stepsOf = (patches: ReadonlyArray<Patch>, story: Story): ReadonlyArray<StoryStep> => {
|
|
128
|
-
const present = new Set(patches.map((patch) => patch.path))
|
|
129
|
-
return withFullCoverage(patches, story).steps.map((step) => ({
|
|
130
|
-
title: step.title,
|
|
131
|
-
files: unique(spansOfStep(step).map((span) => span.path)).filter((path) => present.has(path)),
|
|
132
|
-
spans: spansOfStep(step),
|
|
133
|
-
}))
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const reportOf = (
|
|
137
|
-
patches: ReadonlyArray<Patch>,
|
|
138
|
-
story: Story,
|
|
139
|
-
branchHead: string,
|
|
140
|
-
): StoryReport => {
|
|
141
|
-
const status = statusOf(patches, story, branchHead)
|
|
142
|
-
return {
|
|
143
|
-
version: status.version,
|
|
144
|
-
parent: Option.getOrUndefined(status.parent),
|
|
145
|
-
head: status.storyHead,
|
|
146
|
-
branchHead: status.branchHead,
|
|
147
|
-
stale: status.stale,
|
|
148
|
-
written: story.written,
|
|
149
|
-
summary: story.summary,
|
|
150
|
-
covered: status.covered,
|
|
151
|
-
total: status.total,
|
|
152
|
-
uncovered: status.uncovered,
|
|
153
|
-
vanished: status.vanished,
|
|
154
|
-
steps: stepsOf(patches, story),
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const resolve = (path: string): Promise<string> => realpath(path).catch(() => path)
|
|
159
|
-
|
|
160
|
-
const resolveAll = (paths: ReadonlyArray<string>): Promise<ReadonlyArray<string>> =>
|
|
161
|
-
Promise.all(paths.map(resolve))
|
|
162
|
-
|
|
163
|
-
const worktreeAt = Effect.fn("Cli.worktreeAt")(function* (worktreePath: string) {
|
|
164
|
-
const git = yield* Git
|
|
165
|
-
const asked = yield* Effect.promise(() => resolve(worktreePath))
|
|
166
|
-
const worktrees = yield* git.worktrees(asked)
|
|
167
|
-
const paths = worktrees.map((entry) => entry.path)
|
|
168
|
-
const resolved = yield* Effect.promise(() => resolveAll(paths))
|
|
169
|
-
const at = resolved.indexOf(asked)
|
|
170
|
-
const found = worktrees[at]
|
|
171
|
-
return yield* found === undefined
|
|
172
|
-
? new UnknownWorktree({ worktree: asked, known: worktrees.map((entry) => entry.path) })
|
|
173
|
-
: Effect.succeed(found)
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
const storyOf = Effect.fn("Cli.storyOf")(function* (worktree: Worktree) {
|
|
177
|
-
const store = yield* Store
|
|
178
|
-
return Option.map(yield* store.story(worktree.path), fromStored)
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
export const setStory = Effect.fn("Cli.setStory")(function* (
|
|
182
|
-
worktreePath: string,
|
|
183
|
-
text: string,
|
|
184
|
-
written: string,
|
|
185
|
-
) {
|
|
186
|
-
const store = yield* Store
|
|
187
|
-
const worktree = yield* worktreeAt(worktreePath)
|
|
188
|
-
const input = yield* readStory(text)
|
|
189
|
-
const patches = yield* patchesOf(worktree)
|
|
190
|
-
const previous = yield* storyOf(worktree)
|
|
191
|
-
const story: Story = {
|
|
192
|
-
version: Option.match(previous, { onNone: () => 1, onSome: (old) => old.version + 1 }),
|
|
193
|
-
parent: Option.map(previous, (old) => old.version),
|
|
194
|
-
head: worktree.head,
|
|
195
|
-
base: worktree.base,
|
|
196
|
-
written,
|
|
197
|
-
summary: input.summary,
|
|
198
|
-
steps: input.steps,
|
|
199
|
-
}
|
|
200
|
-
yield* store.saveStory(worktree.path, toStored(story))
|
|
201
|
-
return reportOf(patches, story, worktree.head)
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
export const showStory = Effect.fn("Cli.showStory")(function* (worktreePath: string) {
|
|
205
|
-
const worktree = yield* worktreeAt(worktreePath)
|
|
206
|
-
const patches = yield* patchesOf(worktree)
|
|
207
|
-
const found = yield* storyOf(worktree)
|
|
208
|
-
const story = yield* Option.match(found, {
|
|
209
|
-
onNone: () => new NoStory({ worktree: worktree.path }),
|
|
210
|
-
onSome: Effect.succeed,
|
|
211
|
-
})
|
|
212
|
-
return reportOf(patches, story, worktree.head)
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
export const listStorySteps = Effect.fn("Cli.listStorySteps")(function* (
|
|
216
|
-
repo: string,
|
|
217
|
-
branch: string,
|
|
218
|
-
) {
|
|
219
|
-
const worktree = yield* findBranch(repo, branch)
|
|
220
|
-
const found = yield* storyOf(worktree)
|
|
221
|
-
if (Option.isNone(found)) return [] as ReadonlyArray<StoryStep>
|
|
222
|
-
return stepsOf(yield* patchesOf(worktree), found.value)
|
|
223
|
-
})
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Option } from "effect"
|
|
2
|
-
import type { Hunk, Patch } from "../patch/index.ts"
|
|
3
|
-
import { REMAINDER_TITLE, type Coverage, type Span, type Step, type Story, type StoryBlock } from "./model.ts"
|
|
4
|
-
|
|
5
|
-
type CodeBlock = Extract<StoryBlock, { kind: "code" }>
|
|
6
|
-
|
|
7
|
-
const codeBlockOf = (span: Span): CodeBlock => ({
|
|
8
|
-
kind: "code",
|
|
9
|
-
path: span.path,
|
|
10
|
-
start: span.start,
|
|
11
|
-
end: span.end,
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
export const codeBlocks = (step: Step): ReadonlyArray<CodeBlock> =>
|
|
15
|
-
step.blocks.filter((block): block is CodeBlock => block.kind === "code")
|
|
16
|
-
|
|
17
|
-
export const spansOf = (steps: ReadonlyArray<Step>): ReadonlyArray<Span> =>
|
|
18
|
-
steps.flatMap((step) => codeBlocks(step).map(({ path, start, end }) => ({ path, start, end })))
|
|
19
|
-
|
|
20
|
-
const spanOfHunk = (patch: Patch, hunk: Hunk): Option.Option<Span> => {
|
|
21
|
-
const lines = hunk.rows.flatMap((row) =>
|
|
22
|
-
Option.match(Option.orElse(row.newLine, () => row.oldLine), { onNone: () => [], onSome: (n) => [n] }),
|
|
23
|
-
)
|
|
24
|
-
return lines.length === 0
|
|
25
|
-
? Option.none()
|
|
26
|
-
: Option.some({ path: patch.path, start: Math.min(...lines), end: Math.max(...lines) })
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const overlaps = (a: Span, b: Span): boolean => a.path === b.path && a.start <= b.end && a.end >= b.start
|
|
30
|
-
|
|
31
|
-
export const coverage = (patches: ReadonlyArray<Patch>, steps: ReadonlyArray<Step>): Coverage => {
|
|
32
|
-
const claimed = spansOf(steps)
|
|
33
|
-
const hunks = patches.flatMap((patch) =>
|
|
34
|
-
patch.hunks.flatMap((hunk) => Option.match(spanOfHunk(patch, hunk), { onNone: () => [], onSome: (s) => [s] })),
|
|
35
|
-
)
|
|
36
|
-
const missing = hunks.filter((hunk) => !claimed.some((span) => overlaps(span, hunk)))
|
|
37
|
-
return { total: hunks.length, covered: hunks.length - missing.length, missing }
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const withFullCoverage = (patches: ReadonlyArray<Patch>, story: Story): Story => {
|
|
41
|
-
const gap = coverage(patches, story.steps)
|
|
42
|
-
if (gap.missing.length === 0) return story
|
|
43
|
-
const remainder: Step = {
|
|
44
|
-
title: REMAINDER_TITLE,
|
|
45
|
-
blocks: [
|
|
46
|
-
{
|
|
47
|
-
kind: "prose",
|
|
48
|
-
markdown: `${gap.missing.length} hunks the agent did not account for.`,
|
|
49
|
-
},
|
|
50
|
-
...gap.missing.map((span) => codeBlockOf(span)),
|
|
51
|
-
],
|
|
52
|
-
}
|
|
53
|
-
return { ...story, steps: [...story.steps, remainder] }
|
|
54
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { codeBlocks, coverage, spansOf, withFullCoverage } from "./coverage.ts"
|
|
2
|
-
export { describeStatus, reviseFor, statusOf } from "./version.ts"
|
|
3
|
-
export { REMAINDER_TITLE } from "./model.ts"
|
|
4
|
-
export type { Coverage, Span, Step, Story, StoryBlock, StoryStatus } from "./model.ts"
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { Option } from "effect"
|
|
2
|
-
|
|
3
|
-
export type StoryBlock =
|
|
4
|
-
| { readonly kind: "prose"; readonly markdown: string }
|
|
5
|
-
| { readonly kind: "code"; readonly path: string; readonly start: number; readonly end: number }
|
|
6
|
-
|
|
7
|
-
export type Step = {
|
|
8
|
-
readonly title: string
|
|
9
|
-
readonly blocks: ReadonlyArray<StoryBlock>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type Story = {
|
|
13
|
-
readonly version: number
|
|
14
|
-
readonly head: string
|
|
15
|
-
readonly base: string
|
|
16
|
-
readonly parent: Option.Option<number>
|
|
17
|
-
readonly written: string
|
|
18
|
-
readonly summary: string
|
|
19
|
-
readonly steps: ReadonlyArray<Step>
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type Span = {
|
|
23
|
-
readonly path: string
|
|
24
|
-
readonly start: number
|
|
25
|
-
readonly end: number
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type Coverage = {
|
|
29
|
-
readonly total: number
|
|
30
|
-
readonly covered: number
|
|
31
|
-
readonly missing: ReadonlyArray<Span>
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export type StoryStatus = {
|
|
35
|
-
readonly version: number
|
|
36
|
-
readonly parent: Option.Option<number>
|
|
37
|
-
readonly stale: boolean
|
|
38
|
-
readonly storyHead: string
|
|
39
|
-
readonly branchHead: string
|
|
40
|
-
readonly uncovered: ReadonlyArray<Span>
|
|
41
|
-
readonly vanished: ReadonlyArray<string>
|
|
42
|
-
readonly covered: number
|
|
43
|
-
readonly total: number
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const REMAINDER_TITLE = "not in any step"
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Option } from "effect"
|
|
2
|
-
import type { Patch } from "../patch/index.ts"
|
|
3
|
-
import { codeBlocks, coverage, spansOf, withFullCoverage } from "./coverage.ts"
|
|
4
|
-
import type { Step, Story, StoryStatus } from "./model.ts"
|
|
5
|
-
|
|
6
|
-
export const statusOf = (
|
|
7
|
-
patches: ReadonlyArray<Patch>,
|
|
8
|
-
story: Story,
|
|
9
|
-
branchHead: string,
|
|
10
|
-
): StoryStatus => {
|
|
11
|
-
const gap = coverage(patches, story.steps)
|
|
12
|
-
const present = new Set(patches.map((patch) => patch.path))
|
|
13
|
-
const mentioned = new Set(spansOf(story.steps).map((span) => span.path))
|
|
14
|
-
return {
|
|
15
|
-
version: story.version,
|
|
16
|
-
parent: story.parent,
|
|
17
|
-
stale: story.head !== branchHead,
|
|
18
|
-
storyHead: story.head,
|
|
19
|
-
branchHead,
|
|
20
|
-
uncovered: gap.missing,
|
|
21
|
-
vanished: [...mentioned].filter((path) => !present.has(path)),
|
|
22
|
-
covered: gap.covered,
|
|
23
|
-
total: gap.total,
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const describeStatus = (status: StoryStatus): { line: string; warn: boolean } => {
|
|
28
|
-
if (status.stale) {
|
|
29
|
-
return { line: `v${status.version} written for ${status.storyHead}, head is ${status.branchHead}`, warn: true }
|
|
30
|
-
}
|
|
31
|
-
if (status.uncovered.length > 0) {
|
|
32
|
-
return { line: `v${status.version} covers ${status.covered}/${status.total} hunks`, warn: true }
|
|
33
|
-
}
|
|
34
|
-
const lineage = Option.match(status.parent, {
|
|
35
|
-
onNone: () => `v${status.version}`,
|
|
36
|
-
onSome: (parent) => `v${status.version}, revised from v${parent}`,
|
|
37
|
-
})
|
|
38
|
-
return { line: `${lineage} covers the whole diff`, warn: false }
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const reviseFor = (
|
|
42
|
-
previous: Story,
|
|
43
|
-
branchHead: string,
|
|
44
|
-
patches: ReadonlyArray<Patch>,
|
|
45
|
-
written: string,
|
|
46
|
-
): Story => {
|
|
47
|
-
const present = new Set(patches.map((patch) => patch.path))
|
|
48
|
-
const kept: ReadonlyArray<Step> = previous.steps
|
|
49
|
-
.map((step) => ({
|
|
50
|
-
...step,
|
|
51
|
-
blocks: step.blocks.filter((block) => block.kind === "prose" || present.has(block.path)),
|
|
52
|
-
}))
|
|
53
|
-
.filter((step) => codeBlocks(step).length > 0)
|
|
54
|
-
|
|
55
|
-
return withFullCoverage(patches, {
|
|
56
|
-
...previous,
|
|
57
|
-
version: previous.version + 1,
|
|
58
|
-
parent: Option.some(previous.version),
|
|
59
|
-
head: branchHead,
|
|
60
|
-
written,
|
|
61
|
-
steps: kept,
|
|
62
|
-
})
|
|
63
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Option } from "effect"
|
|
2
|
-
import { lineOn, type Anchor, type Patch, type Range, type Row, type Side } from "./model.ts"
|
|
3
|
-
|
|
4
|
-
const sideOf = (rows: ReadonlyArray<Row>): Side =>
|
|
5
|
-
rows.some((row) => Option.isSome(row.newLine)) ? "new" : "old"
|
|
6
|
-
|
|
7
|
-
const linesOn = (rows: ReadonlyArray<Row>, side: Side): ReadonlyArray<number> =>
|
|
8
|
-
rows.flatMap((row) => Option.match(lineOn(row, side), { onNone: () => [], onSome: (n) => [n] }))
|
|
9
|
-
|
|
10
|
-
export const anchorFor = (patch: Patch, from: number, to: number): Option.Option<Anchor> => {
|
|
11
|
-
const [low, high] = from <= to ? [from, to] : [to, from]
|
|
12
|
-
const rows = patch.rows.slice(low, high + 1)
|
|
13
|
-
if (rows.length === 0) return Option.none()
|
|
14
|
-
|
|
15
|
-
const side = sideOf(rows)
|
|
16
|
-
const lines = linesOn(rows, side)
|
|
17
|
-
if (lines.length === 0) return Option.none()
|
|
18
|
-
|
|
19
|
-
return Option.some({
|
|
20
|
-
path: patch.path,
|
|
21
|
-
blob: patch.blob,
|
|
22
|
-
side,
|
|
23
|
-
start: Math.min(...lines),
|
|
24
|
-
end: Math.max(...lines),
|
|
25
|
-
snippet: rows.map((row) => row.text).join("\n"),
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const rowsForRange = (patch: Patch, range: Range): Option.Option<readonly [number, number]> => {
|
|
30
|
-
const covered = patch.rows.filter((row) =>
|
|
31
|
-
Option.match(lineOn(row, range.side), {
|
|
32
|
-
onNone: () => false,
|
|
33
|
-
onSome: (line) => line >= range.start && line <= range.end,
|
|
34
|
-
}),
|
|
35
|
-
)
|
|
36
|
-
const first = covered[0]
|
|
37
|
-
const last = covered.at(-1)
|
|
38
|
-
if (first === undefined || last === undefined) return Option.none()
|
|
39
|
-
return Option.some([first.index, last.index] as const)
|
|
40
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { anchorFor, rowsForRange } from "./anchor.ts"
|
|
2
|
-
export { parsePatches } from "./parse.ts"
|
|
3
|
-
export { renderPatch, renderWindow, scopeAbove } from "./render.ts"
|
|
4
|
-
export { stickyChain } from "./sticky.ts"
|
|
5
|
-
export type { Rendered, RenderedHunk } from "./render.ts"
|
|
6
|
-
export { lineOn } from "./model.ts"
|
|
7
|
-
export type { Anchor, Blob, FilePath, Hunk, Patch, Range, Row, RowKind, Side } from "./model.ts"
|