#!/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, } 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}")