( content: string, summary: string | undefined, context: ToolUseContext, )
| 189 | } |
| 190 | |
| 191 | async function handleBroadcast( |
| 192 | content: string, |
| 193 | summary: string | undefined, |
| 194 | context: ToolUseContext, |
| 195 | ): Promise<{ data: BroadcastOutput }> { |
| 196 | const appState = context.getAppState() |
| 197 | const teamName = getTeamName(appState.teamContext) |
| 198 | |
| 199 | if (!teamName) { |
| 200 | throw new Error( |
| 201 | 'Not in a team context. Create a team with Teammate spawnTeam first, or set CLAUDE_CODE_TEAM_NAME.', |
| 202 | ) |
| 203 | } |
| 204 | |
| 205 | const teamFile = await readTeamFileAsync(teamName) |
| 206 | if (!teamFile) { |
| 207 | throw new Error(`Team "${teamName}" does not exist`) |
| 208 | } |
| 209 | |
| 210 | const senderName = |
| 211 | getAgentName() || (isTeammate() ? 'teammate' : TEAM_LEAD_NAME) |
| 212 | if (!senderName) { |
| 213 | throw new Error( |
| 214 | 'Cannot broadcast: sender name is required. Set CLAUDE_CODE_AGENT_NAME.', |
| 215 | ) |
| 216 | } |
| 217 | |
| 218 | const senderColor = getTeammateColor() |
| 219 | |
| 220 | const recipients: string[] = [] |
| 221 | for (const member of teamFile.members) { |
| 222 | if (member.name.toLowerCase() === senderName.toLowerCase()) { |
| 223 | continue |
| 224 | } |
| 225 | recipients.push(member.name) |
| 226 | } |
| 227 | |
| 228 | if (recipients.length === 0) { |
| 229 | return { |
| 230 | data: { |
| 231 | success: true, |
| 232 | message: 'No teammates to broadcast to (you are the only team member)', |
| 233 | recipients: [], |
| 234 | }, |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | for (const recipientName of recipients) { |
| 239 | await writeToMailbox( |
| 240 | recipientName, |
| 241 | { |
| 242 | from: senderName, |
| 243 | text: content, |
| 244 | summary, |
| 245 | timestamp: new Date().toISOString(), |
| 246 | color: senderColor, |
| 247 | }, |
| 248 | teamName, |
no test coverage detected