Skip to content

feat(plugin): integrate plugin loader into validate_and_load startup#208

Closed
snipcodeit wants to merge 3 commits intomainfrom
issue/193-integrate-plugin-loader-into-validate-an
Closed

feat(plugin): integrate plugin loader into validate_and_load startup#208
snipcodeit wants to merge 3 commits intomainfrom
issue/193-integrate-plugin-loader-into-validate-an

Conversation

@snipcodeit
Copy link
Owner

Summary

  • Calls discoverPlugins(getDefaultPluginDirs(repoRoot)) and buildRegistry() at bin/mgw.cjs startup (non-fatal IIFE before program.parseAsync()), so every MGW command automatically sees registered plugins
  • Stores the registry as global._mgwPluginRegistry; exposes it via getPluginRegistry() from lib/plugin-loader.cjs for clean consumer access without global coupling
  • Adds [N plugins loaded] suffix to the mgw:run startup banner when plugins are present
  • Documents the plugin loading step in commands/workflows/state.md (new Plugin Loading section + validate_and_load step 5 + Consumers table update)

Closes #193

Milestone Context

Changes

  • bin/mgw.cjs — Import discoverPlugins, buildRegistry, getDefaultPluginDirs; add loadPlugins() IIFE before parseAsync; add plugin count suffix to mgw:run banner
  • lib/plugin-loader.cjs — Add getPluginRegistry() accessor that returns global._mgwPluginRegistry or a new empty Map; export it
  • lib/index.cjs — Add ...require('./plugin-loader.cjs') to barrel export
  • commands/workflows/state.md — New "Plugin Loading" section; plugin step documented in validate_and_load; Consumers table updated

Note: commits efd29c8 and eddfb2f are cherry-picks from issue/192-implement-plugin-discovery-and-loader-in-lib-plugin-loader-cjs (PR #207). They will fast-forward cleanly when #207 merges.

Test Plan

  • node --check bin/mgw.cjs exits 0
  • node --check lib/plugin-loader.cjs exits 0
  • npm test reports 387 pass, 0 fail
  • node -e "const {getPluginRegistry} = require('./lib/plugin-loader.cjs'); console.log(getPluginRegistry() instanceof Map)" prints true
  • node -e "const {getPluginRegistry} = require('./lib/index.cjs'); console.log(typeof getPluginRegistry)" prints function
  • Integration smoke test: run the startup simulation (see VERIFICATION-2.md for exact command)
  • mgw run 1 startup banner format — no crash; if plugins installed, shows [N plugins loaded]

Cross-References

🤖 Generated with Claude Code

Stephen Miller and others added 3 commits March 5, 2026 21:57
Add templates/mgw-plugin-schema.json defining the JSON Schema (draft-07)
for mgw-plugin.json manifests. Schema covers plugin metadata (name, version,
author), plugin type (agent-template, hook, validator), entry point,
supported pipeline stages, hook definitions, and optional config schema.

Add lib/plugin-loader.cjs with validateManifest(), loadPlugin(), and
discoverPlugins() functions. Uses Ajv for schema validation with graceful
degradation to structural checks when Ajv is unavailable.

Closes #191

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ader

Add buildRegistry(plugins) that takes the discoverPlugins() output and
returns a Map<'name:type', pluginEntry> for O(1) lookup by extension point.
Last-found wins on duplicate keys so project-local plugins (discovered
last when dirs are ordered project-first) override user-global plugins.

Add getDefaultPluginDirs(repoRoot) that returns the standard two-path
discovery array: <repoRoot>/.mgw/plugins (project-local, priority) and
~/.mgw/plugins (user-global). Neither path must exist — discoverPlugins
silently skips missing directories.

Also add os module import and expand the module docblock to document
the registry and standard discovery directory pattern.

All smoke tests pass. No breaking changes to existing exports.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…load)

Call discoverPlugins(getDefaultPluginDirs(repoRoot)) and buildRegistry() at
bin/mgw.cjs startup via a non-fatal IIFE that runs before program.parseAsync().
The resulting registry is stored on global._mgwPluginRegistry and exposed through
getPluginRegistry() in lib/plugin-loader.cjs for clean consumer access.

- bin/mgw.cjs: import plugin-loader; add loadPlugins() IIFE before parseAsync;
  show "[N plugins loaded]" in mgw:run startup banner when plugins are present
- lib/plugin-loader.cjs: add getPluginRegistry() accessor for global registry;
  export it in module.exports
- lib/index.cjs: add plugin-loader.cjs to barrel export
- commands/workflows/state.md: document plugin loading step in validate_and_load
  pattern; add Plugin Loading section with implementation details, registry
  access pattern, directory table, and startup banner example; update Consumers table

Non-fatal: broken plugins log a warning and are skipped; startup failures set
an empty Map so commands always receive a usable registry.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions bot added slash-commands Changes to slash command files core Changes to core library templates Changes to templates labels Mar 6, 2026
@snipcodeit
Copy link
Owner Author

Resetting milestone for rerun

@snipcodeit snipcodeit closed this Mar 6, 2026
@snipcodeit snipcodeit deleted the issue/193-integrate-plugin-loader-into-validate-an branch March 6, 2026 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes to core library slash-commands Changes to slash command files templates Changes to templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate plugin loader into validate_and_load startup

1 participant