import { type Resource } from "../resources/store.js"; import { type JobFrontmatterPatch } from "./frontmatter.js"; export interface JobResourceEdit { /** The snapshot the edit was computed from. */ resource: Resource; /** * Fields for the file the current attempt writes from. Called per attempt so * derived and reset fields follow the file the edit actually lands on * instead of reusing the first snapshot's decisions. */ fields: (baseContent: string) => JobFrontmatterPatch; /** Replaces the instructions body when provided. */ body?: string; /** * Re-checks the editor's permission against a retry's file before it is * written. The first attempt already ran the caller's authorization. */ revalidate?: (base: Resource) => Promise; /** Compare-and-swap attempts before the edit reports a conflict. */ attempts?: number; } export type JobResourceEditResult = { ok: true; resource: Resource; replacedContent: string; } | { ok: false; reason: "missing" | "replaced" | "conflict" | "unauthorized"; }; /** * Applies an owner's edit without reverting execution state a scheduler or * runner wrote after this edit was read. The first write is a compare-and-swap * against the exact snapshot the edit was built from; a conflict re-checks * permission, re-applies the edit to the latest content, and retries, so the * other writer's run state (and the completed run's outcome) survives while the * user's fields still land. Reports `missing` when the file is gone, `replaced` * when a different resource now owns the path, `unauthorized` when the editor * lost permission over the retry's file, and `conflict` when it kept changing. */ export declare function applyJobResourceEdit(input: JobResourceEdit): Promise;