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

Function segmentsOf

graph-ui/src/compiler/answer-contract.ts:233–258  ·  view source on GitHub ↗
(line: string, cardIds: readonly string[])

Source from the content-addressed store, hash-verified

231 * plain text with a warning rather than as a button that would navigate nowhere.
232 */
233export function segmentsOf(line: string, cardIds: readonly string[]): AnswerSegment[] {
234 const known = new Set(cardIds);
235 const out: AnswerSegment[] = [];
236 const pattern = /\[[^\]]{1,80}\]/g;
237 let cursor = 0;
238 let match = pattern.exec(line);
239 while (match !== null) {
240 const ids = citationsIn(match[0]);
241 if (ids.length === 0) {
242 match = pattern.exec(line);
243 continue;
244 }
245 if (match.index > cursor) {
246 out.push({ kind: 'text', text: line.slice(cursor, match.index) });
247 }
248 for (const id of ids) {
249 out.push({ kind: 'citation', cardId: id, text: `[${id}]`, known: known.has(id) });
250 }
251 cursor = match.index + match[0].length;
252 match = pattern.exec(line);
253 }
254 if (cursor < line.length) {
255 out.push({ kind: 'text', text: line.slice(cursor) });
256 }
257 return out;
258}

Callers 2

TurnFunction · 0.90

Calls 2

citationsInFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected