earendil-works/pi · error · Error
Could not edit file: . Path is not a file.
Error message
Could not edit file: ${path}. Path is not a file. What it means
The edit tool's execute checks the target path and refuses when it exists but is not a regular file (directory, socket, symlink-to-directory, etc.). Exact text replacement only makes sense on file bytes, so non-file targets are rejected before any read or write is attempted.
Solutions
- Point the edit tool at a regular file, not a directory or a non-existent path.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/agent/src/harness/tools/edit.ts:110 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24).
Data as JSON: /api/errors/2a33f8f64454029e.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/harness/tools/edit.ts:110
typeof editSchema,
EditToolDetails | undefined
> {
return {
name: "edit",
label: "edit",
description:
"Edit a single file using exact text replacement. Every edits[].oldText must match a unique, non-overlapping region of the original file. If two changes affect the same block or nearby lines, merge them into one edit instead of emitting overlapping edits. Do not include large unchanged regions just to connect distant changes.",
parameters: editSchema,
prepareArguments: prepareEditArguments,
async execute(_toolCallId, input, signal, _onUpdate, { env }) {
const { path, edits } = validateEditInput(input);
const absolutePath = await resolveToolPath(env, path, signal);
return withFileMutationQueue(env, absolutePath, async () => {
if (signal?.aborted) throw new Error("Operation aborted");
const info = await env.fileInfo(absolutePath, signal);
if (!info.ok) throw editAccessError(path, info.error);
if (info.value.kind !== "file" && info.value.kind !== "symlink") {
throw new Error(`Could not edit file: ${path}. Path is not a file.`);
}
const readResult = await env.readTextFile(absolutePath, signal);
if (!readResult.ok) throw editAccessError(path, readResult.error);
if (signal?.aborted) throw new Error("Operation aborted");
const { bom, text: content } = stripBom(readResult.value);
const originalEnding = detectLineEnding(content);
const normalizedContent = normalizeToLF(content);
const { baseContent, newContent } = applyEditsToNormalizedContent(normalizedContent, edits, path);
if (signal?.aborted) throw new Error("Operation aborted");
const finalContent = bom + restoreLineEndings(newContent, originalEnding);
const writeResult = await env.writeFile(absolutePath, finalContent, signal);
if (!writeResult.ok) throw editAccessError(path, writeResult.error);
if (signal?.aborted) throw new Error("Operation aborted");
const diffResult = generateDiffString(baseContent, newContent);View on GitHub (pinned to 4af9d21d3b)