( messages: Message[] | undefined, toolUseContext: ToolUseContext, )
| 1333 | } |
| 1334 | |
| 1335 | async function getAutoModeAttachments( |
| 1336 | messages: Message[] | undefined, |
| 1337 | toolUseContext: ToolUseContext, |
| 1338 | ): Promise<Attachment[]> { |
| 1339 | const appState = toolUseContext.getAppState() |
| 1340 | const permissionContext = appState.toolPermissionContext |
| 1341 | const inAuto = permissionContext.mode === 'auto' |
| 1342 | const inPlanWithAuto = |
| 1343 | permissionContext.mode === 'plan' && |
| 1344 | (autoModeStateModule?.isAutoModeActive() ?? false) |
| 1345 | if (!inAuto && !inPlanWithAuto) { |
| 1346 | return [] |
| 1347 | } |
| 1348 | |
| 1349 | // Check if we should attach based on turn count (except for first turn) |
| 1350 | if (messages && messages.length > 0) { |
| 1351 | const { turnCount, foundAutoModeAttachment } = |
| 1352 | getAutoModeAttachmentTurnCount(messages) |
| 1353 | // Only throttle if we've already sent an auto_mode attachment before |
| 1354 | // On first turn in auto mode, always attach |
| 1355 | if ( |
| 1356 | foundAutoModeAttachment && |
| 1357 | turnCount < AUTO_MODE_ATTACHMENT_CONFIG.TURNS_BETWEEN_ATTACHMENTS |
| 1358 | ) { |
| 1359 | return [] |
| 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | // Determine if this should be a full or sparse reminder |
| 1364 | const attachmentCount = |
| 1365 | countAutoModeAttachmentsSinceLastExit(messages ?? []) + 1 |
| 1366 | const reminderType: 'full' | 'sparse' = |
| 1367 | attachmentCount % |
| 1368 | AUTO_MODE_ATTACHMENT_CONFIG.FULL_REMINDER_EVERY_N_ATTACHMENTS === |
| 1369 | 1 |
| 1370 | ? 'full' |
| 1371 | : 'sparse' |
| 1372 | |
| 1373 | return [{ type: 'auto_mode', reminderType }] |
| 1374 | } |
| 1375 | |
| 1376 | /** |
| 1377 | * Returns an auto_mode_exit attachment if we just exited auto mode. |
no test coverage detected