|
93 | 93 | - read `docs-internal/arch/overview.md` for the component map (NodeRuntime, RuntimeDriver, NodeDriver, NodeExecutionDriver, ModuleAccessFileSystem, Permissions) |
94 | 94 | - keep it up to date when adding, removing, or significantly changing components |
95 | 95 |
|
| 96 | +## Code Transformation Policy |
| 97 | + |
| 98 | +- NEVER use regex-based source code transformation for JavaScript/TypeScript (e.g., converting ESM to CJS, rewriting imports, extracting exports) |
| 99 | +- regex transformers break on multi-line syntax, code inside strings/comments/template literals, and edge cases like `import X, { a } from 'Y'` — these bugs are subtle and hard to catch |
| 100 | +- instead, use proper tooling: `es-module-lexer` / `cjs-module-lexer` (the same WASM-based lexers Node.js uses), or run the transformation inside the V8 isolate where the JS engine handles parsing correctly |
| 101 | +- if a source transformation is needed at the bridge/host level, prefer a battle-tested library over hand-rolled regex |
| 102 | +- the V8 runtime already has dual-mode execution (`execute_script` for CJS, `execute_module` for ESM) — lean on V8's native module system rather than pre-transforming source on the host side |
| 103 | +- existing regex-based transforms (e.g., `convertEsmToCjs`, `transformDynamicImport`, `isESM`) are known technical debt and should be replaced |
| 104 | + |
96 | 105 | ## Contracts (CRITICAL) |
97 | 106 |
|
98 | 107 | - `.agent/contracts/` contains behavioral contracts — these are the authoritative source of truth for runtime, bridge, permissions, stdlib, and governance requirements |
@@ -173,6 +182,12 @@ Follow the style in `packages/secure-exec/src/index.ts`. |
173 | 182 | - when adding new work, add it to todo.md |
174 | 183 | - when completing work, mark items done in todo.md |
175 | 184 |
|
| 185 | +## Ralph (Autonomous Agent) |
| 186 | + |
| 187 | +- Ralph's working directory is `scripts/ralph/` — this contains `prd.json`, `progress.txt`, `ralph.sh`, `CLAUDE.md`, and the `archive/` folder |
| 188 | +- do NOT create a `.ralph/` directory at the repo root; `scripts/ralph/` is the canonical location |
| 189 | +- when creating or converting PRDs for Ralph, write to `scripts/ralph/prd.json` |
| 190 | + |
176 | 191 | ## Skills |
177 | 192 |
|
178 | 193 | - create project skills in `.claude/skills/` |
|
0 commit comments