MCPcopy Index your code
hub / github.com/codeaashu/claude-code / getPlanModeAttachmentTurnCount

Function getPlanModeAttachmentTurnCount

src/utils/attachments.ts:1131–1163  ·  view source on GitHub ↗
(messages: Message[])

Source from the content-addressed store, hash-verified

1129}
1130
1131function getPlanModeAttachmentTurnCount(messages: Message[]): {
1132 turnCount: number
1133 foundPlanModeAttachment: boolean
1134} {
1135 let turnsSinceLastAttachment = 0
1136 let foundPlanModeAttachment = false
1137
1138 // Iterate backwards to find most recent plan_mode attachment.
1139 // Count HUMAN turns (non-meta, non-tool-result user messages), not assistant
1140 // messages — the tool loop in query.ts calls getAttachmentMessages on every
1141 // tool round, so counting assistant messages would fire the reminder every
1142 // 5 tool calls instead of every 5 human turns.
1143 for (let i = messages.length - 1; i >= 0; i--) {
1144 const message = messages[i]
1145
1146 if (
1147 message?.type === 'user' &&
1148 !message.isMeta &&
1149 !hasToolResultContent(message.message.content)
1150 ) {
1151 turnsSinceLastAttachment++
1152 } else if (
1153 message?.type === 'attachment' &&
1154 (message.attachment.type === 'plan_mode' ||
1155 message.attachment.type === 'plan_mode_reentry')
1156 ) {
1157 foundPlanModeAttachment = true
1158 break
1159 }
1160 }
1161
1162 return { turnCount: turnsSinceLastAttachment, foundPlanModeAttachment }
1163}
1164
1165/**
1166 * Count plan_mode attachments since the last plan_mode_exit (or from start if no exit).

Callers 1

getPlanModeAttachmentsFunction · 0.85

Calls 1

hasToolResultContentFunction · 0.85

Tested by

no test coverage detected