moai-foundation-core

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

MoAI Foundation Core

MoAI Foundation Core

Foundational principles and architectural patterns that power MoAI-ADK's AI-driven development workflow.
Core Philosophy: Quality-first, domain-driven, modular, and efficient AI development through proven patterns and automated workflows.
支撑MoAI-ADK人工智能驱动开发工作流的基础原则与架构模式。
核心理念:通过经过验证的模式和自动化工作流,实现质量优先、领域驱动、模块化且高效的AI开发。

Quick Reference

快速参考

What is MoAI Foundation Core?
Six essential principles that ensure quality, efficiency, and scalability in AI-powered development:
  1. TRUST 5 Framework - Quality gate system (Tested, Readable, Unified, Secured, Trackable)
  2. SPEC-First DDD - Specification-driven domain-driven development workflow
  3. Delegation Patterns - Task orchestration via specialized agents (never direct execution)
  4. Token Optimization - 200K budget management and context efficiency
  5. Progressive Disclosure - Three-tier knowledge delivery (Quick, Implementation, Advanced)
  6. Modular System - File splitting and reference architecture for scalability
Quick Access:
  • Quality standards in modules/trust-5-framework.md
  • Development workflow in modules/spec-first-ddd.md
  • Agent coordination in modules/delegation-patterns.md
  • Budget management in modules/token-optimization.md
  • Content structure in modules/progressive-disclosure.md
  • File organization in modules/modular-system.md
  • Agent catalog in modules/agents-reference.md
  • Command reference in modules/commands-reference.md
  • Security and constraints in modules/execution-rules.md
Use Cases:
  • New agent creation with quality standards
  • New skill development with structural guidelines
  • Complex workflow orchestration
  • Token budget planning and optimization
  • Documentation architecture design
  • Quality gate configuration

什么是MoAI Foundation Core?
确保AI驱动开发具备高质量、高效性和可扩展性的六项核心原则:
  1. TRUST 5框架 - 质量门系统(可测试、可读、统一、安全、可追踪)
  2. SPEC-First DDD - 规范驱动的领域驱动开发工作流
  3. 委托模式 - 通过专业Agent进行任务编排(绝不直接执行)
  4. Token优化 - 200K预算管理与上下文效率提升
  5. 渐进式披露 - 三层知识交付(快速参考、实现指南、高级进阶)
  6. 模块化系统 - 用于可扩展性的文件拆分与参考架构
快速访问:
  • 模块中的质量标准:modules/trust-5-framework.md
  • 开发工作流:modules/spec-first-ddd.md
  • Agent协作:modules/delegation-patterns.md
  • 预算管理:modules/token-optimization.md
  • 内容结构:modules/progressive-disclosure.md
  • 文件组织:modules/modular-system.md
  • Agent目录:modules/agents-reference.md
  • 命令参考:modules/commands-reference.md
  • 安全与约束:modules/execution-rules.md
适用场景:
  • 遵循质量标准创建新Agent
  • 按照结构指南开发新Skill
  • 复杂工作流编排
  • Token预算规划与优化
  • 文档架构设计
  • 质量门配置

Implementation Guide

实现指南

1. TRUST 5 Framework - Quality Assurance System

1. TRUST 5框架 - 质量保证系统

Purpose: Automated quality gates ensuring code quality, security, and maintainability.
Five Pillars:
Tested Pillar: Maintain comprehensive test coverage with characterization tests ensuring behavior preservation. Execute pytest with coverage reporting. Block merge and generate missing tests on failure. Characterization tests capture current behavior for legacy code, while specification tests validate domain requirements for new code. High coverage ensures code reliability and reduces production defects. Preserves behavior during refactoring and reduces debugging time by 60-70 percent.
Readable Pillar: Use clear and descriptive naming conventions. Execute ruff linter checks. Issue warning and suggest refactoring improvements on failure. Clear naming improves code comprehension and team collaboration. Reduces onboarding time by 40 percent and improves maintenance velocity.
Unified Pillar: Apply consistent formatting and import patterns. Execute black formatter and isort checks. Auto-format code or issue warning on failure. Consistency eliminates style debates and merge conflicts. Reduces code review time by 30 percent and improves readability.
Secured Pillar: Comply with OWASP security standards. Execute security-expert agent analysis. Block merge and require security review on failure. Security vulnerabilities create critical business and legal risks. Prevents 95+ percent of common security vulnerabilities.
Trackable Pillar: Write clear and structured commit messages. Match Git commit message regex patterns. Suggest proper commit message format on failure. Clear history enables debugging, auditing, and collaboration. Reduces issue investigation time by 50 percent.
Integration Points: Pre-commit hooks for automated validation, CI/CD pipelines for quality gate enforcement, Agent workflows for core-quality validation, Documentation for quality metrics.
Detailed Reference: modules/trust-5-framework.md

