MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / createCollapsedGroup

Function createCollapsedGroup

source code/utils/collapseReadSearch.ts:663–754  ·  view source on GitHub ↗
(
  group: GroupAccumulator,
)

Source from the content-addressed store, hash-verified

661}
662
663function createCollapsedGroup(
664 group: GroupAccumulator,
665): CollapsedReadSearchGroup {
666 const firstMsg = group.messages[0]!
667 // When file-path-based reads exist, use unique file count (Set.size) only.
668 // Adding bash operation count on top would double-count — e.g. Read(README.md)
669 // followed by Bash(wc -l README.md) should still show as 1 file, not 2.
670 // Fall back to operation count only when there are no file-path reads (bash-only).
671 const totalReadCount =
672 group.readFilePaths.size > 0
673 ? group.readFilePaths.size
674 : group.readOperationCount
675 // memoryReadFilePaths ⊆ readFilePaths (both populated from Read tool calls),
676 // so this count is safe to subtract from totalReadCount at readCount below.
677 // Absorbed relevant_memories attachments are NOT in readFilePaths — added
678 // separately after the subtraction so readCount stays correct.
679 const toolMemoryReadCount = group.memoryReadFilePaths.size
680 const memoryReadCount =
681 toolMemoryReadCount + (group.relevantMemories?.length ?? 0)
682 // Non-memory read file paths: exclude memory and team memory paths
683 const teamMemReadPaths = feature('TEAMMEM')
684 ? group.teamMemoryReadFilePaths
685 : undefined
686 const nonMemReadFilePaths = [...group.readFilePaths].filter(
687 p =>
688 !group.memoryReadFilePaths.has(p) && !(teamMemReadPaths?.has(p) ?? false),
689 )
690 const teamMemSearchCount = feature('TEAMMEM')
691 ? (group.teamMemorySearchCount ?? 0)
692 : 0
693 const teamMemReadCount = feature('TEAMMEM')
694 ? (group.teamMemoryReadFilePaths?.size ?? 0)
695 : 0
696 const teamMemWriteCount = feature('TEAMMEM')
697 ? (group.teamMemoryWriteCount ?? 0)
698 : 0
699 const result: CollapsedReadSearchGroup = {
700 type: 'collapsed_read_search',
701 // Subtract memory + team memory counts so regular counts only reflect non-memory operations
702 searchCount: Math.max(
703 0,
704 group.searchCount - group.memorySearchCount - teamMemSearchCount,
705 ),
706 readCount: Math.max(
707 0,
708 totalReadCount - toolMemoryReadCount - teamMemReadCount,
709 ),
710 listCount: group.listCount,
711 // REPL operations are intentionally not collapsed (see isCollapsible: false at line 32),
712 // so replCount in collapsed groups is always 0. The replCount field is kept for
713 // sub-agent progress display in AgentTool/UI.tsx which has a separate code path.
714 replCount: 0,
715 memorySearchCount: group.memorySearchCount,
716 memoryReadCount,
717 memoryWriteCount: group.memoryWriteCount,
718 readFilePaths: nonMemReadFilePaths,
719 searchArgs: group.nonMemSearchArgs,
720 latestDisplayHint: group.latestDisplayHint,

Callers 1

flushGroupFunction · 0.85

Calls 3

isFullscreenEnvEnabledFunction · 0.85
maxMethod · 0.80
hasMethod · 0.45

Tested by

no test coverage detected