Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('knownAgentTypeForProvider', () => {
expect(knownAgentTypeForProvider('claude')).toBe('claude-code');
});

it.each(['codex', 'opencode', 'antigravity', 'cursor'])(
it.each(['codex', 'opencode', 'antigravity', 'cursor', 'goose'])(
'registers %s under its own gateway known-agent type',
(providerId) => {
// Without this OpenCode fell through to a fallback and registered as
Expand Down
17 changes: 10 additions & 7 deletions console/packages/agent-controller/src/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { silentLogger } from './log';
import { type AgentObservation, emptyObservation } from './runtime';
import {
type AgentAssignment,
PROVIDERS,
type ProviderStatus,
type SealedLoginResponse,
statusReportSchema,
Expand Down Expand Up @@ -310,21 +311,23 @@ describe('ProviderStatuses', () => {
log: silentLogger,
onChange: () => changes++,
});
// Every provider reports once; every one but the missing cursor is probed.
const installed = PROVIDERS.length - 1;
expect(statuses.snapshot()).toEqual([]);
await statuses.refreshStale();
expect(runtime.probes).toBe(4);
expect(changes).toBe(5);
expect(runtime.probes).toBe(installed);
expect(changes).toBe(PROVIDERS.length);
expect(statuses.snapshot().find((s) => s.provider === 'cursor')?.installed).toBe(false);
clock += PROVIDER_TTL_MS - 1;
await statuses.refreshStale();
expect(runtime.probes).toBe(4);
expect(runtime.probes).toBe(installed);
clock += 1;
await statuses.refreshStale();
expect(runtime.probes).toBe(8);
expect(changes).toBe(5);
expect(runtime.probes).toBe(2 * installed);
expect(changes).toBe(PROVIDERS.length);
runtime.readiness = { status: 'unauthenticated', message: '', models: [] };
await statuses.check('claude');
expect(changes).toBe(6);
expect(changes).toBe(PROVIDERS.length + 1);
expect(statuses.snapshot().find((s) => s.provider === 'claude')?.auth).toBe('missing');
});
});
Expand Down Expand Up @@ -429,7 +432,7 @@ describe('ProviderStatuses taking checks made before it started', () => {
]);
await providers.refreshStale();
// Every provider but the two seeded is checked here.
expect(runtime.probes).toBe(3);
expect(runtime.probes).toBe(PROVIDERS.length - 2);
expect(await providers.binaryPath('claude')).toBe('/bin/claude');
});

Expand Down
20 changes: 18 additions & 2 deletions console/packages/agent-providers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ does not filter; use `pnpm exec vitest run <file>` for one provider.

## ACP providers

Cursor and Antigravity run on one adapter, `src/acp/acp-adapter.ts`, which
Cursor, Antigravity and Goose run on one adapter, `src/acp/acp-adapter.ts`, which
covers the protocol and chooses behaviour from what the agent advertises in
`initialize` and `session/new`:

Expand All @@ -86,7 +86,8 @@ covers the protocol and chooses behaviour from what the agent advertises in
the agent (or its hooks) says it takes them, else as `resource_link`.

Everything else that differs between CLIs is in its hooks file
(`src/cursor/cursor-adapter.ts`, `src/antigravity/antigravity-adapter.ts`):
(`src/cursor/cursor-adapter.ts`, `src/antigravity/antigravity-adapter.ts`,
`src/goose/goose-acp.ts`):
binary and arguments, the `authenticate` method, the mode for each runtime
mode, how a tool call names its MCP server, sign-in checks, and vendor
extensions.
Expand Down Expand Up @@ -127,3 +128,18 @@ requests whose tool call id starts with `interaction_`, and its old sign-in
check; its sign-in command is `antigravity-acp --login`, and Update installs
`agy` over it. Native session ids are stored with an `acp:` prefix; a
conversation saved by the retired CLI runtime starts fresh.

