feat: Support plugin system in opencli#191
Open
ByteYue wants to merge 6 commits intojackwener:mainfrom
Open
Conversation
- Stage 0: discoverPlugins() scans ~/.opencli/plugins/ at startup - Stage 1: demo plugin repos (github-trending, hot-digest) - Stage 2: opencli plugin install/uninstall/list commands - package.json exports ./registry for TS plugin peerDep support - 17 new/updated tests, tsc --noEmit clean
opts.timeout is passed in seconds from runtime.ts but CDPBridge was using it as milliseconds, causing instant timeout (30ms).
- Add src/registry-api.ts: re-exports core registration API (cli, Strategy, getRegistry) without transitive side-effects, safe for plugin imports - Update package.json exports: './registry' -> './dist/registry-api.js' - Update src/registry.ts: use globalThis shared registry to ensure single instance across npm-linked plugin modules - Update .gitignore for plugin-related artifacts
After npm install, replace the npm-installed @jackwener/opencli with a symlink to the running host's package root. This ensures TS plugins always resolve '@jackwener/opencli/registry' against the host installation, avoiding version mismatches when the published npm package lags behind.
Contributor
|
Nice! Plugin system is a natural next step for opencli — and the execution here is solid:
One heads-up: this PR builds on Exciting to see this taking shape! |
…very - installPlugin: after symlinking host opencli, transpile any .ts files to .js using esbuild from the host's node_modules/.bin/ - discoverPluginDir: skip .ts files when a .js sibling exists (production node cannot load .ts directly) - scanPluginCommands: deduplicate basenames via Set to avoid showing 'aggregate, aggregate' when both .ts and .js exist
- New docs/guide/plugins.md covering: - Installation/uninstallation commands - Creating YAML plugins (zero-dep) - Creating TS plugins (with peerDep) - TS plugin install lifecycle (clone → deps → symlink → transpile) - Example plugins and troubleshooting - Add Plugins to VitePress sidebar (EN + ZH) - Link from getting-started.md Next Steps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add a plugin system to opencli, enabling community-contributed adapters.
Users can now install third-party plugins from GitHub repos, and the plugins are automatically discovered at startup alongside built-in commands.
This PR implements the first 3 stages of the plugin roadmap:
~/.opencli/plugins/)opencli plugin install/uninstall/listcommand groupAlso fixes a pre-existing CDPBridge bug discovered during testing.
Type of Change
Checklist
What's New
Plugin Management Commands
Plugin Layout Convention
YAML plugin (zero-dependency, no build step):
TS plugin (with peerDep):
Demo Plugin Repos
TS Plugin Lifecycle
TS plugins are automatically handled during
opencli plugin install:git clone --depth 1from GitHubnpm install --productionfor regular dependencies@jackwener/opencliinto plugin'snode_modules/(ensuresimport from '@jackwener/opencli/registry'resolves against the running host, not a stale npm-published version)esbuildto compile.ts→.js(productionnodecannot load.tsdirectly).jsfiles are preferred over.tssiblings to avoid duplicate registrationScreenshots / Output
Install
List
Plugin automatically appears in
opencli list:Plugin Execution — Table Output
Plugin Execution — JSON Output
Hot-Digest Plugin — Multi-Source Aggregate
Uninstall
Changes
src/discovery.tsdiscoverPlugins()scans~/.opencli/plugins/; prefers.jsover.tssiblingsrc/main.tsdiscoverPlugins()after built-in discoverysrc/plugin.tssrc/registry-api.tspeerDependenciessrc/plugin.test.tssrc/cli.tsopencli plugin install/uninstall/listcommandssrc/engine.test.tsdiscoverPluginsunit testspackage.jsonexportsfield for./registry(TS plugin peerDep support)src/registry.tsglobalThisshared registry for cross-module-instance safetysrc/browser/cdp.tsdocs/guide/plugins.mdTest Results