feat(core): demonstrate aube C ABI (bun:ffi) installer behind Npm.Service#37391
Draft
jdx wants to merge 4 commits into
Draft
feat(core): demonstrate aube C ABI (bun:ffi) installer behind Npm.Service#37391jdx wants to merge 4 commits into
jdx wants to merge 4 commits into
Conversation
…vice Companion demo to the @jdxcode/aube-node PR: same Npm.Service swap implemented over @jdxcode/aube-ffi via bun:ffi. aube_wait blocks its calling thread, so each operation runs in a Bun Worker that posts the handle back for main-thread aube_cancel. Raw package specifiers pass straight to aube_add. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Bun cannot receive FFI callbacks on aube's threads, so progress arrives via the C ABI's polled transport (aube 1.29.0's bufferEvents + aube_events_next): the worker keeps blocking in aube_wait while the main thread — which already dlopens for aube_cancel — drains the event queue on a 50ms interval. Events still buffered when aube_wait returns are discarded with the handle, so the client synthesizes the terminal event from the authoritative result when the stream didn't deliver one; consumers key UI state off it, matching the Node-API transport. Npm.Service gains the same optional EventOptions surface as the aube-node branch so the two backends stay directly comparable. AUBE_FFI_LIBRARY overrides the packaged library path, mirroring aube's own smoke-test convention. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The polled event transport dlopens aube_events_next, which first shipped in the 1.29.0 C ABI libraries. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
6 tasks
Version parity with the Node-API branch; 1.29.1 carries the minimumReleaseAge add-pin fix (jdx/aube#1056). Co-Authored-By: Claude Fable 5 <noreply@anthropic.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.
Issue for this PR
References #37301 (demonstration companion to the Node-API variant #37300; not intended to land alongside it). Supersedes #37305 — GitHub can't reopen a PR after its head branch was rebased, so this is the same branch rebuilt on aube 1.29.0.
Type of change
What does this PR do?
Demonstrates the C ABI / bun:ffi flavor of the same
Npm.Serviceswap proposed in #37301:packages/core/src/npm.tsbacked by@jdxcode/aube-ffiinstead of@npmcli/arborist. This exists so both aube embedding surfaces can be compared side by side against the Node-API PR; the Node-API variant is the one I'd recommend landing.How it works:
aube_waitblocks the thread that calls it, so each operation runs in a BunWorker(packages/core/src/aube-ffi/worker.ts) that dlopens the library, startsaube_install/aube_add, posts the operation handle back, then blocks inaube_waitand posts the JSON result. The client (aube-ffi/client.ts) maps the Effect scope'sAbortSignalto a main-threadaube_cancelon that handle, so the event loop is never blocked and cancellation works. Offline-first policy is identical to the Node-API PR.New since #37305 — install progress over the polled transport. Bun can't receive FFI callbacks on aube's threads, so progress arrives via aube 1.29.0's
bufferEvents+aube_events_next: operations start with buffering enabled and the main thread — which already dlopens foraube_cancel— drains the event queue on a 50 ms interval while the worker blocks inaube_wait(polling from a different thread than the waiter is the documented pattern). Events still buffered whenaube_waitreturns are discarded with the handle, so the client synthesizes the terminal event from the authoritative result when the stream didn't deliver one — consumers key UI state off it, matching the Node-API transport.Npm.Serviceexposes the identical optionalEventOptionssurface as #37300, so the two backends stay directly comparable.AUBE_FFI_LIBRARYoverrides the packaged library path for tests/local dev, mirroring aube's own smoke-test convention.Notable differences vs the Node-API variant, from actually building both:
aube_addtakes an array of spec strings, so git/tarball/alias specs need no name/version splitting (the Node-API input is{name, version}pairs)..npmrcomit=dev|optional→ dependency-selection mapping that the Node-API addon does internally had to be reimplemented here, and the worker/cancel/poll choreography is ~200 lines that@jdxcode/aube-nodesimply doesn't need.bun:ffidoesn't exist under Node, so this variant can't back the node build.bunPluginfor embedding one platform addon per compiled target; doing the same for the FFI dylib would need hand-rolled embed/extract wiring, which I deliberately left out of a demo.How did you verify your code works?
packages/corenpm suite as before (9/9 acrossnpm.test.ts+npm-config.test.ts, including.npmrcomit=devandfile:spec cases);tscclean;oxlint0 errors;prettierclean@jdxcode/aube-ffi@1.29.0:add("express@4.21.2")delivers 272 events (resolving → fetching → linking → complete, 266 progress ticks) and materializes the package; aborting awebpackadd mid-flight rejects withERR_AUBE_INSTALL_CANCELLED— exercising the new main-thread dlopen includingaube_events_nextcompletephase falls into the final poll window and the synthesized terminal arrives insteadScreenshots / recordings
Not a UI change.
Checklist
Written by an AI coding assistant (Claude Code), directed and reviewed by @jdx.