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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ For a small task pipeline, route one phase by sending a request on stdin:

```text
PYTHONPATH=src python3 -m opsle_gearbox.route <<'JSON'
{"schema":"opsle.gearbox.route-request.v1","phase":"BUILD","choice":"auto","available":{"codex":true,"claude":true,"deterministic":false}}
{"schema":"opsle.gearbox.route-request.v2","phase":"BUILD","choice":"auto","available":{"codex":true,"claude":true,"deterministic":false},"profiles":{"codex":{"model":null,"effort":null},"claude":{"model":null,"effort":null}}}
JSON
```

The selector returns one route: `codex`, `claude`, `deterministic`, or `noop`.
The selector returns one route: `codex`, `claude`, `deterministic`, or `noop`,
plus the selected model and reasoning effort for provider routes. Null profile
values select the provider default model and the bounded phase effort policy;
explicit profile values survive unchanged.
`TEST` and `DEPLOY` are deterministic when a command is configured and otherwise
become explicit no-ops. It performs no execution, retries, discovery, or state.

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "opsle-gearbox"
version = "0.1.0"
version = "0.2.0"
description = "Bounded deterministic and lower-cost execution for a primary developer"
readme = "README.md"
requires-python = ">=3.11"
Expand Down
35 changes: 31 additions & 4 deletions src/opsle_gearbox/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
import sys
from typing import Any

REQUEST_SCHEMA = "opsle.gearbox.route-request.v1"
RESULT_SCHEMA = "opsle.gearbox.route-result.v1"
REQUEST_SCHEMA = "opsle.gearbox.route-request.v2"
RESULT_SCHEMA = "opsle.gearbox.route-result.v2"
PHASES = {"PLAN", "BUILD", "TEST", "DEPLOY", "IDEAS"}
CHOICES = {"auto", "codex", "claude"}
EFFORTS = {"none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"}
AUTOMATIC_EFFORT = {"IDEAS": "low", "PLAN": "medium", "BUILD": "high"}


class RouteError(ValueError):
"""The caller supplied an invalid or impossible routing request."""


def select_route(value: object) -> dict[str, Any]:
if not isinstance(value, dict) or set(value) != {"schema", "phase", "choice", "available"}:
raise RouteError("route request must contain exactly schema, phase, choice, and available")
if not isinstance(value, dict) or set(value) != {
"schema", "phase", "choice", "available", "profiles"
}:
raise RouteError("route request must contain exactly schema, phase, choice, available, and profiles")
if value["schema"] != REQUEST_SCHEMA:
raise RouteError("unsupported route request schema")

Expand All @@ -33,6 +37,18 @@ def select_route(value: object) -> dict[str, Any]:
raise RouteError("available must contain exactly codex, claude, and deterministic")
if any(not isinstance(item, bool) for item in available.values()):
raise RouteError("availability values must be booleans")
profiles = value["profiles"]
if not isinstance(profiles, dict) or set(profiles) != {"codex", "claude"}:
raise RouteError("profiles must contain exactly codex and claude")
for profile in profiles.values():
if not isinstance(profile, dict) or set(profile) != {"model", "effort"}:
raise RouteError("each provider profile must contain exactly model and effort")
if profile["model"] is not None and (
not isinstance(profile["model"], str) or not profile["model"].strip()
):
raise RouteError("profile model must be a non-empty string or null")
if profile["effort"] is not None and profile["effort"] not in EFFORTS:
raise RouteError("profile effort is unsupported")

if phase in {"TEST", "DEPLOY"}:
route = "deterministic" if available["deterministic"] else "noop"
Expand All @@ -51,11 +67,22 @@ def select_route(value: object) -> dict[str, Any]:
else:
raise RouteError("no provider is available")

profile = profiles[route] if route in {"codex", "claude"} else None
model = (profile["model"] or "provider-default") if profile else None
effort = (profile["effort"] or AUTOMATIC_EFFORT[phase]) if profile else None
return {
"schema": RESULT_SCHEMA,
"phase": phase,
"route": route,
"reason": reason,
"model": model,
"effort": effort,
"model_selection": "explicit" if profile and profile["model"] else (
"automatic" if profile else "not-applicable"
),
"effort_selection": "explicit" if profile and profile["effort"] else (
"automatic" if profile else "not-applicable"
),
}


Expand Down
24 changes: 22 additions & 2 deletions tests/test_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def request(phase="PLAN", choice="auto", *, codex=True, claude=True, determinist
"phase": phase,
"choice": choice,
"available": {"codex": codex, "claude": claude, "deterministic": deterministic},
"profiles": {
"codex": {"model": None, "effort": None},
"claude": {"model": None, "effort": None},
},
}


Expand All @@ -23,11 +27,27 @@ def test_explicit_provider_wins(self):
self.assertEqual(select_route(request(choice="claude"))["route"], "claude")

def test_auto_is_deterministic(self):
self.assertEqual(select_route(request())["route"], "codex")
plan = select_route(request())
self.assertEqual(plan["route"], "codex")
self.assertEqual(plan["model"], "provider-default")
self.assertEqual(plan["effort"], "medium")
self.assertEqual(plan["effort_selection"], "automatic")
self.assertEqual(select_route(request(codex=False))["route"], "claude")

def test_explicit_model_and_effort_survive_routing(self):
value = request("BUILD")
value["profiles"]["codex"] = {"model": "gpt-fixture", "effort": "xhigh"}
result = select_route(value)
self.assertEqual(result["model"], "gpt-fixture")
self.assertEqual(result["effort"], "xhigh")
self.assertEqual(result["model_selection"], "explicit")
self.assertEqual(result["effort_selection"], "explicit")

def test_test_and_deploy_are_deterministic_or_noop(self):
self.assertEqual(select_route(request("TEST", deterministic=True))["route"], "deterministic")
deterministic = select_route(request("TEST", deterministic=True))
self.assertEqual(deterministic["route"], "deterministic")
self.assertIsNone(deterministic["model"])
self.assertIsNone(deterministic["effort"])
self.assertEqual(select_route(request("DEPLOY"))["route"], "noop")

def test_unavailable_explicit_provider_fails(self):
Expand Down