Files
document-haness/scripts/verify-pipeline.py
T

226 lines
8.4 KiB
Python
Executable File

#!/usr/bin/env python3
from __future__ import annotations
import argparse
from pathlib import Path
REQUIRED_PATHS = (
# 스킬 — 분석에서 게시까지
".agents/skills/analyzing-codebase-for-tech-log/SKILL.md",
".agents/skills/deriving-tech-log-root-tree/SKILL.md",
".agents/skills/deriving-tech-log-root-tree/references/decomposition-checklist.md",
".agents/skills/writing-tech-log-records/SKILL.md",
".agents/skills/writing-tech-log-records/references/root-tree-contract.md",
".agents/skills/writing-tech-log-records/references/record-kinds.md",
".agents/skills/writing-tech-log-records/references/body-syntax.md",
".agents/skills/writing-tech-log-records/references/code-tables-diagrams.md",
".agents/skills/writing-tech-log-records/references/review-checklist.md",
".agents/skills/writing-tech-log-records/references/from-ssot-to-records.md",
".agents/skills/writing-tech-log-records/references/writing-each-kind.md",
".agents/skills/rewriting-technical-prose-naturally/SKILL.md",
".agents/skills/rewriting-technical-prose-naturally/references/protected-content.md",
".agents/skills/rewriting-technical-prose-naturally/references/editorial-rules.md",
".agents/skills/writing-tech-log-records/references/explaining.md",
".agents/skills/writing-tech-log-records/references/ai-tells.md",
".agents/skills/rewriting-technical-prose-naturally/references/research-method.md",
".agents/skills/rewriting-technical-prose-naturally/scripts/check_prose.mjs",
".agents/skills/rewriting-technical-prose-naturally/scripts/style_profile.mjs",
".agents/skills/technical-visualizer/SKILL.md",
".agents/skills/refactoring-from-analysis/SKILL.md",
# 틀
"docs/_templates/state.json",
"docs/_templates/source-index.md",
"docs/_templates/root-tree.md",
"docs/_templates/analysis/00-project-overview.md",
"docs/_templates/analysis/module.md",
"docs/_templates/final/document.md",
".agents/skills/writing-tech-log-records/templates/case.md",
".agents/skills/writing-tech-log-records/templates/concept.md",
# 도구
"scripts/techviz",
"scripts/build-tech-log-tree.py",
"scripts/terminal-evidence/render_terminal.py",
"scripts/terminal-evidence/README.md",
".agents/skills/writing-tech-log-records/scripts/check_body.mjs",
)
ROOT_TREE_TOKENS = (
"PROJECT",
"TOPIC",
"├── CASE",
"├── REFERENCE",
"├── OPEN QUESTION",
"└── DECISION",
"# Node Specifications",
"readiness:",
"source:",
"classification:",
)
QUEUE_TOKENS = ("version:", "activeProject:", "projects:")
REFACTOR_QUEUE_TOKENS = ("version:", "activeItem:", "items:")
STATE_REANALYSIS_TOKENS = (
'"reanalysis"',
'"baselineRevision"',
'"targetRevision"',
'"mode"',
'"changedPaths"',
'"impactedScopes"',
)
ALLOWED_QUEUE_STATUSES = {"PENDING", "IN_PROGRESS", "COMPLETE", "REANALYZE", "BLOCKED", "SKIPPED"}
def _parse_analysis_queue(text: str):
active = None
projects = []
current = None
for raw in text.splitlines():
stripped = raw.strip()
if not stripped or stripped.startswith("#"):
continue
if raw.startswith("activeProject:"):
value = raw.split(":", 1)[1].strip().strip("\"'")
active = None if value in {"", "null", "~"} else value
continue
if stripped.startswith("- name:"):
name = stripped.split(":", 1)[1].strip().strip("\"'")
current = {"name": name, "status": None}
projects.append(current)
continue
if current is not None and stripped.startswith("status:"):
current["status"] = stripped.split(":", 1)[1].strip().strip("\"'")
return active, projects
def _verify_refactor_queue(path: Path) -> list[str]:
errors: list[str] = []
text = path.read_text(encoding="utf-8", errors="replace")
for token in REFACTOR_QUEUE_TOKENS:
if token not in text:
errors.append(f"refactor queue missing token: {token}")
return errors
def _verify_analysis_queue(path: Path) -> list[str]:
errors = []
text = path.read_text(encoding="utf-8", errors="replace")
for token in QUEUE_TOKENS:
if token not in text:
errors.append(f"analysis queue missing token: {token}")
if errors:
return errors
active, projects = _parse_analysis_queue(text)
names = [p["name"] for p in projects]
if len(names) != len(set(names)):
errors.append("analysis queue contains duplicate project names")
for project in projects:
status = project.get("status")
if status not in ALLOWED_QUEUE_STATUSES:
errors.append(f"analysis queue invalid status for {project['name']}: {status}")
in_progress = [p["name"] for p in projects if p.get("status") == "IN_PROGRESS"]
if len(in_progress) > 1:
errors.append("analysis queue has multiple IN_PROGRESS projects")
owned = [p["name"] for p in projects if p.get("status") in {"IN_PROGRESS", "BLOCKED"}]
if len(owned) > 1:
errors.append("analysis queue has multiple active-owned projects")
if active is None:
if owned:
errors.append("activeProject does not match active-owned project")
elif owned != [active]:
errors.append("activeProject does not match active-owned project")
return errors
FORBIDDEN_LITERAL = "document-" + "haness"
TEXT_SUFFIXES = {".md", ".json", ".py", ".sh", ".txt", ".yaml", ".yml", ".toml"}
def _iter_pipeline_text_files(shared_root: Path):
for rel_root in (".agents", "docs/_templates", "scripts"):
root = shared_root / rel_root
if not root.exists():
continue
for path in root.rglob("*"):
if not path.is_file() or path.suffix.lower() not in TEXT_SUFFIXES:
continue
if "__pycache__" in path.parts:
continue
yield path
def verify_pipeline(shared_root: Path) -> list[str]:
shared_root = Path(shared_root)
errors: list[str] = []
for rel in REQUIRED_PATHS:
if not (shared_root / rel).exists():
errors.append(f"missing required path: {rel}")
queue = shared_root / "docs/analysis-queue.yaml"
if queue.exists():
errors.extend(_verify_analysis_queue(queue))
refactor_queue = shared_root / "docs/refactor-queue.yaml"
if refactor_queue.exists():
errors.extend(_verify_refactor_queue(refactor_queue))
state_template = shared_root / "docs/_templates/state.json"
if state_template.exists():
state_text = state_template.read_text(encoding="utf-8", errors="replace")
for token in STATE_REANALYSIS_TOKENS:
if token not in state_text:
errors.append(f"state template missing reanalysis token: {token}")
root_tree = shared_root / "docs/_templates/root-tree.md"
if root_tree.exists():
text = root_tree.read_text(encoding="utf-8", errors="replace")
for token in ROOT_TREE_TOKENS:
if token not in text:
errors.append(f"root-tree template missing token: {token}")
for path in _iter_pipeline_text_files(shared_root):
text = path.read_text(encoding="utf-8", errors="replace")
if FORBIDDEN_LITERAL in text:
rel = path.relative_to(shared_root)
errors.append(f"forbidden legacy dependency in {rel}: {FORBIDDEN_LITERAL}")
if path.is_symlink():
try:
target = str(path.resolve())
except OSError:
target = ""
if FORBIDDEN_LITERAL in target:
rel = path.relative_to(shared_root)
errors.append(f"forbidden legacy symlink target in {rel}: {target}")
return errors
def main() -> int:
parser = argparse.ArgumentParser(description="Verify the Tech Log documentation pipeline workspace.")
parser.add_argument("shared_root", nargs="?", type=Path,
default=Path(__file__).resolve().parent.parent)
args = parser.parse_args()
errors = verify_pipeline(args.shared_root)
if errors:
print("PIPELINE VERIFICATION: FAIL")
for error in errors:
print(f"- {error}")
return 1
print("PIPELINE VERIFICATION: PASS")
print(f"- required paths: {len(REQUIRED_PATHS)}")
print("- analysis queue contract: valid")
print("- root-tree contract: present")
print("- forbidden legacy dependency: absent")
return 0
if __name__ == "__main__":
raise SystemExit(main())