Skip to content

Commit c298351

Browse files
committed
fix(hooks): use path.isAbsolute() for cross-platform path detection
Replace path.startsWith('/') with path.isAbsolute() in directory injector hooks. The startsWith('/') check only works on Unix-like systems where absolute paths begin with '/'. On Windows, absolute paths start with drive letters (e.g., C:\), causing resolveFilePath to incorrectly treat them as relative and prepend the project directory. This follows the same pattern already used in src/features/claude-tasks/storage.ts (commit 8e349aa). Affected hooks: - directory-agents-injector: AGENTS.md injection - directory-readme-injector: README.md injection
1 parent 2df61a2 commit c298351

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/hooks/directory-agents-injector/finder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { existsSync } from "node:fs";
2-
import { dirname, join, resolve } from "node:path";
2+
import { dirname, isAbsolute, join, resolve } from "node:path";
33

44
import { AGENTS_FILENAME } from "./constants";
55

66
export function resolveFilePath(rootDirectory: string, path: string): string | null {
77
if (!path) return null;
8-
if (path.startsWith("/")) return path;
8+
if (isAbsolute(path)) return path;
99
return resolve(rootDirectory, path);
1010
}
1111

src/hooks/directory-readme-injector/finder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { existsSync } from "node:fs";
2-
import { dirname, join, resolve } from "node:path";
2+
import { dirname, isAbsolute, join, resolve } from "node:path";
33

44
import { README_FILENAME } from "./constants";
55

66
export function resolveFilePath(rootDirectory: string, path: string): string | null {
77
if (!path) return null;
8-
if (path.startsWith("/")) return path;
8+
if (isAbsolute(path)) return path;
99
return resolve(rootDirectory, path);
1010
}
1111

0 commit comments

Comments
 (0)