Thanks to visit codestin.com
Credit goes to github.com

Skip to content

WASM Node.js polyfills for node:fs, node:path, node:os #12

Description

@joshuajbouw

Parent: #9

Summary

Extend Tier 1 WASM plugins to support node:fs, node:path, and node:os via polyfills in the shim and new host functions.

Blocked By

Nothing — can start immediately.

Deliverables

C1. Shim Polyfills

Modify: crates/openclaw-bridge/src/shim.rs

Add to generated shim header:

  • require() polyfill dispatching node:fs_virtualFs, node:path_virtualPath, node:os_virtualOs
  • _virtualFs: readFileSynchostReadFile, writeFileSynchostWriteFile, existsSync, mkdirSync, readdirSync, statSync, unlinkSync
  • _virtualPath: pure JS join, resolve, dirname, basename, extname, sep, normalize
  • _virtualOs: homedir()/data, platform()"wasm", tmpdir()/tmp

C2. New Host Functions

Modify: crates/astrid-plugins/src/wasm/host_functions.rs

Add (all through resolve_within_workspace() + SecurityGate):

  • astrid_fs_exists(path: PTR) → i32
  • astrid_fs_mkdir(path: PTR)
  • astrid_fs_readdir(path: PTR) → PTR (JSON array)
  • astrid_fs_stat(path: PTR) → PTR (JSON: {size, isDir, mtime})
  • astrid_fs_unlink(path: PTR)

Update alphabetical host function index and QuickJS dispatch table.

C3. Transpiler Relaxation

Modify: crates/openclaw-bridge/src/transpiler.rs

Allow imports from node:fs, node:path, node:os (polyfilled). Rewrite to require() calls during transpilation. Continue rejecting other runtime imports.

Acceptance Criteria

  • WASM plugin calling require("node:fs").readFileSync(...) works through host functions
  • node:path operations work as pure JS (no host function needed)
  • node:os returns virtual values (homedir/data)
  • 5 new host functions registered in correct alphabetical order
  • Shim dispatch table and QuickJS metadata updated
  • Transpiler allows node:fs, node:path, node:os imports

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions