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.0 KiB
4.0 KiB
Contributing
Thanks for your interest in contributing to OpenCLI.
Quick Start
# 1. Fork & clone
git clone git@github.com:<your-username>/opencli.git
cd opencli
# 2. Install dependencies
npm install
# 3. Build
npm run build
# 4. Run a few checks
npx tsc --noEmit
npm run build
# 5. Link globally (optional, for testing `opencli` command)
npm link
Adding a New Site Adapter
This is the most common type of contribution. All adapters use TypeScript with the cli() API.
Before you start:
- Prefer positional args for the command's primary subject (
search <query>,topic <id>,download <url>). Reserve named flags for optional modifiers such as--limit,--sort,--lang, and--output. - Normalize expected adapter failures to
CliErrorsubclasses instead of rawErrorwhenever possible. PreferAuthRequiredError,EmptyResultError,CommandExecutionError,TimeoutError, andArgumentErrorso the top-level CLI can render better messages and hints. - If you add a new adapter or make a command newly discoverable, update the matching doc page and the user-facing indexes that expose it.
Create the Adapter
Built-in adapters are authored in JavaScript. Create a file like clis/<site>/<command>.js:
import { cli, Strategy } from '@jackwener/opencli/registry';
import { CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
cli({
site: 'mysite',
name: 'search',
description: 'Search MySite',
access: 'read', // 'read' | 'write'
example: 'opencli mysite search <query> -f yaml',
domain: 'www.mysite.com',
strategy: Strategy.COOKIE,
args: [
{ name: 'query', positional: true, required: true, help: 'Search query' },
{ name: 'limit', type: 'int', default: 10, help: 'Max results' },
],
columns: ['title', 'url', 'date'],
func: async (page, kwargs) => {
const { query, limit = 10 } = kwargs;
// ... browser automation logic
if (!Array.isArray(data)) throw new CommandExecutionError('MySite returned an unexpected response');
if (!data.length) throw new EmptyResultError('mysite search', 'Try a different keyword');
return data.slice(0, Number(limit)).map((item) => ({
title: item.title,
url: item.url,
date: item.created_at,
}));
},
});
TypeScript adapters are also supported — see TypeScript Adapter.
Validate Your Adapter
opencli <site> <command> --limit 3 -f json # Test your command
opencli <site> <command> -v # Verbose mode for debugging
Code Style
- TypeScript strict mode — avoid
anywhere possible. - ES Modules — use
.jsextensions in imports (TypeScript output). - Naming:
kebab-casefor files,camelCasefor variables/functions,PascalCasefor types/classes. - No default exports — use named exports.
- Errors — throw
CliErrorsubclasses for expected adapter failures; avoid rawErrorfor normal adapter control flow.
Commit Convention
We use Conventional Commits:
feat(twitter): add thread command
fix(browser): handle CDP timeout gracefully
docs: update CONTRIBUTING.md
test(reddit): add e2e test for save command
chore: bump vitest to v4
Submitting a Pull Request
- Create a feature branch:
git checkout -b feat/mysite-trending - Make your changes and add tests when relevant
- Run the smallest check set that matches your change:
npx tsc --noEmit # Type check npm run build # Ensure dist stays healthy npx vitest run clis/<site>/<command>.test.js # Your adapter's tests npm test # Broader local gate when shared runtime changes justify it - Commit using conventional commit format
- Push and open a PR
If your PR adds a new adapter or changes user-facing commands, also verify:
- Adapter docs exist under
docs/adapters/ docs/adapters/index.mdis updated for new adapters- VitePress sidebar includes the new doc page
README.md/README.zh-CN.mdstay aligned when command discoverability changes