Files
jackwener__opencli/CONTRIBUTING.md
jakevin afa5e6046c refactor: consolidate 6 skills into 3, remove mechanical commands (#1094)
* refactor: consolidate 6 skills into 3, remove mechanical commands

Replaces opencli-oneshot / opencli-explorer / opencli-browser /
opencli-usage with a single opencli-adapter-author skill that takes
the AI agent end-to-end: site recon, API discovery, field decoding,
adapter coding, and `opencli browser verify`.

Removes the mechanical commands (`explore`, `synthesize`, `generate`,
`cascade`, `record`) and their src/tests — they were codegen scaffolding
meant for agents, which the new skill handles more flexibly via
`opencli browser` primitives.

Skill highlights:
- Top-level decision tree + 12-step runbook
- 5 site patterns (SPA / SSR / JSONP / Token / Streaming)
- 5-layer API discovery (network → initial state → bundle → token → interceptor)
- Field decode playbook (self-explanatory → codes → sort-key comparison)
- Output design guide (columns, types, order, ≤15 per adapter)
- Two-layer site memory: in-repo seeds for eastmoney/xueqiu/bilibili/tonghuashun
  plus local `~/.opencli/sites/<site>/` runtime workspace

Kept skills: opencli-autofix (now points to adapter-author for rewrites),
smart-search. Kept primitives: `browser *`, `doctor`, `list`, `validate`,
`verify`, `<site> <cmd>`, `plugin *`, `completion`.

No backward compatibility shims. Full test suite (1605 tests) passes.

* review fixes: honest coverage, hard memory-hit path, typo, stale docs

- site-memory hit path no longer jumps to writing adapter; forces Step 5
  endpoint re-verification + Step 7 field check, and 30-day expiry
- site-memory.md now specifies exact schemas for endpoints.json /
  field-map.json / notes.md / fixtures + write-back timing rules
- coverage-matrix.md marks unverified patterns as 🟡 with an evidence
  section citing coingecko dry run + PR #1091 eastmoney + bilibili
- eastmoney seed typo: resolveSecids -> resolveSecid (and splitSymbols)
- docs/developer/ai-workflow.md rewritten to teach the adapter-author
  skill + opencli browser * primitives (dropped generate/synthesize/
  cascade/explore references)
- ts-adapter.md, getting-started.md, CHANGELOG.md:87 updated to point
  at opencli-adapter-author

* fix(ci): resync package-lock + drop stale built-in list reference

- Regenerate package-lock.json to restore @emnapi/core + @emnapi/runtime
  entries that got dropped during the rebase — `npm ci` was failing on all
  CI jobs (build / audit / docs-build / bun-test / unit-test)
- docs/guide/getting-started.md: built-in list dropped `explore`, now
  reads (list, validate, verify, browser, doctor, plugin...)

* fix(ci): restore package-lock.json from main (unrelated lockfile churn)
2026-04-20 22:00:17 +08:00

5.9 KiB

Contributing to OpenCLI

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 test

# 5. Link globally (optional, for testing `opencli` command)
npm link

Adding a New Site Adapter

All adapters use TypeScript. Use the pipeline API for data-fetching commands, and func() for complex browser interactions.

Create a file like clis/<site>/<command>.js:

import { cli, Strategy } from '@jackwener/opencli/registry';

cli({
  site: 'mysite',
  name: 'trending',
  description: 'Trending posts on MySite',
  domain: 'www.mysite.com',
  strategy: Strategy.PUBLIC,
  browser: false,
  args: [
    { name: 'query', positional: true, required: true, help: 'Search keyword' },
    { name: 'limit', type: 'int', default: 20, help: 'Number of items' },
  ],
  columns: ['rank', 'title', 'score', 'url'],
  pipeline: [
    { fetch: { url: 'https://api.mysite.com/trending' } },
    { map: {
        rank: '${{ index + 1 }}',
        title: '${{ item.title }}',
        score: '${{ item.score }}',
        url: '${{ item.url }}',
    }},
    { limit: '${{ args.limit }}' },
  ],
});

See hackernews/top.js for a real example.

func() Adapter (For complex browser interactions)

Create a file like clis/<site>/<command>.js:

import { cli, Strategy } from '@jackwener/opencli/registry';

cli({
  site: 'mysite',
  name: 'search',
  description: 'Search MySite',
  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;
    await page.goto('https://www.mysite.com');

    const data = await page.evaluate(`
      (async () => {
        const res = await fetch('/api/search?q=${encodeURIComponent(query)}', {
          credentials: 'include'
        });
        return (await res.json()).results;
      })()
    `);

    return data.slice(0, Number(limit)).map((item: any) => ({
      title: item.title,
      url: item.url,
      date: item.created_at,
    }));
  },
});

Install the opencli-adapter-author skill if you need the full adapter workflow — recon → API discovery → field decoding → opencli browser verify.

Validate Your Adapter

# Validate adapter
opencli validate

# Test your command
opencli <site> <command> --limit 3 -f json

# Verbose mode for debugging
opencli <site> <command> -v

Arg Design Convention

Use positional for the primary, required argument of a command (the "what" — query, symbol, id, url, username). Use named options (--flag) for secondary/optional configuration (limit, format, sort, page, filters, language, date).

Rule of thumb: Think about how the user will type the command. opencli xueqiu stock SH600519 is more natural than opencli xueqiu stock --symbol SH600519.

Arg type Positional? Examples
Main target (query, symbol, id, url, username) positional: true search '茅台', stock SH600519, download BV1xxx
Configuration (limit, format, sort, page, type, filters) Named --flag --limit 10, --format json, --sort hot, --location seattle

Do not convert an argument to positional just because it appears first in the file. If the argument is optional, acts like a filter, or selects a mode/configuration, it should usually stay a named option.

Pipeline example:

args: [
  { name: 'query', positional: true, required: true, help: 'Search query' },  // ← primary arg
  { name: 'limit', type: 'int', default: 20, help: 'Max results' },           // ← config arg
]

TS example:

args: [
  { name: 'query', positional: true, required: true, help: 'Search query' },
  { name: 'limit', type: 'int', default: 10, help: 'Max results' },
]

Testing

See TESTING.md for the full guide and exact test locations.

npm test                      # Default local gate: unit + extension + adapter tests
npm run test:adapter          # Adapter-only project (useful while iterating on adapters)
npx vitest run tests/e2e/     # E2E tests
npx vitest run                # All tests

Code Style

  • TypeScript strict mode — avoid any where possible.
  • ES Modules — use .js extensions in imports (TypeScript output).
  • Naming: kebab-case for files, camelCase for variables/functions, PascalCase for types/classes.
  • No default exports — use named exports.

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

Common scopes: site name (twitter, reddit) or module name (browser, pipeline, engine).

Submitting a Pull Request

  1. Create a feature branch: git checkout -b feat/mysite-trending
  2. Make your changes and add tests when relevant
  3. Run the checks that apply:
    npx tsc --noEmit           # Type check
    npm test                   # Default local gate: unit + extension + adapter
    npm run test:adapter       # Adapter-only project (optional while iterating on adapters)
    opencli validate           # Adapter validation
    
  4. Commit using conventional commit format
  5. Push and open a PR

License

By contributing, you agree that your contributions will be licensed under the Apache-2.0 License.