{"version":3,"file":"pruning.d.ts","sourceRoot":"","sources":["../../../src/core/evaluation/pruning.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,uBAAuB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAErF,MAAM,WAAW,WAAW;IAC3B,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,uBAAuB,CAAC;CAClC;AA4BD,wBAAsB,oBAAoB,CACzC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,EAChB,MAAM,GAAE,yBAA+D,EACvE,QAAQ,CAAC,EAAE,uBAAuB,GAChC,OAAO,CAAC,WAAW,CAAC,CAwCtB","sourcesContent":["import { mkdir, readdir, rm, rmdir } from \"node:fs/promises\";\nimport { join, resolve } from \"node:path\";\nimport { createPruneManifest, DEFAULT_EVALUATION_RETENTION_POLICY } from \"./retention.js\";\nimport type { EvaluationPruneManifest, EvaluationRetentionPolicy } from \"./types.js\";\n\nexport interface PruneReport {\n\tmode: \"preview\" | \"execute\";\n\troot: string;\n\tdeleted: string[];\n\tretained: string[];\n\tmutationCount: number;\n\tmanifest: EvaluationPruneManifest;\n}\n\nasync function acquireWriterLease(root: string): Promise<() => Promise<void>> {\n\tconst lease = join(root, \".prune-writer.lock\");\n\tawait mkdir(lease, { recursive: false }).catch((error: unknown) => {\n\t\tthrow new Error(\n\t\t\t`artifact store writer lease unavailable: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t});\n\treturn async () => {\n\t\tawait rmdir(lease).catch(() => undefined);\n\t};\n}\n\nfunction assertManifestMatches(expected: EvaluationPruneManifest, actual: EvaluationPruneManifest): void {\n\tconst expectedEntries = JSON.stringify({\n\t\tentries: expected.entries,\n\t\tprotectedEntries: expected.protectedEntries,\n\t\tpolicyVersion: expected.policyVersion,\n\t});\n\tconst actualEntries = JSON.stringify({\n\t\tentries: actual.entries,\n\t\tprotectedEntries: actual.protectedEntries,\n\t\tpolicyVersion: actual.policyVersion,\n\t});\n\tif (expectedEntries !== actualEntries) throw new Error(\"prune precondition failed: store changed after preview\");\n}\n\nexport async function pruneEvaluationStore(\n\troot: string,\n\texecute: boolean,\n\tpolicy: EvaluationRetentionPolicy = DEFAULT_EVALUATION_RETENTION_POLICY,\n\tmanifest?: EvaluationPruneManifest,\n): Promise<PruneReport> {\n\tconst storeRoot = resolve(root);\n\tawait mkdir(storeRoot, { recursive: true });\n\tconst current = await createPruneManifest(storeRoot, policy);\n\tif (!execute) {\n\t\treturn {\n\t\t\tmode: \"preview\",\n\t\t\troot: storeRoot,\n\t\t\tdeleted: current.entries.map((entry) => join(storeRoot, entry.artifactId)).sort(),\n\t\t\tretained: current.protectedEntries.map((entry) => entry.artifactId).sort(),\n\t\t\tmutationCount: 0,\n\t\t\tmanifest: current,\n\t\t};\n\t}\n\tif (!manifest) throw new Error(\"prune execute requires a preview manifest\");\n\tassertManifestMatches(manifest, current);\n\tconst release = await acquireWriterLease(storeRoot);\n\ttry {\n\t\tconst deleted: string[] = [];\n\t\tfor (const entry of current.entries) {\n\t\t\tif (!entry.artifactId.startsWith(\"temporary/\")) continue;\n\t\t\tconst path = join(storeRoot, entry.artifactId);\n\t\t\tawait rm(path, { recursive: true, force: true });\n\t\t\tdeleted.push(path);\n\t\t}\n\t\tconst remaining = await readdir(join(storeRoot, \"temporary\"), { withFileTypes: true }).catch(() => []);\n\t\treturn {\n\t\t\tmode: \"execute\",\n\t\t\troot: storeRoot,\n\t\t\tdeleted: deleted.sort(),\n\t\t\tretained: [\n\t\t\t\t...current.protectedEntries.map((entry) => entry.artifactId),\n\t\t\t\t...remaining.map((entry) => `temporary/${entry.name}`),\n\t\t\t].sort(),\n\t\t\tmutationCount: deleted.length,\n\t\t\tmanifest: current,\n\t\t};\n\t} finally {\n\t\tawait release();\n\t}\n}\n"]}