From 747424d950fd47a86bed2ebda6b8ff761f13de8d Mon Sep 17 00:00:00 2001 From: Drakontia Date: Sun, 19 Apr 2026 03:07:48 +0900 Subject: [PATCH] fix: use -i flag for GitHub Copilot CLI prompt injection (#799) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../src/components/settings/general-search.ts | 2 +- src/renderer/src/lib/agent-catalog.tsx | 7 +++++++ .../src/lib/tui-agent-startup.test.ts | 19 +++++++++++++++++-- src/renderer/src/lib/tui-agent-startup.ts | 8 ++++++++ src/shared/tui-agent-config.ts | 7 ++++++- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/components/settings/general-search.ts b/src/renderer/src/components/settings/general-search.ts index 89bb1ca350b..a2bf348a721 100644 --- a/src/renderer/src/components/settings/general-search.ts +++ b/src/renderer/src/components/settings/general-search.ts @@ -82,7 +82,7 @@ export const GENERAL_AGENT_SEARCH_ENTRIES: SettingsSearchEntry[] = [ { title: 'Default Agent', description: 'Pre-select an AI coding agent in the new-workspace composer.', - keywords: ['agent', 'default', 'claude', 'codex', 'opencode', 'pi', 'gemini', 'aider'] + keywords: ['agent', 'default', 'claude', 'codex', 'opencode', 'pi', 'gemini', 'aider', 'copilot'] } ] diff --git a/src/renderer/src/lib/agent-catalog.tsx b/src/renderer/src/lib/agent-catalog.tsx index 6a386f91d43..4e041519d9f 100644 --- a/src/renderer/src/lib/agent-catalog.tsx +++ b/src/renderer/src/lib/agent-catalog.tsx @@ -173,6 +173,13 @@ export const AGENT_CATALOG: AgentCatalogEntry[] = [ cmd: 'hermes', faviconDomain: 'nousresearch.com', homepageUrl: 'https://hermes-agent.nousresearch.com/docs/' + }, + { + id: 'copilot', + label: 'GitHub Copilot', + cmd: 'copilot', + faviconDomain: 'github.com', + homepageUrl: 'https://docs.github.com/en/copilot/how-tos/set-up/install-copilot-cli' } ] diff --git a/src/renderer/src/lib/tui-agent-startup.test.ts b/src/renderer/src/lib/tui-agent-startup.test.ts index 894e26b6a90..b9fe47e439f 100644 --- a/src/renderer/src/lib/tui-agent-startup.test.ts +++ b/src/renderer/src/lib/tui-agent-startup.test.ts @@ -77,7 +77,7 @@ describe('buildAgentStartupPlan', () => { }) }) - it('passes Copilot prompts with the --prompt flag', () => { + it('passes Copilot prompts with the -i flag for an interactive session', () => { expect( buildAgentStartupPlan({ agent: 'copilot', @@ -86,7 +86,7 @@ describe('buildAgentStartupPlan', () => { platform: 'darwin' }) ).toEqual({ - launchCommand: "copilot --prompt 'Fix the bug'", + launchCommand: "copilot -i 'Fix the bug'", expectedProcess: 'copilot', followupPrompt: null }) @@ -102,6 +102,21 @@ describe('buildAgentStartupPlan', () => { }) ).toBeNull() }) + + it('uses -i flag for copilot to start an interactive session with initial prompt', () => { + expect( + buildAgentStartupPlan({ + agent: 'copilot', + prompt: 'Fix the bug', + cmdOverrides: {}, + platform: 'darwin' + }) + ).toEqual({ + launchCommand: "copilot -i 'Fix the bug'", + expectedProcess: 'copilot', + followupPrompt: null + }) + }) }) describe('isShellProcess', () => { diff --git a/src/renderer/src/lib/tui-agent-startup.ts b/src/renderer/src/lib/tui-agent-startup.ts index 1193956066b..cc5b7b510f4 100644 --- a/src/renderer/src/lib/tui-agent-startup.ts +++ b/src/renderer/src/lib/tui-agent-startup.ts @@ -55,6 +55,14 @@ export function buildAgentStartupPlan(args: { } } + if (config.promptInjectionMode === 'flag-interactive') { + return { + launchCommand: `${baseCommand} -i ${quotedPrompt}`, + expectedProcess: config.expectedProcess, + followupPrompt: null + } + } + return { launchCommand: baseCommand, expectedProcess: config.expectedProcess, diff --git a/src/shared/tui-agent-config.ts b/src/shared/tui-agent-config.ts index 9600da2672c..25e291a7e3d 100644 --- a/src/shared/tui-agent-config.ts +++ b/src/shared/tui-agent-config.ts @@ -4,6 +4,7 @@ export type AgentPromptInjectionMode = | 'argv' | 'flag-prompt' | 'flag-prompt-interactive' + | 'flag-interactive' | 'stdin-after-start' export type TuiAgentConfig = { @@ -156,6 +157,10 @@ export const TUI_AGENT_CONFIG: Record = { detectCmd: 'copilot', launchCmd: 'copilot', expectedProcess: 'copilot', - promptInjectionMode: 'flag-prompt' + // Why: `copilot --prompt ` runs non-interactively and exits on + // completion, which would kill the TUI session Orca is hosting. + // `-i/--interactive ` starts an interactive session with the + // initial prompt pre-executed — the behavior Orca needs. + promptInjectionMode: 'flag-interactive' } }