fix(desktop): start a chat with no extensions when the user selects none (#11908)

Signed-off-by: Seydi Charyyev <seydi.charyev@gmail.com>
This commit is contained in:
Seydi Charyyev
2026-09-16 11:20:38 +00:00
committed by GitHub
parent 616cdce989
commit f4e97c3532
8 changed files with 143 additions and 39 deletions
+25 -15
View File
@@ -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',
+45 -1
View File
@@ -28,6 +28,23 @@ function sessionInfo(overrides: Partial<SessionInfo> = {}): 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<ReturnType<typeof getAcpClient>>
);
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<ReturnType<typeof getAcpClient>>
);
await acpNewSession('/tmp', [], {
await acpNewSession('/tmp', undefined, {
recipeDeeplink: 'goose://recipe?url=example',
recipeParameterScopeId: 'scope-1',
});
+2 -2
View File
@@ -48,7 +48,7 @@ export interface AcpSubmitMessageOptions extends AcpSnapshotOptions {
export interface AcpChatSessionController {
createSession(
cwd: string,
gooseExtensions: GooseExtension[],
gooseExtensions: GooseExtension[] | undefined,
recipe?: AcpRecipeOptions
): Promise<Session>;
loadSession(sessionId: string, options?: AcpLoadSessionOptions): Promise<void>;
@@ -114,7 +114,7 @@ async function forkSessionWithEditedMessage(
async function createSession(
cwd: string,
gooseExtensions: GooseExtension[],
gooseExtensions: GooseExtension[] | undefined,
recipe?: AcpRecipeOptions
): Promise<Session> {
const { sessionId, sessionInfo, meta } = await acpNewSession(cwd, gooseExtensions, recipe);
+7 -2
View File
@@ -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<AcpNewSessionResult> {
const client = await getAcpClient();
const meta: Record<string, unknown> = { client: 'goose-desktop' };
if (gooseExtensions.length > 0) {
if (gooseExtensions !== undefined) {
meta.enabledExtensions = gooseExtensions;
}
if (recipe?.recipeId) {
+24
View File
@@ -11,6 +11,7 @@ import { UserInput } from '../types/message';
type ChatInputCapture = {
draftRef?: { current: string };
handleSubmit: (input: UserInput) => void;
onNextChatExtensionDraftChange?: (draft: { selectedNames: Set<string> }) => void;
};
type Session = Awaited<ReturnType<typeof createSession>>;
@@ -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);
+7 -7
View File
@@ -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.
@@ -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) {
+31 -11
View File
@@ -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<GooseExtension[] | undefined> {
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,