Skip to content

feat(loop-context): resolve token budget from loop-cost's pattern estimate#258

Merged
cobusgreyling merged 1 commit into
cobusgreyling:mainfrom
KhaiTrang1995:feat/loop-context-budget-from-pattern
Jul 13, 2026
Merged

feat(loop-context): resolve token budget from loop-cost's pattern estimate#258
cobusgreyling merged 1 commit into
cobusgreyling:mainfrom
KhaiTrang1995:feat/loop-context-budget-from-pattern

Conversation

@KhaiTrang1995

Copy link
Copy Markdown
Contributor

Summary

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.

What

Add --budget-from-pattern <id> to loop-context's CLI, plus --budget-level,
--budget-scenario, --budget-cadence, and --budget-conservative to shape
the lookup. 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 message, not 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 (BUDGET=$(... | node -e '...')) -- that hack is no longer needed
now that the flag does it directly.

Why this shape

  • Mirrors the existing cross-tool integration pattern in this monorepo
    (subprocess to a built CLI, not a shared library import) rather than
    introducing a new dependency style.
  • loop-cost has no dependency on loop-context, so no circular dependency.

Tested

tools/loop-context: 31/31 passing after a fully clean rebuild (wiped
node_modules/dist in both loop-context and loop-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-budget overriding, unknown
pattern surfacing loop-cost's error). All pre-existing tests pass unmodified.
Version 1.0.0 -> 1.1.0

…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>
@cobusgreyling

Copy link
Copy Markdown
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.

cobusgreyling added a commit that referenced this pull request Jul 13, 2026
…266)

- Land Amazon Q Developer CLI appendix (rebased from #250; fix official doc link)
- Log Jul 13 maintenance: merged contributor doc PRs, closed invalid/duplicate PRs
- Link watch-list items to open feature PRs #256/#258

Co-authored-by: Cobus Greyling <cobusgreyling@Cobuss-MacBook-Pro-2.local>
@cobusgreyling
cobusgreyling merged commit f12bd92 into cobusgreyling:main Jul 13, 2026
2 checks passed
@cobusgreyling

Copy link
Copy Markdown
Owner

Merged on top of #256 — thanks @KhaiTrang1995! --budget-from-pattern wiring looks solid; 31/31 tests green after rebase. Published as loop-context v1.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants