Skip to content

RTECO-1017 - Detect agent + CI invocation context, enrich metrics wit…#1555

Open
fluxxBot wants to merge 2 commits intomasterfrom
RTECO-1017-CIdetect
Open

RTECO-1017 - Detect agent + CI invocation context, enrich metrics wit…#1555
fluxxBot wants to merge 2 commits intomasterfrom
RTECO-1017-CIdetect

Conversation

@fluxxBot
Copy link
Copy Markdown
Contributor

@fluxxBot fluxxBot commented May 4, 2026

…h agent/is_agent/is_interactive

  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • All static analysis checks passed.
  • This pull request is on the master branch.
  • I used gofmt for formatting the code before submitting the pull request.

Summary

Adds detection of CLI invocation context — agent (Claude, Cursor, Gemini, Goose, Copilot, Windsurf, etc.), CI provider, and stdin TTY — and enriches the existing
jfcli_commands_count metric with the new dimensions.

Motivation

differentiate human / CI / agent invocations of jf. Backend currently can't tell whether a command came from a developer's desktop, a CI runner, or an AI agent. Without this, we can't measure agent-driven usage or separate human vs automated traffic.

Changes

  • New common/commands/execution_context.go — single source of truth for invocation context. DetectExecutionContext() returns agent name, CI system, TTY presence, and
    propagated trace ID.
  • New common/commands/execution_context_test.go — unit tests covering each agent env var, CI providers, trace ID gating, and no-env fallback.
  • Extended utils/metrics/metrics.goMetricsData gains IsAgent, Agent, IsInteractive fields (additive, omitempty).
  • Updated common/commands/metrics_collector.goCollectMetrics populates the new fields via DetectExecutionContext.

Detection

Agent identity is matched against an env-var table (first match wins, then generic AGENT fallback):

Agent Env vars
claude CLAUDECODE, CLAUDE_CODE_ENTRYPOINT
gemini GEMINI_CLI
goose GOOSE_TERMINAL
cursor CURSOR_AGENT, CURSOR_TRACEID
copilot COPILOT_CLI
kilocode KILO_IPC_SOCKET_PATH, KILO_SERVER_PASSWORD
roo_code ROO_CODE_IPC_SOCKET_PATH
replit REPLIT_AGENT
windsurf WINDSURF_SESSION_ID
aider AIDER_MODEL
codex CODEX_HOME

CI detection reuses the existing detectCISystem() provider list (Jenkins, Travis, CircleCI, GitHub Actions, GitLab, Buildkite, Bamboo, Azure DevOps, TeamCity, Drone, Bitbucket,
AWS CodeBuild, plus generic fallbacks).

TraceID is gated on agent identity — only Cursor's CURSOR_TRACEID is honored, and only when the detected agent is cursor. Prevents stale leakage from outer shells.

@fluxxBot fluxxBot added the new feature Automatically generated release notes label May 4, 2026
Comment thread common/commands/execution_context.go Outdated
Comment thread common/commands/execution_context.go Outdated
Comment thread common/commands/execution_context.go Outdated
Comment thread common/commands/execution_context_test.go Outdated
Comment thread common/commands/metrics_collector.go
Comment thread common/commands/execution_context.go Outdated
Comment thread common/commands/execution_context.go Outdated
Comment thread common/commands/execution_context.go Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature Automatically generated release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants