diff --git a/src/main/pi/titlebar-extension-service.ts b/src/main/pi/titlebar-extension-service.ts index 845a987cd..36d508778 100644 --- a/src/main/pi/titlebar-extension-service.ts +++ b/src/main/pi/titlebar-extension-service.ts @@ -44,10 +44,10 @@ function getPiPrefillExtensionSource(): string { return [ 'export default function (pi) {', " pi.on('session_start', async (event, ctx) => {", + " if (event.reason !== 'startup') return", ` const prefill = process.env.${ORCA_PI_PREFILL_ENV_VAR}`, ' if (!prefill) return', ` delete process.env.${ORCA_PI_PREFILL_ENV_VAR}`, - " if (event.reason !== 'startup') return", ' try {', ' ctx.ui.setEditorText(prefill)', ' } catch {}', diff --git a/src/renderer/src/lib/tui-agent-startup.test.ts b/src/renderer/src/lib/tui-agent-startup.test.ts index a3e411935..1adc0dd4a 100644 --- a/src/renderer/src/lib/tui-agent-startup.test.ts +++ b/src/renderer/src/lib/tui-agent-startup.test.ts @@ -188,7 +188,7 @@ describe('buildAgentDraftLaunchPlan', () => { }) ).toEqual({ agent: 'pi', - launchCommand: 'pi', + launchCommand: 'pi; unset ORCA_PI_PREFILL', expectedProcess: 'pi', env: { ORCA_PI_PREFILL: 'https://github.com/acme/repo/issues/42' } }) diff --git a/src/renderer/src/lib/tui-agent-startup.ts b/src/renderer/src/lib/tui-agent-startup.ts index 12226de49..65964af5e 100644 --- a/src/renderer/src/lib/tui-agent-startup.ts +++ b/src/renderer/src/lib/tui-agent-startup.ts @@ -153,9 +153,16 @@ export function buildAgentDraftLaunchPlan(args: { // Why: the env var is set on the PTY-spawn env (not embedded in the // shell command) so the value never has to be shell-escaped and the // user doesn't see a `FOO='...'` prefix typed into their terminal. + // Append a clear-var command so the var is unset from the shell env + // once the agent exits — otherwise re-running the agent in the same + // terminal would inherit the stale value and re-prefill with the old URL. + const clearVar = + platform === 'win32' + ? `set "${config.draftPromptEnvVar}="` + : `unset ${config.draftPromptEnvVar}` return { agent, - launchCommand: baseCommand, + launchCommand: `${baseCommand}; ${clearVar}`, expectedProcess: config.expectedProcess, env: { [config.draftPromptEnvVar]: trimmed } }