UNPKG

@phren/cli

Version:

Knowledge layer for AI agents - CLI, MCP server, and data layer

42 lines (41 loc) • 1.94 kB
import * as path from "path"; import { phrenErr, phrenOk, readRootManifest } from "../shared.js"; import { bootstrapFromExisting } from "./project-registry.js"; import { resolveActiveProfile } from "../profile-store.js"; import { FINDINGS_FILENAME, TASKS_FILENAME } from "../filenames.js"; export function addProjectFromPath(phrenPath, targetPath, requestedProfile, ownership, options = {}) { if (!targetPath) { return phrenErr("Path is required. Pass the current project directory explicitly to avoid adding the wrong working directory."); } const activeProfile = resolveActiveProfile(phrenPath, requestedProfile); if (!activeProfile.ok) return activeProfile; const writePhrenPath = options.writeToPath ?? phrenPath; const manifest = readRootManifest(phrenPath); const resolvedPath = path.resolve(targetPath); if (manifest?.installMode === "project-local") { const workspaceRoot = path.resolve(manifest.workspaceRoot || ""); const matchesWorkspace = resolvedPath === workspaceRoot || resolvedPath.startsWith(workspaceRoot + path.sep); if (!matchesWorkspace) { return phrenErr(`Project-local phren can only add the owning workspace: ${workspaceRoot}`); } } const selectedProfile = activeProfile.data; const added = bootstrapFromExisting(writePhrenPath, resolvedPath, { profile: selectedProfile, profilePhrenPath: phrenPath, ownership, }); return phrenOk({ project: added.project, path: resolvedPath, profile: selectedProfile ?? null, ownership: added.ownership, files: { claude: added.claudePath, summary: path.join(writePhrenPath, added.project, "summary.md"), findings: path.join(writePhrenPath, added.project, FINDINGS_FILENAME), task: path.join(writePhrenPath, added.project, TASKS_FILENAME), }, }); }