diff --git a/eng/vendored-files.json b/eng/vendored-files.json index d4373d0f5a..0ee272b1e4 100644 --- a/eng/vendored-files.json +++ b/eng/vendored-files.json @@ -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" } ] @@ -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" } ] @@ -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" } ] @@ -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" diff --git a/src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/XxHashShared.cs b/src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/XxHashShared.cs index 1f33ac752d..d6843c5e85 100644 --- a/src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/XxHashShared.cs +++ b/src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/XxHashShared.cs @@ -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 @@ -762,12 +763,25 @@ private static Vector128 MultiplyWideningLower(Vector128 source) Vector64 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 diff --git a/src/Platform/Microsoft.Testing.Platform/Helpers/LLMEnvironmentDetector.cs b/src/Platform/Microsoft.Testing.Platform/Helpers/LLMEnvironmentDetector.cs index f061158aaa..fc35d61f21 100644 --- a/src/Platform/Microsoft.Testing.Platform/Helpers/LLMEnvironmentDetector.cs +++ b/src/Platform/Microsoft.Testing.Platform/Helpers/LLMEnvironmentDetector.cs @@ -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 @@ -14,18 +14,23 @@ internal sealed class LLMEnvironmentDetector { private static readonly EnvironmentDetectionRuleWithResult[] DetectionRules = [ + // Cowork (Claude Code cowork mode) - placed before Claude so the more specific variable is listed first + new EnvironmentDetectionRuleWithResult("cowork", new AnyPresentEnvironmentRule("CLAUDE_CODE_IS_COWORK")), // Claude Code - new EnvironmentDetectionRuleWithResult("claude", new AnyPresentEnvironmentRule("CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT")), + new EnvironmentDetectionRuleWithResult("claude", new AnyPresentEnvironmentRule("CLAUDECODE", "CLAUDE_CODE", "CLAUDE_CODE_ENTRYPOINT")), // Cursor AI - new EnvironmentDetectionRuleWithResult("cursor", new AnyPresentEnvironmentRule("CURSOR_EDITOR", "CURSOR_AI")), + new EnvironmentDetectionRuleWithResult("cursor", new AnyPresentEnvironmentRule("CURSOR_EDITOR", "CURSOR_AI", "CURSOR_TRACE_ID", "CURSOR_AGENT")), // Gemini - new EnvironmentDetectionRuleWithResult("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("copilot", new AnyMatchEnvironmentRule( - new BooleanEnvironmentRule("GITHUB_COPILOT_CLI_MODE"), - new AnyPresentEnvironmentRule("GH_COPILOT_WORKING_DIRECTORY", "COPILOT_CLI"))), + new EnvironmentDetectionRuleWithResult("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("copilot-cli", new AnyPresentEnvironmentRule( + "GITHUB_COPILOT_CLI_MODE", "GH_COPILOT_WORKING_DIRECTORY", "COPILOT_CLI", "COPILOT_MODEL", "COPILOT_ALLOW_ALL", "COPILOT_GITHUB_TOKEN")), + // 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("copilot-vscode", new AnyMatchEnvironmentRule( + new EnvironmentVariableValueRule("AI_AGENT", "github_copilot_vscode_agent"), + new AnyPresentEnvironmentRule("COPILOT_AGENT"))), // Codex CLI - new EnvironmentDetectionRuleWithResult("codex", new AnyPresentEnvironmentRule("CODEX_CLI", "CODEX_SANDBOX")), + new EnvironmentDetectionRuleWithResult("codex", new AnyPresentEnvironmentRule("CODEX_CLI", "CODEX_SANDBOX", "CODEX_CI", "CODEX_THREAD_ID")), // Aider new EnvironmentDetectionRuleWithResult("aider", new EnvironmentVariableValueRule("OR_APP_NAME", "Aider")), // Plandex @@ -35,25 +40,31 @@ internal sealed class LLMEnvironmentDetector // Qwen Code new EnvironmentDetectionRuleWithResult("qwen", new AnyPresentEnvironmentRule("QWEN_CODE")), // Droid - new EnvironmentDetectionRuleWithResult("droid", new BooleanEnvironmentRule("DROID_CLI")), + new EnvironmentDetectionRuleWithResult("droid", new AnyPresentEnvironmentRule("DROID_CLI")), // OpenCode new EnvironmentDetectionRuleWithResult("opencode", new AnyPresentEnvironmentRule("OPENCODE_AI")), // Zed AI new EnvironmentDetectionRuleWithResult("zed", new AnyPresentEnvironmentRule("ZED_ENVIRONMENT", "ZED_TERM")), // Kimi CLI - new EnvironmentDetectionRuleWithResult("kimi", new BooleanEnvironmentRule("KIMI_CLI")), + new EnvironmentDetectionRuleWithResult("kimi", new AnyPresentEnvironmentRule("KIMI_CLI")), // OpenHands new EnvironmentDetectionRuleWithResult("openhands", new EnvironmentVariableValueRule("OR_APP_NAME", "OpenHands")), // Goose - new EnvironmentDetectionRuleWithResult("goose", new AnyPresentEnvironmentRule("GOOSE_TERMINAL")), + new EnvironmentDetectionRuleWithResult("goose", new AnyPresentEnvironmentRule("GOOSE_TERMINAL", "GOOSE_PROVIDER")), // Cline new EnvironmentDetectionRuleWithResult("cline", new AnyPresentEnvironmentRule("CLINE_TASK_ID")), // Roo Code new EnvironmentDetectionRuleWithResult("roo", new AnyPresentEnvironmentRule("ROO_CODE_TASK_ID")), // Windsurf new EnvironmentDetectionRuleWithResult("windsurf", new AnyPresentEnvironmentRule("WINDSURF_SESSION")), + // Replit + new EnvironmentDetectionRuleWithResult("replit", new AnyPresentEnvironmentRule("REPL_ID")), + // Augment + new EnvironmentDetectionRuleWithResult("augment", new AnyPresentEnvironmentRule("AUGMENT_AGENT")), + // Antigravity + new EnvironmentDetectionRuleWithResult("antigravity", new AnyPresentEnvironmentRule("ANTIGRAVITY_AGENT")), // (proposed) generic flag for Agentic usage - new EnvironmentDetectionRuleWithResult("generic_agent", new BooleanEnvironmentRule("AGENT_CLI")), + new EnvironmentDetectionRuleWithResult("generic_agent", new AnyPresentEnvironmentRule("AGENT_CLI")), ]; private readonly IEnvironment _environment; @@ -85,45 +96,6 @@ private abstract class EnvironmentDetectionRule public abstract bool IsMatch(IEnvironment environment); } - /// - /// Rule that matches when any of the specified environment variables is set to "true". - /// - 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; - } - } - /// /// Rule that matches when any of the specified environment variables is present and not null/empty. /// diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/WellKnownEnvironmentVariables.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/WellKnownEnvironmentVariables.cs index e52cb3b88b..cf618db08d 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/WellKnownEnvironmentVariables.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/WellKnownEnvironmentVariables.cs @@ -11,16 +11,27 @@ public static class WellKnownEnvironmentVariables /// public static readonly IReadOnlyList 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", @@ -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", ];