Improve Codex startup prompt reliability (#5686)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -902,6 +902,7 @@ type RuntimePtyController = {
|
||||
rows: number
|
||||
cwd?: string
|
||||
command?: string
|
||||
startupCommandDelivery?: WorktreeStartupLaunch['startupCommandDelivery']
|
||||
env?: Record<string, string>
|
||||
envToDelete?: string[]
|
||||
telemetry?: WorktreeStartupLaunch['telemetry']
|
||||
@@ -3161,6 +3162,7 @@ export class OrcaRuntimeService {
|
||||
true,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
{
|
||||
tabId: tab.parentTabId,
|
||||
leafId: tab.leafId,
|
||||
@@ -9923,6 +9925,9 @@ export class OrcaRuntimeService {
|
||||
agent,
|
||||
startup: {
|
||||
command: draftLaunchPlan.launchCommand,
|
||||
...(draftLaunchPlan.startupCommandDelivery
|
||||
? { startupCommandDelivery: draftLaunchPlan.startupCommandDelivery }
|
||||
: {}),
|
||||
...(draftLaunchPlan.env ? { env: draftLaunchPlan.env } : {})
|
||||
}
|
||||
}
|
||||
@@ -9944,6 +9949,9 @@ export class OrcaRuntimeService {
|
||||
agent,
|
||||
startup: {
|
||||
command: startupPlan.launchCommand,
|
||||
...(startupPlan.startupCommandDelivery
|
||||
? { startupCommandDelivery: startupPlan.startupCommandDelivery }
|
||||
: {}),
|
||||
...(startupPlan.env ? { env: startupPlan.env } : {})
|
||||
},
|
||||
draftPaste: { agent, content }
|
||||
@@ -9981,6 +9989,9 @@ export class OrcaRuntimeService {
|
||||
agent,
|
||||
startup: {
|
||||
command: startupPlan.launchCommand,
|
||||
...(startupPlan.startupCommandDelivery
|
||||
? { startupCommandDelivery: startupPlan.startupCommandDelivery }
|
||||
: {}),
|
||||
...(startupPlan.env ? { env: startupPlan.env } : {})
|
||||
},
|
||||
...(startupPlan.followupPrompt
|
||||
@@ -10400,6 +10411,7 @@ export class OrcaRuntimeService {
|
||||
const terminal = await this.createTerminal(`id:${worktree.id}`, {
|
||||
command: effectiveStartup.command,
|
||||
env: effectiveStartup.env,
|
||||
startupCommandDelivery: effectiveStartup.startupCommandDelivery,
|
||||
telemetry: effectiveStartup.telemetry
|
||||
})
|
||||
if (effectiveDraftPaste) {
|
||||
@@ -10981,6 +10993,7 @@ export class OrcaRuntimeService {
|
||||
const terminal = await this.createTerminal(`id:${worktree.id}`, {
|
||||
command: effectiveStartup.command,
|
||||
env: effectiveStartup.env,
|
||||
startupCommandDelivery: effectiveStartup.startupCommandDelivery,
|
||||
telemetry: effectiveStartup.telemetry
|
||||
})
|
||||
if (effectiveDraftPaste) {
|
||||
@@ -11237,6 +11250,7 @@ export class OrcaRuntimeService {
|
||||
const terminal = await this.createTerminal(`path:${result.worktree.path}`, {
|
||||
command: args.startup.command,
|
||||
env: args.startup.env,
|
||||
startupCommandDelivery: args.startup.startupCommandDelivery,
|
||||
telemetry: args.startup.telemetry
|
||||
})
|
||||
if (args.startupDraftPaste) {
|
||||
@@ -12765,6 +12779,7 @@ export class OrcaRuntimeService {
|
||||
opts: {
|
||||
command?: string
|
||||
env?: Record<string, string>
|
||||
startupCommandDelivery?: WorktreeStartupLaunch['startupCommandDelivery']
|
||||
telemetry?: WorktreeStartupLaunch['telemetry']
|
||||
title?: string
|
||||
focus?: boolean
|
||||
@@ -12842,6 +12857,7 @@ export class OrcaRuntimeService {
|
||||
rows: 40,
|
||||
cwd: workspace.path,
|
||||
command: agentTeamsPlan?.command ?? opts.command,
|
||||
startupCommandDelivery: opts.startupCommandDelivery,
|
||||
env,
|
||||
envToDelete: agentTeamsPlan?.envToDelete,
|
||||
telemetry: opts.telemetry,
|
||||
@@ -12938,6 +12954,7 @@ export class OrcaRuntimeService {
|
||||
requestId,
|
||||
worktreeId,
|
||||
command: opts.command,
|
||||
startupCommandDelivery: opts.startupCommandDelivery,
|
||||
title: opts.title,
|
||||
activate: opts.focus === true || opts.activate === true
|
||||
})
|
||||
@@ -12974,6 +12991,7 @@ export class OrcaRuntimeService {
|
||||
return await this.createTerminal(`id:${worktree.id}`, {
|
||||
command: startup.startup.command,
|
||||
env: startup.startup.env,
|
||||
startupCommandDelivery: startup.startup.startupCommandDelivery,
|
||||
telemetry: startup.startup.telemetry,
|
||||
title: opts.title
|
||||
})
|
||||
@@ -12985,6 +13003,7 @@ export class OrcaRuntimeService {
|
||||
afterTabId?: string
|
||||
targetGroupId?: string
|
||||
command?: string
|
||||
startupCommandDelivery?: WorktreeStartupLaunch['startupCommandDelivery']
|
||||
agent?: TuiAgent
|
||||
activate?: boolean
|
||||
} = {}
|
||||
@@ -13011,6 +13030,7 @@ export class OrcaRuntimeService {
|
||||
opts.activate !== false,
|
||||
opts.afterTabId,
|
||||
command,
|
||||
opts.startupCommandDelivery,
|
||||
undefined,
|
||||
opts.agent
|
||||
)
|
||||
@@ -13044,6 +13064,7 @@ export class OrcaRuntimeService {
|
||||
afterTabId: afterDesktopTabId,
|
||||
targetGroupId: opts.targetGroupId,
|
||||
command,
|
||||
startupCommandDelivery: opts.startupCommandDelivery,
|
||||
activate: opts.activate
|
||||
})
|
||||
})
|
||||
@@ -13100,6 +13121,7 @@ export class OrcaRuntimeService {
|
||||
activate: boolean,
|
||||
afterTabId?: string,
|
||||
command?: string,
|
||||
startupCommandDelivery?: WorktreeStartupLaunch['startupCommandDelivery'],
|
||||
identity?: { tabId: string; leafId: string; sessionId?: string },
|
||||
launchAgent?: TuiAgent
|
||||
): Promise<RuntimeMobileSessionCreateTerminalResult> {
|
||||
@@ -13111,6 +13133,7 @@ export class OrcaRuntimeService {
|
||||
const terminal = await this.createTerminal(`id:${worktreeId}`, {
|
||||
focus: false,
|
||||
command,
|
||||
startupCommandDelivery,
|
||||
...(identity
|
||||
? {
|
||||
tabId: identity.tabId,
|
||||
|
||||
@@ -119,6 +119,7 @@ describe('session tab RPC methods', () => {
|
||||
afterTabId: undefined,
|
||||
targetGroupId: 'group-left',
|
||||
command: 'zsh',
|
||||
startupCommandDelivery: undefined,
|
||||
agent: undefined,
|
||||
activate: true
|
||||
})
|
||||
@@ -156,11 +157,51 @@ describe('session tab RPC methods', () => {
|
||||
afterTabId: undefined,
|
||||
targetGroupId: undefined,
|
||||
command: undefined,
|
||||
startupCommandDelivery: undefined,
|
||||
agent: 'codex',
|
||||
activate: undefined
|
||||
})
|
||||
})
|
||||
|
||||
it('dispatches terminal creation with startup command delivery metadata', async () => {
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'test-runtime',
|
||||
createMobileSessionTerminal: vi.fn().mockResolvedValue({
|
||||
tab: {
|
||||
type: 'terminal',
|
||||
id: 'tab-1::leaf-1',
|
||||
parentTabId: 'tab-1',
|
||||
leafId: 'leaf-1',
|
||||
title: 'Terminal',
|
||||
status: 'ready',
|
||||
terminal: 'pty-1',
|
||||
isActive: true
|
||||
},
|
||||
publicationEpoch: 'epoch-1',
|
||||
snapshotVersion: 1
|
||||
})
|
||||
} as unknown as OrcaRuntimeService
|
||||
const dispatcher = new RpcDispatcher({ runtime, methods: SESSION_TAB_METHODS })
|
||||
|
||||
const response = await dispatcher.dispatch(
|
||||
makeRequest('session.tabs.createTerminal', {
|
||||
worktree: 'id:wt-1',
|
||||
command: "codex 'linked issue context'",
|
||||
startupCommandDelivery: 'shell-ready'
|
||||
})
|
||||
)
|
||||
|
||||
expect(response.ok).toBe(true)
|
||||
expect(runtime.createMobileSessionTerminal).toHaveBeenCalledWith('id:wt-1', {
|
||||
afterTabId: undefined,
|
||||
targetGroupId: undefined,
|
||||
command: "codex 'linked issue context'",
|
||||
startupCommandDelivery: 'shell-ready',
|
||||
agent: undefined,
|
||||
activate: undefined
|
||||
})
|
||||
})
|
||||
|
||||
it('rejects unknown agent presets without creating a terminal', async () => {
|
||||
const runtime = {
|
||||
getRuntimeId: () => 'test-runtime',
|
||||
|
||||
@@ -26,6 +26,7 @@ const CreateTerminalTab = WorktreeTabSelector.extend({
|
||||
afterTabId: z.string().optional(),
|
||||
targetGroupId: z.string().optional(),
|
||||
command: z.string().optional(),
|
||||
startupCommandDelivery: z.enum(['fast', 'shell-ready']).optional(),
|
||||
agent: z
|
||||
.custom<TuiAgent>(isTuiAgent, {
|
||||
message: 'Unknown agent preset'
|
||||
@@ -111,6 +112,7 @@ export const SESSION_TAB_METHODS: RpcAnyMethod[] = [
|
||||
afterTabId: params.afterTabId,
|
||||
targetGroupId: params.targetGroupId,
|
||||
command: params.command,
|
||||
startupCommandDelivery: params.startupCommandDelivery,
|
||||
agent: params.agent,
|
||||
activate: params.activate
|
||||
})
|
||||
|
||||
@@ -507,6 +507,7 @@ const TerminalWait = TerminalHandle.extend({
|
||||
const TerminalCreateParams = z.object({
|
||||
worktree: OptionalString,
|
||||
command: OptionalString,
|
||||
startupCommandDelivery: z.enum(['fast', 'shell-ready']).optional(),
|
||||
env: z.record(z.string(), z.string()).optional(),
|
||||
title: OptionalString,
|
||||
focus: z.unknown().optional(),
|
||||
@@ -774,6 +775,7 @@ export const TERMINAL_METHODS: RpcAnyMethod[] = [
|
||||
handler: async (params, { runtime }) => ({
|
||||
terminal: await runtime.createTerminal(params.worktree, {
|
||||
command: params.command,
|
||||
startupCommandDelivery: params.startupCommandDelivery,
|
||||
env: params.env,
|
||||
title: params.title,
|
||||
focus: params.focus === true,
|
||||
|
||||
@@ -118,6 +118,7 @@ export const WorktreeCreate = z
|
||||
// terminal pane launches the selected agent instead of an idle shell.
|
||||
startupCommand: OptionalString,
|
||||
startupEnv: z.record(z.string(), z.string()).optional(),
|
||||
startupCommandDelivery: z.enum(['fast', 'shell-ready']).optional(),
|
||||
// Why: CLI clients should not hardcode agent launch quoting because SSH
|
||||
// workspaces execute in a different shell than the client process.
|
||||
startupAgent: OptionalTuiAgent,
|
||||
|
||||
@@ -83,6 +83,7 @@ describe('worktree RPC methods', () => {
|
||||
repo: 'repo-1',
|
||||
name: 'agent-startup',
|
||||
startupCommand: "codex 'summarize repo'",
|
||||
startupCommandDelivery: 'shell-ready',
|
||||
startupEnv: { ORCA_AGENT_MODE: 'direct' },
|
||||
activate: true
|
||||
})
|
||||
@@ -95,6 +96,7 @@ describe('worktree RPC methods', () => {
|
||||
activate: true,
|
||||
startup: {
|
||||
command: "codex 'summarize repo'",
|
||||
startupCommandDelivery: 'shell-ready',
|
||||
env: { ORCA_AGENT_MODE: 'direct' }
|
||||
}
|
||||
})
|
||||
|
||||
@@ -89,7 +89,10 @@ export const WORKTREE_METHODS: RpcMethod[] = [
|
||||
startup: params.startupCommand
|
||||
? {
|
||||
command: params.startupCommand,
|
||||
...(params.startupEnv ? { env: params.startupEnv } : {})
|
||||
...(params.startupEnv ? { env: params.startupEnv } : {}),
|
||||
...(params.startupCommandDelivery
|
||||
? { startupCommandDelivery: params.startupCommandDelivery }
|
||||
: {})
|
||||
}
|
||||
: undefined,
|
||||
...(params.startupAgent ? { startupAgent: params.startupAgent } : {}),
|
||||
|
||||
Reference in New Issue
Block a user