Skip to content
Open
5 changes: 2 additions & 3 deletions config/patches/@xterm__addon-webgl@0.20.0-beta.219.patch
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ index 46b8efe..4b36a78 100644
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, atlas.pages[i].canvas);
- gl.generateMipmap(gl.TEXTURE_2D);
this._atlasTextures[i].version = atlas.pages[i].version;
}

this._atlasTextures[i].version = atlas.pages[i].version;
}
1 change: 1 addition & 0 deletions src/main/codex-accounts/runtime-home-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function createSettings(overrides: Partial<GlobalSettings> = {}): GlobalSettings
opencodeWorkspaceId: '',
geminiCliOAuthEnabled: false,
agentCmdOverrides: {},
customTuiAgents: [],
keepComputerAwakeWhileAgentsRun: false,
terminalMacOptionAsAlt: 'false',
terminalMacOptionAsAltMigrated: true,
Expand Down
1 change: 1 addition & 0 deletions src/main/codex-accounts/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ function createSettings(overrides: Partial<GlobalSettings> = {}): GlobalSettings
opencodeWorkspaceId: '',
geminiCliOAuthEnabled: false,
agentCmdOverrides: {},
customTuiAgents: [],
keepComputerAwakeWhileAgentsRun: false,
terminalMacOptionAsAlt: 'false',
terminalMacOptionAsAltMigrated: true,
Expand Down
46 changes: 38 additions & 8 deletions src/main/ipc/preflight.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ type HandlerMap = Record<
) => Promise<unknown>
>

// Why: preflight handlers read customTuiAgents from the Store at call time
// (issue #2284). Tests don't exercise persistence, so a minimal stub that
// returns no customs is all we need.
const fakeStore = {
getSettings: () => ({ customTuiAgents: [] })
} as unknown as Parameters<typeof registerPreflightHandlers>[0]

