Skip to content

Commit 26fd44d

Browse files
NathanFlurryclaude
andcommitted
docs: add native/ directory restructure to consolidation proposal
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3d91055 commit 26fd44d

1 file changed

Lines changed: 82 additions & 3 deletions

File tree

docs-internal/proposal-kernel-consolidation.md

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
Consolidate the two parallel architectures (published SDK layer and kernel/OS layer) into a single kernel-first architecture. The kernel becomes the default for all usage. The non-kernel `NodeRuntime` / `SystemDriver` API is removed. Runtime packages (`@secure-exec/nodejs`, `@secure-exec/python`, `@secure-exec/wasmvm`) become kernel drivers that users mount. The user experience is progressive: start with sandboxed Node, add WasmVM for shell/POSIX, add Python for Python — all via `kernel.mount()`.
1010

11+
Additionally, restructure the repository layout to cleanly separate TypeScript packages (`packages/`) from native Rust code (`native/`), eliminating the current split where Rust code is scattered across `crates/` and `wasmvm/` at the repo root.
12+
1113
## Motivation
1214

1315
### Two architectures, one product
@@ -34,6 +36,15 @@ The kernel path wraps the SDK path — `runtime-node` creates a `SystemDriver` a
3436

3537
6. **Naming confusion.** `@secure-exec/node` (published V8 driver) vs `@secure-exec/runtime-node` (kernel runtime driver) vs `@secure-exec/os-node` (kernel platform adapter) — three packages with "node" in the name at different abstraction levels.
3638

39+
### Scattered native code
40+
41+
Rust code lives in two disconnected locations at the repo root:
42+
43+
- **`crates/v8-runtime/`** — a single Rust crate that compiles to a host binary (x86/arm). It's the V8 runtime process that `@secure-exec/v8` spawns. Sits alone in `crates/` with no siblings.
44+
- **`wasmvm/`** — an entire separate Rust workspace with its own `Cargo.toml`, `Cargo.lock`, `Makefile`, `vendor/`, `scripts/`, `patches/`, and `CLAUDE.md`. Contains ~90 command crates compiled to `wasm32-wasip1`, plus C programs and wasi-libc patches.
45+
46+
These two Rust projects have completely different toolchains and targets (host native vs WASM), so they can't share a Cargo workspace. But having them at different nesting levels (`crates/X` vs `wasmvm/`) with different conventions makes the repo harder to navigate. Meanwhile, `packages/` mixes flat top-level packages (`secure-exec-core`) with nested groups (`runtime/node`, `os/browser`), and after the kernel consolidation those nested groups get merged away.
47+
3748
### Why the kernel is effectively free
3849

3950
The kernel constructor (`kernel.ts:88-121`) is synchronous, in-memory setup:
@@ -47,7 +58,52 @@ The expensive part — `NodeExecutionDriver` + V8 isolate + bridge — is identi
4758

4859
## Target Architecture
4960

50-
### Package structure
61+
### Repository layout
62+
63+
```
64+
/
65+
├── native/ ← All Rust/C native code
66+
│ ├── v8-runtime/ ← V8 host binary (x86/arm)
67+
│ │ ├── Cargo.toml
68+
│ │ └── src/
69+
│ └── wasmvm/ ← WASM command workspace (wasm32-wasip1)
70+
│ ├── Cargo.toml ← Workspace root (separate from v8-runtime)
71+
│ ├── Cargo.lock
72+
│ ├── Makefile
73+
│ ├── rust-toolchain.toml
74+
│ ├── crates/
75+
│ │ ├── commands/ ← ~90 command crates (sh, ls, grep, etc.)
76+
│ │ ├── libs/ ← Shared Rust libs for commands
77+
│ │ └── wasi-ext/ ← WASI host import declarations
78+
│ ├── c/ ← C programs compiled to WASM
79+
│ ├── patches/ ← wasi-libc patches
80+
│ ├── vendor/ ← Vendored Rust deps
81+
│ ├── scripts/
82+
│ └── CLAUDE.md
83+
├── packages/ ← All TypeScript packages (pnpm workspace)
84+
│ ├── secure-exec/ ← Re-export of @secure-exec/nodejs
85+
│ ├── secure-exec-core/ ← Kernel + types + utilities
86+
│ ├── secure-exec-nodejs/ ← Node.js runtime driver + bridge
87+
│ ├── secure-exec-v8/ ← V8 bindings (TS side)
88+
│ ├── secure-exec-python/ ← Python runtime driver
89+
│ ├── secure-exec-wasmvm/ ← WasmVM runtime driver (TS side)
90+
│ ├── secure-exec-browser/ ← Browser platform adapter (future)
91+
│ ├── secure-exec-typescript/ ← TypeScript helpers
92+
│ ├── playground/ ← Dev playground (private)
93+
│ └── website/ ← Docs site (private)
94+
├── docs/ ← Public documentation (Astro)
95+
├── docs-internal/ ← Internal specs, proposals, glossary
96+
├── examples/ ← Example projects
97+
└── scripts/ ← Repo-level scripts
98+
```
99+
100+
**Key principles:**
101+
- `packages/` = TypeScript. `native/` = Rust/C. No mixing.
102+
- `native/v8-runtime/` and `native/wasmvm/` remain separate Cargo workspaces (different toolchains, different targets). The `native/` grouping is organizational, not a shared workspace.
103+
- `packages/` is flat — no nested `runtime/`, `os/`, or `kernel/` subdirectories after consolidation.
104+
- `wasmvm/` internals (crates, patches, vendor, Makefile) are preserved as-is under `native/wasmvm/`.
105+
106+
### npm package structure
51107

52108
```
53109
secure-exec (published — convenience re-export)
@@ -333,14 +389,32 @@ const kernel = createKernel({
333389

334390
**This is a semver major bump.** Publish as `secure-exec@0.2.0` (or `1.0.0` if ready).
335391

336-
### Phase 6: Cleanup
392+
### Phase 6: Repository layout restructure (low risk)
393+
394+
Move native code into `native/` and flatten `packages/`.
395+
396+
1. Move `crates/v8-runtime/``native/v8-runtime/`.
397+
2. Move `wasmvm/``native/wasmvm/`.
398+
3. Update `@secure-exec/v8` to reference `native/v8-runtime/` for the Rust binary (postinstall script, build paths).
399+
4. Update `@secure-exec/wasmvm` to reference `native/wasmvm/target/` for WASM binaries.
400+
5. Update `turbo.json` `build:wasm` task inputs from `wasmvm/**` to `native/wasmvm/**`.
401+
6. Update CLAUDE.md references to `wasmvm/` and `crates/`.
402+
7. Update `native/wasmvm/CLAUDE.md` if path references change.
403+
8. Delete empty top-level `crates/` and `wasmvm/` directories.
404+
405+
**Risk:** Low — these are pure file moves with no code changes. The two Rust workspaces remain independent. The main risk is stale path references in scripts, CI, and documentation.
406+
407+
**Verification:** `cd native/v8-runtime && cargo build` and `cd native/wasmvm && make wasm` must both work after the move.
408+
409+
### Phase 7: Cleanup
337410

338411
1. Delete empty/merged packages: `@secure-exec/kernel`, `@secure-exec/runtime-node`, `@secure-exec/runtime-python`, `@secure-exec/runtime-wasmvm`, `@secure-exec/os-node`, `@secure-exec/os-browser`.
339-
2. Update `pnpm-workspace.yaml` to remove old paths.
412+
2. Update `pnpm-workspace.yaml` to remove old paths (`packages/os/*`, `packages/runtime/*`).
340413
3. Update `turbo.json` tasks.
341414
4. Update `docs-internal/arch/overview.md`.
342415
5. Update contracts in `.agent/contracts/`.
343416
6. Update CLAUDE.md.
417+
7. Update CI workflows (`.github/workflows/`) for new paths.
344418

345419
## Open Questions
346420

@@ -404,6 +478,8 @@ This is straightforward but must be done in Phase 3 when the kernel merges into
404478
| Published API break | Certain | High | Semver major bump, migration guide, deprecation warnings |
405479
| turbo.json cache invalidation | Medium | Low | Rebuild cache from scratch after restructure |
406480
| Browser support regression | Low | Low | Already broken, explicitly deferred |
481+
| Stale native path references after layout move | Medium | Medium | Grep all references to `crates/`, `wasmvm/` in CI, scripts, docs, CLAUDE.md; verify `cargo build` and `make wasm` post-move |
482+
| CI workflows break from path changes | Medium | Medium | Update `.github/workflows/` glob patterns and cache keys in same PR as moves |
407483

408484
## Success Criteria
409485

@@ -415,3 +491,6 @@ This is straightforward but must be done in Phase 3 when the kernel merges into
415491
6. Adding WasmVM/Python is one import + one `mount()` call — no API change.
416492
7. No duplicate type definitions between packages.
417493
8. All docs updated to reflect new API.
494+
9. All Rust/C code lives under `native/`. All TypeScript packages live under `packages/`. No code at the repo root.
495+
10. `cd native/v8-runtime && cargo build` and `cd native/wasmvm && make wasm` both succeed.
496+
11. No remaining references to old paths (`crates/v8-runtime`, top-level `wasmvm/`) in CI, scripts, docs, or CLAUDE.md.

0 commit comments

Comments
 (0)