Item 1: host-native workers (bare names) are routable, with a subagent mechanism line. done / next: item 2 session start

This commit is contained in:
swaits committed 2026-11-23 12:24:45 -07:00
1 parent bcc093f436
commit e875ac9a7f
2 files changed
+92

No files matched your search

+10
View File
@@ -615,6 +615,14 @@ def build_candidates(disc=None, records=None):
w = r.get("worker")
if not w or str(w).lower() in alias_set or r.get("kind") not in ("attempt", "run"):
continue
if "/" not in str(w):
# No provider prefix: the host tool's own subagent model. It needs no discovered
# command-line tool and is usable unless marked down (routing checks that).
c = add(None, str(w), usable=True)
if c is not None:
c["host_native"] = True
alias_set.add(str(w).lower())
continue
tool = _guess_tool(w, disc_tools)
installed = any(t["name"] == tool and t.get("installed", True) for t in disc_tools) if tool else False
c = add(tool, r.get("model") or str(w),
@@ -751,6 +759,8 @@ def mechanism_for(cand, host=None):
"""How to start the chosen worker: the host's own subagents first, its cross-provider
delegation when the config says it has one (workers.host_cross_provider), else sisi itself."""
host = host_tool() if host is None else host
if cand.get("host_native"):
return "use the host's own subagent tool with model %s" % (cand.get("model") or cand["worker"])
if host and cand.get("tool") == host:
return "use the host's own subagent mechanism (the worker belongs to the host tool)"
if host and workers_cfg().get("host_cross_provider"):
+82
View File
@@ -0,0 +1,82 @@
"""Routing with host-native workers (bare names), notes, provider limits, session-start wording.
Fixture ledger is shaped like a real one: bare host names with hundreds of attempts beside
prefixed provider workers. Requirement ids: R-7.2-1..3, R-7.1-1, R-17-3, R-17-8."""
import json, os, stat, subprocess, time, unittest
from support import *
FAKE_MUSE = """#!/bin/sh
case "$1" in
exec)
if [ "$2" = "--list-models" ]; then echo "beta-1"; echo "beta-2"; exit 0; fi
echo "done" ;;
*) echo 'muse help' ;;
esac
exit 0
"""
FAKE_CODEX = """#!/bin/sh
case "$1 $2" in
"debug models") echo '{"models":[{"slug":"alpha-1"}]}' ;;
*) echo 'codex help' ;;
esac
exit 0
"""
class RouteCase(SisiCase):
def setUp(self):
super().setUp()
self.bindir = os.path.join(self.tmp, "bin")
os.makedirs(self.bindir)
for name, body in (("muse", FAKE_MUSE), ("codex", FAKE_CODEX)):
p = os.path.join(self.bindir, name)
open(p, "w").write(body)
os.chmod(p, os.stat(p).st_mode | stat.S_IXUSR)
def env(self, **kw):
return dict(PATH=self.bindir, **kw)
def seed(self, spec, type="impl", difficulty=2):
"""spec: [(worker, attempts, accepted)]"""
os.makedirs(self.data, exist_ok=True)
n = 0
with open(os.path.join(self.data, "delegations.jsonl"), "a") as f:
for worker, attempts, accepted in spec:
for i in range(attempts):
n += 1
f.write(json.dumps({"kind": "attempt", "id": "r%d" % n, "ts": 1760000000 + n,
"project": "p", "type": type, "difficulty": difficulty,
"worker": worker, "outcome": "accepted" if i < accepted else "rejected",
"check": "tests", "minutes": 5}) + "\n")
def seed_real_shape(self):
self.seed([("wk-fast", 300, 290), ("wk-mid", 120, 100), ("muse/beta-1", 12, 11), ("codex/alpha-1", 9, 8)])
def down(self, *providers):
for p in providers:
r = self.sisi("workers", "down", p, "--reason", "limit", "--until", "2099-01-02", env=self.env())
self.assertEqual(r.returncode, 0, r.stderr)
class HostNativeTests(RouteCase):
def test_bare_names_are_routable_host_workers(self):
"""R-7.2-1, R-7.2-3, R-7.1-1: a worker id without a provider prefix is a host subagent: routable
with no discovered tool, and the mechanism line says to use the host's subagent tool."""
self.seed_real_shape()
r = self.sisi("route", "--kind", "impl", "--difficulty", "2", env=dict(PATH=""))
self.assertEqual(r.returncode, 0, r.stdout + r.stderr)
first = r.stdout.splitlines()[0]
self.assertTrue(first.startswith("wk-"), r.stdout)
self.assertIn("host's own subagent tool with model %s" % first, r.stdout)
self.assertNotIn("no tool for it", r.stdout)
def test_down_host_worker_is_skipped(self):
"""R-7.2-3: a host worker marked down is passed over like any other."""
self.seed_real_shape()
self.sisi("workers", "down", "wk-fast", "--reason", "limit", "--until", "2099-01-02", env=self.env())
self.sisi("workers", "down", "wk-mid", "--reason", "limit", "--until", "2099-01-02", env=self.env())
r = self.sisi("route", "--kind", "impl", "--difficulty", "2", "--explain", env=self.env())
self.assertNotIn("wk-", r.stdout.splitlines()[0])
if __name__ == "__main__":
unittest.main()