Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
Tell the user when Claude Code isn't available, and find CLIs in a coherent way (#956)
Abel Dantas12312f8378ec
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 97052e097..ac9c02ea0 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1975,6 +1975,10 @@ version of their own to them without also giving them a release of their own.agent"; it was the only place Console showed that name.#### Fixed+- **Settings → Agent providers keeps this computer's report current.** It+ prefers the report from the server Console is on, rereads it while open and+ after the controller reports again, and the install section says so when+ Console's own check disagrees with the controller's.- **The local Switch server starts on Intel Macs without Homebrew.**cryptography publishes no wheel for Intel Macs, so the Intel build ofConsole compiled its own against the build machine's Homebrew OpenSSL, and@@ -3990,9 +3994,10 @@ tags; see RELEASING.md.signed in.** `claude auth status` only says a login or key is present, so akey left by an old install read as signed in while every session failed.When setting up, on a recheck, and whenever a login was not yet known to- work, the controller now sends Claude Code one short test prompt and reports- what it said if it fails. A Claude Code too old to have `auth status` is- reported as such instead of as a check that never finished.+ work, the controller now sends Claude Code one short test prompt, with the+ person's hooks off and stdin closed, and reports what it said if it fails,+ from its result, its `errors` or its stderr. A Claude Code too old to have+ `auth status` is reported as such instead of as a check that never finished.- **A controller updates to the release Switch names while sessions sit idle.**It waited until no session existed on the machine, and a session connected toa room counted even with nothing to do, so a machine with long-lived sessionsdiff --git a/console/apps/switch-console-desktop/src/main/core/embedded-controller/embedded-controller-service.ts b/console/apps/switch-console-desktop/src/main/core/embedded-controller/embedded-controller-service.tsindex ee99ef4e7..8d512f4a5 100644--- a/console/apps/switch-console-desktop/src/main/core/embedded-controller/embedded-controller-service.ts+++ b/console/apps/switch-console-desktop/src/main/core/embedded-controller/embedded-controller-service.ts@@ -94,8 +94,13 @@ export type EmbeddedControllerDeps = {const SUPPORTED_PLATFORMS: readonly NodeJS.Platform[] = ['darwin', 'linux', 'win32'];-/** Every provider's sign-in check runs at once; the slowest allows itself 15 seconds. */-const RECHECK_TIMEOUT_MS = 60_000;+/**+ * Every provider is checked at once. Claude Code's is the slowest: its status+ * command (up to 15 seconds), then a test prompt (up to 30), then the report+ * to Switch, so the wait leaves room for all three and resolves on the+ * report that has them rather than timing out ahead of it.+ */+const RECHECK_TIMEOUT_MS = 90_000;function providerSeedArgs(file: string | null): string[] {return file === null ? [] : ['--provider-seed', file];diff --git a/console/apps/switch-console-desktop/src/main/core/managed-agents/controller.ts b/console/apps/switch-console-desktop/src/main/core/managed-agents/controller.tsindex b01f7609d..b99d5dcaf 100644--- a/console/apps/switch-console-desktop/src/main/core/managed-agents/controller.ts+++ b/console/apps/switch-console-desktop/src/main/core/managed-agents/controller.ts@@ -44,7 +44,7 @@ import type {} from '@shared/core/managed-agents/managed-agents';import type { AgentProviderId } from '@shared/core/providers/agent-provider-registry';import { createRPCController } from '@shared/lib/ipc/rpc';-import { ownedMachines, thisComputerReport } from './owned-machines';+import { ownedMachines, preferredFirst, thisComputerReport } from './owned-machines';async function machinesOn(serverId: string): Promise<OwnedMachine[] | null> {const [thisComputer, hosts] = await Promise.all([@@ -135,11 +135,17 @@ export const managedAgentsController = createRPCController({/*** This computer's providers as its controller last reported them to a- * server it runs for; null when it runs for none, or none has a report,- * and Console's own check is what there is to go by.+ * server it runs for, `preferServerId` (the one Console is on now) first+ * when it is one; null when it runs for none, or none has a report, and+ * Console's own check is what there is to go by.*/- thisComputerProviders: async (): Promise<ThisComputerReport | null> =>- thisComputerReport(await embeddedControllerService.runningServerIds(), machinesOn),+ thisComputerProviders: async (+ preferServerId: string | null = null+ ): Promise<ThisComputerReport | null> =>+ thisComputerReport(+ preferredFirst(await embeddedControllerService.runningServerIds(), preferServerId),+ machinesOn+ ),/*** Gives one of the owner's machines a provider login, sealed here to thediff --git a/console/apps/switch-console-desktop/src/main/core/managed-agents/owned-machines.test.ts b/console/apps/switch-console-desktop/src/main/core/managed-agents/owned-machines.test.tsindex 586284df8..7375bbf52 100644--- a/console/apps/switch-console-desktop/src/main/core/managed-agents/owned-machines.test.ts+++ b/console/apps/switch-console-desktop/src/main/core/managed-agents/owned-machines.test.ts@@ -1,7 +1,12 @@import { describe, expect, it } from 'vitest';import type { ManagementController } from '@main/core/switch-servers/gateway-client';import type { OwnedMachine } from '@shared/core/managed-agents/managed-agents';-import { machineProvider, ownedMachines, thisComputerReport } from './owned-machines';+import {+ machineProvider,+ ownedMachines,+ preferredFirst,+ thisComputerReport,+} from './owned-machines';function controller(patch: Partial<ManagementController> & { id: string }): ManagementController {return {@@ -175,3 +180,11 @@ describe('thisComputerReport', () => {expect(await thisComputerReport([], () => Promise.resolve([machine({})]))).toBeNull();});});++describe('preferredFirst', () => {+ it('asks the server Console is on first, then the rest in order', () => {+ expect(preferredFirst(['a', 'b', 'c'], 'b')).toEqual(['b', 'a', 'c']);+ expect(preferredFirst(['a', 'b'], 'elsewhere')).toEqual(['a', 'b']);+ expect(preferredFirst(['a', 'b'], null)).toEqual(['a', 'b']);+ });+});diff --git a/console/apps/switch-console-desktop/src/main/core/managed-agents/owned-machines.ts b/console/apps/switch-console-desktop/src/main/core/managed-agents/owned-machines.tsindex b12d1a972..e5a925925 100644--- a/console/apps/switch-console-desktop/src/main/core/managed-agents/owned-machines.ts+++ b/console/apps/switch-console-desktop/src/main/core/managed-agents/owned-machines.ts@@ -65,6 +65,17 @@ export function ownedMachines(});}+/**+ * `serverIds` with `preferred` moved to the front when it is among them: the+ * server Console is on now, whose report is the one its screens are about,+ * since controllers on different servers can each say something different.+ */+export function preferredFirst(serverIds: readonly string[], preferred: string | null): string[] {+ return preferred && serverIds.includes(preferred)+ ? [preferred, ...serverIds.filter((serverId) => serverId !== preferred)]+ : [...serverIds];+}+/*** What this computer's controller last reported to the first of `serverIds`* that has a report from it, online: Console's own check of the providersdiff --git a/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/AgentDetailSheet.tsx b/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/AgentDetailSheet.tsxindex 303df7046..0007689b6 100644--- a/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/AgentDetailSheet.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/AgentDetailSheet.tsx@@ -10,7 +10,7 @@ import { AgentSheetHeaderSection } from './AgentSheetHeaderSection';import { InstalledAgentContent } from './InstalledAgentContent';import { InstallSection } from './InstallSection';import { ThisComputerProviderStatus } from './this-computer-provider-status';-import { installedHere, reportedProvider } from './this-computer-status';+import { installedHere, installSourcesDiffer, reportedProvider } from './this-computer-status';interface AgentDetailSheetProps {agentId: string | null;@@ -29,7 +29,9 @@ const AgentDetailSheetContent = observer(function AgentDetailSheetContent({const { value: storedConfig, isOverridden, isLoading, update, reset } = useAgentSettings(agentId);const { data: report } = useThisComputerReport();- const isInstalled = installedHere(reportedProvider(report, agentId), agentPayload?.status);+ const reported = reportedProvider(report, agentId);+ const isInstalled = installedHere(reported, agentPayload?.status);+ const sourcesDiffer = installSourcesDiffer(reported, agentPayload?.status);return (<>@@ -41,6 +43,13 @@ const AgentDetailSheetContent = observer(function AgentDetailSheetContent({<ThisComputerProviderStatus providerId={asAgentProviderId(agentId)} /><Field><Label>Installation</Label>+ {sourcesDiffer && (+ <p className="text-xs text-foreground-muted">+ What Console finds on its own PATH, used to install and update. The status above+ is what this computer’s agents controller reported to Switch, and it looks in+ places Console may not.+ </p>+ )}<InstallSectionagentId={agentId}agentPayload={agentPayload}diff --git a/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/this-computer-status.test.ts b/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/this-computer-status.test.tsindex 0dec7a09b..ffd22dffd 100644--- a/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/this-computer-status.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/this-computer-status.test.ts@@ -1,6 +1,11 @@import { describe, expect, it } from 'vitest';import type { MachineProvider } from '@shared/core/managed-agents/managed-agents';-import { installedHere, reportedHeadline, reportedProvider } from './this-computer-status';+import {+ installedHere,+ installSourcesDiffer,+ reportedHeadline,+ reportedProvider,+} from './this-computer-status';function reported(patch: Partial<MachineProvider>): MachineProvider {return { provider: 'claude', ready: false, problem: null, detail: null, ...patch };@@ -41,4 +46,11 @@ describe('Settings → Agent providers on this computer', () => {'Sign-in could not be checked');});++ it('says when the controller and Console disagree on whether it is installed', () => {+ expect(installSourcesDiffer(reported({ ready: true }), 'missing')).toBe(true);+ expect(installSourcesDiffer(reported({ problem: 'not installed' }), 'available')).toBe(true);+ expect(installSourcesDiffer(reported({ ready: true }), 'available')).toBe(false);+ expect(installSourcesDiffer(null, 'missing')).toBe(false);+ });});diff --git a/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/this-computer-status.ts b/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/this-computer-status.tsindex bfd85ae2e..629ec93aa 100644--- a/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/this-computer-status.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/settings/agents-page/this-computer-status.ts@@ -25,6 +25,21 @@ export function installedHere(return reported ? reported.problem !== 'not installed' : localStatus === 'available';}+/**+ * Whether the controller's report and Console's own check disagree on whether+ * a provider is installed. The Installation section under the status still+ * goes by Console's own check, since that is what installs and updates, so+ * when they disagree it says whose answer each one is.+ */+export function installSourcesDiffer(+ reported: MachineProvider | null,+ localStatus: string | undefined+): boolean {+ return (+ reported !== null && installedHere(reported, localStatus) !== installedHere(null, localStatus)+ );+}+/** The line Settings shows for a provider the controller reported on, worded as Console's own check words it. */export function reportedHeadline(reported: MachineProvider): string {if (reported.ready) return 'Signed in';diff --git a/console/apps/switch-console-desktop/src/renderer/lib/stores/use-agent-installation-statuses.ts b/console/apps/switch-console-desktop/src/renderer/lib/stores/use-agent-installation-statuses.tsindex 721a1cb61..a194cf1ce 100644--- a/console/apps/switch-console-desktop/src/renderer/lib/stores/use-agent-installation-statuses.ts+++ b/console/apps/switch-console-desktop/src/renderer/lib/stores/use-agent-installation-statuses.ts@@ -136,6 +136,7 @@ export function useAgentInstallationStatuses(connectionId?: string) {rpc.providers.uninstall(id, connectionId, method) as Promise<unknown>,onSuccess: (result, vars) => {invalidate();+ if (!connectionId) void recheckThisComputer(queryClient);const name = nameOf(vars.id);if ((result as { success: boolean }).success) {toast({ title: `${name} successfully uninstalled` });diff --git a/console/apps/switch-console-desktop/src/renderer/lib/stores/use-this-computer-report.ts b/console/apps/switch-console-desktop/src/renderer/lib/stores/use-this-computer-report.tsindex 2ed571653..61c5062a9 100644--- a/console/apps/switch-console-desktop/src/renderer/lib/stores/use-this-computer-report.ts+++ b/console/apps/switch-console-desktop/src/renderer/lib/stores/use-this-computer-report.ts@@ -1,6 +1,9 @@-import { type QueryClient, useQuery } from '@tanstack/react-query';-import { rpc } from '@renderer/lib/ipc';+import { type QueryClient, useQuery, useQueryClient } from '@tanstack/react-query';+import { useEffect } from 'react';+import { switchServersStore } from '@renderer/features/switch-servers/switch-servers-store';+import { events, rpc } from '@renderer/lib/ipc';import type { ThisComputerReport } from '@shared/core/managed-agents/managed-agents';+import { embeddedControllerStateChannel } from '@shared/events/embeddedControllerEvents';export const THIS_COMPUTER_REPORT_KEY = ['this-computer-report'] as const;@@ -11,10 +14,27 @@ export const THIS_COMPUTER_REPORT_KEY = ['this-computer-report'] as const;* the New agent form say; Console's own check is the fallback.*/export function useThisComputerReport() {+ const queryClient = useQueryClient();+ // A controller that stops, starts or is turned off, or a server removed,+ // changes which report there is: read it again at once rather than show+ // the old one until the next poll.+ useEffect(+ () =>+ events.on(embeddedControllerStateChannel, () => {+ void queryClient.invalidateQueries({ queryKey: THIS_COMPUTER_REPORT_KEY });+ }),+ [queryClient]+ );return useQuery<ThisComputerReport | null>({queryKey: THIS_COMPUTER_REPORT_KEY,- queryFn: () => rpc.managedAgents.thisComputerProviders(),+ // The server Console is on now first: controllers on different servers+ // can report differently, and that one is what buddy and the forms use.+ queryFn: () => rpc.managedAgents.thisComputerProviders(switchServersStore.activeServerId),staleTime: 10_000,+ // While the page is open, so a sign-in finished elsewhere, a check still+ // running, or a server signed out of shows up without a refresh; the+ // controller reports on its own about as often.+ refetchInterval: 15_000,retry: false,});}diff --git a/console/packages/agent-providers/src/claude/sign-in.ts b/console/packages/agent-providers/src/claude/sign-in.tsindex ec93b9ff0..83c43d98f 100644--- a/console/packages/agent-providers/src/claude/sign-in.ts+++ b/console/packages/agent-providers/src/claude/sign-in.ts@@ -54,41 +54,76 @@ export async function checkClaudeSignIn(input: SignInCheckInput): Promise<Provid}/**- * What a one-line test prompt says about Claude Code's sign-in.+ * What a one-line test prompt says about Claude Code's sign-in, from what it+ * printed on stdout and on stderr.** `claude auth status` only says a login or key is there, not that it works:* a key left by an old install, or one revoked since, reads as signed in while* every session it starts fails. Asking for one short reply is the check that* the agent's own sessions will get answers.*/-export function parseClaudeTestReply(output: string): ProviderReadiness {+export function parseClaudeTestReply(output: string, stderr = ''): ProviderReadiness {let parsed: unknown;try {parsed = JSON.parse(output.trim().split('\n').at(-1) ?? '');} catch {- return readiness('unknown', CLAUDE_TOO_OLD);+ return withoutReply(stderr);}const value = z- .object({ is_error: z.boolean(), result: z.string().optional() })+ .object({+ is_error: z.boolean(),+ result: z.string().optional(),+ errors: z.array(z.unknown()).optional(),+ }).safeParse(parsed);- if (!value.success) return readiness('unknown', CLAUDE_TOO_OLD);+ if (!value.success) return withoutReply(stderr);if (!value.data.is_error)return readiness('authenticated', 'Signed in, and answered a test prompt.');- const said = value.data.result?.trim();+ // Claude puts what went wrong in `result`, or, for some failures and older+ // versions, only in `errors`, as the Claude adapter also reads it.+ const said =+ value.data.result?.trim() ||+ (value.data.errors ?? [])+ .filter((error): error is string => typeof error === 'string')+ .join('; ')+ .trim();return readiness('unauthenticated',`Claude Code is signed in but could not answer a test prompt${said ? ` ("${said.slice(0, 200)}")` : ''}. ${signInWith(CLAUDE_LOGIN)}`);}+/**+ * No JSON answer: a Claude Code too old for the test prompt's options says so+ * on stderr ("unknown option"), and any other failure is shown as Claude+ * worded it rather than guessed at. Not a sign-out either way: the login may+ * well work.+ */+function withoutReply(stderr: string): ProviderReadiness {+ const said = stderr.trim().split('\n').filter(Boolean).at(-1)?.trim() ?? '';+ if (!said || /unknown option|unknown argument/i.test(said))+ return readiness('unknown', CLAUDE_TOO_OLD);+ return readiness(+ 'unknown',+ `Claude Code could not answer a test prompt ("${said.slice(0, 200)}").`+ );+}++/** How long the test prompt may take: well inside the minute and a half a Console recheck waits. */+export const CLAUDE_TEST_PROMPT_TIMEOUT_MS = 30_000;+/*** Sends Claude Code one short prompt, as an agent session would, with no- * tools, no MCP servers and nothing saved, and reads whether it answered.- * Costs one small request, so it is for setting up and rechecks asked for,- * not for every periodic check.+ * tools, no MCP servers, no hooks and nothing saved, and reads whether it+ * answered. The person's settings still load, so the login and any key or+ * provider they configure are what is tried; only hooks are turned off, since+ * theirs could run commands, block, or make calls of their own. Costs one+ * small request, so it is for setting up and rechecks asked for, not for+ * every periodic check.*/export async function verifyClaudeSignIn(input: SignInCheckInput): Promise<ProviderReadiness> {let output: string;+ let stderr = '';try {output = (await execProvider(@@ -104,14 +139,23 @@ export async function verifyClaudeSignIn(input: SignInCheckInput): Promise<Provi'','--strict-mcp-config','--no-session-persistence',+ '--settings',+ '{"disableAllHooks":true}',],- { cwd: input.cwd, env: input.env, timeout: 60_000, maxBuffer: 1024 * 1024 }+ {+ cwd: input.cwd,+ env: input.env,+ timeout: CLAUDE_TEST_PROMPT_TIMEOUT_MS,+ maxBuffer: 1024 * 1024,+ })).stdout;} catch (error) {if ((error as { killed?: boolean }).killed)- return readiness('unknown', 'Claude Code did not answer a test prompt within a minute.');+ return readiness('unknown', 'Claude Code did not answer a test prompt within 30 seconds.');output = commandOutput(error);+ const errorStderr = (error as { stderr?: unknown }).stderr;+ if (typeof errorStderr === 'string') stderr = errorStderr;}- return parseClaudeTestReply(output);+ return parseClaudeTestReply(output, stderr);}diff --git a/console/packages/agent-providers/src/host/provider-readiness.test.ts b/console/packages/agent-providers/src/host/provider-readiness.test.tsindex 986ca013c..30d29a5ab 100644--- a/console/packages/agent-providers/src/host/provider-readiness.test.ts+++ b/console/packages/agent-providers/src/host/provider-readiness.test.ts@@ -43,6 +43,28 @@ describe('provider authentication', () => {expect(answer.status).toBe('unauthenticated');expect(answer.message).toContain('Invalid API key');});+ it('reads what went wrong from `errors` when the result does not say', () => {+ const answer = parseClaudeTestReply(+ '{"type":"result","subtype":"error_during_execution","is_error":true,"errors":["API Error: 401 OAuth token has expired"]}'+ );+ expect(answer.status).toBe('unauthenticated');+ expect(answer.message).toContain('OAuth token has expired');+ });+ it('shows a failure Claude only wrote to stderr, without calling it too old', () => {+ const answer = parseClaudeTestReply('', 'Error: Could not load credentials from keychain\n');+ expect(answer).toEqual({+ status: 'unknown',+ message:+ 'Claude Code could not answer a test prompt ("Error: Could not load credentials from keychain").',+ models: [],+ });+ });+ it('takes a test prompt with options Claude does not know as Claude being too old', () => {+ expect(+ parseClaudeTestReply('', "error: unknown option '--no-session-persistence'").message+ ).toBe(CLAUDE_TOO_OLD);+ expect(parseClaudeTestReply('', '').message).toBe(CLAUDE_TOO_OLD);+ });it('accepts native API-key authentication', () => {expect(parseClaudeAuthStatus('{"loggedIn":true,"authMethod":"api-key"}').status).toBe('authenticated'diff --git a/console/packages/agent-providers/src/provider-process.test.ts b/console/packages/agent-providers/src/provider-process.test.tsindex 9681d76dd..c3d92ffc0 100644--- a/console/packages/agent-providers/src/provider-process.test.ts+++ b/console/packages/agent-providers/src/provider-process.test.ts@@ -42,6 +42,17 @@ function writeCmdCli(name: string, script: string): string {return join(dir, `${name}.cmd`);}+describe('execProvider', () => {+ it('closes the CLI’s stdin, so one that reads it to the end does not wait forever', async () => {+ const { stdout } = await execProvider(+ process.execPath,+ ['-e', "process.stdin.resume(); process.stdin.on('end', () => console.log('ended'))"],+ { timeout: 5000 }+ );+ expect(stdout.trim()).toBe('ended');+ });+});+describe.runIf(process.platform === 'win32')('on Windows', () => {it('finds a .cmd CLI by its bare name, and not npm’s extensionless shell script', async () => {writeFileSync(join(dir, 'tool'), '#!/bin/sh\n');diff --git a/console/packages/agent-providers/src/provider-process.ts b/console/packages/agent-providers/src/provider-process.tsindex 7e26124af..af070e67f 100644--- a/console/packages/agent-providers/src/provider-process.ts+++ b/console/packages/agent-providers/src/provider-process.ts@@ -53,12 +53,17 @@ export function execProvider(options: ExecFileOptions): Promise<{ stdout: string; stderr: string }> {const target = resolved(command, args, options.env);- return promisify(execFile)(target.command, target.args, {+ const run = promisify(execFile)(target.command, target.args, {...options,encoding: 'utf8',windowsHide: true,windowsVerbatimArguments: target.windowsVerbatimArguments,- }) as Promise<{ stdout: string; stderr: string }>;+ });+ // Nothing is ever written to it, and a CLI that reads stdin when it is not+ // a terminal (`claude -p` does) would otherwise wait for an end that never+ // comes: closed, it reads nothing and goes on at once.+ run.child.stdin?.end();+ return run as Promise<{ stdout: string; stderr: string }>;}/**