Skip to content

feat(agent): add explicit context compression tool / 显式上下文压缩工具 - #8000

Merged
SivanCola merged 7 commits into
esengine:main-v2from
SivanCola:codex/explicit-compress-tool
Aug 8, 2026
Merged

feat(agent): add explicit context compression tool / 显式上下文压缩工具#8000
SivanCola merged 7 commits into
esengine:main-v2from
SivanCola:codex/explicit-compress-tool

Conversation

@SivanCola

@SivanCola SivanCola commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add a model-callable compress tool with exact unique user-message anchors and before / after range semantics
  • install all explicit range compaction into context projections without rewriting the canonical transcript
  • preserve checkpoint boundaries, rewind, undo, fork, and file recovery across compression
  • keep CLI, Desktop, Wails, and HTTP positional compression entrypoints compatible while routing them through the projection core
  • update UI copy and tool contract docs to clarify that visible history is retained

Implementation details

  • bind a context-scoped ContextCompressor to each tool execution so child agents operate only on their own session projection
  • serialize compress calls even though the tool is workspace-read-only and Plan Mode safe
  • merge prior compaction summaries, prefer native compaction with summarizer fallback, and reject empty, non-shrinking, or stale projections atomically
  • split range planning, hook/archive preparation, projection building, and atomic installation into focused stages
  • read schema-v1 sidecars and write schema-v2 sidecars with covered count/hash, prompt-cache lineage, and incremented projection versions
  • expose compress in default and Economy tool surfaces while respecting explicit tool allowlists
  • surface folded anchors and non-shrinking positional compression as visible warnings instead of silent success

Cache impact

The system prompt is unchanged. Adding the default tool schema changes the tool-prefix hash once after upgrade. Successful explicit compression reports one compact_tool prefix change; noop and failed attempts do not report a rewrite. Schema-v2 downgrade fallback may cause one cold canonical-prefix request while preventing an older client from misreading newer projection invariants.

Validation

  • go run ./tools/repolint
  • go test ./...
  • go test -race ./internal/agent ./internal/control
  • go vet ./...
  • cd desktop && go test ./...
  • cd desktop/frontend && pnpm typecheck
  • cd desktop/frontend && pnpm exec tsx src/__tests__/app-chrome-tabs.test.ts
  • cd desktop/frontend && pnpm exec tsx src/__tests__/message-reasoning-panel.test.tsx
  • git diff --check

Cache-impact: medium - adds one default tool schema after upgrade; successful compression deliberately replaces the model-visible history prefix, while schema-v2 downgrade fallback may cause one cold canonical-prefix request.
Cache-guard: go test ./internal/boot ./internal/agent ./internal/control - existing tool-prefix goldens, compact_tool rewrite assertions, and sidecar compatibility tests cover schema and prefix behavior.
System-prompt-review: system prompt bytes are unchanged; only the stable tool schema set and explicit projection prefix change.
Documentation-impact: updated - documented the compress tool and clarified projection-only context compression while retaining visible history.

@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) skills Skill system (internal/skill, internal/tool) agent Core agent loop (internal/agent, internal/control) config Configuration & setup (internal/config) labels Aug 8, 2026
Problem:
- V1 sidecars could carry new logical message invariants that previous readers misinterpreted.
- Positional compression adapters treated folded anchors and no-op folds as success.

Root cause:
- Strict-role coalescing moved to outbound requests without a persisted schema boundary.
- Compatibility adapters discarded structured no-op results.

Fix:
- Write schema-v2 projection sidecars while retaining V1 read support.
- Surface folded-boundary and no-savings outcomes through the controller notice path.
- Add focused compatibility and positional compression regressions.

Verification:
- go test ./...
- go test -race ./internal/agent ./internal/control
- go vet ./...
- cd desktop && go test ./...
- cd desktop/frontend && pnpm typecheck
Problem:
- The explicit compression implementation pushed range planning over the complexity and function-size limits.
- New positional and boot coverage extended already oversized test files.

Fix:
- Split range planning, preparation, projection building, and atomic installation into focused helpers.
- Reuse the common compaction telemetry constructor.
- Move positional compression and allowlist coverage into dedicated test files.
- Keep the context compressor binding and UI copy changes line-neutral in baselined files.

Verification:
- go run ./tools/repolint
- go test ./...
- go test -race ./internal/agent ./internal/control
- go vet ./...
- cd desktop && go test ./...
- cd desktop/frontend && pnpm typecheck
Use maps.Copy in the positional compression checkpoint regression so the PR passes the repository's modernize lint rules.

Verification:
- go test ./internal/control -run TestPositionalCompressionPreservesCheckpointLineage -count=1
- golangci-lint run --timeout=5m ./...
- go run ./tools/repolint
@SivanCola
SivanCola marked this pull request as ready for review August 8, 2026 20:42
@SivanCola
SivanCola requested a review from esengine as a code owner August 8, 2026 20:42
@SivanCola
SivanCola enabled auto-merge August 8, 2026 20:47
@SivanCola
SivanCola merged commit a41465e into esengine:main-v2 Aug 8, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Core agent loop (internal/agent, internal/control) config Configuration & setup (internal/config) desktop Wails desktop app (desktop/**) skills Skill system (internal/skill, internal/tool) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant