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

Function sourceQuote

graph-ui/src/architecture/repository-guide.ts:48–92  ·  view source on GitHub ↗
(path: string, source: string, start = 1)

Source from the content-addressed store, hash-verified

46
47/** Quote only repository-authored prose, never infer a responsibility from an identifier. */
48export function sourceQuote(path: string, source: string, start = 1): SourceQuote | undefined {
49 if (!Number.isSafeInteger(start) || start < 1) return undefined;
50 const lines = source.split('\n');
51 if (/(^|\/)readme\.(md|txt|rst)$/i.test(path)) {
52 let fenced = false;
53 for (let index = 0; index < lines.length; index++) {
54 const raw = lines[index].trim();
55 if (/^```|^~~~/.test(raw)) { fenced = !fenced; continue; }
56 if (fenced || !raw || /^(#|[!\[<|>]|[-=]{3})/.test(raw)) continue;
57 const text = plainMarkdown(raw);
58 if (text.length >= 45 && /[a-z]{3}\s+[a-z]{3}/i.test(text)) return { text: text.slice(0, 500), path, line: start + index, kind: 'readme' };
59 }
60 return undefined;
61 }
62 const first = lines.findIndex(line => line.trim() && !/^#!/.test(line.trim()));
63 if (first < 0) return undefined;
64 const firstText = lines[first].trim();
65 const hashComments = /\.(py|rb|sh|bash|zsh|yaml|yml|toml|r|pl|pm|ps1)$/i.test(path);
66 const block = firstText.startsWith('/*') ? ['/*', '*/']
67 : firstText.startsWith('"""') ? ['"""', '"""']
68 : firstText.startsWith("'''") ? ["'''", "'''"] : undefined;
69 const prefix = firstText.startsWith('//') ? '//'
70 : hashComments && firstText.startsWith('#') ? '#' : undefined;
71 if (!block && !prefix) return undefined;
72 const prose: { text: string; line: number }[] = [];
73 for (let index = first; index < Math.min(lines.length, first + 40); index++) {
74 let raw = lines[index].trim(), closed = false;
75 if (block) {
76 if (index === first) raw = raw.slice(block[0].length);
77 const end = raw.indexOf(block[1]);
78 if (end >= 0) { raw = raw.slice(0, end); closed = true; }
79 if (block[0] === '/*') raw = raw.replace(/^\*+\s?/, '');
80 } else {
81 if (!raw.startsWith(prefix!)) break;
82 raw = raw.slice(prefix!.length);
83 }
84 const text = raw.trim();
85 if (/copyright|SPDX|permission is hereby|licensed under|all rights reserved/i.test(text)) return undefined;
86 if (text) prose.push({ text, line: start + index });
87 if (closed) break;
88 }
89 if (!prose.length) return undefined;
90 const text = prose.map(row => row.text).join(' ');
91 return text.length >= 30 && /[a-z]{3}\s+[a-z]{3}/i.test(text) ? { text: text.slice(0, 550), path, line: prose[0].line, kind: 'header' } : undefined;
92}
93
94export interface StaticRoute { edges: MapEvidence[]; limited: boolean }
95/** A bounded actual CALLS walk. Imports and co-change never become execution steps. */

Callers 2

useRepositoryGuideFunction · 0.90

Calls 2

plainMarkdownFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected