Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions host-setup/agent-safety/claude/model-tier-guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
allowed whatever it names. Using no fork for work meant to run below the session's tier therefore
stays a prose rule, in AGENTS.md "Model Tiers".

A config that is missing, unreadable, or lacks the keys cannot say which model is blocked. A call
naming any model is then denied, so the guard never goes quiet without saying so, and a call naming
none is allowed.
A config that is missing, unreadable, or lacks the keys cannot say which model is blocked. Nor can
one whose `inheritingAgentTypes` is not a list of strings, since the hook cannot tell which types it
names. A call naming any model is then denied, so the guard never goes quiet without saying so, and a
call naming none is allowed.

Run `model-tier-guard.py --selftest` to check the decision matrix without Claude Code.
"""
Expand Down Expand Up @@ -70,6 +71,8 @@ def load_tiers(path):
return None
if not isinstance(blocked, str) or not isinstance(default, str) or not blocked:
return None
if not isinstance(inheriting, list) or not all(isinstance(t, str) for t in inheriting):
return None
return {
"blocked": blocked,
"reserved": reserved,
Expand Down
14 changes: 14 additions & 0 deletions host-setup/agent-safety/claude/test_model_tier_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ def test_a_mapping_without_the_key_allows_an_inheriting_type(self):
self.assertIsNone(self.run_hook("Agent", {"subagent_type": "Explore"}))
self.assertDenied(self.run_hook("Agent", {"model": "fable"}))

def test_a_malformed_inheriting_list_is_treated_as_missing(self):
for value in (["Explore", 1], [None], "Explore", {"Explore": True}, 7):
with self.subTest(value=value):
cfg = json.loads(json.dumps(TIERS))
cfg["tools"]["claude-code"]["inheritingAgentTypes"] = value
self.write_config(cfg)
self.assertDenied(
self.run_hook("Agent", {"model": "fable"}), "missing or unreadable"
)
self.assertDenied(
self.run_hook("Agent", {"model": "opus"}), "missing or unreadable"
)
self.assertIsNone(self.run_hook("Agent", {}))

def test_unparseable_input_is_allowed(self):
done = subprocess.run(
[sys.executable, str(self.dir / "model-tier-guard.py")],
Expand Down
Loading