diff --git a/src/hooks/write-existing-file-guard/index.test.ts b/src/hooks/write-existing-file-guard/index.test.ts index d1d222788..588c083fc 100644 --- a/src/hooks/write-existing-file-guard/index.test.ts +++ b/src/hooks/write-existing-file-guard/index.test.ts @@ -4,6 +4,7 @@ import { tmpdir } from "node:os" import { dirname, join, resolve } from "node:path" import { createWriteExistingFileGuardHook } from "./index" +import { isOmoWorkspacePath } from "./tool-execute-before-handler" const BLOCK_MESSAGE = "File already exists. Use edit tool instead." @@ -255,6 +256,14 @@ describe("createWriteExistingFileGuardHook", () => { ).resolves.toBeDefined() }) + test("#given canonical paths #when checking .omo workspace segment #then supports Windows separators", () => { + expect(isOmoWorkspacePath(".omo/plans/plan.txt")).toBe(true) + expect(isOmoWorkspacePath("/repo/.omo/plans/plan.txt")).toBe(true) + expect(isOmoWorkspacePath(String.raw`C:\repo\.omo\plans\plan.txt`)).toBe(true) + expect(isOmoWorkspacePath("/repo/work.omo/plans/plan.txt")).toBe(false) + expect(isOmoWorkspacePath(String.raw`C:\repo\.omo-backup\plans\plan.txt`)).toBe(false) + }) + test("#given file arg variants #when read then write executes #then supports all variants", async () => { const existingFile = createFile("variants.txt") const variants: Array<"filePath" | "path" | "file_path"> = [ diff --git a/src/hooks/write-existing-file-guard/tool-execute-before-handler.ts b/src/hooks/write-existing-file-guard/tool-execute-before-handler.ts index db2ade562..09f094948 100644 --- a/src/hooks/write-existing-file-guard/tool-execute-before-handler.ts +++ b/src/hooks/write-existing-file-guard/tool-execute-before-handler.ts @@ -85,6 +85,10 @@ function invalidateOtherSessions( } } +export function isOmoWorkspacePath(canonicalPath: string): boolean { + return /(^|[/\\])\.omo([/\\]|$)/.test(canonicalPath) +} + export async function handleWriteExistingFileGuardToolExecuteBefore(params: { ctx: PluginInput input: { tool?: string; sessionID?: string } @@ -149,8 +153,7 @@ export async function handleWriteExistingFileGuardToolExecuteBefore(params: { return } - const isOmoPath = canonicalPath.includes("/.omo/") - if (isOmoPath) { + if (isOmoWorkspacePath(canonicalPath)) { log("[write-existing-file-guard] Allowing .omo/** overwrite", { sessionID: input.sessionID, filePath,