refactor(rr): decouple CLI into actions, services, and a plugin facade#235
Merged
Conversation
Command bodies become free-function actions (src/actions/*) taking a single <Name>ActionConfig object; commands are thin wrappers that resolve their service via the ctx.plugins facade (throwing MissingPluginError when no configured plugin provides the capability) and delegate to exactly one action. Actions depend only on services/render/lib, never on the CLI framework. Plugin contract & SDK: - Rename the contract vocabulary: PluginKind -> PluginCapability, the capabilities map type -> PluginServices, and a plugin's runtime method capabilities() -> services(). definePlugin now takes a plain definition object (not a factory), applying `only` narrowing + dedup bin-probe itself. - Drop the `bin` field from the capability interfaces; `ui` is the only display field (ToolService keeps bin private). Label dedup is dropped accordingly. - Move the SDK to src/lib/plugin/*; ad-hoc errors become domain error classes (src/errors/* for the kernel, src/lib/plugin/errors.ts for the SDK). Plugin resolution: - PluginRegistry exposes getService/getServiceOrThrow, providerOf/providersOf, and getAllServices (distinct services deduped by reference, for rr doctor). - A ctx.plugins facade (services/plugin-services.ts) is the only resolution surface commands touch; getJsChecker() composes lint+format into a StaticCheckService when no plugin claims jsc directly. - The official plugin list moves to src/lib/plugin/directory.ts; each entry lists its capabilities, and MissingPluginError derives its install hint via providersOf(capability). - createContext/Context become ContextService/ContextValue. Help surface: - Rebuilt on commander's native formatter: the root is a RunRunCmd subclass that groups commands and attaches a banner + installed/available plugins footer. Per-command "Powered by:" / "See also:" lines are auto-derived from each command's declared capabilities by the Cmd base class (src/program/base.ts); the per-tool doctor subcommand is always present (lazy resolution). clibuddy: drop the `muted` palette token and route callers through palette.dim. Regenerate CLI docs, add decision 015, restore the composed-jsc coverage as static-checker.test.ts, and ship scoped changesets (@rrlab/* and @vlandoss/*). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 4903a88 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Preview releaseLatest commit: Some packages have been released:
Note Use the PR number as tag to install any package. For instance: |
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.
Summary
Completes the
@rrlab/*CLI decoupling. Command bodies become free-function actions, plugin resolution moves behind actx.pluginsfacade, the kernel-internal plugin contract vocabulary is renamed (capabilities→services,PluginKind→PluginCapability), and the help surface is rebuilt on commander's native formatter.Key changes
Layering
ctx.plugins.getServiceOrThrow(...)and delegate to exactly one action (src/actions/*). Actions never import the CLI framework.ctx.pluginsfacade (services/plugin-services.ts) overPluginRegistry;getJsChecker()composes lint + format into aStaticCheckServicewhen no plugin claimsjscdirectly.createContext/Context→ContextService/ContextValue.Plugin contract (kernel-internal)
PluginKind→PluginCapability; the capability-map type →PluginServices; runtimecapabilities()→services().definePlugintakes a plain definition object (not a factory); it ownsonlynarrowing + the dedup bin-probe.bindropped from the capability interfaces —uiis the only display field.src/lib/plugin/directory.ts;MissingPluginError(capability)derives its install hint fromprovidersOf(capability).Help surface
RunRunCmdsubclass grouping commands + banner/footer.Powered by:/See also:are auto-derived from each command's declared capabilities by theCmdbase class; the per-tooldoctorsubcommand is always present (lazy resolution), keeping the--usageKDL spec stable across machines.clibuddy: drop the
mutedpalette token and route callers throughpalette.dim.Test plan
pnpm build && pnpm rr check && pnpm test— all green (8 packages lint/format/tsc; 16 build+test tasks).static-checker.test.ts.CLAUDE.md(×3),decisions/, and the changesets reconciled to the final shape.Changesets
@rrlab/climinor;@rrlab/{biome,oxc,ts,tsdown}-pluginpatch (track the internal contract).@vlandoss/clibuddy+@vlandoss/vlandpatch (palettemuted→dim).🤖 Generated with Claude Code