@markjaquith/agency 3.2.14 → 3.3.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.
Files changed (75) hide show
  1. package/README.md +20 -3
  2. package/cli-main.ts +1 -0
  3. package/package.json +7 -2
  4. package/src/cli-parser.ts +13 -0
  5. package/src/commands/work.ts +70 -2
  6. package/src/services/ReadinessService.ts +20 -0
  7. package/src/workbase/execution-contract.ts +10 -1
  8. package/src/workbase/schemas.ts +12 -0
  9. package/fixtures/protocol/orchestration-recipes.json +0 -53
  10. package/pi-extensions/agency.test.ts +0 -117
  11. package/src/check-commits.test.ts +0 -58
  12. package/src/cli-parser.test.ts +0 -945
  13. package/src/cli.test.ts +0 -1889
  14. package/src/commands/act.test.ts +0 -418
  15. package/src/commands/archive.test.ts +0 -236
  16. package/src/commands/context.test.ts +0 -711
  17. package/src/commands/description.test.ts +0 -103
  18. package/src/commands/doctor.test.ts +0 -185
  19. package/src/commands/epic.test.ts +0 -196
  20. package/src/commands/init.test.ts +0 -117
  21. package/src/commands/integration.test.ts +0 -165
  22. package/src/commands/pr.test.ts +0 -248
  23. package/src/commands/push.test.ts +0 -56
  24. package/src/commands/read-only.test.ts +0 -161
  25. package/src/commands/repo.test.ts +0 -199
  26. package/src/commands/restore.test.ts +0 -106
  27. package/src/commands/status.test.ts +0 -113
  28. package/src/commands/sync.test.ts +0 -200
  29. package/src/commands/task-phase.test.ts +0 -410
  30. package/src/commands/task.test.ts +0 -281
  31. package/src/commands/validate.test.ts +0 -186
  32. package/src/commands/work.test.ts +0 -1375
  33. package/src/commands/workbase.test.ts +0 -170
  34. package/src/graph-schema.test.ts +0 -124
  35. package/src/protocol.test.ts +0 -163
  36. package/src/readiness.test.ts +0 -105
  37. package/src/services/ArchiveBulkService.test.ts +0 -384
  38. package/src/services/ArchiveService.test.ts +0 -1092
  39. package/src/services/EpicService.test.ts +0 -74
  40. package/src/services/FileSystemService.test.ts +0 -81
  41. package/src/services/GraphMutationService.test.ts +0 -486
  42. package/src/services/GraphService.test.ts +0 -494
  43. package/src/services/IntegrationService.test.ts +0 -1091
  44. package/src/services/LifecycleTransaction.test.ts +0 -145
  45. package/src/services/PullRequestService.test.ts +0 -716
  46. package/src/services/PushService.test.ts +0 -408
  47. package/src/services/ReadinessService.test.ts +0 -290
  48. package/src/services/RepositoryService.test.ts +0 -789
  49. package/src/services/ReviewService.test.ts +0 -408
  50. package/src/services/SyncService.test.ts +0 -1377
  51. package/src/services/TaskPhaseService.test.ts +0 -852
  52. package/src/services/VersionControlService.test.ts +0 -62
  53. package/src/services/WorkbaseService.test.ts +0 -910
  54. package/src/services/WorktreeLock.test.ts +0 -205
  55. package/src/services/WorktreePerformance.test.ts +0 -71
  56. package/src/services/WorktreeService.test.ts +0 -2292
  57. package/src/test-utils.ts +0 -110
  58. package/src/usage-log.test.ts +0 -188
  59. package/src/utils/chooser.test.ts +0 -192
  60. package/src/utils/effect.test.ts +0 -30
  61. package/src/utils/interactive.pty.test.ts +0 -128
  62. package/src/utils/interactive.test.tsx +0 -860
  63. package/src/utils/process.test.ts +0 -132
  64. package/src/utils/progress.test.ts +0 -37
  65. package/src/work-view.test.ts +0 -151
  66. package/src/workbase/agent-command.test.ts +0 -128
  67. package/src/workbase/checkout-command.test.ts +0 -62
  68. package/src/workbase/delivery-command.test.ts +0 -180
  69. package/src/workbase/dependency-graph.test.ts +0 -50
  70. package/src/workbase/execution-contract.test.ts +0 -161
  71. package/src/workbase/frontmatter.test.ts +0 -67
  72. package/src/workbase/repository-reference.test.ts +0 -25
  73. package/src/workbase/schemas.test.ts +0 -543
  74. package/src/workbase/work-target.test.ts +0 -108
  75. package/src/workbase/worktree-command.test.ts +0 -61
