import fs from 'node:fs'; import path from 'node:path'; const system = `Your goal is to write a research report based on the given prompt. Use the \`submit-report\` function when you have gathered all information. You can only read from \`docs\` and from the source code directories \`backend/src\` and \`frontend/src\`. Exploration in any other location is forbidden. Only read up to 10 files. If more context is needed, submit the report regardless with all the information available. This is the breakpoint to work iteratively wit hthe user Note: task is terminated after 20 turns, reasoning traces are not persisted after agent turns. `; function resolvePrompt (input) { if (input.prompt) return input.prompt; const candidates = ['prompt.md', 'prompt.txt', 'prompt']; for (const name of candidates) { const file = path.resolve(Gral.path, '.gral', name); if (fs.existsSync(file)) { return fs.readFileSync(file, 'utf8'); } } throw new Error("Prompt required."); } function writeReport(content) { fs.writeFileSync(path.resolve(Gral.path, '.gral/report.md'), content); } export default async function research (input) { const prompt = resolvePrompt(input); let done = false; let res = await Gral.run({ instruction: system, input: prompt, agentId: 7, tools: [{ name: 'submit-report', description: 'Submit a markdown report as your task deliverable.', parameters: { type: 'object', properties: { content: { type: 'string' }, }, required: ['content'], }, handler: (args) => { done = true; writeReport(args.content); } }], read: ['docs', 'frontend/src', 'backend/src'], write: [], defaultTools: ['list-dir', 'read-file', 'find-files', 'search-files'], maxIter: 99, verify: () => done, }); console.log(res); };