Add default tab templates from orca.yaml
This commit is contained in:
@@ -220,6 +220,10 @@ vi.mock('../hooks', () => ({
|
||||
createSetupRunnerScript: vi.fn(),
|
||||
getEffectiveHooks: vi.fn().mockReturnValue(null),
|
||||
getEffectiveHooksFromConfig: vi.fn().mockReturnValue(null),
|
||||
getDefaultTabCommandTrustContent: vi.fn(
|
||||
(hooks: { scripts?: { setup?: string } } | null) => hooks?.scripts?.setup?.trim() ?? ''
|
||||
),
|
||||
getDefaultTabsLaunch: vi.fn().mockReturnValue(undefined),
|
||||
getSetupRunnerEnvVars: (_repo: never, worktreePath: string) => ({
|
||||
ORCA_ROOT_PATH: '/remote/repo',
|
||||
ORCA_WORKTREE_PATH: worktreePath
|
||||
@@ -8044,7 +8048,13 @@ describe('OrcaRuntimeService', () => {
|
||||
}
|
||||
}
|
||||
})
|
||||
expect(activateWorktree).toHaveBeenCalledWith('repo-1', expect.any(String), result.setup)
|
||||
expect(activateWorktree).toHaveBeenCalledWith(
|
||||
'repo-1',
|
||||
expect.any(String),
|
||||
result.setup,
|
||||
undefined,
|
||||
undefined
|
||||
)
|
||||
})
|
||||
|
||||
it('passes setup payloads through when explicitly activating CLI-created worktrees', async () => {
|
||||
@@ -8096,7 +8106,13 @@ describe('OrcaRuntimeService', () => {
|
||||
activate: true
|
||||
})
|
||||
|
||||
expect(activateWorktree).toHaveBeenCalledWith('repo-1', expect.any(String), result.setup)
|
||||
expect(activateWorktree).toHaveBeenCalledWith(
|
||||
'repo-1',
|
||||
expect.any(String),
|
||||
result.setup,
|
||||
undefined,
|
||||
undefined
|
||||
)
|
||||
})
|
||||
|
||||
it('follows normal setup policy for CLI-created worktrees without activating them', async () => {
|
||||
@@ -8731,7 +8747,13 @@ describe('OrcaRuntimeService', () => {
|
||||
expect(detectRemoteAgentsMock).not.toHaveBeenCalled()
|
||||
expect(spawn).not.toHaveBeenCalled()
|
||||
expect(metaById[result.worktree.id]?.createdWithAgent).toBeUndefined()
|
||||
expect(activateWorktree).toHaveBeenCalledWith('repo-1', result.worktree.id, undefined)
|
||||
expect(activateWorktree).toHaveBeenCalledWith(
|
||||
'repo-1',
|
||||
result.worktree.id,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined
|
||||
)
|
||||
})
|
||||
|
||||
it('detects agents on the SSH host before launching remote startup drafts', async () => {
|
||||
@@ -9679,7 +9701,13 @@ describe('OrcaRuntimeService', () => {
|
||||
activate: true
|
||||
})
|
||||
|
||||
expect(activateWorktree).toHaveBeenCalledWith('repo-1', expect.any(String), undefined)
|
||||
expect(activateWorktree).toHaveBeenCalledWith(
|
||||
'repo-1',
|
||||
expect.any(String),
|
||||
undefined,
|
||||
undefined,
|
||||
undefined
|
||||
)
|
||||
})
|
||||
|
||||
it('stamps createdAt alongside lastActivityAt so CLI-created worktrees get the Recent-sort grace window', async () => {
|
||||
|
||||
@@ -346,6 +346,8 @@ import type { AddWorktreeResult } from '../git/worktree'
|
||||
import { isENOENT } from '../ipc/filesystem-auth'
|
||||
import {
|
||||
createSetupRunnerScript,
|
||||
getDefaultTabCommandTrustContent,
|
||||
getDefaultTabsLaunch,
|
||||
getEffectiveHooks,
|
||||
getEffectiveSetupRunPolicy,
|
||||
hasUnrecognizedOrcaYamlKeys,
|
||||
@@ -682,7 +684,8 @@ type RuntimeNotifier = {
|
||||
repoId: string,
|
||||
worktreeId: string,
|
||||
setup?: CreateWorktreeResult['setup'],
|
||||
startup?: WorktreeStartupLaunch
|
||||
startup?: WorktreeStartupLaunch,
|
||||
defaultTabs?: CreateWorktreeResult['defaultTabs']
|
||||
): void
|
||||
createTerminal(worktreeId: string, opts: { command?: string; title?: string }): void
|
||||
revealTerminalSession?(
|
||||
@@ -6856,9 +6859,9 @@ export class OrcaRuntimeService {
|
||||
|
||||
private getSetupHookTrustPayload(
|
||||
repo: Repo,
|
||||
setupScript: string | undefined
|
||||
scriptContentValue: string | undefined
|
||||
): { contentHash: string; scriptContent: string } | undefined {
|
||||
const scriptContent = setupScript?.trim()
|
||||
const scriptContent = scriptContentValue?.trim()
|
||||
if (!scriptContent || repo.hookSettings?.commandSourcePolicy === 'local-only') {
|
||||
return undefined
|
||||
}
|
||||
@@ -6898,7 +6901,10 @@ export class OrcaRuntimeService {
|
||||
hooks,
|
||||
setupRunPolicy: getEffectiveSetupRunPolicy(repo),
|
||||
source: hooks ? 'orca.yaml' : null,
|
||||
setupTrust: this.getSharedSetupHookTrustPayload(repo, hooks?.scripts?.setup)
|
||||
setupTrust: this.getSharedSetupHookTrustPayload(
|
||||
repo,
|
||||
getDefaultTabCommandTrustContent(hooks)
|
||||
)
|
||||
}
|
||||
} catch {
|
||||
return {
|
||||
@@ -6918,7 +6924,10 @@ export class OrcaRuntimeService {
|
||||
hooks,
|
||||
setupRunPolicy,
|
||||
source: hasFile ? 'orca.yaml' : hooks ? 'legacy' : null,
|
||||
setupTrust: this.getSharedSetupHookTrustPayload(repo, sharedHooks?.scripts?.setup)
|
||||
setupTrust: this.getSharedSetupHookTrustPayload(
|
||||
repo,
|
||||
getDefaultTabCommandTrustContent(sharedHooks)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6938,9 +6947,7 @@ export class OrcaRuntimeService {
|
||||
if (result.isBinary) {
|
||||
return { hasHooks: false, hooks: null, mayNeedUpdate: false }
|
||||
}
|
||||
const { parse } = await import('yaml')
|
||||
const parsed = parse(result.content)
|
||||
return { hasHooks: true, hooks: parsed, mayNeedUpdate: false }
|
||||
return { hasHooks: true, hooks: parseOrcaYaml(result.content), mayNeedUpdate: false }
|
||||
} catch {
|
||||
return { hasHooks: false, hooks: null, mayNeedUpdate: false }
|
||||
}
|
||||
@@ -7936,12 +7943,22 @@ export class OrcaRuntimeService {
|
||||
// Why: CLI-created worktrees do not have a renderer preview to mismatch
|
||||
// against. Trust is granted by the direct CLI invocation (`--run-hooks`),
|
||||
// so loading the setup hook from the created worktree is intentional here.
|
||||
const yamlHooks = loadHooks(worktreePath)
|
||||
const hooks = getEffectiveHooks(repo, worktreePath)
|
||||
// Why: setupDecision lets mobile/CLI callers control whether the setup
|
||||
// script runs. 'skip' suppresses it, 'run' forces it, 'inherit' (default)
|
||||
// defers to the repo's orca.yaml setupRunPolicy. runHooks === true maps
|
||||
// to 'run' for backwards compatibility with the desktop create flow.
|
||||
const effectiveDecision = args.runHooks ? 'run' : (args.setupDecision ?? 'inherit')
|
||||
let defaultTabs: CreateWorktreeResult['defaultTabs']
|
||||
try {
|
||||
defaultTabs = getDefaultTabsLaunch(yamlHooks, repo, effectiveDecision)
|
||||
} catch (error) {
|
||||
console.warn(`[hooks] default tab commands skipped for ${worktreePath}:`, error)
|
||||
defaultTabs = yamlHooks?.defaultTabs
|
||||
? { tabs: yamlHooks.defaultTabs, runCommands: false }
|
||||
: undefined
|
||||
}
|
||||
const shouldRunSetup = hooks?.scripts.setup && shouldRunSetupForCreate(repo, effectiveDecision)
|
||||
if (shouldRunSetup && hooks?.scripts.setup) {
|
||||
if (this.authoritativeWindowId !== null) {
|
||||
@@ -8053,9 +8070,21 @@ export class OrcaRuntimeService {
|
||||
// the user can watch prompts/output in a visible pane.
|
||||
const activationSetup = didSpawnSetup ? undefined : setup
|
||||
if (effectiveStartup && !didSpawnStartup) {
|
||||
this.notifier?.activateWorktree(repo.id, worktree.id, activationSetup, effectiveStartup)
|
||||
this.notifier?.activateWorktree(
|
||||
repo.id,
|
||||
worktree.id,
|
||||
activationSetup,
|
||||
effectiveStartup,
|
||||
defaultTabs
|
||||
)
|
||||
} else {
|
||||
this.notifier?.activateWorktree(repo.id, worktree.id, activationSetup)
|
||||
this.notifier?.activateWorktree(
|
||||
repo.id,
|
||||
worktree.id,
|
||||
activationSetup,
|
||||
undefined,
|
||||
defaultTabs
|
||||
)
|
||||
}
|
||||
} else if (this.ptyController?.spawn) {
|
||||
try {
|
||||
@@ -8090,6 +8119,7 @@ export class OrcaRuntimeService {
|
||||
},
|
||||
...(lineageInput ? { lineage, warnings: lineageWarnings } : {}),
|
||||
...(setup ? { setup } : {}),
|
||||
...(defaultTabs ? { defaultTabs } : {}),
|
||||
...(warning ? { warning } : {}),
|
||||
...(addResult.localBaseRefRefresh
|
||||
? { localBaseRefRefresh: addResult.localBaseRefRefresh }
|
||||
|
||||
Reference in New Issue
Block a user