Skip to content

Commit eaf7fd0

Browse files
authored
runtime: single source of truth for embedded Node path/version (#146)
1 parent 8e9ea56 commit eaf7fd0

19 files changed

Lines changed: 199 additions & 44 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
lint:
11-
runs-on: &default-runner blacksmith-4vcpu-ubuntu-2404
11+
runs-on: &default-runner ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v4
1414

.github/workflows/integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ concurrency:
1313

1414
jobs:
1515
docs-scope:
16-
runs-on: &default-runner blacksmith-4vcpu-ubuntu-2404
16+
runs-on: &default-runner ubuntu-latest
1717
outputs:
1818
docs_only: ${{ steps.check.outputs.docs_only }}
1919
steps:

CONFIGURATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Set during `setup.sh` / `baudbot install` via env vars:
146146
| Variable | Description | Default |
147147
|----------|-------------|---------|
148148
| `BAUDBOT_PI_VERSION` | pi package version installed for `baudbot_agent` | `0.52.12` |
149+
| `BAUDBOT_RUNTIME_NODE_VERSION` | embedded Node.js version downloaded to `~/opt/node-v<version>-linux-x64` (with stable symlink `~/opt/node`) | `22.14.0` |
149150
| `GIT_USER_NAME` | Git commit author name | `baudbot-agent` |
150151
| `GIT_USER_EMAIL` | Git commit author email | `baudbot-agent@users.noreply.github.com` |
151152

bin/baudbot

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ if [ -z "${BAUDBOT_ROOT:-}" ]; then
2929
fi
3030
fi
3131

32+
RUNTIME_NODE_HELPER="$BAUDBOT_ROOT/bin/lib/runtime-node.sh"
33+
if [ -f "$RUNTIME_NODE_HELPER" ]; then
34+
# shellcheck source=bin/lib/runtime-node.sh
35+
source "$RUNTIME_NODE_HELPER"
36+
fi
37+
3238
json_get_string_or_empty() {
3339
local file="$1"
3440
local key="$2"
@@ -193,7 +199,7 @@ resolve_node_bin() {
193199
return 0
194200
fi
195201

196-
# 2) Common user-managed Node installs (sudo secure_path may hide these)
202+
# 2) Embedded runtime (sudo secure_path may hide these)
197203
local user_home=""
198204
if [ -n "${SUDO_USER:-}" ] && [ "${SUDO_USER}" != "root" ]; then
199205
user_home="$(resolve_user_home "$SUDO_USER" || true)"
@@ -202,20 +208,26 @@ resolve_node_bin() {
202208
user_home="${HOME:-}"
203209
fi
204210

211+
if [ -n "${RUNTIME_NODE_HELPER:-}" ] && [ -f "$RUNTIME_NODE_HELPER" ]; then
212+
local embedded_node=""
213+
embedded_node="$(bb_resolve_runtime_node_bin "$user_home" || true)"
214+
if [ -n "$embedded_node" ] && [ -x "$embedded_node" ]; then
215+
echo "$embedded_node"
216+
return 0
217+
fi
218+
219+
embedded_node="$(bb_resolve_runtime_node_bin "/home/baudbot_agent" || true)"
220+
if [ -n "$embedded_node" ] && [ -x "$embedded_node" ]; then
221+
echo "$embedded_node"
222+
return 0
223+
fi
224+
fi
225+
226+
# 3) Common user-managed Node installs
205227
local candidate=""
206228
for candidate in \
207229
"$user_home/.local/share/mise/shims/node" \
208-
"$user_home/.local/bin/node" \
209-
"$user_home/opt/node-v22.14.0-linux-x64/bin/node" \
210-
/home/baudbot_agent/opt/node-v22.14.0-linux-x64/bin/node \
211-
"$user_home"/opt/node-v*-linux-x64/bin/node; do
212-
# If the glob didn't expand, skip the literal pattern.
213-
case "$candidate" in
214-
*\**)
215-
continue
216-
;;
217-
esac
218-
230+
"$user_home/.local/bin/node"; do
219231
if [ -x "$candidate" ]; then
220232
echo "$candidate"
221233
return 0
@@ -289,11 +301,14 @@ bootstrap_install() {
289301

290302
echo "Escalating with $escalator for system setup..."
291303
if [ "$escalator" = "sudo" ]; then
292-
sudo --preserve-env=BAUDBOT_PI_VERSION bash "$install_script" "$@"
304+
sudo --preserve-env=BAUDBOT_PI_VERSION,BAUDBOT_RUNTIME_NODE_VERSION bash "$install_script" "$@"
293305
else
294306
# doas has no portable preserve-env flag; pass explicitly when set.
295-
if [ -n "${BAUDBOT_PI_VERSION:-}" ]; then
296-
doas env BAUDBOT_PI_VERSION="$BAUDBOT_PI_VERSION" bash "$install_script" "$@"
307+
if [ -n "${BAUDBOT_PI_VERSION:-}" ] || [ -n "${BAUDBOT_RUNTIME_NODE_VERSION:-}" ]; then
308+
doas env \
309+
BAUDBOT_PI_VERSION="${BAUDBOT_PI_VERSION:-}" \
310+
BAUDBOT_RUNTIME_NODE_VERSION="${BAUDBOT_RUNTIME_NODE_VERSION:-}" \
311+
bash "$install_script" "$@"
297312
else
298313
doas bash "$install_script" "$@"
299314
fi

bin/baudbot.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Restart=on-failure
2222
RestartSec=10
2323

2424
# Environment
25-
Environment=PATH=/home/baudbot_agent/.varlock/bin:/home/baudbot_agent/opt/node-v22.14.0-linux-x64/bin:/usr/local/bin:/usr/bin:/bin
25+
Environment=PATH=/home/baudbot_agent/.varlock/bin:/home/baudbot_agent/opt/node/bin:/usr/local/bin:/usr/bin:/bin
2626
Environment=HOME=/home/baudbot_agent
2727

2828
# Security hardening

bin/ci/setup-arch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ echo "$HELP_OUT" | grep -q "baudbot"
6161
# varlock installed for agent user
6262
test -x /home/baudbot_agent/.varlock/bin/varlock
6363
# Agent can load env (smoke test — varlock validates schema + .env)
64-
sudo -u baudbot_agent bash -c 'export PATH="$HOME/.varlock/bin:$HOME/opt/node-v22.14.0-linux-x64/bin:$PATH" && cd ~ && varlock load --path ~/.config/'
64+
sudo -u baudbot_agent bash -c 'export PATH="$HOME/.varlock/bin:$HOME/opt/node/bin:$PATH" && cd ~ && varlock load --path ~/.config/'
6565
echo " ✓ bootstrap + install verification passed"
6666

6767
echo "=== Running CLI smoke checks ==="
6868
bash /home/baudbot_admin/baudbot/bin/ci/smoke-cli.sh
6969

7070
echo "=== Installing test dependencies ==="
71-
export PATH="/home/baudbot_agent/opt/node-v22.14.0-linux-x64/bin:$PATH"
71+
export PATH="/home/baudbot_agent/opt/node/bin:$PATH"
7272
cd /home/baudbot_admin/baudbot
7373
npm install --ignore-scripts 2>&1 | tail -1
7474
cd slack-bridge && npm install 2>&1 | tail -1

bin/ci/setup-ubuntu.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ echo "$HELP_OUT" | grep -q "baudbot"
9999
# varlock installed for agent user
100100
test -x /home/baudbot_agent/.varlock/bin/varlock
101101
# Agent can load env (smoke test — varlock validates schema + .env)
102-
sudo -u baudbot_agent bash -c 'export PATH="$HOME/.varlock/bin:$HOME/opt/node-v22.14.0-linux-x64/bin:$PATH" && cd ~ && varlock load --path ~/.config/'
102+
sudo -u baudbot_agent bash -c 'export PATH="$HOME/.varlock/bin:$HOME/opt/node/bin:$PATH" && cd ~ && varlock load --path ~/.config/'
103103
echo " ✓ bootstrap + install verification passed"
104104

105105
echo "=== Running CLI smoke checks ==="
106106
bash /home/baudbot_admin/baudbot/bin/ci/smoke-cli.sh
107107

108108
echo "=== Installing test dependencies ==="
109-
export PATH="/home/baudbot_agent/opt/node-v22.14.0-linux-x64/bin:$PATH"
109+
export PATH="/home/baudbot_agent/opt/node/bin:$PATH"
110110
cd /home/baudbot_admin/baudbot
111111
npm install --ignore-scripts 2>&1 | tail -1
112112
cd slack-bridge && npm install 2>&1 | tail -1

bin/deploy.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ if [ "$DRY_RUN" -eq 0 ]; then
8282
cp -r --no-preserve=ownership "$BAUDBOT_SRC/pi/skills" "$STAGE_DIR/skills"
8383
cp --no-preserve=ownership "$BAUDBOT_SRC/start.sh" "$STAGE_DIR/start.sh"
8484
mkdir -p "$STAGE_DIR/bin"
85+
mkdir -p "$STAGE_DIR/bin/lib"
8586
for script in harden-permissions.sh redact-logs.sh prune-session-logs.sh; do
8687
[ -f "$BAUDBOT_SRC/bin/$script" ] && cp --no-preserve=ownership "$BAUDBOT_SRC/bin/$script" "$STAGE_DIR/bin/$script"
8788
done
89+
[ -f "$BAUDBOT_SRC/bin/lib/runtime-node.sh" ] && cp --no-preserve=ownership "$BAUDBOT_SRC/bin/lib/runtime-node.sh" "$STAGE_DIR/bin/lib/runtime-node.sh"
8890
[ -f "$BAUDBOT_SRC/pi/settings.json" ] && cp --no-preserve=ownership "$BAUDBOT_SRC/pi/settings.json" "$STAGE_DIR/settings.json"
8991
[ -f "$BAUDBOT_SRC/.env.schema" ] && cp --no-preserve=ownership "$BAUDBOT_SRC/.env.schema" "$STAGE_DIR/.env.schema"
9092
chmod -R a+rX "$STAGE_DIR"
@@ -245,6 +247,7 @@ echo "Deploying runtime scripts..."
245247

246248
if [ "$DRY_RUN" -eq 0 ]; then
247249
as_agent mkdir -p "$BAUDBOT_HOME/runtime/bin"
250+
as_agent mkdir -p "$BAUDBOT_HOME/runtime/bin/lib"
248251

249252
for script in harden-permissions.sh redact-logs.sh prune-session-logs.sh; do
250253
if [ -f "$STAGE_DIR/bin/$script" ]; then
@@ -254,6 +257,12 @@ if [ "$DRY_RUN" -eq 0 ]; then
254257
fi
255258
done
256259

260+
if [ -f "$STAGE_DIR/bin/lib/runtime-node.sh" ]; then
261+
as_agent cp "$STAGE_DIR/bin/lib/runtime-node.sh" "$BAUDBOT_HOME/runtime/bin/lib/runtime-node.sh"
262+
as_agent chmod u+r "$BAUDBOT_HOME/runtime/bin/lib/runtime-node.sh"
263+
log "✓ bin/lib/runtime-node.sh"
264+
fi
265+
257266
as_agent cp "$STAGE_DIR/start.sh" "$BAUDBOT_HOME/runtime/start.sh"
258267
as_agent chmod u+x "$BAUDBOT_HOME/runtime/start.sh"
259268
log "✓ start.sh"

bin/doctor.sh

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ source "$SCRIPT_DIR/lib/shell-common.sh"
1111
source "$SCRIPT_DIR/lib/paths-common.sh"
1212
# shellcheck source=bin/lib/doctor-common.sh
1313
source "$SCRIPT_DIR/lib/doctor-common.sh"
14+
# shellcheck source=bin/lib/runtime-node.sh
15+
source "$SCRIPT_DIR/lib/runtime-node.sh"
1416
bb_enable_strict_mode
1517
bb_init_paths
1618

19+
BAUDBOT_ROOT="${BAUDBOT_ROOT:-$(cd "$SCRIPT_DIR/.." && pwd)}"
20+
1721
for arg in "$@"; do
1822
case "$arg" in
1923
-h|--help)
@@ -55,21 +59,31 @@ fi
5559
echo ""
5660
echo "Dependencies:"
5761

58-
NODE_BIN="$BAUDBOT_HOME/opt/node-v22.14.0-linux-x64/bin/node"
59-
if [ -x "$NODE_BIN" ]; then
62+
NODE_BIN="$(bb_resolve_runtime_node_bin "$BAUDBOT_HOME" || true)"
63+
if [ -n "$NODE_BIN" ] && [ -x "$NODE_BIN" ]; then
6064
NODE_VER=$("$NODE_BIN" --version 2>/dev/null || echo "unknown")
61-
pass "Node.js $NODE_VER"
65+
pass "Node.js $NODE_VER ($NODE_BIN)"
6266
else
63-
fail "Node.js not found at $NODE_BIN"
67+
NODE_BIN="$(bb_runtime_node_bin_dir "$BAUDBOT_HOME")/node"
68+
fail "Node.js not found (expected: $NODE_BIN)"
6469
fi
6570

66-
PI_BIN="$BAUDBOT_HOME/opt/node-v22.14.0-linux-x64/bin/pi"
71+
PI_BIN="$(bb_resolve_runtime_node_bin_dir "$BAUDBOT_HOME")/pi"
6772
if [ -x "$PI_BIN" ] || [ -L "$PI_BIN" ]; then
6873
pass "pi is installed"
6974
else
7075
fail "pi not found at $PI_BIN"
7176
fi
7277

78+
if [ -n "${BAUDBOT_ROOT:-}" ] && command -v rg &>/dev/null; then
79+
NODE_PATH_DRIFT="$(rg -n --glob '!node_modules/**' --glob '!.git/**' 'node-v[0-9]+\.[0-9]+\.[0-9]+-linux-x64' "$BAUDBOT_ROOT" || true)"
80+
if [ -n "$NODE_PATH_DRIFT" ]; then
81+
fail "hardcoded versioned Node paths found (run test: bin/runtime-node-paths.test.sh)"
82+
else
83+
pass "runtime Node path references are centralized"
84+
fi
85+
fi
86+
7387
if command -v varlock &>/dev/null || [ -x "$BAUDBOT_HOME/.varlock/bin/varlock" ]; then
7488
pass "varlock is installed"
7589
if [ -f "$BAUDBOT_HOME/.varlock/config.json" ] && grep -q '"anonymousId"' "$BAUDBOT_HOME/.varlock/config.json"; then

bin/lib/baudbot-runtime.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/bin/bash
22
# Runtime/status/session helpers for bin/baudbot.
33

4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
5+
# shellcheck source=bin/lib/runtime-node.sh
6+
source "$SCRIPT_DIR/runtime-node.sh"
7+
48
# Detect systemd
59
has_systemd() {
610
command -v systemctl &>/dev/null && [ -d /run/systemd/system ]
@@ -434,7 +438,9 @@ cmd_attach() {
434438
echo -e " ${GREEN}Agent keeps running under systemd in the background.${RESET}"
435439
echo ""
436440
pause_before_attach
437-
exec sudo -u "$AGENT_USER" bash -lc "export PATH='$AGENT_HOME/.varlock/bin:$AGENT_HOME/opt/node-v22.14.0-linux-x64/bin':\$PATH; cd ~; varlock run --path ~/.config/ -- pi --session '$pi_target'"
441+
local node_bin_dir=""
442+
node_bin_dir="$(bb_resolve_runtime_node_bin_dir "$AGENT_HOME")"
443+
exec sudo -u "$AGENT_USER" bash -lc "export PATH='$AGENT_HOME/.varlock/bin:$node_bin_dir':\$PATH; cd ~; varlock run --path ~/.config/ -- pi --session '$pi_target'"
438444
}
439445

440446
choose_tmux_target() {

0 commit comments

Comments
 (0)