Pick only from models the harness offers: saved raw list is truth, table is a hint

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-12-03 07:38:35 -07:00
1 parent 3a349a3859
commit e35dd49828
4 files changed
+73 -27

No files matched your search

+2
View File
@@ -30,6 +30,8 @@ Delegation
sisi models the workers you have: what each is good at and what it costs sisi models the workers you have: what each is good at and what it costs
sisi models research [--record FILE] sisi models research [--record FILE]
the brief for a research worker to rebuild that table; record its answer 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 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 | 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
+1 -1
View File
@@ -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) 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 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})) 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): if tool != "workflow" and not models.claim(probe, text, not shell and bool(names[0]), node):
known = models.known(table_text, text) 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 if models.usable(table_text): # with no usable table there is nothing to pick from: `sisi models` says to research it
+69 -25
View File
@@ -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 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.""" 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 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", 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 4. %(step4)s
5. What the person has said, below, stands exactly and outranks all of this: it is not yours to change. 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 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: 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 | | 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 === === How delegations went here, newest last ===
%(outcomes)s %(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: <one-line reason for the class>`). 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 <id>` and do what it says\" " 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\" "
"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`.") "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 except OSError: return None
def _has(raw, i): return bool(i) and bool(re.search(r"(?<![\w.:/-])%s(?![\w.:/-])" % re.escape(i), raw))
def offered(ext): return store.data("offered", getattr(store, "harness", lambda: "unknown")() + "." + ext)
def wheel():
"""(text, why): the rows to pick from, only models this harness offers (its saved raw list is the truth, the table a hint);
why is set when there is no list, it is old, or no row is offered."""
raw, age = store.read(offered("txt")), 1e9
try: age = (time.time() - time.mktime(time.strptime(raw.split()[1], "%Y-%m-%dT%H:%M:%S"))) / 3600
except (ValueError, IndexError, OverflowError): pass
text = store.read(offered("wheel.md")) or "".join(l + "\n" for l in store.read(table()).splitlines() if l.startswith("|") and (
set(l) <= set("|-: ") or l.lower().startswith("| worker") or any(_has(raw, short(r[0])) for r in rows(l))))
return text, ("no list of the models this harness offers" if not raw.strip() else "the list of offered models is %d h old" % age if age > store.config().get("offered_hours", 24)
else "" if usable(text) else "no offered model has a row")
def stale(mark=None): def stale(mark=None):
"""One line when the table is missing, old, or missed a worker, else "".""" """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] 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") try: store.write(store.data("models.stale"), who + "\n")
except Exception: pass # best effort: a refusal never depends on it except Exception: pass # best effort: a refusal never depends on it
age = age_days() age = age_days()
if why := wheel()[1]: return "sisi: %s: %s" % (why, REFRESH)
if age is None or age > store.config()["research_days"]: 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: " + ("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 "" 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" SINCE = "out since %s, back on the wheel at %s"
def outs(text, log, written, today=None, now=None): 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 """{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 verdict takes it back. A time OUT or more ahead of `now` is a wrong clock and says nothing."""
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, now = {}, now or time.time()
last, today, now = {}, today or time.strftime("%Y-%m-%d"), now or time.time()
for o in log: for o in log:
try: try:
t = time.mktime(time.strptime(o["ts"], "%Y-%m-%dT%H:%M:%S")) 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 ""))) 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): except (KeyError, TypeError, ValueError):
pass # a damaged line is no verdict pass # a damaged line is no verdict
gone = {w: (t, why) for w, (t, verdict, why) in last.items() if verdict == "out"} return {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
def away(): def away(): return outs(store.records("outcomes.jsonl"), time.time())
"""`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 out(r, skip, bad, gone, now): 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 rand = random.random
med = {short(r[0]): median(speed[short(r[0])]) for r in left if (speed or {}).get(short(r[0]))} 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 {} 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)] * 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) x = rand() * sum(weights)
for weight, r in zip(weights, left): for weight, r in zip(weights, left):
@@ -337,7 +363,8 @@ def pick(args, cwd=None, rand=None):
if not cls: if not cls:
print("usage: sisi pick routine|ordinary|hard [--review-of WORKER] [--not WORKER ...] [--limit MINUTES] [--branch NAME]") print("usage: sisi pick routine|ordinary|hard [--review-of WORKER] [--not WORKER ...] [--limit MINUTES] [--branch NAME]")
return 1 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] mine = [r for r in rows(text) if r[2].strip().lower() == cls]
for r in rows(text): for r in rows(text):
if len(re.findall(r"routine|ordinary|hard", r[2].lower())) > 1: 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 {} 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 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]))) 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])) print("good at, bad at: %s\nnotes: %s" % (r[4], r[5]))
t = speed.get(short(r[0])) 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") 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 intro, step2, step4 = ASK_FRESH if fresh else ASK_STALE
return RESEARCH % {"intro": intro, "step2": step2, "step4": step4, "extra": "" if fresh else EXTRA_SHARED, 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)", "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): def research_record(answer_file):
@@ -414,8 +440,6 @@ def research_record(answer_file):
seen[key] = r[0] seen[key] = r[0]
if len(re.findall(r"routine|ordinary|hard", r[2].lower())) != 1: 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]) 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 \"<the provider's message>\"`): | %s |" % " | ".join(r[:6])
if len(lines) > 42 or len(text) > 12000: if len(lines) > 42 or len(text) > 12000:
return "the answer is too long (at most 40 rows and 12,000 characters)" 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]): 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: 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 "<what it did well or badly, or the provider\'s message when it hit a limit, in a sentence>" [--minutes N] [--newest] | extend MINUTES "<reason, 3+ words>" [--newest]') print('usage: sisi judge WORKER good|bad|out "<what it did well or badly, or the provider\'s message when it hit a limit, in a sentence>" [--minutes N] [--newest] | extend MINUTES "<reason, 3+ words>" [--newest]')
return 1 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)] 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 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 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"]: if len(args) == 3 and args[:2] == ["research", "--record"]:
why = research_record(args[2]) why = research_record(args[2])
return (print("sisi models: %s. Nothing was changed." % why) or 1) if why else 0 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 return 1
+1 -1
View File
@@ -10,7 +10,7 @@ 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-9a-f]{8}))?\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 "<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)")