pi and omp extension events for compaction, shutdown and commands
Statement#
In pi 0.87 (@earendil-works/pi-coding-agent) and omp, an extension can:
- run before compaction with
pi.on("session_before_compact", ...); the event hasbranchEntries,customInstructionsandreason(manual,thresholdoroverflow); - run at the end with
pi.on("session_shutdown", ...); the event hasreason(quit,reload,new,resume,fork). omp stops asession_shutdownhandler after 2 s; - get the session file with
ctx.sessionManager.getSessionFile()(undefined for an ephemeral session); - add a slash command with
pi.registerCommand(name, { description, handler: async (args, ctx) => ... })and send text as a user message withpi.sendUserMessage(text). - add a tool the model can call with
pi.registerTool({ name, label, description, promptSnippet, parameters, execute }).parametersis a TypeBox schema; pi aliasestypeboxfor extensions and omp bundles it, soimport { Type } from "typebox"works, andType.Unsafe(jsonSchema)wraps a plain JSON Schema.execute(id, params, signal, onUpdate, ctx)returns{ content: [{ type: "text", text }], details }; throwing from it gives the model an error result. - type the extension with
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent"; omp-only events such assession_stopare not in those types.
pi and omp write the same session format: JSONL entries with type: "message" and message.role user, assistant or toolResult; a bash result ends with Command exited with code N when it failed.
Evidence#
The tool facts come from dist/core/extensions/types.d.ts, docs/extensions.md ("Throw from execute() to produce a failed tool result") and extensions/loader.js of pi 0.87.1; rkb's extension registers its four tools this way and type-checks against these types. Read dist/core/extensions/types.d.ts in ~/.pi/agent/install/releases/0.87.1/node_modules/@earendil-works/pi-coding-agent, the omp binary strings, and the pi-llm-wiki source (the 2 s omp limit, issue #263 there). The rkb extension test drives these events for both harnesses.