diff --git a/apps/hook/server/index.ts b/apps/hook/server/index.ts index a046f924..3893e693 100644 --- a/apps/hook/server/index.ts +++ b/apps/hook/server/index.ts @@ -37,6 +37,7 @@ import { } from "@plannotator/server/annotate"; import { getGitContext, runGitDiff } from "@plannotator/server/git"; import { writeRemoteShareLink } from "@plannotator/server/share-url"; +import path from "path"; // Embed the built HTML at compile time // @ts-ignore - Bun import attribute for text @@ -111,15 +112,33 @@ if (args[0] === "review") { // ANNOTATE MODE // ============================================ - const filePath = args[1]; + let filePath = args[1]; if (!filePath) { console.error("Usage: plannotator annotate "); process.exit(1); } - // Resolve to absolute path - const path = await import("path"); - const absolutePath = path.resolve(filePath); + // Strip @ prefix if present (Claude Code file reference syntax) + if (filePath.startsWith("@")) { + filePath = filePath.slice(1); + } + + // Resolve path - use PLANNOTATOR_CWD if set (original working directory before script cd'd) + const originalCwd = process.env.PLANNOTATOR_CWD || process.cwd(); + + // Debug: log path resolution (visible in stderr, won't interfere with stdout JSON) + if (process.env.PLANNOTATOR_DEBUG) { + console.error(`[DEBUG] Original CWD: ${originalCwd}`); + console.error(`[DEBUG] File path arg: ${filePath}`); + } + + const absolutePath = path.isAbsolute(filePath) + ? filePath + : path.join(originalCwd, filePath); + + if (process.env.PLANNOTATOR_DEBUG) { + console.error(`[DEBUG] Resolved path: ${absolutePath}`); + } // Read the markdown file const file = Bun.file(absolutePath);