Plugin Architecture in Practice: From Editor Errors to Module Publishing
A practical guide to building a plugin-based architecture: how the core stays minimal, how the "base package" works as a bundle, how to fix editor and compiler errors when writing your first plugin, how compiler configuration works, and what a full build pipeline actually does before a module ships.
Introduction
When a command-line tool or agent system needs to keep absorbing new capabilities—model adapters, tool invocation, session logging, approval flows—cramming everything into one monolithic core quickly becomes unmaintainable. A plugin architecture is the common solution: the core handles only lifecycle management and service registration, while concrete capabilities are mounted as plugins.
To actually make this system work, developers need to understand four things at once: how editors and compilers understand the code, how build artifacts are produced, how packages reference each other within a workspace, and how modules are resolved at runtime. This article uses “writing your own plugin” as the thread that ties these four lines together.
Prerequisites: familiarity with the Node.js runtime, basic package manager usage, and the fundamentals of a statically typed superset of JavaScript (e.g., TypeScript).
1. Everything Is a Plugin: Even the Foundation
1.1 Design Philosophy
The core assumption of a plugin architecture is that there is no “privileged kernel” that requires patching. Model adaptation, tool registration, session storage, and main-loop scheduling are all implemented as plugins, then combined via configuration into a complete system.
This design offers three immediate benefits:
- Replaceable: Swapping a model adapter or storage backend means changing one plugin entry—the main flow stays untouched.
- Testable: Each plugin can be mounted into a minimal configuration and verified in isolation.
- Trimable: A deployment that doesn’t need a capability simply drops the corresponding plugin, reducing both size and attack surface.
The costs are equally clear. Dependencies between plugins are implicit, startup order can affect behavior, and when something fails, the call chain is longer than in a monolith—making debugging more expensive.
1.2 The Real Identity of the “Base Package”
Beginners often assume that a package with “base” in its name is a low-level library imported by other code. In a plugin architecture, such packages are usually bundles (composition packages). Their manifest declares them as a bundle type, and they use configuration patches to inject a batch of plugin entries into an empty configuration tree.
The following sketch illustrates this structure:
# Sketch: a bundle injecting plugin entries into the config treeplugins:timer:hot-reload:llm:adapter: vendor-asession:storage: memoryagent:driver: default-looptools:sandbox:approval:
A bundle is essentially a “mounting manifest.” When reading one, focus on two questions: which plugins are mounted, and where each plugin’s configuration is overridden from.
2. Your First Plugin: Starting from Editor Errors
After creating a new plugin directory, you’ll often see waves of red squiggles in the editor. These errors typically come from three sources:
- The editor is using a different configuration file than the build does—for example, the editor opened a subdirectory but picked up the wrong root config.
- Type declarations are missing, or path aliases exist only in the compiler config and were not synced to runtime resolution.
- A dependency’s export fields don’t declare type files, so referencing code is inferred as
any.
For troubleshooting, follow this order:
- Confirm that the editor’s workspace root matches the project root.
- Check which compiler configuration file the current file belongs to; editors usually show this in the status bar or output panel.
- Run a full type check on the command line and compare it with the editor’s results. If the CLI passes while the editor reports errors, the issue is likely language-server caching or config ownership—restarting the language server will verify this.
- Check whether the dependency’s type declaration files have been generated, and whether its export fields point to the correct type paths.
A minimal plugin can be structured like this. The interface here is only a generic illustration; consult your framework’s documentation for exact signatures:
// Sketch: structure of a minimal pluginexport interface PluginContext {logger: { info(message: string): void }}export default function apply(ctx: PluginContext): void {ctx.logger.info('plugin loaded')}
3. Core Concepts of Compiler Configuration
The compiler configuration file defines the rules for type checking and artifact generation. Understanding the following fields explains most “why does it pass here but fail there” questions:
- compilerOptions: Determines the target syntax version, module format, and strictness of type checking.
- File scope (include / exclude): Determines which files participate in type checking. Files outside the scope may run fine but receive no editor hints.
- extends: Lets multiple config files share base rules, with subprojects overriding only the differences.
- paths (aliases): Affects only compile-time type resolution. If the runtime still can’t resolve aliases, the bundler or the runtime’s own alias mechanism must help.
- Module resolution strategy: Determines how packages are located in dependency directories. Different runtime environments require matching strategies, or types may pass while the runtime can’t find the module.
- references (project references): After splitting a large repo into subprojects, supports incremental builds following the dependency graph.
A typical base configuration looks like this:
{"compilerOptions": {"target": "ES2022","strict": true,"declaration": true,"outDir": "dist"},"include": ["src/**/*"]}
One thing to remember: editor errors do not always equal build failures, and a successful build does not guarantee the editor shows no errors. The two may be reading different config files—this is exactly what to verify first when troubleshooting.
4. The Build System: What a Build Actually Does
A complete build typically includes the following steps. Understanding each step’s responsibility helps locate failures:
- Clean old artifacts: Delete the previous build’s output directory so stale files aren’t mistaken for new artifacts and accidentally published.
- Type check: Validate all source files participating in compilation and surface type errors.
- Syntax transformation: Transpile source code into syntax supported by the target runtime environment.
- Generate type declarations: Emit
.d.tsfiles for downstream projects to consume. - Copy static assets: Non-code files—templates, images, default configs—must be explicitly copied to the output directory.
- Generate the publish manifest: Ensure the package manifest’s entry fields point to the output directory, not the source directory.