@@ -1,418 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, test } from "bun:test"
2
- import { Effect } from "effect"
3
- import { mkdir } from "node:fs/promises"
4
- import { join } from "node:path"
5
- import {
6
- captureLogs,
7
- cleanupTempDir,
8
- createTempDir,
9
- runTestEffect,
10
- } from "../test-utils"
11
- import type { Choice } from "../utils/chooser"
12
- import { phase } from "./phase"
13
- import { task } from "./task"
14
- import { act, type ActInteraction } from "./act"
15
-
16
- const scriptedInteraction = (
17
- selections: readonly (string | null)[],
18
- onSelect?: (prompt: string, choices: readonly Choice<unknown>[]) => void,
19
- ): ActInteraction => {
20
- let index = 0
21
- return {
22
- select: (prompt, choices) => {
23
- onSelect?.(prompt, choices)
24
- const selection = selections[index++] ?? null
25
- return Effect.succeed(
26
- selection === null
27
- ? null
28
- : (choices.find((choice) => choice.value === selection)?.value ??
29
- null),
30
- )
31
- },
32
- }
33
- }
34
-
35
- describe("act command", () => {
36
- let root: string
37
-
38
- beforeEach(async () => {
39
- root = await createTempDir()
40
- await Bun.write(join(root, "agency.json"), '{"version":2}\n')
41
- const initialized = Bun.spawnSync([
42
- "git",
43
- "init",
44
- "--bare",
45
- join(root, "repos/agency"),
46
- ])
47
- if (initialized.exitCode !== 0) {
48
- throw new Error(new TextDecoder().decode(initialized.stderr))
49
- }
50
- })
51
-
52
- afterEach(async () => cleanupTempDir(root))
53
-
54
- test("rejects non-interactive and empty invocations cleanly", async () => {
55
- await expect(
56
- runTestEffect(act({ cwd: root, inputAllowed: false })),
57
- ).rejects.toThrow("requires interactive input")
58
- await expect(
59
- runTestEffect(
60
- act({ cwd: root, inputAllowed: true }, scriptedInteraction([])),
61
- ),
62
- ).rejects.toThrow("No active work items")
63
- })
64
-
65
- test("returns an empty target list as JSON without interactive input", async () => {
66
- const logs = await captureLogs(() =>
67
- runTestEffect(act({ cwd: root, inputAllowed: false, json: true })),
68
- )
69
- expect(JSON.parse(logs[0]!)).toEqual({ targets: [] })
70
- })
71
-
72
- test("cancellation exits without changing the selected item", async () => {
73
- await createTask("example")
74
- await runTestEffect(
75
- act({ cwd: root, inputAllowed: true }, scriptedInteraction([null])),
76
- )
77
-
78
- expect(await readTaskStatus("example")).toBe("open")
79
- })
80
-
81
- test("offers state-aware actions and dispatches drop through lifecycle semantics", async () => {
82
- await createTask("example")
83
- const offered: string[][] = []
84
- const logs = await captureLogs(() =>
85
- runTestEffect(
86
- act(
87
- { cwd: root, inputAllowed: true },
88
- scriptedInteraction(["task:example", "drop"], (_prompt, choices) => {
89
- offered.push(choices.map((choice) => String(choice.value)))
90
- }),
91
- ),
92
- ),
93
- )
94
-
95
- expect(offered[1]).toEqual(["work", "pr", "drop"])
96
- expect(logs).toEqual(["Marked task 'example' as dropped"])
97
- expect(await readTaskStatus("example")).toBe("dropped")
98
- })
99
-
100
- test("accepts an explicit selector and prints dry-run command without mutation", async () => {
101
- await createTask("example")
102
- const prompts: string[] = []
103
- const logs = await captureLogs(() =>
104
- runTestEffect(
105
- act(
106
- {
107
- cwd: root,
108
- inputAllowed: true,
109
- taskId: "example",
110
- dryRun: true,
111
- },
112
- scriptedInteraction(["drop"], (prompt) => prompts.push(prompt)),
113
- ),
114
- ),
115
- )
116
-
117
- expect(prompts).toEqual(["Act on task example"])
118
- expect(logs).toEqual(["agency task status example dropped"])
119
- expect(await readTaskStatus("example")).toBe("open")
120
- })
121
-
122
- test("resolves a positional path and task ID without prompting for an item", async () => {
123
- await createTask("example")
124
- await mkdir(join(root, "tasks/example/code/agency"), { recursive: true })
125
- for (const options of [
126
- { cwd: join(root, "tasks/example"), directory: "." },
127
- { cwd: join(root, "tasks/example"), directory: "code/agency" },
128
- { cwd: root, directory: "example" },
129
- ]) {
130
- const prompts: string[] = []
131
- await runTestEffect(
132
- act(
133
- { ...options, inputAllowed: true, dryRun: true, silent: true },
134
- scriptedInteraction(["drop"], (prompt) => prompts.push(prompt)),
135
- ),
136
- )
137
- expect(prompts).toEqual(["Act on task example"])
138
- }
139
- })
140
-
141
- test("resolves a positional phase path without prompting for an item", async () => {
142
- await runTestEffect(
143
- task({
144
- subcommand: "create",
145
- args: ["multi"],
146
- multiPhase: true,
147
- cwd: root,
148
- silent: true,
149
- }),
150
- )
151
- await runTestEffect(
152
- phase({
153
- subcommand: "create",
154
- args: ["multi", "build"],
155
- repo: "agency",
156
- branch: "task/multi-build",
157
- base: "main",
158
- cwd: root,
159
- silent: true,
160
- }),
161
- )
162
- const prompts: string[] = []
163
- await runTestEffect(
164
- act(
165
- {
166
- cwd: join(root, "tasks/multi/phases/build"),
167
- directory: ".",
168
- inputAllowed: true,
169
- dryRun: true,
170
- silent: true,
171
- },
172
- scriptedInteraction(["drop"], (prompt) => prompts.push(prompt)),
173
- ),
174
- )
175
-
176
- expect(prompts).toEqual(["Act on phase multi/build"])
177
- })
178
-
179
- test("orders owned items hierarchically and omits items without actions", async () => {
180
- await runTestEffect(
181
- task({
182
- subcommand: "create",
183
- args: ["multi"],
184
- multiPhase: true,
185
- cwd: root,
186
- silent: true,
187
- }),
188
- )
189
- await runTestEffect(
190
- phase({
191
- subcommand: "create",
192
- args: ["multi", "build"],
193
- repo: "agency",
194
- branch: "task/multi-build",
195
- base: "main",
196
- cwd: root,
197
- silent: true,
198
- }),
199
- )
200
- let choices: readonly Choice<unknown>[] = []
201
- await runTestEffect(
202
- act(
203
- { cwd: root, inputAllowed: true },
204
- scriptedInteraction([null], (_prompt, offered) => {
205
- choices = offered
206
- }),
207
- ),
208
- )
209
-
210
- expect(choices.map((choice) => [choice.value, choice.depth])).toEqual([
211
- ["task:multi", 0],
212
- ["phase:multi/build", 1],
213
- ])
214
- })
215
-
216
- test("returns structured actions and argv for agents", async () => {
217
- await createTask("example")
218
- const logs = await captureLogs(() =>
219
- runTestEffect(
220
- act({
221
- cwd: root,
222
- inputAllowed: false,
223
- taskId: "example",
224
- json: true,
225
- auto: true,
226
- draft: true,
227
- }),
228
- ),
229
- )
230
-
231
- expect(JSON.parse(logs[0]!)).toMatchObject({
232
- targets: [
233
- {
234
- kind: "task",
235
- key: "example",
236
- status: "open",
237
- actions: [
238
- {
239
- id: "work",
240
- command: ["agency", "work", "--task", "example", "--auto"],
241
- },
242
- {
243
- id: "pr",
244
- command: ["agency", "pr", "create", "example", "--draft"],
245
- },
246
- {
247
- id: "drop",
248
- command: ["agency", "task", "status", "example", "dropped"],
249
- },
250
- ],
251
- },
252
- ],
253
- })
254
- })
255
-
256
- test("offers reopen and archive for terminal work", async () => {
257
- await createTask("example")
258
- await runTestEffect(
259
- task({
260
- subcommand: "status",
261
- args: ["example", "dropped"],
262
- cwd: root,
263
- silent: true,
264
- }),
265
- )
266
- let actions: string[] = []
267
- await runTestEffect(
268
- act(
269
- { cwd: root, inputAllowed: true },
270
- scriptedInteraction(["task:example", null], (prompt, choices) => {
271
- if (prompt.startsWith("Act on task")) {
272
- actions = choices.map((choice) => String(choice.value))
273
- }
274
- }),
275
- ),
276
- )
277
-
278
- expect(actions).toEqual(["reopen", "archive"])
279
- })
280
-
281
- test("dispatches phase actions with the parent task identifier", async () => {
282
- await runTestEffect(
283
- task({
284
- subcommand: "create",
285
- args: ["multi"],
286
- multiPhase: true,
287
- cwd: root,
288
- silent: true,
289
- }),
290
- )
291
- await runTestEffect(
292
- phase({
293
- subcommand: "create",
294
- args: ["multi", "build"],
295
- repo: "agency",
296
- branch: "task/multi-build",
297
- base: "main",
298
- cwd: root,
299
- silent: true,
300
- }),
301
- )
302
-
303
- let actions: string[] = []
304
- await runTestEffect(
305
- act(
306
- { cwd: root, inputAllowed: true, silent: true },
307
- scriptedInteraction(
308
- ["phase:multi/build", "drop"],
309
- (prompt, choices) => {
310
- if (prompt.startsWith("Act on phase")) {
311
- actions = choices.map((choice) => String(choice.value))
312
- }
313
- },
314
- ),
315
- ),
316
- )
317
-
318
- expect(actions).toEqual(["work", "pr", "drop"])
319
- const content = await Bun.file(
320
- join(root, "tasks/multi/phases/build/PHASE.md"),
321
- ).text()
322
- expect(content).toContain("status: dropped")
323
- })
324
-
325
- test("dispatches work and pull request actions through their command handlers", async () => {
326
- await createTask("example")
327
- const workCalls: unknown[] = []
328
- await runTestEffect(
329
- act(
330
- { cwd: root, inputAllowed: true, auto: true },
331
- scriptedInteraction(["task:example", "work"]),
332
- ((options) => {
333
- workCalls.push(options)
334
- return Effect.void
335
- }) as Parameters<typeof act>[2],
336
- ),
337
- )
338
- expect(workCalls).toEqual([
339
- expect.objectContaining({
340
- taskId: "example",
341
- auto: true,
342
- cwd: root,
343
- }),
344
- ])
345
-
346
- let prActionSeen = false
347
- await expect(
348
- runTestEffect(
349
- act(
350
- { cwd: root, inputAllowed: true },
351
- {
352
- select: (prompt, choices) => {
353
- if (prompt.startsWith("Act on task")) {
354
- prActionSeen = choices.some((choice) => choice.value === "pr")
355
- return Effect.fail(new Error("stop before external PR command"))
356
- }
357
- return Effect.succeed(
358
- choices.find((choice) => choice.value === "task:example")
359
- ?.value ?? null,
360
- )
361
- },
362
- },
363
- ),
364
- ),
365
- ).rejects.toThrow("stop before external PR command")
366
- expect(prActionSeen).toBe(true)
367
- })
368
-
369
- test("rejects a stale selection before dispatch", async () => {
370
- await createTask("example")
371
- let selection = 0
372
- const interaction: ActInteraction = {
373
- select: (_prompt, choices) => {
374
- selection++
375
- if (selection === 1) {
376
- return Effect.succeed(
377
- choices.find((choice) => choice.value === "task:example")?.value ??
378
- null,
379
- )
380
- }
381
- return Effect.promise(async () => {
382
- await Bun.write(
383
- join(root, "tasks/example/TASK.md"),
384
- (
385
- await Bun.file(join(root, "tasks/example/TASK.md")).text()
386
- ).replace("# Example", "# Example\n\nChanged after selection"),
387
- )
388
- return (
389
- choices.find((choice) => choice.value === "drop")?.value ?? null
390
- )
391
- })
392
- },
393
- }
394
-
395
- await expect(
396
- runTestEffect(act({ cwd: root, inputAllowed: true }, interaction)),
397
- ).rejects.toThrow("Selected work item changed")
398
- expect(await readTaskStatus("example")).toBe("open")
399
- })
400
-
401
- const createTask = (id: string) =>
402
- runTestEffect(
403
- task({
404
- subcommand: "create",
405
- args: [id],
406
- repo: "agency",
407
- branch: `task/${id}`,
408
- base: "main",
409
- cwd: root,
410
- silent: true,
411
- }),
412
- )
413
-
414
- const readTaskStatus = async (id: string) => {
415
- const content = await Bun.file(join(root, `tasks/${id}/TASK.md`)).text()
416
- return content.match(/^status: (.+)$/m)?.[1]
417
- }
418
- })
@@ -1,236 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, test } from "bun:test"
2
- import { mkdir } from "node:fs/promises"
3
- import { join } from "node:path"
4
- import {
5
- captureLogs,
6
- cleanupTempDir,
7
- createTempDir,
8
- runTestEffect,
9
- } from "../test-utils"
10
- import { archive } from "./archive"
11
- import { task } from "./task"
12
-
13
- describe("archive command", () => {
14
- let root: string
15
-
16
- beforeEach(async () => {
17
- root = await createTempDir()
18
- await Bun.write(join(root, "agency.json"), '{"version":2}\n')
19
- const initialized = Bun.spawnSync([
20
- "git",
21
- "init",
22
- "--bare",
23
- join(root, "repos/agency"),
24
- ])
25
- if (initialized.exitCode !== 0) {
26
- throw new Error(new TextDecoder().decode(initialized.stderr))
27
- }
28
- await runTestEffect(
29
- task({
30
- subcommand: "create",
31
- args: ["example"],
32
- ticketUrl: "https://example.com/task",
33
- repo: "agency",
34
- branch: "task/example",
35
- base: "main",
36
- cwd: root,
37
- silent: true,
38
- }),
39
- )
40
- await runTestEffect(
41
- task({
42
- subcommand: "status",
43
- args: ["example", "dropped"],
44
- cwd: root,
45
- silent: true,
46
- }),
47
- )
48
- })
49
-
50
- afterEach(async () => cleanupTempDir(root))
51
-
52
- test("archives a task and outputs the result as JSON", async () => {
53
- const logs = await captureLogs(() =>
54
- runTestEffect(
55
- archive({
56
- type: "task",
57
- args: ["example"],
58
- cwd: root,
59
- json: true,
60
- }),
61
- ),
62
- )
63
-
64
- expect(JSON.parse(logs[0]!)).toMatchObject({
65
- operation: "archive",
66
- kind: "task",
67
- id: "example",
68
- path: join(root, "archive/tasks/example"),
69
- affectedPaths: [join(root, "archive/tasks/example")],
70
- removedWorktrees: [],
71
- dryRun: false,
72
- })
73
- })
74
-
75
- test("preflights an archive without moving the task", async () => {
76
- const logs = await captureLogs(() =>
77
- runTestEffect(
78
- archive({
79
- type: "task",
80
- args: ["example"],
81
- cwd: root,
82
- dryRun: true,
83
- json: true,
84
- }),
85
- ),
86
- )
87
-
88
- expect(JSON.parse(logs[0]!).dryRun).toBe(true)
89
- expect(await Bun.file(join(root, "tasks/example/TASK.md")).exists()).toBe(
90
- true,
91
- )
92
- expect(await Bun.file(join(root, "archive/tasks/example")).exists()).toBe(
93
- false,
94
- )
95
- })
96
-
97
- test("infers a task from a filesystem path", async () => {
98
- const logs = await captureLogs(() =>
99
- runTestEffect(
100
- archive({
101
- args: ["."],
102
- cwd: join(root, "tasks/example"),
103
- dryRun: true,
104
- json: true,
105
- }),
106
- ),
107
- )
108
-
109
- expect(JSON.parse(logs[0]!)).toMatchObject({
110
- operation: "archive",
111
- kind: "task",
112
- id: "example",
113
- dryRun: true,
114
- })
115
- })
116
-
117
- test("infers an epic from a filesystem path", async () => {
118
- const directory = join(root, "epics/delivery")
119
- await mkdir(directory, { recursive: true })
120
- await Bun.write(
121
- join(directory, "EPIC.md"),
122
- `---
123
- ticketUrl: https://example.com/epic
124
- repos:
125
- - repo: agency
126
- ref: main
127
- tasks: []
128
- ---
129
-
130
- # Delivery
131
- `,
132
- )
133
- const logs = await captureLogs(() =>
134
- runTestEffect(
135
- archive({ args: ["."], cwd: directory, dryRun: true, json: true }),
136
- ),
137
- )
138
-
139
- expect(JSON.parse(logs[0]!)).toMatchObject({
140
- operation: "archive",
141
- kind: "epic",
142
- id: "delivery",
143
- dryRun: true,
144
- })
145
- })
146
-
147
- test("rejects ambiguous and unsupported archive paths", async () => {
148
- await expect(
149
- runTestEffect(archive({ args: ["."], cwd: root, silent: true })),
150
- ).rejects.toThrow("Archive path is ambiguous")
151
- await expect(
152
- runTestEffect(
153
- archive({ args: ["repos/agency"], cwd: root, silent: true }),
154
- ),
155
- ).rejects.toThrow("Archive path must be within an active epic or task")
156
-
157
- const phaseDirectory = join(root, "tasks/example/phases/build")
158
- await mkdir(phaseDirectory, { recursive: true })
159
- await expect(
160
- runTestEffect(
161
- archive({ args: ["."], cwd: phaseDirectory, silent: true }),
162
- ),
163
- ).rejects.toThrow("Archive path identifies a phase")
164
- })
165
-
166
- test("reports an already archived task", async () => {
167
- await runTestEffect(
168
- archive({ type: "task", args: ["example"], cwd: root, silent: true }),
169
- )
170
-
171
- await expect(
172
- runTestEffect(
173
- archive({
174
- type: "task",
175
- args: ["example"],
176
- cwd: root,
177
- silent: true,
178
- }),
179
- ),
180
- ).rejects.toThrow("Task 'example' is already archived")
181
- })
182
-
183
- test("outputs one deterministic bulk archive object and a concise human summary", async () => {
184
- const jsonLogs = await captureLogs(() =>
185
- runTestEffect(
186
- archive({
187
- type: "tasks",
188
- args: [],
189
- cwd: root,
190
- dryRun: true,
191
- json: true,
192
- }),
193
- ),
194
- )
195
- expect(jsonLogs).toHaveLength(1)
196
- expect(JSON.parse(jsonLogs[0]!)).toMatchObject({
197
- operation: "archive",
198
- kind: "tasks",
199
- dryRun: true,
200
- tasks: [{ id: "example", disposition: "planned" }],
201
- })
202
-
203
- const humanLogs = await captureLogs(() =>
204
- runTestEffect(
205
- archive({ type: "tasks", args: [], cwd: root, dryRun: true }),
206
- ),
207
- )
208
- expect(humanLogs).toEqual([
209
- "Would archive 1 task: example\nSkipped 0 tasks",
210
- ])
211
- })
212
-
213
- test("requires a supported work item type", async () => {
214
- await expect(
215
- runTestEffect(archive({ args: [], cwd: root, silent: true })),
216
- ).rejects.toThrow(
217
- "Provide a path or use: list, show, epic, task, tasks, phase",
218
- )
219
- })
220
-
221
- test("rejects an extra archive show identifier", async () => {
222
- await runTestEffect(
223
- archive({ type: "task", args: ["example"], cwd: root, silent: true }),
224
- )
225
- await expect(
226
- runTestEffect(
227
- archive({
228
- type: "show",
229
- args: ["task", "example", "extra"],
230
- cwd: root,
231
- silent: true,
232
- }),
233
- ),
234
- ).rejects.toThrow("Usage: agency archive show")
235
- })
236
- })