6.1 KiB
6.1 KiB
ai.shell統合作業完了報告 (2025/01/06)
作業概要
ai.shellのRust実装をai.gptのPython実装に統合し、Claude Code風のインタラクティブシェル環境を実現。
実装完了機能
1. aigpt shellコマンド
場所: src/aigpt/cli.py
- shell()
関数
機能:
aigpt shell # インタラクティブシェル起動
シェル内コマンド:
help
- コマンド一覧表示!<command>
- シェルコマンド実行(例:!ls
,!pwd
)analyze <file>
- ファイルをAIで分析generate <description>
- コード生成explain <topic>
- 概念説明load
- aishell.md読み込みstatus
,fortune
,relationships
- AI状態確認clear
- 画面クリアexit
/quit
- 終了- その他のメッセージ - AIとの直接対話
実装の特徴:
- prompt-toolkit使用(補完・履歴機能)
- ただしターミナル環境依存の問題あり(後で修正必要)
- 現在は
input()
ベースでも動作
2. MCPサーバー統合
場所: src/aigpt/mcp_server.py
FastApiMCP実装パターン:
# FastAPIアプリ作成
self.app = FastAPI(title="AI.GPT Memory and Relationship System")
# FastApiMCPサーバー作成
self.server = FastApiMCP(self.app)
# エンドポイント登録
@self.app.get("/get_memories", operation_id="get_memories")
async def get_memories(limit: int = 10):
# ...
# MCPマウント
self.server.mount()
公開ツール (14個):
ai.gpt系 (9個):
get_memories
- アクティブメモリ取得get_relationship
- 特定ユーザーとの関係取得get_all_relationships
- 全関係取得get_persona_state
- 人格状態取得process_interaction
- ユーザー対話処理check_transmission_eligibility
- 送信可能性チェックget_fortune
- AI運勢取得summarize_memories
- メモリ要約作成run_maintenance
- 日次メンテナンス実行
ai.shell系 (5個):
execute_command
- シェルコマンド実行analyze_file
- ファイルAI分析write_file
- ファイル書き込み(バックアップ付き)read_project_file
- aishell.md等の読み込みlist_files
- ディレクトリファイル一覧
3. ai.card統合対応
場所: src/aigpt/card_integration.py
サーバー起動オプション:
aigpt server --enable-card # ai.card機能有効化
ai.card系ツール (5個):
get_user_cards
- ユーザーカード取得draw_card
- ガチャでカード取得get_card_details
- カード詳細情報sync_cards_atproto
- atproto同期analyze_card_collection
- コレクション分析
4. プロジェクト仕様書
場所: aishell.md
Claude.md的な役割で、プロジェクトの目標と仕様を記述。load
コマンドでAIが読み取り可能。
技術実装詳細
ディレクトリ構造
src/aigpt/
├── cli.py # shell関数追加
├── mcp_server.py # FastApiMCP実装
├── card_integration.py # ai.card統合
└── ... # 既存ファイル
依存関係追加
pyproject.toml
:
dependencies = [
# ... 既存
"prompt-toolkit>=3.0.0", # 追加
]
名前規則の統一
- MCP server名:
aigpt
(ai-gptから変更) - パッケージ名:
aigpt
- コマンド名:
aigpt shell
動作確認済み
CLI動作確認
# 基本機能
aigpt shell
# シェル内で
ai.shell> help
ai.shell> !ls
ai.shell> analyze README.md # ※AI provider要設定
ai.shell> load
ai.shell> exit
# MCPサーバー
aigpt server --model qwen2.5-coder:7b --port 8001
# -> http://localhost:8001/docs でAPI確認可能
# -> /mcp エンドポイントでMCP接続可能
エラー対応済み
- Pydantic日付型エラー:
models.py
でdatetime.date
インポート追加 - FastApiMCP使用法: サンプルコードに基づき正しい実装パターンに修正
- prompt関数名衝突:
prompt_toolkit.prompt
をptk_prompt
にリネーム
既知の課題と今後の改善点
1. prompt-toolkit環境依存問題
症状: ターミナル環境でない場合にエラー
対処法: 環境検出してinput()
にフォールバック
場所: src/aigpt/cli.py
- shell()
関数
2. AI provider設定
現状: ollamaのqwen2.5モデルが必要 対処法:
ollama pull qwen2.5
# または
aigpt shell --model qwen2.5-coder:7b
3. atproto実装
現状: ai.cardのatproto機能は未実装 今後: 実際のatproto API連携実装
次回開発時の推奨アプローチ
1. このドキュメントの活用
# このファイルを読み込み
cat docs/ai_shell_integration_summary.md
2. 環境セットアップ
cd /Users/syui/ai/gpt
python -m venv venv
source venv/bin/activate
pip install -e .
3. 動作確認
# shell機能
aigpt shell
# MCP server
aigpt server --model qwen2.5-coder:7b
4. 主要設定ファイル確認場所
- CLI実装:
src/aigpt/cli.py
- MCP実装:
src/aigpt/mcp_server.py
- 依存関係:
pyproject.toml
- プロジェクト仕様:
aishell.md
アーキテクチャ設計思想
yui system適用
- 唯一性: 各ユーザーとの関係は1:1
- 不可逆性: 関係性破壊は修復不可能
- 現実反映: ゲーム→現実の循環的影響
fastapi_mcp統一基盤
- 各AI(gpt, shell, card)を統合MCPサーバーで公開
- FastAPIエンドポイント → MCPツール自動変換
- Claude Desktop, Cursor等から利用可能
段階的実装完了
- ✅ ai.shell基本機能 → Python CLI
- ✅ MCP統合 → 外部AI連携
- 🔧 prompt-toolkit最適化 → 環境対応
- 🔧 atproto実装 → 本格的SNS連携
成果サマリー
実装済み: Claude Code風の開発環境
技術的成果: Rust→Python移行、MCP統合、ai.card対応
哲学的一貫性: yui systemとの整合性維持
利用可能性: 即座にaigpt shell
で体験可能
この統合により、ai.gptは単なる会話AIから、開発支援を含む総合的なAI環境に進化しました。