UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 9.7 kB
import{l as normalizeOptionalString,o as normalizeLowercaseStringOrEmpty}from"./string-coerce-CpTFcSwY.mjs";import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import{h as normalizeUniqueSingleOrTrimmedStringList}from"./string-normalization-D_oBUpO3.mjs";import"./utils-Dlk0IYAa.mjs";import{i as matchRootFileOpenFailure}from"./boundary-file-read-bB9An35K.mjs";import{c as readPluginCacheFile,n as parsePluginCacheJson,o as pluginCacheStatSync,r as pluginCacheExistsSync}from"./plugin-cache-files-BGuripl0.mjs";import{o as normalizeManifestActivation,t as PLUGIN_MANIFEST_FILENAME}from"./manifest-D8YdMedM.mjs";import{t as DEFAULT_PLUGIN_ENTRY_CANDIDATES}from"./package-manifest-CMy2j7Hf.mjs";import{t as formatErrorMessage}from"./errors-D37BJTfI.mjs";import{t as createSubsystemLogger}from"./subsystem-DLCDFvCH.mjs";import{r as validatePluginRecommendedPrompts}from"./plugin-ui-capabilities--ltwiYc_.mjs";import"./src-DYE2urEz.mjs";import path from"node:path"; //!src/plugins/bundle-manifest.ts const CODEX_BUNDLE_MANIFEST_RELATIVE_PATH=`.codex-plugin/plugin.json`;const CLAUDE_BUNDLE_MANIFEST_RELATIVE_PATH=`.claude-plugin/plugin.json`;const CURSOR_BUNDLE_MANIFEST_RELATIVE_PATH=`.cursor-plugin/plugin.json`;const AGENT_BUNDLE_MANIFEST_RELATIVE_PATH=`plugin.json`;const BUNDLE_MANIFEST_PATHS={agent:AGENT_BUNDLE_MANIFEST_RELATIVE_PATH,claude:CLAUDE_BUNDLE_MANIFEST_RELATIVE_PATH,codex:CODEX_BUNDLE_MANIFEST_RELATIVE_PATH,cursor:CURSOR_BUNDLE_MANIFEST_RELATIVE_PATH};const AGENT_BUNDLE_EXTENSION_NAMESPACE=`ai.openclaw`;const AGENT_BUNDLE_MANIFEST_SCHEMA=`https://agent-plugins.org/schemas/1.0.0/plugin.schema.json`;const MAX_AGENT_BUNDLE_MANIFEST_BYTES=262144;const log=createSubsystemLogger(`plugins/bundle-manifest`);function mergeBundlePathLists(...e){return[...new Set(e.flat())]}function hasInlineCapabilityValue(e){if(typeof e===`string`)return e.trim().length>0;if(Array.isArray(e))return e.length>0;if(isRecord(e))return Object.keys(e).length>0;return e===true}function slugifyPluginId(e,t){const n=path.basename(t);return(normalizeLowercaseStringOrEmpty(e)||normalizeLowercaseStringOrEmpty(n)).replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)||`bundle-plugin`}function loadBundleManifestFile(e){const t=path.join(e.rootDir,e.manifestRelativePath);const n=readPluginCacheFile({rootDir:e.rootDir,rootRealPath:e.rootRealPath,relativePath:e.manifestRelativePath,rejectHardlinks:e.rejectHardlinks,maxBytes:MAX_AGENT_BUNDLE_MANIFEST_BYTES});if(!n.ok)return matchRootFileOpenFailure(n.failure,{path:()=>{if(e.allowMissing)return{ok:true,raw:{},manifestPath:t};return{ok:false,error:`plugin manifest not found: ${t}`,manifestPath:t}},fallback:e=>({ok:false,error:`unsafe plugin manifest path: ${t} (${e.reason})`,manifestPath:t})});const r=parsePluginCacheJson(n,{json5:!e.strictJson});if(!r.ok)return{ok:false,error:`failed to parse plugin manifest: ${formatErrorMessage(r.error)}`,manifestPath:t};if(!isRecord(r.value))return{ok:false,error:`plugin manifest must be an object`,manifestPath:t};return{ok:true,raw:r.value,manifestPath:t}}function resolveCodexComponentDirs(e,t,n){const r=normalizeUniqueSingleOrTrimmedStringList(e[n]);if(r.length>0)return r;return pluginCacheExistsSync(path.join(t,n))?[n]:[]}function resolveBundleComponentPaths(e,t,n){const r=normalizeUniqueSingleOrTrimmedStringList(e);return mergeBundlePathLists(n.filter(e=>pluginCacheExistsSync(path.join(t,e))),r)}function resolveCursorComponents(e,t){const n=resolveBundleComponentPaths(e.commands,t,[`.cursor/commands`]);const r=mergeBundlePathLists(resolveBundleComponentPaths(e.skills,t,[`skills`]),n);const i=resolveBundleComponentPaths(e.subagents??e.agents,t,[`.cursor/agents`]);const a=[...r.length>0?[`skills`]:[],...n.length>0?[`commands`]:[],...i.length>0?[`agents`]:[]];for(const[n,r]of[[`hooks`,`.cursor/hooks.json`],[`rules`,`.cursor/rules`],[`mcpServers`,`.mcp.json`]])if(hasInlineCapabilityValue(e[n])||pluginCacheExistsSync(path.join(t,r)))a.push(n);return{skills:r,capabilities:a}}function resolveAgentActivation(e,t){if(e.extensions===void 0)return;if(!isRecord(e.extensions)){log.warn(`ignoring Agent Plugins extensions in ${t}: expected an object`);return}const n=e.extensions[AGENT_BUNDLE_EXTENSION_NAMESPACE];if(n===void 0)return;if(!isRecord(n)){log.warn(`ignoring Agent Plugins ${AGENT_BUNDLE_EXTENSION_NAMESPACE} extension in ${t}: expected an object`);return}return normalizeManifestActivation(n.activation)}function loadBundleManifest(e){const t=e.rejectHardlinks??true;const n=e.bundleFormat===`codex`||e.bundleFormat===`cursor`||e.bundleFormat===`agent`?BUNDLE_MANIFEST_PATHS[e.bundleFormat]:CLAUDE_BUNDLE_MANIFEST_RELATIVE_PATH;const r=loadBundleManifestFile({rootDir:e.rootDir,...e.rootRealPath!==void 0?{rootRealPath:e.rootRealPath}:{},manifestRelativePath:n,rejectHardlinks:t,allowMissing:e.bundleFormat===`claude`,strictJson:e.bundleFormat===`agent`});if(!r.ok)return r;const i=r.raw;const a=isRecord(i.interface)?i.interface:void 0;const o=normalizeOptionalString(i.name);const s=normalizeOptionalString(i.description)??normalizeOptionalString(i.shortDescription)??normalizeOptionalString(a?.shortDescription);const c=normalizeOptionalString(i.version);const l={id:slugifyPluginId(o,e.rootDir),name:o,description:s,version:c,skills:[],settingsFiles:[],hooks:[],bundleFormat:e.bundleFormat,activation:void 0,capabilities:[]};if(e.bundleFormat===`agent`){if(i.$schema!==AGENT_BUNDLE_MANIFEST_SCHEMA)return{ok:false,error:`root plugin.json is not an Agent Plugins manifest; expected $schema ${AGENT_BUNDLE_MANIFEST_SCHEMA}`,manifestPath:r.manifestPath};if(!o)return{ok:false,error:`agent plugin manifest name must be a non-empty string`,manifestPath:r.manifestPath};l.skills=pluginCacheStatSync(path.join(e.rootDir,`skills`))?.isDirectory()?[`skills`]:[];l.activation=resolveAgentActivation(i,r.manifestPath);l.capabilities=[...l.skills.length>0?[`skills`]:[],...pluginCacheExistsSync(path.join(e.rootDir,`mcp.json`))?[`mcpServers`]:[]]}else{l.activation=normalizeManifestActivation(i.activation);if(e.bundleFormat===`codex`){l.skills=resolveCodexComponentDirs(i,e.rootDir,`skills`);l.hooks=resolveCodexComponentDirs(i,e.rootDir,`hooks`);l.capabilities=[...l.skills.length>0?[`skills`]:[],...l.hooks.length>0?[`hooks`]:[]];for(const[t,n]of[[`mcpServers`,`.mcp.json`],[`apps`,`.app.json`]])if(hasInlineCapabilityValue(i[t])||pluginCacheExistsSync(path.join(e.rootDir,n)))l.capabilities.push(t)}else if(e.bundleFormat===`cursor`)Object.assign(l,resolveCursorComponents(i,e.rootDir));else Object.assign(l,resolveClaudeComponents(i,e.rootDir))}const u=isRecord(i.extensions)?i.extensions:void 0;const d=isRecord(u?.[`com.openai`])?u[`com.openai`]:void 0;const f=(e.bundleFormat===`agent`?isRecord(d?.interface)?d.interface:void 0:e.bundleFormat===`codex`?a:void 0)?.defaultPrompt;const p=validatePluginRecommendedPrompts(typeof f===`string`?[f]:f);if(p.ok&&p.recommendedPrompts!==void 0)l.recommendedPrompts=p.recommendedPrompts;else if(!p.ok)log.warn(`ignoring invalid bundle interface.defaultPrompt in ${r.manifestPath}: ${p.error}`);const m=normalizeOptionalString(d?.onboardingSkill);if(m){const t=path.normalize(m);if(!path.isAbsolute(t)&&t!==`..`&&!t.startsWith(`..${path.sep}`)&&path.basename(t)===`SKILL.md`&&l.skills.some(n=>{const r=path.relative(path.resolve(e.rootDir,n),path.resolve(e.rootDir,t));return r!==`..`&&!r.startsWith(`..${path.sep}`)&&!path.isAbsolute(r)}))l.onboardingSkill=t}return{ok:true,manifest:l,manifestPath:r.manifestPath}}function resolveClaudeComponents(e,t){const n=resolveBundleComponentPaths(e.skills,t,[`skills`]);const r=resolveBundleComponentPaths(e.commands,t,[`commands`]);const i=resolveBundleComponentPaths(e.agents,t,[`agents`]);const a=resolveBundleComponentPaths(e.outputStyles,t,[`output-styles`]);const o=mergeBundlePathLists(n,r,i,a);const s=pluginCacheExistsSync(path.join(t,`settings.json`))?[`settings.json`]:[];const c=resolveBundleComponentPaths(e.hooks,t,[`hooks/hooks.json`]);return{skills:o,settingsFiles:s,hooks:c,capabilities:[...o.length>0?[`skills`]:[],...r.length>0?[`commands`]:[],...i.length>0?[`agents`]:[],...hasInlineCapabilityValue(e.hooks)||c.length>0?[`hooks`]:[],...hasInlineCapabilityValue(e.mcpServers)||resolveBundleComponentPaths(e.mcpServers,t,[`.mcp.json`]).length>0?[`mcpServers`]:[],...hasInlineCapabilityValue(e.lspServers)||resolveBundleComponentPaths(e.lspServers,t,[`.lsp.json`]).length>0?[`lspServers`]:[],...hasInlineCapabilityValue(e.outputStyles)||a.length>0?[`outputStyles`]:[],...s.length>0?[`settings`]:[]]}}function detectBundleManifestFormat(e){if(pluginCacheExistsSync(path.join(e,CODEX_BUNDLE_MANIFEST_RELATIVE_PATH)))return`codex`;if(pluginCacheExistsSync(path.join(e,CURSOR_BUNDLE_MANIFEST_RELATIVE_PATH)))return`cursor`;if(pluginCacheExistsSync(path.join(e,`.claude-plugin/plugin.json`)))return`claude`;if(pluginCacheExistsSync(path.join(e,`openclaw.plugin.json`)))return null;if(pluginCacheExistsSync(path.join(e,AGENT_BUNDLE_MANIFEST_RELATIVE_PATH))){const t=loadBundleManifestFile({rootDir:e,manifestRelativePath:AGENT_BUNDLE_MANIFEST_RELATIVE_PATH,rejectHardlinks:false,strictJson:true});if(t.ok&&t.raw.$schema===AGENT_BUNDLE_MANIFEST_SCHEMA)return`agent`}if(DEFAULT_PLUGIN_ENTRY_CANDIDATES.some(t=>pluginCacheExistsSync(path.join(e,t))))return null;if([path.join(e,`skills`),path.join(e,`commands`),path.join(e,`agents`),path.join(e,`hooks`,`hooks.json`),path.join(e,`.mcp.json`),path.join(e,`.lsp.json`),path.join(e,`settings.json`)].some(e=>pluginCacheExistsSync(e)))return`claude`;return null}export{mergeBundlePathLists as a,loadBundleManifest as i,CLAUDE_BUNDLE_MANIFEST_RELATIVE_PATH as n,resolveBundleComponentPaths as o,detectBundleManifestFormat as r,BUNDLE_MANIFEST_PATHS as t};