diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md index d5d4be51..d35cf596 100644 --- a/packages/coding-agent/CHANGELOG.md +++ b/packages/coding-agent/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Externalized koffi from bun binary builds, reducing archive sizes by ~15MB per platform (e.g. darwin-arm64: 43MB -> 28MB). Koffi's Windows-only `.node` file is now shipped alongside the Windows binary only. + ## [0.54.0] - 2026-02-19 ### Added diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md index 903312f6..bcc556d1 100644 --- a/packages/tui/CHANGELOG.md +++ b/packages/tui/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +### Fixed + +- Changed koffi import from top-level to dynamic require in `enableWindowsVTInput()` to prevent bun from embedding all 18 platform `.node` files (~74MB) into every compiled binary. Koffi is only needed on Windows. + ## [0.54.0] - 2026-02-19 ## [0.53.1] - 2026-02-19 diff --git a/packages/tui/src/terminal.ts b/packages/tui/src/terminal.ts index 5a83d876..52f6361c 100644 --- a/packages/tui/src/terminal.ts +++ b/packages/tui/src/terminal.ts @@ -1,5 +1,4 @@ import * as fs from "node:fs"; -import koffi from "koffi"; import { setKittyProtocolActive } from "./keys.js"; import { StdinBuffer } from "./stdin-buffer.js"; @@ -174,6 +173,10 @@ export class ProcessTerminal implements Terminal { private enableWindowsVTInput(): void { if (process.platform !== "win32") return; try { + // Dynamic require to avoid bundling koffi's 74MB of cross-platform + // native binaries into every compiled binary. Koffi is only needed + // on Windows for VT input support. + const koffi = require("koffi"); const k32 = koffi.load("kernel32.dll"); const GetStdHandle = k32.func("void* __stdcall GetStdHandle(int)"); const GetConsoleMode = k32.func("bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)"); diff --git a/scripts/build-binaries.sh b/scripts/build-binaries.sh index 0488c8cf..fd9a60f5 100755 --- a/scripts/build-binaries.sh +++ b/scripts/build-binaries.sh @@ -102,10 +102,14 @@ fi for platform in "${PLATFORMS[@]}"; do echo "Building for $platform..." + # Externalize koffi to avoid embedding all 18 platform .node files (~74MB) + # into every binary. Koffi is only used on Windows for VT input and the + # call site has a try/catch fallback. For Windows builds, we copy the + # appropriate .node file alongside the binary below. if [[ "$platform" == "windows-x64" ]]; then - bun build --compile --target=bun-$platform ./dist/cli.js --outfile binaries/$platform/pi.exe + bun build --compile --external koffi --target=bun-$platform ./dist/cli.js --outfile binaries/$platform/pi.exe else - bun build --compile --target=bun-$platform ./dist/cli.js --outfile binaries/$platform/pi + bun build --compile --external koffi --target=bun-$platform ./dist/cli.js --outfile binaries/$platform/pi fi done @@ -122,6 +126,14 @@ for platform in "${PLATFORMS[@]}"; do cp -r dist/core/export-html binaries/$platform/ cp -r docs binaries/$platform/ cp -r examples binaries/$platform/ + + # Copy koffi native module for Windows (needed for VT input support) + if [[ "$platform" == "windows-x64" ]]; then + mkdir -p binaries/$platform/node_modules/koffi/build/koffi/win32_x64 + cp ../../node_modules/koffi/index.js binaries/$platform/node_modules/koffi/ + cp ../../node_modules/koffi/package.json binaries/$platform/node_modules/koffi/ + cp ../../node_modules/koffi/build/koffi/win32_x64/koffi.node binaries/$platform/node_modules/koffi/build/koffi/win32_x64/ + fi done # Create archives