Skip to content

feat(js): add customBuiltins to Bash and BashTool#1647

Open
mayneyao wants to merge 2 commits into
everruns:mainfrom
eidos-space:main
Open

feat(js): add customBuiltins to Bash and BashTool#1647
mayneyao wants to merge 2 commits into
everruns:mainfrom
eidos-space:main

Conversation

@mayneyao
Copy link
Copy Markdown

@mayneyao mayneyao commented May 22, 2026

Register JS callbacks as persistent bash builtins that share the Bash/BashTool instance's VFS. Files survive across execute() calls.

Constructor-time: new Bash({ customBuiltins: { name: callback } })
Post-construction: bash.addBuiltin(name, callback)

Callback receives BuiltinContext: { name, argv, stdin, env, cwd } Returns a string result (stdout).

Adds JsCustomBuiltinAdapter (Builtin trait impl) in the NAPI-RS bindings, stores entries in SharedState for reset() persistence, and exposes both customBuiltins option and addBuiltin() method.

10 new tests cover constructor registration, argv/stdin, VFS persistence across calls, reset survival, post-construction addBuiltin, env/cwd context, BashTool integration, and pipes.

#1646

mayneyao added 2 commits May 22, 2026 10:39
Register JS callbacks as persistent bash builtins that share the
Bash/BashTool instance's VFS. Files survive across execute() calls.

Constructor-time: new Bash({ customBuiltins: { name: callback } })
Post-construction: bash.addBuiltin(name, callback)

Callback receives BuiltinContext: { name, argv, stdin, env, cwd }
Returns a string result (stdout).

Adds JsCustomBuiltinAdapter (Builtin trait impl) in the NAPI-RS
bindings, stores entries in SharedState for reset() persistence,
and exposes both customBuiltins option and addBuiltin() method.

10 new tests cover constructor registration, argv/stdin, VFS
persistence across calls, reset survival, post-construction
addBuiltin, env/cwd context, BashTool integration, and pipes.
Replace TSFN one-shot protocol with a two-phase dispatch:
1. Rust sends (callId, requestJson) via TSFN (fire-and-forget)
2. JS calls user callback, awaits if async, then calls
   respondToBuiltin(callId, result) or respondToBuiltinError(callId, err)
3. Registry-backed oneshot channel completes on Rust side

Adds respondToBuiltin / respondToBuiltinError napi methods to
Bash and BashTool. Updates BuiltinCallback type to
(ctx) => string | Promise<string>.

8 new async tests.
@chaliy
Copy link
Copy Markdown
Contributor

chaliy commented May 22, 2026

@mayneyao underline APIs allows adding builtins only during object contruction. This is mostly done to avoid extra lookups during runtime. In rust this is netural, because we have builder APIs which reconstructs Bash only on final step. In TS and Python contract that you built looks netural, but I cannot accept contribution that recreates object explicitly, this is not exepcted for users at all.

Give me some time, let me rebuild underline API so that it would allo adding builtins in runtime, and then API that you built would plugin netuarall. I will look into this in couple of hours.

@mayneyao
Copy link
Copy Markdown
Author

mayneyao commented May 23, 2026

@mayneyao underline APIs allows adding builtins only during object contruction. This is mostly done to avoid extra lookups during runtime. In rust this is netural, because we have builder APIs which reconstructs Bash only on final step. In TS and Python contract that you built looks netural, but I cannot accept contribution that recreates object explicitly, this is not exepcted for users at all.

Give me some time, let me rebuild underline API so that it would allo adding builtins in runtime, and then API that you built would plugin netuarall. I will look into this in couple of hours.

Understood. In my use case I only need customBuiltins and that's enough for me. addBuiltin isn't necessary. That said, it would be great to expose more Rust config to the JS bindings — like env and network.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants