Captures current workflow, packaging rules, and identity/clothing prereqs for sharing.
70 lines
2.1 KiB
Python
70 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def load_rules(path: Path):
|
|
return json.loads(path.read_text())
|
|
|
|
def lint_prompt(stage, group, prompt, rules):
|
|
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 lint_file(path, rules):
|
|
errors = []
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
for idx, line in enumerate(f, 1):
|
|
if not line.strip():
|
|
continue
|
|
obj = json.loads(line)
|
|
stage = obj.get("stage")
|
|
group = obj.get("group")
|
|
prompt = obj.get("prompt", "")
|
|
name = obj.get("name", f"line {idx}")
|
|
errs = lint_prompt(stage, group, prompt, rules)
|
|
for e in errs:
|
|
errors.append(f"{name}: {e}")
|
|
return errors
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Prompt drift lint for npc-nudity-workflow")
|
|
parser.add_argument("--rules", default=str(Path(__file__).resolve().parent.parent / "references" / "prompt-rules.json"))
|
|
parser.add_argument("--stage")
|
|
parser.add_argument("--group")
|
|
parser.add_argument("--prompt")
|
|
parser.add_argument("--file", help="JSONL file with {stage, group, prompt, name}")
|
|
args = parser.parse_args()
|
|
|
|
rules = load_rules(Path(args.rules))
|
|
|
|
if args.file:
|
|
errs = lint_file(args.file, rules)
|
|
else:
|
|
if not (args.stage and args.group and args.prompt):
|
|
print("Provide --file or --stage/--group/--prompt", file=sys.stderr)
|
|
sys.exit(2)
|
|
errs = lint_prompt(args.stage, args.group, args.prompt, rules)
|
|
|
|
if errs:
|
|
for e in errs:
|
|
print(e, file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
print("OK")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|