Skip to content

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.

  1. At startup, local and npm plugin exports are validated before registration; invalid or duplicate tools cannot replace an existing tool.
  2. Every model step sends the current registry’s names, descriptions, and inputSchema values to the provider.
  3. The model returns a structured tool call. CodeN runs PreToolUse first; if a Hook updates input, schema, path, risk, and permission checks run again.
  4. After approval, the executor gives the tool its input and a ToolContext containing an AbortSignal. Timeout and cancellation guarantee signal delivery only; an in-process plugin must cooperate to stop.
  5. 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.
  6. PostToolUse or PostToolUseFailure observes the result, while the whole user turn remains bounded by maxSteps and 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.

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.

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)

These command fragments escalate bash risk to dangerous:

rm -r / rm --recursive
sudo
git reset --hard
git clean -f
git push --force / --force-with-lease
git checkout -- <path>
git restore
mkfs / fdisk / dd
killall / pkill
curl|sh or wget|sh
path contains /etc /usr /bin /sbin

Risk classification is a heuristic guard against mistakes, not a security sandbox: bash and plugins run with the current user’s process permissions.

  • Tools registered by local or npm plugins use their declared risk field 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 AbortSignal cancellation.
{
"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.