From 31c0a703da22850c0f8133bf6f7e67996bf2641b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baldur=20P=C3=A1ll=20H=C3=B3lmgeirsson?= Date: Mon, 23 Nov 2026 13:10:36 +0000 Subject: [PATCH 1/2] fix(branch): --agent-stdin keeps the piped brief with an issue flag (#359) oclif fills a positional that was not given from piped stdin, so with --linear, --github, --jira or --clickup the parse drained the pipe before readBriefStdin ran, and every linear-listen delegation failed with an empty brief. branchName now sets ignoreStdin, and a test runs the real oclif parse with a piped brief for each issue flag. Closes #359 --- .changeset/quiet-pipes-listen.md | 5 +++ src/commands/branch-stdin.test.ts | 62 +++++++++++++++++++++++++++++++ src/commands/branch.ts | 7 +++- 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 .changeset/quiet-pipes-listen.md create mode 100644 src/commands/branch-stdin.test.ts diff --git a/.changeset/quiet-pipes-listen.md b/.changeset/quiet-pipes-listen.md new file mode 100644 index 00000000..309dcef8 --- /dev/null +++ b/.changeset/quiet-pipes-listen.md @@ -0,0 +1,5 @@ +--- +"@northguild/worktree": patch +--- + +`worktree branch --agent-stdin` now reads the piped brief when the branch comes from an issue flag (`--linear`, `--github`, `--jira`, `--clickup`) instead of failing with "The agent brief from --agent-stdin is empty", so `worktree linear-listen` delegations start their agent. diff --git a/src/commands/branch-stdin.test.ts b/src/commands/branch-stdin.test.ts new file mode 100644 index 00000000..4654c67e --- /dev/null +++ b/src/commands/branch-stdin.test.ts @@ -0,0 +1,62 @@ +import { Parser } from "@oclif/core"; +import { afterEach, describe, expect, it } from "vitest"; +import Branch from "./branch.js"; + +// The real oclif parse, not an injected `BriefStdin`: oclif fills a positional +// that was not given from piped stdin, which drained the pipe `--agent-stdin` +// reads its brief from (#359). +const realStdin = Object.getOwnPropertyDescriptor(process, "stdin"); + +async function parseWithPipedStdin(argv: string[], piped: string) { + const { Readable } = await import("node:stream"); + const stdin = Object.assign(Readable.from([piped]), { isTTY: undefined }); + Object.defineProperty(process, "stdin", { value: stdin, configurable: true }); + const cache = globalThis as { oclif?: { stdinCache?: string } }; + if (cache.oclif) cache.oclif.stdinCache = undefined; + + const parsed = await Parser.parse(argv, { + args: Branch.args, + flags: Branch.flags, + strict: Branch.strict, + }); + + return { parsed, remaining: await drain(process.stdin) }; +} + +async function drain(stream: NodeJS.ReadableStream): Promise { + let text = ""; + for await (const chunk of stream) text += chunk; + return text; +} + +afterEach(() => { + if (realStdin) Object.defineProperty(process, "stdin", realStdin); + const cache = globalThis as { oclif?: { stdinCache?: string } }; + if (cache.oclif) cache.oclif.stdinCache = undefined; +}); + +describe("branch parse with a piped brief", () => { + it.each([ + "--linear", + "--github", + "--jira", + "--clickup", + ])("leaves the brief on stdin with %s and no branch name", async (flag) => { + const { parsed, remaining } = await parseWithPipedStdin( + [flag, "ABC-1", "--agent-stdin"], + "Work on ABC-1.", + ); + + expect(parsed.args.branchName).toBeUndefined(); + expect(remaining).toBe("Work on ABC-1."); + }); + + it("does not turn the brief into the branch name", async () => { + const { parsed } = await parseWithPipedStdin( + ["--linear", "ABC-1", "--agent-stdin"], + "Work on ABC-1.", + ); + + expect(parsed.args.branchName).not.toBe("Work on ABC-1."); + }); +}); diff --git a/src/commands/branch.ts b/src/commands/branch.ts index 57834c7f..aa59ec5d 100644 --- a/src/commands/branch.ts +++ b/src/commands/branch.ts @@ -146,7 +146,12 @@ function markBareLinear(argv: string[], booleanChars: string[]): string[] { export default class Branch extends BaseCommand { static override args = { - branchName: Args.string({ description: "Name of the branch to create" }), + // oclif fills a positional that was not given from piped stdin, which would + // drain the pipe `--agent-stdin` reads the brief from (#359). + branchName: Args.string({ + description: "Name of the branch to create", + ignoreStdin: true, + }), }; // The first line is the summary oclif lists in `worktree --help`; the rest is // the `--json` shape and exit codes, kept to key names and nullability. From a52854f9cfdf289638c66c37bd56ae3c4353ab7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baldur=20P=C3=A1ll=20H=C3=B3lmgeirsson?= Date: Mon, 23 Nov 2026 13:31:20 +0000 Subject: [PATCH 2/2] test(branch): cover --agent-stdin with no issue flag instead of a repeated case (#359) --- src/commands/branch-stdin.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/commands/branch-stdin.test.ts b/src/commands/branch-stdin.test.ts index 4654c67e..06692e37 100644 --- a/src/commands/branch-stdin.test.ts +++ b/src/commands/branch-stdin.test.ts @@ -51,12 +51,13 @@ describe("branch parse with a piped brief", () => { expect(remaining).toBe("Work on ABC-1."); }); - it("does not turn the brief into the branch name", async () => { - const { parsed } = await parseWithPipedStdin( - ["--linear", "ABC-1", "--agent-stdin"], + it("leaves the brief on stdin with no issue flag and no branch name", async () => { + const { parsed, remaining } = await parseWithPipedStdin( + ["--agent-stdin"], "Work on ABC-1.", ); - expect(parsed.args.branchName).not.toBe("Work on ABC-1."); + expect(parsed.args.branchName).toBeUndefined(); + expect(remaining).toBe("Work on ABC-1."); }); });