Skip to content

Conversation

@rgarcia
Copy link
Contributor

@rgarcia rgarcia commented Jan 8, 2026

Summary

  • Add --output json (or -o json) flag to CLI commands for machine-readable output
  • For streaming commands (deploy, invoke), output is JSONL format (one JSON object per line)
  • For list commands, output is a JSON array
  • For single-object commands, output is a JSON object
  • Update README with JSON output documentation

Commands with JSON output support:

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

Test plan

  • Test kernel browsers create -o json returns valid JSON
  • Test kernel deploy index.ts -o json streams JSONL events
  • Test kernel app list -o json returns JSON array
  • Test invalid --output value shows error message

Note

Adds machine-readable output across the CLI and documents it.

  • Introduces --output json/-o json for many commands (apps, browsers, browser-pools, profiles, extensions, proxies), emitting raw JSON objects/arrays; suppresses interactive logs when JSON is selected and validates unsupported values
  • Implements JSONL streaming for deploy and invoke follow operations, including terminal-state handling and JSON-formatted errors; updates followDeployment/invocation streaming paths
  • Extends subcommands with new flags and JSON marshalling (e.g., browsers 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)
  • Minor flag tweak: browsers replays download switches to -f/--output-file
  • Updates README with JSON output examples and per-command support list

Written by Cursor Bugbot for commit 362c55a. This will update automatically on new commits. Configure here.

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
rgarcia added a commit to kernel/docs that referenced this pull request Jan 8, 2026
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
Copy link
Contributor

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.

Suggested change
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
Copy link
Contributor

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.

Suggested change
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))
Copy link
Contributor

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.

Suggested change
fmt.Println(string(bs))
bs, err := json.Marshal(resp)
if err != nil {
return err
}
fmt.Println(string(bs))

@rgarcia rgarcia requested a review from Sayan- January 8, 2026 23:50
- 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
Copy link
Contributor

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.

@Sayan-
Copy link
Contributor

Sayan- commented Jan 9, 2026

Small gotcha in cmd/browsers.go line 2177-2184: allowedFlags should include "output": true since it's not a browser config flag. Open to removing this check in favor of a simpler pattern if you have ideas.

Copy link
Contributor

@Sayan- Sayan- left a 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
rgarcia added a commit to kernel/docs that referenced this pull request Jan 9, 2026
* 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
@rgarcia rgarcia merged commit 251fba5 into main Jan 9, 2026
2 checks passed
@rgarcia rgarcia deleted the add-json-output-flag branch January 9, 2026 14:53

if output != "" && output != "json" {
return fmt.Errorf("unsupported --output value: use 'json'")
}
Copy link

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.

Additional Locations (1)

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants