-
Notifications
You must be signed in to change notification settings - Fork 478
feat(cli): default output to JSON for coding agents #5532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jgoux
merged 8 commits into
develop
from
pamela/growth-913-cli-auto-switch-default-output-to-json-for-agents-on
Jun 10, 2026
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3339179
feat(cli): default output to JSON for coding agents
pamelachia 5c57f3e
fix(cli): keep explicit -o output authoritative over agent JSON default
pamelachia 6c907b6
fix(cli): apply agent output format to parse errors
jgoux 310090e
test(cli): harden agent output e2e parsing
jgoux c2f5e4c
refactor(cli): remove agent output override flag
jgoux 47eb743
test(stack): remove port allocator race
jgoux a4b4b3a
fix(cli): preserve legacy agent output controls
jgoux e940eac
fix(cli): scope root version text detection
jgoux File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
| import { runSupabase } from "../../../tests/helpers/cli.ts"; | ||
|
|
||
| function parseJsonLines(output: string): Array<unknown> { | ||
| return output | ||
| .trim() | ||
| .split("\n") | ||
| .filter((line) => line.length > 0) | ||
| .map((line) => JSON.parse(line)); | ||
| } | ||
|
|
||
| describe("legacy CLI agent output", () => { | ||
| test("formats parse errors as JSON for detected coding agents", async () => { | ||
| const { exitCode, stdout, stderr } = await runSupabase(["definitely-not-a-command"], { | ||
| entrypoint: "legacy", | ||
| env: { CODEX_SANDBOX: "1" }, | ||
| }); | ||
|
|
||
| expect(exitCode).toBe(1); | ||
| expect(parseJsonLines(stdout)).toEqual([ | ||
| expect.objectContaining({ _tag: "Help" }), | ||
| expect.objectContaining({ | ||
| _tag: "Error", | ||
| error: expect.objectContaining({ code: "ShowHelp" }), | ||
| }), | ||
| ]); | ||
| expect(parseJsonLines(stderr)).toEqual([ | ||
|
Check failure on line 27 in apps/cli/src/legacy/cli/agent-output.e2e.test.ts
|
||
| expect.objectContaining({ | ||
| _tag: "Errors", | ||
| errors: [expect.objectContaining({ code: "UnknownSubcommand" })], | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| test("keeps parse errors in text mode when --agent=no is explicit", async () => { | ||
| const { exitCode, stdout, stderr } = await runSupabase( | ||
| ["--agent", "no", "definitely-not-a-command"], | ||
| { | ||
| entrypoint: "legacy", | ||
| env: { CODEX_SANDBOX: "1" }, | ||
| }, | ||
| ); | ||
|
|
||
| expect(exitCode).toBe(1); | ||
| expect(stdout).toContain("DESCRIPTION"); | ||
| expect(stderr).toContain('Unknown subcommand "definitely-not-a-command"'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { Option } from "effect"; | ||
| import type { OutputFormat } from "../output/types.ts"; | ||
|
|
||
| type LegacyOutputFormat = "env" | "pretty" | "json" | "toml" | "yaml"; | ||
| type AgentOverride = "auto" | "yes" | "no"; | ||
|
|
||
| interface AgentOutputOptions { | ||
| readonly explicitOutputFormat: Option.Option<OutputFormat>; | ||
| readonly legacyOutputFormat?: Option.Option<LegacyOutputFormat>; | ||
| readonly agentOverride?: AgentOverride; | ||
| readonly detectedAgentName?: Option.Option<string>; | ||
| } | ||
|
|
||
| function readLongFlag(args: ReadonlyArray<string>, name: string): string | undefined { | ||
| const prefix = `${name}=`; | ||
| for (let i = 0; i < args.length; i++) { | ||
| const arg = args[i]; | ||
| if (arg === undefined) { | ||
| continue; | ||
| } | ||
| if (arg === name) { | ||
| return args[i + 1]; | ||
| } | ||
| if (arg.startsWith(prefix)) { | ||
| return arg.slice(prefix.length); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function readOutputFlag(args: ReadonlyArray<string>): string | undefined { | ||
| for (let i = 0; i < args.length; i++) { | ||
| const arg = args[i]; | ||
| if (arg === undefined) { | ||
| continue; | ||
| } | ||
| if (arg === "--output" || arg === "-o") { | ||
| return args[i + 1]; | ||
| } | ||
| if (arg.startsWith("--output=")) { | ||
| return arg.slice("--output=".length); | ||
| } | ||
| if (arg.startsWith("-o=")) { | ||
| return arg.slice("-o=".length); | ||
| } | ||
| if (arg.length > 2 && arg.startsWith("-o")) { | ||
| return arg.slice("-o".length); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function outputFormatFromArg(value: string | undefined): Option.Option<OutputFormat> { | ||
| switch (value) { | ||
| case "text": | ||
| case "json": | ||
| case "stream-json": | ||
| return Option.some(value); | ||
| default: | ||
| return Option.none(); | ||
| } | ||
| } | ||
|
|
||
| function legacyOutputFormatFromArg(value: string | undefined): Option.Option<LegacyOutputFormat> { | ||
| switch (value) { | ||
| case "env": | ||
| case "pretty": | ||
| case "json": | ||
| case "toml": | ||
| case "yaml": | ||
| return Option.some(value); | ||
| default: | ||
| return Option.none(); | ||
| } | ||
| } | ||
|
|
||
| function agentOverrideFromArg(value: string | undefined): AgentOverride { | ||
| switch (value) { | ||
| case "yes": | ||
| case "no": | ||
| return value; | ||
| default: | ||
| return "auto"; | ||
| } | ||
| } | ||
|
|
||
| export function resolveAgentOutputFormat(options: AgentOutputOptions): OutputFormat { | ||
| const legacyOutputFormat = options.legacyOutputFormat ?? Option.none<LegacyOutputFormat>(); | ||
| const agentOverride = options.agentOverride ?? "auto"; | ||
| const detectedAgentName = options.detectedAgentName ?? Option.none<string>(); | ||
| const isCodingAgent = | ||
| agentOverride === "yes" || (agentOverride !== "no" && Option.isSome(detectedAgentName)); | ||
|
|
||
| return Option.getOrElse(options.explicitOutputFormat, () => | ||
| isCodingAgent && Option.isNone(legacyOutputFormat) ? "json" : "text", | ||
| ); | ||
| } | ||
|
|
||
| export function resolveAgentOutputFormatFromArgs( | ||
| args: ReadonlyArray<string>, | ||
| detectedAgentName: Option.Option<string>, | ||
| ): OutputFormat { | ||
| const explicitOutputFormat = outputFormatFromArg(readLongFlag(args, "--output-format")); | ||
| const legacyOutputFormat = legacyOutputFormatFromArg(readOutputFlag(args)); | ||
| const agentOverride = agentOverrideFromArg(readLongFlag(args, "--agent")); | ||
|
|
||
| return resolveAgentOutputFormat({ | ||
| explicitOutputFormat, | ||
| legacyOutputFormat, | ||
| agentOverride, | ||
| detectedAgentName, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { Option } from "effect"; | ||
| import { describe, expect, it } from "vitest"; | ||
| import { resolveAgentOutputFormat, resolveAgentOutputFormatFromArgs } from "./agent-output.ts"; | ||
|
|
||
| describe("resolveAgentOutputFormat", () => { | ||
| it("defaults a coding agent to json", () => { | ||
| expect( | ||
| resolveAgentOutputFormat({ | ||
| explicitOutputFormat: Option.none(), | ||
| detectedAgentName: Option.some("codex"), | ||
| }), | ||
| ).toBe("json"); | ||
| }); | ||
|
|
||
| it("defaults a non-agent to text", () => { | ||
| expect( | ||
| resolveAgentOutputFormat({ | ||
| explicitOutputFormat: Option.none(), | ||
| detectedAgentName: Option.none(), | ||
| }), | ||
| ).toBe("text"); | ||
| }); | ||
|
|
||
| it("honors an explicit format over agent detection", () => { | ||
| expect( | ||
| resolveAgentOutputFormat({ | ||
| explicitOutputFormat: Option.some("text"), | ||
| detectedAgentName: Option.some("codex"), | ||
| }), | ||
| ).toBe("text"); | ||
| expect( | ||
| resolveAgentOutputFormat({ | ||
| explicitOutputFormat: Option.some("stream-json"), | ||
| detectedAgentName: Option.none(), | ||
| }), | ||
| ).toBe("stream-json"); | ||
| expect( | ||
| resolveAgentOutputFormat({ | ||
| explicitOutputFormat: Option.some("json"), | ||
| detectedAgentName: Option.some("codex"), | ||
| }), | ||
| ).toBe("json"); | ||
| }); | ||
|
|
||
| it("honors the --agent override", () => { | ||
| expect( | ||
| resolveAgentOutputFormat({ | ||
| explicitOutputFormat: Option.none(), | ||
| agentOverride: "yes", | ||
| detectedAgentName: Option.none(), | ||
| }), | ||
| ).toBe("json"); | ||
| expect( | ||
| resolveAgentOutputFormat({ | ||
| explicitOutputFormat: Option.none(), | ||
| agentOverride: "no", | ||
| detectedAgentName: Option.some("codex"), | ||
| }), | ||
| ).toBe("text"); | ||
| }); | ||
|
|
||
| it("keeps legacy --output authoritative over the agent JSON default", () => { | ||
| expect( | ||
| resolveAgentOutputFormat({ | ||
| explicitOutputFormat: Option.none(), | ||
| legacyOutputFormat: Option.some("pretty"), | ||
| detectedAgentName: Option.some("codex"), | ||
| }), | ||
| ).toBe("text"); | ||
| }); | ||
|
|
||
| it("resolves the effective format from raw argv for runtime error formatting", () => { | ||
| expect(resolveAgentOutputFormatFromArgs(["bad-command"], Option.some("codex"))).toBe("json"); | ||
| expect( | ||
| resolveAgentOutputFormatFromArgs(["--agent", "no", "bad-command"], Option.some("codex")), | ||
| ).toBe("text"); | ||
| expect( | ||
| resolveAgentOutputFormatFromArgs(["-o", "pretty", "bad-command"], Option.some("codex")), | ||
| ).toBe("text"); | ||
| expect( | ||
| resolveAgentOutputFormatFromArgs( | ||
| ["--output-format=stream-json", "bad-command"], | ||
| Option.some("codex"), | ||
| ), | ||
| ).toBe("stream-json"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,8 @@ | ||
| import { Flag, GlobalFlag } from "effect/unstable/cli"; | ||
| import type { OutputFormat } from "../output/types.ts"; | ||
|
|
||
| export const OutputFormatFlag = GlobalFlag.setting("output-format")({ | ||
| flag: Flag.choice("output-format", ["text", "json", "stream-json"]).pipe( | ||
| Flag.withDescription("Output format: text (default), json, or stream-json (NDJSON)"), | ||
| Flag.withDefault("text" as OutputFormat), | ||
| Flag.optional, | ||
| ), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.