Port add_proposal, supersede_proposal, to_dict name-preserving into the existing Rust crate + 3 FFI twins (proposal_id facade-minted, passed in — intent_id law). Truth +8 residue rows under a uuid4 rig (gen x2 identical); battery residue_parity_battery 8/8; live parity 100% (scripts/ check_ci_parity.py: 5/5 dual-pin resolve scenarios, 8/8 live residue rows); clippy -D warnings clean; Python 24/24 both pins. Audit: 13/16 -> 16/16 FULL RUST.
338 lines
16 KiB
Python
338 lines
16 KiB
Python
#!/usr/bin/env python3
|
|
"""Freeze construction_intent oracle truth for the Rust port battery
|
|
(dichotomy wave #2479 tranche, batch: construction_intent).
|
|
|
|
Exercises EVERY branch of resolve_construction_intent (negation, request
|
|
modals, interrogative structure, bare approval, approval idiom,
|
|
affirmation+demonstrative, imperative+demonstrative, option referents,
|
|
recency tie-break, stale proposals, reference revival, relative-that,
|
|
demand fallthrough, creation-verb standalone, consequence + constraint
|
|
capture) plus the is_question / imperative_verb signal helpers.
|
|
|
|
Output: /tmp/ci_truth.json — replayed VERBATIM by
|
|
src/rust/construction_intent/src/branch_battery.rs.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
os.environ["RUNE_CI_CORE"] = "python" # freeze the ORACLE, never the kernel
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
|
|
|
from rune import construction_intent as cint # noqa: E402
|
|
|
|
|
|
def ctx(turn=0, turns=None, props=None, project=None, task=None):
|
|
c = cint.ConversationContext()
|
|
c.turn = turn
|
|
c.recent_turns = [dict(t) for t in (turns or [])]
|
|
c.pending_proposals = [cint.Proposal(**p) for p in (props or [])]
|
|
c.active_project = project
|
|
c.active_task_id = task
|
|
return c
|
|
|
|
|
|
def snapshot(c: cint.ConversationContext) -> dict:
|
|
return {
|
|
"turn": c.turn,
|
|
"recent_turns": [dict(t) for t in c.recent_turns],
|
|
"pending_proposals": [
|
|
{"proposal_id": p.proposal_id, "summary": p.summary,
|
|
"created_turn": p.created_turn, "superseded": p.superseded}
|
|
for p in c.pending_proposals],
|
|
"active_project": c.active_project,
|
|
"active_task_id": c.active_task_id,
|
|
}
|
|
|
|
|
|
def run(name, text, c, origin=None):
|
|
before = snapshot(c)
|
|
intent = cint.resolve_construction_intent(text, c, origin_context_id=origin)
|
|
d = intent.to_dict()
|
|
d.pop("intent_id") # uuid-random by design; the facade mints it
|
|
return {
|
|
"name": name,
|
|
"input": {"text": text, "origin_context_id": origin,
|
|
"context": before},
|
|
"expected": d,
|
|
"post_context": snapshot(c),
|
|
}
|
|
|
|
|
|
P1 = {"proposal_id": "prop-aaa11111", "summary": "add retry queue with backoff",
|
|
"created_turn": 3, "superseded": False}
|
|
P2 = {"proposal_id": "prop-bbb22222", "summary": "ship the metrics dashboard",
|
|
"created_turn": 4, "superseded": False}
|
|
P3 = {"proposal_id": "prop-ccc33333", "summary": "replace the auth subsystem",
|
|
"created_turn": 5, "superseded": False}
|
|
POLD = {"proposal_id": "prop-olddd01", "summary": "add retry queue with backoff",
|
|
"created_turn": 10, "superseded": False}
|
|
|
|
cases = []
|
|
|
|
# ── 0. negation frame ────────────────────────────────────────────────────
|
|
cases.append(run("negation-blocks", "don't build that yet",
|
|
ctx(project="rune")))
|
|
cases.append(run("negation-stop-never", "stop — never migrate the schema",
|
|
ctx(project="rune",
|
|
turns=[{"role": "user", "text": "never touch the WAL",
|
|
"turn": 1}])))
|
|
|
|
# ── 1a. request modals ───────────────────────────────────────────────────
|
|
cases.append(run("modal-authorizes-proposal", "can you fix that?",
|
|
ctx(turn=6, props=[dict(P1)])))
|
|
cases.append(run("modal-target-project", "could you add the export flag?",
|
|
ctx(project="rune")))
|
|
cases.append(run("modal-no-target", "would you wire the broker?", ctx()))
|
|
cases.append(run("modal-info-opener-wins", "how would you fix that?",
|
|
ctx(turn=6, props=[dict(P1)])))
|
|
cases.append(run("modal-please-remove", "please remove the old cache",
|
|
ctx(project="rune")))
|
|
|
|
# ── 1. interrogative structure ───────────────────────────────────────────
|
|
cases.append(run("question-plain", "what time is it?", ctx(project="rune")))
|
|
cases.append(run("question-analysis", "do you think the API needs improvement?",
|
|
ctx(project="rune")))
|
|
cases.append(run("question-how-build", "How would you build this?",
|
|
ctx(project="rune")))
|
|
cases.append(run("question-constraints-not-captured", "what time is it?",
|
|
ctx(project="rune", turns=[
|
|
{"role": "user", "text": "never store raw tokens", "turn": 2},
|
|
{"role": "user", "text": "must not break the CLI", "turn": 3},
|
|
])))
|
|
|
|
# ── 2. authorization paths ───────────────────────────────────────────────
|
|
cases.append(run("bare-approval", "go ahead",
|
|
ctx(turn=6, props=[dict(P1)], project="rune")))
|
|
cases.append(run("approval-idiom-ship-it", "yes, ship it",
|
|
ctx(turn=6, props=[dict(P2)])))
|
|
cases.append(run("affirmation-demonstrative", "yes, that one",
|
|
ctx(turn=6, props=[dict(P2)])))
|
|
cases.append(run("imperative-demonstrative", "build that",
|
|
ctx(turn=6, props=[dict(P1)])))
|
|
cases.append(run("bare-approval-lgtm", "lgtm", ctx(turn=6, props=[dict(P3)])))
|
|
cases.append(run("bare-approval-approved", "approved",
|
|
ctx(turn=6, props=[dict(P1)])))
|
|
cases.append(run("do-that-period", "Do that.", ctx()))
|
|
cases.append(run("approval-no-referent", "ok", ctx(project=None)))
|
|
cases.append(run("approval-stale-only", "go ahead",
|
|
ctx(turn=14, props=[dict(POLD)])))
|
|
cases.append(run("approval-stale-imperative", "go ahead and build the parser",
|
|
ctx(turn=14, props=[dict(POLD)])))
|
|
cases.append(run("stale-revived-by-reference", "go ahead with the backoff queue",
|
|
ctx(turn=14, props=[dict(POLD)])))
|
|
cases.append(run("ambiguous-two-proposals", "go ahead",
|
|
ctx(turn=6, props=[dict(P1), dict(P2)])))
|
|
cases.append(run("recency-decisive", "go ahead",
|
|
ctx(turn=8, props=[dict(P1), dict(P2, created_turn=7)])))
|
|
cases.append(run("option-second", "the second one, ship it",
|
|
ctx(turn=6, props=[dict(P1), dict(P2)])))
|
|
cases.append(run("option-latter", "the latter works for me",
|
|
ctx(turn=6, props=[dict(P1), dict(P2), dict(P3)])))
|
|
cases.append(run("option-former", "the former is fine",
|
|
ctx(turn=6, props=[dict(P1), dict(P2)])))
|
|
cases.append(run("option-out-of-range", "the third option",
|
|
ctx(turn=6, props=[dict(P1), dict(P2)])))
|
|
cases.append(run("option-other", "the other approach is better, go ahead",
|
|
ctx(turn=6, props=[dict(P1), dict(P2)])))
|
|
cases.append(run("relative-that-no-referent", "the proposal that you suggested",
|
|
ctx(turn=6, props=[dict(P1)])))
|
|
cases.append(run("relative-that-imperative-target",
|
|
"build the thing that you suggested", ctx(project="rune")))
|
|
cases.append(run("idiom-approval-target", "yes, build that",
|
|
ctx(project="rune")))
|
|
cases.append(run("creation-standalone-idiom", "yes, write me a new config parser",
|
|
ctx()))
|
|
cases.append(run("ambiguous-probe-summaries", "go ahead",
|
|
ctx(turn=6, props=[dict(P1), dict(P3)])))
|
|
|
|
# ── 3. explicit imperative demands ───────────────────────────────────────
|
|
cases.append(run("imperative-target", "fix the flaky lease test",
|
|
ctx(project="rune")))
|
|
cases.append(run("imperative-no-target", "fix the flaky lease test", ctx()))
|
|
cases.append(run("imperative-creation-article", "build me a program", ctx()))
|
|
cases.append(run("imperative-creation-no-target", "refactor the scheduler module",
|
|
ctx()))
|
|
cases.append(run("imperative-idiom-strip", "go ahead and then build the indexer",
|
|
ctx(project="rune")))
|
|
cases.append(run("imperative-please-extend", "please extend the report schema",
|
|
ctx(project="rune")))
|
|
|
|
# ── 4. default discussion ────────────────────────────────────────────────
|
|
cases.append(run("default-discussion", "the weather is nice", ctx(project="rune")))
|
|
|
|
# ── consequence levels ───────────────────────────────────────────────────
|
|
cases.append(run("consequence-high", "migrate the auth subsystem to the new provider",
|
|
ctx(project="rune")))
|
|
cases.append(run("consequence-medium", "port the module", ctx(project="rune")))
|
|
cases.append(run("consequence-low", "fix the typo in the README",
|
|
ctx(project="rune")))
|
|
|
|
# ── constraints capture ──────────────────────────────────────────────────
|
|
cases.append(run("constraints-captured", "add the export flag",
|
|
ctx(project="rune", turns=[
|
|
{"role": "user", "text": "no hardcoded endpoints", "turn": 2},
|
|
{"role": "assistant", "text": "understood", "turn": 3},
|
|
{"role": "user", "text": "and never store raw tokens", "turn": 4},
|
|
{"role": "user", "text": "must not break the CLI", "turn": 5},
|
|
{"role": "user", "text": "window filler A", "turn": 6},
|
|
{"role": "user", "text": "window filler B", "turn": 7},
|
|
{"role": "user", "text": "dropped: no hardcoded paths", "turn": 8},
|
|
])))
|
|
|
|
# ── stale gap boundary ───────────────────────────────────────────────────
|
|
cases.append(run("stale-gap-exactly-two", "go ahead",
|
|
ctx(turn=6, props=[dict(P1, created_turn=4)])))
|
|
cases.append(run("stale-gap-three-revived", "go ahead with the retry queue",
|
|
ctx(turn=6, props=[dict(P1, created_turn=3)])))
|
|
|
|
# ── superseded proposals are invisible ───────────────────────────────────
|
|
cases.append(run("superseded-invisible", "go ahead",
|
|
ctx(turn=6, props=[dict(P1, superseded=True)])))
|
|
|
|
# ── origin_context_id round-trip ─────────────────────────────────────────
|
|
cases.append(run("origin-roundtrip", "fix the flaky lease test",
|
|
ctx(project="rune"), origin="ctx-12345"))
|
|
|
|
# ── signal helpers ───────────────────────────────────────────────────────
|
|
is_question_cases = [
|
|
["How would you build this?", True],
|
|
["what time is it?", True],
|
|
["Build me a program", False],
|
|
["The weather is nice", False],
|
|
["replace the old widget", False],
|
|
["shipping it today?", True],
|
|
["remove it?", False],
|
|
["do we ship tonight?", True],
|
|
["did the deploy finish?", True],
|
|
["go ahead?", True],
|
|
]
|
|
imperative_cases = [
|
|
["Build me a program", "build"],
|
|
["please implement X now", "implement"],
|
|
["go ahead and fix the bug", "fix"],
|
|
["go ahead and then build the indexer", "build"],
|
|
[" Build something", "build"],
|
|
["How would you build this?", None],
|
|
["The weather is nice", None],
|
|
["PORT the module", "port"],
|
|
]
|
|
|
|
truth = {
|
|
"frozen": "construction_intent resolve_construction_intent + signal helpers",
|
|
"oracle": "src/rune/construction_intent.py",
|
|
"note": "intent_id popped (uuid-random; facade mints it). Contexts are "
|
|
"PRE-mutation; the facade advances next_turn/record_turn before "
|
|
"delegation, so the Rust kernel receives the POST-mutation state.",
|
|
"resolve": cases,
|
|
"is_question": is_question_cases,
|
|
"imperative_verb": imperative_cases,
|
|
}
|
|
|
|
# ── residue surface (literal-100% sweep L1, 2026-10-15) ──────────────────
|
|
# add_proposal / supersede_proposal / to_dict observed on the live oracle.
|
|
# uuid4 rig: proposal ids are pinned so regeneration is byte-identical
|
|
# (the facade mints real uuids at runtime; the kernel takes the id in).
|
|
|
|
import types # noqa: E402
|
|
|
|
|
|
class _FixedUuid:
|
|
def __init__(self, hexstr):
|
|
self.hex = hexstr
|
|
|
|
|
|
_id_seq = iter(["a1b2c3d4", "e5f6a7b8", "90abcdef"])
|
|
|
|
|
|
def _next_uuid():
|
|
return _FixedUuid(next(_id_seq))
|
|
|
|
|
|
cint.uuid = types.SimpleNamespace(uuid4=_next_uuid)
|
|
|
|
residue = []
|
|
|
|
|
|
def residue_row(name, fn, args, expected):
|
|
residue.append({"name": name, "fn": fn, "args": args, "expected": expected})
|
|
|
|
|
|
# add_proposal: PRE context in, Proposal + POST context out
|
|
c = ctx(turn=5)
|
|
pre = snapshot(c)
|
|
p = c.add_proposal("add retry queue with backoff")
|
|
residue_row("add_proposal-empty", "add_proposal",
|
|
{"context": pre, "proposal_id": p.proposal_id,
|
|
"summary": "add retry queue with backoff"},
|
|
{"proposal": {"proposal_id": p.proposal_id,
|
|
"summary": "add retry queue with backoff",
|
|
"created_turn": 5, "superseded": False},
|
|
"context": snapshot(c)})
|
|
|
|
c = ctx(turn=6, props=[dict(P1)])
|
|
pre = snapshot(c)
|
|
p = c.add_proposal("ship the metrics dashboard")
|
|
residue_row("add_proposal-appends", "add_proposal",
|
|
{"context": pre, "proposal_id": p.proposal_id,
|
|
"summary": "ship the metrics dashboard"},
|
|
{"proposal": {"proposal_id": p.proposal_id,
|
|
"summary": "ship the metrics dashboard",
|
|
"created_turn": 6, "superseded": False},
|
|
"context": snapshot(c)})
|
|
|
|
# supersede_proposal: POST context out (return value is None)
|
|
c = ctx(turn=6, props=[dict(P1), dict(P2)])
|
|
pre = snapshot(c)
|
|
c.supersede_proposal("prop-aaa11111")
|
|
residue_row("supersede-first-of-two", "supersede_proposal",
|
|
{"context": pre, "proposal_id": "prop-aaa11111"},
|
|
{"context": snapshot(c)})
|
|
|
|
c = ctx(turn=6, props=[dict(P1, superseded=True)])
|
|
pre = snapshot(c)
|
|
c.supersede_proposal("prop-aaa11111") # already superseded stays True
|
|
residue_row("supersede-idempotent", "supersede_proposal",
|
|
{"context": pre, "proposal_id": "prop-aaa11111"},
|
|
{"context": snapshot(c)})
|
|
|
|
c = ctx(turn=6, props=[dict(P1)])
|
|
pre = snapshot(c)
|
|
c.supersede_proposal("prop-unknown1") # unknown id: no-op
|
|
residue_row("supersede-unknown-noop", "supersede_proposal",
|
|
{"context": pre, "proposal_id": "prop-unknown1"},
|
|
{"context": snapshot(c)})
|
|
|
|
# to_dict: a directly-built ConstructionIntent with unicode/nulls/lists
|
|
fixed = cint.ConstructionIntent(
|
|
intent_id="intent-fixed01", objective="résumé the ünïcode plan",
|
|
requested_effect="construct: résumé the ünïcode plan",
|
|
resolved_target="rune", resolved_referent=None, origin_context_id=None,
|
|
action_intent="ACTION", approval_state="USER_APPROVED",
|
|
confidence=0.9, ambiguity="NONE", consequence_level="HIGH",
|
|
relevant_constraints=["never store raw tokens"],
|
|
classification_evidence=["imperative construction verb: fix"],
|
|
probe_questions=[])
|
|
d = fixed.to_dict()
|
|
residue_row("to_dict-full", "to_dict", {"intent": d}, {"intent": d})
|
|
shuffled = {k: d[k] for k in reversed(list(d))}
|
|
residue_row("to_dict-shuffled", "to_dict", {"intent": shuffled}, {"intent": d})
|
|
partial = {k: v for k, v in d.items()
|
|
if k not in ("relevant_constraints", "probe_questions",
|
|
"classification_evidence", "intent_id")}
|
|
defaulted = dict(partial, intent_id="", relevant_constraints=[],
|
|
probe_questions=[], classification_evidence=[])
|
|
residue_row("to_dict-partial-defaults", "to_dict", {"intent": partial},
|
|
{"intent": defaulted})
|
|
|
|
truth["residue"] = residue
|
|
|
|
out = Path("/tmp/ci_truth.json")
|
|
out.write_text(json.dumps(truth, indent=1) + "\n")
|
|
print(f"froze {len(cases)} resolve cases + {len(is_question_cases)} is_question "
|
|
f"+ {len(imperative_cases)} imperative_verb -> {out}")
|