import type { Attempt, Case, Effect, HumanRequest, Job, JobId, ResourceState, SpecVersion, WorkItem, WorkItemId, FenceToken, AttemptId, OperationOutcome, } from "../domain/types.ts"; import type { WorkflowSpecV2 } from "../domain/spec-types.ts"; import type { RevisionMigration } from "../application/revision.ts"; export interface JobRepository { createJob(input: { jobId?: JobId; title: string; objective: string; caseMode: Job["caseMode"]; }): Promise; getJob(jobId: JobId): Promise; listJobs(): Promise; saveJob(job: Job): Promise; saveSpecVersion(spec: SpecVersion): Promise; getSpecVersion(jobId: JobId, version: number): Promise; getApprovedSpec(jobId: JobId): Promise<{ record: SpecVersion; workflow: WorkflowSpecV2 } | undefined>; upsertCases(jobId: JobId, cases: Case[]): Promise; listCases(jobId: JobId): Promise; saveWorkItem(item: WorkItem): Promise; getWorkItem(id: WorkItemId): Promise; listWorkItems(jobId: JobId): Promise; listHumans(jobId: JobId): Promise; saveHuman(item: HumanRequest): Promise; getResource(key: string): Promise; saveResource(state: ResourceState): Promise; listResources(): Promise; saveEffect(effect: Effect): Promise; getEffect(id: string): Promise; listEffects(jobId: JobId): Promise; claimWork(input: { workItemId: WorkItemId; attemptId: AttemptId; fenceToken: FenceToken; leaseExpiresAt: string; nowIso: string; }): Promise; heartbeat(input: { attemptId: AttemptId; fenceToken: FenceToken; leaseExpiresAt: string; }): Promise; commitOutcome(input: { attemptId: AttemptId; fenceToken: FenceToken; workItem: WorkItem; job?: Job; outcome: OperationOutcome; finishedAt: string; costUsd?: number; turns?: number; siteActions?: number; }): Promise; createHumanRequest(item: HumanRequest): Promise; consumeGrant(input: { jobId: JobId; grantId: string; effect: Effect; }): Promise; activateRevision(input: { jobId: JobId; newSpec: SpecVersion; workflow: WorkflowSpecV2; migration: RevisionMigration; nowIso: string; }): Promise; cancelJob(jobId: JobId, nowIso: string): Promise; appendAudit(event: { jobId: JobId; at: string; type: string; payload: unknown; evidenceRefs?: string[]; }): Promise; withTransaction(fn: (repo: JobRepository) => Promise): Promise; close(): void; }