MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / call

Function call

source code/commands/compact/compact.ts:42–139  ·  view source on GitHub ↗
(args, context)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

runPostCompactCleanupFunction · 0.85
notifyCompactionFunction · 0.85
markPostCompactionFunction · 0.85
suppressCompactWarningFunction · 0.85
buildDisplayTextFunction · 0.85
compactViaReactiveFunction · 0.85
microcompactMessagesFunction · 0.85
compactConversationFunction · 0.85
getCacheSharingParamsFunction · 0.85

Tested by

no test coverage detected