/** * 金蝶业务项目初始化和产品画像路径。 * 产品画像存储在 .trellis/spec/shared/project-context.md 中。 */ import * as fs from "node:fs"; import * as path from "node:path"; export const TRELLIS_SPEC_DIR = path.join(".trellis", "spec"); export const TRELLIS_PROJECT_SPEC = path.join(TRELLIS_SPEC_DIR, "shared", "project-context.md"); /** @deprecated 仅兼容读取旧 Trellis spec 路径 */ export const LEGACY_TRELLIS_PROJECT_SPEC = path.join(TRELLIS_SPEC_DIR, "project", "index.md"); /** @deprecated 仅兼容读取旧项目 */ export const OPENSPEC_DIR = "OpenSpec"; /** @deprecated 仅兼容读取旧 OpenSpec */ export function openspecDir(cwd: string): string { return path.join(cwd, OPENSPEC_DIR); } /** @deprecated 仅兼容读取旧 OpenSpec */ export function openspecProjectMdPath(cwd: string): string { return path.join(openspecDir(cwd), "project.md"); } /** @deprecated 仅兼容读取旧 OpenSpec */ export function openspecRoadmapPath(cwd: string): string { return path.join(openspecDir(cwd), "roadmap.md"); } /** 读取产品画像:Trellis spec → legacy Trellis spec → OpenSpec */ export function resolveProjectMdPath(cwd: string): string | undefined { const trellis = path.join(cwd, TRELLIS_PROJECT_SPEC); if (fs.existsSync(trellis)) return trellis; const legacyTrellis = path.join(cwd, LEGACY_TRELLIS_PROJECT_SPEC); if (fs.existsSync(legacyTrellis)) return legacyTrellis; const openSpec = openspecProjectMdPath(cwd); if (fs.existsSync(openSpec)) return openSpec; return undefined; } /** 写入产品画像:已有优先,否则新建 .trellis/spec/shared/project-context.md */ export function projectMdWritePath(cwd: string): string { const trellis = path.join(cwd, TRELLIS_PROJECT_SPEC); if (fs.existsSync(trellis)) return trellis; const legacyTrellis = path.join(cwd, LEGACY_TRELLIS_PROJECT_SPEC); if (fs.existsSync(legacyTrellis)) return legacyTrellis; const openSpec = openspecProjectMdPath(cwd); if (fs.existsSync(openSpec)) return openSpec; return trellis; }