Omp hooks

From phatblat/dotfiles · View interactive version

Omp hooks is an AI agent skill from the GitHub repository phatblat/dotfiles. Use when writing, debugging, or configuring an omp hook or extension (ExtensionAPI or legacy HookAPI). Not for Claude Code hooks or the shared harness safety guard.

How to use this skill

Skill file

omp Hooks and Extensions

Disambiguation — three different hook systems

This machine runs three unrelated things called "hooks". Confirm which one the

task means before editing anything:

| System | Lives in | Shape |

|---|---|---|

| omp hooks/extensions (this skill) | ~/.omp/agent/extensions/, <cwd>/.omp/extensions/ | TS/JS module, default-exported factory |

| Claude Code hooks | ~/.claude/settings.json hooks | JSON event → shell command |

| Shared harness guard | ~/.agents/harness/hooks/ | Normalized cross-harness deny policy |

Use `ExtensionAPI`, not `HookAPI`

HookAPI is the legacy API. The runtime now initializes the extension

runner: --hook is an alias for --extension, discovered .ts/.js hook

factories load as extension modules, and tools are wrapped by

ExtensionToolWrapper rather than HookToolWrapper.

ExtensionAPI is a superset — same event model, plus extension-only events

(tool_execution_*, input, user_bash, user_python, mcp_notification,

before_provider_request, session_stop, …), tool/command/renderer/provider

registration.

Write new work against ExtensionAPI. Reach for HookAPI only when

maintaining an existing hook module.

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

export default function myExtension(pi: ExtensionAPI) {
  pi.on("tool_call", async (event, ctx) => {
    if (event.toolName !== "bash") return;
    if (!/\brm\s+-rf\s+\//.test(String(event.input.command ?? ""))) return;
    return { block: true, reason: "rm -rf / blocked by policy" };
  });
}

The default export must be a function (not a class). It may return a

promise; the loader awaits it.

The two contracts you will use most

Block or rewrite a tool call — `tool_call`

Returns { block?, reason?, input? }.

short-circuits). reason becomes the error text the model sees.

incidental exceptions through unless blocking is what you want.

each other's revisions (last non-blocking return wins), it is ignored when

block is true, and it never applies to computer calls.

Patch a tool result — `tool_result`

Returns { content?, details?, isError? }.

each handler sees prior handlers' modifications. Under HookAPI every

handler sees the original event and the last return wins.

the original error is rethrown after handlers run.

Reshape context — `context`

Returns { messages? }, fires before each LLM call, chained (each handler

receives the previous handler's output). Return nothing to pass through.

Where modules live and what wins

Load order, deduped by absolute path, first seen wins:

  1. Native auto-discovered — <cwd>/.omp/extensions, ~/.omp/agent/extensions
  2. Discovered .ts/.js hook-capability factories
  3. Installed plugin entries (package.json omp.extensions)
  4. Explicit configured paths — CLI -e/--extension/--hook first, then

settings extensions

A module both auto-discovered and explicitly configured loads once, at the

auto-discovered position.

Config (user ~/.omp/agent/config.yml, project <cwd>/.omp/config.yml):

extensions:
  - ~/my-exts/safety.ts
  - ./local/ext-pack
disabledExtensions:
  - extension-module:foo # derived from entry path: /x/foo.ts -> foo

Disable controls: --no-extensions (explicit -e/--hook paths still load),

disabledExtensions by capability id. Full precedence, profile paths, and

directory-resolution rules are in references/configuration.md.

Pitfalls that actually bite

from the factory throws ExtensionRuntimeNotInitializedError. Register in

the factory; act from events, commands, and tools.

setInterval/setTimeout/detached-promise callback that throws escapes

handler dispatch, becomes an uncaughtException, and the postmortem handler

tears down the whole session. Use ctx.setInterval / ctx.setTimeout /

ctx.clearTimer: same signatures, contained failures, unref'd, and cleared

on session_shutdown.

(com.example.my-ext.state) and avoid core-reserved values.

gitignore: true, hidden: false; explicit configured-directory scanning uses

readdir and applies no gitignore filtering.

subdirectory; index.ts wins over index.js.

reserved shortcuts (ctrl+c, escape, enter, …) are ignored.

subagent modes.

References

disable ids, layout examples

Authoritative upstream docs ship with the installed omp and are version-matched;

read them directly rather than trusting the website (which is a client-rendered

SPA and returns no content to a fetch):

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.