UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 3.26 kB
import{c as normalizeOptionalLowercaseString}from"./string-coerce-CpTFcSwY.mjs";import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{p as safeStat,t as canAccess}from"./path-existence-BR9MXlgL.mjs";import{t as collectConfiguredAgentHarnessRuntimes}from"./harness-runtimes-DQSA2gCi.mjs";import path from"node:path";import fs from"node:fs/promises";import os from"node:os"; //!src/commands/doctor/shared/codex-native-assets.ts const MAX_SCAN_DEPTH=6;const MAX_DISCOVERED_DIRS=2e3;function resolveUserHome(e){return e.HOME?.trim()||os.homedir()}function resolveHomePath(e,t){if(e===`~`)return resolveUserHome(t);if(e.startsWith(`~/`))return path.join(resolveUserHome(t),e.slice(2));return path.resolve(e)}function resolveCodexHome(e){return resolveHomePath(e.CODEX_HOME?.trim()||`~/.codex`,e)}function resolvePersonalAgentSkillsDir(e){return path.join(resolveUserHome(e),`.agents`,`skills`)}async function discoverDirectoryAssets(e,t){if(!(await safeStat(e))?.isDirectory())return[];const n=[];async function visit(e,r){if(n.length>=MAX_DISCOVERED_DIRS||r>MAX_SCAN_DEPTH)return;if(t===`skill`&&r===1&&path.basename(e)===`.system`)return;const i=t===`skill`?path.join(e,`SKILL.md`):path.join(e,`.codex-plugin`,`plugin.json`);if(await canAccess(i)){n.push({kind:t,path:e});return}for(const t of await fs.readdir(e,{withFileTypes:true}).catch(()=>[]))if(t.isDirectory())await visit(path.join(e,t.name),r+1)}await visit(e,0);return n}function isCodexPluginConfigured(e){const t=e.plugins;if(t?.enabled===false)return false;const n=t?.allow;if(Array.isArray(n))return n.some(e=>normalizeOptionalLowercaseString(e)===`codex`);return isRecord(t?.entries?.codex)&&t.entries.codex.enabled!==false}async function scanCodexNativeAssets(e){const t=e.env??process.env;if(!collectConfiguredAgentHarnessRuntimes(e.cfg).includes(`codex`)&&!isCodexPluginConfigured(e.cfg))return[];const n=resolveCodexHome(t);const r=/* @__PURE__ */ new Map;function record(e){r.set(`${e.kind}:${e.path}`,e)}for(const[e,r]of[[()=>path.join(n,`skills`),`skill`],[()=>resolvePersonalAgentSkillsDir(t),`skill`],[()=>path.join(n,`plugins`,`cache`),`plugin`]])for(const t of await discoverDirectoryAssets(e(),r))record(t);for(const[e,t]of[[`config`,`config.toml`],[`hooks`,path.join(`hooks`,`hooks.json`)]]){const r=path.join(n,t);if(await canAccess(r))record({kind:e,path:r})}return[...r.values()].toSorted((e,t)=>e.path.localeCompare(t.path))}async function collectCodexNativeAssetInfoNotes(e){const t=e.env??process.env;const n=await scanCodexNativeAssets({cfg:e.cfg,env:t});if(n.length===0)return[];return[[`- Personal Codex CLI assets found (${[[`skill`,`skill`],[`plugin`,`plugin`],[`config`,`config file`],[`hooks`,`hook file`]].map(([e,t])=>{const r=n.filter(t=>t.kind===e).length;return`${r} ${t}${r===1?``:`s`}`}).join(`, `)}) in ${resolveCodexHome(t)} and ${resolvePersonalAgentSkillsDir(t)}; native Codex-mode agents use isolated per-agent homes and will not load them.`,`- To review or promote them: install the Codex plugin (openclaw plugins install npm:@openclaw/codex), then run openclaw migrate plan codex.`].join(` `)]}if(process.env.VITEST||false)globalThis[Symbol.for(`openclaw.codexNativeAssetsTestApi`)]={scanCodexNativeAssets};export{collectCodexNativeAssetInfoNotes};