On-Demand Context Loading
Relevant source files
The following files were used as context for generating this wiki page:
On-Demand Context Loading is a core architectural pattern within the opencode-skills-collection project designed to provide high-fidelity, evidence-based technical analysis by retrieving and processing codebase information only when required. This system prioritizes depth over breadth, ensuring that documentation and research are grounded in actual implementation details rather than inferences or file-name conventions.
The mechanism serves as the foundation for complex workflows such as the Wiki Onboarding Guide Generator and the Wiki Page Writer, which require a "zero-to-hero" understanding of a repository. By following strict code paths and dependency chains, the system builds a comprehensive mental model of the software architecture through iterative discovery and verification.
Sources: bundled-skills/wiki-researcher/SKILL.md, bundled-skills/wiki-page-writer/SKILL.md:21-25
Architecture and Core Principles
The architecture follows a "Deep Search" philosophy, mandating the tracing of actual code paths. It operates through a series of specialized skills that work in concert to ingest, analyze, and synthesize codebase context dynamically.
Core Invariants
The system maintains strict invariants to ensure the accuracy of the loaded context:
- Trace Actual Code Paths: The system does not guess from file names; it reads the implementation directly to identify logic and flow.
- Evidence-Based Claims: Every technical claim must be backed by a specific source citation (file path and line number).
- Zero Tolerance for Shallow Research: The system explicitly avoids "vibes-based" diagrams or assumed patterns (e.g., assuming MVC structure without verification).
Sources: bundled-skills/wiki-researcher/SKILL.md:15-30
Context Loading Workflow
The following diagram illustrates the iterative process used to build a complete architectural context from raw source files.
The flow diagram shows the 5-iteration research process used to escalate from a basic file scan to a deep architectural synthesis.
Sources: bundled-skills/wiki-researcher/SKILL.md:46-52, bundled-skills/wiki-architect/SKILL.md:20-25
Component Deep Dive
Discovery and Reconnaissance
Before loading specific file context, the system performs a reconnaissance phase to classify the target environment. This is most visible in the web-scraper and c4-architecture modules.
| Stage | Activity | Tools/Methods |
|---|---|---|
| Discovery | Identifying relevant URLs or file paths | WebSearch, list_tools |
| Reconnaissance | Analyzing page/file structure and types | WebFetch, AST Parsing |
| Classification | Determining extraction mode (table, list, API) | Pattern matching |
Sources: bundled-skills/web-scraper/SKILL.md:120-150, bundled-skills/c4-architecture-c4-architecture/SKILL.md:46-55
Iterative Research Phases
The wiki-researcher skill implements a 5-iteration lens for deep context loading:
- Structural View: Mapping the landscape and entry points.
- Data Flow: Tracing state management and transformations (entry point → destination).
- Integration View: External connections and API contracts.
- Pattern View: Identifying design patterns, trade-offs, and technical debt.
- Synthesis: Combining findings into actionable insights.
Sources: bundled-skills/wiki-researcher/SKILL.md:46-52
Data Extraction and Transformation Logic
Once files are identified, the system extracts structured data. In the web-scraper module, this involves an auto-escalation strategy: if static fetching (Strategy A) fails to provide sufficient context, the system automatically fallbacks to Browser automation (Strategy B).
Sequence of Context Extraction
The following sequence diagram demonstrates how the system handles a request for deep documentation by coordinating multiple agents.
This sequence shows the synchronous flow of context from architectural scanning to final documentation generation.
Sources: bundled-skills/wiki-architect/SKILL.md:20-30, bundled-skills/wiki-researcher/SKILL.md:65-75
Implementation Standards
To maintain the integrity of "On-Demand Context Loading," the project adheres to specific implementation standards for documentation and code analysis:
Citation Format
Every non-trivial claim generated from loaded context must follow the standard citation format: (file_path:line_number). A minimum of 5 different source files must be cited per generated page to ensure comprehensive coverage.
Sources: bundled-skills/wiki-page-writer/SKILL.md:52-55
Data Transformation Rules
When context is loaded, it undergoes automatic transformations to ensure consistency:
- Whitespace Cleanup: Collapsing multiple spaces and removing line breaks in table cells.
- HTML Entity Decoding: Converting characters like
&back to standard symbols. - Normalization: Standardizing dates to ISO-8601 and resolving relative URLs to absolute paths.
Sources: bundled-skills/web-scraper/SKILL.md:290-310
Summary
On-Demand Context Loading transforms a raw repository into a structured knowledge base by strictly adhering to evidence-based research. By combining structural scanning with deep-path tracing and automated validation, the system ensures that every technical artifact—from C4 diagrams to onboarding guides—is accurate, verifiable, and synchronized with the latest implementation of the code.
Sources: bundled-skills/wiki-researcher/SKILL.md:76-85, bundled-skills/wiki-onboarding/SKILL.md:34-45