Chore briefs carry a one-time id: delegate the first line, worker prints the brief by id

This commit is contained in:
sisi committed 2026-12-02 10:21:31 -07:00
1 parent 62e79b8342
commit 8aa79ab492
5 files changed
+123 -29

No files matched your search

+3 -2
View File
@@ -34,6 +34,7 @@ Delegation
| files | check | why |) before handing out any work; `sisi plan` shows each node | files | check | why |) before handing out any work; `sisi plan` shows each node
sisi plan --done ID EVIDENCE | --fail ID WHY sisi plan --done ID EVIDENCE | --fail ID WHY
a node you did yourself (the join) is done; or reopen a node a node you did yourself (the join) is done; or reopen a node
sisi chore show ID print the chore brief under this one-time id; delegate just its first line plus "Run `sisi chore show <id>` and do what it says"
sisi pick --node ID [--review-of WORKER] [--not WORKER ...] [--limit MINUTES] sisi pick --node ID [--review-of WORKER] [--not WORKER ...] [--limit MINUTES]
sisi pick routine|ordinary|hard [--review-of WORKER] [--not WORKER ...] [--limit MINUTES] [--branch NAME] sisi pick routine|ordinary|hard [--review-of WORKER] [--not WORKER ...] [--limit MINUTES] [--branch NAME]
the wheel gives you one worker for a ready plan node (or of a class, for a the wheel gives you one worker for a ready plan node (or of a class, for a
@@ -74,9 +75,9 @@ def main(argv):
if cmd in ("retro", "done"): if cmd in ("retro", "done"):
from . import retro from . import retro
return (retro.run if cmd == "retro" else retro.done)(args) return (retro.run if cmd == "retro" else retro.done)(args)
if cmd == "plan": if cmd in ("plan", "chore"):
from . import plan from . import plan
return plan.run(args) return plan.run(args) if cmd == "plan" else plan.chore(args)
if cmd == "fault": if cmd == "fault":
from . import faults from . import faults
return faults.run(args) return faults.run(args)
+2 -2
View File
@@ -63,8 +63,8 @@ Then one line starting "Fallback order:" that says who takes over when a worker
=== How delegations went here, newest last === === How delegations went here, newest last ===
%(outcomes)s %(outcomes)s
""" """
ASK = ("In the background, give the output of `sisi models research` to a hard-class worker that can search the web " ASK = ("In the background, delegate just the first line of the output of `sisi models research` plus \"Run `sisi chore show <id>` and do what it says\" "
"(`sisi pick hard`: choosing models well pays for itself) and record its answer with `sisi models research --record FILE`.") "to a hard-class worker that can search the web (`sisi pick hard`: choosing models well pays for itself) and record its answer with `sisi models research --record FILE`.")
def table(): return store.data("models.md") def table(): return store.data("models.md")
+24 -21
View File
@@ -3,13 +3,14 @@
Each node says what it needs first, its own branch, the files it may change and its check; one join brings everything Each node says what it needs first, its own branch, the files it may change and its check; one join brings everything
back. The hooks hold the lead to it: no delegation outside the plan or out of order, no turn ending while a node is back. The hooks hold the lead to it: no delegation outside the plan or out of order, no turn ending while a node is
ready and not started. The plan lives in the session state and closes with the piece of work.""" ready and not started. The plan lives in the session state and closes with the piece of work."""
import contextlib, fnmatch, hashlib, re, time import contextlib, fnmatch, hashlib, os, re, time
from . import store from . import store
CLASSES = ("routine", "ordinary", "hard", "lead") CLASSES = ("routine", "ordinary", "hard", "lead")
COLS = ("node", "class", "needs", "branch", "files", "check", "why") COLS = ("node", "class", "needs", "branch", "files", "check", "why")
NODE_LINE = re.compile(r"\W{0,6}sisi node:\s*([a-z0-9-]{1,30})\s*$", re.I) NODE_LINE = re.compile(r"\W{0,6}sisi node:\s*([a-z0-9-]{1,30})\s*$", re.I)
CHORE_LINE = re.compile(r"\W{0,6}sisi chore:\s*(\S.{0,60}?)\s*$", re.I) CHORE_LINE = re.compile(r"\W{0,6}sisi chore:\s*(.+?)(?:\s+([0-9a-f]{8}))?\s*$", re.I)
CHORE_CMD = {"plan": "sisi plan brief", "models research": "sisi models research", "rules organize": "sisi rules organize"}
USAGE = ('usage: sisi plan | sisi plan --record FILE | sisi plan brief | sisi plan --done ID "<evidence>" | sisi plan --fail ID "<why>"\n' USAGE = ('usage: sisi plan | sisi plan --record FILE | sisi plan brief | sisi plan --done ID "<evidence>" | sisi plan --fail ID "<why>"\n'
" FILE holds one markdown table: | node | class | needs | branch | files | check | why | (why is optional)") " FILE holds one markdown table: | node | class | needs | branch | files | check | why | (why is optional)")
@@ -182,17 +183,26 @@ def show(p):
def _sum(text): return hashlib.sha1(text.encode("utf-8", "replace")).hexdigest() def _sum(text): return hashlib.sha1(text.encode("utf-8", "replace")).hexdigest()
_chore_path = lambda cid: os.path.join(store.STATE, "chores", cid + ".txt") if re.fullmatch(r"[0-9a-f]{8}", cid or "") else ""
def issue(name, text, cwd=None): def issue(name, text, cwd=None):
"""Print a chore brief and record it in this session: one delegation whose brief starts with this exact text may go without done or a plan.""" """Print a chore brief with a one-time id and record it in this session: one delegation carrying its first line (or the full text) may go without a plan."""
text = text.strip() cid, text = os.urandom(4).hex(), text.strip()
text = "sisi chore: %s %s\n%s" % (name, cid, text.split("\n", 1)[1] if "\n" in text else "") if text.startswith("sisi chore:") else "sisi chore: %s %s\n%s" % (name, cid, text)
store.write(_chore_path(cid), text + "\n")
if sid := store.current_session(cwd): if sid := store.current_session(cwd):
with store.session(sid) as s: with store.session(sid) as s:
s["chores"] = (s["chores"] if isinstance(s.get("chores"), list) else [])[-9:] + [[name, _sum(text), len(text)]] s["chores"] = (s["chores"] if isinstance(s.get("chores"), list) else [])[-9:] + [[name, _sum(text), len(text), cid]]
print(text) print(text)
def chore(args): # `sisi chore show ID`: print the brief printed under this one-time id (any session may read it)
if len(args) == 2 and args[0] == "show" and (text := store.read(_chore_path(args[1])) if _chore_path(args[1]) else ""):
return print(text, end="") or 0
return print("sisi chore: no brief with id %r: print the brief again (`sisi plan brief`, `sisi models research` or `sisi rules organize`)." % (args[1] if len(args) > 1 else "")) or 1
def run(args, cwd=None): def run(args, cwd=None):
sid = store.current_session(cwd) sid = store.current_session(cwd)
if args == ["brief"]: if args == ["brief"]:
@@ -240,15 +250,12 @@ def run(args, cwd=None):
if not args: if not args:
p = None p = None
if sid: if sid:
with store.session(sid) as s: with store.session(sid) as s: p = get(s)
p = get(s)
return print("\n".join(show(p)) if p else "no plan recorded. `sisi plan brief` prints the brief for a planning worker; `sisi plan --record FILE` records its table.") or 0 return print("\n".join(show(p)) if p else "no plan recorded. `sisi plan brief` prints the brief for a planning worker; `sisi plan --record FILE` records its table.") or 0
print(USAGE) return print(USAGE) or 1
return 1
def why_not(p, i): why_not = lambda p, i: "already " + st(p, i) if st(p, i) in ("running", "done") else "needs not done: " + ", ".join(x for x in node(p, i)["needs"] if st(p, x) != "done")
return "already " + st(p, i) if st(p, i) in ("running", "done") else "needs not done: " + ", ".join(x for x in node(p, i)["needs"] if st(p, x) != "done")
def for_pick(args, cwd=None): def for_pick(args, cwd=None):
@@ -261,15 +268,12 @@ def for_pick(args, cwd=None):
why = ("no plan is recorded: `sisi plan brief`, then `sisi plan --record FILE`" if not p else "no node %r in the plan" % i if not n why = ("no plan is recorded: `sisi plan brief`, then `sisi plan --record FILE`" if not p else "no node %r in the plan" % i if not n
else "node %s is the lead's own: do it and run `sisi plan --done %s \"<evidence>\"`" % (i, i) if n["cls"] == "lead" else "node %s is the lead's own: do it and run `sisi plan --done %s \"<evidence>\"`" % (i, i) if n["cls"] == "lead"
else "node %s is not ready (%s)" % (i, why_not(p, i)) if i not in ready(p) else "") else "node %s is not ready (%s)" % (i, why_not(p, i)) if i not in ready(p) else "")
if why: if why: return print("sisi pick: %s." % why) or (None, None)
print("sisi pick: %s." % why)
return None, None
return [n["cls"]] + args[2:] + ["--branch", n["branch"]], i return [n["cls"]] + args[2:] + ["--branch", n["branch"]], i
def header(p, i): def header(p, i):
n = node(p, i) return "\n".join(["paste at the top of the brief (its first line):", "sisi node: " + i, "branch: %s (its own worktree and build folder)" % (n := node(p, i))["branch"],
return "\n".join(["paste at the top of the brief (its first line):", "sisi node: " + i, "branch: %s (its own worktree and build folder)" % n["branch"],
"may change: " + (", ".join(n["files"]) or "nothing"), "check: " + n["check"], "may change: " + (", ".join(n["files"]) or "nothing"), "check: " + n["check"],
"needs done: " + (", ".join("%s (%s)" % (x, p["state"].get(x, {}).get("evidence", "")) for x in n["needs"]) or "-")]) "needs done: " + (", ".join("%s (%s)" % (x, p["state"].get(x, {}).get("evidence", "")) for x in n["needs"]) or "-")])
@@ -302,11 +306,10 @@ def deny(s, brief, shell=False):
line = lambda rx: next((m for i in at if (m := rx.match(brief[i:].split("\n", 1)[0].strip()))), None) line = lambda rx: next((m for i in at if (m := rx.match(brief[i:].split("\n", 1)[0].strip()))), None)
chores, c = (s["chores"] if isinstance(s.get("chores"), list) else []), line(CHORE_LINE) chores, c = (s["chores"] if isinstance(s.get("chores"), list) else []), line(CHORE_LINE)
if c: if c:
hit = next((k for k, x in enumerate(chores) if isinstance(x, list) and len(x) == 3 and x[0] == c.group(1) and type(x[2]) is int name, cid = c.group(1), c.group(2)
and any(_sum(brief[i:i + x[2]]) == x[1] for i in at)), None) hit = next((k for k, x in enumerate(chores) if isinstance(x, list) and len(x) == 4 and x[0] == name and x[3] == cid and type(x[2]) is int
return ("", None, hit) if hit is not None else (( and (any(_sum(brief[i:i + x[2]]) == x[1] for i in at) or any(len(brief) - i < x[2] for i in at))), None)
"sisi: this `sisi chore: %s` brief is not one sisi printed in this session: print the chore's brief again (`sisi plan brief`, " return ("", None, hit) if hit is not None else (("sisi: this `sisi chore: %s` brief is not one sisi printed in this session (a wrong, reused or other-session id): print the chore's brief again with `%s` and delegate just its first line plus \"Run `sisi chore show %s` and do what it says\"." % (name, CHORE_CMD.get(name, "sisi plan brief`, `sisi models research` or `sisi rules organize"), cid or "<id>")), None, None)
"`sisi models research` or `sisi rules organize`) and send it unchanged at the top of the brief." % c.group(1)), None, None)
if not p: if not p:
return ("sisi: no plan is recorded. Before handing out work, plan it: `sisi plan brief` prints the brief for a hard planning worker " return ("sisi: no plan is recorded. Before handing out work, plan it: `sisi plan brief` prints the brief for a hard planning worker "
"(it carries its `sisi chore: plan` line), then `sisi plan --record FILE`."), None, None "(it carries its `sisi chore: plan` line), then `sisi plan --record FILE`."), None, None
+2 -2
View File
@@ -358,8 +358,8 @@ def due(cwd, claim=False):
cl.update({"claim:" + k: now for k, _ in need}) cl.update({"claim:" + k: now for k, _ in need})
with contextlib.suppress(OSError): with contextlib.suppress(OSError):
store.write(store.data("locks", "organize.json"), json.dumps(cl)) store.write(store.data("locks", "organize.json"), json.dumps(cl))
return ("sisi: the learned rules need organizing (%s). In the background, give the output of " return ("sisi: the learned rules need organizing (%s). In the background, delegate just the first line of the output of "
"`sisi rules organize` to a cheap worker and record its answer with `sisi rules organize --record FILE`." "`sisi rules organize` plus \"Run `sisi chore show <id>` and do what it says\" to a cheap worker and record its answer with `sisi rules organize --record FILE`."
% "; ".join(m for _, m in need)) % "; ".join(m for _, m in need))
+92 -2
View File
@@ -158,7 +158,7 @@ class Plan(unittest.TestCase):
self.ready_plan() self.ready_plan()
rc, out, _ = self.sisi("plan", "brief", sid="s1") rc, out, _ = self.sisi("plan", "brief", sid="s1")
self.assertEqual(rc, 0, out) self.assertEqual(rc, 0, out)
self.assertEqual(out.splitlines()[0], "sisi chore: plan") self.assertRegex(out.splitlines()[0], r"^sisi chore: plan [0-9a-f]{8}$")
for want in ("export every row without losing any", "1. row counts match", "| node | class | needs | branch | files | check | why |", for want in ("export every row without losing any", "1. row counts match", "| node | class | needs | branch | files | check | why |",
"Class by total cost", "routine nodes whenever their", "record (last 20 judged per class)"): "Class by total cost", "routine nodes whenever their", "record (last 20 judged per class)"):
self.assertIn(want, out) self.assertIn(want, out)
@@ -283,11 +283,101 @@ class Plan(unittest.TestCase):
self.hook("prompt", prompt="tidy up") self.hook("prompt", prompt="tidy up")
for args, line in ((("rules", "organize"), "sisi chore: rules organize"), (("models", "research"), "sisi chore: models research")): for args, line in ((("rules", "organize"), "sisi chore: rules organize"), (("models", "research"), "sisi chore: models research")):
rc, brief, _ = self.sisi(*args, sid="s1") rc, brief, _ = self.sisi(*args, sid="s1")
self.assertEqual((rc, brief.splitlines()[0]), (0, line)) self.assertEqual(rc, 0, brief)
self.assertRegex(brief.splitlines()[0], r"^%s [0-9a-f]{8}$" % line)
self.assertEqual(self.sisi("pick", "routine", sid="s1")[0], 0) self.assertEqual(self.sisi("pick", "routine", sid="s1")[0], 0)
self.assertNotIn("permissionDecision", self.decision(self.agent("alpha", brief)), line) self.assertNotIn("permissionDecision", self.decision(self.agent("alpha", brief)), line)
self.assertEqual(self.state()["chores"], []) self.assertEqual(self.state()["chores"], [])
def chore_id(self, brief):
return brief.splitlines()[0].rsplit(" ", 1)[-1]
def short_brief(self, brief):
return brief.splitlines()[0] + "\nRun `sisi chore show %s` and do what it says." % self.chore_id(brief)
def test_a_chore_id_is_issued_and_printed_on_the_first_line(self):
self.table(TABLE)
self.hook("prompt", prompt="build it")
self.done()
brief = self.sisi("plan", "brief", sid="s1")[1]
cid = self.chore_id(brief)
self.assertRegex(cid, r"^[0-9a-f]{8}$")
self.assertIn(cid, [x[3] for x in self.state()["chores"]])
def test_a_short_delegation_with_the_id_passes_once(self):
self.table(TABLE)
self.hook("prompt", prompt="build it")
self.done()
brief = self.sisi("plan", "brief", sid="s1")[1]
self.assertEqual(self.sisi("pick", "hard", sid="s1")[0], 0)
self.assertEqual(self.decision(self.agent("gamma", self.short_brief(brief))), {})
self.assertEqual(self.state().get("chores"), [])
def test_a_reused_chore_id_is_denied(self):
self.table(TABLE)
self.hook("prompt", prompt="build it")
self.done()
brief = self.sisi("plan", "brief", sid="s1")[1]
self.assertEqual(self.sisi("pick", "hard", sid="s1")[0], 0)
self.assertEqual(self.decision(self.agent("gamma", self.short_brief(brief))), {})
self.assertEqual(self.sisi("pick", "hard", sid="s1")[0], 0)
self.denied(self.agent("gamma", self.short_brief(brief)), "is not one sisi printed in this session")
def test_a_wrong_chore_id_is_denied(self):
self.table(TABLE)
self.hook("prompt", prompt="build it")
self.done()
brief = self.sisi("plan", "brief", sid="s1")[1]
cid = self.chore_id(brief)
wrong = ("0" if cid[0] != "0" else "1") + cid[1:]
self.assertEqual(self.sisi("pick", "hard", sid="s1")[0], 0)
why = self.denied(self.agent("gamma", "sisi chore: plan %s\nRun `sisi chore show %s` and do what it says." % (wrong, wrong)),
"is not one sisi printed in this session")
self.assertIn("sisi plan brief", why)
def test_another_sessions_chore_id_is_denied(self):
self.table(TABLE)
self.hook("prompt", prompt="build it")
self.done()
brief = self.sisi("plan", "brief", sid="s1")[1]
self.hook("prompt", sid="s2", prompt="build it")
self.done(sid="s2")
self.assertEqual(self.sisi("pick", "hard", sid="s2")[0], 0)
self.denied(self.agent("gamma", self.short_brief(brief), sid="s2"), "is not one sisi printed in this session")
def test_chore_show_prints_the_brief_and_unknown_id_fails(self):
self.table(TABLE)
self.hook("prompt", prompt="build it")
self.done()
brief = self.sisi("plan", "brief", sid="s1")[1]
cid = self.chore_id(brief)
rc, out, _ = self.sisi("chore", "show", cid, sid="s2")
self.assertEqual(rc, 0, out)
self.assertEqual(out, brief)
rc, out, _ = self.sisi("chore", "show", "deadbeef")
self.assertEqual(rc, 1, out)
self.assertIn("deadbeef", out)
def test_a_full_text_delegation_with_the_id_still_passes(self):
self.table(TABLE)
self.hook("prompt", prompt="build it")
self.done()
brief = self.sisi("plan", "brief", sid="s1")[1]
self.assertEqual(self.sisi("pick", "hard", sid="s1")[0], 0)
self.assertEqual(self.decision(self.agent("gamma", brief)), {})
self.assertEqual(self.state().get("chores"), [])
def test_a_shell_worker_may_carry_the_id_line_on_any_line(self):
self.table(test_core.WORKERS)
self.write(os.path.join(self.data, "config.json"), json.dumps({"core": {"shell_workers": True, "enforce": True}}))
self.hook("prompt", prompt="build it")
self.done()
brief = self.sisi("models", "research", sid="s1")[1]
self.assertEqual(self.sisi("pick", "routine", sid="s1")[0], 0)
d = self.decision(self.tool("Bash", tool_input={"command": 'agy --print "\n%s"' % self.short_brief(brief)}))
self.assertNotIn("permissionDecision", d)
self.assertEqual(self.state()["chores"], [])
def test_deny_an_unpicked_model(self): def test_deny_an_unpicked_model(self):
self.ready_plan() self.ready_plan()
self.denied(self.agent("alpha", self.pick_header("a")), "the wheel did not give you this worker") self.denied(self.agent("alpha", self.pick_header("a")), "the wheel did not give you this worker")