* feat: add /compact skill for manual context compaction added /compact session command to fight context rot in long-running sessions. Uses Claude Agent SDK's built-in /compact command with auth gating (main-group or is_from_me only). * simplify: remove group-queue modification, streamline denied path confirmed against fresh-clone merge. * refactor: extract handleSessionCommand from index.ts into session-commands.ts Verified: 345/345 tests pass on fresh-clone merge.
1.5 KiB
1.5 KiB
Intent: container/agent-runner/src/index.ts
What Changed
- Added
KNOWN_SESSION_COMMANDSwhitelist (/compact) - Added slash command handling block in
main()between prompt building and query loop - Slash commands use
query()with string prompt (not MessageStream),allowedTools: [], no mcpServers - Tracks
compactBoundarySeen,hadError,resultEmittedflags - Observes
compact_boundarysystem event to confirm compaction - PreCompact hook still registered for transcript archival
- Error subtype checking:
resultSubtype?.startsWith('error')emitsstatus: 'error' - Container exits after slash command completes (no IPC wait loop)
Key Sections
- KNOWN_SESSION_COMMANDS (before query loop): Set containing
/compact - Slash command block (after prompt building, before query loop): Detects session command, runs query with minimal options, handles result/error/boundary events
- Existing query loop: Unchanged
Invariants (must-keep)
- ContainerInput/ContainerOutput interfaces
- readStdin, writeOutput, log utilities
- OUTPUT_START_MARKER / OUTPUT_END_MARKER protocol
- MessageStream class with push/end/asyncIterator
- IPC polling (drainIpcInput, waitForIpcMessage, shouldClose)
- runQuery function with all existing logic
- createPreCompactHook for transcript archival
- createSanitizeBashHook for secret stripping
- parseTranscript, formatTranscriptMarkdown helpers
- main() stdin parsing, SDK env setup, query loop
- SECRET_ENV_VARS list