Skip to content

feat: detect if nuxt is run by an agent#394

Merged
danielroe merged 3 commits intomainfrom
feat/agent-detection
Feb 23, 2026
Merged

feat: detect if nuxt is run by an agent#394
danielroe merged 3 commits intomainfrom
feat/agent-detection

Conversation

@atinux
Copy link
Copy Markdown
Member

@atinux atinux commented Feb 11, 2026

❓ Type of change

  • 👌 Enhancement (improving an existing functionality)

📚 Description

Add isAgent and agentName to better understand how many people use Nuxt from agents.

@atinux atinux requested a review from danielroe as a code owner February 11, 2026 12:07
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 11, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Updated dependency std-env in package.json from ^3.10.0 to ^4.0.0-rc.1. src/context.ts now imports and invokes agent-detection utilities (e.g., detectAgent) and populates two new fields on the exported Context: isAgent (boolean) and agentName (string | null). src/types.ts adds those two fields to the Context interface. src/telemetry.ts includes isAgent and agentName in the public telemetry context. test/e2e.spec.ts assertions updated to validate the new context fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: detecting if Nuxt is run by an agent, which aligns with the addition of isAgent and agentName properties throughout the codebase.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of adding isAgent and agentName for understanding agent-based Nuxt usage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/agent-detection

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/context.ts (1)

35-52: ⚠️ Potential issue | 🟠 Major

Wrap determineAgent() in a try/catch to prevent telemetry failures.

determineAgent() is an external call that could throw (e.g., unexpected environment, library bug). Since agent detection is non-critical, a failure here should not break context creation and, by extension, all telemetry reporting.

🛡️ Proposed fix
-  const agent = await determineAgent()
+  let isAgent = false
+  let agentName: string | null = null
+  try {
+    const agent = await determineAgent()
+    isAgent = agent.isAgent
+    agentName = agent.isAgent ? agent.agent.name : null
+  }
+  catch {
+    // Ignore agent detection failures
+  }

   return {
     nuxt,
     seed,
     git,
     projectHash,
     projectSession,
     nuxtVersion,
     nuxtMajorVersion,
     isEdge,
     cli: getCLI(),
     nodeVersion,
     os: os.type().toLocaleLowerCase(),
     environment: getEnv(),
     packageManager: packageManager || 'unknown',
-    isAgent: agent.isAgent,
-    agentName: agent.isAgent ? agent.agent.name : null,
+    isAgent,
+    agentName,
     concent: options.consent,
   }

@atinux
Copy link
Copy Markdown
Member Author

atinux commented Feb 11, 2026

To respond to coderabbit, try/catch is not needed as the only thing capable to fail on the detect-agent is already within a try/catch: https://github.com/vercel/vercel/blob/main/packages/detect-agent/src/index.ts

@danielroe
Copy link
Copy Markdown
Member

linking unjs/std-env#179

@atinux
Copy link
Copy Markdown
Member Author

atinux commented Feb 18, 2026

It's now using std-env @danielroe

Copy link
Copy Markdown
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

nice! 👌

@danielroe danielroe added this pull request to the merge queue Feb 23, 2026
Merged via the queue into main with commit 05f8e45 Feb 23, 2026
5 checks passed
@danielroe danielroe deleted the feat/agent-detection branch February 23, 2026 08:31
This was referenced Feb 23, 2026
This was referenced Mar 31, 2026
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.

2 participants