MCPcopy Create free account
hub / github.com/promptfoo/promptfoo / writeFile

Function writeFile

src/util/agent/fsOperations.ts:45–60  ·  view source on GitHub ↗
(
  filePath: string,
  content: string,
  rootDir: string,
)

Source from the content-addressed store, hash-verified

43 * (e.g., DSL-to-JS compilation) does not require additional gating.
44 */
45export async function writeFile(
46 filePath: string,
47 content: string,
48 rootDir: string,
49): Promise<string> {
50 const resolved = await resolveAndValidate(filePath, rootDir);
51 const ext = path.extname(resolved).toLowerCase();
52 if (!ALLOWED_WRITE_EXTENSIONS.includes(ext)) {
53 throw new Error(
54 `Write rejected: only ${ALLOWED_WRITE_EXTENSIONS.join(', ')} files are allowed`,
55 );
56 }
57 await fs.mkdir(path.dirname(resolved), { recursive: true });
58 await fs.writeFile(resolved, content, 'utf-8');
59 return resolved;
60}
61
62/**
63 * Read a file relative to rootDir. Truncates returned text at MAX_FILE_SIZE

Callers 1

attachTargetLinkFsFunction · 0.90

Calls 1

resolveAndValidateFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…