Skip to content

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

feat: Add intelligent PAI update system with /paiupdate command

Daniel Miesslerb70e808d1772
diff --git a/.claude/commands/README.md b/.claude/commands/README.md
index 337b363a..5176a5c4 100644
--- a/.claude/commands/README.md
+++ b/.claude/commands/README.md
@@ -24,7 +24,11 @@ $ARGUMENTS
Then use it: `/summarize [paste your content here]`
-## Included Examples
+## Built-in Commands
+
+- `/paiupdate` (or `/pa`) - **PAI Update System**: Safely update your PAI installation while preserving your customizations. Your DA analyzes upstream changes and recommends what to adopt.
+
+## Example Commands
- `example.md` - A simple example showing the pattern
diff --git a/.claude/commands/pa.md b/.claude/commands/pa.md
new file mode 100644
index 00000000..cd8fb3ba
--- /dev/null
+++ b/.claude/commands/pa.md
@@ -0,0 +1,7 @@
+# PAI Update (Shortcut)
+
+Run the full PAI update workflow. This is a shortcut for `/paiupdate`.
+
+Execute the `/paiupdate` command now to check for and intelligently merge upstream PAI updates while preserving your customizations.
+
+$ARGUMENTS
diff --git a/.claude/commands/paiupdate.md b/.claude/commands/paiupdate.md
new file mode 100644
index 00000000..d33d35bc
--- /dev/null
+++ b/.claude/commands/paiupdate.md
@@ -0,0 +1,208 @@
+# PAI Update - Intelligent Sideloading System
+
+You are helping the user safely update their PAI installation while preserving their customizations.
+
+## Overview
+
+The user has customized their PAI system (renamed their DA, added skills, modified hooks, changed settings). They want to pull updates from the upstream PAI repository without losing their work.
+
+## Your Task
+
+Execute this workflow step by step:
+
+### Phase 1: Fetch Upstream PAI
+
+1. **Check for staging directory**: Look for `.claude/pai_updates/`
+
+2. **Fetch latest PAI**: The user's project IS a clone of PAI. Use git to get upstream:
+
+```bash
+# Ensure we have the upstream remote
+git remote get-url upstream 2>/dev/null || git remote add upstream https://github.com/danielmiessler/PAI.git
+
+# Fetch latest from upstream (doesn't modify working directory)
+git fetch upstream main
+
+# Create staging directory
+rm -rf .claude/pai_updates
+mkdir -p .claude/pai_updates
+
+# Export upstream's .claude directory to staging (clean, no .git)
+git archive upstream/main -- .claude | tar -x -C .claude/pai_updates --strip-components=1
+```
+
+This gives us `.claude/pai_updates/` containing the pure upstream `.claude/` contents without affecting the user's working directory.
+
+3. **Record version info**:
+```bash
+upstream_commit=$(git rev-parse upstream/main)
+upstream_date=$(git log -1 --format=%ci upstream/main)
+echo "Upstream: $upstream_commit ($upstream_date)"
+```
+
+4. **Check user's current sync state**: Look for `.claude/.pai-sync-history` to see when they last synced
+
+### Phase 2: Analyze Differences
+
+Compare the staging directory (`.claude/pai_updates/`) against the user's active directory (`.claude/`).
+
+For each file category:
+
+**Settings (`settings.json`)**:
+- Identify new keys added upstream
+- Identify keys the user has customized (especially `env.DA`, custom env vars)
+- Plan a smart merge that adds new keys while preserving user values
+
+**Skills (`.claude/skills/`)**:
+- New skills in upstream → Available to add
+- Modified skills → Compare if user has customized
+- User's custom skills → Never touch these
+
+**Hooks (`.claude/hooks/`)**:
+- Critical: hooks often contain custom logic
+- Check if user has modified vs. upstream version
+- Identify breaking changes
+
+**Agents (`.claude/agents/`)**:
+- New agents available
+- Modified agents (usually safe to update)
+
+**Commands (`.claude/commands/`)**:
+- Don't overwrite user's custom commands
+- Offer new commands from upstream
+
+### Phase 3: Generate Report
+
+Present a clear, organized report:
+
+```
+╔═══════════════════════════════════════════════════════════════════╗
+║ PAI UPDATE AVAILABLE ║
+║ Upstream: [commit hash] ║
+║ Your version: [last sync or "initial"] ║
+╠═══════════════════════════════════════════════════════════════════╣
+║ SUMMARY ║
+║ • X new files available ║
+║ • Y files updated upstream ║
+║ • Z potential conflicts with your customizations ║
+╠═══════════════════════════════════════════════════════════════════╣
+```
+
+Then organize by category:
+
+**🔴 REQUIRES ATTENTION** (conflicts with your customizations)
+- List files where both upstream changed AND user modified
+- Show what would be lost if blindly updated
+- Recommend merge strategy
+
+**🟢 SAFE TO AUTO-UPDATE** (you haven't modified these)
+- List files that can be updated without risk
+- These match your current upstream version
+
+**🆕 NEW FEATURES** (available to add)
+- New skills, agents, commands
+- Brief description of what each does
+- Recommendation based on user's apparent use case
+
+**📝 YOUR CUSTOMIZATIONS** (will be preserved)
+- List user's custom files that don't exist upstream
+- Confirm these are safe
+
+### Phase 4: Get User Decision
+
+Present clear options:
+
+```
+What would you like to do?
+
+[A] Apply all safe updates + add all new features (recommended for most users)
+[S] Step through each change individually
+[C] Conservative - only safe updates, skip new features
+[M] Manual - show me the diffs, I'll decide everything
+[N] Not now - keep staging for later review
+```
+
+### Phase 5: Execute Updates
+
+For approved changes:
+
+1. **Create backup**:
+ ```bash
+ timestamp=$(date +%Y%m%d_%H%M%S)
+ mkdir -p .claude/pai_backups
+ cp -r .claude/skills .claude/pai_backups/skills_$timestamp
+ cp -r .claude/hooks .claude/pai_backups/hooks_$timestamp
+ cp .claude/settings.json .claude/pai_backups/settings_$timestamp.json
+ ```
+
+2. **Apply changes**:
+ - Copy approved new files
+ - For settings.json: perform intelligent merge (preserve user keys, add new ones)
+ - For conflicts user approved: apply the merge strategy they chose
+
+3. **Update tracking**:
+ ```bash
+ echo "$(date -Iseconds) $(git rev-parse upstream/main)" >> .claude/.pai-sync-history
+ ```
+
+### Phase 6: Validate
+
+After applying updates:
+1. Check that settings.json is valid JSON
+2. Verify no syntax errors in key hooks
+3. Report success or any issues
+
+### Phase 7: Cleanup Option
+
+Ask if user wants to:
+- Keep `.claude/pai_updates/` for reference
+- Remove it to save space
+
+---
+
+## Important Notes
+
+- **Never overwrite without asking** when user has customized a file
+- **Always backup** before modifying existing files
+- **Preserve user identity**: Their DA name, custom env vars, personal touches
+- **Be conservative**: When in doubt, ask rather than overwrite
+- **Explain clearly**: Users should understand what each change does
+
+## Handling Edge Cases
+
+**First time running `/paiupdate`**:
+- No sync history exists
+- Treat all current files as "user's version" (may be customized)
+- Be extra careful, ask more questions
+
+**User has diverged significantly**:
+- Many files modified
+- Recommend reviewing section by section
+- Offer to show detailed diffs
+
+**Upstream has breaking changes**:
+- Warn prominently
+- Explain what might break
+- Offer to defer those specific changes
+
+**Not a git repo (downloaded as ZIP)**:
+- If no `.git` directory exists, use alternative approach:
+ ```bash
+ mkdir -p .claude/pai_updates
+ cd .claude/pai_updates
+ curl -L https://github.com/danielmiessler/PAI/archive/refs/heads/main.tar.gz | tar -xz --strip-components=2 PAI-main/.claude
+ ```
+- Inform user they should consider using git for easier future updates
+
+**User forked PAI**:
+- Their `origin` is their fork, not upstream PAI
+- Check if `upstream` remote exists, add it if not
+- This is the expected setup for most users
+
+---
+
+## Begin Now
+
+Start by checking for the staging directory and fetching the latest PAI. Then analyze and report.
+
+$ARGUMENTS
diff --git a/.gitignore b/.gitignore
index d6f42b7c..9fd0febd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -61,3 +61,8 @@ out/
private/
secrets/
credentials/
+
+# PAI Update System (sideloading)
+.claude/pai_updates/
+.claude/pai_backups/
+.claude/.pai-sync-history
diff --git a/README.md b/README.md
index 94d3c4e4..fbe2aa27 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@
<br/>
-[**Quick Start**](#-quick-start) · [**Documentation**](#-documentation) · [**Examples**](#-examples) · [**Updates**](#-updates) · [**Community**](#-community)
+[**Quick Start**](#-quick-start) · [**Documentation**](#-documentation) · [**Examples**](#-examples) · [**Updating**](#-updating-pai) · [**Community**](#-community)
<br/>
@@ -372,6 +372,25 @@ Specialized agents with distinct personalities for different tasks. Personality
<br/>
+## 🔄 Updating PAI
+
+PAI includes an intelligent sideloading system that helps you update while preserving your customizations.
+
+```bash
+# In Claude Code, run:
+/paiupdate # or just /pa
+```
+
+**What happens:**
+1. Your DA fetches the latest PAI to a staging area (doesn't touch your files)
+2. Analyzes differences between upstream and your customizations
+3. Generates a personalized report showing conflicts vs. safe updates
+4. You choose what to adopt — your DA handles the merge
+
+Your custom skills, modified hooks, and personalized settings are **never blindly overwritten**. The system understands that your `env.DA`, custom environment variables, and personal tweaks are intentional.
+
+<br/>
+
## 💬 Community
Kai and I work hard to address issues and PRs throughout the week — we try not to get too far behind!