Building Smart Coding Tool Plugins: A Practical Guide to Host Kernels, Types, and Build Output
This guide walks through the engineering foundation that plugin development for smart coding tools depends on: the host kernel, type resolution, and build artifacts. It explains why embedding the kernel source in the repository helps, how to trace editor type errors through four layers, which configuration concepts are commonly confused, and how to prevent runtime module resolution failures before release. Readers will get a reusable checklist-based workflow that turns plugin development from repeated trial and error into a predictable process.
1. Why Plugin Development Gets Stuck at the Foundation
When developers write a plugin for the first time, they tend to focus entirely on business logic and overlook two more fundamental things: the host kernel the plugin runs on, and the correspondence between type definitions and build output. Once either of these is off, the editor starts showing red squiggles and the runtime throws a module-not-found error. The first is a missing signal at the static level; the second is a resolution failure at the dynamic level. Both usually share the same root cause.
So the right order is bottom-up: first understand the host kernel’s dependency injection and lifecycle model, then set up a project skeleton whose types can be resolved, and only then move on to feature implementation and release.
2. The Foundation: Host Kernel and Embedded Source
Mature plugin systems are typically built on a lightweight dependency injection kernel. The core abstractions are only three: Context, Service, and Plugin. The context is the single entry point for a plugin to interact with the host; services are mounted on the context through key-value registration; plugins are loaded, initialized, and unloaded as functions or objects.
A common practice in real projects is to put the kernel source into the repository as an embedded dependency instead of pulling it from a remote source. There are three benefits:
- Version control: kernel upgrades and plugin changes can be committed in the same batch.
- Builds still work offline or in an intranet environment.
- It is easier to set breakpoints and debug kernel behavior, which helps locate subtle issues such as “service not registered.”
The cost is that you have to maintain synchronization yourself, so it is best to pin a baseline version and document the upgrade strategy.
repo/core/ # embedded kernel sourcepackages/plugin-demo/ # plugin packageworkspace.yaml # workspace declaration
3. Your First Plugin: A Troubleshooting Path for Editor Errors
Red squiggles in the editor do not necessarily mean the code is wrong. In most cases, the type resolution chain is broken. It is worth checking four layers in order:
- Whether dependencies are installed: is the workspace recognized correctly, and did the package manager generate a unified lockfile?
- Whether the type entry is reachable: does the package’s type declaration entry field point to a declaration file that actually exists?
- Whether the kernel types are inlined into the output: if the embedded source does not participate in compilation, the editor cannot see the service declarations on the context.
- Whether the editor cache is stale: restart the language service, clear the cache directory, and reload the window.
A minimal working plugin skeleton looks roughly like this. Note that the context type should come from the kernel rather than being declared arbitrarily:
import { Context } from '@demo/core'export const name = 'demo-plugin'export const inject = ['logger']export function apply(ctx: Context) {ctx.logger.info('plugin loaded')ctx.on('ready', () => {ctx.set('demo/state', { ready: true })})}
The key criterion for troubleshooting is this: if the type hints do not show the service methods provided by the kernel, the problem is in the type chain; if the types are fine but the runtime reports a missing module, the problem is in the output and the resolution rules.
4. Clarifying the Core Configuration Concepts
Most arguments about configuration files come from conceptual confusion. Four pairs of concepts need to be kept distinct:
- Compile target and module system: these determine how much syntax is downleveled and what form the module output takes, and both must match what the runtime supports.
- Type resolution and path mapping: path mapping is only an alias for compile time and editor time; it does not change real addressing at runtime.
- Declaration output and source references: whether declaration files are generated determines whether downstream packages get complete hints.
- Scope inclusion and exclusion: the directories that participate in compilation should be declared explicitly, so that embedded source and output directories are not mixed together.
One practical rule: for any problem that resolves at compile time but fails at runtime, suspect first that path mapping has been mistaken for a runtime capability.
5. Build, Release, and Runtime Module Resolution
The build stage must produce self-contained output: it should not depend on the source directory being present, nor on undeclared external paths. Before release, three checks are recommended: the output directory structure, whether the dependency manifest matches actual references, and whether declaration files are complete.
Runtime resolution failures usually come from three causes: the package was not bundled into the output, the module addressing rules differ from the compile-time aliases, or multiple copies of dependencies exist at different levels. The corresponding fixes are to unify dependency versions, make addressing boundaries explicit, and treat the embedded kernel as the single source.
6. Reusable Engineering Conventions
- Set the kernel baseline first, then write business plugins.
- Keep the type entry, build entry, and runtime entry the same in name and meaning.
- Turn the troubleshooting process into a checklist instead of relying on memory.
- Use logging and state reads/writes to verify that lifecycle hooks fire as expected.
Following this path turns plugin development from repeated trial and error into a predictable engineering process. To further reduce the cost of environment setup and dependency governance, you can use general-purpose cloud container platforms, image registries, and logging services for build isolation and issue traceability, keeping your focus on the plugin’s own design.
