From 7891b78cc4fa17a63851e0538c71d8e1adb35b48 Mon Sep 17 00:00:00 2001 From: Bryan <28662377+bryanwieg@users.noreply.github.com> Date: Tue, 24 Nov 2026 14:32:12 +0000 Subject: [PATCH 1/4] Route Fable high only to the hardest work (top+) top sent every total of 9 and every review and revision to the most capable pair (Fable high, about twice Fable medium's run cost). Now top+ is a top stage with a total of 12 or more or risk K2 (plan-check.py's hardest) and takes the old top pick; other top stages take the frontier pair one below it (Fable medium), never below middle+, and step up with --up when a build fails. Reviews run on top, or top+ when the phase holds a top+ stage: the driver passes the phase's hardest stage's scores to route --review. Revisions and plan reviews follow the same split. The risk step no longer applies within top; middle and middle+ are unchanged. On the scores of ~260 real briefs, 11 of 15 top stages move from Fable high to Fable medium, and reviews move to Fable medium unless the phase holds one of the other 4. Version 0.14.0. Co-Authored-By: Claude Opus 5.5 --- README.md | 11 ++-- .../.claude-plugin/plugin.json | 2 +- plugins/phased-delivery/scripts/plan-check.py | 6 +++ plugins/phased-delivery/scripts/run-phase.py | 12 +++-- .../phased-delivery/scripts/select-models.py | 51 ++++++++++++++----- .../skills/plan-in-phases/SKILL.md | 3 +- .../skills/plan-in-phases/model-selection.md | 40 ++++++++++----- .../skills/plan-in-phases/plan-reviewer.md | 3 +- .../tests/test_select_models.py | 39 ++++++++------ 9 files changed, 114 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index 277177e..6fe5e3b 100644 --- a/README.md +++ b/README.md @@ -86,15 +86,18 @@ cost, lower thinking for mechanical stages, a larger model at lower thinking for design work, faster models for long or wide work and one step up for risk. Claude stages and phase reviews are then built headless by `plugins/phased-delivery/scripts/claude-build.sh` (`claude -p`), stopped at -a dollar cap: 150k tokens for `small`, 400k for `middle`, 1M for `top`, at +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. 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 +`top` comes only from a total score of 9 or more. 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. +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 `CLAUDE_BUILD_PERMISSIONS=bypassPermissions` only when Claude Code already runs in a sandbox container (the ai-coding sandbox image sets it). Every cap is at least $0.25, since a cheap diff --git a/plugins/phased-delivery/.claude-plugin/plugin.json b/plugins/phased-delivery/.claude-plugin/plugin.json index c63d771..4657db7 100644 --- a/plugins/phased-delivery/.claude-plugin/plugin.json +++ b/plugins/phased-delivery/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "phased-delivery", - "version": "0.13.0", + "version": "0.14.0", "description": "Plan work as self-contained phases, then implement it phase by phase.", "author": { "name": "Bryan" diff --git a/plugins/phased-delivery/scripts/plan-check.py b/plugins/phased-delivery/scripts/plan-check.py index 538ca38..83b7ac5 100644 --- a/plugins/phased-delivery/scripts/plan-check.py +++ b/plugins/phased-delivery/scripts/plan-check.py @@ -124,6 +124,12 @@ def tier(mb): return total, t, why +def hardest(mb): + """A top stage of the most extreme complexity (a total of 12 or more, or risk K2): the one routed to top+.""" + total, t, _ = tier(mb) + return t == "top" and (total >= 12 or mb["K"] == 2) + + def strings(x, path=""): if isinstance(x, str): yield path, x diff --git a/plugins/phased-delivery/scripts/run-phase.py b/plugins/phased-delivery/scripts/run-phase.py index 38e4d72..1d4438e 100755 --- a/plugins/phased-delivery/scripts/run-phase.py +++ b/plugins/phased-delivery/scripts/run-phase.py @@ -214,8 +214,11 @@ def record(c, what, pair, res, *flags): def stage_pair(c, brief, *steps): """The stage's routed pair, from its brief's scores and the premium spend.""" spent = must(py("build-check.py", "spend", c.pdir), "spend").stdout.strip() - scores = "".join(f"{k}{brief['model_basis'][k]}" for k in "JFRCKPVS") - return route(c, "--scores", scores, "--premium-spent", spent, *steps) + return route(c, "--scores", scores_of(brief), "--premium-spent", spent, *steps) + + +def scores_of(brief): + return "".join(f"{k}{brief['model_basis'][k]}" for k in "JFRCKPVS") def set_findings(c, findings): @@ -369,7 +372,10 @@ def review(c, stages): path = os.path.join(c.pdir, "review.json") rec = plan_check.read_json(os.path.join(c.pdir, "phase.json"))["record"] unchecked = [sid for sid, s in stages.items() if not s["brief"]["checks"]] - pair = route(c, "--scores", "J0F0R0C0K0P0V0S0", "--review") + # the phase's hardest stage decides between top and top+ + hardest = max((s["brief"]["model_basis"] for s in stages.values()), + key=lambda mb: (plan_check.hardest(mb), plan_check.tier(mb)[0])) + pair = route(c, "--scores", scores_of({"model_basis": hardest}), "--review") inputs = [f"- Phase folder: `{c.pdir}`", f"- Diff of the phase: `git diff {rec['start_commit']}`", "- Edits that were present before the phase and are not part of it: " + (", ".join(f"`{p}`" for p in rec["preexisting"]) or "none"), diff --git a/plugins/phased-delivery/scripts/select-models.py b/plugins/phased-delivery/scripts/select-models.py index f38f9a8..0d57839 100755 --- a/plugins/phased-delivery/scripts/select-models.py +++ b/plugins/phased-delivery/scripts/select-models.py @@ -59,8 +59,10 @@ import sys # Tier floors: a candidate qualifies if its score is at least this share of -# the best candidate's score; the cheapest qualifying candidate wins. -FLOORS = {"top": 0.97, "middle": 0.85, "small": 0.50} +# the best candidate's score; the cheapest qualifying candidate wins. Only the +# hardest stages (plan-check.py's hardest) and their phases' reviews get top+; +# top is the frontier pair one below it, never below middle+. +FLOORS = {"top+": 0.97, "middle": 0.85, "small": 0.50} # After a tier picks a candidate, any cheaper candidate scoring within this # many index points (the index runs 0-100) of the pick is taken instead. TIE_POINTS = 3.0 @@ -86,7 +88,7 @@ PROFILES_FILE = "model-profiles.json" # Tokens a stage may spend, by tier; passed on as a dollar cap at the pair's # input price. -CAP_TOKENS = {"small": 150000, "middle": 400000, "middle+": 400000, "top": 1000000} +CAP_TOKENS = {"small": 150000, "middle": 400000, "middle+": 400000, "top": 1000000, "top+": 1000000} # No build's dollar cap is lower than this: at the input price alone a cheap # model's cap rounds to a cent, below what one headless run costs. MIN_CAP_USD = 0.25 @@ -306,10 +308,17 @@ def assign_tiers(scored): pick = min(above, key=lambda c: (c["score"], c["cost"])) tiers["middle+"] = prefer_cheaper(pick, above) else: - tiers["middle+"] = tiers["top"] + tiers["middle+"] = tiers["top+"] + tiers["top"] = below_top_plus(frontier(scored), tiers["top+"], tiers["middle+"]) return best, tiers +def below_top_plus(front, top_plus, middle_plus): + """top: the frontier pair one below top+'s pick, or middle+'s pick when that scores more.""" + lower = [c for c in front if c["score"] < top_plus["score"]] # front is cheapest first + return max(lower[-1:] + [middle_plus], key=lambda c: c["score"]) + + def money(value): return "n/a" if value == math.inf else f"{value:.2f}" @@ -338,7 +347,7 @@ def render(available, profiles, metric, cost_field, best, tiers, scored, exclude "| Tier | Model | Effort | Score | Cost | Report row |", "| --- | --- | --- | --- | --- | --- |", ] - for tier in ["small", "middle", "middle+", "top"]: + for tier in ["small", "middle", "middle+", "top", "top+"]: c = tiers[tier] lines.append(f"| {tier} | {c['tool_model']} | {c['effort']} | {c['score']:.1f}" f" | {money(c['cost'])} | {c['row']['name']} |") @@ -481,12 +490,20 @@ def parse_scores(text): return {text[i]: int(text[i + 1]) for i in range(0, 16, 2)} -def stage_tier(scores): - """plan-check.py's tier: (total, tier, why) with the model-selection overrides.""" +def plan_check(): spec = importlib.util.spec_from_file_location("plan_check", os.path.join(HERE, "plan-check.py")) - plan_check = importlib.util.module_from_spec(spec) - spec.loader.exec_module(plan_check) - return plan_check.tier(scores) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def stage_tier(scores): + """plan-check.py's tier: (total, tier, why), with top+ for its hardest stages.""" + checks = plan_check() + total, tier, why = checks.tier(scores) + if checks.hardest(scores): + return total, "top+", "total of 12 or more, or risk K2" + return total, tier, why def frontier(pool): @@ -502,6 +519,8 @@ def meets_floor(front, tier, best): if tier == "middle+": bar = frontier_pick(front, "middle", best)["score"] return [c for c in front if c["score"] > bar] + if tier == "top": + return [c for c in front if c["score"] >= frontier_pick(front, tier, best)["score"]] return [c for c in front if c["score"] >= FLOORS[tier] * best] @@ -514,6 +533,8 @@ 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)) meeting = meets_floor(front, tier, best) if not meeting: return max(front, key=lambda c: c["score"]) @@ -544,7 +565,7 @@ def pick_pair(allowed, tier, best, scores, signals, up, down): if cap and pick is not frontier_pick(frontier(allowed), tier, best): why.append(f"{'mechanical' if mechanical else 'long or wide'} stage: thinking capped at {cap}") meeting = meets_floor(front, tier, best) - if signals and scores["K"] >= 1: + if signals and scores["K"] >= 1 and tier not in ("top", "top+"): # top+ already takes K2 short = short or front.index(pick) == last stepped = front[min(front.index(pick) + 1, last)] if stepped is not pick: @@ -595,8 +616,10 @@ def route_main(args): if not pool: print("no selectable pair", file=sys.stderr) return 4 - tier, tier_why = ("top", "phase reviews run on top") if options.review \ - else stage_tier(options.scores)[1:] + tier, tier_why = stage_tier(options.scores)[1:] + if options.review: # a review runs on top, or top+ when its scores are the phase's hardest stage's + tier, tier_why = ("top+", "review of a phase with a top+ stage") if tier == "top+" \ + 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 @@ -615,7 +638,7 @@ def route_main(args): print(notes, file=sys.stderr) return 4 standard = [c for c in allowed if not c["row"]["premium"]] - if tier != "top" and choice["row"]["premium"] and standard: + 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. diff --git a/plugins/phased-delivery/skills/plan-in-phases/SKILL.md b/plugins/phased-delivery/skills/plan-in-phases/SKILL.md index 2391d04..391c637 100644 --- a/plugins/phased-delivery/skills/plan-in-phases/SKILL.md +++ b/plugins/phased-delivery/skills/plan-in-phases/SKILL.md @@ -207,7 +207,8 @@ since it reads the files as an implementer will, without the planning session's context. Give it [plan-reviewer.md](plan-reviewer.md) unchanged, with its inputs filled in; that file holds what counts as a finding, where to look and the report format. Use the `top` candidate from the plan's -`models.md`. +`models.md`, or `top+` when the plan holds a `top+` stage (a `top` stage +with a total of 12 or more, or K = 2). The reviewer reports only the finding types plan-reviewer.md lists, each with evidence, and may recommend going back to change earlier phases, even diff --git a/plugins/phased-delivery/skills/plan-in-phases/model-selection.md b/plugins/phased-delivery/skills/plan-in-phases/model-selection.md index 07c6359..91dcc66 100644 --- a/plugins/phased-delivery/skills/plan-in-phases/model-selection.md +++ b/plugins/phased-delivery/skills/plan-in-phases/model-selection.md @@ -47,6 +47,15 @@ more does. (Changed 2026-11-24: the old override, any of J, C or K at 2 means `top`, sent 39% of stages to the most expensive pair.) A measure at 2 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 +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.) + Overrides, which always win over the total: 1. **`small` only for mechanical stages:** J, C, K and S all 0, P = 0 (the @@ -129,7 +138,9 @@ 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`. + `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. - **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 @@ -198,16 +209,16 @@ What `route` does, in this order: | --- | --- | | 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. | | 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; `--review` uses `top`. 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. | +| 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. | | 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. | +| 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. | | 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` 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; 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. | | `--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`, ignoring premium spend and the stage's scores (no caps, risk step or preferences). | +| `--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 @@ -216,7 +227,7 @@ at the top of the script. ### Limits - **Stage caps:** `cap_tokens` is 150000 for `small`, 400000 for `middle` - and `middle+`, 1000000 for `top`. `cap_usd` is that many tokens at the + and `middle+`, 1000000 for `top` and `top+`. `cap_usd` is that many tokens at the pair's input price, rounded to cents, and never below $0.25 (`MIN_CAP_USD`): at the input price alone a `small` stage on Haiku would get $0.01, below one headless run. `claude-build.sh` stops the build @@ -230,7 +241,8 @@ at the top of the script. `Cost:`, or `cap_usd` when the cost is `unknown`) to `route` as `--premium-spent`. Once it reaches $10, builds get no premium pair for the rest of the phase. -- **Reviews** use `route --review`: always `top`, their cost counted +- **Reviews** use `route --review`: `top`, or `top+` for a phase with a + `top+` stage, their cost counted against the premium budget when built by `claude-build.sh`, never a step down. A review stopped at its cap is reported to the user, not retried lower. @@ -287,7 +299,7 @@ brief is revised; the driver routes from them (see "Adjust while working"). = 7 -> override 2 -> `middle+`. Better still, the planner should settle the approach and re-score. - Replace the session store with a new one, migrating stored sessions and - retiring the old path: J1 F2 R2 C2 K2 P2 V1 S1 = 13 -> `top`. + retiring the old path: J1 F2 R2 C2 K2 P2 V1 S1 = 13 -> `top+`. A high score can also mean the stage is too big: before accepting F = 2 or R = 2, check whether the stage should be split. @@ -296,11 +308,13 @@ R = 2, check whether the stage should be split. - **Reviews run on `top`** through `route --review` (on `models-available-codex.json` when the routing rule sends the review to - Codex), whatever the tier of the work under review. A review exists to - catch what the author missed, including bad assumptions; a weaker - reviewer defeats the point. Its cost counts against the premium budget, - but it never drops a step. -- **Planning and plan revision** use `top`. + Codex), or on `top+` when the phase holds a `top+` stage. A review exists + to catch what the author missed, including bad assumptions; it never runs + below `top`, but the most capable pair on every review is more than most + phases need. Its cost counts against the premium budget, but it never + drops a step. +- **Planning and plan revision** use `top`; a plan review uses `top+` when + the plan holds a `top+` stage. - Never dispatch a pair below the one `route` prints for the stage's scores without a written reason in the phase's Notes; a `--down` retry after a budget stop is recorded by its Earlier-Attempt trailer, which diff --git a/plugins/phased-delivery/skills/plan-in-phases/plan-reviewer.md b/plugins/phased-delivery/skills/plan-in-phases/plan-reviewer.md index fb9916d..75a94fd 100644 --- a/plugins/phased-delivery/skills/plan-in-phases/plan-reviewer.md +++ b/plugins/phased-delivery/skills/plan-in-phases/plan-reviewer.md @@ -2,7 +2,8 @@ Give this file, unchanged, to each plan-review subagent, followed by the inputs below. Use a new subagent every round, on the `top` candidate -from the plan's `models.md` (see [model-selection.md](model-selection.md)). +from the plan's `models.md`, or `top+` when the plan holds a `top+` stage +(see [model-selection.md](model-selection.md)). Inputs the orchestrator fills in: diff --git a/plugins/phased-delivery/tests/test_select_models.py b/plugins/phased-delivery/tests/test_select_models.py index b413767..f319726 100644 --- a/plugins/phased-delivery/tests/test_select_models.py +++ b/plugins/phased-delivery/tests/test_select_models.py @@ -39,7 +39,8 @@ def test_any_age_and_check(tmp_path): assert f"Profiles: {fingerprint} (data checked 2020-01-01); {REPORT['attribution']}" in text tiers = [line.split(" | ")[:3] for line in text.splitlines() if line.startswith("| ")][2:] assert tiers == [["| small", "haiku", "high"], ["| middle", "opus", "medium"], - ["| middle+", "opus", "high"], ["| top", "opus", "high"]] + ["| middle+", "opus", "high"], ["| top", "opus", "high"], + ["| top+", "opus", "high"]] assert run("check", models_md, "--profiles", profiles).returncode == 0 repriced = copy.deepcopy(REPORT) @@ -93,20 +94,24 @@ def test_route_stage_signals(offered, tmp_path): assert claude["cap_usd"] == 0.25 # MIN_CAP_USD: at Haiku's input price it would be $0.01 # F2 caps at high: small would be luna xhigh. assert pair(route(offered, "J0F2R0C0K0P0V0S0")) == ("terra", "low") - # F2 prefers the faster close pair: top is astra high, sol high is faster. - assert pair(route(offered, "J1F2R1C1K0P2V2S0")) == ("sol", "high") - # J2 on a top stage (total 9) moves up the model before the thinking level: nova low costs 1.33x astra high. - assert pair(route(offered, "J2F1R1C2K0P2V1S0")) == ("nova", "low") + # A top stage that is not among the hardest gets the pair one below top+ (astra high). + assert pair(route(offered, "J1F2R1C1K0P2V2S0")) == ("sol", "medium") + # F2 prefers the faster close pair: top+ (total 13) is astra high, sol high is faster. + assert pair(route(offered, "J1F2R2C1K2P2V1S1")) == ("sol", "high") + # J2 on a top+ stage moves up the model before the thinking level: nova low costs 1.33x astra high. + assert pair(route(offered, "J2F1R1C2K2P2V1S0")) == ("nova", "low") # Risk moves one frontier pair up from the middle pick, terra high. assert pair(route(offered, "J1F1R0C0K1P0V0S0")) == ("sol", "low") - # The J2 preference never undoes the risk step: without astra and sol high, - # J2 alone picks nova low, and with K1 the step up to nova medium holds. + # On a top stage, K1 does not step up to top+ (only K2 makes a stage top+). + assert pair(route(offered, "J2F1R1C2K1P2V0S0")) == ("sol", "medium") + # Without astra and sol high, J2 on top+ picks nova low, and a --up retry + # after a failure moves on to nova medium. narrow = tmp_path / "narrow.json" narrow.write_text(json.dumps({**OFFERED, "models": [ m if m["id"] != "gpt-9-sol" else {**m, "efforts": ["low", "medium"]} for m in OFFERED["models"] if m["id"] != "gpt-9-astra"]})) - assert pair(route(narrow, "J2F1R1C2K0P2V1S0")) == ("nova", "low") - assert pair(route(narrow, "J2F1R1C2K1P2V0S0")) == ("nova", "medium") + assert pair(route(narrow, "J2F1R1C2K2P2V1S0")) == ("nova", "low") + assert pair(route(narrow, "J2F1R1C2K2P2V1S0", "--up", "1")) == ("nova", "medium") def edited_profiles(tmp_path, changes): @@ -171,21 +176,23 @@ def test_route_fable_limits(tmp_path): def test_route_speed_gain(offered, tmp_path): # sol high at 45 is only 1.125x astra high's 40: under SPEED_GAIN, so F2 keeps astra. slow = edited_profiles(tmp_path, {("GPT-9 Sol", "high"): {"speed": 45}}) - assert pair(route(offered, "J1F2R1C1K0P2V2S0", profiles=slow)) == ("astra", "high") + assert pair(route(offered, "J1F2R2C1K2P2V1S1", profiles=slow)) == ("astra", "high") def test_route_limits(offered): # One step below terra high: luna max is beaten by terra low, terra medium is low gain. down = route(offered, "J1F1R0C0K0P0V0S0", "--down", "1") assert pair(down) == ("terra", "low") and "--down 1" in down["why"] - top_build = "J1F1R1C1K0P2V2S1" - assert route(offered, top_build)["premium"] + top_build = "J1F1R1C1K2P2V2S1" # K2: top+ + assert route(offered, top_build)["premium"] and route(offered, top_build)["tier"] == "top+" over = route(offered, top_build, "--premium-spent", "10") assert pair(over) == ("sol", "high") and not over["premium"] and "budget" in over["why"] + # a review runs on top, or on top+ when its scores are a top+ stage's; premium spend never limits it review = route(offered, "J1F1R0C0K0P0V0S0", "--review", "--premium-spent", "10") - assert (pair(review), review["tier"], review["premium"], review["cap_usd"]) == ( - ("astra", "high"), "top", True, 10.0) - # a review ignores the stage's scores: no caps or preferences shape it - assert pair(route(offered, "J0F2R2C0K2P0V0S2", "--review")) == ("astra", "high") + assert (pair(review), review["tier"]) == (("sol", "medium"), "top") + hard = route(offered, top_build, "--review", "--premium-spent", "10") + assert (pair(hard), hard["tier"], hard["premium"], hard["cap_usd"]) == (("astra", "high"), "top+", True, 10.0) + # no caps or preferences shape a review: S2 and F2 do not move it, K2 below top does not make it top+ + assert pair(route(offered, "J0F2R2C0K2P0V0S2", "--review")) == ("sol", "medium") assert run("route", offered, "--scores", "J1F1R0C0K0P0V0S0", "--profiles", PROFILES, "--down", "-1").returncode == 2 From 1036b4495902a328ff69508a45771bca73918d79 Mon Sep 17 00:00:00 2001 From: Bryan <28662377+bryanwieg@users.noreply.github.com> Date: Tue, 24 Nov 2026 14:39:28 +0000 Subject: [PATCH 2/4] Live feed of each model call on the driver's stderr The driver follows each call's stream.jsonl and prints its thinking summaries, messages, tool calls, failed tool results and result, tagged with the call. claude-build.sh turns on showThinkingSummaries so thinking arrives as text rather than empty signed blocks. The session runs the driver as a background shell so the user can watch it. Co-Authored-By: Claude Opus 5.5 --- .../.claude-plugin/plugin.json | 2 +- .../phased-delivery/scripts/claude-build.sh | 9 +-- plugins/phased-delivery/scripts/run-phase.py | 60 +++++++++++++++++++ .../skills/implement-in-phases/SKILL.md | 6 +- .../skills/implement-in-phases/build-guide.md | 5 +- plugins/phased-delivery/tests/fake-claude.sh | 6 +- .../tests/test_claude_build.py | 2 +- .../phased-delivery/tests/test_run_phase.py | 3 + 8 files changed, 84 insertions(+), 9 deletions(-) diff --git a/plugins/phased-delivery/.claude-plugin/plugin.json b/plugins/phased-delivery/.claude-plugin/plugin.json index 4657db7..e5109b2 100644 --- a/plugins/phased-delivery/.claude-plugin/plugin.json +++ b/plugins/phased-delivery/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "phased-delivery", - "version": "0.14.0", + "version": "0.15.0", "description": "Plan work as self-contained phases, then implement it phase by phase.", "author": { "name": "Bryan" diff --git a/plugins/phased-delivery/scripts/claude-build.sh b/plugins/phased-delivery/scripts/claude-build.sh index 7defbed..9e04b95 100755 --- a/plugins/phased-delivery/scripts/claude-build.sh +++ b/plugins/phased-delivery/scripts/claude-build.sh @@ -4,8 +4,9 @@ # # PROMPT is a file holding stage-builder.md and its inputs, kept outside # REPO; its text is passed as the prompt. Claude works in REPO with the -# phased-delivery plugin off. OUTDIR receives report.md (the final -# message), stream.jsonl and stderr.txt. +# phased-delivery plugin off and thinking summaries on. OUTDIR receives +# report.md (the final message), stream.jsonl (written as the call runs) +# and stderr.txt. # # CLAUDE_BUILD_PERMISSIONS sets the permission mode (default acceptEdits: # file edits work and commands follow the project's allow rules). A session @@ -22,7 +23,7 @@ # seconds without output); 8 the budget was reached; other non-zero: the # claude exit status. Never commits; the orchestrator does. set -u -[ $# -eq 6 ] || { sed -n '2,23p' "$0" >&2; exit 2; } +[ $# -eq 6 ] || { sed -n '2,24p' "$0" >&2; exit 2; } REPO=$1; PROMPT=$2; MODEL=$3; EFFORT=$4; BUDGET=$5; OUT=$6 MODE=${CLAUDE_BUILD_PERMISSIONS:-acceptEdits} case "$MODE" in @@ -37,7 +38,7 @@ mkdir -p "$OUT" TEXT=$(cat "$PROMPT") || exit 2 (cd "$REPO" && exec claude -p "$TEXT" --model "$MODEL" --effort "$EFFORT" \ --max-budget-usd "$BUDGET" \ - --settings '{"enabledPlugins":{"phased-delivery@ai-coding-plugins":false}}' \ + --settings '{"enabledPlugins":{"phased-delivery@ai-coding-plugins":false},"showThinkingSummaries":true}' \ --permission-mode "$MODE" --no-session-persistence \ --output-format stream-json --verbose) \ < /dev/null > "$OUT/stream.jsonl" 2> "$OUT/stderr.txt" & diff --git a/plugins/phased-delivery/scripts/run-phase.py b/plugins/phased-delivery/scripts/run-phase.py index 1d4438e..2f6f6be 100755 --- a/plugins/phased-delivery/scripts/run-phase.py +++ b/plugins/phased-delivery/scripts/run-phase.py @@ -27,6 +27,8 @@ import subprocess import sys import tempfile +import threading +import time from types import SimpleNamespace HERE = os.path.dirname(os.path.abspath(__file__)) @@ -106,6 +108,57 @@ def py(script, *args): return sh(sys.executable, os.path.join(HERE, script), *args) +def feed(label, event): + """The live lines for one stream event: thinking, text, tool calls, failed tool results, the result.""" + def short(text, n=300): + text = " ".join(str(text).split()) + return text if len(text) <= n else text[:n] + "…" + kind, msg = event.get("type"), event.get("message") or {} + blocks = msg.get("content") if isinstance(msg.get("content"), list) else [] + lines = [] + for b in blocks: + if not isinstance(b, dict): + continue + if kind == "assistant" and b.get("type") == "thinking" and b.get("thinking"): + lines.append(f"thinking: {short(b['thinking'])}") + elif kind == "assistant" and b.get("type") == "text" and b.get("text", "").strip(): + lines.append(f"says: {short(b['text'])}") + elif kind == "assistant" and b.get("type") == "tool_use": + args = b.get("input") or {} + what = next((args[k] for k in ("command", "file_path", "pattern", "description", "prompt") if k in args), "") + lines.append(f"{b.get('name')}: {short(what, 160)}") + elif kind == "user" and b.get("type") == "tool_result" and b.get("is_error"): + lines.append(f"tool error: {short(b.get('content'), 160)}") + if kind == "result": + cost = event.get("total_cost_usd") + lines.append(f"result: {event.get('subtype')}" + (f", ${cost:.2f}" if isinstance(cost, (int, float)) else "")) + return [f"[{label}] {x}" for x in lines] + + +def follow(label, path, done): + """Print the call's stream to stderr as it is written, until done is set and the file is read to its end.""" + while not os.path.exists(path): + if done.wait(0.5) and not os.path.exists(path): + return + with open(path, "rb") as f: + pending = b"" + while True: + chunk = f.read() + if not chunk: + if done.is_set(): + return + time.sleep(0.5) + continue + *lines, pending = (pending + chunk).split(b"\n") + for line in lines: + try: + event = json.loads(line) + except ValueError: + continue + for x in feed(label, event) if isinstance(event, dict) else []: + print(x, file=sys.stderr, flush=True) + + def last(text): lines = [x for x in text.splitlines() if x.strip()] return lines[-1].strip() if lines else "" @@ -183,8 +236,15 @@ def call(c, label, guide, inputs, pair, keep_briefs): before = plan_docs(c.plan_dir) present = plan_files(c.plan_dir) for _ in range(2): # a stalled call is undone and run once more + print(f"[{label}] {pair['model']} {pair['effort']}, cap ${pair['cap_usd']}; stream: {out}/stream.jsonl", + file=sys.stderr, flush=True) + done = threading.Event() + watcher = threading.Thread(target=follow, args=(label, os.path.join(out, "stream.jsonl"), done), daemon=True) + watcher.start() r = sh("sh", os.path.join(HERE, "claude-build.sh"), c.top, prompt, pair["model"], pair["effort"], pair["cap_usd"], out) + done.set() + watcher.join() if r.returncode != 7: break for p, doc in before.items(): diff --git a/plugins/phased-delivery/skills/implement-in-phases/SKILL.md b/plugins/phased-delivery/skills/implement-in-phases/SKILL.md index a7f6e62..f6ef626 100644 --- a/plugins/phased-delivery/skills/implement-in-phases/SKILL.md +++ b/plugins/phased-delivery/skills/implement-in-phases/SKILL.md @@ -51,7 +51,11 @@ works this way is in Pass each project instruction file (CLAUDE.md, AGENTS.md) with `--instructions`, and the project's required commit subject annotation and trailers with the other two options. It prints a report and exits 0 - (built), 10 (halted) or 2 (bad usage: fix the command). + (built), 10 (halted) or 2 (bad usage: fix the command). Run it as a + background shell: a phase outlasts a foreground command's time limit, + and the user watches the live feed on its stderr (each call's thinking, + messages and tool calls) in the tool's view of that shell. Do not read + the feed into your own context; wait for the exit and read the report. 2. **On exit 10, answer the halt.** Read `record.halt` in the phase's `phase.json` (the report prints it too): `step`, `stage`, `reason`, `detail` and `next`. Do what `next` says, as the table below expands it, diff --git a/plugins/phased-delivery/skills/implement-in-phases/build-guide.md b/plugins/phased-delivery/skills/implement-in-phases/build-guide.md index cd5848d..015e1d1 100644 --- a/plugins/phased-delivery/skills/implement-in-phases/build-guide.md +++ b/plugins/phased-delivery/skills/implement-in-phases/build-guide.md @@ -16,7 +16,10 @@ in `record.halt` of the phase's `phase.json`. Exit 2: bad usage. Each run prints a report: every stage and its status, the review findings and their outcome, the halt, that Codex is off and, for a built phase, `stage-stats.sh`'s table. `--work` keeps each call's prompt, output and -`report.md` in a numbered folder (a temporary directory otherwise). +`report.md` in a numbered folder (a temporary directory otherwise). While a +call runs, the driver prints its feed to stderr, each line tagged with the +call (`[build-01.2]`): its thinking summaries, messages, tool calls, failed +tool results and result. ## The parts diff --git a/plugins/phased-delivery/tests/fake-claude.sh b/plugins/phased-delivery/tests/fake-claude.sh index f427507..5deca3f 100644 --- a/plugins/phased-delivery/tests/fake-claude.sh +++ b/plugins/phased-delivery/tests/fake-claude.sh @@ -12,7 +12,8 @@ # "exit": N, the exit status (default 0) # "cost": USD} total_cost_usd (default 0.01) # Paths are relative to the directory claude runs in, the repository. It -# prints the result event claude-build.sh parses. A call past the last step +# prints one assistant event (a thinking summary and a tool call, for the +# driver's live feed) and the result event claude-build.sh parses. A call past the last step # exits 1 with a message on stderr and nothing printed. exec python3 - "$@" <<'PY' import json, os, sys, time @@ -38,6 +39,9 @@ for path, fields in step.get("brief", {}).items(): time.sleep(step.get("sleep", 0)) usage = {"input_tokens": 100, "output_tokens": 5, "cache_read_input_tokens": 1000, "cache_creation_input_tokens": 20} +print(json.dumps({"type": "assistant", "message": {"content": [ + {"type": "thinking", "thinking": "fake thinking"}, + {"type": "tool_use", "name": "Bash", "input": {"command": "true"}}]}})) print(json.dumps({"type": "result", "subtype": "success", "result": step.get("report", ""), "usage": usage, "total_cost_usd": step.get("cost", 0.01)})) sys.exit(step.get("exit", 0)) diff --git a/plugins/phased-delivery/tests/test_claude_build.py b/plugins/phased-delivery/tests/test_claude_build.py index afda5df..7adc356 100644 --- a/plugins/phased-delivery/tests/test_claude_build.py +++ b/plugins/phased-delivery/tests/test_claude_build.py @@ -61,7 +61,7 @@ def test_outcomes(tmp_path, events, status, code, message): assert args[:2] == ["-p", "Build stage 03.1."] for flag, value in [("--model", "opus"), ("--effort", "high"), ("--max-budget-usd", "2.5"), ("--permission-mode", "acceptEdits"), ("--output-format", "stream-json"), - ("--settings", '{"enabledPlugins":{"phased-delivery@ai-coding-plugins":false}}')]: + ("--settings", '{"enabledPlugins":{"phased-delivery@ai-coding-plugins":false},"showThinkingSummaries":true}')]: assert args[args.index(flag) + 1] == value assert "--no-session-persistence" in args if events and events[-1] is BUILT: diff --git a/plugins/phased-delivery/tests/test_run_phase.py b/plugins/phased-delivery/tests/test_run_phase.py index dbf37c3..063e4b9 100644 --- a/plugins/phased-delivery/tests/test_run_phase.py +++ b/plugins/phased-delivery/tests/test_run_phase.py @@ -136,6 +136,9 @@ def test_builds_phase(repo): assert any(s.startswith("01.2 Write two") for s in subjects(repo)) assert git(repo, "status", "--porcelain") == "" assert "Codex: off (driver version 1)" in result.stdout + # the live feed of each call, on stderr + for line in ("[revise] thinking: fake thinking", "[build-01.1] Bash: true", "result: success, $0.01"): + assert line in result.stderr, result.stderr def test_rerun_of_built_phase(repo): From 31f4e56b781babf7dd9679a93628e3b73d1fd3dd Mon Sep 17 00:00:00 2001 From: Bryan <28662377+bryanwieg@users.noreply.github.com> Date: Tue, 24 Nov 2026 14:53:08 +0000 Subject: [PATCH 3/4] Ask for thinking summaries with --thinking-display showThinkingSummaries is ignored in headless stream-json runs: thinking blocks still arrived empty. The hidden --thinking-display summarized flag applies there; checked with one Haiku call. Co-Authored-By: Claude Opus 5.5 --- plugins/phased-delivery/scripts/claude-build.sh | 12 +++++++----- plugins/phased-delivery/tests/test_claude_build.py | 3 ++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/phased-delivery/scripts/claude-build.sh b/plugins/phased-delivery/scripts/claude-build.sh index 9e04b95..d96eb22 100755 --- a/plugins/phased-delivery/scripts/claude-build.sh +++ b/plugins/phased-delivery/scripts/claude-build.sh @@ -4,9 +4,10 @@ # # PROMPT is a file holding stage-builder.md and its inputs, kept outside # REPO; its text is passed as the prompt. Claude works in REPO with the -# phased-delivery plugin off and thinking summaries on. OUTDIR receives -# report.md (the final message), stream.jsonl (written as the call runs) -# and stderr.txt. +# phased-delivery plugin off and thinking summarized in the stream (the +# hidden --thinking-display flag; headless runs otherwise leave it empty). +# OUTDIR receives report.md (the final message), stream.jsonl (written as +# the call runs) and stderr.txt. # # CLAUDE_BUILD_PERMISSIONS sets the permission mode (default acceptEdits: # file edits work and commands follow the project's allow rules). A session @@ -23,7 +24,7 @@ # seconds without output); 8 the budget was reached; other non-zero: the # claude exit status. Never commits; the orchestrator does. set -u -[ $# -eq 6 ] || { sed -n '2,24p' "$0" >&2; exit 2; } +[ $# -eq 6 ] || { sed -n '2,25p' "$0" >&2; exit 2; } REPO=$1; PROMPT=$2; MODEL=$3; EFFORT=$4; BUDGET=$5; OUT=$6 MODE=${CLAUDE_BUILD_PERMISSIONS:-acceptEdits} case "$MODE" in @@ -38,7 +39,8 @@ mkdir -p "$OUT" TEXT=$(cat "$PROMPT") || exit 2 (cd "$REPO" && exec claude -p "$TEXT" --model "$MODEL" --effort "$EFFORT" \ --max-budget-usd "$BUDGET" \ - --settings '{"enabledPlugins":{"phased-delivery@ai-coding-plugins":false},"showThinkingSummaries":true}' \ + --settings '{"enabledPlugins":{"phased-delivery@ai-coding-plugins":false}}' \ + --thinking-display summarized \ --permission-mode "$MODE" --no-session-persistence \ --output-format stream-json --verbose) \ < /dev/null > "$OUT/stream.jsonl" 2> "$OUT/stderr.txt" & diff --git a/plugins/phased-delivery/tests/test_claude_build.py b/plugins/phased-delivery/tests/test_claude_build.py index 7adc356..711e7f3 100644 --- a/plugins/phased-delivery/tests/test_claude_build.py +++ b/plugins/phased-delivery/tests/test_claude_build.py @@ -61,7 +61,8 @@ def test_outcomes(tmp_path, events, status, code, message): assert args[:2] == ["-p", "Build stage 03.1."] for flag, value in [("--model", "opus"), ("--effort", "high"), ("--max-budget-usd", "2.5"), ("--permission-mode", "acceptEdits"), ("--output-format", "stream-json"), - ("--settings", '{"enabledPlugins":{"phased-delivery@ai-coding-plugins":false},"showThinkingSummaries":true}')]: + ("--settings", '{"enabledPlugins":{"phased-delivery@ai-coding-plugins":false}}'), + ("--thinking-display", "summarized")]: assert args[args.index(flag) + 1] == value assert "--no-session-persistence" in args if events and events[-1] is BUILT: From 0eaa78c47a8b684264625102f9b664547acf552c Mon Sep 17 00:00:00 2001 From: Bryan <28662377+bryanwieg@users.noreply.github.com> Date: Tue, 24 Nov 2026 15:02:24 +0000 Subject: [PATCH 4/4] Leave a plan directory git ignores uncommitted A plan kept out of the repository (in an ignored folder) is built the same way; finish skips the plan commit instead of halting on git add. Co-Authored-By: Claude Opus 5.5 --- plugins/phased-delivery/.claude-plugin/plugin.json | 2 +- plugins/phased-delivery/scripts/build-check.py | 3 +++ .../skills/implement-in-phases/SKILL.md | 4 ++-- .../skills/implement-in-phases/build-guide.md | 4 +++- plugins/phased-delivery/tests/test_run_phase.py | 14 ++++++++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/plugins/phased-delivery/.claude-plugin/plugin.json b/plugins/phased-delivery/.claude-plugin/plugin.json index e5109b2..3349403 100644 --- a/plugins/phased-delivery/.claude-plugin/plugin.json +++ b/plugins/phased-delivery/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "phased-delivery", - "version": "0.15.0", + "version": "0.15.1", "description": "Plan work as self-contained phases, then implement it phase by phase.", "author": { "name": "Bryan" diff --git a/plugins/phased-delivery/scripts/build-check.py b/plugins/phased-delivery/scripts/build-check.py index 497f2eb..f58d488 100755 --- a/plugins/phased-delivery/scripts/build-check.py +++ b/plugins/phased-delivery/scripts/build-check.py @@ -398,6 +398,9 @@ def cmd_finish(a): last = next(h for h in log if any(c.startswith(h) or h.startswith(c) for c in ours)) save(os.path.join(pdir, "phase.json"), with_record(pj, built=last)) plan_check.render_plan(plan_dir) + if subprocess.run(["git", "-C", top, "check-ignore", "-q", rel(top, plan_dir)]).returncode == 0: + print("not committed: git ignores the plan directory") # a plan kept out of the repository + return 0 subject = f"Phase {os.path.basename(pdir)[:2]} {'stopped' if a.stopped else 'built'}: status and notes" print(git_commit(top, [rel(top, plan_dir)], subject, [f"Phase: {rel(top, pdir)}"] + a.extra_trailer)) return 0 diff --git a/plugins/phased-delivery/skills/implement-in-phases/SKILL.md b/plugins/phased-delivery/skills/implement-in-phases/SKILL.md index f6ef626..89b1572 100644 --- a/plugins/phased-delivery/skills/implement-in-phases/SKILL.md +++ b/plugins/phased-delivery/skills/implement-in-phases/SKILL.md @@ -128,8 +128,8 @@ Continue to the next phase only when the user says so; a user stop wins. ## Report the models' work After the last phase is committed, write `work-report.md` in the plan -directory, commit it with the trailer `Phase: `, and give -the user its tables and Reading. +directory, commit it with the trailer `Phase: ` (unless git +ignores the plan directory), and give the user its tables and Reading. 1. Generate it, never by hand: `sh scripts/stage-stats.sh ..HEAD`. Per model and effort it gives stages, first-try and clean counts, failed diff --git a/plugins/phased-delivery/skills/implement-in-phases/build-guide.md b/plugins/phased-delivery/skills/implement-in-phases/build-guide.md index 015e1d1..a4cb7c0 100644 --- a/plugins/phased-delivery/skills/implement-in-phases/build-guide.md +++ b/plugins/phased-delivery/skills/implement-in-phases/build-guide.md @@ -143,7 +143,9 @@ Each finding's status is kept in `record.findings` of `phase.json`: `build-check.py finish` checks `review.json` and that every stage has a commit and none is reopened, records the built commit, re-renders `phase.md` and `plan.md` and commits the plan directory with a `Phase:` -trailer and each `--extra-trailer`. Its refusal halts `build-error`. +trailer and each `--extra-trailer`; a plan directory git ignores (a plan +kept out of the repository) is left uncommitted. Its refusal halts +`build-error`. ## Premium spend diff --git a/plugins/phased-delivery/tests/test_run_phase.py b/plugins/phased-delivery/tests/test_run_phase.py index 063e4b9..708d82e 100644 --- a/plugins/phased-delivery/tests/test_run_phase.py +++ b/plugins/phased-delivery/tests/test_run_phase.py @@ -141,6 +141,20 @@ def test_builds_phase(repo): assert line in result.stderr, result.stderr +def test_plan_ignored_by_git(repo): + # a plan kept out of the repository: stages are committed, the plan directory never is + (repo / ".gitignore").write_text(PLAN_DIR + "/\n") + git(repo, "rm", "-r", "-q", "--cached", PLAN_DIR) + git(repo, "add", ".gitignore") + git(repo, "commit", "-q", "-m", "ignore the plan") + result = drive(repo, [REVISED_NOTHING, BUILD_ONE, BUILD_TWO, REVIEW]) + assert result.returncode == 0, result.stdout + result.stderr + assert "Status: built" in (repo / PHASE / "phase.md").read_text() + assert [s[:4] for s in subjects(repo)[:2]] == ["01.2", "01.1"] + assert git(repo, "ls-files", PLAN_DIR) == "" + assert git(repo, "status", "--porcelain") == "" + + def test_rerun_of_built_phase(repo): drive(repo, [REVISED_NOTHING, BUILD_ONE, BUILD_TWO, REVIEW]) head = git(repo, "rev-parse", "HEAD")