|
| 1 | +# PI Handler |
| 2 | + |
| 3 | +Implements the PI block executor. Each sub-mode delegates to a dedicated backend while sharing common infrastructure. |
| 4 | + |
| 5 | +## Folder layout |
| 6 | + |
| 7 | +``` |
| 8 | +pi/ |
| 9 | +├── pi-handler.ts # Single dispatcher — reads the block's mode and routes to the correct backend |
| 10 | +├── core/ # Shared contracts and infrastructure |
| 11 | +│ ├── backend.ts # Base backend interface and shared execution logic |
| 12 | +│ ├── context.ts # Request context type passed to every backend |
| 13 | +│ ├── events.ts # Streaming event helpers |
| 14 | +│ ├── keys.ts # API-key resolution utilities |
| 15 | +│ ├── pi-sdk.ts # Thin wrapper around the PI SDK client |
| 16 | +│ └── redaction.ts # Secret redaction for logs and responses |
| 17 | +├── cloud/ # Cloud mode — GitHub-hosted sandboxes |
| 18 | +│ ├── shared.ts # Shared GitHub and sandbox utilities (repo helpers, polling, etc.) |
| 19 | +│ ├── github-pr.ts # Low-level GitHub PR API wrappers |
| 20 | +│ ├── authoring/ # Create PR and Update PR implementation |
| 21 | +│ │ └── backend.ts |
| 22 | +│ ├── review/ # Review Code implementation |
| 23 | +│ │ ├── backend.ts |
| 24 | +│ │ ├── tools.ts # Tool definitions injected into the review agent |
| 25 | +│ │ └── tools-script.ts |
| 26 | +│ └── babysit/ # PR review / check continuation (babysit mode) |
| 27 | +│ ├── backend.ts |
| 28 | +│ ├── github.ts # GitHub status/check polling helpers |
| 29 | +│ └── round.ts # Single babysit iteration logic |
| 30 | +├── local/ # Local Dev mode — SSH-connected local machine |
| 31 | +│ ├── backend.ts |
| 32 | +│ ├── sim-tools.ts # Sim-side tool implementations |
| 33 | +│ └── ssh-tools.ts # SSH tool implementations |
| 34 | +└── search/ # Shared search support used across modes |
| 35 | + ├── tool.ts # Search tool definition |
| 36 | + ├── normalize.ts # Result normalisation |
| 37 | + └── extension-source.ts # Extension-based source adapter |
| 38 | +``` |
| 39 | + |
| 40 | +## Dispatch flow |
| 41 | + |
| 42 | +`pi-handler.ts` is the sole entry point registered in the executor. It inspects the block's `mode` field and calls the matching backend's `run()` method. All backends receive a typed `PiContext` (from `core/context.ts`) and stream incremental events back through `core/events.ts`. |
0 commit comments