The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Move the CLI's curl|bash installer and its publisher here from autonomous-code
0xken1590dabd0ed588
diff --git a/Makefile b/Makefileindex cecfa06a5..dfa268960 100644--- a/Makefile+++ b/Makefile@@ -4,7 +4,7 @@# make install-cli ARGS="--no-restart"# make upload-cli ARGS="0.1.0"-.PHONY: cli-test install-cli upload-cli release-cli release-backend release-desktop remote-machine upload-circle device-test+.PHONY: cli-test install-cli upload-cli upload-cli-install-sh release-cli release-backend release-desktop remote-machine upload-circle device-test## cli-test: typecheck + run the CLI test suite.cli-test:@@ -45,6 +45,13 @@ install-cli:upload-cli:bash cli/scripts/upload-cli.sh $(ARGS)+## upload-cli-install-sh: publish cli/scripts/install.sh — the `curl ... | bash` installer — to+## harness/cli/install.sh in the release bucket (-> https://cdn.autonomous.ai/harness/cli/install.sh).+## One static file, no version; MAINTAINER ONLY, same credential as upload-cli. Verify the CDN edge+## serves the new bytes afterwards (the script prints the command).+upload-cli-install-sh:+ bash cli/scripts/upload-install-sh.sh+## remote-machine: drive a SECOND harness machine in Docker, so the app's remote path (relay ->## another machine's daemon) can be tested from one laptop. ARGS picks the step:## make remote-machine ARGS=build -> bundle this tree + build the imagediff --git a/cli/RELEASE.md b/cli/RELEASE.mdindex 921e816bf..d7e90331b 100644--- a/cli/RELEASE.md+++ b/cli/RELEASE.md@@ -60,6 +60,22 @@ the tag back in line.A failed build stops the release; nothing is uploaded and no version is consumed.+## The `curl | bash` installer++`cli/scripts/install.sh` is what `curl -fsSL https://cdn.autonomous.ai/harness/cli/install.sh | bash`+runs: it installs the managed Node runtime and the CLI bundle from the same manifests the release+publishes to. It is a static file, versioned by nothing, and does **not** ship with a release — publish+it on its own whenever it changes:++```bash+make upload-cli-install-sh # cli/scripts/install.sh -> harness/cli/install.sh in the bucket+curl -fsSL https://cdn.autonomous.ai/harness/cli/install.sh | head -5 # confirm the CDN edge moved+```++Its command contract (flags, exit codes, what it refuses) is pinned by `cli/src/scripts/install.spec.ts`,+which runs with the rest of `make cli-test`. Not to be confused with `cli/scripts/install-cli.sh`, the+local dev loop below.+## Local install (no upload)`bash cli/scripts/install-cli.sh` bundles **this working tree** into `~/.harness/cli` — the samediff --git a/cli/scripts/install.sh b/cli/scripts/install.shnew file mode 100755index 000000000..712b4e0e3--- /dev/null+++ b/cli/scripts/install.sh@@ -0,0 +1,487 @@+#!/bin/sh+# harness — one-line installer, served from the CDN at+# https://cdn.autonomous.ai/harness/cli/install.sh (source of truth: THIS file, cli/scripts/install.sh in+# the autonomous-harness repo — published with `make upload-cli-install-sh` from the repo root, and+# checked by cli/src/scripts/install.spec.ts). Not the same thing as cli/scripts/install-cli.sh, which+# installs the CLI from a working tree for local development and publishes nothing.+# The website (autonomous-code, apps/web) still answers the OLD URL, https://harness.autonomous.ai/cli/+# install.sh, but only as a redirect to the CDN one (its next.config.js) — kept for anyone with the old+# link already saved.+# curl -fsSL https://cdn.autonomous.ai/harness/cli/install.sh | bash+# curl -fsSL https://cdn.autonomous.ai/harness/cli/install.sh | sh -s -- --desktop # Desktop only+# harness login+# harness start+#+# Downloads the self-contained CLI bundle from the public GCS manifest and installs a `harness` command.+# Login and start are deliberately separate: login saves a native SSO session, while start launches the+# adapter from that session. The running daemon auto-updates itself thereafter (polls the same manifest).+# There is no system Node prerequisite. The CLI is plain JS (no native binary, no code-signing) and it runs on a+# checksum-verified Node this installer puts in ~/.harness/runtime — the same runtime Desktop Harness+# manages, shared on purpose so one cli.js is never run by two different Nodes. Your own Node and nvm+# are neither required nor touched. In standalone mode, tmux is the only supported terminal backend,+# so it is prepared and verified before any Harness runtime or CLI files are installed. On macOS the+# supported tmux path is Homebrew; on Ubuntu it is apt. A Linux GUI also requires the clipboard+# helper for its active display protocol. Desktop mode trusts the app's earlier host pre-flight and+# skips that package work. The runtime's absolute path is baked into the launcher,+# so a Finder launch — where PATH is launchd's bare /usr/bin:/bin:/usr/sbin:/sbin — resolves the CLI+# exactly like a terminal does.+# POSIX sh (so `| sh` and `| bash` both work).+set -eu++# No argument is the complete standalone/server installer. Desktop owns host pre-flight and passes+# --desktop so this script installs only the managed runtime and CLI instead of asking twice for the+# same package-manager/admin work.+INSTALL_MODE=standalone+case "${1:-}" in+ "") ;;+ --desktop)+ INSTALL_MODE=desktop+ shift+ ;;+ *)+ echo "✗ Unsupported installer argument: $1" >&2+ echo " This installer no longer accepts a machine token." >&2+ echo " Run the installer without arguments, then: harness login && harness start" >&2+ exit 2+ ;;+esac+if [ "$#" -gt 0 ]; then+ echo "✗ Desktop mode accepts no additional arguments." >&2+ echo "✗ This installer no longer accepts a machine token." >&2+ exit 2+fi++METADATA_URL="${HARNESS_METADATA_URL:-https://storage.googleapis.com/s3-autonomous-upgrade-3/harness/cli/metadata.json}"+# Published by `make upload-node-runtime` in the desktop repo; the desktop app reads the same manifest+# (its --dart-define is spelled the same) so both installers land on identical bytes.+RUNTIME_METADATA_URL="${HARNESS_RUNTIME_METADATA_URL:-https://storage.googleapis.com/s3-autonomous-upgrade-3/harness/runtime/metadata.json}"+HARNESS_KEY="${HARNESS_KEY:-cli}"+CLI_DIR="$HOME/.harness/cli"+RUNTIME_DIR="$HOME/.harness/runtime"+CURRENT_NODE_FILE="$RUNTIME_DIR/current-node"+BIN_DIR="$HOME/.local/bin"+LAUNCHER="$BIN_DIR/harness"++# 1. Standalone host setup. tmux is the CLI's only supported terminal backend, so prepare it before+# writing Node or Harness files and fail clearly if it cannot be verified. This installer already+# runs in a terminal, so package-manager password prompts stay with the OS — never Harness.+require_command() {+ command -v "$1" >/dev/null 2>&1 || {+ echo "✗ Required system tool is missing: $1" >&2+ exit 11+ }+}++apt_as_root() {+ if [ "$(id -u)" -eq 0 ]; then+ apt-get "$@"+ elif command -v sudo >/dev/null 2>&1; then+ sudo apt-get "$@"+ else+ echo "✗ Installing system packages needs root access, but sudo is unavailable." >&2+ return 1+ fi+}++install_with_apt() {+ if apt_as_root install -y "$@"; then+ return 0+ fi+ echo "▸ Refreshing package indexes before retrying"+ apt_as_root update || true+ apt_as_root install -y "$@"+}++if [ "$INSTALL_MODE" = "standalone" ]; then+case "$(uname -s)" in+ Darwin)+ require_command curl+ require_command tar+ require_command sed+ require_command awk+ command -v shasum >/dev/null 2>&1 || { echo "✗ Required system tool is missing: shasum" >&2; exit 11; }+ if ! /usr/bin/xcrun --find clang >/dev/null 2>&1; then+ echo "▸ Apple developer tools are required by Homebrew (Xcode or Command Line Tools)."+ if [ -x /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild ]; then+ echo " Xcode is installed but is not the active developer directory."+ echo " macOS may ask for your password to select it."+ sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer+ else+ echo " macOS will open its installer now. Finish it, then run this Harness installer again."+ xcode-select --install >/dev/null 2>&1 || true+ exit 20+ fi+ /usr/bin/xcrun --find clang >/dev/null 2>&1 || {+ echo "✗ Apple developer tools are selected but are not usable." >&2+ exit 20+ }+ fi+ if ! command -v brew >/dev/null 2>&1; then+ echo "▸ Installing Homebrew (macOS may ask for your password)"+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" || {+ echo "✗ Homebrew installation failed. Review the output above, then retry." >&2+ exit 21+ }+ fi+ eval "$(/opt/homebrew/bin/brew shellenv 2>/dev/null || /usr/local/bin/brew shellenv 2>/dev/null)"+ command -v brew >/dev/null 2>&1 || {+ echo "✗ Homebrew was installed but is not available to this shell." >&2+ exit 21+ }+ if ! command -v tmux >/dev/null 2>&1; then+ echo "▸ Installing tmux via Homebrew"+ brew install tmux || {+ echo "✗ Could not install tmux via Homebrew. Retry with: brew install tmux" >&2+ exit 22+ }+ fi+ ;;+ Linux)+ missing_system_packages=""+ command -v bash >/dev/null 2>&1 || missing_system_packages="$missing_system_packages bash"+ command -v curl >/dev/null 2>&1 || missing_system_packages="$missing_system_packages curl"+ command -v tar >/dev/null 2>&1 || missing_system_packages="$missing_system_packages tar"+ command -v sed >/dev/null 2>&1 || missing_system_packages="$missing_system_packages sed"+ command -v awk >/dev/null 2>&1 || missing_system_packages="$missing_system_packages gawk"+ command -v sha256sum >/dev/null 2>&1 || missing_system_packages="$missing_system_packages coreutils"+ if [ -n "$missing_system_packages" ]; then+ command -v apt-get >/dev/null 2>&1 || {+ echo "✗ Required Linux system tools are missing. Automatic install supports apt-based Linux only." >&2+ echo " Install these packages with this distribution's package manager:$missing_system_packages" >&2+ exit 11+ }+ echo "▸ Installing required Linux system tools (you may be asked for your password)"+ # Intentional word splitting: this list contains only package names selected above.+ # shellcheck disable=SC2086+ install_with_apt $missing_system_packages || {+ echo "✗ Could not install required Linux system tools via apt-get." >&2+ exit 11+ }+ fi+ require_command bash+ require_command curl+ require_command tar+ require_command sed+ require_command awk+ require_command sha256sum+ if ! command -v tmux >/dev/null 2>&1; then+ command -v apt-get >/dev/null 2>&1 || {+ echo "✗ tmux is required. Automatic install supports apt-based Linux only." >&2+ echo " Install tmux with this distribution's package manager, then retry." >&2+ exit 22+ }+ echo "▸ Installing tmux (you may be asked for your password)"+ install_with_apt tmux || {+ echo "✗ Could not install tmux via apt-get. Retry with: sudo apt-get install -y tmux" >&2+ exit 22+ }+ fi+ # Native image paste needs the helper for the display protocol this process will use. A+ # genuinely headless server has no OS clipboard, so installing either package there would add a+ # sudo prompt without adding a capability; the CLI deliberately uses its file-path fallback.+ clipboard_command=""+ clipboard_package=""+ if [ -n "${WAYLAND_DISPLAY:-}" ]; then+ clipboard_command="wl-copy"+ clipboard_package="wl-clipboard"+ elif [ -n "${DISPLAY:-}" ]; then+ clipboard_command="xclip"+ clipboard_package="xclip"+ else+ echo "▸ No X11 or Wayland display detected; native image clipboard is not applicable."+ fi+ if [ -n "$clipboard_command" ] && ! command -v "$clipboard_command" >/dev/null 2>&1; then+ command -v apt-get >/dev/null 2>&1 || {+ echo "✗ $clipboard_command is required for native image paste on this Linux desktop." >&2+ echo " Install $clipboard_package with this distribution's package manager, then retry." >&2+ exit 23+ }+ echo "▸ Installing $clipboard_package for native image paste (you may be asked for your password)"+ install_with_apt "$clipboard_package" || {+ echo "✗ Could not install $clipboard_package via apt-get." >&2+ echo " Retry with: sudo apt-get install -y $clipboard_package" >&2+ exit 23+ }+ fi+ if [ -n "$clipboard_command" ]; then+ command -v "$clipboard_command" >/dev/null 2>&1 || {+ echo "✗ $clipboard_command is required but did not pass verification." >&2+ exit 23+ }+ echo "✓ Linux image clipboard ready ($clipboard_command)"+ fi+ ;;+ *)+ echo "✗ Automatic Harness installation supports macOS and Linux only." >&2+ exit 10+ ;;+esac++command -v tmux >/dev/null 2>&1 && tmux -V >/dev/null 2>&1 || {+ echo "✗ tmux is required but did not pass verification." >&2+ exit 22+}+echo "✓ tmux ready ($(tmux -V))"+else+ echo "▸ Desktop mode: trusting the app's host pre-flight; skipping system packages and tmux setup."+fi++# 2. Resolve the Node that will run the CLI (and this installer's own JSON parse + sha256 verify in+# step 3). The CLI runs on the MANAGED runtime under ~/.harness/runtime, not on whatever Node the+# computer happens to have:+# 1. $HARNESS_NODE_BINARY — Desktop Harness handing over the runtime it just validated.+# 2. ~/.harness/runtime/current-node — the managed runtime, if it is already here.+# 3. otherwise, download it.+# A Node on PATH is used only as a last resort, on a platform we publish no runtime for.+#+# Why not prefer the user's own Node: it is the version-drift bug in a different shirt. A CLI+# driven from the desktop app and from a terminal must be ONE cli.js on ONE Node, and a `node`+# that PATH resolves is none of stable, shared, or ours — it moves with nvm, it differs between a+# Finder launch and a Terminal launch, and it can be upgraded out from under a running daemon.+# Nothing outside ~/.harness is read or changed either way; the user's own Node is left alone.+#+# Everything in this step must run in plain POSIX sh: there is no Node yet to lean on.++# Prints the major version of $1, or nothing when it cannot be run.+node_major() {+ "$1" -e 'process.stdout.write(String(process.versions.node.split(".")[0]))' 2>/dev/null || true+}++node_is_usable() {+ [ -n "${1:-}" ] || return 1+ [ -x "$1" ] || return 1+ _major="$(node_major "$1")"+ [ -n "$_major" ] || return 1+ [ "$_major" -ge 20 ] 2>/dev/null || return 1+ return 0+}++NODE_BIN="${HARNESS_NODE_BINARY:-}"+if [ -n "$NODE_BIN" ]; then+ # An explicit override is an instruction, not a hint: if it is unusable, say so rather than+ # quietly downloading a second runtime behind the caller's back.+ if [ ! -x "$NODE_BIN" ]; then+ echo "✗ HARNESS_NODE_BINARY is not an executable Node runtime: $NODE_BIN" >&2+ exit 1+ fi+ if ! node_is_usable "$NODE_BIN"; then+ echo "✗ HARNESS_NODE_BINARY is older than Node 20: $NODE_BIN ($("$NODE_BIN" -v 2>/dev/null || echo unknown))" >&2+ exit 1+ fi+fi++if [ -z "$NODE_BIN" ] && [ -r "$CURRENT_NODE_FILE" ]; then+ managed_node="$(cat "$CURRENT_NODE_FILE" 2>/dev/null || true)"+ # Only ever trust a path inside the runtime directory we own.+ case "$managed_node" in+ "$RUNTIME_DIR"/*)+ if node_is_usable "$managed_node"; then+ NODE_BIN="$managed_node"+ echo "▸ Using the managed Node runtime already installed ($("$NODE_BIN" -v))"+ fi+ ;;+ esac+fi++if [ -z "$NODE_BIN" ]; then+ # Fetch the same checksum-pinned runtime Desktop Harness uses. A Node already on PATH is+ # deliberately NOT preferred here — see the note in step 1 — but it is still the last resort on a+ # platform we publish no runtime for, so an exotic box keeps working instead of being locked out.+ node_platform=""+ case "$(uname -s)" in+ Darwin) node_os=darwin ;;+ Linux) node_os=linux ;;+ *) node_os="" ;;+ esac+ case "$(uname -m)" in+ arm64|aarch64) node_arch=arm64 ;;+ x86_64|amd64) node_arch=x64 ;;+ *) node_arch="" ;;+ esac+ [ -n "$node_os" ] && [ -n "$node_arch" ] && node_platform="$node_os-$node_arch"++ if [ -z "$node_platform" ]; then+ path_node="$(command -v node 2>/dev/null || true)"+ if [ -n "$path_node" ] && node_is_usable "$path_node"; then+ echo "▸ No managed Node runtime is published for $(uname -s)/$(uname -m) — using $path_node"+ NODE_BIN="$path_node"+ else+ echo "✗ No managed Node runtime is published for $(uname -s)/$(uname -m), and no Node >= 20 on PATH." >&2+ echo " Install Node 20+ from https://nodejs.org, then re-run this installer." >&2+ exit 1+ fi+ fi+fi++if [ -z "$NODE_BIN" ]; then++ # sha256 is the one tool that genuinely differs between the two platforms, and it is needed+ # BEFORE Node exists to smooth it over — hence this pair rather than step 2's single JS path.+ if command -v shasum >/dev/null 2>&1; then+ sha256_of() { shasum -a 256 "$1" | awk '{print $1}'; }+ elif command -v sha256sum >/dev/null 2>&1; then+ sha256_of() { sha256sum "$1" | awk '{print $1}'; }+ else+ echo "✗ Need shasum or sha256sum to verify the Node download, and found neither." >&2+ exit 1+ fi++ echo "▸ Installing the Harness Node runtime into $RUNTIME_DIR"+ echo " The CLI runs on its own Node so it behaves the same from a terminal and from the app."+ echo " Your system Node, nvm and Homebrew are not read or changed."+ runtime_manifest="$(curl -fsSL "$RUNTIME_METADATA_URL")" || {+ echo "✗ Could not fetch the Node runtime manifest: $RUNTIME_METADATA_URL" >&2+ exit 1+ }+ # The manifest is our own, published one key per line; pull just this platform's object out and+ # read its fields. No jq/python dependency, which a bare machine may equally not have.+ runtime_entry="$(printf '%s\n' "$runtime_manifest" | sed -n "/\"$node_platform\"[[:space:]]*:[[:space:]]*{/,/}/p")"+ entry_field() {+ printf '%s\n' "$runtime_entry" | sed -n "s/.*\"$1\"[[:space:]]*:[[:space:]]*\"\([^\"]*\)\".*/\1/p" | head -1+ }+ node_url="$(entry_field url)"+ node_sha="$(entry_field sha256)"+ node_root="$(entry_field archiveRoot)"+ node_version="$(entry_field version)"+ if [ -z "$node_url" ] || [ -z "$node_sha" ] || [ -z "$node_root" ] || [ -z "$node_version" ]; then+ echo "✗ The Node runtime manifest has no usable '$node_platform' entry." >&2+ exit 1+ fi++ mkdir -p "$RUNTIME_DIR"+ chmod 700 "$RUNTIME_DIR" 2>/dev/null || true+ node_target="$RUNTIME_DIR/node-$node_version-$node_platform"+ if [ ! -x "$node_target/bin/node" ]; then+ node_staging="$RUNTIME_DIR/.node-staging-$$"+ rm -rf "$node_staging"+ mkdir -p "$node_staging"+ # Staging never outlives this script, however it ends — a half-unpacked runtime that looked+ # complete would be worse than no runtime at all.+ trap 'rm -rf "$node_staging"' EXIT INT TERM+ echo " ▸ downloading Node $node_version ($node_platform)…"+ curl -fsSL "$node_url" -o "$node_staging/node.tar.gz" || {+ echo "✗ Could not download $node_url" >&2+ exit 1+ }+ node_got="$(sha256_of "$node_staging/node.tar.gz")"+ if [ "$node_got" != "$node_sha" ]; then+ echo "✗ Node download failed checksum verification (expected $node_sha, got $node_got)" >&2+ exit 1+ fi+ tar -xzf "$node_staging/node.tar.gz" -C "$node_staging" || {+ echo "✗ Could not unpack the Node archive" >&2+ exit 1+ }+ [ -x "$node_staging/$node_root/bin/node" ] || {+ echo "✗ The Node archive has no $node_root/bin/node" >&2+ exit 1+ }+ mv "$node_staging/$node_root" "$node_target"+ rm -rf "$node_staging"+ trap - EXIT INT TERM+ fi++ NODE_BIN="$node_target/bin/node"+ if ! node_is_usable "$NODE_BIN"; then+ echo "✗ The installed Node runtime does not run on this computer: $NODE_BIN" >&2+ exit 1+ fi+ # Recorded last, and only once the binary has answered `--version`: this file is what Desktop+ # Harness reads to pick its runtime, so it must never name something that does not work.+ printf '%s\n' "$NODE_BIN" > "$CURRENT_NODE_FILE"+ chmod 600 "$CURRENT_NODE_FILE" 2>/dev/null || true+ echo " ✓ installed Node $node_version → $node_target"+fi++# 3. Fetch manifest, download + sha256-verify cli.js & notify.mjs, install them + the launcher (all in+# Node so it works identically on macOS/Linux without shasum/sha256sum差异).+echo "▸ Installing harness from $METADATA_URL"+HARNESS_METADATA_URL="$METADATA_URL" HARNESS_KEY="$HARNESS_KEY" HARNESS_NODE_BINARY="$NODE_BIN" "$NODE_BIN" <<'HARNESSJS'+const fs = require('fs'), os = require('os'), path = require('path'), crypto = require('crypto')+const META = process.env.HARNESS_METADATA_URL, KEY = process.env.HARNESS_KEY, NODE = process.env.HARNESS_NODE_BINARY+const dir = path.join(os.homedir(), '.harness', 'cli')+const bin = path.join(os.homedir(), '.local', 'bin')+;(async () => {+ const res = await fetch(META)+ if (!res.ok) throw new Error('could not fetch manifest (HTTP ' + res.status + ')')+ const entry = (await res.json())[KEY]+ if (!entry || !entry.version || !entry.cli || !entry.notify) throw new Error("manifest has no valid '" + KEY + "' entry")+ fs.mkdirSync(dir, { recursive: true })+ fs.mkdirSync(bin, { recursive: true })+ const fetchVerified = async (ref, name) => {+ const r = await fetch(ref.url)+ if (!r.ok) throw new Error('HTTP ' + r.status + ' for ' + ref.url)+ const buf = Buffer.from(await r.arrayBuffer())+ const got = crypto.createHash('sha256').update(buf).digest('hex')+ if (got.toLowerCase() !== String(ref.sha256).toLowerCase()) throw new Error('sha256 mismatch for ' + name)+ fs.writeFileSync(path.join(dir, name), buf)+ }+ await fetchVerified(entry.cli, 'cli.js')+ await fetchVerified(entry.notify, 'notify.mjs')+ fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify({ type: 'module' }) + '\n')+ const shellQuote = value => "'" + value.replaceAll("'", "'\\''") + "'"+ fs.writeFileSync(path.join(bin, 'harness'), '#!/bin/sh\nexec ' + shellQuote(NODE) + ' ' + shellQuote(path.join(dir, 'cli.js')) + ' "$@"\n', { mode: 0o755 })+ console.log(' ✓ installed harness ' + entry.version + ' → ' + dir)+})().catch((err) => { console.error('✗ install failed: ' + err.message); process.exit(1) })+HARNESSJS++# 4. Ensure ~/.local/bin is on PATH (per shell), idempotently.+add_path_line='export PATH="$HOME/.local/bin:$PATH"'+marker='# added by harness installer'+ensure_rc() {+ rc="$1"+ [ -f "$rc" ] || : > "$rc"+ if ! grep -qF "$marker" "$rc" 2>/dev/null; then+ printf '\n%s\n%s\n' "$marker" "$add_path_line" >> "$rc"+ echo " ✓ added ~/.local/bin to PATH in $rc"+ fi+}+case "$(basename "${SHELL:-/bin/sh}")" in+ zsh) ensure_rc "$HOME/.zshrc" ;;+ # `.bashrc` alone is not enough. A LOGIN shell reads .bash_profile / .bash_login / .profile and never+ # .bashrc — that is `bash -lc`, `ssh host cmd`, most CI, and every `docker exec … bash -l`. On a+ # desktop or an ssh session the shell is interactive so .bashrc is read and the gap is invisible;+ # inside a container it means `harness` is never on PATH no matter how many new shells you open.+ # macOS already covered this by also writing .bash_profile (Terminal starts login shells); do the+ # same on Linux, writing whichever login file bash will actually consult — it reads the FIRST that+ # exists, so appending to a lower-priority one would be silently ignored.+ bash) ensure_rc "$HOME/.bashrc"+ if [ -f "$HOME/.bash_profile" ]; then ensure_rc "$HOME/.bash_profile"+ elif [ -f "$HOME/.bash_login" ]; then ensure_rc "$HOME/.bash_login"+ elif [ "$(uname)" = "Darwin" ]; then ensure_rc "$HOME/.bash_profile"+ else ensure_rc "$HOME/.profile"+ fi ;;+ fish) mkdir -p "$HOME/.config/fish"+ rc="$HOME/.config/fish/config.fish"; [ -f "$rc" ] || : > "$rc"+ grep -qF "$marker" "$rc" 2>/dev/null || printf '\n%s\nfish_add_path %s\n' "$marker" "$HOME/.local/bin" >> "$rc" ;;+ *) ensure_rc "$HOME/.profile" ;;+esac++# 5. Final verification. Use the launcher by absolute path because this process cannot update its+# parent shell's PATH. Installation never authenticates or starts the adapter implicitly.+"$NODE_BIN" --version >/dev/null 2>&1 || { echo "✗ Managed Node verification failed." >&2; exit 30; }+"$LAUNCHER" version >/dev/null 2>&1 || { echo "✗ Harness CLI verification failed." >&2; exit 31; }+if [ "$INSTALL_MODE" = "standalone" ]; then+ tmux -V >/dev/null 2>&1 || { echo "✗ tmux verification failed." >&2; exit 32; }+fi++# The explicit commands keep+# browser SSO and long-lived daemon lifecycle understandable and scriptable.+echo ""+echo " harness installed."+echo " To connect this computer, run:"+echo " harness login"+echo " harness start"++# 6. Make `harness` usable by NAME. We already added ~/.local/bin to your rc for NEW terminals (step 4);+# a piped `curl … | sh` can't touch the CURRENT shell's PATH, so print the one line that fixes it here+# now — but ONLY when ~/.local/bin isn't already on PATH (many Linux distros add it), to avoid nagging.+case ":${PATH}:" in+ *":$BIN_DIR:"*) : ;; # already on PATH → `harness` works immediately, nothing to do+ *)+ echo ""+ echo " 'harness' is installed in ~/.local/bin. To run it in THIS terminal now:"+ echo " export PATH=\"\$HOME/.local/bin:\$PATH\""+ echo " New terminals already have it (or reload this one with: exec \$SHELL)."+ ;;+esacdiff --git a/cli/scripts/upload-install-sh.sh b/cli/scripts/upload-install-sh.shnew file mode 100755index 000000000..67cbd4da4--- /dev/null+++ b/cli/scripts/upload-install-sh.sh@@ -0,0 +1,53 @@+#!/usr/bin/env bash+# Publish cli/scripts/install.sh — the one-line CLI installer — to the public, CDN-fronted bucket+# everything else here publishes to. Same idiom as upload-cli.sh: one `cp` with explicit headers, no+# build step, no version to bump — this is one static file. `make upload-cli-install-sh` from the+# repo root.+#+# gs://s3-autonomous-upgrade-3/harness/cli/install.sh -> https://cdn.autonomous.ai/harness/cli/install.sh+#+# Cache-Control is no-cache/no-store/must-revalidate at the GCS origin. A positive max-age does not+# survive Cloudflare (which fronts cdn.autonomous.ai): it rewrites it to its own ~31-day edge TTL+# (`cache-control: public, max-age=2678400` observed for an origin max-age=300), a zone-level setting+# nothing in this repo can override. no-cache/no-store is the one directive it DOES honor (confirmed+# via `cf-cache-status: BYPASS`), so that is what keeps a publish reaching people promptly. After+# running this, verify the CDN itself serves the new bytes — the command this script prints at the end.+#+# Prereqs: `gcloud storage` (or gsutil) authenticated with WRITE access on the bucket.+set -euo pipefail++ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # cli/+SCRIPT="$ROOT/scripts/install.sh"++GCS_BUCKET="${GCS_BUCKET:-s3-autonomous-upgrade-3}"+GCS_PATH="harness/cli/install.sh"+CDN_URL="https://cdn.autonomous.ai/${GCS_PATH}"++# --- GCS client: `gcloud storage` if we have it, else gsutil (see upload-cli.sh for why) ---+if command -v gcloud >/dev/null 2>&1 && gcloud storage --help >/dev/null 2>&1; then+ GCS_CLI=gcloud+elif command -v gsutil >/dev/null 2>&1; then+ GCS_CLI=gsutil+ echo ">> note: falling back to gsutil (no 'gcloud storage'); this will not work under workload identity federation" >&2+else+ echo "error: neither 'gcloud storage' nor gsutil found — install/authenticate the gcloud SDK" >&2+ exit 1+fi++[ -f "$SCRIPT" ] || { echo "error: $SCRIPT not found" >&2; exit 1; }+sh -n "$SCRIPT" # fail before uploading a script that doesn't even parse++CC="no-cache, no-store, must-revalidate"+CT="text/x-shellscript; charset=utf-8"+echo ">> uploading $SCRIPT"+echo " -> gs://${GCS_BUCKET}/${GCS_PATH}"+if [ "$GCS_CLI" = gcloud ]; then+ gcloud storage cp --cache-control="$CC" --content-type="$CT" "$SCRIPT" "gs://${GCS_BUCKET}/${GCS_PATH}"+else+ gsutil -h "Cache-Control:$CC" -h "Content-Type:$CT" cp "$SCRIPT" "gs://${GCS_BUCKET}/${GCS_PATH}"+fi++echo ""+echo ">> published: ${CDN_URL}"+echo ">> verify the CDN edge actually serves it (may lag the origin — see this script's header):"+echo " curl -fsSL ${CDN_URL} | head -5"diff --git a/cli/src/scripts/install.spec.ts b/cli/src/scripts/install.spec.tsnew file mode 100644index 000000000..1b690793c--- /dev/null+++ b/cli/src/scripts/install.spec.ts@@ -0,0 +1,381 @@+import { spawnSync } from "child_process";+import { join } from "path";+import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "fs";+import { tmpdir } from "os";+import { describe, expect, it } from "vitest";++// vitest runs from cli/, so this is cli/scripts/install.sh — the file published to the CDN.+const installer = join(process.cwd(), "scripts", "install.sh");++const writeCommand = (directory: string, name: string, lines: string[]) => {+ const path = join(directory, name);+ writeFileSync(path, ["#!/bin/sh", ...lines, ""].join("\n"));+ chmodSync(path, 0o700);+};++const writeLinuxBaseCommands = (directory: string) => {+ for (const command of ["bash", "curl", "tar", "sed", "awk", "sha256sum"]) {+ writeCommand(directory, command, ["exit 0"]);+ }+};++describe("scripts/install.sh command contract", () => {+ it("rejects a legacy machine-token argument before installing", () => {+ const result = spawnSync("sh", [installer, "legacy-token"], { encoding: "utf8" });++ expect(result.status).toBe(2);+ expect(result.stderr).toContain("no longer accepts a machine token");+ expect(result.stderr).toContain("harness login && harness start");+ });++ it("accepts only standalone default or explicit desktop mode", () => {+ const source = readFileSync(installer, "utf8");+ const parser = source.slice(0, source.indexOf('METADATA_URL='));++ const standalone = spawnSync("/bin/sh", ["-s"], {+ encoding: "utf8",+ input: parser,+ });+ const desktop = spawnSync("/bin/sh", ["-s", "--", "--desktop"], {+ encoding: "utf8",+ input: parser,+ });+ const extra = spawnSync(+ "/bin/sh",+ ["-s", "--", "--desktop", "legacy-token"],+ { encoding: "utf8", input: parser },+ );++ expect(standalone.status).toBe(0);+ expect(desktop.status).toBe(0);+ expect(extra.status).toBe(2);+ expect(extra.stderr).toContain("accepts no additional arguments");+ });++ it("accepts a desktop-supplied Node runtime and pins the launcher to it", () => {+ const source = readFileSync(installer, "utf8");++ expect(source).toContain('NODE_BIN="${HARNESS_NODE_BINARY:-}"');+ expect(source).toContain('HARNESS_NODE_BINARY="$NODE_BIN"');+ expect(source).toContain("const shellQuote");+ expect(source).toContain("exec ' + shellQuote(NODE)");+ });++ // The CLI runs on the runtime under ~/.harness/runtime, never on whatever `node` PATH happens to+ // resolve — the same rule the desktop app follows, so one cli.js is never driven by two Nodes.+ it("installs its own Node runtime rather than requiring one", () => {+ const source = readFileSync(installer, "utf8");++ expect(source).toContain("harness/runtime/metadata.json");+ expect(source).toContain('CURRENT_NODE_FILE="$RUNTIME_DIR/current-node"');+ // The runtime is recorded for the desktop app to find, and only after it has answered.+ expect(source).toContain('printf \'%s\\n\' "$NODE_BIN" > "$CURRENT_NODE_FILE"');+ // No Node yet at that point, so the checksum has to be taken with the platform's own tool.+ expect(source).toContain("shasum -a 256");+ expect(source).toContain("sha256sum");+ // The old behaviour — bail out and tell the user to go install Node — must not come back.+ expect(source).not.toContain("brew install node");+ expect(source).not.toContain("deb.nodesource.com");+ });++ it("refuses an unverified Node archive", () => {+ const source = readFileSync(installer, "utf8");++ expect(source).toContain('if [ "$node_got" != "$node_sha" ]; then');+ expect(source).toContain("failed checksum verification");+ });++ it("prepares and verifies required tmux before installing Node or Harness", () => {+ const source = readFileSync(installer, "utf8");+ const tmuxStep = source.indexOf("# 1. Standalone host setup");+ const nodeStep = source.indexOf("# 2. Resolve the Node");+ const cliStep = source.indexOf("# 3. Fetch manifest");++ expect(tmuxStep).toBeGreaterThan(-1);+ expect(nodeStep).toBeGreaterThan(tmuxStep);+ expect(cliStep).toBeGreaterThan(nodeStep);+ expect(source).toContain("/usr/bin/xcrun --find clang");+ expect(source).toContain(+ "sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer",+ );+ expect(source).toContain("xcode-select --install");+ expect(source).toContain("Homebrew installation failed");+ expect(source).toContain("brew install tmux");+ expect(source).toContain("install_with_apt tmux");+ expect(source).toContain('if [ "$(id -u)" -eq 0 ]; then');+ expect(source).toContain('sudo apt-get "$@"');+ expect(source).not.toContain("sudo apt-get update &&");+ expect(source).toContain("Could not install tmux via Homebrew");+ expect(source).toContain("Could not install tmux via apt-get");+ expect(source).toContain("tmux is required but did not pass verification");+ expect(source).toContain("exit 22");+ });++ it("installs missing Linux base tools before tmux", () => {+ const source = readFileSync(installer, "utf8");+ const hostSetup = source.slice(+ source.indexOf("apt_as_root()"),+ source.indexOf("# 2. Resolve the Node"),+ );+ const scratch = mkdtempSync(join(tmpdir(), "harness-linux-tools-"));+ const invocations = join(scratch, "apt-invocations");+ const fakeCurl = join(scratch, "curl");++ try {+ for (const command of ["bash", "tar", "sed", "awk", "sha256sum"]) {+ writeCommand(scratch, command, ["exit 0"]);+ }+ writeCommand(scratch, "id", ["printf '0\\n'"]);+ writeCommand(scratch, "uname", ["printf 'Linux\\n'"]);+ writeCommand(scratch, "tmux", ["printf 'tmux 3.6\\n'"]);+ writeCommand(scratch, "apt-get", [+ `printf '%s\\n' "$*" >> '${invocations}'`,+ `printf '%s\\n' '#!/bin/sh' 'exit 0' > '${fakeCurl}'`,+ `/bin/chmod 700 '${fakeCurl}'`,+ ]);++ const result = spawnSync("/bin/sh", ["-c", hostSetup], {+ encoding: "utf8",+ env: {+ ...process.env,+ INSTALL_MODE: "standalone",+ DISPLAY: "",+ WAYLAND_DISPLAY: "",+ PATH: scratch,+ },+ });++ expect(result.status).toBe(0);+ expect(readFileSync(invocations, "utf8")).toBe("install -y curl\n");+ expect(result.stdout).toContain("Installing required Linux system tools");+ expect(result.stdout.indexOf("system tools")).toBeLessThan(+ result.stdout.indexOf("tmux ready"),+ );+ } finally {+ rmSync(scratch, { recursive: true, force: true });+ }+ });++ it("installs tmux through sudo without refreshing usable package indexes", () => {+ const source = readFileSync(installer, "utf8");+ const tmuxStep = source.slice(+ source.indexOf("apt_as_root()"),+ source.indexOf("# 2. Resolve the Node"),+ );+ const scratch = mkdtempSync(join(tmpdir(), "harness-tmux-user-"));+ const invocation = join(scratch, "sudo-invocation");+ const fakeTmux = join(scratch, "tmux");++ try {+ writeLinuxBaseCommands(scratch);+ writeCommand(scratch, "id", ["printf '1000\\n'"]);+ writeCommand(scratch, "uname", ["printf 'Linux\\n'"]);+ writeCommand(scratch, "apt-get", ["exit 99"]);+ writeCommand(scratch, "sudo", [+ `printf '%s\\n' "$*" > '${invocation}'`,+ `printf '%s\\n' '#!/bin/sh' 'printf "tmux 3.6\\\\n"' > '${fakeTmux}'`,+ `/bin/chmod 700 '${fakeTmux}'`,+ ]);++ const result = spawnSync("/bin/sh", ["-c", tmuxStep], {+ encoding: "utf8",+ env: { ...process.env, INSTALL_MODE: "standalone", PATH: scratch },+ });++ expect(result.status).toBe(0);+ expect(readFileSync(invocation, "utf8")).toBe("apt-get install -y tmux\n");+ expect(result.stdout).toContain("tmux ready");+ } finally {+ rmSync(scratch, { recursive: true, force: true });+ }+ });++ it("installs as root without sudo and retries after a failed index refresh", () => {+ const source = readFileSync(installer, "utf8");+ const tmuxStep = source.slice(+ source.indexOf("apt_as_root()"),+ source.indexOf("# 2. Resolve the Node"),+ );+ const scratch = mkdtempSync(join(tmpdir(), "harness-tmux-root-"));+ const invocations = join(scratch, "apt-invocations");+ const firstAttempt = join(scratch, "first-attempt");+ const fakeTmux = join(scratch, "tmux");++ try {+ writeLinuxBaseCommands(scratch);+ writeCommand(scratch, "id", ["printf '0\\n'"]);+ writeCommand(scratch, "uname", ["printf 'Linux\\n'"]);+ writeCommand(scratch, "apt-get", [+ `printf '%s\\n' "$*" >> '${invocations}'`,+ `if [ "$1" = "update" ]; then exit 77; fi`,+ `if [ ! -f '${firstAttempt}' ]; then : > '${firstAttempt}'; exit 1; fi`,+ `printf '%s\\n' '#!/bin/sh' 'printf "tmux 3.6\\\\n"' > '${fakeTmux}'`,+ `/bin/chmod 700 '${fakeTmux}'`,+ ]);++ const result = spawnSync("/bin/sh", ["-c", tmuxStep], {+ encoding: "utf8",+ env: { ...process.env, INSTALL_MODE: "standalone", PATH: scratch },+ });++ expect(result.status).toBe(0);+ expect(readFileSync(invocations, "utf8")).toBe(+ "install -y tmux\nupdate\ninstall -y tmux\n",+ );+ expect(result.stdout).toContain("tmux ready");+ } finally {+ rmSync(scratch, { recursive: true, force: true });+ }+ });++ it("requires only the active Linux desktop clipboard helper before Node", () => {+ const source = readFileSync(installer, "utf8");+ const wayland = source.indexOf('clipboard_command="wl-copy"');+ const x11 = source.indexOf('clipboard_command="xclip"');+ const nodeStep = source.indexOf("# 2. Resolve the Node");++ expect(wayland).toBeGreaterThan(-1);+ expect(x11).toBeGreaterThan(wayland);+ expect(nodeStep).toBeGreaterThan(x11);+ expect(source).toContain('if [ -n "${WAYLAND_DISPLAY:-}" ]; then');+ expect(source).toContain('elif [ -n "${DISPLAY:-}" ]; then');+ expect(source).toContain('exit 23');+ expect(source).not.toContain("install_with_apt xclip wl-clipboard");+ });++ it("installs xclip for X11 and verifies it", () => {+ const source = readFileSync(installer, "utf8");+ const hostSetup = source.slice(+ source.indexOf("apt_as_root()"),+ source.indexOf("# 2. Resolve the Node"),+ );+ const scratch = mkdtempSync(join(tmpdir(), "harness-xclip-root-"));+ const invocations = join(scratch, "apt-invocations");+ const fakeXclip = join(scratch, "xclip");++ try {+ writeLinuxBaseCommands(scratch);+ writeCommand(scratch, "id", ["printf '0\\n'"]);+ writeCommand(scratch, "uname", ["printf 'Linux\\n'"]);+ writeCommand(scratch, "tmux", ["printf 'tmux 3.6\\n'"]);+ writeCommand(scratch, "apt-get", [+ `printf '%s\\n' "$*" >> '${invocations}'`,+ `printf '%s\\n' '#!/bin/sh' 'exit 0' > '${fakeXclip}'`,+ `/bin/chmod 700 '${fakeXclip}'`,+ ]);++ const result = spawnSync("/bin/sh", ["-c", hostSetup], {+ encoding: "utf8",+ env: {+ ...process.env,+ INSTALL_MODE: "standalone",+ DISPLAY: ":0",+ WAYLAND_DISPLAY: "",+ PATH: scratch,+ },+ });++ expect(result.status).toBe(0);+ expect(readFileSync(invocations, "utf8")).toBe("install -y xclip\n");+ expect(result.stdout).toContain("Linux image clipboard ready (xclip)");+ } finally {+ rmSync(scratch, { recursive: true, force: true });+ }+ });++ it("does not install clipboard packages on a headless Linux host", () => {+ const source = readFileSync(installer, "utf8");+ const hostSetup = source.slice(+ source.indexOf("apt_as_root()"),+ source.indexOf("# 2. Resolve the Node"),+ );+ const scratch = mkdtempSync(join(tmpdir(), "harness-headless-root-"));+ const invoked = join(scratch, "apt-invoked");++ try {+ writeLinuxBaseCommands(scratch);+ writeCommand(scratch, "id", ["printf '0\\n'"]);+ writeCommand(scratch, "uname", ["printf 'Linux\\n'"]);+ writeCommand(scratch, "tmux", ["printf 'tmux 3.6\\n'"]);+ writeCommand(scratch, "apt-get", [`: > '${invoked}'`, "exit 99"]);++ const result = spawnSync("/bin/sh", ["-c", hostSetup], {+ encoding: "utf8",+ env: {+ ...process.env,+ INSTALL_MODE: "standalone",+ DISPLAY: "",+ WAYLAND_DISPLAY: "",+ PATH: scratch,+ },+ });++ expect(result.status).toBe(0);+ expect(result.stdout).toContain("native image clipboard is not applicable");+ expect(() => readFileSync(invoked, "utf8")).toThrow();+ } finally {+ rmSync(scratch, { recursive: true, force: true });+ }+ });++ it("fails before Node when the active Wayland helper cannot be installed", () => {+ const source = readFileSync(installer, "utf8");+ const hostSetup = source.slice(+ source.indexOf("apt_as_root()"),+ source.indexOf("# 2. Resolve the Node"),+ );+ const scratch = mkdtempSync(join(tmpdir(), "harness-wayland-fail-"));++ try {+ writeLinuxBaseCommands(scratch);+ writeCommand(scratch, "id", ["printf '0\\n'"]);+ writeCommand(scratch, "uname", ["printf 'Linux\\n'"]);+ writeCommand(scratch, "tmux", ["printf 'tmux 3.6\\n'"]);+ writeCommand(scratch, "apt-get", ["exit 88"]);++ const result = spawnSync("/bin/sh", ["-c", hostSetup], {+ encoding: "utf8",+ env: {+ ...process.env,+ INSTALL_MODE: "standalone",+ DISPLAY: ":0",+ WAYLAND_DISPLAY: "wayland-0",+ PATH: scratch,+ },+ });++ expect(result.status).toBe(23);+ expect(result.stderr).toContain("Could not install wl-clipboard");+ expect(result.stderr).not.toContain("xclip");+ } finally {+ rmSync(scratch, { recursive: true, force: true });+ }+ });++ it("desktop mode skips all host package and tmux work", () => {+ const source = readFileSync(installer, "utf8");+ const hostSetup = source.slice(+ source.indexOf("apt_as_root()"),+ source.indexOf("# 2. Resolve the Node"),+ );+ const scratch = mkdtempSync(join(tmpdir(), "harness-desktop-mode-"));+ const invoked = join(scratch, "host-command-invoked");++ try {+ for (const command of ["uname", "sudo", "apt-get", "tmux", "brew"]) {+ writeCommand(scratch, command, [`: > '${invoked}'`, "exit 99"]);+ }++ const result = spawnSync("/bin/sh", ["-c", hostSetup], {+ encoding: "utf8",+ env: { ...process.env, INSTALL_MODE: "desktop", PATH: scratch },+ });++ expect(result.status).toBe(0);+ expect(result.stdout).toContain("Desktop mode");+ expect(() => readFileSync(invoked, "utf8")).toThrow();+ } finally {+ rmSync(scratch, { recursive: true, force: true });+ }+ });+});