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
14 changes: 7 additions & 7 deletions eng/vendored-files.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@
"repo": "dotnet/sdk",
"ref": "main",
"path": "src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs",
"baseline_ref_sha": "1ab3ae8e0338cdd06b3974959c5802ccc5a85978",
"baseline_blob_sha": "94cd49826baadaa10154f13d71a7e2ede224b663",
"baseline_ref_sha": "bcafbe92a30b1866bd17789759c9941761bf6b49",
"baseline_blob_sha": "0682d3bf641c49fe17b4a0de4d48929b36ab87e1",
"scope": "LLM/agent detection rules"
}
]
Expand Down Expand Up @@ -228,8 +228,8 @@
"repo": "dotnet/msbuild",
"ref": "main",
"path": "src/Framework/NativeMethods.cs",
"baseline_ref_sha": "fd084bd416a21d504b5d9bb19c0a1ca83c33533d",
"baseline_blob_sha": "915cf0673e4f49f2e7bc286592c036d23441321e",
"baseline_ref_sha": "8243f3a898b4d160cfca7619ed3f48ca7f9a4b00",
"baseline_blob_sha": "de45ea0bc217e2bc11cfb0fe19c876a4b2dba413",
"scope": "QueryIsScreenAndTryEnableAnsiColorCodes and supporting console-mode P/Invokes"
}
]
Expand Down Expand Up @@ -273,8 +273,8 @@
"repo": "dotnet/runtime",
"ref": "main",
"path": "src/libraries/System.IO.Hashing/src/System/IO/Hashing/XxHashShared.cs",
"baseline_ref_sha": "62dfdbff84a97796938836c60697287fc6161aa1",
"baseline_blob_sha": "00f1f919a93c706cbd41a2a2e9d62f26c74b6f92",
"baseline_ref_sha": "c366a53872872cbcafd5145a23038659ac3815c3",
"baseline_blob_sha": "0f8a6dfa2e75409a23cc2a793c64596556235e81",
"scope": "entire file"
}
]
Expand All @@ -287,7 +287,7 @@
{
"repo": "Sergio0694/ComputeSharp",
"ref": "main",
"path": "src/ComputeSharp.SourceGeneration/Helpers/EquatableArray%7BT%7D.cs",
"path": "src/ComputeSharp.SourceGeneration/Helpers/EquatableArray{T}.cs",
"baseline_ref_sha": "c3e9ad4faada0d67a122c0e458cf3978993cf6c5",
"baseline_blob_sha": "b63b1c8773635ffc132b728d5711acc40aae97e3",
"scope": "entire struct"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#if NET
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.Wasm;
using System.Runtime.Intrinsics.X86;
#endif

Expand Down Expand Up @@ -762,12 +763,25 @@ private static Vector128<ulong> MultiplyWideningLower(Vector128<uint> source)
Vector64<uint> sourceHigh = Vector128.Shuffle(source, Vector128.Create(1u, 3, 0, 0)).GetLower();
return AdvSimd.MultiplyWideningLower(sourceLow, sourceHigh);
}
else if (Sse2.IsSupported)
{
var sourceLow = Vector128.Shuffle(source, Vector128.Create(1u, 0, 3, 0));
return Sse2.Multiply(source, sourceLow);
}
else if (PackedSimd.IsSupported)
{
// PackedSimd.MultiplyWideningLower (i64x2.extmul_low_i32x4_u) does
// result[i] = (ulong)a[i] * (ulong)b[i] for i in {0, 1}.
// We need { source[0]*source[1], source[2]*source[3] } to match the Sse2/AdvSimd paths,
// so first move the even lanes into one operand and the odd lanes into the other.
var evens = Vector128.Shuffle(source, Vector128.Create(0u, 2, 0, 0));
var odds = Vector128.Shuffle(source, Vector128.Create(1u, 3, 0, 0));
return PackedSimd.MultiplyWideningLower(evens, odds);
}
else
{
var sourceLow = Vector128.Shuffle(source, Vector128.Create(1u, 0, 3, 0));
return Sse2.IsSupported ?
Sse2.Multiply(source, sourceLow) :
(source & Vector128.Create(~0u, 0u, ~0u, 0u)).AsUInt64() * (sourceLow & Vector128.Create(~0u, 0u, ~0u, 0u)).AsUInt64();
return (source & Vector128.Create(~0u, 0u, ~0u, 0u)).AsUInt64() * (sourceLow & Vector128.Create(~0u, 0u, ~0u, 0u)).AsUInt64();
}
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Microsoft.Testing.Platform.Helpers;

