Skip to content

feat(plugins): narrow CLI loading via activation planning - #65120

Merged
vincentkoc merged 4 commits into
mainfrom
feat/ocplugins-activation-planner
Apr 12, 2026
Merged

vincentkoc merged 4 commits into
mainfrom
feat/ocplugins-activation-planner

Conversation

@vincentkoc

Copy link
Copy Markdown
Member

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: registerPluginCliCommands(..., { primary }) knew the requested command root, but the plugin CLI loaders still loaded every CLI-capable plugin before registration.
  • Why it matters: this left the first real activation-planner seam unused and kept CLI startup broader than necessary even after manifest activation metadata was added.
  • What changed: added src/plugins/activation-planner.ts, taught it to resolve manifest-driven command/provider/channel/route/capability matches, and used command planning to pass onlyPluginIds into CLI runtime/metadata loaders when a primary command is known.
  • What changed: documented that manifest activation is now a real narrowing hint and that command planning still falls back to legacy commandAliases metadata for older plugins.
  • What did NOT change (scope boundary): no loader-wide activation planner rollout, no provider/channel runtime consumers yet, and no plugin runtime behavior change beyond narrower CLI candidate loading.

AI-assisted: yes. Fully tested on the touched surface listed below.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause (if applicable)

For bug fixes or regressions, explain why this happened, not just what changed. Otherwise write N/A. If the cause is unclear, write Unknown.

  • Root cause: N/A
  • Missing detection / guardrail: N/A
  • Contributing context (if known): N/A

Regression Test Plan (if applicable)

For bug fixes or regressions, name the smallest reliable test coverage that should catch this. Otherwise write N/A.

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: N/A
  • Scenario the test should lock in: N/A
  • Why this is the smallest reliable guardrail: N/A
  • Existing test that already covers this (if any): N/A
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

List user-visible changes (including defaults/config).
If none, write None.

  • Plugin CLI loading can now narrow to manifest-matched plugins when a primary command is known during startup.
  • Plugins can opt into better command-triggered CLI narrowing with activation.onCommands; older plugins still benefit from commandAliases fallback.

Diagram (if applicable)

For UI changes or non-trivial logic flows, include a small ASCII diagram reviewers can scan quickly. Otherwise write N/A.

Before:
[primary CLI command known] -> [load all CLI-capable plugins] -> [register selected command]

After:
[primary CLI command known] -> [manifest command planning] -> [load matched plugins only] -> [register selected command]

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS
  • Runtime/container: Node 25 / pnpm workspace
  • Model/provider: N/A
  • Integration/channel (if any): plugin CLI loading
  • Relevant config (redacted): default local config

Steps

  1. Run registerPluginCliCommands(..., { mode: "lazy", primary: "memory" }).
  2. Observe the plugin CLI loader options passed to runtime/metadata loading.
  3. Verify manifest command planning scopes the load to the matched plugin ids and falls back to the full load when no match exists.

Expected

  • Primary-command startup narrows plugin loading when manifest metadata identifies the owning plugin.
  • No narrowing happens when planning has no safe match.

Actual

  • Matches expected.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
    • pnpm test:serial src/plugins/activation-planner.test.ts
    • pnpm test:serial src/plugins/cli.test.ts -t 'registers a selected plugin primary eagerly during lazy startup|keeps full CLI loading when primary command planning finds no plugin match'
    • pnpm lint -- src/plugins/activation-planner.ts src/plugins/activation-planner.test.ts src/plugins/cli-registry-loader.ts src/plugins/cli.ts src/plugins/cli.test.ts
    • pnpm build
  • Edge cases checked:
    • legacy commandAliases[].cliCommand fallback
    • fallback to commandAliases[].name
    • no onlyPluginIds override when planning finds no match
  • What you did not verify:
    • broader loader consumers beyond the CLI path
    • perf measurements beyond scoped narrowing behavior

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: command planning metadata is incomplete for some plugins, so narrowing may not fire.
    • Mitigation: the CLI loader only applies onlyPluginIds when planning returns a non-empty set; otherwise it falls back to the previous full-load behavior.
  • Risk: legacy command aliases could point at the wrong CLI root for a plugin.
    • Mitigation: the planner uses those aliases as a compatibility fallback only; explicit activation.onCommands remains the preferred path and docs now say that clearly.

@vincentkoc vincentkoc self-assigned this Apr 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M maintainer Maintainer-authored PR labels Apr 12, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review April 12, 2026 07:21
@blacksmith-sh

blacksmith-sh Bot commented Apr 12, 2026 •

Copy link
Copy Markdown
Contributor

Found 1 test failure on Blacksmith runners:

Failure

Test View Logs
gateway-watch-regression invalid local run: dirty watched source tree would force a reb
uild inside the watch window/
gateway-watch-regression invalid local run: dirty watched source tree would force a reb
uild inside the watch window
View Logs

