MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / answersTo

Function answersTo

scripts/regression/gate.mjs:270–299  ·  view source on GitHub ↗

Ask each question; for each, which named definitions the answer shows and how long it is.

(dir, questions)

Source from the content-addressed store, hash-verified

268
269/** Ask each question; for each, which named definitions the answer shows and how long it is. */
270async function answersTo(dir, questions) {
271 const cg = CodeGraph.openSync(dir);
272 const firstLine = (file, line) => {
273 try {
274 return (readFileSync(join(dir, file), 'utf8').split('\n')[line - 1] ?? '').trim();
275 } catch {
276 return '';
277 }
278 };
279 const answers = {};
280 try {
281 for (const [kind, question] of Object.entries(questions)) {
282 // A handler of its own for each: the engine leaves out what a session was already sent.
283 const result = await new ToolHandler(cg).execute('codegraph_explore', { query: question.query });
284 const text = result?.content?.[0]?.text ?? '';
285 answers[kind] = {
286 ...question,
287 shown: question.names.map(([, file, line]) => {
288 const text0 = firstLine(file, line);
289 return text0.length >= 4 && text.includes(text0);
290 }),
291 length: text.length,
292 nothing: /No relevant code found/.test(text.slice(0, 400)) || !!result?.isError,
293 };
294 }
295 } finally {
296 cg.close?.();
297 }
298 return answers;
299}
300
301// ---------------------------------------------------------------------------------------------
302// Growth

Callers 1

gate.mjsFile · 0.85

Calls 5

mapMethod · 0.80
firstLineFunction · 0.70
closeMethod · 0.65
openSyncMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected