Skip to content

feat(agenthook): record Antigravity remote agent commands from the login shell - #366

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

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

Conversation

@AnnatarHe

@AnnatarHe AnnatarHe commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Why

Antigravity remote agent conversations (antigravity.google.com/remote/…) never showed up on the Antigravity page, even with cloud.bash in the environment's setup script and .agents/hooks.json committed.

Checking inside a remote VM showed why:

  • Setup worked. The CLI, the daemon, the token in config.yaml, and the shelltime-cloud hook in ~/.gemini/config/hooks.json were all in place.
  • No hook ran. There was no agent-hooks.pending.jsonl, no daemon log, and log.log was untouched since setup. ~/.gemini held only the config folder cloud.bash created, and no Antigravity data folder.
  • The agent runs outside the VM. Each command arrives as /usr/local/bin/cmdlauncher -e JULES_SESSION_ID=… -u antigravity -w /home/antigravity /bin/bash -l -c ….

So hooks can't see these conversations. A login profile can see every command, though, and both JULES_SESSION_ID and $BASH_EXECUTION_STRING (the command) are available to it.

What

shelltime hook-ingest --agent agy --event ShellCommand --session <id> --exit-code <n> [--duration-ms <ms>]:

  • Reads the command from stdin.
  • Records it as one of Antigravity's run_command calls (agenthook.NormalizeShellCommand):
    • tool_use, or tool_failure with exit status <n> when the command exited non-zero
    • metadata.exit_code and metadata.source = login_shell
    • the working directory as the workspace
    • marked cloud by the OS user antigravity (antigravity_sandbox)
  • Delivers it like any hook event: to the daemon, else to the pending file. That shared path is now recordHookEvent.
  • Writes nothing to stdout, since no agent waits for a reply. On a usage error it logs and drops the command.
  • Only Antigravity is accepted; Cursor runs its hooks in its cloud VMs.

An older CLI that gets these flags falls into OnUsageError and records nothing, so it's safe to roll out in either order.

The login profile script that calls this is in shelltime/installation (cloud.bash), in a separate PR that should merge after this one is released.

Not covered

  • Prompts, replies, tokens and cost never enter the VM, so these sessions only have commands, failures, durations and a timeline.
  • gh pr create in such a command isn't linked to the session, because the output isn't captured.
  • A command that never cds is recorded under /home/antigravity, the launcher's working directory.

Tests

  • agenthook: fields, exit status, cloud mark (including an explicit SHELLTIME_CLOUD=false), refusals, the 64 KB cap, JSON-safe tool input
  • commands: saved without a daemon, sent to a daemon, no session, bad flags; stdout stays empty throughout
  • By hand: the built CLI plus the profile script from the installation PR under a fake home. Output and exit status were untouched, nested bash -l wasn't double-counted, and the event landed in the pending file.
  • go test ./...: everything passes except model's TestParseAntigravityDBs_ProtobufAndDedup, which fails on macOS only (/private/var vs /var), comes from feat(aicode): add Cursor and Antigravity usage backfill and daemon sync #364, and is not touched here.

🤖 Generated with Claude Code


Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…gin shell

An Antigravity remote agent (antigravity.google.com/remote) runs outside its
VM and runs no hook there, neither .agents/hooks.json nor
~/.gemini/config/hooks.json, so nothing of its conversations reached ShellTime.
It sends each command into the VM as `bash -l -c <command>` with
JULES_SESSION_ID set, which a login profile can report.

`shelltime hook-ingest --agent agy --event ShellCommand --session <id>
--exit-code <n> [--duration-ms <ms>]` reads the command from stdin and records
it as one of Antigravity's run_command calls (a tool_failure when it exited
non-zero), in the working directory, marked cloud by the OS user antigravity.
It writes nothing to stdout and drops the command on a usage error.

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:25:08.341266Z 2993e35 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.

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.76471% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
commands/hook_ingest.go 87.09% 4 Missing ⚠️
agenthook/shell_command.go 94.44% 3 Missing ⚠️
Flag Coverage Δ
unittests 86.09% <91.76%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
agenthook/shell_command.go 94.44% <94.44%> (ø)
commands/hook_ingest.go 93.98% <87.09%> (-2.10%) ⬇️

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread agenthook/shell_command.go Outdated
Workspace: workspace,
ToolName: AntigravityShellTool,
Command: command,
ToolInput: strings.TrimSuffix(input.String(), "\n"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): ToolInput is a JSON string built from the whole command and then cut by capEvent at MaxTextBytes. For a command longer than about 64 KB (a heredoc that writes a file, say), the cut lands inside the JSON, so the stored tool_input is no longer valid JSON. A consumer that parses it will fail on exactly these events. TestNormalizeShellCommand_CapsText only checks the length, not that the result parses.

Fix: cap command and workspace to a budget well under MaxTextBytes before encoding, so the encoded input always fits whole. Add a json.Unmarshal assertion to the cap test.

Command: command,
ToolInput: strings.TrimSuffix(input.String(), "\n"),
}
if cmd.DurationMs > 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): cmd.DurationMs > 0 treats an explicit --duration-ms 0 the same as "unknown" (-1). If the login-shell script measures in whole seconds or truncates, every fast command reports 0 and loses its duration. Only the -1 default means unknown. Fix: use >= 0 if Event.DurationMs can tell 0 from unset. Otherwise document that 0 is dropped.

Comment thread commands/hook_ingest.go
// The log goes to a file (or stderr), never stdout
SetupLogger(os.ExpandEnv("$HOME/" + model.COMMAND_BASE_STORAGE_FOLDER))

readCtx, cancel := context.WithTimeout(ctx, hookIngestStdinTimeout)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): The shell-command path reuses hookIngestStdinTimeout (500 ms), a bound meant for an agent that waits on a hook. Here the reader is a login shell's exit trap. If the profile script ever runs hook-ingest with stdin left open and nothing written (a tty, or a slow pipe), readWithTimeout stalls the shell's exit for the full 500 ms, and the command is silently dropped with only a log line. Fix: say in a comment that this is intended, or use a separate timeout for this mode.

Comment thread commands/hook_ingest.go
cmd.Command = string(stdin)
cmd.Workspace, _ = hookIngestGetwd()

ev, err := agenthook.NormalizeShellCommand(agent, cmd, hookIngestNow(), hookIngestGetenv)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): Every shell-command event gets a fresh random NewID(), and nothing here dedupes. If the login profile's exit hook fires twice for one command (profile sourced from both .bash_profile and .profile, or a nested bash -l -c under the agent's command that inherits JULES_SESSION_ID), the same command is recorded twice under different ids and counted twice. Fix: have the profile script guard against re-entry (an exported marker variable), or derive the id from session, command and time. Also confirm that nested login shells are not meant to be recorded.

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

⏱️ shelltime track performance

✅ No significant change in shelltime track latency

Comparing main @ 8685792 → #366 @ a69c46c. Each scenario execs the binary the way the shell hooks do; values are the median of 10 interleaved rounds. Lower is better.

Scenario base head Δ p
Startup/floor 302 µs ±3% 297 µs ±1% ~ 0.063 A/A
Startup/version 3.04 ms ±3% 3.01 ms ±1% -0.91% 0.009 ✅
Track/daemon/pre 3.21 ms ±2% 3.15 ms ±2% -1.96% 0.011 ✅
Track/daemon/post 3.19 ms ±2% 3.16 ms ±1% -0.88% 0.035 ✅
Track/direct/pre 3.17 ms ±2% 3.16 ms ±2% ~ 0.481 ✅
Track/direct/post 4.34 ms ±1% 4.37 ms ±2% ~ 0.912 ✅
Track/direct/post-sync 6.11 ms ±2% 6.14 ms ±2% ~ 1.000 ✅

Binary size: 23.6 MiB → 23.6 MiB (+0.0%).

CPU, tail latency and memory

Per exec, base → head (Δ when significant).

Scenario p95 wall user CPU sys CPU peak RSS
Startup/floor 353 µs → 351 µs 223 µs → 221 µs 44 µs → 47 µs 9.3 MiB → 9.4 MiB
Startup/version 3.22 ms → 3.23 ms 1.50 ms → 1.50 ms 1.90 ms → 1.88 ms 17.1 MiB → 16.9 MiB (-1.11%)
Track/daemon/pre 3.44 ms → 3.35 ms (-2.83%) 1.66 ms → 1.55 ms 1.93 ms → 1.96 ms 17.6 MiB → 17.6 MiB (-0.19%)
Track/daemon/post 3.40 ms → 3.34 ms (-1.94%) 1.59 ms → 1.58 ms 1.97 ms → 1.94 ms 17.4 MiB → 17.5 MiB (+0.27%)
Track/direct/pre 3.39 ms → 3.38 ms 1.64 ms → 1.64 ms 1.91 ms → 1.89 ms 17.5 MiB → 17.6 MiB (+0.44%)
Track/direct/post 4.57 ms → 4.59 ms 2.71 ms → 2.67 ms 2.09 ms → 2.14 ms 18.0 MiB → 18.1 MiB (+0.27%)
Track/direct/post-sync 6.49 ms → 6.50 ms 4.65 ms → 4.57 ms 3.42 ms → 3.43 ms 20.7 MiB → 20.6 MiB (-0.44%)
benchstat
goos: linux
goarch: amd64
pkg: github.com/malamtime/cli/perf
cpu: Intel(R) Xeon(R) 6975P-C
                         │    base     │                head                │
                         │   sec/op    │   sec/op     vs base               │
Startup/floor-4            302.3µ ± 3%   297.2µ ± 1%       ~ (p=0.063 n=10)
Startup/version-4          3.035m ± 3%   3.007m ± 1%  -0.91% (p=0.009 n=10)
Track/daemon/pre-4         3.213m ± 2%   3.150m ± 2%  -1.96% (p=0.011 n=10)
Track/daemon/post-4        3.189m ± 2%   3.160m ± 1%  -0.88% (p=0.035 n=10)
Track/direct/pre-4         3.175m ± 2%   3.165m ± 2%       ~ (p=0.481 n=10)
Track/direct/post-4        4.342m ± 1%   4.370m ± 2%       ~ (p=0.912 n=10)
Track/direct/post-sync-4   6.109m ± 2%   6.143m ± 2%       ~ (p=1.000 n=10)
geomean                    2.595m        2.578m       -0.65%

                         │    base     │                head                │
                         │ p50-sec/op  │ p50-sec/op   vs base               │
Startup/floor-4            292.5µ ± 2%   288.7µ ± 1%       ~ (p=0.052 n=10)
Startup/version-4          3.023m ± 3%   2.986m ± 1%  -1.24% (p=0.007 n=10)
Track/daemon/pre-4         3.187m ± 2%   3.130m ± 2%  -1.79% (p=0.011 n=10)
Track/daemon/post-4        3.177m ± 2%   3.141m ± 1%       ~ (p=0.063 n=10)
Track/direct/pre-4         3.153m ± 3%   3.143m ± 2%       ~ (p=0.481 n=10)
Track/direct/post-4        4.323m ± 1%   4.347m ± 2%       ~ (p=0.971 n=10)
Track/direct/post-sync-4   6.101m ± 2%   6.146m ± 2%       ~ (p=0.796 n=10)
geomean                    2.572m        2.556m       -0.64%

                         │    base     │                head                │
                         │ p95-sec/op  │ p95-sec/op   vs base               │
Startup/floor-4            353.2µ ± 5%   351.2µ ± 4%       ~ (p=0.971 n=10)
Startup/version-4          3.222m ± 3%   3.226m ± 2%       ~ (p=0.280 n=10)
Track/daemon/pre-4         3.443m ± 3%   3.346m ± 2%  -2.83% (p=0.005 n=10)
Track/daemon/post-4        3.402m ± 2%   3.336m ± 2%  -1.94% (p=0.043 n=10)
Track/direct/pre-4         3.386m ± 1%   3.384m ± 2%       ~ (p=0.912 n=10)
Track/direct/post-4        4.573m ± 1%   4.591m ± 2%       ~ (p=0.579 n=10)
Track/direct/post-sync-4   6.492m ± 1%   6.502m ± 2%       ~ (p=0.971 n=10)
geomean                    2.797m        2.778m       -0.68%

                         │     base     │                head                 │
                         │  peak-rss-B  │  peak-rss-B   vs base               │
Startup/floor-4            9.306Mi ± 1%   9.384Mi ± 1%       ~ (p=0.631 n=10)
Startup/version-4          17.11Mi ± 0%   16.92Mi ± 0%  -1.11% (p=0.000 n=10)
Track/daemon/pre-4         17.61Mi ± 0%   17.57Mi ± 0%  -0.19% (p=0.000 n=10)
Track/daemon/post-4        17.43Mi ± 0%   17.48Mi ± 0%  +0.27% (p=0.000 n=10)
Track/direct/pre-4         17.51Mi ± 0%   17.59Mi ± 0%  +0.44% (p=0.000 n=10)
Track/direct/post-4        18.03Mi ± 0%   18.08Mi ± 0%  +0.27% (p=0.000 n=10)
Track/direct/post-sync-4   20.68Mi ± 0%   20.59Mi ± 0%  -0.44% (p=0.000 n=10)
geomean                    16.40Mi        16.40Mi       +0.01%

                         │     base     │                head                 │
                         │  sys-sec/op  │  sys-sec/op   vs base               │
Startup/floor-4            43.92µ ± 26%   46.99µ ± 23%       ~ (p=1.000 n=10)
Startup/version-4          1.900m ±  9%   1.875m ±  9%       ~ (p=0.143 n=10)
Track/daemon/pre-4         1.934m ±  9%   1.957m ± 10%       ~ (p=0.739 n=10)
Track/daemon/post-4        1.972m ±  8%   1.937m ±  7%       ~ (p=0.579 n=10)
Track/direct/pre-4         1.912m ±  4%   1.886m ±  6%       ~ (p=0.853 n=10)
Track/direct/post-4        2.088m ±  5%   2.144m ±  7%       ~ (p=0.481 n=10)
Track/direct/post-sync-4   3.422m ±  8%   3.427m ±  4%       ~ (p=0.280 n=10)
geomean                    1.234m         1.245m        +0.89%

                         │     base     │                head                 │
                         │ user-sec/op  │ user-sec/op   vs base               │
Startup/floor-4            222.8µ ±  5%   221.1µ ±  4%       ~ (p=0.436 n=10)
Startup/version-4          1.504m ± 12%   1.501m ±  9%       ~ (p=0.684 n=10)
Track/daemon/pre-4         1.656m ± 11%   1.550m ± 12%       ~ (p=0.796 n=10)
Track/daemon/post-4        1.587m ± 11%   1.578m ± 10%       ~ (p=0.631 n=10)
Track/direct/pre-4         1.635m ±  4%   1.636m ±  7%       ~ (p=0.971 n=10)
Track/direct/post-4        2.710m ±  4%   2.673m ±  4%       ~ (p=0.353 n=10)
Track/direct/post-sync-4   4.648m ±  4%   4.570m ±  3%       ~ (p=0.123 n=10)
geomean                    1.513m         1.489m        -1.58%

Δ compares medians; ~ means no significant difference (Mann-Whitney U, p ≥ 0.05). A scenario is flagged when it is more than 10% and more than 250µs slower with p < 0.05. Startup/floor runs true, not shelltime: it is an A/A check of runner noise. Runner: linux/amd64, Intel(R) Xeon(R) 6975P-C. go1.27.1, 10 rounds × 100 execs per scenario and binary.

@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

capEvent cut the encoded run_command input at 64 KB, inside the JSON for a
longer command. The command is now cut in proportion before it is encoded
(escaping can make it six times longer), the folder is capped at a path's
length, and the zero duration and stdin bound are documented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2993e354cf

ℹ️ 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".

Comment thread commands/hook_ingest.go
Comment on lines +64 to +65
if agenthook.IsShellCommandEvent(c.String("event")) {
runShellCommandIngest(c.Context, c.String("agent"), agenthook.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.

P1 Badge Document the remote-agent integration in user-facing docs

For users setting up Antigravity remote agents, the new login-shell ingestion mode is described only in code and CLAUDE.md; neither README.md nor docs/CONFIG.md explains it. The README's Cloud agents section still describes repository hooks for the Gemini API sandbox, which this change explicitly distinguishes from remote agents that run no hooks inside the VM. Add user-facing documentation distinguishing those environments, explaining the required login-profile integration and its installation dependency, and noting that remote sessions capture commands rather than prompts, replies or token usage. AGENTS.md requires integration and setup changes to update documentation in the same commit.

AGENTS.md reference: AGENTS.md:L54-L58

Useful? React with 👍 / 👎.

}
ev.SetMetadata("exit_code", int64(cmd.ExitCode))
ev.SetMetadata("source", "login_shell")
ev.Cloud = cloudSignal(canonical, payload{}, getenv)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): A command from an Antigravity remote VM is only marked cloud when the login user is antigravity or the hook's environment sets SHELLTIME_CLOUD/CLAUDE_CODE_REMOTE. This event exists only because the VM's profile script reported it, so it is cloud by definition. If the remote VM runs commands as another OS user (root, say) and SHELLTIME_CLOUD isn't exported to the login shell, ev.Cloud stays empty and the server files the session as one from a local machine.

Fix: set ev.Cloud to a signal for this mode, such as the JULES_SESSION_ID the VM sets, unless SHELLTIME_CLOUD=false says otherwise. Or check that cloud.bash always exports SHELLTIME_CLOUD=true.

Comment thread commands/hook_ingest.go
return
}
cmd.Command = string(stdin)
cmd.Workspace, _ = hookIngestGetwd()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): Workspace is the directory the command ended in, not where it started. The daemon takes the repository from Workspace (prepareAgentHookEvents). A command like cd /tmp && curl ... or cd ~/other && make is attributed to /tmp or ~/other, not the agent's project. That can split one session across several projects, or leave it without a repository.

Fix: have the profile script pass the starting directory (for example its $PWD at login) and use that for Workspace. Keep the ending directory in Cwd or metadata if it is still wanted.

Comment thread commands/hook_ingest.go
OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
// The hook still answers. Read the flags from the arguments as they are.
agent, event, project := hookIngestFlagsFromArgs(hookIngestRawArgs())
if agenthook.IsShellCommandEvent(event) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): A malformed optional flag drops the whole command. If --exit-code or --duration-ms is empty or non-numeric (an unset variable in the profile script, say), urfave raises a usage error, and OnUsageError logs a warning and records nothing. The command, session and agent could still be recovered, since hookIngestFlagsFromArgs already reads the raw arguments.

Fix: read --session from the raw arguments too, and record the event without the bad numeric flag. Or have the profile script always pass numbers.

Remote agents run no hooks in their VM, so the README's cloud agents
section now says how they are tracked instead: cloud.bash's login profile
script and `hook-ingest --event ShellCommand`, and what those sessions lack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
}
ev.SetMetadata("exit_code", int64(cmd.ExitCode))
ev.SetMetadata("source", "login_shell")
ev.Cloud = cloudSignal(canonical, payload{}, getenv)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): Shell-command events never get a Surface. Every Antigravity hook event gets one from antigravitySurface(transcriptPath) (SurfaceCLI or SurfaceIDE), but this path leaves it empty. A remote agent's run_command events then reach the server with surface="" and cloud set, so they may be grouped or filtered differently from the other Antigravity sessions. Fix: set ev.Surface explicitly, to a remote or cloud surface constant if the server has one, or confirm the server accepts an empty surface for these events.

Comment thread commands/hook_ingest.go
}()

// The log goes to a file (or stderr), never stdout
SetupLogger(os.ExpandEnv("$HOME/" + model.COMMAND_BASE_STORAGE_FOLDER))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): runShellCommandIngest runs inside the agent's login shell at exit, so anything this process writes to stderr is part of the command's output that the agent sees. SetupLogger writes to stderr when it can't open the log file (os.Stderr.WriteString(err.Error())), and before it runs, slog defaults to stderr. With an unwritable $HOME/.shelltime, every agent command then gets an extra error line appended. Fix: in this mode, discard stderr or install slog.DiscardHandler when the log file can't be opened.

Comment thread commands/hook_ingest.go

// The profile pipes the command in, so stdin ends at once; the hooks' bound only matters for
// a caller that leaves it open, whose shell then waits that long to exit
readCtx, cancel := context.WithTimeout(ctx, hookIngestStdinTimeout)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): readWithTimeout returns nil, ctx.Err() when the 500 ms bound fires, so a command whose stdin is slow to close, for example on a loaded VM, is dropped completely. Only the "too large" case keeps what was read. The command text is the event's whole content, and the data already read is thrown away. Fix: read into a buffer that survives the timeout, or accept the loss and document it. At the least, log the timeout distinctly so lost commands can be told apart from empty ones.

Timestamp: now.UTC().Format(time.RFC3339Nano),
Workspace: workspace,
ToolName: AntigravityShellTool,
Command: strings.TrimSpace(cmd.Command),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit (optional): The tool input and Command can disagree. When escaping pushes the encoded JSON over 64 KB, the loop cuts command for ToolInput, but Command still holds the full trimmed text, up to 64 KB. The same event then shows two different commands, and a secret near the end of a long command stays in Command after being cut from CommandLine. Also, gh pr create run through this path never gets PullRequestURLs, because no output is available, so PR linking silently doesn't work for remote agents. Fix: cap Command to the same cut command, and state the PR-link limitation in the docs.

@AnnatarHe
AnnatarHe merged commit 661c85f into main Nov 29, 2026
14 checks passed
@AnnatarHe
AnnatarHe deleted the feat/agy-remote-shell-commands branch November 29, 2026 15:32
AnnatarHe added a commit to shelltime/installation that referenced this pull request Nov 29, 2026
…shell (#22)

* feat(cloud): record Antigravity remote agent commands from the login 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>

* fix(cloud): never hold a remote agent's command on the daemon start

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>

* fix(cloud): start one daemon when remote agent commands start it together

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>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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