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
This commit is contained in:
MoerAI 2026-02-06 17:23:11 +09:00
parent 2df61a2199
commit c298351d88
2 changed files with 4 additions and 4 deletions

View File

@ -1,11 +1,11 @@
import { existsSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { dirname, isAbsolute, join, resolve } from "node:path";
import { AGENTS_FILENAME } from "./constants";
export function resolveFilePath(rootDirectory: string, path: string): string | null {
if (!path) return null;
if (path.startsWith("/")) return path;
if (isAbsolute(path)) return path;
return resolve(rootDirectory, path);
}

View File

@ -1,11 +1,11 @@
import { existsSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { dirname, isAbsolute, join, resolve } from "node:path";
import { README_FILENAME } from "./constants";
export function resolveFilePath(rootDirectory: string, path: string): string | null {
if (!path) return null;
if (path.startsWith("/")) return path;
if (isAbsolute(path)) return path;
return resolve(rootDirectory, path);
}