Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
chore: prune legacy config switches
  • Loading branch information
jackwener committed Apr 13, 2026
commit 8a1a43f6ebf87aa8a447eb111a5d79cca0917376
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,8 @@ jobs:
run: |
xvfb-run --auto-servernum --server-args="-screen 0 1280x720x24" \
npx vitest run tests/smoke/ --reporter=verbose
env:
OPENCLI_BROWSER_EXECUTABLE_PATH: ${{ steps.setup-chrome.outputs.chrome-path }}

- name: Run smoke tests (macOS / Windows)
if: runner.os != 'Linux'
run: npx vitest run tests/smoke/ --reporter=verbose
env:
OPENCLI_BROWSER_EXECUTABLE_PATH: ${{ steps.setup-chrome.outputs.chrome-path }}
timeout-minutes: 15
4 changes: 0 additions & 4 deletions .github/workflows/e2e-headed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ jobs:
run: |
xvfb-run --auto-servernum --server-args="-screen 0 1280x720x24" \
npx vitest run tests/e2e/ --reporter=verbose
env:
OPENCLI_BROWSER_EXECUTABLE_PATH: ${{ steps.setup-chrome.outputs.chrome-path }}

- name: Run E2E tests (macOS / Windows)
if: runner.os != 'Linux'
run: npx vitest run tests/e2e/ --reporter=verbose
env:
OPENCLI_BROWSER_EXECUTABLE_PATH: ${{ steps.setup-chrome.outputs.chrome-path }}
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ OpenCLI is not only for websites. It can also:
| `OPENCLI_CDP_TARGET` | — | Filter CDP targets by URL substring (e.g. `detail.1688.com`) |
| `OPENCLI_VERBOSE` | `false` | Enable verbose logging (`-v` flag also works) |
| `OPENCLI_DIAGNOSTIC` | `false` | Set to `1` to capture structured diagnostic context on failures |
| `OUTPUT` | — | Override output format: `json`, `yaml`, or `table` |
| `DEBUG` | — | Set to `opencli` for internal debug logging |
| `DEBUG_SNAPSHOT` | — | Set to `1` for DOM snapshot debug output |

## Update
Expand Down
2 changes: 0 additions & 2 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ OpenCLI 不只是网站 CLI,还可以:
| `OPENCLI_CDP_TARGET` | — | 按 URL 子串过滤 CDP target(如 `detail.1688.com`) |
| `OPENCLI_VERBOSE` | `false` | 启用详细日志(`-v` 也可以) |
| `OPENCLI_DIAGNOSTIC` | `false` | 设为 `1` 时在失败时输出结构化诊断上下文 |
| `OUTPUT` | — | 覆盖输出格式:`json`、`yaml` 或 `table` |
| `DEBUG` | — | 设为 `opencli` 开启内部调试日志 |
| `DEBUG_SNAPSHOT` | — | 设为 `1` 输出 DOM 快照调试信息 |

