Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.6 KB
Raw Blame
import { FLOATING_TERMINAL_WORKTREE_ID } from './constants'
import { getRepoIdFromWorktreeId } from './worktree/id'
import { parseWorkspaceKey } from './workspace-scope'

/** Which browser profile new tabs in a workspace use: the shared Default, or one Orca manages per repo or per workspace. */
export type BrowserProfileScope = 'shared' | 'repo' | 'worktree'

export type ManagedBrowserProfileOwner = { kind: 'repo' | 'worktree'; id: string }

export function getManagedBrowserProfileOwner(
  scope: BrowserProfileScope | undefined,
  worktreeId: string
): ManagedBrowserProfileOwner | null {
  if ((scope !== 'repo' && scope !== 'worktree') || worktreeId === FLOATING_TERMINAL_WORKTREE_ID) {
    return null
  }
  // Why: a standalone folder workspace belongs to no repo, so it owns its profile under either scope.
  if (scope === 'repo' && parseWorkspaceKey(worktreeId)?.type !== 'folder') {
    return { kind: 'repo', id: getRepoIdFromWorktreeId(worktreeId) }
  }
  return { kind: 'worktree', id: worktreeId }
}

export function managedBrowserProfileOwnerKey(owner: ManagedBrowserProfileOwner): string {
  return `${owner.kind}:${owner.id}`
}

export function isManagedBrowserProfileOf(
  profile: { owner?: ManagedBrowserProfileOwner },
  owner: ManagedBrowserProfileOwner
): boolean {
  return profile.owner?.kind === owner.kind && profile.owner.id === owner.id
}

/** A partition main never admits, so a tab whose profile main has not made, or has deleted, loads nowhere. */
export function unadmittedBrowserPartition(profileId: string): string {
  return `persist:orca-browser-unminted-${profileId}`
}