|
| 1 | +## Context |
| 2 | + |
| 3 | +`NodeProcess` currently combines two responsibilities: runtime orchestration and Node/`isolated-vm` execution internals. The constructor also accepts direct capability adapters and permissions, while `createNodeDriver` separately applies capability/permission defaults. This split causes ownership ambiguity and policy drift. |
| 4 | + |
| 5 | +This change adopts a strict boundary: |
| 6 | +- Driver owns capability and execution-heavy behavior. |
| 7 | +- `NodeProcess` remains the orchestrator for bridge/loader flow over a generic runtime-driver interface. |
| 8 | +- Runtime configuration (`processConfig`, `osConfig`) is always injected by `NodeProcess`, but sourced from the driver contract. |
| 9 | + |
| 10 | +For this phase, browser support is intentionally disabled to reduce cross-runtime coupling while the Node boundary is refactored. |
| 11 | + |
| 12 | +## Goals / Non-Goals |
| 13 | + |
| 14 | +**Goals:** |
| 15 | +- Make `driver` required for `NodeProcess` construction. |
| 16 | +- Remove direct capability injection from `NodeProcess` options and move ownership into driver construction. |
| 17 | +- Normalize permission behavior to deny-by-default at driver level. |
| 18 | +- Keep bridge/loader orchestration in `NodeProcess` but drive it through a generic execution interface. |
| 19 | +- Preserve current Node runtime behavior (run/exec semantics, active-handle wait, host network facade) after boundary changes. |
| 20 | +- Temporarily disable browser runtime exports/paths during refactor. |
| 21 | + |
| 22 | +**Non-Goals:** |
| 23 | +- Restoring browser runtime support in this change. |
| 24 | +- Introducing new sandbox capabilities beyond the existing fs/network/child_process/process/os/runtime set. |
| 25 | +- Reworking bridge module semantics unrelated to ownership boundaries. |
| 26 | + |
| 27 | +## Decisions |
| 28 | + |
| 29 | +### 1. Require driver at construction |
| 30 | + |
| 31 | +**Choice:** `NodeProcessOptions.driver` becomes required, and constructor fallback logic that synthesizes a driver from raw options is removed. |
| 32 | + |
| 33 | +**Rationale:** This creates a single capability source of truth and removes implicit behavior. |
| 34 | + |
| 35 | +**Alternative considered:** Keep optional driver for backward compatibility. Rejected because it preserves split ownership and duplicate policy paths. |
| 36 | + |
| 37 | +### 2. Introduce a generic runtime-driver interface |
| 38 | + |
| 39 | +**Choice:** Define an internal runtime-driver contract that exposes execution lifecycle and capability handles consumed by `NodeProcess`. |
| 40 | + |
| 41 | +**Rationale:** `NodeProcess` can remain bridge/loader orchestrator while runtime-specific heavy lifting lives in Node driver implementation. |
| 42 | + |
| 43 | +**Alternative considered:** Move all runtime orchestration into driver and reduce `NodeProcess` to a shell. Rejected for this phase because bridge/loader sequencing remains shared orchestration logic. |
| 44 | + |
| 45 | +### 3. Move execution-heavy Node/isolated-vm behavior into Node driver |
| 46 | + |
| 47 | +**Choice:** Shift isolate lifecycle, module execution/caching, dynamic import handling, and host-side marshalling internals into Node driver-owned implementation. |
| 48 | + |
| 49 | +**Rationale:** These are runtime-specific concerns and should not live in a generic process facade. |
| 50 | + |
| 51 | +**Alternative considered:** Keep runtime internals in `NodeProcess` and only change constructor options. Rejected because it does not achieve driver ownership goals. |
| 52 | + |
| 53 | +### 4. Keep `processConfig`/`osConfig` injected by `NodeProcess`, sourced from driver |
| 54 | + |
| 55 | +**Choice:** `NodeProcess` continues to perform bridge/bootstrap injection, but config values are read from the required driver. |
| 56 | + |
| 57 | +**Rationale:** Preserves deterministic initialization point while aligning configuration ownership with driver contract. |
| 58 | + |
| 59 | +**Alternative considered:** Driver performs direct bridge/global injection. Rejected because it duplicates orchestration coupling and weakens shared initialization control. |
| 60 | + |
| 61 | +### 5. Deny-by-default capability policy in driver |
| 62 | + |
| 63 | +**Choice:** Driver defaults to reject all operations when permissions are not explicitly granted. |
| 64 | + |
| 65 | +**Rationale:** Security baseline should be explicit and centralized at the driver boundary. |
| 66 | + |
| 67 | +**Alternative considered:** Preserve permissive fallback when adapters are present. Rejected as unsafe and inconsistent with intended sandbox posture. |
| 68 | + |
| 69 | +### 6. Temporarily disable browser runtime paths |
| 70 | + |
| 71 | +**Choice:** Comment out browser-facing exports/integration paths for this phase and treat browser runtime as unsupported until re-enabled by a follow-up change. |
| 72 | + |
| 73 | +**Rationale:** Avoids maintaining parallel runtime semantics while core ownership boundaries are being refactored. |
| 74 | + |
| 75 | +**Alternative considered:** Keep browser runtime compiling with compatibility shims. Rejected to keep scope tight and reduce regression surface. |
| 76 | + |
| 77 | +## Risks / Trade-offs |
| 78 | + |
| 79 | +- **Breaking constructor and options contract** -> Mitigation: explicit migration in proposal/tasks and targeted updates across tests/examples/docs. |
| 80 | +- **Behavior drift during runtime logic move** -> Mitigation: preserve existing execution scenarios (CJS/ESM exports, dynamic import timing, active-handle waits, host network path) as acceptance criteria. |
| 81 | +- **Permission default regression** -> Mitigation: enforce driver-level deny-default tests and remove remaining permissive fallback paths. |
| 82 | +- **Temporary browser disable may affect consumers** -> Mitigation: clearly document unsupported status and require explicit follow-up change to restore. |
| 83 | + |
| 84 | +## Migration Plan |
| 85 | + |
| 86 | +1. Define new runtime-driver interfaces in `types.ts` and update `NodeProcessOptions` to require `driver`. |
| 87 | +2. Refactor Node driver implementation to own execution-heavy runtime responsibilities and capability policy defaults. |
| 88 | +3. Update `NodeProcess` to consume runtime-driver interface and keep bridge/loader orchestration + config injection flow. |
| 89 | +4. Disable/comment browser integration paths and document temporary unsupported state. |
| 90 | +5. Update tests and examples to required-driver construction; remove direct constructor adapter usage. |
| 91 | +6. Update compatibility/friction documentation and add follow-up for browser restoration. |
| 92 | + |
| 93 | +## Open Questions |
| 94 | + |
| 95 | +- Should browser disable behavior surface as compile-time absence of exports, runtime throw, or both? |
| 96 | +- Do we keep any public mutator methods on `NodeProcess` (currently none required), or make process instances fully immutable post-construction? |
0 commit comments