From 8aa79ab4920ded0e99f2955e480034cfd1bd9b11 Mon Sep 17 00:00:00 2001 From: sisi Date: Wed, 2 Dec 2026 10:21:31 -0700 Subject: [PATCH] Chore briefs carry a one-time id: delegate the first line, worker prints the brief by id --- sisi/cli.py | 5 ++- sisi/models.py | 4 +- sisi/plan.py | 45 +++++++++++----------- sisi/rules.py | 4 +- tests/test_plan.py | 94 +++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 123 insertions(+), 29 deletions(-) diff --git a/sisi/cli.py b/sisi/cli.py index 79bd35c..2ea10ce 100644 --- a/sisi/cli.py +++ b/sisi/cli.py @@ -34,6 +34,7 @@ Delegation | files | check | why |) before handing out any work; `sisi plan` shows each node sisi plan --done ID EVIDENCE | --fail ID WHY 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 ` and do what it says" 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] 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"): from . import retro return (retro.run if cmd == "retro" else retro.done)(args) - if cmd == "plan": + if cmd in ("plan", "chore"): from . import plan - return plan.run(args) + return plan.run(args) if cmd == "plan" else plan.chore(args) if cmd == "fault": from . import faults return faults.run(args) diff --git a/sisi/models.py b/sisi/models.py index 987895d..4ee96dc 100644 --- a/sisi/models.py +++ b/sisi/models.py @@ -63,8 +63,8 @@ Then one line starting "Fallback order:" that says who takes over when a worker === How delegations went here, newest last === %(outcomes)s """ -ASK = ("In the background, give the output of `sisi models research` 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`.") +ASK = ("In the background, delegate just the first line of the output of `sisi models research` plus \"Run `sisi chore show ` and do what it says\" " + "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") diff --git a/sisi/plan.py b/sisi/plan.py index 2ef9dfd..4fa3a1e 100644 --- a/sisi/plan.py +++ b/sisi/plan.py @@ -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 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.""" -import contextlib, fnmatch, hashlib, re, time +import contextlib, fnmatch, hashlib, os, re, time from . import store CLASSES = ("routine", "ordinary", "hard", "lead") 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) -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 "" | sisi plan --fail ID ""\n' " 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() +_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): - """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.""" - text = text.strip() + """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.""" + 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): 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) +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): sid = store.current_session(cwd) if args == ["brief"]: @@ -240,15 +250,12 @@ def run(args, cwd=None): if not args: p = None if sid: - with store.session(sid) as s: - p = get(s) + with store.session(sid) as 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 - print(USAGE) - return 1 + return print(USAGE) or 1 -def why_not(p, i): - 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") +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") 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 else "node %s is the lead's own: do it and run `sisi plan --done %s \"\"`" % (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 "") - if why: - print("sisi pick: %s." % why) - return None, None + if why: return print("sisi pick: %s." % why) or (None, None) return [n["cls"]] + args[2:] + ["--branch", n["branch"]], 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["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 := node(p, i))["branch"], "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 "-")]) @@ -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) chores, c = (s["chores"] if isinstance(s.get("chores"), list) else []), line(CHORE_LINE) 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 - and any(_sum(brief[i:i + x[2]]) == x[1] for i in at)), None) - return ("", None, hit) if hit is not None else (( - "sisi: this `sisi chore: %s` brief is not one sisi printed in this session: print the chore's brief again (`sisi plan brief`, " - "`sisi models research` or `sisi rules organize`) and send it unchanged at the top of the brief." % c.group(1)), None, None) + name, cid = c.group(1), c.group(2) + 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 + 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) + 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 "")), None, None) 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 " "(it carries its `sisi chore: plan` line), then `sisi plan --record FILE`."), None, None diff --git a/sisi/rules.py b/sisi/rules.py index 7fd97c4..77076b5 100644 --- a/sisi/rules.py +++ b/sisi/rules.py @@ -358,8 +358,8 @@ def due(cwd, claim=False): cl.update({"claim:" + k: now for k, _ in need}) with contextlib.suppress(OSError): 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 " - "`sisi rules organize` to a cheap worker and record its answer with `sisi rules organize --record FILE`." + return ("sisi: the learned rules need organizing (%s). In the background, delegate just the first line of the output of " + "`sisi rules organize` plus \"Run `sisi chore show ` 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)) diff --git a/tests/test_plan.py b/tests/test_plan.py index 7d575bc..ae0891e 100644 --- a/tests/test_plan.py +++ b/tests/test_plan.py @@ -158,7 +158,7 @@ class Plan(unittest.TestCase): self.ready_plan() rc, out, _ = self.sisi("plan", "brief", sid="s1") 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 |", "Class by total cost", "routine nodes whenever their", "record (last 20 judged per class)"): self.assertIn(want, out) @@ -283,11 +283,101 @@ class Plan(unittest.TestCase): self.hook("prompt", prompt="tidy up") for args, line in ((("rules", "organize"), "sisi chore: rules organize"), (("models", "research"), "sisi chore: models research")): 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.assertNotIn("permissionDecision", self.decision(self.agent("alpha", brief)), line) 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): self.ready_plan() self.denied(self.agent("alpha", self.pick_header("a")), "the wheel did not give you this worker")