fix: anchor .sisyphus path check to ctx.directory to prevent false positives

- Uses path.join(ctx.directory, '.sisyphus') + sep as prefix instead of loose .includes()
- Prevents false positive when .sisyphus exists in parent directories outside project root
- Adds test for the false positive case (cubic review feedback)
This commit is contained in:
YeonGyu-Kim
2026-02-07 18:49:16 +09:00
parent 2e99e5382e
commit 31f03401b4
3 changed files with 36 additions and 16 deletions
+3 -2
View File
@@ -1,6 +1,6 @@
import type { Hooks, PluginInput } from "@opencode-ai/plugin"
import { existsSync } from "fs"
import { resolve, isAbsolute } from "path"
import { resolve, isAbsolute, join, sep } from "path"
import { log } from "../../shared"
export function createWriteExistingFileGuardHook(ctx: PluginInput): Hooks {
@@ -20,7 +20,8 @@ export function createWriteExistingFileGuardHook(ctx: PluginInput): Hooks {
const resolvedPath = isAbsolute(filePath) ? filePath : resolve(ctx.directory, filePath)
if (existsSync(resolvedPath)) {
const isSisyphusMarkdown = resolvedPath.replace(/\\/g, "/").includes("/.sisyphus/") && filePath.endsWith(".md")
const sisyphusRoot = join(ctx.directory, ".sisyphus") + sep
const isSisyphusMarkdown = resolvedPath.startsWith(sisyphusRoot) && resolvedPath.endsWith(".md")
if (isSisyphusMarkdown) {
log("[write-existing-file-guard] Allowing .sisyphus/*.md overwrite", {
sessionID: input.sessionID,