Address Cody review round 6: executable runbook, static client install, README

CODY-011 deploy/install.sh performs the ownership-sensitive sequence: the
         release is copied to app.new, that one directory is given to the
         hermeven user, npm ci runs unprivileged, and the finished tree is
         handed back to root:root with group/other write removed. Secrets,
         state and model directories are never touched. The guide now gives
         exact commands, including the C/C++ toolchain a clean host needs
         (found by running it on one).
CODY-012 install.sh builds the phone page with the bridge address preset
         and installs it root-owned into /opt/hermeven/www for Caddy. The
         guide explains the web build versus the .ehpk package and when
         each is needed.
CODY-013 README states which commit was deployed, what was checked, and
         what remains unverified.

Also corrects a wrong diagnosis recorded in the previous commit: the phone
page that showed "Browser preview" had been opened in Chrome, not in the
Even app. Host detection keeps a short precautionary wait (2.5 s) and its
comments no longer claim an observed Even-app delay.

tests/deploy/runbook-proof.sh proves the guide on a disposable Ubuntu 24.04
host with systemd.

Not reviewed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-21 12:28:07 -08:00
co-authored by Claude Fable 5.2
parent e5559dc5e7
commit 65260911ae
8 changed files with 333 additions and 52 deletions
+10 -6
View File
@@ -7,18 +7,22 @@ Even supplies the microphone, gestures and display. Hermes stays in charge of th
identity, memory, conversation, model, tools and approval rules. Hermeven is the glasses app and a
small bridge between the two.
## Status: first software slice, not yet run on glasses
## Status: deployed to one server; not yet run in the Even app or on glasses
| Path | State |
|---|---|
| Client, bridge and contract | Implemented. |
| Automated tests with fakes (198) | Passing. |
| Automated tests with fakes (205) | Passing. |
| Client in Even's official simulator | Passing (6 scenarios). Simulator only. |
| Bridge against a real Hermes gateway | Passing (9 scenarios) with a **stub model**. |
| Built-in speech-to-text (Whisper, in the bridge) | Passing (11 scenarios) on a real speech recording, including with no network. Not yet on audio from the glasses. |
| Running on a droplet | **Not run.** See `docs/deploy-droplet.md`. |
| Real model, real tools, approval flow | **Not run.** |
| Physical G2, ring, locked-phone use, battery | **Not run.** See `docs/device-test-plan.md`. |
| Running on a droplet | Commit `f02715fb6487f4e2ff0adeccfaad2403e1724aa5` was deployed on 2026-11-21 and received only the bounded server-side checks in `docs/evidence/droplet/2026-11-21.md` (service start, file modes, transcription timing, two typed questions answered by a real model, HTTPS from outside). Later commits are **not deployed**, with one stated exception: the static phone page on that server was rebuilt from later, unreviewed client commits (see the evidence file). |
| Phone page in an ordinary phone browser | Paired and answered one typed question (Chrome on Android, reported by Dan). This is **not** the Even app: a browser cannot reach the glasses. |
| Phone page inside the Even app; physical G2, ring, microphone, display | **Not run.** See `docs/device-test-plan.md`. |
| Locked-phone and background capture | **Not run.** |
| Real tools and approval flow | **Not run.** The two real-model questions used no tools. |
| Sustained load, backups, monitoring, upgrades on the server | **Not verified.** |
| Clean-host install (`deploy/install.sh`) | Proven on a disposable Ubuntu 24.04 container with systemd (`tests/deploy/runbook-proof.sh`), not on a second real server. |
The product's first goal needs the microphone to work while the phone is locked in a pocket.
Even's documentation says capture stops if the app's WebView is suspended. That is the first
@@ -92,7 +96,7 @@ What each suite does and does not show is in `docs/test-evidence.md`.
| `docs/bridge-api.md` | The bridge contract. |
| `docs/security.md` | Threat model, controls, known gaps. |
| `docs/setup.md` | Running, building, operating. |
| `docs/deploy-droplet.md` | Running the bridge on a DigitalOcean droplet. Written, not yet run. |
| `docs/deploy-droplet.md` | Running the bridge on a server. Run once for real (`docs/evidence/droplet/2026-11-21.md`); the current steps are proven on a disposable host. |
| `docs/device-test-plan.md` | The physical-device checklist. Not yet run. |
| `docs/test-evidence.md` | Commands run and their real results. |
| `docs/decisions/` | Decision records. |
+9 -6
View File
@@ -1,11 +1,13 @@
/**
* Decide whether this page is running inside the Even app.
*
* The Even app's WebView provides `window.flutter_inappwebview.callHandler`, but not
* necessarily before the page's own script starts: on a real phone it appeared after our
* module had already run (first device test, 2026-11-21), although the simulator provides it
* at once. So the page waits for it, and also listens for the WebView's own "platform ready"
* event, before concluding it is in an ordinary browser.
* The Even app's WebView provides `window.flutter_inappwebview.callHandler` (per the SDK's
* README). The simulator provides it before the page's script runs. Whether the real Even app
* always does is NOT known: this wait is a precaution, not a fix for an observed problem.
* (It was written on 2026-11-21 after a wrong diagnosis: a page that showed "Browser preview"
* on a phone had simply been opened in Chrome, not in the Even app.) The page waits briefly
* for the host, and listens for the WebView's own "platform ready" event, before concluding
* it is in an ordinary browser.
*/
export interface HostWindow {
flutter_inappwebview?: { callHandler?: unknown };
@@ -19,7 +21,8 @@ export interface HostDetection {
waitedMs: number;
}
export const HOST_WAIT_MS = 6000;
/** Short, because in an ordinary browser this is pure delay before the preview appears. */
export const HOST_WAIT_MS = 2500;
/** The event flutter_inappwebview dispatches on `window` once its JavaScript bridge is usable. */
export const PLATFORM_READY_EVENT = 'flutterInAppWebViewPlatformReady';
+2 -2
View File
@@ -18,8 +18,8 @@ const RELOAD_FLAG = 'hermeven.reloadedForHost';
async function resolveDevice(): Promise<{ device: DevicePort; runtime: string }> {
const host = window as unknown as HostWindow;
// The Even app can provide its connection a moment after the page starts, so wait for it
// rather than deciding on the first instant.
// Wait briefly for the Even app's connection rather than deciding on the first instant
// (a precaution; see device/hostDetect.ts).
const detection = await waitForEvenHost(host);
if (detection.found) {
const bridge = await waitForEvenAppBridge();
+105
View File
@@ -0,0 +1,105 @@
#!/usr/bin/env bash
# Install or update the Hermeven bridge application tree and the static phone page.
#
# Run as root from a checkout (or extracted archive) of the release you want to deploy:
#
# sudo deploy/install.sh --bridge-url https://bridge.example.com
#
# What it does, in order:
# 1. Creates the `hermeven` system user, /opt/hermeven, /etc/hermeven and the 0700 state
# directory /var/lib/hermeven, if they do not exist.
# 2. Copies this checkout to /opt/hermeven/app.new and gives ONLY that directory to `hermeven`.
# 3. Runs `npm ci` there as `hermeven`, so no package install script ever runs as root.
# 4. Builds the phone page with the bridge address preset (also as `hermeven`).
# 5. Gives the finished tree back to root and removes group/other write, so the running
# service cannot modify its own code.
# 6. Installs the built page into /opt/hermeven/www (root-owned, world-readable) for Caddy.
# 7. Swaps the new tree into /opt/hermeven/app (the previous one is kept as app.old) and
# installs the systemd unit. It does not start or restart the service.
#
# What it never touches: /etc/hermeven/* (secrets), /var/lib/hermeven/* (state) and
# /opt/hermeven/models (the verified speech model). No recursive ownership change reaches them.
set -euo pipefail
NODE_BIN=${NODE_BIN:-/opt/node/bin}
PREFIX=/opt/hermeven
BRIDGE_URL=""
SOURCE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
while [ $# -gt 0 ]; do
case "$1" in
--bridge-url) BRIDGE_URL="${2:-}"; shift 2 ;;
--source) SOURCE="$(cd "${2:?}" && pwd)"; shift 2 ;;
-h|--help) sed -n '2,24p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; exit 0 ;;
*) echo "Unknown option: $1" >&2; exit 2 ;;
esac
done
fail() { echo "install.sh: $*" >&2; exit 1; }
[ "$(id -u)" = 0 ] || fail "must be run as root"
[ -x "$NODE_BIN/node" ] || fail "Node.js not found at $NODE_BIN/node (see docs/deploy-droplet.md, step 2)"
command -v make >/dev/null 2>&1 && command -v g++ >/dev/null 2>&1 || fail "a C/C++ toolchain is required (apt-get install -y build-essential python3)"
[ -f "$SOURCE/package-lock.json" ] && [ -d "$SOURCE/services/bridge" ] || fail "$SOURCE is not a Hermeven checkout"
case "$BRIDGE_URL" in
https://*) ;;
"") fail "--bridge-url https://<your-bridge-host> is required (it is built into the phone page)" ;;
*) fail "--bridge-url must start with https://" ;;
esac
export PATH="$NODE_BIN:$PATH"
echo "==> 1/7 user and directories"
id hermeven >/dev/null 2>&1 || useradd --system --home "$PREFIX" --shell /usr/sbin/nologin hermeven
mkdir -p "$PREFIX" /etc/hermeven
install -d -m 0700 -o hermeven -g hermeven /var/lib/hermeven
echo "==> 2/7 copy the release to $PREFIX/app.new"
rm -rf "$PREFIX/app.new"
mkdir "$PREFIX/app.new"
if git -C "$SOURCE" rev-parse --git-dir >/dev/null 2>&1; then
# Exactly the committed files, and a record of which commit this is.
git -C "$SOURCE" archive --format=tar HEAD | tar -x -C "$PREFIX/app.new"
git -C "$SOURCE" rev-parse HEAD > "$PREFIX/app.new/DEPLOYED_SHA"
else
tar -C "$SOURCE" --exclude=./node_modules --exclude='./*/*/node_modules' --exclude=./apps/even-client/dist -cf - . | tar -x -C "$PREFIX/app.new"
fi
# Ownership is handed over for this one directory only.
chown -R hermeven:hermeven "$PREFIX/app.new"
echo "==> 3/7 npm ci as the unprivileged user"
BUILD_HOME="$(mktemp -d)"
chown hermeven:hermeven "$BUILD_HOME"
as_hermeven() { runuser -u hermeven -- env PATH="$PATH" HOME="$BUILD_HOME" npm_config_cache="$BUILD_HOME/npm-cache" "$@"; }
( cd "$PREFIX/app.new" && as_hermeven npm ci --no-audit --no-fund )
echo "==> 4/7 build the phone page for $BRIDGE_URL"
( cd "$PREFIX/app.new" && as_hermeven env VITE_HERMEVEN_BRIDGE_URL="$BRIDGE_URL" npm run --silent client:build )
[ -f "$PREFIX/app.new/apps/even-client/dist/index.html" ] || fail "the client build produced no index.html"
rm -rf "$BUILD_HOME"
echo "==> 5/7 hand the tree back to root"
chown -R root:root "$PREFIX/app.new"
chmod -R go-w "$PREFIX/app.new"
echo "==> 6/7 install the phone page into $PREFIX/www"
rm -rf "$PREFIX/www.new"
mkdir "$PREFIX/www.new"
cp -R "$PREFIX/app.new/apps/even-client/dist/." "$PREFIX/www.new/"
chown -R root:root "$PREFIX/www.new"
find "$PREFIX/www.new" -type d -exec chmod 0755 {} +
find "$PREFIX/www.new" -type f -exec chmod 0644 {} +
rm -rf "$PREFIX/www.old"
[ -d "$PREFIX/www" ] && mv "$PREFIX/www" "$PREFIX/www.old"
mv "$PREFIX/www.new" "$PREFIX/www"
echo "==> 7/7 activate the new tree and install the unit"
rm -rf "$PREFIX/app.old"
[ -d "$PREFIX/app" ] && mv "$PREFIX/app" "$PREFIX/app.old"
mv "$PREFIX/app.new" "$PREFIX/app"
install -m 0644 -o root -g root "$PREFIX/app/deploy/hermeven-bridge.service" /etc/systemd/system/hermeven-bridge.service
command -v systemctl >/dev/null 2>&1 && systemctl daemon-reload || true
echo
echo "Installed $(cat "$PREFIX/app/DEPLOYED_SHA" 2>/dev/null || echo '(no commit recorded)') to $PREFIX/app"
echo "Phone page installed to $PREFIX/www"
echo "Not started. Next: configuration, speech model, then 'systemctl enable --now hermeven-bridge'"
echo "(or 'systemctl restart hermeven-bridge' for an update). See docs/deploy-droplet.md."
+103 -35
View File
@@ -46,30 +46,64 @@ accurate) and run `fetch-model` again.
## Steps
1. **Droplet and DNS.** Ubuntu LTS. Point a hostname at it (for example `bridge.example.com`).
Firewall: allow 22, 80 and 443 only.
2. **Packages.** Node.js 22.13 or later, git, Caddy.
3. **User and directories.**
Every command below is run as root on the server unless it says otherwise. Replace
`bridge.example.com` with your hostname throughout.
1. **Droplet and DNS.** Ubuntu 24.04. Point a hostname at it. Firewall: allow 22, 80 and 443 only.
The bridge (8787) and the Hermes API (8642) stay on loopback and are never opened.
2. **Packages.** Caddy, git and a C/C++ toolchain from Ubuntu, and Node.js 22 from nodejs.org
with its checksum verified, installed at `/opt/node` (where the unit and the install script
expect it). The toolchain is needed because the SQLite library compiles itself during
`npm ci` when no prebuilt binary is fetched for the machine:
```sh
useradd --system --home /opt/hermeven --shell /usr/sbin/nologin hermeven
mkdir -p /opt/hermeven /etc/hermeven
# The state directory is the service user's alone: mode 0700, set explicitly.
install -d -m 0700 -o hermeven -g hermeven /var/lib/hermeven
apt-get update && apt-get install -y caddy git curl xz-utils ca-certificates build-essential python3
V=$(curl -fsSL https://nodejs.org/dist/latest-v22.x/SHASUMS256.txt | grep -oE 'v22\.[0-9]+\.[0-9]+' | head -1)
cd /tmp && curl -fsSLO https://nodejs.org/dist/$V/node-$V-linux-x64.tar.xz
curl -fsSL https://nodejs.org/dist/$V/SHASUMS256.txt | grep " node-$V-linux-x64.tar.xz\$" | sha256sum -c -
mkdir -p /opt/node-$V && tar -xJf node-$V-linux-x64.tar.xz -C /opt/node-$V --strip-components=1
ln -sfn /opt/node-$V /opt/node && /opt/node/bin/node -v
```
The bridge also enforces this itself at every start. The directory that holds the database
must be owned by the user the bridge runs as: if it belongs to anyone else (including root)
the bridge refuses to start and leaves the directory exactly as it found it, even if its
mode is already 0700. If the owner is right but the mode is looser, the bridge sets it to
0700. So `-o hermeven` in the command above matters as much as `-m 0700`.
4. **Code.** Put the repository at `/opt/hermeven/app` (a clone, or `git archive <sha> | tar -x`),
then run `npm ci` there as the unprivileged `hermeven` user and hand the tree back to root
afterwards (`chown -R root:root /opt/hermeven/app`), so package install scripts never run as
root and the running service cannot modify its own code. (The dev dependencies are needed:
the bridge runs through `tsx`.) Node.js is expected at `/opt/node/bin/node`.
5. **Configuration.** Copy `deploy/bridge.env.example` to `/etc/hermeven/bridge.env`, fill it
in, `chmod 600`, `chown hermeven`.
5a. **Speech model.** As root (not the service user), fetch and verify the pinned model into a
directory the service can read but not write:
3. **Get the release onto the server**, anywhere outside `/opt/hermeven`, for example:
```sh
git clone git@git.xylo.gg:Xylo-Digital/hermeven.git /root/hermeven-src
git -C /root/hermeven-src checkout <the commit you are deploying>
```
(or, from your own machine: `git archive <sha> | ssh root@server 'mkdir -p /root/hermeven-src && tar -x -C /root/hermeven-src'`).
4. **Install the application and the phone page.** One script does the ownership-sensitive part,
so it cannot be done in the wrong order:
```sh
/root/hermeven-src/deploy/install.sh --bridge-url https://bridge.example.com
```
In order, it: creates the `hermeven` system user, `/opt/hermeven`, `/etc/hermeven` and the
state directory (`install -d -m 0700 -o hermeven -g hermeven /var/lib/hermeven`); copies the
release to `/opt/hermeven/app.new` and **gives that one directory to `hermeven`**; runs
`npm ci` **as `hermeven`**, so no package install script runs as root; builds the phone page
with your bridge address preset; **gives the finished tree back to `root:root`** and removes
group/other write, so the running service cannot change its own code; installs the built page
into `/opt/hermeven/www` (root-owned, directories 0755, files 0644, readable by Caddy and not
writable by the service); swaps the tree into `/opt/hermeven/app` (keeping the previous one as
`app.old`); and installs the systemd unit without starting it.
It never touches `/etc/hermeven/*` (secrets), `/var/lib/hermeven/*` (state) or
`/opt/hermeven/models` (the speech model); no recursive ownership change reaches them.
The state directory must be owned by the user the bridge runs as. The bridge checks this at
every start: a directory owned by anyone else (including root) is refused and left exactly
as found, even at mode 0700; with the right owner and a looser mode it is set to 0700.
The dev dependencies are installed too: the bridge runs through `tsx`.
5. **Configuration.**
```sh
install -m 0600 -o hermeven -g hermeven /opt/hermeven/app/deploy/bridge.env.example /etc/hermeven/bridge.env
```
Then edit `/etc/hermeven/bridge.env`: set `HERMES_API_KEY` at least.
6. **Speech model.** Fetch and verify the pinned model, as root, into a directory the service can
read but not write:
```sh
cd /opt/hermeven/app/services/bridge
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env /opt/node/bin/node --import tsx src/cli.ts fetch-model
@@ -79,24 +113,58 @@ accurate) and run `fetch-model` again.
service never downloads anything: it re-verifies these files each time it loads the model and
refuses to load if one is missing or different. This is the only step that needs outbound
access to huggingface.co.
6. **Hermes.** Enable its API server with a key, bound to `127.0.0.1`. Use a read-only or test
profile first.
7. **Service.** Copy `deploy/hermeven-bridge.service` to `/etc/systemd/system/`, then
`systemctl daemon-reload && systemctl enable --now hermeven-bridge`. Watch
`journalctl -u hermeven-bridge -f` for `stt.ready`. `stt.load_failed` with `reason: missing`
or `mismatch` means step 5a was skipped or the files changed.
8. **TLS.** Put `deploy/Caddyfile.example` at `/etc/caddy/Caddyfile` with your hostname, reload
Caddy, then check `curl https://bridge.example.com/healthz`.
9. **App build.** On your own machine:
`HERMEVEN_BRIDGE_ORIGIN=https://bridge.example.com npm run -w @hermeven/even-client pack`.
10. **Pair.** On the droplet, as the service user with the same environment:
7. **Hermes.** Enable its API server with a key, bound to `127.0.0.1` (see `docs/setup.md`), and
put the same key in `bridge.env`. Use a read-only or test profile first.
8. **Start the bridge.**
```sh
systemctl enable --now hermeven-bridge
journalctl -u hermeven-bridge -f # wait for "stt.ready"
curl http://127.0.0.1:8787/healthz
```
`stt.load_failed` with `reason: missing` or `mismatch` means step 6 was skipped or the files
changed.
9. **HTTPS.** Put `deploy/Caddyfile.example` at `/etc/caddy/Caddyfile` with your hostname, then:
```sh
caddy validate --config /etc/caddy/Caddyfile && systemctl reload caddy
curl https://bridge.example.com/healthz # the bridge, through Caddy
curl -I https://bridge.example.com/ # the phone page: 200, text/html
```
Caddy sends `/v1/*` and `/healthz` to the bridge and serves everything else from
`/opt/hermeven/www`.
10. **Pair.** As the service user:
```sh
cd /opt/hermeven/app/services/bridge
runuser -u hermeven -- env HOME=/var/lib/hermeven HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env \
/opt/node/bin/node --import tsx src/cli.ts pair
```
11. **Origin.** Open the phone page, read Diagnostics, "Page origin", put it in
`HERMEVEN_ALLOWED_ORIGINS`, restart the service.
Open `https://bridge.example.com/` in the Even app (see below) and enter the code.
11. **Allowed origins.** Leave `HERMEVEN_ALLOWED_ORIGINS` empty when the phone page is served
from the bridge's own hostname, as above: the page and the API share one origin, so no
cross-origin allowance is needed and none should be added. Only a page served from somewhere
else (a packaged `.ehpk`, whose origin inside the Even app is not documented) needs its exact
origin listed; read it from Diagnostics, "Page origin".
**Updating.** Repeat steps 3 and 4 with the new commit, then `systemctl restart hermeven-bridge`.
If a model manifest changed, repeat step 6 first.
## The two client artifacts: the web page and the `.ehpk`
Both come from the same source (`apps/even-client`) and you need only one of them at a time.
| Artifact | Made by | Lives | Used for |
|---|---|---|---|
| Web build (`dist/`) | `deploy/install.sh` on the server (`npm run client:build`) | `/opt/hermeven/www`, served by Caddy at `https://bridge.example.com/` | Loading Hermeven in the Even app by scanning a QR code for that address (`npx evenhub qr --url https://bridge.example.com`). This is the developer sideload path: nothing is uploaded to Even. Even's documentation says sideloaded apps stop when the phone locks. |
| Package (`hermeven.ehpk`) | `HERMEVEN_BRIDGE_ORIGIN=https://bridge.example.com npm run -w @hermeven/even-client pack`, on your own machine | Uploaded to Even's portal by you (`evenhub create` / `upload`, then `promote --to beta`) | Installing Hermeven as a real app (beta channel), which is what the locked-phone test needs. The package carries its own copy of the page, with the bridge origin in its network whitelist; it does not use `/opt/hermeven/www`. |
For a first run on the glasses only the web build is needed, and the install script has already
produced it. The `.ehpk` is needed only when you move to a beta-channel install. Keeping the web
page in place afterwards is harmless (it is static and holds no secrets) and useful for
diagnostics, but a server that only serves packaged apps does not need it.
## Things to check on the droplet and write down
+8
View File
@@ -0,0 +1,8 @@
# Disposable Ubuntu 24.04 host with systemd as PID 1, for proving docs/deploy-droplet.md.
# Only the operating system and systemd are prepared here. Everything the guide tells the
# operator to install (Caddy, git, Node.js, Hermeven) is installed by the proof script.
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update -qq && apt-get install -y -qq systemd systemd-sysv dbus >/dev/null && apt-get clean
STOPSIGNAL SIGRTMIN+3
CMD ["/sbin/init"]
+93
View File
@@ -0,0 +1,93 @@
#!/usr/bin/env bash
# Proves the server-side steps of docs/deploy-droplet.md on a disposable Ubuntu 24.04 host
# (a privileged Docker container running systemd). Opt-in: needs Docker and network access.
#
# tests/deploy/runbook-proof.sh
#
# It deploys the CURRENT COMMIT (HEAD), from an empty /opt/hermeven, by running the commands
# the guide gives. Hermes is not present in the container, so the bridge starts with the agent
# unreachable; that is expected and is not what this proves.
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/../.."
NAME=hermeven-runbook-proof
IMAGE=hermeven-runbook-host:24.04
SHA=$(git rev-parse HEAD)
[ -z "$(git status --porcelain)" ] || { echo "Commit or stash changes first: the proof deploys HEAD." >&2; exit 1; }
cleanup() { docker rm -f "$NAME" >/dev/null 2>&1 || true; rm -f "$BUNDLE"; }
BUNDLE=$(mktemp --suffix=.bundle)
trap cleanup EXIT
docker rm -f "$NAME" >/dev/null 2>&1 || true
echo "### host image"
docker build -q -t "$IMAGE" tests/deploy >/dev/null
docker run -d --name "$NAME" --privileged --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw --tmpfs /run --tmpfs /run/lock "$IMAGE" >/dev/null
for _ in $(seq 1 30); do docker exec "$NAME" systemctl is-system-running 2>/dev/null | grep -qE 'running|degraded' && break; sleep 1; done
in_host() { docker exec -i "$NAME" bash -euo pipefail -c "$1"; }
in_host '. /etc/os-release; echo "$PRETTY_NAME"; test ! -e /opt/hermeven && echo "/opt/hermeven does not exist"; id hermeven 2>&1 | head -1 || true'
echo "### step 2: packages (Caddy, git, Node.js with checksum)"
in_host 'export DEBIAN_FRONTEND=noninteractive
apt-get update -qq >/dev/null && apt-get install -y -qq caddy git curl xz-utils ca-certificates build-essential python3 >/dev/null 2>&1
V=$(curl -fsSL https://nodejs.org/dist/latest-v22.x/SHASUMS256.txt | grep -oE "v22\.[0-9]+\.[0-9]+" | head -1)
cd /tmp && curl -fsSLO https://nodejs.org/dist/$V/node-$V-linux-x64.tar.xz
curl -fsSL https://nodejs.org/dist/$V/SHASUMS256.txt | grep " node-$V-linux-x64.tar.xz\$" | sha256sum -c -
mkdir -p /opt/node-$V && tar -xJf node-$V-linux-x64.tar.xz -C /opt/node-$V --strip-components=1
ln -sfn /opt/node-$V /opt/node && /opt/node/bin/node -v
caddy version | head -1'
echo "### step 3: get the release onto the server (git clone of $SHA)"
git bundle create "$BUNDLE" HEAD >/dev/null 2>&1
docker cp "$BUNDLE" "$NAME":/root/release.bundle
in_host "git clone -q /root/release.bundle /root/hermeven-src 2>/dev/null && git -C /root/hermeven-src checkout -q $SHA && git -C /root/hermeven-src rev-parse HEAD"
echo "### step 4: deploy/install.sh"
in_host '/root/hermeven-src/deploy/install.sh --bridge-url https://localhost >/tmp/install.log 2>&1 || { echo "install.sh FAILED:"; tail -25 /tmp/install.log; exit 1; }; grep -E "^==>|^Installed|^Phone page|^Not started" /tmp/install.log'
echo "### ownership and permissions after install"
in_host 'echo "DEPLOYED_SHA: $(cat /opt/hermeven/app/DEPLOYED_SHA)"
echo "app tree owner: $(stat -c "%U:%G %a" /opt/hermeven/app)"
echo "not root-owned in app: $(find /opt/hermeven/app ! -user root | wc -l) group/other-writable in app: $(find /opt/hermeven/app -perm /022 ! -type l | wc -l)"
echo "node_modules present: $(test -d /opt/hermeven/app/node_modules && echo yes)"
runuser -u hermeven -- test -w /opt/hermeven/app && echo "hermeven CAN write app (BAD)" || echo "hermeven cannot write the app tree"
runuser -u hermeven -- sh -c "touch /opt/hermeven/app/services/bridge/src/x 2>/dev/null" && echo "hermeven CAN create files in src (BAD)" || echo "hermeven cannot create files in the source"
echo "www: $(stat -c "%U:%G %a" /opt/hermeven/www) index $(stat -c "%U %a" /opt/hermeven/www/index.html) files=$(find /opt/hermeven/www -type f | wc -l)"
runuser -u hermeven -- test -w /opt/hermeven/www && echo "hermeven CAN write www (BAD)" || echo "hermeven cannot write www"
runuser -u caddy -- test -r /opt/hermeven/www/index.html && echo "caddy can read www"
echo "state dir: $(stat -c "%U:%G %a" /var/lib/hermeven)"
echo "secrets dir entries: $(ls -A /etc/hermeven | wc -l) (install.sh wrote none)"
echo "models dir: $(test -e /opt/hermeven/models && echo exists || echo "not created by install.sh")"'
echo "### steps 5, 6: configuration and speech model"
in_host 'install -m 0600 -o hermeven -g hermeven /opt/hermeven/app/deploy/bridge.env.example /etc/hermeven/bridge.env
sed -i "s/^HERMES_API_KEY=.*/HERMES_API_KEY=proof-run-not-a-real-key/" /etc/hermeven/bridge.env
stat -c "%U:%G %a %n" /etc/hermeven/bridge.env
cd /opt/hermeven/app/services/bridge
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env /opt/node/bin/node --import tsx src/cli.ts fetch-model | tail -1
HERMEVEN_ENV_FILE=/etc/hermeven/bridge.env /opt/node/bin/node --import tsx src/cli.ts verify-model | tail -1
echo "models owner: $(stat -c "%U:%G" /opt/hermeven/models)"'
echo "### step 8: start the bridge under systemd"
in_host 'systemd-analyze verify /etc/systemd/system/hermeven-bridge.service && echo "systemd-analyze verify: ok"
systemctl enable --now hermeven-bridge 2>/dev/null
for _ in $(seq 1 60); do journalctl -u hermeven-bridge --no-pager 2>/dev/null | grep -q "stt.ready\|stt.load_failed" && break; sleep 1; done
echo "unit: $(systemctl is-active hermeven-bridge) (running as $(systemctl show hermeven-bridge -p User --value), MainPID uid $(stat -c %U /proc/$(systemctl show hermeven-bridge -p MainPID --value)))"
journalctl -u hermeven-bridge --no-pager | grep -oE "\"msg\":\"(Server listening[^\"]*|stt\.[a-z_]+)\"|\"reason\":\"[a-z]+\"" | tr "\n" " "; echo
echo "healthz (direct): $(curl -sS -m 5 http://127.0.0.1:8787/healthz)"
echo "state files: $(stat -c "%a" /var/lib/hermeven) $(stat -c "%U %a %n" /var/lib/hermeven/* | tr "\n" ";")"'
echo "### step 9: HTTPS through Caddy (hostname replaced by localhost; certificate from Caddy's local CA)"
in_host 'caddy fmt --diff /opt/hermeven/app/deploy/Caddyfile.example >/tmp/fmt.diff 2>&1; echo "caddy fmt --diff on the example: exit $?, $(grep -cE "^[-+]" /tmp/fmt.diff || true) changed line(s)"
sed "s/^bridge\.example\.com {/localhost {/" /opt/hermeven/app/deploy/Caddyfile.example > /etc/caddy/Caddyfile
caddy validate --config /etc/caddy/Caddyfile 2>&1 | tail -1
systemctl restart caddy; sleep 4; echo "caddy: $(systemctl is-active caddy)"
ASSET=$(curl -sSk https://localhost/ | grep -oE "assets/index-[A-Za-z0-9_-]+\.js" | head -1)
echo "GET / -> $(curl -sSk -o /dev/null -w "%{http_code} %{content_type}" https://localhost/)"
echo "GET /$ASSET -> $(curl -sSk -o /dev/null -w "%{http_code} %{content_type} %{size_download} bytes" https://localhost/$ASSET)"
echo "GET /healthz -> $(curl -sSk https://localhost/healthz)"
echo "GET /v1/device -> $(curl -sSk -o /dev/null -w "%{http_code}" https://localhost/v1/device) (no credential)"
echo "headers on /:"; curl -sSkI https://localhost/ | grep -iE "^(strict-transport-security|x-content-type-options|referrer-policy|server):" | sed "s/^/ /"
echo "headers on the asset:"; curl -sSkI https://localhost/$ASSET | grep -iE "^(strict-transport-security|x-content-type-options|referrer-policy|server):" | sed "s/^/ /"
echo "bridge address built into the page: $(grep -c "https://localhost" /opt/hermeven/www/$ASSET) occurrence(s) of https://localhost"
echo "CORS for a foreign origin: $(curl -sSkI -H "Origin: https://evil.example" https://localhost/v1/device | grep -ci "^access-control-allow-origin" || true) allow-origin header(s)"'
echo "### done: $SHA"
+3 -3
View File
@@ -2,8 +2,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { HOST_WAIT_MS, PLATFORM_READY_EVENT, waitForEvenHost, watchForLateHost, type HostWindow } from '../../apps/even-client/src/device/hostDetect.ts';
/**
* Found on the first real-phone run (2026-11-21): the Even app's connection was not yet on
* `window` when the page's script started, and the page wrongly chose browser-preview mode.
* Host detection waits briefly for the Even app's connection instead of deciding on the first
* instant. This is a precaution: no real phone has yet been observed providing it late.
*/
function fakeWindow() {
const listeners = new Map<string, Set<() => void>>();
@@ -28,7 +28,7 @@ describe('detecting the Even app host', () => {
expect(win.listenerCount()).toBe(0);
});
it('appears shortly after the page starts (the real phone): found, not mistaken for a browser', async () => {
it('appears shortly after the page starts: found, not mistaken for a browser', async () => {
const win = fakeWindow();
const detecting = waitForEvenHost(win);
await vi.advanceTimersByTimeAsync(800);