Repository navigation
feat(cloud): support Antigravity and Cursor cloud environments - #21
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| # Cursor Cloud Agents ignore ~/.cursor/hooks.json and rely on the start | ||
| # step: when cloud.bash is run with SHELLTIME_TOKEN as the runtime user, | ||
| # start the daemon immediately so a single start-step call works too. | ||
| if [ "$IS_CURSOR_CLOUD" = true ] && [ -n "${SHELLTIME_TOKEN:-}" ] && [ "$TARGET_USER" = "$(id -un)" ]; then |
There was a problem hiding this comment.
Important: a failing shelltime auth aborts the rest of setup. auth_if_token_present runs shelltime auth --token ... >/dev/null with no || true, and the script runs under set -euo pipefail. If the call fails (no network at setup time, token rejected, CLI error), main exits here. For Antigravity, install_agy_session_hook never runs, so hooks.json is not registered and sessions are never tracked. The Cursor immediate start is skipped as well. The EXIT trap hides the non-zero status, so the failure is easy to miss. Both cloud-start.sh and the Claude hook already tolerate a failed auth with || true / || exit 0.
Fix: make the auth non-fatal, e.g. HOME="$TARGET_HOME" "$ST_DIR/bin/shelltime" auth --token "$SHELLTIME_TOKEN" >/dev/null 2>&1 || true. Also move install_agy_session_hook ahead of it.
| if [ "$TARGET_USER" = "antigravity" ]; then | ||
| IS_AGY_CLOUD=true | ||
| elif [ "$(id -u)" -eq 0 ] && id -u antigravity >/dev/null 2>&1; then | ||
| IS_AGY_CLOUD=true |
There was a problem hiding this comment.
Important: Antigravity is detected by OS user alone, with no explicit cloud signal. The branch at line 102 runs as root and treats any box with a user named antigravity as an Antigravity cloud VM. It then re-targets TARGET_HOME to that user's home. The header and CLAUDE.md say the script installs nothing outside a cloud environment, but this branch makes it replace binaries and write hooks on any root-run machine that has such a user. It also affects a root-run Claude cloud setup on an image that has an antigravity user. There, TARGET_HOME moves to /home/antigravity and cc install and the Claude settings.json hook are written into that user's home instead of root's. fix_ownership then chowns files in the wrong home.
Fix: apply the retarget only when no other cloud signal is set (IS_CLAUDE_CLOUD=false), or require an explicit marker such as SHELLTIME_CLOUD.
| # Fresh VM before checkout/agent init: prepare both hook-based cloud agents | ||
| if [ "$IS_CURSOR_CLOUD" = false ] && [ "$IS_AGY_CLOUD" = false ]; then | ||
| IS_CURSOR_CLOUD=true | ||
| IS_AGY_CLOUD=true |
There was a problem hiding this comment.
Nit (optional): with SHELLTIME_CLOUD=true and no marker found, the fallback enables both Cursor and Antigravity. A Cursor-only fresh VM then gets ~/.gemini/config/hooks.json created. An Antigravity-only VM gets a Cursor-style setup too. The CI Cursor test comment says Cursor "should not get ~/.gemini/config/hooks.json", but it only passes because .cursor is pre-created. The [ -d ~/.gemini ] / command -v agy checks also match a Cursor VM that merely has Gemini CLI installed.
Fix: let users pick explicitly, e.g. a SHELLTIME_CLOUD=cursor|agy value, or do the dual install without writing the Antigravity hooks file unless Antigravity is positively detected.
| import json, sys | ||
| path, cmd = sys.argv[1], sys.argv[2] | ||
| with open(path, "r", encoding="utf-8") as f: | ||
| data = json.load(f) |
There was a problem hiding this comment.
Nit (optional): an existing hooks.json that is not strict JSON (comments, trailing commas) or whose top level is not an object makes jq fail. Under set -e the script aborts, so the hook is not registered and an empty hooks.json.tmp is left behind. The python3 fallback only runs when jq is missing, not when it fails. The .tmp file is also not removed on failure. The CI test only covers a valid pre-existing file.
Fix: on jq failure, try the python fallback or skip with a warning, and clean up the .tmp file.
| ln -sf "$ST_DIR/bin/shelltime" "$TARGET_HOME/.local/bin/shelltime" | ||
| if [ -w /usr/local/bin ]; then | ||
| ln -sf "$ST_DIR/bin/shelltime" /usr/local/bin/shelltime | ||
| ln -sf "$ST_DIR/bin/shelltime-daemon" /usr/local/bin/shelltime-daemon |
There was a problem hiding this comment.
Nit (optional): install_cli now also does ln -sf of shelltime and shelltime-daemon into /usr/local/bin whenever that directory is writable. This applies to Claude Code cloud too, which previously only touched ~/.shelltime and ~/.local/bin. It would overwrite any existing binary there. The CLAUDE.md test-cloud description and the CI checks do not cover this behavior change for Claude.
Fix: limit the symlinks to the Antigravity/Cursor paths that need them, or skip when a non-symlink file already exists.
| - `install.bash` - Main installation script that downloads shelltime CLI binaries and sets up shell hooks | ||
| - `cloud.bash` - Setup for Claude Code cloud environments, run from an environment's setup script with `curl -fsSL https://raw.githubusercontent.com/shelltime/installation/main/cloud.bash | bash`. Installs the Linux CLI and daemon into `~/.shelltime/bin`, runs `shelltime cc install`, and adds a Claude Code SessionStart hook (`~/.shelltime/bin/cloud-session-start.sh`, embedded in the script) that signs in and starts the daemon in each session. The token is a network secret of the environment (host `api.shelltime.xyz`, header `Authorization`, prefix `CLI`) that Anthropic's agent proxy adds to requests outside the VM, so the hook signs in with the placeholder `proxy-injected` (the CLI then sends no `Authorization` header; needs a CLI release with `model.ProxyInjectedToken`). `SHELLTIME_TOKEN` in the environment variables, for environments without network secrets, replaces the placeholder. Setup scripts get neither. It installs nothing unless `CLAUDE_CODE_REMOTE` is `true`, which cloud environments set (the setup script inherits it from `environment-manager`) and which is never true on a user's own machine. A setup script that exits non-zero stops sessions from starting, so it always exits 0 (its `EXIT` trap reports a failure instead), and nothing runs before the final `main` call, so a truncated download installs nothing. The guide that documents it is `content/blogs/track-claude-code-cloud-sessions/` in the web repo; keep the two in step | ||
| - `cloud.bash` - Setup for cloud agent environments (Claude Code cloud, Google Antigravity cloud, and Cursor Cloud Agents), run from an environment's setup/install script with `curl -fsSL https://raw.githubusercontent.com/shelltime/installation/main/cloud.bash | bash`. Detects Claude Code cloud (`CLAUDE_CODE_REMOTE=true`), Antigravity cloud (OS user `antigravity`, including when setup runs as `root` on behalf of `antigravity`), Cursor Cloud Agents (`CURSOR_CLOUD=true`/`1`, `CURSOR_BACKGROUND_AGENT=true`/`1`), or an explicit `SHELLTIME_CLOUD=true` (matching `~/.cursor`/`.cursor/*`/`cursor-agent` vs `~/.gemini`/`.agents/hooks.json`/`agy`, or both in a fresh VM); outside those it installs nothing (ignoring `CURSOR_CODE_REMOTE` and `CURSOR_AGENT`, which local/SSH machines also set). Installs the Linux CLI and daemon into `$TARGET_HOME/.shelltime/bin` (and symlinks into `/usr/local/bin` when writable). For Claude Code cloud, runs `shelltime cc install` and adds a Claude Code SessionStart hook (`~/.shelltime/bin/cloud-session-start.sh`) that signs in with `proxy-injected` (or `SHELLTIME_TOKEN`) and starts the daemon in each session. For Antigravity and Cursor cloud, installs `~/.shelltime/bin/cloud-start.sh` (signs in when `SHELLTIME_TOKEN` is in the env, clears stale `/tmp/shelltime.sock`, starts `shelltime-daemon` with `SHELLTIME_CLOUD=true`) and saves `SHELLTIME_TOKEN` to `config.yaml` if present during setup. For Antigravity, also adds `~/.shelltime/bin/agy-cloud-session-start.sh` under the separate `"shelltime-cloud"` group in `~/.gemini/config/hooks.json` (so `.agents/hooks.json` never yields to it) and fixes ownership to `antigravity` when setup ran as `root`. For Cursor Cloud Agents (which ignore `~/.cursor/hooks.json`), also runs `cloud-start.sh` immediately when `SHELLTIME_TOKEN` is already set. A setup script that exits non-zero stops sessions from starting, so it always exits 0 (its `EXIT` trap reports a failure instead), and nothing runs before the final `main` call, so a truncated download installs nothing. The guides that document it are `content/blogs/track-claude-code-cloud-sessions/` and `content/blogs/track-cursor-and-antigravity/` in the web repo; keep them in step | ||
| - `hooks/` - Shell-specific hook scripts that track command execution. They are copies of the CLI's embedded hooks (`model/hooks/` in shelltime/cli, which `shelltime hooks install` and `shelltime init` write over these), so change both together: |
There was a problem hiding this comment.
Nit (optional): the Testing section of this file still says "The test-cloud job checks that cloud.bash installs nothing without CLAUDE_CODE_REMOTE=true, then runs it twice ... SessionStart hook is registered exactly once ... signs in with proxy-injected". This PR adds Antigravity and Cursor steps to that job, and the refusal now covers more env vars. The Testing paragraph was not updated, so it no longer describes what the job verifies.
Fix: update the test-cloud paragraph to list the Antigravity and Cursor checks.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c9d63690af
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if [ -d "$TARGET_HOME/.gemini" ] || command -v agy >/dev/null 2>&1; then | ||
| IS_AGY_CLOUD=true | ||
| fi | ||
| if [ "$IS_CURSOR_CLOUD" = false ] && [ "$IS_AGY_CLOUD" = false ]; then |
There was a problem hiding this comment.
Preserve Cursor detection after a fresh-VM installation
When installation runs before checkout or agent initialization with only SHELLTIME_CLOUD=true, the fresh-VM fallback enables both platforms and install_agy_session_hook creates ~/.gemini. A subsequent invocation of cloud.bash in the Cursor start step then treats that installer-created directory as Antigravity evidence and skips the repository-marker fallback, even when .cursor/hooks.json now exists. I reproduced detection changing from both platforms to Antigravity-only. Consequently, IS_CURSOR_CLOUD is false and the immediate daemon-start block never runs, breaking the documented option of running cloud.bash directly in the start step. Avoid letting the installer's own directory creation suppress Cursor detection.
Useful? React with 👍 / 👎.
Summary
cloud.bashbeyond Claude Code cloud (CLAUDE_CODE_REMOTE=true) to also support Google Antigravity cloud and Cursor Cloud Agents, while continuing to refuse and install nothing on local machines (including when local/SSH Cursor varsCURSOR_CODE_REMOTEorCURSOR_AGENTare set).antigravity,rooton a VM with userantigravity, orSHELLTIME_CLOUD=truewith Antigravity markers):shelltimeandshelltime-daemoninto/.shelltime/bin(and symlinks into/usr/local/binwhen writable) and fixes ownership toantigravitywhen setup runs asroot.SHELLTIME_TOKENintoconfig.yamlwhen exported during setup.SessionStarthook (agy-cloud-session-start.sh->cloud-start.sh) under a separate"shelltime-cloud"group in~/.gemini/config/hooks.json(so repo.agents/hooks.jsonnever yields to it), printing{}, startingshelltime-daemonwithSHELLTIME_CLOUD=true, and waiting briefly for/tmp/shelltime.sock. Usesjqwith apython3fallback.CURSOR_CLOUD=true|1,CURSOR_BACKGROUND_AGENT=true|1, orSHELLTIME_CLOUD=truewith Cursor markers):~/.shelltime/bin/cloud-start.shfor thestartstep and startsshelltime-daemonimmediately whenSHELLTIME_TOKENis already present as the runtime user (does not touch~/.cursor/hooks.json, which Cursor Cloud Agents ignore)..github/workflows/test.yamland updateREADME.mdandCLAUDE.md.Test plan
bash -n cloud.bashandgit diff --check.CURSOR_CODE_REMOTE=true CURSOR_AGENT=1), Antigravity (jq+python3fallback, idempotent across 2 runs), and Cursor (SHELLTIME_CLOUD=trueinstall step,CURSOR_CLOUD=truestart step,CURSOR_BACKGROUND_AGENT=true).test-cloudmatrix (ubuntu-latest&ubuntu-24.04-arm) exercises real downloads and liveshelltime-daemonstartup for Claude Code, Antigravity, and Cursor.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.