# context_engineering_MCP - Claude Code Context

## プロジェクト概要

**context_engineering_MCP** - Miyabiフレームワークで構築された自律型開発プロジェクト

このプロジェクトは識学理論(Shikigaku Theory)とAI Agentsを組み合わせた自律型開発環境で運用されています。

## 🌸 Miyabi Framework

### 7つの自律エージェント

1. **CoordinatorAgent** - タスク統括・並列実行制御
   - DAG（Directed Acyclic Graph）ベースのタスク分解
   - Critical Path特定と並列実行最適化

2. **IssueAgent** - Issue分析・ラベル管理
   - 識学理論65ラベル体系による自動分類
   - タスク複雑度推定（小/中/大/特大）

3. **CodeGenAgent** - AI駆動コード生成
   - Claude Sonnet 4による高品質コード生成
   - TypeScript strict mode完全対応

4. **ReviewAgent** - コード品質判定
   - 静的解析・セキュリティスキャン
   - 品質スコアリング（100点満点、80点以上で合格）

5. **PRAgent** - Pull Request自動作成
   - Conventional Commits準拠
   - Draft PR自動生成

6. **DeploymentAgent** - CI/CDデプロイ自動化
   - 自動デプロイ・ヘルスチェック
   - 自動Rollback機能

7. **TestAgent** - テスト自動実行
   - テスト実行・カバレッジレポート
   - 80%+カバレッジ目標

## GitHub OS Integration

このプロジェクトは「GitHubをOSとして扱う」設計思想で構築されています:

### 自動化されたワークフロー

1. **Issue作成** → IssueAgentが自動ラベル分類
2. **CoordinatorAgent** → タスクをDAG分解、並列実行プラン作成
3. **CodeGenAgent** → コード実装、テスト生成
4. **ReviewAgent** → 品質チェック（80点以上で次へ）
5. **TestAgent** → テスト実行（カバレッジ確認）
6. **PRAgent** → Draft PR作成
7. **DeploymentAgent** → マージ後に自動デプロイ

**全工程が自律実行、人間の介入は最小限。**

## プロジェクト構造

```
context_engineering_MCP/
├── main.py                      # AI Guides API server (port 8888)
├── gemini_service.py           # Gemini AI integration service
├── scripts/                    # Convenience scripts for common tasks
│   ├── quickstart.sh           # Full platform setup
│   ├── start_context_engineering.sh  # Context Engineering system
│   ├── run-mcp-server.sh       # MCP server startup
│   ├── test-mcp.sh            # MCP server testing
│   └── start_workflow_system.sh # Workflow system
├── context_engineering/        # Context Engineering system (port 9003)
│   ├── context_models.py       # Core data models (Pydantic/dataclass)
│   ├── context_analyzer.py     # AI-powered context analysis
│   ├── context_optimizer.py    # Multi-strategy optimization
│   ├── template_manager.py     # Template CRUD and rendering
│   ├── context_api.py          # FastAPI server
│   └── templates/              # Stored prompt templates
├── mcp-server/                 # MCP server implementations
│   ├── index.js                # Basic AI guides MCP server
│   ├── context_mcp_server.js   # Full platform MCP server (21 tools)
│   └── package.json            # Node.js dependencies
├── workflow_system/            # Workflow automation (experimental)
├── .claude/                    # Claude Code設定
│   ├── agents/                 # Agent定義
│   ├── commands/               # カスタムコマンド
│   └── settings.json           # Claude設定
├── .github/
│   └── workflows/              # GitHub Actions
├── examples/                   # Usage examples and tutorials
└── requirements.txt            # Unified Python dependencies
```

## ラベル体系（識学理論準拠）

### 10カテゴリー、53ラベル

- **type:** bug, feature, refactor, docs, test, chore, security
- **priority:** P0-Critical, P1-High, P2-Medium, P3-Low
- **state:** pending, analyzing, implementing, reviewing, testing, deploying, done
- **agent:** codegen, review, deployment, test, coordinator, issue, pr
- **complexity:** small, medium, large, xlarge
- **phase:** planning, design, implementation, testing, deployment
- **impact:** breaking, major, minor, patch
- **category:** frontend, backend, infra, dx, security
- **effort:** 1h, 4h, 1d, 3d, 1w, 2w
- **blocked:** waiting-review, waiting-deployment, waiting-feedback