// Adapted from https://github.com/dotnet/sdk/tree/eaad2a6f937b2c8d9247c53d71b57204f5d127b2/src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs
// Adapted from https://github.com/dotnet/sdk/tree/bcafbe92a30b1866bd17789759c9941761bf6b49/src/Cli/dotnet/Telemetry/LLMEnvironmentDetectorForTelemetry.cs
// Diverged from the upstream telemetry-only version so detection results can drive
// user-facing platform defaults (ANSI mode, banner, --show-stdout/--show-stderr).
// IMPORTANT: keep the environment-variable list below in sync with
Expand All @@ -14,18 +14,23 @@ internal sealed class LLMEnvironmentDetector
{
private static readonly EnvironmentDetectionRuleWithResult<string>[] DetectionRules =
[
// Cowork (Claude Code cowork mode) - placed before Claude so the more specific variable is listed first
new EnvironmentDetectionRuleWithResult<string>("cowork", new AnyPresentEnvironmentRule("CLAUDE_CODE_IS_COWORK")),
// Claude Code
new EnvironmentDetectionRuleWithResult<string>("claude", new AnyPresentEnvironmentRule("CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT")),
new EnvironmentDetectionRuleWithResult<string>("claude", new AnyPresentEnvironmentRule("CLAUDECODE", "CLAUDE_CODE", "CLAUDE_CODE_ENTRYPOINT")),
// Cursor AI
new EnvironmentDetectionRuleWithResult<string>("cursor", new AnyPresentEnvironmentRule("CURSOR_EDITOR", "CURSOR_AI")),
new EnvironmentDetectionRuleWithResult<string>("cursor", new AnyPresentEnvironmentRule("CURSOR_EDITOR", "CURSOR_AI", "CURSOR_TRACE_ID", "CURSOR_AGENT")),
// Gemini
new EnvironmentDetectionRuleWithResult<string>("gemini", new BooleanEnvironmentRule("GEMINI_CLI")),
// GitHub Copilot (legacy gh extension: GITHUB_COPILOT_CLI_MODE=true; new Copilot CLI: GH_COPILOT_WORKING_DIRECTORY or COPILOT_CLI is set)
new EnvironmentDetectionRuleWithResult<string>("copilot", new AnyMatchEnvironmentRule(
new BooleanEnvironmentRule("GITHUB_COPILOT_CLI_MODE"),
new AnyPresentEnvironmentRule("GH_COPILOT_WORKING_DIRECTORY", "COPILOT_CLI"))),
new EnvironmentDetectionRuleWithResult<string>("gemini", new AnyPresentEnvironmentRule("GEMINI_CLI")),
// GitHub Copilot CLI (legacy gh extension: GITHUB_COPILOT_CLI_MODE; new Copilot CLI: GH_COPILOT_WORKING_DIRECTORY, COPILOT_CLI, COPILOT_MODEL, COPILOT_ALLOW_ALL, or COPILOT_GITHUB_TOKEN is set).
new EnvironmentDetectionRuleWithResult<string>("copilot-cli", new AnyPresentEnvironmentRule(
"GITHUB_COPILOT_CLI_MODE", "GH_COPILOT_WORKING_DIRECTORY", "COPILOT_CLI", "COPILOT_MODEL", "COPILOT_ALLOW_ALL", "COPILOT_GITHUB_TOKEN")),
Comment thread
Evangelink marked this conversation as resolved.
Resolved
// GitHub Copilot agent mode in VS Code, which sets AI_AGENT=github_copilot_vscode_agent and COPILOT_AGENT=1 on the terminals it runs commands in.
new EnvironmentDetectionRuleWithResult<string>("copilot-vscode", new AnyMatchEnvironmentRule(
new EnvironmentVariableValueRule("AI_AGENT", "github_copilot_vscode_agent"),
new AnyPresentEnvironmentRule("COPILOT_AGENT"))),
Comment thread
Evangelink marked this conversation as resolved.
Resolved
// Codex CLI
new EnvironmentDetectionRuleWithResult<string>("codex", new AnyPresentEnvironmentRule("CODEX_CLI", "CODEX_SANDBOX")),
new EnvironmentDetectionRuleWithResult<string>("codex", new AnyPresentEnvironmentRule("CODEX_CLI", "CODEX_SANDBOX", "CODEX_CI", "CODEX_THREAD_ID")),
// Aider
new EnvironmentDetectionRuleWithResult<string>("aider", new EnvironmentVariableValueRule("OR_APP_NAME", "Aider")),
// Plandex
Expand All @@ -35,25 +40,31 @@ internal sealed class LLMEnvironmentDetector
// Qwen Code
new EnvironmentDetectionRuleWithResult<string>("qwen", new AnyPresentEnvironmentRule("QWEN_CODE")),
// Droid
new EnvironmentDetectionRuleWithResult<string>("droid", new BooleanEnvironmentRule("DROID_CLI")),
new EnvironmentDetectionRuleWithResult<string>("droid", new AnyPresentEnvironmentRule("DROID_CLI")),
// OpenCode
new EnvironmentDetectionRuleWithResult<string>("opencode", new AnyPresentEnvironmentRule("OPENCODE_AI")),
// Zed AI
new EnvironmentDetectionRuleWithResult<string>("zed", new AnyPresentEnvironmentRule("ZED_ENVIRONMENT", "ZED_TERM")),
// Kimi CLI
new EnvironmentDetectionRuleWithResult<string>("kimi", new BooleanEnvironmentRule("KIMI_CLI")),
new EnvironmentDetectionRuleWithResult<string>("kimi", new AnyPresentEnvironmentRule("KIMI_CLI")),
// OpenHands
new EnvironmentDetectionRuleWithResult<string>("openhands", new EnvironmentVariableValueRule("OR_APP_NAME", "OpenHands")),
// Goose
new EnvironmentDetectionRuleWithResult<string>("goose", new AnyPresentEnvironmentRule("GOOSE_TERMINAL")),
new EnvironmentDetectionRuleWithResult<string>("goose", new AnyPresentEnvironmentRule("GOOSE_TERMINAL", "GOOSE_PROVIDER")),
// Cline
new EnvironmentDetectionRuleWithResult<string>("cline", new AnyPresentEnvironmentRule("CLINE_TASK_ID")),
// Roo Code
new EnvironmentDetectionRuleWithResult<string>("roo", new AnyPresentEnvironmentRule("ROO_CODE_TASK_ID")),
// Windsurf
new EnvironmentDetectionRuleWithResult<string>("windsurf", new AnyPresentEnvironmentRule("WINDSURF_SESSION")),
// Replit
new EnvironmentDetectionRuleWithResult<string>("replit", new AnyPresentEnvironmentRule("REPL_ID")),
Comment thread
Evangelink marked this conversation as resolved.
Resolved
// Augment
new EnvironmentDetectionRuleWithResult<string>("augment", new AnyPresentEnvironmentRule("AUGMENT_AGENT")),
// Antigravity
new EnvironmentDetectionRuleWithResult<string>("antigravity", new AnyPresentEnvironmentRule("ANTIGRAVITY_AGENT")),
// (proposed) generic flag for Agentic usage
new EnvironmentDetectionRuleWithResult<string>("generic_agent", new BooleanEnvironmentRule("AGENT_CLI")),
new EnvironmentDetectionRuleWithResult<string>("generic_agent", new AnyPresentEnvironmentRule("AGENT_CLI")),
];

private readonly IEnvironment _environment;
Expand Down Expand Up @@ -85,45 +96,6 @@ private abstract class EnvironmentDetectionRule
public abstract bool IsMatch(IEnvironment environment);
}

