-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Background
The Copilot SDK v0.1.26 introduces session compaction and agent selection APIs (PR #544 by Steve Sanderson, Feb 25, 2026). Session compaction allows SDKs to request that the CLI compress the conversation history, which is critical for long-running tasks that would otherwise hit token limits.
Key SDK features:
session.compact()- Requests history compaction from the CLI- Returns compacted message count and new token usage stats
- Useful when session history grows large during multi-turn clarification or complex execution phases
- Prevents token limit errors and improves response times for later messages
Related commit:
- 9d998fb - Add SDK support for agent selection and session compaction APIs
Proposal
Leverage session compaction in Planeteer to handle long-running clarification chats and task execution sessions:
- Track session token usage in
src/services/copilot.ts:- Monitor
sessionEvent.data.usagefields (e.g.,total_tokens,prompt_tokens) - Expose current token count via callback or state update to screens
- Monitor
- Auto-compact when threshold reached:
- Call
session.compact()when token usage exceeds a threshold (e.g., 80% of model context window) - Display compaction events in the UI (e.g., "Session history compacted: 45 → 12 messages")
- Call
- Manual compaction command (optional):
- Add a keybinding in Clarify/Refine screens (e.g.,
c) to trigger manual compaction - Useful if user notices slowdowns or wants to reset context
- Add a keybinding in Clarify/Refine screens (e.g.,
- Persist compaction metrics:
- Log compaction events to plan history for debugging
- Show token usage stats in the status bar or debug view
Benefit
- Prevents token limit errors: Long clarification sessions or complex multi-task plans won't crash due to context overflow
- Faster responses: Compacted history reduces latency for subsequent LLM calls
- Cost savings: Fewer tokens sent to the model on each request
- Better UX: Users see transparent feedback about session state and context management
Acceptance Criteria
-
src/services/copilot.tstracks session token usage fromsession.context_changedorassistant.message_deltaevents - Auto-compaction triggers when token usage exceeds configurable threshold (default: 80% of 128K context for claude-sonnet-4.6)
-
session.compact()is called and compaction results are logged - Compaction events are displayed in Clarify/Refine/Execute screens (e.g., toast notification or event log entry)
- Token usage is displayed in the status bar or a debug panel
- Tests verify compaction is triggered and session continues working after compaction
- Updated to SDK ^0.1.26+ to access compaction APIs
AI generated by Weekly Enhancement Suggestions
Reactions are currently unavailable