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

Function chooseQuestions

scripts/regression/gate.mjs:238–267  ·  view source on GitHub ↗

Questions about a project, from the names its own index holds: two names, three in a sentence, eight.

(dir, sets)

Source from the content-addressed store, hash-verified

236
237/** Questions about a project, from the names its own index holds: two names, three in a sentence, eight. */
238function chooseQuestions(dir, sets) {
239 const db = new DatabaseSync(join(dir, '.codegraph', 'codegraph.db'), { readOnly: true });
240 const rows = db
241 .prepare("SELECT name, file_path AS file, start_line AS line, end_line AS last FROM nodes WHERE kind NOT IN ('file','import','export','parameter') ORDER BY file_path, start_line, name")
242 .all();
243 db.close();
244 const defined = new Map();
245 for (const row of rows) defined.set(row.name, (defined.get(row.name) ?? 0) + 1);
246 const asked = sets > 1 ? rows.filter((row) => !/(^|\/)(__tests__|tests?|fixtures?|node_modules|dist|target|vendor|docs?)\//.test(row.file) && !/\.(test|spec)\./.test(row.file)) : rows;
247 const eligible = asked.filter((row) => WRITTEN_AS_CODE.test(row.name) && /^[\p{L}\p{N}_$]+$/u.test(row.name) && row.name.length >= 3 && defined.get(row.name) <= 3);
248 const bodied = eligible.filter((row) => row.last > row.line);
249 const seen = new Set();
250 const unique = (bodied.length >= 8 ? bodied : eligible).filter((row) => !seen.has(row.name) && seen.add(row.name));
251 const questions = {};
252 for (let set = 0; set < sets; set++) {
253 const chosen = [];
254 const take = Math.min(8, unique.length);
255 for (let at = 0; at < take; at++) {
256 const row = unique[(Math.floor((at * (unique.length - 1)) / Math.max(1, take - 1)) + set * 37) % unique.length];
257 if (!chosen.some((each) => each.name === row.name)) chosen.push(row);
258 }
259 const named = (count) => chosen.slice(0, count).map((row) => [row.name, row.file, row.line]);
260 const key = (kind) => (sets > 1 ? `${kind}#${set}` : kind);
261 const names = chosen.map((row) => row.name);
262 if (names.length >= 2) questions[key('two')] = { query: `${names[0]} ${names[1]}`, names: named(2) };
263 if (names.length >= 3) questions[key('three')] = { query: `how does ${names[0]} use ${names[1]} and ${names[2]}`, names: named(3) };
264 if (names.length >= 8) questions[key('eight')] = { query: names.join(' '), names: named(8) };
265 }
266 return questions;
267}
268
269/** Ask each question; for each, which named definitions the answer shows and how long it is. */
270async function answersTo(dir, questions) {

Callers 1

gate.mjsFile · 0.85

Calls 13

hasMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
keyFunction · 0.70
namedFunction · 0.70
allMethod · 0.65
prepareMethod · 0.65
closeMethod · 0.65
getMethod · 0.65
joinFunction · 0.50
setMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected