<!-- normative for harness; the measurement procedure is informative -->

# Axis 1 design brief — model-produced implementation (self-host Phase 1)

Status: **design brief**. This document specifies the patch-producing `ARTEFACT`
path that replaces the harness's `_commands_for`/`_write_script` candidate
generation (the decisive missing capability in
[self-host Phase 1](../self-host.md#phase-1-model-produced-implementation)).
It also folds in the cheap Axis 3 seed matrix. Nothing here is measured until
the exit gate runs; the gate procedure is informative.

## Scope and the seam

The experiment harness currently produces candidate code deterministically:
`_commands_for`/`_write_script` (`experiment_target.py`) write the known
solution files into `/work` at BUILD time. Axis 1 replaces that with
model-produced code: the model emits an `ARTEFACT` carrying a size-capped,
scope-validated unified diff; the trusted boundary admits it through the
existing model-output path (`model_adapter.validate_output`,
`controller.admit_model_outputs`); and the scope-gated
`WorktreeManager.create_candidate` importer applies it to the disposable
worktree instead of the scripted file write.

The seam is **the attempt executor**. A new `PatchExecutor` (`patch_executor.py`)
replaces `CommandExecutor` as the per-attempt executor. It runs in two phases:

1. **Patch phase** (model-produced): the node's model call emits the `ARTEFACT`
   (a unified diff over the node's owned scope). This is the Axis 1 capability
   — the reply decides what the candidate tree becomes.
2. **Verification phase** (deterministic, unchanged): the visible commands run
   in the sandbox over the patched tree exactly as before, and the resulting
   tree is imported into the trusted integration repository by the existing
   `WorktreeManager.create_candidate` (scope gate, commit-verification, bundle).

The trial driver's leaf loop, the arms, the four frozen target files, and the
hidden oracle are unchanged. The only harness constant that disappears is the
solution content itself (`_SOLUTION_FILES` remains as the calibration
known-good tree, never as a candidate source).

## The patch ARTEFACT boundary

A patch-producing output is an ordinary model output of `output_type`
`ARTEFACT` with body fields:

| Field | Meaning |
|---|---|
| `reference` | attempt-scoped artefact identity (`f"{attempt_id}-patch"`) |
| `path` | the patch subject path (scalar; must lie in the node's owned scope) |
| `media_type` | fixed `application/vnd.orchestrator.unified-diff` |
| `content_hash` | `sha256:` of the patch text exactly as admitted |
| `patch_text` | the unified diff, UTF-8 text |

Boundary rules, all enforced at admission (never at apply time):

- **Size cap**: `patch_text` ≤ 65 536 bytes (the existing
  `MAX_OUTPUT_BODY_BYTES` reply-boundary bound). An oversized body is stripped
  and recorded `MODEL_OUTPUT_REJECTED` before it can reach the store.
- **Scope**: `path` must satisfy `executor_protocol.path_in_scope` against the
  node's delegated `owned_scope` (`src/**`). A patch touching hidden paths
  (`.git/**`, `.orchestrator/**`, `hidden-tests/**`) is rejected at admission.
- **Hunk paths**: every file the diff touches must lie inside the same owned
  scope as `path`; the hunk headers are parsed by the trusted side and each
  target path is scope-checked. A hunk outside scope rejects the whole output
  (no partial application).
- **Form**: the trusted side parses the unified diff and refuses anything that
  is not a sequence of `---`/`+++`/`@@` headers with context/add/remove lines.
  Garbage, binary markers, and empty patches are refused before dispatch to the
  importer. (The importer is the second, independent check: it refuses to
  apply a diff that does not match its base.)
- **No git metadata**: a patch that creates or modifies `.git/**` is rejected
  (R01 — candidate content never controls trusted Git metadata or hooks).

The admitted `ARTEFACT` event records the same fields the existing
`ARTEFACT_ADMITTED` transition requires (`artefact_id`, `type`, `hash`,
`attempt_id`), with `type` = `GIT_CANDIDATE` and `hash` = the content hash
above. Provenance, authority, and input-version checks are the existing
`admit_model_outputs` path; the patch adds only the four boundary rules.

## Per-component grading

The hidden oracle's four checks are already per-component (`hidden-parse`,
`hidden-render`, `hidden-report-format`, `hidden-report-emit`, each bound to one
root acceptance criterion). Axis 1 keeps that manifest unchanged and grades
the model-produced tree with it — the tree is just no longer written by the
harness.

Partial progress is therefore already measurable: `OracleGrade.effective`
per check, `verified_progress` (mandatory-check fraction) and
`criterion_verified_progress` (criterion-weighted) are the per-component
outcomes recorded on the trial. A candidate that fixes the parser but not the
emitter is `0.25`/`0.25` progress with per-check outcomes, never a flat red.

What Axis 1 adds is the **attribution of cost per component**: the patch
phase and the verification phase are separate attempts in the driver's sense
only where the model call is the priced unit. Each model call (patch attempt)
is costed by the existing `cost_report` reconciliation; the recorder's
per-node `note_busy`/`note_deterministic_action` counters plus the model
output record identify which component a priced call addressed. The
experiment-wide cap and per-trial budgets are unchanged (the patch path adds
no unbilled work).

## The two carried inputs

Two harness inputs move from the scripted constant into the model call's
prompt context — they are the only context the patch model sees:

1. **The node's task statement and owned scope** (already in the node
   contract): what must be implemented and which paths the node owns.
2. **The current tree of the node's owned scope** at the attempt's base
   commit (the parsed visible state of `src/` — the stubs the candidate must
   replace), passed as a context item with its content hash.

Hidden content never enters the prompt: `filter_context` drops HIDDEN-class
items and hidden-pattern references (`.git/**`, `.orchestrator/**`,
`hidden-tests/**`) as it does for every other model call (R08).

## Expected outcomes and honest framing

Expected: likely failure at first. The model is asked to produce a working
four-file implementation from stubs under a strict patch schema. That failure
is the measurement. The report must carry:

- per-component hidden outcomes and progress (not just red);
- retries and repair outcomes from the existing bounded repair loop;
- cost per model call and per component;
- the disclosed unmeasured metrics and the honest caveat that the target is
  small and frozen (`docs/report-milestone8-readiness.md`).

A scripted candidate success must never be relabelled as model coding
capability. In particular: the harness never injects `_SOLUTION_FILES` into a
production trial once Axis 1 is active. The calibration suite
(`calibrate_oracle`) is the only consumer of the known-good tree, and it
grades trees that no model produced.

## Exit gate (informative)

With everything else frozen (the four arms, the target, the hidden oracle, the
limits): change only the model reply and confirm the produced tree changes
therefore the hidden oracle's grade changes. A model verdict of failure
produces a failing candidate; a scripted candidate success is never relabelled
as model coding capability. Concretely, the gate is the differential: the same
`(arm, seed)` with the patch-producing client versus the pre-Axis-1 scripted
client yields different `oracle_outcomes` for at least one component, with the
changed component identified.

## Axis 3 (folded)

The cheap seed matrix folds in here: add seeds 1005–1012 (eight `NORMAL`
trials) to widen the denominator so per-component progress has a sample, not a
single data point. Cap scales linearly with the number of trials
(`trials × (MODEL_COST + PER_ATTEMPT_COMMITMENT)`), so the frozen experiment
limits and the owner cap are recomputed for the larger matrix before the run.
No additional arms, no new oracle behaviour.

## Invariants

These hold across the patch path exactly as they do across the scripted one:

- Candidate content never controls trusted Git metadata or hooks (R01).
- A run never executes against the live working tree; disposable worktrees only.
- Hidden content never reaches a prompt, a tool result, or the sandbox (R08).
- The trusted side validates form, scope, and size before anything is applied.
- Failures fail closed and are recorded; accounting preserves reported usage.
- Publication and integration have a human owner; the orchestrator proposes, a
  human merges.
