fix(workspace): match omo guard paths cross-platform
This commit is contained in:
@@ -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"> = [
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user