@markjaquith/agency 2.54.0 → 2.54.1

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/README.md CHANGED
@@ -805,6 +805,7 @@ for restoration. Archived IDs are reserved until restored.
805
805
  agency work [<directory> | --epic <epic-id>] [--runner <name>] [--auto] [--print-command]
806
806
  agency work prepare [target] [--dry-run] [--json]
807
807
  agency worktree <list|inspect|prepare|remove|rebuild|repair>
808
+ agency pr create <task-id> [phase-id] [--draft] [--force] [--json]
808
809
  agency pr [args...]
809
810
  ```
810
811
 
@@ -851,9 +852,12 @@ Agency resolves the ref to a commit and creates a detached worktree. Existing
851
852
  reference worktrees are reused only while their commit still matches the declared
852
853
  ref; use a commit SHA as `ref` when reproducibility matters.
853
854
 
854
- `agency pr` forwards every argument to `gh pr`. From an execution task or phase
855
- directory, including descendants, it runs in that execution unit's authoritative
856
- writable checkout. Otherwise it runs in the caller's current directory.
855
+ Task-aware `agency pr create <task-id> [phase-id]` uses Agency's delivery flow,
856
+ including readiness checks and durable PR recording. Other `agency pr`
857
+ invocations forward every argument to `gh pr`. From an execution task or phase
858
+ directory, including descendants, passthrough runs in that execution unit's
859
+ authoritative writable checkout. Otherwise it runs in the caller's current
860
+ directory.
857
861
 
858
862
  ### Status and Validation
859
863
 
package/cli-main.ts CHANGED
@@ -5,7 +5,7 @@ import { join, resolve } from "node:path"
5
5
  import { parseCli } from "./src/cli-parser"
6
6
  import { init, help as initHelp } from "./src/commands/init"
7
7
  import { task, help as taskHelp } from "./src/commands/task"
8
- import { pr, help as prHelp } from "./src/commands/pr"
8
+ import { pr, prCreate, help as prHelp } from "./src/commands/pr"
9
9
  import { work, workPrepare, help as workHelp } from "./src/commands/work"
10
10
  import { worktree, help as worktreeHelp } from "./src/commands/worktree"
11
11
  import { status, help as statusHelp } from "./src/commands/status"
@@ -134,7 +134,7 @@ const resolveInvocationCwd = (
134
134
  ) =>
135
135
  runEffect(
136
136
  Effect.gen(function* () {
137
- if (commandName === "pr") {
137
+ if (commandName === "pr" && options.passthrough) {
138
138
  return resolve(options.cwd ?? process.cwd())
139
139
  }
140
140
  if (
@@ -287,7 +287,22 @@ const commands: Record<string, Command> = {
287
287
  console.log(prHelp)
288
288
  return
289
289
  }
290
- process.exitCode = await runEffect(pr(args, options.cwd))
290
+ if (options.passthrough) {
291
+ process.exitCode = await runEffect(pr(args, options.cwd))
292
+ return
293
+ }
294
+ await runCommand(
295
+ prCreate({
296
+ taskId: args[1]!,
297
+ phaseId: args[2],
298
+ draft: options.draft,
299
+ force: options.force,
300
+ json: options.json,
301
+ silent: options.silent,
302
+ verbose: options.verbose,
303
+ cwd: options.cwd,
304
+ }),
305
+ )
291
306
  },
292
307
  },
293
308
  phase: {
@@ -726,7 +741,7 @@ Commands:
726
741
  worktree <subcommand> Inspect and maintain managed workspaces
727
742
  vcs <subcommand> Inspect or migrate the version-control backend
728
743
  next List or select ready execution units
729
- pr [args...] Run gh pr with Agency repository focus
744
+ pr create / pr [...] Create an Agency PR or run gh pr with repository focus
730
745
  review refresh Explicitly refresh a pinned review task
731
746
  repo <subcommand> Manage workbase repositories
732
747
  status Show status for the current workbase
@@ -761,7 +776,7 @@ const machineMode = process.argv
761
776
 
762
777
  try {
763
778
  const args = process.argv.slice(2)
764
- const { commandName, args: commandArgs, values } = parseCli(args)
779
+ const { commandName, args: commandArgs, passthrough, values } = parseCli(args)
765
780
 
766
781
  // Handle global flags
767
782
  if (values.version) {
@@ -785,16 +800,29 @@ try {
785
800
  !values.json &&
786
801
  !values["no-input"] &&
787
802
  Boolean(process.stdin.isTTY && process.stdout.isTTY)
788
- const cwd = await resolveInvocationCwd(commandName, values)
803
+ const cwd = await resolveInvocationCwd(commandName, {
804
+ ...values,
805
+ passthrough,
806
+ })
789
807
  if (values.json || (values.jsonl && values.help)) {
790
808
  const result = await collectCommandResult(() =>
791
- command.run(commandArgs, { ...values, cwd, inputAllowed }),
809
+ command.run(commandArgs, { ...values, cwd, inputAllowed, passthrough }),
792
810
  )
793
811
  writeEnvelope(successEnvelope(result))
794
812
  } else if (values.jsonl) {
795
- await command.run(commandArgs, { ...values, cwd, inputAllowed: false })
813
+ await command.run(commandArgs, {
814
+ ...values,
815
+ cwd,
816
+ inputAllowed: false,
817
+ passthrough,
818
+ })
796
819
  } else {
797
- await command.run(commandArgs, { ...values, cwd, inputAllowed })
820
+ await command.run(commandArgs, {
821
+ ...values,
822
+ cwd,
823
+ inputAllowed,
824
+ passthrough,
825
+ })
798
826
  }
799
827
  } catch (error) {
800
828
  if (machineMode) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markjaquith/agency",
3
- "version": "2.54.0",
3
+ "version": "2.54.1",
4
4
  "description": "Manage agentic work across repositories with durable workbases",
5
5
  "keywords": [
6
6
  "agents",
@@ -367,10 +367,34 @@ describe("strict CLI parsing", () => {
367
367
  expect(parseCli(["--cwd", "/workbase", "pr", ...args])).toEqual({
368
368
  commandName: "pr",
369
369
  args,
370
+ passthrough: true,
370
371
  values: { cwd: "/workbase" },
371
372
  })
372
373
  })
373
374
 
375
+ test("parses task-aware pr create without routing it to passthrough", () => {
376
+ expect(
377
+ parseCli([
378
+ "pr",
379
+ "create",
380
+ "ship",
381
+ "release",
382
+ "--draft",
383
+ "--force",
384
+ "--json",
385
+ ]),
386
+ ).toEqual({
387
+ commandName: "pr",
388
+ args: ["create", "ship", "release"],
389
+ values: { draft: true, force: true, json: true },
390
+ })
391
+ const selected = parseCli(["pr", "create", "--task", "ship"])
392
+ expect(selected).toMatchObject({
393
+ args: ["create", "ship"],
394
+ })
395
+ expect(selected.passthrough).toBeUndefined()
396
+ })
397
+
374
398
  test("parses explicit dry-run reconciliation", () => {
375
399
  expect(parseCli(["sync"])).toMatchObject({
376
400
  commandName: "sync",
package/src/cli-parser.ts CHANGED
@@ -895,12 +895,22 @@ const commands = {
895
895
  },
896
896
  },
897
897
  pr: {
898
- usage: "agency pr [args...]",
899
- options: commonOptions,
900
- command: {
901
- usage: "agency pr [args...]",
902
- minArgs: 0,
903
- maxArgs: Number.POSITIVE_INFINITY,
898
+ usage: "agency pr create <task-id> [phase-id] | agency pr [args...]",
899
+ options: {
900
+ ...outputOptions,
901
+ draft: { type: "boolean" },
902
+ force: { type: "boolean" },
903
+ task: { type: "string" },
904
+ phase: { type: "string" },
905
+ },
906
+ subcommands: {
907
+ create: {
908
+ usage:
909
+ "agency pr create <task-id> [phase-id] [--draft] [--force] [--json]",
910
+ minArgs: 1,
911
+ maxArgs: 2,
912
+ options: ["draft", "force", "json", "task", "phase"],
913
+ },
904
914
  },
905
915
  },
906
916
  next: {
@@ -1019,6 +1029,7 @@ const preCommandValueOptions = new Set(["--workbase", "--cwd"])
1019
1029
  export interface ParsedCli {
1020
1030
  readonly commandName?: keyof typeof commands
1021
1031
  readonly args: string[]
1032
+ readonly passthrough?: boolean
1022
1033
  readonly values: Record<
1023
1034
  string,
1024
1035
  boolean | string | (boolean | string)[] | undefined
@@ -1091,6 +1102,7 @@ const targetSlots = (
1091
1102
  if (commandName === "worktree" && subcommand !== "list") {
1092
1103
  return ["task", "phase"]
1093
1104
  }
1105
+ if (commandName === "pr" && subcommand === "create") return ["task", "phase"]
1094
1106
  return []
1095
1107
  }
1096
1108
 
@@ -1311,7 +1323,15 @@ export function parseCli(args: readonly string[]): ParsedCli {
1311
1323
  "agency <command> [options]",
1312
1324
  )
1313
1325
  }
1314
- if (commandName === "pr") {
1326
+ const prArgs = args.slice(commandIndex + 1)
1327
+ const taskAwarePrCreate =
1328
+ commandName === "pr" &&
1329
+ prArgs[0] === "create" &&
1330
+ ((prArgs[1] !== undefined && !prArgs[1].startsWith("-")) ||
1331
+ prArgs.some(
1332
+ (argument) => argument === "--task" || argument.startsWith("--task="),
1333
+ ))
1334
+ if (commandName === "pr" && !taskAwarePrCreate) {
1315
1335
  const parsed = parse(
1316
1336
  args.slice(0, commandIndex),
1317
1337
  rootOptions,
@@ -1336,7 +1356,8 @@ export function parseCli(args: readonly string[]): ParsedCli {
1336
1356
  }
1337
1357
  return {
1338
1358
  commandName,
1339
- args: [...args.slice(commandIndex + 1)],
1359
+ args: prArgs,
1360
+ passthrough: true,
1340
1361
  values: parsed.values,
1341
1362
  }
1342
1363
  }
package/src/cli.test.ts CHANGED
@@ -598,6 +598,20 @@ exit 23
598
598
  blockers: [{ kind: "status", reason: "Task status is dropped" }],
599
599
  },
600
600
  ])
601
+
602
+ const blockedPr = await runCli(["pr", "create", "finished", "--json"], root)
603
+ expect(blockedPr.exitCode).toBe(1)
604
+ expect(blockedPr.stderr).toBe("")
605
+ expect(JSON.parse(blockedPr.stdout)).toMatchObject({
606
+ ok: false,
607
+ error: {
608
+ code: "EXECUTION_BLOCKED",
609
+ fields: {
610
+ status: "dropped",
611
+ blockers: [{ kind: "status", reason: "Task status is dropped" }],
612
+ },
613
+ },
614
+ })
601
615
  })
602
616
 
603
617
  test("reports and synchronizes managed integration files", async () => {
@@ -1,8 +1,15 @@
1
1
  import { afterEach, beforeEach, describe, expect, test } from "bun:test"
2
+ import { Effect } from "effect"
2
3
  import { chmod, mkdir, realpath } from "node:fs/promises"
3
4
  import { dirname, join } from "node:path"
4
- import { cleanupTempDir, createTempDir, runTestEffect } from "../test-utils"
5
- import { pr } from "./pr"
5
+ import { PullRequestService } from "../services/PullRequestService"
6
+ import {
7
+ captureLogs,
8
+ cleanupTempDir,
9
+ createTempDir,
10
+ runTestEffect,
11
+ } from "../test-utils"
12
+ import { pr, prCreate } from "./pr"
6
13
 
7
14
  const write = async (root: string, path: string, content: string) => {
8
15
  const fullPath = join(root, path)
@@ -95,6 +102,39 @@ status: open
95
102
  return root
96
103
  }
97
104
 
105
+ test("creates and records an Agency pull request", async () => {
106
+ const url = "https://github.com/markjaquith/agency/pull/123"
107
+ let received: unknown[] = []
108
+ const logs = await captureLogs(() =>
109
+ Effect.runPromise(
110
+ prCreate({
111
+ taskId: "example",
112
+ phaseId: "implementation",
113
+ draft: true,
114
+ force: true,
115
+ cwd: "/workbase",
116
+ json: true,
117
+ }).pipe(
118
+ Effect.provideService(PullRequestService, {
119
+ create: (...args: unknown[]) => {
120
+ received = args
121
+ return Effect.succeed(url)
122
+ },
123
+ } as never),
124
+ ) as Effect.Effect<void, unknown, never>,
125
+ ),
126
+ )
127
+
128
+ expect(JSON.parse(logs[0]!)).toEqual({ url })
129
+ expect(received).toEqual([
130
+ "example",
131
+ "implementation",
132
+ true,
133
+ "/workbase",
134
+ expect.objectContaining({ force: true, draft: true, json: true }),
135
+ ])
136
+ })
137
+
98
138
  test("focuses task and descendant invocations on the writable checkout", async () => {
99
139
  const root = await createExecutionWorkbase()
100
140
  const task = join(root, "tasks/single")
@@ -2,6 +2,30 @@ import { Effect } from "effect"
2
2
  import { resolve } from "node:path"
3
3
  import { ContextService } from "../services/ContextService"
4
4
  import { FileSystemService } from "../services/FileSystemService"
5
+ import { PullRequestService } from "../services/PullRequestService"
6
+ import type { BaseCommandOptions } from "../utils/command"
7
+ import { createLoggers } from "../utils/effect"
8
+
9
+ interface PrCreateOptions extends BaseCommandOptions {
10
+ readonly taskId: string
11
+ readonly phaseId?: string
12
+ readonly draft?: boolean
13
+ readonly force?: boolean
14
+ }
15
+
16
+ export const prCreate = (options: PrCreateOptions) =>
17
+ Effect.gen(function* () {
18
+ const pullRequests = yield* PullRequestService
19
+ const { log } = createLoggers(options)
20
+ const url = yield* pullRequests.create(
21
+ options.taskId,
22
+ options.phaseId,
23
+ options.draft,
24
+ options.cwd ?? process.cwd(),
25
+ options,
26
+ )
27
+ log(options.json ? JSON.stringify({ url }, null, 2) : url)
28
+ })
5
29
 
6
30
  export const pr = (args: readonly string[], cwd: string = process.cwd()) =>
7
31
  Effect.gen(function* () {
@@ -24,8 +48,10 @@ export const pr = (args: readonly string[], cwd: string = process.cwd()) =>
24
48
  })
25
49
 
26
50
  export const help = `
27
- Usage: agency pr [args...]
51
+ Usage: agency pr create <task-id> [phase-id] [--draft] [--force] [--json]
52
+ agency pr [args...]
28
53
 
29
- Run gh pr unchanged, focusing the writable repository checkout when invoked
30
- from an Agency execution task or phase.
54
+ Create records a pull request for an Agency execution unit. Other invocations
55
+ run gh pr unchanged, focusing the writable repository checkout when invoked from
56
+ an Agency execution task or phase.
31
57
  `
@@ -59,8 +59,8 @@ to override readiness.
59
59
  - Do not run `agency work` from an active agent session unless the user
60
60
  explicitly asks to launch another agent.
61
61
  - Run `agency validate` before worktree or pull-request operations.
62
- - Create a pull request only with explicit user intent. Run `agency pr create`
63
- from its execution unit, then use `agency sync --apply` to reconcile PR state.
62
+ - Create a pull request only with explicit user intent. Run
63
+ `agency pr create <task> [phase]` so the URL is recorded durably.
64
64
 
65
65
  ## Execution
66
66