Skip to content
14 changes: 14 additions & 0 deletions src/main/acp/__fixtures__/session-new-auth-required.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"agent": "grok",
"version": "1.0.70",
"method": "session/new",
"reply": {
"jsonrpc": "2.0",
"id": 2,
"error": {
"code": -32000,
"message": "Authentication required",
"data": "no auth method id provided"
}
}
}
15 changes: 15 additions & 0 deletions src/main/acp/acp-model-catalog-probe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AcpScriptedAgent } from './acp-scripted-agent.test-support'
import { AgentModelCatalogListingStoppedError } from '../native-chat/agent-model-catalog/agent-model-catalog-failures'
import type { ProviderProcessLaunch } from '../provider-process/provider-process-launch'
import { openCodeAcpAccountBinding } from '../opencode/opencode-structured-account-home'
import authRequired from './__fixtures__/session-new-auth-required.json'

const PREFIX = ['run', '--', 'agent']
const launcherSettings = (agent: string) => ({
Expand Down Expand Up @@ -167,6 +168,20 @@ function scriptedOpenCode2(canDelete: boolean): {
}

describe('ACP model catalog probes', () => {
it('projects an agent-authored auth-required session/new error, retaining unknown for other failures', async () => {
const { agent, deps } = scriptedOpenCode2(true)
const { code, message, data } = authRequired.reply.error
agent.on('session/new', (frame) => agent.fail(frame, code, message, data))
const list = () =>
createAcpModelCatalogProbe(OPENCODE, deps)(
{ kind: 'opencode', locator: { kind: 'unmanaged' } },
{ workspacePath: '/work/project' }
)
await expect(list()).rejects.toMatchObject({ unavailable: { reason: 'notSignedIn' } })
agent.on('session/new', (frame) => agent.fail(frame, -32603, 'Internal error'))
await expect(list()).rejects.toMatchObject({ code: -32603 })
})

it('lists Grok from initialize alone, under its pinned account, and closes the child', async () => {
const { agent, deps, launches, closed } = scriptedGrok({ modelState: MODEL_STATE })
deps.resolveCommandSettings = () => launcherSettings('grok')
Expand Down
19 changes: 14 additions & 5 deletions src/main/acp/acp-model-catalog-probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import {
import { homedir } from 'node:os'
import { join } from 'node:path'
import type { AgentCliVersionReader } from '../agent-cli-version-probe'
import type {
AgentModelCatalogProbe,
AgentModelCatalogSuccess
} from '../native-chat/agent-model-catalog/agent-model-catalog-store'
import type { AgentModelCatalogProbe } from '../native-chat/agent-model-catalog/agent-model-catalog-store'
import {
runAgentModelCatalogListing,
runAgentModelCatalogSession
Expand All @@ -32,6 +29,8 @@ import {
} from './acp-structured-launch-resolution'
import { AcpStructuredOptions } from './acp-structured-options'
import type { InitializeResponse } from './generated/acp-protocol.generated'
import { AcpAgentError } from './acp-errors'
import { AgentModelCatalogUnavailableError } from '../native-chat/agent-model-catalog/agent-model-catalog-unavailable'

/** Session-free capability boundary: no session methods are exposed. */
export type AcpModelCatalogConnection = {
Expand Down Expand Up @@ -60,7 +59,7 @@ export function createAcpModelCatalogProbe(
spec: AcpLaunchSpec,
deps: AcpModelCatalogProbeDeps
): AgentModelCatalogProbe {
return async (accountHome, options): Promise<AgentModelCatalogSuccess> => {
const probe: AgentModelCatalogProbe = async (accountHome, options) => {
const operation = options?.operation ?? { signal: options?.signal }
assertStructuredAgentResolutionCurrent(operation)
const discovery = spec.modelDiscovery
Expand Down Expand Up @@ -156,6 +155,16 @@ export function createAcpModelCatalogProbe(
}
return { models, origin: 'probe' }
}
return async (home, options) => {
try {
return await probe(home, options)
} catch (error) {
if (error instanceof AcpAgentError && error.code === -32000) {
throw new AgentModelCatalogUnavailableError({ reason: 'notSignedIn' })
}
throw error
}
}
}

const folderlessListing = (spec: AcpLaunchSpec) =>
Expand Down
176 changes: 176 additions & 0 deletions src/main/claude/__fixtures__/catalog-signin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
{
"version": "2.1.310",
"accounts": {
"signedOut": {
"tokenSource": "none",
"apiProvider": "firstParty"
},
"apiKey": {
"tokenSource": "none",
"apiKeySource": "ANTHROPIC_API_KEY",
"apiProvider": "firstParty"
},
"bearer": {
"tokenSource": "ANTHROPIC_AUTH_TOKEN",
"apiProvider": "firstParty"
},
"bedrock": {
"apiProvider": "bedrock"
}
},
"models": {
"models": [
{
"value": "default",
"resolvedModel": "claude-opus-5-5",
"displayName": "Default (recommended)",
"description": "Use the default model (currently Opus 5.5) · $4/$20 per Mtok",
"supportsEffort": true,
"supportedEffortLevels": ["low", "medium", "high", "xhigh", "max"],
"supportsAdaptiveThinking": true,
"supportsFastMode": true,
"supportsAutoMode": true,
"supportsThinkingOff": false
},
{
"value": "opus",
"resolvedModel": "claude-opus-5-5",
"displayName": "Opus",
"description": "Opus 5.5 · Best for everyday, complex tasks · $4/$20 per Mtok",
"supportsEffort": true,
"supportedEffortLevels": ["low", "medium", "high", "xhigh", "max"],
"supportsAdaptiveThinking": true,
"supportsFastMode": true,
"supportsAutoMode": true,
"supportsThinkingOff": false
},
{
"value": "fable",
"resolvedModel": "claude-fable-5-1",
"displayName": "Fable",
"description": "Fable 5.1 · Most capable for your hardest and longest-running tasks · $10/$50 per Mtok",
"supportsEffort": true,
"supportedEffortLevels": ["low", "medium", "high", "xhigh", "max"],
"supportsAdaptiveThinking": true,
"supportsAutoMode": true,
"supportsThinkingOff": false
},
{
"value": "sonnet",
"resolvedModel": "claude-sonnet-5-5",
"displayName": "Sonnet",
"description": "Sonnet 5.5 · Efficient for routine tasks · $2/$10 per Mtok",
"supportsEffort": true,
"supportedEffortLevels": ["low", "medium", "high", "xhigh", "max"],
"supportsAdaptiveThinking": true,
"supportsAutoMode": true,
"supportsThinkingOff": false
},
{
"value": "haiku",
"resolvedModel": "claude-haiku-5-5",
"displayName": "Haiku",
"description": "Haiku 5.5 · Fastest for quick answers · $0.10/$0.50 per Mtok ($0.50/$2.50 for prompts over 100k)",
"supportsEffort": true,
"supportedEffortLevels": ["low", "medium", "high", "xhigh", "max"],
"supportsAdaptiveThinking": true,
"supportsAutoMode": true,
"supportsThinkingOff": false
}
]
},
"settings": {
"effective": {
"disableAllHooks": true
},
"sources": [
{
"source": "flagSettings",
"settings": {
"disableAllHooks": true
}
}
],
"applied": {
"model": "claude-opus-5-5",
"effort": "medium",
"advisor": null,
"ultracode": false,
"ultracodeRequested": false,
"ultracodeAvailable": true
}
},
"endpointSettings": {
"effective": {
"env": {
"ANTHROPIC_BASE_URL": "https://gateway.example.invalid"
},
"disableAllHooks": true
},
"sources": [
{
"source": "userSettings",
"settings": {
"env": {
"ANTHROPIC_BASE_URL": "https://gateway.example.invalid"
}
}
},
{
"source": "projectSettings",
"settings": {
"env": {
"ANTHROPIC_BASE_URL": "https://gateway.example.invalid"
}
}
},
{
"source": "flagSettings",
"settings": {
"disableAllHooks": true
}
}
],
"applied": {
"model": "claude-opus-5-5",
"effort": "medium",
"advisor": null,
"ultracode": false,
"ultracodeRequested": false,
"ultracodeAvailable": true
}
},
"commandFrames": {
"error": {
"type": "control_response",
"response": {
"subtype": "error",
"request_id": "orca-command-discovery",
"error": "Unsupported control request subtype: orca_unknown_subtype"
}
},
"initialize": {
"type": "control_response",
"response": {
"subtype": "success",
"request_id": "orca-command-discovery",
"response": {
"commands": [
{
"name": "deep-research",
"description": "Deep research harness — fan-out web searches, fetch sources, adversarially verify claims, synthesize a cited report. (dynamic workflow)",
"argumentHint": "",
"builtin": true
},
{
"name": "design",
"description": "Grant or revoke Claude agent access to your Design projects",
"argumentHint": "consent | revoke",
"builtin": true
}
]
}
}
}
}
}
35 changes: 5 additions & 30 deletions src/main/claude/claude-command-catalog-probe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { AgentSessionSlashCommand } from '../../shared/agent-session/agent-session-wire'
import { assertJsonTextStructureWithinLimits } from '../../shared/json-text-structure-limit'
import { runClaudeListing, type ClaudeModelCatalogProbeDeps } from './claude-model-catalog-probe'
import { ClaudeSlashCommandCatalog } from './claude-slash-command-catalog'
import { readClaudeControlResponses } from './claude-control-responses'

const REQUEST_ID = 'orca-command-discovery'

Expand All @@ -12,8 +12,6 @@ const CLAUDE_COMMAND_LIST_STDIN = `${JSON.stringify({
request: { subtype: 'initialize' }
})}\n`

const INITIALIZE_JSON_LIMITS = { structuralTokens: 64 * 1024, nestingDepth: 16 } as const

export type ClaudeCommandCatalogProbe = (request: {
cwd: string
accountHomePath: string
Expand Down Expand Up @@ -42,31 +40,8 @@ export function createClaudeCommandCatalogProbe(
}

function readInitializeCommands(stdout: string): AgentSessionSlashCommand[] | undefined {
for (const rawLine of stdout.split(/\r?\n/)) {
const line = rawLine.trim()
if (!line.startsWith('{') || !line.includes(REQUEST_ID)) {
continue
}
let parsed: unknown
try {
assertJsonTextStructureWithinLimits(line, INITIALIZE_JSON_LIMITS)
parsed = JSON.parse(line)
} catch {
continue
}
const response =
parsed && typeof parsed === 'object' && 'response' in parsed ? parsed.response : undefined
if (
response &&
typeof response === 'object' &&
'subtype' in response &&
response.subtype === 'success' &&
'request_id' in response &&
response.request_id === REQUEST_ID &&
'response' in response
) {
return new ClaudeSlashCommandCatalog(undefined, response.response).commands
}
}
return undefined
const initialization = readClaudeControlResponses(stdout).get(REQUEST_ID)
return initialization === undefined
? undefined
: new ClaudeSlashCommandCatalog(undefined, initialization).commands
}
30 changes: 30 additions & 0 deletions src/main/claude/claude-control-responses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { assertJsonTextStructureWithinLimits } from '../../shared/json-text-structure-limit'

const CONTROL_JSON_LIMITS = { structuralTokens: 64 * 1024, nestingDepth: 16 } as const

function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null && !Array.isArray(value)
}

export function readClaudeControlResponses(stdout: string): Map<string, unknown> {
const responses = new Map<string, unknown>()
for (const line of stdout.split(/\r?\n/)) {
if (!line.trimStart().startsWith('{') || !line.includes('request_id')) {
continue
}
try {
assertJsonTextStructureWithinLimits(line, CONTROL_JSON_LIMITS)
const frame: unknown = JSON.parse(line)
if (!isRecord(frame) || !isRecord(frame.response)) {
continue
}
const response = frame.response
if (response.subtype === 'success' && typeof response.request_id === 'string') {
responses.set(response.request_id, response.response)
}
} catch {
// Diagnostics and incomplete frames establish no control facts.
}
}
return responses
}
Loading
Loading