mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 10:58:10 +00:00
orca server ... replaces orca environment ... and orca host name; --server and --parent-server replace --environment and --parent-environment. Old spellings stay accepted as input only: help, suggestions, errors and printed commands use the new names, and giving both spellings different values is invalid_argument. --host is still parsed but leaves help; orca host list/rm are hidden. Listings name each row's owning server (server: / server=) from data already returned, mapping a stored owner to a saved-server name only from this computer's own store, and print server=unknown instead of guessing local. The ports footer and search hits drop host=. CLI-built JSON uses server keys (server, address.server, parent.server, unknown-server, servers, knownServers, status target kind server). create/set print the same parent line as ps.
136 lines
4.8 KiB
TypeScript
136 lines
4.8 KiB
TypeScript
// Use agent.launch for surface/model/effort; older servers fall back to the create startup terminal.
|
|
|
|
import type { AgentLaunchResult } from '../../shared/agent-launch/contracts/agent-launch-intent'
|
|
import {
|
|
AGENT_LAUNCH_LOCAL_PRESENTATION_RUNTIME_CAPABILITY,
|
|
AGENT_LAUNCH_PROMPT_CARRY_RUNTIME_CAPABILITY
|
|
} from '../../shared/agent-launch/contracts/agent-launch-runtime-capability'
|
|
import type { RuntimeWorktreeCreateResult, RuntimeWorktreeRecord } from '../../shared/runtime-types'
|
|
import {
|
|
callAgentLaunch,
|
|
formatAgentLaunch,
|
|
hasLaunchModelFlags,
|
|
getAgentLaunchCapabilities,
|
|
type CliAgentLaunch,
|
|
SURFACE_UNSUPPORTED_MESSAGE
|
|
} from '../agent-launch-request'
|
|
import { formatWorktreeShow, printResult } from '../format'
|
|
import { RuntimeClientError, type RuntimeClient } from '../runtime-client'
|
|
import { printLineageSummary } from './worktree-lineage-summary'
|
|
import { annotateMutationResult } from './worktree-address-annotation'
|
|
import { printHookWarning } from './worktree-removal-warnings'
|
|
import { withSetupDecisionRecovery } from './worktree-setup-decision-recovery'
|
|
import { withCliAgentLaunchRecovery } from '../agent-launch-recovery'
|
|
|
|
type WorktreeAgentLaunchResult = Pick<
|
|
RuntimeWorktreeCreateResult,
|
|
'lineage' | 'workspaceLineage' | 'crossStoreLineage'
|
|
> & {
|
|
/** Absent only when the server could not show the worktree it just created. */
|
|
worktree?: RuntimeWorktreeRecord
|
|
launch: AgentLaunchResult
|
|
}
|
|
|
|
export async function createWorktreeWithAgent(args: {
|
|
client: RuntimeClient
|
|
flags: Map<string, string | boolean>
|
|
create: Record<string, unknown>
|
|
launch: CliAgentLaunch
|
|
json: boolean
|
|
rawArgs?: readonly string[]
|
|
}): Promise<void> {
|
|
const { client, flags, create, launch, json, rawArgs } = args
|
|
const capabilities = await getAgentLaunchCapabilities(client)
|
|
if (
|
|
!capabilities?.includes(AGENT_LAUNCH_LOCAL_PRESENTATION_RUNTIME_CAPABILITY) ||
|
|
(launch.prompt && !capabilities.includes(AGENT_LAUNCH_PROMPT_CARRY_RUNTIME_CAPABILITY))
|
|
) {
|
|
if (launch.operationId) {
|
|
throw new RuntimeClientError(
|
|
'agent_session_operation_unknown',
|
|
'This server cannot replay the earlier launch. Return to the server that started it; do not retry without --retry-launch.'
|
|
)
|
|
}
|
|
if (hasLaunchModelFlags(flags)) {
|
|
throw new RuntimeClientError(
|
|
'incompatible_runtime',
|
|
"This Orca server can't start an agent on a chosen model or effort. Update Orca on that server, or omit --model and --effort."
|
|
)
|
|
}
|
|
if (launch.surface) {
|
|
throw new RuntimeClientError('incompatible_runtime', SURFACE_UNSUPPORTED_MESSAGE)
|
|
}
|
|
const params = {
|
|
...create,
|
|
startupAgent: launch.agent,
|
|
startupPrompt: launch.prompt?.text ?? '',
|
|
launchSource: 'cli'
|
|
}
|
|
const created = await withSetupDecisionRecovery(
|
|
withCliAgentLaunchRecovery(
|
|
client.call<RuntimeWorktreeCreateResult>('worktree.create', params),
|
|
{
|
|
rawArgs,
|
|
params
|
|
}
|
|
)
|
|
)
|
|
const { response, parentText } = await annotateMutationResult(client, created)
|
|
printHookWarning(response.result, json)
|
|
printLineageSummary(response.result, json, parentText)
|
|
printResult(response, json, formatWorktreeShow)
|
|
return
|
|
}
|
|
const launched = await withSetupDecisionRecovery(
|
|
callAgentLaunch(
|
|
client,
|
|
launch,
|
|
{
|
|
target: { kind: 'create-worktree', create },
|
|
presentation: create.activate === true ? 'focused' : 'background'
|
|
},
|
|
capabilities,
|
|
rawArgs
|
|
),
|
|
launch.operationId !== undefined
|
|
)
|
|
const shown = await showLaunchedWorktree(client, launched.result.worktreeId)
|
|
const annotated = shown
|
|
? await annotateMutationResult(client, { result: { worktree: shown } })
|
|
: undefined
|
|
const worktree = annotated?.response.result.worktree
|
|
const result: WorktreeAgentLaunchResult = {
|
|
...(worktree
|
|
? {
|
|
worktree,
|
|
lineage: worktree.lineage,
|
|
workspaceLineage: worktree.workspaceLineage ?? null,
|
|
crossStoreLineage: worktree.crossStoreLineage ?? null
|
|
}
|
|
: { lineage: null }),
|
|
launch: launched.result
|
|
}
|
|
printLineageSummary(result, json, annotated?.parentText ?? null)
|
|
printResult({ ...launched, result }, json, (value) =>
|
|
[
|
|
...(value.worktree ? [formatWorktreeShow({ worktree: value.worktree })] : []),
|
|
formatAgentLaunch(value.launch)
|
|
].join('\n')
|
|
)
|
|
}
|
|
|
|
/** Reporting, never a reason to fail: the agent already runs, and a retry would start a second. */
|
|
async function showLaunchedWorktree(
|
|
client: RuntimeClient,
|
|
worktreeId: string
|
|
): Promise<RuntimeWorktreeRecord | undefined> {
|
|
try {
|
|
const shown = await client.call<{ worktree: RuntimeWorktreeRecord }>('worktree.show', {
|
|
worktree: `id:${worktreeId}`
|
|
})
|
|
return shown.result.worktree
|
|
} catch {
|
|
return undefined
|
|
}
|
|
}
|