This repository was archived by the owner on Jun 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
WP2: Context Modernization - Lazy Loading #34
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7fac96a
feat(wp2): Context Modernization - Lazy Loading
Steffen025 3c23f24
fix(wp2): Minimal Nützlich statt minimal möglich
Steffen025 dde4e52
fix(wp2): Skill Discovery Index im Bootstrap
Steffen025 c5c1df7
fix(wp2): All content in English only
Steffen025 5253f39
fix(wp2): Address all Code Rabbit review comments
Steffen025 9bcc907
feat(wp2): Hybrid Algorithm loading - Essence + Lazy Load
Steffen025 e3c9310
docs(wp2): Add comprehensive context comparison documentation
Steffen025 4c4c6c8
fix(wp2): Address CodeRabbit review comments
Steffen025 4d68988
fix(wp2): Address CodeRabbit review comments + add workdir documentation
Steffen025 83fa771
fix(wp2): Address CodeRabbit review comments
Steffen025 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # Context Routing System | ||
|
|
||
| > Lazy-loading context routing for PAI-OpenCode v3.0+ | ||
| > **CRITICAL:** The bootstrap contains a "Skill Discovery Index" - without it the system doesn't know which skills exist! | ||
|
|
||
| ## Architecture Overview | ||
|
|
||
| **Before (WP1):** 233KB static context loaded at session start | ||
| **After (WP2):** ~7KB bootstrap-only + on-demand skill loading (or ~12-17KB with User Identity + System Rules) | ||
|
|
||
| ```text | ||
| ┌─────────────────────────────────────────────────────────────┐ | ||
| │ SESSION START │ | ||
| │ (~7KB load) │ | ||
| ├─────────────────────────────────────────────────────────────┤ | ||
| │ MINIMAL_BOOTSTRAP.md │ | ||
| │ ├── Algorithm Core (OBSERVE→LEARN) │ | ||
| │ ├── System Steering Rules │ | ||
| │ ├── User Identity (if exists) │ | ||
| │ └── SKILL DISCOVERY INDEX ⭐️ IMPORTANT! │ | ||
| │ (List of all skills with triggers) │ | ||
| └─────────────────────────────────────────────────────────────┘ | ||
| │ | ||
| ▼ (on-demand via trigger detection) | ||
| ┌─────────────────────┼─────────────────────┐ | ||
| ▼ ▼ ▼ | ||
| ┌─────────┐ ┌─────────┐ ┌─────────┐ | ||
| │ Skill │ │ Skill │ │ Skill │ | ||
| │Research │ │ Agents │ │ Council │ | ||
| └─────────┘ └─────────┘ └─────────┘ | ||
| │ │ │ | ||
| ▼ ▼ ▼ | ||
| SKILL.md SKILL.md SKILL.md | ||
| ``` | ||
|
|
||
| ## Why Skill Discovery Index in Bootstrap? | ||
|
|
||
| **Problem:** If the system doesn't know that e.g. "Research" or "Agents" exist, it cannot load these skills! | ||
|
|
||
| **Solution:** The bootstrap contains a compact registry of all available skills with: | ||
| - Skill name | ||
| - Trigger words (when to load) | ||
| - Path to SKILL.md | ||
|
|
||
| ## Loading Strategies | ||
|
|
||
| ### 1. Bootstrap Loading (Immediate) | ||
|
|
||
| Loaded at every session start: | ||
|
|
||
| | File | Size | Purpose | | ||
| |------|------|---------| | ||
| | `MINIMAL_BOOTSTRAP.md` | ~7KB | Algorithm **Essence** + Steering Rules + Skill Discovery | | ||
| | System AISTEERINGRULES.md | ~2KB | Behavior rules (if exists) | | ||
| | User Identity | ~3-8KB | ABOUTME, TELOS, DAIDENTITY (if exists) | | ||
| | **Total** | **~12-17KB** | Minimal Useful | | ||
|
|
||
| **Note:** The Algorithm essence covers 95% of use cases. For Extended/Advanced/Deep effort requiring detailed ISC decomposition, the full Algorithm v3.7.0 (383 lines) loads on-demand via `skill_find("Algorithm")` or by reading `.opencode/PAI/Algorithm/v3.7.0.md`. | ||
|
|
||
| ### 2. Skill Discovery & Loading (On-Demand) | ||
|
|
||
| **Step 1: Trigger Detection** | ||
| ```typescript | ||
| // User Input: "Research this topic for me" | ||
| // ↓ | ||
| // Pattern-match against Skill Discovery Index | ||
| // ↓ | ||
| // Trigger "Research" found → Load Research Skill | ||
| ``` | ||
|
|
||
| **Step 2: Load skill** | ||
| ```typescript | ||
| // Find a skill by name (known from Discovery Index) | ||
| const skill = await skill_find("Research"); | ||
|
|
||
| // Use the skill (loads its full SKILL.md) | ||
| // Note: skill_use expects the skill name, not ID | ||
| await skill_use(skill.name); | ||
| ``` | ||
|
|
||
| ### 3. Lazy Loading Trigger Examples | ||
|
|
||
| | User says | Skill loaded | Trigger word | | ||
| |-----------|--------------|--------------| | ||
| | "Research this topic" | Research | "Research" | | ||
| | "Agents discuss this" | Agents | "Agents" | | ||
| | "Use Council" | Council | "Council" | | ||
| | "Build CLI tool" | CreateCLI | "CLI" | | ||
| | "Security scan" | WebAssessment | "Security" | | ||
|
|
||
| ## Skill Discovery Index in Bootstrap | ||
|
|
||
| The bootstrap contains a compact table: | ||
|
|
||
| ```markdown | ||
| | Skill | Trigger | Path | | ||
| |-------|---------|------| | ||
| | Research | "Research", "investigate" | skills/Research/SKILL.md | | ||
| | Agents | "Agents", "spawn agent" | skills/Agents/SKILL.md | | ||
| | Council | "Council", "debate" | skills/Council/SKILL.md | | ||
| | ... | ... | ... | | ||
| ``` | ||
|
|
||
| **Benefits:** | ||
| - ✅ System knows which skills exist | ||
| - ✅ Pattern-matching against user input possible | ||
| - ✅ Lazy loading works | ||
| - ✅ No 233KB static loading needed | ||
|
|
||
| ## Migration from WP1 | ||
|
|
||
| ### What changed | ||
|
|
||
| | Before | After | | ||
| |--------|-------| | ||
| | 233KB everything loaded | ~7KB bootstrap + Lazy Loading | | ||
| | No discovery mechanism | Skill Discovery Index in bootstrap | | ||
| | Skills always there | Skills only loaded when needed | | ||
|
|
||
| ### What stays in bootstrap (Minimal Useful) | ||
|
|
||
| 1. **Algorithm Core** - How PAI works | ||
| 2. **System Steering Rules** - Behavior rules | ||
| 3. **User Identity** - Who the user is (if exists) | ||
| 4. **Skill Discovery Index** - Which skills exist | ||
|
|
||
| ### What gets Lazy-Loaded | ||
|
|
||
| - Individual skills (only when trigger recognized) | ||
| - System docs (MemorySystem, HookSystem, etc.) | ||
| - Project-specific contexts | ||
|
|
||
| --- | ||
|
|
||
| *Part of PAI-OpenCode v3.0 Context Modernization (WP2)* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # PAI Bootstrap — Minimal Useful | ||
|
|
||
| > **Core context loaded at session start.** ~7KB: Algorithm essence + Steering Rules + User Identity (if exists) + Skill Discovery Index. Skills load on-demand. | ||
|
|
||
| --- | ||
|
|
||
| ## The Algorithm (v3.7.0 Essence) | ||
|
|
||
| **Goal:** Euphoric Surprise — 9-10 ratings. | ||
|
|
||
| **Method:** CURRENT STATE → IDEAL STATE via verifiable criteria (ISC). | ||
|
|
||
| **7 Phases:** OBSERVE → THINK → PLAN → BUILD → EXECUTE → VERIFY → LEARN | ||
|
|
||
| **Key Rules:** | ||
| - ISC before work (8-12 words, binary testable) | ||
| - Phases are discrete (never merge) | ||
| - All capabilities are skills (actually invoke them) | ||
| - Voice curls at every phase (main agent only) | ||
| - Direct tools before agents (Grep/Glob/Read <2s) | ||
|
|
||
| **Full Algorithm:** This bootstrap contains the Algorithm essence. For complex tasks requiring detailed decomposition, PRD formatting, or extended effort levels: | ||
|
|
||
| ```typescript | ||
| // Load full Algorithm details when needed: | ||
| const algorithmSkill = await skill_find("Algorithm"); | ||
| if (algorithmSkill) { | ||
| await skill_use(algorithmSkill.name); | ||
| // Full 383-line Algorithm v3.7.0 now available | ||
| } | ||
| ``` | ||
|
|
||
| Or directly read: `PAI/Algorithm/v3.7.0.md` | ||
|
|
||
| --- | ||
|
|
||
| ## AI Steering Rules — System | ||
|
|
||
| **Surgical fixes only.** Make precise, targeted corrections. Never delete/gut/rearchitect components as a "fix". | ||
|
|
||
| **Never assert without verification.** Don't say "it is X" without checking with tools. Evidence required. | ||
|
|
||
| **First principles over bolt-ons.** Understand → Simplify → Reduce → Add (last resort). | ||
|
|
||
| **Build ISC from every request.** Decompose into verifiable criteria before executing. | ||
|
|
||
| **Ask before destructive actions.** Deletes, force pushes, production deploys — always ask first. | ||
|
|
||
| **Read before modifying.** Understand existing code, imports, and patterns first. | ||
|
|
||
| **One change when debugging.** Isolate, verify, proceed. | ||
|
|
||
| **Minimal scope.** Only change what was asked. No bonus refactoring. | ||
|
|
||
| **Plan means stop.** "Create a plan" = present and STOP. No execution without approval. | ||
|
|
||
| **Identity.** First person ("I"), user by name (never "the user"). | ||
|
|
||
| See full rules: `PAI/AISTEERINGRULES.md` | ||
|
|
||
| --- | ||
|
|
||
| ## User Identity | ||
|
|
||
| Your personal context (loaded when files exist in `.opencode/PAI/USER/`): | ||
|
|
||
| | File | Purpose | Loaded | | ||
| |------|---------|--------| | ||
| | `.opencode/PAI/USER/ABOUTME.md` | Your background, expertise, goals | ✅ If exists | | ||
| | `.opencode/PAI/USER/TELOS/TELOS.md` | Life goals, mission, values | ✅ If exists | | ||
| | `.opencode/PAI/USER/DAIDENTITY.md` | AI assistant name, personality | ✅ If exists | | ||
| | `.opencode/PAI/USER/AISTEERINGRULES.md` | Personal behavior rules | ✅ If exists | | ||
|
|
||
| --- | ||
|
|
||
| ## Lazy Loading — On-Demand Skills | ||
|
|
||
| **CRITICAL: Skill Discovery Registry** | ||
|
|
||
| The system must know which skills exist to load them: | ||
|
|
||
| ### Available Skills (Discovery Index) | ||
|
|
||
| | Skill | Trigger (when to load) | Path | | ||
| |-------|------------------------|------| | ||
| | **Research** | "Research", "investigate", "find information" | `skills/Research/SKILL.md` | | ||
| | **Agents** | "Agents", "spawn agent", "subagent" | `skills/Agents/SKILL.md` | | ||
| | **Council** | "Council", "debate", "discuss", "perspectives" | `skills/Council/SKILL.md` | | ||
| | **CreateSkill** | "Create skill", "new skill", "build skill" | `skills/CreateSkill/SKILL.md` | | ||
| | **CreateCLI** | "Build CLI", "create CLI", "command line tool" | `skills/CreateCLI/SKILL.md` | | ||
| | **Documents** | "Process document", "PDF", "Word", "Excel" | `skills/Documents/SKILL.md` | | ||
| | **KnowledgeExtraction** | "Extract course", "transcribe", "wisdom" | `skills/KnowledgeExtraction/SKILL.md` | | ||
| | **FirstPrinciples** | "First principles", "decompose", "root cause" | `skills/FirstPrinciples/SKILL.md` | | ||
| | **BeCreative** | "Be creative", "deep thinking", "extended reasoning" | `skills/BeCreative/SKILL.md` | | ||
| | **RedTeam** | "Red team", "attack", "critique", "stress test" | `skills/RedTeam/SKILL.md` | | ||
| | **WebAssessment** | "Security scan", "pentest", "vulnerability" | `skills/WebAssessment/SKILL.md` | | ||
| | **Fabric** | "Fabric pattern", "extract wisdom", "summarize" | `skills/Fabric/SKILL.md` | | ||
| | **Blog** | "Blog post", "article", "write content" | `skills/Blog/SKILL.md` | | ||
| | **ContactEnrichment** | "Enrich contact", "verify email", "OSINT" | `skills/ContactEnrichment/SKILL.md` | | ||
| | **OSINT** | "OSINT", "due diligence", "investigate person" | `skills/OSINT/SKILL.md` | | ||
| | **Recon** | "Recon", "reconnaissance", "bug bounty" | `skills/Recon/SKILL.md` | | ||
| | **Apify** | "Scrape Twitter", "Instagram", "LinkedIn", "Google Maps" | `skills/Apify/SKILL.md` | | ||
| | **BrightData** | "Bright Data", "scrape URL", "web scraping" | `skills/BrightData/SKILL.md` | | ||
| | **AnnualReports** | "Annual report", "security report", "threat report" | `skills/AnnualReports/SKILL.md` | | ||
| | **SECUpdates** | "Security news", "breaches", "security updates" | `skills/SECUpdates/SKILL.md` | | ||
| | **PrivateInvestigator** | "Find person", "locate", "skip trace" | `skills/PrivateInvestigator/SKILL.md` | | ||
| | **WarriorPatterns** | "Warrior patterns", "business analysis", "positioning" | `skills/WarriorPatterns/SKILL.md` | | ||
| | **WarriorsWay** | "Warriors Way", "Core 4", "4Ps", "breakthrough" | `skills/WarriorsWay/SKILL.md` | | ||
| | **Telos** | "TELOS", "life goals", "projects", "books" | `skills/Telos/SKILL.md` | | ||
| | **Aphorisms** | "Aphorism", "quote", "saying" | `skills/Aphorisms/SKILL.md` | | ||
| | **Algorithm** | "Algorithm details", "full algorithm", "PRD format", "ISC decomposition", "Extended effort", "Advanced effort" | `PAI/Algorithm/v3.7.0.md` | | ||
|
|
||
| ### Agent Types (via Task Tool) | ||
|
|
||
| | Agent | Usage | Invocation | | ||
| |-------|-------|------------| | ||
| | **Algorithm** | ISC-specialized work | `Task: subagent_type=Algorithm` | | ||
| | **Engineer** | Build, implement, code | `Task: subagent_type=Engineer` | | ||
| | **Architect** | Design, structure, system thinking | `Task: subagent_type=Architect` | | ||
| | **Pentester** | Security testing, vuln scan | `Task: subagent_type=Pentester` | | ||
| | **Designer** | UI/UX design, Figma | `Task: subagent_type=Designer` | | ||
| | **QATester** | Testing, verification | `Task: subagent_type=QATester` | | ||
| | **BrowserAgent** | Browser automation, screenshots | `Task: subagent_type=BrowserAgent` | | ||
| | **UIReviewer** | UI review, accessibility | `Task: subagent_type=UIReviewer` | | ||
| | **Artist** | Visual content, images | `Task: subagent_type=Artist` | | ||
| | **Writer** | Technical writing, content | `Task: subagent_type=Writer` | | ||
| | **DeepResearcher** | Multi-model research | `Task: subagent_type=DeepResearcher` | | ||
| | **CodexResearcher** | Code archaeology, technical research | `Task: subagent_type=CodexResearcher` | | ||
| | **ClaudeResearcher** | Anthropic ecosystem research | `Task: subagent_type=ClaudeResearcher` | | ||
| | **GeminiResearcher** | Multi-perspective research | `Task: subagent_type=GeminiResearcher` | | ||
| | **PerplexityResearcher** | Real-time web research | `Task: subagent_type=PerplexityResearcher` | | ||
| | **GrokResearcher** | Contrarian, fact-based research | `Task: subagent_type=GrokResearcher` | | ||
|
|
||
| ### Skill Discovery Pattern | ||
|
|
||
| ```typescript | ||
| // 1. Analyze user input for skill triggers | ||
| const userInput = "Research this topic for me"; | ||
|
|
||
| // 2. Identify matching skill from Discovery Index | ||
| // Trigger "Research" → Skill: Research | ||
|
|
||
| // 3. Load the skill | ||
| const skill = await skill_find("Research"); | ||
| if (skill) { | ||
| // Note: skill_use expects the skill name | ||
| await skill_use(skill.name); | ||
| // Skill is now available | ||
| } | ||
| ``` | ||
|
|
||
| **Important:** Without this registry, the system doesn't know that "Research" or "Agents" exist! | ||
|
|
||
| --- | ||
|
|
||
| ## Context Routing | ||
|
|
||
| - **Immediate:** This bootstrap (~7KB) | ||
| - **On-demand:** Skills via `skill_find`/`skill_use` | ||
| - **User context:** Auto-loaded if files exist in `.opencode/PAI/USER/` | ||
| - **System docs:** Lazy load from `PAI/` when referenced | ||
|
|
||
| --- | ||
|
|
||
| *This is the minimal useful bootstrap. Everything else loads when needed.* |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Größenangaben sind inkonsistent zur PR-Zielsetzung.
In Line 9 und Line 53-56 wird mit ~7KB bzw. ~12-17KB als Bootstrap-Kontext argumentiert, obwohl in den PR-Zielen explizit ein ~2KB
MINIMAL_BOOTSTRAPbeschrieben ist. Bitte die Zahlen konsistent auf den aktuellen Stand bringen, damit Migration und Verifikation eindeutig bleiben.Also applies to: 53-56
🤖 Prompt for AI Agents