一套讓人類工程師與 AI Agent 都能高效協作的 Repository 開發規範。
本文件定義 AI-Native Repository 的開發標準。
此標準的目標:
- 提升 Repository 可維護性
- 提升多人協作效率
- 提升 AI Agent 對專案的理解能力
- 降低 AI 修改程式碼時的風險
- 建立可擴展、可驗證、可自動化的工程流程
本規範適用於:
- Backend Service
- SDK / Library
- CLI Tool
- AI Service
- Agent Framework
- RAG System
- Microservice
- Internal Platform
Repository 不只提供人類閱讀。
也必須讓:
- AI Coding Assistant
- AI Agent
- Autonomous Development Tool
- CI Automation
- Code Review Agent
- Testing Agent
能夠:
- 理解架構
- 推理程式行為
- 安全修改程式
- 自動驗證
- 維持一致性
所有規範應盡量明確。
避免:
- 隱含規則
- 團隊默契
- 不可追蹤的架構決策
- 模糊命名
AI 對於 Explicit 規則的遵循能力遠高於 Implicit 規則。
除了人類可讀性外,Repository 必須具備:
- Machine-readable schema
- Structured metadata
- Standardized documentation
- Predictable directory layout
所有流程應盡可能:
- 可重現
- 可驗證
- 可測試
- 可自動化
AI Agent 高度依賴 deterministic workflow。
repo/
├── src/
├── tests/
├── docs/
├── examples/
├── scripts/
├── configs/
├── schemas/
├── deployments/
├── sdk/
├── .ai/
├── repo-meta/
├── .github/
├── pyproject.toml
├── tox.ini
├── Makefile
├── README.md
├── AGENTS.md
├── CLAUDE.md
├── ARCHITECTURE.md
├── CONTRIBUTING.md
├── DECISIONS.md
└── LICENSE
README 必須包含:
- Project Overview
- Features
- Installation
- Quick Start
- Architecture Summary
- Development Setup
- Testing
- Deployment
- Contribution Guide
README 是 AI 與人類理解專案的第一入口。
AI Agent 的主入口文件。
AI Agent 進入 Repository 後必須先閱讀 AGENTS.md,再開始執行任何任務。
應包含:
- Repository Knowledge Map(指引 Agent 依序閱讀所有相關文件)
- Coding Standards
- Testing Rules
- Architecture Constraints
- Forbidden Changes
- Dependency Rules
- Development Workflow(指向
.ai/workflows/) - Common Commands
建議的閱讀順序應明確定義於 AGENTS.md 中:
AGENTS.md
↓
ARCHITECTURE.md + DECISIONS.md ← 理解系統架構
↓
.ai/rules/* ← 學習詳細規則
↓
.ai/workflows/<task-type> ← 依任務類型選擇對應 workflow
範例:
# AGENTS.md
## Coding Rules
- All functions must have type hints
- No business logic inside routers
- Async code must not block event loop
## Testing Rules
- All new features require unit tests
- Integration tests required for API changes
## Forbidden
- Never modify production deployment
- Never commit secrets專為 Claude Code 設計的入口文件。
Claude Code 會在每個 session 開始時自動讀取 CLAUDE.md。
設計原則:
- 內容應極簡,只需引導 Claude Code 閱讀
AGENTS.md - 不重複
AGENTS.md的內容 - 確保 Claude Code 與其他 AI Agent 遵循相同的規範
範例:
# CLAUDE.md
This file is read automatically by Claude Code at the start of every session.
## Start Here
Read `AGENTS.md` before taking any action in this repository.其他 AI 工具(Cursor、Copilot 等)若有類似的自動讀取機制,可依相同模式建立對應的入口文件,並同樣指向 AGENTS.md。
定義:
- System boundaries
- Layer responsibilities
- Dependency flow
- Communication patterns
- Event flow
- Service interactions
範例:
Frontend
↓
API Gateway
↓
Application Layer
↓
Domain Layer
↓
Infrastructure Layer
應避免:
- Circular dependency
- Cross-layer access
- Shared mutable state
定義:
- Branch strategy
- Pull request rules
- Commit conventions
- Review process
- Local development workflow
紀錄架構決策。
範例:
# Decision: Use FastAPI
## Reason
- Async support
- OpenAPI integration
- Strong typing
## Alternatives
- Flask
- DjangoAI Agent 非常需要這些背景資訊。
src/
├── api/
├── application/
├── domain/
├── infrastructure/
├── models/
├── services/
└── utils/
負責:
- Request parsing
- Response formatting
- Authentication
- Validation
禁止:
- Business logic
- Database access
負責:
- Use case orchestration
- Workflow coordination
- Transaction handling
負責:
- Core business logic
- Domain entities
- Domain rules
禁止:
- Infrastructure dependency
負責:
- Database
- Cache
- External APIs
- Messaging systems
所有公開函式必須具有 type hints。
async def get_user(user_id: str) -> User:
...使用:
- ruff
- mypy
- pre-commit
user_id
request_timeoutUserService
OrderRepositoryMAX_RETRY_COUNT
DEFAULT_TIMEOUT禁止:
- Blocking I/O inside async function
- time.sleep()
- synchronous DB call in async context
應使用:
await asyncio.sleep(1)tests/
├── unit/
├── integration/
├── e2e/
└── fixtures/
| Type | Requirement |
|---|---|
| Unit Test | Required |
| Integration Test | Required for API changes |
| E2E Test | Required for critical flow |
- Every bug fix requires regression test
- Snapshot tests discouraged
- Tests must be deterministic
- Tests must not depend on external unstable services
使用:
- poetry
- requirements.txt
新增 dependency 時必須:
- 說明用途
- 避免 duplicate libraries
- 評估 maintenance status
- 評估 security risk
禁止:
- Automatic major upgrade
- Unreviewed dependency updates
sdk/ 存放 LLM 訓練資料中不存在、或專案內部正在開發的 SDK / package 原始碼。
當 Agent 遇到不認識的 import 時,應先查閱 sdk/ 目錄,而非依賴訓練資料猜測 API。
sdk/
├── REGISTRY.md ← 必要:所有 vendored SDK 的索引與 status 標記
├── <sdk-name>/ ← 必要:vendored 原始碼(原封不動)
│ └── src/
└── notes/ ← 選用:人工整理的 API 說明與使用範例
└── <sdk-name>.md
notes/ 為選用目錄。若存在,Agent 應優先閱讀,再進入原始碼 trace。
sdk/REGISTRY.md 是 Agent 的索引入口,應列出所有 vendored SDK 的基本資訊:
# SDK Registry
| Name | Status | Source Path | Purpose |
|-----------------------|----------|---------------------------|--------------------------|
| some-internal-sdk | internal | sdk/some-internal-sdk/ | 專案內部開發中的資料處理 SDK |
| some-new-external-sdk | vendored | sdk/some-new-external-sdk/| LLM 未知的第三方 SDK |Status 欄位說明:
internal— 專案內部開發,尚未發布為公開 packagevendored— 公開發布但 LLM 訓練資料不包含
AGENTS.md 必須包含明確的 SDK lookup 指引:
## SDK Knowledge
If you don't recognize an import, look up in this order:
1. `sdk/notes/<sdk-name>.md` — if exists, read this first
2. `sdk/<sdk-name>/src/` — vendored source for deep tracing
3. `sdk/REGISTRY.md` — index of all vendored SDKs
Never guess SDK APIs. Always trace the source before writing any call.repo-meta/dependencies.yaml 應標記每個 dependency 的 status,讓 Agent 一目了然哪些需要查 sdk/:
dependencies:
- name: fastapi
status: well-known # LLM 熟悉,可直接使用
- name: some-internal-sdk
status: internal
source: sdk/some-internal-sdk
- name: some-new-external-sdk
status: vendored
source: sdk/some-new-external-sdk
version: "0.3.1".github/workflows/
必須包含:
- lint
- type-check
- unit-test
- integration-test
- build
- security-scan
Pull Request 必須:
- All tests passing
- No lint errors
- No type errors
- Security scan passing
AI Agent 進入 Repository 的閱讀路徑應明確定義:
CLAUDE.md (Claude Code)
↓
AGENTS.md ← 所有 AI Agent 的主入口
↓
ARCHITECTURE.md + DECISIONS.md ← 系統架構與決策背景
↓
.ai/rules/* ← 詳細的 coding / testing / security 規則
↓
.ai/workflows/<task-type> ← 依任務類型執行對應 workflow
AGENTS.md 必須包含此閱讀路徑的說明,讓 Agent 知道每個文件的用途與閱讀時機。
.ai/
├── prompts/
├── rules/
├── workflows/
└── examples/
.ai/rules/ 存放語言與領域的詳細規範,供 Agent 在實作前閱讀:
.ai/rules/python.md ← type hints、async 規則、命名慣例、layer 限制
.ai/rules/testing.md ← 測試結構、覆蓋率要求、命名規範
.ai/rules/security.md ← 禁止行為、secret 管理、input validation
.ai/workflows/ 存放各任務類型的逐步流程,Agent 應依任務類型選擇對應文件:
.ai/workflows/
├── feature-development.md ← 新功能開發
├── bug-fix.md ← 先寫 regression test 再修 bug
├── release-process.md ← semantic versioning、changelog、發布
└── refactoring.md ← 行為不變的重構,測試先行
提供 AI 最容易成功的範例。
examples/
├── api-service/
├── worker-service/
├── sdk-library/
└── cli-tool/
AI Agent 通常會模仿 examples 的風格。
schemas/openapi.yaml
schemas/events/
schemas/config/
repo-meta/
├── ownership.yaml
├── dependencies.yaml
├── module-boundaries.yaml
└── service-catalog.yaml
禁止:
- Commit secrets
- Modify production infrastructure automatically
- Store credentials in source code
- Disable security scanning
應使用:
- Environment variables
- Secret manager
- Vault systems
禁止:
API_KEY = "hardcoded-secret"docs/
├── architecture/
├── domain/
├── api/
├── deployment/
├── runbooks/
└── onboarding/
docs/domain/
├── terminology.md
├── metrics.md
├── pubsub.md
└── workflows.md
AI RAG 系統非常適合使用這些知識。
feature/
fix/
refactor/
hotfix/
feat:
fix:
refactor:
test:
docs:
chore:
範例:
feat: add user authentication middleware
fix: resolve async session leak
若 commit 由 AI 協助產生,應使用標準 Git trailer 格式標記:
feat: add retry logic for external API calls
Co-Authored-By: AI Assistant <noreply@example.com>
禁止在 commit message、PR 標題或 PR 描述中出現:
- AI 工具名稱(如 Claude、ChatGPT)
- Session URL 或任何工具內部連結
- Create issue
- Define acceptance criteria
- Implement feature
- Add tests
- Run lint and type check
- Create pull request
- Code review
- Merge
PR 必須包含:
- Summary
- Motivation
- Test evidence
- Breaking changes
- Related issue
建議建立 organization-level template repository。
engineering-standards/
├── templates/
├── examples/
├── standards/
└── golden-path/
| Purpose | Tool |
|---|---|
| Formatting | ruff |
| Type Checking | mypy |
| Testing | pytest |
| Multi-version Test | tox |
| Dependency | poetry |
| Git Hooks | pre-commit |
- Clear repository structure
- AGENTS.md(含 Repository Knowledge Map)
- ARCHITECTURE.md
- CI/CD pipeline
- Type hints
- Deterministic tests
- Machine-readable schema
- Golden path examples
- CLAUDE.md(Claude Code 使用者)
- repo-meta/
- .ai/(含 rules/ 與 workflows/)
- Structured domain docs
- Architecture decision records
- OpenAPI schema
- Event schema
repo/
├── src/
├── tests/
├── docs/
├── .ai/
│ ├── rules/
│ └── workflows/
├── README.md
├── AGENTS.md
├── CLAUDE.md
├── ARCHITECTURE.md
├── pyproject.toml
└── .github/workflows/
AI-Native Repository 的核心目標:
- AI 可理解
- AI 可推理
- AI 可安全修改
- AI 可驗證
- AI 可維護
- AI 可自動化協作
最終建立:
Human + AI Collaborative Engineering System
未來可擴展:
- AI Code Review Agent
- AI Architecture Validation
- AI Dependency Analysis
- AI Security Review
- AI Test Generation
- AI Refactoring Workflow
- AI Release Automation
建立:
- README.md
- AGENTS.md
- ARCHITECTURE.md
- tests/
- CI pipeline
加入:
- ruff
- mypy
- pre-commit
- tox
- OpenAPI schema
建立:
- .ai/
- repo-meta/
- decision records
- golden path examples
導入:
- AI review workflow
- AI automation pipeline
- AI architecture validation
- autonomous testing
建議所有 Repository 明確定義 License:
- MIT
- Apache-2.0
- BSD-3-Clause
- Proprietary
避免 AI 或人類對授權產生誤解。
AI 時代的 Repository 已不只是程式碼儲存空間。
它同時也是:
- Knowledge Base
- Machine-readable System
- Collaboration Protocol
- Engineering Contract
- AI Operational Context
Repository 結構與規範品質,將直接影響:
- 開發效率
- 維護成本
- AI Agent 成功率
- 系統穩定性
- 團隊擴展能力
因此:
Repository Standardization 將成為 AI-Native Engineering 的核心基礎能力。
這是一個高度符合 Domain-Driven Design (DDD) 與 Clean Architecture 的完整 AI-Native Repository 目錄結構範例:
repo/
├── src/
│ ├── api/
│ │ ├── routers/
│ │ ├── middleware/
│ │ ├── dependencies/
│ │ └── schemas/
│ │
│ ├── application/
│ │ ├── services/
│ │ ├── use_cases/
│ │ ├── commands/
│ │ ├── queries/
│ │ └── dto/
│ │
│ ├── domain/
│ │ ├── entities/
│ │ ├── value_objects/
│ │ ├── repositories/
│ │ ├── events/
│ │ ├── exceptions/
│ │ └── specifications/
│ │
│ ├── infrastructure/
│ │ ├── database/
│ │ ├── cache/
│ │ ├── messaging/
│ │ ├── clients/
│ │ ├── repositories/
│ │ ├── observability/
│ │ └── security/
│ │
│ ├── shared/
│ │ ├── constants/
│ │ ├── enums/
│ │ ├── utilities/
│ │ ├── exceptions/
│ │ └── types/
│ │
│ ├── config/
│ ├── main.py
│ └── lifecycle.py
│
├── tests/
│ ├── unit/
│ ├── integration/
│ ├── contract/
│ ├── e2e/
│ ├── performance/
│ └── fixtures/
│
├── docs/
│ ├── architecture/
│ ├── domain/
│ ├── api/
│ ├── deployment/
│ ├── onboarding/
│ ├── runbooks/
│ └── decisions/
│
├── examples/
│ ├── api/
│ ├── sdk/
│ └── workflows/
│
├── scripts/
│ ├── development/
│ ├── deployment/
│ ├── migration/
│ └── maintenance/
│
├── configs/
│ ├── development/
│ ├── staging/
│ ├── production/
│ └── testing/
│
├── schemas/
│ ├── api/
│ ├── events/
│ ├── config/
│ └── database/
│
├── deployments/
│ ├── docker/
│ ├── kubernetes/
│ ├── helm/
│
├── sdk/
│ ├── REGISTRY.md
│ ├── <sdk-name>/
│ │ └── src/
│ └── notes/ ← optional
│ └── <sdk-name>.md
│
└── LICENSE