目标:通过自动化质量门确保代码质量、安全性与可维护性。
五大支柱:
可测试支柱:通过特征测试维持全面的测试覆盖率,确保行为一致性。执行pytest并生成覆盖率报告。若失败则阻止合并并生成缺失的测试。特征测试捕获遗留代码的当前行为,而规范测试验证新代码的领域需求。高覆盖率确保代码可靠性,减少生产缺陷。在重构期间保留行为,将调试时间减少60-70%。
可读支柱:使用清晰且描述性的命名规范。执行ruff代码检查。若失败则发出警告并建议重构改进。清晰的命名提升代码理解度与团队协作效率。将入职时间减少40%,提升维护速度。
统一支柱:应用一致的格式与导入模式。执行black格式化工具与isort检查。若失败则自动格式化代码或发出警告。一致性消除风格争议与合并冲突。将代码审查时间减少30%,提升可读性。
安全支柱:遵循OWASP安全标准。执行security-expert Agent分析。若失败则阻止合并并要求安全审查。安全漏洞会带来严重的业务与法律风险。预防95%以上的常见安全漏洞。
可追踪支柱:撰写清晰且结构化的提交信息。匹配Git提交信息正则表达式模式。若失败则建议正确的提交信息格式。清晰的历史记录便于调试、审计与协作。将问题调查时间减少50%。
集成点:用于自动验证的预提交钩子、用于质量门强制执行的CI/CD流水线、用于核心质量验证的Agent工作流、用于质量指标的文档。
详细参考:modules/trust-5-framework.md

2. SPEC-First DDD - Development Workflow

2. SPEC-First DDD - 开发工作流

Purpose: Specification-driven development ensuring clear requirements before implementation.
Three-Phase Workflow:
Phase 1 SPEC (/moai:1-plan): workflow-spec generates EARS format. Output is .moai/specs/SPEC-XXX/spec.md. Execute /clear to save 45-50K tokens.
Phase 2 DDD (/moai:2-run): ANALYZE for requirements, PRESERVE for existing behavior, IMPROVE for enhancement. Validate with at least 85% coverage.
Phase 3 Docs (/moai:3-sync): API documentation, architecture diagrams, project reports.
EARS Format: Ubiquitous for system-wide always active requirements. Event-driven for trigger-based when X do Y requirements. State-driven for conditional while X do Y requirements. Unwanted for prohibited shall not do X requirements. Optional for nice-to-have where possible do X requirements.
Token Budget: SPEC takes 30K, DDD takes 180K, Docs takes 40K, Total is 250K.
Key Practice: Execute /clear after Phase 1 to initialize context.
Detailed Reference: modules/spec-first-ddd.md

目标:通过规范驱动的开发,确保在实现前明确需求。
三阶段工作流:
阶段1 SPEC(/moai:1-plan):workflow-spec生成EARS格式。输出为.moai/specs/SPEC-XXX/spec.md。执行/clear以节省45-50K Token。
阶段2 DDD(/moai:2-run):ANALYZE用于需求分析,PRESERVE用于保留现有行为,IMPROVE用于功能增强。验证覆盖率至少达到85%。
阶段3 文档(/moai:3-sync):API文档、架构图、项目报告。
EARS格式:通用型(适用于系统范围内始终有效的需求)、事件驱动型(适用于基于触发条件的“当X发生时执行Y”需求)、状态驱动型(适用于条件型“当X成立时执行Y”需求)、禁止型(适用于“不得执行X”的禁止性需求)、可选型(适用于“尽可能执行X”的锦上添花型需求)。
Token预算:SPEC阶段占用30K,DDD阶段占用180K,文档阶段占用40K,总计250K。
关键实践:完成阶段1后执行/clear以初始化上下文。
详细参考:modules/spec-first-ddd.md

3. Delegation Patterns - Agent Orchestration

3. 委托模式 - Agent编排

Purpose: Task delegation to specialized agents, avoiding direct execution.
Core Principle: MoAI must delegate all work through Task() to specialized agents. Direct execution bypasses specialization, quality gates, and token optimization. Proper delegation improves task success rate by 40 percent and enables parallel execution.
Delegation Syntax: Call Task with subagent_type parameter for specialized agent, prompt parameter for clear specific task, and context parameter with relevant data dictionary.
Three Patterns:
Sequential for dependencies: Call Task to api-designer for design, then Task to backend-expert for implementation with design context.
Parallel for independent work: Call Promise.all with Task to backend-expert and Task to frontend-expert simultaneously.
Conditional for analysis-based: Call Task to debug-helper for analysis, then based on analysis.type, call Task to security-expert or other appropriate agent.
Agent Selection: Simple tasks with 1 file use 1-2 agents sequential. Medium tasks with 3-5 files use 2-3 agents sequential. Complex tasks with 10+ files use 5+ agents mixed.
Detailed Reference: modules/delegation-patterns.md

目标:将任务委托给专业Agent,避免直接执行。
核心原则:MoAI必须通过Task()将所有工作委托给专业Agent。直接执行会绕过专业化处理、质量门与Token优化。正确的委托可将任务成功率提升40%,并支持并行执行。
委托语法:调用Task时传入subagent_type参数指定专业Agent,prompt参数传入清晰具体的任务,context参数传入相关数据字典。
三种模式:
顺序模式(适用于依赖任务):先调用Task委托给api-designer进行设计,再调用Task委托给backend-expert并传入设计上下文进行实现。
并行模式(适用于独立任务):使用Promise.all同时调用Task委托给backend-expert和frontend-expert。
条件模式(适用于基于分析的任务):先调用Task委托给debug-helper进行分析,再根据analysis.type调用Task委托给security-expert或其他合适的Agent。
Agent选择:处理1个文件的简单任务使用1-2个Agent顺序执行。处理3-5个文件的中等任务使用2-3个Agent顺序执行。处理10个以上文件的复杂任务使用5个以上Agent混合执行。
详细参考:modules/delegation-patterns.md

4. Token Optimization - Budget Management

4. Token优化 - 预算管理

Purpose: Efficient 200K token budget through strategic context management.
Budget Allocation:
SPEC Phase takes 30K tokens. Strategy is to load requirements only and execute /clear after completion. Specification phase requires minimal context for requirement analysis. Saves 45-50K tokens for implementation phase.
DDD Phase takes 180K tokens. Strategy is selective file loading, load only implementation-relevant files. Implementation requires deep context but not full codebase. Enables 70 percent larger implementations within budget.
Docs Phase takes 40K tokens. Strategy is result caching and template reuse. Documentation builds on completed work artifacts. Reduces redundant file reads by 60 percent.
Total Budget is 250K tokens across all phases. Phase separation with context reset between phases provides clean context boundaries and prevents token bloat. Enables 2-3x larger projects within same budget.
Token Saving Strategies:
Phase Separation: Execute /clear between phases, after /moai:1-plan to save 45-50K, when context exceeds 150K, after 50+ messages.
Selective Loading: Load only necessary files.
Context Optimization: Target 20-30K tokens.
Model Selection: Sonnet for quality, Haiku for speed and cost with 70% cheaper rates for 60-70% total savings.
Detailed Reference: modules/token-optimization.md

目标:通过战略上下文管理高效利用200K Token预算。
预算分配:
SPEC阶段占用30K Token。策略是仅加载需求,完成后执行/clear。规范阶段仅需最少的上下文用于需求分析。为实现阶段节省45-50K Token。
DDD阶段占用180K Token。策略是选择性加载文件,仅加载与实现相关的文件。实现阶段需要深度上下文,但无需完整代码库。在预算内支持规模提升70%的实现任务。
文档阶段占用40K Token。策略是结果缓存与模板复用。文档基于已完成的工作产物构建。将冗余文件读取减少60%。
所有阶段总计预算为250K Token。阶段分离并在各阶段之间重置上下文,提供清晰的上下文边界,防止Token膨胀。在相同预算内支持规模提升2-3倍的项目。
Token节省策略:
阶段分离:在阶段之间执行/clear,完成/moai:1-plan后执行以节省45-50K,当上下文超过150K时执行,或在50条以上消息后执行。
选择性加载:仅加载必要的文件。
上下文优化:目标为20-30K Token。
模型选择:Sonnet用于追求质量,Haiku用于追求速度与成本优势,其费率低70%,可节省60-70%的总成本。
详细参考:modules/token-optimization.md

5. Progressive Disclosure - Content Architecture

5. 渐进式披露 - 内容架构

Purpose: Three-tier knowledge delivery balancing value with depth.
Three Levels:
Quick Reference Level: 30 seconds time investment, core principles and essential concepts, approximately 1,000 tokens. Rapid value delivery for time-constrained users. Users gain 80 percent understanding in 5 percent of time.
Implementation Level: 5 minutes time investment, workflows, practical examples, integration patterns, approximately 3,000 tokens. Bridges concept to execution with actionable guidance. Enables immediate productive work without deep expertise.
Advanced Level: 10+ minutes time investment, deep technical dives, edge cases, optimization techniques, approximately 5,000 tokens. Provides mastery-level knowledge for complex scenarios. Reduces escalations by 70 percent through comprehensive coverage.
SKILL.md Structure (maximum 500 lines): Quick Reference section, Implementation Guide section, Advanced Patterns section, Works Well With section.
Module Architecture: SKILL.md as entry point with cross-references, modules directory for deep dives with unlimited size, examples.md for working samples, reference.md for external links.
File Splitting when exceeding 500 lines: SKILL.md contains Quick at 80-120 lines, Implementation at 180-250 lines, Advanced at 80-140 lines, References at 10-20 lines. Overflow content goes to modules/topic.md.
Detailed Reference: modules/progressive-disclosure.md

目标:通过三层知识交付平衡价值与深度。
三个层级:
快速参考层级:投入30秒时间,涵盖核心原则与基本概念,约1000 Token。为时间有限的用户快速传递价值。用户仅需投入5%的时间即可获得80%的理解。
实现层级:投入5分钟时间,涵盖工作流、实用示例、集成模式,约3000 Token。通过可操作的指导连接概念与执行。无需深厚专业知识即可立即开展有效工作。
高级层级:投入10分钟以上时间,涵盖深度技术剖析、边缘案例、优化技巧,约5000 Token。为复杂场景提供大师级知识。通过全面覆盖将问题升级率降低70%。
SKILL.md结构(最多500行):快速参考部分、实现指南部分、高级模式部分、协同使用部分。
模块架构:SKILL.md作为入口点包含交叉引用,modules目录用于存放无大小限制的深度剖析内容,examples.md用于存放可运行示例,reference.md用于存放外部链接。
当超过500行时拆分文件:SKILL.md包含80-120行的快速参考、180-250行的实现指南、80-140行的高级内容、10-20行的参考内容。溢出内容移至modules/topic.md。
详细参考:modules/progressive-disclosure.md

6. Modular System - File Organization

6. 模块化系统 - 文件组织

Purpose: Scalable file structure enabling unlimited content.
Standard Structure: Create .claude/skills/skill-name/ directory containing SKILL.md as core file under 500 lines, modules directory for extended content with unlimited size including patterns.md, examples.md for working samples, reference.md for external links, scripts directory for utilities (optional), templates directory (optional).
File Principles: SKILL.md stays under 500 lines with progressive disclosure and cross-references. modules directory is topic-focused with no limits and self-contained content. examples.md is copy-paste ready with comments. reference.md contains API docs and resources.
Cross-Reference Syntax: Reference modules as Details in modules/patterns.md, reference examples as Examples in examples.md#auth, reference external docs as External in reference.md#api.
Discovery Flow: SKILL.md to Topic to modules/topic.md to Deep dive.
Detailed Reference: modules/modular-system.md

目标:通过可扩展的文件结构支持无限内容。
标准结构:创建.claude/skills/skill-name/目录,包含核心文件SKILL.md(不超过500行),modules目录用于存放无大小限制的扩展内容(如patterns.md),examples.md用于存放可运行示例,reference.md用于存放外部链接,scripts目录用于存放工具(可选),templates目录(可选)。
文件原则:SKILL.md保持在500行以内,采用渐进式披露并包含交叉引用。modules目录按主题划分,内容独立且无大小限制。examples.md提供可直接复制使用的示例。reference.md包含API文档与资源。
交叉引用语法:引用模块为Details in modules/patterns.md,引用示例为Examples in examples.md#auth,引用外部文档为External in reference.md#api。
探索流程:SKILL.md → 主题 → modules/topic.md → 深度剖析。
详细参考:modules/modular-system.md

Advanced Implementation

高级实现

Advanced patterns including cross-module integration, quality validation, and error handling are available in the detailed module references.
Key Advanced Topics:
  • Cross-Module Integration: Combining TRUST 5 + SPEC-First DDD
  • Token-Optimized Delegation: Parallel execution with context reset
  • Progressive Agent Workflows: Escalation patterns
  • Quality Validation: Pre/Post execution validation
  • Error Handling: Delegation failure recovery
