Merge the delegation and retro cost record
This commit is contained in:
commit
dacfc84594
5 files changed
+170
-22
No files matched your search
+4
-2
@@ -198,7 +198,7 @@ def gate(p, for_subagent=False):
|
||||
_begin(s, cwd)
|
||||
if s.get("worker"):
|
||||
return 0
|
||||
reason = " ".join("sisi: " + LATE % (w, time.strftime("%H:%M", time.localtime(t))) for w, t in models.overdue(s))
|
||||
reason, demand = " ".join("sisi: " + LATE % (w, time.strftime("%H:%M", time.localtime(t))) for w, t in models.overdue(s)), False
|
||||
if not reason and not s.get("paused"):
|
||||
checks = (s.get("done") or {}).get("checks") or []
|
||||
unsaid = ["%d. %s" % (i, c["text"]) for i, c in enumerate(checks, 1) if not c["verdict"]]
|
||||
@@ -207,11 +207,13 @@ def gate(p, for_subagent=False):
|
||||
quick = time.time() - (s.get("done") or {}).get("at", 0) < 60 * store.config()["retro_minutes"] and not s.get("delegations_since")
|
||||
if checks and not unsaid and not failed and (not worked or quick):
|
||||
from . import retro
|
||||
retro.record(s, cwd, {}) # every check passed and nothing changed, or it was quick and alone: the work closes itself
|
||||
retro.record(s, cwd, {}, sid) # every check passed and nothing changed, or it was quick and alone: the work closes itself
|
||||
return 0
|
||||
reason = "" if unsaid and models.waiting(s) else OPEN % "; ".join(unsaid) if unsaid else GATE if worked else FAILED % ", ".join(failed) if failed else ""
|
||||
demand = bool(reason and not unsaid)
|
||||
if not reason or s.get("blocks", 0) >= 2:
|
||||
return 0
|
||||
s["blocks"] = s.get("blocks", 0) + 1
|
||||
demand and s.setdefault("retro_demanded", time.time())
|
||||
print(json.dumps({"decision": "block", "reason": say(reason)}))
|
||||
return 0
|
||||
+21
-9
@@ -163,7 +163,7 @@ def speeds():
|
||||
out = {}
|
||||
for o in store.records("outcomes.jsonl"):
|
||||
if o.get("verdict") == "good" and type(o.get("minutes")) is int and 0 < o["minutes"] <= 10000 and isinstance(o.get("worker"), str):
|
||||
out.setdefault(short(o["worker"]), []).append(o["minutes"])
|
||||
out.setdefault(short(o["model"] if isinstance(o.get("model"), str) and o["model"] else o["worker"]), []).append(o["minutes"])
|
||||
return {w: v[-10:] for w, v in out.items()}
|
||||
|
||||
|
||||
@@ -279,19 +279,31 @@ def judge(args, cwd=None):
|
||||
if len(args) != 3 or not args[0].strip() or args[1] not in ("good", "bad") or len(args[2].split()) < 3 or minutes == 0:
|
||||
print('usage: sisi judge WORKER good|bad "<what it did well or badly, in a sentence>" [--minutes N] [--newest]')
|
||||
return 1
|
||||
sid = store.current_session(cwd)
|
||||
trows = rows(store.read(table()))
|
||||
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)]
|
||||
model = (hits[0][0].split() or [""])[0] if len(hits) == 1 else args[0]
|
||||
sid, now, began = store.current_session(cwd), time.time(), None
|
||||
if sid:
|
||||
with store.session(sid) as s:
|
||||
starts = s["starts"].get(short(args[0])) if isinstance(s.get("starts"), dict) else None
|
||||
starts = s["starts"].get(short(model)) if isinstance(s.get("starts"), dict) else None
|
||||
if isinstance(starts, list) and starts:
|
||||
began = starts.pop(-1 if newest else 0) # one start per open job, oldest first
|
||||
if type(began) in (int, float) and math.isfinite(began) and began <= time.time(): # else dropped, times nothing
|
||||
minutes = minutes or max(1, int((time.time() - began) / 60))
|
||||
cand = starts.pop(-1 if newest else 0) # one start per open job, oldest first
|
||||
if type(cand) in (int, float) and math.isfinite(cand) and cand <= now: # else dropped, times nothing
|
||||
began = cand
|
||||
minutes = minutes or max(1, int((now - began) / 60))
|
||||
note = " (job started %s, %d more open for this worker)" % (time.strftime("%H:%M", time.localtime(began)), len(starts))
|
||||
iso = lambda t: time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(t))
|
||||
rec = {"ts": iso(now), "ended": iso(now), "worker": args[0], "model": model, "verdict": args[1],
|
||||
"why": retro.clean(args[2]), "project": os.path.basename(store.project_root(cwd)),
|
||||
"project_key": store.project_key(cwd)}
|
||||
if sid:
|
||||
rec["session_id"] = sid
|
||||
if began is not None:
|
||||
rec["started"] = iso(began)
|
||||
if minutes:
|
||||
rec["minutes"] = minutes
|
||||
log = store.data("outcomes.jsonl")
|
||||
store.append(log, json.dumps(dict({"ts": time.strftime("%Y-%m-%dT%H:%M:%S"), "worker": args[0], "verdict": args[1],
|
||||
"why": retro.clean(args[2]), "project": os.path.basename(store.project_root(cwd))},
|
||||
**{"minutes": minutes} if minutes else {}), sort_keys=True))
|
||||
store.append(log, json.dumps(rec, sort_keys=True))
|
||||
store.commit("delegation judged", log)
|
||||
print("recorded: %d min%s." % (minutes, note) if minutes else "recorded, not timed.")
|
||||
return 0
|
||||
|
||||
+12
-7
@@ -1,6 +1,6 @@
|
||||
"""The retro: what happened, set against the objective; the gap, its cause, and the instruction that would have
|
||||
prevented it. That instruction becomes a learned rule at once."""
|
||||
import json, os, re, time
|
||||
import json, math, os, re, time
|
||||
from . import rules, store
|
||||
|
||||
DONE_USAGE = """usage: sisi done --goal "<the goal in their words, 5+ words>" --check "<a check that can fail, 4+ words>" [--check ...] \\
|
||||
@@ -95,19 +95,24 @@ def report(sid, cwd):
|
||||
print("\n" + "\n".join(trend()))
|
||||
|
||||
|
||||
def record(s, cwd, opt):
|
||||
def record(s, cwd, opt, sid=None):
|
||||
"""Append one record for the piece of work in this session state, and begin the next one."""
|
||||
d, now = s.get("done") or {}, time.time()
|
||||
entry = dict(opt, ts=time.strftime("%Y-%m-%dT%H:%M:%S"), project=os.path.basename(store.project_root(cwd)),
|
||||
unit=counts(s, cwd), goal=d.get("goal", ""), workers=s.get("workers_since", []))
|
||||
d, now, dem = s.get("done") or {}, time.time(), s.get("retro_demanded")
|
||||
entry = dict(opt, ts=time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(now)),
|
||||
project=os.path.basename(store.project_root(cwd)), unit=counts(s, cwd),
|
||||
goal=d.get("goal", ""), workers=s.get("workers_since", []))
|
||||
if d:
|
||||
entry["done"] = d
|
||||
if sid:
|
||||
entry["session_id"] = sid
|
||||
if type(dem) in (int, float) and math.isfinite(dem) and dem <= now:
|
||||
entry["retro_seconds"] = max(0, int(round(now - dem)))
|
||||
log = store.data("retro.jsonl")
|
||||
store.append(log, json.dumps(entry, sort_keys=True))
|
||||
store.commit("retro recorded", log)
|
||||
s["snapshot"], s["changed"], s["retro_at"] = store.snapshot(cwd), False, now
|
||||
for key in ("prompts_since", "direct_since", "delegations_since", "reasons_since", "workers_since", "done", "paused",
|
||||
"fails_since", "picked", "starts"):
|
||||
"fails_since", "picked", "starts", "retro_demanded"):
|
||||
s.pop(key, None)
|
||||
|
||||
|
||||
@@ -193,7 +198,7 @@ def run(args, cwd=None):
|
||||
if kind == "later":
|
||||
s["paused"] = True
|
||||
else:
|
||||
record(s, cwd, opt)
|
||||
record(s, cwd, opt, sid)
|
||||
elif kind != "later":
|
||||
record({}, cwd, dict(opt, scope=scope) if kind == "gap" else opt)
|
||||
if kind == "gap":
|
||||
|
||||
Reference in new issue
Block a user