feat(js): add customBuiltins to Bash and BashTool#1647
Conversation
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.
|
@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. |
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