Skip to content
Merged
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Tests

# Run the phased-delivery plugin's test suite on every pull request and on
# pushes to main. The tests use only the Python standard library, git and
# POSIX sh; external CLIs (claude, codex) are stubbed.

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

jobs:
pytest:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.x"
- run: python -m pip install pytest
- run: python -m pytest -q -p no:cacheprovider plugins/phased-delivery/tests
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ a dollar cap: 150k tokens for `small`, 400k for `middle`, 1M for `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, and get $10 per phase; past
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. They get $10 per phase; past
that, builds use none. Reviews always run on `top`, 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
23 changes: 22 additions & 1 deletion docs/model-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ How it works now:
risk, `--up`), the cheapest pair above the standard pick is taken. The
user's view, from practice: more thinking scores well on benchmarks but
can do worse on real work, so the next model up at low thinking beats a
smaller model above high. Hence Opus stays capped at `high`;
smaller model above high. Hence Opus stays capped at `high`. Since
2026-11-24 that step takes the premium pair only when its score/cost
ratio is no more than 5% below the standard pick's
(`PREMIUM_RATIO_MARGIN`), except on a `--up` retry after a failed
build. The user's reasoning: Fable is expected to comprehend much better
than Opus and may need fewer tokens at low thinking, so a near tie goes
to Fable low; a clearly worse ratio does not. 5%, not 10%: Fable has its
own quota, and once it is used up builds fall back to Opus anyway;
- reviews (`--review`) run on `top` and ignore the stage's scores.
- **Rule sweep, 2026-11-23** (free: all 6,561 score combinations through
`route` on the live profiles):
Expand All @@ -116,6 +123,20 @@ How it works now:
medium.
- The J2/C2 preference never fires: no pair scores at least Fable high
at a lower thinking level. It waits for a larger model.
- **Fable limits, 2026-11-24:** Fable at medium thinking or above should be
for the top 10% most complex stages. On the 38 stages scored in this
repository's plans and eval tasks (main's 29 plus the 9 in
`docs/plans/implement-structured/` on the `implement-structured`
branch), `route` sent 15 (39%) to Fable high
and 10 to Fable low; 10 of the 15 `top` stages got there only through
K = 2, at totals of 5 to 7. Two changes: `top` comes only from a total of
9 or more (the "J, C or K = 2" override is gone), and the premium step-up
above needs a score/cost ratio within 5% of the standard pick's. After:
2 stages (5%) on Fable high, both totalling 9; 23 on Fable low, the
`middle+` and risk steps (on the current profiles Fable 5.2 low scores
0.0188 points per unit of run cost, Opus 5.5 high 0.0191, 1.3% apart);
5 on Opus high; 8 on Haiku xhigh. A strict "beats" rule was tried first
and rejected: it hinged on that 1.3%.
- **Limits:** a token cap per stage (150k `small`, 400k `middle` and
`middle+`, 1M `top`) passed to `claude -p` as a dollar cap at the pair's
input price, since `--max-budget-usd` is the hard stop it offers. A build
Expand Down
121 changes: 121 additions & 0 deletions docs/plans/fable-limits/01-fable-limits.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Phase 01: Tier rule and premium ratio gate

Implement with the implement-in-phases skill; do not build from this file
without it. Model tiers map to models in [models.md](models.md).
Status: built 5c581aa
Before: `tier` makes any stage with J, C or K at 2 `top`, and `route` takes the premium pair above the standard pick whenever the standard pairs run out before a requested step up, so Fable high and Fable low are the usual picks.
After: `top` comes only from a total of 9 or more, and a premium step-up below `top` needs a score/cost ratio no more than 5% below the standard pick's, except on a `--up` retry. model-selection.md and docs/model-routing.md describe both rules.

## Assumptions
- Verified: `select-models.py` takes its tier from plan-check.py's `tier` through `stage_tier`, so one change covers planning and routing. (plugins/phased-delivery/scripts/select-models.py:480-485)
- Verified: Each route candidate carries `score` and `cost` (the benchmark run cost), which the frontier already compares. (plugins/phased-delivery/scripts/select-models.py:488-493, frontier)

## Size

Quick plan:
- plan-mode.py sketch: quick, score 6.0
- tier rule (interface, plan_check.tier): 3.0
- premium step-up ratio gate (internal): 1
- docs and tests (internal): 2

## Outcome tests
Budget: The plugin suite stays under a minute.

| Outcome | Test | Written in | Passes from |
| --- | --- | --- | --- |
| `select-models.py route` for a stage scored J1F1R1C1K2P1V0S0 (total 7) prints tier `middle+`, not `top`; a stage totalling 9 or more still prints `top`. | `plugins/phased-delivery/tests/test_select_models.py::test_route_fable_limits` | 01.1 | 01.1 |
| When the standard pairs run out before a `middle+` or risk step, `route` prints the premium pair above the standard pick only when its score/cost ratio is no more than 5% below the standard pick's, and otherwise the standard pick with the reason in `why`; with `--up 1` it still prints the premium pair. | `plugins/phased-delivery/tests/test_select_models.py::test_route_fable_limits` | 01.1 | 01.1 |

## Stages

| Stage | Goal | Tier | Order | Status |
| --- | --- | --- | --- | --- |
| 01.1 | `tier` makes `top` only from a total of 9 or more, and `route` takes a premium step-up below `top` only when its score/cost ratio is no more than 5% below the standard pick's or the step is a `--up` retry. | middle | first | done |
| 01.2 | model-selection.md and docs/model-routing.md state the new tier rule and the ratio gate, with the measurement that led to them. | middle | after 01.1 | done |

## 01.1 Tier rule, ratio gate and test

Goal: `tier` makes `top` only from a total of 9 or more, and `route` takes a premium step-up below `top` only when its score/cost ratio is no more than 5% below the standard pick's or the step is a `--up` retry.

Context:
- `plugins/phased-delivery/scripts/plan-check.py:97-98`: The override that makes J, C or K at 2 `top`.
- `plugins/phased-delivery/scripts/select-models.py:619-622`: The step-up branch of the premium gate below top.
- `plugins/phased-delivery/tests/test_select_models.py:122`: The existing premium gate test and its edited-profiles pattern to follow.
- Design, Rules: "`top` comes only from a total of 9 or more."
- Design, Rules: "A `--up` retry after a failed build still steps up"

Contracts:
- function `tier` (provides; plugins/phased-delivery/scripts/select-models.py): tier(mb: dict of J F R C K P V S scores) -> (total, tier, why); top only when total >= 9

Files:
- `plugins/phased-delivery/scripts/plan-check.py` (edit): `tier` without the J, C or K = 2 override
- `plugins/phased-delivery/scripts/select-models.py` (edit): the premium gate's step-up branch checks the score/cost ratio unless `--up` was given
- `plugins/phased-delivery/tests/test_select_models.py` (edit): `test_route_fable_limits` and any expectations the tier change moves

Behaviour:
- Given scores totalling 8 or less with J, C or K at 2, when `tier` runs, then the tier is `middle+` (a measure at 2 on `middle`), not `top`.
- Given scores totalling 9 or more, when `tier` runs, then the tier is `top`, as before.
- Given a middle+ or risk step below top where the standard pairs run out and the premium pair above has a score/cost ratio more than 5% below the standard pick's, when `route` runs without `--up`, then it prints the standard pick, and `why` says the premium pair was left out for its score/cost ratio.
- Given the same stage, when `route` runs with `--up 1`, then it prints the premium pair above the standard pick, as before.
- Given a premium pair whose ratio is no more than 5% below the standard pick's, when `route` runs, then the step up takes it, as before.

External inputs:
none

Tests:
- writes `plugins/phased-delivery/tests/test_select_models.py::test_route_fable_limits` (outcome): `select-models.py route` for a stage scored J1F1R1C1K2P1V0S0 (total 7) prints tier `middle+`, not `top`; a stage totalling 9 or more still prints `top`.
- writes `plugins/phased-delivery/tests/test_select_models.py::test_route_fable_limits` (outcome): When the standard pairs run out before a `middle+` or risk step, `route` prints the premium pair above the standard pick only when its score/cost ratio is no more than 5% below the standard pick's, and otherwise the standard pick with the reason in `why`; with `--up 1` it still prints the premium pair.
- keeps passing `plugins/phased-delivery/tests/test_select_models.py::test_route_premium_below_top` (integration): the cost-and-score rule and the --up step still hold

Done when:
- `python3 -m pytest -q -p no:cacheprovider --basetemp=/cache/pytest-r plugins/phased-delivery/tests` passes

Out of scope:
- The floors, caps and other route rules
- The plan's recorded tiers in existing phase files

Model basis: J1 F1 R1 C1 K0 P1 V0 S0 = 5 -> middle

## 01.2 Docs for the new rules

Goal: model-selection.md and docs/model-routing.md state the new tier rule and the ratio gate, with the measurement that led to them.

Context:
- Builds on 01.1: the new tier rule and ratio gate to describe
- `plugins/phased-delivery/skills/plan-in-phases/model-selection.md:46`: Override 1, which is removed.
- `plugins/phased-delivery/skills/plan-in-phases/model-selection.md:200`: The route table row the ratio rule joins.
- `docs/model-routing.md:94-95`: The routing notes' premium rule list.
- Design, Problem: "Fable at
medium thinking or above should be for the top 10% most complex tasks"

Contracts:
none

Files:
- `plugins/phased-delivery/skills/plan-in-phases/model-selection.md` (edit): overrides without J, C or K = 2 to top, examples re-scored, and the ratio rule in the route table
- `docs/model-routing.md` (edit): the rule change and the 38-stage measurement

Behaviour:
- Given a planner reading model-selection.md, when it picks a tier, then nothing tells it a single 2 means top.

External inputs:
none

Tests:
none

Done when:
- `grep -n 'K = 2: use' plugins/phased-delivery/skills/plan-in-phases/model-selection.md` finds nothing

Out of scope:
- implement-in-phases guides

Model basis: J1 F1 R0 C0 K0 P1 V1 S0 = 4 -> middle

## Notes
- 2026-11-24: measured before the change: 15 of 38 scored stages routed to Fable high, 10 to Fable low; with the override dropped, 2 to Fable high (5%).
- The ratio uses the profiles' `score` and benchmark run `cost` that `route` already compares; no new data. Reason: The selector's frontier already ranks pairs by those two numbers.
- Plan start: 6982bc0. Quick plan: no plan review.
- 2026-11-24: stages built directly by the orchestrator.
- 2026-11-24: revised after 01.1 and 01.2 at the user's request: a premium step-up is taken while its score/cost ratio is no more than 5% below the standard pick's (`PREMIUM_RATIO_MARGIN`), not only when it is at least as good; first 10%, then 5% because Fable has its own quota and builds fall back to Opus once it is used up. Measured after: 2 Fable high (5%), 23 Fable low, 5 Opus high, 8 Haiku xhigh of the 38 stages.
- 2026-11-24: phase review (fable high, in-session): not ready, 1 blocking (this file still described the strict rule; fixed by the revision above) and 7 should-fix, all fixed in 3f2a80f (gate only for premium step-ups, so a `--down` retry is not held; cross-multiplied, no division; risk and `--down` tests) and 5c581aa (example tier, where the 38-stage sample comes from, the README routing sentence; README.md added to 01.2's files by this revision).
37 changes: 37 additions & 0 deletions docs/plans/fable-limits/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Fable limits for implementation: design

Agreed with the user on 2026-11-24.

## Problem

Across the 38 stages scored in this repository's plans and eval tasks (main's
29 plus the 9 in `docs/plans/implement-structured/` on the `implement-structured`
branch), `route`
sends 15 (39%) to Fable high and 10 more to Fable low. Ten of the fifteen
`top` stages reach it only through K = 2, with totals of 5 to 7. Fable at
medium thinking or above should be for the top 10% most complex tasks; picking
it this often means the implementation criteria are not tuned.

## Rules

- `top` comes only from a total of 9 or more. The override "J = 2, C = 2 or
K = 2: use top" is dropped; a measure at 2 still raises `middle` to
`middle+`.
- Fable low as a step up is fine as long as it beats Opus high in
cost/performance ratio. Codified for any premium pair below `top`: when the
standard pairs run out before a step up the stage asked for (`middle+` or
risk), the premium pair above the standard pick is taken only when its score
divided by its benchmark run cost is at least the standard pick's; otherwise
the standard pick stays. A `--up` retry after a failed build still steps up,
because the standard pick has already failed.
- Revised the same day: the user is "ok for now with letting fable low win
if the cost is within an appropriate margin", since Fable should comprehend
better and may need fewer tokens at low thinking. The premium pair's ratio
may be up to 5% below the standard pick's (`PREMIUM_RATIO_MARGIN`); 5%
rather than 10% because Fable has its own quota, and once it is used up
builds fall back to Opus anyway.

## Check

On the 38 scored stages with the current profiles, Fable at medium or above is
picked for at most 10% of stages.
14 changes: 14 additions & 0 deletions docs/plans/fable-limits/models-available.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"tool": "claude-code",
"tool_version": "2.1.330",
"looked_up_from": "Agent tool parameter description (model and effort enums), 2026-11-23",
"subagent_model_choice": "allowed",
"opted_in": true,
"opt_in_where": "phased-delivery skills set model and effort per models.md",
"models": [
{"id": "fable", "efforts": ["low", "medium", "high", "xhigh", "max"]},
{"id": "opus", "efforts": ["low", "medium", "high", "xhigh", "max"]},
{"id": "sonnet", "efforts": ["low", "medium", "high", "xhigh", "max"]},
{"id": "haiku", "efforts": ["low", "medium", "high", "xhigh", "max"]}
]
}
46 changes: 46 additions & 0 deletions docs/plans/fable-limits/models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Models

Generated by `scripts/select-models.py` from `models-available.json` and
the plugin's `model-profiles.json`; rerun it rather than editing this file.

Looked up: claude-code 2.1.330, from Agent tool parameter description (model and effort enums), 2026-11-23
Profiles: 438ab73a830ba4736e7ab9e51196e3b2c0ccfdc3ce65c2a7889d70081e9d9749 (data checked 2026-11-21); Data: Artificial Analysis (https://artificialanalysis.ai)
Subagent model choice: allowed
Score: intelligence; cost: run_cost_usd; best score 61.8; floors: top 97%, middle 85%, small 50%; cheaper within 3 points wins

| Tier | Model | Effort | Score | Cost | Report row |
| --- | --- | --- | --- | --- | --- |
| small | haiku | xhigh | 34.6 | 192.70 | Claude Haiku 5.5 (Xhigh) |
| middle | opus | high | 51.8 | 2715.98 | Claude Opus 5.5 (High, Default Fallback) |
| middle+ | fable | low | 53.9 | 2861.78 | Claude Fable 5.2 (Low, Default Fallback) |
| top | fable | high | 61.8 | 7105.77 | Claude Fable 5.2 (High, Default Fallback) |

Matches (tool model -> report model):
- fable -> Claude Fable 5.2 (alias: newest release containing the name)
- opus -> Claude Opus 5.5 (alias: newest release containing the name)
- sonnet -> Claude Sonnet 5.5 (alias: newest release containing the name)
- haiku -> Claude Haiku 5.5 (alias: newest release containing the name)

Candidates considered:
- fable at high: score 61.8, cost 7105.77
- fable at medium: score 56.4, cost 3359.66
- fable at low: score 53.9, cost 2861.78
- opus at high: score 51.8, cost 2715.98
- opus at medium: score 48.2, cost 2031.27
- sonnet at high: score 41.5, cost 1268.30
- opus at low: score 34.8, cost 979.66
- haiku at xhigh: score 34.6, cost 192.70
- sonnet at medium: score 30.8, cost 679.16
- haiku at high: score 29.9, cost 121.41
- sonnet at low: score 25.6, cost 499.20
- haiku at medium: score 24.6, cost 72.70
- haiku at low: score 18.6, cost 39.60

Excluded:
- fable at max: denied: above this model's high ceiling
- fable at xhigh: denied: above this model's high ceiling
- opus at max: denied: above this model's high ceiling
- opus at xhigh: denied: above this model's high ceiling
- sonnet at max: denied: above this model's high ceiling
- sonnet at xhigh: denied: above this model's high ceiling
- haiku at max: denied: above this model's xhigh ceiling
2 changes: 0 additions & 2 deletions plugins/phased-delivery/scripts/plan-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ def quote_found(q, text):

def tier(mb):
total = sum(mb[m] for m in MEASURES)
if mb["J"] == 2 or mb["C"] == 2 or mb["K"] == 2:
return total, "top", "J, C or K = 2"
t, why = ("small" if total <= 3 else "middle" if total <= 8 else "top"), ""
if t == "small" and not (all(mb[m] == 0 for m in "JCKS") and mb["P"] == 0 and mb["V"] == 0):
t, why = "middle", "small only for mechanical stages"
Expand Down
20 changes: 17 additions & 3 deletions plugins/phased-delivery/scripts/select-models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
# 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 @@ -617,9 +621,19 @@ def route_main(args):
# the next model up at low thinking beats more thinking on a smaller one.
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"]:
choice = next(c for c in front if c["score"] > other["score"]) # front is cheapest first
notes = other_notes + [f"no standard pair above {other['label']} for the step up: "
f"{choice['label']}, the cheapest pair above it"]
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"]
Expand Down
Loading
Loading