#!/usr/bin/env python3 """Write the input schemas of the package and report agents from cp1-assessment-package-agent/app/package.py INPUTS (ADR 0014, ADR 0015), each input typed as its producer declares it, plus null, with no enum. Run after changing INPUTS. Usage (from the Feature folder): python3 scripts/package_schemas.py """ import json import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "cp1-assessment-package-agent")) from app import package # noqa: E402 PRODUCER = {"discovery": "cp1-assessment-intake-agent", "plan": "cp1-assessment-planner-agent", "profiles": "cp1-cloud-readiness-profiler-agent", "risk": "cp1-migration-risk-scorer-agent", "security": "cp1-security-posture-assessment-agent", "dispositions": "cp1-disposition-tco-agent", "critic": "cp1-assessment-critic-agent", "report": "cp1-assessment-report-agent"} RUN = { "engagement_id": {"type": "string"}, "run_id": {"type": "string"}, "discovery_execution_id": {"type": ["string", "null"], "description": "Run input: the Discovery run's execution id."}, "discovery_approval_ref": {"type": ["string", "null"], "description": "Run input: the Discovery approval (ADR 0002)."}, "artifact_ids": {"type": ["array", "string", "null"], "description": "Run input: the Discovery package's artifact id(s)."}, "rate_card_document": {"type": ["string", "null"], "description": "Run input: the rate card's JSON as text (ADR 0009); only its id and sha256 are used."}, "agent_versions": {"type": "object", "additionalProperties": {"type": "string"}, "description": "Each Assessment agent's version when the workflow was built, set as a static input by scripts/build_workflow.py."}, } def schema(title: str, leave_out: set) -> dict: props = dict(RUN) for name, (part, field) in package.INPUTS.items(): if part in leave_out: continue src = json.loads((ROOT / PRODUCER[part] / "schemas" / "output.json").read_text())["properties"][field] t = src.get("type") or "string" props[name] = {"type": sorted(set([t] if isinstance(t, str) else t) | {"null"}), "description": f"{PRODUCER[part]}: {field}. Copied unchanged; no enum, so no value the producer " f"can hold is refused."} if "report" in leave_out: # the report step also reads the Discovery package (ADR 0015 addendum) props["discovery_documents"] = {"type": ["string", "null"], "description": "The parse step's text " "(p1.parsed_content): the Discovery package, read in code to say what each " "application is. The model never receives it."} return {"$schema": "https://json-schema.org/draft/2020-12/schema", "title": title, "type": "object", "required": ["engagement_id", "run_id"], "properties": props} for folder, title, leave_out in (("cp1-assessment-package-agent", "Assessment package inputs", set()), ("cp1-assessment-report-agent", "Assessment report inputs", {"report"})): (ROOT / folder / "schemas" / "input.json").write_text(json.dumps(schema(title, leave_out), indent=2, ensure_ascii=False) + "\n") print(f"wrote {folder}/schemas/input.json")