-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat(core): detect VS Code Copilot as AI agent #33766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
View your CI Pipeline Execution ↗ for commit cbbcf4f
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nx Cloud is proposing a fix for your failed CI:
We fixed the Rust formatting violation in the VS Code Copilot detection test by moving the .to_string() method call to a separate line with proper indentation. This change resolves the nx:format-native task failure while preserving the PR's functionality to detect VS Code Copilot as an AI agent.
We could not verify this fix.
Suggested Fix changes
diff --git a/packages/nx/src/native/utils/ai.rs b/packages/nx/src/native/utils/ai.rs
index ba8098f603..01ffb0c378 100644
--- a/packages/nx/src/native/utils/ai.rs
+++ b/packages/nx/src/native/utils/ai.rs
@@ -216,7 +216,8 @@ mod tests {
// Test with PATH containing copilot-chat
assert!(
is_vscode_copilot_from_path(Some(
- "/usr/bin:/some/path/globalStorage/github.copilot-chat/copilotCli:/usr/local/bin".to_string()
+ "/usr/bin:/some/path/globalStorage/github.copilot-chat/copilotCli:/usr/local/bin"
+ .to_string()
)),
"Should detect VS Code Copilot with github.copilot-chat in PATH"
);
Because this branch comes from a fork, it is not possible for us to apply fixes directly, but you can apply the changes locally using the available options below.
Apply changes locally with:
npx nx-cloud apply-locally tKdo-8oIK
Apply fix locally with your editor ↗ View interactive diff ↗
🎓 Learn more about Self-Healing CI on nx.dev
Add detection for VS Code Copilot chat by checking if the PATH environment variable contains 'github.copilot-chat'. This ensures the TUI is disabled when running commands from VS Code Copilot's chat panel, providing better output for AI agents. Ref nrwl#33698
cbbcf4f to
9e83719
Compare
MaxKless
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Stanzilla I appreciate the PR!
I went into VSCode to verify and it looks like the copilot string is also added to PATH in the regular vscode terminal, not just when running through copilot itself (see below).
This would mean that the TUI won't be shown in the vscode terminal which isn't what we want. So I think we'll need another approach here...
|
Thanks for catching that @MaxKless! You're right - I just verified and the I've checked the environment more thoroughly, and unfortunately there doesn't appear to be a unique environment variable that distinguishes Copilot agent mode from regular VS Code terminal usage:
Do you have any suggestions for how we might detect Copilot agent mode specifically? Some possibilities:
Alternatively, would it make sense to approach this from a different angle - perhaps detecting that the terminal is not truly interactive in some way, even if it reports as a TTY? |
| fn is_vscode_copilot_from_path(path: Option<String>) -> bool { | ||
| match path { | ||
| Some(path) => { | ||
| let is_copilot = path.contains("github.copilot-chat"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this in the PATH just means that the copilot extension is installed. There's actually intentionally not a way right now to determine whether the session is being driven by AI because I worry about tools starting to behave differently if we offer that and therefore start working differently when ideally the agent would be able to handle everything.
What do you think? microsoft/vscode#253945 (comment)
Do most other terminals driven by AI include environment variables now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the code present here, at least Claude, Replit and Cursor are. That's what NX detects right now to do exactly what you were worried about. But is that still a problem for you? Do you see any other good way this could be handled in tools like NX? You don't actually have access to the harness etc, the only thing you could do is try to force it via agent instructions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tyriar thanks for chiming in here! At least there's a solid workaround which is setting NX_TUI=false in the terminal profile setting @Stanzilla (you could also add an instruction to your AGENTS.md or whatever to always run tasks with NX_TUI=false).
@Tyriar I get where you're coming from with not wanting to have tools adapt too much to whether they're being driven by an agent or human. Right now TUIs kind of don't work well with the text-based approach agents have to input/output, so this being broken is a side effect of that decision.
Other tools we looked into do have a way of telling agent invocations apart from regular ones and it's helpful for us.
Seems like either choice will have its drawbacks - one of them immediately relevant today though while the other one is more theoretical in the future. Tricky for sure :D
Current Behavior
When running Nx commands from VS Code Copilot's chat panel, Nx does not detect that it's running inside an AI agent. This means the TUI is enabled, which doesn't work well with AI agents that expect plain text output.
Expected Behavior
Nx should detect when it's running from VS Code Copilot's chat panel and disable the TUI accordingly, similar to how it handles Claude Code, Cursor, and Repl.it.
Related Issue(s)
Fixes #33698
Implementation
Added detection for VS Code Copilot by checking if the
PATHenvironment variable containsgithub.copilot-chat. When VS Code Copilot runs terminal commands, it adds its CLI tool path (e.g.,.../globalStorage/github.copilot-chat/copilotCli) to the PATH.Changes:
is_vscode_copilot()function to detect VS Code Copilotis_vscode_copilot_from_path()helper for testabilityis_ai_agent()to include VS Code Copilot detection