Plugin Protocol Reference
The plugin protocol reference describes machine-checkable boundaries, not ecosystem promises. It covers the public export path, manifest fields, tool types, schema rules, and current loading errors. Package sources, hot reload, and runtime capabilities must be understood within the current version’s limits.
Local TypeScript Plugins
Section titled “Local TypeScript Plugins”Scan locations
Section titled “Scan locations”| Source | Path | Trust |
|---|---|---|
| user | ~/.config/coden/plugins/*.ts |
none (user-initiated install) |
| project | <workspace>/.coden/plugins/*.ts |
workspace trust required |
| additional directories | --plugin <path> or config plugins entries (repeatable) |
project semantics: workspace trust required |
.ts files in a directory load in filename order. Missing project directories are skipped silently.
Single-file constraints
Section titled “Single-file constraints”- A plugin must be self-contained in one file: it is imported in-process through a
data:text/typescriptURL, so relative imports (./helper.ts) cannot resolve; npm bare package imports (import pc from "picocolors") work. - Content hashes drive the module cache: unchanged plugins reuse the loaded module on
/reload; changed ones rebuild the module and atomically replace the tool registry. - Top-level code executes at load time — unrelated to authorization and part of the trust boundary.
Minimal example
Section titled “Minimal example”import type { ToolDefinition } from "@twinklerg/coden/plugin";
const tool: ToolDefinition = { name: "line_count", description: "Count lines in supplied text", risk: "read", inputSchema: { type: "object", additionalProperties: false, required: ["text"], properties: { text: { type: "string" } }, }, async execute(input) { const { text } = input as { text: string }; return { content: String(text.split("\n").length) }; },};
export default tool;Loading and validation
Section titled “Loading and validation”- The export may be a single
ToolDefinitionor aCodeNPlugin(apiVersion: 1,name, non-emptytoolsarray). - Tool names must match
^[a-zA-Z][a-zA-Z0-9_-]{0,63}$; input schemas are compiled and validated with Ajv;executereturns{ content, isError?, metadata? }. - On name collisions (including built-ins) the whole plugin is skipped: existing tools are never overwritten and other plugins are unaffected.
- Execution context:
ToolContextprovidesworkspace,signal(AbortSignal; 60-second timeout requires cooperative cancellation), and structured file-path information.
Runtime requirement
Section titled “Runtime requirement”Local .ts plugins are loaded by Bun. They cannot load under a Node.js runtime: Node returns ERR_UNKNOWN_MODULE_FORMAT for data:text/typescript, so the plugin is skipped and reported as failed (other functionality is unaffected). Run from source with Bun or ensure Bun is on PATH to use local TypeScript plugins.
Related references
Section titled “Related references”npm Plugin Management
Section titled “npm Plugin Management”Install
Section titled “Install”coden plugin install npm:@scope/coden-plugin-examplecoden plugin install npm:@scope/coden-plugin-example@^2 --globalcoden plugin remove @scope/coden-plugin-examplecoden plugin listcoden plugin sync- Default scope is project;
--globalinstalls into the user-global scope. - Specifiers accept only
npm:<package>ornpm:<package>@<version-or-tag>;https://registry.npmjs.orgis always used — private registries, Git, URLs, and local directory sources are unsupported. - Install validation imports the entry: top-level code runs with the current user’s permissions.
- Install/remove/upgrade require a CodeN restart;
/reloadre-reads local.tsplugins only.
Project files
Section titled “Project files”<workspace>/.coden/plugins.json # manifest (commit)<workspace>/.coden/plugin-runtime/.gitignore # excludes node_modules (commit)<workspace>/.coden/plugin-runtime/bun.lock # locked dependencies (commit)plugin-runtime/package.json is generated deterministically from plugins.json; node_modules/ is never committed. Global plugins live at $XDG_DATA_HOME/coden/plugins/ (default ~/.local/share/coden/plugins/) and are not part of the project repository.
coden plugin synccoden plugin sync --global- Project
syncrequiresplugin-runtime/bun.lockto exist, otherwise it reportsplugin.lock_missing. - Sync runs
bun installwith--frozen-lockfile: an outdated lock file reportsplugin.lock_outdated; update and commit the lock file. - Sync rebuilds the runtime and re-validates every plugin entry.
Lifecycle scripts
Section titled “Lifecycle scripts”| Behavior | Meaning |
|---|---|
| disabled by default | equivalent to bun install --ignore-scripts; preinstall/install/postinstall do not run |
--allow-scripts |
lets this package and transitive deps run scripts with user permissions; prints a warning and asks again |
--yes |
skips confirmations only, and never enables scripts on its own |
Listing and shadowing
Section titled “Listing and shadowing”coden plugin list prints project and global sections: package name, installed version, requested version, tool count. When the same package exists in both scopes, the project row is marked as shadowed (shadowed by project) and the global version is inactive.
Transactions and concurrency
Section titled “Transactions and concurrency”- Install/sync/remove commit transactionally (manifest + runtime backups with crash recovery).
- Only one transaction per scope at a time; concurrent operations report
plugin.install_busy(stale locks are cleaned automatically).
Runtime requirement
Section titled “Runtime requirement”Loading npm plugins requires only a built .js/.mjs entry (Node or Bun); install and sync run bun install internally and need Bun on PATH.
Related references
Section titled “Related references”Author Protocol
Section titled “Author Protocol”package.json requirements
Section titled “package.json requirements”{ "name": "@scope/coden-plugin-example", "version": "1.0.0", "type": "module", "files": ["dist"], "coden": { "apiVersion": 1, "plugin": "./dist/index.js" }}| Field | Requirement |
|---|---|
type |
must be "module" |
coden.apiVersion |
must be 1 |
coden.plugin |
a .js or .mjs path starting with ./; no .., \, ://, or whitespace |
| entry file | must publish built JS; publishing TypeScript source only is rejected |
| entry boundary | the resolved real path must stay inside the package directory |
Export shapes (pick one)
Section titled “Export shapes (pick one)”Single tool: default-export a ToolDefinition:
import type { ToolDefinition } from "@twinklerg/coden/plugin";
const tool: ToolDefinition = { name: "example_echo", description: "Echo supplied text", risk: "read", inputSchema: { type: "object", additionalProperties: false, required: ["text"], properties: { text: { type: "string" } }, }, async execute(input) { const { text } = input as { text: string }; return { content: text }; },};
export default tool;Multiple tools: default-export a CodeNPlugin whose name equals the npm package name:
import type { CodeNPlugin, ToolDefinition } from "@twinklerg/coden/plugin";
const readTool: ToolDefinition = { name: "example_read", description: "Read example data", risk: "read", inputSchema: { type: "object", additionalProperties: false }, async execute() { return { content: "read" }; },};
const plugin: CodeNPlugin = { apiVersion: 1, name: "@scope/coden-plugin-example", tools: [readTool],};
export default plugin;Validation rules
Section titled “Validation rules”| Check | Error on failure |
|---|---|
| export is not a tool or plugin object | plugin.export_invalid |
apiVersion is not 1 |
plugin.api_unsupported |
CodeNPlugin.name differs from the package name |
plugin.name_mismatch |
tools empty or containing invalid tools |
plugin.export_invalid |
tool name not matching ^[a-zA-Z][a-zA-Z0-9_-]{0,63}$ |
tool.invalid_name |
| name collides with an existing tool | tool.duplicate (local load) / plugin.tool_conflict (npm composition) |
| invalid inputSchema | tool.invalid_schema |
Public contract
Section titled “Public contract”@twinklerg/coden/pluginis the only public subpath; the main entry"."is not public andimport "@twinklerg/coden"is rejected.- Import
ToolDefinition/CodeNPlugintypes from that subpath; put@twinklerg/codenindevDependencies, andimport typeis erased at build time so no second copy loads at runtime. ToolContext.signalis anAbortSignal: the tsconfig must provide a lib defining it (such as@types/nodeor DOM).src/plugin/index.tsin the repository is the single source of the contract; the build emitsdist/plugin/index.jsanddist/plugin/index.d.tsand never publishessrc.