Repository navigation
fix(cli): return structured results from configure and auth login/logout in machine output modes - #141
fix(cli): return structured results from configure and auth login/logout in machine output modes#141TristanSpeakEasy wants to merge 4 commits into
Conversation
…out in machine output modes
There was a problem hiding this comment.
1 issue found across 6 files
Confidence score: 3/5
- In
templates/templates/cli/configure.go.stmpl, explicit interactive mode can emit form prompts before the JSON result, making--output-format jsoninvalid machine-readable output. Reject this combination before rendering the form.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="templates/templates/cli/configure.go.stmpl">
<violation number="1" location="templates/templates/cli/configure.go.stmpl:175">
P2: Explicit interactive mode can still run the form before this machine result is emitted, so `--output-format json` receives prompts before the JSON object and becomes invalid machine output. Reject this combination or suppress the form whenever a machine format is selected.</violation>
</file>
Shadow auto-approve: would not auto-approve because issues were found.
View guided diff | Turn on auto-fix | Re-trigger cubic
| } | ||
|
|
||
| {{- if isAnyInteractiveEnabled}} | ||
| if output.IsMachineMode(cmd) { |
There was a problem hiding this comment.
P2: Explicit interactive mode can still run the form before this machine result is emitted, so --output-format json receives prompts before the JSON object and becomes invalid machine output. Reject this combination or suppress the form whenever a machine format is selected.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At templates/templates/cli/configure.go.stmpl, line 175:
<comment>Explicit interactive mode can still run the form before this machine result is emitted, so `--output-format json` receives prompts before the JSON object and becomes invalid machine output. Reject this combination or suppress the form whenever a machine format is selected.</comment>
<file context>
@@ -171,6 +171,18 @@ func runConfigureCmd(cmd *cobra.Command, args []string) error {
}
+ {{- if isAnyInteractiveEnabled}}
+ if output.IsMachineMode(cmd) {
+ result := map[string]any{"config_file": config.GetConfigPath()}
+ {{- if hasSecretCLIFields}}
</file context>
There was a problem hiding this comment.
Leaving this as is. The form only runs when the user explicitly asks for it with --interactive (or the CLI defaults to interactive and no value flags are passed), and combining that with -o json is a conflicting request. Forms render on the terminal, and the JSON result is still the only thing configure writes on completion. Scripts should pass value flags or --no-interactive, which skip the form.
…-output # Conflicts: # zSDKs/sdk-cli/.speakeasy/gen.lock
…e machine output stable
AshGodfrey
left a comment
There was a problem hiding this comment.
Verified on a regenerated CLI: configure, auth login and auth logout return the structured envelope under json, yaml, toon, agent mode and --jq, prose is unchanged otherwise, and the output format is pinned before the saved default changes. Merge after #140 and retarget to main.
Stacked on #140 (the
clearedfield reports values removed withconfigure --clear, andauth logoutuses theconfig.DeleteStoredSecrethelper from #140). Retarget tomainonce #140 merges.Why
In machine output modes (
-o json,-o yaml,-o toon,--jq, agent mode) a successful liveconfigure,auth loginorauth logoutstill printed prose such asConfiguration saved to ...to stdout. The--dry-runpath of the same commands already returns a structured no-op object, andwhoamialready returns a structured result, so scripts got a parseable answer from the preview but not from the real run.What changed
On success, in machine mode the commands return an
output.LocalResultinstead of prose. Human output is unchanged.configure:{"config_file": ..., "keychain_stored": bool, "cleared": [...]}.keychain_storedis present when the API declares secret credentials;clearedonly when--clearremoved something. This applies whether or not interactive features are generated.configureresolves the output mode and format before it saves, via a newoutput.PinOutputFormat. Otherwiseconfigure --default-output-format json(or clearing a savedjsondefault) would change how its own result is rendered.auth login:{"config_file": ..., "keychain_stored": bool}.auth logout:{"config_file": ..., "cleared": true, "keychain_cleared": bool}. Logout still clears every credential from the config file, but if the OS keychain refuses to delete one it now returns an error naming the credential instead of reporting success, sokeychain_cleared: truemeans the keychain deletes worked. An unavailable or unresponsive keychain is reported as skipped as before (keychain_cleared: false).configure --clearJSON output (with a savedjsondefault being cleared),auth logoutJSON output, and a failed keychain delete on logout.Example:
Testing
TARGET=review make test-cliandTARGET=primary make test-cli: pass.make check-template-cli: passes.interactiveAuth: falseandinteractiveMode: false: builds, andconfigure -o jsonends with the structured result.configureset and--clearunder-o json, andauth logout -o json.Public-safety check
.claude/skills/public-repo-communication/SKILL.md).git diff --check.