Plugin Authoring
Plugin authors target one narrow public contract: @twinklerg/coden/plugin. Tool names, risk, JSON Schema, results, and cancellation cooperation must be precise, and package entries must be built ESM. Public types support compatibility but do not place plugins in an isolated runtime.
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.
Related references
Section titled “Related references”Trust and Security Boundaries
Section titled “Trust and Security Boundaries”Trust model
Section titled “Trust model”| Type | Trust trigger |
|---|---|
project local plugins (.coden/plugins/*.ts, --plugin directories) |
human workspace confirmation on first load |
| project npm plugins | recorded after plugin install/plugin sync confirmation; skipped and flagged at startup when untrusted |
| user local plugins | no confirmation (the current user installed them) |
| global npm plugins | no startup confirmation (user-initiated install) |
Confirmation accepts only y (--yes affects plugin commands only, never workspace trust). Trust records store the workspace real path (trusted-workspaces.json, 0600); symlink aliases cannot bypass it.
Permission boundaries
Section titled “Permission boundaries”- Plugins are not a sandbox: they run inside the CodeN main process with full user process permissions, reaching files, network, environment variables, and subprocesses.
- Tool
riskaffects call confirmations only and provides no process isolation. - Install validation imports the plugin entry: even with lifecycle scripts disabled, top-level code and static dependencies run with the current user’s permissions.
- Local
.tsplugins load through adata:URL and cannot load under a Node runtime (see the Runtime capability matrix).
Lifecycle scripts
Section titled “Lifecycle scripts”| Option | Behavior |
|---|---|
| default | --ignore-scripts; lifecycle scripts do not run |
--allow-scripts |
this package and its transitive deps run preinstall/install/postinstall with user permissions; warns and confirms again first |
Paths and validation
Section titled “Paths and validation”- npm entries must resolve inside the package directory and pass safe realpath resolution (
withinBoundary+safeRealpath). - Local plugin directory trust is based on the real path; directories/files pass authenticity checks.
- Schema compile failures, tool name collisions, and invalid exports skip that plugin only, leaving other plugins and built-ins unaffected.
Integration guidance
Section titled “Integration guidance”- Install from trusted sources only; review what ships (
npm pack --dry-run, lock-file diffs). - Keep lifecycle scripts disabled by default; enable
--allow-scriptsexplicitly and inspect the dependency tree when needed. - Commit the plugin manifest and
bun.lock; never commitnode_modules. - In sensitive repositories, confirm workspace content before trusting project plugins/hooks.
- Do not leave untrusted plugins in the global scope (global plugins are not re-confirmed).