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

Function initializeTeammateHooks

src/utils/swarm/teammateInit.ts:28–129  ·  view source on GitHub ↗
(
  setAppState: (updater: (prev: AppState) => AppState) => void,
  sessionId: string,
  teamInfo: { teamName: string; agentId: string; agentName: string },
)

Source from the content-addressed store, hash-verified

26 * when this teammate's session stops.
27 */
28export function initializeTeammateHooks(
29 setAppState: (updater: (prev: AppState) => AppState) => void,
30 sessionId: string,
31 teamInfo: { teamName: string; agentId: string; agentName: string },
32): void {
33 const { teamName, agentId, agentName } = teamInfo
34
35 // Read team file to get leader ID
36 const teamFile = readTeamFile(teamName)
37 if (!teamFile) {
38 logForDebugging(`[TeammateInit] Team file not found for team: ${teamName}`)
39 return
40 }
41
42 const leadAgentId = teamFile.leadAgentId
43
44 // Apply team-wide allowed paths if any exist
45 if (teamFile.teamAllowedPaths && teamFile.teamAllowedPaths.length > 0) {
46 logForDebugging(
47 `[TeammateInit] Found ${teamFile.teamAllowedPaths.length} team-wide allowed path(s)`,
48 )
49
50 for (const allowedPath of teamFile.teamAllowedPaths) {
51 // For absolute paths (starting with /), prepend one / to create //path/** pattern
52 // For relative paths, just use path/**
53 const ruleContent = allowedPath.path.startsWith('/')
54 ? `/${allowedPath.path}/**`
55 : `${allowedPath.path}/**`
56
57 logForDebugging(
58 `[TeammateInit] Applying team permission: ${allowedPath.toolName} allowed in ${allowedPath.path} (rule: ${ruleContent})`,
59 )
60
61 setAppState(prev => ({
62 ...prev,
63 toolPermissionContext: applyPermissionUpdate(
64 prev.toolPermissionContext,
65 {
66 type: 'addRules',
67 rules: [
68 {
69 toolName: allowedPath.toolName,
70 ruleContent,
71 },
72 ],
73 behavior: 'allow',
74 destination: 'session',
75 },
76 ),
77 }))
78 }
79 }
80
81 // Find the leader's name from the members array
82 const leadMember = teamFile.members.find(m => m.agentId === leadAgentId)
83 const leadAgentName = leadMember?.name || 'team-lead'
84
85 // Don't register hook if this agent is the leader

Callers 1

useSwarmInitializationFunction · 0.85

Calls 10

readTeamFileFunction · 0.85
logForDebuggingFunction · 0.85
applyPermissionUpdateFunction · 0.85
addFunctionHookFunction · 0.85
setMemberActiveFunction · 0.85
createIdleNotificationFunction · 0.85
getLastPeerDmSummaryFunction · 0.85
writeToMailboxFunction · 0.85
jsonStringifyFunction · 0.85
getTeammateColorFunction · 0.70

Tested by

no test coverage detected