source dump of claude code
at main 88 lines 2.5 kB view raw
1import { isTeamMemFile } from '../memdir/teamMemPaths.js' 2import { FILE_EDIT_TOOL_NAME } from '../tools/FileEditTool/constants.js' 3import { FILE_WRITE_TOOL_NAME } from '../tools/FileWriteTool/prompt.js' 4 5export { isTeamMemFile } 6 7/** 8 * Check if a search tool use targets team memory files by examining its path. 9 */ 10export function isTeamMemorySearch(toolInput: unknown): boolean { 11 const input = toolInput as 12 | { path?: string; pattern?: string; glob?: string } 13 | undefined 14 if (!input) { 15 return false 16 } 17 if (input.path && isTeamMemFile(input.path)) { 18 return true 19 } 20 return false 21} 22 23/** 24 * Check if a Write or Edit tool use targets a team memory file. 25 */ 26export function isTeamMemoryWriteOrEdit( 27 toolName: string, 28 toolInput: unknown, 29): boolean { 30 if (toolName !== FILE_WRITE_TOOL_NAME && toolName !== FILE_EDIT_TOOL_NAME) { 31 return false 32 } 33 const input = toolInput as { file_path?: string; path?: string } | undefined 34 const filePath = input?.file_path ?? input?.path 35 return filePath !== undefined && isTeamMemFile(filePath) 36} 37 38/** 39 * Append team memory summary parts to the parts array. 40 * Encapsulates all team memory verb/string logic for getSearchReadSummaryText. 41 */ 42export function appendTeamMemorySummaryParts( 43 memoryCounts: { 44 teamMemoryReadCount?: number 45 teamMemorySearchCount?: number 46 teamMemoryWriteCount?: number 47 }, 48 isActive: boolean, 49 parts: string[], 50): void { 51 const teamReadCount = memoryCounts.teamMemoryReadCount ?? 0 52 const teamSearchCount = memoryCounts.teamMemorySearchCount ?? 0 53 const teamWriteCount = memoryCounts.teamMemoryWriteCount ?? 0 54 if (teamReadCount > 0) { 55 const verb = isActive 56 ? parts.length === 0 57 ? 'Recalling' 58 : 'recalling' 59 : parts.length === 0 60 ? 'Recalled' 61 : 'recalled' 62 parts.push( 63 `${verb} ${teamReadCount} team ${teamReadCount === 1 ? 'memory' : 'memories'}`, 64 ) 65 } 66 if (teamSearchCount > 0) { 67 const verb = isActive 68 ? parts.length === 0 69 ? 'Searching' 70 : 'searching' 71 : parts.length === 0 72 ? 'Searched' 73 : 'searched' 74 parts.push(`${verb} team memories`) 75 } 76 if (teamWriteCount > 0) { 77 const verb = isActive 78 ? parts.length === 0 79 ? 'Writing' 80 : 'writing' 81 : parts.length === 0 82 ? 'Wrote' 83 : 'wrote' 84 parts.push( 85 `${verb} ${teamWriteCount} team ${teamWriteCount === 1 ? 'memory' : 'memories'}`, 86 ) 87 } 88}