(args, context)
| 38 | /* eslint-enable @typescript-eslint/no-require-imports */ |
| 39 | |
| 40 | export const call: LocalCommandCall = async (args, context) => { |
| 41 | const { abortController } = context |
| 42 | let { messages } = context |
| 43 | |
| 44 | // REPL keeps snipped messages for UI scrollback — project so the compact |
| 45 | // model doesn't summarize content that was intentionally removed. |
| 46 | messages = getMessagesAfterCompactBoundary(messages) |
| 47 | |
| 48 | if (messages.length === 0) { |
| 49 | throw new Error('No messages to compact') |
| 50 | } |
| 51 | |
| 52 | const customInstructions = args.trim() |
| 53 | |
| 54 | try { |
| 55 | // Try session memory compaction first if no custom instructions |
| 56 | // (session memory compaction doesn't support custom instructions) |
| 57 | if (!customInstructions) { |
| 58 | const sessionMemoryResult = await trySessionMemoryCompaction( |
| 59 | messages, |
| 60 | context.agentId, |
| 61 | ) |
| 62 | if (sessionMemoryResult) { |
| 63 | getUserContext.cache.clear?.() |
| 64 | runPostCompactCleanup() |
| 65 | // Reset cache read baseline so the post-compact drop isn't flagged |
| 66 | // as a break. compactConversation does this internally; SM-compact doesn't. |
| 67 | if (feature('PROMPT_CACHE_BREAK_DETECTION')) { |
| 68 | notifyCompaction( |
| 69 | context.options.querySource ?? 'compact', |
| 70 | context.agentId, |
| 71 | ) |
| 72 | } |
| 73 | markPostCompaction() |
| 74 | // Suppress warning immediately after successful compaction |
| 75 | suppressCompactWarning() |
| 76 | |
| 77 | return { |
| 78 | type: 'compact', |
| 79 | compactionResult: sessionMemoryResult, |
| 80 | displayText: buildDisplayText(context), |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // Reactive-only mode: route /compact through the reactive path. |
| 86 | // Checked after session-memory (that path is cheap and orthogonal). |
| 87 | if (reactiveCompact?.isReactiveOnlyMode()) { |
| 88 | return await compactViaReactive( |
| 89 | messages, |
| 90 | context, |
| 91 | customInstructions, |
| 92 | reactiveCompact, |
| 93 | ) |
| 94 | } |
| 95 | |
| 96 | // Fall back to traditional compaction |
| 97 | // Run microcompact first to reduce tokens before summarization |
nothing calls this directly
no test coverage detected