cli: add custom chrome policy flags to browser and pool commands#180
Conversation
Add --chrome-policy / --chrome-policy-file to `browsers create`,
`browser-pools create`, and `browser-pools update`, wiring the API's
chrome_policy field (already supported by the Go SDK) through the CLI.
The two flags are mutually exclusive; --chrome-policy takes an inline
JSON object and --chrome-policy-file reads one from a path ("-" = stdin),
matching the existing --payload/--payload-file convention. A shared
parseChromePolicy helper validates the input is a JSON object. Blocked
kernel-managed policies are enforced server-side, so the CLI forwards
verbatim and surfaces the API error rather than duplicating the rules.
An explicit empty object is dropped from the request (chrome_policy uses
omitzero, which only drops a nil map, so assignment is guarded by len>0);
on pool update an empty object cannot clear an existing policy, which is
surfaced with a warning in human output.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Whitespace policy triggers false update warning
- The warning now only appears for an explicit empty JSON object by checking for a non-nil parsed policy map, and a regression test confirms whitespace-only input stays quiet.
Or push these changes by commenting:
@cursor push 901ffb4d16
You can send follow-ups to the cloud agent here.
Reviewed by Cursor Bugbot for commit 6a470a3. Configure here.
| // An empty policy ({}) cannot clear an existing one: omitzero drops it before it | ||
| // reaches the server. Warn instead of silently doing nothing, but stay quiet on the | ||
| // json path so stdout remains valid JSON. | ||
| pterm.Warning.Println("An empty chrome policy is ignored and does not clear the pool's existing policy; recreate the pool to remove a policy.") |
There was a problem hiding this comment.
Whitespace policy triggers false update warning
Low Severity
On browser-pools update, the empty-policy warning keys off whether --chrome-policy or --chrome-policy-file was provided, not whether parsing produced an explicit {} object. Whitespace-only inline values, an empty policy file, or stdin with only blanks return nil from parseChromePolicy but still print that an empty policy will not clear the pool.
Reviewed by Cursor Bugbot for commit 6a470a3. Configure here.



Summary
Adds CLI support for setting a custom Chrome enterprise policy (the API's
chrome_policyfield, already supported by the Go SDK) on three commands:kernel browsers createkernel browser-pools createkernel browser-pools updateEach gains two mutually-exclusive flags:
--chrome-policy '<json>'— an inline JSON object--chrome-policy-file <path>— read the object from a file (-reads stdin)This mirrors the existing
--payload/--payload-fileand--data/--data-fileconventions.Design notes
parseChromePolicyhelper parses intomap[string]any, so non-object JSON (arrays, scalars,null) is rejected with a clear error before any request is sent.chrome_policyusesomitzero, which only drops a nil map — a non-nil empty{}would serialize as"chrome_policy":{}. Assignment is therefore guarded bylen > 0, so an empty object is treated as "unset".browser-pools update, an empty{}cannot clear an existing policy (omitzero strips it before it reaches the server). Rather than silently no-op, this surfaces a warning in human output (suppressed under-o jsonto keep stdout valid).Scope
browsers updateandinvokeare intentionally excluded: their SDK params structs (BrowserUpdateParams,InvocationNewParams) carry nochrome_policyfield, so there's nothing to wire until the SDK is regenerated.--output jsonwith no printer changes (response structs already carry the field).Test plan
{}omitted (asserted at both the Go field and the serialized JSON), invalid JSON /nullrejected, parser covers file + stdin + whitespace + missing-file, and the pool-lease conflict contract is locked (--chrome-policystays out of the allowed-flag set).make test(go vet + go test ./...) passes; gofmt clean.{}no-ops without clearing; invalid/null/mutual-exclusion exit non-zero before any API call; and the server correctly rejectsProxyMode/ExtensionInstallForcelistwith the CLI surfacing the error.Note (pre-existing, unrelated)
When a browser-config flag is combined with
--pool-id/--pool-name, the existing conflict-confirmation prompt (pterm.DefaultInteractiveConfirm) does not treat EOF / non-TTY stdin as "no", so it blocks in a non-interactive pipeline. This predates this change and affects all config flags equally; flagging it as a possible follow-up.🤖 Generated with Claude Code
Note
Low Risk
CLI-only feature forwarding JSON to existing API fields; validation is local and server enforces blocked policies. No auth or data-path changes.
Overview
Adds
--chrome-policyand--chrome-policy-file(mutually exclusive,-for stdin) tokernel browsers createandkernel browser-pools create/update, wiring the API’schrome_policyfield through a sharedparseChromePolicyhelper.Policies are only sent when the parsed object is non-empty (
len > 0), so{}is not serialized on create. On pool update, passing{}does not clear an existing policy; the CLI warns in human output and stays silent with-o json.poolLeaseAllowedFlagsis extracted so--chrome-policyis not treated as allowed alongside--pool-id/--pool-name, surfacing the existing pool-lease conflict warning instead of ignoring the flag.README documents flags, examples, and the pool-update clearing limitation. Unit tests cover parsing, SDK params, JSON omission, warnings, and pool-lease behavior.
Reviewed by Cursor Bugbot for commit 6a470a3. Bugbot is set up for automated code reviews on this repo. Configure here.