Files
oh-my-opencode/src/hooks/directory-agents-injector/finder.ts
T
MoerAI 9b0335165f 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

39 lines
1.1 KiB
TypeScript

import { existsSync } from "node:fs";
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 (isAbsolute(path)) return path;
return resolve(rootDirectory, path);
}
export function findAgentsMdUp(input: {
startDir: string;
rootDir: string;
}): string[] {
const found: string[] = [];
let current = input.startDir;
while (true) {
// Skip root AGENTS.md - OpenCode's system.ts already loads it via custom()
// See: https://github.com/code-yeongyu/oh-my-opencode/issues/379
const isRootDir = current === input.rootDir;
if (!isRootDir) {
const agentsPath = join(current, AGENTS_FILENAME);
if (existsSync(agentsPath)) {
found.push(agentsPath);
}
}
if (isRootDir) break;
const parent = dirname(current);
if (parent === current) break;
if (!parent.startsWith(input.rootDir)) break;
current = parent;
}
return found.reverse();
}