feat(pi): add hooks support via generated TypeScript extension#2324
Merged
Conversation
Pi Coding Agent has no static hooks config; bridge canonical hooks by generating a rulesync-owned TypeScript extension in Pi's extension discovery paths (.pi/extensions/rulesync-hooks.ts project-scope, ~/.pi/agent/extensions/rulesync-hooks.ts global-scope), following the OpenCode/Kilo generated-plugin precedent. - map canonical events to Pi extension events (sessionStart -> session_start, sessionEnd -> session_shutdown, preToolUse -> tool_call, postToolUse -> tool_result, preModelInvocation -> context, beforeSubmitPrompt -> input, stop -> agent_end, preCompact -> session_before_compact) - honor hook matchers as regexes tested against event.toolName on tool events; embed commands/matchers via JSON.stringify for safe codegen - the generated extension observes events only (no block/mutate) and executes command hooks via the platform shell - register pi in the hooks processor and target tuple, add unit tests (including loading the generated module via tsx and asserting the registered subscriptions), extend the hooks e2e matrix, and update docs/tables/gitignore Closes #2319 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… stop mapping note Applies review feedback: the repo coding guidelines require object arguments for multi-parameter functions, and the CANONICAL_TO_PI_EVENT_NAMES docstring now notes the agent_end vs agent_settled trade-off for the canonical stop event. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
pias a hooks target. Pi Coding Agent has no static hooks config file; instead it exposes an extension API with lifecycle events, so rulesync bridges canonical hooks by generating a rulesync-owned TypeScript extension — following the existing OpenCode/Kilo generated-plugin precedent:.pi/extensions/rulesync-hooks.ts(project scope)~/.pi/agent/extensions/rulesync-hooks.ts(global scope)Both paths are Pi's documented extension discovery locations (extensions.md).
Event mapping
Only canonical events with a semantically faithful Pi extension event are mapped (
CANONICAL_TO_PI_EVENT_NAMES):sessionStartsession_startsessionEndsession_shutdownpreToolUsetool_callpostToolUsetool_resultpreModelInvocationcontextbeforeSubmitPromptinputstopagent_endpreCompactsession_before_compactHook
matchers are honored as regexes tested againstevent.toolNameon the tool events, matching the OpenCode plugin semantics. Commands and matchers are embedded viaJSON.stringifyso arbitrary quoting/backslashes cannot break the generated code. The generated extension observes events only — command hooks run (via the platform shell throughnode:child_process) but never block or mutate Pi events. Import is unsupported (supportsImport: false), same as OpenCode/Kilo, since arbitrary extension code cannot be parsed back into the canonical schema.Scope / conventions checklist
piadded tohooksProcessorToolTargetTupleand registered inhooks-processor.ts(project + global scope)tsxand asserts the registered subscriptionsdocs/reference/file-formats.mdprose updated; supported-tools tables and.gitignoreregeneratedTest plan
pnpm cicheck(green)npx vitest run --config vitest.e2e.config.ts src/e2e/e2e-hooks.spec.ts(66 tests green)rulesync generatewith api-targetedrulesync.jsoncproduces a loadable extension with correct mappings, matcher gating, andpi.hooksoverride mergeCloses #2319
🤖 Generated with Claude Code