---
name: reconstruct
description: "Use when a discover run's goal includes rebuilding a product behaviour (a scoring, ranking or pricing formula, a matcher, a protocol) from captured evidence, then differentially testing it against the live product. Not for describing what a product has."
---

# reconstruct: rebuild a behaviour, then prove it

Goal-gated and optional: a run that only needs to know what exists stops at the review, and a run that skips reconstruction is complete. Capture is the input; a verified, executable reconstruction is the output. The review does not grade it.

## Load triggers

| Reference | Read when |
| --- | --- |
| `references/differential-testing.md` | before building the first test, and whenever a residual appears |

| Script | Use |
| --- | --- |
| `scripts/layers.mjs` | runs frozen fixtures through layers A, B and C and prints per-layer pass rates |

## Sources and authorization

| Source | Reconstruct from | Authorization |
| --- | --- | --- |
| Observable behavior (the common case) | input-output pairs in `evidence/session/`, `evidence/wire/` and surface records | in bounds; observed behavior, never protected code |
| Open source | a `source:full` clone | in bounds |
| Owned or authorized binary | decompilation or pseudocode of a binary the user owns or may examine, with REA's static and reconstruction tools (`wire-tradecraft` skill, `references/rea.md`) | **gated:** confirm in chat, record in `_meta` |

A third-party proprietary binary is **metadata-only**: its shipped code is never decompiled or reconstructed.

## Procedure

1. Confirm the run's goal names a behavior to rebuild. Pick the source row and its authorization; write `reconstruction_source` and `authorization` before building.
2. Build v0 as executable code under `research/<target>/reconstruction/<name>/`, from the captured evidence.
3. Freeze real inputs, adversarial inputs and the product's observed outputs as re-runnable fixtures in `reconstruction/<name>/fixtures/`.
4. Open one obligation per reconstruction claim in `reconstruction/obligation-ledger.md`: claim, verifier, status (`open | closed | failed`), closing fixture.
5. Run `scripts/layers.mjs`. Measure fidelity as per-layer pass rates plus ledger closure.
6. Localise each residual to layer A or B and fix the reconstruction (`references/differential-testing.md`). Re-measure every layer after every change.
7. Repeat 5-6 until a stop condition fires, then freeze the best version, fixtures and ledger.
8. Write `06-reconstruction.md`: what was rebuilt, source and authorization, per-layer pass rates, per-iteration fidelity and fix, residuals that proved to be product findings, open obligations. Frontmatter carries `reconstruction_source: observable | open-source | owned-binary`, `authorization: <none-needed | in-chat-ref>`, `method: reconstruction-verified | inferred`, and the per-layer pass rates.

## Stop conditions

| Condition | Test | Action |
| --- | --- | --- |
| Converged | no open obligation and no layer-B residual | freeze |
| Regression | fidelity drops clearly below best | keep the best prior version, stop |
| Cap | at least 5 iterations; raise it while fidelity climbs | freeze best |

A drop caused by finding that a prior version's pass rate rested on a weak fixture is a **measurement correction, not a regression:** keep the corrected version and record the inflated one as superseded.

## Hard rules

- **Verified only by a passing differential test.** A claim is `reconstruction-verified` (`high`) **only** once every layer passes on frozen fixtures; a plausible implementation without one is `inferred` and stays an open obligation. Contradictions, residual unknowns and missing fixtures keep an obligation open or failed.
- **An obligation closes only when a verifier of authority comparable to the original observation passes.**
- **Layers are scored separately,** never as one aggregate.
- **Never tune away a residual that survives a correct layer B;** it is a finding about the target. **Never silently replicate a product bug:** implement correct behavior by default and put bug-parity behind a documented flag.
- **Read-only and free by default.** A fresh product output is a live read: cheap read-only probes with the existing session are fine; anything that spends, mutates state or needs a credential goes through the run conditions' write authorization and an explicit confirmation, **never** the auto-loop.
- **Read the ledger and fixtures yourself.** A delegated reconstruction is a report; a sub-agent's "it passes" is **never** trusted.
- **No third-party protected-code reconstruction.** Captures and reconstructions stay local; confirm before any cost or state change.
- An unverified reconstruction is **never** promoted to fact by the review or the model; the review may note it as an open obligation, not a scored defect.
