From 3a12dccf16c6fde418e226a589658d206357b468 Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Mon, 23 Nov 2026 15:50:03 -0700 Subject: [PATCH] Item 6: agy learned for real (smoke passed), host listing proof; model list ignores progress lines, disabled providers are not research targets, delegate names the host mechanism, config read once per hook. done / next: report Co-Authored-By: Claude Sonnet 5.5 --- sisi/discovery.py | 31 ++++++++++++++++++------------- sisi/workers.py | 3 ++- tests/test_discovery.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 14 deletions(-) diff --git a/sisi/discovery.py b/sisi/discovery.py index 1a624b6..10e231e 100644 --- a/sisi/discovery.py +++ b/sisi/discovery.py @@ -49,11 +49,12 @@ def data(): return _DATA[0] -def cfg(name): +def conf(): + """The `discovery` settings, each valid or its default; the config is read once per call.""" c = store.config().get("discovery") - v = c.get(name) if isinstance(c, dict) else None - d = DEFAULTS[name] - return v if isinstance(v, (int, float)) and not isinstance(v, bool) and v >= 0 else d + c = c if isinstance(c, dict) else {} + return {k: (c[k] if isinstance(c.get(k), (int, float)) and not isinstance(c.get(k), bool) and c[k] >= 0 else d) + for k, d in DEFAULTS.items()} # ---------------------------------------------------------------- small files @@ -174,8 +175,9 @@ def session_start(now=None): marks = _marks(dirs) starts = int(st.get("starts") or 0) + 1 first = not isinstance(st.get("names"), list) - due = (first or st.get("marks") != marks or now - float(st.get("checked") or 0) >= cfg("path_refresh_s") - or starts >= cfg("path_every_starts")) + c = conf() + due = (first or st.get("marks") != marks or now - float(st.get("checked") or 0) >= c["path_refresh_s"] + or starts >= c["path_every_starts"]) if not due: st["starts"] = starts _save(f, st) @@ -261,7 +263,7 @@ def host_state_file(): return _state_file("host-workers.json") -def apply_listing(state, host, parsed, now, drop_after): +def apply_listing(state, host, parsed, now, drop_after, catalogue_over): """Fold a listing into the stored host workers. Returns how many usable workers are new and worth trying (a provider with more models than discovery.catalogue_over is a catalogue, not a menu). A worker missing from `drop_after` listings in a row is forgotten.""" @@ -272,7 +274,7 @@ def apply_listing(state, host, parsed, now, drop_after): for p in parsed: entry = provs.setdefault(p["provider"], {"models": {}}) entry.update(kind=p["kind"], name=p["name"], usable=p["usable"], reason=p["reason"]) - small = len(p["models"]) <= cfg("catalogue_over") + small = len(p["models"]) <= catalogue_over for m in p["models"]: mrec = entry["models"].get(m["id"]) if mrec is None: @@ -348,7 +350,9 @@ def after_tool(payload): parsed = parse_listing(_tool_result(payload), listing, data().get("blocking_constraint_words") or ()) if not parsed: return - fresh = apply_listing(state, listing["host"], parsed, now, int(cfg("drop_after_listings")) or 1) + c = conf() + fresh = apply_listing(state, listing["host"], parsed, now, int(c["drop_after_listings"]) or 1, + c["catalogue_over"]) if fresh: line = ("sisi: %s reachable through the host's cross-provider delegation (new and unproven: " "routine work only until judged; `sisi workers` lists them, `sisi route` can choose them)." @@ -599,7 +603,7 @@ def smoke(driver, timeout=None): bad-template or no-answer. The command is an argument list: the brief never reaches a shell.""" import shutil, subprocess, tempfile, uuid from . import workers - timeout = float(cfg("smoke_timeout_s") if timeout is None else timeout) + timeout = float(conf()["smoke_timeout_s"] if timeout is None else timeout) nonce = "ok" + uuid.uuid4().hex[:8] tmp = tempfile.mkdtemp(prefix="sisi-smoke-") cmd = workers.build_command(driver, {"model": None, "worker": driver["name"] + "/default"}, @@ -673,7 +677,8 @@ def models_of(driver, timeout=30): return [] if r.returncode != 0: return [] - return workers._parse_models({"list_kind": "lines"}, r.stdout or "")[:500] + # a tool may print a progress line before the list: only a token shaped like an id (a digit or - _ . / :) counts + return [m for m in workers._parse_models({"list_kind": "lines"}, r.stdout or "") if re.search(r"[-_./:\d]", m)][:500] def prove(name, drivers, now=None): @@ -964,7 +969,7 @@ def annotate(cands, records, tools): return cands from . import routing counts = judged_counts(records) - cap = cfg("catalogue_over") + cap = conf()["catalogue_over"] for c in cands: t = marked.get(c.get("tool")) if t is None: @@ -973,7 +978,7 @@ def annotate(cands, records, tools): c["unproven"] = n < routing.MIN_ATTEMPTS if c["unproven"]: c["plan"] = c.get("plan") or "per-use" - if c.get("model") is None or len(t.get("models") or []) <= cap: + if c.get("usable", True) and (c.get("model") is None or len(t.get("models") or []) <= cap): c["unproven_ok"] = True if t.get("host"): c["host_native"] = True diff --git a/sisi/workers.py b/sisi/workers.py index 64e0f75..5d60faa 100644 --- a/sisi/workers.py +++ b/sisi/workers.py @@ -1179,7 +1179,8 @@ def run_delegation(candidates, kind, difficulty, prompt, cwd, explicit=None, rev prefs = effective_prefs(kind, difficulty, cwd) if cand is not None and cand.get("host_native"): notes.append("sisi: %s is a host-native worker; start it with the host's own subagent tool " - "(`sisi delegate` runs only command-line tools)" % cand["worker"]) + "(`sisi delegate` runs only command-line tools)" % cand["worker"] if not cand.get("host_mechanism") else + "sisi: %s is reached through the host, not by `sisi delegate`: %s" % (cand["worker"], cand["host_mechanism"])) return None, None, notes candidates = [c for c in apply_limits(candidates, prefs)[0] if not c.get("host_native")] while True: diff --git a/tests/test_discovery.py b/tests/test_discovery.py index d962201..7ec3f9c 100644 --- a/tests/test_discovery.py +++ b/tests/test_discovery.py @@ -140,6 +140,18 @@ class NewToolOnPath(DiscoveryCase): self.assertEqual(discovery.session_start(now=1000.0 + 7 * 3600), "", "and not again after the age passes") self.assertEqual(self.runs(), [], "nothing on PATH is ever executed") + def test_a_name_that_leaves_and_comes_back_is_not_announced_again(self): + discovery.session_start(now=1.0) + time.sleep(0.02) + p = self.exe("wanderer") + self.assertIn("wanderer", discovery.session_start(now=2.0)) + time.sleep(0.02) + os.unlink(p) + self.assertEqual(discovery.session_start(now=3.0), "") + time.sleep(0.02) + self.exe("wanderer") + self.assertEqual(discovery.session_start(now=4.0), "") + def test_the_tick_hook_prints_the_notice_once_over_two_session_starts(self): env = {"PATH": self.userbin + os.pathsep + os.environ["PATH"]} first = self.sisi_proc("tick", stdin=json.dumps({"session_id": "a1", "source": "startup", "cwd": self.proj}), env=env) @@ -222,6 +234,9 @@ class HostListing(DiscoveryCase): self.assertTrue(cands["alpha/m-1"]["usable"]) self.assertFalse(cands["beta/b-1"]["usable"]) self.assertIn("disabled", cands["beta/b-1"]["reason"]) + self.assertFalse(cands["beta/b-1"].get("unproven_ok")) + self.assertNotIn("beta/b-1", workers.facts_line()) + self.assertIn("alpha/m-1", workers.facts_line()) self.assertNotIn("beta", self.sisi("route", "--kind", "read", "--difficulty", "1").stdout.splitlines()[0]) shown = self.sisi("workers").stdout self.assertIn("beta - not usable now", shown) @@ -239,6 +254,15 @@ class HostListing(DiscoveryCase): self.assertIn("target.model=m-1", lines[1]) self.assertIn("unproven: check this result with at least the tests or a read of the diff", r.stdout) + def test_sisi_delegate_does_not_run_a_host_worker_it_says_how_the_host_starts_it(self): + self.feed(LISTING_TOOL, wrapped(LISTING)) + brief = os.path.join(self.proj, "b.md") + open(brief, "w").write(BRIEF) + r = self.sisi("delegate", "--kind", "read", "--difficulty", "1", "--brief", brief, "--worker", "alpha/m-1") + self.assertEqual(r.returncode, 1) + self.assertIn("target.providerInstanceId=alpha", r.stdout) + self.assertIn("target.model=m-1", r.stdout) + def test_a_worker_gone_from_enough_listings_is_dropped(self): self.feed(LISTING_TOOL, wrapped(LISTING)) only_beta = {"providers": [LISTING["providers"][1]]} @@ -289,6 +313,11 @@ class HostListing(DiscoveryCase): self.assertEqual(len(r.stdout.splitlines()), 1, r.stdout) self.assertIn("2 new workers", json.loads(r.stdout)["hookSpecificOutput"]["additionalContext"]) + def test_a_payload_that_is_not_an_object_does_nothing(self): + for payload in (None, [1], "x", 5, {}, {"tool_name": None}, {"tool_name": LISTING_TOOL}): + discovery.after_tool(payload) + self.assertFalse(os.path.exists(discovery.host_state_file())) + def test_other_tools_cost_nothing_and_are_left_alone(self): self.assertEqual(self.feed("Read", {"x": 1}), "") self.assertEqual(self.feed("Bash"), "") @@ -369,6 +398,14 @@ class LearnedDriver(DiscoveryCase): self.assertIn("must both be 'fakeagent'", r.stdout) self.assertEqual(self.runs(), []) + def test_a_shell_or_interpreter_is_not_a_tool_even_when_the_name_matches(self): + self.exe("sh") # a command on PATH that is not an agent tool + f = driver_file(os.path.join(self.tmp, "sh.json"), name="sh", exe="sh", run=["sh", "{prompt}"], list=None, + list_kind=None, model_flag=None) + r = self.sisi("workers", "learn", "sh", "--check", f) + self.assertEqual(r.returncode, 1, r.stdout) + self.assertIn("shell or interpreter", r.stdout) + def test_a_file_that_is_not_json_or_too_large_is_refused(self): self.exe("fakeagent") p = os.path.join(self.tmp, "x.json")