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.

2.2 KB
Raw Blame
import { normalizeRuntimePathForComparison } from './cross-platform-path'
import {
  createWorktreeVisibilitySourceMatcher,
  type WorktreeVisibilitySourceMatcher
} from './worktree/visibility-sources'

/** Restrict agent scratch matches to reserved repo-root paths; broader matches hide user worktrees (#9388). */
const AGENT_SCRATCH_PATH_PREFIXES: readonly (readonly string[])[] = [
  ['.claude', 'worktrees'],
  ['.gsd-workspaces']
]

export type AgentScratchWorktreePathMatcher = (worktreePath: string) => boolean

export function createAgentScratchWorktreeSourceMatcher(
  checkoutPaths: readonly string[],
  configuredWorktreeBasePaths: readonly string[]
): WorktreeVisibilitySourceMatcher {
  return createWorktreeVisibilitySourceMatcher(checkoutPaths, [], configuredWorktreeBasePaths)
}

export function createAgentScratchWorktreePathMatcher(
  checkoutPaths: readonly string[],
  configuredWorktreeBasePaths: readonly string[]
): AgentScratchWorktreePathMatcher {
  const classify = createAgentScratchWorktreeSourceMatcher(
    checkoutPaths,
    configuredWorktreeBasePaths
  )
  return (worktreePath) => classify(worktreePath)?.kind === 'built-in'
}

export function isAgentScratchWorktreePath(
  repoPath: string,
  worktreePath: string,
  configuredWorktreeBasePaths: readonly string[]
): boolean {
  return createAgentScratchWorktreePathMatcher(
    [repoPath],
    configuredWorktreeBasePaths
  )(worktreePath)
}

/** Agent-created repos under these reserved containers are internal rather than user projects (#9388). */
const AGENT_SCRATCH_REPO_ROOT_SEGMENTS: readonly (readonly string[])[] = [
  ['.codex-tmp'],
  ['.codex', 'vendor_imports'],
  ['.claude', 'skills'],
  ...AGENT_SCRATCH_PATH_PREFIXES
]

export function isAgentScratchRepoRootPath(repoPath: string): boolean {
  const segments = normalizeRuntimePathForComparison(repoPath).split('/')
  for (const marker of AGENT_SCRATCH_REPO_ROOT_SEGMENTS) {
    // Repo scratch containers may occur anywhere above the root; worktree matches instead anchor to a registered checkout.
    for (let index = 0; index + marker.length <= segments.length; index += 1) {
      if (marker.every((segment, offset) => segments[index + offset] === segment)) {
        return true
      }
    }
  }
  return false
}