# AI Dev Assistant: the install for Mac and Linux. Paste this line into a terminal (no administrator rights needed): # curl -fsSL https://ai-dev-assistant.agile-clouds.com/install.sh | sh # For this user only, into ~/Library/Application Support/AI Dev Assistant on a Mac or ~/.local/share/ai-dev-assistant # on Linux. A fresh graphical computer gets Node 22, the signed assistant and its setup launcher; setup adds the tools # the person chooses. Git is needed # and never installed (that needs administrator rights). # Programs already on this computer are left as they are, and so are your sign-ins. Nothing starts with the system. # For a test, set first: ADA_DASHBOARD, ADA_INSTALL_DIR, ADA_NAME, ADA_PROJECTS_DIR, ADA_OWN_TOOLS=1, ADA_DRY_RUN=1 # (for example: curl -fsSL /install.sh | ADA_DRY_RUN=1 sh). # The dashboard serves this file with its own address in Dashboard below. POSIX sh, plain ASCII, LF line ends. The # whole script is one function called on its last line, so a download cut short runs nothing. install_ai_dev_assistant() { # Piped into sh, this script is everyone's standard input: no program it starts may read it. exec &2; return 1 ;; esac # Hidden setup operations reuse the ordinary install's pins, destinations and checks. Window=${ADA_WINDOW_CAPABILITY:-0} SetupTool=${ADA_SETUP_TOOL:-} if [ -n "$SetupTool" ] && [ "$Window" != 1 ]; then printf '%s\n' 'Setup operations need the window capability' >&2; return 1; fi if [ "$Window" = 1 ]; then if [ -n "$AddAI" ]; then printf '%s\n' 'Choose one installer operation' >&2; return 1; fi SetupTool=${SetupTool:-bootstrap} case $SetupTool in bootstrap) ;; claude|codex|both|github) AddAI=$SetupTool ;; launchers) ;; *) printf '%s\n' 'Choose a setup tool' >&2; return 1 ;; esac fi # Pinned by the lead for each release. Do not replace these with a latest-release address. NodeVersion='22.23.3' CodexVersion='0.162.1' CodexSha='0b4b2e33a65883e4f69c903484d8dd7770b3cb8b324f520068b6fd85d42b65ea' # Keep Windows' pins here too, so both installers record the same seven archives. # shellcheck disable=SC2034 CodexWin32X64Sha='5d48824f11a512b0ecb351461c2e90a1040c80de1026bc4a80815d5121f3936d' # shellcheck disable=SC2034 CodexWin32Arm64Sha='afff97ae0c9e7e8ab3d76b1bcfede968da0dec314b6b093265281dbcd56a4355' CodexDarwinX64Sha='e4f53d69d399f1086eb35bc3a47786cbd03dd1f92c85e8217258e36f1470f5ec' CodexDarwinArm64Sha='fe0370027a05237adc0152b482ad8502321f6f9aff1baca3bfa56588923ba9ad' CodexLinuxX64Sha='7417711678b464eee70664126e39e88bb3c84c2928da0e71f14b56e04ff5c09f' CodexLinuxArm64Sha='a355051d0c296ed50e42e55aceabf74f017f2f96e223fc7ee2199ea8a60cad4b' GhVersion='2.102.0' Agent='AI-Dev-Assistant-install' NL=' ' if [ -t 2 ]; then Red=$(printf '\033[31m'); Plain=$(printf '\033[0m'); else Red=''; Plain=''; fi say() { printf '%s\n' "$1"; } setup_phase() { if { [ "$Window" = 1 ] || [ -n "$AddAI" ]; } && [ "$Dry" != 1 ]; then say "ADA_SETUP_PHASE:$1:$2"; fi; } # Its words go to stderr: a step that runs in $(...) cannot swallow them. Piped into sh, exit ends only the install. stop() { printf '\n%sThe install stopped: %s.%s\n' "$Red" "$1" "$Plain" >&2 say 'Paste the command again to continue: what is already installed is kept.' >&2 exit 1 } # "download Node 22 from nodejs.org" reads "Downloading Node 22 from nodejs.org..." while it happens. doing() { verb=${1%% *} rest=${1#* } case $verb in download) verb=Downloading ;; install) verb=Installing ;; make) verb=Making ;; write) verb=Writing ;; read) verb=Reading ;; start) verb=Starting ;; check) verb=Checking ;; copy) verb=Copying ;; replace) verb=Replacing ;; esac printf '%s %s' "$verb" "$rest" } # Every change goes through here, so a dry run shows each step and changes nothing. change() { if [ "$Dry" = 1 ]; then say "would $1"; return 0; fi say "$(doing "$1")..." "$2" } # A string in single quotes, for the launcher. quote() { printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")"; } # One line that matches the whole of an extended regular expression. matches() { case $1 in *"$NL"*) return 1 ;; esac printf '%s\n' "$1" | LC_ALL=C grep -Eqx -- "$2" } under_mnt() { case $1 in /mnt | /mnt/*) return 0 ;; esac; return 1; } # Where a path really leads: its links followed (one that leads nowhere yet too), its . and .. taken, the part that # does not exist yet as it will be made. Nothing is made to find it. More than 40 links: they go round in a circle. physical() { todo=$1 case $todo in /*) ;; *) todo="$PWD/$todo" ;; esac real='' links=0 while [ -n "$todo" ]; do part=${todo%%/*} case $todo in */*) todo=${todo#*/} ;; *) todo='' ;; esac case $part in '' | .) ;; ..) real=${real%/*} ;; *) if [ -L "$real/$part" ]; then links=$((links + 1)) if [ "$links" -gt 40 ]; then return 1; fi target=$(readlink "$real/$part") || return 1 case $target in /*) real='' ;; esac todo="$target/$todo" else real="$real/$part" fi ;; esac done printf '%s\n' "${real:-/}" } # On WSL, Linux's programs and projects stay in Linux's own files: a Windows drive is slow, and loses file modes. # The folder is checked where it really leads, so a link or a .. onto a Windows drive is refused too. linux_only() { real=$(physical "$1") || stop "the folder $1 cannot be reached: its links go round in a circle" if under_mnt "$real"; then where=$1 if [ "$real" != "$1" ]; then where="$1, which is $real"; fi stop "on WSL, $2 Linux's own files, not a Windows drive ($where): set $3 to a folder in your Linux home" fi } sha_of() { if [ "$Os" = mac ]; then shasum -a 256 "$1" | cut -d ' ' -f 1; else sha256sum "$1" | cut -d ' ' -f 1; fi } check_sha() { if [ "$(sha_of "$1")" != "$2" ]; then rm -f "$1" stop "the download ${1##*/} is damaged (its checksum does not match): nothing was installed from it" fi } download() { mkdir -p "${2%/*}" || stop "the folder ${2%/*} could not be made" curl -fsSL -A "$Agent" -o "$2" "$1" || stop "the download $1 failed: try again later" } # A program on this computer, or nothing. With ADA_OWN_TOOLS=1 only this install's own tools count (a test install # beside the computer's own programs). On WSL a Windows program (under /mnt/) never counts. found() { p=$(command -v "$1" 2>/dev/null) || return 1 case $p in /*) ;; *) return 1 ;; esac if [ "$Wsl" = 1 ] && under_mnt "$p"; then return 1; fi if [ "$Own" = 1 ]; then case $p in "$Tools"/*) ;; *) return 1 ;; esac; fi printf '%s\n' "$p" } # The processor's name in Node's files: uname -m's x86_64 is x64, aarch64 and arm64 are arm64. A Mac that answers # x86_64 while it has an Apple processor runs this terminal under Rosetta: it gets the faster arm64 programs. processor() { case $(uname -m) in x86_64 | amd64) if [ "$Os" = mac ] && [ "$(sysctl -n hw.optional.arm64 2>/dev/null)" = 1 ]; then echo arm64; else echo x64; fi ;; aarch64 | arm64) echo arm64 ;; *) return 1 ;; esac } # The system: macOS 13 or later, or Linux with glibc, on x64 or arm64. case $(uname -s) in Darwin) Os=mac ;; Linux) Os=linux ;; *) stop 'AI Dev Assistant installs with this command on a Mac or on Linux (on Windows: the PowerShell command)' ;; esac Wsl=0 if [ "$Os" = linux ]; then if [ -n "${WSL_DISTRO_NAME:-}" ] || grep -qi microsoft /proc/sys/kernel/osrelease 2>/dev/null; then Wsl=1; fi fi Arch=$(processor) || stop "this computer's processor ($(uname -m)) is not one AI Dev Assistant runs on: it needs x64 or arm64" if [ "$Os" = mac ]; then macos=$(sw_vers -productVersion 2>/dev/null) case ${macos%%.*} in '' | *[!0-9]*) macos_major=0 ;; *) macos_major=${macos%%.*} ;; esac if [ "$macos_major" -lt 13 ]; then stop "AI Dev Assistant needs macOS 13 or later (this Mac has ${macos:-an older one})"; fi elif ! getconf GNU_LIBC_VERSION >/dev/null 2>&1; then stop 'AI Dev Assistant needs a Linux with glibc (Ubuntu, Debian, Fedora and most others; not Alpine)' fi if [ -z "${HOME:-}" ]; then stop 'HOME is not set, so the install does not know where your files are'; fi if [ "$Os" = mac ]; then Dir="$HOME/Library/Application Support/$Name" else Dir="${XDG_DATA_HOME:-$HOME/.local/share}/$(printf '%s' "$Name" | tr 'A-Z ' 'a-z-')" fi if [ -n "${ADA_INSTALL_DIR:-}" ]; then Dir=$ADA_INSTALL_DIR case $Dir in /*) ;; *) Dir="$PWD/$Dir" ;; esac while [ "${Dir%/}" != "$Dir" ]; do Dir=${Dir%/}; done fi # The launcher starts the assistant in app/: a projects folder given from here is named in full. case $ProjectsDir in '' | /*) ;; *) ProjectsDir="$PWD/$ProjectsDir" ;; esac App="$Dir/app" Tools="$Dir/tools" Downloads="$Dir/downloads" Launcher="$Dir/ai-dev-assistant" Uninstall="$Dir/uninstall" # Every ordinary install uses local setup and the background launcher. AutoWindow=0 if [ "$Window" != 1 ] && [ -z "$AddAI" ]; then Window=1 SetupTool=bootstrap AutoWindow=1 fi say "AI Dev Assistant: installing for ${USER:-$(id -un)} into $Dir" if [ "$Dry" = 1 ]; then say '(a dry run: every step is shown; nothing is downloaded or changed)'; fi # The names go into the launcher: plain characters only. matches "$Name" '[A-Za-z0-9]([A-Za-z0-9 ._-]*[A-Za-z0-9])?' || stop 'ADA_NAME may hold only letters, digits, spaces, dots, dashes and underscores' matches "$Dashboard" 'https?://[A-Za-z0-9.-]+(:[0-9]+)?(/[A-Za-z0-9._~/-]*)?' || stop "the dashboard's address is not one this install can use ($Dashboard)" if [ -n "$ProjectsDir" ] && ! matches "$ProjectsDir" '[ -~]+'; then stop 'ADA_PROJECTS_DIR may hold only plain characters'; fi matches "$Dir" '[ -~]+' || stop "the folder $Dir has a character this install cannot use: set ADA_INSTALL_DIR to another one" if [ "$Wsl" = 1 ]; then linux_only "$Dir" 'AI Dev Assistant goes into' ADA_INSTALL_DIR # Check the same default place the PC will use for new clones. projects=${ProjectsDir:-$HOME/aidevassistant} linux_only "$projects" 'the projects stay in' ADA_PROJECTS_DIR fi if [ "$SetupTool" != launchers ]; then command -v curl >/dev/null 2>&1 || stop 'curl is needed and was not found'; fi # A copy running from this folder is stopped first: its files are about to be replaced. if [ -z "$AddAI" ] && [ "$SetupTool" != launchers ] && command -v pgrep >/dev/null 2>&1 && pgrep -f "$(printf '%s' "$App/bin/conductor.js" | sed 's/[][\.*^$+?(){}|]/\\&/g')" >/dev/null 2>&1; then stop "$Name is running: stop it first (Your PC, Stop the assistant; Ctrl+C where it runs in a terminal), then paste the command again" fi # The folder owns its name. Read old installer output as text, never as a shell program, before the first change. # Only an explicit internal operation may recover a name when an older launcher did not export ADA_NAME. AdoptInstallName=0 if [ -z "${ADA_NAME:-}" ] && { [ -n "${ADA_ADD_AI:-}" ] || [ -n "${ADA_SETUP_TOOL:-}" ]; }; then AdoptInstallName=1; fi check_install_name() { matches "$1" '[A-Za-z0-9]([A-Za-z0-9 ._-]*[A-Za-z0-9])?' || stop "the install name in $Dir could not be read: nothing was changed" if [ "$AdoptInstallName" = 1 ]; then Name=$1 AdoptInstallName=0 fi if [ "$1" != "$Name" ]; then stop "the folder $Dir is installed as $1; you asked for $Name: run it again with the folder's own name (ADA_NAME='$1')" fi } InstallName="$Dir/install-name" if [ -e "$InstallName" ]; then saved_name=$(cat "$InstallName") || stop "the install name in $Dir could not be read: nothing was changed" check_install_name "$saved_name" else # The earlier Uninstall's own line, matched as text (never expanded): before B134, or since. # shellcheck disable=SC2016 if [ -f "$Uninstall" ] && grep -Fx -e 'dir=$(cd "$(dirname "$0")" && pwd -P) || exit 1' -e 'dir=$(cd "$dir" && pwd -P) || exit 1' "$Uninstall" >/dev/null; then old_name=$(sed -n "s/^name='\([A-Za-z0-9 ._-]*\)'$/\1/p" "$Uninstall") if [ -n "$old_name" ]; then check_install_name "$old_name"; fi fi # The earlier launcher's own line, matched as text (never expanded). # shellcheck disable=SC2016 if [ -f "$Launcher" ] && grep -Fx 'cd "$dir/app" || exit 1' "$Launcher" >/dev/null; then old_name=$(sed -n 's/^# \(.*\): starts the assistant\. Written by its install; the install writes it again\.$/\1/p' "$Launcher") if [ -n "$old_name" ]; then check_install_name "$old_name"; fi fi # Apps and menu entries carry the name too. Count only ones whose start points at this exact launcher. for old_app in "$HOME/Applications/"*.app "$HOME/Desktop/"*.app; do old_start="$old_app/Contents/MacOS/start" if [ -f "$old_start" ] && grep -Fx -e "exec $(quote "$Launcher")" -e "exec $(quote "$Launcher") --background-start" \ -e "exec osascript -e 'on run argv' -e 'tell application \"Terminal\" to do script (quoted form of item 1 of argv)' -e 'end run' $(quote "$Launcher")" "$old_start" >/dev/null; then old_name=$(sed -n 's|^CFBundleName\([^<]*\)$|\1|p' "$old_app/Contents/Info.plist") if [ -n "$old_name" ]; then check_install_name "$old_name"; fi fi done old_launcher=$(printf '%s' "$Launcher" | sed 's/[\\"]/\\&/g') for old_entry in "${XDG_DATA_HOME:-$HOME/.local/share}/applications/"*.desktop; do if [ -f "$old_entry" ] && grep -Fx -e "Exec=\"$old_launcher\"" -e "Exec=\"$old_launcher\" --background-start" "$old_entry" >/dev/null; then old_name=$(sed -n 's/^Name=//p' "$old_entry") if [ -n "$old_name" ]; then check_install_name "$old_name"; fi fi done save_install_name() { mkdir -p "$Dir" || stop "the folder $Dir could not be made" # Noclobber keeps a name another install just saved. Read it again before doing any more work. (set -C; printf '%s\n' "$Name" >"$InstallName") 2>/dev/null || { saved_name=$(cat "$InstallName") || stop "the install name in $Dir could not be saved: nothing was changed" check_install_name "$saved_name" } } change "write the install name $InstallName" save_install_name fi Slug=$(printf '%s' "$Name" | tr 'A-Z ' 'a-z-') MacApp="$HOME/Applications/$Name.app" MacDesktopApp="$HOME/Desktop/$Name.app" DesktopFile="${XDG_DATA_HOME:-$HOME/.local/share}/applications/$Slug.desktop" # Tools an earlier run installed here are found first, so running the command again keeps them. On WSL, Windows' # programs (under /mnt/, which WSL adds to PATH) are left out: npm or codex there would be the Windows ones. if [ "$Wsl" = 1 ]; then PATH=$(printf '%s\n' "$PATH" | tr ':' '\n' | grep -v '^/mnt$' | grep -v '^/mnt/' | tr '\n' ':') PATH=${PATH%:} fi PATH="$Tools/node/bin:$Tools/gh/bin:$Tools/codex/bin:$HOME/.local/bin:$PATH" export PATH if [ "$SetupTool" != launchers ]; then if [ -z "$AddAI" ]; then # The lead's public key is replaced here by the first signed release; it is not a secret. RELEASE_PUBLIC_KEY='LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUNvd0JRWURLMlZ3QXlFQThHUTJ0WmZxYzNaYzlNSDNTZkhXS2FrTVNUL0IvZGlNb0lvY2dmTHZoUTQ9Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQ==' # 1. What the dashboard carries: the assistant's version and its checksum. answer=$(curl -sSL -A "$Agent" -w '\n%{http_code}' "$Dashboard/install/manifest.json" 2>&1) || stop "the dashboard ($Dashboard) could not be reached: $(printf '%s\n' "$answer" | sed -n 's/^curl: ([0-9]*) //p' | head -n 1)" status=$(printf '%s' "$answer" | tail -n 1) if [ "$status" = 404 ]; then stop 'the assistant cannot be downloaded yet: paste the command again in an hour'; fi if [ "$status" != 200 ]; then stop "the dashboard ($Dashboard) could not be reached: it answered $status"; fi Version=$(printf '%s\n' "$answer" | sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)".*/\1/p' | head -n 1) Sha=$(printf '%s\n' "$answer" | sed -n 's/.*"sha256"[[:space:]]*:[[:space:]]*"\([0-9a-f]\{64\}\)".*/\1/p' | head -n 1) Size=$(printf '%s\n' "$answer" | sed -n 's/.*"size"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' | head -n 1) CodeHash=$(printf '%s\n' "$answer" | sed -n 's/.*"codeHash"[[:space:]]*:[[:space:]]*"\([0-9a-f]\{64\}\)".*/\1/p' | head -n 1) KeyId=$(printf '%s\n' "$answer" | sed -n 's/.*"keyId"[[:space:]]*:[[:space:]]*"\([0-9a-f-]*\)".*/\1/p' | head -n 1) Signature=$(printf '%s\n' "$answer" | sed -n 's#.*"signature"[[:space:]]*:[[:space:]]*"\([A-Za-z0-9+/=]*\)".*#\1#p' | head -n 1) if [ -z "$Version" ] || [ -z "$Sha" ]; then stop "the dashboard's answer about the assistant could not be read: try again later"; fi if [ -n "$RELEASE_PUBLIC_KEY" ] && { [ -z "$Size" ] || [ -z "$CodeHash" ] || [ -z "$KeyId" ] || [ -z "$Signature" ]; }; then stop "the dashboard's answer about the assistant could not be read: try again later"; fi # 2. Git: needed (the assistant keeps each task's work with it) and never installed (that needs administrator # rights), so it is checked before anything is downloaded. git_exe=$(command -v git 2>/dev/null) || git_exe='' if [ "$Wsl" = 1 ] && under_mnt "$git_exe"; then git_exe=''; fi if [ "$Os" = mac ]; then # /usr/bin/git on a Mac is only a stand-in until Apple's command line tools are installed. if [ -z "$git_exe" ] || { [ "$git_exe" = /usr/bin/git ] && ! xcode-select -p >/dev/null 2>&1; }; then stop "Git is needed: run xcode-select --install (Apple's command line tools, which include Git), then paste the command again" fi elif [ -z "$git_exe" ]; then if command -v apt-get >/dev/null 2>&1; then get='sudo apt install git' elif command -v dnf >/dev/null 2>&1; then get='sudo dnf install git' elif command -v pacman >/dev/null 2>&1; then get='sudo pacman -S git' else get='' fi if [ -n "$get" ]; then stop "Git is needed: run $get (it asks for your password), then paste the command again"; fi stop "Git is needed: install it with your system's package manager, then paste the command again" fi say 'Git: already on this computer, kept' # 3. Node 22, which runs the assistant (its npm installs Codex). NodeExe=$(found node) || NodeExe='' node_version='' if [ -n "$NodeExe" ]; then node_version=$("$NodeExe" --version 2>/dev/null) || node_version=''; fi node_major=${node_version#v} node_major=${node_major%%.*} case $node_major in '' | *[!0-9]*) node_major=0 ;; esac if [ "$node_major" -ge 22 ]; then say "Node 22: already on this computer ($node_version), kept" else NodeExe="$Tools/node/bin/node" node_os=linux if [ "$Os" = mac ]; then node_os=darwin; fi install_node() { file="node-v$NodeVersion-$node_os-$Arch.tar.gz" case "$node_os-$Arch" in linux-x64) sha='1084aa36196bba4c3a5e69a1ee388a6e4ff729dad09445fbcd434b28fe3c24af' ;; linux-arm64) sha='5ced2d48d1d7198739b7f86804de0171aefb6823b684b12341d3321afc3cb0b2' ;; darwin-x64) sha='8a677b0219178efd6eb0e475457c4afb452b521a92f6e67845a73bd85727f2a8' ;; darwin-arm64) sha='23b25245dcfb9af7262f8ff142e9e2e0af025368117329e7a7458a51e5922f53' ;; esac download "https://nodejs.org/dist/v$NodeVersion/$file" "$Downloads/$file" check_sha "$Downloads/$file" "$sha" rm -rf "${Downloads:?}/node" mkdir -p "$Downloads/node" || stop "the folder $Downloads/node could not be made" tar -xzf "$Downloads/$file" -C "$Downloads/node" || stop 'Unpacking Node 22 failed' rm -rf "${Tools:?}/node" mkdir -p "$Tools" || stop "the folder $Tools could not be made" mv "$Downloads/node/${file%.tar.gz}" "$Tools/node" || stop 'Node 22 was unpacked, but could not be moved into place' rm -rf "${Downloads:?}/node" "${Downloads:?}/$file" "$NodeExe" --version >/dev/null || stop 'Node 22 was installed, but does not start on this computer' say "Node 22: checked, installed ($file)" } change "download Node $NodeVersion for $node_os-$Arch from nodejs.org" install_node fi check_release() { if [ -z "$RELEASE_PUBLIC_KEY" ]; then return; fi if ! "$NodeExe" -e "const c=require('node:crypto'),p=Buffer.from(process.argv[1],'base64'),m=process.argv.slice(2,6),s=Buffer.from(process.argv[6],'base64'),k=c.createPublicKey(p.toString()),f=c.createHash('sha256').update(k.export({type:'spki',format:'der'})).digest('hex').match(/.{1,4}/g).slice(0,4).join('-');process.exit(f===process.argv[7]&&c.verify(null,Buffer.from(['version','sha256','size','codeHash'].map((k,i)=>k+':'+m[i]).join('\\n')),k,s)?0:1)" "$RELEASE_PUBLIC_KEY" "$Version" "$Sha" "$Size" "$CodeHash" "$Signature" "$KeyId"; then stop "this release is not signed with AI Dev Assistant's key: nothing was installed" fi say "AI Dev Assistant release key $KeyId: checked" } change "check AI Dev Assistant $Version with release key $KeyId" check_release # The local setup only with a package that says it has the complete setup window: its package.json, inside the # archive whose checksum the signed manifest holds, checked here before the path is chosen. An older package, or one # this cannot read, gets today's full install. The archive is kept for step 7. AppDownloaded=0 if [ "$AutoWindow" = 1 ]; then if [ "$Dry" = 1 ]; then say "would check that AI Dev Assistant $Version opens its setup in your browser" else download "$Dashboard/install/ai-dev-assistant.tgz" "$Downloads/ai-dev-assistant.tgz" check_sha "$Downloads/ai-dev-assistant.tgz" "$Sha" AppDownloaded=1 if ! "$NodeExe" -e 'try{const b=require("node:zlib").gunzipSync(require("node:fs").readFileSync(process.argv[1]),{maxOutputLength:67108864});for(let a=0;a+512<=b.length;){const h=b.subarray(a,a+512);if(h.every(x=>x===0))break;const p=h.toString("utf8",0,100).split("\0")[0],s=parseInt(h.toString("ascii",124,136),8);if(!Number.isSafeInteger(s)||s<0)break;if(p==="package.json")process.exit(JSON.parse(b.subarray(a+512,a+512+s)).aiDevAssistant?.window>=2?0:1);a+=512+Math.ceil(s/512)*512}}catch{}process.exit(1)' "$Downloads/ai-dev-assistant.tgz"; then stop 'this version could not open its setup on this PC: nothing was installed. Paste the command again later' fi fi fi else NodeExe=$(command -v node) || stop 'Node was not found beside the running assistant' fi # 4. GitHub CLI, unpacked into this folder. if { [ -z "$AddAI" ] && [ "$Window" != 1 ]; } || [ "$AddAI" = github ]; then if found gh >/dev/null; then setup_phase github already; say 'GitHub CLI: already on this computer, kept' else gh_arch=amd64 if [ "$Arch" = arm64 ]; then gh_arch=arm64; fi if [ "$Os" = mac ]; then gh_file="macOS_$gh_arch.zip"; gh_os="macOS $gh_arch"; else gh_file="linux_$gh_arch.tar.gz"; gh_os="Linux $gh_arch"; fi install_gh() { file="gh_${GhVersion}_$gh_file" case "$Os-$Arch" in linux-x64) sha='bb766f710eef8ede859c18578c72c327597cd4c8a85b06001b1f3843c6019386' ;; linux-arm64) sha='7862c86c72f43df3a2d93ddde6f473285b4e2af61b494849846827e513ef6484' ;; mac-x64) sha='b245f24eb2bf5f75b426b4c26da3651a107f8d5b6f4fddfbfccc5679041378b3' ;; mac-arm64) sha='da922c20d1792e5b2cbf375593d7a658acf034c12c84e007e71c76ef959c337e' ;; esac setup_phase github downloading download "https://github.com/cli/cli/releases/download/v$GhVersion/$file" "$Downloads/$file" check_sha "$Downloads/$file" "$sha" setup_phase github installing rm -rf "${Tools:?}/gh" mkdir -p "$Tools/gh" || stop "the folder $Tools/gh could not be made" # Its files are in one folder, gh___/: left out, so the program is tools/gh/bin/gh. # A Mac's tar reads its zip too. tar -xf "$Downloads/$file" -C "$Tools/gh" --strip-components 1 || stop 'Unpacking GitHub CLI failed' if [ ! -x "$Tools/gh/bin/gh" ]; then stop 'GitHub CLI was unpacked, but its program is missing'; fi rm -f "$Downloads/$file" say "GitHub CLI: checked, installed ($file)" setup_phase github installed } change "download GitHub CLI $GhVersion for $gh_os from GitHub" install_gh fi fi # 5. Codex: both archives checked against our pins before npm uses the local files offline. Its program starts with # "env node": the launcher puts this Node first. if { [ -z "$AddAI" ] && [ "$Window" != 1 ]; } || [ "$AddAI" = codex ] || [ "$AddAI" = both ]; then if found codex >/dev/null; then setup_phase codex already; say 'Codex: already on this computer, kept' else platform="$Os-$Arch" case $platform in mac-x64) platform=darwin-x64; platform_sha=$CodexDarwinX64Sha ;; mac-arm64) platform=darwin-arm64; platform_sha=$CodexDarwinArm64Sha ;; linux-x64) platform_sha=$CodexLinuxX64Sha ;; linux-arm64) platform_sha=$CodexLinuxArm64Sha ;; esac install_codex() { npm_exe="${NodeExe%/*}/npm" if [ ! -x "$npm_exe" ]; then stop 'npm was not found beside Node, so Codex cannot be installed'; fi file="openai-codex-$CodexVersion.tgz" platform_file="openai-codex-$CodexVersion-$platform.tgz" setup_phase codex downloading download "https://registry.npmjs.org/@openai/codex/-/codex-$CodexVersion.tgz" "$Downloads/$file" check_sha "$Downloads/$file" "$CodexSha" download "https://registry.npmjs.org/@openai/codex/-/codex-$CodexVersion-$platform.tgz" "$Downloads/$platform_file" check_sha "$Downloads/$platform_file" "$platform_sha" # Both files name themselves @openai/codex: give the platform file its dependency name. setup_phase codex installing "$npm_exe" install --global --prefix "$Tools/codex" "$Downloads/$file" "@openai/codex-$platform@file:$Downloads/$platform_file" --offline --no-fund --no-audit || stop 'Installing Codex with npm failed' rm -f "$Downloads/$file" "$Downloads/$platform_file" say 'Codex: installed' setup_phase codex installed } change "install Codex $CodexVersion (@openai/codex), downloading codex-$CodexVersion-$platform.tgz too, into $Tools/codex" install_codex fi fi # 6. Claude Code lives in the person's own home (~/.local/bin) and may be their own: never installed again, even for # a test. if { [ -z "$AddAI" ] && [ "$Window" != 1 ]; } || [ "$AddAI" = claude ] || [ "$AddAI" = both ]; then claude_exe=$(command -v claude 2>/dev/null) || claude_exe='' if [ "$Wsl" = 1 ] && under_mnt "$claude_exe"; then claude_exe=''; fi if [ -n "$claude_exe" ]; then setup_phase claude already; say 'Claude Code: already on this computer, kept' else install_claude() { # In its own process, as Anthropic gives it. setup_phase claude downloading download 'https://claude.ai/install.sh' "$Downloads/claude-install.sh" setup_phase claude installing bash "$Downloads/claude-install.sh" || stop "Claude Code's install failed" command -v claude >/dev/null 2>&1 || stop "Claude Code's install ended, but its program was not found" rm -f "$Downloads/claude-install.sh" say 'Claude Code: installed' setup_phase claude installed } change "install Claude Code with Anthropic's own install (claude.ai/install.sh)" install_claude fi fi if [ -n "$AddAI" ]; then return; fi # 7. The assistant itself, from this dashboard. Its state/, projects/ and .env are never in the package: they stay. host=${Dashboard#*://} host=${host%%/*} install_app() { if [ "$AppDownloaded" != 1 ]; then download "$Dashboard/install/ai-dev-assistant.tgz" "$Downloads/ai-dev-assistant.tgz"; fi check_sha "$Downloads/ai-dev-assistant.tgz" "$Sha" # Keep the existing package folders, including assets/window, and refuse paths or links outside them. "$NodeExe" -e 'const fs=require("node:fs"),z=require("node:zlib"),b=z.gunzipSync(fs.readFileSync(process.argv[1]),{maxOutputLength:67108864}),seen=new Set();for(let a=0;a+512<=b.length;){const h=b.subarray(a,a+512);if(h.every(x=>x===0))break;const p=h.toString("utf8",0,100).split("\0")[0],s=parseInt(h.toString("ascii",124,136),8),t=h[156];if(!/^(package\.json|(bin|src|assets)\/[A-Za-z0-9_./-]+)$/.test(p)||p.split("/").some(x=>!x||x.startsWith("."))||h.subarray(345,500).some(x=>x!==0)||(t!==0&&t!==48)||!Number.isSafeInteger(s)||s<0||a+512+Math.ceil(s/512)*512>b.length||seen.has(p.toLowerCase()))throw Error("Refused package path");seen.add(p.toLowerCase());a+=512+Math.ceil(s/512)*512}' "$Downloads/ai-dev-assistant.tgz" || stop 'Checking AI Dev Assistant package paths failed' # No file of an older version stays behind. rm -rf "${App:?}/bin" "${App:?}/src" "${App:?}/assets" mkdir -p "$App" || stop "the folder $App could not be made" tar -xzf "$Downloads/ai-dev-assistant.tgz" -C "$App" || stop 'Unpacking AI Dev Assistant failed' rm -rf "$Downloads" say "AI Dev Assistant $Version: checked, installed" } change "download AI Dev Assistant $Version from $host" install_app # Installed from another dashboard (a test): the assistant links to that one. A line already there is never changed, # so pasting the command again keeps this computer linked where it is. The file holds this computer's key: only its # user may read it. EnvFile="$App/.env" if [ "$Dashboard" != "$PcDashboard" ] && ! grep -Eq '^[[:space:]]*CONDUCTOR_DASHBOARD_URL[[:space:]]*=' "$EnvFile" 2>/dev/null; then write_env() { ( umask 077 if [ -s "$EnvFile" ] && [ -n "$(tail -c 1 "$EnvFile")" ]; then printf '\n' >>"$EnvFile"; fi printf 'CONDUCTOR_DASHBOARD_URL=%s\n' "$Dashboard" >>"$EnvFile" ) || stop "$EnvFile could not be written" chmod 600 "$EnvFile" || stop "$EnvFile could not be made private" } change "write $EnvFile (the dashboard this computer links to: $Dashboard)" write_env fi fi # 8. The launcher: the tools of this folder first (programs started from the Dock or a menu get a bare PATH), and the # restart after an update (exit code 75). A local PC's launcher leaves its terminal when it sees a screen (QA 260); an # online PC's, and one over SSH, in WSL or without a screen, runs in its terminal. Its lines in single quotes are # written as they are: they expand when the launcher runs. # shellcheck disable=SC2016 write_launcher() { mkdir -p "$Dir" || stop "the folder $Dir could not be made" { say '#!/bin/sh' say "# $Name: starts the assistant. Written by its install; the install writes it again." # B134: its folder by the shell's own words (cd and pwd are built in): nothing is looked up on PATH, which may # begin with the caller's folder, before it is left. say 'case $0 in */*) dir=${0%/*} ;; *) dir=. ;; esac' say 'dir=$(cd "$dir" && pwd -P) || exit 1' say 'cd "$dir/app" || exit 1' say '# Started by its launcher: the assistant may restart itself after an update (exit code 75) or a restore (76).' say 'ADA_LAUNCHER=1' if [ "$Os" = mac ]; then say 'PATH="$dir/tools/node/bin:$dir/tools/gh/bin:$dir/tools/codex/bin:$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:$PATH"' else say 'PATH="$dir/tools/node/bin:$dir/tools/gh/bin:$dir/tools/codex/bin:$HOME/.local/bin:$PATH"' fi say 'export ADA_LAUNCHER PATH' if [ -n "$ProjectsDir" ]; then say "CONDUCTOR_PROJECTS_DIR=$(quote "$ProjectsDir")"; say 'export CONDUCTOR_PROJECTS_DIR'; fi if [ "$Window" = 1 ]; then say "ADA_NAME=$(quote "$Name"); export ADA_NAME" say '# With a screen it opens the local window and runs without this terminal; SSH, WSL and no screen keep it.' say 'screen=0' if [ "$Os" = mac ]; then say '[ -n "${SSH_CONNECTION:-}${SSH_TTY:-}" ] || screen=1' else say 'if [ -z "${SSH_CONNECTION:-}${SSH_TTY:-}${WSL_DISTRO_NAME:-}" ] && ! grep -qi microsoft /proc/sys/kernel/osrelease 2>/dev/null && { [ -n "${DISPLAY:-}" ] || [ -n "${WAYLAND_DISPLAY:-}" ]; }; then screen=1; fi' fi say 'if [ "$screen" = 1 ]; then' say ' ADA_WINDOW_CAPABILITY=1; export ADA_WINDOW_CAPABILITY' say ' launcher_sum=$(cksum <"$dir/ai-dev-assistant")' say 'fi' # The app and the menu entry ask for it (--background-start); a start typed in a terminal with a screen leaves # that terminal too, so closing it can never stop the assistant (QA 260). say 'if [ "${1:-}" != --background-child ] && { [ "$screen" = 1 ] || [ "${1:-}" = --background-start ]; }; then' say ' nohup "$dir/ai-dev-assistant" --background-child /dev/null 2>&1 &' say " [ -t 1 ] && echo '$Name is running in the background: open it from its icon, stop it from Your PC, Stop the assistant.'" say ' exit 0' say 'fi' fi if [ "$Window" = 1 ]; then # The opening screen, as on Windows: "Opening AI Dev Assistant..." from the press until the dashboard opens # (the runner writes the signal file), the window is only reopened or the start ends (the file is removed), or # 20 seconds. Only with a screen, on a press or a return from online; a missing helper only skips it. # One opening screen at a time: a press while one shows (a slow start pressed twice) adds none. Its folder lock # is taken atomically and released when that screen ends; one left by a lost screen is taken again after about # two minutes, far beyond the screen's own 20 seconds. say 'signal=' say 'opening_pid=' say 'back="$dir/app/state/opening-local"' say 'opening_local=0' # A changed launcher's exec below carries the unconsumed Release marker to its new copy. say 'if [ "$screen" = 1 ] && [ "${ADA_WINDOW_LAUNCHER_HANDOFF:-}" = 1 ] && [ "${ADA_WINDOW_RESTART:-}" = 1 ] && [ -f "$back" ]; then' say ' rm -f "$back"; opening_local=1' say 'fi' say 'unset ADA_WINDOW_LAUNCHER_HANDOFF' say 'start_opening() {' say 'if [ "${1:-}" = --background-child ] && [ "$screen" = 1 ] && { [ "${ADA_WINDOW_RESTART:-}" != 1 ] || [ "$opening_local" = 1 ]; }; then' if [ "$Os" = mac ]; then say ' opening=$(command -v osascript 2>/dev/null) && [ -f "$dir/app/assets/opening-mac.js" ] || opening=' else say ' opening=$(command -v zenity 2>/dev/null) || opening=' fi say ' token=$(od -An -N16 -tx1 /dev/urandom 2>/dev/null | tr -d " \n")' say ' case $token in *[!0-9a-f]*) token= ;; esac' say ' showing="$dir/app/state/opening-screen"' say ' if [ -d "$showing" ] && [ -n "$(find "$showing" -prune -mmin +1 2>/dev/null)" ]; then rmdir "$showing" 2>/dev/null; fi' say ' if [ -n "$opening" ] && [ "${#token}" -eq 32 ] && mkdir -p "$dir/app/state" && mkdir "$showing" 2>/dev/null; then' say ' if { true >"$dir/app/state/window-open-$token"; } 2>/dev/null; then' say ' signal="$dir/app/state/window-open-$token"' say ' ADA_WINDOW_OPEN_SIGNAL=$token; export ADA_WINDOW_OPEN_SIGNAL' if [ "$Os" = mac ]; then say ' ( "$opening" -l JavaScript "$dir/app/assets/opening-mac.js" "$signal" "$dir/app/assets/logo.png"; rmdir "$showing" ) /dev/null 2>&1 &' else # B25: a failed start's 'failed' (the runner's reason on the next line, if any) leaves the screen on one line for a # minute: zenity takes new words from a "# " line, and a person closing it ends the wait at the next line sent. say ' ( { n=0; while [ -e "$signal" ] && [ ! -s "$signal" ] && [ "$n" -lt 200 ]; do sleep 0.1; n=$((n + 1)); done' say ' if [ "$(head -n 1 "$signal" 2>/dev/null)" = failed ]; then' say ' why=$(sed -n 2p "$signal" 2>/dev/null); log="$dir/app/state/assistant.log"' say ' if [ -n "$why" ]; then words="$why The full reason is in its log: $log"; else words="AI Dev Assistant could not start. Its log may say why: $log"; fi' say ' n=0; while [ "$n" -lt 60 ] && printf "# %s\n" "$words"; do sleep 1; n=$((n + 1)); done' say ' fi' say ' rm -f "$signal"; echo 100; } |' say " \"\$opening\" --progress --pulsate --auto-close --no-cancel --title=$(quote "$Name") --text=\"Opening AI Dev Assistant$(printf '\342\200\246')\"; rmdir \"\$showing\" ) /dev/null 2>&1 &" fi say ' opening_pid=$!' say ' else rmdir "$showing" 2>/dev/null; fi' say ' fi' say 'fi' say '}' say 'start_opening "$@"' say 'ADA_WINDOW_PRESS_ID=$(od -An -N16 -tx1 /dev/urandom | tr -d " \n"); export ADA_WINDOW_PRESS_ID' say 'if [ "$screen" = 1 ] && [ "${ADA_WINDOW_RESTART:-}" != 1 ] && [ -f "$dir/app/bin/open-window.js" ]; then' # A refusal was already answered and logged by the runner; another start would repeat the same press. say ' if node "$dir/app/bin/open-window.js"; then opened=0; else opened=$?; fi' say ' if [ "$opened" -eq 0 ] || [ "$opened" -eq 2 ]; then [ -z "$signal" ] || rm -f "$signal"; exit 0; fi' say 'fi' fi # A start that keeps its terminal names that window, so it is not taken for an ordinary prompt and closed. say "if [ -t 1 ]; then printf '\\033]0;%s\\007' $(quote "$Name (running)"); fi" say "echo '$Name is starting. Keep this terminal open while it works (Ctrl+C stops it).'" say "echo 'Online access uses $Dashboard.'" say 'echo' say 'while :; do' if [ "$Window" = 1 ]; then say ' [ "$screen" != 1 ] || rm -f "$back"'; fi # B125: an update that stopped part way through its swap (a crash, a power cut) left its journal beside its own # finisher in app/state/update, outside the folders it moves. The finisher puts the code back whole, or finds it # whole, before anything of it runs. One that cannot ends like a failed start (its words on the opening screen or # in this terminal), and nothing starts. say ' if [ -f "$dir/app/state/update/swap.json" ] && [ -f "$dir/app/state/update/swap-finish.mjs" ] && ! node "$dir/app/state/update/swap-finish.mjs" --finish-swap; then' say ' code=1' say ' else' say ' node "$dir/app/bin/conductor.js"' say ' code=$?' say ' fi' # The opening screen closes when its start ends, an update's or restore's restart included, as on Windows. A start # that failed while it still shows (B25) leaves it the runner's words, or 'failed' for a runner that said none. if [ "$Window" = 1 ]; then say ' if [ -n "$signal" ] && [ -f "$signal" ] && [ "$code" -ne 0 ] && [ "$code" -ne 75 ] && [ "$code" -ne 76 ]; then' say ' [ -s "$signal" ] || printf "failed\n" >"$signal" 2>/dev/null' say ' else' say ' [ -z "$signal" ] || rm -f "$signal"' say ' fi' say ' [ -z "$opening_pid" ] || wait "$opening_pid"' say ' [ -z "$signal" ] || rm -f "$signal"' say ' signal=; opening_pid=; unset ADA_WINDOW_OPEN_SIGNAL' fi say ' [ "$code" -eq 75 ] || [ "$code" -eq 76 ] || break' if [ "$Window" = 1 ]; then say ' ADA_WINDOW_RESTART=1; export ADA_WINDOW_RESTART'; fi say ' echo' # 76: what this computer had before its uninstall was just restored (src/backup.js). say ' if [ "$code" -eq 76 ]; then echo "Restored: starting again with the settings of this computer..."; else echo "Updated: starting the new version..."; fi' if [ "$Window" = 1 ]; then # The installer renames a new file over the old one. The running shell keeps its old loop until exec. # Do it only after its runner ended, keeping this process, arguments and restart environment (no second open). say ' if [ "$screen" = 1 ] && [ "$code" -eq 75 ] && [ -n "$launcher_sum" ] && [ "$launcher_sum" != "$(cksum <"$dir/ai-dev-assistant")" ]; then' say ' ADA_WINDOW_LAUNCHER_HANDOFF=1; export ADA_WINDOW_LAUNCHER_HANDOFF' say ' exec "$dir/ai-dev-assistant" "$@"' say ' exit 1' say ' fi' say ' if [ "$screen" = 1 ] && [ -f "$back" ]; then' say ' rm -f "$back"; opening_local=1' say ' start_opening "$@"' say ' opening_local=0' say ' fi' fi say 'done' say 'echo' say "if [ -t 1 ]; then printf '\\033]0;%s\\007' $(quote "$Name (stopped)"); fi" say "echo '$Name has stopped.'" say 'exit "$code"' } >"$Launcher.next" || stop "the launcher $Launcher could not be written" chmod 755 "$Launcher.next" || stop "the launcher $Launcher could not be made a program" # Replaced in one rename: a start while the running assistant refreshes it never reads a half-written launcher. mv -f "$Launcher.next" "$Launcher" || stop "the launcher $Launcher could not be written" } change "write the launcher $Launcher" write_launcher # The Uninstall lives beside the launcher. It removes only this install and a Git helper that names this install's # own GitHub CLI. Projects and sign-ins live elsewhere and are deliberately kept. # shellcheck disable=SC2016 write_uninstall() { { say '#!/bin/sh' # B134: its folder by the shell's own words (cd and pwd are built in): nothing is looked up on PATH, which may # begin with the caller's folder, before it is left. say 'case $0 in */*) dir=${0%/*} ;; *) dir=. ;; esac' say 'dir=$(cd "$dir" && pwd -P) || exit 1' # B128: this install's folder is the current one, so an empty or relative PATH entry never finds a program in the # folder the Uninstall was started from. say 'cd "$dir" || exit 1' # Bound the entire runner, including module loading and any synchronous filesystem read (B131: and the swap's # finisher, named in uninstall_entry). say 'run_uninstall() {' say ' limit=$1; shift' say ' PATH="$dir/tools/node/bin:$PATH" node "${uninstall_entry:-$dir/app/bin/conductor.js}" "$@" &' say ' task=$!' say ' (' say ' elapsed=0' say ' while [ "$elapsed" -lt "$limit" ]; do' say ' sleep 1' say ' elapsed=$((elapsed + 1))' say ' done' say ' echo "Uninstall could not finish in time. The dashboard release could not be confirmed."' say ' pkill -KILL -P "$task" 2>/dev/null || :' say ' kill -KILL "$task" 2>/dev/null || :' say ' ) &' say ' timer=$!' say ' wait "$task"; code=$?' say ' kill "$timer" 2>/dev/null || :' say ' wait "$timer" 2>/dev/null || :' say ' return "$code"' say '}' say "name=$(quote "$Name")" say "mac_app=$(quote "$MacApp")" say "mac_desktop_app=$(quote "$MacDesktopApp")" say "desktop_file=$(quote "$DesktopFile")" say 'echo "This removes $name from this computer, for this user:"' say 'echo " - its folder, $dir: the program, its tools and its saved state;"' if [ "$Os" = mac ]; then say 'echo " - its app, from Applications and the Desktop."' else say 'echo " - its shortcut, from your applications menu."' fi say 'echo "It keeps your projects folder, your sign-ins (GitHub, Claude, Codex), Claude Code and your work on GitHub."' say 'echo "It also keeps $HOME/.ai-dev-assistant-keys, a private folder this computer uses if you install it here again."' say 'echo' say 'local_mode=1' say 'ADA_WINDOW_CAPABILITY=1; export ADA_WINDOW_CAPABILITY' # Readable results have their own codes: Node startup failures leave state unknown. say 'state_code=0' say 'PATH="$dir/tools/node/bin:$PATH" node -e "const f=require('\''fs'\''),limit=134217728;setTimeout(()=>process.exit(2),2000);f.promises.lstat(process.argv[1]).then(s=>{if(!s.isFile()||s.size>limit)throw Error();return f.promises.readFile(process.argv[1],'\''utf8'\'')}).then(text=>{if(Buffer.byteLength(text)>limit)throw Error();const s=JSON.parse(text);if(!s||typeof s!=='\''object'\''||Array.isArray(s))throw Error();process.exit(s.onlineAccess?.on===true?11:10)}).catch(()=>process.exit(2))" "$dir/app/state/state.json" 2>/dev/null || state_code=$?' say 'if [ "$state_code" != 10 ] && [ "$state_code" != 11 ]; then' say ' echo "Its saved state could not be read, so it may not be able to keep a backup."' say 'else' say ' if [ "$state_code" = 11 ]; then echo "Online access was on for this PC."; else echo "Online access was off for this PC."; fi' say ' echo "It keeps a backup of your projects, tasks, Done list, choices and local conversations on this computer."' say ' echo "Backup: $dir.local-backup-v1"' say ' echo "Installed again here, Welcome back offers to restore it with development OFF. To remove the backup too, delete that file yourself."' say ' if [ "$state_code" = 11 ]; then' say ' echo "It also turns Online access off for this computer on your dashboard. Installed again, Your PC, Online access, Turn on brings it back."' say ' fi' say 'fi' say 'echo' say 'pattern=$(printf "%s" "$dir/app/bin/conductor.js" | sed '\''s/[][\\.*^$+?(){}|]/\\&/g'\'')' say 'if command -v pgrep >/dev/null 2>&1 && pgrep -f "$pattern" >/dev/null 2>&1; then' say ' echo "$name is running: stop it first (Your PC, Stop the assistant; Ctrl+C where it runs in a terminal), then start its Uninstall again."' say ' exit 1' say 'fi' say 'dry=${ADA_DRY_RUN:-0}' say 'if [ "$dry" != 1 ]; then' say ' printf "Remove %s now? [y/N] " "$name"' say ' read answer' say ' case $answer in y | Y | yes | YES | Yes) ;; *) echo "Nothing was removed."; exit 0 ;; esac' say 'fi' # Released on the dashboard first (the owner, 2026-10-13): the assistant's own step, with this install's Node. # B127: a swap of Update now that a crash stopped part way goes back whole first, so conductor.js can load (B125: # the finisher the swap left beside its journal, outside the folders it moves; its own words are the launchers'). # B131: within the same bounded wrapper as the runner; one that does not end in time is one that could not finish. say 'swap_left=0' say 'if [ "$dry" != 1 ] && [ -f "$dir/app/state/update/swap.json" ] && [ -f "$dir/app/state/update/swap-finish.mjs" ]; then' say ' uninstall_entry="$dir/app/state/update/swap-finish.mjs"' say ' run_uninstall 30 --finish-swap >/dev/null 2>&1 || swap_left=1' say 'fi' say 'uninstall_entry=' say 'if [ "$dry" = 1 ]; then' say ' if [ "$state_code" != 10 ] && [ "$state_code" != 11 ]; then echo "would try to keep a backup"; else echo "would save and verify the local backup at $dir.local-backup-v1"; fi' # It cannot: the app is still removed, as after any failed backup, and the release-only fallback is still tried. # With Online access off nothing waits on the dashboard. say 'elif [ "$swap_left" = 1 ]; then' say ' echo "Your backup could not be kept because the code was partly updated. Removing the app."' say ' if run_uninstall 75 --uninstall-release || [ "$state_code" = 10 ]; then :; else' say ' echo "Your dashboard was not told, so Online access is still on there for this computer: nothing was removed yet."' say ' printf "Remove %s anyway (your online dashboard keeps this computer until you press Turn off online access for it)? [y/N] " "$name"' say ' read answer' say ' case $answer in y | Y | yes | YES | Yes) ;; *) echo "Nothing was removed. Start its Uninstall again once this computer is online."; exit 1 ;; esac' say ' fi' # Not released (no internet, or the dashboard refused): nothing is removed unless the person says so. say 'elif run_uninstall 260 --uninstall; then' say ' :' say 'else' # Only 2 means account release failed. Every backup outcome continues to removal. say ' code=$?' say ' if [ "$code" != 2 ]; then' say ' if run_uninstall 75 --uninstall-release; then code=0; else code=2; fi' say ' fi' say ' if [ "$code" = 2 ]; then' say ' echo "Your dashboard was not told, so Online access is still on there for this computer: nothing was removed yet."' say ' printf "Remove %s anyway (your online dashboard keeps this computer until you press Turn off online access for it)? [y/N] " "$name"' say ' read answer' say ' case $answer in y | Y | yes | YES | Yes) ;; *) echo "Nothing was removed. Start its Uninstall again once this computer is online."; exit 1 ;; esac' say ' fi' say 'fi' say 'for key in credential.https://github.com.helper credential.https://gist.github.com.helper; do' say ' git config --global --get-all "$key" 2>/dev/null | while IFS= read -r value; do' say ' case $value in *"$dir/tools/gh/"*)' say ' if [ "$dry" = 1 ]; then echo "would remove from your Git settings: $key, which points to the GitHub CLI of this program"' say ' else git config --global --fixed-value --unset-all "$key" "$value" 2>/dev/null || :; echo "Removed from your Git settings: $key, which pointed to the GitHub CLI of this program."; fi ;;' say ' esac' say ' done' say 'done' say 'if [ "$dry" = 1 ]; then' say ' echo "would remove the app and desktop shortcuts"' say ' echo "would remove $dir"' say ' exit 0' say 'fi' say 'for shortcut in "$mac_app" "$mac_desktop_app"; do' say ' if grep -F "$dir/ai-dev-assistant" "$shortcut/Contents/MacOS/start" >/dev/null 2>&1; then rm -rf "$shortcut"; fi' say 'done' say 'if grep -F "Exec=\"$dir/ai-dev-assistant\"" "$desktop_file" >/dev/null 2>&1; then rm -f "$desktop_file"; fi' say 'cd "${TMPDIR:-/tmp}" || exit 1' say 'echo "Removing $dir..."' say 'if [ -d "$HOME/.ai-dev-assistant-keys" ]; then echo "Kept $HOME/.ai-dev-assistant-keys: the private folder this computer uses if you install it here again."; fi' say 'rm -rf "$dir"' say 'if [ -e "$dir" ]; then echo "Some of its files are in use: close what uses them, then delete the folder yourself."; exit 1; fi' say 'echo "$name is removed from this computer."' } >"$Uninstall" || stop "the Uninstall $Uninstall could not be written" chmod 755 "$Uninstall" || stop "the Uninstall $Uninstall could not be made a program" } change "write the Uninstall $Uninstall" write_uninstall write_mac_app() { contents="$MacApp/Contents" if [ -e "$MacApp" ] && ! grep -F -e "$Launcher" -e "$(quote "$Launcher")" "$contents/MacOS/start" >/dev/null 2>&1; then stop "$MacApp already exists and belongs to something else: move or rename it, then paste the command again" fi mkdir -p "$contents/MacOS" "$contents/Resources" || stop "the app $MacApp could not be made" cp "$App/assets/logo.icns" "$contents/Resources/logo.icns" || stop "the logo could not be put in $MacApp" cat >"$contents/Info.plist" < CFBundleExecutablestart CFBundleIconFilelogo.icns CFBundleIdentifiercom.agile-clouds.ai-dev-assistant CFBundleName$Name CFBundlePackageTypeAPPL LSUIElement EOF { say '#!/bin/sh' # The path as it is, so this install and its Uninstall know the app again even when the path holds a quote. say "# $Name: $Launcher" # A local PC's app starts the hidden host and ends (LSUIElement: no Dock icon, no Terminal). An online PC keeps # its Terminal window, which shows its log and is where Ctrl+C stops it. say "exec $(quote "$Launcher") --background-start" } >"$contents/MacOS/start.next" || stop "the app $MacApp could not be written" chmod 755 "$contents/MacOS/start.next" || stop "the app $MacApp could not be made a program" mv -f "$contents/MacOS/start.next" "$contents/MacOS/start" || stop "the app $MacApp could not be written" } copy_mac_app() { mkdir -p "${MacDesktopApp%/*}" 2>/dev/null || { say "The desktop copy was not made: macOS did not allow access to your Desktop."; return 0; } if [ -e "$MacDesktopApp" ] && ! grep -F -e "$Launcher" -e "$(quote "$Launcher")" "$MacDesktopApp/Contents/MacOS/start" >/dev/null 2>&1; then say "The desktop copy was not made: $MacDesktopApp already belongs to something else. The app is still in Applications." return 0 fi rm -rf "$MacDesktopApp" 2>/dev/null || : cp -R "$MacApp" "$MacDesktopApp" 2>/dev/null || say "The desktop copy was not made: macOS did not allow access to your Desktop. The app is still in Applications." } write_desktop_entry() { mkdir -p "${DesktopFile%/*}" || stop "the applications folder ${DesktopFile%/*} could not be made" escaped_launcher=$(printf '%s' "$Launcher" | sed 's/[\\"]/\\&/g') escaped_icon=$(printf '%s' "$App/assets/logo.png" | sed 's/\\/\\\\/g') # A local PC's entry opens no terminal and starts the hidden host; no window of its own follows, so the desktop is # told not to wait for one (StartupNotify). An online PC keeps its terminal, which shows its log. exec_line="\"$escaped_launcher\" --background-start" terminal=false cat >"$DesktopFile" <>"$DesktopFile" || stop "the desktop entry $DesktopFile could not be written"; fi chmod 644 "$DesktopFile" || stop "the desktop entry $DesktopFile could not be written" } if [ "$Os" = mac ]; then change "make the $Name app in Applications" write_mac_app change "copy the $Name app to the Desktop" copy_mac_app else change "make the $Name desktop entry" write_desktop_entry fi # A launcher refresh and an explicit setup operation stop here. Only the handover above starts the launcher, which # leaves this terminal at once (it has a screen) while the assistant opens its setup in the default browser. No # sign-in lines: setup reads only the chosen services. if [ "$SetupTool" = launchers ]; then say 'The manual launchers are ready.'; return; fi if [ "$Window" = 1 ] && [ "$AutoWindow" != 1 ]; then say 'The setup files are installed.'; return; fi # Match the launcher's no-screen choice. The install must keep its first link in this terminal too: an app open or # --background-start would discard it. A slow first start stays here until the runner can print its own link. headless=0 if [ -n "${SSH_CONNECTION:-}${SSH_TTY:-}" ] || { [ "$Os" = linux ] && { [ -n "${WSL_DISTRO_NAME:-}" ] || grep -qi microsoft /proc/sys/kernel/osrelease 2>/dev/null || { [ -z "${DISPLAY:-}" ] && [ -z "${WAYLAND_DISPLAY:-}" ]; }; }; }; then headless=1; fi if [ "$Window" = 1 ] && [ "$headless" = 1 ]; then say 'Open the link printed below in a browser to link this PC.' say 'Waiting for the assistant. Keep this terminal open while it works (Ctrl+C stops it).' start_console() { "$Launcher" || stop "$Name could not be started: run $Launcher in this terminal"; } change "start $Name" start_console return fi if [ "$Window" = 1 ]; then start_setup() { if [ "$Os" = mac ]; then open "$MacApp" || stop "the $Name app could not be opened: open it from Applications" else "$Launcher" --background-start || stop "$Name could not be started: start it from your applications menu" fi } setup_complete=0 if [ "$Dry" != 1 ]; then # Read the installed copy's own completion rule without creating or changing any saved file. if "$NodeExe" -e 'const f=require("fs"),p=require("path"),u=require("url");setTimeout(()=>process.exit(1),2000);const a=process.argv[1];Promise.all([f.promises.readFile(p.join(a,"state/state.json"),"utf8"),f.promises.readFile(p.join(a,"state/pc.json"),"utf8"),import(u.pathToFileURL(p.join(a,"src/setup-consent.js")).href)]).then(([s,c,m])=>process.exit(m.localSetupComplete(JSON.parse(s),JSON.parse(c).id)?0:1)).catch(()=>process.exit(1))' "$App" 2>/dev/null; then setup_complete=1; fi fi if [ "$setup_complete" = 1 ]; then change "start $Name" start_setup else change "start $Name setup" start_setup fi say '' if [ "$setup_complete" = 1 ]; then say 'Your dashboard opened in your browser.' else say 'Setup opened in your browser.' fi if [ "$Os" = mac ]; then say "Open it again from the $Name app in Applications or on the Desktop." else say "Open it again from $Name in your applications menu." fi return fi } install_ai_dev_assistant