Skip to content

Commit c5255db

Browse files
committed
Auto update, version
1 parent b4877ab commit c5255db

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
with:
2929
node-version: 24
3030
registry-url: https://registry.npmjs.org
31+
- name: Stamp CLI version
32+
run: sed -i "s/__CLI_VERSION__/$(node -p 'require(\"./package.json\").version')/" bin/aibox
3133
- run: npm publish --access public --provenance
3234

3335
homebrew:

bin/aibox

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
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 ──────────────────────────────────────────────
6566
SCRIPT_NAME="$(basename "$0")"
6667
AIBOX_VERSION="9"
68+
AIBOX_CLI_VERSION="__CLI_VERSION__"
6769
CONFIG_DIR="${HOME}/.config/aibox"
6870
DEFAULT_IMAGE="aibox:latest"
6971
CONTAINER_PREFIX="aibox"
@@ -1840,10 +1842,63 @@ cmd_help() {
18401842
}
18411843

18421844
cmd_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+
18471902
case "${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
*)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aibox-cli",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "Run AI coding agents in isolated Docker containers",
55
"author": "repalash <palash@shaders.app>",
66
"license": "MIT",

0 commit comments

Comments
 (0)