From f4e97c3532bbb5ae41a3bf999909cb3303cd4617 Mon Sep 17 00:00:00 2001 From: Seydi Charyyev Date: Wed, 16 Sep 2026 11:20:38 +0000 Subject: [PATCH] fix(desktop): start a chat with no extensions when the user selects none (#11908) Signed-off-by: Seydi Charyyev --- .../src/__tests__/createSession.test.ts | 40 ++++++++++------ ui/desktop/src/acp/__tests__/sessions.test.ts | 46 ++++++++++++++++++- ui/desktop/src/acp/chatSessionController.ts | 4 +- ui/desktop/src/acp/sessions.ts | 9 +++- ui/desktop/src/components/Hub.test.tsx | 24 ++++++++++ ui/desktop/src/components/Hub.tsx | 14 +++--- .../src/components/apps/StandaloneAppView.tsx | 3 +- ui/desktop/src/sessions.ts | 42 ++++++++++++----- 8 files changed, 143 insertions(+), 39 deletions(-) diff --git a/ui/desktop/src/__tests__/createSession.test.ts b/ui/desktop/src/__tests__/createSession.test.ts index 48c518e6e..93ae12571 100644 --- a/ui/desktop/src/__tests__/createSession.test.ts +++ b/ui/desktop/src/__tests__/createSession.test.ts @@ -104,25 +104,12 @@ describe('createSession ACP session extensions', () => { }); }); - it('falls back to enabled configured extensions when extension configs are empty', async () => { + it('sends an explicitly empty selection as an empty list, not as "unspecified"', async () => { await createSession('/tmp', { extensionConfigs: [], allExtensions: [configuredExtension('developer', true), configuredExtension('memory', false)], }); - expect(mockedGetConfiguredGooseExtensions).toHaveBeenCalledOnce(); - expect(mockedCreateAcpSession).toHaveBeenCalledWith('/tmp', [gooseExtension('developer')], { - recipeDeeplink: undefined, - recipeId: undefined, - recipeParameterScopeId: undefined, - }); - }); - - it('omits ACP session extensions when no configured extensions are enabled', async () => { - await createSession('/tmp', { - allExtensions: [configuredExtension('developer', false)], - }); - expect(mockedGetConfiguredGooseExtensions).not.toHaveBeenCalled(); expect(mockedCreateAcpSession).toHaveBeenCalledWith('/tmp', [], { recipeDeeplink: undefined, @@ -131,11 +118,34 @@ describe('createSession ACP session extensions', () => { }); }); + it('leaves the set unspecified when no configured extensions are enabled', async () => { + await createSession('/tmp', { + allExtensions: [configuredExtension('developer', false)], + }); + + expect(mockedGetConfiguredGooseExtensions).not.toHaveBeenCalled(); + expect(mockedCreateAcpSession).toHaveBeenCalledWith('/tmp', undefined, { + recipeDeeplink: undefined, + recipeId: undefined, + recipeParameterScopeId: undefined, + }); + }); + + it('leaves the set unspecified while the configured extensions are still loading', async () => { + await createSession('/tmp', { allExtensions: [] }); + + expect(mockedCreateAcpSession).toHaveBeenCalledWith('/tmp', undefined, { + recipeDeeplink: undefined, + recipeId: undefined, + recipeParameterScopeId: undefined, + }); + }); + it('scopes startup parameters to recipe deeplink session creation', async () => { await createSession('/tmp', { recipeDeeplink: 'goose://recipe?url=example' }); expect(mockedBeginConfiguredRecipeParameterScope).toHaveBeenCalledOnce(); - expect(mockedCreateAcpSession).toHaveBeenCalledWith('/tmp', [], { + expect(mockedCreateAcpSession).toHaveBeenCalledWith('/tmp', undefined, { recipeDeeplink: 'goose://recipe?url=example', recipeId: undefined, recipeParameterScopeId: 'scope-1', diff --git a/ui/desktop/src/acp/__tests__/sessions.test.ts b/ui/desktop/src/acp/__tests__/sessions.test.ts index bd4150f2b..a800d16d3 100644 --- a/ui/desktop/src/acp/__tests__/sessions.test.ts +++ b/ui/desktop/src/acp/__tests__/sessions.test.ts @@ -28,6 +28,23 @@ function sessionInfo(overrides: Partial = {}): SessionInfo { } as unknown as SessionInfo; } +function newSessionClient() { + const client = { + connection: { + agent: { + request: vi.fn().mockResolvedValue({ sessionId: 'session-1' }), + }, + }, + goose: { + sessionInfo_unstable: vi.fn().mockResolvedValue({ session: sessionInfo() }), + }, + }; + vi.mocked(getAcpClient).mockResolvedValue( + client as unknown as Awaited> + ); + return client; +} + describe('ACP sessions', () => { beforeEach(() => { vi.clearAllMocks(); @@ -109,6 +126,33 @@ describe('ACP sessions', () => { ); }); + it('sends an explicitly empty extension set as an empty list', async () => { + const client = newSessionClient(); + + await acpNewSession('/tmp', []); + + expect(client.connection.agent.request).toHaveBeenCalledWith(methods.agent.session.new, { + cwd: '/tmp', + mcpServers: [], + _meta: { + client: 'goose-desktop', + enabledExtensions: [], + }, + }); + }); + + it('omits the extension key when the caller names no set', async () => { + const client = newSessionClient(); + + await acpNewSession('/tmp', undefined); + + expect(client.connection.agent.request).toHaveBeenCalledWith(methods.agent.session.new, { + cwd: '/tmp', + mcpServers: [], + _meta: { client: 'goose-desktop' }, + }); + }); + it('carries the recipe parameter scope id in new-session metadata', async () => { const createdSessionInfo = sessionInfo(); const client = { @@ -125,7 +169,7 @@ describe('ACP sessions', () => { client as unknown as Awaited> ); - await acpNewSession('/tmp', [], { + await acpNewSession('/tmp', undefined, { recipeDeeplink: 'goose://recipe?url=example', recipeParameterScopeId: 'scope-1', }); diff --git a/ui/desktop/src/acp/chatSessionController.ts b/ui/desktop/src/acp/chatSessionController.ts index d21f4ef0e..74956a742 100644 --- a/ui/desktop/src/acp/chatSessionController.ts +++ b/ui/desktop/src/acp/chatSessionController.ts @@ -48,7 +48,7 @@ export interface AcpSubmitMessageOptions extends AcpSnapshotOptions { export interface AcpChatSessionController { createSession( cwd: string, - gooseExtensions: GooseExtension[], + gooseExtensions: GooseExtension[] | undefined, recipe?: AcpRecipeOptions ): Promise; loadSession(sessionId: string, options?: AcpLoadSessionOptions): Promise; @@ -114,7 +114,7 @@ async function forkSessionWithEditedMessage( async function createSession( cwd: string, - gooseExtensions: GooseExtension[], + gooseExtensions: GooseExtension[] | undefined, recipe?: AcpRecipeOptions ): Promise { const { sessionId, sessionInfo, meta } = await acpNewSession(cwd, gooseExtensions, recipe); diff --git a/ui/desktop/src/acp/sessions.ts b/ui/desktop/src/acp/sessions.ts index 0b3b009cb..298b35b93 100644 --- a/ui/desktop/src/acp/sessions.ts +++ b/ui/desktop/src/acp/sessions.ts @@ -235,14 +235,19 @@ export interface AcpRecipeOptions { recipeParameterScopeId?: string; } +/** + * `gooseExtensions` is three-valued: `undefined` leaves the key out so the backend + * uses the configured set, while `[]` asks for a session with no extensions. The + * backend already distinguishes the two, so the client has to as well. + */ export async function acpNewSession( cwd: string, - gooseExtensions: GooseExtension[], + gooseExtensions: GooseExtension[] | undefined, recipe?: AcpRecipeOptions ): Promise { const client = await getAcpClient(); const meta: Record = { client: 'goose-desktop' }; - if (gooseExtensions.length > 0) { + if (gooseExtensions !== undefined) { meta.enabledExtensions = gooseExtensions; } if (recipe?.recipeId) { diff --git a/ui/desktop/src/components/Hub.test.tsx b/ui/desktop/src/components/Hub.test.tsx index a4aa6832a..5b8fbe58a 100644 --- a/ui/desktop/src/components/Hub.test.tsx +++ b/ui/desktop/src/components/Hub.test.tsx @@ -11,6 +11,7 @@ import { UserInput } from '../types/message'; type ChatInputCapture = { draftRef?: { current: string }; handleSubmit: (input: UserInput) => void; + onNextChatExtensionDraftChange?: (draft: { selectedNames: Set }) => void; }; type Session = Awaited>; @@ -82,6 +83,29 @@ describe('Hub', () => { captured.chatInput = null; }); + it('starts a chat with no extensions when the user cleared the picker', async () => { + vi.mocked(createSession).mockResolvedValue({ id: 'session-1' } as Session); + renderHub({ current: '' }); + + // Touching the picker is what turns "not specified" into a real choice, and + // clearing it is the case the composer already promises in a toast. + await act(async () => { + captured.chatInput?.onNextChatExtensionDraftChange?.({ selectedNames: new Set() }); + }); + await submit(); + + expect(createSession).toHaveBeenCalledWith('/tmp/goose', { extensionConfigs: [] }); + }); + + it('leaves the set unspecified when the picker was never touched', async () => { + vi.mocked(createSession).mockResolvedValue({ id: 'session-1' } as Session); + renderHub({ current: '' }); + + await submit(); + + expect(createSession).toHaveBeenCalledWith('/tmp/goose', { allExtensions: [] }); + }); + it('hands the draft to the input', () => { const draftRef = { current: DRAFT }; renderHub(draftRef); diff --git a/ui/desktop/src/components/Hub.tsx b/ui/desktop/src/components/Hub.tsx index 66fccf845..a9b73d6c1 100644 --- a/ui/desktop/src/components/Hub.tsx +++ b/ui/desktop/src/components/Hub.tsx @@ -111,13 +111,13 @@ export default function Hub({ setIsCreatingSession(true); try { - const selectedExtensions = nextChatExtensionDraft - ? selectNextChatExtensions(extensionsList, nextChatExtensionDraft) - : []; - const sessionOptions = - selectedExtensions.length > 0 - ? { extensionConfigs: selectedExtensions } - : { allExtensions: extensionsList }; + // A draft exists only once the user has opened the picker, so its absence is + // "not specified" while an empty draft is "start with no extensions". + const sessionOptions = nextChatExtensionDraft + ? { + extensionConfigs: selectNextChatExtensions(extensionsList, nextChatExtensionDraft), + } + : { allExtensions: extensionsList }; // Resolve the effective directory at submit time: the IPC lookup may still // be pending when the user submits, and an explicit pick must win. diff --git a/ui/desktop/src/components/apps/StandaloneAppView.tsx b/ui/desktop/src/components/apps/StandaloneAppView.tsx index 2bc19f02e..ccbd45409 100644 --- a/ui/desktop/src/components/apps/StandaloneAppView.tsx +++ b/ui/desktop/src/components/apps/StandaloneAppView.tsx @@ -73,7 +73,8 @@ export default function StandaloneAppView() { } try { - const { sessionId: sid } = await acpNewSession(workingDir, []); + // This view names no extension set, so the backend uses the configured one. + const { sessionId: sid } = await acpNewSession(workingDir, undefined); setSessionId(sid); setLoading(false); } catch (err) { diff --git a/ui/desktop/src/sessions.ts b/ui/desktop/src/sessions.ts index 4dcd56ee7..e5c796494 100644 --- a/ui/desktop/src/sessions.ts +++ b/ui/desktop/src/sessions.ts @@ -1,5 +1,6 @@ import type { Session } from './types/session'; import type { ExtensionConfig } from './types/extensions'; +import type { GooseExtension } from '@aaif/goose-acp-client'; import type { setViewType } from './hooks/useNavigation'; import type { FixedExtensionEntry } from './components/ConfigContext'; import { AppEvents } from './constants/events'; @@ -26,19 +27,44 @@ interface CreateSessionOptions { allExtensions?: FixedExtensionEntry[]; } -function selectedExtensionConfigs(options?: CreateSessionOptions): ExtensionConfig[] { - if (options?.extensionConfigs && options.extensionConfigs.length > 0) { +/** + * Three-valued on purpose. `undefined` means the caller is not naming a set and the + * backend should use the configured one; `[]` means the user asked for a session with + * no extensions at all. Collapsing the two is what made an all-off selection come back + * with the default extensions. + */ +function selectedExtensionConfigs(options?: CreateSessionOptions): ExtensionConfig[] | undefined { + if (options?.extensionConfigs) { return options.extensionConfigs; } if (options?.allExtensions) { - return options.allExtensions + const enabled = options.allExtensions .filter((extension) => extension.enabled) .map((extension) => { const { enabled: _enabled, ...config } = extension; return config as ExtensionConfig; }); + // An empty configured list is also what this looks like before the config + // finishes loading, so it stays "not specified" rather than becoming an + // explicit empty selection. Only `extensionConfigs` can express that. + return enabled.length > 0 ? enabled : undefined; } - return []; + return undefined; +} + +async function resolveGooseExtensions( + selected: ExtensionConfig[] | undefined +): Promise { + if (selected === undefined) { + return undefined; + } + if (selected.length === 0) { + return []; + } + const selectedNames = new Set(selected.map((config) => config.name)); + return (await getConfiguredGooseExtensions()) + .filter((entry) => selectedNames.has(gooseExtensionName(entry.extension))) + .map((entry) => entry.extension); } async function createAcpSession( @@ -55,13 +81,7 @@ async function createAcpSession( throw new RecipeParameterScopesUnsupportedError(); } } - const selectedNames = new Set(selectedExtensionConfigs(options).map((config) => config.name)); - const gooseExtensions = - selectedNames.size > 0 - ? (await getConfiguredGooseExtensions()) - .filter((entry) => selectedNames.has(gooseExtensionName(entry.extension))) - .map((entry) => entry.extension) - : []; + const gooseExtensions = await resolveGooseExtensions(selectedExtensionConfigs(options)); return await acpChatSessionController.createSession(workingDir, gooseExtensions, { recipeId: options?.recipeId, recipeDeeplink: options?.recipeDeeplink,