Plugins

Put .js files in .oi/plugins/ (project) or ~/.config/oi/plugins/, or pass --plugin. Each plugin runs in its own JSRuntime with a byte-capped allocator (plugin_mem_mb, default 128) and a 30 s limit per synchronous slice.

oi.registerTool({ name: "word_count", description: "Count words", deferred: true,
  input_schema: { type: "object", properties: { text: { type: "string" } } } },
  async ({ text }) => `${text.split(/\s+/).length} words`);       // string | {content, is_error}

oi.on("before_tool", ({ name, input }) => {                       // policy: deny or rewrite input
  if (name === "bash" && /rm -rf/.test(input.command)) return { deny: "not here" };
});
oi.on("before_model", ({ messages }) => { /* return { messages } to transform context */ });
oi.on("after_tool", ({ name, content }) => name === "bash" ? { append: "remember to run the tests" } : undefined);
oi.registerPrompt("style", "Answer briefly.");
oi.registerCommand({ name: "fix-issue", argument_hint: "<number>", prompt: "Fix GitHub issue #$1 and add a test." });
const r = await oi.tools.call("bash", { command: "git status" }); // gated like any other call

Hooks: before_model, before_tool, after_tool, user_prompt, session_start, stop and notification (see Hooks). Every registration is tagged with the plugin's handle. Unloading or reloading (/reload in the REPL) sweeps that plugin's tools, hooks, prompts, commands and agent profiles, then frees the runtime; the unit tests assert that 0 bytes remain charged to it. Hooks can only make a call stricter: the capability gate still runs on whatever input survives them. A hook that throws blocks the call (fail-closed). Examples: tests/fixtures/plugins/.

Replay

oi replay <session> [--plugin a.js] --vs b.js re-runs the recorded branch open-loop. Model turns and tool results come from the recording, so nothing executes. It reports context sent, the largest request, system prompt size, policy blocks, compactions, and the first model call where the two variants' contexts diverge.

Sub-agents: by default a recorded agent call is answered with its recorded report, and recorded background reports arrive where they did. --deep re-runs each sub-agent's loop too, fed from that child's own recorded session, so plugin policy and context transforms are compared inside children as well.