Quick Reference (30 seconds)
Purpose: Load relevant documentation on-demand based on user intent and context.
Primary Tools:
- WebSearch: Find latest documentation and resources online
- WebFetch: Retrieve specific documentation pages
- Context7 MCP: Access official library documentation (when available)
- Read, Grep, Glob: Search local project documentation
Trigger Patterns:
- User asks specific technical questions
- Technology keywords detected in conversation
- Domain expertise required for task completion
- Implementation guidance needed
Implementation Guide
Intent Detection
The system recognizes documentation needs through several patterns:
Question-Based Triggers:
- When users ask specific implementation questions (e.g., "how do I implement JWT authentication?")
- When users seek best practices or optimization guidance
- When troubleshooting questions arise
Technology-Specific Triggers:
- Detection of framework names: FastAPI, React, PostgreSQL, Docker, Kubernetes
- Detection of library names: pytest, TypeScript, GraphQL, Redis
- Detection of tool names: npm, pip, cargo, maven
Domain-Specific Triggers:
- Authentication and authorization topics
- Database and data modeling discussions
- Performance optimization inquiries
- Security-related questions
Pattern-Based Triggers:
- Implementation requests: "implement", "create", "build"
- Architecture discussions: "design", "structure", "pattern"
- Troubleshooting: "debug", "fix", "error", "not working"
Documentation Sources
The system retrieves documentation from multiple sources in priority order:
Local Project Documentation (Highest Priority):
- Check .moai/docs/ for project-specific documentation
- Check .moai/specs/ for requirements and specifications
- Check README.md for project overview
- Check docs/ directory for comprehensive documentation
Official Documentation Sources:
- Use WebFetch to retrieve official framework documentation
- Use Context7 MCP tools when available for library documentation
- Access technology-specific official websites
Community Resources:
- Use WebSearch to find high-quality tutorials
- Search for Stack Overflow solutions with high vote counts
- Find GitHub discussions for specific issues
Real-Time Web Research:
- Use WebSearch with current year for latest information
- Search for recent best practices and updates
- Find new features and deprecation notices
Loading Strategies
Intent Analysis Process:
- Identify technologies mentioned in user request
- Determine domain areas relevant to the question
- Classify question type (implementation, troubleshooting, conceptual)
- Assess complexity to determine documentation depth needed
Source Prioritization:
- If local documentation exists: Load project-specific docs first
- If official documentation available: Retrieve authoritative sources
- If implementation examples needed: Search community resources
- If latest information required: Perform web research
Context-Aware Caching:
- Cache retrieved documentation within session
- Maintain relevance based on current conversation context
- Remove outdated content when context shifts
- Prioritize frequently accessed documentation
Quality Assessment
Content Quality Evaluation:
- Authority: Official sources receive highest trust
- Recency: Content within 12 months preferred for fast-moving technologies
- Completeness: Documentation with examples ranked higher
- Relevance: Match between content and user intent
Relevance Ranking:
- Calculate match between documentation content and user question
- Weight authority (30%), recency (25%), completeness (25%), relevance (20%)
- Return highest-scoring documentation first
- Indicate confidence level in retrieved information
Practical Workflows
Authentication Implementation Workflow:
- When user asks about authentication: Detect technologies (e.g., FastAPI, JWT)
- Identify domains: authentication, security
- Load FastAPI security documentation via WebFetch
- Search for JWT best practices via WebSearch
- Provide comprehensive guidance with source attribution
Database Optimization Workflow:
- When user asks about query performance: Detect database technology
- Identify domain: performance, optimization
- Load official database documentation
- Search for optimization guides and tutorials
- Provide actionable recommendations with sources
New Technology Adoption Workflow:
- When user introduces unfamiliar technology: Detect technology name
- Load official getting started documentation
- Search for migration guides if applicable
- Find integration patterns with existing stack
- Provide strategic adoption guidance
Error Handling
Network Failures:
- If web search fails: Fall back to cached content
- If WebFetch fails: Use local documentation if available
- Indicate partial results when some sources unreachable
Content Quality Issues:
- If retrieved content seems outdated: Search for newer sources
- If relevance unclear: Ask user for clarification
- If conflicting information found: Present multiple sources with dates
Relevance Mismatches:
- If initial search yields poor results: Refine search query
- If user context unclear: Request clarification before loading
- If documentation gap exists: Acknowledge limitation
Performance Optimization
Caching Strategy:
- Maintain session-level cache for frequently accessed docs
- Keep project-specific documentation in memory
- Evict stale content based on access time
Efficient Loading:
- Load documentation only when explicitly needed
- Avoid preloading all possible documentation
- Use targeted searches rather than broad queries
Batch Processing:
- Combine related searches when possible
- Group documentation requests by technology
- Process multiple sources in parallel when appropriate
Advanced Patterns
Multi-Source Aggregation:
- Combine official documentation with community examples
- Cross-reference multiple authoritative sources
- Synthesize comprehensive answers from diverse materials
Context Persistence:
- Remember documentation loaded earlier in conversation
- Avoid redundant loading of same documentation
- Build cumulative knowledge through session
Proactive Loading:
- Anticipate documentation needs based on conversation flow
- Pre-load related topics when discussing complex features
- Suggest relevant documentation before user asks
Works Well With
Agents:
- workflow-docs: Documentation generation
- core-planner: Documentation planning
- workflow-spec: SPEC documentation
Skills:
- moai-docs-generation: Documentation generation
- moai-workflow-docs: Documentation validation
- moai-library-nextra: Nextra documentation
Commands:
- /moai:3-sync: Documentation synchronization
- /moai:9-feedback: Documentation improvements
Common Rationalizations
| Rationalization |
Reality |
| "I already know where the docs are, JIT loading is unnecessary" |
JIT docs discover context you did not know existed. Manual lookup misses cross-references. |
| "Loading all docs upfront is simpler than on-demand" |
Upfront loading wastes tokens on irrelevant content. JIT loads only what matches the current intent. |
| "The cached version is recent enough" |
Stale caches serve stale answers. Validate cache freshness before using cached documents. |
| "This task does not need documentation" |
Every non-trivial task benefits from context. JIT docs surface relevant constraints proactively. |
| "I will find the right doc by browsing the directory" |
Directory browsing is O(n). JIT matching by intent keywords is O(1) for the user. |
Red Flags
- Agent proceeds with implementation without loading any project documentation
- Cached document served when the source file was modified more recently
- Documentation loaded but not referenced in the implementation rationale
- Multiple redundant document loads in the same session (cache miss on repeated content)
- JIT loader returns zero results for a keyword that clearly maps to existing docs
Verification
1---2name: moai-workflow-jit-docs3description: Enhanced Just-In-Time document loading system that discovers, loads, and caches relevant documentation based on user intent and project context. Use when users need specific documentation on demand.4license: Apache-2.05---6
7## Quick Reference (30 seconds)
8
9Purpose: Load relevant documentation on-demand based on user intent and context.
10
11Primary Tools:
12
13- WebSearch: Find latest documentation and resources online
14- WebFetch: Retrieve specific documentation pages
15- Context7 MCP: Access official library documentation (when available)
16- Read, Grep, Glob: Search local project documentation
17
18Trigger Patterns:
19
20- User asks specific technical questions
21- Technology keywords detected in conversation
22- Domain expertise required for task completion
23- Implementation guidance needed
24
25## Implementation Guide
26
27### Intent Detection
28
29The system recognizes documentation needs through several patterns:
30
31Question-Based Triggers:
32
33- When users ask specific implementation questions (e.g., "how do I implement JWT authentication?")
34- When users seek best practices or optimization guidance
35- When troubleshooting questions arise
36
37Technology-Specific Triggers:
38
39- Detection of framework names: FastAPI, React, PostgreSQL, Docker, Kubernetes
40- Detection of library names: pytest, TypeScript, GraphQL, Redis
41- Detection of tool names: npm, pip, cargo, maven
42
43Domain-Specific Triggers:
44
45- Authentication and authorization topics
46- Database and data modeling discussions
47- Performance optimization inquiries
48- Security-related questions
49
50Pattern-Based Triggers:
51
52- Implementation requests: "implement", "create", "build"
53- Architecture discussions: "design", "structure", "pattern"
54- Troubleshooting: "debug", "fix", "error", "not working"
55
56### Documentation Sources
57
58The system retrieves documentation from multiple sources in priority order:
59
60Local Project Documentation (Highest Priority):
61
62- Check .moai/docs/ for project-specific documentation
63- Check .moai/specs/ for requirements and specifications
64- Check README.md for project overview
65- Check docs/ directory for comprehensive documentation
66
67Official Documentation Sources:
68
69- Use WebFetch to retrieve official framework documentation
70- Use Context7 MCP tools when available for library documentation
71- Access technology-specific official websites
72
73Community Resources:
74
75- Use WebSearch to find high-quality tutorials
76- Search for Stack Overflow solutions with high vote counts
77- Find GitHub discussions for specific issues
78
79Real-Time Web Research:
80
81- Use WebSearch with current year for latest information
82- Search for recent best practices and updates
83- Find new features and deprecation notices
84
85### Loading Strategies
86
87Intent Analysis Process:
88
89- Identify technologies mentioned in user request
90- Determine domain areas relevant to the question
91- Classify question type (implementation, troubleshooting, conceptual)
92- Assess complexity to determine documentation depth needed
93
94Source Prioritization:
95
96- If local documentation exists: Load project-specific docs first
97- If official documentation available: Retrieve authoritative sources
98- If implementation examples needed: Search community resources
99- If latest information required: Perform web research
100
101Context-Aware Caching:
102
103- Cache retrieved documentation within session
104- Maintain relevance based on current conversation context
105- Remove outdated content when context shifts
106- Prioritize frequently accessed documentation
107
108### Quality Assessment
109
110Content Quality Evaluation:
111
112- Authority: Official sources receive highest trust
113- Recency: Content within 12 months preferred for fast-moving technologies
114- Completeness: Documentation with examples ranked higher
115- Relevance: Match between content and user intent
116
117Relevance Ranking:
118
119- Calculate match between documentation content and user question
120- Weight authority (30%), recency (25%), completeness (25%), relevance (20%)
121- Return highest-scoring documentation first
122- Indicate confidence level in retrieved information
123
124### Practical Workflows
125
126Authentication Implementation Workflow:
127
128- When user asks about authentication: Detect technologies (e.g., FastAPI, JWT)
129- Identify domains: authentication, security
130- Load FastAPI security documentation via WebFetch
131- Search for JWT best practices via WebSearch
132- Provide comprehensive guidance with source attribution
133
134Database Optimization Workflow:
135
136- When user asks about query performance: Detect database technology
137- Identify domain: performance, optimization
138- Load official database documentation
139- Search for optimization guides and tutorials
140- Provide actionable recommendations with sources
141
142New Technology Adoption Workflow:
143
144- When user introduces unfamiliar technology: Detect technology name
145- Load official getting started documentation
146- Search for migration guides if applicable
147- Find integration patterns with existing stack
148- Provide strategic adoption guidance
149
150### Error Handling
151
152Network Failures:
153
154- If web search fails: Fall back to cached content
155- If WebFetch fails: Use local documentation if available
156- Indicate partial results when some sources unreachable
157
158Content Quality Issues:
159
160- If retrieved content seems outdated: Search for newer sources
161- If relevance unclear: Ask user for clarification
162- If conflicting information found: Present multiple sources with dates
163
164Relevance Mismatches:
165
166- If initial search yields poor results: Refine search query
167- If user context unclear: Request clarification before loading
168- If documentation gap exists: Acknowledge limitation
169
170### Performance Optimization
171
172Caching Strategy:
173
174- Maintain session-level cache for frequently accessed docs
175- Keep project-specific documentation in memory
176- Evict stale content based on access time
177
178Efficient Loading:
179
180- Load documentation only when explicitly needed
181- Avoid preloading all possible documentation
182- Use targeted searches rather than broad queries
183
184Batch Processing:
185
186- Combine related searches when possible
187- Group documentation requests by technology
188- Process multiple sources in parallel when appropriate
189
190## Advanced Patterns
191
192Multi-Source Aggregation:
193
194- Combine official documentation with community examples
195- Cross-reference multiple authoritative sources
196- Synthesize comprehensive answers from diverse materials
197
198Context Persistence:
199
200- Remember documentation loaded earlier in conversation
201- Avoid redundant loading of same documentation
202- Build cumulative knowledge through session
203
204Proactive Loading:
205
206- Anticipate documentation needs based on conversation flow
207- Pre-load related topics when discussing complex features
208- Suggest relevant documentation before user asks
209
210---
211
212## Works Well With
213
214Agents:
215
216- workflow-docs: Documentation generation
217- core-planner: Documentation planning
218- workflow-spec: SPEC documentation
219
220Skills:
221
222- moai-docs-generation: Documentation generation
223- moai-workflow-docs: Documentation validation
224- moai-library-nextra: Nextra documentation
225
226Commands:
227
228- /moai:3-sync: Documentation synchronization
229- /moai:9-feedback: Documentation improvements
230
231<!-- moai:evolvable-start id="rationalizations" -->
232## Common Rationalizations
233
234| Rationalization | Reality |
235|---|---|
236| "I already know where the docs are, JIT loading is unnecessary" | JIT docs discover context you did not know existed. Manual lookup misses cross-references. |
237| "Loading all docs upfront is simpler than on-demand" | Upfront loading wastes tokens on irrelevant content. JIT loads only what matches the current intent. |
238| "The cached version is recent enough" | Stale caches serve stale answers. Validate cache freshness before using cached documents. |
239| "This task does not need documentation" | Every non-trivial task benefits from context. JIT docs surface relevant constraints proactively. |
240| "I will find the right doc by browsing the directory" | Directory browsing is O(n). JIT matching by intent keywords is O(1) for the user. |
241
242<!-- moai:evolvable-end -->
243
244<!-- moai:evolvable-start id="red-flags" -->
245## Red Flags
246
247- Agent proceeds with implementation without loading any project documentation
248- Cached document served when the source file was modified more recently
249- Documentation loaded but not referenced in the implementation rationale
250- Multiple redundant document loads in the same session (cache miss on repeated content)
251- JIT loader returns zero results for a keyword that clearly maps to existing docs
252
253<!-- moai:evolvable-end -->
254
255<!-- moai:evolvable-start id="verification" -->
256## Verification
257
258- [ ] At least one document was loaded via JIT matching for non-trivial tasks
259- [ ] Loaded documents are referenced in the agent's reasoning or output
260- [ ] Cache hits validated against source file modification time
261- [ ] No duplicate document loads in the same session (check load log)
262- [ ] JIT trigger keywords match the user's stated intent
263
264<!-- moai:evolvable-end -->