import type { HostFailure } from "./HostFailure.ts";

export type RunRecordState =
  | "created"
  | "starting"
  | "running"
  | "completed"
  | "failed"
  | "cancelled"
  | "delivery_unknown";

export type ContinuationMode =
  | "same_session"
  | "resumed_session"
  | "new_session_from_files";

export interface RunRecord {
  schema: "codeflowmu.run/v1";

  runId: string;
  workerId: string;
  doorbellId: string;

  bindingId: string;
  hostId: string;
  /** Generated before each external host call for crash recovery / dedupe. */
  deliveryAttemptId: string;
  externalRunId?: string;

  state: RunRecordState;

  taskId?: string;
  sourceFactRefs: string[];

  continuationMode: ContinuationMode;

  startedAt?: string;
  settledAt?: string;
  failure?: HostFailure;
}
