diff --git a/sisi/discovery.py b/sisi/discovery.py index 46259b3..a41bbd5 100644 --- a/sisi/discovery.py +++ b/sisi/discovery.py @@ -161,6 +161,26 @@ def _hinted(name): return bool(hints & set(re.split(r"[-_.]", name.lower()))) +def _short_names(names, limit=3, width=16): + shown = ["%s%s" % (n[:width - 1], "…") if len(n) > width else n for n in names[:limit]] + return ", ".join(shown) + (" (and %d more)" % (len(names) - limit) if len(names) > limit else "") + + +def new_line(models, tools): + """The ONE session-start line for what is new and unproven: worker models discovery found and command-line + tools that appeared on this machine ("" when there are neither). Names are shortened and counted.""" + if not models and not tools: + return "" + parts = [] + if models: + parts.append("worker model%s %s" % ("" if len(models) == 1 else "s", _short_names(models))) + if tools: + parts.append("command-line tool%s %s" % ("" if len(tools) == 1 else "s", + _short_names(sorted(tools, key=lambda n: (not _hinted(n), n)), 2))) + return ("sisi: new %s: unproven, so low-stakes work first, checked one level more carefully.%s" + % (" and ".join(parts), " An AI agent among the tools: `sisi workers learn NAME`." if tools else "")) + + def new_tools_line(new): """One line naming at most five new tools, those whose names look like an agent's first.""" ordered = sorted(new, key=lambda n: (not _hinted(n), n)) @@ -172,10 +192,17 @@ def new_tools_line(new): def session_start(now=None): - """The session-start notice about new executables in the user-level PATH folders, or "". The first + """The session-start notice about new executables in the user-level PATH folders, or "" (session start itself + uses new_tools(), with the new worker models, in one line: new_line). The first run stores the list and says nothing. The list is looked at again when a folder changed, when it is older than discovery.path_refresh_s, or after discovery.path_every_starts session starts; otherwise one stat per folder is all it costs. A name is announced once.""" + new = new_tools(now) + return new_tools_line(new) if new else "" + + +def new_tools(now=None): + """The names of new executables in the user-level PATH folders since the last look (once each), a list.""" now = time.time() if now is None else now f = _state_file("path.json") st = _load(f) @@ -189,14 +216,14 @@ def session_start(now=None): if not due: st["starts"] = starts _save(f, st) - return "" + return [] names = sorted({n for d in dirs for n in list_executables(d)}) announced = [n for n in st.get("announced") or [] if isinstance(n, str)] new = [] if first else _candidate_names([n for n in names if n not in set(st["names"]) | set(announced)], _known_tool_names()) st.update(names=names, marks=marks, checked=now, starts=0, announced=(announced + new)[-500:]) _save(f, st) - return new_tools_line(new) if new else "" + return new # ---------------------------------------------------------------- what the host can reach @@ -1033,7 +1060,7 @@ def facts_targets(cands): def facts_phrase(targets): - shown = targets[:MAX_NAMED] + shown = targets[:3] return "the new workers %s%s" % (", ".join(shown), " and %d more" % (len(targets) - len(shown)) if len(targets) > len(shown) else "") diff --git a/sisi/learning.py b/sisi/learning.py index 80a55f9..4416139 100644 --- a/sisi/learning.py +++ b/sisi/learning.py @@ -800,10 +800,8 @@ def pending_notice(count=None): n = len(load_pending()) if count is None else count if not n: return "" - return ("sisi: %d change(s) wait for the owner's decision. Ask the owner through the host's " - "question dialog (`sisi approve` lists each change in full; show the owner what it would do) and give " - "the owner the command to run in a terminal: `sisi approve ID --yes` or `--no`. " - "Do not run it for the owner." % n) + return ("sisi: %d decision(s) wait for the owner. Ask through the host's question dialog, then give the owner the " + "command to run in a terminal (`sisi approve` lists each in full). Do not run it for the owner." % n) # ---- owner statements (one path: learn writes, oracle prints) --------------------- diff --git a/sisi/tick.py b/sisi/tick.py index 1c7770e..1474619 100644 --- a/sisi/tick.py +++ b/sisi/tick.py @@ -101,21 +101,19 @@ def main(args=()): store.save_session(sid, sess) except Exception as e: store.log_error("tick-workers", e) - try: + try: # ONE line for new worker models and new command-line tools (each kind is announced once) sess3 = rec or store.load_session(sid) - from . import workers as _W3 + from . import discovery, workers as _W3 if not sess3.get("subagent") and not _W3.is_subagent_payload(payload): - line = _W3.new_worker_line() + models = [] + try: + models = _W3.new_worker_names() + except Exception as e: + store.log_error("tick-new-workers", e) + tools = discovery.new_tools() # the first run only stores the list + line = discovery.new_line(models, tools) if line: sys.stdout.write(line + "\n") - except Exception as e: - store.log_error("tick-new-workers", e) - try: - from . import discovery, workers as _W2 - if not _W2.is_subagent_payload(payload): - note = discovery.session_start() # new executables on PATH, once per set (the first run only stores them) - if note: - sys.stdout.write(note + "\n") except Exception as e: store.log_error("tick-discovery", e) try: diff --git a/sisi/workers.py b/sisi/workers.py index 4a9535b..3f2cdd7 100644 --- a/sisi/workers.py +++ b/sisi/workers.py @@ -371,10 +371,9 @@ def _model_names(disc): if "contributor" not in str(m).lower()} # a tier that trains on its prompts is never offered -def new_worker_line(): - """One line naming up to three models discovery found that the previous discovery did not have, once; they - are unproven, so low-stakes work first and a closer look at what they return, until their record is no longer - thin. None when there is nothing new (or it was said already).""" +def new_worker_names(): + """The models discovery found that the previous discovery did not have, once (they are unproven until their + record is no longer thin): a list, empty when there is nothing new or it was said already.""" disc = load_discovery() records = read_records() judged = {} @@ -384,9 +383,18 @@ def new_worker_line(): new = [w for w in disc.get("new_unannounced") or [] if "contributor" not in w.lower() and judged.get(w.lower(), 0) < routing.MIN_ATTEMPTS] if not disc.get("new_unannounced"): - return None + return [] disc["new_unannounced"] = [] write_json(discovery_path(), disc) + return new + + +def new_worker_line(): + """One line naming up to three models discovery found that the previous discovery did not have, once; they + are unproven, so low-stakes work first and a closer look at what they return, until their record is no longer + thin. None when there is nothing new (or it was said already). Session start uses discovery.new_line, which + says this and the new command-line tools in one line.""" + new = new_worker_names() if not new: return None more = " (and %d more)" % (len(new) - 3) if len(new) > 3 else "" @@ -1062,11 +1070,8 @@ def facts_line(now=None): what = "worker facts are missing (no prices or benchmark standing recorded yet)" else: what = "worker facts are stale (newest from %s)" % (status["newest"] or "an unstated date") - return ("sisi: %s: ask a fast, cheap worker to research current prices and " - "software-engineering benchmark standing for the workers found here (`sisi workers`) " - "and record each with its source: `sisi workers fact WORKER --price N --source S` " - "and `sisi workers fact WORKER --standing N --source S`. Until then routing " - "goes by the judged record alone." % what) + return ("sisi: %s: a cheap worker can research them (`sisi workers fact WORKER --price N|--standing N " + "--source S`); until then routing uses the judged record alone." % what) def estimate_cost(tokens, price_entry): diff --git a/tests/test_cycle_hardening.py b/tests/test_cycle_hardening.py index 0f5bb42..6ea7596 100644 --- a/tests/test_cycle_hardening.py +++ b/tests/test_cycle_hardening.py @@ -180,6 +180,15 @@ class Approval(Base): "sisi approve $(echo P-0001) --yes", "sisi approve P-000{1,2} --yes", "sisi approve docs; sisi approve $X --yes", + # a learned tool (drv-NAME) and an allowance probe (probe-PROVIDER) are decided the same way, so the same + # wrappers are refused for them, and for an id of any shape + 'script -qec "sisi approve drv-x --yes" /dev/null