Item 7: delegation brief template and check carry the rebuild's lessons (six advice flags). done 7 / next 8 (recipes and verifier entry)

This commit is contained in:
swaits committed 2026-11-23 12:30:53 -07:00
1 parent 1b57d00e60
commit d63b0f9c49
3 files changed
+129 -6

No files matched your search

+57
View File
@@ -37,15 +37,21 @@ def template():
"",
"## Acceptance",
"[How the result will be judged: the check that decides accepted or rejected.]",
"[Every size, speed or brevity requirement is a number with the command that measures it.]",
"[If the worker writes data for another module to read, name that reader and require one end-to-end test that shows the reader's behaviour changes.]",
"[If you ask for a classifier, matcher or heuristic and a labelled set, the labels come from a different worker, or a held-out part is written first.]",
"",
"## Deliverables and report format",
"[What to send back, and in what shape: a short report, what changed, the check run.]",
"[For numbered items: a commit after each, with a one-line \"done / next\" note in the message.]",
"",
"## Files you may change",
"[The files or folders the worker may change; everything else is read-only.]",
"",
"## Verification",
"[The check the worker must run before reporting, and what output to include.]",
"[For an approval gate, trust check or validation step, list the abuse cases the tests must cover: omit the field that triggers the gate, forge the field that marks trust, make the failing-before step fail for an unrelated reason.]",
"[New test modules are run about 30 times, with copies in parallel, before the report.]",
"",
"## Budget and escalation",
"[Time or cost budget; when to stop and escalate instead of guessing.]",
@@ -114,3 +120,54 @@ def missing_required(text):
found = sections(text)
return [title for key, title, _n, _r in PARTS
if key in _REQUIRED and (key not in found or not _filled(found[key]))]
# ---------------------------------------------------------------- advice (never blocks)
_VAGUE = re.compile(r"\b(short|fast|small|brief|concise|quick)\b", re.I)
_GATE = re.compile(r"\b(approv\w*|trust\w*|validat\w*|untrusted)\b", re.I)
_ABUSE = re.compile(r"\b(abuse|misuse)\b", re.I)
_TESTS = re.compile(r"\btests?\b", re.I)
_REPEAT = re.compile(r"\brepeat|\b\d+ times\b|in parallel", re.I)
_FOR_OTHERS = re.compile(r"(for|that) (other|another|downstream) modules? (to|will|that)? ?(read|consume|use)|"
r"(other|another) modules? (reads?|will read|consumes?)", re.I)
_READER = re.compile(r"\b(read by|reader is|reader:|the reader|consumer is|consumer:)\s+[`\w./]+", re.I)
_HEURISTIC = re.compile(r"\b(classifier|matcher|heuristic)\b", re.I)
_LABELS = re.compile(r"\blabell?ed\b|\blabels\b|ground truth", re.I)
_LABELS_INDEPENDENT = re.compile(r"different worker|another worker|other worker|held[- ]?out|blind", re.I)
_NUMBERED = re.compile(r"^\s*(\d+[.)]|item \d+)\s", re.I | re.M)
_COMMIT_PER_ITEM = re.compile(r"commit (after|per|for) each|done ?/ ?next", re.I)
def _written(text):
"""The lines the brief's author wrote: the template's bracketed guidance does not count."""
return [ln for ln in (text or "").splitlines()
if not (ln.strip().startswith("[") and ln.strip().endswith("]"))]
def advice(text):
"""Short pieces of advice about a brief, each with its reason. Advice never blocks a delegation."""
lines = _written(text)
body = "\n".join(lines)
acceptance = sections("\n".join(lines)).get("acceptance", [])
out = []
vague = sorted({m.group(1).lower() for ln in acceptance if not re.search(r"\d", ln) for m in _VAGUE.finditer(ln)})
if vague:
out.append("Acceptance says %s with no number: state each size, speed or brevity limit as a number "
"and the command that measures it." % "/".join(vague))
if _GATE.search(body) and not _ABUSE.search(body):
out.append("It mentions approval, trust or validation but lists no abuse cases: name them (omit the "
"trigger field, forge the trust mark, fail the before-step for an unrelated reason).")
if _TESTS.search(body) and not _REPEAT.search(body):
out.append("It asks for tests but not a repeat run: run new test modules about 30 times, with copies "
"in parallel, before reporting (exposes time and order dependence).")
if _FOR_OTHERS.search(body) and not _READER.search(body):
out.append("The worker writes data for other modules to read, but no reader is named: name it and ask "
"for one end-to-end test showing its behaviour changes.")
if _HEURISTIC.search(body) and _LABELS.search(body) and not _LABELS_INDEPENDENT.search(body):
out.append("It asks for a classifier, matcher or heuristic and a labelled set from the same worker: the "
"labels should come from a different worker, or a held-out part be written first.")
if len(_NUMBERED.findall(body)) >= 2 and not _COMMIT_PER_ITEM.search(body):
out.append("It has numbered items but no commit per item: ask for a commit after each, with a "
"\"done / next\" note, so an interruption loses at most one.")
return out
+11 -6
View File
@@ -1563,12 +1563,17 @@ def _cmd_brief_check(args):
missing = brief_contract.missing_parts(text)
if not missing:
print("brief ok: all %d parts present" % len(brief_contract.PARTS))
return 0
print("brief lacks:")
for title in missing:
print(" - %s" % title)
print("`sisi delegate brief` prints the template.")
return 1
else:
print("brief lacks:")
for title in missing:
print(" - %s" % title)
print("`sisi delegate brief` prints the template.")
advice = brief_contract.advice(text)
if advice:
print("advice (does not block):")
for line in advice:
print(" - %s" % line)
return 1 if missing else 0
def _cmd_down(args):
+61
View File
@@ -80,6 +80,67 @@ class BriefTests(OrchCase):
self.assertIn("Acceptance", r.stdout)
self.assertIn("Files you may change", r.stdout)
def brief_with(self, **parts):
"""valid_brief() with the text of some parts replaced; keys are the heading words."""
text = valid_brief()
heads = {"acceptance": "Acceptance", "verification": "Verification", "outcome": "Outcome and scope",
"deliverables": "Deliverables and report format"}
for key, body in parts.items():
h = heads[key]
start = text.index("## " + h)
end = text.find("\n\n##", start)
end = len(text) if end < 0 else end
text = text[:start] + "## %s\n%s" % (h, body) + text[end:]
return text
def advice(self, text):
p = os.path.join(self.proj, "b.md")
open(p, "w").write(text)
r = self.sisi("delegate", "check", p, env=self.env())
self.assertEqual(r.returncode, 0, r.stdout) # advice never blocks
self.assertLessEqual(len(r.stdout.splitlines()), 20)
return r.stdout
def test_brief_template_carries_what_the_rebuild_learned(self):
"""R-7.5-1: the template's guidance names the six cases, and an unfilled template is still unfilled."""
t = self.sisi("delegate", "brief", env=self.env()).stdout
for phrase in ("a number with the command that measures it", "name that reader", "different worker",
"held-out", "abuse cases", "forge the field that marks trust", "unrelated reason",
"30 times", "in parallel", "done / next"):
self.assertIn(phrase, t)
p = os.path.join(self.proj, "t.md")
open(p, "w").write(t)
r = self.sisi("delegate", "check", p, env=self.env())
self.assertNotEqual(r.returncode, 0)
self.assertNotIn("advice", r.stdout) # the template's own guidance is not the author's words
def test_check_flags_each_case_and_stays_quiet_on_a_clean_brief(self):
"""R-7.5-1, abuse: each flag has a brief that trips it and a near-identical one that does not."""
self.assertNotIn("advice", self.advice(valid_brief()))
cases = {
"acceptance": (dict(acceptance="Keep the report short and fast."), "Acceptance says"),
"gate": (dict(outcome="Add an approval gate for deploys."), "abuse cases"),
"tests": (dict(verification="Write tests for the parser."), "repeat run"),
"reader": (dict(outcome="Write the index file for other modules to read."), "no reader is named"),
"labels": (dict(outcome="Build a matcher and a labelled set of examples."), "different worker"),
"commits": (dict(deliverables="1. the parser\n2. the writer"), "commit per item"),
}
for name, (parts, flag) in cases.items():
with self.subTest(name):
self.assertIn(flag, self.advice(self.brief_with(**parts)))
fixed = {
"acceptance": dict(acceptance="The report is under 40 lines (`wc -l report.md`) and the check runs in 5 s."),
"gate": dict(outcome="Add an approval gate for deploys.", verification="Abuse cases: omit the trigger field."),
"tests": dict(verification="Write tests; run the new module 30 times in parallel."),
"reader": dict(outcome="Write the index for other modules to read; the reader is `sisi/search.py`."),
"labels": dict(outcome="Build a matcher; the labelled set comes from a different worker."),
"commits": dict(deliverables="1. the parser\n2. the writer\nCommit after each item with a done / next note."),
}
for name, parts in fixed.items():
with self.subTest("fixed " + name):
self.assertNotIn("advice", self.advice(self.brief_with(**parts)))
self.assertLessEqual(len(self.advice(self.brief_with(**{k: v for c in cases.values() for k, v in c[0].items()})).splitlines()), 20)
def test_check_passes_a_full_brief(self):
p = os.path.join(self.proj, "full.md")
open(p, "w").write(valid_brief())