( context: CollectContextDataInput, )
| 32 | } |
| 33 | |
| 34 | export async function collectContextData( |
| 35 | context: CollectContextDataInput, |
| 36 | ): Promise<ContextData> { |
| 37 | const { |
| 38 | messages, |
| 39 | getAppState, |
| 40 | options: { |
| 41 | mainLoopModel, |
| 42 | tools, |
| 43 | agentDefinitions, |
| 44 | customSystemPrompt, |
| 45 | appendSystemPrompt, |
| 46 | }, |
| 47 | } = context |
| 48 | |
| 49 | let apiView = getMessagesAfterCompactBoundary(messages) |
| 50 | if (feature('CONTEXT_COLLAPSE')) { |
| 51 | /* eslint-disable @typescript-eslint/no-require-imports */ |
| 52 | const { projectView } = |
| 53 | require('../../services/contextCollapse/operations.js') as typeof import('../../services/contextCollapse/operations.js') |
| 54 | /* eslint-enable @typescript-eslint/no-require-imports */ |
| 55 | apiView = projectView(apiView) |
| 56 | } |
| 57 | |
| 58 | const { messages: compactedMessages } = await microcompactMessages(apiView) |
| 59 | const appState = getAppState() |
| 60 | |
| 61 | return analyzeContextUsage( |
| 62 | compactedMessages, |
| 63 | mainLoopModel, |
| 64 | async () => appState.toolPermissionContext, |
| 65 | tools, |
| 66 | agentDefinitions, |
| 67 | undefined, // terminalWidth |
| 68 | // analyzeContextUsage only reads options.{customSystemPrompt,appendSystemPrompt} |
| 69 | // but its signature declares the full Pick<ToolUseContext, 'options'>. |
| 70 | { options: { customSystemPrompt, appendSystemPrompt } } as Pick< |
| 71 | ToolUseContext, |
| 72 | 'options' |
| 73 | >, |
| 74 | undefined, // mainThreadAgentDefinition |
| 75 | apiView, // original messages for API usage extraction |
| 76 | ) |
| 77 | } |
| 78 | |
| 79 | export async function call( |
| 80 | _args: string, |
no test coverage detected