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

Function readReferences

graph-ui/src/provider/compact-rows.ts:192–210  ·  view source on GitHub ↗
(lines: string[], from: number, key: 'rows' | 'results')

Source from the content-addressed store, hash-verified

190}
191
192function readReferences(lines: string[], from: number, key: 'rows' | 'results'):
193 { refs?: ReadonlyMap<number, string>; next: number } {
194 const head = new RegExp(`^${key}_refs:\\s*(\\d+)\\s*\\(cols:\\s*id\\s+prefix\\)\\s*$`).exec(lines[from]);
195 if (!head) return { next: from };
196 const count = Number(head[1]);
197 const collected = collectRows(lines, from + 1, ['id', 'prefix'], `${key}_refs`);
198 if (!Number.isSafeInteger(count) || collected.rows.length !== count)
199 throw new Error(`${key}_refs: declared count does not match reference rows`);
200 const refs = new Map<number, string>();
201 for (const [id, prefix] of collected.rows) {
202 const number = Number(id);
203 if (!/^\d+$/.test(id) || !Number.isSafeInteger(number) || refs.has(number))
204 throw new Error(`${key}_refs: invalid or duplicate reference id ${id}`);
205 refs.set(number, prefix);
206 }
207 if (lines[collected.next]?.trim() !== `${key}_ref_rule: @N+suffix=prefix+suffix`)
208 throw new Error(`${key}_refs: missing or unsupported reference rule`);
209 return { refs, next: collected.next + 1 };
210}
211
212function validateCounts(parsed: CompactRows | SearchResults): void {
213 for (const value of [parsed.total, parsed.returned, 'offset' in parsed ? parsed.offset : undefined,

Callers 2

parseCompactRowsFunction · 0.85
parseSearchResultsFunction · 0.85

Calls 1

collectRowsFunction · 0.85

Tested by

no test coverage detected