refactor(pocket-pi): TypeScript build pipeline for the JS guest layer - #4
Merged
Conversation
…peline The JS glue was hand-dropped .js files. Now all of it is TypeScript under js/src/, compiled by one build step (js/build.mjs) that emits the artifacts the Rust crate embeds. This does NOT affect future pi bumps — the glue is Pocket Pi's own runtime layer, entirely separate from pi (which is still a real unmodified npm dependency, bundled). A bump stays `npm update` + rebuild + (if needed) add a shim; the shim being .ts changes nothing. Layout: js/src/runtime/** → crates/pocket-pi/js/** (per-file transpile; include_str!'d) js/src/trimmed/** → crates/pocket-pi/js/agent.bundle.js js/src/pi-full/** → crates/pocket-pi/js/pi-full.bundle.js(.gz) + harness scripts - One `node js/build.mjs` runs tsc (typecheck) + esbuild (transpile runtime glue, emit harness scripts, bundle trimmed + full pi). esbuild/typescript are real devDeps now (no more `npx esbuild@…`). build-pi-full.mjs folded in. - The emitted runtime .js and agent.bundle.js are committed so `cargo` still builds Rust-only; the full pi bundle stays git-ignored. - tsconfig typechecks Pocket Pi's own orchestration code (the pi-full session harness); the runtime polyfills and pi-ai/undici adapter glue are transpile- only (typechecking a polyfill against the APIs it reimplements is counterproductive). env.d.ts declares the loose host/global surface. - Rust include_str! paths are UNCHANGED (emit lands where they expect). Only the test harness paths moved (js/pi-full → crates/pocket-pi/js/pi-full for emitted scripts, js/src/pi-full for the example extension). Along the way the trimmed bundle now builds against pi 0.81 too (pi-ai-stub gains contentText/retryAssistantCall/uuidv7, which 0.81's pi-agent-core imports). Full suite green (23 unit + 8 ignored: bundle load, extension bind + tool turn, persistence, embedded full pi), typecheck + clippy clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <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.
Phase 3 of the effort (follows the pi 0.81 bump + self-contained binary in #3). The JS glue was hand-dropped
.js; now it's TypeScript underjs/src/, compiled by one build step.Does this affect future pi bumps? No.
The glue is Pocket Pi's own runtime layer, separate from pi (still a real, unmodified npm dependency that gets bundled). A bump stays
npm update+ rebuild + (if the newer pi needs a new builtin/global) add a shim — and the shim being.tsinstead of.jschanges nothing. The bundle output is JS regardless (esbuild takes a.tsentry). If anything, the typecheck makes the "fix what breaks" step safer.Layout
node js/build.mjsrunstsc --noEmit(typecheck) + esbuild (transpile the runtime glue, emit the harness scripts, bundle the trimmed + full pi).esbuildandtypescriptare real devDeps now (no morenpx esbuild@…);build-pi-full.mjsfolded in.include_str!paths are unchanged — the build emits.jsexactly where they're expected. The emitted runtime.js+agent.bundle.jsare committed socargostill builds Rust-only; the full-pi bundle stays git-ignored.pi-fullsession harness). The runtime polyfills and the pi-ai/undici adapter glue are transpile-only — typechecking a polyfill against the very APIs it reimplements is counterproductive.env.d.tsdeclares the loose host/global surface.pi-aistub gainscontentText/retryAssistantCall/uuidv7, which 0.81'spi-agent-coreimports).Tests / CI
Full suite green — 23 unit tests + 8
#[ignore](bundle load, extension bind, extension tool turn, persistence, embedded full pi);tsc+clippy -D warningsclean.🤖 Generated with Claude Code