## 更新
Expand Down
9 changes: 2 additions & 7 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ it('producthunt me fails gracefully without login', async () => {
|---|---|---|
| `e2e-headed` | push/PR 到 `main`,`dev`,或手动触发 | 安装真实 Chrome,`xvfb-run` 执行 `tests/e2e/` |

E2E 与 smoke 都使用 `./.github/actions/setup-chrome` 准备真实 Chrome,并通过 `OPENCLI_BROWSER_EXECUTABLE_PATH` 注入浏览器路径
E2E 与 smoke 都使用 `./.github/actions/setup-chrome` 准备真实 Chrome。

### Sharding

Expand All @@ -233,12 +233,7 @@ opencli 通过 Browser Bridge 扩展连接浏览器:
| 扩展已安装 / 已连接 | Extension 模式 | 本地用户,连接已登录的 Chrome |
| 无扩展 token | CLI 自行拉起浏览器 | CI、无登录态或纯自动化场景 |

CI 中使用 `OPENCLI_BROWSER_EXECUTABLE_PATH` 指定真实 Chrome 路径:

```yaml
env:
OPENCLI_BROWSER_EXECUTABLE_PATH: ${{ steps.setup-chrome.outputs.chrome-path }}
```
CI 通过 `./.github/actions/setup-chrome` 准备真实 Chrome,再直接执行测试。

---

Expand Down
5 changes: 2 additions & 3 deletions clis/boss/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,10 @@ export async function typeAndSendMessage(page, text) {
return true;
}
/**
* Verbose log helper — prints when OPENCLI_VERBOSE is set, with DEBUG=opencli
* kept as a compatibility fallback.
* Verbose log helper — prints when OPENCLI_VERBOSE is set.
*/
export function verbose(msg) {
if (process.env.OPENCLI_VERBOSE || process.env.DEBUG?.includes('opencli')) {
if (process.env.OPENCLI_VERBOSE) {
console.error(`[opencli:boss] ${msg}`);
}
}
8 changes: 0 additions & 8 deletions docs/advanced/remote-chrome.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,3 @@ steps:
--remote-debugging-port=9222 &
```
:::

Set the browser executable path:
::: v-pre
```yaml
env:
OPENCLI_BROWSER_EXECUTABLE_PATH: ${{ steps.setup-chrome.outputs.chrome-path }}
```
:::
11 changes: 2 additions & 9 deletions docs/developer/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ it('producthunt me fails gracefully without login', async () => {
|---|---|---|
| `e2e-headed` | push/PR 到 `main`,`dev`,或手动触发 | 安装真实 Chrome,`xvfb-run` 执行 `tests/e2e/` |

E2E 与 smoke 都使用 `./.github/actions/setup-chrome` 准备真实 Chrome,并通过 `OPENCLI_BROWSER_EXECUTABLE_PATH` 注入浏览器路径
E2E 与 smoke 都使用 `./.github/actions/setup-chrome` 准备真实 Chrome。

### Sharding

Expand All @@ -236,14 +236,7 @@ opencli 通过 Browser Bridge 扩展连接浏览器:
| 扩展已安装 / 已连接 | Extension 模式 | 本地用户,连接已登录的 Chrome |
| 无扩展 token | CLI 自行拉起浏览器 | CI、无登录态或纯自动化场景 |

CI 中使用 `OPENCLI_BROWSER_EXECUTABLE_PATH` 指定真实 Chrome 路径:

::: v-pre
```yaml
env:
OPENCLI_BROWSER_EXECUTABLE_PATH: ${{ steps.setup-chrome.outputs.chrome-path }}
```
:::
CI 通过 `./.github/actions/setup-chrome` 准备真实 Chrome,再直接执行测试。

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
In `src/constants.ts`, add after the `DEFAULT_DAEMON_PORT` line:

```typescript
/** Default idle timeout before daemon auto-exits (ms). Override via OPENCLI_DAEMON_TIMEOUT env var. */
/** Default idle timeout before daemon auto-exits (ms). */
export const DEFAULT_DAEMON_IDLE_TIMEOUT = 4 * 60 * 60 * 1000; // 4 hours
```

Expand Down Expand Up @@ -174,7 +174,7 @@ Replace the `IDLE_TIMEOUT` constant (line 27):
import { DEFAULT_DAEMON_PORT, DEFAULT_DAEMON_IDLE_TIMEOUT } from './constants.js';

const PORT = parseInt(process.env.OPENCLI_DAEMON_PORT ?? String(DEFAULT_DAEMON_PORT), 10);
const IDLE_TIMEOUT = Number(process.env.OPENCLI_DAEMON_TIMEOUT ?? DEFAULT_DAEMON_IDLE_TIMEOUT);
const IDLE_TIMEOUT = DEFAULT_DAEMON_IDLE_TIMEOUT;
```

Replace the idle timer state and `resetIdleTimer` function (lines 37, 49-57) with the `IdleManager` class:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ If either signal is active, the daemon stays alive. This means:
- Recent CLI activity keeps the daemon alive even if Extension temporarily
disconnects (Chrome restarting, Extension updating)

**Timeout value:** 4 hours by default, configurable via `OPENCLI_DAEMON_TIMEOUT`
environment variable. Value in milliseconds. Set to `0` to disable timeout entirely.
**Timeout value:** 4 hours by default.

```typescript
const DEFAULT_IDLE_TIMEOUT = 4 * 60 * 60 * 1000; // 4 hours
const IDLE_TIMEOUT = Number(process.env.OPENCLI_DAEMON_TIMEOUT ?? DEFAULT_IDLE_TIMEOUT);
const IDLE_TIMEOUT = DEFAULT_IDLE_TIMEOUT;
```

**Timer implementation:**
Expand Down
6 changes: 3 additions & 3 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { styleText } from 'node:util';

function isVerbose(): boolean {
return !!process.env.OPENCLI_VERBOSE || !!process.env.DEBUG?.includes('opencli');
return !!process.env.OPENCLI_VERBOSE;
}

export const log = {
Expand Down Expand Up @@ -37,14 +37,14 @@ export const log = {
process.stderr.write(`${styleText('red', '✖')} ${msg}\n`);
},

/** Verbose output (shown when -v flag, OPENCLI_VERBOSE, or DEBUG=opencli is set) */
/** Verbose output (shown when -v flag or OPENCLI_VERBOSE is set) */
verbose(msg: string): void {
if (isVerbose()) {
process.stderr.write(`${styleText('dim', '[verbose]')} ${msg}\n`);
}
},

/** @deprecated Use log.verbose() instead. Kept as alias for backward compatibility. */
/** Alias for verbose output. */
debug(msg: string): void {
this.verbose(msg);
},
Expand Down
21 changes: 0 additions & 21 deletions src/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { render } from './output.js';

describe('output TTY detection', () => {
const originalIsTTY = process.stdout.isTTY;
const originalEnv = process.env.OUTPUT;
let logSpy: ReturnType<typeof vi.spyOn>;

beforeEach(() => {
Expand All @@ -12,8 +11,6 @@ describe('output TTY detection', () => {

afterEach(() => {
Object.defineProperty(process.stdout, 'isTTY', { value: originalIsTTY, writable: true });
if (originalEnv === undefined) delete process.env.OUTPUT;
else process.env.OUTPUT = originalEnv;
logSpy.mockRestore();
});

Expand All @@ -40,24 +37,6 @@ describe('output TTY detection', () => {
expect(JSON.parse(out)).toEqual([{ name: 'alice' }]);
});

it('OUTPUT env var overrides default table in non-TTY', () => {
Object.defineProperty(process.stdout, 'isTTY', { value: false, writable: true });
process.env.OUTPUT = 'json';
render([{ name: 'alice' }], { fmt: 'table' });
const out = logSpy.mock.calls.map((c: unknown[]) => c[0]).join('\n');
expect(JSON.parse(out)).toEqual([{ name: 'alice' }]);
});

it('explicit -f flag takes precedence over OUTPUT env var', () => {
Object.defineProperty(process.stdout, 'isTTY', { value: false, writable: true });
process.env.OUTPUT = 'json';
render([{ name: 'alice' }], { fmt: 'csv', fmtExplicit: true });
const out = logSpy.mock.calls.map((c: unknown[]) => c[0]).join('\n');
expect(out).toContain('name');
expect(out).toContain('alice');
expect(out).not.toContain('"name"'); // not JSON
});

it('explicit -f table overrides non-TTY auto-downgrade', () => {
Object.defineProperty(process.stdout, 'isTTY', { value: false, writable: true });
render([{ name: 'alice' }], { fmt: 'table', fmtExplicit: true, columns: ['name'] });
Expand Down
5 changes: 1 addition & 4 deletions src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ function resolveColumns(rows: Record<string, unknown>[], opts: RenderOptions): s
export function render(data: unknown, opts: RenderOptions = {}): void {
let fmt = opts.fmt ?? 'table';
// Non-TTY auto-downgrade only when format was NOT explicitly passed by user.
// Priority: explicit -f (any value) > OUTPUT env var > TTY auto-detect > table
if (!opts.fmtExplicit) {
const envFmt = process.env.OUTPUT?.trim().toLowerCase();
if (envFmt) fmt = envFmt;
else if (fmt === 'table' && !process.stdout.isTTY) fmt = 'yaml';
if (fmt === 'table' && !process.stdout.isTTY) fmt = 'yaml';
}
if (data === null || data === undefined) {
console.log(data);
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/browser-public.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* E2E tests for core browser commands (bilibili, zhihu, v2ex, IMDb).
* These use OPENCLI_HEADLESS=1 to launch a headless Chromium.
* These launch a headless Chromium in CI.
*
* NOTE: Some sites may block headless browsers with bot detection.
* Tests are wrapped with tryBrowserCommand() which allows graceful failure.
Expand Down
Loading