Redesign project codebase configuration

This commit is contained in:
Dotta 2026-03-16 15:56:37 -05:00
parent dd828e96ad
commit 9b7b90521f
9 changed files with 389 additions and 176 deletions

View file

@ -4,6 +4,7 @@ import path from "node:path";
const DEFAULT_INSTANCE_ID = "default";
const INSTANCE_ID_RE = /^[a-zA-Z0-9_-]+$/;
const PATH_SEGMENT_RE = /^[a-zA-Z0-9_-]+$/;
const FRIENDLY_PATH_SEGMENT_RE = /[^a-zA-Z0-9._-]+/g;
function expandHomePrefix(value: string): string {
if (value === "~") return os.homedir();
@ -61,6 +62,34 @@ export function resolveDefaultAgentWorkspaceDir(agentId: string): string {
return path.resolve(resolvePaperclipInstanceRoot(), "workspaces", trimmed);
}
function sanitizeFriendlyPathSegment(value: string | null | undefined, fallback = "_default"): string {
const trimmed = value?.trim() ?? "";
if (!trimmed) return fallback;
const sanitized = trimmed
.replace(FRIENDLY_PATH_SEGMENT_RE, "-")
.replace(/^-+|-+$/g, "");
return sanitized || fallback;
}
export function resolveManagedProjectWorkspaceDir(input: {
companyId: string;
projectId: string;
repoName?: string | null;
}): string {
const companyId = input.companyId.trim();
const projectId = input.projectId.trim();
if (!companyId || !projectId) {
throw new Error("Managed project workspace path requires companyId and projectId.");
}
return path.resolve(
resolvePaperclipInstanceRoot(),
"projects",
sanitizeFriendlyPathSegment(companyId, "company"),
sanitizeFriendlyPathSegment(projectId, "project"),
sanitizeFriendlyPathSegment(input.repoName, "_default"),
);
}
export function resolveHomeAwarePath(value: string): string {
return path.resolve(expandHomePrefix(value));
}