Files
jackwener__opencli/docs/zh/guide/plugins.md
jakevin 70b1145b5e refactor: migrate all CLI adapters from YAML to TypeScript (#887)
* refactor: remove version field from GenerateOutcome and EarlyHint

All consumers are in the same repo and evolve together — version field
adds ceremony without practical value at this stage.

Keeps schema_version in VerifiedArtifactMetadata (sidecar file format).

* refactor: migrate all 123 CLI adapters from YAML to TypeScript

Remove YAML as an adapter format entirely. All adapters now use
TypeScript with cli() from @jackwener/opencli/registry.

- Convert 123 YAML adapter files to TypeScript via batch script
- Remove YAML scanning from discovery.ts (registerYamlCli, yaml import)
- Remove scanYaml() and shouldReplaceManifestEntry() from build-manifest.ts
- Change synthesize.ts to output JSON candidates (internal format)
- Change generate-verified.ts to write .ts adapter files instead of .yaml
- Delete yaml-schema.ts (dead code) and scripts/yaml-to-ts.mjs (one-time tool)
- Update all tests to match new format

Closes discussion in #OpenCLI thread 47ddba82.

* fix: close YAML migration gaps in plugin scaffold, validation, and scan

- plugin-scaffold.ts: generate hello.ts (TS pipeline) instead of hello.yaml
- plugin.ts validatePluginStructure: no longer accept .yaml as valid command file
- plugin.ts scanPluginCommands: remove .yaml/.yml from scanned extensions
- discovery.ts: add explicit log.warn() when YAML files detected in clis/ or plugins/
- plugin.test.ts: update all test fixtures from .yaml to .js
- plugin-scaffold.test.ts: update hello.yaml references to hello.ts
- Delete dead src/yaml-schema.ts

Resolves PR #887 review blockers from @mbp-codex-pr0.

* refactor: complete YAML removal across docs, skills, record, and binance adapters

Code changes:
- record.ts: candidate output changed from .yaml (yaml.dump) to .json (JSON.stringify), removed js-yaml import
- src/clis/binance: convert all 11 YAML adapters to TypeScript cli() format
- binance/commands.test.ts: rewrite to use registry instead of yaml.load
- skill-generate.test.ts, diagnostic.test.ts: update mock paths from .yaml to .ts
- build-manifest.ts, synthesize.ts: update stale YAML comments

Documentation:
- README.md: remove .yaml from Dynamic Loader, fix plugin types, fix synthesize comment
- README.zh-CN.md: fix synthesize comment
- CONTRIBUTING.md: replace YAML Adapter section with Pipeline Adapter (TS), update arg examples
- docs/developer/yaml-adapter.md: replaced with deprecation redirect
- docs/developer/architecture.md: remove YAML pipeline references
- docs/developer/contributing.md: remove YAML adapter section
- docs/developer/ai-workflow.md: YAML → TS in synthesize description
- docs/guide/getting-started.md: remove .yaml from loader, update engine description
- docs/guide/plugins.md: remove YAML plugin option, update plugin types
- docs/index.md, docs/comparison.md: remove YAML adapter references
- docs/zh/guide/plugins.md: remove .yaml from scan description

Skills:
- opencli-explorer/SKILL.md: rewrite YAML vs TS decision tree to TS-only
- opencli-oneshot/SKILL.md: replace YAML templates with TS cli() templates
- opencli-generate/SKILL.md: YAML artifact path → TS artifact path
- opencli-usage/SKILL.md, plugins.md: update adapter format references

* fix: clean up remaining YAML adapter references in docs

- docs/zh/guide/plugins.md: replace YAML plugin example with TS pipeline
- docs/developer/testing.md: YAML Adapter heading → Adapter, remove validate line
- TESTING.md: same fix in root testing doc
- CONTRIBUTING.md: remove "YAML validation" comment
- docs/.vitepress/config.mts: mark YAML Adapter Guide as (Deprecated) in nav
- docs/advanced/download.md: remove "YAML Adapters" from pipeline step heading
2026-04-08 23:01:08 +08:00

4.9 KiB
Raw Permalink Blame History

插件

OpenCLI 支持社区贡献的 plugins。你可以从 GitHub 安装第三方 adapters,它们会和内置 commands 一起在启动时自动发现。

安装插件

# 安装插件
opencli plugin install github:ByteYue/opencli-plugin-github-trending

# 列出已安装插件
opencli plugin list

# 更新单个插件
opencli plugin update github-trending

# 更新全部已安装插件
opencli plugin update --all

# 使用插件(本质上就是普通 command)
opencli github-trending today

# 卸载插件
opencli plugin uninstall github-trending

插件目录结构

Plugins 存放在 ~/.opencli/plugins/<name>/。每个子目录都会在启动时扫描 .ts、.js 命令文件,格式与内置 adapters 相同。

安装来源

opencli plugin install github:user/repo
opencli plugin install github:user/repo/subplugin   # 安装 monorepo 中的指定子插件
opencli plugin install https://github.com/user/repo

如果仓库名带 opencli-plugin- 前缀,本地目录会自动去掉这个前缀。例如 opencli-plugin-hot-digest 会变成 hot-digest。

插件清单 (opencli-plugin.json)

插件可以在仓库根目录放置 opencli-plugin.json 来声明元数据:

{
  "name": "my-plugin",
  "version": "1.0.0",
  "opencli": ">=1.0.0",
  "description": "我的插件"
}
字段 说明
name 插件名称(覆盖从仓库名推导的名称)
version 语义化版本
opencli 所需的 opencli 版本范围(如 >=1.0.0、^1.2.0)
description 描述
plugins Monorepo 子插件声明(见下文)

清单文件是可选的——没有它的插件依然可以正常工作。

Monorepo 插件

一个仓库可以通过在 opencli-plugin.json 中声明 plugins 字段来包含多个插件:

{
  "version": "1.0.0",
  "opencli": ">=1.0.0",
  "description": "我的插件合集",
  "plugins": {
    "polymarket": {
      "path": "packages/polymarket",
      "description": "预测市场分析",
      "version": "1.2.0"
    },
    "defi": {
      "path": "packages/defi",
      "description": "DeFi 协议数据",
      "version": "0.8.0"
    },
    "experimental": {
      "path": "packages/experimental",
      "disabled": true
    }
  }
}
# 安装 monorepo 中的全部子插件
opencli plugin install github:user/opencli-plugins

# 安装指定子插件
opencli plugin install github:user/opencli-plugins/polymarket
  • Monorepo 只 clone 一次到 ~/.opencli/monorepos/<repo>/
  • 每个子插件通过 symlink 出现在 ~/.opencli/plugins/<name>/
  • 更新任何子插件会拉取整个 monorepo 并刷新所有子插件
  • 卸载最后一个子插件时,monorepo 目录会被自动清理

版本追踪

OpenCLI 会把已安装 plugin 的版本记录到 ~/.opencli/plugins.lock.json。每条记录会保存 plugin source、当前 git commit hash、安装时间,以及最近一次更新时间。只要有这份元数据,opencli plugin list 就会显示对应的短 commit hash。

Pipeline plugin 示例

my-plugin/
  package.json
  hot.ts

hot.ts:

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

cli({
  site: 'my-plugin',
  name: 'hot',
  description: 'Example plugin command',
  strategy: Strategy.PUBLIC,
  browser: false,
  columns: ['title', 'url'],
  pipeline: [
    { evaluate: `() => [{ title: 'hello', url: 'https://example.com' }]` },
  ],
});

func() plugin 示例

my-plugin/
  index.ts
  package.json
{
  "name": "opencli-plugin-my-plugin",
  "type": "module"
}
import { cli, Strategy } from '@jackwener/opencli/registry';

cli({
  site: 'my-plugin',
  name: 'hot',
  description: 'Example TS plugin command',
  strategy: Strategy.PUBLIC,
  browser: false,
  columns: ['title', 'url'],
  func: async () => [{ title: 'hello', url: 'https://example.com' }],
});

运行 opencli plugin install 时,TS plugins 会自动完成基础设置:

  1. 安装 plugin 自身依赖
  2. 补齐 TypeScript 运行环境
  3. 将宿主 @jackwener/opencli 链接到 plugin 的 node_modules/,保证 @jackwener/opencli/registry 指向当前宿主版本

示例 plugins

  • opencli-plugin-github-trending:GitHub Trending 仓库
  • opencli-plugin-hot-digest:多平台热点聚合(zhihu、weibo、bilibili、v2ex、stackoverflow、reddit、linux-do)
  • opencli-plugin-juejin:稀土掘金热榜、分类和文章流
  • opencli-plugin-rubysec:RubySec 漏洞归档与单篇漏洞文章读取

排查问题

TS plugin import 报错

如果看到 Cannot find module '@jackwener/opencli/registry',通常是宿主 symlink 失效。重新安装 plugin 即可:

opencli plugin uninstall my-plugin
opencli plugin install github:user/opencli-plugin-my-plugin

安装或卸载 plugin 后,建议重新打开一个终端,确保启动时重新发现命令。