{"version":3,"file":"write-pack.d.ts","sourceRoot":"","sources":["../../../src/pack/templates/write-pack.ts"],"names":[],"mappings":"AAMA,OAAO,EAA2B,KAAK,eAAe,EAAwB,MAAM,YAAY,CAAC;AAEjG,MAAM,WAAW,oBAAoB;IACpC,iDAAiD;IACjD,EAAE,EAAE,MAAM,CAAC;IACX,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,mBAAmB;IACnC,QAAQ,EAAE,eAAe,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACtC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CA4C9B","sourcesContent":["import { mkdir, mkdtemp, readFile, rm, writeFile } from \"node:fs/promises\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { publishEvoComponentArtifact } from \"../../components/artifact.ts\";\nimport { composeWorkflowEntrypoint } from \"../../components/workflow-sdk/index.ts\";\nimport { getEvoPaths } from \"../../paths.ts\";\nimport { computeEvoPackIntegrity, type EvoPackManifest, parseEvoPackManifest } from \"../pack.ts\";\n\nexport interface WorkflowPackTemplate {\n\t/** Workflow component id, also the pack name. */\n\tid: string;\n\t/** Slash trigger, e.g. \"/deep-review\". */\n\ttrigger: string;\n\tversion: string;\n\tdescription: string;\n\t/** Author script body; composed with the workflow SDK prelude. */\n\tbody: string;\n}\n\nexport interface WrittenWorkflowPack {\n\tmanifest: EvoPackManifest;\n\tintegrity: string;\n}\n\n/**\n * Write a complete, importable single-workflow optimization pack into\n * `directory`: the composed workflow artifact plus an integrity-signed\n * pack.json. The staging component store is temporary and removed.\n */\nexport async function writeWorkflowPack(\n\tdirectory: string,\n\ttemplate: WorkflowPackTemplate,\n): Promise<WrittenWorkflowPack> {\n\tconst staging = await mkdtemp(join(tmpdir(), `pi-evo-${template.id}-pack-`));\n\ttry {\n\t\tconst artifact = await publishEvoComponentArtifact(getEvoPaths(join(staging, \"evo\")), {\n\t\t\tid: template.id,\n\t\t\tversion: template.version,\n\t\t\tabi: \"workflow/v1\",\n\t\t\tactivationBoundary: \"invocation\",\n\t\t\tcapabilities: [\"spawn-agent\"],\n\t\t\tentrypointContent: await composeWorkflowEntrypoint(template.body),\n\t\t});\n\t\tconst artifactDirectory = join(directory, \"workflows\", template.id);\n\t\tawait mkdir(artifactDirectory, { recursive: true });\n\t\tawait writeFile(\n\t\t\tjoin(artifactDirectory, \"manifest.json\"),\n\t\t\tawait readFile(join(artifact.directory, \"manifest.json\")),\n\t\t);\n\t\tawait writeFile(join(artifactDirectory, artifact.manifest.entrypoint), await readFile(artifact.entrypoint));\n\t\tconst unsigned = parseEvoPackManifest({\n\t\t\tpackFormat: 1,\n\t\t\tname: template.id,\n\t\t\tversion: template.version,\n\t\t\tdescription: template.description,\n\t\t\tcontents: {\n\t\t\t\tworkflows: [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: template.id,\n\t\t\t\t\t\ttrigger: template.trigger,\n\t\t\t\t\t\tabi: \"workflow/v1\",\n\t\t\t\t\t\tartifact: `workflows/${template.id}`,\n\t\t\t\t\t\tcapabilities: [\"spawn-agent\"],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\trequiresAbis: [\"workflow/v1\"],\n\t\t\trequiresCapabilities: [\"spawn-agent\"],\n\t\t});\n\t\tconst integrity = await computeEvoPackIntegrity(directory, unsigned);\n\t\tconst manifest: EvoPackManifest = { ...unsigned, integrity };\n\t\tawait writeFile(join(directory, \"pack.json\"), `${JSON.stringify(manifest, undefined, \"\\t\")}\\n`);\n\t\treturn { manifest, integrity };\n\t} finally {\n\t\tawait rm(staging, { recursive: true, force: true });\n\t}\n}\n"]}