import{stripLogicalPathExtension}from"#discover/filesystem.js";import{normalizeInstructionsDefinition}from"#internal/authored-definition/core.js";import{loadModuleBackedDefinition}from"#compiler/normalize-helpers.js";import{isDynamicSentinel}from"#shared/dynamic-tool-definition.js";async function compileInstructionsEntry(r,i){if(i.sourceKind===`markdown`){let n=normalizeInstructionsDefinition(i.definition,`Expected the compiled instructions definition at "${i.logicalPath}" to match the public Eve shape.`);return{kind:`instructions`,definition:{name:stripLogicalPathExtension(i.logicalPath),logicalPath:i.logicalPath,markdown:n.markdown,sourceId:i.sourceId,sourceKind:i.sourceKind}}}let a=await loadModuleBackedDefinition({agentRoot:r,kind:`instructions`,source:i});if(isDynamicSentinel(a)){let t=stripLogicalPathExtension(i.logicalPath).replace(/^instructions\//,``);return{kind:`dynamic-instructions`,definition:{eventNames:Object.keys(a.events),exportName:i.exportName,logicalPath:i.logicalPath,slug:t,sourceId:i.sourceId,sourceKind:`module`}}}let o=normalizeInstructionsDefinition(a,`Expected the instructions export "${i.exportName??`default`}" from "${i.logicalPath}" to match the public Eve shape.`);return{kind:`instructions`,definition:{name:stripLogicalPathExtension(i.logicalPath),logicalPath:i.logicalPath,markdown:o.markdown,sourceId:i.sourceId,sourceKind:i.sourceKind}}}async function compileInstructions(e,t){let n=await compileInstructionsEntry(e,t);if(n.kind===`dynamic-instructions`)throw Error(`Expected static instructions from "${t.logicalPath}" but got a dynamic resolver. Use compileInstructionsEntry instead.`);return n.definition}export{compileInstructions,compileInstructionsEntry};