{"version":3,"file":"plan-prompt.mjs","names":[],"sources":["../../../../../../../ai/src/planner/plan-prompt.ts"],"sourcesContent":["import type { PlannerCapability } from \"../contracts/planner/planner-capability.type\";\nimport type { SystemPromptContract } from \"../contracts/system-prompt.contract\";\n\n/**\n * Assemble the plan-generation system prompt: optional caller framing on\n * top, then the mechanical block listing every capability + its\n * description and the rules for emitting an ordered plan.\n *\n * Runs once at factory time (the capability set is fixed for the\n * planner's lifetime) — the produced string is baked onto the internal\n * planning agent.\n */\nexport function buildPlanSystemPrompt(\n  capabilities: PlannerCapability[],\n  maxSteps: number,\n  prefix: SystemPromptContract | string | undefined,\n  dag = false,\n): string {\n  const capabilityLines = capabilities.map(\n    (capability) => `- ${capability.name}: ${capability.description}`,\n  );\n\n  const sections: string[] = [];\n  const resolvedPrefix = resolvePrefix(prefix);\n\n  if (resolvedPrefix && resolvedPrefix.trim().length > 0) {\n    sections.push(resolvedPrefix.trim(), \"\");\n  }\n\n  sections.push(\n    \"You are a planner. Break the user's goal into an ordered sequence of steps,\",\n    \"each one dispatching exactly one of the available capabilities below.\",\n    \"\",\n    \"Available capabilities:\",\n    ...capabilityLines,\n    \"\",\n    \"Rules:\",\n    `- Produce at most ${maxSteps} steps.`,\n    \"- Each step's `capability` must be exactly one name from the list above.\",\n    \"- Each step's `input` is the concrete instruction passed to that capability.\",\n    \"- Order the steps so each builds on the outputs of the ones before it.\",\n    \"- Never invent a capability name that is not listed.\",\n    \"- Keep the plan minimal — only the steps actually needed to satisfy the goal.\",\n  );\n\n  if (dag) {\n    // DAG mode — the runtime schedules independent steps in parallel off\n    // `dependsOn`, so the model should declare dependencies explicitly\n    // rather than relying purely on array order.\n    sections.push(\n      \"- Give each step a stable `id` and list the ids it builds on in `dependsOn`.\",\n      \"- Steps with no `dependsOn` between them run in PARALLEL — only add a\",\n      \"  dependency when a step genuinely needs an earlier step's output.\",\n      \"- The plan must converge: avoid dependency cycles.\",\n    );\n  }\n\n  return sections.join(\"\\n\");\n}\n\n/**\n * Resolve a caller-supplied `systemPrompt` (string or contract) to plain\n * text. Returns `undefined` when none was supplied.\n */\nfunction resolvePrefix(prompt: SystemPromptContract | string | undefined): string | undefined {\n  if (!prompt) {\n    return undefined;\n  }\n\n  return typeof prompt === \"string\" ? prompt : prompt.resolve();\n}\n"],"mappings":";;;;;;;;;;AAYA,SAAgB,sBACd,cACA,UACA,QACA,MAAM,OACE;CACR,MAAM,kBAAkB,aAAa,KAClC,eAAe,KAAK,WAAW,KAAK,IAAI,WAAW,aACtD;CAEA,MAAM,WAAqB,CAAC;CAC5B,MAAM,iBAAiB,cAAc,MAAM;CAE3C,IAAI,kBAAkB,eAAe,KAAK,CAAC,CAAC,SAAS,GACnD,SAAS,KAAK,eAAe,KAAK,GAAG,EAAE;CAGzC,SAAS,KACP,+EACA,yEACA,IACA,2BACA,GAAG,iBACH,IACA,UACA,qBAAqB,SAAS,UAC9B,4EACA,gFACA,0EACA,wDACA,+EACF;CAEA,IAAI,KAIF,SAAS,KACP,gFACA,yEACA,sEACA,oDACF;CAGF,OAAO,SAAS,KAAK,IAAI;AAC3B;;;;;AAMA,SAAS,cAAc,QAAuE;CAC5F,IAAI,CAAC,QACH;CAGF,OAAO,OAAO,WAAW,WAAW,SAAS,OAAO,QAAQ;AAC9D"}