Skip to content

feat(cli): detect all major AI-agent harnesses for the agent reporter - #455

Merged
oekazuma merged 1 commit into
mainfrom
feat/agent-detection-gunshi
Aug 10, 2026
Merged

oekazuma merged 1 commit into
mainfrom
feat/agent-detection-gunshi

Conversation

@oekazuma

@oekazuma oekazuma commented Aug 10, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to the gunshi migration (#448 plan): the agent reporter's auto-selection now recognizes the major AI-agent harnesses instead of a two-entry allow-list.

Before / after

The curated list detected exactly CLAUDECODE (+ the SVELTE_VITALS_AGENT opt-in) — so Cursor, Codex, Replit, Gemini CLI, and every other harness got console output despite the help text promising "auto-selected under AI-agent envs". Detection now delegates to gunshi/agent's getAgentProfile() (std-env, inlined in gunshi, zero new deps): Claude Code, Cursor (CURSOR_AGENT), Codex, Replit, Gemini, opencode, auggie, goose, devin, kiro, plus the AI_AGENT universal override — all env-var-based, no TTY heuristics (the design constraint holds; verified from the bundled detection source). The recognized list evolves with gunshi updates behind the exact pin.

The testability mechanism (the subtle part)

std-env computes its profile once at gunshi's module load from the real process.env — no in-process env stub can exercise it (verified empirically; vi.resetModules doesn't re-run an externalized dependency's init). Resolution: isAgentEnv(env) keeps its injectable signature — the SVELTE_VITALS_AGENT opt-in reads the PASSED env (fully testable), and the gunshi delegation fires only when env is process.env by reference, which is exactly the production default (opts.env ?? process.env) and never a test's literal object. Zero production call-site changes; the constraint is documented at the function. The delegation itself is tested for real in scripts/cli-e2e.mjs (now 10 checks): fresh child processes of the built CLI with ambient agent signals scrubbed, asserting clean-env→console, CLAUDECODE→agent, and CURSOR_AGENT→agent.

Also fixed en route (root-caused): the e2e harness's execFileSync discarded stderr on zero-exit runs — the exact stream the auto-selection hint uses — switched to spawnSync with uniform stream capture.

Precedence is unchanged and pinned: explicit --reporter > SVELTE_VITALS_REPORTER > agent env > GitHub Actions > console. Docs (en/ja reporters + CLI guides, bundled output topic) updated without hard-coding an agent-name list (anti-rot rule). Changeset: svelte-vitals minor declaring the widened detection.

Gates: full suite green, e2e 10/10, lint/typecheck clean.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Agent reporter auto-selection now recognizes a broader range of AI-agent environments.
    • Unrecognized environments can opt in with SVELTE_VITALS_AGENT=1.
    • Explicit reporter settings continue to take precedence over automatic detection.
  • Documentation

    • Updated CLI and reporter guidance in English and Japanese to explain detection, selection priority, and opt-in behavior.
    • Clarified that GitHub Actions behavior remains unchanged.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@oekazuma, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: eaba1f1d-ba6d-4fb7-9098-f7c6261dfd3d

📥 Commits

Reviewing files that changed from the base of the PR and between 33f8a75 and ada0519.

📒 Files selected for processing (1)
  • scripts/cli-e2e.mjs
📝 Walkthrough

Walkthrough

The CLI now detects recognized AI-agent harnesses through Gunshi agent profiles and supports SVELTE_VITALS_AGENT=1 as an explicit opt-in. Reporter precedence remains covered by unit and E2E tests. English and Japanese documentation now describe the updated behavior.

Changes

Agent reporter detection

Layer / File(s) Summary
Reporter detection and unit coverage
packages/cli/src/reporter-resolve.ts, packages/cli/test/reporter-resolve.test.ts, packages/cli/test/pulse-animation.test.ts, packages/cli/test/run.test.ts
Reporter resolution uses Gunshi agent profiles for process.env and SVELTE_VITALS_AGENT for supplied environments. Tests cover empty values, precedence, and ignored CLAUDECODE injection.
CLI E2E validation
scripts/cli-e2e.mjs
The E2E runner sanitizes detection variables, captures child-process results with spawnSync, and verifies console and agent reporter selection.
Documentation and release notes
packages/cli/docs/output.md, packages/cli/src/docs/generated.ts, docs/src/content/docs/guides/..., docs/src/content/docs/ja/guides/..., .changeset/agent-detection-via-gunshi.md
Documentation and the changeset describe Gunshi-based harness detection and the SVELTE_VITALS_AGENT=1 override.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant ReporterResolver
  participant Gunshi
  participant Reporter
  CLI->>ReporterResolver: resolve reporter
  ReporterResolver->>Gunshi: getAgentProfile(process.env)
  Gunshi-->>ReporterResolver: recognized harness profile
  ReporterResolver-->>CLI: agent reporter selection
  CLI->>Reporter: emit agent output
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: expanded CLI detection of major AI-agent harnesses for the agent reporter.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/cli/test/reporter-resolve.test.ts (1)

20-20: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Name the test after its observable behavior.

Remove the Gunshi implementation details and E2E reference from the test name. Name the test for the false result from an injected harness variable.

Proposed change
-  it('does not recognize harness-specific vars (e.g. CLAUDECODE) in an injected env — that detection is delegated to gunshi/agent, which only reads the real process.env; see scripts/cli-e2e.mjs for the end-to-end coverage', () => {
+  it('returns false for harness-specific variables in an injected environment', () => {

As per coding guidelines, tests must be named after the behavior they verify, not the reasoning behind the implementation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/cli/test/reporter-resolve.test.ts` at line 20, Rename the test case
around the observable outcome: an injected harness-specific environment variable
does not trigger detection. Remove references to Gunshi, delegation, real
process.env, and E2E coverage from the test name while preserving the test
behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/cli-e2e.mjs`:
- Around line 53-76: Update cleanEnv() to construct the child environment from
an explicit allowlist of required OS variables instead of spreading process.env
and deleting AGENT_DETECTION_ENV_KEYS. Preserve applying the provided overrides
last, and remove the deny-list-based inheritance so newly introduced detection
signals cannot leak into the fallback environment.

---

Nitpick comments:
In `@packages/cli/test/reporter-resolve.test.ts`:
- Line 20: Rename the test case around the observable outcome: an injected
harness-specific environment variable does not trigger detection. Remove
references to Gunshi, delegation, real process.env, and E2E coverage from the
test name while preserving the test behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1cd1b8e4-4cdf-484c-9bab-f71f10d6e921

📥 Commits

Reviewing files that changed from the base of the PR and between 6d09409 and 33f8a75.

📒 Files selected for processing (12)
  • .changeset/agent-detection-via-gunshi.md
  • docs/src/content/docs/guides/(reporting)/reporters.md
  • docs/src/content/docs/guides/(setup)/cli.md
  • docs/src/content/docs/ja/guides/(reporting)/reporters.md
  • docs/src/content/docs/ja/guides/(setup)/cli.md
  • packages/cli/docs/output.md
  • packages/cli/src/docs/generated.ts
  • packages/cli/src/reporter-resolve.ts
  • packages/cli/test/pulse-animation.test.ts
  • packages/cli/test/reporter-resolve.test.ts
  • packages/cli/test/run.test.ts
  • scripts/cli-e2e.mjs

Comment thread scripts/cli-e2e.mjs Outdated
…#448)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@oekazuma
oekazuma force-pushed the feat/agent-detection-gunshi branch from 33f8a75 to ada0519 Compare August 10, 2026 15:40
@oekazuma
oekazuma merged commit 04df077 into main Aug 10, 2026
8 checks passed
@oekazuma
oekazuma deleted the feat/agent-detection-gunshi branch August 10, 2026 16:01
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