/** * The PROFILE-injected `RepairOracle` closure for the leader's single-agent self-repair loop * (`runRepairLoop`, core [ref] / D1). See `sema-internal server/docs/LEADER-REPAIRLOOP-INTEGRATION.md` (§3.1 + the authoritative * §10 corrected layer). The closure GRADES a worker's candidate in an ISOLATED grader env (the reused * integration sandbox, distinct from the worker env) and maps the result to a core `OracleResult`. core only * fixes the `OracleResult` shape + the read-only/identity contract; the composition lives HERE so the core type * never grows a discriminated union. * * Hardened by the cross-review round (§10): * - §10.1 HERMETIC grade: the grader tree is reset to a clean base (`git reset --hard && git clean * -fdx`) BEFORE applying the worker's LATEST full `base..HEAD` diff each call — so a 2nd/3rd attempt never * applies cumulatively onto an already-applied tree (the BROKEN finding). The diff is recomputed fresh every * call (never a stale cached diff — verify.ts:328 BUG5). * - flaky: the gate is re-isolated K times on a green-looking verdict; a disagreement is reported `flaky:true` * and core's `terminalForTier` provably refuses to project it to a passing terminal. * - §10.9 DE-CORRELATION: the L3 judge can only contribute a CLEARING tier when the verifier model is PROVABLY * distinct from the generator — and the closure CANNOT resolve roles→models itself (that happens inside * `Runner.runTask` after the closure returns), so the WIRE resolves both ids and passes them in; the closure * downgrades to `l3_judge_advisory` when they are equal. v1 ships L3 OFF (`cfg.l3` unset) → L2 `trusted_hidden` * is the sole clearer and `terminalForTier` caps every PASS at `candidate_only`. Wiring the actual * `verifyCompleted` invocation is a future enable: it needs the worker's `TaskResult` threaded to the oracle * (core passes only the report `evidence` today), so it is deliberately NOT invoked here. * * The grader topology (graderEnv = the reused integration sandbox, oracle seeded ONLY there, worker env distinct) * means the worker can never read the oracle; for SAFE-tier `candidate_only` the bare `graderEnv !== workerEnv` * identity check is sufficient, so the caller OMITS `immutableOraclePaths` (the structural bash write-probe is * vacuous across distinct sandboxes and matters only for the mandate-OFF auto-accept path — §10.2). */ import { type ExecStep, type OracleTier, type RepairOracle } from "@sema-agent/core"; /** A worker's latest diff, pulled fresh from ITS env (the same `PullDiffResult` shape as `diffout.ts`). */ export type WorkerDiff = { ok: true; patch: string; } | { ok: false; error: string; }; export interface RepairOracleCfg { /** Pull the worker's LATEST full `base..HEAD` diff from its own env (recomputed every grade — §10.1). */ pullWorkerDiff: () => Promise; /** Write a file into the GRADER env (the wire binds this to the integration sandbox's `writeFile`). */ graderWriteFile: (path: string, content: string) => Promise; /** Repo dir inside the grader (e.g. `/repo`). */ graderRepoDir: string; /** The grader's CLEAN base rev — `git rev-parse HEAD` taken right after seed + oracle-inject (`merge.ts:137` * pattern). The §10.1 hermetic reset target; the grade always runs base→latest, never cumulative. */ integBase: string; /** TRUSTED, spec-derived oracle steps (the hidden-oracle `testCmd` [+ `measureCmd`]) run in the grader. MUST * NOT be worker-authored (the security contract of `runExecGate` — exec-gate.ts header). */ oracleSteps: ExecStep[]; /** The tier to assign on a PASS (control-plane data, never agent-visible): `trusted_hidden` iff the steps run * an oracleFiles-backed hidden held-out oracle; `property_harness_weak` for a compile-only gate; `none` if * there is no usable oracle. */ passTier: OracleTier; /** K re-isolations to settle a flaky verdict (`LEADER_ORACLE_FLAKY_K`, default 2). */ flakyK?: number; /** Optional L3 de-correlation gate (§10.9). When the leader runs a distinct verifier model, the wire resolves * both ids and passes them; a self-certifying pair (`verifierModelId === generatorModelId`) downgrades a PASS * to `l3_judge_advisory` (advisory never clears). Unset in v1 (L3 off → the L2 tier stands). */ l3?: { generatorModelId: string; verifierModelId: string; }; /** fork1.2 — paths the candidate patch must NOT touch (the seeded hidden-oracle / test paths). * The §10.2 factory lane OMITs the engine's path-level probe, so a patch that EDITS the grader's oracle could * rewrite the grade and get rubber-stamped as `candidate_only`. A patch touching one of these is REFUSED * as `needs_human_oracle` (surfaced for a human, never a silent candidate). Matched by exact path or subtree. */ oraclePaths?: string[]; /** 🔴 council 2026-06-17 — the seeded hidden-oracle files (path + content). The hermetic `git clean -fdx` * DELETES them (they are untracked/ignored, not committed at `integBase`), so they MUST be RE-INJECTED after * the worker patch is applied — both to restore the oracle the `clean` wiped AND to overwrite any file the * patch placed at an oracle path (defence-in-depth with `oraclePaths`). Without this the gate runs against NO * oracle (or a worker-substituted one) and `trusted_hidden` is a false label. Empty when grading is a pure * inline `testCmd` with no seeded files (then there is nothing for `clean` to wipe). */ oracleFiles?: Array<{ path: string; content: string; }>; /** fork2.2 — report the EXACT bytes that were graded (the diff + its hash) so the caller binds * the SURFACED candidate to the graded artifact (a human reviews the bytes that produced the verdict, not a * re-pulled diff that may differ). Isomorphic to core's boundInputHash: "grade/review the thing you ship". */ onGraded?: (info: { diff: string; hash: string; passed: boolean; }) => void; log?: (event: string, x?: Record) => void; } /** * Build the `RepairOracle` closure. The returned `(graderEnv, evidence) => OracleResult` is what the leader * passes as `RepairLoopConfig.oracle`. `evidence` (the worker's report text) is intentionally unused — the * closure recomputes the candidate diff from the worker env each call (§10.1). */ export declare function mkRepairOracle(cfg: RepairOracleCfg): RepairOracle; //# sourceMappingURL=repair-oracle.d.ts.map