Item 3: delegating a build needs a valid unit (kind from the routing record, else a brief word list kept as data). done / next: item 4 (pause)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-23 14:17:04 -07:00
1 parent db81060279
commit ed55af910a
3 files changed
+141 -15

No files matched your search

+87 -14
View File
@@ -1,17 +1,90 @@
{
"note": "Word lists for the before-tool guard (sisi/unitguard.py). Data, so a host or a project can be adapted without code.",
"edit_tools": ["Edit", "Write", "MultiEdit", "NotebookEdit"],
"edit_name_words": ["edit", "write", "create", "delete", "move", "rename", "patch", "apply", "insert"],
"delegation_tools": ["Agent", "Task"],
"build_kinds": ["impl", "impl-multi", "edit", "tests", "debug"],
"build_words": ["change", "changing", "fix", "fixing", "implement", "implementing", "write", "writing", "edit", "editing",
"modify", "modifying", "refactor", "rewrite", "patch", "add a", "add the", "build", "create", "update",
"rename", "remove", "delete", "code"],
"read_only_phrases": ["read-only", "read only", "do not modify", "do not change", "do not edit", "do not write",
"don't modify", "don't change", "don't edit", "without changing", "without modifying",
"no changes", "report only", "only report", "do not create"],
"self_refs": ["me", "myself", "i", "my", "own", "self", "yourself", "the author", "author", "this session", "same session",
"the agent", "the implementer"],
"ignore_changed": ["**/__pycache__/**", "**/*.pyc", "**/.pytest_cache/**", "**/.mypy_cache/**", "**/.ruff_cache/**",
"**/node_modules/**", ".git/**"]
"edit_tools": [
"Edit",
"Write",
"MultiEdit",
"NotebookEdit"
],
"edit_name_words": [
"edit",
"write",
"create",
"delete",
"move",
"rename",
"patch",
"apply",
"insert"
],
"delegation_tools": [
"Agent",
"Task"
],
"build_kinds": [
"impl",
"impl-multi",
"edit",
"tests",
"debug"
],
"build_words": [
"change",
"fix",
"implement",
"write",
"edit",
"modify",
"refactor",
"rewrite",
"patch",
"create",
"update",
"rename",
"remove",
"delete",
"add"
],
"read_only_phrases": [
"read-only",
"read only",
"do not modify",
"do not change",
"do not edit",
"do not write",
"don't modify",
"don't change",
"don't edit",
"without changing",
"without modifying",
"no changes",
"report only",
"only report",
"do not create"
],
"self_refs": [
"me",
"myself",
"i",
"my",
"own",
"self",
"yourself",
"the author",
"author",
"this session",
"same session",
"the agent",
"the implementer"
],
"ignore_changed": [
"**/__pycache__/**",
"**/*.pyc",
"**/.pytest_cache/**",
"**/.mypy_cache/**",
"**/.ruff_cache/**",
"**/node_modules/**",
".git/**"
],
"build_words_note": "Whole words; an inflection (s, es, ed, d, ing) counts. A read-only phrase below cancels them."
}
+2 -1
View File
@@ -599,7 +599,8 @@ def is_building_delegation(sess, payload):
text = _brief_text(payload)
if any(ph in text for ph in _list("read_only_phrases")):
return False
return any(re.search(r"\b" + re.escape(w), text) for w in _list("build_words"))
return any(re.search(r"\b(?:" + re.escape(w) + r"(?:s|es|ed|d|ing)?|" + re.escape(w[:-1] if w.endswith("e") else w) + r"ing)\b", text)
for w in _list("build_words"))
# ---------------------------------------------------------------- the hooks
+52
View File
@@ -470,5 +470,57 @@ class RefusalTests(GuardCase):
self.assertLessEqual(len((self.edit("auth/login.py") or "").splitlines()), 12)
class DelegationTests(GuardCase):
"""Item 3: delegating a build needs the unit too (R-9-1; the contract is where a brief's acceptance comes from)."""
def spawn(self, prompt, tool="Agent", **kw):
return self.before(tool, {"description": "worker", "prompt": prompt, "subagent_type": "general-purpose"}, **kw)
def route(self, kind):
s = store.load_session(self.sid)
s["route"] = {"kind": kind}
store.save_session(self.sid, s)
def test_delegating_a_build_with_no_unit_is_refused_and_says_where_the_acceptance_comes_from(self):
for tool in ("Agent", "Task"):
msg = self.spawn("Implement the new greeting in src/app.py and fix the tests", tool=tool)
self.assertIsNotNone(msg)
self.assertIn("sisi contract init", msg)
self.assertIn("acceptance", msg)
self.assertLessEqual(len(msg.splitlines()), 12)
self.assertEqual(len(self.refusals()), 2)
def test_a_read_only_search_is_allowed(self):
self.assertIsNone(self.spawn("Search the codebase for every caller of greet and list them"))
self.assertIsNone(self.spawn("Find where the config is read. Do not modify any file."))
self.assertEqual(self.refusals(), [])
def test_the_routing_kind_decides_when_one_is_recorded(self):
for kind in ("impl", "impl-multi", "edit", "tests", "debug"):
self.route(kind)
self.assertIsNotNone(self.spawn("look into the greeting"), kind)
for kind in ("review", "search", "research"):
self.route(kind)
self.assertIsNone(self.spawn("fix and implement everything"), kind)
def test_with_a_valid_bound_unit_the_delegation_goes_through(self):
self.open_unit()
self.assertIsNone(self.spawn("Implement the new greeting in src/app.py"))
def test_with_another_sessions_unit_it_is_refused_with_the_three_ways_on(self):
self.write_contract(good_contract(goal="old work"))
G.bind("someone", self.proj, C.load(self.contract_path), "init")
msg = self.spawn("Implement the new greeting")
self.assertIn("sisi unit park", msg)
self.assertIn("old work", msg)
def test_a_worker_session_delegating_is_not_refused(self):
self.assertIsNone(self.spawn("Implement the new greeting", agent_id="w1"))
def test_a_guard_error_lets_the_delegation_through(self):
with mock.patch.object(G, "is_building_delegation", side_effect=RuntimeError("x")):
self.assertIsNone(self.spawn("Implement the new greeting"))
if __name__ == "__main__":
unittest.main()