source dump of claude code
at main 93 lines 2.7 kB view raw
1import type { UUID } from 'crypto' 2import { getSessionId } from '../../bootstrap/state.js' 3import type { ToolUseContext } from '../../Tool.js' 4import { 5 AGENT_COLORS, 6 type AgentColorName, 7} from '../../tools/AgentTool/agentColorManager.js' 8import type { 9 LocalJSXCommandContext, 10 LocalJSXCommandOnDone, 11} from '../../types/command.js' 12import { 13 getTranscriptPath, 14 saveAgentColor, 15} from '../../utils/sessionStorage.js' 16import { isTeammate } from '../../utils/teammate.js' 17 18const RESET_ALIASES = ['default', 'reset', 'none', 'gray', 'grey'] as const 19 20export async function call( 21 onDone: LocalJSXCommandOnDone, 22 context: ToolUseContext & LocalJSXCommandContext, 23 args: string, 24): Promise<null> { 25 // Teammates cannot set their own color 26 if (isTeammate()) { 27 onDone( 28 'Cannot set color: This session is a swarm teammate. Teammate colors are assigned by the team leader.', 29 { display: 'system' }, 30 ) 31 return null 32 } 33 34 if (!args || args.trim() === '') { 35 const colorList = AGENT_COLORS.join(', ') 36 onDone(`Please provide a color. Available colors: ${colorList}, default`, { 37 display: 'system', 38 }) 39 return null 40 } 41 42 const colorArg = args.trim().toLowerCase() 43 44 // Handle reset to default (gray) 45 if (RESET_ALIASES.includes(colorArg as (typeof RESET_ALIASES)[number])) { 46 const sessionId = getSessionId() as UUID 47 const fullPath = getTranscriptPath() 48 49 // Use "default" sentinel (not empty string) so truthiness guards 50 // in sessionStorage.ts persist the reset across session restarts 51 await saveAgentColor(sessionId, 'default', fullPath) 52 53 context.setAppState(prev => ({ 54 ...prev, 55 standaloneAgentContext: { 56 ...prev.standaloneAgentContext, 57 name: prev.standaloneAgentContext?.name ?? '', 58 color: undefined, 59 }, 60 })) 61 62 onDone('Session color reset to default', { display: 'system' }) 63 return null 64 } 65 66 if (!AGENT_COLORS.includes(colorArg as AgentColorName)) { 67 const colorList = AGENT_COLORS.join(', ') 68 onDone( 69 `Invalid color "${colorArg}". Available colors: ${colorList}, default`, 70 { display: 'system' }, 71 ) 72 return null 73 } 74 75 const sessionId = getSessionId() as UUID 76 const fullPath = getTranscriptPath() 77 78 // Save to transcript for persistence across sessions 79 await saveAgentColor(sessionId, colorArg, fullPath) 80 81 // Update AppState for immediate effect 82 context.setAppState(prev => ({ 83 ...prev, 84 standaloneAgentContext: { 85 ...prev.standaloneAgentContext, 86 name: prev.standaloneAgentContext?.name ?? '', 87 color: colorArg as AgentColorName, 88 }, 89 })) 90 91 onDone(`Session color set to: ${colorArg}`, { display: 'system' }) 92 return null 93}