A plugins/spire/skills/curator/agents/openai.yaml M plugins/spire/skills/gremlins/SKILL.md M plugins/spire/skills/gremlins/preamble.md M plugins/spire/skills/gremlins/templates/rebase.md M plugins/spire/skills/gremlins/templates/spawn.md M plugins/spire/skills/gremlins/templates/train.md A plugins/spire/skills/gremlins/tests/test_prompts.py M plugins/spire/skills/implementation/references/run-log.md A plugins/spire/skills/init/agents/openai.yaml M plugins/spire/skills/svg/SKILL.md
87 lines
3.4 KiB
Python
87 lines
3.4 KiB
Python
"""Wording pins for the prompt layers (design 0.4.0 §7, §9.2)."""
|
|
import re
|
|
import string
|
|
import sys
|
|
import textwrap
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
SKILL = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(SKILL))
|
|
|
|
from grm import cli # noqa: E402
|
|
|
|
TEMPLATES = ("train.md", "spawn.md", "rebase.md")
|
|
# Every key cli passes to render_template, per template.
|
|
KEYS = {
|
|
"train.md": ["base", "run", "state_dir", "notes_dir", "out_dir", "brief"],
|
|
"spawn.md": ["block", "base", "run", "delta", "note_path", "out_dir", "commit_line", "brief"],
|
|
"rebase.md": ["base", "run", "notes_dir", "delta", "brief"],
|
|
}
|
|
SAMPLE_COMMIT = " You cannot commit here (`.git` is read-only in your sandbox); list the paths you changed."
|
|
|
|
|
|
def read(rel):
|
|
return (SKILL / rel).read_text(encoding="utf-8")
|
|
|
|
|
|
class PromptWordingTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.preamble = read("preamble.md")
|
|
self.templates = {n: read("templates/" + n) for n in TEMPLATES}
|
|
|
|
def test_role_phrases_once_in_preamble_only(self):
|
|
for phrase in ("Trained once, as the base", "Forked once per task"):
|
|
self.assertEqual(self.preamble.count(phrase), 1, phrase)
|
|
for n, t in self.templates.items():
|
|
self.assertNotIn(phrase, t, n)
|
|
|
|
def test_no_ready_line(self):
|
|
for n, t in self.templates.items():
|
|
self.assertNotIn("READY", t, n)
|
|
self.assertNotIn("READY", self.preamble)
|
|
|
|
def test_spawn_has_no_commit_sentence(self):
|
|
text = self.templates["spawn.md"].replace("${commit_line}", "")
|
|
# headings ("Delta since the base commit") are not sentences
|
|
body = "\n".join(l for l in text.splitlines() if not l.lstrip().startswith("#"))
|
|
self.assertNotIn("commit", body.lower())
|
|
self.assertEqual(self.templates["spawn.md"].count("${commit_line}"), 1)
|
|
self.assertIn("Gate and test output: `${out_dir}`.${commit_line}", self.templates["spawn.md"])
|
|
|
|
def test_stale_snapshot_rule_only_in_preamble(self):
|
|
phrase = "newest delta header wins"
|
|
self.assertEqual(self.preamble.count(phrase), 1)
|
|
for n, t in self.templates.items():
|
|
self.assertNotIn(phrase, t, n)
|
|
|
|
def test_templates_render_with_every_cli_key(self):
|
|
for name in TEMPLATES:
|
|
for commit_line in ("", SAMPLE_COMMIT):
|
|
values = {k: "<%s>" % k for k in KEYS[name]}
|
|
if "commit_line" in values:
|
|
values["commit_line"] = commit_line
|
|
text = cli.render_template(name, values)
|
|
self.assertNotIn("${", text, name)
|
|
self.assertTrue(set(re.findall(r"\$\{(\w+)\}", self.templates[name])) <= set(KEYS[name]), name)
|
|
if commit_line and name == "spawn.md":
|
|
self.assertIn(commit_line, text)
|
|
|
|
def test_handoff_block_equals_run_log(self):
|
|
path = cli.SKILL_DIR.parent / "implementation/references/run-log.md"
|
|
self.assertTrue(path.is_file(), "missing: %s" % path)
|
|
|
|
def block(text, after=None):
|
|
if after:
|
|
text = text[text.index(after):]
|
|
m = re.search(r"```markdown\n(.*?)```", text, re.S)
|
|
self.assertIsNotNone(m)
|
|
return textwrap.dedent(m.group(1)).strip()
|
|
|
|
theirs = block(path.read_text(encoding="utf-8"), "## Handoff note")
|
|
self.assertEqual(block(self.preamble), theirs)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|