MCPcopy Create free account
hub / github.com/Noumena-Network/code / getPlanModeAttachments

Function getPlanModeAttachments

src/utils/attachments.ts:1188–1244  ·  view source on GitHub ↗
(
  messages: Message[] | undefined,
  toolUseContext: ToolUseContext,
)

Source from the content-addressed store, hash-verified

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

Callers 1

getAttachmentsFunction · 0.85

Calls 6

getPlanFilePathFunction · 0.85
getPlanFunction · 0.85
setHasExitedPlanModeFunction · 0.50

Tested by

no test coverage detected