bun was the wrong runtime for our environment, two ways:
1. bun doesn't ship node:sqlite. sf-db.ts falls back through node:sqlite
→ better-sqlite3 → null. Result: 'No SQLite provider available' and
degraded-mode filesystem-state derivation, even though sqlite is
actually available (node:sqlite under node, bun:sqlite under bun —
both valid, but our code only knows the node names).
2. bun's loader doesn't inherit the system library search path under
Nix. libz.so.1 isn't found for forge_engine.node, so the native
addon falls through to JS implementations (slower).
Both warnings ("Native addon not available", "DB unavailable —
degraded mode") were the symptom of "we're running under bun".
Fix: use node + the existing src/resources/extensions/sf/tests/
resolve-ts.mjs loader hook (which already handles .js → .ts
import-specifier remapping for runtime resolution) +
--experimental-strip-types (node 22+, native in 24).
Result: from-source via node loads cleanly. No native warning.
No sqlite warning. No degraded mode. Exec: `./bin/sf-from-source
--print "..."` returns the model output and nothing else.
Drops the LD_LIBRARY_PATH zlib-injection hack that was added in
4912f6ea8 — that was working around the bun native-loader issue
that doesn't exist under node.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
1.6 KiB
Bash
Executable file
40 lines
1.6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# sf-from-source — run SF directly from this source checkout via node.
|
|
#
|
|
# Purpose: every local commit in this repo is live immediately without
|
|
# rebuilding dist/. Subagents can spawn sf by pointing SF_BIN_PATH at
|
|
# this script instead of dist/loader.js.
|
|
#
|
|
# Why node, not bun:
|
|
# - bun doesn't ship node:sqlite (sf-db.ts falls back to filesystem-
|
|
# derivation degraded mode under bun).
|
|
# - bun's native-addon loader doesn't inherit the system library
|
|
# search path under Nix (libz.so.1 not found for forge_engine.node).
|
|
# - node 22.5+ has node:sqlite built-in; node 24 supports
|
|
# --experimental-strip-types so .ts runs directly.
|
|
# - The src/resources/extensions/sf/tests/resolve-ts.mjs loader hook
|
|
# already handles .js → .ts import-specifier remapping for runtime
|
|
# resolution.
|
|
#
|
|
# Contract:
|
|
# - Executable shim; spawn() / exec() can launch directly.
|
|
# - Exports SF_BIN_PATH before handing off to loader.ts so loader.ts's
|
|
# `SF_BIN_PATH ||= process.argv[1]` branch preserves the shim path
|
|
# instead of clobbering it with the .ts loader path (which is not
|
|
# directly executable by child_process.spawn).
|
|
#
|
|
# Requirements: node >= 22.5 on PATH (24+ recommended for strip-types),
|
|
# node_modules populated.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR=$(cd -- "$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")" &>/dev/null && pwd)
|
|
SF_SOURCE_ROOT=$(cd -- "$SCRIPT_DIR/.." &>/dev/null && pwd)
|
|
|
|
export SF_BIN_PATH="$SCRIPT_DIR/sf-from-source"
|
|
|
|
exec node \
|
|
--import "$SF_SOURCE_ROOT/src/resources/extensions/sf/tests/resolve-ts.mjs" \
|
|
--experimental-strip-types \
|
|
--no-warnings \
|
|
"$SF_SOURCE_ROOT/src/loader.ts" "$@"
|