Skip to content

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.

{
"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

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;
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
  • @twinklerg/coden/plugin is the only public subpath; the main entry "." is not public and import "@twinklerg/coden" is rejected.
  • Import ToolDefinition/CodeNPlugin types from that subpath; put @twinklerg/coden in devDependencies, and import type is erased at build time so no second copy loads at runtime.
  • ToolContext.signal is an AbortSignal: the tsconfig must provide a lib defining it (such as @types/node or DOM).
  • src/plugin/index.ts in the repository is the single source of the contract; the build emits dist/plugin/index.js and dist/plugin/index.d.ts and never publishes src.
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.

  • 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 risk affects 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 .ts plugins load through a data: URL and cannot load under a Node runtime (see the Runtime capability matrix).
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
  • 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.
  1. Install from trusted sources only; review what ships (npm pack --dry-run, lock-file diffs).
  2. Keep lifecycle scripts disabled by default; enable --allow-scripts explicitly and inspect the dependency tree when needed.
  3. Commit the plugin manifest and bun.lock; never commit node_modules.
  4. In sensitive repositories, confirm workspace content before trusting project plugins/hooks.
  5. Do not leave untrusted plugins in the global scope (global plugins are not re-confirmed).