feat(governance): implement PLAN-SPECIFICATION-AND-GOVERNANCE-STANDARD, 3-tier flexibility protocol & plan validator
This commit is contained in:
1 parent
fe33f7d8e8
commit
d526ede701
4 files changed
+271
-2
No files matched your search
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
src/hyperstitionstud_io/ci/plan_validator.py
|
||||
Plan Specification & Governance Validator (`hs-plan-lint`).
|
||||
Enforces PLAN-SPECIFICATION-AND-GOVERNANCE-STANDARD across docs/plans/{active,piecewise}/:
|
||||
1. Mandatory companion ReportLab Dark-Mode PDF (.pdf) for every active/piecewise Markdown plan (.md).
|
||||
2. Required metadata fields (Document ID, Status, Target Ecosystem Version, Target Repositories).
|
||||
3. Registration in roadmap-plan-ledger.md.
|
||||
4. Zero container host path serialization.
|
||||
5. Shorthand disambiguation compliance (<PREFIX><NN>.<DOMAIN_TAG>).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from hyperstitionstud_io.config import load_workspace_config
|
||||
|
||||
REQUIRED_METADATA_KEYS = [
|
||||
"Document ID",
|
||||
"Status",
|
||||
"Target Ecosystem Version",
|
||||
"Target Repositories",
|
||||
]
|
||||
|
||||
CONTAINER_HOST_PATH_PATTERNS = [
|
||||
re.compile(r"/home/[a-zA-Z0-9_-]+/\.hermes"),
|
||||
re.compile(r"/var/lib/docker"),
|
||||
re.compile(r"/tmp/docker"),
|
||||
]
|
||||
|
||||
|
||||
def verify_plan_specifications(workspace_root: str | Path | None = None) -> dict[str, Any]:
|
||||
cfg = load_workspace_config(workspace_root=workspace_root)
|
||||
plans_dir = cfg.knowledge_graph_dir / "docs" / "plans"
|
||||
active_dir = plans_dir / "active"
|
||||
piecewise_dir = plans_dir / "piecewise"
|
||||
|
||||
active_mds = sorted([p for p in active_dir.glob("PLAN-*.md") if p.is_file()])
|
||||
piecewise_mds = sorted([p for p in piecewise_dir.glob("PLAN-*.md") if p.is_file()])
|
||||
all_target_mds = active_mds + piecewise_mds
|
||||
|
||||
ledger_candidates = [
|
||||
Path.home() / ".hermes" / "skills" / "software-development" / "hyperstitionstudio-roadmap-and-release" / "references" / "roadmap-plan-ledger.md",
|
||||
Path("/root/.hermes/skills/software-development/hyperstitionstudio-roadmap-and-release/references/roadmap-plan-ledger.md"),
|
||||
]
|
||||
ledger_text = ""
|
||||
for lc in ledger_candidates:
|
||||
if lc.is_file():
|
||||
ledger_text = lc.read_text(encoding="utf-8")
|
||||
break
|
||||
|
||||
missing_pdfs: list[str] = []
|
||||
missing_ledger_entries: list[str] = []
|
||||
metadata_errors: list[dict[str, Any]] = []
|
||||
host_path_errors: list[dict[str, Any]] = []
|
||||
errors: list[str] = []
|
||||
|
||||
for md_p in all_target_mds:
|
||||
rel_p = md_p.relative_to(cfg.workspace_root).as_posix()
|
||||
pdf_p = md_p.with_suffix(".pdf")
|
||||
if not pdf_p.is_file():
|
||||
missing_pdfs.append(rel_p)
|
||||
|
||||
txt = md_p.read_text(encoding="utf-8")
|
||||
|
||||
# Check metadata fields
|
||||
missing_keys = []
|
||||
for key in REQUIRED_METADATA_KEYS:
|
||||
if not re.search(rf"\*\*{re.escape(key)}:\*\*", txt):
|
||||
missing_keys.append(key)
|
||||
if missing_keys:
|
||||
metadata_errors.append({"file": rel_p, "missing_keys": missing_keys})
|
||||
|
||||
# Check host path leakage
|
||||
for pat in CONTAINER_HOST_PATH_PATTERNS:
|
||||
m = pat.search(txt)
|
||||
if m:
|
||||
host_path_errors.append({"file": rel_p, "leakage": m.group(0)})
|
||||
|
||||
# Check ledger presence if ledger is found
|
||||
if ledger_text:
|
||||
plan_stem = md_p.stem
|
||||
if plan_stem not in ledger_text:
|
||||
missing_ledger_entries.append(plan_stem)
|
||||
|
||||
if missing_pdfs:
|
||||
errors.append(f"Missing companion Dark-Mode PDFs for: {', '.join(missing_pdfs)}")
|
||||
if metadata_errors:
|
||||
errors.append(f"Metadata errors: {metadata_errors}")
|
||||
if host_path_errors:
|
||||
errors.append(f"Host path leakage detected: {host_path_errors}")
|
||||
if missing_ledger_entries:
|
||||
errors.append(f"Plans missing from roadmap-plan-ledger.md: {missing_ledger_entries}")
|
||||
|
||||
return {
|
||||
"ok": len(errors) == 0,
|
||||
"active_plans_checked": len(active_mds),
|
||||
"piecewise_plans_checked": len(piecewise_mds),
|
||||
"total_plans_checked": len(all_target_mds),
|
||||
"missing_pdfs": missing_pdfs,
|
||||
"missing_ledger_entries": missing_ledger_entries,
|
||||
"metadata_errors": metadata_errors,
|
||||
"host_path_errors": host_path_errors,
|
||||
"errors": errors,
|
||||
}
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
ap = argparse.ArgumentParser(prog="hs-plan-lint", description="Validate active/piecewise architectural plans against governance standard.")
|
||||
ap.add_argument("--workspace-root", default=None, help="Root directory of hyperstitionstud.io workspace.")
|
||||
args = ap.parse_args(argv)
|
||||
|
||||
res = verify_plan_specifications(workspace_root=args.workspace_root)
|
||||
print(json.dumps(res, indent=2))
|
||||
return 0 if res["ok"] else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user