|
| 1 | +## Context |
| 2 | + |
| 3 | +`RuntimeDriver` currently carries both capability configuration (filesystem/network/child-process/permissions/runtime config) and execution-construction hooks (`runtimeHooks`). This mixes data ownership with engine-construction concerns and makes the generic driver type depend on Node-specific execution wiring. |
| 4 | + |
| 5 | +The goal is to preserve runtime behavior while clarifying boundaries: capability data stays on the driver, and execution construction moves to a separate factory contract. |
| 6 | + |
| 7 | +## Goals / Non-Goals |
| 8 | + |
| 9 | +**Goals:** |
| 10 | +- Separate capability/config ownership from execution-engine construction. |
| 11 | +- Keep `runtime.process` and `runtime.os` sourced from the driver and injected into execution. |
| 12 | +- Preserve deny-by-default semantics and existing run/exec behavior. |
| 13 | +- Provide a clean extension point for non-Node execution engines without hook leakage. |
| 14 | + |
| 15 | +**Non-Goals:** |
| 16 | +- Reworking module loading/bridge semantics. |
| 17 | +- Changing permission policy behavior. |
| 18 | +- Restoring browser runtime support in this change. |
| 19 | + |
| 20 | +## Decisions |
| 21 | + |
| 22 | +1. Introduce explicit execution factory contract. |
| 23 | +- Decision: Add a dedicated runtime execution factory/provider type and remove `runtimeHooks` from `RuntimeDriver`. |
| 24 | +- Rationale: keeps `RuntimeDriver` as pure capability/config surface and removes implicit, optional hook coupling. |
| 25 | +- Alternative considered: keep `runtimeHooks` but make fields required. Rejected because it still blends concerns and keeps generic driver tied to execution internals. |
| 26 | + |
| 27 | +2. Update `NodeRuntime` constructor to accept both capability driver and execution factory. |
| 28 | +- Decision: `NodeRuntime` requires explicit factory wiring at construction time. |
| 29 | +- Rationale: dependency is explicit at API boundary and independent of driver data shape. |
| 30 | +- Alternative considered: global/default factory fallback. Rejected because hidden defaults reduce clarity and complicate multi-runtime composition. |
| 31 | + |
| 32 | +3. Keep runtime config injection path unchanged in intent. |
| 33 | +- Decision: `process`/`os` config remains on driver and is normalized by `NodeRuntime` before creating execution driver. |
| 34 | +- Rationale: preserves current ownership expectations and avoids duplicating runtime config across surfaces. |
| 35 | +- Alternative considered: move runtime config into factory options only. Rejected because driver is the canonical capability/config bundle. |
| 36 | + |
| 37 | +4. Keep Node-owned heavy lifting in Node factory/driver modules. |
| 38 | +- Decision: Node-specific isolate wiring and execution driver construction stays in Node implementation modules, not generic runtime types. |
| 39 | +- Rationale: aligns with driver-owned specialization and reduces generic runtime coupling. |
| 40 | + |
| 41 | +## Risks / Trade-offs |
| 42 | + |
| 43 | +- [Breaking API surface] Constructor/type signatures change for hosts creating `NodeRuntime` directly. → Mitigation: update exports/types in one change and cover with type tests. |
| 44 | +- [Migration confusion] Existing code may still expect `driver.runtimeHooks`. → Mitigation: remove hook references in runtime/docs and update Node factory helpers to provide the new execution factory directly. |
| 45 | +- [Behavior drift risk] Refactor could accidentally alter deny-by-default behavior. → Mitigation: run targeted permissions/runtime tests and preserve adapter wrapping/stubs paths. |
0 commit comments