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