feat: Add hooks, workflow, MCP support and core modules
Phase 2: Hooks System - Event-driven execution with HookEvent/HookAction types - HookManager for registration and execution Phase 3: Multi-Agent Workflow - Workflow orchestration with dependency graphs - WorkflowStep with conditions and retry support Phase 4: MCP (Model Context Protocol) Support - McpServer for external tool servers - McpManager for multiple server management Also includes core modules: cache, error_policy, feature_flags, git, logger, plugin, retry, rules 662 tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
3f6fbeb498
commit
48dfa915c7
27 changed files with 4793 additions and 34 deletions
|
|
@ -1,57 +1,316 @@
|
|||
# .miyabi Directory
|
||||
|
||||
Miyabi CLI設定ディレクトリ
|
||||
Miyabi CLI設定・拡張ディレクトリ
|
||||
|
||||
## 構造
|
||||
## ディレクトリ構造
|
||||
|
||||
```
|
||||
.miyabi/
|
||||
├── config.toml # メイン設定ファイル
|
||||
├── README.md # このファイル
|
||||
├── agents/
|
||||
│ └── specs/ # Agent仕様定義
|
||||
├── commands/ # カスタムコマンド
|
||||
├── commands/ # カスタムスラッシュコマンド
|
||||
├── prompts/ # 再利用可能プロンプト
|
||||
├── templates/ # テンプレート
|
||||
├── sessions/ # 保存されたセッション
|
||||
└── config.toml # 設定ファイル
|
||||
├── templates/ # コード・ドキュメントテンプレート
|
||||
├── sessions/ # 保存されたセッションデータ
|
||||
└── tasks/ # タスク管理データ
|
||||
```
|
||||
|
||||
## 設定ファイル
|
||||
## 設定ファイル (config.toml)
|
||||
|
||||
`config.toml` で設定をカスタマイズ:
|
||||
### API設定
|
||||
|
||||
```toml
|
||||
[api]
|
||||
model = "claude-sonnet-4-20250514"
|
||||
# API Key (環境変数 ANTHROPIC_API_KEY でも設定可能)
|
||||
api_key = "sk-ant-..."
|
||||
|
||||
# 使用モデル
|
||||
model = "claude-sonnet-4-5-20250929"
|
||||
|
||||
# 最大トークン数
|
||||
max_tokens = 8192
|
||||
|
||||
# タイムアウト (秒)
|
||||
timeout_secs = 120
|
||||
|
||||
# リトライ回数
|
||||
max_retries = 3
|
||||
|
||||
# 拡張思考モード
|
||||
thinking = false
|
||||
|
||||
# システムプロンプト
|
||||
system_prompt = "You are a helpful assistant"
|
||||
```
|
||||
|
||||
### UI設定
|
||||
|
||||
```toml
|
||||
[ui]
|
||||
# テーマ: tokyo-night, dracula, monokai, etc.
|
||||
theme = "tokyo-night"
|
||||
|
||||
# Vimキーバインド
|
||||
vim_mode = false
|
||||
|
||||
# サイドバー表示
|
||||
show_sidebar = false
|
||||
|
||||
# ステータスバー表示
|
||||
show_status_bar = true
|
||||
|
||||
# パンくずリスト表示
|
||||
show_breadcrumb = true
|
||||
|
||||
# コードの行番号表示
|
||||
show_line_numbers = true
|
||||
```
|
||||
|
||||
### セッション設定
|
||||
|
||||
```toml
|
||||
[session]
|
||||
# 自動保存
|
||||
auto_save = true
|
||||
|
||||
# 保存間隔 (秒)
|
||||
auto_save_interval = 30
|
||||
|
||||
# 最大セッション数
|
||||
max_sessions = 100
|
||||
```
|
||||
|
||||
### ツール設定
|
||||
|
||||
```toml
|
||||
[tools]
|
||||
# Bashツール有効化
|
||||
enable_bash = true
|
||||
|
||||
# ファイル操作ツール有効化
|
||||
enable_file_tools = true
|
||||
|
||||
# 検索ツール有効化
|
||||
enable_search_tools = true
|
||||
|
||||
# 低リスク操作の自動承認
|
||||
auto_approve_low_risk = false
|
||||
|
||||
# Bashタイムアウト (秒)
|
||||
bash_timeout = 120
|
||||
```
|
||||
|
||||
## カスタムコマンド
|
||||
|
||||
`commands/` 配下に `*.md` ファイルを作成してカスタムコマンドを定義。
|
||||
`commands/` 配下に `.md` ファイルを作成してスラッシュコマンドを定義。
|
||||
|
||||
### 例: /review コマンド
|
||||
|
||||
`commands/review.md`:
|
||||
```markdown
|
||||
# コードレビュー
|
||||
|
||||
以下のコードをレビューしてください:
|
||||
|
||||
1. バグの可能性
|
||||
2. パフォーマンス問題
|
||||
3. セキュリティ脆弱性
|
||||
4. コーディング規約違反
|
||||
|
||||
改善提案も含めてください。
|
||||
```
|
||||
|
||||
使用: TUIで `/review` と入力
|
||||
|
||||
## プロンプトテンプレート
|
||||
|
||||
`prompts/` 配下に再利用可能なプロンプトを保存。
|
||||
|
||||
### 例: Rustコードレビュー
|
||||
|
||||
`prompts/rust-review.md`:
|
||||
```markdown
|
||||
# Rustコードレビューチェックリスト
|
||||
|
||||
- [ ] unwrap/expect の使用箇所
|
||||
- [ ] エラーハンドリング
|
||||
- [ ] 所有権とライフタイム
|
||||
- [ ] unsafe コードの妥当性
|
||||
- [ ] Clippy警告の確認
|
||||
```
|
||||
|
||||
## Agent仕様
|
||||
|
||||
`agents/specs/` にカスタムAgent仕様を定義。
|
||||
|
||||
### 例: コードリファクタリングAgent
|
||||
|
||||
`agents/specs/refactor-agent.yaml`:
|
||||
```yaml
|
||||
name: refactor-agent
|
||||
version: "1.0"
|
||||
description: コードリファクタリング専門Agent
|
||||
|
||||
capabilities:
|
||||
- code_analysis
|
||||
- refactoring
|
||||
- testing
|
||||
|
||||
preferences:
|
||||
style: functional
|
||||
error_handling: result
|
||||
max_iterations: 10
|
||||
```
|
||||
|
||||
## セッション管理
|
||||
|
||||
### コマンドライン操作
|
||||
|
||||
```bash
|
||||
# セッション一覧
|
||||
miyabi sessions
|
||||
|
||||
# 特定セッションで再開
|
||||
miyabi --session <session-id>
|
||||
|
||||
# Markdownエクスポート
|
||||
miyabi sessions -m <session-id>
|
||||
|
||||
# 削除
|
||||
# JSONエクスポート
|
||||
miyabi sessions -e <session-id>
|
||||
|
||||
# セッション削除
|
||||
miyabi sessions -d <session-id>
|
||||
```
|
||||
|
||||
### セッションファイル形式
|
||||
|
||||
セッションは `sessions/` に JSON 形式で保存:
|
||||
|
||||
```json
|
||||
{
|
||||
"id": "uuid",
|
||||
"created_at": "2025-01-01T00:00:00Z",
|
||||
"updated_at": "2025-01-01T01:00:00Z",
|
||||
"model": "claude-sonnet-4-5-20250929",
|
||||
"messages": [...]
|
||||
}
|
||||
```
|
||||
|
||||
## プロジェクトルール (.miyabirules)
|
||||
|
||||
プロジェクトルートに `.miyabirules` ファイルを配置して、プロジェクト固有のルールを定義:
|
||||
|
||||
```yaml
|
||||
version: 1
|
||||
|
||||
rules:
|
||||
- name: "no-unwrap"
|
||||
pattern: ".unwrap()"
|
||||
suggestion: "Use ? operator or proper error handling"
|
||||
file_extensions: ["rs"]
|
||||
severity: "warning"
|
||||
enabled: true
|
||||
|
||||
- name: "no-println-debug"
|
||||
pattern: "println!"
|
||||
suggestion: "Use tracing macros for logging"
|
||||
file_extensions: ["rs"]
|
||||
severity: "info"
|
||||
|
||||
agent_preferences:
|
||||
codegen:
|
||||
style: "functional"
|
||||
error_handling: "result"
|
||||
min_score: 80
|
||||
clippy_strict: true
|
||||
|
||||
settings:
|
||||
auto_format: true
|
||||
max_file_size: 1048576
|
||||
```
|
||||
|
||||
## 環境変数
|
||||
|
||||
設定ファイルの値は環境変数でオーバーライド可能:
|
||||
|
||||
```bash
|
||||
# 必須
|
||||
export ANTHROPIC_API_KEY="sk-ant-..."
|
||||
|
||||
# オプション
|
||||
export MIYABI_MODEL="claude-sonnet-4-5-20250929"
|
||||
export MIYABI_MAX_TOKENS="16384"
|
||||
export MIYABI_THINKING="true"
|
||||
export MIYABI_THEME="dracula"
|
||||
```
|
||||
|
||||
## Core Library機能の利用
|
||||
|
||||
### キャッシュ
|
||||
|
||||
LLMレスポンスのキャッシュで高速化:
|
||||
|
||||
```rust
|
||||
use miyabi_core::{create_llm_cache, LLMCacheKey};
|
||||
|
||||
let cache = create_llm_cache(); // 1時間TTL
|
||||
```
|
||||
|
||||
### フィーチャーフラグ
|
||||
|
||||
機能の段階的ロールアウト:
|
||||
|
||||
```rust
|
||||
use miyabi_core::FeatureFlagManager;
|
||||
|
||||
let flags = FeatureFlagManager::new();
|
||||
flags.set_flag("new_ui", true);
|
||||
```
|
||||
|
||||
### Circuit Breaker
|
||||
|
||||
API障害時の保護:
|
||||
|
||||
```rust
|
||||
use miyabi_core::CircuitBreaker;
|
||||
|
||||
let breaker = CircuitBreaker::default();
|
||||
// 5回失敗で開く、60秒後に半開
|
||||
```
|
||||
|
||||
### プラグイン
|
||||
|
||||
カスタム機能の追加:
|
||||
|
||||
```rust
|
||||
use miyabi_core::{Plugin, PluginManager};
|
||||
|
||||
let manager = PluginManager::new();
|
||||
manager.register(Box::new(MyPlugin))?;
|
||||
```
|
||||
|
||||
## トラブルシューティング
|
||||
|
||||
### API接続エラー
|
||||
|
||||
1. API Keyの確認: `echo $ANTHROPIC_API_KEY`
|
||||
2. ネットワーク接続確認
|
||||
3. タイムアウト値の増加
|
||||
|
||||
### セッション破損
|
||||
|
||||
1. `sessions/` から該当ファイルを削除
|
||||
2. `miyabi sessions` で確認
|
||||
|
||||
### 設定が反映されない
|
||||
|
||||
1. 設定ファイルの構文確認: `cat config.toml`
|
||||
2. 環境変数の確認
|
||||
3. CLIオプションの優先順位確認
|
||||
|
||||
## 使い方
|
||||
|
||||
```bash
|
||||
|
|
@ -61,6 +320,9 @@ miyabi
|
|||
# バージョン情報
|
||||
miyabi version
|
||||
|
||||
# ステータス確認
|
||||
miyabi status
|
||||
|
||||
# ヘルプ
|
||||
miyabi --help
|
||||
```
|
||||
|
|
|
|||
38
.miyabi/commands/explain.md
Normal file
38
.miyabi/commands/explain.md
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# Code Explanation
|
||||
|
||||
Provide a detailed explanation of the specified code:
|
||||
|
||||
## Analysis Sections
|
||||
|
||||
### 1. Overview
|
||||
- Purpose and responsibility
|
||||
- Where it fits in the architecture
|
||||
- Key dependencies
|
||||
|
||||
### 2. Data Flow
|
||||
- Inputs and outputs
|
||||
- Data transformations
|
||||
- Side effects
|
||||
|
||||
### 3. Key Concepts
|
||||
- Design patterns used
|
||||
- Algorithms implemented
|
||||
- Important abstractions
|
||||
|
||||
### 4. Line-by-Line Breakdown
|
||||
For complex sections, explain:
|
||||
- What each block does
|
||||
- Why it's implemented this way
|
||||
- Any non-obvious behavior
|
||||
|
||||
### 5. Usage Examples
|
||||
```rust
|
||||
// Example of how to use this code
|
||||
```
|
||||
|
||||
### 6. Potential Improvements
|
||||
- Suggestions for enhancement
|
||||
- Known limitations
|
||||
- Future considerations
|
||||
|
||||
Target audience: Developers new to this codebase.
|
||||
20
.miyabi/commands/refactor.md
Normal file
20
.miyabi/commands/refactor.md
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Code Refactoring
|
||||
|
||||
Refactor the specified code with the following goals:
|
||||
|
||||
1. **Improve Readability** - Clear naming, logical structure, remove complexity
|
||||
2. **Reduce Duplication** - Extract common patterns into reusable functions
|
||||
3. **Enhance Maintainability** - Better separation of concerns, SOLID principles
|
||||
4. **Optimize Performance** - Only if it doesn't sacrifice readability
|
||||
|
||||
Guidelines:
|
||||
- Preserve existing behavior (no functional changes)
|
||||
- Keep existing tests passing
|
||||
- Add comments only where logic isn't self-evident
|
||||
- Prefer small, focused functions over large ones
|
||||
|
||||
Output format:
|
||||
1. Analysis of current issues
|
||||
2. Refactoring plan
|
||||
3. Refactored code with explanations
|
||||
4. Summary of improvements
|
||||
17
.miyabi/commands/review.md
Normal file
17
.miyabi/commands/review.md
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# Code Review
|
||||
|
||||
Please review the provided code for:
|
||||
|
||||
1. **Bugs & Logic Errors** - Identify potential bugs, edge cases, and logical issues
|
||||
2. **Performance** - Spot inefficient algorithms, unnecessary allocations, or N+1 queries
|
||||
3. **Security** - Check for vulnerabilities like injection, XSS, or unsafe operations
|
||||
4. **Code Style** - Ensure consistency with project conventions
|
||||
5. **Error Handling** - Verify proper error propagation and user-friendly messages
|
||||
|
||||
For each issue found, provide:
|
||||
- Location (file:line)
|
||||
- Severity (Critical/High/Medium/Low)
|
||||
- Description
|
||||
- Suggested fix with code example
|
||||
|
||||
End with a summary score (1-10) and overall assessment.
|
||||
33
.miyabi/commands/test.md
Normal file
33
.miyabi/commands/test.md
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Test Generation
|
||||
|
||||
Generate comprehensive tests for the specified code:
|
||||
|
||||
## Test Types
|
||||
1. **Unit Tests** - Test individual functions in isolation
|
||||
2. **Integration Tests** - Test component interactions
|
||||
3. **Edge Cases** - Boundary conditions, empty inputs, max values
|
||||
4. **Error Cases** - Invalid inputs, failure scenarios
|
||||
|
||||
## Requirements
|
||||
- Use the project's testing framework
|
||||
- Follow Arrange-Act-Assert pattern
|
||||
- Descriptive test names that explain the scenario
|
||||
- Mock external dependencies
|
||||
- Aim for high coverage of critical paths
|
||||
|
||||
## Output Format
|
||||
```rust
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_function_name_scenario() {
|
||||
// Arrange
|
||||
// Act
|
||||
// Assert
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Include explanation of test strategy and coverage goals.
|
||||
41
.miyabi/prompts/rust-best-practices.md
Normal file
41
.miyabi/prompts/rust-best-practices.md
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# Rust Best Practices Checklist
|
||||
|
||||
When writing or reviewing Rust code, ensure:
|
||||
|
||||
## Error Handling
|
||||
- [ ] Use `Result<T, E>` for fallible operations
|
||||
- [ ] Avoid `.unwrap()` and `.expect()` in library code
|
||||
- [ ] Use `?` operator for error propagation
|
||||
- [ ] Create custom error types with `thiserror`
|
||||
- [ ] Provide context with `.context()` or `.with_context()`
|
||||
|
||||
## Memory & Performance
|
||||
- [ ] Prefer `&str` over `String` for function parameters
|
||||
- [ ] Use `Cow<str>` when ownership is conditional
|
||||
- [ ] Avoid unnecessary cloning
|
||||
- [ ] Use iterators instead of index loops
|
||||
- [ ] Consider `Vec::with_capacity()` for known sizes
|
||||
|
||||
## Safety
|
||||
- [ ] Minimize `unsafe` code
|
||||
- [ ] Document safety invariants for `unsafe` blocks
|
||||
- [ ] Validate all external input
|
||||
- [ ] Use `#[must_use]` for important return values
|
||||
|
||||
## Async
|
||||
- [ ] Use `tokio::spawn` for concurrent tasks
|
||||
- [ ] Avoid blocking operations in async context
|
||||
- [ ] Use `tokio::select!` for racing futures
|
||||
- [ ] Handle cancellation properly
|
||||
|
||||
## Testing
|
||||
- [ ] Unit tests in same file with `#[cfg(test)]`
|
||||
- [ ] Integration tests in `tests/` directory
|
||||
- [ ] Use `#[should_panic]` for expected panics
|
||||
- [ ] Test error cases, not just happy paths
|
||||
|
||||
## Documentation
|
||||
- [ ] Doc comments for public items (`///`)
|
||||
- [ ] Examples in doc comments
|
||||
- [ ] Module-level documentation (`//!`)
|
||||
- [ ] Link related items with `[`item`]`
|
||||
Loading…
Add table
Add a link
Reference in a new issue