( messages: Message[] | undefined, toolUseContext: ToolUseContext, )
| 1238 | } |
| 1239 | |
| 1240 | async function getPlanModeAttachments( |
| 1241 | messages: Message[] | undefined, |
| 1242 | toolUseContext: ToolUseContext, |
| 1243 | ): Promise<Attachment[]> { |
| 1244 | const appState = toolUseContext.getAppState() |
| 1245 | const permissionContext = appState.toolPermissionContext |
| 1246 | if (permissionContext.mode !== 'plan') { |
| 1247 | return [] |
| 1248 | } |
| 1249 | |
| 1250 | // Check if we should attach based on turn count (except for first turn) |
| 1251 | if (messages && messages.length > 0) { |
| 1252 | const { turnCount, foundPlanModeAttachment } = |
| 1253 | getPlanModeAttachmentTurnCount(messages) |
| 1254 | // Only throttle if we've already sent a plan_mode attachment before |
| 1255 | // On first turn in plan mode, always attach |
| 1256 | if ( |
| 1257 | foundPlanModeAttachment && |
| 1258 | turnCount < PLAN_MODE_ATTACHMENT_CONFIG.TURNS_BETWEEN_ATTACHMENTS |
| 1259 | ) { |
| 1260 | return [] |
| 1261 | } |
| 1262 | } |
| 1263 | |
| 1264 | const planFilePath = getPlanFilePath(toolUseContext.agentId) |
| 1265 | const existingPlan = getPlan(toolUseContext.agentId) |
| 1266 | |
| 1267 | const attachments: Attachment[] = [] |
| 1268 | |
| 1269 | // Check for re-entry: flag is set AND plan file exists |
| 1270 | if (hasExitedPlanModeInSession() && existingPlan !== null) { |
| 1271 | attachments.push({ type: 'plan_mode_reentry', planFilePath }) |
| 1272 | setHasExitedPlanMode(false) // Clear flag - one-time guidance |
| 1273 | } |
| 1274 | |
| 1275 | // Determine if this should be a full or sparse reminder |
| 1276 | // Full reminder on 1st, 6th, 11th... (every Nth attachment) |
| 1277 | const attachmentCount = |
| 1278 | countPlanModeAttachmentsSinceLastExit(messages ?? []) + 1 |
| 1279 | const reminderType: 'full' | 'sparse' = |
| 1280 | attachmentCount % |
| 1281 | PLAN_MODE_ATTACHMENT_CONFIG.FULL_REMINDER_EVERY_N_ATTACHMENTS === |
| 1282 | 1 |
| 1283 | ? 'full' |
| 1284 | : 'sparse' |
| 1285 | |
| 1286 | // Always add the main plan_mode attachment |
| 1287 | attachments.push({ |
| 1288 | type: 'plan_mode', |
| 1289 | reminderType, |
| 1290 | isSubAgent: !!toolUseContext.agentId, |
| 1291 | planFilePath, |
| 1292 | planExists: existingPlan !== null, |
| 1293 | }) |
| 1294 | |
| 1295 | return attachments |
| 1296 | } |
| 1297 |
no test coverage detected