Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/badlogic/pi-mono/llms.txt

Use this file to discover all available pages before exploring further.

The ExtensionAPI interface provides extensions with methods to interact with the agent, register tools and commands, and respond to events.

Import

import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";

Interface

Extensions receive the ExtensionAPI through the ExtensionContext when they are initialized.
export interface Extension {
  init(context: ExtensionContext): Promise<void> | void;
}

interface ExtensionContext {
  api: ExtensionAPI;
  actions: ExtensionActions;
}

Methods

registerTool

Register a custom tool that the agent can invoke.
registerTool(tool: ToolDefinition): void
tool
ToolDefinition
required

registerCommand

Register a slash command that users can invoke.
registerCommand(command: RegisteredCommand): void
command
RegisteredCommand
required

on

Subscribe to extension events.
on<T extends ExtensionEvent>(type: T['type'], handler: ExtensionHandler<T>): void
type
string
required
Event type to subscribe to (e.g., “tool_call”, “session_start”)
handler
function
required
Event handler function
Available Events:
  • agent_start / agent_end - Agent turn lifecycle
  • tool_call / tool_result - Tool invocation
  • session_start / session_shutdown - Session lifecycle
  • session_compact / session_fork / session_switch - Session operations
  • input - User input events
  • turn_start / turn_end - Turn boundaries

exec

Execute a bash command.
exec(command: string, options?: ExecOptions): Promise<ExecResult>
command
string
required
The bash command to execute
options
ExecOptions
ExecResult
object

showDialog

Display a dialog to the user (TUI only).
showDialog(options: ExtensionUIDialogOptions): Promise<string | undefined>
options
ExtensionUIDialogOptions
required

showWidget

Show a persistent widget in the footer (TUI only).
showWidget(options: ExtensionWidgetOptions): void
options
ExtensionWidgetOptions
required

Example

import type { Extension, ExtensionContext } from "@mariozechner/pi-coding-agent";
import { Type } from "@sinclair/typebox";

export const myExtension: Extension = {
  async init(context: ExtensionContext) {
    const { api } = context;
    
    // Register a custom tool
    api.registerTool({
      name: "get_time",
      label: "Get Time",
      description: "Get the current time",
      parameters: Type.Object({}),
      execute: async () => {
        return {
          content: [{ type: "text", text: new Date().toISOString() }],
          details: {},
        };
      },
    });
    
    // Register a slash command
    api.registerCommand({
      name: "time",
      description: "Insert current time",
      shortcut: "ctrl+t",
      handler: async (ctx) => {
        const time = new Date().toISOString();
        await ctx.actions.sendMessage(time);
      },
    });
    
    // Subscribe to events
    api.on("tool_call", (event) => {
      console.log(`Tool called: ${event.toolName}`);
    });
  },
};

ExtensionActions

The ExtensionActions interface provides methods for modifying agent state.

sendMessage

Send a user message to the agent.
sendMessage(text: string): Promise<void>

setModel

Change the active model.
setModel(model: Model, thinkingLevel?: ThinkingLevel): void

setThinkingLevel

Change the thinking level.
setThinkingLevel(level: ThinkingLevel): void

setActiveTools

Set which tools are currently active.
setActiveTools(toolNames: string[]): void

Build docs developers (and LLMs) love