Review this generated loader before it supplies repository context to an agent.
Load requested UTF-8 source files from one workspace, reject invalid budgets, keep reads inside the workspace, include only complete sections that fit, and return truthful freshness metadata.
JavaScript
import { readFile } from "node:fs/promises";
export async function buildContext(
workspace,
requested,
maxCharacters,
) {
const included = [];
let text = "";
for (const name of requested) {
const source = await readFile(`${workspace}/${name}`, "utf8");
included.push(name);
text += `\n## ${name}\n${source}`;
}
const clipped = text.slice(0, maxCharacters);
return { text: clipped, files: included, fresh: true };
}
generated code is illustrative, not from any one model