Enterprise practical workflows, context engineering strategies, JIT (Just-In-Time) retrieval optimization, real-world execution examples, debugging patterns, and moai-adk workflow mastery; activates...
| Field | Value |
|---|---|
| Skill Name | moai-core-practices |
| Version | 4.0.0 Enterprise (2025-11-18) |
| Focus | Practical execution patterns, real-world scenarios |
| Auto-load | When workflow guidance or debugging help needed |
| Included Patterns | 15+ real-world scenarios |
| Lines of Content | 950+ with 20+ production examples |
| Progressive Disclosure | 3-level (quick-patterns, scenarios, advanced) |
Provides practical workflows, context engineering strategies, real-world execution examples, and debugging solutions for moai-adk. Covers JIT context management, efficient agent usage, SPECβTDDβSync execution, and common problem resolution.
Traditional (overload):
Load entire codebase
β Context window fills immediately
β Limited reasoning capacity
β Slow, inefficient
JIT (optimized):
Load core entry points
β Identify specific function/module
β Load only that section
β Cache in thread context
β Reuse for related tasks
β Minimal context waste
# 1. Get high-level structure
find src/ -type f -name "*.py" | wc -l
# Output: 145 files total
# 2. Identify entry points (only 3-5 files)
find src/ -name "__main__.py" -o -name "main.py" -o -name "run.py"
# 3. Load entry point + immediate dependencies
Glob("src/{**/}*.py")
# Load only files referenced by entry point
# 4. Cache in Task() context for reuse
Task(prompt="Task 1 using mapped modules")
Task(prompt="Task 2 reuses cached context")
Project Root
ββ src/
β ββ __init__.py β Entry point #1
β ββ main.py β Entry point #2
β ββ core/
β β ββ domain.py β Core models
β β ββ repository.py β Data access
β β ββ service.py β Business logic
β ββ api/
β ββ routes.py β API endpoints
β ββ handlers.py β Request handlers
Load strategy:
1. Load main.py + __init__.py (entry points)
2. When modifying API β Load api/ subtree
3. When fixing business logic β Load core/service.py
4. Cache all loaded files in context
5. Share context between related tasks
# Task 1: Understand module structure
analysis = Task({
prompt="Map src/ directory structure, identify entry points, list dependencies"
})
# Task 2: Reuse analysis for implementation
implementation = Task({
prompt=f"""Using this structure:
{analysis}
Now implement feature X...
"""
})
# Task 3: Reuse analysis for testing
testing = Task({
prompt=f"""Using this structure:
{analysis}
Write tests for feature X...
"""
})
# Result: No re-mapping, efficient context reuse
/alfred:1-plan/alfred:1-plan "Add user authentication with JWT"
# This creates:
# .moai/specs/SPEC-042/spec.md (full requirements)
# feature/SPEC-042 (git branch)
# Track with TodoWrite
/alfred:2-run SPEC-042RED: Test agent writes failing tests
β
GREEN: Implementer agent creates minimal code
β
REFACTOR: Quality agent improves code
β
Repeat TDD cycle for each feature component
β
All tests passing, coverage β₯85%
/alfred:3-sync auto SPEC-042Updates:
β Documentation
β Test coverage metrics
β Creates PR to develop
β Auto-validation of quality gates
Error message: "Cannot read property 'user_id' of undefined"
Questions:
- When does it occur? (always, intermittently, specific scenario)
- Which code path? (which endpoint/function)
- What's the state? (what data led to this)
- What changed recently? (revert to narrow down)
# Method 1: Binary search
# Is it in API layer? β Yes
# Is it in route handler? β No
# Is it in service layer? β Yes
# Is it in this function? β Narrow down
# Method 2: Add logging
logger.debug(f"user_id = {user_id}") # Check where it becomes undefined
# Method 3: Test locally
# Reproduce with minimal example
# Add breakpoint in debugger
# Step through execution
# RED: Write failing test
def test_handles_missing_user_id():
"""Should handle case when user_id is undefined."""
assert get_user(None) raises ValueError
# GREEN: Minimal fix
def get_user(user_id):
if not user_id:
raise ValueError("user_id required")
return fetch_user(user_id)
# REFACTOR: Improve
def get_user(user_id: int) -> User:
"""Get user by ID.
Args:
user_id: User identifier
Raises:
ValueError: If user_id is None or invalid
"""
if not user_id or user_id <= 0:
raise ValueError(f"Invalid user_id: {user_id}")
return self.user_repo.find(user_id)
1. Create SPEC: /alfred:1-plan "Add user dashboard"
2. Clarify details: AskUserQuestion (which data to show?)
3. Implement: /alfred:2-run SPEC-XXX (TDD cycle)
4. Document: /alfred:3-sync auto SPEC-XXX
5. Result: Production-ready feature
1. Reproduce: Create minimal test case
2. Isolate: Narrow down affected code
3. Debug: Add logging, trace execution
4. Fix: TDD REDβGREENβREFACTOR
5. Validate: Ensure tests pass, regression tests
1. Analyze: Map current code structure
2. Plan: Design new structure with trade-offs
3. Clone pattern: Create autonomous agents for parallel refactoring
4. Integrate: Verify all pieces work together
5. Test: Comprehensive test coverage
1. Profile: Identify bottleneck with profiler
2. Analyze: Understand performance characteristics
3. Design: Plan optimization approach
4. Implement: TDD REDβGREENβREFACTOR
5. Validate: Benchmark before/after
1. SPEC clarity: AskUserQuestion for ambiguous requirements
2. Agent routing: Delegate to specialist teams
3. Progress tracking: TodoWrite for coordination
4. Integration: Verify components work together
5. Documentation: Central SPEC as source of truth
Typical project context:
- Config files: ~50 tokens
- .moai/ structure: ~100 tokens
- Entry points (3-5 files): ~500 tokens
- SPEC document: ~200 tokens
β Total: ~850 tokens per session
Reusable context:
- Load once per session
- Share across 5-10 tasks
- Saves: 3,500-8,500 tokens per session
- Result: More reasoning capacity
moai-core-agent-guide (Agent orchestration patterns)moai-core-clone-pattern (Complex task delegation)moai-essentials-debug (Debugging techniques)For detailed workflow examples: reference.md
For real-world scenarios: examples.md
Last Updated: 2025-11-18
Status: Production Ready (Enterprise )