Skip to content

feat(loop-init): wire loop-context circuit breaker into scaffolding + ci-sweeper#140

Merged
cobusgreyling merged 10 commits into
cobusgreyling:mainfrom
KhaiTrang1995:feat/loop-context-integration
Jul 4, 2026
Merged

feat(loop-init): wire loop-context circuit breaker into scaffolding + ci-sweeper#140
cobusgreyling merged 10 commits into
cobusgreyling:mainfrom
KhaiTrang1995:feat/loop-context-integration

Conversation

@KhaiTrang1995

Copy link
Copy Markdown
Contributor

Summary

Building on the loop-context tool landed in #129, this makes the circuit
breaker something new projects get by default instead of a tool nobody
wires up. loop-init now scaffolds a loop-guard skill and a seeded
loop-ledger.json for fix-capable patterns, and the ci-sweeper pattern doc
shows where the breaker sits in the loop.

Why

loop-context gives us deterministic stagnation / no-progress / token-budget
detection, 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

  • New loop-guard skill template (templates/SKILL.md.loop-guard):
    log each attempt to loop-ledger.json, run loop-context --check before
    retrying, and on exit 2 inject a pruned summary and escalate to a human.
  • loop-init scaffolding: fix-capable patterns (pr-babysitter,
    ci-sweeper, dependency-sweeper, post-merge-cleanup) now also get the
    loop-guard skill + a goal-seeded loop-ledger.json. Report-only patterns
    (daily-triage, issue-triage, changelog-drafter) skip it to keep the
    scaffold minimal.
  • ci-sweeper pattern doc: loop-guard added to Required Skills and to the
    retry step of the run cycle.
  • loop-constraints template: the soft "max 3 fix attempts" rule now points
    at the mechanical loop-context --check gate.

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 fix
    patterns (grok + opencode paths) and not for report-only daily-triage.
  • loop-context: 18/18 tests pass; tsc --noEmit clean; committed dist/
    matches a fresh build (zero-install npx stays honest).
  • End-to-end smoke: scaffolding ci-sweeper seeds a valid ledger; an empty
    ledger returns CONTINUE (exit 0); a ledger with the same error 3× returns
    ESCALATE [stagnation] (exit 2).
  • Validate gates, registry schema/validity, loop-init sync, and pattern
    structure checks all pass. Loop readiness score unchanged (100 / L3).

Scope / non-goals

Deliberately does not touch loop-audit scoring — rewarding a configured
breaker is opinionated (it shifts everyone's score) and better discussed
separately. This PR is purely adoption + docs.

KhaiTrang1995 and others added 10 commits June 26, 2026 07:42
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>
@cobusgreyling cobusgreyling changed the title feat(loop-init): wire loop-context circuit breaker into scaffolding + ci-sweeperFeat/loop context integration feat(loop-init): wire loop-context circuit breaker into scaffolding + ci-sweeper Jul 4, 2026
@cobusgreyling cobusgreyling merged commit e4960d9 into cobusgreyling:main Jul 4, 2026
2 checks passed
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