parmanu 0.4.14

Extensions

An extension is a TypeScript or JavaScript file that adds tools, slash commands and event handlers to the chat. parmanu runs it with Bun, so a .ts file needs no build step. anu run and anu eval never load extensions.

Where extensions come from

  1. ~/.anu/extensions/*.ts|js|mjs (skipped with --no-global).
  2. .anu/extensions/*.ts|js|mjs in a trusted project (anu trust).
  3. Each --extension <file> (or -e <file>).

--no-extensions skips 1 and 2 and keeps the -e files. /hooks lists what loaded.

An extension

ts
export default function (parmanu) {
  parmanu.registerTool({
    name: 'word_count',
    description: 'Counts the words in a text.',
    parameters: { type: 'object', properties: { text: { type: 'string' } }, required: ['text'] },
    readOnly: true,
    run: (args) => String(String(args.text).split(/\s+/).filter(Boolean).length),
  });

  parmanu.registerCommand('standup', {
    description: 'ask for a standup summary',
    run: () => parmanu.sendUserMessage('Summarize what changed in this repo today, in 5 bullets.'),
  });

  parmanu.on('tool_call', (e) => {
    if (e.name === 'bash' && /rm\s+-rf\s+\//.test(String(e.args.cmd))) return { block: 'not on this machine' };
  });
}

The API

  • parmanu.cwd: the project root.
  • parmanu.registerTool({ name, description, parameters?, readOnly?, run(args, { cwd }) }): a tool the model can call. run returns the text the model sees; a throw is an error result. The names of parmanu's own tools are taken.
  • parmanu.registerCommand(name, { description, run(arg) }): /name arg in the chat. Built-in command names are taken.
  • parmanu.notify(text, tone?): a note in the transcript (dim, yellow or red).
  • parmanu.sendUserMessage(text): sends a message as if the user typed it (after the running turn).
  • anu.exec(cmd, { timeoutMs? }): runs a shell command; resolves { code, stdout, stderr }.
  • parmanu.on(event, handler): handlers run in load order and may be async.
EventGetsMay return
session_start{ runId }nothing
input{ text }{ block } to stop the message, { text } to replace it
tool_call{ name, args }{ block } to stop the call, { args } to replace its arguments
tool_result{ name, args, out, ok }{ out } to change what the model sees
agent_end{ status, summary }nothing

Any other event name is a ledger record type (edit, check, compact, ...), and ledger gets every record. These handlers see the record and are not awaited.

Extension handlers run before hook commands. A handler that throws turns its extension off for the session, with a red note; the chat goes on.

Extensions run with your permissions, like any program you install. Only load files you trust.

This page is built from docs/extensions.md in parmanu 0.4.14.