2222# aibox nuke Remove ALL aibox containers (all projects)
2323# aibox build [--image NAME] Build the base image
2424# aibox init [flags] Generate compose.dev.yaml + configure WebStorm
25+ # aibox update Update aibox to the latest version
2526# aibox version Show version
2627# aibox help Show this help (default)
2728#
@@ -64,6 +65,7 @@ set -euo pipefail
6465# ── Script identity ──────────────────────────────────────────────
6566SCRIPT_NAME=" $( basename " $0 " ) "
6667AIBOX_VERSION=" 9"
68+ AIBOX_CLI_VERSION=" __CLI_VERSION__"
6769CONFIG_DIR=" ${HOME} /.config/aibox"
6870DEFAULT_IMAGE=" aibox:latest"
6971CONTAINER_PREFIX=" aibox"
@@ -1840,10 +1842,63 @@ cmd_help() {
18401842}
18411843
18421844cmd_version () {
1843- echo " aibox v${AIBOX_VERSION} "
1845+ echo " aibox v${AIBOX_CLI_VERSION} (image v${AIBOX_VERSION} )"
1846+ }
1847+
1848+ # ── Update check (non-blocking, cached for 24h) ─────────────────
1849+ _check_for_updates () {
1850+ [[ ! -t 1 || -n " ${CI:- } " || " $AIBOX_CLI_VERSION " == " __CLI_VERSION__" ]] && return 0
1851+
1852+ local cache_file=" ${CONFIG_DIR} /update-check"
1853+ mkdir -p " $CONFIG_DIR "
1854+
1855+ if [[ -f " $cache_file " ]]; then
1856+ local mtime latest
1857+ mtime=$( stat -c %Y " $cache_file " 2> /dev/null || stat -f %m " $cache_file " 2> /dev/null || echo 0)
1858+ if (( $(date +% s) - mtime < 86400 )) ; then
1859+ latest=$( cat " $cache_file " )
1860+ [[ -n " $latest " && " $latest " != " $AIBOX_CLI_VERSION " ]] && \
1861+ _warn " aibox ${_B} v${latest}${_N}${_BY} available${_N} (current: v${AIBOX_CLI_VERSION} ). Run: ${_B} aibox update${_N} "
1862+ return 0
1863+ fi
1864+ fi
1865+
1866+ # Refresh cache in background (silent — notice shown on next run)
1867+ ( curl -fsSL --max-time 3 " https://registry.npmjs.org/aibox-cli/latest" 2> /dev/null \
1868+ | grep -o ' "version":"[^"]*"' | head -1 | cut -d' "' -f4 > " $cache_file "
1869+ ) & > /dev/null &
1870+ disown 2> /dev/null || true
1871+ }
1872+
1873+ cmd_update () {
1874+ local script_path
1875+ script_path=" $( realpath " $0 " 2> /dev/null || readlink -f " $0 " 2> /dev/null || echo " $0 " ) "
1876+
1877+ if [[ " $script_path " == * /Cellar/* || " $script_path " == * /homebrew/* ]]; then
1878+ if ! command -v brew & > /dev/null; then
1879+ _err " Installed via Homebrew but ${_B} brew${_N} not found in PATH."
1880+ echo " Run: brew upgrade aibox"
1881+ exit 1
1882+ fi
1883+ _step " Updating via Homebrew"
1884+ brew update && brew upgrade aibox
1885+ elif command -v npm & > /dev/null && npm list -g aibox-cli & > /dev/null; then
1886+ _step " Updating via npm"
1887+ npm update -g aibox-cli
1888+ else
1889+ _err " Could not detect install method (Homebrew or npm)."
1890+ echo " Update manually:"
1891+ echo " Homebrew: brew upgrade aibox"
1892+ echo " npm: npm update -g aibox-cli"
1893+ exit 1
1894+ fi
1895+
1896+ _ok " Updated. Run ${_B} aibox build${_N} to rebuild the Docker image."
18441897}
18451898
18461899# ── Main ─────────────────────────────────────────────────────────
1900+ _check_for_updates
1901+
18471902case " ${1:- help} " in
18481903 up) cmd_up ;;
18491904 claude) shift ; cmd_claude " $@ " ;;
@@ -1855,6 +1910,7 @@ case "${1:-help}" in
18551910 nuke) cmd_nuke ;;
18561911 build) cmd_build ;;
18571912 init) cmd_init ;;
1913+ update) cmd_update ;;
18581914 help|-h) cmd_help ;;
18591915 version|-v|--version) cmd_version ;;
18601916 * )
0 commit comments