Description
POST /api/file/save can never create a new file. Any save request whose target path does not already exist returns 404 File not found before the write happens. Only overwriting existing files works.
Source evidence
Audited against the 0.4.12 source preview (release/extraction.json sourceRevision 9b9885e42a3cf1a3df1cfa52a46e4fdb034cfcee); line numbers refer to that revision.
- The save route passes
resolveBodyPath to the handler: packages/local-runtime/src/files/api.ts:557-559.
resolveBodyPath calls resolveExistingWorkspacePath: packages/local-runtime/src/files/api.ts:1950-1960.
resolveExistingWorkspacePath runs realpath(target) and maps the resulting ENOENT to a 404 File not found response: packages/local-runtime/src/files/api.ts:1997-2002.
- The handler itself clearly intends to create files:
packages/local-runtime/src/files/save.ts:23-25 does mkdir(dirname(target.absolute), { recursive: true }) followed by writeFile(...) — both dead code for new files because the 404 short-circuits first.
So the mkdir + writeFile creation path is unreachable for any nonexistent target.
Expected behavior
Saving to a new path creates the file (that is what the recursive mkdir in the handler is for).
Actual behavior
Saving to a new path returns 404 {"error":"File not found"}.
Suggested fix
Give the save route a resolver that allows a non-existing leaf: resolve the parent directory with realpath, validate containment against the workspace root, then append the leaf name. resolveExistingWorkspacePath is the right resolver for read/open/reveal routes, but not for a write that is expected to create.
Environment
Found by source audit; not runtime-reproduced yet. The relevant code paths are small and self-contained, so the trace above should be quick to confirm.
Description
POST /api/file/savecan never create a new file. Any save request whose target path does not already exist returns404 File not foundbefore the write happens. Only overwriting existing files works.Source evidence
Audited against the 0.4.12 source preview (
release/extraction.jsonsourceRevision9b9885e42a3cf1a3df1cfa52a46e4fdb034cfcee); line numbers refer to that revision.resolveBodyPathto the handler:packages/local-runtime/src/files/api.ts:557-559.resolveBodyPathcallsresolveExistingWorkspacePath:packages/local-runtime/src/files/api.ts:1950-1960.resolveExistingWorkspacePathrunsrealpath(target)and maps the resultingENOENTto a 404File not foundresponse:packages/local-runtime/src/files/api.ts:1997-2002.packages/local-runtime/src/files/save.ts:23-25doesmkdir(dirname(target.absolute), { recursive: true })followed bywriteFile(...)— both dead code for new files because the 404 short-circuits first.So the
mkdir + writeFilecreation path is unreachable for any nonexistent target.Expected behavior
Saving to a new path creates the file (that is what the recursive
mkdirin the handler is for).Actual behavior
Saving to a new path returns
404 {"error":"File not found"}.Suggested fix
Give the save route a resolver that allows a non-existing leaf: resolve the parent directory with
realpath, validate containment against the workspace root, then append the leaf name.resolveExistingWorkspacePathis the right resolver for read/open/reveal routes, but not for a write that is expected to create.Environment
Found by source audit; not runtime-reproduced yet. The relevant code paths are small and self-contained, so the trace above should be quick to confirm.