73 lines
2.7 KiB
Python
73 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import agent_runtime_manifest as runtime_manifest
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
def build_markdown_summary(health: dict[str, object]) -> str:
|
|
lines = [
|
|
"# Prompt registry healthcheck",
|
|
"",
|
|
f"- status: `{health.get('status')}`",
|
|
f"- default_prompt_version: `{health.get('default_prompt_version') or 'n/a'}`",
|
|
f"- active_prompt_version: `{health.get('active_prompt_version') or 'n/a'}`",
|
|
f"- prompt_source: `{health.get('prompt_source') or 'n/a'}`",
|
|
f"- prompt_hash: `{health.get('prompt_hash') or 'n/a'}`",
|
|
"",
|
|
"## Prompt files",
|
|
]
|
|
files = health.get("prompt_files") if isinstance(health.get("prompt_files"), list) else []
|
|
if not files:
|
|
lines.append("- no prompt files resolved")
|
|
else:
|
|
for item in files:
|
|
if not isinstance(item, dict):
|
|
continue
|
|
exists = "yes" if item.get("exists") is True else "no"
|
|
lines.append(f"- `{item.get('slot')}` `{item.get('relative_path')}` exists=`{exists}`")
|
|
|
|
failures = health.get("failures") if isinstance(health.get("failures"), list) else []
|
|
warnings = health.get("warnings") if isinstance(health.get("warnings"), list) else []
|
|
lines.extend(["", "## Failures"])
|
|
lines.extend([f"- {item}" for item in failures] if failures else ["- none"])
|
|
lines.extend(["", "## Warnings"])
|
|
lines.extend([f"- {item}" for item in warnings] if warnings else ["- none"])
|
|
return "\n".join(lines).strip() + "\n"
|
|
|
|
|
|
def build_parser() -> argparse.ArgumentParser:
|
|
parser = argparse.ArgumentParser(description="Fail-loud prompt registry healthcheck for AGENT semantic runs.")
|
|
parser.add_argument("--prompt-version", help="Override active prompt version. Defaults to backend DEFAULT_PROMPT_VERSION.")
|
|
parser.add_argument("--json", action="store_true", help="Print machine-readable JSON instead of markdown.")
|
|
parser.add_argument(
|
|
"--allow-preset-mismatch",
|
|
action="store_true",
|
|
help="Downgrade saved preset prompt-version mismatch to warning for exploratory local runs.",
|
|
)
|
|
return parser
|
|
|
|
|
|
def main() -> int:
|
|
args = build_parser().parse_args()
|
|
health = runtime_manifest.build_prompt_registry_health(
|
|
REPO_ROOT,
|
|
prompt_version=args.prompt_version,
|
|
strict_preset_match=not bool(args.allow_preset_mismatch),
|
|
)
|
|
if args.json:
|
|
print(json.dumps(health, ensure_ascii=False, indent=2))
|
|
else:
|
|
print(build_markdown_summary(health), end="")
|
|
return 0 if health.get("status") == "pass" else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|