import{t as e}from"./subsystem-hyY_8Y33.js";import{t}from"./boolean-DypnRoRK.js";import n from"node:path";import r from"node:fs";import i from"json5";import a from"yaml";const o=globalThis,s=o.__openclaw_internal_hook_handlers__??=new Map,c=e(`internal-hooks`);function l(e,t){s.has(e)||s.set(e,[]),s.get(e).push(t)}async function u(e){let t=s.get(e.type)??[],n=s.get(`${e.type}:${e.action}`)??[],r=[...t,...n];if(r.length!==0)for(let t of r)try{await t(e)}catch(t){let n=t instanceof Error?t.message:String(t);c.error(`Hook error [${e.type}:${e.action}]: ${n}`)}}function d(e,t,n,r={}){return{type:e,action:t,sessionKey:n,context:r,timestamp:new Date,messages:[]}}function f(e,t,n){return e.type===t&&e.action===n}function p(e){let t=e.context;return!t||typeof t!=`object`?null:t}function m(e,t){return typeof e[t]==`string`}function h(e){if(!f(e,`agent`,`bootstrap`))return!1;let t=p(e);return!t||!m(t,`workspaceDir`)?!1:Array.isArray(t.bootstrapFiles)}function g(e){return f(e,`gateway`,`startup`)?!!p(e):!1}const _=[],v=`openclaw`,y=_;function b(e){return e==null?!1:typeof e==`boolean`?e:typeof e==`number`?e!==0:typeof e==`string`?e.trim().length>0:!0}function x(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 S(e,t,n){let r=x(e,t);return r===void 0&&t in n?n[t]??!1:b(r)}function C(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 w(e){let t=e.os??[],n=e.remotePlatforms??[];return t.length>0&&!t.includes(T())&&!n.some(e=>t.includes(e))?!1:e.always===!0?!0:C({requires:e.requires,hasBin:e.hasBin,hasRemoteBin:e.hasRemoteBin,hasAnyRemoteBin:e.hasAnyRemoteBin,hasEnv:e.hasEnv,isConfigPathTruthy:e.isConfigPathTruthy})}function T(){return process.platform}function E(){let e=process.env.PATHEXT;return[``,...(e===void 0?[`.EXE`,`.CMD`,`.BAT`,`.COM`]:e.split(`;`).map(e=>e.trim())).filter(Boolean)]}let D,O;const k=new Map;function A(e){let t=process.env.PATH??``,i=process.platform===`win32`?process.env.PATHEXT??``:``;if((D!==t||O!==i)&&(D=t,O=i,k.clear()),k.has(e))return k.get(e);let a=t.split(n.delimiter).filter(Boolean),o=process.platform===`win32`?E():[``];for(let t of a)for(let i of o){let a=n.join(t,e+i);try{return r.accessSync(a,r.constants.X_OK),k.set(e,!0),!0}catch{}}return k.set(e,!1),!1}function j(e){return e.startsWith(`"`)&&e.endsWith(`"`)||e.startsWith(`'`)&&e.endsWith(`'`)?e.slice(1,-1):e}function M(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 N(e){try{let t=a.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=M(r);i&&(n[t]=i)}return n}catch{return null}}function P(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 F(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}=P(n,r);e&&(t[i]={value:e,kind:`multiline`,rawInline:a}),r+=o;continue}}let o=j(a);o&&(t[i]={value:o,kind:`inline`,rawInline:a}),r+=1}return t}function I(e){let t={};for(let[n,r]of Object.entries(e))t[n]=r.value;return t}function L(e){return/^[|>][+-]?(\d+)?[+-]?$/.test(e)}function R(e){let{lineEntry:t,yamlValue:n}=e;return n.kind!==`structured`||t.kind!==`inline`||L(t.rawInline)?!1:t.value.includes(`:`)}function z(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 B(e){let t=z(e);if(!t)return{};let n=F(t),r=N(t);if(r===null)return I(n);let i={};for(let[e,t]of Object.entries(r)){i[e]=t.value;let r=n[e];r&&R({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 V(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 H(e,t){let n=e[t];return typeof n==`string`?n:void 0}function U(e,n){let r=t(e);return r===void 0?n:r}function W(e){let t=H(e.frontmatter,e.key??`metadata`);if(t)try{let e=i.parse(t);if(!e||typeof e!=`object`)return;let n=[v,...y];for(let t of n){let n=e[t];if(n&&typeof n==`object`)return n}return}catch{return}}function G(e){let t=typeof e.requires==`object`&&e.requires!==null?e.requires:void 0;if(t)return{bins:V(t.bins),anyBins:V(t.anyBins),env:V(t.env),config:V(t.config)}}function K(e,t){return(Array.isArray(e.install)?e.install:[]).map(e=>t(e)).filter(e=>!!e)}function q(e){return V(e.os)}function J(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=V(n.bins);return a.length>0&&(i.bins=a),i}function Y(e,t){return t.id&&(e.id=t.id),t.label&&(e.label=t.label),t.bins&&(e.bins=t.bins),e}export{g as _,J as a,q as c,w as d,A as f,h as g,d as h,U as i,G as l,v as m,H as n,W as o,S as p,V as r,K as s,Y as t,B as u,l as v,u as y};
