import { ApiClient } from "./api-client.js"; import { MergeConflictsError } from "./exit.js"; export declare function isUuid(value: string): boolean; export type WorkflowBranch = { id: string; name: string; is_default?: boolean; head_version_id?: string; } & Record; export type PullRequest = { id: string; number: number; status: string; title: string | null; source_branch_name: string; target_branch_name: string; } & Record; export type MergeConflict = { field: string; key: string; base?: unknown; source?: unknown; target?: unknown; reason: string; dependsOn?: { field: string; key: string; }; }; export type MergePreview = { mergeable: boolean; merged?: Record; conflicts: MergeConflict[]; graphErrors?: unknown[]; graphWarnings?: unknown[]; sourceHeadVersionId: string; targetHeadVersionId: string; mergeBases?: { id: string; version: string | null; }[]; }; export declare function branchesPath(workflowId: string): string; export declare function pullRequestsPath(workflowId: string): string; /** * A branch is named by its id or its name. An id that matches no branch is * still rejected here rather than passed through, so a typo fails with the * list of branches instead of a bare 404 from the API. */ export declare function findBranch(branches: WorkflowBranch[], ref: string): WorkflowBranch; export declare function listBranches(client: ApiClient, workflowId: string): Promise; export declare function resolveBranch(client: ApiClient, workflowId: string, ref: string): Promise; /** * For flags that only need the branch id: a UUID is sent as-is (one request * fewer, and the API answers 404 for an unknown one), anything else is looked * up by name. */ export declare function resolveBranchId(client: ApiClient, workflowId: string, ref: string): Promise; /** The id of the highest version matching an exact version or semver range. */ export declare function resolveVersionId(client: ApiClient, workflowId: string, version: string): Promise; export type PullRequestRef = { number: number; } | { id: string; }; /** `12`, `#12` or a pull request id. */ export declare function parsePullRequestRef(ref: string): PullRequestRef; export declare function getPullRequest(client: ApiClient, workflowId: string, ref: string): Promise; export declare const PR_STATES: readonly ["open", "merged", "closed", "all"]; export type PullRequestState = (typeof PR_STATES)[number]; export declare function filterPullRequests(prs: PullRequest[], state: PullRequestState): PullRequest[]; export declare function conflictKey(conflict: { field: string; key: string; }): string; /** * Whether a conflict can be resolved by removing the item. Single-value * fields and a schema's top-level keywords always exist, so for them `null` * would be written as a value, not mean "delete". */ export declare function canDelete(conflict: MergeConflict): boolean; export declare function describeConflict(conflict: MergeConflict): string; export declare function formatMatchHeads(preview: { sourceHeadVersionId: string; targetHeadVersionId: string; }): string; export declare function parseMatchHeads(value: string): { sourceHeadVersionId: string; targetHeadVersionId: string; }; /** The JSON `prs diff` prints: everything needed to decide and resolve. */ export declare function buildDiffOutput(pr: PullRequest, preview: MergePreview, opts?: { includeMerged?: boolean; }): Record; /** * A resolutions file to edit by hand, pre-filled with the source side of every * conflict that needs its own answer. Referential conflicts are left out: * they follow the conflict they depend on. */ export declare function buildResolutionsTemplate(preview: MergePreview): Record; export type ResolveChoice = "source" | "target" | "delete"; /** `--resolve =`; the key may contain ":" and "=". */ export declare function parseResolveFlag(value: string): { key: string; choice: ResolveChoice; }; export type ResolutionInput = { resolve?: { key: string; choice: ResolveChoice; }[]; take?: "source" | "target"; custom?: Record; }; /** * Turns per-conflict choices into the literal values the merge endpoint * expects, taken from the same preview the heads are checked against. * Precedence: --resolutions-file values, then --resolve, then --take. A * referential conflict left unanswered follows the side its driving conflict * took, as the API does - including a file value equal to one side's - and * stays unresolved when the driving one was given a value matching neither. Every conflict must end up answered, and every answer must * name a real conflict - the API would otherwise ignore a stale key silently. */ export declare function buildResolutions(conflicts: MergeConflict[], input: ResolutionInput): Record; /** * What to do next for the branch and pull request errors an agent can act on. * Returns the error unchanged when there is nothing more specific to say. */ export declare function withBranchHint(err: unknown, pr?: string): unknown; /** * The API's 409 for a merge with unanswered conflicts, restated so it says * which pull request, how many conflicts and what each one is, and gives the * exact commands that answer them. Returns undefined for any other error. */ export declare function toMergeConflictsError(err: unknown, pr: { number: number; }, workflowId: string): MergeConflictsError | undefined;