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.2 KB
Raw Blame
export const FILE_EXPLORER_FULL_ROOT = '/'

/** Accepts only string-valued choices with safe record keys; directory eligibility is validated against the current worktree. */
export function normalizeExplorerDisplayRootByWorktree(value: unknown): Record<string, string> {
  if (!value || typeof value !== 'object' || Array.isArray(value)) {
    return {}
  }
  return Object.fromEntries(
    Object.entries(value).filter(
      ([key, choice]) =>
        key &&
        !['__proto__', 'constructor', 'prototype'].includes(key) &&
        typeof choice === 'string'
    )
  )
}

/** Preserves full-root navigation for preexisting sparse worktrees without replacing explicit saved choices. */
export function migrateExplorerDisplayRoots(
  saved: unknown,
  migrated: boolean,
  worktreeMeta: Record<string, { sparseDirectories?: string[] }>
): Record<string, string> {
  const choices = normalizeExplorerDisplayRootByWorktree(saved)
  if (!migrated) {
    for (const [id, meta] of Object.entries(worktreeMeta)) {
      if (
        meta?.sparseDirectories?.length &&
        !['__proto__', 'constructor', 'prototype'].includes(id) &&
        choices[id] === undefined
      ) {
        choices[id] = FILE_EXPLORER_FULL_ROOT
      }
    }
  }
  return choices
}