core/generate/determine/render.py
Shay 7cb826a548 feat(determine): calibrated disclosed estimation — the engine earns the right to guess (Step E)
The final AGI-spine step (A INSTRUMENT → B WIRE → C DEEPEN → D CLOSE → E ESTIMATION).
The engine may now SERVE a DISCLOSED estimate for a query it would otherwise refuse —
but only for a predicate-class that has measured itself reliable, and never as fact.

This executes the ADR-0206 §5 cognition-path widening: the bridge's LICENSE node
(reliability_gate.license_for), previously "built — not yet called from serving", is now
called. govern_response returns APPROXIMATE iff a genuine licensed Action.SERVE
LicenseDecision is passed (STRICT for every other input — so every existing serving call
site is byte-identical); shape_surface DISCLOSES the estimate as "[approximate] …".

Mechanism:
- generate/determine/estimate.py — a BLIND converse-guesser: told p(a,b), asked p(b,a),
  it commits the converse. It never reads the pack's symmetry metadata; whether the guess
  is right is MEASURED, not assumed.
- evals/determination_estimation/ — the gold lane: run_practice (sealed, ADR-0199) folds
  the converse-guesser over symmetric (sibling_of) vs directed (parent_of) cases, scored
  against the pack's graph.edge.symmetric truth (gold independent of the solver). The gate
  DISCRIMINATES: sibling_of earns SERVE (660 correct → Wilson floor 0.990046 ≥ θ_SERVE),
  parent_of does not (660 wrong → 0.0). The license is earned by VOLUME — 657 perfect
  commits is the exact θ_SERVE=0.99 threshold (656 is below).
- generate/determine/data/estimation_ledger.json — the ratified committed ledger,
  hash-verified on load (a hand-edited ledger raises RatifiedLedgerError); it IS the
  deterministic sealed-practice output (a GSM8K-style --check test pins this).
- chat/runtime.py — when a converse query is refused and the class holds a SERVE license,
  the disclosed estimate is surfaced through the bridge (gated by config.estimation_enabled,
  default OFF; only meaningful with accrue_realized_knowledge).

Invariants:
- wrong=0 by construction — an estimate is ALWAYS disclosed ([approximate]), never a silent
  commit (UNVERIFIED_POSSIBLE is never in APPROXIMATE's admissible set), and only a genuine
  ratified license widens (a forged {"licensed":True} dict / a PROPOSE license / an
  unlicensed SERVE all stay STRICT). Defense-in-depth: type-gate ∧ admissible-set ∧
  hardcoded disclosed state.
- never self-authored — ceilings stay at safe defaults (θ_SERVE=0.99); the engine cannot
  raise its own bar. The ledger is sealed practice, hash-verified.
- session/serving only — no corpus/pack/identity/proposal/vault mutation; the HITL teaching
  path is untouched. Deterministic; no clock/random.
- byte-identical for every non-E turn (the 2643 govern_response call passes no license).

Out of scope (separate ADR-0206 §5 PRs): the math-serving seam (select_self_verified,
touches the sealed metric), SITUATE (stakes), and the live FEED-BACK loop.

Verified green: smoke (90), architectural invariants (56), response_governance (321,
incl. the new license-gated widening test), the determination-estimation lane (12), and
the B/D/determine regression net. Four-lens adversarial review (disclosure/wrong=0,
calibration integrity, byte-identity, boundary/determinism): all held. Design:
docs/analysis/E-estimation-design-2026-06-06.md.
2026-06-06 13:49:07 -07:00

42 lines
1.9 KiB
Python

"""Deterministic surface rendering for a Determined answer (Step B-2) and a converse
estimate (Step E).
Turns a ``Determined`` into the user-facing string the runtime surfaces. The basis is
rendered HONESTLY: SPECULATIVE grounds (today's only case) render as "as I was told",
never "verified" — only COHERENT-admissible grounds (not yet reachable) would. D0 only
ever asserts ``answer=True``, so the surface is an affirmation; there is no fabricated
or asserted-False surface to render.
``render_estimate`` renders the base claim of a converse-guess; the ADR-0206
``shape_surface`` then DISCLOSES it with an ``[approximate]`` prefix — so the estimate is
never confused with a grounded determination.
"""
from __future__ import annotations
from generate.determine.determine import Determined
from generate.determine.estimate import ConverseEstimate
#: Predicate → surface phrase. ``member`` reads as "is a"; the relational pack
#: predicates fall back to their lemma with underscores spaced ("less_than" → "less
#: than"). Closed and deterministic; an unknown predicate still renders legibly.
_PREDICATE_PHRASE: dict[str, str] = {
"member": "is a",
}
def render_determination(d: Determined) -> str:
"""The user-facing surface for a Determined answer — deterministic, honest basis."""
phrase = _PREDICATE_PHRASE.get(d.predicate, d.predicate.replace("_", " "))
qualifier = "as I was told" if d.basis == "as_told" else "verified"
return f"Yes — {qualifier}, {d.subject} {phrase} {d.object}."
def render_estimate(e: ConverseEstimate) -> str:
"""The base claim of a converse-guess (pre-disclosure).
``shape_surface`` prefixes ``[approximate]`` — so this stays a plain claim; the
honesty marker is added by the bridge, not baked in here. Deterministic.
"""
phrase = _PREDICATE_PHRASE.get(e.predicate, e.predicate.replace("_", " "))
return f"{e.subject} {phrase} {e.object}"