diff --git a/packages/opencode/src/tool/write.ts b/packages/opencode/src/tool/write.ts index 6b134e5253de..c28e33667961 100644 --- a/packages/opencode/src/tool/write.ts +++ b/packages/opencode/src/tool/write.ts @@ -7,7 +7,6 @@ import DESCRIPTION from "./write.txt" import { Bus } from "../bus" import { File } from "../file" import { FileWatcher } from "../file/watcher" -import { Format } from "../format" import { FileTime } from "../file/time" import { Filesystem } from "../util/filesystem" import { Instance } from "../project/instance" @@ -42,9 +41,10 @@ export const WriteTool = Tool.define("write", { }, }) - await Filesystem.write(filepath, params.content) - await Format.file(filepath) - Bus.publish(File.Event.Edited, { file: filepath }) + await Filesystem.write(filepath, params.content, 0o644) + await Bus.publish(File.Event.Edited, { + file: filepath, + }) await Bus.publish(FileWatcher.Event.Updated, { file: filepath, event: exists ? "change" : "add", diff --git a/packages/opencode/src/util/filesystem.ts b/packages/opencode/src/util/filesystem.ts index 29f79e9587ae..465059278070 100644 --- a/packages/opencode/src/util/filesystem.ts +++ b/packages/opencode/src/util/filesystem.ts @@ -62,6 +62,9 @@ export namespace Filesystem { try { if (mode) { await writeFile(p, content, { mode }) + // writeFile mode is still filtered by process umask for newly created files, + // and won't update mode for existing files. Force the requested mode explicitly. + await chmod(p, mode) } else { await writeFile(p, content) } @@ -70,6 +73,7 @@ export namespace Filesystem { await mkdir(dirname(p), { recursive: true }) if (mode) { await writeFile(p, content, { mode }) + await chmod(p, mode) } else { await writeFile(p, content) }