|
| 1 | +# PAI (Personal AI) |
| 2 | + |
| 3 | +**Agent Name:** PAI |
| 4 | +**Plugin:** `opencode-pai-plugin` |
| 5 | +**Type:** Core Infrastructure |
| 6 | + |
| 7 | +## Description |
| 8 | +PAI is the core Personal AI Infrastructure agent implemented by this plugin. It serves as the primary interface for the OpenCode environment, managing session context, logging, and user interactions. |
| 9 | + |
| 10 | +## Capabilities |
| 11 | +- **Context Management:** Automatically loads the `core/SKILL.md` file from the user's skills directory at the start of each session, injecting it as the core system prompt. |
| 12 | +- **Event Logging:** Logs all session events, tool calls, and message updates to the `.opencode/history/raw-outputs` directory for audit and debugging purposes. |
| 13 | +- **Session Status:** Updates the terminal tab title to reflect the current activity or thought process of the agent. |
| 14 | +- **Session Summarization:** Generates a summary of the session in `.opencode/history/sessions` when a session ends (if configured). |
| 15 | + |
| 16 | +## Configuration |
| 17 | +The agent's behavior contains some configurable elements via environment variables or file templates: |
| 18 | + |
| 19 | +| Configuration | Description | |
| 20 | +| :--- | :--- | |
| 21 | +| `core/SKILL.md` | The core system prompt/skill definition file located in `.opencode/skills/core/SKILL.md`. | |
| 22 | +| `USER_NAME` | Environment variable to override the user's name (default: "Engineer"). | |
| 23 | + |
| 24 | +## Codebase Structure |
| 25 | +- `src/index.ts`: The plugin entry point. It defines the `PAIPlugin` export and sets up hooks for event listening (`event`, `chat.message`, `tool.execute.after`). |
| 26 | +- `src/lib/context-loader.ts`: Responsible for reading and processing the `core/SKILL.md` file, injecting environment variables. |
| 27 | +- `src/lib/logger.ts`: Implements a buffering JSONL logger. It captures events and tool outputs, writing them to `raw-outputs/{session-id}.jsonl`. It handles file creation and flushing. |
| 28 | +- `src/lib/notifier.ts`: A utility to send POST requests to a local voice server (defaulting to `localhost:8888`). It fails gracefully (silently ignores errors) if the server is not unreachable. |
| 29 | +- `src/lib/paths.ts`: Contains helper functions for resolving paths (`getHistoryDir`, `getRawOutputsDir`, `getSkillsDir`) and handling environment variable expansion in paths. |
0 commit comments