9b395f5cc3
Build Chrome Extension / build (push) Waiting to run
Trigger Website Rebuild (Docs Updated) / dispatch (push) Waiting to run
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
4.8 KiB
4.8 KiB
Architecture
OpenCLI is a command surface that sits on top of four major subsystems:
- command discovery and registry
- execution and formatting
- browser / daemon / CDP connectivity
- adapter, plugin, and external CLI integration
Runtime Shape
opencli CLI
├─ command discovery / registry
├─ execution / output
├─ browser runtime
│ ├─ Browser Bridge extension
│ ├─ local daemon
│ └─ direct CDP path
├─ adapter loading
│ ├─ built-in site adapters
│ ├─ generated adapters
│ └─ pipeline-backed adapters
├─ plugin loading
└─ external CLI passthrough
Core Modules
CLI Surface
src/main.ts— process entrypointsrc/cli.ts— top-level command tree and built-in command groupssrc/completion.ts/src/completion-fast.ts— shell completion
Discovery, Registry, Execution
src/discovery.ts— discovers built-in adapters, generated adapters, plugins, and manifestssrc/registry.ts— central command registrysrc/registry-api.ts— adapter-facing registration helperssrc/execution.ts— argument validation, lazy loading, and command executionsrc/commanderAdapter.ts— bridges registry metadata into Commander subcommandssrc/output.ts—table,json,yaml,md,csvformattingsrc/serialization.ts— registry and manifest serialization helpers
Browser and Runtime
src/runtime.ts— shared command runtime and target resolutionsrc/daemon.ts— lifecycle and bridge behavior for the local daemonsrc/doctor.ts— browser bridge diagnosticssrc/observation/— trace artifacts, redaction, and structured runtime evidencesrc/interceptor.ts— interception helpers for browser-backed strategiessrc/browser/— Browser Bridge connection and browser-side primitives
Pipeline Engine
src/pipeline/executor.ts— pipeline executionsrc/pipeline/template.ts— template expansionsrc/pipeline/transform.ts— transform helperssrc/pipeline/steps/— concrete steps such as:fetchdownloadbrowserintercepttaptransform
Adapter and Extension Surfaces
clis/— built-in site adapterssrc/plugin.ts/src/plugin-manifest.ts/src/plugin-scaffold.ts— plugin install, metadata, scaffoldsrc/external.ts/src/external-clis.yaml— external CLI passthrough and installable toolssrc/electron-apps.ts— desktop / Electron app support
Command Sources
OpenCLI merges commands from multiple places into one registry:
| Source | Location | Examples |
|---|---|---|
| Built-in adapters | clis/ |
twitter, bilibili, reddit, chatgpt-app |
| Generated / local adapters | ~/.opencli/clis/ |
user-authored adapters |
| Plugins | ~/.opencli/plugins/ |
community-contributed commands |
| External CLIs | src/external-clis.yaml + local registrations |
gh, docker, vercel |
The user sees one unified command tree through opencli list.
Connectivity Modes
Browser Bridge mode
Primary path for browser-backed commands:
opencli process
↔ local daemon
↔ Browser Bridge extension
↔ logged-in Chrome / Chromium
This path is used for:
- cookie-backed websites
- browser automation primitives
- interactive browser verification
Direct CDP mode
Used when OpenCLI talks directly to a Chrome or Electron debugging endpoint through OPENCLI_CDP_ENDPOINT.
Typical uses:
- remote Chrome
- headless Chrome
- Electron desktop adapters
Authentication / Access Strategies
OpenCLI currently uses these access strategies:
| Strategy | Purpose |
|---|---|
public |
direct fetch with no login |
cookie |
reuse browser session cookies |
intercept |
capture the app's own network responses |
ui |
DOM / accessibility driven interaction |
The key distinction is operational:
publicfavors direct network accesscookie,intercept,uidepend on a live browser or desktop surface
High-Risk Change Zones
Changes in these files usually affect broad command behavior:
src/cli.tssrc/commanderAdapter.tssrc/discovery.tssrc/execution.tssrc/runtime.tssrc/daemon.tssrc/plugin.tssrc/external.tssrc/pipeline/**
These areas deserve targeted tests first, then broader validation when the change crosses module boundaries.
Mental Model
The simplest accurate model is:
- OpenCLI discovers command definitions.
- It registers them into one command registry.
- It resolves each invocation through execution + runtime.
- It reaches the target through one of:
- network fetch
- Browser Bridge
- direct CDP
- external CLI passthrough
- It formats the result into a stable output surface.
That is the architecture to preserve when refactoring.