Skip to content

feat(cloud): record Antigravity remote agent commands from the login shell - #22

Merged
AnnatarHe merged 3 commits into
mainfrom
feat/agy-remote-commands
Nov 29, 2026
Merged

AnnatarHe merged 3 commits into
mainfrom
feat/agy-remote-commands

Conversation

@AnnatarHe

@AnnatarHe AnnatarHe commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Why

Antigravity remote agents (antigravity.google.com/remote) run outside their VM and run no hook there. Every command arrives as cmdlauncher -e JULES_SESSION_ID=… -u antigravity … /bin/bash -l -c <command>. So the .agents/hooks.json hooks and the shelltime-cloud SessionStart hook that cloud.bash sets 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.bash now:

  • Writes ~/.shelltime/bin/agy-cloud-profile.sh. When JULES_SESSION_ID and BASH_EXECUTION_STRING are set, it adds an EXIT trap that:
    • pipes the command to shelltime hook-ingest --agent agy --event ShellCommand --session "$JULES_SESSION_ID" --exit-code <status> [--duration-ms <ms>] (the duration comes from EPOCHREALTIME, bash 5)
    • then runs 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.
    • prints nothing, keeps the command's exit status, and ignores shells the command starts itself (SHELLTIME_AGY_COMMAND)
  • Sources that script, for bash only, from the login profile bash reads: the first of ~/.bash_profile, ~/.bash_login, ~/.profile, else a new ~/.profile. It's one line, and a rerun doesn't add a second.
  • Gives that file to antigravity when 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.bash installs the latest CLI release, and an older CLI drops these reports, harmlessly.

Tests

  • CI (test-cloud, Antigravity run): the profile line is there exactly once after two runs. With a stub shelltime, a bash -l -c command under JULES_SESSION_ID:
    • keeps its output and exit status (7)
    • is reported once, nested bash -l included, with the right flags, stdin and a duration of at least 200 ms
    • reports nothing without JULES_SESSION_ID
  • By hand on macOS bash 3.2: the same with the real CLI from cli#366 and no daemon. The event landed in the pending file; there's no duration without EPOCHREALTIME.

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-bot with what you need.

…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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T15:31:28.132371Z b91b5e9 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@shelltime

shelltime Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

🤖 Claude Code · Fix Antigravity cloud-session detection in CLI

Improved the CLI’s Antigravity cloud-session handling by updating shell command/process detection logic, adding regression tests, and preparing the changes for review.

💰 Cost 🔢 Tokens ⏱️ Duration 🧠 Models 💬 Prompts ✏️ Lines
$12.52 34.4M 1h 23m (29m active) claude-opus-5-5, claude-haiku-5-5 7 +228 / −0

34.4M tokens: 39K input · 154.1K output · 33.7M cache read · 430.8K cache write

📝 AI summary

Investigated 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 cli/agenthook/shell_command.go with the recommended Antigravity handling changes and expanded cli/agenthook/shell_command_test.go to cover the relevant command/process patterns. The implementation was validated with targeted tests, and the resulting change set was prepared and raised for merge-request review.

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>
Comment thread cloud.bash Outdated
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 &)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cloud.bash Outdated
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 \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cloud.bash
# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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" ... &).

Comment thread cloud.bash Outdated
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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cloud.bash
LOGIN_PROFILE_PATH="$TARGET_HOME/$name"
break
fi
done

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Comment thread cloud.bash
__shelltime_agy_start=${EPOCHREALTIME:-}
__shelltime_agy_report() {
local status=$? st="$HOME/.shelltime" ms= IFS=$' \t\n'
set +euf

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment thread cloud.bash
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 &)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cloud.bash
# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cloud.bash
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 \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@AnnatarHe
AnnatarHe merged commit e5765c5 into main Nov 29, 2026
19 checks passed
@AnnatarHe
AnnatarHe deleted the feat/agy-remote-commands branch November 29, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant