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`; 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, 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 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`. 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 @@ -275,7 +275,9 @@ shelltime cc pr --session-id <claude-code-session-id> https://github.com/owner/r

The command hands the URLs to the daemon, and the daemon sends them to ShellTime, where they appear on the session. If no daemon is running, the CLI sends them itself. A session can link any number of PRs. Sending the same URL again does nothing. The command does nothing if you are not logged in.

For Codex, and for Claude Code sessions without the mod, the ShellTime server looks for opened PRs in the OTEL data the daemon forwards. It confirms them through the ShellTime GitHub App, so this needs the app connected in your ShellTime settings.
For **Cursor** and **Google Antigravity**, `shelltime hook-ingest` watches successful `gh pr create` and GitHub MCP `create_pull_request` calls (`postToolUse` / `PostToolUse`, reading the Antigravity `transcript.jsonl` step when present) and extracts only the created pull request URLs — raw tool output is never stored or uploaded — so the daemon links them via `/api/v1/cc/session-pull-requests`.

For Codex, Claude Code sessions without the mod, and Cursor or Antigravity calls whose output was not visible locally, the ShellTime server also looks for opened PRs in the telemetry the daemon forwards. It confirms them through the ShellTime GitHub App, so this needs the app connected in your ShellTime settings.

## Security and Privacy

Expand Down
3 changes: 3 additions & 0 deletions agenthook/antigravity.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func normalizeAntigravity(ev *Event, event string, p payload) {
} else {
ev.EventType = EventToolUse
ev.Status = StatusOK
if isPRCreateToolCall(ev.ToolName, ev.Command) {
ev.PullRequestURLs = extractAntigravityToolPRURLs(p, transcript)
}
}
case strings.ToLower(AntigravityPostInvocation):
ev.EventType = EventAgentResponse
Expand Down
Loading
Loading