Skip to content

Conversation

@ThomasK33
Copy link
Member

Summary

  • Add post-compaction attachment system to preserve context after history compaction
  • Implement extractEditedFiles utility to track and combine file edit diffs
  • Add PostCompactionSection UI to show what will be re-injected
  • Support opening plans in external editors with auto-refresh on focus
  • New API endpoints for post-compaction state, bash execution, and editor integration

Test plan

  • Verify post-compaction attachments inject correctly after compaction
  • Test file edit tracking across multiple edits to same file
  • Confirm PostCompactionSection displays plan and edited files
  • Test external editor opening and content refresh on window focus
  • Run existing test suite: bun test src/common/utils/messages/extractEditedFiles.test.ts

Generated with mux

@ThomasK33 ThomasK33 force-pushed the post-compaction-context branch from b0d98d0 to eb3e135 Compare December 9, 2025 16:12
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@ammario
Copy link
Member

ammario commented Dec 9, 2025

Just to clarify, this is closing in on parity with Claude Code? Not new magic?/

Copy link
Member Author

Correct

@ThomasK33 ThomasK33 force-pushed the post-compaction-context branch 4 times, most recently from 34ad7e4 to 5972013 Compare December 11, 2025 17:20
@ThomasK33
Copy link
Member Author

@codex review

@chatgpt-codex-connector

This comment has been minimized.

@ThomasK33
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@ThomasK33 ThomasK33 force-pushed the post-compaction-context branch from 814a2d4 to 0c294b1 Compare December 11, 2025 17:41
@ThomasK33
Copy link
Member Author

@codex review

chatgpt-codex-connector[bot]

This comment was marked as outdated.

@ThomasK33 ThomasK33 force-pushed the post-compaction-context branch from 0c294b1 to b8af4a0 Compare December 11, 2025 17:57
@ThomasK33
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@ThomasK33 ThomasK33 force-pushed the post-compaction-context branch from b8af4a0 to 7b3af9f Compare December 11, 2025 18:25
@ThomasK33
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@ThomasK33
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@ThomasK33 ThomasK33 force-pushed the post-compaction-context branch from ceb6da2 to fda5d5b Compare December 11, 2025 18:49
@ThomasK33
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@ThomasK33
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@ThomasK33
Copy link
Member Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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.
@ThomasK33 ThomasK33 force-pushed the post-compaction-context branch from c6c1ef4 to 3ffaf9e Compare December 11, 2025 20:03
@ThomasK33
Copy link
Member Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. 🎉

ℹ️ 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".

@ThomasK33 ThomasK33 added this pull request to the merge queue Dec 11, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 11, 2025
@ThomasK33 ThomasK33 added this pull request to the merge queue Dec 11, 2025
Merged via the queue into main with commit 04231ce Dec 11, 2025
20 checks passed
@ThomasK33 ThomasK33 deleted the post-compaction-context branch December 11, 2025 21:07
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.

2 participants