feat(loop-context): resolve token budget from loop-cost's pattern estimate#258
Merged
cobusgreyling merged 1 commit intoJul 13, 2026
Conversation
…imate loop-context's circuit breaker only accepts --token-budget as a hand-typed number, and loop-budget.md's "On budget exceed" section admits the budget number itself is usually a guess. loop-cost already computes a realistic per-run token estimate for every pattern and readiness level from patterns/registry.yaml -- nothing connected the two. Add --budget-from-pattern <id> (with --budget-level, --budget-scenario, --budget-cadence, --budget-conservative) to loop-context's CLI. It shells out to loop-cost's built CLI -- the same monorepo-sibling-then-installed-dependency resolution loop-init already uses for loop-audit -- so the two packages stay independent at the source level. An explicit --token-budget always overrides the derived value; an unknown pattern id surfaces loop-cost's own error instead of a silent fallback. Also updates the loop-guard skill template and loop-cost's README, both of which previously worked around the missing wiring with a manual JSON-parsing shell pipe -- that hack is no longer needed. Tested: 31/31 in tools/loop-context (13 new: resolver unit tests + CLI integration tests covering scenario selection, explicit-override precedence, and unknown-pattern error surfacing). Existing --token-budget behavior is unchanged. Version 1.0.0 -> 1.1.0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Owner
|
Thanks @KhaiTrang1995 — CI is green. This PR depends on the loop-cost orchestration changes in #256; we'll review/merge #256 first, then rebase this branch onto main. No action needed from you until #256 lands. |
Owner
|
Merged on top of #256 — thanks @KhaiTrang1995! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
loop-context's circuit breaker only accepts--token-budgetas a hand-typednumber, and
loop-budget.md's "On budget exceed" section admits the budgetnumber itself is usually a guess.
loop-costalready computes a realisticper-run token estimate for every pattern and readiness level from
patterns/registry.yaml-- nothing connected the two.What
Add
--budget-from-pattern <id>toloop-context's CLI, plus--budget-level,--budget-scenario,--budget-cadence, and--budget-conservativeto shapethe lookup. It shells out to
loop-cost's built CLI -- the samemonorepo-sibling-then-installed-dependency resolution
loop-initalready usesfor
loop-audit-- so the two packages stay independent at the source level:--token-budgetalways overrides the derived value.loop-cost's own error message, not a silentfallback.
Also updates the
loop-guardskill template andloop-cost's README, both ofwhich previously worked around the missing wiring with a manual JSON-parsing
shell pipe (
BUDGET=$(... | node -e '...')) -- that hack is no longer needednow that the flag does it directly.
Why this shape
(subprocess to a built CLI, not a shared library import) rather than
introducing a new dependency style.
loop-costhas no dependency onloop-context, so no circular dependency.Tested
tools/loop-context: 31/31 passing after a fully clean rebuild (wipednode_modules/distin bothloop-contextandloop-cost, reinstalled,rebuilt). 13 new tests: resolver unit tests (scenario selection, unknown
pattern, invalid scenario rejected before spawning) and CLI integration tests
(budget resolved from pattern, explicit
--token-budgetoverriding, unknownpattern surfacing
loop-cost's error). All pre-existing tests pass unmodified.Version 1.0.0 -> 1.1.0