-
Notifications
You must be signed in to change notification settings - Fork 32
🤖 feat: post-compaction context preservation system #1035
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b0d98d0 to
eb3e135
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Just to clarify, this is closing in on parity with Claude Code? Not new magic?/ |
|
Correct |
34ad7e4 to
5972013
Compare
|
@codex review |
This comment has been minimized.
This comment has been minimized.
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
814a2d4 to
0c294b1
Compare
|
@codex review |
0c294b1 to
b8af4a0
Compare
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
b8af4a0 to
7b3af9f
Compare
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
ceb6da2 to
fda5d5b
Compare
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Implement a comprehensive system to preserve critical context after chat history compaction, ensuring continuity in long-running agent sessions. ## Post-Compaction Attachments Add attachment types and services to re-inject context after compaction: - Plan file references: preserve current plan path and content - Edited files references: preserve diffs of up to 10 recently edited files - Automatic injection on first turn after compaction, then every 5 turns - Content truncation at 50KB per file to manage token usage ## File Edit Tracking New `extractEditedFiles` utility scans message history for successful file edit tool calls, combining multiple diffs per file into unified before/after representations. Handles sequential edits, overlapping modifications, and graceful fallbacks when patch application fails. ## UI Enhancements - PostCompactionSection in CostsTab shows what will be re-injected - ProposePlanToolCall supports opening plans in external editors - Window focus listener refreshes plan content after external edits - Smart filename display with parent directory disambiguation ## Backend Services - AttachmentService generates plan and edited file attachments - AgentSession tracks file state for external edit detection - CompactionHandler caches file diffs before clearing history - Message queue management for multi-message interactions ## New API Endpoints - workspace.getPostCompactionState: fetch plan path and tracked files - workspace.executeBash: direct bash execution in workspace context - workspace.clearQueue: clear message queue - general.openInEditor: open files in external editor - general.canOpenInEditor: check editor availability ## Tool Changes - file_edit_insert/operation: record file state for tracking - Plan file awareness with dual runtime (local vs workspace)
Add ability to enable/disable individual post-compaction context items (plan file and tracked files) without deleting them. Disabled items remain visible in the UI but are excluded from attachments sent to the model. Changes: - Add PostCompactionExclusions type and setPostCompactionExclusion API - Store exclusions per-workspace in ~/.mux/sessions/<id>/exclusions.json - Add Eye/EyeOff toggle icons in PostCompactionSection UI - Show included/total count for file diffs - Excluded items display with 50% opacity and strikethrough text - Use proper Radix UI tooltips with high z-index (renders above chat) - Fix open-in-editor for paths with ~ (expand to absolute path)
Introduce a global experiments/feature flags system for gating
experimental features. Experiments are persisted in localStorage
and manageable via a new Settings > Experiments section.
The post-compaction context feature (plan file and edited file
diffs re-injected after compaction) is now disabled by default
and requires explicit opt-in through the experiments panel.
Changes:
- Add ExperimentsContext with useSyncExternalStore for efficient
reactive updates per-experiment
- Create reusable Switch component, refactor ProvidersSection
- Pass experiment state through SendMessageOptions to backend
- Gate PostCompactionSection rendering and attachment generation
- Add bulk toggle (eye icon) for file diffs in post-compaction UI
- Support legacy plan paths (~/.mux/plans/{id}.md) alongside new
project-organized paths for backwards compatibility
Eliminate separate API calls and polling for post-compaction context by bundling it with workspace metadata when the experiment is enabled. - Add includePostCompaction param to workspace.list API - Fetch post-compaction state in parallel during list() when requested - Refactor usePostCompactionState to read from bundled metadata - Refresh metadata when experiment toggle changes - Remove 5-second polling interval from usePostCompactionState
Increase switch dimensions from 20x36px to 24x44px for better touch targets. Update styling to use standard shadcn patterns including proper focus ring tokens, shadow on thumb, and consistent border handling.
Add three stories to cover the experiments settings UI: - Experiments: displays the experiments section - ExperimentsToggleOn: toggles an experiment switch on - ExperimentsToggleOff: toggles on then off to show both states
Wrap planPath with shellQuote() when executing rm -f to delete plan files. Without quoting, paths containing spaces or shell metacharacters could cause command failures or potential command injection.
Forward experiments configuration from session options to the underlying agent, enabling experiment flags to influence agent behavior at runtime.
Add onCompactionComplete callback to AgentSession that fires when context compaction finishes. WorkspaceService uses this to fetch and emit updated metadata including postCompaction state, allowing the frontend to reactively update without polling.
shellQuote uses single quotes which prevent shell tilde expansion. The previous comment incorrectly assumed the shell would expand ~, but single-quoted strings are treated literally. Now we explicitly expand the tilde before quoting to ensure the path resolves correctly on both local and remote runtimes.
Use useExperimentValue hook instead of isExperimentEnabled so the component re-renders when experiment state changes. Previously, toggling the post-compaction context experiment required a refresh to take effect.
The isExperimentEnabled function is no longer used in useSendMessageOptions after the experiment toggles refactor. Cleaning up the dead import.
c6c1ef4 to
3ffaf9e
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. 🎉 ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
Summary
extractEditedFilesutility to track and combine file edit diffsPostCompactionSectionUI to show what will be re-injectedTest plan
bun test src/common/utils/messages/extractEditedFiles.test.tsGenerated with
mux