Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
feat(installer): daily auto-update timer + version surfaced to the phone
enesc176723cfc40
diff --git a/docs/SERVER.md b/docs/SERVER.mdindex 8af20157d..bbbfb81f0 100644--- a/docs/SERVER.md+++ b/docs/SERVER.md@@ -101,10 +101,49 @@ The installer (`scripts/install-server.sh`) is idempotent — re-run it any timeserver bundle;- installs a **systemd** service (`NODETERM_HEADLESS=1`, `Restart=on-failure`, journald logs):a system unit at `/etc/systemd/system/nodeterm-server.service` when run as root, or a- per-user unit + `loginctl enable-linger` otherwise — then enables and (re)starts it.+ per-user unit + `loginctl enable-linger` otherwise — then enables and (re)starts it;+- writes **`<data-dir>/install-meta.json`** (`{version, commit, installedAt}`, where `<data-dir>`+ defaults to `~/.nodeterm-server`). The server reads it at boot and surfaces it to a paired phone+ through the agent-status mirror's top-level `server` block, so a connection can show which version+ this install is on — the answer to "how does an installed Server Edition learn about updates?";+- installs a **daily auto-update timer** (unless you opt out — see below).Follow the logs with `journalctl -u nodeterm-server -f` (add `--user` for a non-root install).+### Auto-update++The installer also installs a `nodeterm-server-update.service` (a `oneshot`) plus a+`nodeterm-server-update.timer` (`OnCalendar=daily`, `RandomizedDelaySec=3600`, `Persistent=true`),+with the **same root/user split** as the main service (a system unit under+`/etc/systemd/system/`, or a per-user unit under `~/.config/systemd/user/`). When it fires, the+service:++1. `git pull --ff-only` in `~/.nodeterm-server-app` — updating the checkout **including this+ updater script**, so the updater logic keeps itself current;+2. re-execs the freshly-pulled `scripts/install-server.sh`, which rebuilds and restarts the+ service. The installer is idempotent, so an already-current pull just no-ops through a harmless+ rebuild.++**Opt out:** run the installer with `NODETERM_NO_AUTOUPDATE=1` — it skips the timer, and (so a+re-run can turn auto-update off) **removes an existing** timer/service. The installer prints the+timer status (`systemctl list-timers`) in its summary so you can confirm the next run.++Check or trigger it manually:++```bash+systemctl list-timers nodeterm-server-update.timer # add --user for a non-root install+systemctl start nodeterm-server-update.service # run an update now+```++### Per-user installs (one per Unix user)++An install covers **only the Unix user it runs as** — its systemd unit, `~/.nodeterm-server-app`+checkout, and `~/.nodeterm-server` data dir are that user's. A box with several server users+(`root`, `customerservice`, …) needs **one install per user**; the phone offers this per+connection (it installs under whichever user its SSH session logs in as). Non-root installs rely on+`loginctl enable-linger <user>` (the installer runs it) so the user's systemd manager — and thus+both the service and the auto-update timer — keep running without an active login session.+### `NODETERM_HEADLESS`Set `NODETERM_HEADLESS=1` (also accepts `true`, case-insensitive) to boot in headless mode.diff --git a/scripts/install-server.sh b/scripts/install-server.shindex f7079eff7..c7decb624 100755--- a/scripts/install-server.sh+++ b/scripts/install-server.sh@@ -15,7 +15,13 @@ set -euo pipefailREPO_URL="${NODETERM_REPO_URL:-https://github.com/eneskirca/nodeterm}"APP_DIR="${NODETERM_APP_DIR:-$HOME/.nodeterm-server-app}"+# Where the running server keeps its state (auth, sessions, workspace, scrollback). Matches the+# server's own default (src/server/config.ts) so the install-meta.json we write below lands where+# the server reads it. Override with NODETERM_DATA_DIR (mirror the same override into the service if+# you use one).+DATA_DIR="${NODETERM_DATA_DIR:-$HOME/.nodeterm-server}"SERVICE_NAME="nodeterm-server"+UPDATE_SERVICE_NAME="nodeterm-server-update"MIN_NODE_MAJOR=20# When the system Node is missing or too old we provision this pinned LTS privately (see ensure_node).# v22.14.0 is a Node 22 "Jod" LTS release. Override with NODETERM_NODE_VERSION for a different pin.@@ -172,6 +178,28 @@ npm rebuild node-pty[ -f "$APP_DIR/out/server/main.cjs" ] || fail "Build did not produce out/server/main.cjs — check the output above."+# ---- install metadata (surfaced to the phone via the agent-status mirror's `server` block) -----+# The server reads <DATA_DIR>/install-meta.json at boot (src/server/index.ts readInstallMeta) and+# advertises {version, commit, installedAt} to a paired phone, so a connection can show which+# version this install is on. Written only after a successful build above.+write_install_meta() {+ local meta_file commit version now+ meta_file="$DATA_DIR/install-meta.json"+ commit="$(git -C "$APP_DIR" rev-parse --short HEAD 2>/dev/null || echo unknown)"+ version="$("$NODE_BIN" -p "require('$APP_DIR/package.json').version" 2>/dev/null || echo 0.0.0)"+ now="$(date -u +%Y-%m-%dT%H:%M:%SZ)"+ mkdir -p "$DATA_DIR"+ cat > "$meta_file" <<META+{+ "commit": "$commit",+ "installedAt": "$now",+ "version": "$version"+}+META+ ok "Wrote install metadata to $meta_file (commit $commit, v$version)"+}+write_install_meta+# ---- install + (re)start the systemd service -------------------------------------------------UNIT_DESC="nodeterm headless notification host"@@ -197,6 +225,42 @@ WantedBy=$2UNIT}+# ---- auto-update: a oneshot service + daily timer --------------------------------------------+# The timer fires the oneshot service ~daily (randomized). The service pulls the latest code and+# then RE-EXECS the freshly-pulled install-server.sh — so the updater logic updates itself. The+# installer is idempotent, so a no-op pull (already current) is harmless. Opt out with+# NODETERM_NO_AUTOUPDATE=1 (see the branches below), which also removes an existing timer.+write_update_units() {+ # $1 = target unit directory (system-wide or per-user)+ cat > "$1/${UPDATE_SERVICE_NAME}.service" <<UNIT+[Unit]+Description=$UNIT_DESC — auto-update+After=network-online.target+Wants=network-online.target++[Service]+Type=oneshot+WorkingDirectory=$APP_DIR+# git pull to update the checkout (incl. THIS updater script), then re-exec the pulled installer,+# which rebuilds and restarts the service. Absolute paths are baked in at write time.+ExecStart=/bin/sh -c 'cd "$APP_DIR" && git pull --ff-only && exec bash "$APP_DIR/scripts/install-server.sh"'+UNIT+ cat > "$1/${UPDATE_SERVICE_NAME}.timer" <<UNIT+[Unit]+Description=$UNIT_DESC — daily auto-update check++[Timer]+OnCalendar=daily+# Spread the load off exactly-midnight and de-sync fleets.+RandomizedDelaySec=3600+# Catch up a run missed while the host was off.+Persistent=true++[Install]+WantedBy=timers.target+UNIT+}+if [ "$(id -u)" = "0" ]; then# Root install: system-wide unit.UNIT_PATH="/etc/systemd/system/${SERVICE_NAME}.service"@@ -206,11 +270,27 @@ if [ "$(id -u)" = "0" ]; thensystemctl enable "$SERVICE_NAME"systemctl restart "$SERVICE_NAME"ok "Service installed and (re)started."++ # Auto-update timer (system-wide). Opt out with NODETERM_NO_AUTOUPDATE=1, which also removes an+ # existing timer so a re-run can turn auto-update off.+ UPDATE_UNIT_DIR="/etc/systemd/system"+ if [ -n "${NODETERM_NO_AUTOUPDATE:-}" ]; then+ systemctl disable --now "${UPDATE_SERVICE_NAME}.timer" >/dev/null 2>&1 || true+ rm -f "$UPDATE_UNIT_DIR/${UPDATE_SERVICE_NAME}.service" "$UPDATE_UNIT_DIR/${UPDATE_SERVICE_NAME}.timer"+ systemctl daemon-reload+ info "Auto-update disabled (NODETERM_NO_AUTOUPDATE set)."+ else+ write_update_units "$UPDATE_UNIT_DIR"+ systemctl daemon-reload+ systemctl enable --now "${UPDATE_SERVICE_NAME}.timer"+ ok "Auto-update timer installed (daily; opt out with NODETERM_NO_AUTOUPDATE=1)."+ fiechosystemctl --no-pager status "$SERVICE_NAME" || trueecho+ [ -z "${NODETERM_NO_AUTOUPDATE:-}" ] && { systemctl --no-pager list-timers "${UPDATE_SERVICE_NAME}.timer" || true; echo; }info "Logs: journalctl -u $SERVICE_NAME -f"- info "Update: re-run this script."+ info "Update: automatic (daily timer) or re-run this script."else# Non-root install: per-user unit + linger so it runs without an active login session.command -v systemctl >/dev/null 2>&1 || fail "systemctl not found — a systemd host is required for the service. (You can still run it manually: NODETERM_HEADLESS=1 node $APP_DIR/out/server/main.cjs)"@@ -225,11 +305,26 @@ elsesystemctl --user enable "$SERVICE_NAME"systemctl --user restart "$SERVICE_NAME"ok "Service installed and (re)started."++ # Auto-update timer (per-user). Linger (enabled above) keeps the user manager running so the+ # timer fires without an active login. Opt out with NODETERM_NO_AUTOUPDATE=1.+ if [ -n "${NODETERM_NO_AUTOUPDATE:-}" ]; then+ systemctl --user disable --now "${UPDATE_SERVICE_NAME}.timer" >/dev/null 2>&1 || true+ rm -f "$UNIT_DIR/${UPDATE_SERVICE_NAME}.service" "$UNIT_DIR/${UPDATE_SERVICE_NAME}.timer"+ systemctl --user daemon-reload+ info "Auto-update disabled (NODETERM_NO_AUTOUPDATE set)."+ else+ write_update_units "$UNIT_DIR"+ systemctl --user daemon-reload+ systemctl --user enable --now "${UPDATE_SERVICE_NAME}.timer"+ ok "Auto-update timer installed (daily; opt out with NODETERM_NO_AUTOUPDATE=1)."+ fiechosystemctl --user --no-pager status "$SERVICE_NAME" || trueecho+ [ -z "${NODETERM_NO_AUTOUPDATE:-}" ] && { systemctl --user --no-pager list-timers "${UPDATE_SERVICE_NAME}.timer" || true; echo; }info "Logs: journalctl --user -u $SERVICE_NAME -f"- info "Update: re-run this script."+ info "Update: automatic (daily timer) or re-run this script."fiechodiff --git a/src/core/agent-status-mirror.test.ts b/src/core/agent-status-mirror.test.tsindex 2c9d8f018..8d2ffeb5a 100644--- a/src/core/agent-status-mirror.test.ts+++ b/src/core/agent-status-mirror.test.ts@@ -17,6 +17,7 @@ import {flush,initAgentStatusMirror,setMirrorSettingsProvider,+ setMirrorServerProvider,setMirrorUsageProvider,buildMirrorUsage,toolActivity,@@ -302,6 +303,73 @@ describe('settings block', () => {})})+// ---- server-update (install metadata block) -------------------------------------------------++describe('server block', () => {+ let tmpDir: string++ beforeEach(() => {+ _resetForTest()+ tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-status-'))+ })++ afterEach(() => {+ _resetForTest()+ fs.rmSync(tmpDir, { recursive: true, force: true })+ })++ it('buildFile includes the server block when given one', () => {+ const doc = buildFile({}, 1000, undefined, undefined, undefined, undefined, {+ version: '0.2.17',+ commit: '1e56f83',+ installedAt: '2026-07-23T00:00:00Z'+ })+ expect(doc.server).toEqual({+ version: '0.2.17',+ commit: '1e56f83',+ installedAt: '2026-07-23T00:00:00Z'+ })+ })++ it('buildFile omits the server key entirely when none given (old-file shape)', () => {+ expect('server' in buildFile({}, 1000)).toBe(false)+ // An all-empty block is also omitted (nothing worth advertising).+ expect('server' in buildFile({}, 1000, undefined, undefined, undefined, undefined, {})).toBe(false)+ })++ it('filterMirrorForNodes drops the server block from slices (host-local info)', () => {+ const doc = buildFile({}, 1000, undefined, undefined, undefined, undefined, { version: '0.2.17' })+ expect('server' in doc).toBe(true)+ expect('server' in filterMirrorForNodes(doc, new Set())).toBe(false)+ })++ it('flush consults the server provider at flush time', async () => {+ const file = path.join(tmpDir, 'status.json')+ initAgentStatusMirror(file)+ setMirrorServerProvider(() => ({ version: '0.2.17', commit: 'abc1234' }))+ await flush()+ const written = JSON.parse(fs.readFileSync(file, 'utf-8'))+ expect(written.server).toEqual({ version: '0.2.17', commit: 'abc1234' })+ })++ it('a throwing provider fails open (no server block, file still written)', async () => {+ const file = path.join(tmpDir, 'status.json')+ initAgentStatusMirror(file)+ setMirrorServerProvider(() => {+ throw new Error('boom')+ })+ await flush()+ expect('server' in JSON.parse(fs.readFileSync(file, 'utf-8'))).toBe(false)+ })++ it('writes no server block when no provider is wired (desktop parity)', async () => {+ const file = path.join(tmpDir, 'status.json')+ initAgentStatusMirror(file)+ await flush()+ expect('server' in JSON.parse(fs.readFileSync(file, 'utf-8'))).toBe(false)+ })+})+// ---- mobile-usage-inbox ---------------------------------------------------------------------describe('inbox event production (via recordAgentEvent)', () => {diff --git a/src/core/agent-status-mirror.ts b/src/core/agent-status-mirror.tsindex 7b0cfbae5..23838c388 100644--- a/src/core/agent-status-mirror.ts+++ b/src/core/agent-status-mirror.ts@@ -47,6 +47,20 @@ export interface MirrorEntry {updatedAt: number}+/** This host's Server-Edition install metadata (spec: server-update). Written by the installer+ * (`scripts/install-server.sh` → `<dataDir>/install-meta.json`) and surfaced to the phone so it+ * can show the installed version / commit and answer "how does this install learn about updates?".+ * Set ONLY by the SERVER shell (the desktop app is not an "installed server"); every field is+ * optional and the whole block is dropped from SSH slices (it is host-local info). */+export interface MirrorServer {+ /** package.json version of the installed checkout, e.g. "0.2.17". */+ version?: string+ /** Short git commit of the installed checkout, e.g. "1e56f83". */+ commit?: string+ /** ISO-8601 timestamp of the last successful install/update. */+ installedAt?: string+}+/** Host-level launch settings the phone consumes (spec: mobile-agent-launch-parity).* Additive to MirrorFile v1 — absent on old files, ignored by old readers. */export interface MirrorSettings {@@ -71,6 +85,10 @@ export interface MirrorFile {/** Agent inbox: an event feed + per-node "what it's doing right now" (spec: mobile-usage-inbox).* Additive/optional. Unlike `usage`, SSH slices KEEP a filtered inbox (their own nodes only). */inbox?: MirrorInbox+ /** This host's Server-Edition install metadata (spec: server-update). Additive/optional — absent+ * on old files and whenever no server provider is wired (e.g. the desktop app). Dropped from SSH+ * slices (host-local info, like `usage`). */+ server?: MirrorServer}// ---- Usage block (mobile-usage-inbox) ------------------------------------------------------@@ -288,8 +306,10 @@ export function reduceEntry(** `usage` is likewise DROPPED (spec: mobile-usage-inbox): a remote host's account credentials* live on that host, so the desktop cannot answer for them — a host running nodeterm itself- * writes its own mirror with its own usage. `inbox` is KEPT but filtered to the slice's node ids- * (both the `events` feed and the per-node `nodes` map).+ * writes its own mirror with its own usage. `server` (install metadata) is DROPPED for the same+ * reason (it describes THIS host's install, not the remote's — a remote nodeterm writes its own).+ * `inbox` is KEPT but filtered to the slice's node ids (both the `events` feed and the per-node+ * `nodes` map).*/export function filterMirrorForNodes(doc: MirrorFile, nodeIds: ReadonlySet<string>): MirrorFile {const nodes: MirrorFile['nodes'] = {}@@ -315,7 +335,8 @@ export function buildFile(expireMs = EXPIRE_MS,settings?: MirrorSettings,usage?: MirrorUsage,- inbox?: MirrorInbox+ inbox?: MirrorInbox,+ server?: MirrorServer): MirrorFile {const out: MirrorFile = { v: 1, updatedAt: now, nodes: {} }for (const [id, e] of Object.entries(nodes)) {@@ -328,6 +349,8 @@ export function buildFile(if (usage) out.usage = usage// Only attach a non-empty inbox — an empty one would gratuitously change the old-file shape.if (inbox && (inbox.events.length > 0 || Object.keys(inbox.nodes).length > 0)) out.inbox = inbox+ // Only attach a non-empty server block (all fields absent ⇒ omit, keeping the old-file shape).+ if (server && (server.version || server.commit || server.installedAt)) out.server = serverreturn out}@@ -425,6 +448,9 @@ let settingsProvider: (() => MirrorSettings | undefined) | null = null// Supplies the local-accounts usage block, consulted fresh on every flush (so a poll landing// between flushes is picked up). Null = no `usage` block written (byte-identical old shape).let usageProvider: (() => MirrorUsage | undefined) | null = null+// Supplies this host's install metadata block (spec: server-update). Set only by the SERVER shell+// (the desktop app leaves it null). Consulted fresh on every flush. Null = no `server` block.+let serverProvider: (() => MirrorServer | undefined) | null = null// ---- Inbox state (feed + per-node activity) ------------------------------------------------// The event feed is oldest→newest and capped at INBOX_EVENTS_CAP; `inboxNodes` is the per-node@@ -794,6 +820,24 @@ function safeUsage(): MirrorUsage | undefined {}}+/**+ * Wire (or clear with `null`) the provider for the additive `server` install-metadata block+ * (spec: server-update). Called once by the SERVER shell on launch; absent ⇒ the mirror writes no+ * `server` key (the desktop app's shape is byte-identical to before this block existed).+ */+export function setMirrorServerProvider(p: (() => MirrorServer | undefined) | null): void {+ serverProvider = p+}++/** Read the server provider, failing open (a throwing/absent provider yields no block). */+function safeServer(): MirrorServer | undefined {+ try {+ return serverProvider?.() ?? undefined+ } catch {+ return undefined+ }+}+/*** Subscribe to every flush's built doc (fires even when the local disk write fails — the doc is* the product, the file is one consumer of it). Returns an unsubscribe. Feeds the SSH-host@@ -1145,7 +1189,7 @@ export async function flush(): Promise<void> {if (!file) returnconst now = Date.now()const inbox: MirrorInbox = { events: inboxEvents, nodes: Object.fromEntries(inboxNodes) }- const doc = buildFile(Object.fromEntries(state), now, undefined, safeSettings(), safeUsage(), inbox)+ const doc = buildFile(Object.fromEntries(state), now, undefined, safeSettings(), safeUsage(), inbox, safeServer())// Also drop expired entries from memory so the map itself can't grow without bound.for (const [id, e] of state) if (now - e.updatedAt > EXPIRE_MS) state.delete(id)// Prune stale per-node activity the same way (events stay — they are capped feed history).@@ -1177,6 +1221,7 @@ export function _resetForTest(): void {flushListeners.clear()settingsProvider = nullusageProvider = null+ serverProvider = nullinboxEvents = []inboxNodes.clear()inboxSeq = 0diff --git a/src/server/index.ts b/src/server/index.tsindex a4cbd3f7e..0e242f02e 100644--- a/src/server/index.ts+++ b/src/server/index.ts@@ -30,10 +30,12 @@ import {recordAgentEvent,ackDone,setMirrorSettingsProvider,+ setMirrorServerProvider,onInboxActionable,onNodeStateChange,onNodeNowChange,- type MirrorSettings+ type MirrorSettings,+ type MirrorServer} from '../core/agent-status-mirror'import { createPushNotify, createLiveUpdatePush } from '../core/push-notify'import { createGrantsAccessor } from '../core/push-grants'@@ -68,6 +70,31 @@ function readAppVersion(): string {}}+/**+ * This host's Server-Edition install metadata (spec: server-update), surfaced to the phone via the+ * agent-status mirror's top-level `server` block. `scripts/install-server.sh` writes+ * `<dataDir>/install-meta.json` (`{version, commit, installedAt}`) after every successful install+ * or auto-update; the auto-update path restarts the service, so a boot-time read is always current.+ * Tolerant: a missing/corrupt file or a block with no usable fields yields `undefined` (no block).+ */+function readInstallMeta(dataDir: string): MirrorServer | undefined {+ try {+ const raw = fs.readFileSync(path.join(dataDir, 'install-meta.json'), 'utf8')+ const p = JSON.parse(raw) as { version?: unknown; commit?: unknown; installedAt?: unknown }+ const str = (v: unknown): string | undefined => (typeof v === 'string' && v ? v : undefined)+ const out: MirrorServer = {}+ const version = str(p.version)+ const commit = str(p.commit)+ const installedAt = str(p.installedAt)+ if (version) out.version = version+ if (commit) out.commit = commit+ if (installedAt) out.installedAt = installedAt+ return out.version || out.commit || out.installedAt ? out : undefined+ } catch {+ return undefined+ }+}+/*** Boot the headless server: wires the CorePlatform (ServerPlatform) to auth + HTTP +* WebSocket, then constructs and registers the same core services the desktop main@@ -213,6 +240,13 @@ export async function startServer(.map((a) => ({ id: a.id, dir: claudeConfigDirFor(a.id) }))}})+ // Advertise this install's version/commit/installedAt to the phone (spec: server-update). The+ // installer writes <dataDir>/install-meta.json after a successful install/update; read it once at+ // boot (the auto-update path restarts this service, so a boot-time read is always current) and+ // expose it as the mirror's `server` block. Desktop never sets this provider. Tolerant — a+ // missing/corrupt file simply yields no block.+ const installMeta = readInstallMeta(config.dataDir)+ setMirrorServerProvider(() => installMeta)wireAgentStatus(platform)// Deterministic hook-reply approvals (docs/hook-reply-approvals.md): the browser canvas answers a// held Claude permission hook here. The Server Edition runs ON the host, so a local project's