/** * The OUT-OF-PROCESS grader plumbing for the leader × `runRepairLoop` integration * (`sema-internal server/docs/LEADER-REPAIRLOOP-INTEGRATION.md` §3.2 + the authoritative §10 layer). Two distinct consumers: * * - **R1 (single-agent oracle, §10.1)** — the `RepairOracle` closure (`repair-oracle.ts`) reuses the EXISTING * integration sandbox as its grader at ZERO extra sandbox cost. It needs only a `GraderHandle` (a writeFile + * exec bound to that sandbox via the wire's `asIntegrationEnv`/`sh` pattern) and the worker-diff source — it * grades through `runExecGate(graderEnv, steps)` itself, so it does NOT use `applyAndGrade` (the closure owns * its hermetic reset+apply inline; `repair-oracle.ts:89`). This file gives the merge path the SAME apply-and- * grade primitive so the two stay byte-consistent. * * - **R2 (measure-drives-repair, §10.4)** — the merge path (`merge.ts`, Stage-2) RE-SEEDS a single minted * grader per measure round (NOT a new microVM): `git reset --hard && git clean -fdx`, re-apply the * INTEGRATED patch, then run the trusted `measureCmd` there. The repair agent edits the merged sandbox, so the * measure must NOT run in that (possibly poisoned) sandbox — `applyAndGrade` runs it in a fresh-seeded grader. * Before re-measure, the caller mechanically checks the patch's changed-file list against an allowlist * (`changedFilesWithinAllowlist`, §10.4(ii)) — an out-of-allowlist / build-config touch denies the candidate. * * A standalone, mint-a-distinct-sandbox grader belongs to the AUTO-ACCEPT slice, which has NOT been designed or * built. v1 reuses the integration sandbox (R1) + re-seeds it (R2) instead. **There is no config key that turns * such a factory on** — an earlier revision of this header named one and shipped a `throw`-only stub beside it, * but no such key ever existed in `config.ts`, so an operator following that text set an env var that did * nothing. Both the stub and the promise were removed ([ref] 车4 件3 / staleness ledger P2-9); the auto-accept * slice, when it happens, is a new design件 that lands its factory, its wiring and its knob in one batch. * * Everything here is additive + OFF by default: nothing in this file runs unless the Stage-2 seams call it behind * `LEADER_REPAIR_LOOP` / `LEADER_MEASURE_GATES`. */ import { type ExecutionEnv, type ExecStep } from "@sema-agent/core"; /** * A grader env bound to a concrete sandbox. The wire constructs this from the integration sandbox's * `RemoteExecutionEnv` (the `asIntegrationEnv`/`sh` pattern in `wire.ts`), so `grader-env-factory.ts` never * depends on the adapter/wire module (no cycle). `env` is the core `ExecutionEnv` `runExecGate` grades in; * `writeFile` plants the candidate patch into the grader tree; `repoDir`/`integBase` are the hermetic reset * target (§10.1) — `git rev-parse HEAD` taken right after seed + oracle-inject (`merge.ts:137` pattern). */ export interface GraderHandle { /** The isolated grader env (the reused integration sandbox for R1, a fresh-minted one for the auto-accept slice). */ env: ExecutionEnv; /** Write a file into the grader tree (the wire binds this to the sandbox's `writeFile`). */ writeFile: (path: string, content: string) => Promise; /** Repo dir inside the grader (e.g. `/repo`). */ repoDir: string; /** The grader's CLEAN base rev — the hermetic reset target (§10.1). Re-applies run base→latest, never cumulative. */ integBase: string; } /** The outcome of one `applyAndGrade` round: whether the trusted steps passed + a failure trace tail (untrusted). */ export interface GradeOutcome { /** True iff the prep applied cleanly AND every trusted step ran and exited 0. */ passed: boolean; /** False when the patch failed to apply onto the clean base (an apply conflict) — distinct from a step failure. */ applied: boolean; /** Failure-output tail (untrusted worker-adjacent data; the caller delimits/sanitizes before surfacing). */ trace?: string; } /** * §10.1/§10.4 — HERMETIC apply-and-grade. Reset the grader to its clean `integBase` (`git reset --hard` + * `git clean -fdx`), apply the FULL `base→latest` `patch` (never cumulative onto an already-applied tree), then * run the TRUSTED, spec-derived `steps` (`testCmd` / `measureCmd`) there. `steps` MUST NOT be worker-authored * (the `runExecGate` security contract — exec-gate.ts header). Used by the R2 measure grader; the R1 oracle * closure performs the equivalent inline (`repair-oracle.ts`) so the single-agent and merge paths grade * identically. Never throws — an apply conflict or a step failure is a non-passing `GradeOutcome`. */ export declare function applyAndGrade(handle: GraderHandle, patch: string, steps: ExecStep[]): Promise; /** The §10.4(ii) decision: the subset of `changedFiles` that is OUT of the allowlist or hits a build-config deny. */ export declare function changedFilesOutOfAllowlist(changedFiles: string[], allowlist: string[]): string[]; /** §10.4(ii): true iff EVERY changed file is within the allowlist and none is a denied build-config path. */ export declare function changedFilesWithinAllowlist(changedFiles: string[], allowlist: string[]): boolean; //# sourceMappingURL=grader-env-factory.d.ts.map