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

147 lines
6.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);
}
feat(phase21.5/22.1): MirBuilder JsonFrag refactor + FileBox ring-1 + registry tests Phase 21.5 (AOT/LLVM Optimization Prep) - FileBox ring-1 (core-ro) provider: priority=-100, always available, no panic path - src/runner/modes/common_util/provider_registry.rs: CoreRoFileProviderFactory - Auto-registers at startup, eliminates fallback panic structurally - StringBox fast path prototypes (length/size optimization) - Performance benchmarks (C/Python/Hako comparison baseline) Phase 22.1 (JsonFrag Unification) - JsonFrag.last_index_of_from() for backward search (VM fallback) - Replace hand-written lastIndexOf in lower_loop_sum_bc_box.hako - SentinelExtractorBox for Break/Continue pattern extraction MirBuilder Refactor (Box → JsonFrag Migration) - 20+ lower_*_box.hako: Box-heavy → JsonFrag text assembly - MirBuilderMinBox: lightweight using set for dev env - Registry-only fast path with [registry:*] tag observation - pattern_util_box.hako: enhanced pattern matching Dev Environment & Testing - Dev toggles: SMOKES_DEV_PREINCLUDE=1 (point-enable), HAKO_MIR_BUILDER_SKIP_LOOPS=1 - phase2160: registry opt-in tests (array/map get/set/push/len) - content verification - phase2034: rc-dependent → token grep (grep -F based validation) - run_quick.sh: fast smoke testing harness - ENV documentation: docs/ENV_VARS.md Test Results ✅ quick phase2034: ALL GREEN (MirBuilder internal patterns) ✅ registry phase2160: ALL GREEN (array/map get/set/push/len) ✅ rc-dependent tests → content token verification complete ✅ PREINCLUDE policy: default OFF, point-enable only where needed Technical Notes - No INCLUDE by default (maintain minimalism) - FAIL_FAST=0 in Bring-up contexts only (explicit dev toggles) - Tag-based route observation ([mirbuilder/min:*], [registry:*]) - MIR structure validation (not just rc parity) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 19:42:42 +09:00
/// Builtin ring1 FileBox provider (corero) — always available, lowest priority
struct CoreRoFileProviderFactory;
impl ProviderFactory for CoreRoFileProviderFactory {
fn box_name(&self) -> &str { "FileBox" }
fn create_provider(&self) -> Arc<dyn FileIo> { Arc::new(CoreRoFileIo::new()) }
fn is_available(&self) -> bool { true }
fn priority(&self) -> i32 { -100 } // ring1: lower than any plugin/provider
}
/// Ensure ring1 (corero) provider is present in the registry
fn ensure_builtin_file_provider_registered() {
let reg = PROVIDER_FACTORIES.get_or_init(|| Mutex::new(Vec::new()));
let mut guard = reg.lock().unwrap();
// If at least one FileBox provider exists, we still keep ring1 present for safety; avoid duplicates by checking any corero present by priority
let has_core_ro = guard.iter().any(|f| f.box_name() == "FileBox" && f.priority() <= -100);
if !has_core_ro {
guard.push(Arc::new(CoreRoFileProviderFactory));
}
}
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
/// 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 quiet_pipe = crate::config::env::env_bool("NYASH_JSON_ONLY");
feat(phase21.5/22.1): MirBuilder JsonFrag refactor + FileBox ring-1 + registry tests Phase 21.5 (AOT/LLVM Optimization Prep) - FileBox ring-1 (core-ro) provider: priority=-100, always available, no panic path - src/runner/modes/common_util/provider_registry.rs: CoreRoFileProviderFactory - Auto-registers at startup, eliminates fallback panic structurally - StringBox fast path prototypes (length/size optimization) - Performance benchmarks (C/Python/Hako comparison baseline) Phase 22.1 (JsonFrag Unification) - JsonFrag.last_index_of_from() for backward search (VM fallback) - Replace hand-written lastIndexOf in lower_loop_sum_bc_box.hako - SentinelExtractorBox for Break/Continue pattern extraction MirBuilder Refactor (Box → JsonFrag Migration) - 20+ lower_*_box.hako: Box-heavy → JsonFrag text assembly - MirBuilderMinBox: lightweight using set for dev env - Registry-only fast path with [registry:*] tag observation - pattern_util_box.hako: enhanced pattern matching Dev Environment & Testing - Dev toggles: SMOKES_DEV_PREINCLUDE=1 (point-enable), HAKO_MIR_BUILDER_SKIP_LOOPS=1 - phase2160: registry opt-in tests (array/map get/set/push/len) - content verification - phase2034: rc-dependent → token grep (grep -F based validation) - run_quick.sh: fast smoke testing harness - ENV documentation: docs/ENV_VARS.md Test Results ✅ quick phase2034: ALL GREEN (MirBuilder internal patterns) ✅ registry phase2160: ALL GREEN (array/map get/set/push/len) ✅ rc-dependent tests → content token verification complete ✅ PREINCLUDE policy: default OFF, point-enable only where needed Technical Notes - No INCLUDE by default (maintain minimalism) - FAIL_FAST=0 in Bring-up contexts only (explicit dev toggles) - Tag-based route observation ([mirbuilder/min:*], [registry:*]) - MIR structure validation (not just rc parity) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 19:42:42 +09:00
// Always ensure ring1 (corero) exists before inspecting registry
ensure_builtin_file_provider_registered();
let registry = PROVIDER_FACTORIES.get();
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
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();
}
}
feat(phase21.5/22.1): MirBuilder JsonFrag refactor + FileBox ring-1 + registry tests Phase 21.5 (AOT/LLVM Optimization Prep) - FileBox ring-1 (core-ro) provider: priority=-100, always available, no panic path - src/runner/modes/common_util/provider_registry.rs: CoreRoFileProviderFactory - Auto-registers at startup, eliminates fallback panic structurally - StringBox fast path prototypes (length/size optimization) - Performance benchmarks (C/Python/Hako comparison baseline) Phase 22.1 (JsonFrag Unification) - JsonFrag.last_index_of_from() for backward search (VM fallback) - Replace hand-written lastIndexOf in lower_loop_sum_bc_box.hako - SentinelExtractorBox for Break/Continue pattern extraction MirBuilder Refactor (Box → JsonFrag Migration) - 20+ lower_*_box.hako: Box-heavy → JsonFrag text assembly - MirBuilderMinBox: lightweight using set for dev env - Registry-only fast path with [registry:*] tag observation - pattern_util_box.hako: enhanced pattern matching Dev Environment & Testing - Dev toggles: SMOKES_DEV_PREINCLUDE=1 (point-enable), HAKO_MIR_BUILDER_SKIP_LOOPS=1 - phase2160: registry opt-in tests (array/map get/set/push/len) - content verification - phase2034: rc-dependent → token grep (grep -F based validation) - run_quick.sh: fast smoke testing harness - ENV documentation: docs/ENV_VARS.md Test Results ✅ quick phase2034: ALL GREEN (MirBuilder internal patterns) ✅ registry phase2160: ALL GREEN (array/map get/set/push/len) ✅ rc-dependent tests → content token verification complete ✅ PREINCLUDE policy: default OFF, point-enable only where needed Technical Notes - No INCLUDE by default (maintain minimalism) - FAIL_FAST=0 in Bring-up contexts only (explicit dev toggles) - Tag-based route observation ([mirbuilder/min:*], [registry:*]) - MIR structure validation (not just rc parity) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-10 19:42:42 +09:00
// Fallback policy
// Allow a narrow, explicit carveout:
// - When JSONonly pipeline is active (quiet structured I/O), or
// - When NYASH_FILEBOX_ALLOW_FALLBACK=1 is set,
// always use corero provider even if FailFast is ON.
let allow_fb_override =
crate::config::env::env_bool("NYASH_JSON_ONLY") ||
crate::config::env::env_bool("NYASH_FILEBOX_ALLOW_FALLBACK");
if crate::config::env::fail_fast() && !allow_fb_override {
eprintln!("[failfast/provider/filebox:auto-fallback-blocked]");
panic!("Fail-Fast: FileBox provider fallback is disabled (NYASH_FAIL_FAST=0 or NYASH_FILEBOX_ALLOW_FALLBACK=1 to override)");
} else {
if !quiet_pipe {
eprintln!(
"[provider-registry] FileBox: using core-ro fallback{}",
if allow_fb_override { " (override)" } else { "" }
);
}
Arc::new(CoreRoFileIo::new())
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::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())
}
}
}