2.7 KiB
2.7 KiB
packages/pi/
Publishable npm package for the OpenPets Pi coding-agent integration.
Responsibility
- Exposes
@open-pets/pias a Pi package with a Pi extension resource. - Maps Pi session/tool activity to safe OpenPets reactions through
@open-pets/client. - Registers a user slash command namespace,
/openpets, for status, test, react, and say commands. - Keeps MVP behavior default-pet-only and non-blocking; no Pi model-callable tools are registered.
Design/Patterns
- Package structure: Standard npm package with
main/typespointing todist/index.js, Pi extension declared inpi.extensionsarray. - Dual exports: Main package exports (
index.ts) and dedicated extension entry (extension.ts) for Pi loader consumption. - Peer dependency: Declares optional peer dependency on
@earendil-works/pi-coding-agentfor type safety without hard coupling. - Fire-and-forget scheduling: All automatic event handlers use non-blocking scheduling with swallowed IPC failures to prevent Pi execution disruption.
- Privacy-first: Prompt text, assistant text, tool output, command output, file paths, URLs, and secrets are never forwarded to OpenPets.
Flow
Pi extension loader
-> packages/pi/src/extension.ts
-> packages/pi/src/runtime.ts
-> @open-pets/client
-> OpenPets desktop local IPC
Automatic event flow:
- Pi emits lifecycle events (
session_start,agent_start,turn_start, etc.) extension.tsreceives event viaapi.on()and wraps inPiEventEnveloperuntime.tsclassifies event to determine appropriate reaction- Reaction dispatched to OpenPets client via scheduled non-blocking call
- IPC failures logged (if debug enabled) but never thrown to Pi
Command flow:
- User types
/openpets <command>in Pi registerCommand()handler invoked with args stringparseOpenPetsCommand()validates and structures commandexecuteCommand()performs synchronous OpenPets client calls- UI notifications sent via
ctx.ui.notify()
Integration
- Upstream: Consumes
@open-pets/agent-eventsfor speech validation and@open-pets/clientfor IPC. - Downstream: Pi coding agent loads extension via
pi.extensionsmanifest entry. - Desktop: Communicates with OpenPets desktop app through local socket IPC (via
@open-pets/client). - Commands:
/openpets status,/openpets test,/openpets react <reaction>,/openpets say <message>.
Safety notes
- Automatic events use reactions and fixed message pools only.
- Prompt text, assistant text, tool output, command output, file paths, URLs, and secrets are not forwarded.
- OpenPets IPC failures are swallowed by automatic event handlers so Pi execution continues.