Skip to content

feat: add command-level CDP overrides / 增加命令级 CDP 覆盖#406

Closed
coolxll wants to merge 1 commit intojackwener:mainfrom
coolxll:fix/windows-mcp-and-cdp-targeting
Closed

feat: add command-level CDP overrides / 增加命令级 CDP 覆盖#406
coolxll wants to merge 1 commit intojackwener:mainfrom
coolxll:fix/windows-mcp-and-cdp-targeting

Conversation

@coolxll
Copy link
Copy Markdown

@coolxll coolxll commented Mar 25, 2026

Summary / 摘要

This PR adds command-level CDP overrides so browser-backed commands can target different Chrome/Electron sessions without mutating global shell state.

这个 PR 为浏览器相关命令增加了命令级 CDP 覆盖参数,使不同的 Chrome / Electron 会话可以按命令单独指定,而不需要反复切换全局环境变量。

Why / 背景与原因

Today opencli mainly relies on global environment variables such as OPENCLI_CDP_ENDPOINT and OPENCLI_CDP_TARGET.
That works for single-app usage, but it becomes awkward when switching between multiple Electron apps, multiple Chrome instances, or multiple debugging ports.

目前 opencli 主要依赖全局环境变量,例如 OPENCLI_CDP_ENDPOINTOPENCLI_CDP_TARGET
这种方式在单应用场景下可用,但一旦需要在多个 Electron 应用、多个 Chrome 实例、或者多个调试端口之间切换,就会很不方便。

Typical problems:

  • only one active target can be selected through global state
  • switching apps requires editing shell state repeatedly
  • wrappers become necessary for otherwise simple workflows
  • long-running commands such as antigravity serve are harder to route cleanly

典型问题包括:

  • 只能通过全局状态选择一个当前目标
  • 切换应用需要频繁修改 shell 环境
  • 原本简单的工作流不得不额外包一层脚本
  • 类似 antigravity serve 这种长运行命令也不容易干净地指定目标

Changes / 修改内容

  • add --cdp-endpoint and --cdp-target to browser-backed dynamic commands

  • add the same command-level overrides to built-in browser commands such as explore, generate, record, and cascade

  • add command-level overrides to opencli antigravity serve

  • add runtime helpers to apply and restore CDP env overrides safely during command execution

  • update Antigravity docs and skill docs to document per-command usage

  • add unit tests for runtime override behavior and Commander integration

  • 为浏览器相关的动态命令增加 --cdp-endpoint--cdp-target

  • exploregeneraterecordcascade 等内建浏览器命令增加同样的命令级覆盖能力

  • opencli antigravity serve 增加命令级覆盖能力

  • 增加运行时 helper,在命令执行期间安全地设置并恢复 CDP 环境变量

  • 更新 Antigravity 文档与技能说明,补充按命令传参的用法

  • 增加对应单元测试,覆盖运行时覆盖逻辑和 Commander 接入行为

Example / 示例

opencli antigravity status --cdp-endpoint http://127.0.0.1:9333 --cdp-target Launchpad
opencli antigravity serve --port 8082 --cdp-endpoint http://127.0.0.1:9333 --cdp-target antigravity

This makes multi-app workflows much easier without breaking existing env-based usage.

这样可以在不破坏现有环境变量用法的前提下,显著改善多应用场景下的使用体验。

Verification / 验证

  • npm test
  • npm run typecheck

@Astro-Han
Copy link
Copy Markdown
Contributor

Useful feature — per-command CDP overrides solve a real pain point for multi-app workflows. One major concern plus a few smaller items:

Critical

Conflicts with your PR #408

Both PRs define the same exports (BrowserEnvOverrides, withBrowserEnvOverrides, extractBrowserEnvOverrides) with different signatures and modify the same files (cli.ts, runtime.ts, commanderAdapter.ts). They cannot be merged independently — whichever lands second will have type conflicts and likely lose the other's semantics during rebase.

Suggestion: consolidate both PRs into one, with a unified BrowserEnvOverrides type covering cdpEndpoint, cdpTarget, and browserCdp together. The precedence should be: explicit --cdp-endpoint > --browser-cdp auto-discovery > env var default.

Warnings

runtime.test.ts leaks env varsvi.stubEnv('OPENCLI_CDP_ENDPOINT', ...) is called without afterEach(() => vi.unstubAllEnvs()). This can cause flaky test failures in other suites that depend on these env vars.

No URL validation on --cdp-endpoint — invalid values like foobar are passed directly to the CDP connection layer, producing unfriendly errors. A basic scheme check (http:///ws://) with a clear error message would help.

Option registration repeated 5 times — identical .option('--cdp-endpoint') + .option('--cdp-target') + withBrowserEnvOverrides wrapping in explore, generate, record, cascade, and antigravity serve. Should be extracted into a shared helper (same issue noted in #408).

Non-browser commands also wrappedcommanderAdapter.ts unconditionally calls withBrowserEnvOverrides for all commands. A short-circuit for browser: false commands would avoid the unnecessary async wrapper.

@coolxll
Copy link
Copy Markdown
Author

coolxll commented Mar 26, 2026

Superseded by #408. I consolidated the command-level CDP override work into the PR #408 branch so the two changes no longer conflict.

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.

2 participants