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 { dirname, join, resolve } from "node:path"
|
||||||
|
|
||||||
import { createWriteExistingFileGuardHook } from "./index"
|
import { createWriteExistingFileGuardHook } from "./index"
|
||||||
|
import { isOmoWorkspacePath } from "./tool-execute-before-handler"
|
||||||
|
|
||||||
const BLOCK_MESSAGE = "File already exists. Use edit tool instead."
|
const BLOCK_MESSAGE = "File already exists. Use edit tool instead."
|
||||||
|
|
||||||
@@ -255,6 +256,14 @@ describe("createWriteExistingFileGuardHook", () => {
|
|||||||
).resolves.toBeDefined()
|
).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 () => {
|
test("#given file arg variants #when read then write executes #then supports all variants", async () => {
|
||||||
const existingFile = createFile("variants.txt")
|
const existingFile = createFile("variants.txt")
|
||||||
const variants: Array<"filePath" | "path" | "file_path"> = [
|
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: {
|
export async function handleWriteExistingFileGuardToolExecuteBefore(params: {
|
||||||
ctx: PluginInput
|
ctx: PluginInput
|
||||||
input: { tool?: string; sessionID?: string }
|
input: { tool?: string; sessionID?: string }
|
||||||
@@ -149,8 +153,7 @@ export async function handleWriteExistingFileGuardToolExecuteBefore(params: {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const isOmoPath = canonicalPath.includes("/.omo/")
|
if (isOmoWorkspacePath(canonicalPath)) {
|
||||||
if (isOmoPath) {
|
|
||||||
log("[write-existing-file-guard] Allowing .omo/** overwrite", {
|
log("[write-existing-file-guard] Allowing .omo/** overwrite", {
|
||||||
sessionID: input.sessionID,
|
sessionID: input.sessionID,
|
||||||
filePath,
|
filePath,
|
||||||
|
|||||||
Reference in New Issue
Block a user