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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
__pycache__/
.pytest_cache/
.pytest-tmp/
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ up for risk. Claude stages and phase reviews are then built headless by
a dollar cap: 150k tokens for `small`, 400k for `middle`, 1M for `top` and `top+`, at
the pair's input price. A stage stopped at its cap is retried one step down
the frontier; one that fails its checks, one step up. Premium models
(output price of $30 or more per million tokens) are used below `top` only
when cheaper than the standard pick and as good, or as the step up past the
last standard pick while their score per unit of cost is within 5% of it;
`top` comes only from a total score of 9 or more. The most capable pair is
(output price of $30 or more per million tokens) are never used below
`top`, except as a retry after a failed build once the standard pairs run
out; `top` comes only from a total score of 9 or more. Fable is picked at
medium thinking at most. The most capable pair is
kept for `top+`: a `top` stage with a total of 12 or more or the highest
risk (K2); other `top` stages get the pair one below it, and step up only
when a build fails. They get $10 per phase; past that, builds use none.
risk (K2); other `top` stages get the pair one below it, never premium
while a standard pair is that good, and step up only when a build fails. They get $10 per phase; past that, builds use none.
Reviews run on `top`, or on `top+` for a phase with a `top+` stage, and
their cost counts against that budget. The builder may edit files and runs only the commands
your project's permission rules allow; set
Expand Down
2 changes: 1 addition & 1 deletion plugins/phased-delivery/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "phased-delivery",
"version": "0.15.3",
"version": "0.16.0",
"description": "Plan work as self-contained phases, then implement it phase by phase.",
"author": {
"name": "Bryan"
Expand Down
70 changes: 36 additions & 34 deletions plugins/phased-delivery/scripts/select-models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
("anthropic", "haiku", "xhigh"), # Haiku: xhigh keeps it a real small option
("anthropic", None, "high"), # other Claude: xhigh and max cost far more
]
# Most thinking a model family is picked at. Pairs above it still set the best
# score the floors measure from, as premium pairs do once the budget is spent.
PICK_CEILINGS = {"fable": "medium"} # Fable above medium is unaffordable
DEFAULT_EFFORT = "default" # report row without a thinking-level suffix
# A pair is premium when its output price is at least this many dollars per
# million tokens.
Expand All @@ -101,10 +104,6 @@
# A long or wide stage takes a faster pair only at this multiple of the pick's
# speed: thinking levels of one model differ by a few percent, which is noise.
SPEED_GAIN = 1.2
# A premium step-up below top is taken while its score per unit of run cost is
# no more than this fraction worse than the standard pick's: a near tie goes to
# the larger model, which may need fewer tokens than the benchmark shows.
PREMIUM_RATIO_MARGIN = 0.05
SCORES_FORM = "J F R C K P V S in that order, each followed by 0, 1 or 2, such as J1F1R0C0K0P0V0S0"

HERE = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -196,6 +195,11 @@ def effort_denial(effort, ceiling):
return None


def over_pick_ceiling(c):
words = set(normalize(c["row"]["model"]).split("-"))
return any(family in words and effort_denial(c["effort"], cap) for family, cap in PICK_CEILINGS.items())


def build_candidates(available, profiles):
rows_by_base = {}
for row in profiles["pairs"]:
Expand Down Expand Up @@ -299,17 +303,21 @@ def prefer_cheaper(pick, pool):

def assign_tiers(scored):
best = max(c["score"] for c in scored)
pickable = [c for c in scored if not over_pick_ceiling(c)] or scored
# Below top only standard pairs, as route picks them (premium only on a --up retry).
standard = [c for c in pickable if not c["row"]["premium"]] or pickable
tiers = {}
for tier, floor in FLOORS.items():
pick = cheapest([c for c in scored if c["score"] >= floor * best])
tiers[tier] = prefer_cheaper(pick, scored)
above = [c for c in scored if c["score"] > tiers["middle"]["score"]]
pool = pickable if tier == "top+" else standard
meeting = [c for c in pool if c["score"] >= floor * best] or [max(pool, key=lambda c: c["score"])]
tiers[tier] = prefer_cheaper(cheapest(meeting), pool)
above = [c for c in standard if c["score"] > tiers["middle"]["score"]]
if above:
pick = min(above, key=lambda c: (c["score"], c["cost"]))
tiers["middle+"] = prefer_cheaper(pick, above)
else:
tiers["middle+"] = tiers["top+"]
tiers["top"] = below_top_plus(frontier(scored), tiers["top+"], tiers["middle+"])
tiers["middle+"] = tiers["middle"]
tiers["top"] = below_top_plus(frontier(pickable), tiers["top+"], tiers["middle+"])
return best, tiers


