From 207a98ce46761d469dbc8d51e70fac8a6ee77381 Mon Sep 17 00:00:00 2001 From: Merge Sim Date: Wed, 2 Sep 2026 15:23:25 -0700 Subject: [PATCH] fix(native-chat): ignore resolved default agent args in routing --- .../sidebar/folder-workspace-composer-submit.ts | 4 ++-- src/renderer/src/lib/agent-launch-routing.test.ts | 11 +++++++++++ src/renderer/src/lib/agent-launch-routing.ts | 12 +++++++++--- src/renderer/src/lib/launch-agent-in-new-tab.ts | 4 ++-- src/renderer/src/lib/launch-work-item-direct.ts | 4 ++-- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts b/src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts index 75b4ee943ac..604378ec710 100644 --- a/src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts +++ b/src/renderer/src/components/sidebar/folder-workspace-composer-submit.ts @@ -24,7 +24,7 @@ import { } from './folder-workspace-composer-helpers' import { hasExplicitTuiLaunchCustomization, - hasSemanticallyNonEmptyAgentArgs, + hasExplicitTuiAgentArgs, resolveAgentLaunchRoute } from '@/lib/agent-launch-routing' import { readLocalRuntimeCapabilities } from '@/runtime/local-runtime-capabilities' @@ -157,7 +157,7 @@ export async function submitFolderWorkspaceCreate({ launchText: launchDraftPrompt ?? note, nativeChatTranscriptIsLocalReadable: !launchIsRemote, requiresTuiLaunchCustomization: - hasSemanticallyNonEmptyAgentArgs(agentArgs) || + hasExplicitTuiAgentArgs(quickAgent, agentArgs) || hasExplicitTuiLaunchCustomization(settings, quickAgent), initialSessionOptions: startupPlan?.sessionOptions }) diff --git a/src/renderer/src/lib/agent-launch-routing.test.ts b/src/renderer/src/lib/agent-launch-routing.test.ts index 7720713aa02..a3456e29d16 100644 --- a/src/renderer/src/lib/agent-launch-routing.test.ts +++ b/src/renderer/src/lib/agent-launch-routing.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest' import { STRUCTURED_AGENT_SESSION_RUNTIME_CAPABILITY } from '../../../shared/protocol-version' import { + hasExplicitTuiAgentArgs, hasExplicitTuiLaunchCustomization, hasSemanticallyNonEmptyAgentArgs, resolveAgentLaunchRoute @@ -113,4 +114,14 @@ describe('resolveAgentLaunchRoute', () => { ) ).toBe(false) }) + + it('does not classify the resolved default TUI args as customization', () => { + expect(hasExplicitTuiAgentArgs('codex', '--dangerously-bypass-approvals-and-sandbox')).toBe( + false + ) + expect(hasExplicitTuiAgentArgs('codex', '--model gpt-5.6-sol')).toBe(true) + expect(route({ agentArgs: '--dangerously-bypass-approvals-and-sandbox' })).toBe( + 'structured-native-chat' + ) + }) }) diff --git a/src/renderer/src/lib/agent-launch-routing.ts b/src/renderer/src/lib/agent-launch-routing.ts index 511c0d605d8..dd72cb29794 100644 --- a/src/renderer/src/lib/agent-launch-routing.ts +++ b/src/renderer/src/lib/agent-launch-routing.ts @@ -52,9 +52,7 @@ export function hasExplicitTuiLaunchCustomization( Object.entries(configuredEnv).some(([key, value]) => defaultEnv[key] !== value)) return ( Boolean(settings?.agentCmdOverrides?.[agent]?.trim()) || - (configuredArgs !== undefined && - configuredArgs.trim().length > 0 && - configuredArgs.trim() !== getTuiAgentDefaultArgs(agent).trim()) || + hasExplicitTuiAgentArgs(agent, configuredArgs) || envIsCustomized ) } @@ -63,6 +61,14 @@ export function hasSemanticallyNonEmptyAgentArgs(value: string | null | undefine return Boolean(value?.trim()) } +export function hasExplicitTuiAgentArgs( + agent: TuiAgent, + value: string | null | undefined +): boolean { + const trimmed = value?.trim() ?? '' + return trimmed.length > 0 && trimmed !== getTuiAgentDefaultArgs(agent).trim() +} + export function resolveAgentLaunchRoute(input: AgentLaunchRoutingInput): AgentLaunchRoute { const initialViewMode = decideInitialAgentTabViewMode({ experimentalNativeChat: input.settings?.experimentalNativeChat, diff --git a/src/renderer/src/lib/launch-agent-in-new-tab.ts b/src/renderer/src/lib/launch-agent-in-new-tab.ts index 59a0051a2a7..751763afa4c 100644 --- a/src/renderer/src/lib/launch-agent-in-new-tab.ts +++ b/src/renderer/src/lib/launch-agent-in-new-tab.ts @@ -35,7 +35,7 @@ import { seedNativeChatAppliedSessionOptions } from '@/components/native-chat/na import { startStructuredCodexLaunch } from '@/lib/structured-agent-session-launch' import { hasExplicitTuiLaunchCustomization, - hasSemanticallyNonEmptyAgentArgs, + hasExplicitTuiAgentArgs, resolveAgentLaunchRoute } from '@/lib/agent-launch-routing' import { readLocalRuntimeCapabilities } from '@/runtime/local-runtime-capabilities' @@ -217,7 +217,7 @@ function launchAgentInNewTabInternal( initialViewModeOptions.nativeChatTranscriptIsLocalReadable, requiresTuiLaunchCustomization: Boolean(initialCwd?.trim()) || - hasSemanticallyNonEmptyAgentArgs(agentArgs) || + hasExplicitTuiAgentArgs(agent, agentArgs) || hasExplicitTuiLaunchCustomization(store.settings, agent), initialSessionOptions: startupPlan.sessionOptions }) diff --git a/src/renderer/src/lib/launch-work-item-direct.ts b/src/renderer/src/lib/launch-work-item-direct.ts index 45b216919a8..a70a4ef4896 100644 --- a/src/renderer/src/lib/launch-work-item-direct.ts +++ b/src/renderer/src/lib/launch-work-item-direct.ts @@ -35,7 +35,7 @@ import { import { getExecutionHostIdForWorktree } from '@/lib/worktree-runtime-owner' import { hasExplicitTuiLaunchCustomization, - hasSemanticallyNonEmptyAgentArgs, + hasExplicitTuiAgentArgs, resolveAgentLaunchRoute } from '@/lib/agent-launch-routing' import { readLocalRuntimeCapabilities } from '@/runtime/local-runtime-capabilities' @@ -268,7 +268,7 @@ export async function launchWorkItemDirect(args: LaunchWorkItemDirectArgs): Prom nativeChatTranscriptIsLocalReadable: isNativeChatTranscriptLocalReadable(launchConnectionId), requiresTuiLaunchCustomization: - hasSemanticallyNonEmptyAgentArgs(agentArgs) || + hasExplicitTuiAgentArgs(effectiveAgent, agentArgs) || hasExplicitTuiLaunchCustomization(settings, effectiveAgent), initialSessionOptions: startupPlan?.sessionOptions })