Skip to content

fix: embed claw binary into clawctl + production build script#21

Merged
TimBeyer merged 9 commits intomainfrom
fix/embed-claw-binary
Mar 15, 2026
Merged

fix: embed claw binary into clawctl + production build script#21
TimBeyer merged 9 commits intomainfrom
fix/embed-claw-binary

Conversation

@TimBeyer
Copy link
Owner

@TimBeyer TimBeyer commented Mar 15, 2026

Summary

  • Embed claw binary into the compiled clawctl executable using Bun's import ... with { type: "file" } asset embedding. The release binary is now fully self-contained — no sibling dist/claw file needed.
  • Materialize to temp file in compiled mode: Bun's /$bunfs/ virtual paths aren't accessible to external tools like limactl copy, so we extract the embedded binary to a real temp file on first use.
  • Production build flags: Add --minify --sourcemap --bytecode --format=esm to all compiled builds (Bun's recommended production settings). Minify alone saves ~110MB on clawctl.
  • Build script (scripts/build.ts): Replace inline shell commands with a proper Bun.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.tsnew: embedded asset import + temp file extraction
  • packages/host-core/src/provision.ts — use clawPath instead of broken import.meta.dir resolution
  • packages/host-core/src/index.ts — re-export clawPath
  • scripts/build.tsnew: Bun.build() API build script
  • package.json — simplified build scripts

Test plan

  • bun run build:release succeeds
  • bun run build:claw succeeds
  • bun run build succeeds
  • Compiled clawctl provisions a VM (deploys claw from embedded asset)
  • Lint and format pass

🤖 Generated with Claude Code

TimBeyer and others added 9 commits March 16, 2026 00:19
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>
@TimBeyer TimBeyer merged commit 1ef67a8 into main Mar 15, 2026
4 checks passed
@TimBeyer TimBeyer deleted the fix/embed-claw-binary branch March 15, 2026 23:46
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.

1 participant