/**
 * Kernel Execution — types.
 *
 * Owns the contract CLI / MCP / orchestrator go through when they want to
 * actually change the repo. The execution path is deliberately linear:
 *
 *   step()   — run a mutation inside an isolated git worktree
 *   verify() — hash the changed files + optionally run verifiers
 *   merge()  — fast-forward the target branch only when verify is fresh
 *
 * The invariants live in `service.ts`; this module only declares shapes.
 */
export type RunStatus = 'succeeded' | 'failed';
export type VerifyStatus = 'passed' | 'failed';
export type MergeStatus = 'merged' | 'rejected';
/** Reasons a merge can be rejected. Keep this set small and obvious. */
export type MergeRejectedReason = 'no_verify' | 'stale_verify' | 'verify_failed' | 'merge_conflict' | 'step_not_found' | 'internal_error';
/**
 * Mutation the step-phase applies inside the isolated worktree.
 *
 * Deliberately small. Callers that need richer semantics (patches, scripts)
 * should compose these or wrap them; the kernel does not invent a DSL here.
 */
export type RunStepMutation = {
    kind: 'write_file';
    path: string;
    content: string;
} | {
    kind: 'append_file';
    path: string;
    content: string;
} | {
    kind: 'delete_file';
    path: string;
} | {
    kind: 'run_command';
    command: string;
    cwd?: string;
};
export interface RunStepRequest {
    runId: string;
    stepId: string;
    task: string;
    intent?: string;
    /** Ref to branch off of. Defaults to the repo's current HEAD. */
    baseRef?: string;
    /** Optional label (e.g. ticket id) persisted onto the worktree branch. */
    worktreeHintRef?: string;
    mutations?: RunStepMutation[];
    /** Extra attribution — caller id, agent id, ticket — recorded in ledger. */
    metadata?: Record<string, unknown>;
}
export interface RunStepResult {
    runId: string;
    stepId: string;
    status: RunStatus;
    /** Branch name created for this step (also the worktree ref). */
    worktreeRef: string;
    /** Absolute path of the checked-out worktree. */
    worktreePath: string;
    baseRef: string;
    changedFiles: string[];
    commitSha?: string;
    warnings: string[];
    ledgerEntryId: string;
    debug?: Record<string, unknown>;
}
export interface VerifierResult {
    id: string;
    status: VerifyStatus;
    output?: string;
}
export interface RunVerifyRequest {
    runId: string;
    stepId: string;
    /** If empty/omitted the verify records hashes only (no external checks). */
    verifierIds?: string[];
    metadata?: Record<string, unknown>;
}
export interface RunVerifyResult {
    verifyId: string;
    runId: string;
    stepId: string;
    status: VerifyStatus;
    verifierResults: VerifierResult[];
    /** Map of relative path → sha256. Used by merge() to detect drift. */
    verifiedFileHashes: Record<string, string>;
    warnings: string[];
    ledgerEntryId: string;
    debug?: Record<string, unknown>;
}
export interface RunMergeRequest {
    runId: string;
    stepId: string;
    /** Explicit verify pin. If omitted, the latest passed verify is used. */
    verifyId?: string;
    targetRef: string;
    reason?: string;
    metadata?: Record<string, unknown>;
}
export interface RunMergeResult {
    mergeId: string;
    runId: string;
    stepId: string;
    status: MergeStatus;
    mergedSha?: string;
    targetRef: string;
    rejectedReason?: MergeRejectedReason;
    warnings: string[];
    ledgerEntryId: string;
    debug?: Record<string, unknown>;
}
/** One append-only ledger row. Written once, never mutated in place. */
export interface LedgerEntry {
    id: string;
    timestamp: string;
    runId: string;
    op: 'step' | 'verify' | 'merge';
    status: RunStatus | VerifyStatus | MergeStatus;
    stepId?: string;
    verifyId?: string;
    mergeId?: string;
    worktreeRef?: string;
    changedFiles?: string[];
    verifiedFileHashes?: Record<string, string>;
    verifierResults?: VerifierResult[];
    warnings?: string[];
    reasons?: string[];
    /** Caller attribution (agent, ticket, operative). Not interpreted. */
    meta?: Record<string, unknown>;
}
