@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
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises"
|
|
2
|
-
import { join } from "node:path"
|
|
3
|
-
import { Context, Effect, Layer, Option } from "effect"
|
|
4
|
-
import { FileUnreadable } from "./error.ts"
|
|
5
|
-
import type { DiffStat, Worktree } from "./model.ts"
|
|
6
|
-
import { gitOrEmpty } from "./run.ts"
|
|
7
|
-
|
|
8
|
-
const DEFAULT_BRANCH_CANDIDATES = ["origin/master", "origin/main", "master", "main"]
|
|
9
|
-
|
|
10
|
-
const STAT = /(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?/
|
|
11
|
-
|
|
12
|
-
type Shape = {
|
|
13
|
-
readonly worktrees: (repo: string) => Effect.Effect<ReadonlyArray<Worktree>>
|
|
14
|
-
readonly diff: (worktree: Worktree, context: number) => Effect.Effect<string>
|
|
15
|
-
readonly stat: (worktree: Worktree) => Effect.Effect<DiffStat>
|
|
16
|
-
readonly source: (
|
|
17
|
-
worktree: Worktree,
|
|
18
|
-
path: string,
|
|
19
|
-
) => Effect.Effect<Option.Option<ReadonlyArray<string>>>
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class Git extends Context.Service<Git, Shape>()("adiff/Git") {}
|
|
23
|
-
|
|
24
|
-
const parseStat = (raw: string): DiffStat => {
|
|
25
|
-
const matched = STAT.exec(raw)
|
|
26
|
-
return {
|
|
27
|
-
files: Number(matched?.[1] ?? 0),
|
|
28
|
-
added: Number(matched?.[2] ?? 0),
|
|
29
|
-
removed: Number(matched?.[3] ?? 0),
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type Entry = { path: string; branch: string; head: string; detached: boolean }
|
|
34
|
-
|
|
35
|
-
const readEntries = (porcelain: string): ReadonlyArray<Entry> => {
|
|
36
|
-
const entries: Array<Entry> = []
|
|
37
|
-
for (const line of porcelain.split("\n")) {
|
|
38
|
-
if (line.startsWith("worktree ")) {
|
|
39
|
-
entries.push({ path: line.slice("worktree ".length), branch: "", head: "", detached: false })
|
|
40
|
-
}
|
|
41
|
-
const current = entries.at(-1)
|
|
42
|
-
if (current === undefined) continue
|
|
43
|
-
if (line.startsWith("branch ")) current.branch = line.slice("branch ".length).replace("refs/heads/", "")
|
|
44
|
-
if (line.startsWith("HEAD ")) current.head = line.slice("HEAD ".length)
|
|
45
|
-
if (line === "detached") current.detached = true
|
|
46
|
-
}
|
|
47
|
-
return entries
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const baseNames = new Map<string, string>()
|
|
51
|
-
const mergeBases = new Map<string, string>()
|
|
52
|
-
|
|
53
|
-
const findDefaultBranch = Effect.fn("Git.findDefaultBranch")(function* (repo: string) {
|
|
54
|
-
const symbolic = yield* gitOrEmpty(repo, ["symbolic-ref", "refs/remotes/origin/HEAD"])
|
|
55
|
-
if (symbolic.trim().length > 0) return symbolic.trim().replace("refs/remotes/", "")
|
|
56
|
-
for (const candidate of DEFAULT_BRANCH_CANDIDATES) {
|
|
57
|
-
const verified = yield* gitOrEmpty(repo, ["rev-parse", "--verify", candidate])
|
|
58
|
-
if (verified.trim().length > 0) return candidate
|
|
59
|
-
}
|
|
60
|
-
return "HEAD"
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
const defaultBranch = Effect.fn("Git.defaultBranch")(function* (repo: string) {
|
|
64
|
-
const known = baseNames.get(repo)
|
|
65
|
-
if (known !== undefined) return known
|
|
66
|
-
const found = yield* findDefaultBranch(repo)
|
|
67
|
-
baseNames.set(repo, found)
|
|
68
|
-
return found
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
const mergeBaseOf = Effect.fn("Git.mergeBase")(function* (entry: Entry, base: string) {
|
|
72
|
-
const key = `${entry.path} ${entry.head} ${base}`
|
|
73
|
-
const known = mergeBases.get(key)
|
|
74
|
-
if (known !== undefined) return known
|
|
75
|
-
const found = (yield* gitOrEmpty(entry.path, ["merge-base", base, "HEAD"])).trim()
|
|
76
|
-
mergeBases.set(key, found)
|
|
77
|
-
return found
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
const toWorktree = Effect.fn("Git.toWorktree")(function* (entry: Entry, base: string) {
|
|
81
|
-
const mergeBase = yield* mergeBaseOf(entry, base)
|
|
82
|
-
return {
|
|
83
|
-
path: entry.path,
|
|
84
|
-
branch: entry.detached ? `(detached ${entry.head.slice(0, 8)})` : entry.branch,
|
|
85
|
-
head: entry.head.slice(0, 8),
|
|
86
|
-
base: mergeBase.slice(0, 8),
|
|
87
|
-
detached: entry.detached,
|
|
88
|
-
} satisfies Worktree
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
const splitLines = (text: string): ReadonlyArray<string> => text.split("\n")
|
|
92
|
-
|
|
93
|
-
const absent = Effect.succeed(Option.none<string>())
|
|
94
|
-
|
|
95
|
-
const readText = Effect.fn("Git.readText")(function* (absolute: string, path: string) {
|
|
96
|
-
return yield* Effect.tryPromise({
|
|
97
|
-
try: () => readFile(absolute, "utf8"),
|
|
98
|
-
catch: (cause) => new FileUnreadable({ path, reason: String(cause) }),
|
|
99
|
-
}).pipe(Effect.map(Option.some), Effect.catchTag("FileUnreadable", () => absent))
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
const listWorktrees = Effect.fn("Git.worktrees")(function* (repo: string) {
|
|
103
|
-
const porcelain = yield* gitOrEmpty(repo, ["worktree", "list", "--porcelain"])
|
|
104
|
-
const base = yield* defaultBranch(repo)
|
|
105
|
-
const entries = readEntries(porcelain)
|
|
106
|
-
const found: Array<Worktree> = []
|
|
107
|
-
for (const entry of entries) found.push(yield* toWorktree(entry, base))
|
|
108
|
-
return found as ReadonlyArray<Worktree>
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
const readDiff = Effect.fn("Git.diff")(function* (worktree: Worktree, context: number) {
|
|
112
|
-
const target = worktree.base.length > 0 ? worktree.base : "HEAD"
|
|
113
|
-
return yield* gitOrEmpty(worktree.path, ["diff", `-U${context}`, target])
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
const readStat = Effect.fn("Git.stat")(function* (worktree: Worktree) {
|
|
117
|
-
const raw = yield* gitOrEmpty(worktree.path, ["diff", "--shortstat", worktree.base])
|
|
118
|
-
return parseStat(raw)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
const readSource = Effect.fn("Git.source")(function* (worktree: Worktree, path: string) {
|
|
122
|
-
const text = yield* readText(join(worktree.path, path), path)
|
|
123
|
-
return Option.map(text, splitLines)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const shape: Shape = {
|
|
127
|
-
worktrees: listWorktrees,
|
|
128
|
-
diff: readDiff,
|
|
129
|
-
stat: readStat,
|
|
130
|
-
source: readSource,
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export const GitLive = Layer.succeed(Git)(shape)
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Data } from "effect"
|
|
2
|
-
|
|
3
|
-
export class StoreUnwritable extends Data.TaggedError("StoreUnwritable")<{
|
|
4
|
-
readonly path: string
|
|
5
|
-
readonly reason: string
|
|
6
|
-
}> {}
|
|
7
|
-
|
|
8
|
-
export class StoreUnreadable extends Data.TaggedError("StoreUnreadable")<{
|
|
9
|
-
readonly path: string
|
|
10
|
-
readonly reason: string
|
|
11
|
-
}> {}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { Store, StoreLive, storeAt } from "./service.ts"
|
|
2
|
-
export { StoreUnreadable, StoreUnwritable } from "./error.ts"
|
|
3
|
-
export { branchDir, defaultRoot, inboxPath, reportPath, reportsDir, slugOf, statePath, storyPath } from "./paths.ts"
|
|
4
|
-
export { emptyBranchState } from "./model.ts"
|
|
5
|
-
export type { Batch, BranchState, StoredComment, StoredStory } from "./model.ts"
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Anchor } from "../../domain/patch/index.ts"
|
|
2
|
-
import type { Step } from "../../domain/narrative/index.ts"
|
|
3
|
-
|
|
4
|
-
export type StoredStory = {
|
|
5
|
-
readonly version: number
|
|
6
|
-
readonly head: string
|
|
7
|
-
readonly base: string
|
|
8
|
-
readonly parent: number | undefined
|
|
9
|
-
readonly written: string
|
|
10
|
-
readonly summary: string
|
|
11
|
-
readonly steps: ReadonlyArray<Step>
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type StoredComment = {
|
|
15
|
-
readonly id: string
|
|
16
|
-
readonly anchor: Anchor
|
|
17
|
-
readonly body: string
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type Batch = {
|
|
21
|
-
readonly id: string
|
|
22
|
-
readonly at: string
|
|
23
|
-
readonly head: string
|
|
24
|
-
readonly comments: ReadonlyArray<StoredComment>
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type BranchState = {
|
|
28
|
-
readonly vouches: Readonly<Record<string, string>>
|
|
29
|
-
readonly consumed: number
|
|
30
|
-
readonly pending: ReadonlyArray<StoredComment>
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const emptyBranchState: BranchState = { vouches: {}, consumed: 0, pending: [] }
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { homedir } from "node:os"
|
|
2
|
-
import { join } from "node:path"
|
|
3
|
-
|
|
4
|
-
const NON_SLUG = /[^a-zA-Z0-9]+/g
|
|
5
|
-
|
|
6
|
-
export const slugOf = (worktreePath: string): string => worktreePath.replace(NON_SLUG, "-")
|
|
7
|
-
|
|
8
|
-
export const defaultRoot = (): string => join(homedir(), ".adiff")
|
|
9
|
-
|
|
10
|
-
export const branchDir = (root: string, worktreePath: string): string =>
|
|
11
|
-
join(root, "branches", slugOf(worktreePath))
|
|
12
|
-
|
|
13
|
-
export const inboxPath = (root: string, worktreePath: string): string =>
|
|
14
|
-
join(branchDir(root, worktreePath), "inbox.jsonl")
|
|
15
|
-
|
|
16
|
-
export const statePath = (root: string, worktreePath: string): string =>
|
|
17
|
-
join(branchDir(root, worktreePath), "state.json")
|
|
18
|
-
|
|
19
|
-
export const storyPath = (root: string, worktreePath: string): string =>
|
|
20
|
-
join(branchDir(root, worktreePath), "story.json")
|
|
21
|
-
|
|
22
|
-
export const reportsDir = (root: string): string => join(root, "reports")
|
|
23
|
-
|
|
24
|
-
export const reportPath = (root: string, stamp: string): string =>
|
|
25
|
-
join(reportsDir(root), `${stamp}.md`)
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { mkdir, readFile, appendFile, writeFile } from "node:fs/promises"
|
|
2
|
-
import { Context, Effect, Layer, Option } from "effect"
|
|
3
|
-
import { StoreUnreadable, StoreUnwritable } from "./error.ts"
|
|
4
|
-
import { emptyBranchState, type Batch, type BranchState, type StoredComment, type StoredStory } from "./model.ts"
|
|
5
|
-
import { branchDir, defaultRoot, inboxPath, reportPath, reportsDir, statePath, storyPath } from "./paths.ts"
|
|
6
|
-
|
|
7
|
-
type Shape = {
|
|
8
|
-
readonly root: string
|
|
9
|
-
readonly submit: (worktreePath: string, batch: Batch) => Effect.Effect<void, StoreUnwritable>
|
|
10
|
-
readonly inbox: (worktreePath: string) => Effect.Effect<ReadonlyArray<Batch>, StoreUnreadable>
|
|
11
|
-
readonly state: (worktreePath: string) => Effect.Effect<BranchState, StoreUnreadable>
|
|
12
|
-
readonly saveState: (
|
|
13
|
-
worktreePath: string,
|
|
14
|
-
state: BranchState,
|
|
15
|
-
) => Effect.Effect<void, StoreUnwritable>
|
|
16
|
-
readonly stage: (
|
|
17
|
-
worktreePath: string,
|
|
18
|
-
comment: StoredComment,
|
|
19
|
-
) => Effect.Effect<ReadonlyArray<StoredComment>, StoreUnreadable | StoreUnwritable>
|
|
20
|
-
readonly saveReport: (stamp: string, text: string) => Effect.Effect<string, StoreUnwritable>
|
|
21
|
-
readonly story: (
|
|
22
|
-
worktreePath: string,
|
|
23
|
-
) => Effect.Effect<Option.Option<StoredStory>, StoreUnreadable>
|
|
24
|
-
readonly saveStory: (
|
|
25
|
-
worktreePath: string,
|
|
26
|
-
story: StoredStory,
|
|
27
|
-
) => Effect.Effect<void, StoreUnwritable>
|
|
28
|
-
readonly take: (
|
|
29
|
-
worktreePath: string,
|
|
30
|
-
) => Effect.Effect<ReadonlyArray<Batch>, StoreUnreadable | StoreUnwritable>
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export class Store extends Context.Service<Store, Shape>()("adiff/Store") {}
|
|
34
|
-
|
|
35
|
-
const ensureDir = Effect.fn("Store.ensureDir")(function* (path: string) {
|
|
36
|
-
return yield* Effect.tryPromise({
|
|
37
|
-
try: () => mkdir(path, { recursive: true }),
|
|
38
|
-
catch: (cause) => new StoreUnwritable({ path, reason: String(cause) }),
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
const readOptional = Effect.fn("Store.readOptional")(function* (path: string) {
|
|
43
|
-
return yield* Effect.tryPromise({
|
|
44
|
-
try: () => readFile(path, "utf8"),
|
|
45
|
-
catch: (cause) => new StoreUnreadable({ path, reason: String(cause) }),
|
|
46
|
-
}).pipe(Effect.map(Option.some), Effect.catchTag("StoreUnreadable", () => missing))
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
const missing = Effect.succeed(Option.none<string>())
|
|
50
|
-
|
|
51
|
-
const parseBatches = (raw: string): ReadonlyArray<Batch> =>
|
|
52
|
-
raw
|
|
53
|
-
.split("\n")
|
|
54
|
-
.filter((line) => line.trim().length > 0)
|
|
55
|
-
.map((line) => JSON.parse(line) as Batch)
|
|
56
|
-
|
|
57
|
-
const parseState = (raw: string): BranchState => ({
|
|
58
|
-
...emptyBranchState,
|
|
59
|
-
...(JSON.parse(raw) as Partial<BranchState>),
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
type Reader = (worktreePath: string) => Effect.Effect<BranchState, StoreUnreadable>
|
|
63
|
-
type Writer = (worktreePath: string, next: BranchState) => Effect.Effect<void, StoreUnwritable>
|
|
64
|
-
type Inbox = (worktreePath: string) => Effect.Effect<ReadonlyArray<Batch>, StoreUnreadable>
|
|
65
|
-
|
|
66
|
-
const cursorOps = (state: Reader, saveState: Writer, inbox: Inbox) => {
|
|
67
|
-
const stage = Effect.fn("Store.stage")(function* (worktreePath: string, comment: StoredComment) {
|
|
68
|
-
const current = yield* state(worktreePath)
|
|
69
|
-
const pending = [...current.pending, comment]
|
|
70
|
-
yield* saveState(worktreePath, { ...current, pending })
|
|
71
|
-
return pending as ReadonlyArray<StoredComment>
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
const take = Effect.fn("Store.take")(function* (worktreePath: string) {
|
|
75
|
-
const batches = yield* inbox(worktreePath)
|
|
76
|
-
const current = yield* state(worktreePath)
|
|
77
|
-
const pending = batches.slice(current.consumed)
|
|
78
|
-
if (pending.length > 0) yield* saveState(worktreePath, { ...current, consumed: batches.length })
|
|
79
|
-
return pending
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
return { stage, take }
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const storyOps = (root: string) => {
|
|
86
|
-
const story = Effect.fn("Store.story")(function* (worktreePath: string) {
|
|
87
|
-
const raw = yield* readOptional(storyPath(root, worktreePath))
|
|
88
|
-
return Option.map(raw, (text) => JSON.parse(text) as StoredStory)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
const saveStory = Effect.fn("Store.saveStory")(function* (
|
|
92
|
-
worktreePath: string,
|
|
93
|
-
next: StoredStory,
|
|
94
|
-
) {
|
|
95
|
-
const path = storyPath(root, worktreePath)
|
|
96
|
-
yield* ensureDir(branchDir(root, worktreePath))
|
|
97
|
-
yield* Effect.tryPromise({
|
|
98
|
-
try: () => writeFile(path, JSON.stringify(next, undefined, 2), "utf8"),
|
|
99
|
-
catch: (cause) => new StoreUnwritable({ path, reason: String(cause) }),
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
return { story, saveStory }
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const makeStore = (root: string): Shape => {
|
|
107
|
-
const submit = Effect.fn("Store.submit")(function* (worktreePath: string, batch: Batch) {
|
|
108
|
-
const path = inboxPath(root, worktreePath)
|
|
109
|
-
yield* ensureDir(branchDir(root, worktreePath))
|
|
110
|
-
yield* Effect.tryPromise({
|
|
111
|
-
try: () => appendFile(path, `${JSON.stringify(batch)}\n`, "utf8"),
|
|
112
|
-
catch: (cause) => new StoreUnwritable({ path, reason: String(cause) }),
|
|
113
|
-
})
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
const inbox = Effect.fn("Store.inbox")(function* (worktreePath: string) {
|
|
117
|
-
const raw = yield* readOptional(inboxPath(root, worktreePath))
|
|
118
|
-
return Option.match(raw, { onNone: (): ReadonlyArray<Batch> => [], onSome: parseBatches })
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
const state = Effect.fn("Store.state")(function* (worktreePath: string) {
|
|
122
|
-
const raw = yield* readOptional(statePath(root, worktreePath))
|
|
123
|
-
return Option.match(raw, { onNone: () => emptyBranchState, onSome: parseState })
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
const saveState = Effect.fn("Store.saveState")(function* (
|
|
127
|
-
worktreePath: string,
|
|
128
|
-
next: BranchState,
|
|
129
|
-
) {
|
|
130
|
-
const path = statePath(root, worktreePath)
|
|
131
|
-
yield* ensureDir(branchDir(root, worktreePath))
|
|
132
|
-
yield* Effect.tryPromise({
|
|
133
|
-
try: () => writeFile(path, JSON.stringify(next, undefined, 2), "utf8"),
|
|
134
|
-
catch: (cause) => new StoreUnwritable({ path, reason: String(cause) }),
|
|
135
|
-
})
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
const saveReport = Effect.fn("Store.saveReport")(function* (stamp: string, text: string) {
|
|
139
|
-
const path = reportPath(root, stamp)
|
|
140
|
-
yield* ensureDir(reportsDir(root))
|
|
141
|
-
yield* Effect.tryPromise({
|
|
142
|
-
try: () => writeFile(path, text, "utf8"),
|
|
143
|
-
catch: (cause) => new StoreUnwritable({ path, reason: String(cause) }),
|
|
144
|
-
})
|
|
145
|
-
return path
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
const cursors = cursorOps(state, saveState, inbox)
|
|
149
|
-
return { root, submit, inbox, state, saveState, saveReport, ...storyOps(root), ...cursors }
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export const storeAt = (root: string): Layer.Layer<Store> => Layer.succeed(Store)(makeStore(root))
|
|
153
|
-
|
|
154
|
-
export const StoreLive = storeAt(defaultRoot())
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
-
import { TestDriver } from "./index.ts"
|
|
3
|
-
|
|
4
|
-
describe("using adiff without reading its documentation", () => {
|
|
5
|
-
it("describes the commands it exposes, with the options each needs", async () => {
|
|
6
|
-
// ARRANGE
|
|
7
|
-
await using driver = await TestDriver.create()
|
|
8
|
-
|
|
9
|
-
// ACT
|
|
10
|
-
const result = await driver.app.runDescribe()
|
|
11
|
-
|
|
12
|
-
// ASSERT
|
|
13
|
-
expect(result.code).toBe(0)
|
|
14
|
-
const commands = (result.envelope as { commands: ReadonlyArray<{ name: string }> }).commands
|
|
15
|
-
expect(commands.map((command) => command.name)).toEqual([
|
|
16
|
-
"branch list",
|
|
17
|
-
"comment add",
|
|
18
|
-
"comment stage",
|
|
19
|
-
"comment take",
|
|
20
|
-
"file vouch",
|
|
21
|
-
"review submit",
|
|
22
|
-
"review progress",
|
|
23
|
-
"story set",
|
|
24
|
-
"story show",
|
|
25
|
-
"review open",
|
|
26
|
-
"describe",
|
|
27
|
-
])
|
|
28
|
-
expect(commands).toContainEqual(
|
|
29
|
-
expect.objectContaining({
|
|
30
|
-
name: "story set",
|
|
31
|
-
safety: "write",
|
|
32
|
-
dataKey: "story",
|
|
33
|
-
options: expect.arrayContaining([
|
|
34
|
-
expect.objectContaining({ name: "json", required: true }),
|
|
35
|
-
]),
|
|
36
|
-
}),
|
|
37
|
-
)
|
|
38
|
-
expect(commands).toContainEqual(
|
|
39
|
-
expect.objectContaining({
|
|
40
|
-
name: "comment take",
|
|
41
|
-
safety: "write",
|
|
42
|
-
dataKey: "comments",
|
|
43
|
-
options: expect.arrayContaining([
|
|
44
|
-
expect.objectContaining({ name: "worktree", required: true }),
|
|
45
|
-
]),
|
|
46
|
-
}),
|
|
47
|
-
)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it("names the commands it knows when asked to describe one that does not exist", async () => {
|
|
51
|
-
// ARRANGE
|
|
52
|
-
await using driver = await TestDriver.create()
|
|
53
|
-
|
|
54
|
-
// ACT
|
|
55
|
-
const result = await driver.app.runDescribe("comment delete")
|
|
56
|
-
|
|
57
|
-
// ASSERT
|
|
58
|
-
expect(result.code).toBe(2)
|
|
59
|
-
expect(result.envelope).toMatchObject({
|
|
60
|
-
ok: false,
|
|
61
|
-
error: { type: "UnknownCommand", known: expect.arrayContaining(["comment add"]) },
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it("keeps failures off stdout, so a caller can parse stdout unconditionally", async () => {
|
|
66
|
-
// ARRANGE
|
|
67
|
-
await using driver = await TestDriver.create()
|
|
68
|
-
await driver.branch.create({ name: "cdr-1-real" })
|
|
69
|
-
|
|
70
|
-
// ACT
|
|
71
|
-
const result = await driver.app.runProgress("cdr-99-imaginary")
|
|
72
|
-
|
|
73
|
-
// ASSERT
|
|
74
|
-
expect(result.stdout).toBe("")
|
|
75
|
-
expect(result.stderr).toContain("UnknownBranch")
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it("returns only the asked-for fields, so a caller pays for what it reads", async () => {
|
|
79
|
-
// ARRANGE
|
|
80
|
-
await using driver = await TestDriver.create()
|
|
81
|
-
await driver.branch.create({ name: "cdr-1-add-third" })
|
|
82
|
-
|
|
83
|
-
// ACT
|
|
84
|
-
const result = await driver.app.runBranches(["--fields", "branch,files"])
|
|
85
|
-
|
|
86
|
-
// ASSERT
|
|
87
|
-
expect(result.envelope).toEqual({
|
|
88
|
-
ok: true,
|
|
89
|
-
branches: [{ branch: "cdr-1-add-third", files: 1 }],
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
})
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
-
import { TestDriver } from "./index.ts"
|
|
3
|
-
|
|
4
|
-
describe("reviewing a branch the way a pull request is reviewed", () => {
|
|
5
|
-
it("holds staged comments back until the review is submitted", async () => {
|
|
6
|
-
// ARRANGE
|
|
7
|
-
await using driver = await TestDriver.create()
|
|
8
|
-
const branch = await driver.branch.create()
|
|
9
|
-
|
|
10
|
-
// ACT
|
|
11
|
-
await driver.app.runStage({
|
|
12
|
-
branch: branch.name,
|
|
13
|
-
file: "src/api.ts",
|
|
14
|
-
start: 4,
|
|
15
|
-
end: 4,
|
|
16
|
-
body: "third is unused",
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
// ASSERT
|
|
20
|
-
expect(await driver.agent.listBatches(branch.worktree)).toHaveLength(0)
|
|
21
|
-
expect(await driver.agent.listComments(branch.worktree)).toHaveLength(0)
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
it("delivers a whole review as one batch, so the agent wakes once", async () => {
|
|
25
|
-
// ARRANGE
|
|
26
|
-
await using driver = await TestDriver.create()
|
|
27
|
-
const branch = await driver.branch.create()
|
|
28
|
-
await driver.app.runStage({
|
|
29
|
-
branch: branch.name,
|
|
30
|
-
file: "src/api.ts",
|
|
31
|
-
start: 4,
|
|
32
|
-
end: 4,
|
|
33
|
-
body: "first",
|
|
34
|
-
})
|
|
35
|
-
await driver.app.runStage({
|
|
36
|
-
branch: branch.name,
|
|
37
|
-
file: "src/api.ts",
|
|
38
|
-
start: 5,
|
|
39
|
-
end: 5,
|
|
40
|
-
body: "second",
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
// ACT
|
|
44
|
-
const result = await driver.app.runSubmit(branch.name)
|
|
45
|
-
|
|
46
|
-
// ASSERT
|
|
47
|
-
expect(result.code).toBe(0)
|
|
48
|
-
const batches = await driver.agent.listBatches(branch.worktree)
|
|
49
|
-
expect(batches).toHaveLength(1)
|
|
50
|
-
const comments = await driver.agent.listComments(branch.worktree)
|
|
51
|
-
expect(comments.map((comment) => comment.body)).toEqual(["first", "second"])
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it("reports how many comments are waiting to be submitted", async () => {
|
|
55
|
-
// ARRANGE
|
|
56
|
-
await using driver = await TestDriver.create()
|
|
57
|
-
const branch = await driver.branch.create()
|
|
58
|
-
await driver.app.runStage({
|
|
59
|
-
branch: branch.name,
|
|
60
|
-
file: "src/api.ts",
|
|
61
|
-
start: 4,
|
|
62
|
-
end: 4,
|
|
63
|
-
body: "first",
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
// ACT
|
|
67
|
-
const result = await driver.app.runProgress(branch.name)
|
|
68
|
-
|
|
69
|
-
// ASSERT
|
|
70
|
-
expect(result.envelope).toMatchObject({ ok: true, pending: 1 })
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it("empties the review once submitted, so nothing is sent twice", async () => {
|
|
74
|
-
// ARRANGE
|
|
75
|
-
await using driver = await TestDriver.create()
|
|
76
|
-
const branch = await driver.branch.create()
|
|
77
|
-
await driver.app.runStage({
|
|
78
|
-
branch: branch.name,
|
|
79
|
-
file: "src/api.ts",
|
|
80
|
-
start: 4,
|
|
81
|
-
end: 4,
|
|
82
|
-
body: "only",
|
|
83
|
-
})
|
|
84
|
-
await driver.app.runSubmit(branch.name)
|
|
85
|
-
|
|
86
|
-
// ACT
|
|
87
|
-
const result = await driver.app.runSubmit(branch.name)
|
|
88
|
-
|
|
89
|
-
// ASSERT
|
|
90
|
-
expect(result.code).toBe(2)
|
|
91
|
-
expect(await driver.agent.listBatches(branch.worktree)).toHaveLength(1)
|
|
92
|
-
})
|
|
93
|
-
})
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "@effect/vitest"
|
|
2
|
-
import { TestDriver } from "./index.ts"
|
|
3
|
-
|
|
4
|
-
const oneFile = {
|
|
5
|
-
files: [
|
|
6
|
-
{
|
|
7
|
-
path: "src/api.ts",
|
|
8
|
-
before: ["const keep = 0"],
|
|
9
|
-
after: ["const keep = 0", "const first = 1"],
|
|
10
|
-
},
|
|
11
|
-
],
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
describe("choosing which branch needs you", () => {
|
|
15
|
-
it("says how many comments are waiting to be sent", async () => {
|
|
16
|
-
// ARRANGE
|
|
17
|
-
await using driver = await TestDriver.create()
|
|
18
|
-
const branch = await driver.branch.create(oneFile)
|
|
19
|
-
await driver.app.runStage({
|
|
20
|
-
branch: branch.name,
|
|
21
|
-
file: "src/api.ts",
|
|
22
|
-
start: 2,
|
|
23
|
-
end: 2,
|
|
24
|
-
body: "why",
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
// ACT
|
|
28
|
-
const result = await driver.app.runBranches()
|
|
29
|
-
|
|
30
|
-
// ASSERT
|
|
31
|
-
expect(result.envelope).toMatchObject({
|
|
32
|
-
ok: true,
|
|
33
|
-
branches: [{ branch: branch.name, staged: 1, unread: 0 }],
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it("says how many the agent has not collected", async () => {
|
|
38
|
-
// ARRANGE
|
|
39
|
-
await using driver = await TestDriver.create()
|
|
40
|
-
const branch = await driver.branch.create(oneFile)
|
|
41
|
-
await driver.app.runComment({
|
|
42
|
-
branch: branch.name,
|
|
43
|
-
file: "src/api.ts",
|
|
44
|
-
start: 2,
|
|
45
|
-
end: 2,
|
|
46
|
-
body: "sent now",
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
// ACT
|
|
50
|
-
const result = await driver.app.runBranches()
|
|
51
|
-
|
|
52
|
-
// ASSERT
|
|
53
|
-
expect(result.envelope).toMatchObject({
|
|
54
|
-
ok: true,
|
|
55
|
-
branches: [{ branch: branch.name, staged: 0, unread: 1 }],
|
|
56
|
-
})
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it("shows the counts on the branches screen", async () => {
|
|
60
|
-
// ARRANGE
|
|
61
|
-
await using driver = await TestDriver.create()
|
|
62
|
-
const branch = await driver.branch.create(oneFile)
|
|
63
|
-
await driver.app.runStage({
|
|
64
|
-
branch: branch.name,
|
|
65
|
-
file: "src/api.ts",
|
|
66
|
-
start: 2,
|
|
67
|
-
end: 2,
|
|
68
|
-
body: "why",
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
// ACT
|
|
72
|
-
await driver.screen.open()
|
|
73
|
-
|
|
74
|
-
// ASSERT
|
|
75
|
-
const rows = (await driver.screen.getFrame()).split("\n")
|
|
76
|
-
const row = rows.find((line) => line.includes("cdr-1-add-third"))
|
|
77
|
-
expect(row).toContain("1 staged")
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
describe("coming back to the branch list", () => {
|
|
82
|
-
it("shows work staged since the list was last drawn", async () => {
|
|
83
|
-
// ARRANGE
|
|
84
|
-
await using driver = await TestDriver.create()
|
|
85
|
-
await driver.branch.create(oneFile)
|
|
86
|
-
await driver.screen.open()
|
|
87
|
-
await driver.screen.pressKeys(["RETURN", "c"])
|
|
88
|
-
await driver.screen.typeText("hold this")
|
|
89
|
-
await driver.screen.pressCtrl("a")
|
|
90
|
-
|
|
91
|
-
// ACT
|
|
92
|
-
await driver.screen.pressEscape()
|
|
93
|
-
|
|
94
|
-
// ASSERT
|
|
95
|
-
const rows = (await driver.screen.getFrame()).split("\n")
|
|
96
|
-
const row = rows.find((line) => line.includes("cdr-1-add-third"))
|
|
97
|
-
expect(row).toContain("1 staged")
|
|
98
|
-
})
|
|
99
|
-
})
|