## 開発ガイドライン

### セットアップ

#### Quick Start (Recommended)
```bash
# Use the convenience script for full setup
./quickstart.sh
```

#### Manual Setup

##### 1. AI Guides API Server (Port 8888)
```bash
# Install Python dependencies
pip install -r requirements.txt

# Run AI Guides server
uvicorn main:app --host 0.0.0.0 --port 8888 --reload
```

##### 2. Context Engineering System (Port 9003)
```bash
cd context_engineering
pip install -r requirements.txt
python context_api.py
```

##### 3. MCP Server
```bash
cd mcp-server
npm install
node context_mcp_server.js
```

### セキュリティ

- **機密情報は環境変数で管理**: `GITHUB_TOKEN`, `ANTHROPIC_API_KEY`, `GEMINI_API_KEY`
- **.env を .gitignore に含める**
- **Webhook検証**: HMAC-SHA256署名検証

### テスト

```bash
# Run all tests
pytest

# Run with coverage
pytest --cov=. --cov-report=html

# Test MCP server
./test-mcp.sh
```

目標: 80%+ カバレッジ

## Architecture & Technical Decisions

### Core Architecture Patterns
1. **Multi-Service Design**: Three independent FastAPI services (AI Guides, Context Engineering, Workflow)
2. **MCP Protocol Integration**: Native Claude Desktop support with stdio transport
3. **Async-First Design**: All I/O operations use asyncio for high concurrency
4. **Type Safety**: Comprehensive type hints with Pydantic models and dataclasses

### Data Models Architecture
- **ContextElement**: Basic building blocks with content, type, priority
- **ContextWindow**: Collections of elements with token management
- **ContextSession**: High-level groupings for project organization
- **PromptTemplate**: Reusable components with variable substitution

### AI Integration Strategy
- **AI Provider**: Gemini 2.0 Flash for all AI operations
- **Rate Limiting**: Built-in respect for Gemini API limits (60 RPM)
- **Error Recovery**: Graceful degradation when AI services are unavailable

## 使用方法

### Issue作成（Claude Code推奨）

```bash
# Claude Code から直接実行
gh issue create --title "機能追加: ユーザー認証" --body "JWT認証を実装"
```

または Claude Code のスラッシュコマンド:

```
/create-issue
```

### 状態確認

```bash
npx miyabi status          # 現在の状態
npx miyabi status --watch  # リアルタイム監視
```

### Agent実行

```bash
/agent-run                 # Claude Code から実行
```

## カスタムスラッシュコマンド

Claude Code で以下のコマンドが使用可能:

- `/test` - プロジェクト全体のテストを実行
- `/generate-docs` - コードからドキュメント自動生成
- `/create-issue` - Agent実行用Issueを対話的に作成
- `/deploy` - デプロイ実行
- `/verify` - システム動作確認（環境・コンパイル・テスト）
- `/security-scan` - セキュリティ脆弱性スキャン実行
- `/agent-run` - Autonomous Agent実行（Issue自動処理パイプライン）

## 識学理論（Shikigaku Theory）5原則

1. **責任の明確化** - 各AgentがIssueに対する責任を負う
2. **権限の委譲** - Agentは自律的に判断・実行可能
3. **階層の設計** - CoordinatorAgent → 各専門Agent
4. **結果の評価** - 品質スコア、カバレッジ、実行時間で評価
5. **曖昧性の排除** - DAGによる依存関係明示、状態ラベルで進捗可視化

## 環境変数

```bash
# Gemini API Key（必須）
GEMINI_API_KEY=your_gemini_api_key_here

# GitHub Personal Access Token（必須）
GITHUB_TOKEN=ghp_xxxxx

# Anthropic API Key（Agent実行時）
ANTHROPIC_API_KEY=sk-ant-xxxxx
```

## サポート

- **Framework**: [Miyabi](https://github.com/ShunsukeHayashi/Autonomous-Operations)
- **Documentation**: README.md
- **Issues**: GitHub Issues で管理

---

🌸 **Miyabi** - Beauty in Autonomous Development

*このファイルは Claude Code が自動的に参照します。プロジェクトの変更に応じて更新してください。*
