Files
orcs-code/src/utils/projectInstructions.ts
ZhaoXiaoLuo b3f3dc4e66 Prefer AGENTS.md over CLAUDE.md for project instructions (#439)
* Prefer AGENTS.md over CLAUDE.md for project instructions

* fix: preserve CLAUDE.md fallback behavior

* fix: isolate onboarding tests and preserve legacy init

* fix: restore full fsOperations exports in test mock and align compact cwd

* Fix onboarding test isolation and init migration guidance

* Tighten init prompt coverage and onboarding copy

* Handle nested project instruction paths consistently

* Fix NEW_INIT feature gate for Bun build

---------

Co-authored-by: 赵小落 <zhaoxiaoluo@zhaoxiaoluodeMac-mini.local>
Co-authored-by: zhaomo01 <zhaomo01@baidu.com>
2026-04-12 21:31:33 +08:00

56 lines
1.4 KiB
TypeScript

import { dirname, join } from 'path'
export const PRIMARY_PROJECT_INSTRUCTION_FILE = 'AGENTS.md'
export const FALLBACK_PROJECT_INSTRUCTION_FILE = 'CLAUDE.md'
export function getProjectInstructionFilePaths(dir: string): string[] {
return [
join(dir, PRIMARY_PROJECT_INSTRUCTION_FILE),
join(dir, FALLBACK_PROJECT_INSTRUCTION_FILE),
]
}
export function getProjectInstructionFilePath(
dir: string,
existsSync: (path: string) => boolean,
): string {
const [primaryPath, fallbackPath] = getProjectInstructionFilePaths(dir)
return existsSync(primaryPath)
? primaryPath
: fallbackPath
}
export function hasProjectInstructionFile(
dir: string,
existsSync: (path: string) => boolean,
): boolean {
return getProjectInstructionFilePaths(dir).some(path => existsSync(path))
}
export function findProjectInstructionFilePathInAncestors(
startDir: string,
existsSync: (path: string) => boolean,
): string | null {
let currentDir = startDir
while (true) {
if (hasProjectInstructionFile(currentDir, existsSync)) {
return getProjectInstructionFilePath(currentDir, existsSync)
}
const parentDir = dirname(currentDir)
if (parentDir === currentDir) {
return null
}
currentDir = parentDir
}
}
export function isProjectInstructionFileName(name: string): boolean {
return (
name === PRIMARY_PROJECT_INSTRUCTION_FILE ||
name === FALLBACK_PROJECT_INSTRUCTION_FILE
)
}