import{AGENTS as e}from"../definitions/agents.mjs";import{AGENT_BODIES as t}from"../definitions/bodies.mjs";import{MCP_SERVER_ENTRY as n,SERVER_NAME as r}from"../definitions/mcp.mjs";import{getAgentModelConfig as i}from"../definitions/models.mjs";import{PROTOCOLS as a}from"../definitions/protocols.mjs";import{buildCompactAgentTable as o,buildSkillsSection as s,lowerFirst as c}from"./_shared.mjs";function l(e,t){let n=t.args.map(e=>JSON.stringify(e)).join(`, `);return`[mcp_servers.${e}]\ncommand = ${JSON.stringify(t.command)}\nargs = [${n}]\n`}function u(e){return e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/[^a-zA-Z0-9]+/g,`-`).replace(/^-+|-+$/g,``).toLowerCase()}function d(e){return JSON.stringify(String(e))}function f(e){let t=String(e).replace(/\r\n/g,`
`).trim();return t?`"""\n${t}\n"""`:`""`}function p(e,n){let r=t[e];return typeof r==`function`?r(n):r||``}function m(e){let t=[];e.extraBody&&t.push(e.extraBody),e.sharedBase&&a[e.sharedBase]&&t.push(a[e.sharedBase]);for(let n of e.sharedProtocols||[])a[n]&&t.push(a[n]);return t}function h({name:e,description:t,identity:n,body:r,skills:i,additionalSections:a}){return[n?`You are the **${e}**${n}`:`You are the **${e}**, ${c(t)}.`,r,...a||[],s(i)].filter(Boolean).join(`

`).trim()}function g({name:e,description:t,developerInstructions:n,modelConfig:r}){let i=[`name = ${d(e)}`,`description = ${d(t)}`];return r?.primary&&i.push(`model = ${d(r.primary)}`),r?.reasoningEffort&&i.push(`model_reasoning_effort = ${d(r.reasoningEffort)}`),i.push(`developer_instructions = ${f(n)}`,``),i.join(`
`)}function _(){let t=[],n=o(e);for(let[r,a]of Object.entries(e)){let e=p(r,n),o=m(a);if(a.variants){for(let[n,s]of Object.entries(a.variants)){let c=`${r}-${n}`,l=u(c),d=s.description||a.description;t.push({path:`.codex/agents/${l}.toml`,content:g({name:l,description:d,modelConfig:i(`codex`,c),developerInstructions:h({name:c,description:d,identity:s.identity,body:e,skills:a.skills,additionalSections:[...o,s.bodyAddendum].filter(Boolean)})})})}continue}let s=u(r);t.push({path:`.codex/agents/${s}.toml`,content:g({name:s,description:a.description,modelConfig:i(`codex`,r),developerInstructions:h({name:r,description:a.description,identity:a.identity,body:e,skills:a.skills,additionalSections:o})})})}return t}function v(){return[{path:`.codex/config.toml`,content:l(r,n)},..._()]}export{v as generateCodex};