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