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

Function getPlanModeAttachmentTurnCount

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

Source from the content-addressed store, hash-verified

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