( messages: Message[] | undefined, toolUseContext: ToolUseContext, )
| 1184 | } |
| 1185 | |
| 1186 | async function getPlanModeAttachments( |
| 1187 | messages: Message[] | undefined, |
| 1188 | toolUseContext: ToolUseContext, |
| 1189 | ): Promise<Attachment[]> { |
| 1190 | const appState = toolUseContext.getAppState() |
| 1191 | const permissionContext = appState.toolPermissionContext |
| 1192 | if (permissionContext.mode !== 'plan') { |
| 1193 | return [] |
| 1194 | } |
| 1195 | |
| 1196 | // Check if we should attach based on turn count (except for first turn) |
| 1197 | if (messages && messages.length > 0) { |
| 1198 | const { turnCount, foundPlanModeAttachment } = |
| 1199 | getPlanModeAttachmentTurnCount(messages) |
| 1200 | // Only throttle if we've already sent a plan_mode attachment before |
| 1201 | // On first turn in plan mode, always attach |
| 1202 | if ( |
| 1203 | foundPlanModeAttachment && |
| 1204 | turnCount < PLAN_MODE_ATTACHMENT_CONFIG.TURNS_BETWEEN_ATTACHMENTS |
| 1205 | ) { |
| 1206 | return [] |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | const planFilePath = getPlanFilePath(toolUseContext.agentId) |
| 1211 | const existingPlan = getPlan(toolUseContext.agentId) |
| 1212 | |
| 1213 | const attachments: Attachment[] = [] |
| 1214 | |
| 1215 | // Check for re-entry: flag is set AND plan file exists |
| 1216 | if (hasExitedPlanModeInSession() && existingPlan !== null) { |
| 1217 | attachments.push({ type: 'plan_mode_reentry', planFilePath }) |
| 1218 | setHasExitedPlanMode(false) // Clear flag - one-time guidance |
| 1219 | } |
| 1220 | |
| 1221 | // Determine if this should be a full or sparse reminder |
| 1222 | // Full reminder on 1st, 6th, 11th... (every Nth attachment) |
| 1223 | const attachmentCount = |
| 1224 | countPlanModeAttachmentsSinceLastExit(messages ?? []) + 1 |
| 1225 | const reminderType: 'full' | 'sparse' = |
| 1226 | attachmentCount % |
| 1227 | PLAN_MODE_ATTACHMENT_CONFIG.FULL_REMINDER_EVERY_N_ATTACHMENTS === |
| 1228 | 1 |
| 1229 | ? 'full' |
| 1230 | : 'sparse' |
| 1231 | |
| 1232 | // Always add the main plan_mode attachment |
| 1233 | attachments.push({ |
| 1234 | type: 'plan_mode', |
| 1235 | reminderType, |
| 1236 | isSubAgent: !!toolUseContext.agentId, |
| 1237 | planFilePath, |
| 1238 | planExists: existingPlan !== null, |
| 1239 | }) |
| 1240 | |
| 1241 | return attachments |
| 1242 | } |
| 1243 |
no test coverage detected