feat: Change requests against a Baseline (ADR-0006)

A caller restates a request to say how requirements have changed, naming a
completed Execution of the same Customer case as the Baseline.

- app/baseline.py reads a Baseline from its files and refuses one that
  does not exist, did not complete or belongs to another case, before
  anything runs or is recorded. A Baseline is never modified.
- Requirements carry a change (unchanged, added, changed, removed) and a
  reason. Submission is refused when a Baseline requirement disappears, an
  id is reused, or an unchanged requirement's text differs. A removed
  requirement stays on record and asks nothing downstream.
- Each Specialist starts from its delivered version; the graph and the code
  are its working copy, and the description is carried over when the
  design's shape is the same.
- app/workflows/changes.py compares versions by id and traces what each
  changed requirement reaches; anything else that changed is listed as
  unrequested. Approvals show the change for their Phase, and changes.json
  is written with the full Deliverables.
- Intake no longer starts a message read as a change: it names the
  Execution to give as the Baseline.
- A fifth evaluation case runs a request and then a change to it, with
  four checks that the change is recorded, reaches Checks, stays contained
  and costs less than its Baseline.

Tested with scripted agents only; no Change request has run with real
models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 11:38:15 +01:00
parent db28d02f56
commit 5ef434d00e
32 changed files with 1824 additions and 40 deletions

View File

@@ -53,12 +53,14 @@ from app.workflows.chain import (
unimplementable_checks,
validation_outcome,
)
from app.workflows.changes import CHANGES_FILE, change_summary, is_empty
from app.workflows.deliverables import (
DEPENDENCY_GRAPH,
PHASE_ORDER,
DeliverableKind,
dependencies_for,
)
from app.workflows.target_architecture import GRAPH_ATTACHMENT
logger = logging.getLogger(__name__)
@@ -260,7 +262,9 @@ def make_execution_nodes(
)
return finish_with("end_with_warnings", warnings=warnings)
toolbox = OrchestratorToolbox(ledger, deliverables, pending_questions)
toolbox = OrchestratorToolbox(
ledger, deliverables, pending_questions, state.get("baseline")
)
refusals = list(state.get("refusals", []))
update["refusals"] = refusals
view = TurnView(
@@ -382,6 +386,11 @@ def make_execution_nodes(
kind = DeliverableKind(task_input["kind"])
working: dict[str, Any] = dict(task_input.get("working") or {})
upstream = task_input["context"].get("dependencies") or {}
before = task_input.get("baseline")
if before and not working:
# A Change request starts from the Baseline's version, not from nothing:
# its graph, its files and its description are the working copy.
_start_from(kind, before, working, task_input.get("baseline_basis"))
source = DEPENDENCY_GRAPH[kind].working_copy
if source and source is not kind:
# The tools work on the files as they were last submitted.
@@ -440,6 +449,7 @@ def make_execution_nodes(
working=working,
library=task_input.get("library"),
review=review if submission_review else None,
baseline=before,
# With a user present, their first sight of a Deliverable comes
# before it is submitted, whatever the Specialist intends.
confirm_first=confirm_drafts
@@ -707,6 +717,8 @@ def _specialist_input(
) -> dict[str, Any]:
spec = DEPENDENCY_GRAPH[kind]
given = dependencies_for(kind, deliverables)
baseline = state.get("baseline") or None
before = (baseline or {}).get("deliverables", {}).get(kind.value)
return {
"execution_id": state["execution_id"],
# The Deliverables given as data files alone, whole, for reading on demand.
@@ -723,6 +735,12 @@ def _specialist_input(
# Whether the user has been shown a draft of this Deliverable. Answering some
# other question about it, such as what to do after it stopped, is not that.
"shown": kind.value in state.get("drafts_shown", []),
# The Baseline's version of this Deliverable, in a Change request.
"baseline": before,
# What the Baseline's version was written from, to tell whether it still stands.
"baseline_basis": spec.written_from((baseline or {}).get("deliverables"))
if baseline and spec.written_from
else None,
"context": {
"workflow_request": state["workflow_request"],
"pre_approved": bool(state.get("pre_approved")),
@@ -736,10 +754,60 @@ def _specialist_input(
state.get("working", {}).get(kind.value, {})
),
"attempt": attempt,
# Set only in a Change request: what this Execution changes, and from what.
"baseline": _baseline_context(kind, baseline, before, deliverables)
if baseline
else None,
},
}
# The solution guide is assembled afresh from the revised Deliverables, so the
# Baseline's guide, the longest document there is, is not handed back to its author.
_NOT_HANDED_BACK = {DeliverableKind.SOLUTION_GUIDE}
def _baseline_context(
kind: DeliverableKind,
baseline: Mapping[str, Any],
before: Mapping[str, Any] | None,
deliverables: Mapping[str, Mapping[str, Any]],
) -> dict[str, Any]:
summary = change_summary(baseline.get("deliverables"), deliverables)
return {
"execution_id": baseline.get("execution_id"),
"original_request": baseline.get("workflow_request"),
"deliverable": dict(before)
if before and kind not in _NOT_HANDED_BACK
else None,
# What has changed so far, upstream of this Deliverable.
"changes": None if is_empty(summary) else summary,
}
def _start_from(
kind: DeliverableKind,
before: Mapping[str, Any],
working: dict[str, Any],
basis: str | None = None,
) -> None:
"""Make the Baseline's version of a Deliverable its working copy."""
attachments = dict(before.get("attachments", {}))
spec = DEPENDENCY_GRAPH[kind]
if kind is DeliverableKind.TARGET_ARCHITECTURE and GRAPH_ATTACHMENT in attachments:
workspace.keep_graph(working, attachments[GRAPH_ATTACHMENT])
if spec.working_copy is kind:
working[workspace.FILES] = attachments
if basis:
# Kept as it stands when what it was written from is the same as before.
working[STANDING] = {
"basis": basis,
"feedback": [],
"content": before.get("content", ""),
"attachments": attachments,
}
def _outcome_record(
role: str, kind: DeliverableKind, attempt: int, outcome: Outcome
) -> dict[str, Any]:
@@ -896,6 +964,15 @@ def _write_outputs(
# submitted, or back in draft after something it depends on was reopened
"status": ledger.status(DeliverableKind(kind)).value,
}
baseline = state.get("baseline") or None
if baseline:
# What this Change request changed against its Baseline, worked out from
# the ids in the two versions' data files.
files[CHANGES_FILE] = json.dumps(
change_summary(baseline.get("deliverables"), deliverables),
indent=2,
ensure_ascii=False,
)
for name, content in files.items():
path = out_dir / name
path.parent.mkdir(parents=True, exist_ok=True)
@@ -907,12 +984,15 @@ def _write_outputs(
"session_id": state.get("session_id"),
"intent_version": state.get("intent_version"),
"workflow_request": state["workflow_request"],
# The Execution this one changes, for a Change request.
"baseline": (state.get("baseline") or {}).get("execution_id"),
"status": status,
"warnings": list(state.get("warnings", [])),
"phases": {
phase.value: ledger.phase_status(phase).value for phase in PHASE_ORDER
},
"solution_guide": GUIDE_FILENAME if guide else None,
"changes": CHANGES_FILE if baseline else None,
"deliverables": by_kind,
}
out_dir.mkdir(parents=True, exist_ok=True)