Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/renderer/src/i18n/en-runtime-required.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/renderer/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18684,6 +18684,8 @@
"agentDisabled": "{{agent}} is disabled in Agent settings.",
"agentUnavailable": "{{agent}} was not detected on this workspace host.",
"sent": "Session context sent to {{agent}} in a new session.",
"openSession": "Open session",
"draftLoaded": "Session context loaded as a draft in the new {{agent}} session. Review it and press Enter to continue.",
"deliveryFailed": "The new {{agent}} session started, but its context could not be sent.",
"deliveryUnconfirmed": "Orca could not confirm {{agent}} received the session context. Check the new session, and paste it yourself if its input is empty.",
"copyPrompt": "Copy prompt",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { expect, it, vi } from 'vitest'
import type { Tab } from '../../../shared/tab-types'
import type { StructuredAgentLaunchHooks } from './structured-agent-launch-settlement'

const mocks = vi.hoisted(() => {
const unifiedTabsByWorktree: Record<string, Tab[]> = {}
return {
store: { unifiedTabsByWorktree },
begin: vi.fn<(args: { hooks: StructuredAgentLaunchHooks }) => null>(() => null)
}
})
vi.mock('@/store', () => ({ useAppStore: { getState: () => mocks.store } }))
vi.mock('@/lib/structured-agent-session-provisional-tab', () => ({
structuredLaunchPairedOwner: () => ({ executionHostId: 'host-1' }),
beginStructuredAgentSessionProvisionalLaunch: mocks.begin
}))

import { adoptAgentSessionLaunchVerdict } from './agent-session-launch-plan'
import { launchStructuredAgentFromNewTab } from './launch-agent-in-new-tab-structured-route'

it('reports the admitted paired session tab, never a sibling or a missing session', () => {
const onCreatedTab = vi.fn()
launchStructuredAgentFromNewTab({
plan: adoptAgentSessionLaunchVerdict({
requestId: 'request-1',
route: 'structured-native-chat',
agent: 'codex',
worktreeId: 'wt-1',
prompt: 'continue',
promptDelivery: 'auto-submit'
}),
worktreeId: 'wt-1',
onCreatedTab,
openTerminal: () => null
})
const hook = mocks.begin.mock.calls[0][0].hooks.onStructuredReady
const tab: Tab = {
id: 'exact-tab',
entityId: 'session-1',
contentType: 'agent-session',
worktreeId: 'wt-1',
groupId: 'group-1',
label: 'Codex',
customLabel: null,
color: null,
sortOrder: 0,
createdAt: 0
}
mocks.store.unifiedTabsByWorktree = {
'wt-1': [tab],
'wt-other': [{ ...tab, id: 'sibling', worktreeId: 'wt-other' }]
}
hook?.('session-1')
expect(onCreatedTab).toHaveBeenCalledExactlyOnceWith('exact-tab')
hook?.('session-missing')
mocks.store.unifiedTabsByWorktree['wt-1'] = []
hook?.('session-1')
expect(onCreatedTab).toHaveBeenCalledOnce()
})
15 changes: 14 additions & 1 deletion src/renderer/src/lib/launch-agent-in-new-tab-structured-route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useAppStore } from '@/store'
import { findStructuredAgentSessionTab } from './structured-agent-session-tab-activation'
import {
adoptAgentSessionLaunchVerdict,
type AgentSessionLaunchPlan
Expand Down Expand Up @@ -27,6 +29,7 @@ export function launchStructuredAgentFromNewTab(args: {
plan: AgentSessionLaunchPlan
worktreeId: string
groupId?: string
onCreatedTab?: (tabId: string) => void
beforeSurfaceOpen?: LaunchAgentInNewTabArgs['beforeSurfaceOpen']
openTerminal: (terminalPlan: AgentSessionLaunchPlan) => {
promptDeliveryResult?: Promise<StructuredPromptDeliveryResult>
Expand Down Expand Up @@ -66,7 +69,17 @@ export function launchStructuredAgentFromNewTab(args: {
}
const launch = beginStructuredAgentSessionProvisionalLaunch({
plan,
hooks: {},
hooks: {
onStructuredReady: (sessionId) => {
const tab = findStructuredAgentSessionTab(useAppStore.getState().unifiedTabsByWorktree, {
workspaceId: args.worktreeId,
sessionId
})
if (tab) {
args.onCreatedTab?.(tab.id)
}
}
},
target: { worktreeId: args.worktreeId, executionHostId: paired.executionHostId },
...(args.groupId ? { targetGroupId: args.groupId } : {}),
onHostDeclined: () => {
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/src/lib/launch-agent-in-new-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type LaunchAgentInNewTabArgs = LaunchAgentInNewTabRequest & {
launchPlatform?: NodeJS.Platform
/** Called after the prompt is actually delivered to the agent input path. */
onPromptDelivered?: () => void
onCreatedTab?: (tabId: string) => void
/**
* Called before `onPromptDelivered` when the paste was written without ever observing the
* agent's composer, so the launch cannot claim the prompt arrived. Fires only on the
Expand Down Expand Up @@ -197,6 +198,7 @@ function launchAgentInNewTabInternal(args: LaunchAgentInNewTabArgs): LaunchAgent
if (plan?.route === 'structured-native-chat') {
const structured = launchStructuredAgentFromNewTab({
plan,
onCreatedTab: args.onCreatedTab,
worktreeId,
...(groupId ? { groupId } : {}),
...(beforeSurfaceOpen ? { beforeSurfaceOpen } : {}),
Expand Down Expand Up @@ -232,7 +234,8 @@ function launchAgentInNewTabInternal(args: LaunchAgentInNewTabArgs): LaunchAgent
// Why: omission means terminal locally, but would let a paired host apply
// its own default; send the client's resolved terminal choice explicitly.
viewMode: initialViewModeProps.viewMode ?? 'terminal',
onPromptDelivered
onPromptDelivered,
onCreatedTab: args.onCreatedTab
})
return {
surface: { kind: 'host-published' },
Expand All @@ -256,6 +259,7 @@ function launchAgentInNewTabInternal(args: LaunchAgentInNewTabArgs): LaunchAgent
...(activate === false ? { activate: false } : {}),
...initialViewModeProps
})
args.onCreatedTab?.(tab.id)
seedNativeChatAppliedSessionOptions(tab.id, agent, startupPlan.sessionOptions)
if (initialCwd?.trim()) {
// Why: queue before mount so local, WSL, and SSH continuations preserve their subdirectory.
Expand Down
Loading
Loading