From e35dd4982830a0ce3f860a86cab6a5df70a0597a Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Thu, 3 Dec 2026 07:38:35 -0700 Subject: [PATCH] Pick only from models the harness offers: saved raw list is truth, table is a hint Co-Authored-By: Claude Sonnet 5.5 --- sisi/cli.py | 2 ++ sisi/hooks.py | 2 +- sisi/models.py | 94 ++++++++++++++++++++++++++++++++++++-------------- sisi/plan.py | 2 +- 4 files changed, 73 insertions(+), 27 deletions(-) diff --git a/sisi/cli.py b/sisi/cli.py index 2ea10ce..cd54be1 100644 --- a/sisi/cli.py +++ b/sisi/cli.py @@ -30,6 +30,8 @@ Delegation sisi models the workers you have: what each is good at and what it costs sisi models research [--record FILE] the brief for a research worker to rebuild that table; record its answer + sisi models offered [--record FILE] + save the host's raw model list (stdin); record the worker's table of those models sisi plan brief | --record FILE the brief for a planning worker; record its graph (| node | class | needs | branch | files | check | why |) before handing out any work; `sisi plan` shows each node sisi plan --done ID EVIDENCE | --fail ID WHY diff --git a/sisi/hooks.py b/sisi/hooks.py index 37d22bb..73f61d7 100644 --- a/sisi/hooks.py +++ b/sisi/hooks.py @@ -226,7 +226,7 @@ def _outside(s, tool, ti, brief, text, shell, names, cfg): s.get("done") or chore is not None or why.append(NODONE) stray and (cfg["enforce"] or plan.get(s)) and why.append(stray) # as reminders, plan notes only once there is a plan probe = json.loads(json.dumps({k: s.get(k) for k in ("picked", "starts", "pending", "meta", "workers_since") if k in s})) - table_text = store.read(models.table()) + table_text = store.read(models.table()) + models.wheel()[0] if tool != "workflow" and not models.claim(probe, text, not shell and bool(names[0]), node): known = models.known(table_text, text) if models.usable(table_text): # with no usable table there is nothing to pick from: `sisi models` says to research it diff --git a/sisi/models.py b/sisi/models.py index 4ee96dc..2309059 100644 --- a/sisi/models.py +++ b/sisi/models.py @@ -2,7 +2,7 @@ A research worker writes it, the lead reads it to route, and `sisi judge` adds how each delegation went so the next research knows. The table is plain text a person can read and correct.""" -import json, math, os, re, time +import json, math, os, re, sys, time from . import rules, store ASK_FRESH = ("which providers and models from the shipped baseline table below are usable on this machine, how to call each, and what each costs here; map them to whatever providers this user has", @@ -34,7 +34,6 @@ Find out %(intro)s, and write the personal table an engineering lead will route 4. %(step4)s 5. What the person has said, below, stands exactly and outranks all of this: it is not yours to change. -List only workers the host's delegation tool can actually start: check the host's own list of enabled providers. Answer with exactly this and nothing else. First a markdown table of at most 40 rows, at most one row per provider per class, ordered within each class most efficient first (the wheel weights by row order), with these columns: | worker | provider | maker | how to call it | use for | cost | efficiency | good at, bad at | notes | @@ -63,6 +62,23 @@ Then one line starting "Fallback order:" that says who takes over when a worker === How delegations went here, newest last === %(outcomes)s """ +REFRESH = "ask the host for every model its delegation tool can start, save its raw answer to a file and run `sisi models offered < FILE`." +OFFERED = """sisi chore: models offered +You are a worker. Do this task yourself; do not delegate it further. + +Below is the host's raw list of the models it offers, and the researched table. Write one table row per offered model (at most 80) +in the table's columns (| worker | provider | maker | how to call it | use for | cost | efficiency | good at, bad at | notes |). A known model: copy +its row, with "how to call it" replaced by the exact dispatch from the list. An unknown model: a provisional row (provider, maker, use for +exactly one of routine|ordinary|hard as a guess, the dispatch, notes starting `new: `). Skip any provider the list marks +disabled or unable to run child tasks. Never invent an id: each worker id must appear verbatim in the list and in its dispatch. Write the table to a +file and run `sisi models offered --record FILE`. + +=== The table now === +%s + +=== Offered by this harness === +%s +""" 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`.") @@ -100,6 +116,22 @@ def age_days(): except OSError: return None +def _has(raw, i): return bool(i) and bool(re.search(r"(? store.config().get("offered_hours", 24) + else "" if usable(text) else "no offered model has a row") + + def stale(mark=None): """One line when the table is missing, old, or missed a worker, else "".""" who = re.sub(r"[^\w./:+-]", "", str(store.read(store.data("models.stale")) if mark is None else mark), flags=re.A)[:80] @@ -107,6 +139,7 @@ def stale(mark=None): try: store.write(store.data("models.stale"), who + "\n") except Exception: pass # best effort: a refusal never depends on it age = age_days() + if why := wheel()[1]: return "sisi: %s: %s" % (why, REFRESH) if age is None or age > store.config()["research_days"]: return "sisi: " + ("there is no models table yet. " if age is None else "the models table is %d days old. " % age) + ASK return ("sisi: a delegation named `%s`, which the models table does not list. " % who + ASK) if who and not known(store.read(table()), who) else "" @@ -210,28 +243,20 @@ clock = lambda t: time.strftime("%m-%d %H:%M", time.localtime(t)) SINCE = "out since %s, back on the wheel at %s" -def outs(text, log, written, today=None, now=None): - """{worker: (since, why)}: each worker last said to be out, and when. An `out` verdict in the log says it, and any - later verdict takes it back. A table from before `out` verdicts says it with a note, `out until DATE` (DATE today or - later), unless the log holds a verdict for that worker newer than the table (`written`); the note dates from the table. A time OUT or more ahead of `now` is a wrong clock and says nothing.""" - last, today, now = {}, today or time.strftime("%Y-%m-%d"), now or time.time() +def outs(log, now=None): + """{worker: (since, why)}: each worker last said to be out, and when: an `out` verdict in the log says it, and any + later verdict takes it back. A time OUT or more ahead of `now` is a wrong clock and says nothing.""" + last, now = {}, now or time.time() for o in log: try: t = time.mktime(time.strptime(o["ts"], "%Y-%m-%dT%H:%M:%S")) t - now < OUT and last.__setitem__(short(o["model"] if isinstance(o.get("model"), str) and o["model"] else o["worker"]), (t, o.get("verdict"), str(o.get("why") or ""))) except (KeyError, TypeError, ValueError): pass # a damaged line is no verdict - gone = {w: (t, why) for w, (t, verdict, why) in last.items() if verdict == "out"} - for r in rows(text): - w, until = short(r[0]), [d for d in re.findall(r"out until (\d{4}-\d{2}-\d{2})", " ".join(r).lower()) if d >= today] - if until and written is not None and written - now < OUT and not (w in last and last[w][0] >= int(written)): # the log keeps whole seconds - gone[w] = (written, "out until " + until[0]) - return gone + return {w: (t, why) for w, (t, verdict, why) in last.items() if verdict == "out"} -def away(): - """`outs` for the table and the log as they are now.""" - return outs(store.read(table()), store.records("outcomes.jsonl"), os.path.getmtime(table()) if os.path.exists(table()) else None, now=time.time()) +def away(): return outs(store.records("outcomes.jsonl"), time.time()) def out(r, skip, bad, gone, now): @@ -311,7 +336,8 @@ def choose(text, cls, skip=(), review=None, rand=None, speed=None, gone=None, no rand = random.random med = {short(r[0]): median(speed[short(r[0])]) for r in left if (speed or {}).get(short(r[0]))} fast, qual = min(med.values(), default=1), quality or {} - weights = [w * (max(0.02, (fast / med[short(r[0])]) ** 3) if short(r[0]) in med else 1) + tried = lambda r: sum(1 for o in store.records("outcomes.jsonl") if o.get("verdict") in ("good", "bad") and short(o.get("model") or o.get("worker") or "") == short(r[0])) + weights = [(len(left) if tried(r) < 3 else w) * (max(0.02, (fast / med[short(r[0])]) ** 3) if short(r[0]) in med else 1) * max(1 / 11, qual.get(short(r[0]), 1)) * (share or {}).get(pkey(r[7]), 1) for w, r in zip(range(len(left), 0, -1), left)] x = rand() * sum(weights) for weight, r in zip(weights, left): @@ -337,7 +363,8 @@ def pick(args, cwd=None, rand=None): if not cls: print("usage: sisi pick routine|ordinary|hard [--review-of WORKER] [--not WORKER ...] [--limit MINUTES] [--branch NAME]") return 1 - text = store.read(table()) + text, why = wheel() + if why: return print("sisi pick: %s: %s" % (why, REFRESH)) or 1 mine = [r for r in rows(text) if r[2].strip().lower() == cls] for r in rows(text): if len(re.findall(r"routine|ordinary|hard", r[2].lower())) > 1: @@ -363,8 +390,7 @@ def pick(args, cwd=None, rand=None): q = s["pending"] if isinstance(s.get("pending"), dict) else {} s["pending"] = {**q, w: (q[w] if isinstance(q.get(w), list) else []) + [{"limit": limit, "branch": branch, "node": node}]} # one entry per pick, claimed in order print("worker: %s (model id: %s)\nstart it with the host's delegation tool; one pick buys one delegation" % (r[0], short(r[0]))) - if store.config()["shell_workers"] or not command(r): - print("how to call it: " + r[1]) + print("how to call it: " + r[1]) print("good at, bad at: %s\nnotes: %s" % (r[4], r[5])) t = speed.get(short(r[0])) print("speed: median %g min over %d timed jobs" % (median(t), len(t)) if t else "speed: no timed jobs yet") @@ -395,7 +421,7 @@ def research_brief(): intro, step2, step4 = ASK_FRESH if fresh else ASK_STALE return RESEARCH % {"intro": intro, "step2": step2, "step4": step4, "extra": "" if fresh else EXTRA_SHARED, "shared": shipped or "(none yet)", "table": store.read(table()).rstrip() or "(none yet)", - "owner": "\n".join(owner) or "(nothing)", "outcomes": "\n".join(outcomes(60)) or "(none yet)"} + "owner": "\n".join(owner) or "(nothing)", "outcomes": "\n".join(outcomes(60)) or "(none yet)"} + "\n=== Offered by this harness ===\n" + store.read(offered("txt")) def research_record(answer_file): @@ -414,8 +440,6 @@ def research_record(answer_file): seen[key] = r[0] if len(re.findall(r"routine|ordinary|hard", r[2].lower())) != 1: return "each row's \"use for\" must name exactly one of routine, ordinary or hard: | %s |" % " | ".join(r[:6]) - if re.search(r"\bout (?:until|till)\b", " ".join(r), re.I): # what the wheel would read as a legacy note - return "a row may not say who is out: delete the `out until` note from it (the agent that delegates judges a worker that hit a limit: `sisi judge WORKER out \"\"`): | %s |" % " | ".join(r[:6]) if len(lines) > 42 or len(text) > 12000: return "the answer is too long (at most 40 rows and 12,000 characters)" if shared and ("|" not in shared or not _shared_date(shared)[0]): @@ -454,7 +478,7 @@ def judge(args, cwd=None): if not args or not args[0].strip() or not (ext or (len(args) == 3 and args[1] in ("good", "bad", "out") and minutes != 0)) or len(args[-1].split()) < 3: print('usage: sisi judge WORKER good|bad|out "" [--minutes N] [--newest] | extend MINUTES "" [--newest]') return 1 - trows = rows(store.read(table())) + trows = rows(store.read(table()) + wheel()[0]) hits = [r for r in trows if short(r[0]) == short(args[0])] or [r for r in trows if claim({"picked": [short(r[0])]}, args[0], True)] if args[1] == "out" and len(hits) != 1: # a verdict that names no one worker would change nothing return print("sisi judge: %r is not one worker of the models table; name it as the table does." % args[0]) or 1 @@ -516,5 +540,25 @@ def run(args, cwd=None): if len(args) == 3 and args[:2] == ["research", "--record"]: why = research_record(args[2]) return (print("sisi models: %s. Nothing was changed." % why) or 1) if why else 0 - print("usage: sisi models | sisi models research [--record FILE]") + if args == ["offered"]: + raw = sys.stdin.read(200001).strip() + if not raw or len(raw) > 200000: return print("sisi models: give the host's raw list of offered models on stdin (1 to 200,000 characters). Nothing was changed.") or 1 + with store.lock("models"): + store.write(offered("txt"), "listed %s by harness %s\n%s\n" % (time.strftime("%Y-%m-%dT%H:%M:%S"), os.path.basename(offered("txt"))[:-4], raw)) + os.path.isfile(offered("wheel.md")) and os.remove(offered("wheel.md")) + store.commit("offered models listed", offered("txt"), offered("wheel.md")) + from . import plan + return plan.issue("models offered", OFFERED % (store.read(table()).rstrip() or "(none yet)", raw), cwd) or 0 + if len(args) == 3 and args[:2] == ["offered", "--record"]: + raw, text = store.read(offered("txt")), store.read(args[2]) + bad = [r[0] for r in rows(text) if not (_has(raw, short(r[0])) and short(r[0]) in r[1].lower() and len(re.findall(r"routine|ordinary|hard", r[2].lower())) == 1)] + if not raw or not rows(text) or bad or len(rows(text)) > 80: + return print("sisi models: %s. Nothing was changed." % ("needs the list first (`sisi models offered < FILE`) and 1 to 80 rows" if not raw or not rows(text) or len(rows(text)) > 80 else "not in the list verbatim, in the how-to-call cell, or not one class: " + ", ".join(bad))) or 1 + with store.lock("models"): + store.write(offered("wheel.md"), text.strip() + "\n") + store.commit("offered models table", offered("wheel.md")) + new = [short(r[0]) for r in rows(text) if r[5].lower().startswith("new:")] + print("recorded %d offered models.%s" % (len(rows(text)), " " + ASK.replace("sisi models research`", "sisi models research` (its brief names: %s)" % ", ".join(new), 1) if new else "")) + return 0 + print("usage: sisi models | sisi models research [--record FILE] | sisi models offered [--record FILE]") return 1 diff --git a/sisi/plan.py b/sisi/plan.py index c6a299a..b0feea0 100644 --- a/sisi/plan.py +++ b/sisi/plan.py @@ -10,7 +10,7 @@ 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-9a-f]{8}))?\s*$", re.I) -CHORE_CMD = {"plan": "sisi plan brief", "models research": "sisi models research", "rules organize": "sisi rules organize"} +CHORE_CMD = {"plan": "sisi plan brief", "models research": "sisi models research", "models offered": "sisi models offered < FILE", "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)")