Files
gcp_solution_architecture_a…/app/customer_case.py
Jonathan Boniface e9246828b3 feat: establish the Target architecture as a graph before code
Design is now approved before any infrastructure code is written (ADR-0005).
A new target-architect Specialist produces one graph of Elements,
Relationships and Checks; the diagram is rendered from it, deployment
guidance must account for every Check, and validation gives a verdict per
Check. Requirements, components, products and recommendations carry ids in
data files, and a submission with a gap in the Requirements chain is refused.

Also in this commit:
- Customer cases group Executions, with an intent history per case
- lesson candidates are captured when an Execution ends
- evaluation gains chain, verdict, judged and interactive checks, and
  per-case thresholds
- Terraform providers are cached between checks
- the requirements analyst proposes defaults instead of asking
- the legacy-baseline case and the checks that only read it are removed
- ADR-0006 (Change requests) accepted; ADR-0004 and ADR-0007 proposed
- plans for iterations 4 to 7 under .agents/plans/

Unproven with a real model: no evaluation run has completed on this design.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 13:59:09 +01:00

106 lines
3.6 KiB
Python

"""A Customer case on disk: its intent and the history of that intent.
deliverables/cases/<customer_case>/
intent/
001.md, 002.md, ... each statement of what the customer wants, as given
history.json every statement in order, the Execution it started
and how that Execution ended
executions/<execution_id>/ what was generated for one statement
The intent is recorded when an Execution starts, so a request is on record even if
nothing was delivered for it. history.json is the index of the case.
"""
from __future__ import annotations
import json
from datetime import UTC, datetime
from pathlib import Path
from typing import Any
from app.states.execution_state import case_dir
INTENT_DIR = "intent"
HISTORY_FILENAME = "history.json"
IN_PROGRESS = "in_progress"
def intent_dir(output_root: Path, customer_case: str) -> Path:
return case_dir(output_root, customer_case) / INTENT_DIR
def read_history(output_root: Path, customer_case: str) -> dict[str, Any]:
"""The case's intent history; empty when the case has none yet."""
path = intent_dir(output_root, customer_case) / HISTORY_FILENAME
if path.is_file():
try:
history = json.loads(path.read_text(encoding="utf-8"))
if isinstance(history, dict) and isinstance(history.get("intents"), list):
return history
except ValueError:
pass
return {"customer_case": customer_case, "intents": []}
def record_intent(
output_root: Path,
customer_case: str,
*,
execution_id: str,
session_id: str,
workflow_request: str,
) -> int:
"""Record a new statement of the customer's intent and return its version."""
folder = intent_dir(output_root, customer_case)
folder.mkdir(parents=True, exist_ok=True)
history = read_history(output_root, customer_case)
version = max((item["version"] for item in history["intents"]), default=0) + 1
recorded_at = datetime.now(UTC).isoformat(timespec="seconds")
statement = f"{version:03d}.md"
(folder / statement).write_text(
f"# Intent {version}: {customer_case}\n\n"
f"- Recorded: {recorded_at}\n"
f"- Execution: `{execution_id}`\n\n"
f"## What the customer wants\n\n{workflow_request.strip()}\n",
encoding="utf-8",
)
history["intents"].append(
{
"version": version,
"recorded_at": recorded_at,
"statement": f"{INTENT_DIR}/{statement}",
"workflow_request": workflow_request,
"execution_id": execution_id,
"session_id": session_id,
"status": IN_PROGRESS,
"execution": None,
}
)
_write_history(folder, history)
return version
def close_intent(
output_root: Path,
customer_case: str,
*,
execution_id: str,
status: str,
has_files: bool,
) -> None:
"""Record how the Execution started by an intent ended, and where its files are."""
history = read_history(output_root, customer_case)
for item in history["intents"]:
if item.get("execution_id") == execution_id:
item["status"] = status
item["execution"] = f"executions/{execution_id}" if has_files else None
_write_history(intent_dir(output_root, customer_case), history)
return
def _write_history(folder: Path, history: dict[str, Any]) -> None:
folder.mkdir(parents=True, exist_ok=True)
(folder / HISTORY_FILENAME).write_text(
json.dumps(history, indent=2, ensure_ascii=False) + "\n", encoding="utf-8"
)