-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add --output json flag for machine-readable output #67
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
Conversation
Add JSON output support to CLI commands for scripting and automation: Tier 1 (create/acquire operations): - browsers create - browser-pools create, acquire - profiles create - extensions upload - proxies create - deploy (JSONL streaming) Tier 2 (list/get operations): - browsers list, get, view - browser-pools list, get, update - profiles list, get - extensions list - proxies list, get Tier 3 (app/invoke/browser sub-operations): - app list, history - deploy history - invoke (JSONL streaming), history - browsers replays list, start - browsers process exec, spawn - browsers fs file-info, list-files For streaming commands (deploy, invoke), output is JSONL format (one JSON object per line) for real-time parsing. Usage: --output json or -o json
Document JSON output support for CLI commands: - Add JSON Output section to main CLI reference page - Document --output json flag for deploy, invoke, app commands - Document --output json flag for browsers, browser-pools, profiles - Document --output json flag for extensions, proxies - Add browser-pools and profiles CLI sections Related to kernel/cli#67
cmd/app.go
Outdated
|
|
||
| if output != "" && output != "json" { | ||
| pterm.Error.Println("unsupported --output value: use 'json'") | ||
| return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning nil here exits 0, which is a bit surprising for an invalid flag value (especially if this is used in scripts). Consider returning an error so the CLI exits non-zero.
| return nil | |
| if output != "" && output != "json" { | |
| return fmt.Errorf("unsupported --output value: use 'json'") | |
| } |
cmd/deploy.go
Outdated
| if status == string(kernel.DeploymentGetResponseStatusFailed) || | ||
| status == string(kernel.DeploymentGetResponseStatusStopped) || | ||
| status == string(kernel.DeploymentGetResponseStatusRunning) { | ||
| return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In JSONL mode this returns success even when the deployment fails/stops. It’d be nicer for automation if the exit code still reflected failure.
| return nil | |
| if status == string(kernel.DeploymentGetResponseStatusFailed) || | |
| status == string(kernel.DeploymentGetResponseStatusStopped) { | |
| return fmt.Errorf("deployment %s: %s", status, deploymentState.Deployment.StatusReason) | |
| } | |
| if status == string(kernel.DeploymentGetResponseStatusRunning) { | |
| return nil | |
| } |
| if resp.Status != kernel.InvocationNewResponseStatusQueued { | ||
| if jsonOutput { | ||
| bs, _ := json.Marshal(resp) | ||
| fmt.Println(string(bs)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: avoid ignoring json.Marshal errors here.
| fmt.Println(string(bs)) | |
| bs, err := json.Marshal(resp) | |
| if err != nil { | |
| return err | |
| } | |
| fmt.Println(string(bs)) |
- profiles get: output null instead of pterm error when profile not found - invoke: output JSON error object instead of human-readable text when API call fails in JSON mode Addresses cursor[bot] review feedback.
1. Fix replays download flag: read "output-file" instead of "output" 2. Return proper exit codes in JSON mode for failures: - deploy: return error on failed/stopped deployments - invoke: return error on failed invocations 3. Handle acquire timeout in JSON mode: - browser-pools acquire: output null instead of pterm warning - browsers create (with pool): output null instead of pterm error
cmd/app.go
Outdated
|
|
||
| if output != "" && output != "json" { | ||
| pterm.Error.Println("unsupported --output value: use 'json'") | ||
| return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we return an error and exit non-zero instead of just error logging? Might be more script-friendly.
|
Small gotcha in |
Sayan-
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice feature! Two small items flagged inline/in comments.
1. Return error (non-zero exit) for invalid --output value instead of just logging and returning nil - more script-friendly 2. Add "output" to allowedFlags in browsers create pool path so --output flag doesn't conflict with pool configuration
* docs: add --output json flag documentation for CLI commands Document JSON output support for CLI commands: - Add JSON Output section to main CLI reference page - Document --output json flag for deploy, invoke, app commands - Document --output json flag for browsers, browser-pools, profiles - Document --output json flag for extensions, proxies - Add browser-pools and profiles CLI sections Related to kernel/cli#67 * fix: address review feedback - Add cross-links to /browsers/pools and /browsers/profiles pages - Fix flag documentation: use `-o json` instead of just `-o` for consistency
|
|
||
| if output != "" && output != "json" { | ||
| return fmt.Errorf("unsupported --output value: use 'json'") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing output flag registration on deploy github subcommand
Medium Severity
The runDeployGithub handler reads the output flag on line 97, but this flag is not registered on deployGithubCmd. The flag is only registered on the parent deployCmd (line 60), and Cobra's regular Flags() are not inherited by subcommands. Users running kernel deploy github ... -o json will get an "unknown flag: -o" error instead of JSON output.
Summary
--output json(or-o json) flag to CLI commands for machine-readable outputdeploy,invoke), output is JSONL format (one JSON object per line)Commands with JSON output support:
Tier 1 (create/acquire operations):
browsers createbrowser-pools create,acquireprofiles createextensions uploadproxies createdeploy(JSONL streaming)Tier 2 (list/get operations):
browsers list,get,viewbrowser-pools list,get,updateprofiles list,getextensions listproxies list,getTier 3 (app/invoke/browser sub-operations):
app list,historydeploy historyinvoke(JSONL streaming),historybrowsers replays list,startbrowsers process exec,spawnbrowsers fs file-info,list-filesTest plan
kernel browsers create -o jsonreturns valid JSONkernel deploy index.ts -o jsonstreams JSONL eventskernel app list -o jsonreturns JSON array--outputvalue shows error messageNote
Adds machine-readable output across the CLI and documents it.
--output json/-o jsonfor many commands (apps, browsers, browser-pools, profiles, extensions, proxies), emitting raw JSON objects/arrays; suppresses interactive logs when JSON is selected and validates unsupported valuesdeployandinvokefollow operations, including terminal-state handling and JSON-formatted errors; updatesfollowDeployment/invocation streaming pathsbrowsers view/get/create, replays list/start, process exec/spawn, fs file-info/list-files; browser-pools create/get/update/acquire; app list/history; deploy history)browsers replays downloadswitches to-f/--output-fileWritten by Cursor Bugbot for commit 362c55a. This will update automatically on new commits. Configure here.