import{t as e}from"./boolean-D15s2V33.js";import t from"node:path";import n from"node:fs";import r from"json5";import i from"yaml";const a=[],o=`openclaw`,s=a;function c(e){return e==null?!1:typeof e==`boolean`?e:typeof e==`number`?e!==0:typeof e==`string`?e.trim().length>0:!0}function l(e,t){let n=t.split(`.`).filter(Boolean),r=e;for(let e of n){if(typeof r!=`object`||!r)return;r=r[e]}return r}function u(e,t,n){let r=l(e,t);return r===void 0&&t in n?n[t]??!1:c(r)}function d(e){let t=e.requires;if(!t)return!0;let n=t.bins??[];if(n.length>0){for(let t of n)if(!e.hasBin(t)&&!e.hasRemoteBin?.(t))return!1}let r=t.anyBins??[];if(r.length>0&&!r.some(t=>e.hasBin(t))&&!e.hasAnyRemoteBin?.(r))return!1;let i=t.env??[];if(i.length>0){for(let t of i)if(!e.hasEnv(t))return!1}let a=t.config??[];if(a.length>0){for(let t of a)if(!e.isConfigPathTruthy(t))return!1}return!0}function f(e){let t=e.os??[],n=e.remotePlatforms??[];return t.length>0&&!t.includes(p())&&!n.some(e=>t.includes(e))?!1:e.always===!0?!0:d({requires:e.requires,hasBin:e.hasBin,hasRemoteBin:e.hasRemoteBin,hasAnyRemoteBin:e.hasAnyRemoteBin,hasEnv:e.hasEnv,isConfigPathTruthy:e.isConfigPathTruthy})}function p(){return process.platform}function m(){let e=process.env.PATHEXT;return[``,...(e===void 0?[`.EXE`,`.CMD`,`.BAT`,`.COM`]:e.split(`;`).map(e=>e.trim())).filter(Boolean)]}let h,g;const _=new Map;function v(e){let r=process.env.PATH??``,i=process.platform===`win32`?process.env.PATHEXT??``:``;if((h!==r||g!==i)&&(h=r,g=i,_.clear()),_.has(e))return _.get(e);let a=r.split(t.delimiter).filter(Boolean),o=process.platform===`win32`?m():[``];for(let r of a)for(let i of o){let a=t.join(r,e+i);try{return n.accessSync(a,n.constants.X_OK),_.set(e,!0),!0}catch{}}return _.set(e,!1),!1}function y(e){return e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`)?e.slice(1,-1):e}function b(e){if(e!=null){if(typeof e==`string`)return{value:e.trim(),kind:`scalar`};if(typeof e==`number`||typeof e==`boolean`)return{value:String(e),kind:`scalar`};if(typeof e==`object`)try{return{value:JSON.stringify(e),kind:`structured`}}catch{return}}}function x(e){try{let t=i.parse(e,{schema:`core`});if(!t||typeof t!=`object`||Array.isArray(t))return null;let n={};for(let[e,r]of Object.entries(t)){let t=e.trim();if(!t)continue;let i=b(r);i&&(n[t]=i)}return n}catch{return null}}function S(e,t){let n=[],r=t+1;for(;r<e.length;){let t=e[r];if(t.length>0&&!t.startsWith(` `)&&!t.startsWith(`	`))break;n.push(t),r+=1}return{value:n.join(`
`).trim(),linesConsumed:r-t}}function C(e){let t={},n=e.split(`
`),r=0;for(;r<n.length;){let e=n[r].match(/^([\w-]+):\s*(.*)$/);if(!e){r+=1;continue}let i=e[1],a=e[2].trim();if(!i){r+=1;continue}if(!a&&r+1<n.length){let e=n[r+1];if(e.startsWith(` `)||e.startsWith(`	`)){let{value:e,linesConsumed:o}=S(n,r);e&&(t[i]={value:e,kind:`multiline`,rawInline:a}),r+=o;continue}}let o=y(a);o&&(t[i]={value:o,kind:`inline`,rawInline:a}),r+=1}return t}function w(e){let t={};for(let[n,r]of Object.entries(e))t[n]=r.value;return t}function T(e){return/^[|>][+-]?(\d+)?[+-]?$/.test(e)}function E(e){let{lineEntry:t,yamlValue:n}=e;return n.kind!==`structured`||t.kind!==`inline`||T(t.rawInline)?!1:t.value.includes(`:`)}function D(e){let t=e.replace(/\r\n/g,`
`).replace(/\r/g,`
`);if(!t.startsWith(`---`))return;let n=t.indexOf(`
---`,3);if(n!==-1)return t.slice(4,n)}function O(e){let t=D(e);if(!t)return{};let n=C(t),r=x(t);if(r===null)return w(n);let i={};for(let[e,t]of Object.entries(r)){i[e]=t.value;let r=n[e];r&&E({lineEntry:r,yamlValue:t})&&(i[e]=r.value)}for(let[e,t]of Object.entries(n))e in i||(i[e]=t.value);return i}function k(e){return e?Array.isArray(e)?e.map(e=>String(e).trim()).filter(Boolean):typeof e==`string`?e.split(`,`).map(e=>e.trim()).filter(Boolean):[]:[]}function A(e,t){let n=e[t];return typeof n==`string`?n:void 0}function j(t,n){let r=e(t);return r===void 0?n:r}function M(e){let t=A(e.frontmatter,e.key??`metadata`);if(t)try{let e=r.parse(t);if(!e||typeof e!=`object`)return;let n=[o,...s];for(let t of n){let n=e[t];if(n&&typeof n==`object`)return n}return}catch{return}}function N(e){let t=typeof e.requires==`object`&&e.requires!==null?e.requires:void 0;if(t)return{bins:k(t.bins),anyBins:k(t.anyBins),env:k(t.env),config:k(t.config)}}function P(e,t){return(Array.isArray(e.install)?e.install:[]).map(e=>t(e)).filter(e=>!!e)}function F(e){return k(e.os)}function I(e,t){if(!e||typeof e!=`object`)return;let n=e,r=(typeof n.kind==`string`?n.kind:typeof n.type==`string`?n.type:``).trim().toLowerCase();if(!t.includes(r))return;let i={raw:n,kind:r};typeof n.id==`string`&&(i.id=n.id),typeof n.label==`string`&&(i.label=n.label);let a=k(n.bins);return a.length>0&&(i.bins=a),i}function L(e,t){return t.id&&(e.id=t.id),t.label&&(e.label=t.label),t.bins&&(e.bins=t.bins),e}export{I as a,F as c,f as d,v as f,j as i,N as l,o as m,A as n,M as o,u as p,k as r,P as s,L as t,O as u};
