Ray's Knowledge Base

pi and omp extension events for compaction, shutdown and commands

FactVerified 27 Sep 2026Holds anywhere
Fact. A statement and the evidence for it.

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 has branchEntries, customInstructions and reason (manual, threshold or overflow);
  • run at the end with pi.on("session_shutdown", ...); the event has reason (quit, reload, new, resume, fork). omp stops a session_shutdown handler 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 with pi.sendUserMessage(text).
  • add a tool the model can call with pi.registerTool({ name, label, description, promptSnippet, parameters, execute }). parameters is a TypeBox schema; pi aliases typebox for extensions and omp bundles it, so import { Type } from "typebox" works, and Type.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 as session_stop are 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.