@bongos/core 1.24.76 → 1.24.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env bash
2
+ # scripts/bongos/autobongos-bootstrap.sh — the first lines of Autobongos setup on
3
+ # a Mac (task 1005095, goal 1000139). The Windows twin is autobongos-bootstrap.ps1.
4
+ #
5
+ # autobongos-bootstrap.sh --code abr_… --api-base https://… --repo https://github.com/owner/name
6
+ #
7
+ # WHY THIS IS SHELL AND SO SHORT. Everything that sets a runner up is one Node
8
+ # program (autobongos-host.js), the same on Windows and Mac. But Node cannot
9
+ # install Node, and the program lives in a copy of the project that does not exist
10
+ # yet. So this does only what must happen before Node can take over: find or
11
+ # install git, Node and Claude Code, make the runner ITS OWN copy of the project,
12
+ # and hand over.
13
+ #
14
+ # NO sudo, ANYWHERE. git comes from Apple's own command-line tools (macOS asks
15
+ # with its own window), Node is unpacked into the runner's folder when the Mac has
16
+ # none, and Claude Code installs into the person's own account.
17
+ #
18
+ # EVERY STOP IS A SENTENCE: what happened and what to do, never raw tool output.
19
+ # Safe to run again — each step checks before it acts.
20
+ #
21
+ # It also runs on Linux, where the runner then has no start-at-sign-in entry (the
22
+ # goal covers Windows and Mac); that is what lets CI exercise this file.
23
+
24
+ set -u
25
+
26
+ CODE=""; API_BASE=""; REPO=""; DRY_RUN=0
27
+ RUNNER_HOME="${AUTOBONGOS_HOME:-$HOME/.cloudbongos-runner}"
28
+
29
+ stop_setup() {
30
+ printf '\nAutobongos setup stopped here: %s\nWhat to do: %s\n' "$1" "$2" >&2
31
+ exit 1
32
+ }
33
+
34
+ while [ $# -gt 0 ]; do
35
+ case "$1" in
36
+ --code) CODE="${2:-}"; shift 2 ;;
37
+ --api-base) API_BASE="${2:-}"; shift 2 ;;
38
+ --repo) REPO="${2:-}"; shift 2 ;;
39
+ --home) RUNNER_HOME="${2:-}"; shift 2 ;;
40
+ --dry-run) DRY_RUN=1; shift ;;
41
+ *) shift ;;
42
+ esac
43
+ done
44
+
45
+ if [ -z "$CODE" ] || [ -z "$API_BASE" ] || [ -z "$REPO" ]; then
46
+ stop_setup "the setup command is incomplete." "Copy the whole command again from Settings > Your Autobongos runner."
47
+ fi
48
+ case "$REPO" in
49
+ https://*) : ;;
50
+ *) stop_setup "the project address in the command does not look right." "Copy the whole command again from Settings > Your Autobongos runner." ;;
51
+ esac
52
+ # The one-time code is sent to this address and the runner's login comes back
53
+ # from it, so it must be https. Plain http is for this machine alone (a
54
+ # developer's own instance); autobongos-host.js applies the same rule again.
55
+ case "$API_BASE" in
56
+ https://*|http://localhost|http://localhost:*|http://127.0.0.1|http://127.0.0.1:*) : ;;
57
+ *) stop_setup "the project's address in the command is not a secure (https) address." "Copy the whole command again from Settings > Your Autobongos runner." ;;
58
+ esac
59
+
60
+ have() { command -v "$1" >/dev/null 2>&1; }
61
+
62
+ # The setup command is piped into bash, so the keyboard is /dev/tty, not stdin.
63
+ # OPENED, not just tested: with no terminal at all (CI, a remote command) the
64
+ # device node still exists and reads as readable, and opening it is what fails.
65
+ if { true </dev/tty; } 2>/dev/null; then HAVE_TTY=1; else HAVE_TTY=0; fi
66
+
67
+ echo "Setting this device up as an Autobongos runner."
68
+ echo "It gets its own copy of the project and its own sign-in; your own work here is not touched."
69
+ echo
70
+ echo "Checking the three programs it needs..."
71
+
72
+ # --- git ---------------------------------------------------------------------
73
+ # On a Mac /usr/bin/git exists even with no tools installed (it is a stub that
74
+ # opens the installer), so ask xcode-select, not the PATH.
75
+ if [ "$(uname -s)" = "Darwin" ] && ! xcode-select -p >/dev/null 2>&1; then
76
+ if [ "$DRY_RUN" = 1 ]; then echo " would install Apple's command-line tools (git)"
77
+ else
78
+ xcode-select --install >/dev/null 2>&1 || true
79
+ stop_setup "this Mac needs Apple's command-line tools, which include git." "A window has opened asking to install them. Press Install, wait for it to finish, then paste the setup command again."
80
+ fi
81
+ elif have git; then echo " found git"
82
+ elif [ "$DRY_RUN" = 1 ]; then echo " would need git"
83
+ else stop_setup "git is not installed." "Install git, open a new terminal window, and paste the setup command again."
84
+ fi
85
+
86
+ # --- node --------------------------------------------------------------------
87
+ # Unpacked into the runner's own folder when the device has none: no installer,
88
+ # no password, and removing the runner removes it.
89
+ NODE_DIR="$RUNNER_HOME/node"
90
+ if [ -x "$NODE_DIR/bin/node" ]; then PATH="$NODE_DIR/bin:$PATH"; fi
91
+ if have node; then echo " found node"
92
+ elif [ "$DRY_RUN" = 1 ]; then echo " would install Node into $NODE_DIR"
93
+ else
94
+ echo " installing Node into the runner's folder..."
95
+ case "$(uname -s)" in Darwin) NODE_OS=darwin ;; Linux) NODE_OS=linux ;; *) NODE_OS="" ;; esac
96
+ case "$(uname -m)" in arm64|aarch64) NODE_ARCH=arm64 ;; x86_64|amd64) NODE_ARCH=x64 ;; *) NODE_ARCH="" ;; esac
97
+ if [ -z "$NODE_OS" ] || [ -z "$NODE_ARCH" ]; then
98
+ stop_setup "Node is not installed, and this kind of device is not one this setup can install it on." "Install Node from https://nodejs.org, open a new terminal window, and paste the setup command again."
99
+ fi
100
+ NODE_BASE="https://nodejs.org/dist/latest-v22.x"
101
+ NODE_TAR="$(curl -fsSL "$NODE_BASE/SHASUMS256.txt" 2>/dev/null | awk '{print $2}' | grep -E "^node-v[0-9.]+-${NODE_OS}-${NODE_ARCH}\.tar\.gz$" | head -n 1)"
102
+ if [ -z "$NODE_TAR" ]; then
103
+ stop_setup "Node could not be downloaded." "Check this device is online, or install Node from https://nodejs.org, then paste the setup command again."
104
+ fi
105
+ mkdir -p "$NODE_DIR"
106
+ if ! curl -fsSL "$NODE_BASE/$NODE_TAR" | tar -xz -C "$NODE_DIR" --strip-components 1; then
107
+ stop_setup "Node could not be unpacked." "Install Node from https://nodejs.org, open a new terminal window, and paste the setup command again."
108
+ fi
109
+ PATH="$NODE_DIR/bin:$PATH"
110
+ have node || stop_setup "Node did not install." "Install Node from https://nodejs.org, open a new terminal window, and paste the setup command again."
111
+ echo " installed node"
112
+ fi
113
+
114
+ # --- claude ------------------------------------------------------------------
115
+ if [ -x "$HOME/.local/bin/claude" ]; then PATH="$HOME/.local/bin:$PATH"; fi
116
+ if have claude; then echo " found claude"
117
+ elif [ "$DRY_RUN" = 1 ]; then echo " would install Claude Code"
118
+ else
119
+ echo " installing Claude Code..."
120
+ npm install -g @anthropic-ai/claude-code >/dev/null 2>&1 || true
121
+ have claude || stop_setup "Claude Code did not install." "Install it from https://claude.com/claude-code, open a new terminal window, and paste the setup command again."
122
+ echo " installed Claude Code"
123
+ fi
124
+
125
+ REPO_DIR="$RUNNER_HOME/repo"
126
+ echo
127
+ if [ "$DRY_RUN" = 1 ]; then
128
+ echo "Would make the runner's copy of the project in $REPO_DIR and hand over to autobongos-host.js."
129
+ exit 0
130
+ fi
131
+
132
+ mkdir -p "$RUNNER_HOME"
133
+ if [ -d "$REPO_DIR/.git" ]; then
134
+ echo "The runner's copy is already here; bringing it up to date..."
135
+ if [ "$HAVE_TTY" = 1 ]; then git -C "$REPO_DIR" fetch --quiet origin main </dev/tty; else git -C "$REPO_DIR" fetch --quiet origin main; fi \
136
+ || stop_setup "this device could not fetch the project's code from GitHub." "Sign in to GitHub on this device (the GitHub CLI's gh auth login is the simplest way), then paste the setup command again."
137
+ git -C "$REPO_DIR" reset --quiet --hard origin/main
138
+ else
139
+ echo "Making the runner's own copy of the project (GitHub may ask you to sign in)..."
140
+ if [ "$HAVE_TTY" = 1 ]; then git clone --quiet "$REPO" "$REPO_DIR" </dev/tty; else git clone --quiet "$REPO" "$REPO_DIR"; fi \
141
+ || stop_setup "this device could not copy the project from GitHub." "Sign in to GitHub on this device with an account that can see the project (the GitHub CLI's gh auth login is the simplest way), then paste the setup command again."
142
+ fi
143
+
144
+ HOST_JS="$REPO_DIR/scripts/bongos/autobongos-host.js"
145
+ [ -f "$HOST_JS" ] || stop_setup "the project's copy has no runner program in it." "The project is on an older version. Ask the project owner to update it, then try again."
146
+
147
+ export AUTOBONGOS_HOME="$RUNNER_HOME" PATH
148
+ if [ "$HAVE_TTY" = 1 ]; then
149
+ exec node "$HOST_JS" setup --code "$CODE" --api-base "$API_BASE" --mark-runner-copy </dev/tty
150
+ fi
151
+ exec node "$HOST_JS" setup --code "$CODE" --api-base "$API_BASE" --mark-runner-copy