feat: add Forever Mode for autonomous long-running agent sessions

Add --forever CLI flag that enables autonomous agent operation with
auto-resume, context management, and session optimization.

Core features:
- schedule_work tool: agent declares pause duration, system auto-resumes
  with countdown timer
- PreCompress hook enhancement: hooks can return newHistory to replace
  built-in LLM compression
- Idle hook: fires after configurable inactivity, can auto-submit prompts
- Forever mode disables MemoryTool, EnterPlanModeTool, interactive shell

Session optimization for long-running sessions:
- Record lastCompressionIndex on ConversationRecord; on resume, only load
  post-compression messages (O(N) → O(recent))
- Skip file I/O in updateMessagesFromHistory when no tool results to sync
- Prune UI history to last 50 items after each context compression to
  prevent unbounded memory growth
This commit is contained in:
Sandy Tao
2026-03-08 11:41:36 -07:00
parent 77a874cf65
commit 5194cef9c1
31 changed files with 752 additions and 52 deletions
@@ -85,6 +85,7 @@ describe('useQuotaAndFallback', () => {
updateItem: vi.fn(),
clearItems: vi.fn(),
loadHistory: vi.fn(),
pruneItems: vi.fn(),
};
mockSetModelSwitchedFromQuotaError = vi.fn();
mockOnShowAuthSelection = vi.fn();