- Add compactEmbeddedPiSessionDirect for synchronous compaction
- Detect active run and use direct method to avoid self-abort deadlock
- Fixes transcript repair error when session_compact called mid-session
Improvements:
1. threshold parameter - skip compaction if context below threshold %
2. Auto-saves compaction file to memory/compactions/ with timestamp
3. Returns file path in response so agent knows where to read
This enables fully autonomous context management without manual steps.
Adds a new core tool that allows agents to proactively compact their own session
context without user intervention. This enables agents to self-manage their
context window when nearing limits.
The tool:
- Uses the existing compactEmbeddedPiSession infrastructure
- Supports optional custom instructions for focused compaction
- Returns token usage before/after for transparency
- Integrates with existing compaction count tracking
Use case: Agents can monitor context usage via session_status and invoke
session_compact when approaching thresholds (e.g., 60%+ context), then
read their memory/compactions/ files to restore state.
Closes: Agent self-management of context window