import{t as e}from"./rolldown-runtime-CNxR59P3.js";import{cu as t}from"./auth-profiles-qXC1L8hs.js";import{t as n}from"./command-format-CLxIPuLR.js";import{_ as r,r as i}from"./onboard-helpers-DX-C8lCE.js";import{t as a}from"./skills-status-Bzj-kJgo.js";import{t as o}from"./skills-install-KEnmj18e.js";var s=e({setupSkills:()=>d});function c(e){let t=e.replace(/^Install failed(?:\s*\([^)]*\))?\s*:?\s*/i,``).trim();return t?t.length>140?`${t.slice(0,139)}…`:t:void 0}function l(e){let t=e.description?.trim(),n=e.install[0]?.label?.trim(),r=t&&n?`${t} — ${n}`:t||n;return r?r.length>90?`${r.slice(0,89)}…`:r:`install`}function u(e,t,n){let r={...e.skills?.entries};return r[t]={...r[t]??{},...n},{...e,skills:{...e.skills,entries:r}}}async function d(e,s,d,f){let p=a(s,{config:e}),m=p.skills.filter(e=>e.eligible),h=p.skills.filter(e=>!e.disabled&&!e.blockedByAllowlist&&e.missing.os.length>0),g=p.skills.filter(e=>!e.eligible&&!e.disabled&&!e.blockedByAllowlist&&e.missing.os.length===0),_=p.skills.filter(e=>e.blockedByAllowlist);if(await f.note([`Eligible: ${m.length}`,`Missing requirements: ${g.length}`,`Unsupported on this OS: ${h.length}`,`Blocked by allowlist: ${_.length}`].join(`
`),`Skills status`),!await f.confirm({message:`Configure skills now? (recommended)`,initialValue:!0}))return e;let v=g.filter(e=>e.install.length>0&&e.missing.bins.length>0),y=e;if(v.length>0){let e=(await f.multiselect({message:`Install missing skill dependencies`,options:[{value:`__skip__`,label:`Skip for now`,hint:`Continue without installing dependencies`},...v.map(e=>({value:e.name,label:`${e.emoji??`🧩`} ${e.name}`,hint:l(e)}))]})).filter(e=>e!==`__skip__`),t=e.map(e=>v.find(t=>t.name===e)).filter(e=>!!e);if(process.platform!==`win32`&&t.some(e=>e.install.some(e=>e.kind===`brew`))&&!await i(`brew`)&&(await f.note([`Many skill dependencies are shipped via Homebrew.`,`Without brew, you'll need to build from source or download releases manually.`].join(`
`),`Homebrew recommended`),await f.confirm({message:`Show Homebrew install command?`,initialValue:!0})&&await f.note([`Run:`,`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`].join(`
`),`Homebrew install`)),t.some(e=>e.install.some(e=>e.kind===`node`))){let e=await f.select({message:`Preferred node manager for skill installs`,options:r()});y={...y,skills:{...y.skills,install:{...y.skills?.install,nodeManager:e}}}}for(let t of e){let e=v.find(e=>e.name===t);if(!e||e.install.length===0)continue;let r=e.install[0]?.id;if(!r)continue;let i=f.progress(`Installing ${t}…`),a=await o({workspaceDir:s,skillName:e.name,installId:r,config:y}),l=a.warnings??[];if(a.ok){i.stop(l.length>0?`Installed ${t} (with warnings)`:`Installed ${t}`);for(let e of l)d.log(e);continue}let u=a.code==null?``:` (exit ${a.code})`,p=c(a.message);i.stop(`Install failed: ${t}${u}${p?` — ${p}`:``}`);for(let e of l)d.log(e);a.stderr?d.log(a.stderr.trim()):a.stdout&&d.log(a.stdout.trim()),d.log(`Tip: run \`${n(`openclaw doctor`)}\` to review skills + requirements.`),d.log(`Docs: https://docs.openclaw.ai/skills`)}}for(let e of g){if(!e.primaryEnv||e.missing.env.length===0||!await f.confirm({message:`Set ${e.primaryEnv} for ${e.name}?`,initialValue:!1}))continue;let n=String(await f.text({message:`Enter ${e.primaryEnv}`,validate:e=>e?.trim()?void 0:`Required`}));y=u(y,e.skillKey,{apiKey:t(n)})}return y}export{d as n,s as t};
