Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 13m53s
## HTTP Client Refactoring - Create unified HttpClient module (src/http_client.rs) - Refactor 24 files to use shared HTTP client - Replace .unwrap() with proper error handling - Eliminate code duplication in HTTP requests ## Project Restructuring - Rename package: ai → aibot - Add dual binary support: aibot (main) + ai (compatibility alias) - Migrate config directory: ~/.config/ai/ → ~/.config/syui/ai/bot/ - Implement backward compatibility with automatic migration ## Testing Infrastructure - Add unit tests for HttpClient - Create test infrastructure with cargo-make - Add test commands: test, test-quick, test-verbose ## Documentation - Complete migration guide with step-by-step instructions - Updated development guide with new structure - HTTP client API reference documentation - Comprehensive refactoring summary ## Files Changed - Modified: 24 source files (HTTP client integration) - Added: src/http_client.rs, src/alias.rs, src/tests/ - Added: 5 documentation files in docs/ - Added: migration setup script 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
6.8 KiB
6.8 KiB
ai.bot 段階的移行ガイド
概要
ai.botプロジェクトの命名規則とディレクトリ構造を統一するための段階的移行作業の記録です。
移行内容
1. パッケージ・CLI名の変更
項目 | 変更前 | 変更後 |
---|---|---|
パッケージ名 | ai |
aibot |
メインCLI | ai |
aibot |
互換性CLI | - | ai (aibotへのエイリアス) |
2. ディレクトリ構造の変更
用途 | 変更前 | 変更後 |
---|---|---|
設定ディレクトリ | ~/.config/ai/ |
~/.config/syui/ai/bot/ |
ログディレクトリ | ~/.config/ai/txt/ |
~/.config/syui/ai/bot/txt/ |
スクリプトディレクトリ | ~/.config/ai/scpt/ |
~/.config/syui/ai/bot/scpt/ |
実装した機能
1. デュアルバイナリシステム
Cargo.toml設定
[package]
name = "aibot"
description = "ai.bot - Bluesky AT Protocol Bot"
[[bin]]
name = "aibot"
path = "src/main.rs"
[[bin]]
name = "ai"
path = "src/alias.rs"
エイリアスバイナリ (src/alias.rs)
ai
コマンドがaibot
を自動的に呼び出し- 同一ディレクトリ内のaibotバイナリを優先検索
- PATH内のaibotもフォールバック対応
2. 設定ディレクトリの自動移行
data_file関数の改良
pub fn data_file(s: &str) -> String {
// 新しい設定ディレクトリ(優先)
let new_config_dir = "/.config/syui/ai/bot/";
// 旧設定ディレクトリ(互換性のため)
let old_config_dir = "/.config/ai/";
// 自動移行ロジック
// 1. 新しいパスにファイルが存在 → 新しいパスを使用
// 2. 旧パスのみに存在 → 新しいパスにコピーして使用
// 3. どちらにも存在しない → 新しいパスを使用
}
log_file関数も同様の移行対応
3. 移行セットアップスクリプト
scripts/setup-migration.sh
#!/bin/bash
# 新しい設定ディレクトリの作成
mkdir -p ~/.config/syui/ai/bot/
# スクリプトディレクトリのコピー
cp -r ~/.config/ai/scpt ~/.config/syui/ai/bot/
# エイリアス設定の提案
echo "alias ai='aibot'"
後方互換性
1. 設定ファイル
- 自動移行: 旧パスから新パスへ自動コピー
- 継続読み込み: 移行後も旧パスは参照可能
- 透過的: ユーザーは変更を意識する必要なし
2. コマンドライン
- aiコマンド: 既存スクリプトで引き続き使用可能
- aibotコマンド: 新しい正式名称
- 完全互換: 引数、オプション、出力すべて同一
3. スクリプト
- shellscript:
ai
コマンドをそのまま使用可能 - エイリアス推奨:
alias ai='aibot'
で統一
移行手順
1. 自動移行(推奨)
# プロジェクトをビルド
cargo build
# 移行スクリプトを実行
./scripts/setup-migration.sh
# 新しいバイナリを使用
./target/debug/aibot --help
./target/debug/ai --help # 互換性確認
2. 手動移行
# 1. 新しい設定ディレクトリ作成
mkdir -p ~/.config/syui/ai/bot/
# 2. スクリプトディレクトリのコピー
cp -r ~/.config/ai/scpt ~/.config/syui/ai/bot/
# 3. バイナリのインストール
cargo install --path .
# 4. エイリアス設定(オプション)
echo "alias ai='aibot'" >> ~/.zshrc
3. 段階的移行(企業環境等)
# Phase 1: 新しいバイナリの導入
cargo install --path . --bin aibot
# Phase 2: エイリアス設定
echo "alias ai='aibot'" >> ~/.profile
# Phase 3: スクリプトの段階的更新
# (既存スクリプトは変更不要)
# Phase 4: 旧設定の完全移行(任意のタイミング)
rm -rf ~/.config/ai/ # 十分な検証後
影響範囲
1. 変更が必要な箇所
- ❌ なし (完全後方互換)
2. 変更が推奨される箇所
- 📝 shellrcでのエイリアス設定
- 📝 ドキュメント内のコマンド例
- 📝 CI/CDスクリプト(新しい名前使用)
3. 変更が不要な箇所
- ✅ 既存のshellscript
- ✅ 設定ファイル
- ✅ ログファイル
- ✅ git submodule
トラブルシューティング
1. 設定ファイルが見つからない
# 現在の設定ディレクトリを確認
ls -la ~/.config/syui/ai/bot/
ls -la ~/.config/ai/ # 旧ディレクトリ
# 手動でコピー
cp ~/.config/ai/token.json ~/.config/syui/ai/bot/
2. aiコマンドが動作しない
# aibotバイナリの存在確認
which aibot
./target/debug/aibot --help
# エイリアスの設定
alias ai='aibot'
# または
export PATH="$(pwd)/target/debug:$PATH"
3. スクリプトディレクトリが見つからない
# 手動でコピー
cp -r ~/.config/ai/scpt ~/.config/syui/ai/bot/
# gitサブモジュールの場合
cd ~/.config/syui/ai/bot/scpt
git remote -v # リモートURLを確認
検証方法
1. 基本動作確認
# 新しいコマンド
aibot --help
aibot post "Test from aibot"
# 互換性確認
ai --help
ai post "Test from ai alias"
# 設定ディレクトリ確認
ls -la ~/.config/syui/ai/bot/
2. 自動移行確認
# 旧設定で動作確認
touch ~/.config/ai/test_file
aibot some_command # 新ディレクトリにコピーされることを確認
ls -la ~/.config/syui/ai/bot/test_file
3. スクリプト互換性確認
# 既存スクリプトの動作確認
cd ~/.config/syui/ai/bot/scpt
./ai.zsh # aiコマンドが正常動作することを確認
今後の予定
Phase 1 (完了)
- ✅ パッケージ名の変更
- ✅ デュアルバイナリシステム
- ✅ 設定ディレクトリの自動移行
- ✅ 後方互換性の確保
Phase 2 (将来)
- 📅 ドキュメントの更新
- 📅 CI/CDの新コマンド対応
- 📅 パフォーマンス最適化
Phase 3 (任意)
- 📅 旧設定ディレクトリの削除
- 📅 エイリアスバイナリの削除
- 📅 完全な新体系への移行
関連ファイル
Cargo.toml
- パッケージ設定src/alias.rs
- エイリアスバイナリsrc/data.rs
- 設定ディレクトリ管理scripts/setup-migration.sh
- 移行スクリプトdocs/migration-guide.md
- 本ドキュメント
注意事項
- gitサブモジュール: scptディレクトリがgitサブモジュールの場合、リモートURLの確認が必要
- 権限: 設定ディレクトリの権限は適切に設定すること
- バックアップ: 重要な設定は移行前にバックアップを推奨
- テスト: 本番環境での使用前に十分なテストを実施