Add default tab templates from orca.yaml
This commit is contained in:
@@ -429,6 +429,7 @@ export function getDefaultWorkspaceSession(): WorkspaceSessionState {
|
||||
activeBrowserTabIdByWorktree: {},
|
||||
activeFileIdByWorktree: {},
|
||||
activeTabTypeByWorktree: {},
|
||||
browserUrlHistory: []
|
||||
browserUrlHistory: [],
|
||||
defaultTerminalTabsAppliedByWorktreeId: {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,10 @@ describe('remote workspace session projection', () => {
|
||||
remoteSessionIdsByTabId: {
|
||||
'tab-1': 'pty-1',
|
||||
'tab-local': 'pty-local'
|
||||
},
|
||||
defaultTerminalTabsAppliedByWorktreeId: {
|
||||
'repo-a::/srv/app': true as const,
|
||||
'repo-local::/tmp/local': true as const
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +65,7 @@ describe('remote workspace session projection', () => {
|
||||
'tab-1': { root: null, activeLeafId: null, expandedLeafId: null }
|
||||
})
|
||||
expect(projected.remoteSessionIdsByTabId).toEqual({ 'tab-1': 'pty-1' })
|
||||
expect(projected.defaultTerminalTabsAppliedByWorktreePath).toEqual({ '/srv/app': true })
|
||||
})
|
||||
|
||||
it('imports projected terminal state into this client repo id', () => {
|
||||
@@ -85,7 +90,8 @@ describe('remote workspace session projection', () => {
|
||||
terminalLayoutsByTabId: {
|
||||
'tab-1': { root: null, activeLeafId: null, expandedLeafId: null }
|
||||
},
|
||||
remoteSessionIdsByTabId: { 'tab-1': 'pty-1' }
|
||||
remoteSessionIdsByTabId: { 'tab-1': 'pty-1' },
|
||||
defaultTerminalTabsAppliedByWorktreePath: { '/srv/app': true }
|
||||
},
|
||||
{ resolveWorktreeId: (path) => (path === '/srv/app' ? 'repo-b::/srv/app' : null) }
|
||||
)
|
||||
@@ -97,6 +103,9 @@ describe('remote workspace session projection', () => {
|
||||
worktreeId: 'repo-b::/srv/app'
|
||||
})
|
||||
expect(session.remoteSessionIdsByTabId).toEqual({ 'tab-1': 'pty-1' })
|
||||
expect(session.defaultTerminalTabsAppliedByWorktreeId).toEqual({
|
||||
'repo-b::/srv/app': true
|
||||
})
|
||||
})
|
||||
|
||||
it('imports active worktree metadata even when the worktree has no terminal tabs', () => {
|
||||
|
||||
@@ -79,6 +79,17 @@ export function exportRemoteWorkspaceSession(
|
||||
}
|
||||
}
|
||||
|
||||
const defaultTerminalTabsAppliedByWorktreePath: Record<string, true> = {}
|
||||
for (const worktreeId of Object.keys(session.defaultTerminalTabsAppliedByWorktreeId ?? {})) {
|
||||
if (!options.isTargetWorktree(worktreeId)) {
|
||||
continue
|
||||
}
|
||||
const worktreePath = worktreePathFromId(worktreeId)
|
||||
if (worktreePath) {
|
||||
defaultTerminalTabsAppliedByWorktreePath[worktreePath] = true
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
activeWorktreePath,
|
||||
activeTabId,
|
||||
@@ -100,7 +111,8 @@ export function exportRemoteWorkspaceSession(
|
||||
)
|
||||
)
|
||||
: undefined,
|
||||
lastVisitedAtByWorktreePath
|
||||
lastVisitedAtByWorktreePath,
|
||||
defaultTerminalTabsAppliedByWorktreePath
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +169,14 @@ export function importRemoteWorkspaceSession(
|
||||
}
|
||||
}
|
||||
|
||||
const defaultTerminalTabsAppliedByWorktreeId: Record<string, true> = {}
|
||||
for (const worktreePath of Object.keys(remote.defaultTerminalTabsAppliedByWorktreePath ?? {})) {
|
||||
const worktreeId = resolvePath(worktreePath)
|
||||
if (worktreeId) {
|
||||
defaultTerminalTabsAppliedByWorktreeId[worktreeId] = true
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...session,
|
||||
activeRepoId: activeWorktreeId ? (splitWorktreeId(activeWorktreeId)?.repoId ?? null) : null,
|
||||
@@ -179,6 +199,7 @@ export function importRemoteWorkspaceSession(
|
||||
)
|
||||
)
|
||||
: undefined,
|
||||
lastVisitedAtByWorktreeId
|
||||
lastVisitedAtByWorktreeId,
|
||||
defaultTerminalTabsAppliedByWorktreeId
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ export type RemoteWorkspaceSession = {
|
||||
activeTabIdByWorktreePath?: Record<string, string | null>
|
||||
remoteSessionIdsByTabId?: Record<string, string>
|
||||
lastVisitedAtByWorktreePath?: Record<string, number>
|
||||
defaultTerminalTabsAppliedByWorktreePath?: Record<string, true>
|
||||
}
|
||||
|
||||
export type RemoteWorkspaceSnapshot = {
|
||||
|
||||
@@ -698,6 +698,10 @@ export type WorkspaceSessionState = {
|
||||
* older builds — hydration tolerates missing/partial maps and the
|
||||
* active worktree is seeded on first restore. */
|
||||
lastVisitedAtByWorktreeId?: Record<string, number>
|
||||
/** Worktrees whose repo-defined default terminal tabs have already been
|
||||
* considered. Persisted so closing all tabs and re-opening the workspace
|
||||
* does not recreate the template. */
|
||||
defaultTerminalTabsAppliedByWorktreeId?: Record<string, true>
|
||||
}
|
||||
|
||||
export type WorkspaceSessionPatch = Partial<WorkspaceSessionState>
|
||||
@@ -1463,6 +1467,13 @@ export type OrcaHooks = {
|
||||
archive?: string // Runs before worktree is archived
|
||||
}
|
||||
issueCommand?: string // Shared default command for linked GitHub issues
|
||||
defaultTabs?: OrcaDefaultTabTemplate[] // Terminal tabs to create once for a new worktree
|
||||
}
|
||||
|
||||
export type OrcaDefaultTabTemplate = {
|
||||
title?: string
|
||||
color?: string
|
||||
command?: string
|
||||
}
|
||||
|
||||
export type RepoHookSettings = {
|
||||
@@ -1487,6 +1498,11 @@ export type WorktreeStartupLaunch = {
|
||||
env?: Record<string, string>
|
||||
}
|
||||
|
||||
export type WorktreeDefaultTabsLaunch = {
|
||||
tabs: OrcaDefaultTabTemplate[]
|
||||
runCommands: boolean
|
||||
}
|
||||
|
||||
export type CreateSparseCheckoutRequest = {
|
||||
directories: string[]
|
||||
/** Set when the directories came from a saved preset and the user did not
|
||||
@@ -1552,6 +1568,7 @@ export type CreateWorktreeResult = {
|
||||
lineage?: WorktreeLineage | null
|
||||
warnings?: WorktreeLineageWarning[]
|
||||
setup?: WorktreeSetupLaunch
|
||||
defaultTabs?: WorktreeDefaultTabsLaunch
|
||||
warning?: string
|
||||
initialBaseStatus?: WorktreeBaseStatusEvent
|
||||
localBaseRefRefresh?: LocalBaseRefRefreshResult
|
||||
|
||||
@@ -222,6 +222,26 @@ describe('parseWorkspaceSession', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('accepts default-tab idempotency markers', () => {
|
||||
const result = parseWorkspaceSession({
|
||||
activeRepoId: null,
|
||||
activeWorktreeId: null,
|
||||
activeTabId: null,
|
||||
tabsByWorktree: {},
|
||||
terminalLayoutsByTabId: {},
|
||||
defaultTerminalTabsAppliedByWorktreeId: {
|
||||
'repo1::/path/wt1': true
|
||||
}
|
||||
})
|
||||
|
||||
expect(result.ok).toBe(true)
|
||||
if (result.ok) {
|
||||
expect(result.value.defaultTerminalTabsAppliedByWorktreeId).toEqual({
|
||||
'repo1::/path/wt1': true
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
it('caps oversized browser history while parsing legacy workspace sessions', () => {
|
||||
const result = parseWorkspaceSession({
|
||||
activeRepoId: null,
|
||||
|
||||
@@ -252,7 +252,8 @@ export const workspaceSessionStateSchema: z.ZodType<WorkspaceSessionState> = z.o
|
||||
},
|
||||
z.record(z.string(), z.number().finite().nonnegative())
|
||||
)
|
||||
.optional()
|
||||
.optional(),
|
||||
defaultTerminalTabsAppliedByWorktreeId: z.record(z.string(), z.literal(true)).optional()
|
||||
})
|
||||
|
||||
export type ParsedWorkspaceSession =
|
||||
|
||||
Reference in New Issue
Block a user