Repository navigation
feat(cloud): record Antigravity remote agent commands from the login shell - #22
Conversation
…shell An Antigravity remote agent runs outside its VM and runs no hook there, so the hooks cloud.bash set up never fired. It sends each command in as `bash -l -c <command>` with JULES_SESSION_ID set, so cloud.bash now writes ~/.shelltime/bin/agy-cloud-profile.sh and sources it (bash only) from the login profile bash reads. Its EXIT trap pipes the command to `shelltime hook-ingest --agent agy --event ShellCommand` with the session, exit status and duration, then starts the daemon. It prints nothing, keeps the exit status and skips shells the command starts. Needs the CLI's ShellCommand mode (shelltime/cli#366). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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. |
🤖 Claude Code · Fix Antigravity cloud-session detection in CLIImproved the CLI’s Antigravity cloud-session handling by updating shell command/process detection logic, adding regression tests, and preparing the changes for review.
34.4M tokens: 39K input · 154.1K output · 33.7M cache read · 430.8K cache write 📝 AI summaryInvestigated why Antigravity cloud sessions were not being collected despite successful Shelltime installation and valid remote sessions. The debugging used the supplied environment, installation details, and process tree to identify weaknesses in how the CLI recognized or associated Antigravity shell commands and cloud-session processes. Updated View this session on ShellTime → Updated 2026-11-30 15:10 UTC by ShellTime · totals for the whole session so far · the session page is visible to its owner |
The EXIT trap ran cloud-start.sh in the foreground, so a command's shell could wait up to a second for the daemon's socket, longer on a sign-in. It now runs detached after the command is recorded (to the pending file when no daemon runs yet, which a starting daemon sends first). Setup also writes /etc/profile.d/shelltime-agy-cloud.sh when it may, so a ~/.bash_profile a tool creates later doesn't hide the line in ~/.profile. CI covers the line going into an existing ~/.bash_login and the command not waiting for cloud-start.sh. CLAUDE.md lists what isn't reported (exec, a command's own EXIT trap, SIGKILL). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| fi | ||
| printf '%s' "$BASH_EXECUTION_STRING" | "$st/bin/shelltime" hook-ingest --agent agy --event ShellCommand \ | ||
| --session "$JULES_SESSION_ID" --exit-code "$status" ${ms:+--duration-ms "$ms"} >/dev/null 2>&1 | ||
| ("$st/bin/cloud-start.sh" >/dev/null 2>&1 </dev/null &) |
There was a problem hiding this comment.
Important: every reported command spawns its own detached cloud-start.sh. That script's pgrep check, rm -f /tmp/shelltime.sock and daemon start are not atomic. When an agent runs several commands at once before the daemon is up, two scripts can both find no daemon. Both then start shelltime-daemon, and the second rm deletes the first daemon's socket, which leaves a daemon with no socket. Fix: serialize the start with flock on a lock file under ~/.shelltime, or skip the launch when /tmp/shelltime.sock exists and a daemon is running. Also only start it when the daemon is actually missing, not after every command.
| if [ -n "$__shelltime_agy_start" ] && [ -n "${EPOCHREALTIME:-}" ]; then | ||
| ms=$(( (10#${EPOCHREALTIME//[!0-9]/} - 10#${__shelltime_agy_start//[!0-9]/}) / 1000 )) | ||
| fi | ||
| printf '%s' "$BASH_EXECUTION_STRING" | "$st/bin/shelltime" hook-ingest --agent agy --event ShellCommand \ |
There was a problem hiding this comment.
Nit (optional): the EXIT trap runs in the agent's own shell, so it uses whatever IFS and set -f the command left behind. A command that sets IFS=, (or set -f) makes the unquoted ${ms:+--duration-ms "$ms"} split or glob wrongly, and hook-ingest gets bad arguments. The error is hidden by >/dev/null 2>&1, so the command goes unreported with no sign. The trap also calls $st/bin/shelltime with no time limit, so a hung hook-ingest holds the agent's command open, even though the comments say it is bounded. Fix: start the function with local IFS=$' \t\n'; set +f, and wrap the call in timeout 2 when timeout is available.
| # exits. It prints nothing and leaves the command's exit status as it was. | ||
| if [ -n "${JULES_SESSION_ID:-}" ] && [ -n "${BASH_EXECUTION_STRING:-}" ] && | ||
| [ -z "${SHELLTIME_AGY_COMMAND:-}" ] && [ -x "$HOME/.shelltime/bin/shelltime" ]; then | ||
| export SHELLTIME_AGY_COMMAND=1 |
There was a problem hiding this comment.
Nit (optional): export SHELLTIME_AGY_COMMAND=1 puts a ShellTime-internal variable into the environment of the agent's command and everything it starts. That includes the daemon, which cloud-start.sh starts from inside the trap. A later bash -l -c that the agent runs on purpose from inside the command is silently never reported. This is the intended nesting rule, but it also hides a command the agent runs separately from a tool wrapper it started. Fix: leave it as is if intended. Otherwise unset SHELLTIME_AGY_COMMAND JULES_SESSION_ID for the daemon in the trap, as in (unset SHELLTIME_AGY_COMMAND; "$st/bin/cloud-start.sh" ... &).
| done | ||
| # An earlier run's line stays the only one | ||
| if ! grep -qF "agy-cloud-profile.sh" "$LOGIN_PROFILE_PATH" 2>/dev/null; then | ||
| printf '\n%s\n%s\n' "$comment" "$line" >>"$LOGIN_PROFILE_PATH" |
There was a problem hiding this comment.
Nit (optional): cloud.bash runs under set -euo pipefail, so if appending to the login profile fails (read-only or root-owned file, full disk), install_agy_shell_profile aborts main. fix_ownership and the final message never run. chown -R of ~/.shelltime is skipped when setup runs as root for antigravity, so the runtime user cannot read its own config or binaries. The same applies to the /etc/profile.d write at line 341. Fix: add || true to both writes, since the login-shell hook is best effort, or move fix_ownership before install_agy_shell_profile.
| LOGIN_PROFILE_PATH="$TARGET_HOME/$name" | ||
| break | ||
| fi | ||
| done |
There was a problem hiding this comment.
Nit (optional): the "already installed" check only greps the one profile file picked on this run. If an earlier run put the line in ~/.profile and a ~/.bash_profile or ~/.bash_login appears later, a rerun appends a second copy there and leaves the old one behind. The CI step relies on this. Nothing breaks, because SHELLTIME_AGY_COMMAND stops a double report, but stale lines build up across reruns. Fix: check all three candidate files for the marker before appending, and append only if none has it.
…ther Each remote agent command starts cloud-start.sh detached, so parallel commands could both find no daemon and remove each other's socket. cloud-start.sh now runs one at a time under flock (the daemon doesn't keep the lock). The EXIT trap resets IFS and globbing the command may have changed, marks the event cloud with SHELLTIME_CLOUD=true whatever the OS user, keeps its own variables from the daemon, and a profile that can't be written no longer stops the rest of setup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| __shelltime_agy_start=${EPOCHREALTIME:-} | ||
| __shelltime_agy_report() { | ||
| local status=$? st="$HOME/.shelltime" ms= IFS=$' \t\n' | ||
| set +euf |
There was a problem hiding this comment.
Nit (optional): The report function claims to print nothing, but it only turns off -e, -u and -f. If the agent's command runs set -x (or set -v), the trap body's trace lines go to the command's stderr. The agent then sees extra output the command never produced. Fix: also run set +xv at the top of __shelltime_agy_report, or redirect the whole body (for example wrap it in { ...; } 2>/dev/null).
| fi | ||
| printf '%s' "$BASH_EXECUTION_STRING" | SHELLTIME_CLOUD=true "$st/bin/shelltime" hook-ingest --agent agy \ | ||
| --event ShellCommand --session "$JULES_SESSION_ID" --exit-code "$status" ${ms:+--duration-ms "$ms"} >/dev/null 2>&1 | ||
| (unset SHELLTIME_AGY_COMMAND JULES_SESSION_ID; "$st/bin/cloud-start.sh" >/dev/null 2>&1 </dev/null &) |
There was a problem hiding this comment.
Nit (optional): cloud-start.sh is detached only with ( ... &). It stays in the command's process group and session, and it starts on every command, running pgrep each time. If the remote agent's launcher kills the command's process group or cgroup when the command returns, cloud-start.sh can die before it starts the daemon. The command's own record then stays in the pending file with no daemon to send it. Fix: start it with setsid (when available), for example (unset ...; setsid "$st/bin/cloud-start.sh" ... &), as the daemon start already does.
| # One at a time: an Antigravity remote agent's commands each start this, often | ||
| # together, and two could both find no daemon and remove each other's socket. | ||
| # The daemon doesn't keep the lock (9>&- below). | ||
| if command -v flock >/dev/null 2>&1 && exec 9>"$st/cloud-start.lock"; then |
There was a problem hiding this comment.
Nit (optional): If cloud-start.sh can't open cloud-start.lock for writing, the exec 9> redirection error is printed to stderr and the script runs without the lock. This happens when the file was created by another user, for example root running the script by hand. Every command then runs the check-then-start sequence unserialized. That brings back the duplicate-daemon and socket-removal race this change fixes, and it says nothing about it. Fix: chmod the lock file or place it somewhere per-user, silence the error (exec 9>... 2>/dev/null), and consider a mkdir-based fallback lock.
| if [ -n "$__shelltime_agy_start" ] && [ -n "${EPOCHREALTIME:-}" ]; then | ||
| ms=$(( (10#${EPOCHREALTIME//[!0-9]/} - 10#${__shelltime_agy_start//[!0-9]/}) / 1000 )) | ||
| fi | ||
| printf '%s' "$BASH_EXECUTION_STRING" | SHELLTIME_CLOUD=true "$st/bin/shelltime" hook-ingest --agent agy \ |
There was a problem hiding this comment.
Nit (optional): The full command string is sent to hook-ingest, and from there to ShellTime. The header comment says "Prompts, replies and tokens never reach the VM", but a command such as curl -H "Authorization: Bearer ..." or export TOKEN=... && ... carries secrets inline, and they are now recorded verbatim. Fix: say so in the docs, or have the CLI redact obvious secrets before storing them.
| echo "$out" | ||
| echo "$out" | grep -q "ShellTime is installed; Antigravity sessions" || { echo "run $run did not finish"; exit 1; } | ||
| done | ||
| # Without a login profile the line goes into a new ~/.profile, once |
There was a problem hiding this comment.
Nit (optional): The new checks don't cover the /etc/profile.d/shelltime-agy-cloud.sh branch of install_agy_shell_profile, which is the only fallback when a tool later creates ~/.bash_profile. The runner isn't root, so that branch is skipped. A typo in the generated file, or a /etc/profile that doesn't source profile.d, goes unnoticed. Fix: add a root run (for example via sudo, then remove the file) or at least assert the file's content and that a bash -l reads it.
Why
Antigravity remote agents (
antigravity.google.com/remote) run outside their VM and run no hook there. Every command arrives ascmdlauncher -e JULES_SESSION_ID=… -u antigravity … /bin/bash -l -c <command>. So the.agents/hooks.jsonhooks and theshelltime-cloudSessionStart hook thatcloud.bashsets up never fire, and nothing of those conversations reached ShellTime. A remote VM showed it: setup had installed everything, but there was no pending file, no daemon and no Antigravity data. See shelltime/cli#366 for the details.What
For Antigravity cloud,
cloud.bashnow:~/.shelltime/bin/agy-cloud-profile.sh. WhenJULES_SESSION_IDandBASH_EXECUTION_STRINGare set, it adds an EXIT trap that:shelltime hook-ingest --agent agy --event ShellCommand --session "$JULES_SESSION_ID" --exit-code <status> [--duration-ms <ms>](the duration comes fromEPOCHREALTIME, bash 5)cloud-start.sh, which signs in and starts the daemon. The command is recorded first, so without a daemon it goes to the pending file, which a starting daemon sends first.SHELLTIME_AGY_COMMAND)~/.bash_profile,~/.bash_login,~/.profile, else a new~/.profile. It's one line, and a rerun doesn't add a second.antigravitywhen setup ran as root.The hooks setup stays for places where Antigravity does run hooks. The comments, the closing message and CLAUDE.md now describe both.
Merge after shelltime/cli#366 is released.
cloud.bashinstalls the latest CLI release, and an older CLI drops these reports, harmlessly.Tests
test-cloud, Antigravity run): the profile line is there exactly once after two runs. With a stubshelltime, abash -l -ccommand underJULES_SESSION_ID:bash -lincluded, with the right flags, stdin and a duration of at least 200 msJULES_SESSION_IDEPOCHREALTIME.Follow-up
The guide
content/blogs/track-cursor-and-antigravity/in the web repo doesn't cover remote agents yet.🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.