# Pi Integration

## Setup

1. Install the extension file to your Pi extensions directory (copy or symlink):
   ```bash
   mkdir -p ~/.pi/agent/extensions

   # copy
   cp pi/extensions/agent-hooks-logger.ts ~/.pi/agent/extensions/agent-hooks-logger.ts

   # or symlink (recommended while developing)
   ln -sfn "$(pwd)/pi/extensions/agent-hooks-logger.ts" ~/.pi/agent/extensions/agent-hooks-logger.ts
   ```

2. Ensure Pi can access the project root:
   ```bash
   export GIT_ROOT=$(pwd)
   ```

3. Restart Pi to load the extension

## Extension Architecture

The Pi integration uses TypeScript extensions that subscribe to Pi lifecycle events:

- **File**: `pi/extensions/agent-hooks-logger.ts`
- **Event System**: Pi's built-in extension event API
- **Logging**: Via CLI `npm run log` command

## Trigger Events

After the extension is loaded:
- **session_start** triggers when Pi starts a new session
- **tool_call** triggers when Pi executes any tool

## Event Details

### session_start
- Captures session initialization
- Includes session context and metadata
- Logged as "Pi session started"

### tool_call
- Captures tool execution
- Includes tool name and execution details
- Logged as "Tool called: {toolName}"

## Verify

After using Pi:
```bash
npm run summary
```

Expected: Pi events logged in the summary with `source: "extension"`.

## Technical Notes

- The extension uses Pi's `ExtensionContext` API for event subscriptions
- Events are logged asynchronously via the CLI logger
- Uses `GIT_ROOT` environment variable for path resolution
- Extension handles errors gracefully with console warnings