Plugin-Based Runtime Frameworks: Core Mechanics and a Practical Guide
This article explains how plugin-based runtime frameworks work by tracing a plugin from the configuration tree through module resolution to lifecycle activation. It covers composition bundles, build artifacts, runtime profiles, type and runtime entries, workspace links, publishing checks, and a practical troubleshooting sequence for common editor and installation errors.
Many developers first encounter a plugin-based runtime framework through a misleading assumption about the “base composition bundle.” It looks like a low-level API library, but in practice it is a configuration manifest that declares which plugins should be mounted. To understand and use this kind of framework, you need to connect five things into one continuous chain: the configuration tree, the plugin manifest, build artifacts, runtime profiles, and module resolution. This article follows the process of writing your own plugin, starting from editor static-check errors, and breaks down the core mechanics of the plugin system step by step.
1. Establish the Mental Model: A Configuration Tree, Not “Core Plus Patches”
A plugin-based runtime framework is usually not structured as “one privileged core plus several peripheral plugins.” It is structured as “an empty configuration tree + plugin entries + composition bundles.” At runtime, the framework first reads a runtime profile, merges patches provided by multiple composition bundles, forms the final configuration tree, and then instantiates plugins in dependency order. During development, it may load source code or a transpiled cache directly; during release, it loads the distribution package entry. These two paths use different module resolution rules, which is the root cause of many “works locally, fails after installation” problems.
To understand the framework, focus on five objects:
- Configuration tree: describes which capabilities the current runtime environment needs, in what order they should be mounted, and how parameters are overridden.
- Plugin: a capability unit responsible for registering interfaces, listening to events, and extending tools or policies.
- Composition bundle: not an API library that gets called, but a manifest that declares dependencies and inserts plugin entries.
- Build artifact: the delivery boundary that determines which files are actually loaded after installation.
- Runtime profile: an environment selector that determines which composition bundles are used and which configurations are overridden.
2. Foundation: Everything Is a Plugin; a Composition Bundle Is Just a Manifest
The core philosophy of this kind of framework is “everything is a plugin.” Model adapters, tool calls, session logs, the agent main loop, subprocess execution, sandbox approvals, file system policies, settings storage, and network capabilities can all be plugins. There is no privileged core that needs to be patched; all capabilities are assembled through configuration.
Consider a base composition bundle. Its name may contain “base,” which makes it sound like a low-level library, but it is actually a composition bundle: its package manifest declares that it is a composition bundle, and its patch manifest inserts several plugin entries into the empty configuration tree. A simplified example looks like this:
Composition bundle: base-capabilitiesPatches:- Add: timer plugin- Add: hot reload plugin- Add: model adapter plugin- Add: session log plugin- Add: agent main loop plugin- Add: tool registry plugin- Add: prompt assembly plugin- Add: subprocess plugin- Add: sandbox approval plugin- Add: file policy plugin- Add: settings storage plugin- Add: network capability plugin
The benefits of this design are that capabilities can be trimmed, implementations can be replaced, dependencies are explicit, runtime behavior is observable, and configuration becomes architecture. The cost is that developers must understand configuration merge order and the plugin lifecycle. If you mistake a base composition bundle for an ordinary API library and import it that way, you will run into a series of problems in editor resolution, build entries, and runtime loading.
3. Your First Plugin: Classify Editor Errors Before Changing Code
When you write your first plugin, editor static-check errors are common. Do not rush to change the code. First classify the problem along the chain:
- Module not found: the workspace link may not be established, the package entry field may be wrong, or a path alias may not be mapped.
- Type mismatch: the declaration entry may be missing, the declaration and implementation versions may differ, or a composite project may not have been built first.
- Missing declarations: the build pipeline may not have generated declaration files, or the type entry may point to the source directory.
- Broken workspace link: dependencies between local packages may not be linked correctly, or hoisted dependencies may cause version conflicts.
- Build artifact not generated: the runtime entry may point to an output directory, but the build has not run or the output directory is misplaced.
- Path aliases affecting only type checking: type checking passes, but the file cannot be found at runtime.
A recommended troubleshooting order is: confirm whether the plugin has entered the configuration tree → confirm workspace links → confirm the type entry → confirm path aliases and the source root → confirm build artifacts → clear caches → create a minimal reproduction. A minimal plugin manifest should clearly separate the runtime entry from the type entry:
Plugin manifest:Name: hello-policyRuntime entry: <distribution entry path>Type entry: <declaration entry path>Activation function: registerPolicy
The runtime entry and type entry are separated to keep the resolution boundary clear between development and release. If the type entry points to source code and the runtime entry points to build output, make sure the two remain consistent after the build.
4. Type Configuration: Module Resolution Strategy Determines How Strings Become Files
In a statically typed project, the module resolution strategy determines how a module reference string becomes an actual file. Workspace projects usually need to pay attention to workspace-aware resolution, path aliases, declaration output, composite projects, source roots, and output roots. Common pitfalls include a mismatch between the root directory and the output directory; declaration files not being generated; path mappings affecting only type checking and not runtime; and composite project dependencies not being built in order.
A simplified configuration looks like this:
Type project configuration:Module resolution: workspace-awarePath aliases: enabledDeclaration output: enabledComposite projects: enabledSource root: srcOutput root: dist
The key here is not to memorize a specific field name, but to understand that “type resolution” and “runtime resolution” are two separate chains. Editor errors usually indicate only that the type chain has a problem; runtime failures indicate that module resolution or the artifact entry has a problem. The two cannot be conflated.
5. Build System: What the Build Command Actually Does
A build is not a simple transpilation step. It is a pipeline: clean old artifacts, run type checking, transpile or bundle, generate declarations, copy static assets, generate the plugin manifest, and validate entries. Development builds can skip minification and retain debug information; production builds must ensure stable entries, complete declarations, and all required assets.
A successful build does not guarantee successful runtime. The reason is that runtime resolution uses the distribution package entry and conditional exports, while the build tool may only verify references at the source level. Before release, check whether the runtime entry points to build output; whether the type entry exists; whether the patch manifest is packaged; whether static assets are shipped with the package; and whether dependency versions have been replaced with installable versions.
6. Source Startup vs. Build Artifacts: Two Runtime Paths
During development, the framework may load source code or a transpiled cache directly. In production, it loads the distribution package entry. The differences between these two paths include entry fields, conditional exports, file extensions, path aliases, workspace links, and cache hits.
When troubleshooting, first determine which path the current process is taking. When loading a plugin, you can print the actual resolved file path to confirm whether it is loading source code, cache, or a distribution artifact. Many “works in development, fails after installation” problems are essentially caused by the development path relying on workspace symlinks and path aliases, while the production path recognizes only the distribution package entry.
7. Workspace Mechanics: Local Links and Publish Replacement
A workspace links multiple local packages into a dependency graph. The linking strategy determines whether local packages are symlinked or copied; the version protocol determines how versions are replaced with real versions at publish time. During development, symlinks make hot updates convenient. At publish time, workspace version protocols must be replaced with installable versions; otherwise, the installation side cannot resolve dependencies.
Check the following: whether package manifest dependencies use the workspace protocol; whether version rewriting is completed in the release artifact; whether hoisted dependencies cause version conflicts; and whether local links fail in a clean environment. The most reliable verification method is to install and start the package in a clean directory that does not contain workspace links.
8. Publishing a Composition Bundle: From Local Plugin to Installable Distribution
An installable composition bundle should contain at least a package manifest, a plugin runtime entry, type declarations, a patch manifest, static assets, and version and dependency declarations. Before publishing, perform a “clean environment install” validation: do not run from the workspace root, do not rely on local links, and start through the production entry.
Common failures include missing declaration files, entries still pointing to source code, the patch manifest not being packaged, workspace protocols not being replaced, and static asset paths being hardcoded. Release validation should confirm each deliverable item by item, rather than only checking whether the local build passes.
9. Runtime Profiles: Environment Selection and Override Order
Named runtime profiles under the user-level configuration directory are essentially selectors: which composition bundles to use, which configurations to override, and which credentials and caches to isolate. The loading order is usually: default configuration → composition bundle patches → user profile overrides → temporary command-line overrides. Understanding this override order is necessary to explain “why the configuration change did not take effect.”
Use an independent profile for each project to avoid global pollution; separate credentials, caches, and project configuration; and explicitly declare the source and version of composition bundles in the profile. This makes problems reproducible and reduces collaboration costs across a team.
10. The Complete Module Resolution Chain
A single plugin load usually goes through these steps: read the configuration tree → compute plugin entries → resolve the package entry → apply conditional exports → resolve workspace links → check cache hits → dynamic loading → lifecycle activation. If any step fails, the symptom may appear as “module not found” or “type mismatch.”
During troubleshooting, verify each segment of the chain: Is the plugin present in the configuration tree? Does the package entry point to the correct file? Do conditional exports match the current environment? Are workspace links valid? Is the cache stale? Is dynamic loading blocked by sandbox policy? Does the activation function throw an error? Do not guess at a single point, and do not delete caches to mask the root cause.
11. Conclusion: Put Errors Back into the Chain
The mental model for this kind of framework can be summarized in one sentence: the configuration tree is the skeleton, plugins are capability units, composition bundles are manifests, build artifacts are the delivery boundary, runtime profiles are environment selectors, and module resolution is the final step that makes everything concrete. When writing a plugin, declare the manifest first, then ensure that the type entry and runtime entry are consistent, and finally validate the release in a clean environment. Once you understand this chain, editor errors are no longer mysterious; they become engineering problems that can be located segment by segment.
