1
0

fix claude

This commit is contained in:
2025-06-01 23:35:22 +09:00
parent a9bdf20415
commit 575ea58b14
21 changed files with 2113 additions and 7 deletions

115
docs/architecture.md Normal file
View File

@ -0,0 +1,115 @@
# ai.shell Architecture
## 全体構成
```
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ User Input │ │ ai-shell CLI │ │ MCP Server │
│ (Terminal) │────▶│ (Rust) │────▶│ (Python) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │
│ ▼
│ ┌─────────────────┐
│ │ Local LLM │
│ │ (Ollama) │
│ └─────────────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ File System │ │ Code Analysis │
│ Operations │ │ & Generation │
└─────────────────┘ └─────────────────┘
```
## MCP Serverの主要な役割
### 1. **LLMとの通信ハブ**
- ローカルLLMOllamaとの通信を管理
- プロンプトの最適化と前処理
- レスポンスの後処理とフォーマット
### 2. **ツール実行エンジン**
MCP Serverは以下のツール関数を提供
```python
# 既存の実装から
- code_with_local_llm() # コード生成
- read_file_with_analysis() # ファイル読み込み&分析
- write_code_to_file() # コード書き込み
- debug_with_llm() # デバッグ支援
- explain_code() # コード説明
- execute_command() # シェルコマンド実行
- git_operations() # Git操作
```
### 3. **コンテキスト管理**
- プロジェクトのコンテキスト保持
- 会話履歴の管理
- ファイルの依存関係追跡
### 4. **セキュリティレイヤー**
- コマンドのサンドボックス実行
- ファイルアクセス権限の管理
- 危険な操作の検証
## Rust CLI ↔ MCP Server 通信
### 通信プロトコル
```rust
// Rust側のリクエスト例
struct MCPRequest {
method: String, // "code_with_local_llm"
params: Value, // {"prompt": "...", "language": "rust"}
context: ProjectContext,
}
// MCP Server側のレスポンス
{
"result": {
"code": "fn main() { ... }",
"explanation": "This creates a simple HTTP server...",
"files_created": ["src/server.rs"]
},
"error": null
}
```
### 実装の流れ
1. **ユーザー入力Rust CLI**
```
ai> create a web server in rust
```
2. **リクエスト構築Rust**
- プロンプト解析
- コンテキスト収集(現在のディレクトリ、プロジェクトタイプなど)
3. **MCP Server処理Python**
- ツール選択code_with_local_llm
- LLMへのプロンプト送信
- コード生成
- ファイル操作
4. **レスポンス処理Rust**
- 結果の表示
- ファイル変更の確認
- 次のアクションの提案
## なぜMCP Serverが必要か
### 1. **言語の分離**
- Python: AI/MLエコシステムが充実
- Rust: 高速で安全なCLI実装
### 2. **拡張性**
- 新しいLLMの追加が容易
- ツールの追加・変更が独立
### 3. **再利用性**
- 他のクライアントVS Code拡張などからも利用可能
- APIとして公開可能
### 4. **プロセス分離**
- LLMの重い処理とUIの軽快な動作を分離
- クラッシュ時の影響を最小化

153
docs/development-status.md Normal file
View File

