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.4 KB
Raw Blame
/** Managed SSH orcad stops after 15 unused minutes like the relay; the next connect restarts it. */
import { z } from 'zod'

/** Test-only quiet period; a client forwards it to the servers it launches. */
export const ORCAD_E2E_IDLE_TIMEOUT_ENV = 'ORCA_E2E_ORCAD_IDLE_TIMEOUT_MS'
export const ORCAD_IDLE_EXIT_TIMEOUT_MS = 15 * 60_000
const ORCAD_E2E_IDLE_TIMEOUT_MAX_MS = 60 * 60_000

export function readOrcadE2EIdleTimeoutMs(env: NodeJS.ProcessEnv): number | null {
  const raw = env[ORCAD_E2E_IDLE_TIMEOUT_ENV]
  const value = raw ? Number(raw) : Number.NaN
  return Number.isSafeInteger(value) && value >= 1 && value <= ORCAD_E2E_IDLE_TIMEOUT_MAX_MS
    ? value
    : null
}

/** Client-chosen quiet period for the hosts it launches; older orcads ignore it and keep the default. */
export const ORCAD_IDLE_TIMEOUT_ENV = 'ORCA_ORCAD_IDLE_TIMEOUT_MS'
const ORCAD_IDLE_TIMEOUT_MIN_MS = 60_000
/** WSL hosts: an idle orcad holds the distro's VM (about 1.2 GB); a cold reopen costs about 4 s. */
export const WSL_ORCAD_IDLE_EXIT_TIMEOUT_MS = 5 * 60_000

/** Only shortens the default; anything unset, malformed or under a minute keeps it. */
export function readOrcadIdleTimeoutMs(env: NodeJS.ProcessEnv): number | null {
  const raw = env[ORCAD_IDLE_TIMEOUT_ENV]
  const value = raw ? Number(raw) : Number.NaN
  return Number.isSafeInteger(value) &&
    value >= ORCAD_IDLE_TIMEOUT_MIN_MS &&
    value <= ORCAD_IDLE_EXIT_TIMEOUT_MS
    ? value
    : null
}

/** Written to the data root just before an idle stop; the next start reports and clears it. */
export const ORCAD_IDLE_STOP_RECORD_FILENAME = 'orcad-idle-stop.json'

export const OrcadIdleStopRecordSchema = z.object({
  schemaVersion: z.literal(1),
  kind: z.literal('orcad_idle_stop'),
  pid: z.number().int().positive(),
  version: z.string().max(255),
  quietSince: z.iso.datetime({ offset: true }),
  stoppedAt: z.iso.datetime({ offset: true }),
  idleTimeoutMs: z.number().int().positive()
})

export type OrcadIdleStopRecord = z.infer<typeof OrcadIdleStopRecordSchema>

/**
 * In a WSL distro's data root (`~/.orca`): orcad's pid, written on an idle stop that left no
 * terminal daemon. The distro holder ends once that pid exits, so WSL may stop the idle distro.
 */
export const ORCAD_WSL_HOLDER_RELEASE_FILENAME = 'wsl-holder-release'

/** Beside the release request: the first few things keeping an idle distro held, one line. */
export const ORCAD_WSL_HOLDER_BLOCKED_FILENAME = 'wsl-holder-blocked'