clawdie-ai/scripts/bhyve-evidence.sh
Operator & Claude Code 75009dcb7f refactor(identity): remove PLATFORM_ID/SERVICE_NAME/RUNTIME_USER env vars
Step 5 of system-namespace cutover: complete the env-var removal that
step 4 set up. All consumers now import SERVICE_NAME from
src/platform-identity.ts directly; the deprecated PLATFORM_*
re-exports in src/config.ts are gone.

src/config.ts:
- PLATFORM_ID, PLATFORM_SERVICE_NAME, PLATFORM_RUNTIME_USER exports
  removed.
- PLATFORM_RUNTIME_HOME stays (derived from SERVICE_NAME, used by
  ~10 consumers for path construction).
- Env-var allowlist drops PLATFORM_ID / PLATFORM_SERVICE_NAME /
  PLATFORM_RUNTIME_USER / PLATFORM_RUNTIME_HOME entries.
- CONTROLPLANE_AIDER_TMUX_SESSION uses SERVICE_NAME directly.

setup/onboarding.ts:
- writeIdentity() simplified to write only ASSISTANT_NAME (display).
  PLATFORM_ID / PLATFORM_SERVICE_NAME / PLATFORM_RUNTIME_USER are no
  longer written to .env. Fresh installs have no PLATFORM_* keys.
- Status emission switched from PLATFORM_ID to SERVICE_NAME.

setup/env-audit.ts:
- Audit lists SERVICE_NAME instead of PLATFORM_ID; the env-file
  PLATFORM_ID read is gone.

24 source files (src/*.ts, setup/*.ts, scripts/dashboard.ts):
- Bare PLATFORM_ID / PLATFORM_SERVICE_NAME / PLATFORM_RUNTIME_USER
  references replaced with SERVICE_NAME.
- Imports rewired: SERVICE_NAME comes from
  ../{src/}platform-identity.js, not from config.js.
- Imports deduped where the sed sweep produced collisions.

Shell scripts (scripts/bhyve-evidence.sh, glass.sh, inspect-system.sh):
- Hardcoded SERVICE_NAME='clawdie' and SERVICE_USER='clawdie'.
  No more grep-the-.env fallbacks; the constants are the source.

Tests (middle path):
- Mechanical fixes (import path, renamed assertion text):
  src/hostd/privileged-commands.test.ts, src/startup-report.test.ts,
  setup/env-audit.test.ts, setup/install-mode.test.ts.
- Skipped with `// system-namespace:` markers (pinned removed
  env-driven override behavior; Codex rewrites once the bootstrap-
  config service-user override path lands):
    setup/verify.test.ts > 'uses the platform service name for PID candidates'
    setup/service.test.ts > 'resolves a platform runtime separately from the tenant'

Test files still containing PLATFORM_* strings in vi.mock contents,
ENV_KEYS arrays, or comments are left untouched — they are test
artifacts that don't affect runtime; mock contents resolve to
'clawdie' which still equals SERVICE_NAME.

tsc clean. 2095 tests pass, 4 skipped, 0 fail.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

---
Build: pass | Tests: pass — Tests  2095 passed | 4 skipped (2099)
2026-05-02 14:49:19 +02:00

113 lines
3.7 KiB
Bash
Executable file

#!/usr/bin/env bash
# bhyve-evidence.sh — Collect deployment evidence from inside a bhyve guest.
# Runs preflight, tsc check, and screenshot capture, then emits a single
# JSON bundle to stdout. Designed to be copy-pasted to another agent.
#
# Usage:
# sudo bash scripts/bhyve-evidence.sh # full run
# sudo bash scripts/bhyve-evidence.sh --quick # skip preflight (tsc + screenshot only)
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
if [ -f "$PROJECT_DIR/.env" ]; then
set -a
# shellcheck disable=SC1091
. "$PROJECT_DIR/.env"
set +a
fi
TENANT_ID="${TENANT_ID:-clawdie}"
# Service name is the constant 'clawdie' baked into code (see
# src/platform-identity.ts). PLATFORM_* env vars are removed.
SERVICE_NAME="clawdie"
TIMESTAMP="$(date -u '+%Y-%m-%dT%H:%M:%SZ')"
HOSTNAME="$(hostname)"
QUICK=false
for arg in "$@"; do
[ "$arg" = "--quick" ] && QUICK=true
done
# ── 1. Preflight ────────────────────────────────────────────────────────────
PREFLIGHT_STATUS="skipped"
PREFLIGHT_JSON="{}"
if [ "$QUICK" = false ]; then
echo "==> Running preflight..." >&2
cd "$PROJECT_DIR"
if npm run preflight-check 2>&1 | tee "$PROJECT_DIR/logs/preflight-latest.log" >&2; then
PREFLIGHT_STATUS="pass"
else
PREFLIGHT_STATUS="fail"
fi
# Find the most recent summary.json (preflight writes to tmp/preflight/)
SUMMARY="$(ls -t "$PROJECT_DIR"/tmp/preflight/*/summary.json 2>/dev/null | head -1)"
if [ -n "$SUMMARY" ]; then
PREFLIGHT_JSON="$(cat "$SUMMARY")"
fi
fi
# ── 2. TypeScript compile check ─────────────────────────────────────────────
echo "==> Running tsc --noEmit..." >&2
cd "$PROJECT_DIR"
if npx tsc --noEmit 2>&1 >&2; then
TSC_STATUS="pass"
else
TSC_STATUS="fail"
fi
# ── 3. Screenshot capture ───────────────────────────────────────────────────
SCREENSHOT_JSON="{}"
SCREENSHOT_STATUS="skipped"
SCREENSHOT_SCRIPT="$PROJECT_DIR/.agent/skills/tmux-screenshot/tmux-screenshot.py"
if [ -f "$SCREENSHOT_SCRIPT" ] && command -v python3 >/dev/null 2>&1; then
echo "==> Capturing screenshot..." >&2
CAPTURE_OUTPUT="$(python3 "$SCREENSHOT_SCRIPT" \
--session "$SERVICE_NAME" \
--publish 2>&1)" || true
# Extract the per-capture JSON if it exists
CAPTURE_DIR="$PROJECT_DIR/tmp/screenshots"
LATEST_JSON="$(ls -t "$CAPTURE_DIR"/*.json 2>/dev/null | grep -v manifest | head -1)"
if [ -n "$LATEST_JSON" ]; then
SCREENSHOT_JSON="$(cat "$LATEST_JSON")"
SCREENSHOT_STATUS="pass"
else
SCREENSHOT_STATUS="fail"
fi
else
echo "WARN: screenshot script or python3 not found, skipping" >&2
fi
# ── 4. Emit bundle ──────────────────────────────────────────────────────────
cat <<ENDJSON
{
"evidence_version": 1,
"tenant_id": "${TENANT_ID}",
"hostname": "${HOSTNAME}",
"collected_at": "${TIMESTAMP}",
"codebase_version": "$(grep '"version"' "$PROJECT_DIR/package.json" | head -1 | sed 's/.*: *"//;s/".*//')",
"checks": {
"preflight": {
"status": "${PREFLIGHT_STATUS}",
"summary": ${PREFLIGHT_JSON}
},
"tsc": {
"status": "${TSC_STATUS}"
},
"screenshot": {
"status": "${SCREENSHOT_STATUS}",
"capture": ${SCREENSHOT_JSON}
}
}
}
ENDJSON