MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / collapseRepeats

Function collapseRepeats

graph-ui/src/system/system-model.ts:78–89  ·  view source on GitHub ↗
(records: readonly DaemonLogRecord[])

Source from the content-addressed store, hash-verified

76 * occurrence. Per session the larger of the two is the number of occurrences.
77 */
78export function collapseRepeats(records: readonly DaemonLogRecord[]): LogRow[] {
79 const groups = new Map<string, { last: number; first: string; sessions: Map<string, { plain: number; counted: number }> }>();
80 records.forEach((record, index) => {
81 const { key, session, repeat } = repeatIdentity(record);
82 const group = groups.get(key) ?? { last: index, first: record.ts, sessions: new Map() };
83 const tally = group.sessions.get(session) ?? { plain: 0, counted: 0 };
84 if (repeat === undefined) tally.plain += 1; else tally.counted = Math.max(tally.counted, repeat);
85 group.sessions.set(session, tally); group.last = index; groups.set(key, group);
86 });
87 return [...groups.values()].sort((a, b) => a.last - b.last).map((group) => ({ record: records[group.last]!, first: group.first,
88 count: [...group.sessions.values()].reduce((sum, tally) => sum + Math.max(tally.plain, tally.counted), 0) }));
89}
90
91/** The tooltip of a combined row. */
92export function repeatTitle(row: LogRow): string {

Callers 2

SystemWorkspaceFunction · 0.90

Calls 3

repeatIdentityFunction · 0.85
reduceMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected