@markjaquith/agency 0.8.0 → 1.0.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
@@ -10,11 +10,26 @@ bun install -g @markjaquith/agency
10
10
 
11
11
  ## Primary Commands
12
12
 
13
- ### `agency task [branch-name]`
13
+ ### `agency task <branch-name>`
14
14
 
15
- Initialize `AGENTS.md` and `TASK.md` files using the template you've set for this repo. Commits smuggled files and lands you on that branch.
15
+ Create a new feature branch from the latest `origin/main` and initialize `AGENTS.md` and `TASK.md` files using the template you've set for this repo. Commits smuggled files and lands you on that branch.
16
16
 
17
- ### `agency task edit`
17
+ **Options:**
18
+
19
+ - `--from <branch>` - Branch from a specific branch instead of `origin/main`
20
+ - `--from-current` - Initialize on current branch instead of creating a new one
21
+ - `--continue` - Continue a task by copying agency files to a new branch (after PR merge)
22
+
23
+ **Examples:**
24
+
25
+ ```bash
26
+ agency task my-feature # Create 'my-feature' from latest origin/main
27
+ agency task my-feature --from dev # Create 'my-feature' from 'dev' branch
28
+ agency task --from-current # Initialize on current branch (no new branch)
29
+ agency task --continue my-feature-v2 # Continue task on new branch after PR merge
30
+ ```
31
+
32
+ ### `agency edit`
18
33
 
19
34
  Open `TASK.md` in the system editor for editing. Nice if you have to paste in large amounts of context.
20
35
 
package/cli.ts CHANGED
@@ -426,8 +426,8 @@ Global Options:
426
426
 
427
427
  Examples:
428
428
  agency init # Initialize with template (run first)
429
- agency task # Initialize on current feature branch
430
- agency task my-feature # Create 'my-feature' branch and initialize
429
+ agency task my-feature # Create 'my-feature' branch from origin/main
430
+ agency task --from-current # Initialize on current feature branch
431
431
  agency emit # Emit a branch (prompts for base branch)
432
432
  agency switch # Toggle between source and emitted branch
433
433
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markjaquith/agency",
3
- "version": "0.8.0",
3
+ "version": "1.0.1",
4
4
  "description": "Manages personal agents files",
5
5
  "license": "MIT",
6
6
  "author": "Mark Jaquith",
