Review fixes: late faults per session, one-commit learn --means, FIFO pending, extend targets late job, said guards, flags header, README
ci / test (push) Canceled after 0s

This commit is contained in:
sisi committed 2026-11-25 22:54:07 -07:00
1 parent a63134ee6e
commit a5882e3cfd
7 files changed
+110 -27

No files matched your search

+8 -7
View File
@@ -8,7 +8,8 @@ BLOCK = 'sisi: open fault(s) with no fix started and no blocker named: %s. Start
_path = lambda cwd=None: os.path.join(store.STATE, "core-faults", store.project_key(cwd) + ".json")
_gb = lambda b: "%d GB" % round(b / 1e9) if b >= 1e9 else "%.1f GB" % (b / 1e9)
_safe = lambda s: str(s).encode("utf-8", "replace").decode("utf-8")
lines = lambda cwd=None: [_fmt(f) for f in _load(_path(cwd))[0]["items"]]
_mine = lambda f, sid: not f.get("kind", "").startswith("late:") or bool(sid) and f["kind"].startswith("late:%s:" % sid[:8]) # a late fault belongs to the session that started the job
lines = lambda cwd=None, sid="": [_fmt(f) for f in _load(_path(cwd))[0]["items"] if _mine(f, sid)]
def _load(p):
empty = {"next": 1, "items": []}
@@ -30,8 +31,8 @@ def _fmt(f):
age = "%ds" % s if s < 60 else "%dm" % (s // 60) if s < 3600 else "%dh" % (s // 3600) if s < 86400 else "%dd" % (s // 86400)
return "#%d [%s, %s] %s%s" % (f["id"], f["state"], age, _safe(f["text"]), " — " + _safe(f["note"]) if f.get("note") else "")
def gate(cwd=None):
opened = [f for f in _load(_path(cwd))[0]["items"] if f["state"] == "open"]
def gate(cwd=None, sid=""):
opened = [f for f in _load(_path(cwd))[0]["items"] if f["state"] == "open" and _mine(f, sid)]
return BLOCK % "; ".join("#%d %s" % (f["id"], _safe(f["text"])) for f in opened) if opened else ""
def add(cwd, text, kind="", flag="", fid=0):
@@ -44,8 +45,8 @@ def add(cwd, text, kind="", flag="", fid=0):
hit = next((f for f in doc["items"] if f["id"] == fid), None)
if not hit:
return None
if hit.get("kind", "").startswith("late:"):
raise OSError('sisi fault: #%d is a late worker fault; run `sisi judge WORKER good|bad "<why>"` or `sisi judge WORKER extend MINUTES "<reason>"`.' % fid)
if hit.get("kind", "").startswith("late:") and (flag != "--fixed" or hit["kind"].startswith("late:%s:" % (store.current_session(cwd) or "")[:8])):
raise OSError('#%d is a late worker fault; run `sisi judge WORKER good|bad "<why>"` or `sisi judge WORKER extend MINUTES "<reason>"`.' % fid)
doc["items"] = [f for f in doc["items"] if f["id"] != fid] if flag == "--fixed" else doc["items"]
hit.update(state=flag[2:], note=text)
elif kind and any(f.get("kind") == kind for f in doc["items"]):
@@ -82,7 +83,7 @@ def _checkouts(cwd):
except OSError:
return 0
def check(cwd, start_free=None):
def check(cwd, start_free=None, sid=""):
cfg, hits, pos = store.config(), [], lambda k: type(cfg[k]) in (int, float) and cfg[k] > 0
try:
st = os.statvfs(cwd) if pos("disk_free_percent") or (pos("disk_drop_percent") and type(start_free) in (int, float)) else None
@@ -102,7 +103,7 @@ def check(cwd, start_free=None):
add(cwd, text, kind)
except OSError:
unsaved.append("[open] " + text)
ls = ([] if err else lines(cwd)) + unsaved
ls = ([] if err else lines(cwd, sid)) + unsaved
return "\n".join(([err] if err else []) + ([HEAD] + ls[:10] + (["and %d more: sisi fault" % (len(ls) - 10)] if len(ls) > 10 else []) if ls else []))
def run(args, cwd=None):
+6 -6
View File
@@ -99,11 +99,11 @@ def _begin(state, cwd):
pass
def _faults(cwd, gate=False, free=None):
def _faults(cwd, gate=False, free=None, sid=""):
if gate and not os.path.lexists(os.path.join(store.STATE, "core-faults", store.project_key(cwd) + ".json")):
return ""
from . import faults
return faults.gate(cwd) if gate else faults.check(cwd, free)
return faults.gate(cwd, sid) if gate else faults.check(cwd, free, sid)
def tick(p):
@@ -118,7 +118,7 @@ def tick(p):
store.append(env, "export SISI_SESSION_ID=%s" % sid, once=True) # so `sisi retro` knows its session
if not os.path.exists(os.path.join(store.DATA, "generated", "core.md")):
rules.build_rulebook()
text = "\n".join(x for x in (rules.project_text(cwd), rules.due(cwd, claim=True), models.stale(), "" if worker else _faults(cwd, False, free)) if x)
text = "\n".join(x for x in (rules.project_text(cwd), rules.due(cwd, claim=True), models.stale(), "" if worker else _faults(cwd, False, free, sid)) if x)
if text:
print(text)
return 0
@@ -141,13 +141,13 @@ def prompt(p):
if not s.get("prompts") and WORKER.search(p["prompt"][:2000]):
s["worker"] = True
worker, free = worker or bool(s.get("worker")), s.get("free_bytes")
worker or not p["prompt"].strip() or s.update(said=(s.get("said", []) + [" ".join(p["prompt"].split())[:8000]])[-20:]) # the person's own words
worker or not p["prompt"].strip() or WORKER.search(p["prompt"][:2000]) or s.update(said=((s["said"] if isinstance(s.get("said"), list) else []) + [" ".join(p["prompt"].split())[:8000]])[-20:]) # the person's own words
s["prompts"] = s.get("prompts", 0) + 1
s.get("prompts_since") or s.update(began=time.time()) # the first request of a piece of work
s["prompts_since"] = s.get("prompts_since", 0) + 1
s["direct"], s["extra"], s["blocks"] = 0, 0, 0
not worker and (models.sync_late(s, cwd, sid), late1 := models.late(s, 1))
not worker and (text := "\n".join(x for x in [_faults(cwd, False, free)] + _late_lines(late1, cwd) if x)) and print(text)
not worker and (text := "\n".join(x for x in [_faults(cwd, False, free, sid)] + _late_lines(late1, cwd) if x)) and print(text)
return 0
@@ -218,7 +218,7 @@ def gate(p, for_subagent=False):
if s.get("worker"):
return 0
models.sync_late(s, cwd, sid)
open_f, starts = _faults(cwd, True), s["starts"] if isinstance(s.get("starts"), dict) else {}
open_f, starts = _faults(cwd, True, None, sid), s["starts"] if isinstance(s.get("starts"), dict) else {}
seen = [x for x in (s["reminded"] if isinstance(s.get("reminded"), list) else [])
if isinstance(x, list) and len(x) == 2 and x[1] in (starts.get(x[0]) if isinstance(starts.get(x[0]), list) else ())]
late = models.overdue({"starts": {w: [t for t in v if [w, t] not in seen] for w, v in starts.items() if isinstance(v, list)}, "meta": s.get("meta")})
+5 -2
View File
@@ -165,7 +165,7 @@ def claim(s, text, segment=False):
t, starts = time.time(), (s["starts"] if isinstance(s.get("starts"), dict) else {})
starts[name] = (starts[name] if isinstance(starts.get(name), list) else []) + [t]
s["starts"] = starts # `sisi judge` times the job from here
if isinstance(s.get("pending"), dict) and isinstance(meta := s["pending"].pop(name, None), dict):
if isinstance(s.get("pending"), dict) and isinstance(q := s["pending"].get(name), list) and q and isinstance(meta := q.pop(0), dict):
s["meta"] = {**(s["meta"] if isinstance(s.get("meta"), dict) else {}), "%s %r" % (name, t): meta}
s.setdefault("workers_since", []).append(name)
return True
@@ -276,7 +276,8 @@ def pick(args, cwd=None, rand=None):
if sid:
with store.session(sid) as s:
s.setdefault("picked", []).append(w := short(r[0]))
if limit is not None or branch is not None: s["pending"] = {**(s["pending"] if isinstance(s.get("pending"), dict) else {}), w: {"limit": limit, "branch": branch}}
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}]} # 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])
@@ -363,6 +364,8 @@ def judge(args, cwd=None):
with store.session(sid) as s:
starts = s["starts"].get(wkey) if isinstance(s.get("starts"), dict) else None
cand = (starts.pop(-1 if newest else 0) if not ext else starts[-1 if newest else 0]) if isinstance(starts, list) and starts 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)
ok_t = type(cand) in (int, float) and math.isfinite(cand) and cand <= now
if ext:
if not ok_t: return print("sisi judge: no open job for %s." % args[0]) or 1
+1 -1
View File
@@ -45,7 +45,7 @@ def facts(state, cwd):
"evidence (measured): %d check(s) passed, %d failed" % (n["checks_pass"], n["checks_fail"])] + d[1:-1]
out += ["value (judged): did the person get what they wanted? changed: %d commit(s), %d file(s) uncommitted" % (n["commits"], len(dirty))]
from . import faults
fs = faults.lines(cwd)
fs = faults.lines(cwd, store.current_session(cwd))
return out + d[:1] + d[1:][-1:] + (["open faults (%d):" % len(fs)] + [" " + l for l in fs] if fs else []) + ["learning (measured): last 10 pieces of work named: %s" % (named or "none yet")]
+6 -7
View File
@@ -182,20 +182,20 @@ def _commit(msg, *paths, snap=None):
raise OSError("store git commit failed")
def add(text, scope, source, cwd=None, log=None):
def add(text, scope, source, cwd=None, log=None, means=""):
"""Put one rule in force; returns (line, warning). Raises OSError before writing when the list cannot be written."""
line = "- %s [%s %s]" % (" ".join(str(text).split()), source, time.strftime("%Y-%m-%d"))
line, *more = ["- %s [%s %s]" % (" ".join(str(t).split()), src, time.strftime("%Y-%m-%d")) for t, src in ((text, source), (means, "agent reading")) if t] # one commit holds both
dest = path(scope, cwd)
scope == PROJECT and not dest and _check_writable(dest)
with store.lock(dest if scope == PROJECT else "user"):
if scope == USER:
store.append(dest, line)
[store.append(dest, l) for l in [line, *more]]
else:
_check_writable(dest)
msg = _move(dest, _legacy(cwd))
msg and print(msg)
before = _text(dest)
after = _append(before, [line])
after = _append(before, [line, *more])
store.write(dest, after)
note(dest)
try:
@@ -305,7 +305,7 @@ def organize_brief(cwd):
def organize_record(answer_file, cwd):
"""Replace both lists with the worker's answer. Returns why not, or None when it is done."""
cfg = store.config()
body, *flags = re.split(r"(?m)^## flags[ \t]*$", store.read(answer_file), 1) # the flags are for the person, not rules
body, *flags = re.split(r"(?im)^##\s*flags\s*$", store.read(answer_file), 1) # the flags are for the person, not rules
flags = "".join(flags)
parts = re.split(r"(?m)^## (user|project)[ \t]*$", body)
got = {parts[i]: [l.rstrip() for l in parts[i + 1].splitlines() if l.startswith("- ")]
@@ -466,8 +466,7 @@ def learn(args, cwd=None):
heard = _said(text, cwd)
log = os.path.join(store.DATA, "rules", "owner.log") # their exact words are kept, whatever organizing later does to the rule
try:
line, warn = add(text, scope, "owner" if heard else "agent, attributed to owner", cwd, (log, "%s %s %s" % (time.strftime("%Y-%m-%d"), scope, " ".join(text.split()))))
means and add(means, scope, "agent reading", cwd)
line, warn = add(text, scope, "owner" if heard else "agent, attributed to owner", cwd, (log, "%s %s %s" % (time.strftime("%Y-%m-%d"), scope, " ".join(text.split()))), means)
except OSError as e:
print("sisi learn: could not write %s (%s). Nothing was changed, and your words were not kept." % (path(scope, cwd) or cwd or os.getcwd(), e))
return 1