qa(frame): #000002 land — reference-frame polarity contract (D3 → ✓)

The phrase-pattern retrieval route (commit 1b8677d) closed the
RETRIEVAL side of reference-frame failure; this ticket closes
the ANSWER side.

New module aborist/qa/frame.py:
  FrameDetection dataclass (frame_kind, reference_title,
    reference_uri, confidence). Sidecar — never enters cache_key
    or governance_policy_hash.
  detect_frame(question, sources, phrase_match_roots) — heuristic
    detector. Reference-frame classification fires when:
    (a) phrase route surfaced at least one source, AND
    (b) at least one phrase-matched source is a reference work,
        determined by:
          - title parenthetical disambig (`(novel)` / `(film)` /
            `(play)` / `(franchise)` / etc.), OR
          - body sample contains ≥3 DISTINCT fiction markers
            (novel / published / protagonist / plot / ...).
    Distinct-marker count keeps the heuristic robust against a
    history article saying "novel approach" twice.

aborist/qa/query.py:
  Calls detect_frame for lattice modes only. Body sample uses the
  ARTICLE LEAD (chunk_idx=0, post-wikitext-strip) — fiction
  markers cluster in the lead on Wikipedia, not in plot chunks
  that may have been query-relevance-ranked higher.
  New policy field claim_lattice_polarity_preamble injected as a
  user-role message before the grounding_reminder when
  frame_kind == "reference". Format-string with
  {reference_title} placeholder.
  Result dict carries frame_detection (kind / title / uri /
  confidence) for renderer + bench consumption.

aborist/cli.py:
  Renderer adds a `reference frame: <title>` line when
  frame_detection.kind == "reference". Skipped for literal /
  no-phrase-route / ambiguous rows.

Live verification — Orwell case:
  PRE  : "The text does not directly state that Oceania has always
          been at war with East Asia."
  POST : "In George Orwell's dystopian novel Nineteen Eighty-Four,
          the nation of Oceania is always at war with Eastasia,
          but this is a result of propaganda and doublethink, not
          actual historical continuity. The war with Eastasia is
          a fabricated conflict to maintain control..."

Multi-frame compilation: distinguishes propaganda claim from
fictional-actual continuity, exactly the polarity contract from
the ticket §2 abstraction.

Literal queries (capital of france) unchanged — polarity preamble
only injects when frame_kind classifies as "reference".

22 new tests (19 in test_frame.py + 3 in test_cli_render.py).
Full suite: 734 passed (was 712, +22).

Directive D3 status: ½ → ✓. Ticket #000002 closed.

All seven structural directives now ✓:
  D1, D2, D5 (were ✓);
  D3 #000002, D4 #000001, D6 #000003, D7 #000005 (closed in this
  series).
This commit is contained in:
russell@unturf.com 2026-05-01 20:18:13 -04:00
parent 1dfa4636c3
commit 9ec9469c4d
No known key found for this signature in database
8 changed files with 725 additions and 23 deletions

View file

@ -296,6 +296,59 @@ def test_render_label_ungrounded_in_claim_lattice_stays_ungrounded():
assert "via claim_lattice" in out
def test_render_shows_reference_frame_notes_when_detected():
"""When frame_detection.kind == 'reference', the renderer
surfaces the named reference work so an operator can see the
substrate routed to a fictional / reference source."""
r = _result(
audit_mode="STRICT",
verifier_method="claim_lattice",
frame_detection={
"kind": "reference",
"reference_title": "Nineteen Eighty-Four",
"reference_uri": "https://en.wikipedia.org/wiki/Nineteen_Eighty-Four",
"confidence": 0.8,
},
)
out = _render_query_human(r, "has oceania always been at war with east asia")
assert "reference frame: Nineteen Eighty-Four" in out
def test_render_omits_reference_frame_notes_for_literal_query():
"""Literal-frame queries (no allusion) don't render the frame
notes line keeps the daily render clean for the common case."""
r = _result(
audit_mode="STRICT",
verifier_method="claim_lattice",
frame_detection={
"kind": "no_phrase_route",
"reference_title": None,
"reference_uri": None,
"confidence": 0.0,
},
)
out = _render_query_human(r, "what is the capital of france?")
assert "reference frame:" not in out
def test_render_omits_reference_frame_notes_for_ambiguous():
"""Ambiguous frame (phrase route fired but no clear reference
work) no frame notes line. The signal isn't strong enough
to claim a named reference."""
r = _result(
audit_mode="STRICT",
verifier_method="claim_lattice",
frame_detection={
"kind": "ambiguous",
"reference_title": None,
"reference_uri": None,
"confidence": 0.4,
},
)
out = _render_query_human(r, "some allusion-shape query")
assert "reference frame:" not in out
def test_render_label_quote_mode_keeps_audit_mode_token():
"""Quote / span / entity / paraphrase modes verify against
pinned spans, not synthesis. STRICT in quote mode IS a strong