Repository navigation
feat(code): suggest compacting large resumed threads #5318
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
Merged
Johannes du Plessis (johannes117)
merged 9 commits into
main
from
johannes117/code/compact-on-resume
Aug 5, 2026
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b084cda
feat(code): suggest compacting large resumed threads
johannes117 7c70680
fix(code): resume threads without blocking the message pump
open-swe b60401b
cleanup
open-swe 05d4b95
chore(code): remove unrelated model command changes
open-swe 50b6087
Merge branch 'main' into johannes117/code/compact-on-resume
johannes117 9d59918
fix(code): correct compact-on-resume sequencing
johannes117 923eaef
refactor(code): simplify compact-on-resume changes
johannes117 950dbb5
refactor(code): prompt for compaction after resume completes
johannes117 b65ee36
fix(code): offer compaction on resumed launches that carry a prompt
johannes117 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| """Prompt for compacting a large resumed thread.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING, ClassVar | ||
|
|
||
| from textual.binding import Binding, BindingType | ||
| from textual.containers import Vertical | ||
| from textual.screen import ModalScreen | ||
| from textual.widgets import Static | ||
|
|
||
| from deepagents_code._session_stats import format_token_count | ||
| from deepagents_code.config import get_glyphs | ||
|
|
||
| if TYPE_CHECKING: | ||
| from textual.app import ComposeResult | ||
|
|
||
|
|
||
| class ResumeCompactPromptScreen(ModalScreen[bool]): | ||
| """Ask whether to compact a just-resumed thread before the next turn.""" | ||
|
|
||
| can_focus = True | ||
|
|
||
| BINDINGS: ClassVar[list[BindingType]] = [ | ||
| Binding("enter", "compact", "Compact", show=False, priority=True), | ||
| Binding("escape", "skip", "Skip", show=False, priority=True), | ||
| Binding( | ||
| "ctrl+c", | ||
| "quit_or_interrupt", | ||
| "Quit/Interrupt", | ||
| show=False, | ||
| priority=True, | ||
| ), | ||
| Binding("ctrl+d", "quit_app", "Quit", show=False, priority=True), | ||
| ] | ||
|
|
||
| CSS = """ | ||
| ResumeCompactPromptScreen { | ||
| align: center middle; | ||
| } | ||
|
|
||
| ResumeCompactPromptScreen > Vertical { | ||
| width: 72; | ||
| max-width: 90%; | ||
| height: auto; | ||
| background: $surface; | ||
| border: solid $warning; | ||
| padding: 1 2; | ||
| } | ||
|
|
||
| ResumeCompactPromptScreen .resume-compact-title { | ||
| text-style: bold; | ||
| color: $warning; | ||
| text-align: center; | ||
| margin-bottom: 1; | ||
| } | ||
|
|
||
| ResumeCompactPromptScreen .resume-compact-body { | ||
| height: auto; | ||
| color: $text; | ||
| margin-bottom: 1; | ||
| } | ||
|
|
||
| ResumeCompactPromptScreen .resume-compact-help { | ||
| height: auto; | ||
| color: $text-muted; | ||
| text-style: italic; | ||
| text-align: center; | ||
| } | ||
| """ | ||
|
|
||
| def __init__(self, *, context_tokens: int, threshold: int) -> None: | ||
| """Initialize the prompt. | ||
|
|
||
| Args: | ||
| context_tokens: Latest model-reported context size for the thread. | ||
| threshold: Configured token count that triggered the suggestion. | ||
| """ | ||
| super().__init__() | ||
| self._context_tokens = context_tokens | ||
| self._threshold = threshold | ||
|
|
||
| def compose(self) -> ComposeResult: | ||
| """Compose the confirmation dialog. | ||
|
|
||
| Yields: | ||
| Title, explanation, and keyboard help. | ||
| """ | ||
| with Vertical(): | ||
| yield Static( | ||
| "Compact this thread?", | ||
| classes="resume-compact-title", | ||
| markup=False, | ||
| ) | ||
| yield Static( | ||
| f"This thread uses {format_token_count(self._context_tokens)} context " | ||
| "tokens, above the configured " | ||
| f"{format_token_count(self._threshold)} token threshold. Compacting " | ||
| "summarizes older messages so later turns cost less.", | ||
| classes="resume-compact-body", | ||
| markup=False, | ||
| ) | ||
| yield Static( | ||
| f" {get_glyphs().bullet} ".join( | ||
| ("Enter: compact now", "Esc: keep full context") | ||
| ), | ||
| classes="resume-compact-help", | ||
| markup=False, | ||
| ) | ||
|
|
||
| def on_mount(self) -> None: | ||
| """Focus the modal so its bindings receive keyboard input.""" | ||
| self.focus() | ||
|
|
||
| def action_compact(self) -> None: | ||
| """Compact the thread before the next turn.""" | ||
| self.dismiss(True) | ||
|
|
||
| def action_skip(self) -> None: | ||
| """Leave the thread's context untouched.""" | ||
| self.dismiss(False) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.