Ask each question; for each, which named definitions the answer shows and how long it is.
(dir, questions)
| 268 | |
| 269 | /** Ask each question; for each, which named definitions the answer shows and how long it is. */ |
| 270 | async 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 |