Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Optional daemon services (feature-gated via config):
- **AICodeOtelServer**: gRPC OTEL collector for AI coding CLI metrics, logs and traces (Claude Code, Codex). Spans (`claude_code.interaction`, `llm_request`, `tool`, ...) go to the same `/api/v1/cc/otel` endpoint in `spans`; a span without `session.id` takes it from another span of its trace in the same export. `shelltime cc install` turns traces on (`CLAUDE_CODE_ENHANCED_TELEMETRY_BETA`, `OTEL_TRACES_EXPORTER=otlp`). In a Claude Code cloud session (`CLAUDE_CODE_REMOTE=true`, where the SessionStart hook starts the daemon) it adds the VM's `CLAUDE_CODE_REMOTE_SESSION_ID` as the `ccr.session.id` attribute to Claude Code records that lack it; the server marks those sessions as cloud sessions. `daemon/main_test.go` clears both variables so tests behave the same inside a cloud session
- **Git repositories** (`model/git_repository.go`): the server groups coding agent sessions into projects by git repository, not folder, so a renamed or moved clone, a worktree or a subfolder stays one project. `GitRepositoryResolver` asks the git CLI (found through `CommandService`, so the daemon's limited PATH reaches Homebrew) for a directory's top level and its `origin` remote (else `upstream`, else the first by name; `remote get-url`, so `insteadOf` applies) without optional locks, within one 2 s budget per lookup, since the daemon resolves on the OTLP export path. Concurrent lookups of one directory share one run, which goes on its own goroutine: a stat or git blocked in the kernel (a hung network mount) ignores the context, so the lookup is given up on after the budget (plus `gitRepositoryGrace`), or when its caller's context ends, and the directory gets no other until it returns (its answer is kept then). git runs with `LC_ALL=C`, since its messages are read; a remote's path segments are decoded and escaped again (`url.PathEscape`), like the server's. A migration run stops asking after `projectMigrationMaxUnanswered` folders' stats timed out (a hung mount; git refusing a folder doesn't count), and a folder that doesn't exist counts as missing, one it can't stat otherwise as unchecked. git refusing a repository it doesn't trust (`safe.directory`) or killed by a signal is no answer about the directory; a git binary not found is looked for again every 30 s. It keeps definitive answers, negative ones too (10 min in the daemon), and a timeout or git failing to start for 30 s only, reported as unknown by `Lookup` (`Resolve` drops the flag). `CanonicalRepositoryURL` turns any remote into `https://<host>/<path>` without credentials, port or `.git`, the form Claude Code reports; a local path is no repository. The repository travels as `vcs.repository.url.full` (`model.AICodeRepositoryAttribute`): the OTEL processor adds it to metrics and log events whose resource has a `pwd` and that don't name one (not to spans: the server keys a session from its events), and never when the resource names one (Claude Code's own value wins; git isn't asked then), the socket's `session_project` handler sends it with the statusline's directory, and backfill adds it to uploaded events (Codex's `session_meta.git.repository_url` first, since it was true when the session ran, else the transcript directory's). `aiCodeOtel.sendRepository: false` (`ShellTimeConfig.SendsRepository`) turns all of it off: no resolver in the processor or the socket, the processor removes the attribute from every record (the agent's own too), backfill attaches none, and neither the daemon nor `cc projects` migrates
- **Project migration** (`daemon/project_migration.go`, `model/project_migration.go`): sessions recorded before the repository was sent are folder projects on the server. A while after start the daemon runs `MigrateProjectRepositories` once, never in AI cloud only mode (marker `~/.shelltime/project-repositories.v1`, written only when the run is `Complete`: a 404 from an older server, a failure, more pages than one run goes through (50), a folder git couldn't answer for, or a machine without a host name of its own leaves none, so the next start tries again): it lists the folder projects of this machine's names (`ProjectMigrationHosts`: the host name, without its domain, and the `machine.name` in `~/.claude/settings.json`, leaving out names many machines share, like `localhost`, `genericHostNames`) from `POST /api/v1/cc/projects/unresolved`, a page at a time by the last project of the page (`after`), and posts the folders that still exist and are clones to `POST /api/v1/cc/projects/repositories`. `shelltime cc projects` / `shelltime codex projects` run it by hand (`--dry-run` lists what would move; skipped in AI cloud only mode)
- **Agent hooks (Cursor, Antigravity)**: neither has OTEL, so `shelltime cursor install` / `shelltime agy install` (`commands/agent_hooks_install.go`; `model/cursor_hooks.go`, `model/antigravity_hooks.go`, on the ordered-JSON kit of `model/aicode_otel_claude_settings.go`) register the hidden `shelltime hook-ingest --agent cursor|agy --event <name> --project` in the current repository's `.cursor/hooks.json` and in a `shelltime` group of its `.agents/hooks.json` (`model.ProjectHooksRoot`: the nearest folder up with `.git` below the home folder, else the folder itself, never the home folder, `ErrHomeIsNotAProject`), the only files Cursor Cloud Agents and the Antigravity agent's Gemini API sandbox run (never PreToolUse: a reply without a decision denies the tool; a file with a BOM, comments or invalid JSON is refused, never rewritten). Installing into a user-level file is refused (`ErrUserHooksRetired`), and so is Windows (`ErrProjectHooksUnsupported`: no daemon there); install leaves what older versions put in `~/.cursor/hooks.json` / `~/.gemini/config/hooks.json` (they still record every other folder) and says so, uninstall removes it (a user file it can't read is a warning, never a failure), and doctor's fix removes it when its binary is gone. The file is committed and the agents disagree on the folder a hook runs in, so each command is self-contained POSIX sh (`projectHookCommand`): it adds `model.ProjectHookSearchDirs` (`~/.shelltime/bin`, `/opt/homebrew/bin`, `/usr/local/bin`; doctor checks the same) to PATH, runs hook-ingest only when `shelltime` and `shelltime-daemon` are both found, and echoes the pass-through reply otherwise or when hook-ingest fails (a `shelltime` from before it exits non-zero; its stdout is dropped). A `--project` run whose event an older version's user-level hook records too (`userHooksRecord`: the user file registers that event with an absolute, executable binary, `AgentHooksStatus.EventBinaries`; Antigravity hooks and groups marked `"enabled": false` don't count) and that isn't cloud goes to the daemon with `YieldToUserHooks`, and the batcher drops it unless its session is cloud (Cloud Agents run no user-level hooks; Cursor marks only `sessionStart`); without a daemon hook-ingest drops it. The mark never reaches the server (`prepareAgentHookEvents` clears it). `hook-ingest` writes nothing to stdout but `agenthook.PassThrough` (`{"continue":true}` for Cursor's beforeSubmitPrompt, `{"decision":"allow"}` for Antigravity's Stop, else `{}`), exactly once, even on a panic, and exits 0. The `agenthook` package (no dependency on `model`) normalizes the payloads into `agenthook.Event`; for successful `gh pr create` or GitHub MCP `create_pull_request` tool calls (`agenthook/pr.go`), it also extracts normalized PR URLs from Cursor `tool_output` (or Antigravity `transcript.jsonl` / output fields) into daemon-only `PullRequestURLs` without keeping raw tool output. Each event's `cloud` names what showed it ran in a cloud agent's VM (`agenthook.cloudSignal`): Cursor's `is_background_agent` (only in `sessionStart`) or, for Antigravity, the OS user `antigravity` (`agenthook.InAntigravitySandbox`: the user database, else `USER`/`LOGNAME`), else `SHELLTIME_CLOUD=true` or `CLAUDE_CODE_REMOTE=true` in the hook's environment (`agenthook.CloudEnvSignal`), and an explicit `SHELLTIME_CLOUD=false` overrides them all (`agenthook.CloudEnvExplicit`); neither agent marks every hook of a cloud run, and Cursor's `CURSOR_CODE_REMOTE` (any remote workspace, the user's SSH hosts too) is only `metadata.remote_workspace`. hook-ingest hands it to the daemon (`agent_hook` socket message, acknowledged within 50 ms) or, without one, applies `model.ApplyAgentHookPrivacy` and appends it to `~/.shelltime/agent-hooks.pending.jsonl`; a payload over 4 MiB is recorded from its first 4 MiB, marked `truncated` (`agenthook.NormalizeTruncated`: the top-level fields before the cut). `AgentHookBatcher` (`daemon/agent_hooks.go`) marks the later events of a session an event showed was cloud (for an hour after its last event, `fillCloudLocked`) and sends batches to `POST /api/v1/agent-hooks` every 2 s or 100 events (stripping `PullRequestURLs` from the wire payload and dispatching `model.SendSessionPullRequests` to `POST /api/v1/cc/session-pull-requests` once a chunk succeeds, deduplicated per session+URL within `agentHookSessionTTL` and honoring `Exclude`), readied by `prepareAgentHookEvents` (the workspace's repository under `aiCodeOtel.sendRepository`, and the privacy settings, `agentHooks.sendContent` included, from the config on disk), and saves what can be sent later (no token, the failures `agentHookSendCanWait` names, a 404/405 from a server without the endpoint among them) for `AgentHookResyncService` (30-min interval), which readies saved events and dispatches their saved `PullRequestURLs` the same way; both run in AI cloud only mode too. hook-ingest and the daemon share the pending file under `agent-hooks.pending.lock`, an advisory flock like the command store's: appends hold it shared and the resync's read-and-rewrite exclusively, nobody waits more than 50 ms (an append then goes ahead, a rewrite returns `ErrAgentHookPendingBusy` and the pass changes nothing), and a rewrite carries over the lines appended since its read
- **Agent hooks (Cursor, Antigravity)**: neither has OTEL, so `shelltime cursor install` / `shelltime agy install` (`commands/agent_hooks_install.go`; `model/cursor_hooks.go`, `model/antigravity_hooks.go`, on the ordered-JSON kit of `model/aicode_otel_claude_settings.go`) register the hidden `shelltime hook-ingest --agent cursor|agy --event <name> --project` in the current repository's `.cursor/hooks.json` and in a `shelltime` group of its `.agents/hooks.json` (`model.ProjectHooksRoot`: the nearest folder up with `.git` below the home folder, else the folder itself, never the home folder, `ErrHomeIsNotAProject`), the only files Cursor Cloud Agents and the Antigravity agent's Gemini API sandbox run (never PreToolUse: a reply without a decision denies the tool; a file with a BOM, comments or invalid JSON is refused, never rewritten). Installing into a user-level file is refused (`ErrUserHooksRetired`), and so is Windows (`ErrProjectHooksUnsupported`: no daemon there); install leaves what older versions put in `~/.cursor/hooks.json` / `~/.gemini/config/hooks.json` (they still record every other folder) and says so, uninstall removes it (a user file it can't read is a warning, never a failure), and doctor's fix removes it when its binary is gone. The file is committed and the agents disagree on the folder a hook runs in, so each command is self-contained POSIX sh (`projectHookCommand`): it adds `model.ProjectHookSearchDirs` (`~/.shelltime/bin`, `/opt/homebrew/bin`, `/usr/local/bin`; doctor checks the same) to PATH, runs hook-ingest only when `shelltime` and `shelltime-daemon` are both found, and echoes the pass-through reply otherwise or when hook-ingest fails (a `shelltime` from before it exits non-zero; its stdout is dropped). A `--project` run whose event an older version's user-level hook records too (`userHooksRecord`: the user file registers that event with an absolute, executable binary, `AgentHooksStatus.EventBinaries`; Antigravity hooks and groups marked `"enabled": false` don't count) and that isn't cloud goes to the daemon with `YieldToUserHooks`, and the batcher drops it unless its session is cloud (Cloud Agents run no user-level hooks; Cursor marks only `sessionStart`); without a daemon hook-ingest drops it. The mark never reaches the server (`prepareAgentHookEvents` clears it). `hook-ingest` writes nothing to stdout but `agenthook.PassThrough` (`{"continue":true}` for Cursor's beforeSubmitPrompt, `{"decision":"allow"}` for Antigravity's Stop, else `{}`), exactly once, even on a panic, and exits 0. The `agenthook` package (no dependency on `model`) normalizes the payloads into `agenthook.Event`; for successful `gh pr create` or GitHub MCP `create_pull_request` tool calls (`agenthook/pr.go`), it also extracts normalized PR URLs from Cursor `tool_output` (or Antigravity `transcript.jsonl` / output fields) into daemon-only `PullRequestURLs` without keeping raw tool output. Each event's `cloud` names what showed it ran in a cloud agent's VM (`agenthook.cloudSignal`): Cursor's `is_background_agent` (only in `sessionStart`) or, for Antigravity, the OS user `antigravity` (`agenthook.InAntigravitySandbox`: the user database, else `USER`/`LOGNAME`), else `SHELLTIME_CLOUD=true` or `CLAUDE_CODE_REMOTE=true` in the hook's environment (`agenthook.CloudEnvSignal`), and an explicit `SHELLTIME_CLOUD=false` overrides them all (`agenthook.CloudEnvExplicit`); neither agent marks every hook of a cloud run, and Cursor's `CURSOR_CODE_REMOTE` (any remote workspace, the user's SSH hosts too) is only `metadata.remote_workspace`. An Antigravity remote agent (antigravity.google.com/remote) runs outside its VM and runs no hook there: it sends each command in as `bash -l -c <command>` with `JULES_SESSION_ID` set, so `cloud.bash` (installation repo) adds a login profile script that pipes each command to `shelltime hook-ingest --agent agy --event ShellCommand --session <id> --exit-code <n> [--duration-ms <ms>]` when its shell exits. That mode (`agenthook.NormalizeShellCommand`, Antigravity only) records the command as a `run_command` call (`tool_failure` with `exit status <n>` when non-zero; `metadata.exit_code`, `metadata.source = login_shell`), the working directory as the workspace, writes nothing to stdout and drops the command on a usage error. hook-ingest hands it to the daemon (`agent_hook` socket message, acknowledged within 50 ms) or, without one, applies `model.ApplyAgentHookPrivacy` and appends it to `~/.shelltime/agent-hooks.pending.jsonl`; a payload over 4 MiB is recorded from its first 4 MiB, marked `truncated` (`agenthook.NormalizeTruncated`: the top-level fields before the cut). `AgentHookBatcher` (`daemon/agent_hooks.go`) marks the later events of a session an event showed was cloud (for an hour after its last event, `fillCloudLocked`) and sends batches to `POST /api/v1/agent-hooks` every 2 s or 100 events (stripping `PullRequestURLs` from the wire payload and dispatching `model.SendSessionPullRequests` to `POST /api/v1/cc/session-pull-requests` once a chunk succeeds, deduplicated per session+URL within `agentHookSessionTTL` and honoring `Exclude`), readied by `prepareAgentHookEvents` (the workspace's repository under `aiCodeOtel.sendRepository`, and the privacy settings, `agentHooks.sendContent` included, from the config on disk), and saves what can be sent later (no token, the failures `agentHookSendCanWait` names, a 404/405 from a server without the endpoint among them) for `AgentHookResyncService` (30-min interval), which readies saved events and dispatches their saved `PullRequestURLs` the same way; both run in AI cloud only mode too. hook-ingest and the daemon share the pending file under `agent-hooks.pending.lock`, an advisory flock like the command store's: appends hold it shared and the resync's read-and-rewrite exclusively, nobody waits more than 50 ms (an append then goes ahead, a rewrite returns `ErrAgentHookPendingBusy` and the pass changes nothing), and a rewrite carries over the lines appended since its read
- **HeartbeatResyncService**: Periodic resync of failed heartbeats (30-min interval)
- **CleanupTimerService**: Periodic log file cleanup (24-hour interval)

Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ shelltime agy install # in each repository you use Google Antigravity in
| `shelltime codex projects` | Same as `shelltime cc projects`: the projects of both agents are grouped together |
| `shelltime cursor install` | Add the ShellTime hooks to the current repository's `.cursor/hooks.json` (Cursor IDE, `cursor-agent` and Cloud Agents) |
| `shelltime cursor uninstall` | Remove the ShellTime hooks from the current repository's `.cursor/hooks.json` and `~/.cursor/hooks.json` |
| `shelltime agy install` | Add the ShellTime hook group to the current repository's `.agents/hooks.json` (Antigravity app, `agy` CLI and the Antigravity agent's Gemini API sandbox); `shelltime antigravity` works too |
| `shelltime agy install` | Add the ShellTime hook group to the current repository's `.agents/hooks.json` (Antigravity app, `agy` CLI and the Antigravity agent's Gemini API sandbox; remote agents run no hooks, see [Cloud agents](#cloud-agents)); `shelltime antigravity` works too |
| `shelltime agy uninstall` | Remove the ShellTime hook group from the current repository's `.agents/hooks.json` and `~/.gemini/config/hooks.json` |

### Environment helpers
Expand Down Expand Up @@ -226,6 +226,8 @@ Token usage (used to calculate estimated USD cost on the server) is captured per

In a Cursor Cloud Agent's environment, install ShellTime, sign it in (`shelltime auth --token …`), set `SHELLTIME_CLOUD=true` in the environment's variables or secrets, and keep `shelltime-daemon` running, started with that variable set: the daemon reads it once, when it starts (or put `aiCloudOnly: true` in its config). The committed hooks do the rest. Cursor marks a cloud run only in `sessionStart` (`is_background_agent`), which the daemon passes on to the session's later events, so the variable is what marks every event. The Antigravity agent's Gemini API sandbox needs the same setup (its environment takes variables too); its hooks are marked as cloud by the sandbox's OS user, `antigravity`, even without the variable. With the variable the machine collects AI coding agent usage only (see `aiCloudOnly` in [CONFIG.md](docs/CONFIG.md)). Claude Code cloud environments (`CLAUDE_CODE_REMOTE=true`) count as cloud too.

Antigravity **remote agents** (`antigravity.google.com/remote`) are different: the agent runs outside its VM and runs no hook there, neither `.agents/hooks.json` nor `~/.gemini/config/hooks.json`. It sends each command into the VM as `bash -l -c <command>` with `JULES_SESSION_ID` set. Add `curl -fsSL https://raw.githubusercontent.com/shelltime/installation/main/cloud.bash | bash` to the environment's setup script, with your token in `SHELLTIME_TOKEN`: it installs ShellTime and a login profile script that reports each command when its shell exits (`shelltime hook-ingest --agent agy --event ShellCommand --session <id> --exit-code <n> [--duration-ms <ms>]`, command on stdin). Each conversation then shows as a cloud Antigravity session of `run_command` calls, failed when the command exited non-zero, in the folder it ended in. Prompts, replies and token usage never reach the VM, so these sessions have none.

## Projects

ShellTime groups your coding agent sessions into projects by the git repository they ran in, so a renamed or moved clone, a worktree or a subfolder stays one project. The repository comes from the folder's `origin` remote (else `upstream`, else the first remote), sent as `https://<host>/<path>` with any credentials in the remote URL removed. Claude Code reports it itself (`shelltime cc install` turns this on); for Codex and older Claude Code setups the daemon asks git about the session's folder. Sessions outside a repository, or in one without a remote, are grouped by machine and folder.
Expand Down
Loading
Loading