feat(B): superseded-context detector + ts_stale_context (agent-agnostic) - #111
Merged
Conversation
Pure function over transcript Events (any harness): flags tool results made obsolete later in the same session — a file read then re-read, a file read then edited, a Bash command re-run. Names the stale + fresh event so a caller can drop the stale content or point to the fresh copy. Delivery (follow-up): a callable MCP tool (works on every agent) + a Claude Code PreCompact hook. This module stays pure/harness-free by design. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Exposes find_superseded as an agent-agnostic MCP tool: scans the recent session transcript(s), lists tool results made obsolete later in the same session (reread / read-then-edit / rerun), and returns the stale refs so the agent can drop that content or refetch the fresh copy. Works on any MCP client — this is B's cross-agent path (the PreCompact hook is a Claude-only bonus, still to wire). META handler, read-only, PII-safe. Tool count 69 -> 70. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The all-tools coverage guard requires every TOOL_SCHEMAS entry to appear in
ARGUMENTS_REALISTES. Add ts_stale_context ({} — all params optional).
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.
Feature B, cross-agent core. Reclaims context wasted on tool results that a later action made obsolete.
Detector (
discover/superseded.py::find_superseded) — a pure function over the transcript Events any harness produces. Flags, per session: a file read then re-read, a file read then edited (the read is stale), a Bash command re-run. Names the stale + fresh event so a caller can drop the stale content or point to the fresh copy. Deterministic, no model.Universal delivery (
ts_stale_contextMCP tool) — scans the recent session transcript(s), runs the detector, returns the stale refs as a table or JSON. Works on any MCP client, not just Claude Code — this is the cross-agent path. The Claude-only PreCompact hook (which can actually prune at compaction) is a follow-up bonus; everywhere else the tool is advisory, because an MCP server cannot delete context it does not own.Design note: the durable cross-agent prevention is the pointer-returning tools (get_full_context intent, capture relevant: — already merged in #110). This B tool cleans up what slipped through.
Tests: detector (reread / read-then-edit / rerun / mcp-prefix / cross-session isolation / determinism) + tool formatting + handler smoke over real transcripts. ruff clean, tool count 69->70, protocol end-to-end green.