feat(openclaw): add native dependency stubs for WebContainer#8
Open
Dhi13man wants to merge 3 commits intoopen-gitagent:mainfrom
Open
feat(openclaw): add native dependency stubs for WebContainer#8Dhi13man wants to merge 3 commits intoopen-gitagent:mainfrom
Dhi13man wants to merge 3 commits intoopen-gitagent:mainfrom
Conversation
Stub sharp, @lydell/node-pty, playwright-core, sqlite-vec, and node-llama-cpp with dual ESM/CJS exports. Includes installer script that copies stubs into node_modules/ after npm install, replacing native packages that crash in WebContainer's WASM sandbox. Co-Authored-By: Dhiman's Agentic Suite <dhiman.seal@hotmail.com>
…, installer guard - Add resolveModelFile and LlamaLogLevel to node-llama-cpp stub (OpenClaw destructures these in embeddings.ts) - Add hasAlpha and channels to sharp metadata() return (OpenClaw reads these in image-ops.ts:377) - Add node_modules existence check to installer script Co-Authored-By: Dhiman's Agentic Suite <dhiman.seal@hotmail.com>
Two test files: - stubs.test.ts: STUB_FILES map integrity, package.json dual exports, installer script correctness - stubs-behavior.test.ts: require() each stub and verify API surface — sharp chainable builder + metadata, node-pty spawn throws, playwright browser launchers reject, sqlite-vec load no-op, node-llama-cpp getLlama/resolveModelFile/LlamaLogLevel exports Co-Authored-By: Dhiman's Agentic Suite <dhiman.seal@hotmail.com>
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.
Why
OpenClaw depends on 5 native Node.js modules (
sharp,@lydell/node-pty,playwright-core,sqlite-vec,node-llama-cpp) that use C/C++ bindings. WebContainer runs a WASM-based Node.js sandbox that cannot load native addons — anyrequire('sharp')crashes the process immediately. This blocks #4.This PR provides stub packages that export the expected API surface with no-op implementations, allowing OpenClaw to import these modules without crashing.
Design Context
flowchart LR A[npm install openclaw] --> B[node_modules/ contains real native packages] B --> C[INSTALL_STUBS_SCRIPT runs] C --> D[cp stubs over real packages in node_modules/] D --> E["require('sharp') → stub builder, no crash"] D --> F["require('node-pty') → stub, spawn throws at call time"] D --> G["require('playwright-core') → stub, launch rejects"]Each stub is a directory with 3 files:
package.json— dualexportsfield (import→.mjs,require→.cjs)index.cjs— explicitmodule.exports.X =pattern (compatible withcjs-module-lexer)index.mjs— re-exports from CJSWhy explicit
module.exports.Xinstead of Proxy or spread?Node's
cjs-module-lexer(used by the ESM loader to detect CJS named exports) only parses static patterns.module.exports = new Proxy(...)ormodule.exports = { ...obj }won't be detected. Every stub usesmodule.exports.X = Xon separate lines so ESMimport { X } from 'pkg'resolves correctly.Trade-offs
sharp().resize().toBuffer()returns an emptyBuffer. OpenClaw code that checks buffer size (e.g.,optimizeImageToPng) will get 0 bytes and short-circuit. Accepted — image processing is disabled in WebContainer, not simulated.INSTALL_STUBS_SCRIPTcopies stubs over real packages afternpm install. This is a post-install override, not a pre-install interception. If npm install itself crashes on native build steps, the existing--ignore-scriptsflag incontainer.ts:203prevents that.How to review
src/openclaw/stubs/sharp/index.cjsmetadata()returnshasAlpha/channelssrc/openclaw/stubs/node-llama-cpp/index.cjsresolveModelFileandLlamaLogLevelexports (OpenClaw destructures these)src/openclaw/stubs.tsSTUB_FILESmap (15 entries),INSTALL_STUBS_SCRIPTwith@lydellscope handlingsrc/openclaw/stubs-behavior.test.tsrequire()and exercisedTest plan
npx vitest run— 42 tests covering:STUB_FILEShas 15 entries, each package haspackage.json/.cjs/.mjs, dual exports configured,module.exportspattern used, ESM re-exports present@lydellscope dir, guards against missingnode_modulestoBuffer()→ empty Buffer,metadata()includeshasAlpha/channelsspawn()throws with descriptive errorchromium.launch()rejects,devicesexported,TimeoutErrorclass existsload()is no-op,getLoadablePath()returns empty stringgetLlama()rejects,resolveModelFile()rejects,LlamaLogLevelhas numeric levelsCloses #4 (partial — native dependency stubs)
Generated with Dhiman's Agentic Suite