Expand Down Expand Up @@ -533,11 +541,12 @@ def frontier_pick(front, tier, best):
if tier == "middle+":
middle = front.index(frontier_pick(front, "middle", best))
return front[min(middle + 1, len(front) - 1)]
if tier == "top":
return below_top_plus(front, frontier_pick(front, "top+", best), frontier_pick(front, "middle+", best))
if tier == "top": # never below middle+ as route ends it: on a standard pair
standard = [c for c in front if not c["row"]["premium"]] or front
return below_top_plus(front, frontier_pick(front, "top+", best), frontier_pick(standard, "middle+", best))
meeting = meets_floor(front, tier, best)
if not meeting:
return max(front, key=lambda c: c["score"])
return prefer_cheaper(max(front, key=lambda c: c["score"]), front)
return prefer_cheaper(cheapest(meeting), front)


Expand Down Expand Up @@ -573,6 +582,8 @@ def pick_pair(allowed, tier, best, scores, signals, up, down):
pick = stepped
# The preferences never go below this score, so they cannot undo the risk step.
least = pick["score"]
# Nor move a standard pick onto a premium pair, whose run cost understates its real spend.
meeting = [c for c in meeting if c["row"]["premium"] <= pick["row"]["premium"]]
if signals and (scores["J"] == 2 or scores["C"] == 2):
lighter = min([pick] + [c for c in meeting if c["score"] >= least
and c["cost"] <= PREFER_COST_RATIO * pick["cost"]],
Expand Down Expand Up @@ -622,7 +633,8 @@ def route_main(args):
else ("top", "reviews run on top")
best = max(c["score"] for c in pool)
over_budget = not options.review and options.premium_spent >= PREMIUM_BUDGET_USD
allowed = [c for c in pool if not c["row"]["premium"]] if over_budget else pool
allowed = [c for c in pool if not over_pick_ceiling(c)]
allowed = [c for c in allowed if not c["row"]["premium"]] if over_budget else allowed
if not allowed:
print("no selectable pair within the premium budget", file=sys.stderr)
return 4
Expand All @@ -639,27 +651,16 @@ def route_main(args):
return 4
standard = [c for c in allowed if not c["row"]["premium"]]
if tier not in ("top", "top+") and choice["row"]["premium"] and standard:
# Below top a premium pair must beat the standard pick on cost and score,
# unless the standard pairs cannot give a step up the stage asked for:
# the next model up at low thinking beats more thinking on a smaller one.
# Below top no premium pair: benchmark run cost understates its real spend (Fable low
# averaged 2.6-4.5x Opus high per stage). Only a --up retry after a failed build, once
# the standard pairs run out, takes the cheapest pair above the standard pick.
other, other_notes, other_short, _ = pick_pair(standard, tier, best, scores, signals, *steps)
if other is not None and other_short and choice["score"] > other["score"]:
above = next(c for c in front if c["score"] > other["score"]) # front is cheapest first
# A step up the plan asked for (middle+ or risk) takes a premium pair only while
# its score/cost ratio is within the margin of the standard pick's; a --up retry
# after a failure takes it regardless. Cross-multiplied: costs may be 0.
if above["row"]["premium"] and not options.up and above["score"] * other["cost"] \
< (1 - PREMIUM_RATIO_MARGIN) * other["score"] * above["cost"]:
choice = other
notes = other_notes + [f"premium {above['label']} left out below top: its score/cost "
f"is more than {PREMIUM_RATIO_MARGIN:.0%} below {other['label']}'s"]
else:
choice = above
notes = other_notes + [f"no standard pair above {other['label']} for the step up: "
f"{choice['label']}, the cheapest pair above it"]
elif other is not None and (choice["cost"] > other["cost"] or choice["score"] < other["score"]):
notes = other_notes + [f"premium {choice['label']} left out below top: "
f"{other['label']} costs less or scores at least as well"]
if other is not None and other_short and options.up and choice["score"] > other["score"]:
choice = next(c for c in front if c["score"] > other["score"]) # front is cheapest first
notes = other_notes + [f"--up retry, no standard pair above {other['label']}: "
f"{choice['label']}, the cheapest pair above it"]
elif other is not None:
notes = other_notes + [f"premium {choice['label']} left out below top"]
choice = other
why += notes
row = choice["row"]
Expand All @@ -683,7 +684,8 @@ def main(argv):
available, profiles, candidates, excluded, matches = load_offered(
options["available"], options["profiles"])
scored, unscored, metric, cost_field = score_and_cost(candidates)
excluded += unscored
excluded += unscored + [(c["tool_model"], c["effort"], "sets the best score, never picked: above "
"its family's PICK_CEILINGS") for c in scored if over_pick_ceiling(c)]
if not scored:
print("no selectable candidate; see the exclusions below", file=sys.stderr)
for model, effort, reason in excluded:
Expand Down
28 changes: 17 additions & 11 deletions plugins/phased-delivery/skills/plan-in-phases/model-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ raises `middle` to `middle+` (override 2).
`top` has a step above it for the most extreme complexity: **`top+`** is a
`top` stage with a total of 12 or more, or with K = 2 (`plan-check.py`'s
`hardest`). Only `top+` stages, and the reviews of phases that hold one,
get the most capable pair (Fable high today); other `top` stages get the
frontier pair one below it (Fable medium), and a failed build there steps
get the most capable pair (Fable low today); other `top` stages get the
frontier pair one below it (Opus high), and a failed build there steps
up with `--up`. (Changed 2026-11-24: `top` on the most capable pair sent
every review and every total of 9 to Fable high, at about twice Fable
medium's run cost.)
medium's run cost. Changed 2026-11-26: Fable still took 148 of 258 scored
stages, mostly Fable low on `middle+`, at $1.59 a stage against $0.35 to
$0.61 for Opus high; its benchmark run cost understates its real spend.)

Overrides, which always win over the total:

Expand Down Expand Up @@ -130,6 +132,9 @@ What the code enforces, so the agent does not:
models never above `high`, except Haiku, which may use `xhigh`. Higher
levels, and levels the script cannot place, are denied even if offered
and charted. The ceilings are the `CEILINGS` table in the script.
- **Pick ceilings:** Fable is never picked above `medium`. Its higher
levels still set the best score the floors are measured from, so the
other tiers keep their picks (`PICK_CEILINGS`).
- Each candidate is scored by the Artificial Analysis Intelligence Index
(a quarter coding, plus reasoning-heavy science and HLE-Diamond; the free
data has no separate coding or reasoning score) and costed by the benchmark run cost, which counts
Expand All @@ -138,9 +143,10 @@ What the code enforces, so the agent does not:
best** (the floors are constants at the top of the script). So a large
model at low thinking beats a small model at high thinking when it scores
as well for less. `middle+` is the next more capable candidate above
`middle`. `top+` takes the floor of 97% of the best score; `top` is the
frontier pair one below `top+`'s, or `middle+`'s pick when that scores
more.
`middle`. Below `top` only standard-price candidates are picked. `top+`
takes the floor of 97% of the best score; `top` is the frontier pair one
below `top+`'s, or `middle+`'s pick when that scores more. A tier no
candidate meets takes the best-scoring one, then the 3-point tie rule.
- **Within 3 points, the cheaper candidate wins.** After a tier picks, any
cheaper candidate scoring within 3 index points of the pick replaces it,
even across a floor (for `middle+`, only candidates still above
Expand Down Expand Up @@ -207,21 +213,21 @@ What `route` does, in this order:

| Rule | Pick |
| --- | --- |
| Candidates | Offered pairs within the thinking-level ceilings that have a score and a benchmark run cost, minus low-gain thinking steps: a step up gaining under 2 points for more than 1.5 times the run cost of the level below. |
| Candidates | Offered pairs within the thinking-level ceilings that have a score and a benchmark run cost, minus low-gain thinking steps: a step up gaining under 2 points for more than 1.5 times the run cost of the level below. The best score is taken here; then pairs above their pick ceiling (Fable above `medium`) are left out. |
| Frontier | Only pairs on the score/cost frontier: a pair another beats on both score and cost is never chosen. |
| Tier | The tier from the scores with the overrides above, and `top+` for the hardest `top` stages; `--review` uses `top`, or `top+` when its scores are a `top+` stage's. The pick is the cheapest frontier pair meeting the tier's floor, then any cheaper pair within 3 points; `middle+` is the next frontier pair above the `middle` pick; `top` is the frontier pair one below the `top+` pick, never below `middle+`'s. |
| Tier | The tier from the scores with the overrides above, and `top+` for the hardest `top` stages; `--review` uses `top`, or `top+` when its scores are a `top+` stage's. The pick is the cheapest frontier pair meeting the tier's floor, then any cheaper pair within 3 points; `middle+` is the next frontier pair above the `middle` pick; `top` is the frontier pair one below the `top+` pick, never below `middle+`'s standard pick. |
| Premium budget | With `--premium-spent` at or above $10, builds leave premium pairs out. |
| Mechanical (J, P and V all 0, tier above `small`) | Thinking at `medium` or below. `small` stages keep the small model's higher levels. |
| Long or wide (S, R or F = 2) | Thinking at `high` or below. |
| Risk (K of 1 or more) | One frontier pair up, below `top` only: K = 2 makes a `top` stage `top+`. |
| Design or contract (J = 2 or C = 2) | Among pairs meeting the floor that score at least the pick and cost at most 1.5 times it, the lowest thinking level: a larger model at lower thinking. |
| Design or contract (J = 2 or C = 2) | Among pairs meeting the floor that score at least the pick and cost at most 1.5 times it, the lowest thinking level: a larger model at lower thinking. This and the speed preference never move a standard pick onto a premium pair. |
| Long or wide (S, R or F = 2) | Among pairs meeting the floor within 3 points of the pick (with K of 1 or more, at least the risk step's score) and costing at most 1.5 times it, the fastest, if at least 1.2 times the pick's speed (thinking levels of one model differ by a few percent). |
| Premium below `top` | A premium pick below `top` (and `top+`) is routed again without premium pairs; the premium pair stays only if it costs no more than that standard pick and scores at least as well. When the standard pairs run out before a step up the stage asked for (`middle+`, risk, `--up`), the cheapest pair scoring above the standard pick is taken instead (the next model up at low thinking, not more thinking on a smaller model), but only when its score divided by its benchmark run cost is no more than 5% below the standard pick's (`PREMIUM_RATIO_MARGIN`); otherwise the standard pick stays. A `--up` retry after a failed build takes it regardless. |
| Premium below `top` | A premium pick below `top` (and `top+`) is routed again without premium pairs, and the standard pick is taken: a premium pair's benchmark run cost understates its real spend. Only a `--up` retry after a failed build, when the standard pairs run out before the step, takes the cheapest pair scoring above the standard pick (the next model up at low thinking, not more thinking on a smaller model). |
| `--down N`, `--up N` | Move N frontier pairs cheaper or dearer from the pick, stopping at either end. N is 0 or more; not both at once. |
| `--review` | `top`, or `top+` when `--scores` are a `top+` stage's (the driver passes the phase's hardest stage); premium spend and the scores' other signals do not shape it (no caps, risk step or preferences). |

The constants (`LOW_GAIN_POINTS`, `LOW_GAIN_COST_RATIO`, `FLOORS`,
`TIE_POINTS`, `PREMIUM_BUDGET_USD`, `PREFER_COST_RATIO`, `SPEED_GAIN`, `CAP_TOKENS`) are
`TIE_POINTS`, `PICK_CEILINGS`, `PREMIUM_BUDGET_USD`, `PREFER_COST_RATIO`, `SPEED_GAIN`, `CAP_TOKENS`) are
at the top of the script.

### Limits
Expand Down
23 changes: 23 additions & 0 deletions plugins/phased-delivery/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import os
import tempfile
from pathlib import Path

import pytest


def noexec(path):
return bool(os.statvfs(path).f_flag & os.ST_NOEXEC)


def pytest_configure(config):
# The tests put stub claude and codex scripts on PATH. On a noexec temp directory
# (the ai-coding sandbox's /tmp) a stub cannot run and the real CLI answers instead,
# so keep the temp files in the repository's ignored .pytest-tmp.
if config.option.basetemp is None and noexec(tempfile.gettempdir()):
config.option.basetemp = str(Path(__file__).parent / ".pytest-tmp")
# and stop git there, so a test directory is never taken as part of this repository
os.environ["GIT_CEILING_DIRECTORIES"] = config.option.basetemp
base = Path(config.option.basetemp or tempfile.gettempdir())
base.mkdir(parents=True, exist_ok=True)
if noexec(base):
raise pytest.UsageError(f"{base} is mounted noexec: pass --basetemp on a mount that can run files")
Loading
Loading