Detailed Reference: examples.md for working code samples

包括跨模块集成、质量验证与错误处理在内的高级模式可在详细模块参考中获取。
关键高级主题:
  • 跨模块集成:TRUST 5 + SPEC-First DDD的组合使用
  • 优化Token的委托:带上下文重置的并行执行
  • 渐进式Agent工作流:升级模式
  • 质量验证:执行前/后验证
  • 错误处理:委托失败恢复
详细参考:examples.md提供可运行的代码示例

Works Well With

协同使用

Agents: agent-factory for creating agents with foundation principles, skill-factory for generating skills with modular architecture, core-quality for automated TRUST 5 validation, workflow-spec for EARS format specification, workflow-ddd for ANALYZE-PRESERVE-IMPROVE execution, workflow-docs for documentation with progressive disclosure.
Skills: moai-cc-claude-md for CLAUDE.md with foundation patterns, moai-cc-configuration for config with TRUST 5, moai-cc-memory for token optimization, moai-context7-integration for MCP integration.
Tools: AskUserQuestion for direct user interaction and clarification needs.
Commands: /moai:1-plan for SPEC-First Phase 1, /moai:2-run for DDD Phase 2, /moai:3-sync for Documentation Phase 3, /moai:9-feedback for continuous improvement, /clear for token management.
Foundation Modules (Extended Documentation): modules/agents-reference.md for 26-agent catalog with 7-tier hierarchy, modules/commands-reference.md for 6 core commands workflow, modules/execution-rules.md for security, Git strategy, and compliance.

Agents:agent-factory用于遵循基础原则创建Agent,skill-factory用于生成具备模块化架构的Skill,core-quality用于自动TRUST 5验证,workflow-spec用于生成EARS格式规范,workflow-ddd用于执行ANALYZE-PRESERVE-IMPROVE,workflow-docs用于生成采用渐进式披露的文档。
Skills:moai-cc-claude-md用于遵循基础模式的CLAUDE.md,moai-cc-configuration用于遵循TRUST 5的配置,moai-cc-memory用于Token优化,moai-context7-integration用于MCP集成。
工具:AskUserQuestion用于直接用户交互与澄清需求。
命令:/moai:1-plan用于SPEC-First第一阶段,/moai:2-run用于DDD第二阶段,/moai:3-sync用于文档第三阶段,/moai:9-feedback用于持续改进,/clear用于Token管理。
基础模块(扩展文档):modules/agents-reference.md包含26个Agent的7层级目录,modules/commands-reference.md包含6个核心命令工作流,modules/execution-rules.md包含安全、Git策略与合规要求。

Quick Decision Guide

快速决策指南

New Agent: Primary principle is TRUST 5 and Delegation. Supporting principles are Token Optimization and Modular.
New Skill: Primary principle is Progressive and Modular. Supporting principles are TRUST 5 and Token Optimization.
Workflow: Primary principle is Delegation Patterns. Supporting principles are SPEC-First and Token Optimization.
Quality: Primary principle is TRUST 5 Framework. Supporting principle is SPEC-First DDD.
Budget: Primary principle is Token Optimization. Supporting principles are Progressive and Modular.
Docs: Primary principle is Progressive and Modular. Supporting principle is Token Optimization.
Module Deep Dives: modules/trust-5-framework.md, modules/spec-first-ddd.md, modules/delegation-patterns.md, modules/token-optimization.md, modules/progressive-disclosure.md, modules/modular-system.md, modules/agents-reference.md, modules/commands-reference.md, modules/execution-rules.md.
Full Examples: examples.md External Resources: reference.md
创建新Agent:核心原则为TRUST 5与委托模式。辅助原则为Token优化与模块化。
开发新Skill:核心原则为渐进式披露与模块化。辅助原则为TRUST 5与Token优化。
工作流编排:核心原则为委托模式。辅助原则为SPEC-First与Token优化。
质量保障:核心原则为TRUST 5框架。辅助原则为SPEC-First DDD。
预算管理:核心原则为Token优化。辅助原则为渐进式披露与模块化。
文档编写:核心原则为渐进式披露与模块化。辅助原则为Token优化。
模块深度剖析:modules/trust-5-framework.md、modules/spec-first-ddd.md、modules/delegation-patterns.md、modules/token-optimization.md、modules/progressive-disclosure.md、modules/modular-system.md、modules/agents-reference.md、modules/commands-reference.md、modules/execution-rules.md。
完整示例:examples.md 外部资源:reference.md