describe('preflight', () => {
const originalPlatform = process.platform
const handlers: HandlerMap = {}
Expand Down Expand Up @@ -277,7 +284,7 @@ describe('preflight', () => {
.mockResolvedValueOnce({ stdout: 'github.com\n' })
.mockResolvedValueOnce({ stdout: 'Logged in to gitlab.com\n' })

registerPreflightHandlers()
registerPreflightHandlers(fakeStore)

const status = await handlers['preflight:check']()

Expand All @@ -304,7 +311,7 @@ describe('preflight', () => {
.mockResolvedValueOnce({ stdout: 'github.com\n - Active account: true\n' })
.mockResolvedValueOnce({ stdout: 'Logged in to gitlab.com\n' })

registerPreflightHandlers()
registerPreflightHandlers(fakeStore)

const firstStatus = await handlers['preflight:check']()
const refreshedStatus = await handlers['preflight:check'](null, { force: true })
Expand Down Expand Up @@ -346,7 +353,30 @@ describe('preflight', () => {
throw new Error('not found')
})

await expect(detectInstalledAgents()).resolves.toEqual(['claude', 'cursor'])
await expect(detectInstalledAgents([])).resolves.toEqual(['claude', 'cursor'])
})

it('includes a custom agent id when its detect command resolves on PATH', async () => {
execFileAsyncMock.mockImplementation(async (command, args) => {
if (command !== 'which') {
throw new Error(`unexpected command ${String(command)}`)
}
if (String(args[0]) === 'my-wrapper') {
return { stdout: '/usr/local/bin/my-wrapper\n' }
}
throw new Error('not found')
})

await expect(
detectInstalledAgents([
{
id: 'custom:my-wrapper-abc123',
label: 'My Wrapper',
command: 'my-wrapper --beta',
promptInjectionMode: 'stdin-after-start'
}
])
).resolves.toEqual(['custom:my-wrapper-abc123'])
})

it('registers agent detection through the shared launch config commands', async () => {
Expand All @@ -360,7 +390,7 @@ describe('preflight', () => {
throw new Error('not found')
})

registerPreflightHandlers()
registerPreflightHandlers(fakeStore)

await expect(handlers['preflight:detectAgents']()).resolves.toEqual(['cursor'])
})
Expand All @@ -384,7 +414,7 @@ describe('preflight', () => {
throw new Error('not found')
})

await expect(detectInstalledAgents({ wslDistro: 'Ubuntu' })).resolves.toEqual(['claude'])
await expect(detectInstalledAgents([], { wslDistro: 'Ubuntu' })).resolves.toEqual(['claude'])
})

it('detects agents from the default WSL distro when requested', async () => {
Expand Down Expand Up @@ -431,7 +461,7 @@ describe('preflight', () => {
throw new Error('not found')
})

registerPreflightHandlers()
registerPreflightHandlers(fakeStore)

const result = (await handlers['preflight:refreshAgents']()) as {
agents: string[]
Expand Down Expand Up @@ -467,7 +497,7 @@ describe('preflight', () => {
throw new Error('not found')
})

registerPreflightHandlers()
registerPreflightHandlers(fakeStore)

const result = (await handlers['preflight:refreshAgents']()) as {
agents: string[]
Expand Down Expand Up @@ -496,7 +526,7 @@ describe('preflight', () => {
hydrateShellPathMock.mockResolvedValueOnce({ segments: [], ok: false, failureReason })
execFileAsyncMock.mockRejectedValue(new Error('not found'))

registerPreflightHandlers()
registerPreflightHandlers(fakeStore)

const result = (await handlers['preflight:refreshAgents']()) as {
pathSource: string
Expand Down
79 changes: 64 additions & 15 deletions src/main/ipc/preflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { execFile } from 'child_process'
import { promisify } from 'util'
import path from 'path'
import { TUI_AGENT_CONFIG } from '../../shared/tui-agent-config'
import type { PathSource, ShellHydrationFailureReason } from '../../shared/types'
import { firstExecutableToken } from '../../shared/effective-tui-agent'
import type { CustomTuiAgent, PathSource, ShellHydrationFailureReason } from '../../shared/types'
import type { Store } from '../persistence'
import { hydrateShellPath, mergePathSegments } from '../startup/hydrate-shell-path'
import { getAzureDevOpsAuthStatus } from '../azure-devops/client'
import { getBitbucketAuthStatus } from '../bitbucket/client'
Expand Down Expand Up @@ -102,11 +104,27 @@ async function isCommandOnPath(command: string, wslTarget?: WslPreflightTarget):
}
}

const KNOWN_AGENT_COMMANDS = Object.entries(TUI_AGENT_CONFIG).map(([id, config]) => ({
const BUILT_IN_AGENT_COMMANDS = Object.entries(TUI_AGENT_CONFIG).map(([id, config]) => ({
id,
cmd: config.detectCmd
}))

// Why: custom agent presets (issue #2284) need to surface in detection so the
// New Workspace / Quick Launch pickers mark them installed when their detect
// command resolves on PATH. Falls back to the executable token of the launch
// command when no explicit detectCmd is set.
function getKnownAgentCommands(
customAgents: readonly CustomTuiAgent[]
): { id: string; cmd: string }[] {
const customs = customAgents
.map((agent) => ({
id: agent.id,
cmd: agent.detectCmd?.trim() || firstExecutableToken(agent.command)
}))
.filter((entry) => entry.cmd.length > 0)
return [...BUILT_IN_AGENT_COMMANDS, ...customs]
}

function getPreflightWslTarget(context?: PreflightRuntimeContext): WslPreflightTarget | null {
if (process.platform !== 'win32') {
return null
Expand Down Expand Up @@ -134,10 +152,31 @@ async function detectCommandRuntime(
return { installed: false }
}

export async function detectInstalledAgents(context?: PreflightRuntimeContext): Promise<string[]> {
const wslTarget = getPreflightWslTarget(context)
function resolveDetectInstalledAgentsArgs(
customAgentsOrContext?: readonly CustomTuiAgent[] | PreflightRuntimeContext,
context?: PreflightRuntimeContext
): { customAgents: readonly CustomTuiAgent[]; context?: PreflightRuntimeContext } {
if (isCustomAgentList(customAgentsOrContext)) {
return { customAgents: customAgentsOrContext, context }
}
return { customAgents: [], context: customAgentsOrContext }
}

function isCustomAgentList(
value: readonly CustomTuiAgent[] | PreflightRuntimeContext | undefined
): value is readonly CustomTuiAgent[] {
return Array.isArray(value)
}

export async function detectInstalledAgents(
customAgentsOrContext?: readonly CustomTuiAgent[] | PreflightRuntimeContext,
context?: PreflightRuntimeContext
): Promise<string[]> {
const resolved = resolveDetectInstalledAgentsArgs(customAgentsOrContext, context)
const wslTarget = getPreflightWslTarget(resolved.context)
const knownCommands = getKnownAgentCommands(resolved.customAgents)
const checks = await Promise.all(
KNOWN_AGENT_COMMANDS.map(async ({ id, cmd }) => ({
knownCommands.map(async ({ id, cmd }) => ({
id,
installed: await isCommandOnPath(cmd, wslTarget ?? undefined)
}))
Expand Down Expand Up @@ -169,11 +208,12 @@ export type RefreshAgentsResult = {
* without requiring an app restart.
*/
export async function refreshShellPathAndDetectAgents(
customAgents: readonly CustomTuiAgent[],
context?: PreflightRuntimeContext
): Promise<RefreshAgentsResult> {
const hydration = await hydrateShellPath({ force: true })
const added = hydration.ok ? mergePathSegments(hydration.segments) : []
const agents = await detectInstalledAgents(context)
const agents = await detectInstalledAgents(customAgents, context)
return {
agents,
addedPathSegments: added,
Expand All @@ -183,13 +223,16 @@ export async function refreshShellPathAndDetectAgents(
}
}

export async function detectRemoteAgents(args: { connectionId: string }): Promise<string[]> {
export async function detectRemoteAgents(args: {
connectionId: string
customAgents: readonly CustomTuiAgent[]
}): Promise<string[]> {
const mux = getActiveMultiplexer(args.connectionId)
if (!mux || mux.isDisposed()) {
throw new Error(`No active SSH connection for "${args.connectionId}"`)
}
const result = (await mux.request('preflight.detectAgents', {
commands: KNOWN_AGENT_COMMANDS
commands: getKnownAgentCommands(args.customAgents)
})) as { agents: string[] }
return result.agents
}
Expand Down Expand Up @@ -280,7 +323,12 @@ export async function runPreflightCheck(
return result
}

export function registerPreflightHandlers(): void {
export function registerPreflightHandlers(store: Store): void {
// Why: custom agent presets (issue #2284) live in settings, so detection
// handlers read them at call time. Passing the Store keeps the IPC contract
// unchanged while giving every handler the freshest custom list.
const getCustomAgents = (): readonly CustomTuiAgent[] => store.getSettings().customTuiAgents ?? []

ipcMain.handle(
'preflight:check',
async (
Expand All @@ -294,22 +342,23 @@ export function registerPreflightHandlers(): void {
ipcMain.handle(
'preflight:detectAgents',
async (_event, args?: PreflightRuntimeContext): Promise<string[]> => {
return detectInstalledAgents(args)
return detectInstalledAgents(getCustomAgents(), args)
}
)

ipcMain.handle('preflight:refreshAgents', async (_event, args?: PreflightRuntimeContext) => {
return refreshShellPathAndDetectAgents(args)
return refreshShellPathAndDetectAgents(getCustomAgents(), args)
})

// Why: remote worktrees need agent detection on the SSH host, not the local
// machine. This handler forwards the same KNOWN_AGENT_COMMANDS list to the
// relay's preflight.detectAgents RPC, which runs `which` inside a login shell
// on the remote host to match the PATH users see in PTY sessions.
// machine. This handler forwards the same agent command list to the relay's
// preflight.detectAgents RPC, which runs `which` inside a login shell on the
// remote host to match the PATH users see in PTY sessions. Custom agents
// flow through the same payload since the relay handler is protocol-agnostic.
ipcMain.handle(
'preflight:detectRemoteAgents',
async (_event, args: { connectionId: string }): Promise<string[]> => {
return detectRemoteAgents(args)
return detectRemoteAgents({ ...args, customAgents: getCustomAgents() })
}
)
}
2 changes: 1 addition & 1 deletion src/main/ipc/register-core-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function registerCoreHandlers(

registerAppHandlers(store, { onBeforeRelaunch: lifecycleOptions.onBeforeRelaunch })
registerCliHandlers()
registerPreflightHandlers()
registerPreflightHandlers(store)
registerClaudeUsageHandlers(claudeUsage)
registerCodexUsageHandlers(codexUsage)
registerOpenCodeUsageHandlers(openCodeUsage)
Expand Down
Loading
Loading