Captures current workflow, packaging rules, and identity/clothing prereqs for sharing.
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
from pathlib import Path
|
|
|
|
RULES_PATH = Path(__file__).resolve().parent.parent / "references" / "prompt-rules.json"
|
|
|
|
|
|
def _load_rules(path: Path = RULES_PATH):
|
|
return json.loads(path.read_text())
|
|
|
|
|
|
def lint_prompt(stage: str, group: str, prompt: str, rules_path: Path = RULES_PATH):
|
|
rules = _load_rules(rules_path)
|
|
stage_rules = rules.get(stage, {})
|
|
rule = stage_rules.get(group)
|
|
if not rule:
|
|
return [f"No rule for stage={stage} group={group}"]
|
|
|
|
p = prompt.lower()
|
|
errors = []
|
|
for req in rule.get("required", []):
|
|
if req.lower() not in p:
|
|
errors.append(f"Missing required phrase: '{req}'")
|
|
for bad in rule.get("forbidden", []):
|
|
if bad.lower() in p:
|
|
errors.append(f"Forbidden phrase present: '{bad}'")
|
|
return errors
|
|
|
|
|
|
def enforce(stage: str, group: str, prompt: str, rules_path: Path = RULES_PATH):
|
|
errs = lint_prompt(stage, group, prompt, rules_path)
|
|
if errs:
|
|
raise ValueError("Prompt lint failed: " + "; ".join(errs))
|
|
return True
|