MCPcopy
hub / github.com/codeaashu/claude-code / getLastPeerDmSummary

Function getLastPeerDmSummary

src/utils/teammateMailbox.ts:1149–1183  ·  view source on GitHub ↗
(messages: Message[])

Source from the content-addressed store, hash-verified

1147 * Returns undefined when the turn didn't end with a peer DM.
1148 */
1149export function getLastPeerDmSummary(messages: Message[]): string | undefined {
1150 for (let i = messages.length - 1; i >= 0; i--) {
1151 const msg = messages[i]
1152 if (!msg) continue
1153
1154 // Stop at wake-up boundary: a user prompt (string content), not tool results (array content)
1155 if (msg.type === 'user' && typeof msg.message.content === 'string') {
1156 break
1157 }
1158
1159 if (msg.type !== 'assistant') continue
1160 for (const block of msg.message.content) {
1161 if (
1162 block.type === 'tool_use' &&
1163 block.name === SEND_MESSAGE_TOOL_NAME &&
1164 typeof block.input === 'object' &&
1165 block.input !== null &&
1166 'to' in block.input &&
1167 typeof block.input.to === 'string' &&
1168 block.input.to !== '*' &&
1169 block.input.to.toLowerCase() !== TEAM_LEAD_NAME.toLowerCase() &&
1170 'message' in block.input &&
1171 typeof block.input.message === 'string'
1172 ) {
1173 const to = block.input.to
1174 const summary =
1175 'summary' in block.input && typeof block.input.summary === 'string'
1176 ? block.input.summary
1177 : block.input.message.slice(0, 80)
1178 return `[to ${to}] ${summary}`
1179 }
1180 }
1181 }
1182 return undefined
1183}
1184

Callers 2

initializeTeammateHooksFunction · 0.85
runInProcessTeammateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected