Add default tab templates from orca.yaml
This commit is contained in:
@@ -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