feat(Ring0): Phase 107 - Ring0.FsApi FileIo integration complete

Implementation Summary:
Phase 107 establishes FileBox as a unified layer over Ring0.FsApi

Completed Tasks:
- Task 1: FsApi SSOT review and documentation
- Task 2: FileIo designed as FsApi wrapper
- Task 3: Ring0FsFileIo implementation added
- Task 4: Fail-Fast integration verified
- Task 5: Documentation integration complete

Key Changes:
1. New File: src/providers/ring1/file/ring0_fs_fileio.rs
   - Ring0.FsApi-based FileIo implementation
   - Stateful wrapper (open/read/close)
   - UTF-8 handling via read_to_string()
   - One-file-at-a-time semantics (tested)

2. provider_lock.rs:
   - Added init_default_filebox_provider()
   - Auto-registration helper for Ring0FsFileIo

3. plugin_host.rs:
   - with_core_from_registry_optional() auto-registers default provider
   - Plugin priority maintained (debug logging)
   - Phase 106 MissingService check still active (Fail-Fast preserved)

4. Documentation:
   - phase107_fsapi_fileio_bridge.md: Complete design doc
   - phase106_filebox_design_revised.md: Phase 107 integration notes
   - core_boxes_design.md: Layer diagram and principles

Design Decisions:
- UTF-8 handling: read_to_string() for text-focused use cases
- One file at a time: open() returns Err if already open
- Plugin priority: init_default_filebox_provider() fails gracefully

Test Results:
- cargo build --release: SUCCESS
- plugin_host tests: 11 passed
- ring0_fs_fileio tests: 4 passed

Next Steps (Phase 108+):
- minimal/no-fs profile support
- write operations
- multi-file handle support
This commit is contained in:
nyash-codex
2025-12-03 18:16:49 +09:00
parent 38db674101
commit 0fd4962e4c
9 changed files with 375 additions and 102 deletions

View File

@ -155,8 +155,25 @@ impl PluginHost {
use crate::runtime::core_services::*;
use crate::runtime::provider_lock;
// Phase 107: Auto-register default FileBox provider (Ring0.FsApi-based)
// This happens before the Phase 106 check, so plugins can still override.
// If a plugin has already registered, this returns Err but we continue.
if CoreBoxId::File.is_core_required() {
match provider_lock::init_default_filebox_provider(&ring0) {
Ok(()) => {
// Default provider registered successfully
ring0.log.debug("[Phase 107] Ring0FsFileIo registered as default FileBox provider");
}
Err(msg) => {
// Plugin provider already registered - this is OK (plugin priority)
ring0.log.debug(&format!("[Phase 107] {}", msg));
}
}
}
// Phase 106: FileBox provider チェック追加
// CoreBoxId がFileを必須と判定している場合、provider が登録されていることを確認
// Phase 107: With auto-registration above, this check should always pass
if CoreBoxId::File.is_core_required() {
if provider_lock::get_filebox_provider().is_none() {
return Err(CoreInitError::MissingService {
@ -303,15 +320,13 @@ mod tests {
// Phase 94: 実際の registry を使用してテスト
use crate::runtime::ring0::default_ring0;
use crate::box_factory::builtin::BuiltinBoxFactory;
use crate::boxes::file::core_ro::CoreRoFileIo;
use crate::runtime::provider_lock;
let ring0 = Arc::new(default_ring0());
let mut registry = UnifiedBoxRegistry::new();
registry.register(Arc::new(BuiltinBoxFactory::new()));
// Phase 106: Initialize FileBox provider before PluginHost creation
let _ = provider_lock::set_filebox_provider(Arc::new(CoreRoFileIo::new()));
// Phase 107: FileBox provider auto-registration (no manual setup needed)
// with_core_from_registry will call init_default_filebox_provider internally
let plugin_host = PluginHost::with_core_from_registry(ring0, &registry)
.expect("CoreServices should be initialized with builtin boxes");
@ -325,15 +340,13 @@ mod tests {
// Phase 94: 実際の registry を使用して全フィールドが存在することを確認
use crate::runtime::ring0::default_ring0;
use crate::box_factory::builtin::BuiltinBoxFactory;
use crate::boxes::file::core_ro::CoreRoFileIo;
use crate::runtime::provider_lock;
let ring0 = Arc::new(default_ring0());
let mut registry = UnifiedBoxRegistry::new();
registry.register(Arc::new(BuiltinBoxFactory::new()));
// Phase 106: Initialize FileBox provider before PluginHost creation
let _ = provider_lock::set_filebox_provider(Arc::new(CoreRoFileIo::new()));
// Phase 107: FileBox provider auto-registration (no manual setup needed)
// with_core_from_registry will call init_default_filebox_provider internally
let plugin_host = PluginHost::with_core_from_registry(ring0, &registry)
.expect("CoreServices should be initialized");

View File

@ -67,3 +67,28 @@ pub fn get_filebox_provider() -> Option<&'static Arc<dyn FileIo>> {
pub fn get_filebox_caps() -> Option<FileCaps> {
get_filebox_provider().map(|p| p.caps())
}
/// Phase 107: Initialize default FileBox provider using Ring0.FsApi
///
/// This helper registers Ring0FsFileIo as the default FileBox provider.
/// It should be called during runtime initialization, after CoreServices setup.
///
/// # Returns
///
/// - `Ok(())`: Default provider registered successfully
/// - `Err(msg)`: Provider already registered (plugin took precedence)
///
/// # Design
///
/// Plugin providers have priority over the default. If a plugin has already
/// registered a FileBox provider, this function returns Err but the system
/// continues normally (plugin priority is honored).
pub fn init_default_filebox_provider(
ring0: &Arc<crate::runtime::ring0::Ring0Context>
) -> Result<(), String> {
use crate::providers::ring1::file::ring0_fs_fileio::Ring0FsFileIo;
let provider = Arc::new(Ring0FsFileIo::new(ring0.clone()));
set_filebox_provider(provider)
.map_err(|_| "Plugin FileBox provider already registered".to_string())
}