UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

6 lines • 4.15 kB
import{t as formatCliCommand}from"./command-format-D7KhNLP0.mjs";import{i as listAgentIds}from"./agent-roster-4XrgUgPK.mjs";import{f as resolveAgentWorkspaceDir}from"./agent-scope-config-CG9CFpGX.mjs";import"./agent-scope-Dw5XRSEh.mjs";import{t as note}from"./note-e4DtVgg2.mjs";import{n as buildWorkspaceSkillStatus}from"./status-CZBiav9O.mjs";import{r as shouldAutoApproveDoctorFix}from"./doctor-repair-mode-Dilz8sGs.mjs";import{n as disableUnavailableSkillsInConfig,t as collectUnavailableAgentSkills}from"./doctor-skills-core-CXmCIN9K.mjs";import{existsSync}from"node:fs";import{posix,win32}from"node:path"; //!src/commands/doctor-skills.ts function describeGhConfigDirHint(e){const t=e.find(e=>e.name===`github`);if(!t?.eligible||t.blockedByAgentFilter)return[];const n=process.env;if(n.GH_CONFIG_DIR?.trim())return[];const r=process.platform;const i=r===`win32`?win32:posix;const a=n.XDG_CONFIG_HOME?.trim();const o=n.APPDATA?.trim();const s=n.USERPROFILE?.trim();const c=n.HOME?.trim();const l=a?i.join(a,`gh`):r===`win32`&&o?i.join(o,`GitHub CLI`):r===`win32`&&s?i.join(s,`AppData`,`Roaming`,`GitHub CLI`):c?i.join(c,`.config`,`gh`):void 0;if(!l||existsSync(i.join(l,`hosts.yml`)))return[];const u=/* @__PURE__ */ new Set;if(r!==`win32`)u.add(`/root`);const d=n.SUDO_USER?.trim();if(d){u.add(i.join(`/home`,d));if(r===`darwin`)u.add(i.join(`/Users`,d))}const f=n.USER?.trim();if(f&&f!==`root`){if(r===`darwin`)u.add(i.join(`/Users`,f));else if(r!==`win32`)u.add(i.join(`/home`,f))}if(c)u.delete(c);for(const e of u){const t=i.join(e,`.config`,`gh`);if(t!==l&&existsSync(i.join(t,`hosts.yml`)))return[`GitHub CLI auth was found at a different HOME than the one this OpenClaw process uses.`,` Process gh config dir: ${l}`,` Authenticated config: ${t} (contains hosts.yml)`,` Authenticated HOME: ${e}`,` Fix: set GH_CONFIG_DIR=${t} on the OpenClaw service environment, then restart the gateway.`]}return[]}async function maybeRepairSkillReadiness(e){const t=listAgentIds(e.cfg);const n=t.map(t=>({agentId:t,workspaceDir:resolveAgentWorkspaceDir(e.cfg,t)})).map(({agentId:t,workspaceDir:n})=>{const buildReport=()=>{const r=buildWorkspaceSkillStatus(n,{config:e.cfg,agentId:t});return{agentId:t,skills:r.skills,unavailable:collectUnavailableAgentSkills(r)}};return e.runWithPluginMetadataSnapshot?e.runWithPluginMetadataSnapshot({config:e.cfg,workspaceDir:n},buildReport):buildReport()});const r=new Set(n.flatMap(({skills:e})=>e.filter(e=>!e.blockedByAgentFilter&&(e.eligible||e.missing.bins.length>0||e.missing.anyBins.length>0)).map(e=>e.skillKey)));const i=/* @__PURE__ */ new Map;for(const e of n.flatMap(({unavailable:e})=>e))if(!r.has(e.skillKey))i.set(e.skillKey,e);const a=[...i.values()];const o=new Set(a.map(e=>e.skillKey));const s=shouldAutoApproveDoctorFix(e.prompter.repairMode,{blockDuringUpdate:true});for(const{agentId:e,skills:r,unavailable:i}of n){const n=t.length>1?`Agent "${e}":\n`:``;const a=describeGhConfigDirHint(r);if(a.length>0)note(`${n}${a.join(` `)}`,`GitHub CLI`);if(i.length>0){const e=i.some(e=>o.has(e.skillKey));const t=i.length;const r=[`${t} allowed skill${t===1?` is`:`s are`} not usable in this environment (missing binaries, env vars, or config).`,`- ${i.map(e=>e.name).toSorted((e,t)=>e.localeCompare(t)).join(`, `)}`];if(i.some(e=>e.missing.bins.length>0||e.missing.anyBins.length>0))r.push(`Missing local binaries may exist on paired nodes; these skills remain enabled.`);if(e&&!s)r.push(`Disable unused skills: ${formatCliCommand(`openclaw doctor --fix`)}`);r.push(`Inspect details: ${formatCliCommand(`openclaw skills check --agent <id>`)} or ${formatCliCommand(`openclaw skills info <name> --agent <id>`)}`);note(`${n}${r.join(` `)}`,`Skills`)}}if(a.length===0)return e.cfg;if(!await e.prompter.confirmRuntimeRepair({message:t.length===1?`Disable ${a.length} unavailable skill${a.length===1?``:`s`} in config?`:`Disable ${a.length} skill${a.length===1?``:`s`} unavailable to every configured agent?`,initialValue:false}))return e.cfg;const c=disableUnavailableSkillsInConfig(e.cfg,a);note(a.map(e=>`- Disabled ${e.name}`).join(` `),`Doctor changes`);return c}export{maybeRepairSkillReadiness};