Files
hakorune/src/runner/modes/common_util/provider_registry.rs

109 lines
4.0 KiB
Rust
Raw Normal View History

FileBox SSOT設計移行完了: Provider Pattern実装 ## 🎯 目的 FileBoxをSSOT(Single Source of Truth)設計に移行し、 static/dynamic/builtin providerを統一的に扱える基盤を構築。 ## ✅ 実装完了(7タスク) ### 1. Provider Lock Global **File**: `src/runtime/provider_lock.rs` - `FILEBOX_PROVIDER: OnceLock<Arc<dyn FileIo>>` 追加 - `set_filebox_provider()` / `get_filebox_provider()` 実装 ### 2. VM初期化時のProvider選択 **File**: `src/runner/modes/vm.rs` - `execute_vm_mode()` 冒頭でprovider選択・登録 - ENV(`NYASH_FILEBOX_MODE`, `NYASH_DISABLE_PLUGINS`)対応 ### 3. CoreRoFileIo完全実装 **File**: `src/boxes/file/core_ro.rs` (NEW) - Read-onlyファイルI/O実装 - Thread-safe: `RwLock<Option<File>>` - Newline正規化(CRLF→LF) ### 4. FileBox委譲化 **File**: `src/boxes/file/mod.rs` - 直接`std::fs::File`使用 → `Arc<dyn FileIo>` provider委譲 - 全メソッドをprovider経由に変更 - Fail-Fast: write/delete等の非対応操作は明確エラー ### 5. basic/file_box.rs Deprecate **File**: `src/boxes/file/basic/file_box.rs` - 120行 → 12行に削減 - `#[deprecated]` マーク + 再エクスポート - 後方互換性維持 ### 6. Feature Flag追加 **File**: `Cargo.toml` - `builtin-filebox = []` feature追加 ### 7. Provider抽象・選択ロジック **Files**: - `src/boxes/file/provider.rs` (NEW) - FileIo trait定義 - `src/boxes/file/box_shim.rs` (NEW) - 薄いラッパー - `src/runner/modes/common_util/provider_registry.rs` (NEW) - 選択ロジック ## 📊 アーキテクチャ進化 **Before**: ``` FileBox (mod.rs) ──直接使用──> std::fs::File FileBox (basic/) ──直接使用──> std::fs ``` **After**: ``` FileBox ──委譲──> Arc<dyn FileIo> ──実装──> CoreRoFileIo ├──> PluginFileIo (future) └──> BuiltinFileIo (future) ``` ## 🔧 技術的成果 1. **Thread Safety**: `RwLock<Option<File>>` で並行アクセス安全 2. **Fail-Fast**: 非対応操作は明確エラー(silent failure無し) 3. **後方互換性**: deprecated re-exportで既存コード維持 4. **環境制御**: `NYASH_FILEBOX_MODE` でランタイム切替 ## 📝 環境変数 - `NYASH_FILEBOX_MODE=auto|core-ro|plugin-only` - `auto`: プラグインあれば使用、なければCoreRoにフォールバック - `core-ro`: 強制的にCoreRo(read-only) - `plugin-only`: プラグイン必須(なければFail-Fast) - `NYASH_DISABLE_PLUGINS=1`: 強制的にcore-roモード ## 🎯 次のステップ(Future) - [ ] Dynamic統合(plugin_loaderとの連携) - [ ] BuiltinFileIo実装(feature builtin-filebox) - [ ] Write/Delete等の操作対応(provider拡張) ## 📚 ドキュメント - 詳細仕様: `docs/development/runtime/FILEBOX_PROVIDER.md` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 15:13:22 +09:00
//! Provider registry: selects concrete providers for core resources (e.g. FileBox).
Phase 21.4 Complete: FileBox SSOT + Analyzer Stabilization (7 Tasks) ✅ Task 1: Fallback Guarantee (create_box failure → ring1/core-ro auto fallback) - Three-tier fallback system: plugin → builtin → core-ro - Mode control: auto/plugin-only/core-ro - New: src/box_factory/builtin_impls/file_box.rs - New: tools/test_filebox_fallback_smoke.sh ✅ Task 2: Provider Registration SSOT (static/dynamic/core-ro unified) - ProviderFactory trait with priority-based selection - Global registry PROVIDER_FACTORIES implementation - Priority: dynamic(100) > builtin(10) > core-ro(0) - New: src/boxes/file/builtin_factory.rs - New: tools/smoke_provider_modes.sh ✅ Task 3: FileBox Publication Unification - Verified: basic/file_box.rs already minimized (11 lines) - Perfect re-export pattern maintained ✅ Task 4: ENV Unification (FILEBOX_MODE/DISABLE_PLUGINS priority) - Removed auto-setting of NYASH_USE_PLUGIN_BUILTINS - Removed auto-setting of NYASH_PLUGIN_OVERRIDE_TYPES - Added deprecation warnings with migration guide - ENV hierarchy: DISABLE_PLUGINS > BOX_FACTORY_POLICY > FILEBOX_MODE ✅ Task 5: Error Log Visibility (Analyzer rule execution errors to stderr) - Added [rule/exec] logging before IR-based rule execution - Format: [rule/exec] HC012 (dead_static_box) <filepath> - VM errors now traceable via stderr output ✅ Task 6: Unnecessary Using Removal (14 rules Str alias cleanup) - Removed unused `using ... as Str` from 14 rule files - All rules use local _itoa() helper instead - 14 lines of dead code eliminated ✅ Task 7: HC017 Skip & TODO Documentation (UTF-8 support required) - Enhanced run_tests.sh with clear skip message - Added "Known Limitations" section to README.md - Technical requirements documented (3 implementation options) - Re-enable timeline: Phase 22 (Unicode Support Phase) 📊 Test Results: - Analyzer: 10 tests PASS, 1 skipped (HC017) - FileBox fallback: All 3 modes PASS - Provider modes: All 4 modes PASS - Build: Success (0 errors, 0 warnings) 🎯 Key Achievements: - 28 files modified/created - Three-Tier Fallback System (stability) - SSOT Provider Registry (extensibility) - ENV unification (operational clarity) - Error visibility (debugging efficiency) - Code cleanup (maintainability) - Comprehensive documentation (Phase 22 ready) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 17:04:21 +09:00
//! SSOT (Single Source of Truth) for provider selection via ProviderFactory registration.
FileBox SSOT設計移行完了: Provider Pattern実装 ## 🎯 目的 FileBoxをSSOT(Single Source of Truth)設計に移行し、 static/dynamic/builtin providerを統一的に扱える基盤を構築。 ## ✅ 実装完了(7タスク) ### 1. Provider Lock Global **File**: `src/runtime/provider_lock.rs` - `FILEBOX_PROVIDER: OnceLock<Arc<dyn FileIo>>` 追加 - `set_filebox_provider()` / `get_filebox_provider()` 実装 ### 2. VM初期化時のProvider選択 **File**: `src/runner/modes/vm.rs` - `execute_vm_mode()` 冒頭でprovider選択・登録 - ENV(`NYASH_FILEBOX_MODE`, `NYASH_DISABLE_PLUGINS`)対応 ### 3. CoreRoFileIo完全実装 **File**: `src/boxes/file/core_ro.rs` (NEW) - Read-onlyファイルI/O実装 - Thread-safe: `RwLock<Option<File>>` - Newline正規化(CRLF→LF) ### 4. FileBox委譲化 **File**: `src/boxes/file/mod.rs` - 直接`std::fs::File`使用 → `Arc<dyn FileIo>` provider委譲 - 全メソッドをprovider経由に変更 - Fail-Fast: write/delete等の非対応操作は明確エラー ### 5. basic/file_box.rs Deprecate **File**: `src/boxes/file/basic/file_box.rs` - 120行 → 12行に削減 - `#[deprecated]` マーク + 再エクスポート - 後方互換性維持 ### 6. Feature Flag追加 **File**: `Cargo.toml` - `builtin-filebox = []` feature追加 ### 7. Provider抽象・選択ロジック **Files**: - `src/boxes/file/provider.rs` (NEW) - FileIo trait定義 - `src/boxes/file/box_shim.rs` (NEW) - 薄いラッパー - `src/runner/modes/common_util/provider_registry.rs` (NEW) - 選択ロジック ## 📊 アーキテクチャ進化 **Before**: ``` FileBox (mod.rs) ──直接使用──> std::fs::File FileBox (basic/) ──直接使用──> std::fs ``` **After**: ``` FileBox ──委譲──> Arc<dyn FileIo> ──実装──> CoreRoFileIo ├──> PluginFileIo (future) └──> BuiltinFileIo (future) ``` ## 🔧 技術的成果 1. **Thread Safety**: `RwLock<Option<File>>` で並行アクセス安全 2. **Fail-Fast**: 非対応操作は明確エラー(silent failure無し) 3. **後方互換性**: deprecated re-exportで既存コード維持 4. **環境制御**: `NYASH_FILEBOX_MODE` でランタイム切替 ## 📝 環境変数 - `NYASH_FILEBOX_MODE=auto|core-ro|plugin-only` - `auto`: プラグインあれば使用、なければCoreRoにフォールバック - `core-ro`: 強制的にCoreRo(read-only) - `plugin-only`: プラグイン必須(なければFail-Fast) - `NYASH_DISABLE_PLUGINS=1`: 強制的にcore-roモード ## 🎯 次のステップ(Future) - [ ] Dynamic統合(plugin_loaderとの連携) - [ ] BuiltinFileIo実装(feature builtin-filebox) - [ ] Write/Delete等の操作対応(provider拡張) ## 📚 ドキュメント - 詳細仕様: `docs/development/runtime/FILEBOX_PROVIDER.md` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 15:13:22 +09:00
Phase 21.4 Complete: FileBox SSOT + Analyzer Stabilization (7 Tasks) ✅ Task 1: Fallback Guarantee (create_box failure → ring1/core-ro auto fallback) - Three-tier fallback system: plugin → builtin → core-ro - Mode control: auto/plugin-only/core-ro - New: src/box_factory/builtin_impls/file_box.rs - New: tools/test_filebox_fallback_smoke.sh ✅ Task 2: Provider Registration SSOT (static/dynamic/core-ro unified) - ProviderFactory trait with priority-based selection - Global registry PROVIDER_FACTORIES implementation - Priority: dynamic(100) > builtin(10) > core-ro(0) - New: src/boxes/file/builtin_factory.rs - New: tools/smoke_provider_modes.sh ✅ Task 3: FileBox Publication Unification - Verified: basic/file_box.rs already minimized (11 lines) - Perfect re-export pattern maintained ✅ Task 4: ENV Unification (FILEBOX_MODE/DISABLE_PLUGINS priority) - Removed auto-setting of NYASH_USE_PLUGIN_BUILTINS - Removed auto-setting of NYASH_PLUGIN_OVERRIDE_TYPES - Added deprecation warnings with migration guide - ENV hierarchy: DISABLE_PLUGINS > BOX_FACTORY_POLICY > FILEBOX_MODE ✅ Task 5: Error Log Visibility (Analyzer rule execution errors to stderr) - Added [rule/exec] logging before IR-based rule execution - Format: [rule/exec] HC012 (dead_static_box) <filepath> - VM errors now traceable via stderr output ✅ Task 6: Unnecessary Using Removal (14 rules Str alias cleanup) - Removed unused `using ... as Str` from 14 rule files - All rules use local _itoa() helper instead - 14 lines of dead code eliminated ✅ Task 7: HC017 Skip & TODO Documentation (UTF-8 support required) - Enhanced run_tests.sh with clear skip message - Added "Known Limitations" section to README.md - Technical requirements documented (3 implementation options) - Re-enable timeline: Phase 22 (Unicode Support Phase) 📊 Test Results: - Analyzer: 10 tests PASS, 1 skipped (HC017) - FileBox fallback: All 3 modes PASS - Provider modes: All 4 modes PASS - Build: Success (0 errors, 0 warnings) 🎯 Key Achievements: - 28 files modified/created - Three-Tier Fallback System (stability) - SSOT Provider Registry (extensibility) - ENV unification (operational clarity) - Error visibility (debugging efficiency) - Code cleanup (maintainability) - Comprehensive documentation (Phase 22 ready) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 17:04:21 +09:00
use std::sync::{Arc, Mutex, OnceLock};
FileBox SSOT設計移行完了: Provider Pattern実装 ## 🎯 目的 FileBoxをSSOT(Single Source of Truth)設計に移行し、 static/dynamic/builtin providerを統一的に扱える基盤を構築。 ## ✅ 実装完了(7タスク) ### 1. Provider Lock Global **File**: `src/runtime/provider_lock.rs` - `FILEBOX_PROVIDER: OnceLock<Arc<dyn FileIo>>` 追加 - `set_filebox_provider()` / `get_filebox_provider()` 実装 ### 2. VM初期化時のProvider選択 **File**: `src/runner/modes/vm.rs` - `execute_vm_mode()` 冒頭でprovider選択・登録 - ENV(`NYASH_FILEBOX_MODE`, `NYASH_DISABLE_PLUGINS`)対応 ### 3. CoreRoFileIo完全実装 **File**: `src/boxes/file/core_ro.rs` (NEW) - Read-onlyファイルI/O実装 - Thread-safe: `RwLock<Option<File>>` - Newline正規化(CRLF→LF) ### 4. FileBox委譲化 **File**: `src/boxes/file/mod.rs` - 直接`std::fs::File`使用 → `Arc<dyn FileIo>` provider委譲 - 全メソッドをprovider経由に変更 - Fail-Fast: write/delete等の非対応操作は明確エラー ### 5. basic/file_box.rs Deprecate **File**: `src/boxes/file/basic/file_box.rs` - 120行 → 12行に削減 - `#[deprecated]` マーク + 再エクスポート - 後方互換性維持 ### 6. Feature Flag追加 **File**: `Cargo.toml` - `builtin-filebox = []` feature追加 ### 7. Provider抽象・選択ロジック **Files**: - `src/boxes/file/provider.rs` (NEW) - FileIo trait定義 - `src/boxes/file/box_shim.rs` (NEW) - 薄いラッパー - `src/runner/modes/common_util/provider_registry.rs` (NEW) - 選択ロジック ## 📊 アーキテクチャ進化 **Before**: ``` FileBox (mod.rs) ──直接使用──> std::fs::File FileBox (basic/) ──直接使用──> std::fs ``` **After**: ``` FileBox ──委譲──> Arc<dyn FileIo> ──実装──> CoreRoFileIo ├──> PluginFileIo (future) └──> BuiltinFileIo (future) ``` ## 🔧 技術的成果 1. **Thread Safety**: `RwLock<Option<File>>` で並行アクセス安全 2. **Fail-Fast**: 非対応操作は明確エラー(silent failure無し) 3. **後方互換性**: deprecated re-exportで既存コード維持 4. **環境制御**: `NYASH_FILEBOX_MODE` でランタイム切替 ## 📝 環境変数 - `NYASH_FILEBOX_MODE=auto|core-ro|plugin-only` - `auto`: プラグインあれば使用、なければCoreRoにフォールバック - `core-ro`: 強制的にCoreRo(read-only) - `plugin-only`: プラグイン必須(なければFail-Fast) - `NYASH_DISABLE_PLUGINS=1`: 強制的にcore-roモード ## 🎯 次のステップ(Future) - [ ] Dynamic統合(plugin_loaderとの連携) - [ ] BuiltinFileIo実装(feature builtin-filebox) - [ ] Write/Delete等の操作対応(provider拡張) ## 📚 ドキュメント - 詳細仕様: `docs/development/runtime/FILEBOX_PROVIDER.md` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 15:13:22 +09:00
use crate::boxes::file::provider::FileIo;
use crate::boxes::file::core_ro::CoreRoFileIo;
#[allow(dead_code)]
pub enum FileBoxMode { Auto, CoreRo, PluginOnly }
Phase 21.4 Complete: FileBox SSOT + Analyzer Stabilization (7 Tasks) ✅ Task 1: Fallback Guarantee (create_box failure → ring1/core-ro auto fallback) - Three-tier fallback system: plugin → builtin → core-ro - Mode control: auto/plugin-only/core-ro - New: src/box_factory/builtin_impls/file_box.rs - New: tools/test_filebox_fallback_smoke.sh ✅ Task 2: Provider Registration SSOT (static/dynamic/core-ro unified) - ProviderFactory trait with priority-based selection - Global registry PROVIDER_FACTORIES implementation - Priority: dynamic(100) > builtin(10) > core-ro(0) - New: src/boxes/file/builtin_factory.rs - New: tools/smoke_provider_modes.sh ✅ Task 3: FileBox Publication Unification - Verified: basic/file_box.rs already minimized (11 lines) - Perfect re-export pattern maintained ✅ Task 4: ENV Unification (FILEBOX_MODE/DISABLE_PLUGINS priority) - Removed auto-setting of NYASH_USE_PLUGIN_BUILTINS - Removed auto-setting of NYASH_PLUGIN_OVERRIDE_TYPES - Added deprecation warnings with migration guide - ENV hierarchy: DISABLE_PLUGINS > BOX_FACTORY_POLICY > FILEBOX_MODE ✅ Task 5: Error Log Visibility (Analyzer rule execution errors to stderr) - Added [rule/exec] logging before IR-based rule execution - Format: [rule/exec] HC012 (dead_static_box) <filepath> - VM errors now traceable via stderr output ✅ Task 6: Unnecessary Using Removal (14 rules Str alias cleanup) - Removed unused `using ... as Str` from 14 rule files - All rules use local _itoa() helper instead - 14 lines of dead code eliminated ✅ Task 7: HC017 Skip & TODO Documentation (UTF-8 support required) - Enhanced run_tests.sh with clear skip message - Added "Known Limitations" section to README.md - Technical requirements documented (3 implementation options) - Re-enable timeline: Phase 22 (Unicode Support Phase) 📊 Test Results: - Analyzer: 10 tests PASS, 1 skipped (HC017) - FileBox fallback: All 3 modes PASS - Provider modes: All 4 modes PASS - Build: Success (0 errors, 0 warnings) 🎯 Key Achievements: - 28 files modified/created - Three-Tier Fallback System (stability) - SSOT Provider Registry (extensibility) - ENV unification (operational clarity) - Error visibility (debugging efficiency) - Code cleanup (maintainability) - Comprehensive documentation (Phase 22 ready) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 17:04:21 +09:00
/// Factory for creating FileIo providers
pub trait ProviderFactory: Send + Sync {
fn box_name(&self) -> &str;
fn create_provider(&self) -> Arc<dyn FileIo>;
fn is_available(&self) -> bool;
fn priority(&self) -> i32 {
0 // Default priority (higher = preferred)
}
}
/// Global registry of provider factories
static PROVIDER_FACTORIES: OnceLock<Mutex<Vec<Arc<dyn ProviderFactory>>>> = OnceLock::new();
/// Register a provider factory (called by builtin/dynamic loaders)
pub fn register_provider_factory(factory: Arc<dyn ProviderFactory>) {
let registry = PROVIDER_FACTORIES.get_or_init(|| Mutex::new(Vec::new()));
registry.lock().unwrap().push(factory);
}
/// Read FileBox mode from environment variables
FileBox SSOT設計移行完了: Provider Pattern実装 ## 🎯 目的 FileBoxをSSOT(Single Source of Truth)設計に移行し、 static/dynamic/builtin providerを統一的に扱える基盤を構築。 ## ✅ 実装完了(7タスク) ### 1. Provider Lock Global **File**: `src/runtime/provider_lock.rs` - `FILEBOX_PROVIDER: OnceLock<Arc<dyn FileIo>>` 追加 - `set_filebox_provider()` / `get_filebox_provider()` 実装 ### 2. VM初期化時のProvider選択 **File**: `src/runner/modes/vm.rs` - `execute_vm_mode()` 冒頭でprovider選択・登録 - ENV(`NYASH_FILEBOX_MODE`, `NYASH_DISABLE_PLUGINS`)対応 ### 3. CoreRoFileIo完全実装 **File**: `src/boxes/file/core_ro.rs` (NEW) - Read-onlyファイルI/O実装 - Thread-safe: `RwLock<Option<File>>` - Newline正規化(CRLF→LF) ### 4. FileBox委譲化 **File**: `src/boxes/file/mod.rs` - 直接`std::fs::File`使用 → `Arc<dyn FileIo>` provider委譲 - 全メソッドをprovider経由に変更 - Fail-Fast: write/delete等の非対応操作は明確エラー ### 5. basic/file_box.rs Deprecate **File**: `src/boxes/file/basic/file_box.rs` - 120行 → 12行に削減 - `#[deprecated]` マーク + 再エクスポート - 後方互換性維持 ### 6. Feature Flag追加 **File**: `Cargo.toml` - `builtin-filebox = []` feature追加 ### 7. Provider抽象・選択ロジック **Files**: - `src/boxes/file/provider.rs` (NEW) - FileIo trait定義 - `src/boxes/file/box_shim.rs` (NEW) - 薄いラッパー - `src/runner/modes/common_util/provider_registry.rs` (NEW) - 選択ロジック ## 📊 アーキテクチャ進化 **Before**: ``` FileBox (mod.rs) ──直接使用──> std::fs::File FileBox (basic/) ──直接使用──> std::fs ``` **After**: ``` FileBox ──委譲──> Arc<dyn FileIo> ──実装──> CoreRoFileIo ├──> PluginFileIo (future) └──> BuiltinFileIo (future) ``` ## 🔧 技術的成果 1. **Thread Safety**: `RwLock<Option<File>>` で並行アクセス安全 2. **Fail-Fast**: 非対応操作は明確エラー(silent failure無し) 3. **後方互換性**: deprecated re-exportで既存コード維持 4. **環境制御**: `NYASH_FILEBOX_MODE` でランタイム切替 ## 📝 環境変数 - `NYASH_FILEBOX_MODE=auto|core-ro|plugin-only` - `auto`: プラグインあれば使用、なければCoreRoにフォールバック - `core-ro`: 強制的にCoreRo(read-only) - `plugin-only`: プラグイン必須(なければFail-Fast) - `NYASH_DISABLE_PLUGINS=1`: 強制的にcore-roモード ## 🎯 次のステップ(Future) - [ ] Dynamic統合(plugin_loaderとの連携) - [ ] BuiltinFileIo実装(feature builtin-filebox) - [ ] Write/Delete等の操作対応(provider拡張) ## 📚 ドキュメント - 詳細仕様: `docs/development/runtime/FILEBOX_PROVIDER.md` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 15:13:22 +09:00
#[allow(dead_code)]
pub fn read_filebox_mode_from_env() -> FileBoxMode {
match std::env::var("NYASH_FILEBOX_MODE").unwrap_or_else(|_| "auto".to_string()).as_str() {
"core-ro" => FileBoxMode::CoreRo,
"plugin-only" => FileBoxMode::PluginOnly,
_ => {
if std::env::var("NYASH_DISABLE_PLUGINS").as_deref() == Ok("1") {
FileBoxMode::CoreRo
} else { FileBoxMode::Auto }
}
}
}
Phase 21.4 Complete: FileBox SSOT + Analyzer Stabilization (7 Tasks) ✅ Task 1: Fallback Guarantee (create_box failure → ring1/core-ro auto fallback) - Three-tier fallback system: plugin → builtin → core-ro - Mode control: auto/plugin-only/core-ro - New: src/box_factory/builtin_impls/file_box.rs - New: tools/test_filebox_fallback_smoke.sh ✅ Task 2: Provider Registration SSOT (static/dynamic/core-ro unified) - ProviderFactory trait with priority-based selection - Global registry PROVIDER_FACTORIES implementation - Priority: dynamic(100) > builtin(10) > core-ro(0) - New: src/boxes/file/builtin_factory.rs - New: tools/smoke_provider_modes.sh ✅ Task 3: FileBox Publication Unification - Verified: basic/file_box.rs already minimized (11 lines) - Perfect re-export pattern maintained ✅ Task 4: ENV Unification (FILEBOX_MODE/DISABLE_PLUGINS priority) - Removed auto-setting of NYASH_USE_PLUGIN_BUILTINS - Removed auto-setting of NYASH_PLUGIN_OVERRIDE_TYPES - Added deprecation warnings with migration guide - ENV hierarchy: DISABLE_PLUGINS > BOX_FACTORY_POLICY > FILEBOX_MODE ✅ Task 5: Error Log Visibility (Analyzer rule execution errors to stderr) - Added [rule/exec] logging before IR-based rule execution - Format: [rule/exec] HC012 (dead_static_box) <filepath> - VM errors now traceable via stderr output ✅ Task 6: Unnecessary Using Removal (14 rules Str alias cleanup) - Removed unused `using ... as Str` from 14 rule files - All rules use local _itoa() helper instead - 14 lines of dead code eliminated ✅ Task 7: HC017 Skip & TODO Documentation (UTF-8 support required) - Enhanced run_tests.sh with clear skip message - Added "Known Limitations" section to README.md - Technical requirements documented (3 implementation options) - Re-enable timeline: Phase 22 (Unicode Support Phase) 📊 Test Results: - Analyzer: 10 tests PASS, 1 skipped (HC017) - FileBox fallback: All 3 modes PASS - Provider modes: All 4 modes PASS - Build: Success (0 errors, 0 warnings) 🎯 Key Achievements: - 28 files modified/created - Three-Tier Fallback System (stability) - SSOT Provider Registry (extensibility) - ENV unification (operational clarity) - Error visibility (debugging efficiency) - Code cleanup (maintainability) - Comprehensive documentation (Phase 22 ready) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 17:04:21 +09:00
/// Select provider based on mode and registered factories (SSOT)
FileBox SSOT設計移行完了: Provider Pattern実装 ## 🎯 目的 FileBoxをSSOT(Single Source of Truth)設計に移行し、 static/dynamic/builtin providerを統一的に扱える基盤を構築。 ## ✅ 実装完了(7タスク) ### 1. Provider Lock Global **File**: `src/runtime/provider_lock.rs` - `FILEBOX_PROVIDER: OnceLock<Arc<dyn FileIo>>` 追加 - `set_filebox_provider()` / `get_filebox_provider()` 実装 ### 2. VM初期化時のProvider選択 **File**: `src/runner/modes/vm.rs` - `execute_vm_mode()` 冒頭でprovider選択・登録 - ENV(`NYASH_FILEBOX_MODE`, `NYASH_DISABLE_PLUGINS`)対応 ### 3. CoreRoFileIo完全実装 **File**: `src/boxes/file/core_ro.rs` (NEW) - Read-onlyファイルI/O実装 - Thread-safe: `RwLock<Option<File>>` - Newline正規化(CRLF→LF) ### 4. FileBox委譲化 **File**: `src/boxes/file/mod.rs` - 直接`std::fs::File`使用 → `Arc<dyn FileIo>` provider委譲 - 全メソッドをprovider経由に変更 - Fail-Fast: write/delete等の非対応操作は明確エラー ### 5. basic/file_box.rs Deprecate **File**: `src/boxes/file/basic/file_box.rs` - 120行 → 12行に削減 - `#[deprecated]` マーク + 再エクスポート - 後方互換性維持 ### 6. Feature Flag追加 **File**: `Cargo.toml` - `builtin-filebox = []` feature追加 ### 7. Provider抽象・選択ロジック **Files**: - `src/boxes/file/provider.rs` (NEW) - FileIo trait定義 - `src/boxes/file/box_shim.rs` (NEW) - 薄いラッパー - `src/runner/modes/common_util/provider_registry.rs` (NEW) - 選択ロジック ## 📊 アーキテクチャ進化 **Before**: ``` FileBox (mod.rs) ──直接使用──> std::fs::File FileBox (basic/) ──直接使用──> std::fs ``` **After**: ``` FileBox ──委譲──> Arc<dyn FileIo> ──実装──> CoreRoFileIo ├──> PluginFileIo (future) └──> BuiltinFileIo (future) ``` ## 🔧 技術的成果 1. **Thread Safety**: `RwLock<Option<File>>` で並行アクセス安全 2. **Fail-Fast**: 非対応操作は明確エラー(silent failure無し) 3. **後方互換性**: deprecated re-exportで既存コード維持 4. **環境制御**: `NYASH_FILEBOX_MODE` でランタイム切替 ## 📝 環境変数 - `NYASH_FILEBOX_MODE=auto|core-ro|plugin-only` - `auto`: プラグインあれば使用、なければCoreRoにフォールバック - `core-ro`: 強制的にCoreRo(read-only) - `plugin-only`: プラグイン必須(なければFail-Fast) - `NYASH_DISABLE_PLUGINS=1`: 強制的にcore-roモード ## 🎯 次のステップ(Future) - [ ] Dynamic統合(plugin_loaderとの連携) - [ ] BuiltinFileIo実装(feature builtin-filebox) - [ ] Write/Delete等の操作対応(provider拡張) ## 📚 ドキュメント - 詳細仕様: `docs/development/runtime/FILEBOX_PROVIDER.md` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 15:13:22 +09:00
#[allow(dead_code)]
pub fn select_file_provider(mode: FileBoxMode) -> Arc<dyn FileIo> {
Phase 21.4 Complete: FileBox SSOT + Analyzer Stabilization (7 Tasks) ✅ Task 1: Fallback Guarantee (create_box failure → ring1/core-ro auto fallback) - Three-tier fallback system: plugin → builtin → core-ro - Mode control: auto/plugin-only/core-ro - New: src/box_factory/builtin_impls/file_box.rs - New: tools/test_filebox_fallback_smoke.sh ✅ Task 2: Provider Registration SSOT (static/dynamic/core-ro unified) - ProviderFactory trait with priority-based selection - Global registry PROVIDER_FACTORIES implementation - Priority: dynamic(100) > builtin(10) > core-ro(0) - New: src/boxes/file/builtin_factory.rs - New: tools/smoke_provider_modes.sh ✅ Task 3: FileBox Publication Unification - Verified: basic/file_box.rs already minimized (11 lines) - Perfect re-export pattern maintained ✅ Task 4: ENV Unification (FILEBOX_MODE/DISABLE_PLUGINS priority) - Removed auto-setting of NYASH_USE_PLUGIN_BUILTINS - Removed auto-setting of NYASH_PLUGIN_OVERRIDE_TYPES - Added deprecation warnings with migration guide - ENV hierarchy: DISABLE_PLUGINS > BOX_FACTORY_POLICY > FILEBOX_MODE ✅ Task 5: Error Log Visibility (Analyzer rule execution errors to stderr) - Added [rule/exec] logging before IR-based rule execution - Format: [rule/exec] HC012 (dead_static_box) <filepath> - VM errors now traceable via stderr output ✅ Task 6: Unnecessary Using Removal (14 rules Str alias cleanup) - Removed unused `using ... as Str` from 14 rule files - All rules use local _itoa() helper instead - 14 lines of dead code eliminated ✅ Task 7: HC017 Skip & TODO Documentation (UTF-8 support required) - Enhanced run_tests.sh with clear skip message - Added "Known Limitations" section to README.md - Technical requirements documented (3 implementation options) - Re-enable timeline: Phase 22 (Unicode Support Phase) 📊 Test Results: - Analyzer: 10 tests PASS, 1 skipped (HC017) - FileBox fallback: All 3 modes PASS - Provider modes: All 4 modes PASS - Build: Success (0 errors, 0 warnings) 🎯 Key Achievements: - 28 files modified/created - Three-Tier Fallback System (stability) - SSOT Provider Registry (extensibility) - ENV unification (operational clarity) - Error visibility (debugging efficiency) - Code cleanup (maintainability) - Comprehensive documentation (Phase 22 ready) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 17:04:21 +09:00
let registry = PROVIDER_FACTORIES.get();
let quiet_pipe = crate::config::env::env_bool("NYASH_JSON_ONLY");
FileBox SSOT設計移行完了: Provider Pattern実装 ## 🎯 目的 FileBoxをSSOT(Single Source of Truth)設計に移行し、 static/dynamic/builtin providerを統一的に扱える基盤を構築。 ## ✅ 実装完了(7タスク) ### 1. Provider Lock Global **File**: `src/runtime/provider_lock.rs` - `FILEBOX_PROVIDER: OnceLock<Arc<dyn FileIo>>` 追加 - `set_filebox_provider()` / `get_filebox_provider()` 実装 ### 2. VM初期化時のProvider選択 **File**: `src/runner/modes/vm.rs` - `execute_vm_mode()` 冒頭でprovider選択・登録 - ENV(`NYASH_FILEBOX_MODE`, `NYASH_DISABLE_PLUGINS`)対応 ### 3. CoreRoFileIo完全実装 **File**: `src/boxes/file/core_ro.rs` (NEW) - Read-onlyファイルI/O実装 - Thread-safe: `RwLock<Option<File>>` - Newline正規化(CRLF→LF) ### 4. FileBox委譲化 **File**: `src/boxes/file/mod.rs` - 直接`std::fs::File`使用 → `Arc<dyn FileIo>` provider委譲 - 全メソッドをprovider経由に変更 - Fail-Fast: write/delete等の非対応操作は明確エラー ### 5. basic/file_box.rs Deprecate **File**: `src/boxes/file/basic/file_box.rs` - 120行 → 12行に削減 - `#[deprecated]` マーク + 再エクスポート - 後方互換性維持 ### 6. Feature Flag追加 **File**: `Cargo.toml` - `builtin-filebox = []` feature追加 ### 7. Provider抽象・選択ロジック **Files**: - `src/boxes/file/provider.rs` (NEW) - FileIo trait定義 - `src/boxes/file/box_shim.rs` (NEW) - 薄いラッパー - `src/runner/modes/common_util/provider_registry.rs` (NEW) - 選択ロジック ## 📊 アーキテクチャ進化 **Before**: ``` FileBox (mod.rs) ──直接使用──> std::fs::File FileBox (basic/) ──直接使用──> std::fs ``` **After**: ``` FileBox ──委譲──> Arc<dyn FileIo> ──実装──> CoreRoFileIo ├──> PluginFileIo (future) └──> BuiltinFileIo (future) ``` ## 🔧 技術的成果 1. **Thread Safety**: `RwLock<Option<File>>` で並行アクセス安全 2. **Fail-Fast**: 非対応操作は明確エラー(silent failure無し) 3. **後方互換性**: deprecated re-exportで既存コード維持 4. **環境制御**: `NYASH_FILEBOX_MODE` でランタイム切替 ## 📝 環境変数 - `NYASH_FILEBOX_MODE=auto|core-ro|plugin-only` - `auto`: プラグインあれば使用、なければCoreRoにフォールバック - `core-ro`: 強制的にCoreRo(read-only) - `plugin-only`: プラグイン必須(なければFail-Fast) - `NYASH_DISABLE_PLUGINS=1`: 強制的にcore-roモード ## 🎯 次のステップ(Future) - [ ] Dynamic統合(plugin_loaderとの連携) - [ ] BuiltinFileIo実装(feature builtin-filebox) - [ ] Write/Delete等の操作対応(provider拡張) ## 📚 ドキュメント - 詳細仕様: `docs/development/runtime/FILEBOX_PROVIDER.md` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 15:13:22 +09:00
match mode {
Phase 21.4 Complete: FileBox SSOT + Analyzer Stabilization (7 Tasks) ✅ Task 1: Fallback Guarantee (create_box failure → ring1/core-ro auto fallback) - Three-tier fallback system: plugin → builtin → core-ro - Mode control: auto/plugin-only/core-ro - New: src/box_factory/builtin_impls/file_box.rs - New: tools/test_filebox_fallback_smoke.sh ✅ Task 2: Provider Registration SSOT (static/dynamic/core-ro unified) - ProviderFactory trait with priority-based selection - Global registry PROVIDER_FACTORIES implementation - Priority: dynamic(100) > builtin(10) > core-ro(0) - New: src/boxes/file/builtin_factory.rs - New: tools/smoke_provider_modes.sh ✅ Task 3: FileBox Publication Unification - Verified: basic/file_box.rs already minimized (11 lines) - Perfect re-export pattern maintained ✅ Task 4: ENV Unification (FILEBOX_MODE/DISABLE_PLUGINS priority) - Removed auto-setting of NYASH_USE_PLUGIN_BUILTINS - Removed auto-setting of NYASH_PLUGIN_OVERRIDE_TYPES - Added deprecation warnings with migration guide - ENV hierarchy: DISABLE_PLUGINS > BOX_FACTORY_POLICY > FILEBOX_MODE ✅ Task 5: Error Log Visibility (Analyzer rule execution errors to stderr) - Added [rule/exec] logging before IR-based rule execution - Format: [rule/exec] HC012 (dead_static_box) <filepath> - VM errors now traceable via stderr output ✅ Task 6: Unnecessary Using Removal (14 rules Str alias cleanup) - Removed unused `using ... as Str` from 14 rule files - All rules use local _itoa() helper instead - 14 lines of dead code eliminated ✅ Task 7: HC017 Skip & TODO Documentation (UTF-8 support required) - Enhanced run_tests.sh with clear skip message - Added "Known Limitations" section to README.md - Technical requirements documented (3 implementation options) - Re-enable timeline: Phase 22 (Unicode Support Phase) 📊 Test Results: - Analyzer: 10 tests PASS, 1 skipped (HC017) - FileBox fallback: All 3 modes PASS - Provider modes: All 4 modes PASS - Build: Success (0 errors, 0 warnings) 🎯 Key Achievements: - 28 files modified/created - Three-Tier Fallback System (stability) - SSOT Provider Registry (extensibility) - ENV unification (operational clarity) - Error visibility (debugging efficiency) - Code cleanup (maintainability) - Comprehensive documentation (Phase 22 ready) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 17:04:21 +09:00
FileBoxMode::Auto => {
// Try: dynamic/builtin (by priority) → core-ro fallback
if let Some(reg) = registry {
let mut factories: Vec<_> = reg.lock().unwrap()
.iter()
.filter(|f| f.box_name() == "FileBox" && f.is_available())
.cloned()
.collect();
// Sort by priority (descending)
factories.sort_by(|a, b| b.priority().cmp(&a.priority()));
if let Some(factory) = factories.first() {
if !quiet_pipe {
eprintln!("[provider-registry] FileBox: using registered provider (priority={})", factory.priority());
}
return factory.create_provider();
}
}
// Fallback to core-ro
if !quiet_pipe {
eprintln!("[provider-registry] FileBox: using core-ro fallback");
}
Arc::new(CoreRoFileIo::new())
}
FileBoxMode::PluginOnly => {
// Try only registered providers, Fail-Fast if none available
if let Some(reg) = registry {
let mut factories: Vec<_> = reg.lock().unwrap()
.iter()
.filter(|f| f.box_name() == "FileBox" && f.is_available())
.cloned()
.collect();
factories.sort_by(|a, b| b.priority().cmp(&a.priority()));
if let Some(factory) = factories.first() {
if !quiet_pipe {
eprintln!("[provider-registry] FileBox: using plugin-only provider (priority={})", factory.priority());
}
return factory.create_provider();
}
}
panic!("FileBox plugin-only mode: no provider registered. Set NYASH_FILEBOX_MODE=auto or NYASH_FILEBOX_MODE=core-ro to use fallback.");
}
FileBoxMode::CoreRo => {
// Always use core-ro, ignore registry
if !quiet_pipe {
eprintln!("[provider-registry] FileBox: using core-ro (forced)");
}
FileBox SSOT設計移行完了: Provider Pattern実装 ## 🎯 目的 FileBoxをSSOT(Single Source of Truth)設計に移行し、 static/dynamic/builtin providerを統一的に扱える基盤を構築。 ## ✅ 実装完了(7タスク) ### 1. Provider Lock Global **File**: `src/runtime/provider_lock.rs` - `FILEBOX_PROVIDER: OnceLock<Arc<dyn FileIo>>` 追加 - `set_filebox_provider()` / `get_filebox_provider()` 実装 ### 2. VM初期化時のProvider選択 **File**: `src/runner/modes/vm.rs` - `execute_vm_mode()` 冒頭でprovider選択・登録 - ENV(`NYASH_FILEBOX_MODE`, `NYASH_DISABLE_PLUGINS`)対応 ### 3. CoreRoFileIo完全実装 **File**: `src/boxes/file/core_ro.rs` (NEW) - Read-onlyファイルI/O実装 - Thread-safe: `RwLock<Option<File>>` - Newline正規化(CRLF→LF) ### 4. FileBox委譲化 **File**: `src/boxes/file/mod.rs` - 直接`std::fs::File`使用 → `Arc<dyn FileIo>` provider委譲 - 全メソッドをprovider経由に変更 - Fail-Fast: write/delete等の非対応操作は明確エラー ### 5. basic/file_box.rs Deprecate **File**: `src/boxes/file/basic/file_box.rs` - 120行 → 12行に削減 - `#[deprecated]` マーク + 再エクスポート - 後方互換性維持 ### 6. Feature Flag追加 **File**: `Cargo.toml` - `builtin-filebox = []` feature追加 ### 7. Provider抽象・選択ロジック **Files**: - `src/boxes/file/provider.rs` (NEW) - FileIo trait定義 - `src/boxes/file/box_shim.rs` (NEW) - 薄いラッパー - `src/runner/modes/common_util/provider_registry.rs` (NEW) - 選択ロジック ## 📊 アーキテクチャ進化 **Before**: ``` FileBox (mod.rs) ──直接使用──> std::fs::File FileBox (basic/) ──直接使用──> std::fs ``` **After**: ``` FileBox ──委譲──> Arc<dyn FileIo> ──実装──> CoreRoFileIo ├──> PluginFileIo (future) └──> BuiltinFileIo (future) ``` ## 🔧 技術的成果 1. **Thread Safety**: `RwLock<Option<File>>` で並行アクセス安全 2. **Fail-Fast**: 非対応操作は明確エラー(silent failure無し) 3. **後方互換性**: deprecated re-exportで既存コード維持 4. **環境制御**: `NYASH_FILEBOX_MODE` でランタイム切替 ## 📝 環境変数 - `NYASH_FILEBOX_MODE=auto|core-ro|plugin-only` - `auto`: プラグインあれば使用、なければCoreRoにフォールバック - `core-ro`: 強制的にCoreRo(read-only) - `plugin-only`: プラグイン必須(なければFail-Fast) - `NYASH_DISABLE_PLUGINS=1`: 強制的にcore-roモード ## 🎯 次のステップ(Future) - [ ] Dynamic統合(plugin_loaderとの連携) - [ ] BuiltinFileIo実装(feature builtin-filebox) - [ ] Write/Delete等の操作対応(provider拡張) ## 📚 ドキュメント - 詳細仕様: `docs/development/runtime/FILEBOX_PROVIDER.md` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-08 15:13:22 +09:00
Arc::new(CoreRoFileIo::new())
}
}
}