Tool Plugin Execution Model
Tool plugins are CodeN’s signature extension point. Once loaded, their tools join built-ins in the registry; the registry exposes names, descriptions, and input schemas; the model produces calls; the executor runs Hooks, validation, and permissions; and plugin results return to the agent loop as tool messages. risk participates in approval policy but does not restrict plugin process privileges.
Call path
Section titled “Call path”- At startup, local and npm plugin exports are validated before registration; invalid or duplicate tools cannot replace an existing tool.
- Every model step sends the current registry’s names, descriptions, and
inputSchemavalues to the provider. - The model returns a structured tool call. CodeN runs
PreToolUsefirst; if a Hook updates input, schema, path, risk, and permission checks run again. - After approval, the executor gives the tool its input and a
ToolContextcontaining anAbortSignal. Timeout and cancellation guarantee signal delivery only; an in-process plugin must cooperate to stop. - A success or error is truncated to the runtime limit and recorded as a tool message. The agent uses that result in its next model request; CodeN does not interpret it in place of the model.
PostToolUseorPostToolUseFailureobserves the result, while the whole user turn remains bounded bymaxStepsand the Stop Hook.
This path explains why plugins are both powerful and sensitive: they enter the model’s decision surface and the machine’s execution surface.
Tools and Risk Levels
Section titled “Tools and Risk Levels”Built-in tools
Section titled “Built-in tools”| Tool | Risk | Input highlights | Key behavior |
|---|---|---|---|
read |
read |
path, offset (default 1), limit (default 500, max 2000) |
Reads UTF-8 text by 1-based line offset; output capped at 50000 chars with an omission notice; opens with O_NOFOLLOW |
write |
modify |
path, content |
Creates or fully overwrites; file mode 0600; creates parent directories |
edit |
modify |
path, oldText, newText |
Replaces the unique matching block exactly; returns edit.multiple_matches when not unique and edit.no_match when absent |
bash |
modify (can escalate to dangerous) |
command, timeout (default 30000, range 100–60000), maxOutput (default 30000, range 1000–100000) |
Runs bash -lc with the workspace as cwd; non-zero exit, timeout, or cancellation are errors; timeout kills the process group |
activate_skill |
read |
name |
Loads the full instructions and root of a skill by name; unknown names return skill.not_found; reads only the discovered entry file after verifying its content is unchanged |
Tools execute sequentially in the model’s returned order; a single call times out after 60 seconds (cooperative cancellation only). All tool output is truncated to 50000 characters before re-entering context.
Risk levels and authorization
Section titled “Risk levels and authorization”| Level | Default interactive mode | --smart-approve |
--auto |
|---|---|---|---|
read |
auto-allowed | auto-allowed | auto-allowed |
modify |
human confirmation (y/s/N) |
LLM review, escalating to human on uncertainty | auto-allowed |
dangerous |
human confirmation (y/N only, no session grant) |
human confirmation | auto-allowed (hook deny still applies) |
Dangerous-command detection (bash)
Section titled “Dangerous-command detection (bash)”These command fragments escalate bash risk to dangerous:
rm -r / rm --recursivesudogit reset --hardgit clean -fgit push --force / --force-with-leasegit checkout -- <path>git restoremkfs / fdisk / ddkillall / pkillcurl|sh or wget|shpath contains /etc /usr /bin /sbinRisk classification is a heuristic guard against mistakes, not a security sandbox: bash and plugins run with the current user’s process permissions.
Plugin tools
Section titled “Plugin tools”- Tools registered by local or npm plugins use their declared
riskfield and join the same authorization flow. - Tool names must match
^[a-zA-Z][a-zA-Z0-9_-]{0,63}$; name collisions (including with built-ins) skip the whole plugin. - Plugin tools share the same 60-second timeout and cooperative
AbortSignalcancellation.
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.