Skip to content

refactor(agent): inline turn-loop helpers; fix compact test cap regression - #228

Merged
zjshen14 merged 1 commit into
mainfrom
refactor/inline-agent-turn-loop
Jun 6, 2026
Merged

refactor(agent): inline turn-loop helpers; fix compact test cap regression#228
zjshen14 merged 1 commit into
mainfrom
refactor/inline-agent-turn-loop

Conversation

@zjshen14

@zjshen14 zjshen14 commented Jun 6, 2026

Copy link
Copy Markdown
Owner

What

Two things, both in the A5b context-management area:

  1. Inline the turn-loop helpersbuildTurnSetup, streamLLM, recordAssistantMessage, checkMaxTurnsGuard, checkStuckLoopGuard, executeTurnTools, drainSnapshotWarnings are folded back into the main run() generator (PR feat(A5b): auto-compact at turn boundary with safety gates #191 review follow-up). Behaviour unchanged; agent.test.ts drops the unit tests that targeted those now-gone private methods. Net −95 lines.

  2. Fix a compact.test.ts regression — the "quotes the original first user task" test had its cap lowered to 5 (below KEEP_RECENT=10), which left an empty compaction head so compaction never ran and the assertion failed. Restored to cap 25 / 50 messages so both pruning and compaction fire (as the original comment required).

Why a fresh branch

This supersedes fix/a5b-review-points, which had diverged (28 commits behind main, no open PR). This branch is the same refactor rebuilt cleanly on current main.

Checks

typecheck · lint · format:check · test (665 passed) all green locally and via pre-push.

🤖 Generated with Claude Code

…ssion

Inline the seven extracted private helpers (buildTurnSetup, streamLLM,
recordAssistantMessage, checkMaxTurnsGuard, checkStuckLoopGuard,
executeTurnTools, drainSnapshotWarnings) back into the main run() generator,
collapsing an over-decomposed loop into one readable flow (PR #191 review
follow-up). Behaviour is unchanged; agent.test.ts drops the now-obsolete
unit tests that targeted those private methods.

Also fix a self-inflicted regression in compact.test.ts: the "quotes the
original first user task" test had its cap lowered to 5 (< KEEP_RECENT=10),
which left an empty compaction head so compaction never ran and the
assertion failed. Restore the cap to 25 (>KEEP_RECENT) with 50 messages so
both pruning and compaction fire, as the original comment required.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@zjshen14
zjshen14 force-pushed the refactor/inline-agent-turn-loop branch from 0de5776 to 1a86802 Compare June 6, 2026 16:28
@zjshen14
zjshen14 merged commit a79ab83 into main Jun 6, 2026
3 checks passed
@zjshen14
zjshen14 deleted the refactor/inline-agent-turn-loop branch June 6, 2026 16:31
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.

1 participant