**Goose** runs `goose acp` and needs no `authenticate`: it signs in to the
model provider chosen with `goose configure`, or to the one named by
`GOOSE_PROVIDER` and `GOOSE_MODEL` with that provider's key (for Groq,
`GOOSE_PROVIDER=groq` and `GROQ_API_KEY`). Its sign-in check first opens
`goose acp` to confirm the `goose` found is Block's, not pressly/goose (a
database migration tool of the same name), then reads the provider choice from
`config.yaml` and the environment, the way Goose resolves it. It never touches
the keyring or calls a model, so a wrong key shows on the first turn. `GOOSE_PATH_ROOT` points it at another profile. On a headless machine,
set `GOOSE_DISABLE_KEYRING=1` and keep the key in the environment or Goose's
`secrets.yaml`. Goose's modes map as approval-required and auto-accept-edits
to `approve`, auto to `smart_approve` and full-access to `auto`; it starts in
`approve` until the session's mode is set. A tool call names its extension in
`_meta.goose.toolCall`, and its subagents are the `delegate` tool of its
`summon` extension.
1 change: 1 addition & 0 deletions console/packages/agent-providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@opencode-ai/sdk": "^1.18.27",
"@sandboxaq/switch-agent-runtime": "workspace:*",
"@switch-console/shared": "workspace:*",
"js-yaml": "^5.3.0",
"jsonc-parser": "3.3.1",
"smol-toml": "^1.8.0",
"zod": "^4.6.7"
Expand Down
210 changes: 210 additions & 0 deletions console/packages/agent-providers/src/goose/goose-acp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, describe, expect, it, vi } from 'vitest';
import type { AcpSessionContext } from '../acp/hooks';
import type { AcpInitializeResult, AcpToolCall } from '../acp/protocol';
import { gooseAcp, gooseConfigDirectory } from './goose-acp';

const directories: string[] = [];
afterEach(async () => {
await Promise.all(
directories.splice(0).map((path) => rm(path, { recursive: true, force: true }))
);
});

async function profile(contents?: string) {
const root = await mkdtemp(join(tmpdir(), 'switch-goose-'));
directories.push(root);
await mkdir(join(root, 'config'));
if (contents !== undefined) await writeFile(join(root, 'config', 'config.yaml'), contents);
return { GOOSE_PATH_ROOT: root };
}

async function check(
env: Record<string, string>,
handshake = vi.fn(async (): Promise<AcpInitializeResult> => ({
agentInfo: { name: 'goose', version: '1.57.0' },
}))
) {
const result = await gooseAcp.checkSignIn!({
binaryPath: 'goose',
cwd: '.',
env,
handshake,
request: vi.fn(),
});
expect(handshake).toHaveBeenCalledTimes(1);
return result;
}

