🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(hetero-agent): let Claude Code see claude.ai connectors (#21294)
YuTengjing63690d638e90
diff --git a/apps/desktop/src/main/controllers/HeterogeneousAgentImpl.ts b/apps/desktop/src/main/controllers/HeterogeneousAgentImpl.tsindex 48fd92c03d5..d243384dfa4 100644--- a/apps/desktop/src/main/controllers/HeterogeneousAgentImpl.ts+++ b/apps/desktop/src/main/controllers/HeterogeneousAgentImpl.ts@@ -92,6 +92,7 @@ import {DSH_COMMAND,ensureClaudeCodeResumeTranscript,getCodexAppServerUnsupportedArgs,+ getHeterogeneousAgentPresetEnv,GrokAcpSession,isCursorAcpSessionNotFoundError,isDevinAcpSessionNotFoundError,@@ -1077,9 +1078,7 @@ export default class HeterogeneousAgentCtr {const env: NodeJS.ProcessEnv = {...withEmbeddedCliEnv(inheritedEnv),...proxyEnv,- ...(session.agentType === 'codebuddy'- ? { CODEBUDDY_CODE_DISABLE_BACKGROUND_TASKS: '1' }- : {}),+ ...getHeterogeneousAgentPresetEnv(session.agentType),...session.env,...(includeProcessOwnership? managedProcessEnvironment(diff --git a/apps/desktop/src/main/controllers/__tests__/HeterogeneousAgentCtr.test.ts b/apps/desktop/src/main/controllers/__tests__/HeterogeneousAgentCtr.test.tsindex 73027938543..8d712892252 100644--- a/apps/desktop/src/main/controllers/__tests__/HeterogeneousAgentCtr.test.ts+++ b/apps/desktop/src/main/controllers/__tests__/HeterogeneousAgentCtr.test.ts@@ -1887,14 +1887,14 @@ describe('HeterogeneousAgentCtr', () => {}});- it('disables CodeBuddy background tasks in the spawned environment', async () => {- const { cliArgs, options } = await runSendPrompt('hello', {- agentType: 'codebuddy',- command: 'codebuddy',- });-+ // LOBE-14393: without MCP_CONNECTION_NONBLOCKING the first turn misses claude.ai connectors.+ it.each([+ ['codebuddy', 'codebuddy', 'CODEBUDDY_CODE_DISABLE_BACKGROUND_TASKS', '1'],+ ['claude-code', 'claude', 'MCP_CONNECTION_NONBLOCKING', 'false'],+ ])('applies the %s preset env', async (agentType, command, key, value) => {+ const { cliArgs, options } = await runSendPrompt('hello', { agentType, command });expect(cliArgs).toContain('--include-partial-messages');- expect(options.env.CODEBUDDY_CODE_DISABLE_BACKGROUND_TASKS).toBe('1');+ expect(options.env[key]).toBe(value);});it('passes the selected model to the native CodeBuddy process', async () => {diff --git a/packages/heterogeneous-agents/src/spawn/index.ts b/packages/heterogeneous-agents/src/spawn/index.tsindex ecf6731216f..96750d8fe62 100644--- a/packages/heterogeneous-agents/src/spawn/index.ts+++ b/packages/heterogeneous-agents/src/spawn/index.ts@@ -182,6 +182,7 @@ export {type EnsureResumeTranscriptResult,resolveClaudeCodeTranscriptPath,} from './ensureResumeTranscript';+export { getHeterogeneousAgentPresetEnv } from './presetEnv';export {AMP_BASE_ARGS,buildQoderArgs,diff --git a/packages/heterogeneous-agents/src/spawn/presetEnv.ts b/packages/heterogeneous-agents/src/spawn/presetEnv.tsnew file mode 100644index 00000000000..b6109db48a5--- /dev/null+++ b/packages/heterogeneous-agents/src/spawn/presetEnv.ts@@ -0,0 +1,24 @@+/**+ * Environment variables a host always sets for a heterogeneous agent, shared by+ * every spawn site (desktop CLI/SDK runs, `lh hetero exec`). Hosts apply them+ * over the inherited environment and under the agent's configured `env`, so an+ * explicit per-agent setting still wins.+ */+const HETEROGENEOUS_AGENT_PRESET_ENV: Partial<Record<string, Readonly<Record<string, string>>>> = {+ /**+ * Headless Claude Code (`-p`, also the Agent SDK) starts the first model call+ * without waiting for MCP servers, and claude.ai connectors (Microsoft 365,+ * Gmail, ...) connect last because their list is fetched from claude.ai first.+ * Our runs send the prompt at spawn and usually exit after one turn, so those+ * tools never reach the model. Waiting costs about 1.5s per turn and is+ * capped by `MCP_CONNECT_TIMEOUT_MS` (5s by default) when a server hangs.+ * See https://linear.app/lobehub/issue/LOBE-14393+ */+ 'claude-code': { MCP_CONNECTION_NONBLOCKING: 'false' },+ /** A one-shot print-mode process cannot reliably service background tasks. */+ 'codebuddy': { CODEBUDDY_CODE_DISABLE_BACKGROUND_TASKS: '1' },+};++export const getHeterogeneousAgentPresetEnv = (+ agentType: string,+): Readonly<Record<string, string>> => HETEROGENEOUS_AGENT_PRESET_ENV[agentType] ?? {};diff --git a/packages/heterogeneous-agents/src/spawn/spawnAgent.presetEnv.test.ts b/packages/heterogeneous-agents/src/spawn/spawnAgent.presetEnv.test.tsnew file mode 100644index 00000000000..44fefe6e1bf--- /dev/null+++ b/packages/heterogeneous-agents/src/spawn/spawnAgent.presetEnv.test.ts@@ -0,0 +1,78 @@+import type * as childProcess from 'node:child_process';+import { EventEmitter } from 'node:events';+import type * as os from 'node:os';+import { PassThrough } from 'node:stream';++import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++import { spawnAgent } from './spawnAgent';++const spawnCalls: Array<{ env: NodeJS.ProcessEnv }> = [];++vi.mock('node:child_process', async () => {+ const actual = await vi.importActual<typeof childProcess>('node:child_process');+ return {+ ...actual,+ spawn: vi.fn((_command: string, _args: string[], options: { env: NodeJS.ProcessEnv }) => {+ spawnCalls.push({ env: options.env });+ const proc = new EventEmitter() as any;+ proc.stdin = { end: vi.fn(), once: vi.fn(), write: vi.fn(() => true) };+ proc.stdout = new PassThrough();+ proc.stderr = new PassThrough();+ proc.kill = vi.fn();+ proc.pid = 4321;+ return proc;+ }),+ };+});++vi.mock('node:os', async () => {+ const actual = await vi.importActual<typeof os>('node:os');+ return { ...actual, platform: vi.fn(() => 'linux') };+});++const spawnClaudeCode = async (env?: Record<string, string>) => {+ const handle = await spawnAgent({+ agentType: 'claude-code',+ env,+ operationId: 'op-preset-env',+ prompt: 'hello',+ });+ handle.kill();+ return spawnCalls.at(-1)!.env;+};++describe('spawnAgent preset env', () => {+ beforeEach(() => {+ spawnCalls.length = 0;+ });++ afterEach(() => {+ vi.unstubAllEnvs();+ });++ // LOBE-14393: claude.ai connectors finish connecting after the first model call.+ it('makes Claude Code wait for MCP servers before its first turn', async () => {+ vi.stubEnv('MCP_CONNECTION_NONBLOCKING', undefined);++ const env = await spawnClaudeCode();++ expect(env.MCP_CONNECTION_NONBLOCKING).toBe('false');+ });++ it('lets an agent-configured env override the preset', async () => {+ const env = await spawnClaudeCode({ MCP_CONNECTION_NONBLOCKING: 'true' });++ expect(env.MCP_CONNECTION_NONBLOCKING).toBe('true');+ });++ it('does not apply the Claude Code preset to other agents', async () => {+ vi.stubEnv('MCP_CONNECTION_NONBLOCKING', undefined);++ const handle = await spawnAgent({ agentType: 'codebuddy', operationId: 'op-cb', prompt: 'hi' });+ handle.kill();++ expect(spawnCalls.at(-1)!.env.MCP_CONNECTION_NONBLOCKING).toBeUndefined();+ expect(spawnCalls.at(-1)!.env.CODEBUDDY_CODE_DISABLE_BACKGROUND_TASKS).toBe('1');+ });+});diff --git a/packages/heterogeneous-agents/src/spawn/spawnAgent.ts b/packages/heterogeneous-agents/src/spawn/spawnAgent.tsindex 57b532c99e1..64d09ceb6c5 100644--- a/packages/heterogeneous-agents/src/spawn/spawnAgent.ts+++ b/packages/heterogeneous-agents/src/spawn/spawnAgent.ts@@ -26,6 +26,7 @@ import {} from './codexShellEnv';import type { AgentPromptInput, BuildAgentInputOptions } from './input';import { buildAgentInput } from './input';+import { getHeterogeneousAgentPresetEnv } from './presetEnv';import { assertSpawnableWorkingDirectory } from './workingDirectory';export interface SpawnAgentOptions {@@ -481,7 +482,7 @@ export const spawnAgent = async (options: SpawnAgentOptions): Promise<SpawnAgentconst inputPlan = await buildAgentInput(options.agentType, options.prompt, options.inputOptions);const childEnv: NodeJS.ProcessEnv = {...process.env,- ...(options.agentType === 'codebuddy' ? { CODEBUDDY_CODE_DISABLE_BACKGROUND_TASKS: '1' } : {}),+ ...getHeterogeneousAgentPresetEnv(options.agentType),...options.env,};// Codex builds each shell command's env from `[shell_environment_policy]`,