9b0335165f
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
39 lines
1.1 KiB
TypeScript
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();
|
|
}
|