/// <summary>
/// Rule that matches when any of the specified environment variables is set to "true".
/// </summary>
private sealed class BooleanEnvironmentRule : EnvironmentDetectionRule
{
private readonly string[] _variables;

public BooleanEnvironmentRule(params string[] variables)
=> _variables = variables ?? throw new ArgumentNullException(nameof(variables));

public override bool IsMatch(IEnvironment environment)
=> _variables.Any(variable => EnvironmentVariableParser.ParseBool(environment.GetEnvironmentVariable(variable), defaultValue: false));
}

private static class EnvironmentVariableParser
{
public static bool ParseBool(string? str, bool defaultValue)
{
if (str is "1" ||
string.Equals(str, "true", StringComparison.OrdinalIgnoreCase) ||
string.Equals(str, "yes", StringComparison.OrdinalIgnoreCase) ||
string.Equals(str, "on", StringComparison.OrdinalIgnoreCase))
{
return true;
}

if (str is "0" ||
string.Equals(str, "false", StringComparison.OrdinalIgnoreCase) ||
string.Equals(str, "no", StringComparison.OrdinalIgnoreCase) ||
string.Equals(str, "off", StringComparison.OrdinalIgnoreCase))
{
return false;
}

// Not set to a known value, return default value.
return defaultValue;
}
}

/// <summary>
/// Rule that matches when any of the specified environment variables is present and not null/empty.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,27 @@ public static class WellKnownEnvironmentVariables
/// </summary>
public static readonly IReadOnlyList<string> LLMEnvironmentVariables =
[
"CLAUDE_CODE_IS_COWORK",
"CLAUDECODE",
"CLAUDE_CODE",
"CLAUDE_CODE_ENTRYPOINT",
"CURSOR_EDITOR",
"CURSOR_AI",
"CURSOR_TRACE_ID",
"CURSOR_AGENT",
"GEMINI_CLI",
"GITHUB_COPILOT_CLI_MODE",
"GH_COPILOT_WORKING_DIRECTORY",
"COPILOT_CLI",
"COPILOT_MODEL",
"COPILOT_ALLOW_ALL",
"COPILOT_GITHUB_TOKEN",
"AI_AGENT",
"COPILOT_AGENT",
"CODEX_CLI",
"CODEX_SANDBOX",
"CODEX_CI",
"CODEX_THREAD_ID",
"OR_APP_NAME",
"AMP_HOME",
"QWEN_CODE",
Expand All @@ -30,9 +41,13 @@ public static class WellKnownEnvironmentVariables
"ZED_TERM",
"KIMI_CLI",
"GOOSE_TERMINAL",
"GOOSE_PROVIDER",
"CLINE_TASK_ID",
"ROO_CODE_TASK_ID",
"WINDSURF_SESSION",
"REPL_ID",
"AUGMENT_AGENT",
"ANTIGRAVITY_AGENT",
"AGENT_CLI",
];

Expand Down
Loading