mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* feat(workspaces): run setup and archive scripts for folder projects Folder projects get the setup and archive scripts git projects have: creating a workspace runs setup in a Setup tab, and removing one runs archive first. The script sees the workspace's name and id, so `orca worktree create` inside it attaches each new worktree to that workspace, however the workspace was created. - Folder creates (desktop IPC and runtime) prepare setup through the shared setup prep; runtime creates start it with the worktree terminal startup, so Setup-before-agent ordering matches. - Runner files live in <folder>/.orca, one fresh file per launch, removed with the workspace. - Only the host whose catalog holds the folder reads its orca.yaml or runs its scripts; a setup problem becomes a warning, never a failed create. - Shared orca.yaml setup with no approval from an older client is skipped; ask/inherit never refuses a folder create. - No orca.yaml default tabs for folders, since every workspace shares the directory. - New capability worktree.folder-setup.v1 gates the Settings section on runtime hosts; the composer, Settings and trust prompt reuse the existing setup surfaces. * i18n: add folder workspace hooks strings * chore: drop the runner's sync-fs baseline and an array cast * fix(workspaces): close review gaps in folder project setup - Whole-project trust sends an explicit run for folder creates the policy would run, since it carries no content hash. - Folder setup skips file access for a skipped setup and never starts a stopped WSL distro for a create nobody started; removal does the same. - Runtime folder creates return the trust mismatch, so the window re-asks. - The composer hides folder setup controls on hosts without worktree.folder-setup.v1 and keeps their old explicit skip. - Hook checks read a folder only on the host that owns it. - Git archive hooks get the removed workspace's id; WSL hooks blank inherited pane identity too. - Runner files are written through the drive path WSL needs for its drive mounts, and kept out of git status with .orca/.gitignore. - The CLI's older-host warning covers --agent creates and --json output. * fix(workspaces): wait for the folder setup capability and read orca.yaml once Create now waits for a runtime host's folder-setup answer instead of sending Skip while the probe is pending, and runtime setup reuses the parsed orca.yaml when merging effective hooks. * fix(workspaces): keep a failed folder setup probe unknown and retry it on create * fix(workspaces): share folder setup capability answers with the composer * fix(workspaces): re-ask the host for folder setup support on every create * fix(settings): read orca.yaml for folder projects and use workspace copy in hook rows QA found Settings reporting no orca.yaml for folder projects while the composer ran that script, and the inner hook rows still said worktree. * fix(folder-workspaces): open one Setup tab for an instant folder create * fix(workspaces): run setup when a created workspace has only editor tabs * perf(folder-workspaces): per-workspace runner dir, bounded setup answers, one archive config read * fix(folder-workspaces): retain setup capability for active consumers * fix(folder-workspaces): match hook search to workspace descriptions * fix(i18n): drop obsolete hook search descriptions * test(folder-workspaces): follow relocated setup trust modules
147 lines
4.9 KiB
TypeScript
147 lines
4.9 KiB
TypeScript
// Use agent.launch for surface/model/effort; older hosts fall back to the create startup terminal.
|
|
|
|
import {
|
|
folderSetupUnsupportedWarning,
|
|
withFolderSetupSupportWarning
|
|
} from './folder-setup-support-warning'
|
|
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 { 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 host 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 host cannot replay the earlier launch. Return to the original execution host; do not retry without --retry-launch.'
|
|
)
|
|
}
|
|
if (hasLaunchModelFlags(flags)) {
|
|
throw new RuntimeClientError(
|
|
'incompatible_runtime',
|
|
'This Orca host cannot start an agent on a chosen model or effort. Update Orca on the execution host, 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 response = await withSetupDecisionRecovery(
|
|
withCliAgentLaunchRecovery(
|
|
client.call<RuntimeWorktreeCreateResult>('worktree.create', params),
|
|
{
|
|
rawArgs,
|
|
params
|
|
}
|
|
)
|
|
)
|
|
const created = {
|
|
...response,
|
|
result: await withFolderSetupSupportWarning(client, response.result, create)
|
|
}
|
|
printHookWarning(created.result, json)
|
|
printLineageSummary(created.result, json)
|
|
printResult(created, 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 worktree = await showLaunchedWorktree(client, launched.result.worktreeId)
|
|
const setupWarning = await folderSetupUnsupportedWarning(
|
|
client,
|
|
launched.result.worktreeId,
|
|
create
|
|
)
|
|
if (setupWarning) {
|
|
// stderr keeps --json output parseable while still reporting the skipped setup.
|
|
console.error(`warning: ${setupWarning}`)
|
|
}
|
|
const result: WorktreeAgentLaunchResult = {
|
|
...(worktree
|
|
? {
|
|
worktree,
|
|
lineage: worktree.lineage,
|
|
workspaceLineage: worktree.workspaceLineage ?? null,
|
|
crossStoreLineage: worktree.crossStoreLineage ?? null
|
|
}
|
|
: { lineage: null }),
|
|
launch: launched.result
|
|
}
|
|
printLineageSummary(result, json)
|
|
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
|
|
}
|
|
}
|