describe('Goose ACP hooks', () => {
it('starts ACP with supervised defaults and exactly the supplied environment', async () => {
const env = { GOOGLE_API_KEY: 'placeholder', GOOSE_MODE: 'auto' };
expect(await gooseAcp.launch({ binaryPath: '/tools/goose', cwd: '.', env })).toEqual({
command: '/tools/goose',
args: ['acp'],
env: { ...env, GOOSE_MODE: 'approve', GOOSE_DISABLE_SESSION_NAMING: 'true' },
});
expect(env.GOOSE_MODE).toBe('auto');
expect(gooseAcp.authMethodId).toBeUndefined();
});

it('leaves session naming to the machine when it sets it', async () => {
const env = { GOOSE_DISABLE_SESSION_NAMING: 'false' };
expect(
(await gooseAcp.launch({ binaryPath: 'goose', cwd: '.', env })).env
.GOOSE_DISABLE_SESSION_NAMING
).toBe('false');
});

it.each([
['approval-required', 'approve'],
['auto-accept-edits', 'approve'],
['auto', 'smart_approve'],
['full-access', 'auto'],
] as const)('maps %s to %s', (mode, expected) => {
expect(gooseAcp.sessionMode!(mode, undefined)).toBe(expected);
});

it('recognizes environment configuration without reading the profile', async () => {
expect(
(await check({ GOOSE_PROVIDER: 'google', GOOSE_MODEL: 'gemini-2.5-flash' })).status
).toBe('authenticated');
});

it.each([
'GOOSE_PROVIDER: google\nGOOSE_MODEL: gemini-2.5-flash\n',
'active_provider: google\nproviders:\n google:\n model: gemini-2.5-flash\n',
])('recognizes saved provider configuration', async (contents) => {
expect((await check(await profile(contents))).status).toBe('authenticated');
});

it('combines an environment provider with a saved model', async () => {
expect(
(
await check({
...(await profile('GOOSE_MODEL: gemini-2.5-flash\n')),
GOOSE_PROVIDER: 'google',
})
).status
).toBe('authenticated');
});

it.each([
undefined,
'',
'# no settings yet\n',
'GOOSE_PROVIDER: google\n',
'GOOSE_PROVIDER: " "\nGOOSE_MODEL: model\n',
])('reports incomplete configuration without starting a login', async (contents) => {
expect((await check(await profile(contents))).status).toBe('unconfigured');
});

it.each([
[
'a goose that is not an ACP agent',
() => Promise.reject(new Error('provider process exited')),
],
['another ACP agent', async () => ({ agentInfo: { name: 'other' } })],
])('does not take %s for Goose', async (_case, answer) => {
const env = { GOOSE_PROVIDER: 'google', GOOSE_MODEL: 'gemini-2.5-flash' };
const result = await check(env, vi.fn(answer));
expect(result.status).toBe('unknown');
expect(result.message).toContain('pressly/goose');
});

it('reports unreadable configuration without including its contents', async () => {
const result = await check(await profile('GOOSE_PROVIDER: [invalid'));
expect(result.status).toBe('unknown');
expect(result.message).not.toContain('[invalid');
});

it('uses the execution host profile on each platform', () => {
expect(gooseConfigDirectory({ HOME: '/home/example' }, 'linux')).toBe(
join('/home/example', '.config', 'goose')
);
expect(
gooseConfigDirectory({ HOME: '/home/example', XDG_CONFIG_HOME: '/settings' }, 'linux')
).toBe(join('/settings', 'goose'));
expect(gooseConfigDirectory({ HOME: '/Users/example' }, 'darwin')).toBe(
join('/Users/example', 'Library', 'Application Support', 'Block', 'goose')
);
expect(gooseConfigDirectory({ APPDATA: '/roaming' }, 'win32')).toBe(
join('/roaming', 'Block', 'goose', 'config')
);
});

it('reads MCP server identity only from Goose tool metadata', () => {
expect(
gooseAcp.mcpServerOf!({
toolCallId: 'call',
_meta: { goose: { toolCall: { extensionName: 'echo' } } },
})
).toBe('echo');
expect(gooseAcp.mcpServerOf!({ toolCallId: 'call', title: 'echo: run' })).toBeUndefined();
expect(
gooseAcp.mcpServerOf!({
toolCallId: 'call',
_meta: { goose: { toolCall: { extensionName: 1 } } },
})
).toBeUndefined();
});

it.each(['developer', 'summon', 'Extension Manager'])(
'does not take the built-in %s extension for an MCP server',
(extensionName) => {
expect(gooseAcp.mcpServerOf!(tool('shell', extensionName))).toBeUndefined();
}
);

it.each([
['shell', 'command_execution'],
['write', 'file_change'],
['edit', 'file_change'],
] as const)('types the developer %s tool as %s', (toolName, type) => {
expect(gooseAcp.itemType!(tool(toolName, 'developer'))).toBe(type);
expect(gooseAcp.itemType!(tool(toolName, 'echo'))).toBeUndefined();
});

it('identifies delegation from Goose metadata without matching prose titles', () => {
expect(gooseAcp.itemType!(tool('delegate', 'summon'))).toBe('subagent');
expect(gooseAcp.itemType!(tool('delegate', 'echo'))).toBeUndefined();
expect(gooseAcp.itemType!({ toolCallId: 'call', title: 'Delegate this task' })).toBeUndefined();
});

it.each([
['shell · echo hi', 'execute'],
['write · notes.txt', 'edit'],
['edit · src/index.ts', 'edit'],
['echo: write · notes.txt', undefined],
['constructor · x', undefined],
])('gives the permission request for %s the kind %s', (title, kind) => {
const request = {
sessionId: 'session',
toolCall: { toolCallId: 'call', title, kind: 'other' },
options: [],
};
expect(gooseAcp.permission!({} as AcpSessionContext, request)).toBeUndefined();
expect(request.toolCall.kind).toBe(kind ?? 'other');
});

it('never offers what Goose would save for good, and names the rest', () => {
// Goose's options, as `goose acp` 1.57.0 sends them.
const option = (kind: string) => ({ optionId: kind, name: kind, kind });
const request = {
sessionId: 'session',
toolCall: { toolCallId: 'call', title: 'shell · ls' },
options: ['allow_always', 'allow_once', 'reject_once', 'reject_always'].map(option),
};
gooseAcp.permission!({} as AcpSessionContext, request);
expect(request.options).toEqual([
{ optionId: 'allow_once', name: 'Allow once', kind: 'allow_once' },
{ optionId: 'reject_once', name: 'Reject', kind: 'reject_once' },
]);
});
});

function tool(toolName: string, extensionName: string): AcpToolCall {
return { toolCallId: 'call', _meta: { goose: { toolCall: { toolName, extensionName } } } };
}
Loading
Loading