feat(phase109): RuntimeProfile設計で FileBox を条件付き optional に
Phase 109 完全実装完了: - RuntimeProfile enum (Default, NoFs) で profile 制御 - CoreBoxId.is_required_in(profile) で条件付き required/optional - initialize_runtime() で env 読み込み責務を一元化(修正1) - NoFsFileIo スタブで no-fs プロファイルでの FileBox 無効化(修正2) - Logger/ConsoleService は no-fs でも有効と明示(修正2) - Profile 拡張予定(TestMock/Sandbox/ReadOnly/Embedded)を予約(修正3) 実装ファイル: - src/runtime/runtime_profile.rs (新規) - src/providers/ring1/file/nofs_fileio.rs (新規) - src/runtime/core_box_ids.rs (修正) - src/runtime/plugin_host.rs (修正) - src/runtime/provider_lock.rs (修正) - docs 更新 テスト: Phase 109 11/11 PASS ✅ ビルド: cargo build --release SUCCESS ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -292,7 +292,122 @@ FileBox の実体 I/O は、以下の層構造で Ring0.FsApi を通す設計が
|
||||
- `src/runtime/provider_lock.rs`: init_default_filebox_provider() ヘルパー
|
||||
- `src/runtime/plugin_host.rs`: 起動時自動登録
|
||||
|
||||
### 5.4 今後の拡張
|
||||
### 5.4 Phase 109 - RuntimeProfile 機構(2025-12-03 完了)✅
|
||||
|
||||
**ゴール**:
|
||||
- FileBox を **profile 依存の conditional required** に変更
|
||||
- Default profile(selfhost/standard)では FileBox 必須を維持
|
||||
- NoFs profile(minimal runtime)では FileBox を optional に
|
||||
|
||||
**実装内容**:
|
||||
|
||||
1. **RuntimeProfile enum 導入** (`src/runtime/runtime_profile.rs`):
|
||||
```rust
|
||||
pub enum RuntimeProfile {
|
||||
Default, // selfhost/standard
|
||||
NoFs, // minimal runtime without filesystem
|
||||
}
|
||||
|
||||
impl RuntimeProfile {
|
||||
pub fn from_env() -> Self {
|
||||
// NYASH_RUNTIME_PROFILE=no-fs → NoFs
|
||||
// それ以外 → Default
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
2. **CoreBoxId に profile-aware 判定追加** (`src/runtime/core_box_ids.rs`):
|
||||
```rust
|
||||
pub fn is_required_in(&self, profile: &RuntimeProfile) -> bool {
|
||||
match profile {
|
||||
RuntimeProfile::Default => {
|
||||
// FileBox は required(Phase 106 互換)
|
||||
self.is_core_required()
|
||||
}
|
||||
RuntimeProfile::NoFs => {
|
||||
// FileBox は optional
|
||||
matches!(self, String | Integer | Bool | Array | Map | Console)
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. **PluginHost に profile 引数追加** (`src/runtime/plugin_host.rs`):
|
||||
- `with_core_from_registry_optional(ring0, registry, config, profile)` に拡張
|
||||
- profile-aware FileBox provider チェック:
|
||||
- Default: provider 必須(CoreInitError::MissingService if None)
|
||||
- NoFs: provider なくても OK(黙って skip)
|
||||
|
||||
4. **NoFsFileIo stub 実装** (`src/providers/ring1/file/nofs_fileio.rs`):
|
||||
```rust
|
||||
pub struct NoFsFileIo;
|
||||
|
||||
impl FileIo for NoFsFileIo {
|
||||
fn caps(&self) -> FileCaps { FileCaps { read: false, write: false } }
|
||||
fn open/read/write/close → Err(FileError::Unsupported)
|
||||
}
|
||||
```
|
||||
|
||||
5. **initialize_runtime() に profile 読み込み追加** (`src/runtime/mod.rs`):
|
||||
- 環境変数から profile を読む(**この層のみで実施**)
|
||||
- NoFs profile の場合、NoFsFileIo を登録
|
||||
- PluginHost に profile を渡す(**env に依存しない**)
|
||||
|
||||
**設計原則(Modification 1: 責務分離)**:
|
||||
```
|
||||
【Layer】 【責務】 【Example】
|
||||
────────────────────────────────────────────────────────
|
||||
env User configuration NYASH_RUNTIME_PROFILE=no-fs
|
||||
initialize_runtime() env → RuntimeProfile profile = RuntimeProfile::from_env()
|
||||
PluginHost profile-aware checks is_required_in(&profile)
|
||||
CoreBoxId 条件付き required 判定 is_required_in(&profile)
|
||||
provider_lock provider 登録(Profile 後)set_filebox_provider()
|
||||
FileBox provider 経由 read/write 実装
|
||||
```
|
||||
|
||||
**Logger/ConsoleService の有効性(Modification 2)**:
|
||||
- ✅ **NoFs profile でも有効**:
|
||||
- Ring0.log(OS抽象化層 - panic/exit 時の最終出力)
|
||||
- ConsoleBox(言語レベル console - stdout/stderr)
|
||||
- その他 core_required(String/Integer/Bool/Array/Map/Console)
|
||||
- ❌ **NoFs profile で無効**:
|
||||
- FileBox(ファイルシステム依存)
|
||||
- Regex/Time/JSON 等のオプショナル boxes(将来:profile ごとに制御可能)
|
||||
|
||||
**将来の拡張予定(Modification 3)**:
|
||||
- **TestMock**: テスト用(すべてのプラグインが mock に)
|
||||
- **Sandbox**: サンドボックス(外部 I/O 禁止)
|
||||
- **ReadOnly**: 読み取り専用(FileBox.write 禁止)
|
||||
- **Embedded**: 組み込み(メモリ制限あり、GC あり)
|
||||
|
||||
**実装箇所**:
|
||||
- `src/runtime/runtime_profile.rs`: RuntimeProfile enum 定義
|
||||
- `src/runtime/core_box_ids.rs`: is_required_in() メソッド
|
||||
- `src/runtime/plugin_host.rs`: profile-aware 初期化ロジック
|
||||
- `src/runtime/provider_lock.rs`: init_filebox_provider_for_profile()
|
||||
- `src/providers/ring1/file/nofs_fileio.rs`: NoFs stub 実装
|
||||
- `src/runtime/mod.rs`: initialize_runtime() に profile 読み込み
|
||||
|
||||
**テスト**:
|
||||
- ✅ test_core_box_id_is_required_in_default
|
||||
- ✅ test_core_box_id_is_required_in_nofs
|
||||
- ✅ test_with_core_from_registry_nofs_filebox_optional
|
||||
- ✅ test_nofs_fileio_caps/open/read/write/close_unsupported
|
||||
|
||||
**互換性**:
|
||||
- Phase 107/108 の既存動作は Default profile で完全維持
|
||||
- NoFs profile は完全に新規追加(既存コードに影響なし)
|
||||
|
||||
### 5.5 今後の拡張(Phase 110+)
|
||||
|
||||
Phase 110 以降では、FileBox/FS 周りの扱いをプロファイルと Box 設計の両面から広げていく予定:
|
||||
- **Phase 110: FileHandleBox**
|
||||
- FileBox は「1 ファイル専用 API」としてシンプルに保ち、複数ファイル同時アクセスは FileHandleBox 側に切り出す設計。
|
||||
- Ring0FsFileIo を内部で再利用しつつ、ハンドル単位で FsApi をラップする。
|
||||
- **Phase 111: metadata API 整理**
|
||||
- `FsApi::metadata/exists/canonicalize` を FileIo / FileBox 側に橋渡しし、Nyash 側から stat 情報を扱えるようにする。
|
||||
|
||||
これらはすべて `CoreBoxId` / Ring0.FsApi / FileIo / FileBox の既存ラインの上に小さく積む形で設計する。
|
||||
|
||||
新しいメソッド追加は `src/runtime/core_box_ids.rs` の編集のみで完結:
|
||||
1. CoreMethodId enum にバリアント追加
|
||||
|
||||
@ -351,12 +351,12 @@ provider_lock 登録・参照 OnceLock管理
|
||||
FileBox ユーザーAPI provider 経由のみ
|
||||
```
|
||||
|
||||
### 拡張ポイント
|
||||
### 拡張ポイント(Phase 109+)
|
||||
|
||||
**将来の実装**:
|
||||
- MockFileIo: FsApi の代わりに in-memory mock を使う
|
||||
- NetworkFileIo: FsApi の代わりに remote FS を使う
|
||||
- minimal/no-fs: provider 登録をスキップ(FileBox optional化)
|
||||
**将来の実装候補**:
|
||||
- MockFileIo: FsApi の代わりに in-memory mock を使う(テスト専用)
|
||||
- NetworkFileIo: FsApi の代わりに remote FS を使う(将来の分散 FS / リモートログ用途)
|
||||
- minimal/no-fs: RuntimeProfile に応じて provider 登録をスキップし、FileBox を read-only / disabled として扱う
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -322,4 +322,41 @@ fn test_filebox_double_open() {
|
||||
|
||||
---
|
||||
|
||||
## 9. Phase 109 以降の計画
|
||||
|
||||
### Phase 109: RuntimeProfile 機構の追加
|
||||
|
||||
**Phase 109 完了により、FileBox は conditional required に変更されました**:
|
||||
|
||||
- **RuntimeProfile enum 導入**(Default/NoFs)
|
||||
- **Default profile**: FileBox は required(Phase 107/108 の動作を維持)
|
||||
- **NoFs profile**: FileBox は optional(NoFsFileIo stub で無効化)
|
||||
|
||||
**設計変更**:
|
||||
```rust
|
||||
// Phase 109 以前: FileBox は常に required
|
||||
CoreBoxId::File.is_core_required() // → true
|
||||
|
||||
// Phase 109 以降: profile 依存の判定に
|
||||
CoreBoxId::File.is_required_in(&RuntimeProfile::Default) // → true
|
||||
CoreBoxId::File.is_required_in(&RuntimeProfile::NoFs) // → false
|
||||
```
|
||||
|
||||
**プロファイル別動作**:
|
||||
- **Default**: Ring0FsFileIo(read/write 両対応)自動登録
|
||||
- **NoFs**: NoFsFileIo(全操作で Unsupported エラー)登録
|
||||
|
||||
**将来の拡張計画**(Phase 109 Modification 3):
|
||||
- TestMock: テスト用(全プラグインが mock に)
|
||||
- Sandbox: サンドボックス(外部 I/O 禁止)
|
||||
- ReadOnly: 読み取り専用(FileBox.write 禁止)
|
||||
- Embedded: 組み込み(メモリ制限・GC あり)
|
||||
|
||||
**互換性**:
|
||||
- Phase 107/108 の既存動作は Default profile で完全維持
|
||||
- NoFs profile は完全に新規追加(既存コードに影響なし)
|
||||
|
||||
---
|
||||
|
||||
**Phase 108 指示書作成日**: 2025-12-03(微調整版)
|
||||
**Phase 109 追記**: 2025-12-03(RuntimeProfile 統合完了)
|
||||
|
||||
@ -557,13 +557,37 @@ rg 'impl.*LogApi' --type rust
|
||||
|
||||
## Summary
|
||||
|
||||
Phase 99 establishes a **clear inventory** of logging infrastructure and println! call sites:
|
||||
Phase 85–108 で、Ring0 / CoreServices / FileBox / Logging の基礎はほぼ出揃った:
|
||||
|
||||
1. **Ring0.log**: Underutilized, ready for expansion
|
||||
2. **println!/eprintln!**: 1477 production call sites categorized into 4 groups
|
||||
3. **Migration strategy**: Phased approach starting with user-facing messages
|
||||
4. **Success criteria**: Clear metrics for each phase
|
||||
- Ring0Context: Mem/Io/Time/Log/Fs/Thread の抽象化が確立
|
||||
- CoreBoxId/CoreMethodId: Box 名・メソッド名の SSOT 化
|
||||
- CoreServices/PluginHost: ring1-core (String/Integer/Bool/Array/Map/Console) の service 化
|
||||
- ConsoleService/Logging: 3層設計(Ring0.log / ConsoleService / test println!)が定着
|
||||
- FileBox: CoreRequired 扱い + Ring0FsFileIo 経由で read/write 両対応
|
||||
|
||||
**Phase 102**: StdMem implementation complete, preparing for hakmem integration.
|
||||
Phase 99 は logging infrastructure と println! call site の在庫を整理し:
|
||||
|
||||
**Next Steps**: Phase 100+ will implement gradual migrations based on this inventory.
|
||||
1. **Ring0.log**: dev/debug ログの受け皿として拡張準備済み
|
||||
2. **println!/eprintln!**: ~1400 箇所を 4 カテゴリに分類(user-facing/dev/test/internal)
|
||||
3. **Migration strategy**: user-facing → Ring0.log/internal の順で段階的移行
|
||||
|
||||
Phase 102 では StdMem 実装により hakmem 統合の足場を用意し、
|
||||
Phase 106–108 では FileBox provider_lock / Ring0FsFileIo / write/write_all 実装により、
|
||||
`FileBox → FileIo → Ring0.FsApi → std::fs` のパイプラインが完成した。
|
||||
|
||||
### Next Phases(計画)
|
||||
|
||||
今後の候補フェーズ(優先度の高い順):
|
||||
|
||||
- **Phase 109: runtime profiles(default/no-fs)**
|
||||
- `NYASH_PROFILE={default|no-fs}` などのプロファイル導入
|
||||
- default では FileBox 必須、no-fs では FileBox provider 未登録(エラー文字列で通知)
|
||||
- **Phase 110: FileHandleBox**
|
||||
- FileBox を「1ファイル専用」に保ちつつ、複数ファイル同時アクセスは FileHandleBox 側に切り出す
|
||||
- Ring0FsFileIo を再利用してハンドル単位の管理を行う
|
||||
- **Phase 111: Fs metadata 拡張**
|
||||
- `exists/metadata/canonicalize` を FileIo / FileBox 側にきちんとエクスポート
|
||||
- Ring0.FsApi の stat 情報を Nyash 側から扱えるようにする
|
||||
|
||||
さらに長期的には、Ring0 全体を「統一サービスレジストリ」として扱うフェーズ(Mem/Io/Time/Log/Fs/Thread の trait 統合)を
|
||||
Phase 11x 以降で検討する予定だよ。
|
||||
|
||||
Reference in New Issue
Block a user