feat(explore): --plan-review gjoer "be om svar, bruke svarene" naabar fra CLI (F4, ORDRE 20260825T133139Z)
F4 fra misjonsreviewen: begge operatorflatene nektet enable_plan_review, og eneste doer var
explore(..., plan_reviewer=...) i bibliotek-APIet. Maalbildets HITL-loop var dermed unaabar for
enhver som ikke importerte pakka. Reviewens tre fil:linje-paastander ble verifisert mot kilden foer
bygging og stemte.
Flate: CLI. `--plan-review` bygger en terminal_plan_reviewer() og gir den til den UENDREDE sloeyfa.
Operatoren vises planen og svarer "approve" eller "revise <hva>"; en revisjon gaar tilbake til
manageren, som replanlegger og spoer IGJEN om den NYE planen.
Gaten er den ANDRE halvdelen av setningen. En doer som printer planen, leser linja og kaster den
bestaar "operatoren ble spurt" og feiler maalbildet -- repoets vakuoes-gate-klasse. T1 er derfor
test_explore_loadbearing sin T15 loeftet til CLI-niva og er ROED mot en alltid-godkjenn-reviewer.
Vitnet er {run_id}-exploration.json (skrevet fra en finally), ikke skrapet stdout.
Fail-closed paa operatorens egen input: alt utenfor vokabularet spoerres paa nytt, og EOF raiser
PlanReviewInputError -- stillhet er aldri en signatur.
Fire nekter ved navn, hvorav to lukket et stille dropp ingen test dekket: report_forbidden (report-
modus returnerer FOER hver utforsknings-nekt) og portefoelje-partisjonen. De to konfig-avhengige
nektene deler tokenet enable_plan_review og har derfor ulik saertekst; den eksisterende testen
asserterte paa det delte tokenet og er rettet (oekt-57-mutasjonen, niende gang).
Hosting nekter fortsatt -- reviewen er synkron og ville blokkert bade HTTP-requesten og event-loekka
som svarer /readiness -- men meldingen navngir na CLI-doeren i stedet for aa paasta at biblioteket er
den eneste.
Mid-loep-spoersmaal er IKKE bygget, og fravaeret er MAALT: _magentic.py har noeyaktig ETT
ctx.request_info (:1044, plan review) i hele modulen. Reviewens "kun plan-review FOER loepet" er
derimot upresist -- samme forespoersel fyrer ogsaa ved re-plan etter en stall.
Load-bearing MAALT (tests/test_plan_review_cli_door_loadbearing.py, 12 tester), elleve mutasjoner
alle roede mot HELE suiten + groenn kontroll 1040/5 og golden demo-transcript.stdout BYTE-UENDRET
(ea8c534773acdbe41ae68f2c55724d69aaf8be4f).
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LtMDsh2zfp4Bmw8KGJ4aLD
This commit is contained in:
parent
444fea7e94
commit
84e8de8679
7 changed files with 612 additions and 17 deletions
|
|
@ -24,10 +24,11 @@ This module imports ``agent_framework.orchestrations`` and therefore may never b
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
from collections.abc import Callable, Mapping, Sequence
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Any, Final, Literal
|
||||
from typing import Any, Final, Literal, TextIO
|
||||
|
||||
from agent_framework import Agent, BaseChatClient, FunctionTool, tool
|
||||
from agent_framework.orchestrations import (
|
||||
|
|
@ -363,6 +364,80 @@ class PlanReviewDecision:
|
|||
PlanReviewer = Callable[[PlanReviewRequest], PlanReviewDecision]
|
||||
|
||||
|
||||
class PlanReviewInputError(ExplorationError):
|
||||
"""A terminal plan review was left without an answer: the input ended mid-review.
|
||||
|
||||
A distinct type rather than a distinguishing message, for the reason ``_classify_stop`` reads
|
||||
counts instead of the termination prose: a caller deciding what happened should never have to
|
||||
match wording. It is an ``ExplorationError`` (a ``RuntimeError``) because the run FAILED — the
|
||||
caller's argv was fine and the loop had already started spending; the same channel an
|
||||
unreadable marked hypothesis leaves by.
|
||||
"""
|
||||
|
||||
|
||||
#: The closed answer vocabulary of the terminal door. Two words, matched structurally.
|
||||
_APPROVE_ANSWER: Final = "approve"
|
||||
_REVISE_ANSWER: Final = "revise"
|
||||
|
||||
|
||||
def terminal_plan_reviewer(
|
||||
*, stream_in: TextIO | None = None, stream_out: TextIO | None = None
|
||||
) -> PlanReviewer:
|
||||
"""A ``PlanReviewer`` that asks the operator at a terminal and reads their typed answer.
|
||||
|
||||
This is the door that makes målbilde §3's "still spørsmål, be om svar, bruke svarene" reachable
|
||||
without importing the package (F4): ``run.py``'s ``--plan-review`` builds one of these and
|
||||
hands it to ``explore()``. Blocking is not an oversight — ``explore()`` calls the reviewer
|
||||
synchronously (it is not awaited), so the loop waits on the human exactly as the ``PlanReviewer``
|
||||
contract says. That is also the reason the hosted surface keeps refusing the review: there,
|
||||
blocking the reviewer would block the event loop that answers ``/readiness``.
|
||||
|
||||
**The streams are resolved at CALL time, not here** (the ``shared_root()`` idiom): a factory
|
||||
that captured ``sys.stdin`` at construction could not be driven by a caller — or a test — that
|
||||
replaces the stream afterwards, and the only way left to exercise the door would be a
|
||||
subprocess.
|
||||
|
||||
**Fail-closed on the operator's own input.** ``approve`` signs off; ``revise <what to change>``
|
||||
sends the words back to the manager. Anything else — a blank line, a typo, a bare ``revise`` —
|
||||
is asked AGAIN, never taken as a decision. End of input raises ``PlanReviewInputError``:
|
||||
reading silence as approval would let an autonomous loop run on a plan no human signed, and do
|
||||
it invisibly. Validation, NEVER repair (the ``write_concept_file`` rule).
|
||||
"""
|
||||
|
||||
def review(request: PlanReviewRequest) -> PlanReviewDecision:
|
||||
source = sys.stdin if stream_in is None else stream_in
|
||||
sink = sys.stdout if stream_out is None else stream_out
|
||||
stalled = " (a RE-PLAN after a stall)" if request.is_stalled else ""
|
||||
print(f"\nPLAN REVIEW #{request.index + 1}{stalled}", file=sink)
|
||||
print("--- the plan the exploration would run ---", file=sink)
|
||||
print(request.plan, file=sink)
|
||||
if request.current_progress.strip():
|
||||
print("--- progress so far ---", file=sink)
|
||||
print(request.current_progress, file=sink)
|
||||
while True:
|
||||
print(
|
||||
f'Answer "{_APPROVE_ANSWER}" to sign it off, '
|
||||
f'or "{_REVISE_ANSWER} <what to change>": ',
|
||||
file=sink,
|
||||
)
|
||||
sink.flush()
|
||||
line = source.readline()
|
||||
if line == "":
|
||||
raise PlanReviewInputError(
|
||||
"the plan review reached end of input without an answer. Silence is not a "
|
||||
"sign-off: the exploration will not run a plan nobody approved"
|
||||
)
|
||||
answer = line.strip()
|
||||
if answer == _APPROVE_ANSWER:
|
||||
return PlanReviewDecision.approve()
|
||||
verb, _, feedback = answer.partition(" ")
|
||||
if verb == _REVISE_ANSWER and feedback.strip():
|
||||
return PlanReviewDecision.revise(feedback.strip())
|
||||
print(f"Not an answer: {answer!r}.", file=sink)
|
||||
|
||||
return review
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------
|
||||
# The tools. Level 1 of the three-guarantee table: real computation, ADVISORY verdicts.
|
||||
# ---------------------------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue