Files
oh-my-opencode/src/hooks/directory-readme-injector/finder.ts
T
MoerAI c298351d88 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
2026-02-11 19:23:42 +09:00

34 lines
861 B
TypeScript

import { existsSync } from "node:fs";
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 (isAbsolute(path)) return path;
return resolve(rootDirectory, path);
}
export function findReadmeMdUp(input: {
startDir: string;
rootDir: string;
}): string[] {
const found: string[] = [];
let current = input.startDir;
while (true) {
const readmePath = join(current, README_FILENAME);
if (existsSync(readmePath)) {
found.push(readmePath);
}
if (current === input.rootDir) break;
const parent = dirname(current);
if (parent === current) break;
if (!parent.startsWith(input.rootDir)) break;
current = parent;
}
return found.reverse();
}