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

Function visit

graph-ui/src/browser-ai/explanation-context.ts:123–147  ·  view source on GitHub ↗
(current: unknown, path: string, depth: number)

Source from the content-addressed store, hash-verified

121 else omittedFields++;
122 };
123 const visit = (current: unknown, path: string, depth: number) => {
124 if (current === undefined) return;
125 if (++visited > 100 || depth > 5 || remaining < 35) { omittedFields++; return; }
126 if (Array.isArray(current)) {
127 add(`${path}: ${current.length} snapshot items`);
128 const take = Math.min(current.length, 3);
129 if (current.length > take) add(`${path}: ${current.length - take} snapshot items omitted from this explanation`);
130 for (let index = 0; index < take; index++) visit(current[index], `${path}[${index}]`, depth + 1);
131 return;
132 }
133 const object = record(current);
134 if (object) {
135 const entries = Object.entries(object);
136 // Put counts and scalar identity before potentially large collections.
137 const ordered = [...entries.filter(([, item]) => item === null || typeof item !== 'object'),
138 ...entries.filter(([, item]) => item !== null && typeof item === 'object')];
139 for (const [key, item] of ordered.slice(0, 24)) visit(item, `${path}.${bounded(key, 60)}`, depth + 1);
140 if (ordered.length > 24) add(`${path}: ${ordered.length - 24} fields omitted`);
141 return;
142 }
143 if (typeof current === 'string') {
144 const literal = prefix(current, 180);
145 add(`${path}: ${JSON.stringify(literal)}${literal.length < current.length ? ` (${current.length - literal.length} characters omitted)` : ''}`);
146 } else if (current === null || typeof current === 'number' || typeof current === 'boolean') add(`${path}: ${String(current)}`);
147 };
148 visit(value, name, 0);
149 if (omittedFields) {
150 const note = `${omittedFields} additional graph fields omitted from this explanation.`;

Callers 1

graphFactsFunction · 0.70

Calls 4

prefixFunction · 0.85
addFunction · 0.70
recordFunction · 0.70
boundedFunction · 0.70

Tested by

no test coverage detected