fix: exec() node fallback + feat: includeNodeShims option (fixes #64, #63)#66
Open
aayushprsingh wants to merge 2 commits intorivet-dev:mainfrom
Open
fix: exec() node fallback + feat: includeNodeShims option (fixes #64, #63)#66aayushprsingh wants to merge 2 commits intorivet-dev:mainfrom
aayushprsingh wants to merge 2 commits intorivet-dev:mainfrom
Conversation
Fixes rivet-dev#64 — exec() throws 'No shell available' when only NodeRuntime is mounted (which registers 'node', not 'sh'). Before this change: createKernel() → mount(createNodeRuntime()) kernel.exec('node -e "console.log(1)"') // throws: No shell available After this change: - If 'sh' is registered: routes through shell (existing behavior) - If only 'node' is registered: parses command string, strips 'node' prefix, spawns node directly with remaining args - If neither: throws improved error with actionable guidance Added: - #parseCommandArgs(): shell-like tokenizer (handles '...', "..." escapes) - #collectExecResult(): extracted common stdout/stderr collection logic - 3 new test cases in kernel-integration.test.ts
Author
|
Hey! Ran into issue #64 when trying the README example — This PR adds a fallback: when Happy to iterate if you'd like a different approach — e.g. if you'd prefer to just improve the error message rather than auto-fallback. Let me know! |
…lyfills Fixes rivet-dev#63 — adds ability to disable Node.js polyfill shims (fs, http, process, Buffer, etc.) on globalThis. When includeNodeShims: false is passed to createNodeRuntime(): - globalThis.fs, globalThis.http, globalThis.process, globalThis.Buffer are NOT injected into the isolate - Useful for AI agents that need a clean globalThis scope - fs/http are still accessible via require('fs') / await import('fs') when host filesystem is permitted via permissions API: createNodeRuntime({ includeNodeShims: false }) Default: true (existing behavior unchanged). Changes: - packages/nodejs/src/kernel-runtime.ts: Added includeNodeShims to NodeRuntimeOptions - packages/nodejs/src/driver.ts: Added includeNodeShims to NodeDriverOptions, pass to runtime config - packages/nodejs/src/execution-driver.ts: buildFullBridgeCode() now keyed by includeNodeShims in a Map<boolean,string> cache; per-driver bridge code built in constructor - packages/nodejs/test/kernel-runtime.test.ts: 3 new tests for includeNodeShims=false/true
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
fix: exec() falls back to node when sh is unavailable (fixes #64)
File: packages/core/src/kernel/kernel.ts
exec() currently throws "No shell available" when only createNodeRuntime() is mounted, because NodeRuntime registers 'node', not 'sh'. This breaks the README example immediately.
Fix: Added a fallback path — when 'sh' is not registered but 'node' is, exec() parses the command string, strips the 'node' prefix, and spawns node directly.
Now works out-of-the-box:
kernel.exec("node -e "console.log('hello')"") // ✓ instead of throwing
Changes:
feat: add includeNodeShims option (fixes #63)
Files: packages/nodejs/src/kernel-runtime.ts, packages/nodejs/src/driver.ts, packages/nodejs/src/execution-driver.ts, packages/nodejs/test/kernel-runtime.test.ts
Adds ability to disable Node.js polyfill shims (fs, http, process, Buffer, etc.) on globalThis. Useful for AI agents that need a clean global scope.
Usage:
// Clean scope: globalThis has NO injected shims
const driver = createNodeRuntime({ includeNodeShims: false });
await kernel.mount(driver);
// globalThis.fs === undefined ✓
// require('fs') still works via bridge permissions
Default: true (existing behavior unchanged).
Technical: buildFullBridgeCode() is keyed by includeNodeShims in a Map<boolean,string> cache. Each driver's bridge code is built once in the constructor.
Tests
Both changes include tests — 3 for the exec() fallback, 3 for includeNodeShims.