Plugin Architecture for AI Coding Tools: A Practical Guide to Building and Running Your First Plugin

    This article explains the "everything is a plugin" architecture used by plugin-based AI coding tools, where model adapters, tool calls, session logs, the agent loop, file systems, and sandbox approvals are all plugins composed through a configuration tree. It walks through building and running a first plugin, covering configuration patches, TypeScript compilation concepts, build and verification steps, source versus build-artifact startup, workspace linking, publishing, profiles, and the runtime module resolution chain. Readers will learn how to diagnose common plugin loading failures and deliver plugin projects reliably. Requires basic familiarity with Node.js, package managers, and TypeScript.

    Plugin Architecture for AI Coding Tools: A Practical Guide

    Why “Everything Is a Plugin” Comes First

    When developers first try a plugin-based AI coding tool, the biggest question is usually not how to call an API, but “what exactly is the core?” Traditional software follows a layered intuition: start with a stable kernel, then attach extensions around it. These tools often invert that design. There is no privileged kernel to patch. Model adapters, tool invocation, session logs, the agent main loop, the file system, and sandbox approval are all plugins, composed together by a configuration tree.

    Once this is clear, everything else—building, publishing, and module resolution—falls into place. This article follows a single thread: writing your own plugin and getting it to actually run. It covers five main areas in order: editor resolution, project and build setup, artifact publishing, and runtime resolution. The prerequisites are modest: basic knowledge of Node.js, a package manager (such as npm or pnpm), and TypeScript.

    1. The Foundation: Bundles and Configuration Patches

    1.1 A “Base Bundle” Is Really a Configuration Manifest

    Take a bundle named base. The name sounds like a low-level library that gets imported, but it is actually a bundle: its package manifest declares a bundle field and ships a configuration patch file that inserts dozens of plugin declarations into an empty configuration tree. It is not an API you call; it is a manifest that says “mount these plugins.”

    Illustrative excerpt (pseudocode, structure only):

    1. # cordis.patch.yml structure example
    2. insert:
    3. - timer / hmr # timers and hot reload
    4. - llm / llm-adapter # model capability + specific model adapter
    5. - session # session event log and in-memory storage
    6. - agent / agent-loop # agent interface + default main loop
    7. - tools / system-prompt# tool registry + prompt assembly
    8. - subprocess / shell # subprocess and shell execution
    9. - sandbox / approval # sandbox and approval policy
    10. - fs / tool-fs # file system capability
    11. - settings / credentials # settings and credentials
    12. - subagent / workflow # subagents and workflows
    13. - web / tool-web # retrieval and fetching

    1.2 Benefits and Trade-offs

    There are three benefits. First, replaceability: swapping a model adapter or an approval policy means changing configuration, not code. Second, trimmability: capabilities you do not need are not mounted, which reduces both the attack surface and startup overhead. Third, composability: an organization can layer compliance, auditing, or private tools onto its own profile.

    The trade-offs are equally clear. Debugging chains get longer, and errors may come from “configuration assembly” rather than “code logic.” Dependencies become implicit and require tooling to trace. That is why a later section is dedicated to diagnosing editor errors.

    2. Your First Plugin: Start with Troubleshooting

    A good first plugin does not add a feature; it adds observability: print the parsed configuration tree and list mounted plugins with their versions. The typical development flow is:

    1. Create a plugin directory in your local project and declare the package manifest and entry point.
    2. Point the dependency at local source using the workspace protocol.
    3. Run from source and watch the logs.
    4. If resolution fails, first check whether the inserted patch lines were merged correctly, then check whether dependencies resolved to the expected versions.

    Common pitfalls: the entry field does not match the actual artifact path; the patch insertion point falls under a branch that was trimmed away; the same plugin is mounted twice through two paths, causing port or event conflicts.

    3. Clarifying Key TypeScript Configuration Concepts

    The most misunderstood question in TypeScript configuration is “who decides what gets compiled.” Key points:

    • Generating declaration files, type-checking, and transpile-only are three independent concerns.
    • Path aliases only apply at compile time; runtime still needs matching resolution rules, otherwise you get “compiles fine, fails at startup.”
    • Project references suit large multi-package projects but require a correct build order, or artifacts will be missing.
    • Strict mode is recommended by default in plugin projects; type errors at plugin boundaries are often the crash points at runtime.

    4. The Build System: What One Build Command Actually Does

    An aggregated build command usually does four things: sort packages by dependency topology, compile each package, generate declarations and artifacts, and clean and verify. Example:

    1. { "scripts": { "build": "tsc -b && node scripts/verify.mjs" } }

    Verification should cover at least: the entry file exists, the manifest’s export fields match the actual artifacts, and the configuration patch is structurally valid. Moving verification earlier catches many problems locally that would otherwise surface only after publishing.

    5. Two Run Paths: Source Startup vs. Build Artifacts

    Source startup suits development: run the entry source directly with hot reload, and changes take effect immediately. The downside is slower startup and sensitivity to compilation configuration. Artifact startup suits release validation: it loads only the packaged output and exposes issues like “alias not resolved” or “declaration missing.” A mature practice is to run a smoke test on both paths before publishing.

    6. Workspace Mechanics: How Local Dependencies Are Linked

    In a multi-package project, packages declare dependencies with the workspace protocol, and the package manager links them to local directories instead of downloading remote versions. Key points: linking happens at the file-system level, so changes are visible immediately; but before publishing you must replace the workspace references with real version numbers, or installation will fail for users. A script can rewrite and roll back these references automatically during the release flow.

    7. Publishing: From Local Plugin to Installable Unit

    The publishing unit is usually “a package that can be referenced by the configuration tree.” Recommendations: keep the artifact directory clean, include the configuration patch and documentation, follow semantic versioning, and write a changelog that spells out compatibility. If a plugin includes native dependencies or large assets, consider distributing them through object storage and content delivery capabilities, fetching them on demand at install time.

    8. Profiles: What the Configuration Under the User Directory Really Is

    The profile directory under the user directory is essentially a “personal configuration tree plus the landing place for installed plugins.” It determines which plugins are mounted at startup and how parameters override defaults. To troubleshoot “why my settings do not take effect,” check in order: whether the profile was loaded, the patch insertion order, and parameter override precedence.

    9. The Full Module Resolution Chain

    Runtime resolution roughly goes: locate entry → read package manifest → resolve exports → load configuration patch → merge configuration tree → instantiate plugins → inject dependencies. A failure at any step shows up as “plugin not mounted.” To locate it: turn on resolution logs, bisect by commenting out patch lines, and verify link targets.

    10. Mental Model Summary

    In one sentence: the configuration tree is the source of truth, plugins are the execution units, and build and publish merely turn source code into units that can be resolved. With this main thread in hand, you can deliver plugin projects reliably to your team and business side, using general-purpose container platforms, logging services, and monitoring and alerting capabilities such as those offered by Baidu AI Cloud.