feat(loop-init): wire loop-context circuit breaker into scaffolding + ci-sweeper#140
Merged
cobusgreyling merged 10 commits intoJul 4, 2026
Conversation
MCP server exposes loop-engineering patterns, skills, state, budget,
and safety docs as queryable resources via Model Context Protocol.
Agents can query what they need on-demand instead of prompt stuffing.
Resources: registry, config, budget, run-log, safety, patterns/{id},
skills/{name}, state/{file}
Tools: list_patterns, list_skills, list_state_files, get_pattern,
get_skill, get_state, recommend_pattern, estimate_cost
Includes 16 tests, CI gate integration, and MCP config example.
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
feat(mcp-server): add MCP server for runtime resource lookup
…ation tests zod was imported in src/index.ts but only resolved transitively via @modelcontextprotocol/sdk, so the build could break if the SDK changed its zod range. Declare it explicitly in dependencies. Add 4 integration tests that spawn the real server over stdio and exercise the index.ts tool/resource handlers (tools/list, loop_list_patterns, loop_estimate_cost, pattern resource read), complementing the existing resolver-level unit tests. Suite now 20/20 passing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
fix(mcp-server): declare zod as direct dependency + add server ation tests
# Conflicts: # package.json # scripts/ci-validate-gates.sh # tools/mcp-server/README.md # tools/mcp-server/dist/resolver.d.ts # tools/mcp-server/dist/resolver.js # tools/mcp-server/src/resolver.ts # tools/mcp-server/test/server.test.mjs
…aker Adds tools/loop-context — a deterministic, dependency-free manager that sits between an agent loop and its durable memory to prevent the two classic long-run failures: context overflow/rot and stagnant/no-progress loops. Before each iteration it can: - summarize what has been tried (factual rollup, no LLM needed), - prune verbose stack traces, collapse repeated errors, and keep only a recent window of attempts, - inject a compact context block into the next prompt. The circuit breaker escalates to a human on stagnation (same error N× in a row), no-progress (N consecutive failures), token budget, or iteration cap — instead of burning tokens in a hopeless loop. Errors are normalized to a stable signature so "the same error" is recognized across volatile details (line numbers, ports, addresses, temp paths). Ships a CLI (--check/--prune/--inject/--summary/--status, stdin or --ledger) with escalate=exit 2, a library API, 18 tests, and CI gate + build wiring. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feat(loop-context): stateful memory manager with pruner + circuit breaker
# Conflicts: # tools/loop-context/README.md # tools/loop-context/package.json
loop-context (the stateful memory manager / circuit breaker) shipped in cobusgreyling#129, but nothing wired it into a real loop yet. This makes the breaker part of the scaffold so new projects get it by default. - New loop-guard skill template: log each attempt to loop-ledger.json and run `loop-context --check` before retrying; on exit 2, inject a pruned summary and escalate instead of looping. - loop-init now scaffolds the loop-guard skill + a goal-seeded loop-ledger.json for fix-capable patterns (pr-babysitter, ci-sweeper, dependency-sweeper, post-merge-cleanup). Report-only patterns skip it. - Wire the breaker into the ci-sweeper pattern doc and the loop-constraints template, turning the soft "max 3 attempts" rule into a mechanical gate. - Tests: guard + ledger scaffolded for fix patterns (grok and opencode paths) and NOT for report-only daily-triage. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Building on the
loop-contexttool landed in #129, this makes the circuitbreaker something new projects get by default instead of a tool nobody
wires up.
loop-initnow scaffolds aloop-guardskill and a seededloop-ledger.jsonfor fix-capable patterns, and theci-sweeperpattern docshows where the breaker sits in the loop.
Why
loop-contextgives us deterministic stagnation / no-progress / token-budgetdetection, but until a loop actually maintains a ledger and calls it, an L2/L3
run can still retry the same failing fix forever — the exact context-rot and
cost-blowup failure the tool was built to stop. The missing piece was
adoption, not more logic.
What changed
loop-guardskill template (templates/SKILL.md.loop-guard):log each attempt to
loop-ledger.json, runloop-context --checkbeforeretrying, and on exit
2inject a pruned summary and escalate to a human.loop-initscaffolding: fix-capable patterns (pr-babysitter,ci-sweeper,dependency-sweeper,post-merge-cleanup) now also get theloop-guardskill + a goal-seededloop-ledger.json. Report-only patterns(
daily-triage,issue-triage,changelog-drafter) skip it to keep thescaffold minimal.
ci-sweeperpattern doc:loop-guardadded to Required Skills and to theretry step of the run cycle.
loop-constraintstemplate: the soft "max 3 fix attempts" rule now pointsat the mechanical
loop-context --checkgate.How it works
append attempt → loop-context --check
├─ exit 0 → continue (optionally --inject a pruned context block)
└─ exit 2 → STOP: --inject > escalation.md, write STATE.md, hand to human
Triggers: same error N× in a row (default 3), too many consecutive failures
(default 5), token budget, or iteration cap (default 10).
Testing
loop-init: 12/12 tests pass, incl. 3 new ones — breaker scaffolded for fixpatterns (grok + opencode paths) and not for report-only
daily-triage.loop-context: 18/18 tests pass;tsc --noEmitclean; committeddist/matches a fresh build (zero-install
npxstays honest).ci-sweeperseeds a valid ledger; an emptyledger returns
CONTINUE(exit 0); a ledger with the same error 3× returnsESCALATE [stagnation](exit 2).structure checks all pass. Loop readiness score unchanged (100 / L3).
Scope / non-goals
Deliberately does not touch
loop-auditscoring — rewarding a configuredbreaker is opinionated (it shifts everyone's score) and better discussed
separately. This PR is purely adoption + docs.