Plan: the graph stays wide, exact and current by construction
- overlap refusal names the file and says to split the nodes or give the shared edit to one small owner
node; two nodes may share a file each in its own worktree under one worker join that needs both
- a need between two live nodes that share a file must say what it uses (`id (what)`), unless the node
merges parallel work or the need was already recorded: a need only to settle a shared file made a chain
- files are compared only between nodes that can still run (not done ones)
- `{a,b}.rs` in a files cell is each of its files (it was cut at the comma and collided falsely)
- every record, every `sisi plan` and every returning node prints the width (running or ready now, widest
wave, longest path of nodes left, class mix) and the nodes the most others build on; a chain is told to
re-plan, once at the end of a turn too; the pick header tells a worker how many nodes build on its result
- re-recording never resets a done node whose class, branch, files and check are unchanged (fault 41)
- `sisi judge WORKER` with several nameable open jobs and no --node/--chore refuses (fault 58)
- planning brief and rulebook: needs are results used, class by what builds on a node, the graph is
re-assessed as nodes return, a design node ends in a lead plan node
- size caps at the measured counts: code 3337 lines (was 3269), rulebook 146 lines, 12213 characters (was
11778); the owner said on 2026-12-05 to take the room needed
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
3241e977f3
commit
ab0d405394
7 files changed
+262
-35
No files matched your search
@@ -99,10 +99,10 @@ its limits are.
|
||||
| `sisi learn --level core\|user\|project "…" [--means "…"]` | The person's own words become a rule at once, tagged `[owner]` only when they appear in the person's recent messages in this session. `--means` adds, in the same undoable step, one line saying how the agent will apply it |
|
||||
| `sisi rules move "<start of a rule>" core\|user\|project\|canon [--project PATH]` | Move one rule line, verbatim, to another level, and print the command that moves it back: `sisi rules revert` does not undo a move (core is a queue for the product, in force as a user rule until it is added to canon/core.md, then `canon` takes it out of the queue); a level is always named, `project` needs a git repo, and organize also audits placement every `audit_after` (12) retros |
|
||||
| `sisi rules` / `sisi rules organize [--record FILE]` / `sisi rules revert` | See the learned rules; have a worker organize them (using known problems, prior attempts, and past drop reasons; an optional `## drops` section can record a reason and matching problem number for any dropped or merged rule, with `none given` recorded when omitted); undo the last rule change made with `learn`, a retro or `organize` (including any drop reasons recorded by that `organize`), in the user list or a project's `.sisi/rules.md` (not the one-time move of old rules; after `sisi rules move`, or an `organize` that moved lines between levels, it changes nothing and prints the command(s) that move them back, which that command also printed; a second `revert` re-applies what the first undid; it declines, changing nothing, when the project file changed since or its folder moved or is gone) |
|
||||
| `sisi plan brief` / `sisi plan --record FILE` / `sisi plan` / `sisi plan --done\|--fail ID "…"` | The dependency graph of a piece of work, recorded before any delegation: `\| node \| class \| needs \| branch \| files \| check \| why \|`, one join every node reaches; refused on a cycle, a missing need, a shared branch, or overlapping files between nodes that can run at once. Prints the waves to dispatch together. `sisi pick --node ID` gives the worker and a header for the brief; the hook denies a lead's delegation outside the plan, out of order, unpicked, or without its own worktree, and the end of a turn sends the lead back while ready nodes wait. `sisi judge` closes or reopens the node. A `sisi chore:` brief (models research, plan brief) needs no plan. `"enforce": false` turns denials into reminders |
|
||||
| `sisi plan brief` / `sisi plan --record FILE` / `sisi plan` / `sisi plan --done\|--fail ID "…"` | The dependency graph of a piece of work, recorded before any delegation: `\| node \| class \| needs \| branch \| files \| check \| why \|`, one join every node reaches; refused on a cycle, a missing need, a shared branch, or overlapping files between nodes that can still run at once (the refusal names the file and says to split the nodes or give the shared edit to one small owner node; two nodes may share a file each in its own worktree under one worker join that needs both). A need is only for a result the node uses: between two nodes that share a file it must say what, `id (what it uses from it)`, unless the node merges parallel work. Re-recording never resets a done node whose class, branch, files and check are unchanged. Every record, every `sisi plan` and every returning node prints the width (running or ready now, widest wave, longest path against nodes left, the class mix) and the nodes the most others build on; a chain (at most one node can run while four or more wait) is told to re-plan, once at the end of a turn too. Prints the waves to dispatch together. `sisi pick --node ID` gives the worker and a header for the brief; the hook denies a lead's delegation outside the plan, out of order, unpicked, or without its own worktree, and the end of a turn sends the lead back while ready nodes wait. `sisi judge` closes or reopens the node. A `sisi chore:` brief (models research, plan brief) needs no plan. `"enforce": false` turns denials into reminders |
|
||||
| `sisi models` / `sisi models research [--record FILE]` | The workers table: at most one row per provider (the plan or account a call draws on) per class (`routine`, `ordinary`, `hard`, `deep`), the cheapest among those within one point of the class's best score (a tie never goes to the dearer one; the dearest tier is its own class, `deep`, never a default for `hard`, `ordinary` or `routine`), the one whose published allowance goes furthest, with its source and quota windows (`5h: N req; week: N req`); the wheel picks a plan less the more of its windows sisi's own delegations have used (never below 5%); research is redone every 3 days by a hard worker. (the shared baseline table ships with sisi in `canon/models.md`), and each worker that is out with when it is back on the wheel; have a worker rebuild it |
|
||||
| `sisi models offered [--record FILE]` | Save the host's raw offered-model list from stdin and print the chore to match it against the table; `--record FILE` saves the harness's wheel so `sisi pick` only returns models this harness offers |
|
||||
| `sisi judge WORKER good\|bad\|out "…" [--minutes N] [--newest] [--node ID \| --chore ID]` | How a delegation went (`out` with the provider's own message when it hit a limit: off the wheel for 6 hours, then tried again); the minutes are measured from the pick's delegation (or `--minutes N`) and make the wheel favour faster workers. With several of one worker's jobs open, the oldest is judged first (and if another open job has `--node`/`--chore`, a note names the closed job and the remaining ones with their targeting flags), `--newest` the newest, `--node ID` closes or reopens the job running that plan node, and `--chore ID` closes that chore job |
|
||||
| `sisi judge WORKER good\|bad\|out "…" [--minutes N] [--newest] [--node ID \| --chore ID]` | How a delegation went (`out` with the provider's own message when it hit a limit: off the wheel for 6 hours, then tried again); the minutes are measured from the pick's delegation (or `--minutes N`) and make the wheel favour faster workers. With several of one worker's jobs open that `--node`/`--chore` can name, a verdict without one is refused and lists them (sisi never guesses which job is meant); `--newest` judges the newest and names what stays open, `--node ID` closes or reopens the job running that plan node, and `--chore ID` closes that chore job |
|
||||
| `sisi judge WORKER extend MINUTES "<reason>" [--newest] [--node ID \| --chore ID]` | Give a late job more time instead of judging it: the job that is past its limit (past twice it first, else past once, else the oldest, or the job for `--node ID` / `--chore ID`) gets MINUTES more from now, and its late fault clears |
|
||||
| `sisi direct "…"` | Allow more direct tool calls this turn, with the reason |
|
||||
|
||||
|
||||
+6
-2
@@ -63,8 +63,12 @@ final call. Class each piece (routine, ordinary, hard, deep) by total cost: your
|
||||
Near-free routine models take anything exactly specified (files, change, a deciding check) and keep being
|
||||
tried on it; judgement and design go to hard: a cheap job redone is waste. Plan first: `sisi plan brief` goes
|
||||
to a hard worker; `sisi plan --record FILE` keeps the graph: many small exact nodes (class, needs, branch,
|
||||
files, quick check, reach); joins merge and run slow checks. Nodes that run together get their own worktrees
|
||||
and disjoint files. Before the first pick and whenever sisi asks, give `sisi models offered` the full raw list
|
||||
files, quick check, reach); joins merge and run slow checks. Nodes that run together get their own worktrees,
|
||||
and disjoint files or one join that merges them. The graph is the strategy: keep it wide, exact and current. A
|
||||
need is only for a result the node uses, never to settle a shared file. What many nodes build on gets a class
|
||||
up and a review before they start; a leaf goes to the cheapest worker that can pass its check. When a node
|
||||
returns, re-assess what follows and record the plan again; a design node ends in a lead plan node that fills
|
||||
in the graph behind it. Before the first pick and whenever sisi asks, give `sisi models offered` the full raw list
|
||||
of models the host's delegation tool can start; hand its brief to a routine worker. For each ready node
|
||||
`sisi pick --node ID` spins the wheel over that class among models the host offers (new ones tried at once) and
|
||||
gives a worker and brief header with the reach; dispatch all ready nodes in one message. sisi refuses a
|
||||
|
||||
+8
-3
@@ -515,8 +515,8 @@ def sync_late(s, cwd, sid, add=True):
|
||||
|
||||
def judge(args, cwd=None):
|
||||
"""`sisi judge WORKER good|bad|out "<why>" [--minutes N] [--newest] [--node ID | --chore ID] | extend MINUTES "<why>" [--newest] [--node ID | --chore ID]`.
|
||||
Without --node/--chore a verdict closes the worker's oldest open job (--newest: its newest); with --node, the job that runs that
|
||||
plan node; with --chore, the job started under that chore id."""
|
||||
Without --node/--chore a verdict closes the worker's one open job, and refuses when several are open and can be named
|
||||
(--newest: its newest); with --node, the job that runs that plan node; with --chore, the job started under that chore id."""
|
||||
from . import retro # not at the top: hooks import this module and must stay quick
|
||||
args, newest, minutes, note, node, chore, warn = [a for a in args if a != "--newest"], "--newest" in args, None, "", None, None, ""
|
||||
if "--minutes" in args:
|
||||
@@ -567,6 +567,10 @@ def judge(args, cwd=None):
|
||||
return print("sisi judge: chore %s is not an open job for %s (open: %s). Nothing was changed." % (chore, wkey, ", ".join(jobs) or "none")) or 1
|
||||
if not ext: open_.remove(cand)
|
||||
else:
|
||||
infos = [_job_info(s, wkey, t) for t in open_ if type(t) in (int, float) and math.isfinite(t)]
|
||||
if not ext and not newest and len(infos) > 1 and any(f for _, f, _ in infos): # several open jobs: never guess which one is meant
|
||||
return print("sisi judge: %s has %d open jobs; name the one you judge: %s. Nothing was changed." % (
|
||||
wkey, len(infos), ", ".join("%s (started %s)" % (f, h) if f else "started %s (--newest if it is the newest)" % h for _, f, h in infos))) or 1
|
||||
cand = (open_.pop(-1 if newest else 0) if not ext else open_[-1 if newest else 0]) if open_ else None
|
||||
if ext and not newest: # the job that is late, not just the oldest open one
|
||||
cand = next((min(t for w, t, *_ in l if w == wkey) for l in (late(s, 2), late(s, 1)) if any(w == wkey for w, *_ in l)), cand)
|
||||
@@ -586,7 +590,8 @@ def judge(args, cwd=None):
|
||||
warn = "closed %s; still open: %s" % (closed, left)
|
||||
isinstance(s.get("meta"), dict) and s["meta"].pop("%s %r" % (wkey, cand), None)
|
||||
if node is not None: s["plan"]["state"][node] = {"st": "done", "evidence": "judged " + args[1]} if args[1] in ("good", "floor") else {"st": "failed", "why": "judged " + args[1]} # as plan.judged moves the node its job started
|
||||
elif s.get("plan"): from . import plan; plan.judged(s, wkey, cand, "good" if args[1] == "floor" else args[1])
|
||||
elif s.get("plan"): from . import plan; node = plan.judged(s, wkey, cand, "good" if args[1] == "floor" else args[1])
|
||||
if node is not None: warn = "\n".join(x for x in (warn, plan.back(s, node)) if x)
|
||||
if ok_t:
|
||||
began = cand
|
||||
minutes = minutes or max(1, int((now - began) / 60))
|
||||
|
||||
+78
-15
@@ -30,10 +30,12 @@ Answer with exactly one markdown table and nothing else:
|
||||
| node | class | needs | branch | files | check | reach | why |
|
||||
- node: a short id, [a-z0-9-], at most 30 characters, unique.
|
||||
- class: routine, ordinary, hard, deep, or lead (done by the lead itself: the final join, and judgement only it can make).
|
||||
- needs: the node ids that must be done first, comma-separated, or -.
|
||||
- needs: the node ids whose result it uses, comma-separated, or -. Never a need to settle a shared file: that makes
|
||||
a chain. A need on a node that shares a file with it says what it uses: `id (what it uses from it)`.
|
||||
- branch: its own git branch (each worker node gets its own worktree and build folder); - for a lead node.
|
||||
- files: the paths, folders or globs it may change, comma-separated (- for none). Nodes that can run at the same
|
||||
time must have disjoint files.
|
||||
time have disjoint files (split them by file, or give a shared edit to one small owner node), or share a file each
|
||||
in its own worktree with one join node that needs both, merges them and runs the checks.
|
||||
- check: how its result is proven, a check that can fail.
|
||||
- reach: a target far past the check, a number or a totality, that should feel a little delusional, e.g. "make this 100x faster", "delete half the codebase without breaking anything", "turn every bug we've ever fixed into a property test", "find all implicit invariants, formally prove them or find counterexamples"; the check alone decides done. - when there is no far target.
|
||||
- why: a few words on the class choice, e.g. "exact spec, test decides" or "design judgement, redo costly".
|
||||
@@ -51,12 +53,32 @@ record grows; judgement-heavy or design work goes to hard; deep (the dearest tie
|
||||
hardest jobs that need the most deep thought and highest intelligence (novel design, hard root causes, the central
|
||||
mechanism) — never banned and never a default for hard, ordinary or routine. Finishing or follow-up nodes (compile,
|
||||
fix, test an existing design) are ordinary, never inherited as hard or deep.
|
||||
Class by what builds on a node too: this is the strategy of the graph. A node whose result most later nodes use, or
|
||||
whose output decides what they do, is worth a class up and a review node before the rest starts: a mistake there is
|
||||
redone in every node after it. A leaf nothing builds on goes to the cheapest worker that can pass its check. Aim for
|
||||
a plan a large team of near-free workers carries, with a few ordinary, the occasional hard and a rare deep node.
|
||||
The graph is alive: where the work behind a design or fact-finding node cannot be planned until it returns, end that
|
||||
branch in a lead node `plan-<it>` that needs it; when it returns, the lead has the graph behind it filled in and
|
||||
records the plan again. Do not guess those nodes now.
|
||||
%(record)s
|
||||
"""
|
||||
|
||||
|
||||
def _cells(line): return [c.strip() for c in line.strip().strip("|").split("|")]
|
||||
def _list(cell): return [] if cell.strip() in ("", "-") else [x.strip() for x in cell.split(",") if x.strip()]
|
||||
def _brace(x):
|
||||
m = re.search(r"\{([^{}]*)\}", x)
|
||||
return [y for alt in m.group(1).split(",") for y in _brace(x[:m.start()] + alt.strip() + x[m.end():])] if m else [x]
|
||||
def _files(cell): return [y for x in re.split(r",(?![^{}]*\})", cell) if x.strip() not in ("", "-") for y in _brace(x.strip())] # `a/{b,c}.py` is a/b.py and a/c.py
|
||||
SPLIT = "split the nodes so their files differ, or give the shared edit to one small owner node"
|
||||
CHAIN = ("sisi: the plan is a chain: %d nodes wait behind %d that can run. Re-plan what is left as a wide graph of small, exactly specified nodes now: `sisi plan brief` "
|
||||
"to a hard worker, then `sisi plan --record FILE`. A need is only for a result the node uses; nodes that share a file are split, or run in their own worktrees under one join.")
|
||||
|
||||
|
||||
def _needs(cell):
|
||||
"""(the ids a needs cell names, {id: what the node uses from it}) from `a, b (what it uses), c`."""
|
||||
got = [(i.strip(), store.clean(u)) for i, u in re.findall(r"([^,()]+)(?:\(([^)]*)\))?", "" if cell.strip() == "-" else cell) if i.strip()]
|
||||
return [i for i, _ in got], {i: u for i, u in got if u}
|
||||
|
||||
|
||||
def parse(text):
|
||||
@@ -74,8 +96,9 @@ def parse(text):
|
||||
if len(c) != len(cols):
|
||||
return None, "row %r has %d cells, the header %d" % (c[0], len(c), len(cols))
|
||||
r = dict(zip(cols, c))
|
||||
nodes.append({"id": r["node"], "cls": r["class"].lower(), "needs": _list(r["needs"]), "branch": r["branch"],
|
||||
"files": _list(r["files"]), "check": store.clean(r["check"]), "reach": store.clean(r.get("reach", "")), "why": store.clean(r.get("why", ""))})
|
||||
needs, uses = _needs(r["needs"])
|
||||
nodes.append({"id": r["node"], "cls": r["class"].lower(), "needs": needs, "branch": r["branch"], **({"uses": uses} if uses else {}),
|
||||
"files": _files(r["files"]), "check": store.clean(r["check"]), "reach": store.clean(r.get("reach", "")), "why": store.clean(r.get("why", ""))})
|
||||
return (nodes, "") if nodes else (None, "no table found (a `| node | class | needs | branch | files | check |` header and rows)")
|
||||
|
||||
|
||||
@@ -101,8 +124,9 @@ def overlap(a, b):
|
||||
def beside(r, a, b): return a != b and a not in r[b] and b not in r[a]
|
||||
|
||||
|
||||
def check(nodes):
|
||||
"""The first problem with this plan, or ""."""
|
||||
def check(nodes, done=(), old=()):
|
||||
"""The first problem with this plan, or "". Files are compared only between nodes that can still run (not in `done`);
|
||||
a need already recorded (a (node, need) pair in `old`) is not asked what it uses."""
|
||||
ids, seen = {n["id"] for n in nodes}, set()
|
||||
branches = [n["branch"] for n in nodes if n["cls"] != "lead"]
|
||||
for n in nodes:
|
||||
@@ -119,11 +143,17 @@ def check(nodes):
|
||||
r = reach(nodes)
|
||||
if r is None:
|
||||
return "the needs hold a cycle"
|
||||
by, shares = {n["id"]: n for n in nodes}, lambda a, b: next(((x, y) for x in a["files"] for y in b["files"] if overlap(x, y)), None)
|
||||
for a in nodes:
|
||||
for b in nodes:
|
||||
hit = a["id"] < b["id"] and beside(r, a["id"], b["id"]) and next(((x, y) for x in a["files"] for y in b["files"] if overlap(x, y)), None)
|
||||
if hit:
|
||||
return "nodes %s and %s can run at the same time but both may change %s / %s: make the files disjoint or make one need the other" % (a["id"], b["id"], *hit)
|
||||
hit = a["id"] != b["id"] and not {a["id"], b["id"]} & set(done) and shares(a, b)
|
||||
if hit and a["id"] < b["id"] and beside(r, a["id"], b["id"]) and not any(n["cls"] != "lead" and {a["id"], b["id"]} <= set(n["needs"]) for n in nodes):
|
||||
return ("nodes %s and %s can run at the same time but both may change %s / %s: %s; or let each change it in its own worktree and "
|
||||
"add one join node (a worker's) that needs both, merges them and runs the checks" % (a["id"], b["id"], *hit, SPLIT))
|
||||
merges = any(x not in done and beside(r, a["id"], x) and shares(by[x], b) for x in b["needs"]) # b brings a's files together with work done beside a: a join, not a chain link
|
||||
if hit and a["id"] in b["needs"] and not merges and (b["id"], a["id"]) not in old and len(b.get("uses", {}).get(a["id"], "").split()) < 3:
|
||||
return ("node %s needs %s and both may change %s / %s. A need only to settle a shared file makes a chain: %s. If %s uses what %s produces, "
|
||||
"say what in the needs cell: `%s (what %s uses from it)`" % (b["id"], a["id"], *hit[::-1], SPLIT, b["id"], a["id"], a["id"], b["id"]))
|
||||
sinks = [n for n in nodes if not any(n["id"] in m["needs"] for m in nodes)]
|
||||
if len(sinks) != 1:
|
||||
return "the plan needs exactly one final join that every node leads to; it ends in %d nodes: %s" % (len(sinks), ", ".join(n["id"] for n in sinks))
|
||||
@@ -145,7 +175,7 @@ def get(s):
|
||||
return None
|
||||
ids = {n["id"] for n in p["nodes"]}
|
||||
for n in p["nodes"]:
|
||||
n["needs"], n["files"] = [x for x in n["needs"] if x in ids], [x for x in n["files"] if isinstance(x, str)]
|
||||
n["needs"], n["files"] = [x for x in n["needs"] if x in ids], _files(",".join(x for x in n["files"] if isinstance(x, str)))
|
||||
p["state"] = {k: v for k, v in p["state"].items() if isinstance(v, dict) and k in ids} if isinstance(p.get("state"), dict) else {}
|
||||
return p
|
||||
|
||||
@@ -161,6 +191,26 @@ def ready(p):
|
||||
def node(p, i): return next((n for n in p["nodes"] if n["id"] == i), None)
|
||||
|
||||
|
||||
def after(p):
|
||||
"""{id: how many nodes not done build on it, directly or not}."""
|
||||
r = reach(p["nodes"]) or {}
|
||||
return {i: sum(i in r[m["id"]] for m in p["nodes"] if st(p, m["id"]) != "done") for i in r}
|
||||
|
||||
|
||||
def width(p):
|
||||
"""(the plan's width over the nodes not done, as a line; the nodes most others build on, or ""; the re-plan message when it is a chain, or "")."""
|
||||
left = [n for n in p["nodes"] if st(p, n["id"]) != "done"]
|
||||
w = waves([dict(n, needs=[x for x in n["needs"] if st(p, x) != "done"]) for n in left])
|
||||
now = len(ready(p)) + sum(st(p, n["id"]) == "running" for n in left)
|
||||
mix = ", ".join("%s %d" % (c, k) for c in CLASSES if (k := sum(n["cls"] == c for n in left)))
|
||||
line = "width: %d running or ready now, widest wave %d, longest path %d of %d nodes left%s" % (
|
||||
now, max((list(w.values()).count(k) for k in w.values()), default=0), max(w.values(), default=0), len(left), " (%s)" % mix if mix else "")
|
||||
k = after(p)
|
||||
key = sorted((n for n in left if n["cls"] != "lead" and k.get(n["id"], 0) >= 3), key=lambda n: -k[n["id"]])[:3]
|
||||
return (line, "built on most: %s. What many nodes build on decides them all: class it up, brief it exactly, review it before they start." % ", ".join(
|
||||
"%s [%s] by %d" % (n["id"], n["cls"], k[n["id"]]) for n in key) if key else "", CHAIN % (len(left) - now, now) if now <= 1 and len(left) - now >= 4 else "")
|
||||
|
||||
|
||||
def record_line():
|
||||
"""sisi's own record per class: good of judged, over the last 20 judged jobs of each class."""
|
||||
from . import models
|
||||
@@ -186,7 +236,14 @@ def show(p):
|
||||
label = ("running (%s, since %s, %d min)" % (v.get("worker"), time.strftime("%H:%M", time.localtime(t)), (now - t) / 60) if s == "running"
|
||||
else "done" if s == "done" else "failed: %s" % v.get("why", "") if s == "failed" and n["id"] in rd else "ready" if n["id"] in rd else "waiting")
|
||||
out.append(" %s [%s] %s needs: %s" % (n["id"], n["cls"], label, ", ".join(n["needs"]) or "-"))
|
||||
return out + ["ready: " + (", ".join(rd) or "none")]
|
||||
return out + ["ready: " + (", ".join(rd) or "none")] + [x for x in width(p) if x]
|
||||
|
||||
|
||||
def back(s, i):
|
||||
"""What the lead is told when node `i` returns: the plan is a living graph, re-assessed at every return."""
|
||||
p = get(s)
|
||||
return "\n".join(["node %s is back (%s). Re-assess the plan now: does its result add, split, drop or re-class what follows? Fill in what it made plannable as small exact nodes, "
|
||||
"then `sisi plan --record FILE` (done and running nodes keep their state)." % (i, st(p, i)), "ready: " + (", ".join(ready(p)) or "none")] + [x for x in width(p) if x])
|
||||
|
||||
|
||||
def _sum(text): return hashlib.sha1(text.encode("utf-8", "replace")).hexdigest()
|
||||
@@ -223,15 +280,16 @@ def run(args, cwd=None):
|
||||
"checks": "\n".join(" %d. %s" % (i, c["text"]) for i, c in enumerate(d["checks"], 1))}, cwd) or 0
|
||||
if len(args) == 2 and args[0] == "--record":
|
||||
nodes, why = parse(store.read(args[1]))
|
||||
why = why or check(nodes) or ("" if sid else "no session; run this from the agent's session")
|
||||
with store.session(sid) if sid else contextlib.nullcontext({}) as s:
|
||||
old, new = get(s) or {"nodes": [], "state": {}}, {n["id"]: n for n in nodes or []}
|
||||
same = lambda i: i in new and all(node(old, i).get(k) == new[i].get(k) for k in ("cls", "branch", "files", "check")) # the work itself is unchanged
|
||||
keep = {i for i, v in old["state"].items() if v.get("st") == "running" or node(old, i) == new.get(i) or (v.get("st") == "done" and same(i))}
|
||||
why = why or check(nodes, {i for i in keep if st(old, i) == "done"}, {(n["id"], x) for n in old["nodes"] for x in n["needs"]}) or ("" if sid else "no session; run this from the agent's session")
|
||||
moved = [i for i, v in old["state"].items() if v.get("st") == "running" and (i not in new or (
|
||||
new[i]["branch"], new[i]["files"]) != (node(old, i)["branch"], node(old, i)["files"]))]
|
||||
why = why or (moved and "node %s is running: keep its id, branch and files in the new plan, or judge it first" % moved[0])
|
||||
if why:
|
||||
return print("sisi plan: %s. Nothing was recorded." % why) or 1
|
||||
keep = {i for i, v in old["state"].items() if v.get("st") == "running" or node(old, i) == new.get(i)}
|
||||
s["plan"] = p = {"nodes": nodes, "state": {i: v for i, v in old["state"].items() if i in keep and i in new}}
|
||||
w = waves(nodes)
|
||||
print("plan recorded: %d nodes, critical path %d wave(s)." % (len(nodes), max(w.values())))
|
||||
@@ -241,7 +299,7 @@ def run(args, cwd=None):
|
||||
go, mine = [i for i in rd if node(p, i)["cls"] != "lead"], [i for i in rd if node(p, i)["cls"] == "lead"]
|
||||
go and print("dispatch wave 1 now, all in one message: %s (`sisi pick --node ID` for each)" % ", ".join(go))
|
||||
mine and print("yours to do now: %s" % ", ".join(mine))
|
||||
print(record_line())
|
||||
print("\n".join(x for x in (*width(p), record_line()) if x))
|
||||
return 0
|
||||
if len(args) == 3 and args[0] in ("--done", "--fail") and len(args[2].split()) >= 3 and sid:
|
||||
with store.session(sid) as s:
|
||||
@@ -252,7 +310,7 @@ def run(args, cwd=None):
|
||||
if why:
|
||||
return print("sisi plan: %s." % why) or 1
|
||||
p["state"][args[1]] = {"st": "done", "evidence": store.clean(args[2])} if args[0] == "--done" else {"st": "failed", "why": store.clean(args[2])}
|
||||
print("\n".join(show(p)))
|
||||
print("\n".join(show(p)[:-len([x for x in width(p) if x]) - 1] + [back(s, args[1])]))
|
||||
return 0
|
||||
if not args:
|
||||
p = None
|
||||
@@ -283,6 +341,7 @@ def header(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"],
|
||||
"may change: " + (", ".join(n["files"]) or "nothing"), "check: " + n["check"],
|
||||
"reach: " + (n.get("reach") or "-"), REACH_LINE,
|
||||
*(["built on by: %d later nodes; what you make decides theirs, so get it right and report any doubt" % k] if (k := after(p).get(i, 0)) >= 3 else []),
|
||||
"needs done: " + (", ".join("%s on %s (%s)" % (x, node(p, x)["branch"], p["state"].get(x, {}).get("evidence", "")) for x in n["needs"]) or "-")])
|
||||
|
||||
|
||||
@@ -297,6 +356,7 @@ def judged(s, worker, t, verdict):
|
||||
hit = next((i for i, v in p["state"].items() if v.get("st") == "running" and v.get("worker") == worker and v.get("since") == t), None) if p and t is not None else None
|
||||
if hit:
|
||||
p["state"][hit] = {"st": "done", "evidence": "judged good"} if verdict == "good" else {"st": "failed", "why": "judged " + verdict}
|
||||
return hit
|
||||
|
||||
|
||||
def starts(brief, shell):
|
||||
@@ -346,4 +406,7 @@ def gate(s):
|
||||
if go:
|
||||
return "sisi: nodes %s are ready and not started: pick and dispatch them all now in one message (%s)." % (
|
||||
", ".join(go), " ".join("`sisi pick --node %s`" % i for i in go))
|
||||
if p and not p.get("told") and width(p)[2]: # once per recorded plan: the gate helps, it does not nag
|
||||
p["told"] = 1
|
||||
return width(p)[2]
|
||||
return ""
|
||||
+3
-3
@@ -4751,10 +4751,10 @@ cli.main(["tick"])
|
||||
|
||||
def test_the_product_stays_small(self):
|
||||
code = sum(len(self.read(p).splitlines()) for p in glob.glob(os.path.join(REPO, "sisi", "*.py")))
|
||||
self.assertLessEqual(code, 3269, "sisi is two loops. If it needs more than this, find the simpler shape.")
|
||||
self.assertLessEqual(code, 3337, "sisi is two loops. If it needs more than this, find the simpler shape.")
|
||||
rulebook = self.read(REPO, "canon", "core.md")
|
||||
self.assertLess(len(rulebook.splitlines()), 144)
|
||||
self.assertLessEqual(len(rulebook), 11778)
|
||||
self.assertLess(len(rulebook.splitlines()), 147)
|
||||
self.assertLessEqual(len(rulebook), 12213)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -133,21 +133,29 @@ class JudgeChore(unittest.TestCase):
|
||||
self.assertEqual(rc_j1, 0, out_j1)
|
||||
self.assertEqual(self.state()["starts"]["alpha"], [])
|
||||
|
||||
def test_2_judge_without_flag_warns_with_closed_and_open_targets(self):
|
||||
def test_2_judge_without_flag_refuses_to_guess_and_newest_says_what_it_closed(self): # fault 58
|
||||
cid1 = self.start_chore("plan", "brief")
|
||||
time.sleep(0.02)
|
||||
cid2 = self.start_chore("models", "research")
|
||||
t1, t2 = self.state()["starts"]["alpha"]
|
||||
|
||||
rc, out, _ = self.sisi("judge", "alpha", "good", "oldest chore finished cleanly")
|
||||
before_state, before_out = self.state(), self.outcomes()
|
||||
rc, out, _ = self.sisi("judge", "alpha", "good", "one chore finished cleanly")
|
||||
self.assertEqual(rc, 1, out)
|
||||
self.assertEqual(len(out.strip().splitlines()), 1, out)
|
||||
self.assertIn("--chore " + cid1, out)
|
||||
self.assertIn("--chore " + cid2, out)
|
||||
self.assertIn("Nothing was changed", out)
|
||||
self.assertEqual((self.state(), self.outcomes()), (before_state, before_out))
|
||||
|
||||
rc, out, _ = self.sisi("judge", "alpha", "good", "newest chore finished cleanly", "--newest")
|
||||
self.assertEqual(rc, 0, out)
|
||||
self.assertEqual(self.state()["starts"]["alpha"], [t2])
|
||||
self.assertEqual(self.state()["starts"]["alpha"], [t1])
|
||||
lines = out.strip().splitlines()
|
||||
self.assertEqual(len(lines), 2, out)
|
||||
self.assertIn("job started %s" % time.strftime("%H:%M", time.localtime(t1)), lines[0])
|
||||
self.assertIn(cid1, lines[1])
|
||||
self.assertIn("job started %s" % time.strftime("%H:%M", time.localtime(t2)), lines[0])
|
||||
self.assertIn(cid2, lines[1])
|
||||
self.assertIn("--chore " + cid2, lines[1])
|
||||
self.assertIn("--chore " + cid1, lines[1])
|
||||
|
||||
def test_3_stop_gate_lists_unjudged_jobs_on_one_line_without_blocking_on_them(self):
|
||||
graph = ("| node | class | needs | branch | files | check | why |\n|---|---|---|---|---|---|---|\n"
|
||||
|
||||
+151
-4
@@ -18,6 +18,7 @@ PLAN = COLS + (
|
||||
"| b | ordinary | - | p-b | sisi/b.py | test b passes | some judgement |\n"
|
||||
"| c | hard | a, b | p-c | sisi/c.py | test c passes | design judgement, redo costly |\n"
|
||||
"| join | lead | c | - | - | full suite passes | the lead merges |\n")
|
||||
APART = PLAN.replace("| c | hard | a, b |", "| c | hard | a |").replace("| join | lead | c |", "| join | lead | b, c |") # no worker node joins a and b
|
||||
|
||||
|
||||
class Plan(unittest.TestCase):
|
||||
@@ -91,12 +92,139 @@ class Plan(unittest.TestCase):
|
||||
self.refused(PLAN.replace("| p-b |", "| - |"), "node b needs a branch of its own")
|
||||
|
||||
def test_refuses_parallel_nodes_that_share_files(self):
|
||||
for a, b in (("sisi/a.py", "sisi/a.py"), ("sisi", "sisi/b.py"), ("sisi/*.py", "sisi/b.py")):
|
||||
self.refused(PLAN.replace("| sisi/a.py |", "| %s |" % a).replace("| sisi/b.py |", "| %s |" % b),
|
||||
for a, b in (("sisi/a.py", "sisi/a.py"), ("sisi/a", "sisi/a/b.py"), ("sisi/a*.py", "sisi/ab.py")):
|
||||
self.refused(APART.replace("| sisi/a.py |", "| %s |" % a).replace("| sisi/b.py |", "| %s |" % b),
|
||||
"nodes a and b can run at the same time")
|
||||
|
||||
def test_nodes_in_sequence_may_share_files(self):
|
||||
self.ready_plan(text=PLAN.replace("| sisi/c.py |", "| sisi/a.py, sisi/b.py |"))
|
||||
def test_parallel_nodes_may_share_files_under_a_worker_join_that_needs_both(self): # each in its own worktree; the join merges
|
||||
out = self.ready_plan(text=PLAN.replace("| sisi/b.py |", "| sisi/a.py |"))
|
||||
self.assertIn("dispatch wave 1 now, all in one message: a, b", out)
|
||||
self.pick("a")
|
||||
self.denied(self.tool("Agent", tool_input={"model": "alpha", "prompt": self.pick_header("a")}), "worktree")
|
||||
|
||||
def test_a_brace_list_of_files_is_each_of_its_files(self): # `{a,x}.py` was cut at its comma: "x}.py" then collided with any other
|
||||
self.ready_plan(text=APART.replace("| sisi/a.py |", "| sisi/{a,x}.py |").replace("| sisi/b.py |", "| tests/{b, x}.py, docs |"))
|
||||
nodes = self.state()["plan"]["nodes"]
|
||||
self.assertEqual((nodes[0]["files"], nodes[1]["files"]), (["sisi/a.py", "sisi/x.py"], ["tests/b.py", "tests/x.py", "docs"]))
|
||||
st = self.state()
|
||||
st["plan"]["nodes"][0]["files"], st["plan"]["state"] = ["sisi/{a", "x}.py"], {"a": {"st": "running", "worker": "alpha", "since": 1.0}} # as recorded before
|
||||
self.write(os.path.join(self.tmp, "state", "core-sessions", "s1.json"), json.dumps(st))
|
||||
rc, out, _ = self.record(APART.replace("| sisi/a.py |", "| sisi/{a,x}.py |"))
|
||||
self.assertEqual(rc, 0, out) # the running node's files are the same files
|
||||
self.assertEqual(self.nodes(), {"a": "running"})
|
||||
rc, out, _ = self.record(APART.replace("| sisi/a.py |", "| sisi/{a,x}.py |").replace("| sisi/b.py |", "| sisi/{b,x}.py |"))
|
||||
self.assertEqual((rc, "sisi/x.py" in out), (1, True), out)
|
||||
|
||||
def test_overlap_refusal_names_the_file_and_never_offers_a_need(self):
|
||||
rc, out, _ = self.record(APART.replace("| sisi/b.py |", "| sisi/a.py |"))
|
||||
self.assertEqual(rc, 1, out)
|
||||
self.assertIn("sisi/a.py", out)
|
||||
self.assertIn("one join node", out)
|
||||
self.assertIn("split the nodes so their files differ", out)
|
||||
self.assertIn("one small owner node", out)
|
||||
self.assertNotIn("need the other", out)
|
||||
|
||||
def test_a_need_between_nodes_that_share_a_file_must_say_what_it_uses(self):
|
||||
shared = PLAN.replace("| sisi/c.py |", "| sisi/a.py, sisi/b.py |").replace("| b | ordinary | - |", "| b | ordinary | a |")
|
||||
rc, out, _ = self.record(shared)
|
||||
self.assertEqual(rc, 1, out)
|
||||
self.assertIn("node c needs a and both may change sisi/a.py", out)
|
||||
self.assertIn("a (what c uses from it)", out)
|
||||
self.assertIn("one small owner node", out)
|
||||
self.refused(shared.replace("| a, b |", "| a (its parser), b (its table) |"), "node c needs a and both may change") # two words say nothing
|
||||
out = self.ready_plan(text=shared.replace("| a, b |", "| a (the parser a adds, with its errors), b (the table b writes) |"))
|
||||
st = self.state()["plan"]["nodes"][2]
|
||||
self.assertEqual((st["needs"], st["uses"]["a"]), (["a", "b"], "the parser a adds, with its errors"))
|
||||
self.assertIn("ready: a\n", self.sisi("plan", sid="s1")[1])
|
||||
|
||||
def test_a_second_need_does_not_hide_a_collision_need(self): # c merges nothing of b: its need on a is still asked what it uses
|
||||
self.refused(PLAN.replace("| sisi/c.py |", "| sisi/a.py, sisi/c.py |"), "node c needs a and both may change sisi/a.py")
|
||||
self.ready_plan(text=PLAN.replace("| sisi/c.py |", "| sisi/a.py, sisi/c.py |").replace("| a, b |", "| a (the parser a adds), b |"))
|
||||
|
||||
def test_a_recorded_need_between_sharing_nodes_is_not_asked_again(self): # a plan recorded before the rule keeps recording
|
||||
shared = PLAN.replace("| sisi/c.py |", "| sisi/a.py, sisi/b.py |").replace("| b | ordinary | - |", "| b | ordinary | a |")
|
||||
self.ready_plan(text=PLAN.replace("| b | ordinary | - |", "| b | ordinary | a |"))
|
||||
st = self.state()
|
||||
st["plan"]["nodes"][2]["files"] = ["sisi/a.py", "sisi/b.py"]
|
||||
self.write(os.path.join(self.tmp, "state", "core-sessions", "s1.json"), json.dumps(st))
|
||||
self.assertEqual(self.record(shared)[0], 0)
|
||||
|
||||
def test_files_shared_with_a_done_node_are_no_overlap(self):
|
||||
self.ready_plan()
|
||||
self.assertEqual(self.sisi("plan", "--done", "a", "done by hand and tested", sid="s1")[0], 0)
|
||||
more = PLAN.replace("| join | lead | c |", "| d | routine | - | p-d | sisi/a.py | test d passes | follow-up on a's file |\n"
|
||||
"| e | routine | a | p-e | sisi/a.py, sisi/e.py | test e passes | uses done a |\n| join | lead | c, d, e |")
|
||||
rc, out, _ = self.record(more)
|
||||
self.assertEqual((rc, "nodes d and e" in out), (1, True), out) # two live nodes still may not share a file
|
||||
rc, out, _ = self.record(more.replace("| sisi/a.py, sisi/e.py |", "| sisi/e.py |"))
|
||||
self.assertEqual(rc, 0, out)
|
||||
self.assertEqual(self.nodes(), {"a": "done"})
|
||||
|
||||
def test_record_and_plan_print_the_width(self):
|
||||
out = self.ready_plan()
|
||||
line = "width: 2 running or ready now, widest wave 2, longest path 3 of 4 nodes left"
|
||||
self.assertIn(line, out)
|
||||
self.assertIn(line, self.sisi("plan", sid="s1")[1])
|
||||
self.assertNotIn("chain", out)
|
||||
for n in ("a", "b"):
|
||||
self.assertEqual(self.sisi("plan", "--done", n, "done by hand and tested", sid="s1")[0], 0)
|
||||
self.assertIn("width: 1 running or ready now, widest wave 1, longest path 2 of 2 nodes left", self.sisi("plan", sid="s1")[1])
|
||||
|
||||
CHAIN = COLS + "| n1 | routine | - | p-1 | sisi/1.py | test 1 passes | exact |\n" + "".join(
|
||||
"| n%d | routine | n%d | p-%d | sisi/%d.py | test %d passes | exact |\n" % (k, k - 1, k, k, k) for k in range(2, 6)) + "| join | lead | n5 | - | - | full suite passes | the lead merges |\n"
|
||||
|
||||
def test_a_chain_is_told_to_replan_at_record_plan_and_once_at_the_gate(self):
|
||||
out = self.ready_plan(text=self.CHAIN)
|
||||
self.assertIn("width: 1 running or ready now, widest wave 1, longest path 6 of 6 nodes left", out)
|
||||
for text in (out, self.sisi("plan", sid="s1")[1]):
|
||||
self.assertIn("the plan is a chain: 5 nodes wait behind 1", text)
|
||||
self.assertIn("built on most: n1 [routine] by 5, n2 [routine] by 4, n3 [routine] by 3", text)
|
||||
self.assertIn("sisi plan brief", text)
|
||||
self.assertNotIn("built on", self.ready_plan(sid="s2")) # nothing in a small plan carries three others
|
||||
self.assertIn("built on by: 5 later nodes", self.pick("n1"))
|
||||
self.assertEqual(self.decision(self.agent("alpha", self.pick_header("n1"))), {})
|
||||
out = self.hook("gate")[1]
|
||||
self.assertIn('"block"', out)
|
||||
self.assertIn("the plan is a chain", out)
|
||||
self.assertIn("plan brief", out)
|
||||
self.assertNotIn("the plan is a chain", self.hook("gate")[1]) # said once per recorded plan: a gate helps, it does not nag
|
||||
self.assertEqual(self.record(self.CHAIN)[0], 0)
|
||||
self.assertIn("the plan is a chain", self.hook("gate")[1]) # a new record of a chain is told again
|
||||
|
||||
def test_a_wide_plan_is_never_told_to_replan(self):
|
||||
wide = COLS + "".join("| n%d | routine | - | p-%d | sisi/%d.py | test %d passes | exact |\n" % (k, k, k, k) for k in range(1, 7)) + \
|
||||
"| join | lead | n1, n2, n3, n4, n5, n6 | - | - | full suite passes | the lead merges |\n"
|
||||
out = self.ready_plan(text=wide)
|
||||
self.assertIn("width: 6 running or ready now, widest wave 6, longest path 2 of 7 nodes left", out)
|
||||
self.assertNotIn("chain", out)
|
||||
|
||||
def test_rerecording_changed_needs_keeps_done_nodes(self): # fault 41
|
||||
self.ready_plan()
|
||||
for n in ("a", "b"):
|
||||
self.assertEqual(self.sisi("plan", "--done", n, "done by hand and tested", sid="s1")[0], 0)
|
||||
rc, out, _ = self.record(PLAN.replace("| b | ordinary | - |", "| b | ordinary | a |").replace("some judgement", "another reason"))
|
||||
self.assertEqual(rc, 0, out)
|
||||
self.assertEqual(self.nodes(), {"a": "done", "b": "done"})
|
||||
self.assertEqual(self.state()["plan"]["state"]["b"]["evidence"], "done by hand and tested")
|
||||
self.assertEqual(self.record(PLAN.replace("test b passes", "test b and b2 pass"))[0], 0)
|
||||
self.assertEqual(self.nodes(), {"a": "done"}) # a done node whose work changed is open again
|
||||
|
||||
def test_judge_refuses_to_guess_between_two_running_nodes(self): # fault 58
|
||||
self.ready_plan(text=PLAN.replace("| b | ordinary |", "| b | routine |"))
|
||||
for n in ("a", "b"):
|
||||
self.pick(n)
|
||||
self.assertEqual(self.decision(self.agent("alpha", self.pick_header(n))), {})
|
||||
before = self.state()
|
||||
rc, out, _ = self.sisi("judge", "alpha", "good", "did the work well", sid="s1")
|
||||
self.assertEqual(rc, 1, out)
|
||||
self.assertIn("--node a", out)
|
||||
self.assertIn("--node b", out)
|
||||
self.assertIn("Nothing was changed", out)
|
||||
self.assertEqual(self.state(), before)
|
||||
self.assertEqual(self.sisi("judge", "alpha", "good", "did the work well", "--node", "b", sid="s1")[0], 0)
|
||||
self.assertEqual(self.nodes(), {"a": "running", "b": "done"})
|
||||
self.assertEqual(self.sisi("judge", "alpha", "good", "did the work well", sid="s1")[0], 0) # one open job: nothing to guess
|
||||
self.assertEqual(self.nodes(), {"a": "done", "b": "done"})
|
||||
|
||||
def test_refuses_more_than_one_sink(self):
|
||||
self.refused(PLAN.replace("| c | hard | a, b |", "| c | hard | a |"), "exactly one final join")
|
||||
@@ -713,6 +841,25 @@ class Plan(unittest.TestCase):
|
||||
self.assertIn("ready: b", out)
|
||||
self.assertIn("a [routine] done", out)
|
||||
|
||||
def test_a_node_coming_back_has_the_plan_reassessed(self): # the graph is kept current as nodes return
|
||||
self.ready_plan()
|
||||
self.pick("a")
|
||||
self.agent("alpha", self.pick_header("a"))
|
||||
out = self.sisi("judge", "alpha", "good", "did the work well", "--node", "a", sid="s1")[1]
|
||||
self.assertIn("node a is back (done). Re-assess the plan now", out)
|
||||
self.assertIn("sisi plan --record FILE", out)
|
||||
self.assertIn("width: 1 running or ready now, widest wave 1, longest path 3 of 3 nodes left", out)
|
||||
self.pick("b")
|
||||
self.tool("Agent", tool_input={"model": "beta", "prompt": self.pick_header("b"), "isolation": "worktree"})
|
||||
out = self.sisi("judge", "beta", "bad", "broke the tests badly", sid="s1")[1]
|
||||
self.assertIn("node b is back (failed). Re-assess the plan now", out)
|
||||
out = self.sisi("plan", "--done", "b", "done by hand and tested", sid="s1")[1]
|
||||
self.assertIn("node b is back (done). Re-assess the plan now", out)
|
||||
brief = self.sisi("plan", "brief", sid="s1")[1]
|
||||
self.assertIn("cannot be planned until", brief)
|
||||
self.assertIn("own worktree", brief)
|
||||
self.assertIn("what builds on a node", brief)
|
||||
|
||||
def test_gate_sends_the_lead_back_while_nodes_are_ready_and_not_started(self):
|
||||
self.ready_plan()
|
||||
rc, out, _ = self.hook("gate")
|
||||
|
||||
Reference in new issue
Block a user