Files
Jonathan Boniface 9e503885cc ALZ-F01 Discovery: package step, value scorecard, application grouping, cases
- New cp1-discovery-package-agent (ADR 0020): one package per reviewed run, every part
  hashed (sha256 over canonical JSON), with a manifest and a value scorecard.
- Applications grouped CMDB -> tag -> resource group with a judged model fallback (ADR 0021):
  CMDB 0.7.0 carries ownership, dependency mapping 0.6.0 groups, report 0.9.0 shows them.
- Critic 0.6.1 accepts the producers' enums; build_workflow.py refuses a consumer enum
  narrower than its producer's.
- Code hooks, sub-agents and tests for the inventory, CMDB, dependency, planner and critic
  agents; the report and Well-Architected review agents; ADRs 0012-0021.
- Workflow cases with value bars and run limits; run evaluation and usage collection scripts;
  the run context template and the field-by-field review for ADR 0016.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 22:13:25 +00:00

63 lines
3.5 KiB
Python

"""The live path end to end: which uploads to read, normalise them, list the scope, reconcile (ADR 0018)."""
from __future__ import annotations
from typing import Any, Awaitable, Callable, Dict, List, Tuple
from app import cmdb, reconcile
from app import run_context as rc
from app import scope as sc
Listing = Callable[[str], Awaitable[Tuple[List[Dict[str, Any]], List[str], List[str]]]]
class ScopeIncomplete(cmdb.CmdbFailed):
"""The scope couldn't be listed in full, so ghosts can't be told from resources that weren't listed."""
def list_scope(provider: str, call: sc.Call):
return sc.list_all(provider, call)
async def build(payload: Dict[str, Any], ask: cmdb.Ask, listing: Listing, batch_size: int = 25,
max_tries: int = 3, log: cmdb.Log = lambda *a, **k: None, sleep=None,
ask_relationships: cmdb.Ask = None) -> Dict[str, Any]:
gaps = {g.get("source") for g in payload.get("source_gaps") or []}
text = payload.get("source_documents") if isinstance(payload.get("source_documents"), str) else None
uploads = rc.uploads_from(text, "cmdb")
if "cmdb" in gaps or not uploads:
why = ("the plan declares no CMDB source" if "cmdb" in gaps
else "no CMDB export is listed in the run context's uploads")
return reconcile.empty(payload, f"No CMDB was read: {why}. No asset is reported as missing from a CMDB.")
kwargs = {"batch_size": batch_size, "max_tries": max_tries, "log": log}
if sleep is not None:
kwargs["sleep"] = sleep
cis, sources = await cmdb.normalise(uploads, ask, **kwargs)
rel_uploads = rc.uploads_from(text, "cmdb_relationships")
rows: List[Dict[str, Any]] = []
if rel_uploads:
rows, rel_sources = await cmdb.normalise_relationships(rel_uploads, ask_relationships or ask, **kwargs)
sources += rel_sources
relationships, dangling = cmdb.resolve(cis, rows)
items, refs, issues = await listing(payload["provider"])
if issues:
raise ScopeIncomplete("the scope could not be listed in full, so the CMDB was not reconciled: "
+ "; ".join(issues))
result = reconcile.reconcile(payload, cis, items, refs, rc.context_section(text))
injections = [x["injection_note"] for x in cis + rows if x.get("injection_detected")]
s = result["summary"]
note = (f"Read {len(cis)} CIs from {', '.join(u['name'] for u in uploads)} and reconciled them against "
f"{len(items)} listed resources and {len(payload.get('records') or [])} inventory records: "
f"{s['matched']} matched, {s['stale_attributes']} stale attributes, {s['orphans']} orphans, "
f"{s['ghosts']} ghosts. Not drift: {s['retired']} retired, {s['out_of_scope']} outside the scope, "
f"{s['unplaced']} with no cloud id or unique name match."
+ (f" {len(relationships)} relationships between CIs, {len(dangling)} dangling."
if relationships or dangling or rel_uploads else "")
+ (f" {len(injections)} rows carried text that reads as an instruction; it was not acted on."
if injections else "") + " No ITSM source was read.")
log("cmdb_reconciled", **s)
return {"report_id": f"DRIFT-{payload.get('run_id') or payload['engagement_id']}",
"engagement_id": payload["engagement_id"], "drift_items": result["drift_items"], "itsm_signals": [],
"summary": s, "injections_found": injections, "cmdb_sources": sources, "note": note,
"cis": result["ci_results"], "relationships": relationships, "dangling_relationships": dangling}