Fix in Cursor

@greptile-apps

greptile-apps Bot commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR introduces src/plugins/activation-planner.ts to narrow CLI plugin loading when a primary command is known at startup, rather than always loading every CLI-capable plugin. The planner matches manifest activation.onCommands entries and falls back to legacy commandAliases for older plugins, wiring the result into both the runtime and metadata loader paths via the new primaryCommand propagation in cli-registry-loader.ts.

  • Type mismatch in cli.ts: primary (string | null) is passed as primaryCommand where PluginCliPublicLoadParams.primaryCommand?: string (i.e., string | undefined). With strict: true, pnpm tsgo will reject null as not assignable to string | undefined. Fix: primaryCommand: primary ?? undefined.

Confidence Score: 4/5

Safe to merge after resolving the null/undefined type mismatch in cli.ts; runtime behavior is correct but pnpm tsgo will reject the current types.

One P1 TypeScript strict-mode type error (null vs undefined for primaryCommand) needs fixing before the full type-check gate passes. All other findings are P2 (dead code style). The activation logic, fallback behavior, loader wiring, and tests are solid.

src/plugins/cli.ts — the primaryCommand: primary assignment needs ?? undefined to satisfy strict null checks.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/plugins/cli.ts
Line: 51-56

Comment:
**`null` assigned to `string | undefined` — strict TypeScript type error**

`primary` is `string | null` (because `RegisterPluginCliOptions.primary?: string | null` combined with `?? null`), but `PluginCliPublicLoadParams.primaryCommand` is typed `primaryCommand?: string` (i.e., `string | undefined`). With `strict: true` in `tsconfig.json`, `null` is not assignable to `string | undefined`, so `pnpm tsgo` will reject this.

Functionally, the runtime is safe (`null?.trim()` → `undefined`, and `!undefined` → early return in `resolvePrimaryCommandPluginIds`), but the type violation needs fixing:

```suggestion
    await registerPluginCliCommandGroups(
      program,
      await loadPluginCliRegistrationEntriesWithDefaults({
        cfg,
        env,
        loaderOptions,
        primaryCommand: primary ?? undefined,
      }),
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/plugins/activation-planner.ts
Line: 59-62

Comment:
**Unreachable `return false` after exhaustive switch**

The switch covers all five variants of `PluginActivationPlannerTrigger` (every `case` returns), so the `return false` on line 62 is dead code. The same pattern appears at the end of `hasActivationCapability` (line 111). Consider removing both, or replacing them with a `satisfies never` exhaustiveness check — that would turn future union extensions into a compile-time error rather than silently falling through.

```suggestion
    case "capability":
      return hasActivationCapability(plugin, trigger.capability);
  }
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Merge branch 'main' into feat/ocplugins-..." | Re-trigger Greptile

Comment thread src/plugins/cli.ts Resolved
Comment thread src/plugins/activation-planner.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 78dcf29704

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/plugins/cli.ts Resolved
@vincentkoc
vincentkoc merged commit a9c7c2e into main Apr 12, 2026
40 of 49 checks passed
@vincentkoc
vincentkoc deleted the feat/ocplugins-activation-planner branch April 12, 2026 08:07
trudbot pushed a commit to trudbot/openclaw that referenced this pull request Apr 12, 2026
…5120)

* feat(plugins): narrow cli loading via activation planning

* fix(plugins): normalize primary CLI command nullability

* fix(plugins): enforce activation planner exhaustiveness
TOMUIV pushed a commit to TOMUIV/openclaw that referenced this pull request Apr 14, 2026
…5120)

* feat(plugins): narrow cli loading via activation planning

* fix(plugins): normalize primary CLI command nullability

* fix(plugins): enforce activation planner exhaustiveness
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…5120)

* feat(plugins): narrow cli loading via activation planning

* fix(plugins): normalize primary CLI command nullability

* fix(plugins): enforce activation planner exhaustiveness
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…5120)

* feat(plugins): narrow cli loading via activation planning

* fix(plugins): normalize primary CLI command nullability

* fix(plugins): enforce activation planner exhaustiveness
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
…5120)

* feat(plugins): narrow cli loading via activation planning

* fix(plugins): normalize primary CLI command nullability

* fix(plugins): enforce activation planner exhaustiveness
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…5120)

* feat(plugins): narrow cli loading via activation planning

* fix(plugins): normalize primary CLI command nullability

* fix(plugins): enforce activation planner exhaustiveness
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…5120)

* feat(plugins): narrow cli loading via activation planning

* fix(plugins): normalize primary CLI command nullability

* fix(plugins): enforce activation planner exhaustiveness
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…5120)

* feat(plugins): narrow cli loading via activation planning

* fix(plugins): normalize primary CLI command nullability

* fix(plugins): enforce activation planner exhaustiveness
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant