import { createHash } from "node:crypto"; import { homedir } from "node:os"; import { isAbsolute, join, normalize, resolve } from "node:path"; export function defaultPiStateDirectory(): string { return join(homedir(), ".pi", "agent"); } export function workflowWorkspaceId(workspacePath: string): string { const canonical = canonicalWorkspacePath(workspacePath); return createHash("sha256").update(canonical).digest("hex"); } export function workflowNamespaceDirectory( piStateDirectory: string, workspacePath: string, ): string { if (!isAbsolute(piStateDirectory)) { throw new TypeError("Pi state directory must be absolute"); } return join( normalize(piStateDirectory), "workspaces", workflowWorkspaceId(workspacePath), "pi-amq-workflow", ); } function canonicalWorkspacePath(workspacePath: string): string { if (!isAbsolute(workspacePath)) throw new TypeError("Workspace path must be absolute"); return normalize(resolve(workspacePath)); }