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.

4.9 KB
Raw Blame
// Desktop automation parity (row 5): renderer asserts the request, main feeds it to pty:spawn. C7/C5 compare against this table.
import {
  LAUNCH_LEAF_ID,
  LAUNCH_TAB_ID,
  LAUNCH_TOKEN,
  launchWorkspaceId,
  type LaunchClient,
  type LaunchWorkspace,
  type WindowProviderFacts
} from './launch-parity-window-request.test-fixture'
import { POSIX_PATH, WIN_PATH, WSL_PATH } from './launch-parity-window-cases.test-fixture'

export type AutomationLaunchCase = {
  name: string
  client: LaunchClient
  workspace: LaunchWorkspace
  settings?: Record<string, unknown>
  agent: 'claude' | 'codex' | 'aider'
  /** The run title; every dispatch passes "<automation name> run <n>". */
  title: string
  request: { command: string; agentCommand: string; shellOverride?: string }
  provider: WindowProviderFacts
}

// Why an apostrophe: it is the byte that tells POSIX and PowerShell quoting apart.
export const AUTOMATION_PROMPT = "don't stop"
const SKIP = '--dangerously-skip-permissions'
const POSIX_CLAUDE = `claude '${SKIP}'`
const posix = { command: `${POSIX_CLAUDE} 'don'"'"'t stop'`, agentCommand: POSIX_CLAUDE }
const powershell = { command: `${POSIX_CLAUDE} 'don''t stop'`, agentCommand: POSIX_CLAUDE }
const CODEX = "codex '--dangerously-bypass-approvals-and-sandbox'"
const CODEX_LAUNCH =
  "codex '-c' 'check_for_update_on_startup=false' '-c' 'disable_paste_burst=true' '--dangerously-bypass-approvals-and-sandbox'"
const AGENT_COMMAND = {
  codex: { command: `${CODEX_LAUNCH} 'don'"'"'t stop'`, agentCommand: CODEX },
  aider: {
    command: "aider '--yes-always' '--no-check-update' '--no-show-release-notes'",
    agentCommand: "aider '--yes-always'"
  }
} as const
const ZSH = { shellOverride: '/bin/zsh' }
const PWSH = { shellOverride: 'powershell.exe', terminalWindowsWslDistro: null }
const WSL_EXE = { shellOverride: 'wsl.exe', terminalWindowsWslDistro: 'Ubuntu' }
const repo = (path: string): LaunchWorkspace => ({ kind: 'repo', path })
type AutomationCaseFields = Omit<AutomationLaunchCase, 'name' | 'agent' | 'title'> &
  Partial<Pick<AutomationLaunchCase, 'agent'>>
const automation = (name: string, fields: AutomationCaseFields): AutomationLaunchCase => ({
  name,
  agent: 'claude',
  title: 'Nightly audit run 3',
  ...fields
})

// Only local WSL workspaces send shellOverride; quote for the execution host’s OS, independently of shell, matching window tabs.
export const AUTOMATION_LAUNCH_CASES: AutomationLaunchCase[] = [
  automation('macOS repo', {
    client: 'darwin',
    workspace: repo(POSIX_PATH),
    request: posix,
    provider: ZSH
  }),
  automation('Windows C: repo, default PowerShell', {
    client: 'win32',
    workspace: repo(WIN_PATH),
    request: powershell,
    provider: PWSH
  }),
  automation('Windows wsl$ repo, no saved runtime', {
    client: 'win32',
    workspace: repo(WSL_PATH),
    request: { ...posix, shellOverride: 'wsl.exe' },
    provider: WSL_EXE
  }),
  automation('Linux repo, codex', {
    client: 'linux',
    agent: 'codex',
    workspace: repo(POSIX_PATH),
    request: AGENT_COMMAND.codex,
    provider: ZSH
  }),
  // stdin-after-start: the prompt is pasted after launch, never on argv.
  automation('Linux repo, aider', {
    client: 'linux',
    agent: 'aider',
    workspace: repo(POSIX_PATH),
    request: AGENT_COMMAND.aider,
    provider: ZSH
  })
]

const AGENT_KIND = { claude: 'claude-code', codex: 'codex', aider: 'aider' } as const
const AGENT_ARGS = {
  claude: SKIP,
  codex: '--dangerously-bypass-approvals-and-sandbox',
  aider: '--yes-always'
} as const

/** The full pty:spawn request launchAgentBackgroundSession sends for this case. */
export function automationSpawnRequest(c: AutomationLaunchCase): Record<string, unknown> {
  const worktreeId = launchWorkspaceId(c.workspace)
  return {
    cols: 120,
    rows: 40,
    cwd: c.workspace.path,
    command: c.request.command,
    ...(c.request.shellOverride ? { shellOverride: c.request.shellOverride } : {}),
    ...(c.agent === 'codex' ? { startupCommandDelivery: 'shell-ready' } : {}),
    env: {
      ...(c.agent === 'claude' ? { DISABLE_AUTOUPDATER: '1' } : {}),
      ORCA_PANE_KEY: `${LAUNCH_TAB_ID}:${LAUNCH_LEAF_ID}`,
      ORCA_TAB_ID: LAUNCH_TAB_ID,
      ORCA_WORKTREE_ID: worktreeId,
      ORCA_AGENT_LAUNCH_TOKEN: LAUNCH_TOKEN
    },
    launchConfig: {
      agentCommand: c.request.agentCommand,
      agentArgs: AGENT_ARGS[c.agent],
      agentEnv: {}
    },
    launchToken: LAUNCH_TOKEN,
    launchAgent: c.agent,
    connectionId: null,
    worktreeId,
    tabId: LAUNCH_TAB_ID,
    leafId: LAUNCH_LEAF_ID,
    placement: { kind: 'new-tab', row: { customTitle: c.title } },
    telemetry: { agent_kind: AGENT_KIND[c.agent], launch_source: 'unknown', request_kind: 'new' }
  }
}

/** The phone's view of a run tab: hidden under its run title, no agent named, active. */
export function automationPhoneTab(
  c: Pick<AutomationLaunchCase, 'title'>
): Record<string, unknown> {
  return { title: c.title, launchAgent: undefined, isActive: true }
}