Skip to content

feat(context): keep the latest read of each file inline - #40

Merged
ayman3000 merged 1 commit into
mainfrom
feat/ctxmgr-keep-latest-read
Aug 5, 2026
Merged

feat(context): keep the latest read of each file inline#40
ayman3000 merged 1 commit into
mainfrom
feat/ctxmgr-keep-latest-read

Conversation

@ayman3000

Copy link
Copy Markdown
Owner

What

Stops the re-read loop on multi-file coding tasks. Once the agent reads a file, its most-recent read stays in live context instead of being externalized to an artifact — so the model doesn't re-read the same file to "confirm" (the behavior that burned 100+ tool calls / hit the turn cap).

How

  • ContextManager gains keepLatestReadsInline: Bool = true and readToolNames: Set<String> = ["read_file"] (a set so the generic manager isn't coupled to any tools product).
  • modelMessages(): builds callsByID before the eviction loop, precomputes the newest rest index per file path for keep-worthy reads (in readToolNames, not an error, maxActiveResultChars), and the oldest-first eviction loop skips externalizing the whole exchange that holds a latest-per-path read — keeping the whole exchange preserves tool_call/tool_result pairing (a provider requirement).
  • Bounded: only activates over inlineBudgetChars, each kept read is size-capped, and older kept reads still fall out via Conversation.trim() — can't grow unbounded.

Testing

✅ Full suite 160 green, incl. 5 new: latest read kept while older run_shell evicted; only newest read of a path kept; newest of each distinct path kept; a read > maxActiveResultChars still externalized (size guard); flag off restores old behavior.

Rollout

Consumed by Naseem via a dependency bump to 0.3.0-alpha.31 — no app code change (AgentFactory builds ContextManager() with defaults, feature on). Spec in the Naseem repo: docs/superpowers/specs/2026-08-05-ctxmgr-keep-latest-read-design.md.

🤖 Generated with Claude Code

Stops the re-read loop on multi-file tasks: once the agent has read a file, its
most-recent read stays in live context instead of being externalized to an
artifact, so the model doesn't re-read the same file to "confirm."

- ContextManager gains `keepLatestReadsInline` (default true) and
  `readToolNames` (default ["read_file"]).
- modelMessages() precomputes the newest `rest` index per file path for
  keep-worthy reads (in readToolNames, not error, ≤ maxActiveResultChars), and
  the oldest-first eviction loop skips externalizing the whole exchange that
  holds a latest-per-path read (preserving tool_call/result pairing).
- Bounded: only over inlineBudgetChars, size-capped per read, and older kept
  reads still fall out via Conversation.trim() — can't grow unbounded.

Tests (5): latest read kept while older shell evicted; only newest read of a
path kept; newest read of each distinct path kept; large read still
externalized (size guard); flag off restores old behavior. Full suite 160 green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@ayman3000
ayman3000 merged commit eea8d35 into main Aug 5, 2026
1 check passed
@ayman3000
ayman3000 deleted the feat/ctxmgr-keep-latest-read branch August 5, 2026 07:55
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