@ -0,0 +1,153 @@
# ai.shell 開発状況
## プロジェクト概要
- **目的**: Claude Codeのようなローカル環境で動作するAIコーディングアシスタント
- **アーキテクチャ**: Rust CLI + Python MCP Server + Ollama (Local LLM)
- **作者**: syui
- **リポジトリ**: https://git.syui.ai/ai/shell
## 現在の実装状況
### ✅ 完了した機能
1. **基本アーキテクチャ**
- Rust CLIクライアント
- Python MCPサーバー
- HTTP REST API通信
2. **環境構築**
- `~/.config/ai-shell/` にPython venv環境
- セットアップスクリプト (`make setup`)
- 起動スクリプト
3. **CLI機能**
- インタラクティブモード
- ワンショット実行 (`ai-shell exec "prompt"`)
- ファイル分析 (`ai-shell analyze file`)
- ヘルスチェック (`ai-shell health`)
4. **コマンド**
- `/help` - ヘルプ表示
- `/clear` - 画面クリア
- `/model [name]` - モデル切り替えUI実装済み、機能は未実装
- `/analyze <file>` - ファイル分析
- `/create <type> <name>` - プロジェクト作成
5. **MCP Server API**
- `POST /execute` - ツール実行
- `GET /health` - ヘルスチェック
- `GET /tools` - 利用可能ツール一覧
## 🚧 未実装・改善が必要な機能
### 高優先度
1. **会話履歴の保持**
- 現在は単発のリクエストのみ
- コンテキストを維持した連続的な会話
2. **ファイル操作の安全性**
- ファイル書き込み前の確認
- バックアップ機能
- undo/redo機能
3. **エラーハンドリング**
- Ollamaが起動していない場合の対処
- ネットワークエラーの適切な処理
### 中優先度
1. **モデル切り替え機能**
- `/model` コマンドの実装
- 設定ファイルへの保存
2. **Git統合**
- `git diff` の解析
- コミットメッセージ生成
- ブランチ情報の取得
3. **プロジェクトテンプレート**
- より多くの言語サポート
- カスタムテンプレート
### 低優先度
1. **TUIモード**
- ratatuiを使用した分割画面
- プログレスバー表示
2. **プラグインシステム**
- カスタムツールの追加
- 外部コマンドの統合
## 技術的な詳細
### ディレクトリ構造
```
/Users/syui/ai/shell/
├── src/
│ ├── main.rs # CLIエントリーポイント
│ ├── lib.rs # ライブラリルート
│ ├── mcp_client.rs # MCPクライアント実装
│ ├── config.rs # 設定管理
│ ├── prompt.rs # プロンプト表示
│ └── commands.rs # コマンドハンドラー
├── mcp_server.py # MCPサーバー実装
├── requirements.txt # Python依存関係
├── Cargo.toml # Rust依存関係
└── scripts/
├── setup.sh # セットアップスクリプト
└── start.sh # 起動スクリプト
~/.config/ai-shell/ # ユーザー設定ディレクトリ
├── venv/ # Python仮想環境
├── config.toml # ユーザー設定
├── mcp_server.py # MCPサーバーコピー
└── bin/
├── ai-shell # CLIラッパー
└── mcp-server # サーバーラッパー
```
### 主要な依存関係
- **Rust**: clap, tokio, reqwest, colored, serde
- **Python**: aiohttp, requests, toml
- **LLM**: Ollama (qwen2.5-coder:7b)
## 次回の開発時の開始方法
```bash
# リポジトリに移動
cd /Users/syui/ai/shell
# 現在の状態を確認
git status
# サーバーを起動Terminal 1
make run-server
# CLIを起動Terminal 2
./target/debug/ai-shell
# または、セットアップ済みなら
ai-shell
```
## 重要な設計思想
1. **分離された責務**
- Rust: 高速なCLI、ユーザーインターフェース
- Python: AI/ML処理、MCPサーバー
- Ollama: ローカルLLM実行
2. **プライバシー重視**
- 完全ローカル動作
- 外部APIへの依存なし
3. **拡張性**
- MCPプロトコルによる標準化
- 新しいツールの追加が容易
## 参考リンク
- [プロジェクト哲学 (claude.md)](/Users/syui/ai/shell/claude.md)
- [MCPプロトコル仕様](/Users/syui/ai/shell/docs/mcp-protocol.md)
- [アーキテクチャ図](/Users/syui/ai/shell/docs/architecture.md)
---
最終更新: 2025-06-01

88
docs/mcp-protocol.md Normal file
View File

@ -0,0 +1,88 @@
# MCP Protocol Specification for ai.shell
## 通信プロトコル
### 基本仕様
- プロトコル: HTTP REST API
- エンコーディング: JSON
- 認証: なし(ローカル使用のため)
### エンドポイント
#### 1. ツール実行
```
POST /execute
Content-Type: application/json
{
"id": "uuid-v4",
"method": "tool_name",
"params": {
// tool specific parameters
},
"context": {
"current_dir": "/path/to/project",
"project_type": "rust",
"files": ["src/main.rs", "Cargo.toml"],
"git_branch": "main"
}
}
Response:
{
"id": "uuid-v4",
"result": {
// tool specific result
},
"error": null
}
```
#### 2. 利用可能ツール一覧
```
GET /tools
Response:
{
"tools": [
{
"name": "code_with_local_llm",
"description": "Generate code using local LLM",
"parameters": {
"prompt": "string",
"language": "string"
}
},
// ...
]
}
```
#### 3. ヘルスチェック
```
GET /health
Response:
{
"status": "ok",
"llm_status": "connected",
"version": "0.1.0"
}
```
## エラーコード
| Code | Description |
|------|-------------|
| 1001 | Invalid method |
| 1002 | Missing parameters |
| 1003 | LLM connection failed |
| 1004 | File operation failed |
| 1005 | Command execution failed |
| 2001 | Internal server error |
## タイムアウト設定
- デフォルト: 300秒LLM処理
- ファイル操作: 10秒
- コマンド実行: 60秒