-
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 all 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,126 @@ | ||
| import { describe, expect, test } from "vitest"; | ||
| import { runSupabase } from "../../../tests/helpers/cli.ts"; | ||
|
|
||
| function stripAnsi(output: string): string { | ||
| let stripped = ""; | ||
| for (let i = 0; i < output.length; i++) { | ||
| const charCode = output.charCodeAt(i); | ||
| if (charCode !== 0x1b || output[i + 1] !== "[") { | ||
| stripped += output[i]; | ||
| continue; | ||
| } | ||
|
|
||
| i += 2; | ||
| while (i < output.length) { | ||
| const code = output.charCodeAt(i); | ||
| if (code >= 0x40 && code <= 0x7e) { | ||
| break; | ||
| } | ||
| i++; | ||
| } | ||
| } | ||
| return stripped; | ||
| } | ||
|
|
||
| function parseJsonLines(output: string): Array<unknown> { | ||
| return stripAnsi(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([ | ||
| expect.objectContaining({ | ||
| _tag: "Errors", | ||
| errors: [expect.objectContaining({ code: "UnknownSubcommand" })], | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| test("keeps parse errors in text mode when --output-format=text is explicit", async () => { | ||
| const { exitCode, stdout, stderr } = await runSupabase( | ||
| ["--output-format", "text", "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"'); | ||
| }); | ||
|
|
||
| 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"'); | ||
| }); | ||
|
|
||
| test("formats parse errors as JSON when --agent=yes is explicit", async () => { | ||
| const { exitCode, stdout, stderr } = await runSupabase( | ||
| ["--agent", "yes", "definitely-not-a-command"], | ||
| { | ||
| entrypoint: "legacy", | ||
| env: {}, | ||
| }, | ||
| ); | ||
|
|
||
| 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([ | ||
| expect.objectContaining({ | ||
| _tag: "Errors", | ||
| errors: [expect.objectContaining({ code: "UnknownSubcommand" })], | ||
| }), | ||
| ]); | ||
| }); | ||
|
|
||
| test("keeps built-in version and help in text mode for detected coding agents", async () => { | ||
| const version = await runSupabase(["--version"], { | ||
| entrypoint: "legacy", | ||
| env: { CODEX_SANDBOX: "1" }, | ||
| }); | ||
| const help = await runSupabase(["--help"], { | ||
| entrypoint: "legacy", | ||
| env: { CODEX_SANDBOX: "1" }, | ||
| }); | ||
|
|
||
| expect(version.exitCode).toBe(0); | ||
| expect(version.stdout.trim()).toMatch(/^\d+\.\d+\.\d+/); | ||
| expect(() => JSON.parse(version.stdout)).toThrow(); | ||
| expect(help.exitCode).toBe(0); | ||
| expect(help.stdout).toContain("DESCRIPTION"); | ||
| expect(() => JSON.parse(help.stdout)).toThrow(); | ||
| }); | ||
| }); |
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,181 @@ | ||
| 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>; | ||
| readonly isBuiltInTextRequest?: boolean; | ||
| } | ||
|
|
||
| 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"; | ||
| } | ||
| } | ||
|
|
||
| function isRootValueFlag(arg: string): boolean { | ||
| return ( | ||
| arg === "--output-format" || | ||
| arg === "--output" || | ||
| arg === "-o" || | ||
| arg === "--profile" || | ||
| arg === "--workdir" || | ||
| arg === "--network-id" || | ||
| arg === "--dns-resolver" || | ||
| arg === "--agent" | ||
| ); | ||
| } | ||
|
|
||
| function isRootValueFlagWithInlineValue(arg: string): boolean { | ||
| return ( | ||
| arg.startsWith("--output-format=") || | ||
| arg.startsWith("--output=") || | ||
| arg.startsWith("-o=") || | ||
| (arg.length > 2 && arg.startsWith("-o")) || | ||
| arg.startsWith("--profile=") || | ||
| arg.startsWith("--workdir=") || | ||
| arg.startsWith("--network-id=") || | ||
| arg.startsWith("--dns-resolver=") || | ||
| arg.startsWith("--agent=") | ||
| ); | ||
| } | ||
|
|
||
| function isRootBooleanFlag(arg: string): boolean { | ||
| return ( | ||
| arg === "--debug" || arg === "--experimental" || arg === "--yes" || arg === "--create-ticket" | ||
| ); | ||
| } | ||
|
|
||
| function hasRootVersionRequest(args: ReadonlyArray<string>): boolean { | ||
| for (let i = 0; i < args.length; i++) { | ||
| const arg = args[i]; | ||
| if (arg === undefined || arg === "--") { | ||
| return false; | ||
| } | ||
| if (arg === "--version" || arg === "-v") { | ||
| return true; | ||
| } | ||
| if (isRootValueFlag(arg)) { | ||
| i++; | ||
| continue; | ||
| } | ||
| if (isRootValueFlagWithInlineValue(arg) || isRootBooleanFlag(arg)) { | ||
| continue; | ||
| } | ||
| return false; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| function hasHelpRequest(args: ReadonlyArray<string>): boolean { | ||
| for (const arg of args) { | ||
| if (arg === "--") return false; | ||
| if (arg === "--help" || arg === "-h") return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| export function isBuiltInTextRequest(args: ReadonlyArray<string>): boolean { | ||
| return hasHelpRequest(args) || hasRootVersionRequest(args); | ||
| } | ||
|
|
||
| export function resolveAgentOutputFormat(options: AgentOutputOptions): OutputFormat { | ||
| const legacyOutputFormat = options.legacyOutputFormat ?? Option.none<LegacyOutputFormat>(); | ||
| const detectedAgentName = options.detectedAgentName ?? Option.none<string>(); | ||
| const agentOverride = options.agentOverride ?? "auto"; | ||
| const isCodingAgent = | ||
| agentOverride === "yes" || (agentOverride === "auto" && Option.isSome(detectedAgentName)); | ||
|
|
||
| return Option.getOrElse(options.explicitOutputFormat, () => | ||
| isCodingAgent && Option.isNone(legacyOutputFormat) && !options.isBuiltInTextRequest | ||
| ? "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, | ||
| isBuiltInTextRequest: isBuiltInTextRequest(args), | ||
| }); | ||
| } |
Oops, something went wrong.
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.