fix: embed claw binary into clawctl + production build script#21
Merged
fix: embed claw binary into clawctl + production build script#21
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the broken `import.meta.dir` path resolution (which fails in
compiled binaries) with Bun's `import ... with { type: "file" }` asset
embedding. In dev mode, returns the original `dist/claw` path; in
compiled mode, extracts to a temp location automatically.
Also fixes `build:release` to build `claw` before `clawctl`, ensuring
the asset exists at bundle time.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
In compiled mode, Bun's `import ... with { type: "file" }` returns a
`/$bunfs/` virtual path. Bun's own fs polyfills can read it, but
external tools like `limactl copy` cannot. Detect the virtual path and
extract the binary to a real temp file before handing it to the driver.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Follows Bun's production deployment recommendations. Minify reduces JS payload size, sourcemaps preserve original locations in stack traces (zstd-compressed, zero cost until an error), and bytecode compilation moves parsing from runtime to build time for faster startup. Applied to build:claw, build, and build:release. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bun's minifier and bytecode compiler don't support top-level await, which yoga-layout (Ink dependency) uses. Keep all three flags on build:claw (no TLA in our code), use only --sourcemap for clawctl. Wrap claw.ts entry point in async IIFE to satisfy the minifier. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Bun's bytecode and minifier require --format=esm to support top-level await (fixed in Bun 1.3.9, oven-sh/bun#14412). With the flag set, all three production flags (--minify --sourcemap --bytecode) now work for both claw and clawctl builds. Reverts the async IIFE workaround in claw.ts — no longer needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move build configuration into a proper Bun.build() script. Shared options (format, minify, sourcemap, bytecode) are defined once. Sequencing (claw before clawctl) is handled in code, not shell &&. Usage: bun scripts/build.ts [claw|release|all] Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
With --compile, linked sourcemaps produce stray .map files that won't travel with the standalone binary. Use inline to embed them directly. (Bun still creates the external files as a side effect, but they're gitignored and the maps are embedded in the binary either way.) Co-Authored-By: Claude Opus 4.6 (1M context) <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.
Summary
clawctlexecutable using Bun'simport ... with { type: "file" }asset embedding. The release binary is now fully self-contained — no siblingdist/clawfile needed./$bunfs/virtual paths aren't accessible to external tools likelimactl copy, so we extract the embedded binary to a real temp file on first use.--minify --sourcemap --bytecode --format=esmto all compiled builds (Bun's recommended production settings). Minify alone saves ~110MB onclawctl.scripts/build.ts): Replace inline shell commands with a properBun.build()script. Shared options defined once, proper error handling, clear sequencing. Package.json scripts become one-liners.Files changed
packages/host-core/src/claw-binary.ts— new: embedded asset import + temp file extractionpackages/host-core/src/provision.ts— useclawPathinstead of brokenimport.meta.dirresolutionpackages/host-core/src/index.ts— re-exportclawPathscripts/build.ts— new:Bun.build()API build scriptpackage.json— simplified build scriptsTest plan
bun run build:releasesucceedsbun run build:clawsucceedsbun run buildsucceedsclawctlprovisions a VM (deploys claw from embedded asset)🤖 Generated with Claude Code