Skip to content

⛰️ LifeOS — The AI-powered Life Operating System that helps you hill climb to wherever you're going.

docs: add detailed architecture and installation guide to README

riskcomplexx581d460948c1
diff --git a/README.md b/README.md
index 5fe9616e..bcb3c6ce 100644
--- a/README.md
+++ b/README.md
@@ -222,6 +222,84 @@ The packs are extracted from Kai - real capabilities that have been running in p
---
+## How PAI Works
+
+This section explains the technical architecture, installation process, and runtime mechanics of the Personal AI Infrastructure (PAI) system.
+
+### 1. High-Level Architecture
+
+PAI is not a standalone application but a **configuration and automation layer** that sits on top of **Claude Code** (Anthropic's CLI agent). It transforms a generic AI agent into a personalized system with persistent memory, security controls, and defined skills.
+
+The architecture consists of three main layers:
+
+1. **The Engine (Claude Code)**: The underlying AI agent that executes commands and processes prompts.
+2. **The Middleware (Hooks)**: A system of event listeners that intercept Claude Code's operations (like tool use, session start) to enforce security, inject context, and log activity.
+3. **The Content (Packs)**: Modular bundles of markdown files and scripts that define "Skills" (workflows), "Tools" (executable code), and "Identity" (system prompts).
+
+### 2. The Hook System (The "Magic")
+
+The core mechanism that makes PAI work is the **Hook System**. Claude Code has a native capability to run scripts when certain events occur. PAI leverages this to inject its logic.
+
+**How Hooks Work:**
+1. **Configuration**: Hooks are registered in `~/.claude/settings.json`. This file maps events (like `PreToolUse`) to specific scripts.
+2. **Events**:
+ * `SessionStart`: Fires when you open Claude Code. PAI uses this to load your "CORE" skill and context.
+ * `PreToolUse`: Fires before the AI runs a command (e.g., `bash`, `edit`). PAI uses this for **Security Validation** (blocking `rm -rf`, etc.).
+ * `PostToolUse`: Fires after a command. Used for logging and observability.
+ * `UserPromptSubmit`: Fires when you type a message. Used to update terminal tab titles.
+3. **Execution**: When an event fires, Claude Code runs the corresponding TypeScript script (using `bun`) located in `~/.claude/hooks/`.
+4. **Communication**: The script receives event data via `stdin` (JSON) and can control the outcome (e.g., allow or block a command) via exit codes or `stdout`.
+
+### 3. Installation Process
+
+The installation is a two-phase process: **Bootstrapping** (Manual) and **Pack Installation** (AI-Driven).
+
+**Phase 1: Bootstrapping (The `install.ts` script)**
+The user runs `bun run Bundles/Kai/install.ts`. This script **does not** install the full system. Instead, it:
+1. **Creates Directory Structure**: Sets up `~/.claude/` (or `$PAI_DIR`) with folders for `skills`, `hooks`, `history`, etc.
+2. **Generates Config Files**: Creates `SKILL.md`, `Contacts.md`, and `CoreStack.md` with user preferences (name, timezone).
+3. **Sets Environment Variables**: Updates `.zshrc` or `.bashrc` with `DA` (Assistant Name), `PAI_DIR`, etc.
+4. **Updates `settings.json`**: Injects environment variables into Claude Code's settings.
+
+**Crucially, this phase does not install the hooks or skills.** It prepares the environment for the AI to do it.
+
+**Phase 2: Pack Installation (AI-Driven)**
+The user is instructed to "give each pack file to your AI". This is where the actual installation happens.
+1. **User Action**: The user pastes the content of a pack file (e.g., `Packs/kai-hook-system.md`) into Claude Code.
+2. **AI Execution**: The pack file contains natural language instructions and code blocks. The AI reads these instructions and:
+ * **Writes Files**: Creates the TypeScript hook files (e.g., `hooks/security-validator.ts`) and skill definitions.
+ * **Configures System**: Updates `settings.json` to register the new hooks.
+ * **Verifies**: Runs verification commands to ensure the pack is working.
+
+This "Inception-style" installation (using the AI to build the AI's infrastructure) ensures that the system is self-documenting and the AI "knows" about its own components.
+
+### 4. Runtime Flow
+
+Here is what happens when you use PAI:
+
+1. **Start**: You run `claude`.
+2. **Initialization (`SessionStart`)**:
+ * Claude Code fires `SessionStart`.
+ * `hooks/initialize-session.ts` runs.
+ * `hooks/load-core-context.ts` runs. It reads `skills/CORE/SKILL.md` and injects it into the context. Now the AI knows who it is and what skills it has.
+3. **User Interaction**: You ask "Create a new blog post".
+4. **Routing**: The AI (guided by the injected `SKILL.md`) recognizes this matches a skill (e.g., `CreateContent`). It loads the specific workflow for that skill.
+5. **Execution (`PreToolUse`)**: The AI decides to run a command (e.g., `touch blog.md`).
+ * Claude Code fires `PreToolUse`.
+ * `hooks/security-validator.ts` runs. It checks if `touch blog.md` is safe.
+ * If safe (Exit Code 0), the command runs.
+ * If unsafe (Exit Code 1+), the command is blocked.
+6. **Completion**: The AI finishes the task and updates its memory (via `kai-history-system` hooks).
+
+### 5. Key Components
+
+* **`kai-hook-system`**: The engine room. Provides the event bus and security layer.
+* **`kai-core-install`**: The brain. Defines the "CORE" skill, identity, and routing logic.
+* **`kai-history-system`**: The memory. Captures session data and learnings.
+* **`kai-voice-system`**: (Optional) Adds voice capabilities via ElevenLabs.
+
+---
+
## 📦 Available Packs
### Features (Architectural Systems)