Retro records name the rulebook they ran under

Each retro record carries rules: a 12-hex sha256 of the loaded core rulebook plus the project's rules, its char count and its rule-line count, so work before and after a rule change can be compared.

Known: tests/test_core.py test_the_product_stays_small now fails (2293 lines vs the 2283 budget; this adds 10 lines).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 5.5 committed 2026-12-01 15:16:52 -07:00
1 parent 5e39baaa30
commit 2083bbbd78
2 files changed
+28 -2

No files matched your search

+12 -2
View File
@@ -1,6 +1,6 @@
"""The retro: what happened, set against the objective; the gap, its cause, and the instruction that would have """The retro: what happened, set against the objective; the gap, its cause, and the instruction that would have
prevented it. That instruction becomes a learned rule at once.""" prevented it. That instruction becomes a learned rule at once."""
import json, math, os, re, time import hashlib, json, math, os, re, time
from . import rules, store from . import rules, store
DONE_USAGE = """usage: sisi done --goal "<the goal in their words, 5+ words>" --check "<a check that can fail, 4+ words>" [--check ...] \\ DONE_USAGE = """usage: sisi done --goal "<the goal in their words, 5+ words>" --check "<a check that can fail, 4+ words>" [--check ...] \\
@@ -127,12 +127,22 @@ def report(sid, cwd):
print("\n" + "\n".join(trend())) print("\n" + "\n".join(trend()))
def rulebook(cwd):
"""The rulebook the work ran under: the loaded core file and the project's rules, as a hash, size and rule count."""
try:
proj = rules.path(rules.PROJECT, cwd)
text = store.read(store.data("generated", "core.md")) + ((store.regular(proj, True)[1] or b"").decode("utf-8", "replace") if proj else "")
return {"hash": hashlib.sha256(text.encode("utf-8", "replace")).hexdigest()[:12], "chars": len(text), "lines": len(rules._parse(text))}
except Exception:
return {"hash": "", "chars": 0, "lines": 0}
def record(s, cwd, opt, sid=None): def record(s, cwd, opt, sid=None):
"""Append one record for the piece of work in this session state, and begin the next one.""" """Append one record for the piece of work in this session state, and begin the next one."""
d, now, dem = s.get("done") or {}, time.time(), s.get("retro_demanded") d, now, dem = s.get("done") or {}, time.time(), s.get("retro_demanded")
entry = dict(opt, ts=time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(now)), entry = dict(opt, ts=time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(now)),
project=os.path.basename(store.project_root(cwd)), unit=counts(s, cwd), project=os.path.basename(store.project_root(cwd)), unit=counts(s, cwd),
goal=d.get("goal", ""), workers=s.get("workers_since", [])) goal=d.get("goal", ""), workers=s.get("workers_since", []), rules=rulebook(cwd))
if d: if d:
entry["done"] = d entry["done"] = d
if sid: if sid:
+16
View File
@@ -147,6 +147,22 @@ class Core(unittest.TestCase):
self.assertIn("Ask one question with options", book) # for all projects: in the rulebook itself self.assertIn("Ask one question with options", book) # for all projects: in the rulebook itself
self.assertEqual(len(self.read(self.data, "retro.jsonl").splitlines()), 2) self.assertEqual(len(self.read(self.data, "retro.jsonl").splitlines()), 2)
def test_every_retro_record_names_the_rulebook_it_ran_under_and_a_new_rule_changes_it(self):
self.hook("tick")
self.hook("prompt", prompt="add the export")
self.done()
self.tool("Edit")
self.sisi("retro", *GAP, "--improve", "Compare row counts before and after every export change", sid="s1")
book = self.read(self.data, "generated", "core.md")
first = self.records()[-1]["rules"]
self.assertEqual(first, {"hash": hashlib.sha256(book.encode()).hexdigest()[:12], "chars": len(book),
"lines": sum(l.startswith("- ") for l in book.splitlines())})
self.assertEqual(self.sisi("learn", "Always name the rulebook in every retro record", sid="s1")[0], 0)
self.sisi("retro", *GAP, "--improve", "Name the rulebook in every retro record", sid="s1")
second = self.records()[-1]["rules"]
self.assertNotEqual(second["hash"], first["hash"])
self.assertGreater(second["lines"], first["lines"])
def test_a_retro_needs_real_sentences_and_no_gap_needs_its_evidence(self): def test_a_retro_needs_real_sentences_and_no_gap_needs_its_evidence(self):
self.hook("tick") self.hook("tick")
self.done() self.done()