Skip to content

armgit / Orkas

Public Imported from GitHub
0

Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.

1.8 KB
Raw Blame
/** Test-owned attribution only. No exception-message inference or runtime retry. */
export interface PreviewAttempt {
  id: number;
  entryKey: string;
  version: string | null;
  stable: boolean;
  started: number;
  ended: number;
  interactions: boolean;
  ok: boolean;
  windows: number[];
  viewports: string[];
  runtimeErrorWindows: number[];
}
export interface PreviewRecoverySnapshot {
  attempts: PreviewAttempt[];
  currentVersions: Record<string, string | null>;
}

export function recoveredPreviewWindows(snapshot: PreviewRecoverySnapshot) {
  const latest = new Map<string, PreviewAttempt>();
  const owners = new Map<number, PreviewAttempt[]>();
  for (const attempt of snapshot.attempts) {
    const previous = latest.get(attempt.entryKey);
    if (!previous || attempt.started > previous.started) latest.set(attempt.entryKey, attempt);
    for (const window of attempt.windows) owners.set(window, [...(owners.get(window) ?? []), attempt]);
  }
  const recovered: Array<{ windowId: number; failedAttempt: number; recoveredBy: number }> = [];
  for (const failed of snapshot.attempts) {
    if (failed.ok || !failed.stable || !failed.version || !failed.interactions || !failed.ended) continue;
    const verified = latest.get(failed.entryKey);
    if (!verified || !verified.ok || !verified.stable || !verified.version || !verified.interactions
      || verified.runtimeErrorWindows.length || verified.started <= failed.ended
      || verified.version !== snapshot.currentVersions[failed.entryKey]
      || !failed.viewports.every(view => verified.viewports.includes(view))) continue;
    for (const window of failed.runtimeErrorWindows) {
      if (owners.get(window)?.length === 1 && failed.windows.includes(window)) {
        recovered.push({ windowId: window, failedAttempt: failed.id, recoveredBy: verified.id });
      }
    }
  }
  return recovered;
}