@@ -60,7 +60,7 @@ describe("emit command", () => {
60
60
  // Initialize AGENTS.md and commit in one go
61
61
  await initAgency(tempDir, "test")
62
62
 
63
- await runTestEffect(task({ silent: true }))
63
+ await runTestEffect(task({ silent: true, fromCurrent: true }))
64
64
  await addAndCommit(tempDir, "AGENTS.md", "Add AGENTS.md")
65
65
 
66
66
  // Set up origin/main for git-filter-repo
@@ -64,7 +64,7 @@ describe("merge command", () => {
64
64
  // Initialize AGENTS.md on feature branch
65
65
  await initAgency(tempDir, "test")
66
66
 
67
- await runTestEffect(task({ silent: true }))
67
+ await runTestEffect(task({ silent: true, fromCurrent: true }))
68
68
 
69
69
  // Ensure agency.json has baseBranch set (task should auto-detect it, but ensure it's there)
70
70
  const agencyJsonPath = join(tempDir, "agency.json")
@@ -676,13 +676,13 @@ describe("task command", () => {
676
676
  })
677
677
 
678
678
  describe("branch handling", () => {
679
- test("fails when on main branch without branch name", async () => {
679
+ test("fails when no branch name provided (silent mode)", async () => {
680
680
  await initGitRepo(tempDir)
681
681
  process.chdir(tempDir)
682
682
 
683
683
  await initAgency(tempDir, "test")
684
684
  await expect(runTestEffect(task({ silent: true }))).rejects.toThrow(
685
- "main branch",
685
+ "Branch name is required",
686
686
  )
687
687
  })
688
688
 
@@ -415,7 +415,23 @@ export const task = (options: TaskOptions = {}) =>
415
415
  )
416
416
  }
417
417
  } else {
418
- // Default: determine main upstream branch (preferring remote)
418
+ // Default: fetch and use latest main upstream branch
419
+ // First, determine the remote to fetch from
420
+ const remote =
421
+ (yield* git.getRemoteConfig(targetPath)) ||
422
+ (yield* git.findDefaultRemote(targetPath))
423
+
424
+ if (remote) {
425
+ verboseLog(`Fetching from remote: ${remote}`)
426
+ yield* git.fetch(targetPath, remote).pipe(
427
+ Effect.catchAll((err) => {
428
+ verboseLog(`Failed to fetch from ${remote}: ${err}`)
429
+ return Effect.void
430
+ }),
431
+ )
432
+ }
433
+
434
+ // Now resolve the main branch (preferring remote)
419
435
  baseBranchToBranchFrom =
420
436
  (yield* git.resolveMainBranch(targetPath)) || undefined
421
437
 
@@ -431,7 +447,8 @@ export const task = (options: TaskOptions = {}) =>
431
447
 
432
448
  // Check if the base branch is an agency source branch
433
449
  // If so, we need to emit it first and use the emit branch instead
434
- if (baseBranchToBranchFrom) {
450
+ // Skip this check if using --from-current (we want to stay on current branch, not branch from it)
451
+ if (baseBranchToBranchFrom && !options.fromCurrent) {
435
452
  const cleanFromBase = extractCleanBranch(
436
453
  baseBranchToBranchFrom,
437
454
  config.sourceBranchPattern,
@@ -473,17 +490,14 @@ export const task = (options: TaskOptions = {}) =>
473
490
  // Determine branch name logic
474
491
  let branchName = options.emit || options.branch
475
492
 
476
- // If on main branch, using --from, or on an agency source branch without a branch name, prompt for it (unless in silent mode)
477
- if ((!isFeature || options.from || hasAgencyJson) && !branchName) {
493
+ // Determine if we need a new branch name:
494
+ // - With --from-current on a feature branch without agency.json: can stay on current branch
495
+ // - All other cases: require a new branch name
496
+ const canStayOnCurrentBranch =
497
+ options.fromCurrent && isFeature && !hasAgencyJson
498
+
499
+ if (!branchName && !canStayOnCurrentBranch) {
478
500
  if (silent) {
479
- if (options.from) {
480
- return yield* Effect.fail(
481
- new Error(
482
- `Branch name is required when using --from flag.\n` +
483
- `Use: 'agency task <branch-name> --from ${options.from}'`,
484
- ),
485
- )
486
- }
487
501
  if (hasAgencyJson) {
488
502
  return yield* Effect.fail(
489
503
  new Error(
@@ -495,10 +509,9 @@ export const task = (options: TaskOptions = {}) =>
495
509
  }
496
510
  return yield* Effect.fail(
497
511
  new Error(
498
- `You're currently on ${highlight.branch(currentBranch)}, which appears to be your main branch.\n` +
499
- `To initialize on a feature branch, either:\n` +
500
- ` 1. Switch to an existing feature branch first, then run 'agency task'\n` +
501
- ` 2. Provide a new branch name: 'agency task <branch-name>'`,
512
+ `Branch name is required.\n` +
513
+ `Use: 'agency task <branch-name>'\n` +
514
+ `Or use --from-current to initialize on the current branch.`,
502
515
  ),
503
516
  )
504
517
  }
@@ -928,6 +941,7 @@ const taskEditEffect = (options: TaskEditOptions = {}) =>
928
941
  }
929
942
 
930
943
  // Get editor from environment or use sensible defaults
944
+ // On macOS, use 'open -W' to wait for the editor to close
931
945
  const editor =
932
946
  process.env.VISUAL ||
933
947
  process.env.EDITOR ||
@@ -935,7 +949,16 @@ const taskEditEffect = (options: TaskEditOptions = {}) =>
935
949
 
936
950
  verboseLog(`Using editor: ${editor}`)
937
951
 
938
- const result = yield* fs.runCommand([editor, taskFilePath])
952
+ // Build the command array
953
+ // If using 'open' on macOS, add -W flag to wait for the app to close
954
+ const editorCommand =
955
+ editor === "open" ? [editor, "-W", taskFilePath] : [editor, taskFilePath]
956
+
957
+ // Use interactive mode for editors that need terminal access (stdin/stdout/stderr)
958
+ // 'open' on macOS launches a separate app, so it doesn't need interactive mode
959
+ const result = yield* fs.runCommand(editorCommand, {
960
+ interactive: editor !== "open",
961
+ })
939
962
 
940
963
  if (result.exitCode !== 0) {
941
964
  return yield* Effect.fail(
@@ -983,28 +1006,22 @@ Example:
983
1006
  `
984
1007
 
985
1008
  export const help = `
986
- Usage: agency task [branch-name] [options]
1009
+ Usage: agency task <branch-name> [options]
987
1010
 
988
1011
  Initialize template files (AGENTS.md, TASK.md, opencode.json) in a git repository.
989
1012
 
990
1013
  IMPORTANT:
991
1014
  - You must run 'agency init' first to select a template
992
- - This command must be run on a feature branch, not the main branch
993
-
994
- If you're on the main branch, you must either:
995
- 1. Switch to an existing feature branch first, then run 'agency task'
996
- 2. Provide a branch name: 'agency task <branch-name>'
997
-
998
- Initializes files at the root of the current git repository.
1015
+ - A branch name is required (creates a new branch from the latest origin/main)
999
1016
 
1000
1017
  Arguments:
1001
- branch-name Create and switch to this branch before initializing
1018
+ branch-name Name for the new feature branch (required)
1002
1019
 
1003
1020
  Options:
1004
1021
  --emit Branch name to create (alternative to positional arg)
1005
1022
  --branch (Deprecated: use --emit) Branch name to create
1006
1023
  --from <branch> Branch to branch from instead of main upstream branch
1007
- --from-current Branch from the current branch
1024
+ --from-current Initialize on current branch instead of creating a new one
1008
1025
  --continue Continue a task by copying agency files to a new branch
1009
1026
 
1010
1027
  Continue Mode (--continue):
@@ -1020,39 +1037,33 @@ Continue Mode (--continue):
1020
1037
  4. The emitBranch in agency.json is updated for the new branch
1021
1038
 
1022
1039
  Base Branch Selection:
1023
- By default, 'agency task' branches from the main upstream branch (e.g., origin/main).
1024
- You can override this behavior with:
1040
+ By default, 'agency task' fetches from the remote and branches from the latest
1041
+ main upstream branch (e.g., origin/main). You can override this behavior with:
1025
1042
 
1026
1043
  - --from <branch>: Branch from a specific branch
1027
- - --from-current: Branch from your current branch
1044
+ - --from-current: Initialize on your current branch (no new branch created)
1028
1045
 
1029
1046
  If the base branch is an agency source branch (e.g., agency/branch-A), the command
1030
1047
  will automatically use its emit branch instead. This allows you to layer work on top
1031
1048
  of other feature branches while maintaining clean branch history.
1032
1049
 
1033
1050
  Examples:
1034
- agency task # Branch from main upstream branch
1035
- agency task --from agency/branch-B # Branch from agency/branch-B's emit branch
1036
- agency task --from-current # Branch from current branch's emit branch
1051
+ agency task my-feature # Create 'my-feature' from latest origin/main
1037
1052
  agency task my-feature --from develop # Create 'my-feature' from 'develop'
1053
+ agency task --from-current # Initialize on current branch (no new branch)
1038
1054
  agency task --continue my-feature-v2 # Continue task on new branch after PR merge
1039
1055
 
1040
1056
  Template Workflow:
1041
1057
  1. Run 'agency init' to select template (saved to .git/config)
1042
- 2. Run 'agency task' to create template files on feature branch
1058
+ 2. Run 'agency task <branch-name>' to create feature branch with template files
1043
1059
  3. Use 'agency template save <file>' to update template with local changes
1044
1060
  4. Template directory only created when you save files to it
1045
1061
 
1046
1062
  Branch Creation:
1047
1063
  When creating a new branch without --from or --from-current:
1048
- 1. Auto-detects main upstream branch (origin/main, origin/master, etc.)
1049
- 2. Falls back to configured main branch in .git/config (agency.mainBranch)
1050
- 3. In --silent mode, a base branch must already be configured
1051
-
1052
- When using --from with an agency source branch:
1053
- 1. Verifies the emit branch exists for the source branch
1054
- 2. Uses the emit branch as the actual base to avoid agency files
1055
- 3. Fails if emit branch doesn't exist (run 'agency emit' first)
1064
+ 1. Fetches from the configured remote (or origin)
1065
+ 2. Auto-detects main upstream branch (origin/main, origin/master, etc.)
1066
+ 3. Creates new branch from the latest remote main branch
1056
1067
 
1057
1068
  Notes:
1058
1069
  - Files are created at the git repository root, not the current directory
@@ -152,13 +152,15 @@ export class FileSystemService extends Effect.Service<FileSystemService>()(
152
152
  options?: {
153
153
  readonly cwd?: string
154
154
  readonly captureOutput?: boolean
155
+ readonly interactive?: boolean
155
156
  },
156
157
  ) =>
157
158
  pipe(
158
159
  spawnProcess(args, {
159
160
  cwd: options?.cwd,
161
+ stdin: options?.interactive ? "inherit" : "pipe",
160
162
  stdout: options?.captureOutput ? "pipe" : "inherit",
161
- stderr: "pipe",
163
+ stderr: options?.interactive ? "inherit" : "pipe",
162
164
  }),
163
165
  Effect.mapError(
164
166
  (processError) =>
package/src/types.ts CHANGED
@@ -55,7 +55,7 @@ Agency is a CLI tool for managing \`AGENTS.md\`, \`TASK.md\`, and \`opencode.jso
55
55
 
56
56
  ## Key Commands
57
57
 
58
- - \`agency task\` - Initialize template files on a feature branch
58
+ - \`agency task <branch-name>\` - Create feature branch and initialize template files
59
59
  - \`agency edit\` - Open TASK.md in system editor
60
60
  - \`agency template save\` - Save current file versions back to a template
61
61
  - \`agency template use\` - Switch to a different template
@@ -14,6 +14,7 @@ interface ProcessResult {
14
14
  */
15
15
  interface SpawnOptions {
16
16
  readonly cwd?: string
17
+ readonly stdin?: "pipe" | "inherit"
17
18
  readonly stdout?: "pipe" | "inherit"
18
19
  readonly stderr?: "pipe" | "inherit"
19
20
  readonly env?: Record<string, string>
@@ -41,6 +42,7 @@ export const spawnProcess = (
41
42
  try: async () => {
42
43
  const proc = Bun.spawn([...args], {
43
44
  cwd: options?.cwd ?? process.cwd(),
45
+ stdin: options?.stdin ?? "pipe",
44
46
  stdout: options?.stdout ?? "pipe",
45
47
  stderr: options?.stderr ?? "pipe",
46
48
  env: options?.env ? { ...process.env, ...options.env } : process.env,