@crewx/sdk 0.9.0-rc.126 → 0.9.0-rc.127

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- 'use strict';var Qn=require('crypto'),C=require('fs'),B=require('path'),li=require('js-yaml'),promises=require('fs/promises'),hi=require('os'),_i=require('tar'),zlib=require('zlib');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var Qn__namespace=/*#__PURE__*/_interopNamespace(Qn);var C__namespace=/*#__PURE__*/_interopNamespace(C);var B__namespace=/*#__PURE__*/_interopNamespace(B);var li__namespace=/*#__PURE__*/_interopNamespace(li);var hi__namespace=/*#__PURE__*/_interopNamespace(hi);var _i__namespace=/*#__PURE__*/_interopNamespace(_i);var D=class extends Error{constructor(t,i=t,o){super(i);this.code=t;this.currentRevision=o;}code;currentRevision;name="UiRuntimeError"};var xi=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,wi=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i,Ci=/<\/?[A-Za-z][^>]*>/,vi=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,Vi=/^(?:https?|file|ftp|ws|wss):\/\//i;function W(){throw new D("INPUT_INVALID","JSON value is not projection-safe")}function Fi(e){let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var ji=8,Bi=4;function ln(e,n,t,i,o,r){if(n>i&&W(),e===null||typeof e=="string"||typeof e=="boolean")return typeof e=="string"&&(Ci.test(e)||Vi.test(e)&&!Hi(o,r)||vi.test(e))&&W(),e;if(typeof e=="number")return Number.isFinite(e)||W(),e;(typeof e!="object"||e===void 0||typeof e=="function"||typeof e=="bigint")&&W();let s=e;t.has(s)&&W(),t.add(s);try{if(Array.isArray(e))return e.map(c=>ln(c,n+1,t,i,o,r));Fi(s)||W();let a={};for(let[c,p]of Object.entries(e))(xi.test(c)||wi.test(c))&&W(),a[c]=ln(p,n+1,t,i,[...o,c],r);return a}finally{t.delete(s);}}function se(e,n=0,t=[]){(!Number.isInteger(n)||n<0||n>Bi)&&W(),(!Array.isArray(t)||t.some(o=>typeof o!="string"))&&W();let i=ln(e,0,new Set,ji+n,[],t);return (i===null||Array.isArray(i)||typeof i!="object")&&W(),i}function Ie(e,n){if(!e||!n)return false;let t=e.split("."),i=n.split(".");return t.length>=i.length&&i.every((o,r)=>t[r]===o)}function Hi(e,n){if(e.length===0)return false;let t=e.join(".");return n.some(i=>Ie(t,i))}function me(e){try{let n=JSON.stringify(e);return n===void 0&&W(),n}catch{W();}}function un(e){return Array.isArray(e)?e.map(un):e!==null&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,un(e[n])])):e}function J(e){return me(un(e))}function fn(e){return Buffer.byteLength(e,"utf8")}function yn(e){return J(e)}var ae="window";var it=["__proto__","prototype","constructor","proof","token","secret","password","cookie","authorization","private_key","private-key","stack","exception","plugin_text","url","uri","endpoint","path","filename","filepath","cwd","shell","directory","dir","folder"],zi=new Set(it),Gi=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,$i=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i;function he(e){return zi.has(e)||Gi.test(e)||$i.test(e)}var Fe=/^[A-Za-z0-9_]+$/,Le=/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/,Ee=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,An=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,gn=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,In=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/,mn=["blue","violet","emerald","amber","rose","sky","slate","indigo"],hn=["inline","panel"];var Wi=1,Ji=/^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$/,Ki=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,ft=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,Xi=/<\/?[A-Za-z][^>]*>/,Yi=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,qi=/^(?:https?|file|ftp|ws|wss):\/\//i,Zi=/^\s*(?:javascript|data):/i,ot=/data:[^,\s]*,/i,Qi=/(?:https?|file|ftp|ws|wss):\/\//i,eo=/javascript:/i,no=/(?:^[\s]*|[\s"'(=])(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)(?=[^\s"'<>])[^\s"'<>]*/,to=["manifestVersion","pluginId","definitionId","version","primitiveSet","activation","schema","layout"],io=["manifestVersion","pluginId","definitionId","version","name","description","entry","surfaces","size","stateProjection","actions"],oo=["_meta","icon","tone","entryHash","initialState","usage","detailPanel","displayModes","dataPaths","focusedAiDataPaths"],ro=["actionId","capability","mutation","inputSchema","resultProjection","backend"],so=["confirmation","dataInputs","_meta"],ao=4*1024,co=["type","handler"],po=["type","command"],lo=["path"],uo=["hash"],fo=/^[0-9a-f]{64}$/,yo=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/,Ao=/[\r\n]/,go=16,Io=["card-shell","meta-banner","heading","labeled-text","step-flow","text-list"],G=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="UiPluginValidationError"};function d(e,n=e){throw new G(e,n)}function k(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function S(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function x(e,n,t=[]){let i=new Set([...n,...t]);Object.keys(e).some(o=>!i.has(o))&&d("MANIFEST_INVALID"),n.some(o=>!S(e,o))&&d("MANIFEST_INVALID");}function Ge(e,n=false,t=false,i=false){return Xi.test(e)||!i&&qi.test(e)||Yi.test(e)||t&&ot.test(e)||Zi.test(e)&&!(n&&/^\s*data:/i.test(e)&&!ot.test(e))}function He(e,n=new Set,t=0,i=false,o=false){if(typeof e=="string"){Ge(e,i,o)&&d("UNSAFE_VALUE");return}if(!(e===null||typeof e!="object")){(t>8||n.has(e))&&d("MANIFEST_INVALID"),n.add(e);try{if(Array.isArray(e)){for(let r of e)He(r,n,t+1);return}k(e)||d("MANIFEST_INVALID");for(let[r,s]of Object.entries(e))He(s,n,t+1,i&&t===0&&(r==="name"||r==="description"),o);}finally{n.delete(e);}}}function Z(e,n){let t=e[n];return typeof t!="string"&&d("MANIFEST_INVALID"),t}function q(e,n,t){let i=e[n];return (!Number.isSafeInteger(i)||i<t)&&d("MANIFEST_INVALID"),i}function En(e){return Ki.test(e)||d("MANIFEST_INVALID"),e}function _e(e){return Ji.test(e)||d("TOKEN_INVALID"),e}function mo(e){return ft.test(e)||d("MANIFEST_INVALID"),e}function ho(e){k(e)||d("MANIFEST_INVALID");let n={};for(let[t,i]of Object.entries(e)){let o=mo(t);k(i)||d("MANIFEST_INVALID");let r=i.type;if(r==="text"){x(i,["type","maxLength"]),n[o]={type:r,maxLength:q(i,"maxLength",1)};continue}if(r==="text-list"){x(i,["type","max","itemMaxLength"]),n[o]={type:r,max:q(i,"max",0),itemMaxLength:q(i,"itemMaxLength",1)};continue}if(r==="step-list"){x(i,["type","min","max","labelMaxLength","detailMaxLength"]);let s=q(i,"min",0),a=q(i,"max",1);s>a&&d("MANIFEST_INVALID"),n[o]={type:r,min:s,max:a,labelMaxLength:q(i,"labelMaxLength",1),detailMaxLength:q(i,"detailMaxLength",1)};continue}typeof r=="string"&&d("SCHEMA_TYPE_UNSUPPORTED"),d("MANIFEST_INVALID");}return n}function Eo(e,n,t){let i=e[n];(!i||i.type!==t)&&d("MANIFEST_INVALID");}function je(e,n,t){let i=Z(e,"field");return ft.test(i)||d("MANIFEST_INVALID"),Eo(n,i,t),i}function _o(e,n){k(e)||d("MANIFEST_INVALID");let t=e.primitive;switch(typeof t!="string"&&d("MANIFEST_INVALID"),Io.includes(t)||d("PRIMITIVE_UNKNOWN"),t){case "card-shell":return x(e,["primitive"]),{primitive:t};case "meta-banner":return x(e,["primitive","badgeToken","noticeToken"]),{primitive:t,badgeToken:_e(Z(e,"badgeToken")),noticeToken:_e(Z(e,"noticeToken"))};case "heading":return x(e,["primitive","field"]),{primitive:t,field:je(e,n,"text")};case "labeled-text":return x(e,["primitive","titleToken","field","variant"]),e.variant!=="callout"&&d("MANIFEST_INVALID"),{primitive:t,titleToken:_e(Z(e,"titleToken")),field:je(e,n,"text"),variant:"callout"};case "step-flow":return x(e,["primitive","titleToken","field"]),{primitive:t,titleToken:_e(Z(e,"titleToken")),field:je(e,n,"step-list")};case "text-list":{x(e,["primitive","titleToken","field"],["emptyToken","hideWhenEmpty"]);let i={primitive:t,titleToken:_e(Z(e,"titleToken")),field:je(e,n,"text-list")};return S(e,"emptyToken")&&(i.emptyToken=_e(Z(e,"emptyToken"))),S(e,"hideWhenEmpty")&&(typeof e.hideWhenEmpty!="boolean"&&d("MANIFEST_INVALID"),i.hideWhenEmpty=e.hideWhenEmpty),i}}return d("MANIFEST_INVALID")}function To(e,n){return Array.isArray(e)||d("MANIFEST_INVALID"),e.map(t=>_o(t,n))}function w(e="v2 manifest exceeds a contract limit"){return d("LIMIT_EXCEEDED",e)}function K(e="initial state is not projection-safe"){return d("INITIAL_STATE_INVALID",e)}function rt(e,n){return (typeof e!="string"||e.length===0||e.length>4096||e.trim().length===0||yo.test(e)||Ao.test(e))&&d("MANIFEST_INVALID",`${n} is invalid`),(Ge(e,true,true)||Qi.test(e)||eo.test(e)||no.test(e))&&d("UNSAFE_VALUE",`${n} contains an unsafe value`),e}function _n(e,n){return (typeof e!="string"||!Ee.test(e))&&d("MANIFEST_INVALID",`${n} is invalid`),e}function Po(e){return (typeof e!="string"||!An.test(e)||e==="*"||e==="all")&&d("MANIFEST_INVALID","action capability is invalid"),e}function yt(e){return (typeof e!="string"||!fo.test(e))&&d("MANIFEST_INVALID","resource hash is invalid"),e}function Tn(e,n=new Set,t=0){if(typeof e=="string"){e.length>4096&&w("v2 manifest string is too long");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||d("MANIFEST_INVALID","v2 manifest contains a non-finite number");return}(e===void 0||typeof e=="function"||typeof e=="bigint")&&d("MANIFEST_INVALID","v2 manifest contains a non-JSON value"),typeof e!="object"&&d("MANIFEST_INVALID"),t>8&&w("v2 manifest nesting is too deep"),n.has(e)&&d("MANIFEST_INVALID","v2 manifest contains a cycle"),n.add(e);try{if(Array.isArray(e)){e.length>128&&w("v2 manifest array is too long");for(let i of e)Tn(i,n,t+1);return}k(e)||d("MANIFEST_INVALID","v2 manifest contains a non-plain object");for(let i of Object.values(e))Tn(i,n,t+1);}finally{n.delete(e);}}}function At(e){return (typeof e!="string"||e.length>4096||!Le.test(e))&&(typeof e=="string"&&e.length>4096&&w("projection path is too long"),d("MANIFEST_INVALID","projection paths must be canonical exact paths")),e.split(".").some(t=>he(t))&&d("MANIFEST_INVALID","projection paths cannot address reserved state keys"),e}function gt(e){k(e)||d("MANIFEST_INVALID","projection policy must be an object"),x(e,["allow"]),Array.isArray(e.allow)||d("MANIFEST_INVALID","projection allow must be an array"),e.allow.length>128&&w("projection allowlist is too long");let n=[],t=new Set;for(let i of e.allow){let o=At(i);t.has(o)&&d("MANIFEST_INVALID","projection allowlist contains a duplicate path"),t.add(o),n.push(o);}return {allow:n}}function Do(e,n){if(e===void 0)return;Array.isArray(e)||d("MANIFEST_INVALID","dataPaths must be an array"),e.length>go&&w("dataPaths exceed the v2 limit");let t=[],i=new Set;for(let o of e){let r=At(o);i.has(r)&&d("MANIFEST_INVALID","dataPaths contain a duplicate path"),n.some(s=>Ie(r,s))||d("MANIFEST_INVALID","dataPaths must be projection-allowed"),i.add(r),t.push(r);}return t}function Te(e,n,t=Number.MAX_SAFE_INTEGER){return (!Number.isSafeInteger(e)||e<0||e>t)&&d("MANIFEST_INVALID",`${n} is invalid`),e}function st(e,n){return (typeof e!="number"||!Number.isFinite(e))&&d("MANIFEST_INVALID",`${n} is invalid`),e}function Pn(e,n=0,t=new Set){if(typeof e=="string")return (e.length>4096||Ge(e))&&d("UNSAFE_VALUE","schema enum contains an unsafe string"),e;if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||d("MANIFEST_INVALID","schema enum contains a non-finite number"),e;(n>8||typeof e!="object"||e===void 0)&&w("schema enum is too deep"),t.has(e)&&d("MANIFEST_INVALID","schema enum contains a cycle"),t.add(e);try{if(Array.isArray(e))return e.length>128&&w("schema enum array is too long"),e.map(o=>Pn(o,n+1,t));k(e)||d("MANIFEST_INVALID","schema enum contains a non-plain object");let i={};for(let[o,r]of Object.entries(e))he(o)&&d("MANIFEST_INVALID","schema enum contains a reserved key"),i[o]=Pn(r,n+1,t);return i}finally{t.delete(e);}}function bo(e,n){if(e===void 0)return;Array.isArray(e)||d("MANIFEST_INVALID","schema required must be an array"),e.length>64&&w("schema required list is too long");let t=[],i=new Set;for(let o of e)(typeof o!="string"||!Le.test(o))&&d("MANIFEST_INVALID","schema required contains an invalid key"),o.length>4096&&w("schema required key is too long"),i.has(o)&&d("MANIFEST_INVALID","schema required contains a duplicate key"),n&&!Object.prototype.hasOwnProperty.call(n,o)&&d("MANIFEST_INVALID","schema required references an undeclared property"),i.add(o),t.push(o);return t}function No(e,n){let t=n?Le:Fe;return e.length>4096&&w("schema property name is too long"),(!t.test(e)||e.split(".").some(i=>he(i)))&&d("MANIFEST_INVALID","schema property name is invalid"),e}function Dn(e,n=0,t=false){k(e)||d("MANIFEST_INVALID","action inputSchema must be an object"),n>8&&w("action inputSchema is too deep");let i=e.type;i!=="object"&&i!=="string"&&i!=="number"&&i!=="integer"&&i!=="boolean"&&i!=="array"&&i!=="null"&&(typeof i=="string"&&d("SCHEMA_TYPE_UNSUPPORTED","action inputSchema type is unsupported"),d("MANIFEST_INVALID","action inputSchema type is required"));let o=["type","enum"];i==="string"&&o.push("minLength","maxLength"),i==="array"&&o.push("minItems","maxItems","items"),i==="object"&&o.push("minProperties","maxProperties","properties","required","additionalProperties"),(i==="number"||i==="integer")&&o.push("minimum","maximum"),x(e,["type"],o.filter(a=>a!=="type"));let r={type:i};if(S(e,"enum")&&(Array.isArray(e.enum)||d("MANIFEST_INVALID","schema enum must be an array"),e.enum.length>128&&w("schema enum is too long"),r.enum=e.enum.map(a=>Pn(a))),i==="string"&&(S(e,"minLength")&&(r.minLength=Te(e.minLength,"schema minLength",4096)),S(e,"maxLength")&&(r.maxLength=Te(e.maxLength,"schema maxLength",4096)),r.minLength!==void 0&&r.maxLength!==void 0&&r.minLength>r.maxLength&&d("MANIFEST_INVALID","schema string length bounds are inverted")),(i==="number"||i==="integer")&&(S(e,"minimum")&&(r.minimum=st(e.minimum,"schema minimum")),S(e,"maximum")&&(r.maximum=st(e.maximum,"schema maximum")),r.minimum!==void 0&&r.maximum!==void 0&&r.minimum>r.maximum&&d("MANIFEST_INVALID","schema numeric bounds are inverted")),i==="array"&&(S(e,"minItems")&&(r.minItems=Te(e.minItems,"schema minItems",128)),S(e,"maxItems")&&(r.maxItems=Te(e.maxItems,"schema maxItems",128)),r.minItems!==void 0&&r.maxItems!==void 0&&r.minItems>r.maxItems&&d("MANIFEST_INVALID","schema array length bounds are inverted"),S(e,"items")&&(r.items=Dn(e.items,n+1,false))),i==="object"){let a;if(S(e,"properties")){k(e.properties)||d("MANIFEST_INVALID","schema properties must be an object");let p=Object.entries(e.properties);p.length>64&&w("schema properties are too many"),a={};for(let[u,f]of p){let A=No(u,t);a[A]=Dn(f,n+1,false);}r.properties=a;}S(e,"minProperties")&&(r.minProperties=Te(e.minProperties,"schema minProperties",64)),S(e,"maxProperties")&&(r.maxProperties=Te(e.maxProperties,"schema maxProperties",64)),r.minProperties!==void 0&&r.maxProperties!==void 0&&r.minProperties>r.maxProperties&&d("MANIFEST_INVALID","schema object property bounds are inverted");let c=bo(e.required,a);c!==void 0&&(r.required=c),S(e,"additionalProperties")&&(e.additionalProperties!==false&&d("MANIFEST_INVALID","schema additionalProperties must be false"),r.additionalProperties=false);}let s=JSON.stringify(r);return (s===void 0||Buffer.byteLength(s,"utf8")>65536)&&w("action inputSchema subtree is too large"),r}function Mo(e){let n=Dn(e,0,true);return (n.type!=="object"||!n.properties)&&d("MANIFEST_INVALID","action inputSchema must declare object properties"),n}function So(e){if(k(e)||d("MANIFEST_INVALID","action backend must be an object"),e.type==="core"){x(e,co);let n=e.handler;return (typeof n!="string"||!gn.test(n))&&d("MANIFEST_INVALID","core backend handler is invalid"),{type:"core",handler:n}}if(e.type==="skill"){x(e,po),(!Array.isArray(e.command)||e.command.length===0||e.command.length>16)&&d("MANIFEST_INVALID","skill backend command is invalid");let n=[];for(let t of e.command)(typeof t!="string"||t.length===0||t.length>256||!In.test(t))&&d("MANIFEST_INVALID","skill backend command token is invalid"),n.push(t);return {type:"skill",command:n}}d("MANIFEST_INVALID","action backend type is unsupported");}function Lo(e){k(e)||d("MANIFEST_INVALID","action must be an object"),x(e,ro,so),S(e,"_meta")&&It(e._meta);let n=_n(e.actionId,"actionId"),t=Po(e.capability),i=e.mutation;typeof i!="boolean"&&d("MANIFEST_INVALID","action mutation must be boolean");let o=Mo(e.inputSchema),r;if(S(e,"dataInputs")){Array.isArray(e.dataInputs)||d("MANIFEST_INVALID","action dataInputs must be an array");let p=o.properties,u=new Set,f=[];for(let A of e.dataInputs)(typeof A!="string"||!S(p,A)||u.has(A))&&d("MANIFEST_INVALID","action dataInputs must be unique declared properties"),u.add(A),f.push(A);r=f;}let s=gt(e.resultProjection),a=So(e.backend),c;if(S(e,"confirmation")){let p=e.confirmation;p!=="none"&&p!=="native"&&d("MANIFEST_INVALID","action confirmation is invalid"),c=p;}return {actionId:n,capability:t,mutation:i,inputSchema:o,resultProjection:s,backend:a,...r===void 0?{}:{dataInputs:r},...c===void 0?{}:{confirmation:c}}}function Uo(e){return k(e)||d("INITIAL_STATE_INVALID","initialState must be an object"),x(e,lo,uo),e.path!=="ui/state.json"&&d("MANIFEST_INVALID","initialState path is not fixed"),S(e,"hash")?{path:"ui/state.json",hash:yt(e.hash)}:{path:"ui/state.json"}}function Ro(e,n){He(e,new Set,0,true,true),Tn(e),k(e)||d("MANIFEST_INVALID"),x(e,io,oo),S(e,"_meta")&&It(e._meta),e.manifestVersion!==2&&d("MANIFEST_INVALID");let t=_n(e.pluginId,"pluginId"),i=_n(e.definitionId,"definitionId"),o=q(e,"version",1),r=rt(e.name,"name"),s=rt(e.description,"description"),a;S(e,"icon")&&((typeof e.icon!="string"||!/^[a-z][a-z0-9-]{0,63}$/.test(e.icon))&&d("MANIFEST_INVALID","icon is invalid"),a=e.icon);let c;S(e,"tone")&&((typeof e.tone!="string"||!mn.includes(e.tone))&&d("MANIFEST_INVALID","tone is invalid"),c=e.tone),e.entry!=="ui/index.html"&&d("MANIFEST_INVALID","entry path is not fixed");let p;S(e,"entryHash")&&(p=yt(e.entryHash));let u;S(e,"initialState")&&(u=Uo(e.initialState));let f;S(e,"usage")&&(e.usage!=="card"&&e.usage!=="window"&&d("MANIFEST_INVALID","usage is invalid"),f=e.usage);let A;S(e,"detailPanel")&&(typeof e.detailPanel!="boolean"&&d("MANIFEST_INVALID","detailPanel is invalid"),A=e.detailPanel);let m;if(S(e,"displayModes")){((f??ae)!==ae||!Array.isArray(e.displayModes)||e.displayModes.length===0)&&d("MANIFEST_INVALID","displayModes are only valid for window Apps");let R=new Set(["inline","floating","focused"]);(new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(l=>typeof l!="string"||!R.has(l)))&&d("MANIFEST_INVALID","displayModes are invalid"),m=e.displayModes;}(f??ae)===ae&&A!==void 0&&d("MANIFEST_INVALID","detailPanel is card-only");let g=n.mode??"local";g!=="local"&&g!=="installed"&&g!=="published"&&d("MANIFEST_INVALID","manifest mode is invalid"),g!=="local"&&p===void 0&&d("MANIFEST_INVALID","installed manifests require entryHash"),g!=="local"&&u!==void 0&&u.hash===void 0&&d("MANIFEST_INVALID","installed manifests require initialState.hash"),(!Array.isArray(e.surfaces)||e.surfaces.length===0)&&d("MANIFEST_INVALID","surfaces are invalid"),e.surfaces.length>2&&w("surfaces exceed the v2 limit");let T=[],M=new Set;for(let R of e.surfaces)(typeof R!="string"||!hn.includes(R))&&d("MANIFEST_INVALID","surface is unsupported"),M.has(R)&&d("MANIFEST_INVALID","surfaces contain a duplicate"),M.add(R),T.push(R);k(e.size)||d("MANIFEST_INVALID","size must be an object"),x(e.size,["height"]);let L=q(e.size,"height",1);L>720&&w("size.height exceeds the v2 limit");let y=gt(e.stateProjection),I=Do(e.dataPaths,y.allow);Array.isArray(e.actions)||d("MANIFEST_INVALID","actions must be an array"),e.actions.length>32&&w("actions exceed the v2 limit");let P=[],v=new Set;for(let R of e.actions){let l=Lo(R);if(v.has(l.actionId)&&d("MANIFEST_INVALID","actions contain a duplicate actionId"),l.backend.type==="core"&&l.backend.handler==="state.set"){l.mutation||d("MANIFEST_INVALID","state.set actions must be mutations");for(let N of Object.keys(l.inputSchema.properties))y.allow.includes(N)||d("MANIFEST_INVALID","state.set input paths must be projection-allowed");}v.add(l.actionId),P.push(l);}return {manifestVersion:2,pluginId:t,definitionId:i,version:o,name:r,description:s,...a===void 0?{}:{icon:a},...c===void 0?{}:{tone:c},entry:"ui/index.html",...p===void 0?{}:{entryHash:p},...u===void 0?{}:{initialState:u},...f===void 0?{}:{usage:f},...A===void 0?{}:{detailPanel:A},...m===void 0?{}:{displayModes:m},surfaces:T,size:{height:L},stateProjection:y,...I===void 0?{}:{dataPaths:I},actions:P}}function It(e){k(e)||d("MANIFEST_INVALID","_meta must be an object");let n=JSON.stringify(e);(n===void 0||Buffer.byteLength(n,"utf8")>ao)&&w("_meta exceeds the 4 KiB limit");}function Oo(e){let n={},t={};for(let r of e.actions){n[r.actionId]={capabilities:[r.capability],inputKeys:Object.keys(r.inputSchema.properties??{}),...r.dataInputs===void 0?{}:{dataInputs:r.dataInputs},resultProjection:r.resultProjection,...r.confirmation===void 0?{}:{confirmation:r.confirmation}};let s=r.backend.type==="skill"||r.backend.type==="core"&&r.backend.handler==="state.set";t[r.actionId]={actionId:r.actionId,mutation:r.mutation,backend:r.backend,launchPolicy:s?"allowed":"denied",...s?{}:{denialCode:"EXEC_DENIED"}};}let i={id:e.definitionId,version:e.version,renderer:"sandbox-html",...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},surfaces:e.surfaces,stateProjection:e.stateProjection,...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},actions:n},o={entry:{path:"ui/index.html",...e.entryHash===void 0?{}:{hash:e.entryHash}},...e.initialState===void 0?{}:{initialState:e.initialState}};return {manifest:e,definition:i,handlers:t,resources:o}}function bn(e,n,t,i,o,r){if(typeof e=="string"){let s=o.length>0&&r.some(a=>Ie(o.join("."),a));return (e.length>4096||Ge(e,false,false,s))&&K("state contains an unsafe string"),e}if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||K("state contains a non-finite number"),e;(e===void 0||typeof e!="object"||typeof e=="function"||typeof e=="bigint")&&K("state contains a non-JSON value"),t>8&&K("state is too deep"),n.has(e)&&K("state contains a cycle"),n.add(e);try{let s;if(Array.isArray(e))e.length>128&&K("state array is too long"),s=e.map(c=>bn(c,n,t+1,65536,o,r));else {k(e)||K("state contains a non-plain object");let c={};for(let[p,u]of Object.entries(e))(p.length>4096||!Fe.test(p)||he(p))&&(p.length>4096&&K("state key is too long"),K("state contains a reserved or invalid key")),c[p]=bn(u,n,t+1,65536,[...o,p],r);s=c;}let a=JSON.stringify(s);return (a===void 0||Buffer.byteLength(a,"utf8")>i)&&K("state subtree is too large"),s}finally{n.delete(e);}}function Mn(e,n=[]){k(e)||K("initial state must be a JSON object");let t=bn(e,new Set,0,65536,[],n);return (t===null||Array.isArray(t)||typeof t!="object")&&K(),t}function ko(e,n={}){He(e),k(e)||d("MANIFEST_INVALID"),x(e,to),e.manifestVersion!==1&&d("MANIFEST_INVALID");let t=En(Z(e,"pluginId")),i=En(Z(e,"definitionId")),o=q(e,"version",1),r=q(e,"primitiveSet",1),s=n.supportedPrimitiveSet??Wi;(!Number.isSafeInteger(s)||s<1)&&d("MANIFEST_INVALID"),r>s&&d("PRIMITIVE_SET_UNSUPPORTED"),k(e.activation)||d("MANIFEST_INVALID"),x(e.activation,["kind","language"]),e.activation.kind!=="fenced-code"&&d("MANIFEST_INVALID");let a=En(Z(e.activation,"language")),c=ho(e.schema),p=To(e.layout,c);return {manifestVersion:1,pluginId:t,definitionId:i,version:o,primitiveSet:r,activation:{kind:"fenced-code",language:a},schema:c,layout:p}}function xo(e,n={}){return k(e)||d("MANIFEST_INVALID"),Object.hasOwn(e,"lineage")&&d("MANIFEST_INVALID","lineage is only allowed in product bundle indexes"),e.manifestVersion===2?Ro(e,n):ko(e,n)}function fe(e,n={}){try{return xo(e,n)}catch(t){if(t instanceof G)throw t;return d("MANIFEST_INVALID")}}function Sn(e,n={}){let t=fe(e,n);return t.manifestVersion===2?Oo(t):t}var ht="SKILL.md",Fo=/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;function Et(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function jo(e){return e.isDirectory()||e.isSymbolicLink()}function bt(e){try{return C.existsSync(e)&&C.statSync(e).isDirectory()}catch{return false}}function Un(e){let n;try{n=C.readFileSync(e,"utf8");}catch{return {frontmatter:{},readable:false,valid:false,hasFrontmatter:false}}let t=n.match(Fo);if(!t)return {frontmatter:{},readable:true,valid:true,hasFrontmatter:false};try{let i=li.load(t[1]??"");if(!Et(i))return {frontmatter:{},readable:!0,valid:!1,hasFrontmatter:!0};let o=Et(i.metadata)?i.metadata:void 0;return {frontmatter:{...typeof i.name=="string"?{name:i.name}:{},...typeof(o?.version??i.version)=="string"?{version:o?.version??i.version}:{},...typeof i.description=="string"?{description:i.description}:{}},readable:!0,valid:!0,hasFrontmatter:!0}}catch{return {frontmatter:{},readable:true,valid:false,hasFrontmatter:true}}}function Bo(e){return [B.join(e,ht),B.join(e,"skill",ht)]}function _t(e,n){if(!bt(e))return null;for(let t of Bo(e)){if(!C.existsSync(t))continue;let o=Un(t).frontmatter;return {name:o.name??n,...o.version===void 0?{}:{version:o.version},...o.description===void 0?{}:{description:o.description},skillMdPath:t,dir:e}}return null}function Tt(e){try{return C.readdirSync(e,{withFileTypes:!0}).filter(jo)}catch{return []}}function Pt(e,n,t){!e||n.has(e.name)||(n.add(e.name),t.push(e));}function Nt(e){let n=[],t=new Set;for(let i of e)if(bt(i))for(let o of Tt(i)){if(o.name.startsWith("@")){let r=B.join(i,o.name);for(let s of Tt(r))Pt(_t(B.join(r,s.name),s.name),t,n);continue}Pt(_t(B.join(i,o.name),o.name),t,n);}return n.sort((i,o)=>i.name.localeCompare(o.name))}var zo=/^[0-9a-f]{64}$/;function ce(e){let t=e.renderer!==void 0||e.surfaces!==void 0||e.stateProjection!==void 0||e.dataPaths!==void 0||e.usage!==void 0||e.detailPanel!==void 0||e.displayModes!==void 0||e.summaryProjection!==void 0||e.legacy!==void 0||Object.values(e.actions).some(o=>o.resultProjection!==void 0)?{id:e.id,version:e.version,...e.renderer===void 0?{}:{renderer:e.renderer},...e.surfaces===void 0?{}:{surfaces:e.surfaces},...e.stateProjection===void 0?{}:{stateProjection:e.stateProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.legacy===void 0?{}:{legacy:e.legacy},...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},actions:e.actions}:e.sourceHash===void 0?{id:e.id,version:e.version,actions:e.actions}:{id:e.id,version:e.version,sourceHash:e.sourceHash,actions:e.actions},i=se(t);return Qn.createHash("sha256").update(J(i)).digest("hex")}function pe(e){if(!/^\d+$/.test(String(e.version))||e.version<1||e.id.length<1||e.id.length>128)throw new D("DEFINITION_UNSUPPORTED","UI definition is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!zo.test(e.sourceHash)))throw new D("DEFINITION_UNSUPPORTED","UI definition source hash is invalid");if(!/^[0-9a-f]{64}$/.test(e.hash)||ce(e)!==e.hash)throw new D("DEFINITION_UNSUPPORTED","UI definition hash is invalid");for(let[n,t]of Object.entries(e.actions)){if(!n||!Array.isArray(t.capabilities)||t.capabilities.some(i=>!$o(i)))throw new D("DEFINITION_UNSUPPORTED","UI action declaration is invalid");if(t.confirmation!==void 0&&t.confirmation!=="none"&&t.confirmation!=="native")throw new D("DEFINITION_UNSUPPORTED","UI action confirmation is invalid");if(t.inputKeys&&(!Array.isArray(t.inputKeys)||t.inputKeys.some(i=>typeof i!="string"||!i)))throw new D("DEFINITION_UNSUPPORTED","UI action input declaration is invalid");if(t.dataInputs!==void 0&&(!Array.isArray(t.dataInputs)||new Set(t.dataInputs).size!==t.dataInputs.length||t.dataInputs.some(i=>typeof i!="string"||!i||t.inputKeys!==void 0&&!t.inputKeys.includes(i))))throw new D("DEFINITION_UNSUPPORTED","UI action data input declaration is invalid");t.resultProjection&&Rn(t.resultProjection);}if(e.renderer!==void 0&&(!e.renderer||e.renderer.length>128))throw new D("DEFINITION_UNSUPPORTED","UI definition renderer is invalid");if(e.surfaces&&(!Array.isArray(e.surfaces)||e.surfaces.some(n=>!n||n.length>64)))throw new D("DEFINITION_UNSUPPORTED","UI definition surfaces are invalid");if(e.usage!==void 0&&e.usage!=="card"&&e.usage!=="window")throw new D("DEFINITION_UNSUPPORTED","UI definition usage is invalid");if(e.detailPanel!==void 0&&typeof e.detailPanel!="boolean")throw new D("DEFINITION_UNSUPPORTED","UI definition detailPanel is invalid");if(e.displayModes&&(!Array.isArray(e.displayModes)||e.displayModes.length===0||new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(n=>n!=="inline"&&n!=="floating"&&n!=="focused")))throw new D("DEFINITION_UNSUPPORTED","UI definition displayModes are invalid");if(e.usage==="card"&&e.displayModes!==void 0)throw new D("DEFINITION_UNSUPPORTED","Card definitions cannot declare displayModes");if(e.usage==="window"&&e.detailPanel!==void 0)throw new D("DEFINITION_UNSUPPORTED","Window definitions cannot declare detailPanel");if(e.stateProjection&&Rn(e.stateProjection),e.summaryProjection){Rn(e.summaryProjection);let n=new Set(e.stateProjection?.allow??[]);if(e.summaryProjection.allow.some(t=>!n.has(t)))throw new D("DEFINITION_UNSUPPORTED","UI summary projection exceeds state projection")}if(e.legacy!==void 0){if(!e.legacy||typeof e.legacy!="object"||Array.isArray(e.legacy)||Object.keys(e.legacy).some(o=>!["readTool","actionTool","hostTools","agentAccess"].includes(o)))throw new D("DEFINITION_UNSUPPORTED","UI legacy metadata is invalid");let n=new Set;for(let[o,r]of [["readTool",e.legacy.readTool],["actionTool",e.legacy.actionTool]])if(r!==void 0){if(Go(r,o==="readTool"),n.has(r.name))throw new D("DEFINITION_UNSUPPORTED","UI legacy tool names collide");n.add(r.name);}let t=e.legacy.hostTools;if(t!==void 0){if(!t||typeof t!="object"||Array.isArray(t))throw new D("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");let o={"doc.open":"crewx_app_html_viewer_open","pty.connect":"crewx_app_terminal_connect"};for(let[r,s]of Object.entries(t)){if(!Object.hasOwn(o,r)||o[r]!==s||typeof s!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(s)||n.has(s))throw new D("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");n.add(s);}}let i=e.legacy.agentAccess;if(i!==void 0&&(!i||typeof i!="object"||Array.isArray(i)||Object.entries(i).some(([o,r])=>!o||!Object.hasOwn(e.actions,o)||r!=="allowed"&&r!=="denied")))throw new D("DEFINITION_UNSUPPORTED","UI legacy agent access is invalid");if(e.legacy.actionTool!==void 0&&(!i||Object.keys(i).length===0))throw new D("DEFINITION_UNSUPPORTED","UI legacy action tool requires its complete agent access map")}if(e.dataPaths!==void 0){let n=new Set(["__proto__","prototype","constructor"]);if(!Array.isArray(e.dataPaths)||e.dataPaths.length>16||new Set(e.dataPaths).size!==e.dataPaths.length||e.dataPaths.some(t=>typeof t!="string"||!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(t)||t.split(".").some(i=>n.has(i))||!(e.stateProjection?.allow??[]).some(i=>Ie(t,i))))throw new D("DEFINITION_UNSUPPORTED","UI definition dataPaths are invalid")}}function Go(e,n){if(!e||typeof e!="object"||Array.isArray(e))throw new D("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");let t=e,i=["name","description","inputSchema","textFallback","visibility"],o=Object.hasOwn(t,"fixedResult");if(Object.keys(t).some(r=>!i.includes(r)&&!(n&&r==="fixedResult"))||i.some(r=>!Object.hasOwn(t,r))||typeof t.name!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(t.name)||typeof t.description!="string"||t.description.trim().length===0||t.description.length>8192||typeof t.textFallback!="string"||t.textFallback.trim().length===0||t.textFallback.length>16384||!t.inputSchema||typeof t.inputSchema!="object"||Array.isArray(t.inputSchema)||!Array.isArray(t.visibility)||t.visibility.length===0||t.visibility.some(r=>r!=="model"&&r!=="app")||new Set(t.visibility).size!==t.visibility.length)throw new D("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");try{let r=se(t.inputSchema);if(r.type!==void 0&&r.type!=="object")throw new Error("schema type");if(o){if(!n)throw new Error("fixed result location");let s=t.fixedResult;if(!s||typeof s!="object"||Array.isArray(s))throw new Error("fixed result");let a=s;if(Object.keys(a).sort().join(",")!=="argsPolicy,structuredContent"||a.argsPolicy!=="empty-only"&&a.argsPolicy!=="ignore"||!a.structuredContent||typeof a.structuredContent!="object"||Array.isArray(a.structuredContent))throw new Error("fixed result");let c=se(a.structuredContent);if(fn(me(c))>4*1024)throw new Error("fixed result size")}}catch{throw new D("DEFINITION_UNSUPPORTED","UI legacy tool metadata is not projection-safe")}}function Rn(e){if(!Array.isArray(e.allow)||e.allow.some(n=>!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(n)))throw new D("DEFINITION_UNSUPPORTED","UI projection policy is invalid")}function $o(e){return e.length>0&&e.length<=128&&e!=="*"&&e!=="all"&&!/[/*]/.test(e)}var ee=class extends Error{constructor(t,i=t,o=[]){super(i);this.code=t;this.violations=o;}code;violations;name="UiDefinitionLineageError"},Mt=/^[0-9a-f]{64}$/,Wo=["version","hash","definition"],Jo=["sourceHash","compat"],Ko=["id","version","actions"],Xo=["sourceHash","usage","detailPanel","displayModes","renderer","surfaces","stateProjection","dataPaths","summaryProjection","legacy"],Yo=["capabilities"],qo=["inputKeys","dataInputs","confirmation","resultProjection"];function xe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function On(e,n,t=[]){let i=new Set([...n,...t]),o=Object.keys(e);return n.every(r=>Object.hasOwn(e,r))&&o.every(r=>i.has(r))}function Lt(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))Lt(n);return Object.freeze(e)}function V(e){throw new ee("LINEAGE_INVALID",e)}function Zo(e){throw new ee("LINEAGE_STALE",e)}function Ut(e){if(!xe(e)||!On(e,Ko,Xo)||!xe(e.actions))return V("Lineage definition shape is invalid");for(let n of Object.values(e.actions))if(!xe(n)||!On(n,Yo,qo))return V("Lineage action definition shape is invalid");return e}function Qo(e){if(!xe(e)||!On(e,Wo,Jo))return V("Lineage entry shape is invalid");if(!Number.isSafeInteger(e.version)||e.version<1||typeof e.hash!="string"||!Mt.test(e.hash))return V("Lineage entry identity is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!Mt.test(e.sourceHash)))return V("Lineage source hash is invalid");if(e.compat!==void 0&&e.compat!=="break")return V("Lineage compatibility marker is invalid");let n=Ut(e.definition);if(n.version!==e.version)return V("Lineage version does not match its definition");if(e.sourceHash!==void 0&&n.sourceHash!==e.sourceHash)return V("Lineage source hash does not match its definition");let t;try{t=ce(n),pe({...n,hash:e.hash});}catch{return V("Lineage definition is invalid")}return t!==e.hash?V("Lineage definition hash does not match"):Lt({version:e.version,hash:e.hash,definition:n,...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},...e.compat===void 0?{}:{compat:e.compat}})}function St(e){return e.stateProjection?.allow??[]}function er(e,n){let t=[],i=new Set(St(n));St(e).some(a=>!i.has(a))&&t.push("S1_STATE_PROJECTION");let o=new Set(n.dataPaths??[]);(e.dataPaths??[]).some(a=>!o.has(a))&&t.push("S2_DATA_PATHS");for(let[a,c]of Object.entries(e.actions)){let p=n.actions[a];if(p&&(c.confirmation??"native")==="native"&&(p.confirmation??"native")!=="native"){t.push("S3_ACTION_CONFIRMATION");break}}Object.keys(e.legacy?.agentAccess??{}).some(a=>!Object.hasOwn(n.actions,a))&&t.push("S4_LEGACY_AGENT_ACTIONS");let s=e.summaryProjection?.allow;if(s!==void 0){let a=new Set(n.summaryProjection?.allow??[]);s.some(c=>!a.has(c))&&t.push("S5_SUMMARY_PROJECTION");}return t}function nr(e,n){return J(e)===J(n)}function Rt(e,n){if(!Array.isArray(e)||e.length===0)return V("Definition lineage is missing");if(!xe(n)||typeof n.hash!="string")return V("Current definition is invalid");let t,i;try{let{hash:a,...c}=n;i=Ut(c),t={...i,hash:a},pe(t);}catch{return V("Current definition is invalid")}let o=e.map(Qo),r=o[0].definition.id;if(o.some(a=>a.definition.id!==r))return V("Lineage definition ids do not match");if(o.some((a,c)=>c>0&&a.version<=o[c-1].version))return V("Lineage generations are not in increasing version order");if(o.some((a,c)=>o.findIndex(p=>p.hash===a.hash)!==c))return V("Lineage contains a duplicate hash");let s=o[o.length-1];if(s.version!==t.version||s.hash!==t.hash||s.definition.id!==t.id||!nr(s.definition,i))return Zo("The last lineage generation does not match the current package");for(let a=0;a<o.length-1;a+=1){if(o.slice(a,-1).some(u=>u.compat==="break"))continue;let p=er(o[a].definition,t);if(p.length>0)throw new ee("LINEAGE_INVALID",`Lineage compatibility failed: ${p.join(", ")}`,p)}return Object.freeze({entries:Object.freeze(o),current:t})}var tr=new WeakSet;function Ot(e){return tr.add(e),e}var de=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="McpAppContractError"};function kn(e,n=e){throw new de(e,n)}var kt=["crewx_app_terminal_connect","crewx_app_html_viewer_open"];var $e=8*1024*1024;new Set(kt);var or=4;function xn(e,n=0){try{let t=se(e,n);return t.type!==void 0&&t.type!=="object"&&kn("TOOL_INVALID","MCP App inputSchema must describe an object"),t}catch(t){if(t instanceof de)throw t;kn("TOOL_INVALID","MCP App inputSchema must be projection-safe JSON");}}function xt(e){if(e.length===0)return xn({type:"object",properties:{},additionalProperties:false});let n=e.map(i=>i.actionId),t=new Map;for(let i of e)t.set(i.actionId,xn(i.inputSchema));return xn(rr(n,t),or)}function rr(e,n){let t=e.map(i=>({type:"object",properties:{actionId:{type:"string",const:i},input:n.get(i)??{type:"object"}},required:["actionId","input"],additionalProperties:false}));return Object.freeze({type:"object",oneOf:Object.freeze(t),properties:Object.freeze({actionId:Object.freeze({type:"string",enum:Object.freeze([...e])}),input:Object.freeze({type:"object"})}),required:Object.freeze(["actionId","input"]),additionalProperties:false})}var _=class extends Error{constructor(t){super(t);this.code=t;}code;name="AppDiscoveryFsError"},jt=C.constants.O_NOFOLLOW,pr=C.constants.O_NONBLOCK,dr=C.constants.O_RDONLY|(jt??0)|(pr??0);function ne(e){let n=typeof e=="object"&&e!==null&&"code"in e?String(e.code):"";return n==="ENOENT"?new _("NOT_FOUND"):n==="ELOOP"?new _("PATH_ESCAPED"):n==="EFBIG"||n==="EOVERFLOW"?new _("LIMIT_EXCEEDED"):n==="EACCES"||n==="EPERM"||n==="ENOTDIR"?new _("READ_DENIED"):new _("READ_DENIED")}function lr(e){if(typeof e!="string"||e.length===0||!B.isAbsolute(e))throw new _("READ_DENIED")}function wt(e){if(typeof e!="string"||B.isAbsolute(e)||/[\\\u0000]/.test(e))throw new _("PATH_ESCAPED");if(e==="")return [];let n=e.split("/");if(n.some(t=>t.length===0||t==="."||t===".."))throw new _("PATH_ESCAPED");return n}function We(e,n){let t=B.relative(e,n);return t===""||t!==".."&&!t.startsWith(`..${B.sep}`)&&!B.isAbsolute(t)}function Je(e){return {dev:e.dev,ino:e.ino,size:e.size,mtimeNs:e.mtimeNs,ctimeNs:e.ctimeNs}}function vn(e,n){return e.dev===n.dev&&e.ino===n.ino}function Bt(e,n){return vn(e,n)&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}async function Ct(e){lr(e);let n,t;try{n=await promises.realpath(e),t=await promises.stat(n,{bigint:!0});}catch(i){throw ne(i)}if(!t.isDirectory())throw new _("READ_DENIED");return {realRoot:n,identity:Je(t)}}async function ur(e,n,t){if(t.length<2||t[0]!=="apps"&&t[0]!=="skills")return;let i,o;try{if(i=B.resolve(e,t[0],t[1]),o=await promises.realpath(i),!(await promises.stat(o,{bigint:!0})).isDirectory())throw new _("READ_DENIED")}catch(r){throw r instanceof _?r:ne(r)}if(!We(n,o))throw new _("PATH_ESCAPED");return o}async function vt(e,n,t,i){let o,r,s;try{o=await promises.lstat(e,{bigint:!0}),r=await promises.realpath(e),s=await promises.stat(r,{bigint:!0});}catch(a){throw ne(a)}if(!We(n,r)||t!==void 0&&!We(t,r))throw new _("PATH_ESCAPED");if(!o.isFile()||!s.isFile())throw new _("READ_DENIED");if(!vn(i,o)||!vn(i,s)||i.dev!==s.dev)throw new _("PATH_ESCAPED")}async function wn(e,n){let t,i;try{t=await promises.realpath(e),i=await promises.stat(t,{bigint:!0});}catch{throw new _("PATH_ESCAPED")}if(t!==n.realRoot||!Bt(n.identity,Je(i)))throw new _("PATH_ESCAPED")}function fr(e){return e.isSymbolicLink()?{name:e.name,kind:"symlink"}:e.isDirectory()?{name:e.name,kind:"directory"}:e.isFile()?{name:e.name,kind:"file"}:{name:e.name,kind:"other"}}var Ke=class{async listDirectory(n,t){let i=wt(t),o=await Ct(n),r=B.resolve(n,...i),s,a;try{s=await promises.realpath(r),a=await promises.stat(s,{bigint:!0});}catch(c){let p=ne(c);if(p.code==="NOT_FOUND")return [];throw p}if(!We(o.realRoot,s)||!a.isDirectory())throw new _("PATH_ESCAPED");try{let c=await promises.readdir(s,{withFileTypes:!0,encoding:"utf8"});return await wn(n,o),c.map(fr)}catch(c){let p=ne(c);if(p.code==="NOT_FOUND")return [];throw p}}async readdir(n,t){return this.listDirectory(n,t)}async readDirectory(n,t){return this.listDirectory(n,t)}async readVerifiedFile(n,t,i){if(!Number.isSafeInteger(i)||i<0)throw new _("READ_DENIED");if(jt===void 0)throw new _("UNSUPPORTED");let o=wt(t),r=await Ct(n),s=B.resolve(n,...o),a=B.relative(n,s);if(a===".."||a.startsWith(`..${B.sep}`)||B.isAbsolute(a))throw new _("PATH_ESCAPED");let c;try{c=await promises.open(s,dr);}catch(p){throw ne(p)}try{let p;try{let g=await c.stat({bigint:!0});p=Je(g);}catch(g){throw ne(g)}if(p.size>BigInt(i))throw new _("LIMIT_EXCEEDED");if(p.size>BigInt(Number.MAX_SAFE_INTEGER))throw new _("LIMIT_EXCEEDED");await wn(n,r);let u=await ur(n,r.realRoot,o);await vt(s,r.realRoot,u,p);let f=new Uint8Array(new ArrayBuffer(Number(p.size))),A=0;for(;A<f.byteLength;){let g;try{g=(await c.read(f,A,f.byteLength-A,A)).bytesRead;}catch(T){throw ne(T)}if(g<=0)throw new _("IDENTITY_CHANGED");A+=g;}let m;try{let g=await c.stat({bigint:!0});m=Je(g);}catch(g){throw ne(g)}if(!Bt(p,m))throw new _("IDENTITY_CHANGED");return await vt(s,r.realRoot,u,m),await wn(n,r),new Uint8Array(f)}finally{await c.close().catch(()=>{});}}async readFileVerified(n,t,i){return this.readVerifiedFile(n,t,i)}},Ht=new Ke;var Fn="crewx_local_app_";function yr(e){if(typeof e!="string"||!Ee.test(e))throw new TypeError("pluginId must be a safe UI plugin identifier");let n=`${Fn}${e}`.length+7<=128?e:`hash_${Qn.createHash("sha256").update(e,"utf8").digest("hex")}`;return {read:`${Fn}${n}_read`,action:`${Fn}${n}_action`}}var zt=["bundled","apps","skills"],Ar=256*1024,Gn=64,$n=128,gr=Gn*$n,Ir=2*1024*1024,jn=32*1024*1024,Hn=/^[0-9a-f]{64}$/,mr=new TextDecoder("utf-8",{fatal:true});function Ae(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function qe(e){return typeof e=="string"&&Ee.test(e)?e:void 0}function hr(e,n){return n.length===0||n==="."||n===".."||/[\\/\u0000]/.test(n)?e==="skills"?"skills":"apps":`${e==="skills"?"skills":"apps"}/${n}`}function Yt(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function Ne(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),o=Math.min(t.byteLength,i.byteLength);for(let r=0;r<o;r+=1){let s=t[r]-i[r];if(s!==0)return s}return t.byteLength-i.byteLength}function Er(e){if(typeof e=="string")return {name:e,kind:"directory"};if(e===null||typeof e!="object")return null;let n=e;if(typeof n.name!="string")return null;if(n.kind==="file"||n.kind==="directory"||n.kind==="symlink"||n.kind==="other")return {name:n.name,kind:n.kind};if(n.type==="file"||n.type==="directory"||n.type==="symlink"||n.type==="other")return {name:n.name,kind:n.type};let t=n.isDirectory;if(typeof t=="function"&&t.call(e))return {name:n.name,kind:"directory"};let i=n.isSymbolicLink;if(typeof i=="function"&&i.call(e))return {name:n.name,kind:"symlink"};let o=n.isFile;return typeof o=="function"&&o.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function _r(e){if(e instanceof Uint8Array)return new Uint8Array(e);if(e instanceof ArrayBuffer)return new Uint8Array(e.slice(0));if(Array.isArray(e)&&e.every(n=>Number.isInteger(n)&&n>=0&&n<=255))return Uint8Array.from(e);throw new TypeError("filesystem port returned an invalid byte array")}function qt(e){return mr.decode(e)}function Wn(e){return JSON.parse(qt(e))}function Tr(e){if(!Ae(e))return;let n=qe(e.pluginId);if(!n)return;let t=qe(e.definitionId),i=e.version,o=t&&Number.isSafeInteger(i)&&i>=1?`${t}\0${String(i)}`:void 0;return {pluginId:n,...o===void 0?{}:{definitionKey:o}}}function Pr(e){let n=Wn(e);return {value:n,identity:Tr(n)}}function en(e,n,t,i){let o={code:e,...i===void 0?{}:{pluginId:i},source:n,relativePath:t};return Object.freeze(o)}function Gt(e){switch(e){case "ENOENT":return "NOT_FOUND";case "ELOOP":case "EXDEV":return "PATH_ESCAPED";case "EFBIG":case "EOVERFLOW":return "LIMIT_EXCEEDED";case "EACCES":case "EPERM":case "ENOTDIR":return "READ_DENIED";default:return e}}function le(e){if(e instanceof _)return Gt(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return Gt(n)}}function ve(e,n){return e==="PATH_ESCAPED"||e==="IDENTITY_CHANGED"||e==="TOCTOU"?"PATH_ESCAPED":e==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":n==="manifest"&&e==="NOT_FOUND"?"MANIFEST_MISSING":n==="entry"?"ENTRY_INVALID":n==="initial"?"INITIAL_STATE_INVALID":"MANIFEST_INVALID"}function $t(e){switch(e.code){case "MANIFEST_INVALID":case "PRIMITIVE_UNKNOWN":case "PRIMITIVE_SET_UNSUPPORTED":case "SCHEMA_TYPE_UNSUPPORTED":case "TOKEN_INVALID":case "UNSAFE_VALUE":return "MANIFEST_INVALID";case "LIMIT_EXCEEDED":return "LIMIT_EXCEEDED";case "INITIAL_STATE_INVALID":return "INITIAL_STATE_INVALID";default:return Zt("UiPluginValidationError",e.code)}}function Zt(e,n){throw new Error(`Unmapped ${e} code: ${String(n)}`)}function Bn(e){switch(e){case "APP_ID_INVALID":case "TOOL_ID_INVALID":case "RESOURCE_URI_INVALID":case "TOOL_INVALID":case "SERIALIZATION_INVALID":return "MANIFEST_INVALID";case "APP_ID_CONFLICT":case "TOOL_ID_CONFLICT":return "DUPLICATE_ID";case "RESOURCE_NOT_FOUND":case "HTML_INVALID":return "ENTRY_INVALID";case "STATE_INVALID":case "STATE_PROJECTION_INVALID":case "BUTTON_INVALID":return "INITIAL_STATE_INVALID";default:return Zt("McpAppContractError",e)}}function X(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function Ye(e,n){let t=Object.keys(e).sort(Ne),i=[...n].sort(Ne);return t.length===i.length&&t.every((o,r)=>o===i[r])}function Wt(e){if(typeof e!="string"||e.length===0||e.startsWith("/")||/[\\\u0000]/.test(e))return;let n=e.split("/");if(!n.some(t=>t.length===0||t==="."||t===".."))return n}function Dr(e){let n;try{n=Wn(e);}catch{return}if(!Ae(n)||!Ye(n,["version","packages"])||n.version!==1||!Array.isArray(n.packages)||n.packages.length>Gn)return;let t=new Set,i=new Set,o=0,r=[];for(let s of n.packages){if(!Ae(s))return;let a=["packageDir","appId","definition","files"],c=Object.hasOwn(s,"lineage");if(!Ye(s,c?[...a,"lineage"]:a))return;let p=Wt(s.packageDir),u=qe(s.appId);if(!p||p.length!==2||p[0]!=="apps"||!Yt(p[1])||!u||t.has(s.packageDir)||!Ae(s.definition)||!Ye(s.definition,["id","version","hash"]))return;let f=qe(s.definition.id),A=s.definition.version,m=s.definition.hash;if(!f||!Number.isSafeInteger(A)||A<1||typeof m!="string"||!Hn.test(m)||!Array.isArray(s.files)||s.files.length<2||s.files.length>$n)return;let g=new Set,T=[];for(let M of s.files){if(!Ae(M)||!Ye(M,["path","sha256"]))return;let L=Wt(M.path);if(!L||typeof M.sha256!="string"||!Hn.test(M.sha256))return;let y=L.join("/"),I=`${s.packageDir}/${y}`;if(g.has(y)||i.has(I))return;g.add(y),i.add(I),T.push(Object.freeze({path:y,sha256:M.sha256}));}if(!g.has("ui-plugin.json")||!g.has("ui/index.html")||(o+=T.length,o>gr))return;t.add(s.packageDir),r.push(Object.freeze({packageDir:s.packageDir,appId:u,definition:Object.freeze({id:f,version:A,hash:m}),lineage:Array.isArray(s.lineage)?s.lineage:[],files:Object.freeze(T.sort((M,L)=>Ne(M.path,L.path)))}));}return Object.freeze({version:1,packages:Object.freeze(r)})}function br(e){return {pluginId:e.appId,definitionKey:`${e.definition.id}\0${String(e.definition.version)}`}}function ye(e){let n=le(e);return n==="PATH_ESCAPED"||n==="IDENTITY_CHANGED"||n==="TOCTOU"?"PATH_ESCAPED":n==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":"BUNDLE_INTEGRITY"}async function Nr(e,n,t,i,o){let r=[],s=async(a,c)=>{if(!X(i,o))throw new _("LIMIT_EXCEEDED");if(c>2)throw new _("LIMIT_EXCEEDED");let p=await Qe(e,n,a);for(let u of p){if(typeof u.name!="string"||u.name.length===0||u.name==="."||u.name===".."||/[\\/\u0000]/.test(u.name))throw new _("PATH_ESCAPED");let f=`${a}/${u.name}`;if(u.kind==="file"){if(r.push(f.slice(t.length+1)),r.length>$n)throw new _("LIMIT_EXCEEDED")}else if(u.kind==="directory")await s(f,c+1);else throw u.kind==="symlink"?new _("PATH_ESCAPED"):new _("READ_DENIED")}};return await s(t,0),r.sort(Ne)}function Mr(e){return e==="ui-plugin.json"?262144:e==="ui/index.html"?$e:e==="ui/state.json"?65536:Ir}async function Sr(e,n,t,i){if(e===void 0)return {packages:[],diagnostics:[],incomplete:false};let o=[],r=(l,N,Y)=>en(l,"bundled",N,Y);if(typeof e.root!="string"||e.root.length===0||typeof e.expectedIndexHash!="string"||!Hn.test(e.expectedIndexHash))return o.push(r("BUNDLE_INTEGRITY","bundle-index.json")),{packages:[],diagnostics:o,incomplete:false};let s;try{s=await Ze(n,e.root,"bundle-index.json",Ar);}catch(l){return o.push(r(ye(l),"bundle-index.json")),{packages:[],diagnostics:o,incomplete:false}}let a=Qn.createHash("sha256").update(s).digest("hex");if(a!==e.expectedIndexHash)return o.push(r("BUNDLE_INTEGRITY","bundle-index.json")),{packages:[],diagnostics:o,incomplete:false};let c=Dr(s);if(c===void 0)return o.push(r("BUNDLE_INTEGRITY","bundle-index.json")),{indexHash:a,packages:[],diagnostics:o,incomplete:false};if(!X(t,i))return o.push(r("LIMIT_EXCEEDED","bundle-index.json")),{indexHash:a,packages:c.packages.map(l=>({indexEntry:l,failureCode:"LIMIT_EXCEEDED"})),diagnostics:o,incomplete:true};let p;try{p=await Qe(n,e.root,"");}catch(l){return o.push(r(ye(l),"bundle-index.json")),{indexHash:a,packages:c.packages.map(N=>({indexEntry:N,failureCode:ye(l)})),diagnostics:o,incomplete:false}}if(!X(t,i))return o.push(r("LIMIT_EXCEEDED","bundle-index.json")),{indexHash:a,packages:c.packages.map(l=>({indexEntry:l,failureCode:"LIMIT_EXCEEDED"})),diagnostics:o,incomplete:true};let u=p.find(l=>l.name==="bundle-index.json"&&l.kind==="file"),f=p.find(l=>l.name==="apps"&&l.kind==="directory"),A=l=>c.packages.map(N=>({indexEntry:N,failureCode:l}));if(!u)return o.push(r("BUNDLE_INTEGRITY","bundle-index.json")),{indexHash:a,packages:A("BUNDLE_INTEGRITY"),diagnostics:o,incomplete:false};let m=p.filter(l=>l.name!=="bundle-index.json"&&l.name!=="apps");if(m.length>0){let l=m.some(N=>N.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return o.push(r(l,"bundle-index.json")),{indexHash:a,packages:A("BUNDLE_INTEGRITY"),diagnostics:o,incomplete:false}}if(p.some(l=>l.name==="apps"&&l.kind!=="directory"))return o.push(r("PATH_ESCAPED","apps")),{indexHash:a,packages:A("PATH_ESCAPED"),diagnostics:o,incomplete:false};let g=[];if(f)try{g=await Qe(n,e.root,"apps");}catch(l){return o.push(r(ye(l),"apps")),{indexHash:a,packages:A(ye(l)),diagnostics:o,incomplete:false}}if(!X(t,i))return o.push(r("LIMIT_EXCEEDED","apps")),{indexHash:a,packages:A("LIMIT_EXCEEDED"),diagnostics:o,incomplete:true};if(g.length>Gn)return o.push(r("LIMIT_EXCEEDED","apps")),{indexHash:a,packages:A("LIMIT_EXCEEDED"),diagnostics:o,incomplete:true};let T=new Map(c.packages.map(l=>[l.packageDir.slice(5),l])),M=g.filter(l=>!T.has(l.name));for(let l of M)o.push(r(l.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY",`apps/${l.name}`));if(M.length>0){let l=M.some(N=>N.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return {indexHash:a,packages:A(l),diagnostics:o,incomplete:false}}let L=new Set,y=new Map,I=new Map;for(let l of c.packages){let N=y.get(l.appId)??[];N.push(l),y.set(l.appId,N);let Y=`${l.definition.id}\0${String(l.definition.version)}`,$=I.get(Y)??[];$.push(l),I.set(Y,$);}for(let l of [...y.values(),...I.values()])if(l.length>1)for(let N of l)L.add(N);let P=[],v=s.byteLength,R=false;for(let l of c.packages){if(!X(t,i)){R=true,P.push({indexEntry:l,failureCode:"LIMIT_EXCEEDED"});continue}let N;try{let O=l.lineage[l.lineage.length-1];if(!O)throw new ee("LINEAGE_INVALID","Definition lineage is missing");if(O.definition.id!==l.definition.id||O.version!==l.definition.version||O.hash!==l.definition.hash)throw new ee("LINEAGE_STALE","Last lineage generation does not match bundle identity");N=Rt(l.lineage,{...O.definition,hash:O.hash}).entries;}catch(O){let E=O instanceof ee?O.code:"LINEAGE_INVALID";o.push(r(E,l.packageDir)),P.push({indexEntry:l,failureCode:E});continue}let Y=g.find(O=>O.name===l.packageDir.slice(5));if(!f||!Y){P.push({indexEntry:l,failureCode:"BUNDLE_INTEGRITY"});continue}if(Y.kind!=="directory"){P.push({indexEntry:l,failureCode:Y.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY"});continue}let $;try{let O=await Nr(n,e.root,l.packageDir,t,i);if(!X(t,i)){R=!0,P.push({indexEntry:l,failureCode:"LIMIT_EXCEEDED"});continue}let E=l.files.map(H=>H.path);if(O.length!==E.length||O.some((H,Q)=>H!==E[Q])){P.push({indexEntry:l,failureCode:"BUNDLE_INTEGRITY"});continue}$=new Map;let j;for(let H of l.files){if(!X(t,i)){j="LIMIT_EXCEEDED",R=!0;break}if(v>=jn){j="LIMIT_EXCEEDED";break}let Q;try{Q=await Ze(n,e.root,`${l.packageDir}/${H.path}`,Mr(H.path));}catch(tt){j=ye(tt);break}if(!X(t,i)){j="LIMIT_EXCEEDED",R=!0;break}if(v+Q.byteLength>jn){v=jn,j="LIMIT_EXCEEDED";break}if(v+=Q.byteLength,Qn.createHash("sha256").update(Q).digest("hex")!==H.sha256){j="BUNDLE_INTEGRITY";break}$.set(H.path,Q);}if(j!==void 0){P.push({indexEntry:l,failureCode:j});continue}}catch(O){X(t,i)||(R=true),P.push({indexEntry:l,failureCode:ye(O)});continue}P.push({indexEntry:l,lineage:N,files:$,...L.has(l)?{failureCode:"DUPLICATE_ID"}:{}});}return {indexHash:a,packages:P,diagnostics:o,incomplete:R}}function Lr(){return globalThis.performance?.now()??Date.now()}function De(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))De(n);return Object.freeze(e)}function Jt(e){return Object.freeze(Array.from(e))}async function zn(e,n,t,i){if(n.pinnedFiles!==void 0){let o=n.pinnedFiles.get(t);if(o===void 0)throw new _("NOT_FOUND");if(o.byteLength>i)throw new _("LIMIT_EXCEEDED");return new Uint8Array(o)}return Ze(e,n.root,`${n.relativePath}/${t}`,i)}function Ur(e,n,t){let i=Qn.createHash("sha256"),o=new TextEncoder().encode(J(e)),r=s=>{let a=new Uint8Array(8);new DataView(a.buffer).setBigUint64(0,BigInt(s)),i.update(a);};return r(o.byteLength),i.update(o),r(n.byteLength),i.update(n),r(t.byteLength),i.update(t),i.digest("hex")}function Rr(e,n){let t={...e.definition,sourceHash:n},i={...t,hash:ce(t)};try{pe(i);}catch{throw new G("MANIFEST_INVALID","normalized definition is invalid")}return i}function Or(e){return e.actions.some(n=>n.backend.type==="core"&&n.backend.handler!=="state.set")}function kr(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function xr(e){if(typeof e.listDirectory=="function")return e.listDirectory;if(typeof e.readDirectory=="function")return e.readDirectory;if(typeof e.readdir=="function")return e.readdir}async function Ze(e,n,t,i){let o=kr(e);if(!o)throw new _("READ_DENIED");return _r(await o.call(e,n,t,i))}async function Qe(e,n,t){let i=xr(e);if(!i)throw new _("READ_DENIED");let o=await i.call(e,n,t);if(!Array.isArray(o))throw new _("READ_DENIED");return o.map(Er).filter(r=>r!==null)}function wr(e){let n=[];for(let t of [e.reserved,e.builtin])t&&n.push(t);return e.builtins&&"listMcpApps"in e.builtins?n.push(Kt(e.builtins)):e.builtins&&n.push(e.builtins),e.builtinCatalog&&n.push(Kt(e.builtinCatalog)),n.push({...e.reservedAppIds===void 0?{}:{appIds:e.reservedAppIds},...e.reservedDefinitionIds===void 0?{}:{definitionIds:e.reservedDefinitionIds},...e.reservedToolNames===void 0?{}:{toolNames:e.reservedToolNames}}),n}function Kt(e){let n=[],t=[],i=[];for(let o of e.listMcpApps())typeof o.appId=="string"&&n.push(o.appId),o.definition&&typeof o.definition.id=="string"&&t.push(o.definition.id);for(let o of e.listMcpAppTools())typeof o.name=="string"&&i.push(o.name);return {appIds:n,definitionIds:t,toolNames:i}}function te(e,n){e.diagnostic||(e.diagnostic=en(n,e.source,e.relativePath,e.identity?.pluginId));}function Cr(e){let n=new Map;for(let i of e){let o=i.identity?.pluginId;if(o===void 0)continue;let r=n.get(o)??[];r.push(i),n.set(o,r);}for(let i of n.values()){if(i.length<2)continue;let o=i.filter(s=>s.provenance!==void 0);if(o.length>0){for(let s of i)s.provenance===void 0&&te(s,"RESERVED_ID");if(o.length>1)for(let s of o)te(s,"DUPLICATE_ID");continue}let r=i.filter(s=>s.source==="apps");if(r.length>1){for(let s of r)te(s,"DUPLICATE_ID");for(let s of i.filter(a=>a.source==="skills"))te(s,"DUPLICATE_ID");}else for(let s of i.filter(a=>a.source==="skills"))te(s,"DUPLICATE_ID");}let t=new Map;for(let i of e){if(i.diagnostic?.code==="RESERVED_ID")continue;let o=i.identity?.definitionKey;if(o===void 0)continue;let r=t.get(o)??[];r.push(i),t.set(o,r);}for(let i of t.values())if(i.length>1)for(let o of i)te(o,"DUPLICATE_ID");}function vr(e,n,t){let i=new Set,o=new Set,r=new Set,s=new Set(t.map(c=>c.appId)),a=new Set(e.filter(c=>c.source==="bundled"&&c.candidate===void 0).flatMap(c=>c.bundleIdentity===void 0?[]:[c.bundleIdentity.definitionId]));for(let c of wr(n)){for(let p of c.appIds??[])typeof p=="string"&&i.add(p);for(let p of c.definitionIds??[])typeof p=="string"&&o.add(p);for(let p of c.toolNames??[])typeof p=="string"&&r.add(p);}for(let c of e){let p=c.candidate;if(!p)continue;if(i.has(p.pluginId)||o.has(p.definitionId)){te(c,"RESERVED_ID");continue}if(c.provenance===void 0&&(s.has(p.pluginId)||a.has(p.definitionId))){te(c,"RESERVED_ID");continue}[p.toolNames.read,p.toolNames.action].filter(f=>f!==void 0).some(f=>r.has(f))&&te(c,"DUPLICATE_ID");}}function Vr(e){return [...e].sort((n,t)=>{let i=zt.indexOf(n.source)-zt.indexOf(t.source);return i!==0?i:Ne(n.relativePath,t.relativePath)})}function b(e,n){e.diagnostic=en(n,e.source,e.relativePath,e.identity?.pluginId);}async function Xt(e,n,t){if(t.byteLength>262144){b(n,"LIMIT_EXCEEDED");return}let i;try{i=Pr(t);}catch{b(n,"MANIFEST_INVALID");return}if(n.bundleIdentity===void 0)n.identity=i.identity;else if(i.identity?.pluginId!==n.bundleIdentity.appId||i.identity.definitionKey!==`${n.bundleIdentity.definitionId}\0${String(n.bundleIdentity.version)}`){b(n,"BUNDLE_INTEGRITY");return}if(Ae(i.value)&&i.value.builtinOnly===true){b(n,"RESERVED_ID");return}let o;try{let E=fe(i.value,{mode:"local"});if(E.manifestVersion!==2)throw new G("MANIFEST_INVALID","workspace App requires v2");o=E;}catch(E){if(E instanceof G){b(n,$t(E));return}if(E instanceof de){b(n,Bn(E.code));return}if(Ae(E)&&typeof E.code=="string"){b(n,Bn(E.code));return}throw E}let r={pluginId:o.pluginId,definitionKey:`${o.definitionId}\0${String(o.version)}`};if(n.bundleIdentity===void 0&&(n.identity=r),o.actions.length>0)try{xt(o.actions.map(E=>({actionId:E.actionId,inputSchema:E.inputSchema})));}catch(E){if(E instanceof de){b(n,Bn(E.code));return}throw E}let s;try{s=await zn(e,n,"ui/index.html",$e);}catch(E){b(n,ve(le(E),"entry"));return}if(s.byteLength>$e){b(n,"LIMIT_EXCEEDED");return}let a;try{a=qt(s);}catch{b(n,"ENTRY_INVALID");return}if(s.byteLength===0||a.length===0){b(n,"ENTRY_INVALID");return}let c=Qn.createHash("sha256").update(s).digest("hex");if(o.entryHash!==void 0&&o.entryHash!==c){b(n,"ENTRY_INVALID");return}let p={},u,f;if(o.initialState!==void 0){try{u=await zn(e,n,"ui/state.json",65536);}catch(E){b(n,ve(le(E),"initial"));return}if(u.byteLength>65536){b(n,"LIMIT_EXCEEDED");return}try{let E=Wn(u),j=o.dataPaths??[],H=Mn(E,j);p=se(H,0,j),me(p);}catch{b(n,"INITIAL_STATE_INVALID");return}if(f=Qn.createHash("sha256").update(u).digest("hex"),o.initialState.hash!==void 0&&o.initialState.hash!==f){b(n,"INITIAL_STATE_INVALID");return}}let A={...o,entryHash:c,...o.initialState===void 0?{}:{initialState:{path:"ui/state.json",hash:f}}},m=Sn(A),g=Ur(A,s,u??new Uint8Array),T;try{T=Rr(m,g);}catch(E){if(E instanceof G){b(n,$t(E));return}throw E}let M;if(n.bundleLineage!==void 0){let E=n.bundleLineage[n.bundleLineage.length-1];if(!E){b(n,"LINEAGE_INVALID");return}let{legacy:j,summaryProjection:H,...Q}=E.definition,{hash:tt,...ki}=T;if(J(Q)!==J(ki)){b(n,"LINEAGE_STALE");return}if(j!==void 0&&(T={...T,legacy:j}),H!==void 0&&(T={...T,summaryProjection:H}),j!==void 0||H!==void 0)try{T={...T,hash:ce(T)},pe(T);}catch{b(n,"LINEAGE_INVALID");return}M=n.bundleLineage;}if(n.bundleIdentity!==void 0&&n.bundleIdentity.appId!==o.pluginId){b(n,"BUNDLE_INTEGRITY");return}if(n.bundleIdentity!==void 0&&(n.bundleIdentity.definitionId!==T.id||n.bundleIdentity.version!==T.version||n.bundleIdentity.definitionHash!==T.hash)){b(n,"LINEAGE_STALE");return}let L=yr(o.pluginId),y=o.actions.length===0?{read:L.read}:L,I=De(m),P=De(A),v=De(T),R=De({...m.handlers}),l=Jt(s),N=u===void 0?void 0:Jt(u),Y=Object.freeze({...n.provenance===void 0?{}:{provenance:n.provenance},entry:Object.freeze({path:"ui/index.html",hash:c,bytes:l}),...N===void 0?{}:{initialState:Object.freeze({path:"ui/state.json",hash:f,bytes:N})}}),$={appId:o.pluginId,pluginId:o.pluginId,definitionId:o.definitionId,version:o.version,relativePath:n.relativePath,manifest:P,normalized:I,name:o.name,description:o.description,...o.icon===void 0?{}:{icon:o.icon},...o.tone===void 0?{}:{tone:o.tone},definition:v,handlers:R,resources:Y,html:a,entryBytes:l,entryHash:c,initialState:De(p),...N===void 0?{}:{initialStateBytes:N},...f===void 0?{}:{initialStateHash:f},sourceHash:g,toolNames:Object.freeze(y)},O=n.provenance===void 0?{...$,source:n.source}:{...$,provenance:n.provenance,lineage:M??[]};n.candidate=Object.freeze(O),Or(o)&&b(n,"EXEC_DENIED");}async function Fr(e,n){try{return await zn(e,n,"ui-plugin.json",262144)}catch(t){if(le(t)==="NOT_FOUND")return;b(n,ve(le(t),"manifest"));return}}function jr(e,n,t){let i=Vr(e);Cr(i);let o=Object.freeze(i.filter(a=>a.candidate!==void 0&&a.diagnostic===void 0).map(a=>a.candidate)),r=Object.freeze(i.filter(a=>a.diagnostic!==void 0).map(a=>a.diagnostic)),s={apps:o,diagnostics:r,complete:n===void 0,...n===void 0?{}:{incompleteReason:n},...t===void 0?{}:{productBundleIndexHash:t}};return Object.defineProperty(s,"candidates",{configurable:false,enumerable:false,get:()=>o}),Object.freeze(s)}function Br(e){if(e===null||typeof e!="object"&&typeof e!="function")return false;let n=e;return typeof n.readVerifiedFile=="function"||typeof n.readFileVerified=="function"||typeof n.listDirectory=="function"||typeof n.readDirectory=="function"||typeof n.readdir=="function"}function Hr(e,n){if(Br(e))return {fs:e,options:{}};let t=e??n??{};return {fs:t.filesystem??t.fileSystem??t.fs??Ht,options:t}}async function Qt(e,n,t){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");let{fs:i,options:o}=Hr(n,t),r=o.clock??Lr,s=r(),a=[],c=0,p,u=await Sr(o.productBundle,i,s,r);a.push(...u.diagnostics.map(m=>({source:m.source,root:o.productBundle?.root??e,name:"",relativePath:m.relativePath,diagnostic:m})));let f=u.packages.map(m=>m.indexEntry);u.incomplete&&(p="time_limit");for(let m of u.packages){let g=m.indexEntry,T=g.packageDir,M=u.indexHash===void 0?void 0:Ot(Object.freeze({kind:"bundled",indexHash:u.indexHash,packageDir:T,appId:g.appId,definitionId:g.definition.id,version:g.definition.version,definitionHash:g.definition.hash,files:g.files})),L={source:"bundled",root:o.productBundle?.root??e,name:T.slice(5),relativePath:T,...M===void 0?{}:{provenance:M},...m.files===void 0?{}:{pinnedFiles:m.files},...m.lineage===void 0?{}:{bundleLineage:m.lineage},bundleIdentity:{appId:g.appId,definitionId:g.definition.id,version:g.definition.version,definitionHash:g.definition.hash},identity:br(g)};if(a.push(L),c+=1,m.failureCode!==void 0){b(L,m.failureCode);continue}let y=m.files?.get("ui-plugin.json");if(y===void 0){b(L,"BUNDLE_INTEGRITY");continue}await Xt(i,L,y),L.candidate!==void 0&&L.diagnostic===void 0&&c<64&&!X(s,r)&&(p="time_limit");}let A=[{source:"apps",directory:"apps"},{source:"skills",directory:"skills"}];for(let m of A){let{source:g,directory:T}=m,M;try{M=await Qe(i,e,T);}catch(y){if(le(y)==="NOT_FOUND")continue;a.push({source:g,root:e,name:"",relativePath:g,diagnostic:en(ve(le(y),"manifest"),g,g)});continue}let L=M.filter(y=>y.kind==="directory"||y.kind==="symlink").filter(y=>Yt(y.name)).map(y=>({source:g,root:e,name:y.name,relativePath:hr(g,y.name)})).sort((y,I)=>Ne(y.relativePath,I.relativePath));for(let y of L){let I={...y};a.push(I);let P;if(g==="skills"&&(P=await Fr(i,I),P===void 0))continue;if(c>=64){b(I,"LIMIT_EXCEEDED");continue}if(y.relativePath.split("/").length-1>2){b(I,"LIMIT_EXCEEDED");continue}if(p!==void 0||!X(s,r)){b(I,"LIMIT_EXCEEDED"),p="time_limit";continue}if(c+=1,P===void 0)try{P=await Ze(i,I.root,`${I.relativePath}/ui-plugin.json`,262144);}catch(R){b(I,ve(le(R),"manifest"));continue}await Xt(i,I,P),I.diagnostic===void 0&&c<64&&!X(s,r)&&(p="time_limit");}}return vr(a,o,f),jr(a,p,u.indexHash)}var Gr=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/;function tn(e){let n="screenHash"in e?e.screenHash:void 0,i=("skillHash"in e?e.skillHash:void 0)??(e.relativePath!==void 0&&e.fileBytes!==void 0?$r(e.relativePath,e.fileBytes):void 0);if(n!==void 0&&i!==void 0){let o=JSON.stringify({screenHash:n,skillHash:i});return Qn.createHash("sha256").update(o,"utf8").digest("hex")}if(n!==void 0)return n;if(i!==void 0)return i;throw new TypeError("App definition hash input must contain a screenHash or skill bytes")}function $r(e,n){let t=new TextEncoder().encode(on(e)),i=Wr(n),o=new Uint8Array(t.byteLength+1+i.byteLength);return o.set(t,0),o[t.byteLength]=0,o.set(i,t.byteLength+1),Qn.createHash("sha256").update(o).digest("hex")}function Wr(e){if(typeof e=="string")return new TextEncoder().encode(e);if(e instanceof Uint8Array)return new Uint8Array(e);if(e instanceof ArrayBuffer)return new Uint8Array(e.slice(0));if(Array.isArray(e)&&e.every(n=>Number.isInteger(n)&&n>=0&&n<=255))return Uint8Array.from(e);throw new TypeError("fileBytes must be UTF-8 text or bytes")}function on(e){if(typeof e!="string"||e.length===0||B.isAbsolute(e)||/[\\\u0000]/.test(e))throw new TypeError("relative path must be package-relative");let n=e.split("/").filter(t=>t.length>0&&t!==".").join("/");if(!n||n.split("/").some(t=>t===".."))throw new TypeError("relative path must stay inside the package");return n}function nn(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),o=Math.min(t.byteLength,i.byteLength);for(let r=0;r<o;r+=1){let s=t[r]-i[r];if(s!==0)return s}return t.byteLength-i.byteLength}function ti(e,n){let t=B.relative(e,n).split(B.sep).join("/");return !t||t===".."||t.startsWith("../")||B.isAbsolute(t)?null:on(t)}function Jr(e){return e==="apps"||e.startsWith("apps/")?"apps":e==="skills"||e.startsWith("skills/")?"skills":e==="node_modules"||e.startsWith("node_modules/")?"node_modules":null}function ii(e){return Object.freeze({packageRoot:e})}function Kr(e){return Object.freeze({id:e.definition.id,version:e.definition.version,hash:e.definition.hash,usage:e.definition.usage??ae,...e.definition.detailPanel===void 0?{}:{detailPanel:e.definition.detailPanel},...e.definition.displayModes===void 0?{}:{displayModes:e.definition.displayModes}})}function oi(e){return {capabilities:Object.freeze([...e]),origin:"local",ownership:"unknown",shareability:"unknown",sharingAvailability:"unavailable"}}function Xr(e,n){let t=e.candidate,i=t.provenance!==void 0,o=n&&!i?["screen","skill"]:["screen"],r=Kr(t),s=tn(n?{screenHash:r.hash,skillHash:n.skillHash}:{screenHash:r.hash}),a=t.description||n?.skill.description||"",c=String(t.version),p={appId:t.pluginId,name:t.name,description:a,version:c,...oi(o),definition:r,...n===void 0||i?{}:{skillName:n.skill.name},...i?{provenance:t.provenance}:{localDefinitionRef:ii(e.packageRoot)},definitionHash:s};return {...i?{}:{packageRoot:e.packageRoot},source:i?"bundled":t.source,appId:p.appId,capabilities:o,summary:Object.freeze(p)}}function Yr(e){let n=qr(e.skill.name),t={appId:n,name:e.skill.name,description:e.skill.description??"",...e.skill.version===void 0?{}:{version:e.skill.version},...oi(["skill"]),skillName:e.skill.name,localDefinitionRef:ii(e.packageRoot),definitionHash:tn({skillHash:e.skillHash})};return {packageRoot:e.packageRoot,source:e.source,appId:n,capabilities:["skill"],summary:Object.freeze(t)}}function qr(e){return `skill.${e.replace(/^@/,"").replace(/\//g,".").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,122)||"unnamed"}`}function F(e,n,t,i){return Object.freeze({code:e,source:n,relativePath:Zr(t),...i===void 0?{}:{appId:i}})}function Zr(e){if(typeof e!="string"||e.length===0||B.isAbsolute(e)||/[\\\u0000]/.test(e))return "<unknown>";let n=e.split("/").filter(t=>t.length>0&&t!==".").join("/");return n.split("/").some(t=>t==="..")?"<unknown>":n}function Qr(e){return F(e.code,e.source,e.relativePath,e.pluginId)}function es(e,n){let t=ti(e,n.dir);if(!t)return {diagnostic:F("PATH_ESCAPED","node_modules","node_modules")};let i=Jr(t);if(!i)return {diagnostic:F("PATH_ESCAPED","node_modules",t)};let o=Un(n.skillMdPath);if(!o.readable)return {diagnostic:F("SKILL_READ_FAILED",i,t)};if(!o.valid)return {diagnostic:F("SKILL_INVALID",i,t)};let r=ns(n.dir,n.skillMdPath);if(!r)return {diagnostic:F("PATH_ESCAPED",i,t)};try{let s=new Uint8Array(C.readFileSync(n.skillMdPath));return {skill:n,packageRoot:t,relativeSkillPath:r,skillHash:tn({relativePath:r,fileBytes:s}),source:i}}catch{return {diagnostic:F("SKILL_READ_FAILED",i,t)}}}function ns(e,n){let t=B.relative(e,n).split(B.sep).join("/");try{return on(t)}catch{return null}}function ts(e){if(!Gr.test(e.appId))return {diagnostic:F("BUILTIN_INVALID","builtin",`builtin/${e.appId||"unknown"}`)};let n=e.definition===void 0?void 0:{id:e.definition.id,version:e.definition.version,hash:e.definition.hash,usage:e.definition.usage??ae,...e.definition.detailPanel===void 0?{}:{detailPanel:e.definition.detailPanel},...e.definition.displayModes===void 0?{}:{displayModes:e.definition.displayModes}},t=n?.hash??Qn.createHash("sha256").update(JSON.stringify({appId:e.appId,name:e.name,description:e.description}),"utf8").digest("hex"),i={appId:e.appId,name:e.name,description:e.description,...n===void 0?{}:{version:String(n.version),definition:n},capabilities:["screen"],origin:"builtin",ownership:"unknown",shareability:"forbidden",sharingAvailability:"unavailable",definitionHash:t};return {source:"builtin",appId:e.appId,summary:Object.freeze(i)}}function is(e){return e.builtinCatalog}function os(e){let n=e.packageRoot??e.relativePath??e.packageRootPath;if(n===void 0)return null;try{return on(n)}catch{return null}}function rs(e){let n=e.marketplaceContentId;return typeof n=="string"&&n.length>0?n:void 0}function ss(e,n,t){let i=n.installed??[],o=new Map;for(let s of i){let a=os(s);if(!a){t.push(F("INSTALLED_IDENTITY_MISMATCH","installed","installed"));continue}let c=o.get(a);if(c&&JSON.stringify(c)!==JSON.stringify(s)){t.push(F("INSTALLED_IDENTITY_MISMATCH","installed",a));continue}o.set(a,s);}let r=new Map;for(let s of e)s.packageRoot!==void 0&&r.set(s.packageRoot,s);for(let[s,a]of o){let c=r.get(s);if(!c){t.push(F("INSTALLED_MISSING","installed",s,a.appId));continue}let p=rs(a);if(!p){t.push(F("INSTALLED_CONTENT_ID_MISSING","installed",s,a.appId));continue}if(a.appId!==void 0&&a.appId!==c.appId||a.definitionHash!==void 0&&a.definitionHash!==c.summary.definitionHash){t.push(F("INSTALLED_IDENTITY_MISMATCH","installed",s,a.appId));continue}let u={...c.summary,origin:"installed",...a.slug===void 0?{}:{slug:a.slug},marketplaceContentId:p},f=e.indexOf(c);f>=0&&(e[f]={...c,summary:Object.freeze(u)});}}function as(e,n){let t=new Map;for(let o of e){let r=t.get(o.appId)??[];r.push(o),t.set(o.appId,r);}let i=new Set;for(let o of t.values()){if(o.length<2)continue;let r=o.some(s=>s.source==="builtin")?"builtin":o.some(s=>s.source==="bundled")?"bundled":void 0;if(r!==void 0){let s=o.filter(a=>a.source===r);for(let a of o.filter(c=>c.source!==r))i.add(a),n.push(F("RESERVED_ID",a.source,Kn(a),a.appId));if(s.length>1)for(let a of s)i.add(a),n.push(F("DUPLICATE_ID",a.source,Kn(a),a.appId));continue}for(let s of o)i.add(s),n.push(F("DUPLICATE_ID",s.source,Kn(s),s.appId));}return e.filter(o=>!i.has(o))}function Kn(e){return e.packageRoot??e.summary.provenance?.packageDir??`builtin/${e.appId}`}function cs(e,n){return e.filter(t=>!(t.code==="MANIFEST_MISSING"&&n.has(t.relativePath))).map(Qr)}function ps(e){return e.filesystem}function ds(e,n){let t=ps(e);return {...t===void 0?{}:{filesystem:t},...e.productBundle===void 0?{}:{productBundle:e.productBundle},...n===void 0?{}:{builtinCatalog:n}}}async function ri(e,n={}){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");let t=is(n),i=await Qt(e,ds(n,t)),o=[B.join(e,"skills"),B.join(e,"node_modules"),B.join(e,"apps")],r=[],s=[],a=[],c=new Set;for(let y of o)for(let I of Nt([y])){let P=ti(e,I.dir);(P===null||!c.has(P))&&(a.push(I),P!==null&&c.add(P));}for(let y of a){let I=es(e,y);"diagnostic"in I?r.push(I.diagnostic):s.push(I);}let p=new Map;for(let y of i.apps??i.candidates??[]){let I=y.provenance===void 0?`workspace\0${y.relativePath}`:`bundled\0${y.provenance.indexHash}\0${y.provenance.packageDir}`;p.set(I,{candidate:y,packageRoot:y.relativePath});}let u=new Map(s.map(y=>[y.packageRoot,y])),f=[];for(let y of p.values()){let I=y.candidate.provenance===void 0?u.get(y.packageRoot):void 0,P=Xr(y,I);f.push({...P.packageRoot===void 0?{}:{packageRoot:P.packageRoot},source:P.source,appId:P.appId,summary:P.summary});}let A=new Set([...p.values()].filter(y=>y.candidate.provenance===void 0).map(y=>y.packageRoot));for(let y of s){if(A.has(y.packageRoot))continue;let I=Yr(y);f.push({packageRoot:I.packageRoot,source:I.source,appId:I.appId,summary:I.summary});}let m=[...cs(i.diagnostics,new Set(s.map(y=>y.packageRoot))),...r],g=[];if(t)for(let y of t.listMcpApps()){let I=ts(y);"diagnostic"in I?m.push(I.diagnostic):g.push(I);}let T=as([...f,...g],m);ss(T,n,m);let M=T.map(y=>y.summary).sort((y,I)=>nn(y.appId,I.appId)),L=[...m].sort((y,I)=>nn(y.relativePath,I.relativePath)||nn(y.code,I.code)||nn(y.appId??"",I.appId??""));return Object.freeze({items:Object.freeze(M),diagnostics:Object.freeze(L)})}function ls(e){let n=o=>o.replace(/[.+^${}()|[\]\\]/g,"\\$&"),i=e.split("/").map(o=>o==="**"?".*":o.split("*").map(n).join("[^/]*"));return new RegExp(`^${i.join("\\/")}$`)}function Me(e,n){try{return ls(n).test(e)}catch{return false}}function rn(e,...n){let t=e.split("/");if(t.length<n.length)return false;let i=t.length-n.length;return n.every((o,r)=>Me(t[i+r],o))}function us(e,n){return e.split("/").some(t=>Me(t,n))}var si=[{label:".env*",test:e=>Me(e,".env*")},{label:".git/",test:(e,n,t)=>t&&e===".git"},{label:"memory/",test:(e,n,t)=>t&&e==="memory"},{label:"*.key",test:e=>Me(e,"*.key")},{label:"*.pem",test:e=>Me(e,"*.pem")},{label:"auth.json",test:e=>e==="auth.json"},{label:"node_modules/",test:(e,n,t)=>t&&e==="node_modules"},{label:"conversations/",test:(e,n,t)=>t&&e==="conversations"},{label:".crewx/threads/",test:(e,n,t)=>t&&rn(n,".crewx","threads")},{label:".crewx/crewx.db",test:(e,n,t)=>!t&&rn(n,".crewx","crewx.db")},{label:".crewx/*.log",test:(e,n,t)=>!t&&rn(n,".crewx","*.log")},{label:".crewx/publish/",test:(e,n,t)=>t&&rn(n,".crewx","publish")},{label:".crewx/",test:(e,n)=>us(n,".crewx")}];function sn(e,n,t){for(let i of si)if(i.test(e,n,t))return i.label;return null}function qn(e){let n=[],t=[];function i(o,r,s){let a;try{a=C__namespace.readdirSync(o,{withFileTypes:!0});}catch{return}a.sort((c,p)=>c.name.localeCompare(p.name));for(let c of a){let p=r?`${r}/${c.name}`:c.name,u=B__namespace.join(o,c.name);if(c.isSymbolicLink()){let f;try{f=C__namespace.statSync(u);}catch{t.push({path:p,rule:"symlink"});continue}if(f.isDirectory()){t.push({path:p,rule:s??"symlink-dir"});continue}let A=s??sn(c.name,p,false);A?t.push({path:p,rule:A}):t.push({path:p,rule:"symlink"});continue}if(c.isDirectory()){let f=s??sn(c.name,p,true);i(u,p,f);continue}if(c.isFile()){let f=s??sn(c.name,p,false);f?t.push({path:p,rule:f}):n.push(p);}}}return i(e,"",null),n.sort(),t.sort((o,r)=>o.path<r.path?-1:o.path>r.path?1:0),{included:n,excluded:t}}var fs=[{rule:"token-prefix",regex:/\b(?:sk-|ghp_|xoxb-)[A-Za-z0-9_-]{10,}/},{rule:"private-key",regex:/-----BEGIN [A-Z ]*PRIVATE KEY-----/},{rule:"aws-access-key",regex:/\bAKIA[0-9A-Z]{16}\b/}];function ys(e){return e.includes(0)}function Zn(e,n,t){let i=[];for(let o of n){let r=B__namespace.join(e,o),s;try{let c=t?.get(o);s=c===void 0?C__namespace.readFileSync(r):Buffer.from(c);}catch{continue}if(ys(s))continue;s.toString("utf8").split(/\r\n|\r|\n/).forEach((c,p)=>{for(let{rule:u,regex:f}of fs)f.test(c)&&i.push({path:o,line:p+1,rule:u});});}return i}var ie=class extends Error{constructor(t,i){super(`publish: [${t}]${i?` ${i}`:""}`);this.code=t;}code;name="PublishError"};function h(e,n){return new ie(e,n)}var di=/^[a-z0-9-]+$/,As=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/,gs=/^[A-Za-z_][A-Za-z0-9_]*$/;function Is(e){let n=B__namespace.join(e,"crewx.yaml");if(!C__namespace.existsSync(n))return {};let t;try{t=li__namespace.load(C__namespace.readFileSync(n,"utf8"));}catch{return {}}if(!t||typeof t!="object")return {};let i=t.metadata;if(!i||typeof i!="object")return {};let o=i;return {name:typeof o.name=="string"?o.name:void 0,version:typeof o.version=="string"?o.version:void 0,description:typeof o.description=="string"?o.description:void 0,requiredEnv:o.requiredEnv,crewxMinVersion:typeof o.crewxMinVersion=="string"?o.crewxMinVersion:void 0}}function ms(e){return Qn__namespace.createHash("sha256").update(e).digest("hex")}function ui(e){let n;try{n=C__namespace.lstatSync(e);}catch{throw h("PACKAGE_FILE_INVALID",`file is not readable: ${B__namespace.basename(e)}`)}if(n.isSymbolicLink())throw h("PACKAGE_SYMLINK","symlink content is not publishable");if(!n.isFile())throw h("PACKAGE_FILE_INVALID","only regular files are publishable");return Qn__namespace.createHash("sha256").update(new Uint8Array(C__namespace.readFileSync(e))).digest("hex")}function hs(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),o=Math.min(t.byteLength,i.byteLength);for(let r=0;r<o;r+=1){let s=t[r]-i[r];if(s!==0)return s}return t.byteLength-i.byteLength}function fi(e){if(typeof e!="string"||e.length===0||e.includes("\\")||e.includes("\0")||B__namespace.posix.isAbsolute(e)||e.split("/").some(n=>n===".."||n.length===0))throw h("PACKAGE_PATH_TRAVERSAL","manifest file path must be a non-empty POSIX relative path")}function Es(e){if(!/^(?:apps|skills)\/[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(e))throw h("APP_PACKAGE_ROOT_INVALID","packageRoot must be apps/<safe-id> or skills/<safe-id>")}function yi(e){if(!As.test(e))throw new Error(`publish: invalid version "${e}" \u2014 must be semver (e.g. 1.0.0)`)}function Ai(e,n,t={}){let i=Is(e),o=i.name??B__namespace.basename(e);if(!di.test(o))throw new Error(`publish: invalid name "${o}" \u2014 must match ${di} (lowercase letters, numbers, hyphen only)`);let r=t.version??i.version;if(!r)throw new Error("publish: version is required \u2014 set crewx.yaml metadata.version or pass opts.version");yi(r);let s=Array.isArray(i.requiredEnv)?i.requiredEnv:[],a=[];for(let u of s){if(typeof u!="string"||!gs.test(u))throw new Error(`publish: requiredEnv must contain names only (no values), got "${String(u)}"`);a.push(u);}let c=n.map(u=>(fi(u),{path:u,sha256:ui(B__namespace.join(e,u))})).sort((u,f)=>u.path<f.path?-1:u.path>f.path?1:0),p={name:o,version:r,type:"template",description:i.description??"",files:c,requiredEnv:a};return i.crewxMinVersion&&(p.crewxMinVersion=i.crewxMinVersion),p}function _s(e){let n=e.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"");if(!n)throw h("APP_PACKAGE_ROOT_INVALID","appId cannot produce a marketplace name");return n}function gi(e,n){if(Es(n.packageRoot),!n.version)throw new Error("publish: version is required for App publishing \u2014 pass opts.version");if(yi(n.version),typeof n.description!="string")throw new Error("publish: App description must be a string");let t=[...new Set(n.capabilities)].sort();if(t.length===0||t.some(s=>s!=="screen"&&s!=="skill"))throw new Error("publish: App capabilities must contain screen or skill");let i=`${n.packageRoot}/`;if(t.includes("screen")){if(typeof n.definitionId!="string"||n.definitionId.length===0)throw h("APP_UI_MANIFEST_INVALID","screen App manifests require definitionId");for(let s of ["ui-plugin.json","ui/index.html"])if(!n.includedFiles.includes(`${i}${s}`))throw h("APP_UI_MANIFEST_INVALID",`screen App is missing ${s}`)}if(t.includes("skill")&&!n.includedFiles.includes(`${i}SKILL.md`))throw h("APP_SKILL_MISSING","skill capability requires package-root SKILL.md");let o=new Set,r=n.includedFiles.map(s=>{if(fi(s),!s.startsWith(i))throw h("PACKAGE_PATH_TRAVERSAL","App manifest file is outside packageRoot");let a=n.generatedFiles?.get(s);return a!==void 0&&o.add(s),{path:s,sha256:a===void 0?ui(B__namespace.join(e,s)):ms(a),...a===void 0?{}:{generated:true}}}).sort((s,a)=>hs(s.path,a.path));if(o.size>0&&(o.size!==1||!o.has(`${i}ui-plugin.json`)))throw new Error("publish: only the generated ui-plugin.json may be present in an App package");return {manifestVersion:1,name:_s(n.appId),version:n.version,type:"app",description:n.description,appId:n.appId,...n.definitionId===void 0?{}:{definitionId:n.definitionId},...n.definitionHash===void 0?{}:{definitionHash:n.definitionHash},capabilities:t,packageRoot:n.packageRoot,files:r,requiredEnv:[]}}function Ii(e){return Qn__namespace.createHash("sha256").update(e).digest("hex")}function Ti(e,n){if(typeof n!="string"||n.length===0||n.includes("\\")||n.includes("\0")||B__namespace.posix.isAbsolute(n)||n.split("/").some(o=>o===".."||o.length===0))throw h("PACKAGE_PATH_TRAVERSAL","archive paths must be non-empty POSIX relative paths");let t=B__namespace.resolve(e),i=B__namespace.resolve(t,...n.split("/"));if(i!==t&&!i.startsWith(`${t}${B__namespace.sep}`))throw h("PACKAGE_PATH_TRAVERSAL","archive path escaped its root");return i}function mi(e,n){let t=Ti(e,n),i;try{i=C__namespace.lstatSync(t);}catch{throw h("PACKAGE_FILE_INVALID","manifest file is missing")}if(i.isSymbolicLink())throw h("PACKAGE_SYMLINK","symlink content is not publishable");if(!i.isFile())throw h("PACKAGE_FILE_INVALID","only regular files are publishable");return new Uint8Array(C__namespace.readFileSync(t))}async function Pi(e,n,t={}){let i=B__namespace.join(e,".crewx","publish");C__namespace.mkdirSync(i,{recursive:true});let o=B__namespace.join(i,`${n.name}-${n.version}.tgz`),r=B__namespace.join(i,`.${n.name}-${n.version}.${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}.tmp.tgz`),s=C__namespace.mkdtempSync(B__namespace.join(hi__namespace.tmpdir(),"crewx-publish-"));try{let a=new Set,c=[];for(let p of n.files){if(a.has(p.path))throw h("PACKAGE_PATH_TRAVERSAL","manifest contains duplicate file paths");a.add(p.path);let u=t.generatedFiles?.get(p.path);if(p.generated===!0&&u===void 0)throw h("PACKAGE_GENERATED_FILE_MISSING","generated manifest file bytes are missing");if(t.sourceFileHashes?.has(p.path)){let m=mi(e,p.path);if(t.sourceFileHashes.get(p.path)!==Ii(m))throw h("PACKAGE_STAGED_BYTES_MISMATCH","workspace source changed before staging")}let f=u??mi(e,p.path);if(Ii(f)!==p.sha256)throw h("PACKAGE_STAGED_BYTES_MISMATCH",`staged bytes differ for ${p.path}`);let A=Ti(s,p.path);C__namespace.mkdirSync(B__namespace.dirname(A),{recursive:!0}),C__namespace.writeFileSync(A,new Uint8Array(f)),c.push(p.path);}C__namespace.writeFileSync(B__namespace.join(s,"manifest.json"),JSON.stringify(n,null,2)),await _i__namespace.create({gzip:!0,file:r,cwd:s,portable:!0,noMtime:!0},["manifest.json",...c]),C__namespace.renameSync(r,o);}finally{try{C__namespace.rmSync(r,{force:!0});}catch{}C__namespace.rmSync(s,{recursive:true,force:true});}return o}var Se="/api/v1";var Ds=201,bs=200,Ns=409,et=401,Di={APP_NAME_CONFLICT:"APP_NAME_CONFLICT",CONTENT_SUSPENDED:"PUBLISH_CONTENT_SUSPENDED",CONTENT_REJECTED:"CONTENT_REJECTED",APP_VERSION_MUST_INCREASE:"APP_VERSION_MUST_INCREASE",APP_VERSION_INVALID:"APP_VERSION_INVALID"};function Ms(){return process.env.WI013_FAKE_UPLOAD==="1"}function Ss(e){let n=zlib.gunzipSync(new Uint8Array(e)),t=zlib.gzipSync(new Uint8Array(n),{level:1});if(Buffer.compare(new Uint8Array(t),new Uint8Array(e))===0)throw new Error("publish: [E_MALFORMED] Re-gzipped upload bytes are identical to the original \u2014 tamper is a no-op");return t}function Ls(e){return e.replace(/\/+$/,"")}async function Ve(e){try{return await e.json()}catch{return null}}function bi(e,n,t){let i=e;if(!i||i.success!==true||i.data===void 0)throw new Error(`publish: [E_MALFORMED] ${n} response envelope is malformed (expected { success: true, data }) \u2014 HTTP ${t}`);return i.data}function Us(e){if(!e||typeof e!="object"||Array.isArray(e))return;let n=e;if(typeof n.contentId=="string"&&n.contentId.length>0)return n.contentId;if(!n.data||typeof n.data!="object"||Array.isArray(n.data))return;let t=n.data;return typeof t.contentId=="string"&&t.contentId.length>0?t.contentId:void 0}function Rs(e){if(!e||typeof e!="object"||Array.isArray(e))return;let n=e;if(typeof n.slug=="string"&&n.slug.length>0)return n.slug;if(!n.data||typeof n.data!="object"||Array.isArray(n.data))return;let t=n.data;return typeof t.slug=="string"&&t.slug.length>0?t.slug:void 0}function Ni(e,n){if(!e||typeof e!="object"||Array.isArray(e))return;let t=e,i=t.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:void 0,o=[t.code,t.message,i?.code,i?.message];for(let r of o){if(typeof r!="string"||!Object.prototype.hasOwnProperty.call(Di,r))continue;let s=r,a=s==="APP_NAME_CONFLICT"?`marketplace name is already in use: ${n}`:void 0;return h(Di[s],a)}}async function Os(e){if(!e.baseUrl.trim())throw new Error("publish: [E_ENV_MISSING] Marketplace base URL is required");if(!e.accessToken.trim())throw new Error("publish: [E_AUTH_EXPIRED] A valid bearer token is required");let n=Ls(e.baseUrl),t=e.accessPolicy??"private",i=e.manifest.name,o=e.manifest.type==="app"?e.manifest:void 0,r=o!==void 0,s=o?.appId,a;try{a=await fetch(`${n}${Se}/publisher/items`,{method:"POST",headers:{Authorization:`Bearer ${e.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify({slug:i,displayName:i,description:e.manifest.description,type:e.manifest.type,version:e.manifest.version,accessPolicy:t,...s===void 0?{}:{appId:s}})});}catch{throw new Error("publish: [E_NETWORK] Submit request failed (network)")}let c=await Ve(a),p=Us(c),u=Rs(c),f=r&&u!==void 0?u:i,A;if(a.status===Ds)A="created";else if(r&&a.status===bs){if(p===void 0)throw h("PUBLISH_CONTENT_ID_MISSING","App republish did not return an opaque contentId");A="existing";}else if(a.status===Ns){if(r)throw Ni(c,i)??h("APP_NAME_CONFLICT",`marketplace name is already in use: ${i}`);A="existing";}else throw a.status===et?new Error("publish: [E_AUTH_EXPIRED] Authentication is expired or missing \u2014 please log in again (HTTP 401)"):new Error(`publish: [E_HTTP] Submit request failed \u2014 HTTP ${a.status}`);let m="not-needed",g=null;if(A==="existing"&&!r){let l;try{l=await fetch(`${n}${Se}/publisher/items`,{method:"GET",headers:{Authorization:`Bearer ${e.accessToken}`}});}catch{throw new Error("publish: [E_NETWORK] Publisher items request failed (network)")}let N=await Ve(l);if(l.status!==200)throw new Error(`publish: [E_HTTP] Publisher items request failed \u2014 HTTP ${l.status}`);let $=bi(N,"publisher items",l.status)?.items;if(!Array.isArray($))throw new Error(`publish: [E_MALFORMED] Publisher items response is malformed (expected data.items[]) \u2014 HTTP ${l.status}`);let O=$.find(E=>!E||typeof E!="object"?false:E.slug===i);if(!O||typeof O.version!="string")throw new Error(`publish: [E_MALFORMED] Publisher items response does not contain slug "${i}" \u2014 HTTP ${l.status}`);if(g=O.version,g!==e.manifest.version){let E;try{E=await fetch(`${n}${Se}/publisher/items/${encodeURIComponent(i)}`,{method:"PUT",headers:{Authorization:`Bearer ${e.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify({version:e.manifest.version})});}catch{throw new Error("publish: [E_NETWORK] Version update request failed (network)")}if(!E.ok)throw await Ve(E),E.status===et?new Error(`publish: [E_AUTH_EXPIRED] Authentication is expired or missing \u2014 please log in again (HTTP ${E.status})`):E.status===403?new Error(`publish: [E_FORBIDDEN] Version update is forbidden; only the item owner can update an existing item (HTTP ${E.status})`):new Error(`publish: [E_HTTP] Version update failed \u2014 HTTP ${E.status}`);m="applied";}}let T=C__namespace.readFileSync(e.tgzPath),M=Ms()?Ss(T):T,L=new FormData;L.set("archive",new Blob([new Uint8Array(M)],{type:"application/gzip"}),`${f}-${e.manifest.version}.tgz`);let y=r&&p!==void 0?p:i,I;try{I=await fetch(`${n}${Se}/publisher/items/${encodeURIComponent(y)}/upload`,{method:"POST",headers:{Authorization:`Bearer ${e.accessToken}`},body:L});}catch{throw new Error("publish: [E_NETWORK] Upload request failed (network)")}if(I.status===et)throw new Error("publish: [E_AUTH_EXPIRED] Authentication is expired or missing \u2014 please log in again (HTTP 401)");if(!I.ok){let l=await Ve(I);if(r){let N=Ni(l,f);if(N)throw N}throw new Error(`publish: [E_HTTP] Upload request failed \u2014 HTTP ${I.status}`)}let P=await Ve(I),v=bi(P,"upload",I.status),R=typeof v.contentId=="string"&&v.contentId.length>0?v.contentId:p;if(r&&R===void 0)throw h("PUBLISH_CONTENT_ID_MISSING","App upload did not return an opaque contentId");return {slug:f,version:e.manifest.version,...R===void 0?{}:{contentId:R},artifactChecksum:v.artifactChecksum,artifactSizeBytes:v.artifactSizeBytes,submitOutcome:A,versionUpdate:m,serverVersionBefore:g}}var ks=1e4,xs=100*1024*1024;function nt(e){return Qn__namespace.createHash("sha256").update(e).digest("hex")}function ws(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function cn(e,n){if(!n||n.includes("\\")||n.includes("\0")||B__namespace.posix.isAbsolute(n)||n.split("/").some(r=>r===".."||r.length===0))throw h("PACKAGE_PATH_TRAVERSAL","workspace file path is not a safe relative path");let t=B__namespace.resolve(e,...n.split("/")),i=B__namespace.resolve(e);if(t!==i&&!t.startsWith(`${i}${B__namespace.sep}`))throw h("PACKAGE_PATH_TRAVERSAL","workspace file path escaped the workspace root");let o;try{o=C__namespace.lstatSync(t);}catch{throw h("PACKAGE_FILE_INVALID",`workspace file is missing: ${n}`)}if(o.isSymbolicLink())throw h("PACKAGE_SYMLINK",`symlink is not publishable: ${n}`);if(!o.isFile())throw h("PACKAGE_FILE_INVALID",`not a regular file: ${n}`);return new Uint8Array(C__namespace.readFileSync(t))}function pn(e,n){return e===n||e.startsWith(`${n}/`)}function Cs(e,n){return e.path<n.path?-1:e.path>n.path?1:e.rule.localeCompare(n.rule)}function Si(e,n,t){let i=e??n;if(!Number.isSafeInteger(i)||i<=0)throw new ie("PACKAGE_SIZE_LIMIT",`${t} must be a positive integer`);return i}function Ui(e,n,t,i){let o=Si(t.maxFileCount??t.maxFiles,ks,"max file count"),r=Si(t.maxTotalBytes??t.maxBytes,xs,"max total bytes");if(n.length>o)throw new ie("PACKAGE_SIZE_LIMIT",`package exceeds file count limit (${o})`);let s=0;for(let a of n){let c=i?.get(a);if(c!==void 0?s+=c.byteLength:s+=cn(e,a).byteLength,s>r)throw new ie("PACKAGE_SIZE_LIMIT",`package exceeds byte limit (${r})`)}}function vs(e){return e.appId!==void 0||e.expectedDefinitionHash!==void 0}function Vs(e){let n=e.appId!==void 0,t=e.expectedDefinitionHash!==void 0;if(!n&&t)throw h("APP_ID_REQUIRED","appId is required with expectedDefinitionHash");if(n&&!t)throw h("APP_DEFINITION_HASH_REQUIRED","expectedDefinitionHash is required with appId");if(!n||!t)throw h("APP_ID_REQUIRED")}function Fs(e,n){let t=e.filter(i=>i.appId===n);if(t.length===0)throw h("APP_NOT_FOUND",`no publishable App matches ${n}`);if(t.length!==1)throw h("APP_AMBIGUOUS",`more than one App matches ${n}`);return t[0]}function js(e){let n=e.localDefinitionRef?.packageRoot;if(!n||!/^(?:apps|skills)\/[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(n))throw h("APP_PACKAGE_ROOT_INVALID","selected App is not rooted in apps/<safe-id> or skills/<safe-id>");return n}function Bs(e,n){let t=[];for(let i of e.excluded)t.push(pn(i.path,n)?i:{path:i.path,rule:"out-of-app-scope"});for(let i of e.included)pn(i,n)||t.push({path:i,rule:"out-of-app-scope"});return t.sort(Cs)}function Hs(e,n,t,i){let o=`${t}/ui-plugin.json`;if(!i.includes(o))throw h("APP_UI_MANIFEST_INVALID","selected screen App has no package ui-plugin.json");let r=cn(e,o),s=nt(r),a;try{a=JSON.parse(Buffer.from(r).toString("utf8"));}catch{throw h("APP_UI_MANIFEST_INVALID","ui-plugin.json is not valid JSON")}let c;try{let A=fe(a,{mode:"local"});if(A.manifestVersion!==2)throw new Error("screen App requires manifestVersion 2");c=A;}catch(A){throw A instanceof G?h("APP_UI_MANIFEST_INVALID",A.code):h("APP_UI_MANIFEST_INVALID")}if(c.pluginId!==n.appId)throw h("APP_DEFINITION_CONFLICT","ui-plugin.json pluginId no longer matches the selected App");let p=`${t}/ui/index.html`;if(!i.includes(p))throw h("APP_UI_MANIFEST_INVALID","screen entry is outside package scope");let u=nt(cn(e,p)),f=JSON.parse(JSON.stringify(a));if(f.entryHash=u,Object.prototype.hasOwnProperty.call(f,"initialState")){let A=f.initialState;if(!ws(A)||A.path!=="ui/state.json")throw h("APP_INITIAL_STATE_OUT_OF_SCOPE","initialState must reference ui/state.json inside the package");let m=`${t}/ui/state.json`;if(!i.includes(m))throw h("APP_INITIAL_STATE_OUT_OF_SCOPE","initialState reference is outside the selected package");let g=cn(e,m);f.initialState={...A,hash:nt(g)};}try{let A=fe(f,{mode:"published"});return {bytes:new Uint8Array(Buffer.from(yn(A),"utf8")),sourceHash:s}}catch(A){throw A instanceof G?h("APP_UI_MANIFEST_INVALID",A.code):h("APP_UI_MANIFEST_INVALID")}}async function zs(e,n){let{included:t,excluded:i}=qn(e);Ui(e,t,n);let o=Ai(e,t,{version:n.version}),r=Zn(e,t);return {plan:{manifest:o,included:t,excluded:i,secretFindings:r},archiveOptions:{}}}async function Gs(e,n){Vs(n);let t=await ri(e),i=Fs(t.items,n.appId);if(i.definitionHash!==n.expectedDefinitionHash)throw h("APP_DEFINITION_CONFLICT",`definitionHash changed for ${n.appId}`);let o=js(i),r=qn(e);if(r.excluded.some(m=>pn(m.path,o)&&(m.rule==="symlink"||m.rule==="symlink-dir")))throw h("PACKAGE_SYMLINK","selected App package contains a symlink");let s=r.included.filter(m=>pn(m,o)),a=Bs(r,o),c=new Map,p=new Map;if(i.capabilities.includes("screen")){let m=Hs(e,i,o,s);c.set(`${o}/ui-plugin.json`,m.bytes),p.set(`${o}/ui-plugin.json`,m.sourceHash);}if(i.capabilities.includes("skill")&&!s.includes(`${o}/SKILL.md`))throw h("APP_SKILL_MISSING","skill capability requires package-root SKILL.md");Ui(e,s,n,c);let u={appId:i.appId,version:n.version??"",description:i.description,capabilities:i.capabilities,packageRoot:o,...i.definition?.id===void 0?{}:{definitionId:i.definition.id},definitionHash:i.definitionHash,includedFiles:s,generatedFiles:c},f=gi(e,u),A=Zn(e,s,c);return {plan:{manifest:f,included:s,excluded:a,secretFindings:A},archiveOptions:{generatedFiles:c,sourceFileHashes:p}}}async function Ri(e,n){let t=B__namespace.resolve(e);if(vs(n))return Gs(t,n);if(n.expectedDefinitionHash!==void 0)throw h("APP_ID_REQUIRED");return zs(t,n)}async function gp(e,n={}){return (await Ri(e,n)).plan}function $s(e){let n=e.map(t=>`${t.path}:${t.line} (${t.rule})`).join(", ");throw new ie("PUBLISH_SECRET_FINDINGS",`aborted \u2014 secret findings must be resolved before packing: ${n}`)}async function Oi(e,n={}){let t=B__namespace.resolve(e),i=await Ri(t,n);i.plan.secretFindings.length>0&&$s(i.plan.secretFindings);let o=await Pi(t,i.plan.manifest,i.archiveOptions);return {manifest:i.plan.manifest,tgzPath:o}}async function Ip(e,n={}){return Oi(e,n)}async function mp(e,n){let t=await Oi(e,n);if(t.manifest.type!=="app")throw new Error("publish: App pack unexpectedly produced a template manifest");return t}
2
- exports.DEFAULT_PUBLISH_MAX_BYTES=xs;exports.DEFAULT_PUBLISH_MAX_FILES=ks;exports.EXCLUDE_RULES=si;exports.MARKETPLACE_API_PREFIX=Se;exports.PublishError=ie;exports.packApp=mp;exports.packPublish=Oi;exports.packTemplate=Ip;exports.planPublish=gp;exports.uploadToMarketplace=Os;
1
+ 'use strict';var tt=require('crypto'),C=require('fs'),B=require('path'),ui=require('js-yaml'),promises=require('fs/promises'),Ei=require('os'),Ti=require('tar'),zlib=require('zlib');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var tt__namespace=/*#__PURE__*/_interopNamespace(tt);var C__namespace=/*#__PURE__*/_interopNamespace(C);var B__namespace=/*#__PURE__*/_interopNamespace(B);var ui__namespace=/*#__PURE__*/_interopNamespace(ui);var Ei__namespace=/*#__PURE__*/_interopNamespace(Ei);var Ti__namespace=/*#__PURE__*/_interopNamespace(Ti);var b=class extends Error{constructor(t,i=t,o){super(i);this.code=t;this.currentRevision=o;}code;currentRevision;name="UiRuntimeError"};var xi=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,wi=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i,Ci=/<\/?[A-Za-z][^>]*>/,vi=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,ji=/^(?:https?|file|ftp|ws|wss):\/\//i;function J(){throw new b("INPUT_INVALID","JSON value is not projection-safe")}function Vi(e){let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var Fi=8,Bi=4;function un(e,n,t,i,o,r){if(n>i&&J(),e===null||typeof e=="string"||typeof e=="boolean")return typeof e=="string"&&(Ci.test(e)||ji.test(e)&&!Hi(o,r)||vi.test(e))&&J(),e;if(typeof e=="number")return Number.isFinite(e)||J(),e;(typeof e!="object"||e===void 0||typeof e=="function"||typeof e=="bigint")&&J();let s=e;t.has(s)&&J(),t.add(s);try{if(Array.isArray(e))return e.map(c=>un(c,n+1,t,i,o,r));Vi(s)||J();let a={};for(let[c,p]of Object.entries(e))(xi.test(c)||wi.test(c))&&J(),a[c]=un(p,n+1,t,i,[...o,c],r);return a}finally{t.delete(s);}}function se(e,n=0,t=[]){(!Number.isInteger(n)||n<0||n>Bi)&&J(),(!Array.isArray(t)||t.some(o=>typeof o!="string"))&&J();let i=un(e,0,new Set,Fi+n,[],t);return (i===null||Array.isArray(i)||typeof i!="object")&&J(),i}function Ie(e,n){if(!e||!n)return false;let t=e.split("."),i=n.split(".");return t.length>=i.length&&i.every((o,r)=>t[r]===o)}function Hi(e,n){if(e.length===0)return false;let t=e.join(".");return n.some(i=>Ie(t,i))}function me(e){try{let n=JSON.stringify(e);return n===void 0&&J(),n}catch{J();}}function fn(e){return Array.isArray(e)?e.map(fn):e!==null&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,fn(e[n])])):e}function K(e){return me(fn(e))}function yn(e){return Buffer.byteLength(e,"utf8")}function An(e){return K(e)}var ae="window";var rt=["__proto__","prototype","constructor","proof","token","secret","password","cookie","authorization","private_key","private-key","stack","exception","plugin_text","url","uri","endpoint","path","filename","filepath","cwd","shell","directory","dir","folder"],zi=new Set(rt),Gi=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,$i=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i;function he(e){return zi.has(e)||Gi.test(e)||$i.test(e)}var Ve=/^[A-Za-z0-9_]+$/,Le=/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/,Ee=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,gn=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,In=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,mn=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/,hn=["blue","violet","emerald","amber","rose","sky","slate","indigo"],En=["inline","panel"];var Wi=1,Ji=/^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$/,Ki=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,At=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,Xi=/<\/?[A-Za-z][^>]*>/,Yi=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,qi=/^(?:https?|file|ftp|ws|wss):\/\//i,Zi=/^\s*(?:javascript|data):/i,st=/data:[^,\s]*,/i,Qi=/(?:https?|file|ftp|ws|wss):\/\//i,eo=/javascript:/i,no=/(?:^[\s]*|[\s"'(=])(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)(?=[^\s"'<>])[^\s"'<>]*/,to=["manifestVersion","pluginId","definitionId","version","primitiveSet","activation","schema","layout"],io=["manifestVersion","pluginId","definitionId","version","name","description","entry","surfaces","size","stateProjection","actions"],oo=["_meta","icon","tone","entryHash","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths"],ro=["actionId","capability","mutation","inputSchema","resultProjection","backend"],so=["confirmation","dataInputs","_meta"],ao=4*1024,co=["type","handler"],po=["type","command"],lo=["path"],uo=["hash"],fo=/^[0-9a-f]{64}$/,yo=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/,Ao=/[\r\n]/,go=16,Io=["card-shell","meta-banner","heading","labeled-text","step-flow","text-list"],G=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="UiPluginValidationError"};function d(e,n=e){throw new G(e,n)}function O(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function S(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function k(e,n,t=[]){let i=new Set([...n,...t]);Object.keys(e).some(o=>!i.has(o))&&d("MANIFEST_INVALID"),n.some(o=>!S(e,o))&&d("MANIFEST_INVALID");}function Ge(e,n=false,t=false,i=false){return Xi.test(e)||!i&&qi.test(e)||Yi.test(e)||t&&st.test(e)||Zi.test(e)&&!(n&&/^\s*data:/i.test(e)&&!st.test(e))}function He(e,n=new Set,t=0,i=false,o=false){if(typeof e=="string"){Ge(e,i,o)&&d("UNSAFE_VALUE");return}if(!(e===null||typeof e!="object")){(t>8||n.has(e))&&d("MANIFEST_INVALID"),n.add(e);try{if(Array.isArray(e)){for(let r of e)He(r,n,t+1);return}O(e)||d("MANIFEST_INVALID");for(let[r,s]of Object.entries(e))He(s,n,t+1,i&&t===0&&(r==="name"||r==="description"),o);}finally{n.delete(e);}}}function Z(e,n){let t=e[n];return typeof t!="string"&&d("MANIFEST_INVALID"),t}function q(e,n,t){let i=e[n];return (!Number.isSafeInteger(i)||i<t)&&d("MANIFEST_INVALID"),i}function _n(e){return Ki.test(e)||d("MANIFEST_INVALID"),e}function _e(e){return Ji.test(e)||d("TOKEN_INVALID"),e}function mo(e){return At.test(e)||d("MANIFEST_INVALID"),e}function ho(e){O(e)||d("MANIFEST_INVALID");let n={};for(let[t,i]of Object.entries(e)){let o=mo(t);O(i)||d("MANIFEST_INVALID");let r=i.type;if(r==="text"){k(i,["type","maxLength"]),n[o]={type:r,maxLength:q(i,"maxLength",1)};continue}if(r==="text-list"){k(i,["type","max","itemMaxLength"]),n[o]={type:r,max:q(i,"max",0),itemMaxLength:q(i,"itemMaxLength",1)};continue}if(r==="step-list"){k(i,["type","min","max","labelMaxLength","detailMaxLength"]);let s=q(i,"min",0),a=q(i,"max",1);s>a&&d("MANIFEST_INVALID"),n[o]={type:r,min:s,max:a,labelMaxLength:q(i,"labelMaxLength",1),detailMaxLength:q(i,"detailMaxLength",1)};continue}typeof r=="string"&&d("SCHEMA_TYPE_UNSUPPORTED"),d("MANIFEST_INVALID");}return n}function Eo(e,n,t){let i=e[n];(!i||i.type!==t)&&d("MANIFEST_INVALID");}function Fe(e,n,t){let i=Z(e,"field");return At.test(i)||d("MANIFEST_INVALID"),Eo(n,i,t),i}function _o(e,n){O(e)||d("MANIFEST_INVALID");let t=e.primitive;switch(typeof t!="string"&&d("MANIFEST_INVALID"),Io.includes(t)||d("PRIMITIVE_UNKNOWN"),t){case "card-shell":return k(e,["primitive"]),{primitive:t};case "meta-banner":return k(e,["primitive","badgeToken","noticeToken"]),{primitive:t,badgeToken:_e(Z(e,"badgeToken")),noticeToken:_e(Z(e,"noticeToken"))};case "heading":return k(e,["primitive","field"]),{primitive:t,field:Fe(e,n,"text")};case "labeled-text":return k(e,["primitive","titleToken","field","variant"]),e.variant!=="callout"&&d("MANIFEST_INVALID"),{primitive:t,titleToken:_e(Z(e,"titleToken")),field:Fe(e,n,"text"),variant:"callout"};case "step-flow":return k(e,["primitive","titleToken","field"]),{primitive:t,titleToken:_e(Z(e,"titleToken")),field:Fe(e,n,"step-list")};case "text-list":{k(e,["primitive","titleToken","field"],["emptyToken","hideWhenEmpty"]);let i={primitive:t,titleToken:_e(Z(e,"titleToken")),field:Fe(e,n,"text-list")};return S(e,"emptyToken")&&(i.emptyToken=_e(Z(e,"emptyToken"))),S(e,"hideWhenEmpty")&&(typeof e.hideWhenEmpty!="boolean"&&d("MANIFEST_INVALID"),i.hideWhenEmpty=e.hideWhenEmpty),i}}return d("MANIFEST_INVALID")}function To(e,n){return Array.isArray(e)||d("MANIFEST_INVALID"),e.map(t=>_o(t,n))}function x(e="v2 manifest exceeds a contract limit"){return d("LIMIT_EXCEEDED",e)}function X(e="initial state is not projection-safe"){return d("INITIAL_STATE_INVALID",e)}function at(e,n){return (typeof e!="string"||e.length===0||e.length>4096||e.trim().length===0||yo.test(e)||Ao.test(e))&&d("MANIFEST_INVALID",`${n} is invalid`),(Ge(e,true,true)||Qi.test(e)||eo.test(e)||no.test(e))&&d("UNSAFE_VALUE",`${n} contains an unsafe value`),e}function Tn(e,n){return (typeof e!="string"||!Ee.test(e))&&d("MANIFEST_INVALID",`${n} is invalid`),e}function Po(e){return (typeof e!="string"||!gn.test(e)||e==="*"||e==="all")&&d("MANIFEST_INVALID","action capability is invalid"),e}function gt(e){return (typeof e!="string"||!fo.test(e))&&d("MANIFEST_INVALID","resource hash is invalid"),e}function Pn(e,n=new Set,t=0){if(typeof e=="string"){e.length>4096&&x("v2 manifest string is too long");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||d("MANIFEST_INVALID","v2 manifest contains a non-finite number");return}(e===void 0||typeof e=="function"||typeof e=="bigint")&&d("MANIFEST_INVALID","v2 manifest contains a non-JSON value"),typeof e!="object"&&d("MANIFEST_INVALID"),t>8&&x("v2 manifest nesting is too deep"),n.has(e)&&d("MANIFEST_INVALID","v2 manifest contains a cycle"),n.add(e);try{if(Array.isArray(e)){e.length>128&&x("v2 manifest array is too long");for(let i of e)Pn(i,n,t+1);return}O(e)||d("MANIFEST_INVALID","v2 manifest contains a non-plain object");for(let i of Object.values(e))Pn(i,n,t+1);}finally{n.delete(e);}}}function It(e){return (typeof e!="string"||e.length>4096||!Le.test(e))&&(typeof e=="string"&&e.length>4096&&x("projection path is too long"),d("MANIFEST_INVALID","projection paths must be canonical exact paths")),e.split(".").some(t=>he(t))&&d("MANIFEST_INVALID","projection paths cannot address reserved state keys"),e}function Dn(e){O(e)||d("MANIFEST_INVALID","projection policy must be an object"),k(e,["allow"]),Array.isArray(e.allow)||d("MANIFEST_INVALID","projection allow must be an array"),e.allow.length>128&&x("projection allowlist is too long");let n=[],t=new Set;for(let i of e.allow){let o=It(i);t.has(o)&&d("MANIFEST_INVALID","projection allowlist contains a duplicate path"),t.add(o),n.push(o);}return {allow:n}}function Do(e,n){if(e===void 0)return;Array.isArray(e)||d("MANIFEST_INVALID","dataPaths must be an array"),e.length>go&&x("dataPaths exceed the v2 limit");let t=[],i=new Set;for(let o of e){let r=It(o);i.has(r)&&d("MANIFEST_INVALID","dataPaths contain a duplicate path"),n.some(s=>Ie(r,s))||d("MANIFEST_INVALID","dataPaths must be projection-allowed"),i.add(r),t.push(r);}return t}function Te(e,n,t=Number.MAX_SAFE_INTEGER){return (!Number.isSafeInteger(e)||e<0||e>t)&&d("MANIFEST_INVALID",`${n} is invalid`),e}function ct(e,n){return (typeof e!="number"||!Number.isFinite(e))&&d("MANIFEST_INVALID",`${n} is invalid`),e}function bn(e,n=0,t=new Set){if(typeof e=="string")return (e.length>4096||Ge(e))&&d("UNSAFE_VALUE","schema enum contains an unsafe string"),e;if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||d("MANIFEST_INVALID","schema enum contains a non-finite number"),e;(n>8||typeof e!="object"||e===void 0)&&x("schema enum is too deep"),t.has(e)&&d("MANIFEST_INVALID","schema enum contains a cycle"),t.add(e);try{if(Array.isArray(e))return e.length>128&&x("schema enum array is too long"),e.map(o=>bn(o,n+1,t));O(e)||d("MANIFEST_INVALID","schema enum contains a non-plain object");let i={};for(let[o,r]of Object.entries(e))he(o)&&d("MANIFEST_INVALID","schema enum contains a reserved key"),i[o]=bn(r,n+1,t);return i}finally{t.delete(e);}}function bo(e,n){if(e===void 0)return;Array.isArray(e)||d("MANIFEST_INVALID","schema required must be an array"),e.length>64&&x("schema required list is too long");let t=[],i=new Set;for(let o of e)(typeof o!="string"||!Le.test(o))&&d("MANIFEST_INVALID","schema required contains an invalid key"),o.length>4096&&x("schema required key is too long"),i.has(o)&&d("MANIFEST_INVALID","schema required contains a duplicate key"),n&&!Object.prototype.hasOwnProperty.call(n,o)&&d("MANIFEST_INVALID","schema required references an undeclared property"),i.add(o),t.push(o);return t}function No(e,n){let t=n?Le:Ve;return e.length>4096&&x("schema property name is too long"),(!t.test(e)||e.split(".").some(i=>he(i)))&&d("MANIFEST_INVALID","schema property name is invalid"),e}function Nn(e,n=0,t=false){O(e)||d("MANIFEST_INVALID","action inputSchema must be an object"),n>8&&x("action inputSchema is too deep");let i=e.type;i!=="object"&&i!=="string"&&i!=="number"&&i!=="integer"&&i!=="boolean"&&i!=="array"&&i!=="null"&&(typeof i=="string"&&d("SCHEMA_TYPE_UNSUPPORTED","action inputSchema type is unsupported"),d("MANIFEST_INVALID","action inputSchema type is required"));let o=["type","enum"];i==="string"&&o.push("minLength","maxLength"),i==="array"&&o.push("minItems","maxItems","items"),i==="object"&&o.push("minProperties","maxProperties","properties","required","additionalProperties"),(i==="number"||i==="integer")&&o.push("minimum","maximum"),k(e,["type"],o.filter(a=>a!=="type"));let r={type:i};if(S(e,"enum")&&(Array.isArray(e.enum)||d("MANIFEST_INVALID","schema enum must be an array"),e.enum.length>128&&x("schema enum is too long"),r.enum=e.enum.map(a=>bn(a))),i==="string"&&(S(e,"minLength")&&(r.minLength=Te(e.minLength,"schema minLength",4096)),S(e,"maxLength")&&(r.maxLength=Te(e.maxLength,"schema maxLength",4096)),r.minLength!==void 0&&r.maxLength!==void 0&&r.minLength>r.maxLength&&d("MANIFEST_INVALID","schema string length bounds are inverted")),(i==="number"||i==="integer")&&(S(e,"minimum")&&(r.minimum=ct(e.minimum,"schema minimum")),S(e,"maximum")&&(r.maximum=ct(e.maximum,"schema maximum")),r.minimum!==void 0&&r.maximum!==void 0&&r.minimum>r.maximum&&d("MANIFEST_INVALID","schema numeric bounds are inverted")),i==="array"&&(S(e,"minItems")&&(r.minItems=Te(e.minItems,"schema minItems",128)),S(e,"maxItems")&&(r.maxItems=Te(e.maxItems,"schema maxItems",128)),r.minItems!==void 0&&r.maxItems!==void 0&&r.minItems>r.maxItems&&d("MANIFEST_INVALID","schema array length bounds are inverted"),S(e,"items")&&(r.items=Nn(e.items,n+1,false))),i==="object"){let a;if(S(e,"properties")){O(e.properties)||d("MANIFEST_INVALID","schema properties must be an object");let p=Object.entries(e.properties);p.length>64&&x("schema properties are too many"),a={};for(let[u,f]of p){let A=No(u,t);a[A]=Nn(f,n+1,false);}r.properties=a;}S(e,"minProperties")&&(r.minProperties=Te(e.minProperties,"schema minProperties",64)),S(e,"maxProperties")&&(r.maxProperties=Te(e.maxProperties,"schema maxProperties",64)),r.minProperties!==void 0&&r.maxProperties!==void 0&&r.minProperties>r.maxProperties&&d("MANIFEST_INVALID","schema object property bounds are inverted");let c=bo(e.required,a);c!==void 0&&(r.required=c),S(e,"additionalProperties")&&(e.additionalProperties!==false&&d("MANIFEST_INVALID","schema additionalProperties must be false"),r.additionalProperties=false);}let s=JSON.stringify(r);return (s===void 0||Buffer.byteLength(s,"utf8")>65536)&&x("action inputSchema subtree is too large"),r}function Mo(e){let n=Nn(e,0,true);return (n.type!=="object"||!n.properties)&&d("MANIFEST_INVALID","action inputSchema must declare object properties"),n}function So(e){if(O(e)||d("MANIFEST_INVALID","action backend must be an object"),e.type==="core"){k(e,co);let n=e.handler;return (typeof n!="string"||!In.test(n))&&d("MANIFEST_INVALID","core backend handler is invalid"),{type:"core",handler:n}}if(e.type==="skill"){k(e,po),(!Array.isArray(e.command)||e.command.length===0||e.command.length>16)&&d("MANIFEST_INVALID","skill backend command is invalid");let n=[];for(let t of e.command)(typeof t!="string"||t.length===0||t.length>256||!mn.test(t))&&d("MANIFEST_INVALID","skill backend command token is invalid"),n.push(t);return {type:"skill",command:n}}d("MANIFEST_INVALID","action backend type is unsupported");}function Lo(e){O(e)||d("MANIFEST_INVALID","action must be an object"),k(e,ro,so),S(e,"_meta")&&mt(e._meta);let n=Tn(e.actionId,"actionId"),t=Po(e.capability),i=e.mutation;typeof i!="boolean"&&d("MANIFEST_INVALID","action mutation must be boolean");let o=Mo(e.inputSchema),r;if(S(e,"dataInputs")){Array.isArray(e.dataInputs)||d("MANIFEST_INVALID","action dataInputs must be an array");let p=o.properties,u=new Set,f=[];for(let A of e.dataInputs)(typeof A!="string"||!S(p,A)||u.has(A))&&d("MANIFEST_INVALID","action dataInputs must be unique declared properties"),u.add(A),f.push(A);r=f;}let s=Dn(e.resultProjection),a=So(e.backend),c;if(S(e,"confirmation")){let p=e.confirmation;p!=="none"&&p!=="native"&&d("MANIFEST_INVALID","action confirmation is invalid"),c=p;}return {actionId:n,capability:t,mutation:i,inputSchema:o,resultProjection:s,backend:a,...r===void 0?{}:{dataInputs:r},...c===void 0?{}:{confirmation:c}}}function Uo(e){return O(e)||d("INITIAL_STATE_INVALID","initialState must be an object"),k(e,lo,uo),e.path!=="ui/state.json"&&d("MANIFEST_INVALID","initialState path is not fixed"),S(e,"hash")?{path:"ui/state.json",hash:gt(e.hash)}:{path:"ui/state.json"}}function Ro(e,n){He(e,new Set,0,true,true),Pn(e),O(e)||d("MANIFEST_INVALID"),k(e,io,oo),S(e,"_meta")&&mt(e._meta),e.manifestVersion!==2&&d("MANIFEST_INVALID");let t=Tn(e.pluginId,"pluginId"),i=Tn(e.definitionId,"definitionId"),o=q(e,"version",1),r=at(e.name,"name"),s=at(e.description,"description"),a;S(e,"icon")&&((typeof e.icon!="string"||!/^[a-z][a-z0-9-]{0,63}$/.test(e.icon))&&d("MANIFEST_INVALID","icon is invalid"),a=e.icon);let c;S(e,"tone")&&((typeof e.tone!="string"||!hn.includes(e.tone))&&d("MANIFEST_INVALID","tone is invalid"),c=e.tone),e.entry!=="ui/index.html"&&d("MANIFEST_INVALID","entry path is not fixed");let p;S(e,"entryHash")&&(p=gt(e.entryHash));let u;S(e,"initialState")&&(u=Uo(e.initialState));let f;S(e,"usage")&&(e.usage!=="card"&&e.usage!=="window"&&d("MANIFEST_INVALID","usage is invalid"),f=e.usage);let A;S(e,"detailPanel")&&(typeof e.detailPanel!="boolean"&&d("MANIFEST_INVALID","detailPanel is invalid"),A=e.detailPanel);let m;if(S(e,"displayModes")){((f??ae)!==ae||!Array.isArray(e.displayModes)||e.displayModes.length===0)&&d("MANIFEST_INVALID","displayModes are only valid for window Apps");let l=new Set(["inline","floating","focused"]);(new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(T=>typeof T!="string"||!l.has(T)))&&d("MANIFEST_INVALID","displayModes are invalid"),m=e.displayModes;}(f??ae)===ae&&A!==void 0&&d("MANIFEST_INVALID","detailPanel is card-only");let g=n.mode??"local";g!=="local"&&g!=="installed"&&g!=="published"&&d("MANIFEST_INVALID","manifest mode is invalid"),g!=="local"&&p===void 0&&d("MANIFEST_INVALID","installed manifests require entryHash"),g!=="local"&&u!==void 0&&u.hash===void 0&&d("MANIFEST_INVALID","installed manifests require initialState.hash"),(!Array.isArray(e.surfaces)||e.surfaces.length===0)&&d("MANIFEST_INVALID","surfaces are invalid"),e.surfaces.length>2&&x("surfaces exceed the v2 limit");let P=[],M=new Set;for(let l of e.surfaces)(typeof l!="string"||!En.includes(l))&&d("MANIFEST_INVALID","surface is unsupported"),M.has(l)&&d("MANIFEST_INVALID","surfaces contain a duplicate"),M.add(l),P.push(l);O(e.size)||d("MANIFEST_INVALID","size must be an object"),k(e.size,["height"]);let L=q(e.size,"height",1);L>720&&x("size.height exceeds the v2 limit");let y=Dn(e.stateProjection),I=e.summaryProjection===void 0?void 0:Dn(e.summaryProjection);I!==void 0&&I.allow.some(l=>!y.allow.includes(l))&&d("MANIFEST_INVALID","summaryProjection must be a subset of stateProjection.allow");let D=Do(e.dataPaths,y.allow);Array.isArray(e.actions)||d("MANIFEST_INVALID","actions must be an array"),e.actions.length>32&&x("actions exceed the v2 limit");let v=[],w=new Set;for(let l of e.actions){let T=Lo(l);if(w.has(T.actionId)&&d("MANIFEST_INVALID","actions contain a duplicate actionId"),T.backend.type==="core"&&T.backend.handler==="state.set"){T.mutation||d("MANIFEST_INVALID","state.set actions must be mutations");for(let H of Object.keys(T.inputSchema.properties))y.allow.includes(H)||d("MANIFEST_INVALID","state.set input paths must be projection-allowed");}w.add(T.actionId),v.push(T);}return {manifestVersion:2,pluginId:t,definitionId:i,version:o,name:r,description:s,...a===void 0?{}:{icon:a},...c===void 0?{}:{tone:c},entry:"ui/index.html",...p===void 0?{}:{entryHash:p},...u===void 0?{}:{initialState:u},...f===void 0?{}:{usage:f},...A===void 0?{}:{detailPanel:A},...m===void 0?{}:{displayModes:m},surfaces:P,size:{height:L},stateProjection:y,...I===void 0?{}:{summaryProjection:I},...D===void 0?{}:{dataPaths:D},actions:v}}function mt(e){O(e)||d("MANIFEST_INVALID","_meta must be an object");let n=JSON.stringify(e);(n===void 0||Buffer.byteLength(n,"utf8")>ao)&&x("_meta exceeds the 4 KiB limit");}function Oo(e){let n={},t={};for(let r of e.actions){n[r.actionId]={capabilities:[r.capability],inputKeys:Object.keys(r.inputSchema.properties??{}),...r.dataInputs===void 0?{}:{dataInputs:r.dataInputs},resultProjection:r.resultProjection,...r.confirmation===void 0?{}:{confirmation:r.confirmation}};let s=r.backend.type==="skill"||r.backend.type==="core"&&r.backend.handler==="state.set";t[r.actionId]={actionId:r.actionId,mutation:r.mutation,backend:r.backend,launchPolicy:s?"allowed":"denied",...s?{}:{denialCode:"EXEC_DENIED"}};}let i={id:e.definitionId,version:e.version,renderer:"sandbox-html",...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},surfaces:e.surfaces,stateProjection:e.stateProjection,...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},actions:n},o={entry:{path:"ui/index.html",...e.entryHash===void 0?{}:{hash:e.entryHash}},...e.initialState===void 0?{}:{initialState:e.initialState}};return {manifest:e,definition:i,handlers:t,resources:o}}function Mn(e,n,t,i,o,r){if(typeof e=="string"){let s=o.length>0&&r.some(a=>Ie(o.join("."),a));return (e.length>4096||Ge(e,false,false,s))&&X("state contains an unsafe string"),e}if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||X("state contains a non-finite number"),e;(e===void 0||typeof e!="object"||typeof e=="function"||typeof e=="bigint")&&X("state contains a non-JSON value"),t>8&&X("state is too deep"),n.has(e)&&X("state contains a cycle"),n.add(e);try{let s;if(Array.isArray(e))e.length>128&&X("state array is too long"),s=e.map(c=>Mn(c,n,t+1,65536,o,r));else {O(e)||X("state contains a non-plain object");let c={};for(let[p,u]of Object.entries(e))(p.length>4096||!Ve.test(p)||he(p))&&(p.length>4096&&X("state key is too long"),X("state contains a reserved or invalid key")),c[p]=Mn(u,n,t+1,65536,[...o,p],r);s=c;}let a=JSON.stringify(s);return (a===void 0||Buffer.byteLength(a,"utf8")>i)&&X("state subtree is too large"),s}finally{n.delete(e);}}function Ln(e,n=[]){O(e)||X("initial state must be a JSON object");let t=Mn(e,new Set,0,65536,[],n);return (t===null||Array.isArray(t)||typeof t!="object")&&X(),t}function ko(e,n={}){He(e),O(e)||d("MANIFEST_INVALID"),k(e,to),e.manifestVersion!==1&&d("MANIFEST_INVALID");let t=_n(Z(e,"pluginId")),i=_n(Z(e,"definitionId")),o=q(e,"version",1),r=q(e,"primitiveSet",1),s=n.supportedPrimitiveSet??Wi;(!Number.isSafeInteger(s)||s<1)&&d("MANIFEST_INVALID"),r>s&&d("PRIMITIVE_SET_UNSUPPORTED"),O(e.activation)||d("MANIFEST_INVALID"),k(e.activation,["kind","language"]),e.activation.kind!=="fenced-code"&&d("MANIFEST_INVALID");let a=_n(Z(e.activation,"language")),c=ho(e.schema),p=To(e.layout,c);return {manifestVersion:1,pluginId:t,definitionId:i,version:o,primitiveSet:r,activation:{kind:"fenced-code",language:a},schema:c,layout:p}}function xo(e,n={}){return O(e)||d("MANIFEST_INVALID"),Object.hasOwn(e,"lineage")&&d("MANIFEST_INVALID","lineage is only allowed in product bundle indexes"),e.manifestVersion===2?Ro(e,n):ko(e,n)}function fe(e,n={}){try{return xo(e,n)}catch(t){if(t instanceof G)throw t;return d("MANIFEST_INVALID")}}function Un(e,n={}){let t=fe(e,n);return t.manifestVersion===2?Oo(t):t}var Et="SKILL.md",Vo=/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;function _t(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function Fo(e){return e.isDirectory()||e.isSymbolicLink()}function Nt(e){try{return C.existsSync(e)&&C.statSync(e).isDirectory()}catch{return false}}function On(e){let n;try{n=C.readFileSync(e,"utf8");}catch{return {frontmatter:{},readable:false,valid:false,hasFrontmatter:false}}let t=n.match(Vo);if(!t)return {frontmatter:{},readable:true,valid:true,hasFrontmatter:false};try{let i=ui.load(t[1]??"");if(!_t(i))return {frontmatter:{},readable:!0,valid:!1,hasFrontmatter:!0};let o=_t(i.metadata)?i.metadata:void 0;return {frontmatter:{...typeof i.name=="string"?{name:i.name}:{},...typeof(o?.version??i.version)=="string"?{version:o?.version??i.version}:{},...typeof i.description=="string"?{description:i.description}:{}},readable:!0,valid:!0,hasFrontmatter:!0}}catch{return {frontmatter:{},readable:true,valid:false,hasFrontmatter:true}}}function Bo(e){return [B.join(e,Et),B.join(e,"skill",Et)]}function Tt(e,n){if(!Nt(e))return null;for(let t of Bo(e)){if(!C.existsSync(t))continue;let o=On(t).frontmatter;return {name:o.name??n,...o.version===void 0?{}:{version:o.version},...o.description===void 0?{}:{description:o.description},skillMdPath:t,dir:e}}return null}function Pt(e){try{return C.readdirSync(e,{withFileTypes:!0}).filter(Fo)}catch{return []}}function Dt(e,n,t){!e||n.has(e.name)||(n.add(e.name),t.push(e));}function Mt(e){let n=[],t=new Set;for(let i of e)if(Nt(i))for(let o of Pt(i)){if(o.name.startsWith("@")){let r=B.join(i,o.name);for(let s of Pt(r))Dt(Tt(B.join(r,s.name),s.name),t,n);continue}Dt(Tt(B.join(i,o.name),o.name),t,n);}return n.sort((i,o)=>i.name.localeCompare(o.name))}var zo=/^[0-9a-f]{64}$/;function ce(e){let t=e.renderer!==void 0||e.surfaces!==void 0||e.stateProjection!==void 0||e.dataPaths!==void 0||e.usage!==void 0||e.detailPanel!==void 0||e.displayModes!==void 0||e.summaryProjection!==void 0||e.legacy!==void 0||Object.values(e.actions).some(o=>o.resultProjection!==void 0)?{id:e.id,version:e.version,...e.renderer===void 0?{}:{renderer:e.renderer},...e.surfaces===void 0?{}:{surfaces:e.surfaces},...e.stateProjection===void 0?{}:{stateProjection:e.stateProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.legacy===void 0?{}:{legacy:e.legacy},...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},actions:e.actions}:e.sourceHash===void 0?{id:e.id,version:e.version,actions:e.actions}:{id:e.id,version:e.version,sourceHash:e.sourceHash,actions:e.actions},i=se(t);return tt.createHash("sha256").update(K(i)).digest("hex")}function pe(e){if(!/^\d+$/.test(String(e.version))||e.version<1||e.id.length<1||e.id.length>128)throw new b("DEFINITION_UNSUPPORTED","UI definition is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!zo.test(e.sourceHash)))throw new b("DEFINITION_UNSUPPORTED","UI definition source hash is invalid");if(!/^[0-9a-f]{64}$/.test(e.hash)||ce(e)!==e.hash)throw new b("DEFINITION_UNSUPPORTED","UI definition hash is invalid");for(let[n,t]of Object.entries(e.actions)){if(!n||!Array.isArray(t.capabilities)||t.capabilities.some(i=>!$o(i)))throw new b("DEFINITION_UNSUPPORTED","UI action declaration is invalid");if(t.confirmation!==void 0&&t.confirmation!=="none"&&t.confirmation!=="native")throw new b("DEFINITION_UNSUPPORTED","UI action confirmation is invalid");if(t.inputKeys&&(!Array.isArray(t.inputKeys)||t.inputKeys.some(i=>typeof i!="string"||!i)))throw new b("DEFINITION_UNSUPPORTED","UI action input declaration is invalid");if(t.dataInputs!==void 0&&(!Array.isArray(t.dataInputs)||new Set(t.dataInputs).size!==t.dataInputs.length||t.dataInputs.some(i=>typeof i!="string"||!i||t.inputKeys!==void 0&&!t.inputKeys.includes(i))))throw new b("DEFINITION_UNSUPPORTED","UI action data input declaration is invalid");t.resultProjection&&kn(t.resultProjection);}if(e.renderer!==void 0&&(!e.renderer||e.renderer.length>128))throw new b("DEFINITION_UNSUPPORTED","UI definition renderer is invalid");if(e.surfaces&&(!Array.isArray(e.surfaces)||e.surfaces.some(n=>!n||n.length>64)))throw new b("DEFINITION_UNSUPPORTED","UI definition surfaces are invalid");if(e.usage!==void 0&&e.usage!=="card"&&e.usage!=="window")throw new b("DEFINITION_UNSUPPORTED","UI definition usage is invalid");if(e.detailPanel!==void 0&&typeof e.detailPanel!="boolean")throw new b("DEFINITION_UNSUPPORTED","UI definition detailPanel is invalid");if(e.displayModes&&(!Array.isArray(e.displayModes)||e.displayModes.length===0||new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(n=>n!=="inline"&&n!=="floating"&&n!=="focused")))throw new b("DEFINITION_UNSUPPORTED","UI definition displayModes are invalid");if(e.usage==="card"&&e.displayModes!==void 0)throw new b("DEFINITION_UNSUPPORTED","Card definitions cannot declare displayModes");if(e.usage==="window"&&e.detailPanel!==void 0)throw new b("DEFINITION_UNSUPPORTED","Window definitions cannot declare detailPanel");if(e.stateProjection&&kn(e.stateProjection),e.summaryProjection){kn(e.summaryProjection);let n=new Set(e.stateProjection?.allow??[]);if(e.summaryProjection.allow.some(t=>!n.has(t)))throw new b("DEFINITION_UNSUPPORTED","UI summary projection exceeds state projection")}if(e.legacy!==void 0){if(!e.legacy||typeof e.legacy!="object"||Array.isArray(e.legacy)||Object.keys(e.legacy).some(o=>!["readTool","actionTool","hostTools","agentAccess"].includes(o)))throw new b("DEFINITION_UNSUPPORTED","UI legacy metadata is invalid");let n=new Set;for(let[o,r]of [["readTool",e.legacy.readTool],["actionTool",e.legacy.actionTool]])if(r!==void 0){if(Go(r,o==="readTool"),n.has(r.name))throw new b("DEFINITION_UNSUPPORTED","UI legacy tool names collide");n.add(r.name);}let t=e.legacy.hostTools;if(t!==void 0){if(!t||typeof t!="object"||Array.isArray(t))throw new b("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");let o={"doc.open":"crewx_app_html_viewer_open","pty.connect":"crewx_app_terminal_connect"};for(let[r,s]of Object.entries(t)){if(!Object.hasOwn(o,r)||o[r]!==s||typeof s!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(s)||n.has(s))throw new b("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");n.add(s);}}let i=e.legacy.agentAccess;if(i!==void 0&&(!i||typeof i!="object"||Array.isArray(i)||Object.entries(i).some(([o,r])=>!o||!Object.hasOwn(e.actions,o)||r!=="allowed"&&r!=="denied")))throw new b("DEFINITION_UNSUPPORTED","UI legacy agent access is invalid");if(e.legacy.actionTool!==void 0&&(!i||Object.keys(i).length===0))throw new b("DEFINITION_UNSUPPORTED","UI legacy action tool requires its complete agent access map")}if(e.dataPaths!==void 0){let n=new Set(["__proto__","prototype","constructor"]);if(!Array.isArray(e.dataPaths)||e.dataPaths.length>16||new Set(e.dataPaths).size!==e.dataPaths.length||e.dataPaths.some(t=>typeof t!="string"||!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(t)||t.split(".").some(i=>n.has(i))||!(e.stateProjection?.allow??[]).some(i=>Ie(t,i))))throw new b("DEFINITION_UNSUPPORTED","UI definition dataPaths are invalid")}}function Go(e,n){if(!e||typeof e!="object"||Array.isArray(e))throw new b("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");let t=e,i=["name","description","inputSchema","textFallback","visibility"],o=Object.hasOwn(t,"fixedResult");if(Object.keys(t).some(r=>!i.includes(r)&&!(n&&r==="fixedResult"))||i.some(r=>!Object.hasOwn(t,r))||typeof t.name!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(t.name)||typeof t.description!="string"||t.description.trim().length===0||t.description.length>8192||typeof t.textFallback!="string"||t.textFallback.trim().length===0||t.textFallback.length>16384||!t.inputSchema||typeof t.inputSchema!="object"||Array.isArray(t.inputSchema)||!Array.isArray(t.visibility)||t.visibility.length===0||t.visibility.some(r=>r!=="model"&&r!=="app")||new Set(t.visibility).size!==t.visibility.length)throw new b("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");try{let r=se(t.inputSchema);if(r.type!==void 0&&r.type!=="object")throw new Error("schema type");if(o){if(!n)throw new Error("fixed result location");let s=t.fixedResult;if(!s||typeof s!="object"||Array.isArray(s))throw new Error("fixed result");let a=s;if(Object.keys(a).sort().join(",")!=="argsPolicy,structuredContent"||a.argsPolicy!=="empty-only"&&a.argsPolicy!=="ignore"||!a.structuredContent||typeof a.structuredContent!="object"||Array.isArray(a.structuredContent))throw new Error("fixed result");let c=se(a.structuredContent);if(yn(me(c))>4*1024)throw new Error("fixed result size")}}catch{throw new b("DEFINITION_UNSUPPORTED","UI legacy tool metadata is not projection-safe")}}function kn(e){if(!Array.isArray(e.allow)||e.allow.some(n=>!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(n)))throw new b("DEFINITION_UNSUPPORTED","UI projection policy is invalid")}function $o(e){return e.length>0&&e.length<=128&&e!=="*"&&e!=="all"&&!/[/*]/.test(e)}var Q=class extends Error{constructor(t,i=t,o=[]){super(i);this.code=t;this.violations=o;}code;violations;name="UiDefinitionLineageError"},St=/^[0-9a-f]{64}$/,Wo=["version","hash","definition"],Jo=["sourceHash","compat"],Ko=["id","version","actions"],Xo=["sourceHash","usage","detailPanel","displayModes","renderer","surfaces","stateProjection","dataPaths","summaryProjection","legacy"],Yo=["capabilities"],qo=["inputKeys","dataInputs","confirmation","resultProjection"];function xe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function xn(e,n,t=[]){let i=new Set([...n,...t]),o=Object.keys(e);return n.every(r=>Object.hasOwn(e,r))&&o.every(r=>i.has(r))}function Ut(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))Ut(n);return Object.freeze(e)}function j(e){throw new Q("LINEAGE_INVALID",e)}function Zo(e){throw new Q("LINEAGE_STALE",e)}function Rt(e){if(!xe(e)||!xn(e,Ko,Xo)||!xe(e.actions))return j("Lineage definition shape is invalid");for(let n of Object.values(e.actions))if(!xe(n)||!xn(n,Yo,qo))return j("Lineage action definition shape is invalid");return e}function Qo(e){if(!xe(e)||!xn(e,Wo,Jo))return j("Lineage entry shape is invalid");if(!Number.isSafeInteger(e.version)||e.version<1||typeof e.hash!="string"||!St.test(e.hash))return j("Lineage entry identity is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!St.test(e.sourceHash)))return j("Lineage source hash is invalid");if(e.compat!==void 0&&e.compat!=="break")return j("Lineage compatibility marker is invalid");let n=Rt(e.definition);if(n.version!==e.version)return j("Lineage version does not match its definition");if(e.sourceHash!==void 0&&n.sourceHash!==e.sourceHash)return j("Lineage source hash does not match its definition");let t;try{t=ce(n),pe({...n,hash:e.hash});}catch{return j("Lineage definition is invalid")}return t!==e.hash?j("Lineage definition hash does not match"):Ut({version:e.version,hash:e.hash,definition:n,...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},...e.compat===void 0?{}:{compat:e.compat}})}function Lt(e){return e.stateProjection?.allow??[]}function er(e,n){let t=[],i=new Set(Lt(n));Lt(e).some(a=>!i.has(a))&&t.push("S1_STATE_PROJECTION");let o=new Set(n.dataPaths??[]);(e.dataPaths??[]).some(a=>!o.has(a))&&t.push("S2_DATA_PATHS");for(let[a,c]of Object.entries(e.actions)){let p=n.actions[a];if(p&&(c.confirmation??"native")==="native"&&(p.confirmation??"native")!=="native"){t.push("S3_ACTION_CONFIRMATION");break}}Object.keys(e.legacy?.agentAccess??{}).some(a=>!Object.hasOwn(n.actions,a))&&t.push("S4_LEGACY_AGENT_ACTIONS");let s=e.summaryProjection?.allow;if(s!==void 0){let a=new Set(n.summaryProjection?.allow??[]);s.some(c=>!a.has(c))&&t.push("S5_SUMMARY_PROJECTION");}return t}function nr(e,n){return K(e)===K(n)}function wn(e,n){if(!Array.isArray(e)||e.length===0)return j("Definition lineage is missing");if(!xe(n)||typeof n.hash!="string")return j("Current definition is invalid");let t,i;try{let{hash:a,...c}=n;i=Rt(c),t={...i,hash:a},pe(t);}catch{return j("Current definition is invalid")}let o=e.map(Qo),r=o[0].definition.id;if(o.some(a=>a.definition.id!==r))return j("Lineage definition ids do not match");if(o.some((a,c)=>c>0&&a.version<=o[c-1].version))return j("Lineage generations are not in increasing version order");if(o.some((a,c)=>o.findIndex(p=>p.hash===a.hash)!==c))return j("Lineage contains a duplicate hash");let s=o[o.length-1];if(s.version!==t.version||s.hash!==t.hash||s.definition.id!==t.id||!nr(s.definition,i))return Zo("The last lineage generation does not match the current package");if(t.legacy!==void 0){let a=new Set(Object.keys(t.actions)),c=new Set;for(let u of o)if(u.sourceHash===void 0)for(let f of Object.keys(u.definition.actions))a.has(f)&&c.add(f);let p=Object.keys(t.legacy.agentAccess??{});if(p.length!==c.size||p.some(u=>!c.has(u))){let u="S4_LEGACY_AGENT_ACCESS_COMPLETE";throw new Q("LINEAGE_INVALID",`Lineage compatibility failed: ${u}`,[u])}}for(let a=0;a<o.length-1;a+=1){if(o.slice(a,-1).some(u=>u.compat==="break"))continue;let p=er(o[a].definition,t);if(p.length>0)throw new Q("LINEAGE_INVALID",`Lineage compatibility failed: ${p.join(", ")}`,p)}return Object.freeze({entries:Object.freeze(o),current:t})}var tr=new WeakSet;function Ot(e){return tr.add(e),e}var de=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="McpAppContractError"};function Cn(e,n=e){throw new de(e,n)}var kt=["crewx_app_terminal_connect","crewx_app_html_viewer_open"],xt=["crewx_listWorkspaces","crewx_queryAgent","crewx_executeAgent","crewx_getTaskResult","crewx_listTasks","crewx_listAgents","callBrowser","openTab","listTabs","closeTab"];var $e=8*1024*1024;new Set(kt);new Set(xt);var or=4;function vn(e,n=0){try{let t=se(e,n);return t.type!==void 0&&t.type!=="object"&&Cn("TOOL_INVALID","MCP App inputSchema must describe an object"),t}catch(t){if(t instanceof de)throw t;Cn("TOOL_INVALID","MCP App inputSchema must be projection-safe JSON");}}function wt(e){if(e.length===0)return vn({type:"object",properties:{},additionalProperties:false});let n=e.map(i=>i.actionId),t=new Map;for(let i of e)t.set(i.actionId,vn(i.inputSchema));return vn(rr(n,t),or)}function rr(e,n){let t=e.map(i=>({type:"object",properties:{actionId:{type:"string",const:i},input:n.get(i)??{type:"object"}},required:["actionId","input"],additionalProperties:false}));return Object.freeze({type:"object",oneOf:Object.freeze(t),properties:Object.freeze({actionId:Object.freeze({type:"string",enum:Object.freeze([...e])}),input:Object.freeze({type:"object"})}),required:Object.freeze(["actionId","input"]),additionalProperties:false})}var _=class extends Error{constructor(t){super(t);this.code=t;}code;name="AppDiscoveryFsError"},Bt=C.constants.O_NOFOLLOW,pr=C.constants.O_NONBLOCK,dr=C.constants.O_RDONLY|(Bt??0)|(pr??0);function ee(e){let n=typeof e=="object"&&e!==null&&"code"in e?String(e.code):"";return n==="ENOENT"?new _("NOT_FOUND"):n==="ELOOP"?new _("PATH_ESCAPED"):n==="EFBIG"||n==="EOVERFLOW"?new _("LIMIT_EXCEEDED"):n==="EACCES"||n==="EPERM"||n==="ENOTDIR"?new _("READ_DENIED"):new _("READ_DENIED")}function lr(e){if(typeof e!="string"||e.length===0||!B.isAbsolute(e))throw new _("READ_DENIED")}function Ct(e){if(typeof e!="string"||B.isAbsolute(e)||/[\\\u0000]/.test(e))throw new _("PATH_ESCAPED");if(e==="")return [];let n=e.split("/");if(n.some(t=>t.length===0||t==="."||t===".."))throw new _("PATH_ESCAPED");return n}function We(e,n){let t=B.relative(e,n);return t===""||t!==".."&&!t.startsWith(`..${B.sep}`)&&!B.isAbsolute(t)}function Je(e){return {dev:e.dev,ino:e.ino,size:e.size,mtimeNs:e.mtimeNs,ctimeNs:e.ctimeNs}}function Fn(e,n){return e.dev===n.dev&&e.ino===n.ino}function Ht(e,n){return Fn(e,n)&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}async function vt(e){lr(e);let n,t;try{n=await promises.realpath(e),t=await promises.stat(n,{bigint:!0});}catch(i){throw ee(i)}if(!t.isDirectory())throw new _("READ_DENIED");return {realRoot:n,identity:Je(t)}}async function ur(e,n,t){if(t.length<2||t[0]!=="apps"&&t[0]!=="skills")return;let i,o;try{if(i=B.resolve(e,t[0],t[1]),o=await promises.realpath(i),!(await promises.stat(o,{bigint:!0})).isDirectory())throw new _("READ_DENIED")}catch(r){throw r instanceof _?r:ee(r)}if(!We(n,o))throw new _("PATH_ESCAPED");return o}async function jt(e,n,t,i){let o,r,s;try{o=await promises.lstat(e,{bigint:!0}),r=await promises.realpath(e),s=await promises.stat(r,{bigint:!0});}catch(a){throw ee(a)}if(!We(n,r)||t!==void 0&&!We(t,r))throw new _("PATH_ESCAPED");if(!o.isFile()||!s.isFile())throw new _("READ_DENIED");if(!Fn(i,o)||!Fn(i,s)||i.dev!==s.dev)throw new _("PATH_ESCAPED")}async function jn(e,n){let t,i;try{t=await promises.realpath(e),i=await promises.stat(t,{bigint:!0});}catch{throw new _("PATH_ESCAPED")}if(t!==n.realRoot||!Ht(n.identity,Je(i)))throw new _("PATH_ESCAPED")}function fr(e){return e.isSymbolicLink()?{name:e.name,kind:"symlink"}:e.isDirectory()?{name:e.name,kind:"directory"}:e.isFile()?{name:e.name,kind:"file"}:{name:e.name,kind:"other"}}var Ke=class{async listDirectory(n,t){let i=Ct(t),o=await vt(n),r=B.resolve(n,...i),s,a;try{s=await promises.realpath(r),a=await promises.stat(s,{bigint:!0});}catch(c){let p=ee(c);if(p.code==="NOT_FOUND")return [];throw p}if(!We(o.realRoot,s)||!a.isDirectory())throw new _("PATH_ESCAPED");try{let c=await promises.readdir(s,{withFileTypes:!0,encoding:"utf8"});return await jn(n,o),c.map(fr)}catch(c){let p=ee(c);if(p.code==="NOT_FOUND")return [];throw p}}async readdir(n,t){return this.listDirectory(n,t)}async readDirectory(n,t){return this.listDirectory(n,t)}async readVerifiedFile(n,t,i){if(!Number.isSafeInteger(i)||i<0)throw new _("READ_DENIED");if(Bt===void 0)throw new _("UNSUPPORTED");let o=Ct(t),r=await vt(n),s=B.resolve(n,...o),a=B.relative(n,s);if(a===".."||a.startsWith(`..${B.sep}`)||B.isAbsolute(a))throw new _("PATH_ESCAPED");let c;try{c=await promises.open(s,dr);}catch(p){throw ee(p)}try{let p;try{let g=await c.stat({bigint:!0});p=Je(g);}catch(g){throw ee(g)}if(p.size>BigInt(i))throw new _("LIMIT_EXCEEDED");if(p.size>BigInt(Number.MAX_SAFE_INTEGER))throw new _("LIMIT_EXCEEDED");await jn(n,r);let u=await ur(n,r.realRoot,o);await jt(s,r.realRoot,u,p);let f=new Uint8Array(new ArrayBuffer(Number(p.size))),A=0;for(;A<f.byteLength;){let g;try{g=(await c.read(f,A,f.byteLength-A,A)).bytesRead;}catch(P){throw ee(P)}if(g<=0)throw new _("IDENTITY_CHANGED");A+=g;}let m;try{let g=await c.stat({bigint:!0});m=Je(g);}catch(g){throw ee(g)}if(!Ht(p,m))throw new _("IDENTITY_CHANGED");return await jt(s,r.realRoot,u,m),await jn(n,r),new Uint8Array(f)}finally{await c.close().catch(()=>{});}}async readFileVerified(n,t,i){return this.readVerifiedFile(n,t,i)}},zt=new Ke;var Hn="crewx_local_app_";function yr(e){if(typeof e!="string"||!Ee.test(e))throw new TypeError("pluginId must be a safe UI plugin identifier");let n=`${Hn}${e}`.length+7<=128?e:`hash_${tt.createHash("sha256").update(e,"utf8").digest("hex")}`;return {read:`${Hn}${n}_read`,action:`${Hn}${n}_action`}}var Gt=["bundled","apps","skills"],Ar=256*1024,Jn=64,Kn=128,gr=Jn*Kn,Ir=2*1024*1024,zn=32*1024*1024,$n=/^[0-9a-f]{64}$/,mr=new TextDecoder("utf-8",{fatal:true});function Ae(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function qe(e){return typeof e=="string"&&Ee.test(e)?e:void 0}function hr(e,n){return n.length===0||n==="."||n===".."||/[\\/\u0000]/.test(n)?e==="skills"?"skills":"apps":`${e==="skills"?"skills":"apps"}/${n}`}function qt(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function Ne(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),o=Math.min(t.byteLength,i.byteLength);for(let r=0;r<o;r+=1){let s=t[r]-i[r];if(s!==0)return s}return t.byteLength-i.byteLength}function Er(e){if(typeof e=="string")return {name:e,kind:"directory"};if(e===null||typeof e!="object")return null;let n=e;if(typeof n.name!="string")return null;if(n.kind==="file"||n.kind==="directory"||n.kind==="symlink"||n.kind==="other")return {name:n.name,kind:n.kind};if(n.type==="file"||n.type==="directory"||n.type==="symlink"||n.type==="other")return {name:n.name,kind:n.type};let t=n.isDirectory;if(typeof t=="function"&&t.call(e))return {name:n.name,kind:"directory"};let i=n.isSymbolicLink;if(typeof i=="function"&&i.call(e))return {name:n.name,kind:"symlink"};let o=n.isFile;return typeof o=="function"&&o.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function _r(e){if(e instanceof Uint8Array)return new Uint8Array(e);if(e instanceof ArrayBuffer)return new Uint8Array(e.slice(0));if(Array.isArray(e)&&e.every(n=>Number.isInteger(n)&&n>=0&&n<=255))return Uint8Array.from(e);throw new TypeError("filesystem port returned an invalid byte array")}function Zt(e){return mr.decode(e)}function Xn(e){return JSON.parse(Zt(e))}function Tr(e){if(!Ae(e))return;let n=qe(e.pluginId);if(!n)return;let t=qe(e.definitionId),i=e.version,o=t&&Number.isSafeInteger(i)&&i>=1?`${t}\0${String(i)}`:void 0;return {pluginId:n,...o===void 0?{}:{definitionKey:o}}}function Pr(e){let n=Xn(e);return {value:n,identity:Tr(n)}}function en(e,n,t,i){let o={code:e,...i===void 0?{}:{pluginId:i},source:n,relativePath:t};return Object.freeze(o)}function $t(e){switch(e){case "ENOENT":return "NOT_FOUND";case "ELOOP":case "EXDEV":return "PATH_ESCAPED";case "EFBIG":case "EOVERFLOW":return "LIMIT_EXCEEDED";case "EACCES":case "EPERM":case "ENOTDIR":return "READ_DENIED";default:return e}}function le(e){if(e instanceof _)return $t(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return $t(n)}}function ve(e,n){return e==="PATH_ESCAPED"||e==="IDENTITY_CHANGED"||e==="TOCTOU"?"PATH_ESCAPED":e==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":n==="manifest"&&e==="NOT_FOUND"?"MANIFEST_MISSING":n==="entry"?"ENTRY_INVALID":n==="initial"?"INITIAL_STATE_INVALID":"MANIFEST_INVALID"}function Wt(e){switch(e.code){case "MANIFEST_INVALID":case "PRIMITIVE_UNKNOWN":case "PRIMITIVE_SET_UNSUPPORTED":case "SCHEMA_TYPE_UNSUPPORTED":case "TOKEN_INVALID":case "UNSAFE_VALUE":return "MANIFEST_INVALID";case "LIMIT_EXCEEDED":return "LIMIT_EXCEEDED";case "INITIAL_STATE_INVALID":return "INITIAL_STATE_INVALID";default:return Qt("UiPluginValidationError",e.code)}}function Qt(e,n){throw new Error(`Unmapped ${e} code: ${String(n)}`)}function Gn(e){switch(e){case "APP_ID_INVALID":case "TOOL_ID_INVALID":case "RESOURCE_URI_INVALID":case "TOOL_INVALID":case "SERIALIZATION_INVALID":return "MANIFEST_INVALID";case "APP_ID_CONFLICT":case "TOOL_ID_CONFLICT":return "DUPLICATE_ID";case "RESOURCE_NOT_FOUND":case "HTML_INVALID":return "ENTRY_INVALID";case "STATE_INVALID":case "STATE_PROJECTION_INVALID":case "BUTTON_INVALID":return "INITIAL_STATE_INVALID";default:return Qt("McpAppContractError",e)}}function Y(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function Ye(e,n){let t=Object.keys(e).sort(Ne),i=[...n].sort(Ne);return t.length===i.length&&t.every((o,r)=>o===i[r])}function Jt(e){if(typeof e!="string"||e.length===0||e.startsWith("/")||/[\\\u0000]/.test(e))return;let n=e.split("/");if(!n.some(t=>t.length===0||t==="."||t===".."))return n}function Dr(e){let n;try{n=Xn(e);}catch{return}if(!Ae(n)||!Ye(n,["version","packages"])||n.version!==1||!Array.isArray(n.packages)||n.packages.length>Jn)return;let t=new Set,i=new Set,o=0,r=[];for(let s of n.packages){if(!Ae(s))return;let a=["packageDir","appId","definition","files"],c=Object.hasOwn(s,"lineage");if(!Ye(s,c?[...a,"lineage"]:a))return;let p=Jt(s.packageDir),u=qe(s.appId);if(!p||p.length!==2||p[0]!=="apps"||!qt(p[1])||!u||t.has(s.packageDir)||!Ae(s.definition)||!Ye(s.definition,["id","version","hash"]))return;let f=qe(s.definition.id),A=s.definition.version,m=s.definition.hash;if(!f||!Number.isSafeInteger(A)||A<1||typeof m!="string"||!$n.test(m)||!Array.isArray(s.files)||s.files.length<2||s.files.length>Kn)return;let g=new Set,P=[];for(let M of s.files){if(!Ae(M)||!Ye(M,["path","sha256"]))return;let L=Jt(M.path);if(!L||typeof M.sha256!="string"||!$n.test(M.sha256))return;let y=L.join("/"),I=`${s.packageDir}/${y}`;if(g.has(y)||i.has(I))return;g.add(y),i.add(I),P.push(Object.freeze({path:y,sha256:M.sha256}));}if(!g.has("ui-plugin.json")||!g.has("ui/index.html")||(o+=P.length,o>gr))return;t.add(s.packageDir),r.push(Object.freeze({packageDir:s.packageDir,appId:u,definition:Object.freeze({id:f,version:A,hash:m}),lineage:Array.isArray(s.lineage)?s.lineage:[],files:Object.freeze(P.sort((M,L)=>Ne(M.path,L.path)))}));}return Object.freeze({version:1,packages:Object.freeze(r)})}function br(e){return {pluginId:e.appId,definitionKey:`${e.definition.id}\0${String(e.definition.version)}`}}function ye(e){let n=le(e);return n==="PATH_ESCAPED"||n==="IDENTITY_CHANGED"||n==="TOCTOU"?"PATH_ESCAPED":n==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":"BUNDLE_INTEGRITY"}async function Nr(e,n,t,i,o){let r=[],s=async(a,c)=>{if(!Y(i,o))throw new _("LIMIT_EXCEEDED");if(c>2)throw new _("LIMIT_EXCEEDED");let p=await Qe(e,n,a);for(let u of p){if(typeof u.name!="string"||u.name.length===0||u.name==="."||u.name===".."||/[\\/\u0000]/.test(u.name))throw new _("PATH_ESCAPED");let f=`${a}/${u.name}`;if(u.kind==="file"){if(r.push(f.slice(t.length+1)),r.length>Kn)throw new _("LIMIT_EXCEEDED")}else if(u.kind==="directory")await s(f,c+1);else throw u.kind==="symlink"?new _("PATH_ESCAPED"):new _("READ_DENIED")}};return await s(t,0),r.sort(Ne)}function Mr(e){return e==="ui-plugin.json"?262144:e==="ui/index.html"?$e:e==="ui/state.json"?65536:Ir}async function Sr(e,n,t,i){if(e===void 0)return {packages:[],diagnostics:[],incomplete:false};let o=[],r=(l,T,H)=>en(l,"bundled",T,H);if(typeof e.root!="string"||e.root.length===0||typeof e.expectedIndexHash!="string"||!$n.test(e.expectedIndexHash))return o.push(r("BUNDLE_INTEGRITY","bundle-index.json")),{packages:[],diagnostics:o,incomplete:false};let s;try{s=await Ze(n,e.root,"bundle-index.json",Ar);}catch(l){return o.push(r(ye(l),"bundle-index.json")),{packages:[],diagnostics:o,incomplete:false}}let a=tt.createHash("sha256").update(s).digest("hex");if(a!==e.expectedIndexHash)return o.push(r("BUNDLE_INTEGRITY","bundle-index.json")),{packages:[],diagnostics:o,incomplete:false};let c=Dr(s);if(c===void 0)return o.push(r("BUNDLE_INTEGRITY","bundle-index.json")),{indexHash:a,packages:[],diagnostics:o,incomplete:false};if(!Y(t,i))return o.push(r("LIMIT_EXCEEDED","bundle-index.json")),{indexHash:a,packages:c.packages.map(l=>({indexEntry:l,failureCode:"LIMIT_EXCEEDED"})),diagnostics:o,incomplete:true};let p;try{p=await Qe(n,e.root,"");}catch(l){return o.push(r(ye(l),"bundle-index.json")),{indexHash:a,packages:c.packages.map(T=>({indexEntry:T,failureCode:ye(l)})),diagnostics:o,incomplete:false}}if(!Y(t,i))return o.push(r("LIMIT_EXCEEDED","bundle-index.json")),{indexHash:a,packages:c.packages.map(l=>({indexEntry:l,failureCode:"LIMIT_EXCEEDED"})),diagnostics:o,incomplete:true};let u=p.find(l=>l.name==="bundle-index.json"&&l.kind==="file"),f=p.find(l=>l.name==="apps"&&l.kind==="directory"),A=l=>c.packages.map(T=>({indexEntry:T,failureCode:l}));if(!u)return o.push(r("BUNDLE_INTEGRITY","bundle-index.json")),{indexHash:a,packages:A("BUNDLE_INTEGRITY"),diagnostics:o,incomplete:false};let m=p.filter(l=>l.name!=="bundle-index.json"&&l.name!=="apps");if(m.length>0){let l=m.some(T=>T.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return o.push(r(l,"bundle-index.json")),{indexHash:a,packages:A("BUNDLE_INTEGRITY"),diagnostics:o,incomplete:false}}if(p.some(l=>l.name==="apps"&&l.kind!=="directory"))return o.push(r("PATH_ESCAPED","apps")),{indexHash:a,packages:A("PATH_ESCAPED"),diagnostics:o,incomplete:false};let g=[];if(f)try{g=await Qe(n,e.root,"apps");}catch(l){return o.push(r(ye(l),"apps")),{indexHash:a,packages:A(ye(l)),diagnostics:o,incomplete:false}}if(!Y(t,i))return o.push(r("LIMIT_EXCEEDED","apps")),{indexHash:a,packages:A("LIMIT_EXCEEDED"),diagnostics:o,incomplete:true};if(g.length>Jn)return o.push(r("LIMIT_EXCEEDED","apps")),{indexHash:a,packages:A("LIMIT_EXCEEDED"),diagnostics:o,incomplete:true};let P=new Map(c.packages.map(l=>[l.packageDir.slice(5),l])),M=g.filter(l=>!P.has(l.name));for(let l of M)o.push(r(l.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY",`apps/${l.name}`));if(M.length>0){let l=M.some(T=>T.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return {indexHash:a,packages:A(l),diagnostics:o,incomplete:false}}let L=new Set,y=new Map,I=new Map;for(let l of c.packages){let T=y.get(l.appId)??[];T.push(l),y.set(l.appId,T);let H=`${l.definition.id}\0${String(l.definition.version)}`,$=I.get(H)??[];$.push(l),I.set(H,$);}for(let l of [...y.values(),...I.values()])if(l.length>1)for(let T of l)L.add(T);let D=[],v=s.byteLength,w=false;for(let l of c.packages){if(!Y(t,i)){w=true,D.push({indexEntry:l,failureCode:"LIMIT_EXCEEDED"});continue}let T;try{let R=l.lineage[l.lineage.length-1];if(!R)throw new Q("LINEAGE_INVALID","Definition lineage is missing");if(R.definition.id!==l.definition.id||R.version!==l.definition.version||R.hash!==l.definition.hash)throw new Q("LINEAGE_STALE","Last lineage generation does not match bundle identity");T=wn(l.lineage,{...R.definition,hash:R.hash}).entries;}catch(R){let E=R instanceof Q?R.code:"LINEAGE_INVALID";o.push(r(E,l.packageDir)),D.push({indexEntry:l,failureCode:E});continue}let H=g.find(R=>R.name===l.packageDir.slice(5));if(!f||!H){D.push({indexEntry:l,failureCode:"BUNDLE_INTEGRITY"});continue}if(H.kind!=="directory"){D.push({indexEntry:l,failureCode:H.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY"});continue}let $;try{let R=await Nr(n,e.root,l.packageDir,t,i);if(!Y(t,i)){w=!0,D.push({indexEntry:l,failureCode:"LIMIT_EXCEEDED"});continue}let E=l.files.map(W=>W.path);if(R.length!==E.length||R.some((W,re)=>W!==E[re])){D.push({indexEntry:l,failureCode:"BUNDLE_INTEGRITY"});continue}$=new Map;let F;for(let W of l.files){if(!Y(t,i)){F="LIMIT_EXCEEDED",w=!0;break}if(v>=zn){F="LIMIT_EXCEEDED";break}let re;try{re=await Ze(n,e.root,`${l.packageDir}/${W.path}`,Mr(W.path));}catch(ln){F=ye(ln);break}if(!Y(t,i)){F="LIMIT_EXCEEDED",w=!0;break}if(v+re.byteLength>zn){v=zn,F="LIMIT_EXCEEDED";break}if(v+=re.byteLength,tt.createHash("sha256").update(re).digest("hex")!==W.sha256){F="BUNDLE_INTEGRITY";break}$.set(W.path,re);}if(F!==void 0){D.push({indexEntry:l,failureCode:F});continue}}catch(R){Y(t,i)||(w=true),D.push({indexEntry:l,failureCode:ye(R)});continue}D.push({indexEntry:l,lineage:T,files:$,...L.has(l)?{failureCode:"DUPLICATE_ID"}:{}});}return {indexHash:a,packages:D,diagnostics:o,incomplete:w}}function Lr(){return globalThis.performance?.now()??Date.now()}function De(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))De(n);return Object.freeze(e)}function Kt(e){return Object.freeze(Array.from(e))}async function Wn(e,n,t,i){if(n.pinnedFiles!==void 0){let o=n.pinnedFiles.get(t);if(o===void 0)throw new _("NOT_FOUND");if(o.byteLength>i)throw new _("LIMIT_EXCEEDED");return new Uint8Array(o)}return Ze(e,n.root,`${n.relativePath}/${t}`,i)}function Ur(e,n,t){let i=tt.createHash("sha256"),o=new TextEncoder().encode(K(e)),r=s=>{let a=new Uint8Array(8);new DataView(a.buffer).setBigUint64(0,BigInt(s)),i.update(a);};return r(o.byteLength),i.update(o),r(n.byteLength),i.update(n),r(t.byteLength),i.update(t),i.digest("hex")}function Rr(e,n){let t={...e.definition,sourceHash:n},i={...t,hash:ce(t)};try{pe(i);}catch{throw new G("MANIFEST_INVALID","normalized definition is invalid")}return i}function Or(e){return e.actions.some(n=>n.backend.type==="core"&&n.backend.handler!=="state.set")}function kr(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function xr(e){if(typeof e.listDirectory=="function")return e.listDirectory;if(typeof e.readDirectory=="function")return e.readDirectory;if(typeof e.readdir=="function")return e.readdir}async function Ze(e,n,t,i){let o=kr(e);if(!o)throw new _("READ_DENIED");return _r(await o.call(e,n,t,i))}async function Qe(e,n,t){let i=xr(e);if(!i)throw new _("READ_DENIED");let o=await i.call(e,n,t);if(!Array.isArray(o))throw new _("READ_DENIED");return o.map(Er).filter(r=>r!==null)}function wr(e){let n=[];for(let t of [e.reserved,e.builtin])t&&n.push(t);return e.builtins&&"listMcpApps"in e.builtins?n.push(Xt(e.builtins)):e.builtins&&n.push(e.builtins),e.builtinCatalog&&n.push(Xt(e.builtinCatalog)),n.push({...e.reservedAppIds===void 0?{}:{appIds:e.reservedAppIds},...e.reservedDefinitionIds===void 0?{}:{definitionIds:e.reservedDefinitionIds},...e.reservedToolNames===void 0?{}:{toolNames:e.reservedToolNames}}),n}function Xt(e){let n=[],t=[],i=[];for(let o of e.listMcpApps())typeof o.appId=="string"&&n.push(o.appId),o.definition&&typeof o.definition.id=="string"&&t.push(o.definition.id);for(let o of e.listMcpAppTools())typeof o.name=="string"&&i.push(o.name);return {appIds:n,definitionIds:t,toolNames:i}}function ne(e,n){e.diagnostic||(e.diagnostic=en(n,e.source,e.relativePath,e.identity?.pluginId));}function Cr(e){let n=new Map;for(let i of e){let o=i.identity?.pluginId;if(o===void 0)continue;let r=n.get(o)??[];r.push(i),n.set(o,r);}for(let i of n.values()){if(i.length<2)continue;let o=i.filter(s=>s.provenance!==void 0);if(o.length>0){for(let s of i)s.provenance===void 0&&ne(s,"RESERVED_ID");if(o.length>1)for(let s of o)ne(s,"DUPLICATE_ID");continue}let r=i.filter(s=>s.source==="apps");if(r.length>1){for(let s of r)ne(s,"DUPLICATE_ID");for(let s of i.filter(a=>a.source==="skills"))ne(s,"DUPLICATE_ID");}else for(let s of i.filter(a=>a.source==="skills"))ne(s,"DUPLICATE_ID");}let t=new Map;for(let i of e){if(i.diagnostic?.code==="RESERVED_ID")continue;let o=i.identity?.definitionKey;if(o===void 0)continue;let r=t.get(o)??[];r.push(i),t.set(o,r);}for(let i of t.values())if(i.length>1)for(let o of i)ne(o,"DUPLICATE_ID");}function vr(e,n,t){let i=new Set,o=new Set,r=new Set,s=new Set(t.map(c=>c.appId)),a=new Set(e.filter(c=>c.source==="bundled"&&c.candidate===void 0).flatMap(c=>c.bundleIdentity===void 0?[]:[c.bundleIdentity.definitionId]));for(let c of wr(n)){for(let p of c.appIds??[])typeof p=="string"&&i.add(p);for(let p of c.definitionIds??[])typeof p=="string"&&o.add(p);for(let p of c.toolNames??[])typeof p=="string"&&r.add(p);}for(let c of e){let p=c.candidate;if(!p)continue;if(i.has(p.pluginId)||o.has(p.definitionId)){ne(c,"RESERVED_ID");continue}if(c.provenance===void 0&&(s.has(p.pluginId)||a.has(p.definitionId))){ne(c,"RESERVED_ID");continue}[p.toolNames.read,p.toolNames.action].filter(f=>f!==void 0).some(f=>r.has(f))&&ne(c,"DUPLICATE_ID");}}function jr(e){return [...e].sort((n,t)=>{let i=Gt.indexOf(n.source)-Gt.indexOf(t.source);return i!==0?i:Ne(n.relativePath,t.relativePath)})}function N(e,n){e.diagnostic=en(n,e.source,e.relativePath,e.identity?.pluginId);}async function Yt(e,n,t){if(t.byteLength>262144){N(n,"LIMIT_EXCEEDED");return}let i;try{i=Pr(t);}catch{N(n,"MANIFEST_INVALID");return}if(n.bundleIdentity===void 0)n.identity=i.identity;else if(i.identity?.pluginId!==n.bundleIdentity.appId||i.identity.definitionKey!==`${n.bundleIdentity.definitionId}\0${String(n.bundleIdentity.version)}`){N(n,"BUNDLE_INTEGRITY");return}if(Ae(i.value)&&i.value.builtinOnly===true){N(n,"RESERVED_ID");return}let o;try{let E=fe(i.value,{mode:"local"});if(E.manifestVersion!==2)throw new G("MANIFEST_INVALID","workspace App requires v2");o=E;}catch(E){if(E instanceof G){N(n,Wt(E));return}if(E instanceof de){N(n,Gn(E.code));return}if(Ae(E)&&typeof E.code=="string"){N(n,Gn(E.code));return}throw E}let r={pluginId:o.pluginId,definitionKey:`${o.definitionId}\0${String(o.version)}`};if(n.bundleIdentity===void 0&&(n.identity=r),o.actions.length>0)try{wt(o.actions.map(E=>({actionId:E.actionId,inputSchema:E.inputSchema})));}catch(E){if(E instanceof de){N(n,Gn(E.code));return}throw E}let s;try{s=await Wn(e,n,"ui/index.html",$e);}catch(E){N(n,ve(le(E),"entry"));return}if(s.byteLength>$e){N(n,"LIMIT_EXCEEDED");return}let a;try{a=Zt(s);}catch{N(n,"ENTRY_INVALID");return}if(s.byteLength===0||a.length===0){N(n,"ENTRY_INVALID");return}let c=tt.createHash("sha256").update(s).digest("hex");if(o.entryHash!==void 0&&o.entryHash!==c){N(n,"ENTRY_INVALID");return}let p={},u,f;if(o.initialState!==void 0){try{u=await Wn(e,n,"ui/state.json",65536);}catch(E){N(n,ve(le(E),"initial"));return}if(u.byteLength>65536){N(n,"LIMIT_EXCEEDED");return}try{let E=Xn(u),F=o.dataPaths??[],W=Ln(E,F);p=se(W,0,F),me(p);}catch{N(n,"INITIAL_STATE_INVALID");return}if(f=tt.createHash("sha256").update(u).digest("hex"),o.initialState.hash!==void 0&&o.initialState.hash!==f){N(n,"INITIAL_STATE_INVALID");return}}let A={...o,entryHash:c,...o.initialState===void 0?{}:{initialState:{path:"ui/state.json",hash:f}}},m=Un(A),g=Ur(A,s,u??new Uint8Array),P;try{P=Rr(m,g);}catch(E){if(E instanceof G){N(n,Wt(E));return}throw E}let M;if(n.bundleLineage!==void 0){let E=n.bundleLineage[n.bundleLineage.length-1];if(!E){N(n,"LINEAGE_INVALID");return}let{legacy:F,...W}=E.definition,{hash:re,...ln}=P;if(K(W)!==K(ln)){N(n,"LINEAGE_STALE");return}if(F!==void 0&&(P={...P,legacy:F}),F!==void 0)try{P={...P,hash:ce(P)},pe(P);}catch{N(n,"LINEAGE_INVALID");return}M=n.bundleLineage;}if(n.bundleIdentity!==void 0&&n.bundleIdentity.appId!==o.pluginId){N(n,"BUNDLE_INTEGRITY");return}if(n.bundleIdentity!==void 0&&(n.bundleIdentity.definitionId!==P.id||n.bundleIdentity.version!==P.version||n.bundleIdentity.definitionHash!==P.hash)){N(n,"LINEAGE_STALE");return}let L=yr(o.pluginId),y=o.actions.length===0?{read:L.read}:L,I=De(m),D=De(A),v=De(P),w=De({...m.handlers}),l=Kt(s),T=u===void 0?void 0:Kt(u),H=Object.freeze({...n.provenance===void 0?{}:{provenance:n.provenance},entry:Object.freeze({path:"ui/index.html",hash:c,bytes:l}),...T===void 0?{}:{initialState:Object.freeze({path:"ui/state.json",hash:f,bytes:T})}}),$={appId:o.pluginId,pluginId:o.pluginId,definitionId:o.definitionId,version:o.version,relativePath:n.relativePath,manifest:D,normalized:I,name:o.name,description:o.description,...o.icon===void 0?{}:{icon:o.icon},...o.tone===void 0?{}:{tone:o.tone},definition:v,handlers:w,resources:H,html:a,entryBytes:l,entryHash:c,initialState:De(p),...T===void 0?{}:{initialStateBytes:T},...f===void 0?{}:{initialStateHash:f},sourceHash:g,toolNames:Object.freeze(y)},R=n.provenance===void 0?{...$,source:n.source}:{...$,provenance:n.provenance,lineage:M??[]};n.candidate=Object.freeze(R),Or(o)&&N(n,"EXEC_DENIED");}async function Vr(e,n){try{return await Wn(e,n,"ui-plugin.json",262144)}catch(t){if(le(t)==="NOT_FOUND")return;N(n,ve(le(t),"manifest"));return}}function Fr(e,n,t){let i=jr(e);Cr(i);let o=Object.freeze(i.filter(a=>a.candidate!==void 0&&a.diagnostic===void 0).map(a=>a.candidate)),r=Object.freeze(i.filter(a=>a.diagnostic!==void 0).map(a=>a.diagnostic)),s={apps:o,diagnostics:r,complete:n===void 0,...n===void 0?{}:{incompleteReason:n},...t===void 0?{}:{productBundleIndexHash:t}};return Object.defineProperty(s,"candidates",{configurable:false,enumerable:false,get:()=>o}),Object.freeze(s)}function Br(e){if(e===null||typeof e!="object"&&typeof e!="function")return false;let n=e;return typeof n.readVerifiedFile=="function"||typeof n.readFileVerified=="function"||typeof n.listDirectory=="function"||typeof n.readDirectory=="function"||typeof n.readdir=="function"}function Hr(e,n){if(Br(e))return {fs:e,options:{}};let t=e??n??{};return {fs:t.filesystem??t.fileSystem??t.fs??zt,options:t}}async function ei(e,n,t){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");let{fs:i,options:o}=Hr(n,t),r=o.clock??Lr,s=r(),a=[],c=0,p,u=await Sr(o.productBundle,i,s,r);a.push(...u.diagnostics.map(m=>({source:m.source,root:o.productBundle?.root??e,name:"",relativePath:m.relativePath,diagnostic:m})));let f=u.packages.map(m=>m.indexEntry);u.incomplete&&(p="time_limit");for(let m of u.packages){let g=m.indexEntry,P=g.packageDir,M=u.indexHash===void 0?void 0:Ot(Object.freeze({kind:"bundled",indexHash:u.indexHash,packageDir:P,appId:g.appId,definitionId:g.definition.id,version:g.definition.version,definitionHash:g.definition.hash,files:g.files})),L={source:"bundled",root:o.productBundle?.root??e,name:P.slice(5),relativePath:P,...M===void 0?{}:{provenance:M},...m.files===void 0?{}:{pinnedFiles:m.files},...m.lineage===void 0?{}:{bundleLineage:m.lineage},bundleIdentity:{appId:g.appId,definitionId:g.definition.id,version:g.definition.version,definitionHash:g.definition.hash},identity:br(g)};if(a.push(L),c+=1,m.failureCode!==void 0){N(L,m.failureCode);continue}let y=m.files?.get("ui-plugin.json");if(y===void 0){N(L,"BUNDLE_INTEGRITY");continue}await Yt(i,L,y),L.candidate!==void 0&&L.diagnostic===void 0&&c<64&&!Y(s,r)&&(p="time_limit");}let A=[{source:"apps",directory:"apps"},{source:"skills",directory:"skills"}];for(let m of A){let{source:g,directory:P}=m,M;try{M=await Qe(i,e,P);}catch(y){if(le(y)==="NOT_FOUND")continue;a.push({source:g,root:e,name:"",relativePath:g,diagnostic:en(ve(le(y),"manifest"),g,g)});continue}let L=M.filter(y=>y.kind==="directory"||y.kind==="symlink").filter(y=>qt(y.name)).map(y=>({source:g,root:e,name:y.name,relativePath:hr(g,y.name)})).sort((y,I)=>Ne(y.relativePath,I.relativePath));for(let y of L){let I={...y};a.push(I);let D;if(g==="skills"&&(D=await Vr(i,I),D===void 0))continue;if(c>=64){N(I,"LIMIT_EXCEEDED");continue}if(y.relativePath.split("/").length-1>2){N(I,"LIMIT_EXCEEDED");continue}if(p!==void 0||!Y(s,r)){N(I,"LIMIT_EXCEEDED"),p="time_limit";continue}if(c+=1,D===void 0)try{D=await Ze(i,I.root,`${I.relativePath}/ui-plugin.json`,262144);}catch(w){N(I,ve(le(w),"manifest"));continue}await Yt(i,I,D),I.diagnostic===void 0&&c<64&&!Y(s,r)&&(p="time_limit");}}return vr(a,o,f),Fr(a,p,u.indexHash)}var Gr=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/;function tn(e){let n="screenHash"in e?e.screenHash:void 0,i=("skillHash"in e?e.skillHash:void 0)??(e.relativePath!==void 0&&e.fileBytes!==void 0?$r(e.relativePath,e.fileBytes):void 0);if(n!==void 0&&i!==void 0){let o=JSON.stringify({screenHash:n,skillHash:i});return tt.createHash("sha256").update(o,"utf8").digest("hex")}if(n!==void 0)return n;if(i!==void 0)return i;throw new TypeError("App definition hash input must contain a screenHash or skill bytes")}function $r(e,n){let t=new TextEncoder().encode(on(e)),i=Wr(n),o=new Uint8Array(t.byteLength+1+i.byteLength);return o.set(t,0),o[t.byteLength]=0,o.set(i,t.byteLength+1),tt.createHash("sha256").update(o).digest("hex")}function Wr(e){if(typeof e=="string")return new TextEncoder().encode(e);if(e instanceof Uint8Array)return new Uint8Array(e);if(e instanceof ArrayBuffer)return new Uint8Array(e.slice(0));if(Array.isArray(e)&&e.every(n=>Number.isInteger(n)&&n>=0&&n<=255))return Uint8Array.from(e);throw new TypeError("fileBytes must be UTF-8 text or bytes")}function on(e){if(typeof e!="string"||e.length===0||B.isAbsolute(e)||/[\\\u0000]/.test(e))throw new TypeError("relative path must be package-relative");let n=e.split("/").filter(t=>t.length>0&&t!==".").join("/");if(!n||n.split("/").some(t=>t===".."))throw new TypeError("relative path must stay inside the package");return n}function nn(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),o=Math.min(t.byteLength,i.byteLength);for(let r=0;r<o;r+=1){let s=t[r]-i[r];if(s!==0)return s}return t.byteLength-i.byteLength}function ii(e,n){let t=B.relative(e,n).split(B.sep).join("/");return !t||t===".."||t.startsWith("../")||B.isAbsolute(t)?null:on(t)}function Jr(e){return e==="apps"||e.startsWith("apps/")?"apps":e==="skills"||e.startsWith("skills/")?"skills":e==="node_modules"||e.startsWith("node_modules/")?"node_modules":null}function oi(e){return Object.freeze({packageRoot:e})}function Kr(e){return Object.freeze({id:e.definition.id,version:e.definition.version,hash:e.definition.hash,usage:e.definition.usage??ae,...e.definition.detailPanel===void 0?{}:{detailPanel:e.definition.detailPanel},...e.definition.displayModes===void 0?{}:{displayModes:e.definition.displayModes},...e.definition.summaryProjection===void 0?{}:{summaryProjection:e.definition.summaryProjection}})}function ri(e){return {capabilities:Object.freeze([...e]),origin:"local",ownership:"unknown",shareability:"unknown",sharingAvailability:"unavailable"}}function Xr(e,n){let t=e.candidate,i=t.provenance!==void 0,o=n&&!i?["screen","skill"]:["screen"],r=Kr(t),s=tn(n?{screenHash:r.hash,skillHash:n.skillHash}:{screenHash:r.hash}),a=t.description||n?.skill.description||"",c=String(t.version),p={appId:t.pluginId,name:t.name,description:a,version:c,...ri(o),definition:r,...n===void 0||i?{}:{skillName:n.skill.name},...i?{provenance:t.provenance}:{localDefinitionRef:oi(e.packageRoot)},definitionHash:s};return {...i?{}:{packageRoot:e.packageRoot},source:i?"bundled":t.source,appId:p.appId,capabilities:o,summary:Object.freeze(p)}}function Yr(e){let n=qr(e.skill.name),t={appId:n,name:e.skill.name,description:e.skill.description??"",...e.skill.version===void 0?{}:{version:e.skill.version},...ri(["skill"]),skillName:e.skill.name,localDefinitionRef:oi(e.packageRoot),definitionHash:tn({skillHash:e.skillHash})};return {packageRoot:e.packageRoot,source:e.source,appId:n,capabilities:["skill"],summary:Object.freeze(t)}}function qr(e){return `skill.${e.replace(/^@/,"").replace(/\//g,".").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,122)||"unnamed"}`}function V(e,n,t,i){return Object.freeze({code:e,source:n,relativePath:Zr(t),...i===void 0?{}:{appId:i}})}function Zr(e){if(typeof e!="string"||e.length===0||B.isAbsolute(e)||/[\\\u0000]/.test(e))return "<unknown>";let n=e.split("/").filter(t=>t.length>0&&t!==".").join("/");return n.split("/").some(t=>t==="..")?"<unknown>":n}function Qr(e){return V(e.code,e.source,e.relativePath,e.pluginId)}function es(e,n){let t=ii(e,n.dir);if(!t)return {diagnostic:V("PATH_ESCAPED","node_modules","node_modules")};let i=Jr(t);if(!i)return {diagnostic:V("PATH_ESCAPED","node_modules",t)};let o=On(n.skillMdPath);if(!o.readable)return {diagnostic:V("SKILL_READ_FAILED",i,t)};if(!o.valid)return {diagnostic:V("SKILL_INVALID",i,t)};let r=ns(n.dir,n.skillMdPath);if(!r)return {diagnostic:V("PATH_ESCAPED",i,t)};try{let s=new Uint8Array(C.readFileSync(n.skillMdPath));return {skill:n,packageRoot:t,relativeSkillPath:r,skillHash:tn({relativePath:r,fileBytes:s}),source:i}}catch{return {diagnostic:V("SKILL_READ_FAILED",i,t)}}}function ns(e,n){let t=B.relative(e,n).split(B.sep).join("/");try{return on(t)}catch{return null}}function ts(e){if(!Gr.test(e.appId))return {diagnostic:V("BUILTIN_INVALID","builtin",`builtin/${e.appId||"unknown"}`)};let n=e.definition===void 0?void 0:{id:e.definition.id,version:e.definition.version,hash:e.definition.hash,usage:e.definition.usage??ae,...e.definition.detailPanel===void 0?{}:{detailPanel:e.definition.detailPanel},...e.definition.displayModes===void 0?{}:{displayModes:e.definition.displayModes},...e.definition.summaryProjection===void 0?{}:{summaryProjection:e.definition.summaryProjection}},t=n?.hash??tt.createHash("sha256").update(JSON.stringify({appId:e.appId,name:e.name,description:e.description}),"utf8").digest("hex"),i={appId:e.appId,name:e.name,description:e.description,...n===void 0?{}:{version:String(n.version),definition:n},capabilities:["screen"],origin:"builtin",ownership:"unknown",shareability:"forbidden",sharingAvailability:"unavailable",definitionHash:t};return {source:"builtin",appId:e.appId,summary:Object.freeze(i)}}function is(e){return e.builtinCatalog}function os(e){let n=e.packageRoot??e.relativePath??e.packageRootPath;if(n===void 0)return null;try{return on(n)}catch{return null}}function rs(e){let n=e.marketplaceContentId;return typeof n=="string"&&n.length>0?n:void 0}function ss(e,n,t){let i=n.installed??[],o=new Map;for(let s of i){let a=os(s);if(!a){t.push(V("INSTALLED_IDENTITY_MISMATCH","installed","installed"));continue}let c=o.get(a);if(c&&JSON.stringify(c)!==JSON.stringify(s)){t.push(V("INSTALLED_IDENTITY_MISMATCH","installed",a));continue}o.set(a,s);}let r=new Map;for(let s of e)s.packageRoot!==void 0&&r.set(s.packageRoot,s);for(let[s,a]of o){let c=r.get(s);if(!c){t.push(V("INSTALLED_MISSING","installed",s,a.appId));continue}let p=rs(a);if(!p){t.push(V("INSTALLED_CONTENT_ID_MISSING","installed",s,a.appId));continue}if(a.appId!==void 0&&a.appId!==c.appId||a.definitionHash!==void 0&&a.definitionHash!==c.summary.definitionHash){t.push(V("INSTALLED_IDENTITY_MISMATCH","installed",s,a.appId));continue}let u={...c.summary,origin:"installed",...a.slug===void 0?{}:{slug:a.slug},marketplaceContentId:p},f=e.indexOf(c);f>=0&&(e[f]={...c,summary:Object.freeze(u)});}}function as(e,n){let t=new Map;for(let o of e){let r=t.get(o.appId)??[];r.push(o),t.set(o.appId,r);}let i=new Set;for(let o of t.values()){if(o.length<2)continue;let r=o.some(s=>s.source==="builtin")?"builtin":o.some(s=>s.source==="bundled")?"bundled":void 0;if(r!==void 0){let s=o.filter(a=>a.source===r);for(let a of o.filter(c=>c.source!==r))i.add(a),n.push(V("RESERVED_ID",a.source,qn(a),a.appId));if(s.length>1)for(let a of s)i.add(a),n.push(V("DUPLICATE_ID",a.source,qn(a),a.appId));continue}for(let s of o)i.add(s),n.push(V("DUPLICATE_ID",s.source,qn(s),s.appId));}return e.filter(o=>!i.has(o))}function qn(e){return e.packageRoot??e.summary.provenance?.packageDir??`builtin/${e.appId}`}function cs(e,n){return e.filter(t=>!(t.code==="MANIFEST_MISSING"&&n.has(t.relativePath))).map(Qr)}function ps(e){return e.filesystem}function ds(e,n){let t=ps(e);return {...t===void 0?{}:{filesystem:t},...e.productBundle===void 0?{}:{productBundle:e.productBundle},...n===void 0?{}:{builtinCatalog:n}}}async function si(e,n={}){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");let t=is(n),i=await ei(e,ds(n,t)),o=[B.join(e,"skills"),B.join(e,"node_modules"),B.join(e,"apps")],r=[],s=[],a=[],c=new Set;for(let y of o)for(let I of Mt([y])){let D=ii(e,I.dir);(D===null||!c.has(D))&&(a.push(I),D!==null&&c.add(D));}for(let y of a){let I=es(e,y);"diagnostic"in I?r.push(I.diagnostic):s.push(I);}let p=new Map;for(let y of i.apps??i.candidates??[]){let I=y.provenance===void 0?`workspace\0${y.relativePath}`:`bundled\0${y.provenance.indexHash}\0${y.provenance.packageDir}`;p.set(I,{candidate:y,packageRoot:y.relativePath});}let u=new Map(s.map(y=>[y.packageRoot,y])),f=[];for(let y of p.values()){let I=y.candidate.provenance===void 0?u.get(y.packageRoot):void 0,D=Xr(y,I);f.push({...D.packageRoot===void 0?{}:{packageRoot:D.packageRoot},source:D.source,appId:D.appId,summary:D.summary});}let A=new Set([...p.values()].filter(y=>y.candidate.provenance===void 0).map(y=>y.packageRoot));for(let y of s){if(A.has(y.packageRoot))continue;let I=Yr(y);f.push({packageRoot:I.packageRoot,source:I.source,appId:I.appId,summary:I.summary});}let m=[...cs(i.diagnostics,new Set(s.map(y=>y.packageRoot))),...r],g=[];if(t)for(let y of t.listMcpApps()){let I=ts(y);"diagnostic"in I?m.push(I.diagnostic):g.push(I);}let P=as([...f,...g],m);ss(P,n,m);let M=P.map(y=>y.summary).sort((y,I)=>nn(y.appId,I.appId)),L=[...m].sort((y,I)=>nn(y.relativePath,I.relativePath)||nn(y.code,I.code)||nn(y.appId??"",I.appId??""));return Object.freeze({items:Object.freeze(M),diagnostics:Object.freeze(L)})}function ls(e){let n=o=>o.replace(/[.+^${}()|[\]\\]/g,"\\$&"),i=e.split("/").map(o=>o==="**"?".*":o.split("*").map(n).join("[^/]*"));return new RegExp(`^${i.join("\\/")}$`)}function Me(e,n){try{return ls(n).test(e)}catch{return false}}function rn(e,...n){let t=e.split("/");if(t.length<n.length)return false;let i=t.length-n.length;return n.every((o,r)=>Me(t[i+r],o))}function us(e,n){return e.split("/").some(t=>Me(t,n))}var ai=[{label:".env*",test:e=>Me(e,".env*")},{label:".git/",test:(e,n,t)=>t&&e===".git"},{label:"memory/",test:(e,n,t)=>t&&e==="memory"},{label:"*.key",test:e=>Me(e,"*.key")},{label:"*.pem",test:e=>Me(e,"*.pem")},{label:"auth.json",test:e=>e==="auth.json"},{label:"node_modules/",test:(e,n,t)=>t&&e==="node_modules"},{label:"conversations/",test:(e,n,t)=>t&&e==="conversations"},{label:".crewx/threads/",test:(e,n,t)=>t&&rn(n,".crewx","threads")},{label:".crewx/crewx.db",test:(e,n,t)=>!t&&rn(n,".crewx","crewx.db")},{label:".crewx/*.log",test:(e,n,t)=>!t&&rn(n,".crewx","*.log")},{label:".crewx/publish/",test:(e,n,t)=>t&&rn(n,".crewx","publish")},{label:".crewx/",test:(e,n)=>us(n,".crewx")}];function sn(e,n,t){for(let i of ai)if(i.test(e,n,t))return i.label;return null}function et(e){let n=[],t=[];function i(o,r,s){let a;try{a=C__namespace.readdirSync(o,{withFileTypes:!0});}catch{return}a.sort((c,p)=>c.name.localeCompare(p.name));for(let c of a){let p=r?`${r}/${c.name}`:c.name,u=B__namespace.join(o,c.name);if(c.isSymbolicLink()){let f;try{f=C__namespace.statSync(u);}catch{t.push({path:p,rule:"symlink"});continue}if(f.isDirectory()){t.push({path:p,rule:s??"symlink-dir"});continue}let A=s??sn(c.name,p,false);A?t.push({path:p,rule:A}):t.push({path:p,rule:"symlink"});continue}if(c.isDirectory()){let f=s??sn(c.name,p,true);i(u,p,f);continue}if(c.isFile()){let f=s??sn(c.name,p,false);f?t.push({path:p,rule:f}):n.push(p);}}}return i(e,"",null),n.sort(),t.sort((o,r)=>o.path<r.path?-1:o.path>r.path?1:0),{included:n,excluded:t}}var fs=[{rule:"token-prefix",regex:/\b(?:sk-|ghp_|xoxb-)[A-Za-z0-9_-]{10,}/},{rule:"private-key",regex:/-----BEGIN [A-Z ]*PRIVATE KEY-----/},{rule:"aws-access-key",regex:/\bAKIA[0-9A-Z]{16}\b/}];function ys(e){return e.includes(0)}function nt(e,n,t){let i=[];for(let o of n){let r=B__namespace.join(e,o),s;try{let c=t?.get(o);s=c===void 0?C__namespace.readFileSync(r):Buffer.from(c);}catch{continue}if(ys(s))continue;s.toString("utf8").split(/\r\n|\r|\n/).forEach((c,p)=>{for(let{rule:u,regex:f}of fs)f.test(c)&&i.push({path:o,line:p+1,rule:u});});}return i}var te=class extends Error{constructor(t,i){super(`publish: [${t}]${i?` ${i}`:""}`);this.code=t;}code;name="PublishError"};function h(e,n){return new te(e,n)}var li=/^[a-z0-9-]+$/,As=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/,gs=/^[A-Za-z_][A-Za-z0-9_]*$/;function Is(e){let n=B__namespace.join(e,"crewx.yaml");if(!C__namespace.existsSync(n))return {};let t;try{t=ui__namespace.load(C__namespace.readFileSync(n,"utf8"));}catch{return {}}if(!t||typeof t!="object")return {};let i=t.metadata;if(!i||typeof i!="object")return {};let o=i;return {name:typeof o.name=="string"?o.name:void 0,version:typeof o.version=="string"?o.version:void 0,description:typeof o.description=="string"?o.description:void 0,requiredEnv:o.requiredEnv,crewxMinVersion:typeof o.crewxMinVersion=="string"?o.crewxMinVersion:void 0}}function ms(e){return tt__namespace.createHash("sha256").update(e).digest("hex")}function fi(e){let n;try{n=C__namespace.lstatSync(e);}catch{throw h("PACKAGE_FILE_INVALID",`file is not readable: ${B__namespace.basename(e)}`)}if(n.isSymbolicLink())throw h("PACKAGE_SYMLINK","symlink content is not publishable");if(!n.isFile())throw h("PACKAGE_FILE_INVALID","only regular files are publishable");return tt__namespace.createHash("sha256").update(new Uint8Array(C__namespace.readFileSync(e))).digest("hex")}function hs(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),o=Math.min(t.byteLength,i.byteLength);for(let r=0;r<o;r+=1){let s=t[r]-i[r];if(s!==0)return s}return t.byteLength-i.byteLength}function yi(e){if(typeof e!="string"||e.length===0||e.includes("\\")||e.includes("\0")||B__namespace.posix.isAbsolute(e)||e.split("/").some(n=>n===".."||n.length===0))throw h("PACKAGE_PATH_TRAVERSAL","manifest file path must be a non-empty POSIX relative path")}function Es(e){if(!/^(?:apps|skills)\/[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(e))throw h("APP_PACKAGE_ROOT_INVALID","packageRoot must be apps/<safe-id> or skills/<safe-id>")}function Ai(e){if(!As.test(e))throw new Error(`publish: invalid version "${e}" \u2014 must be semver (e.g. 1.0.0)`)}function gi(e,n,t={}){let i=Is(e),o=i.name??B__namespace.basename(e);if(!li.test(o))throw new Error(`publish: invalid name "${o}" \u2014 must match ${li} (lowercase letters, numbers, hyphen only)`);let r=t.version??i.version;if(!r)throw new Error("publish: version is required \u2014 set crewx.yaml metadata.version or pass opts.version");Ai(r);let s=Array.isArray(i.requiredEnv)?i.requiredEnv:[],a=[];for(let u of s){if(typeof u!="string"||!gs.test(u))throw new Error(`publish: requiredEnv must contain names only (no values), got "${String(u)}"`);a.push(u);}let c=n.map(u=>(yi(u),{path:u,sha256:fi(B__namespace.join(e,u))})).sort((u,f)=>u.path<f.path?-1:u.path>f.path?1:0),p={name:o,version:r,type:"template",description:i.description??"",files:c,requiredEnv:a};return i.crewxMinVersion&&(p.crewxMinVersion=i.crewxMinVersion),p}function _s(e){let n=e.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"");if(!n)throw h("APP_PACKAGE_ROOT_INVALID","appId cannot produce a marketplace name");return n}function Ii(e,n){if(Es(n.packageRoot),!n.version)throw new Error("publish: version is required for App publishing \u2014 pass opts.version");if(Ai(n.version),typeof n.description!="string")throw new Error("publish: App description must be a string");let t=[...new Set(n.capabilities)].sort();if(t.length===0||t.some(s=>s!=="screen"&&s!=="skill"))throw new Error("publish: App capabilities must contain screen or skill");let i=`${n.packageRoot}/`;if(t.includes("screen")){if(typeof n.definitionId!="string"||n.definitionId.length===0)throw h("APP_UI_MANIFEST_INVALID","screen App manifests require definitionId");for(let s of ["ui-plugin.json","ui/index.html"])if(!n.includedFiles.includes(`${i}${s}`))throw h("APP_UI_MANIFEST_INVALID",`screen App is missing ${s}`)}if(t.includes("skill")&&!n.includedFiles.includes(`${i}SKILL.md`))throw h("APP_SKILL_MISSING","skill capability requires package-root SKILL.md");let o=new Set,r=n.includedFiles.map(s=>{if(yi(s),!s.startsWith(i))throw h("PACKAGE_PATH_TRAVERSAL","App manifest file is outside packageRoot");let a=n.generatedFiles?.get(s);return a!==void 0&&o.add(s),{path:s,sha256:a===void 0?fi(B__namespace.join(e,s)):ms(a),...a===void 0?{}:{generated:true}}}).sort((s,a)=>hs(s.path,a.path));if(o.size>0&&(o.size!==1||!o.has(`${i}ui-plugin.json`)))throw new Error("publish: only the generated ui-plugin.json may be present in an App package");return {manifestVersion:1,name:_s(n.appId),version:n.version,type:"app",description:n.description,appId:n.appId,...n.definitionId===void 0?{}:{definitionId:n.definitionId},...n.definitionHash===void 0?{}:{definitionHash:n.definitionHash},capabilities:t,packageRoot:n.packageRoot,files:r,requiredEnv:[]}}function mi(e){return tt__namespace.createHash("sha256").update(e).digest("hex")}function Pi(e,n){if(typeof n!="string"||n.length===0||n.includes("\\")||n.includes("\0")||B__namespace.posix.isAbsolute(n)||n.split("/").some(o=>o===".."||o.length===0))throw h("PACKAGE_PATH_TRAVERSAL","archive paths must be non-empty POSIX relative paths");let t=B__namespace.resolve(e),i=B__namespace.resolve(t,...n.split("/"));if(i!==t&&!i.startsWith(`${t}${B__namespace.sep}`))throw h("PACKAGE_PATH_TRAVERSAL","archive path escaped its root");return i}function hi(e,n){let t=Pi(e,n),i;try{i=C__namespace.lstatSync(t);}catch{throw h("PACKAGE_FILE_INVALID","manifest file is missing")}if(i.isSymbolicLink())throw h("PACKAGE_SYMLINK","symlink content is not publishable");if(!i.isFile())throw h("PACKAGE_FILE_INVALID","only regular files are publishable");return new Uint8Array(C__namespace.readFileSync(t))}async function Di(e,n,t={}){let i=B__namespace.join(e,".crewx","publish");C__namespace.mkdirSync(i,{recursive:true});let o=B__namespace.join(i,`${n.name}-${n.version}.tgz`),r=B__namespace.join(i,`.${n.name}-${n.version}.${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}.tmp.tgz`),s=C__namespace.mkdtempSync(B__namespace.join(Ei__namespace.tmpdir(),"crewx-publish-"));try{let a=new Set,c=[];for(let p of n.files){if(a.has(p.path))throw h("PACKAGE_PATH_TRAVERSAL","manifest contains duplicate file paths");a.add(p.path);let u=t.generatedFiles?.get(p.path);if(p.generated===!0&&u===void 0)throw h("PACKAGE_GENERATED_FILE_MISSING","generated manifest file bytes are missing");if(t.sourceFileHashes?.has(p.path)){let m=hi(e,p.path);if(t.sourceFileHashes.get(p.path)!==mi(m))throw h("PACKAGE_STAGED_BYTES_MISMATCH","workspace source changed before staging")}let f=u??hi(e,p.path);if(mi(f)!==p.sha256)throw h("PACKAGE_STAGED_BYTES_MISMATCH",`staged bytes differ for ${p.path}`);let A=Pi(s,p.path);C__namespace.mkdirSync(B__namespace.dirname(A),{recursive:!0}),C__namespace.writeFileSync(A,new Uint8Array(f)),c.push(p.path);}C__namespace.writeFileSync(B__namespace.join(s,"manifest.json"),JSON.stringify(n,null,2)),await Ti__namespace.create({gzip:!0,file:r,cwd:s,portable:!0,noMtime:!0},["manifest.json",...c]),C__namespace.renameSync(r,o);}finally{try{C__namespace.rmSync(r,{force:!0});}catch{}C__namespace.rmSync(s,{recursive:true,force:true});}return o}var Se="/api/v1";var Ds=201,bs=200,Ns=409,it=401,bi={APP_NAME_CONFLICT:"APP_NAME_CONFLICT",CONTENT_SUSPENDED:"PUBLISH_CONTENT_SUSPENDED",CONTENT_REJECTED:"CONTENT_REJECTED",APP_VERSION_MUST_INCREASE:"APP_VERSION_MUST_INCREASE",APP_VERSION_INVALID:"APP_VERSION_INVALID"};function Ms(){return process.env.WI013_FAKE_UPLOAD==="1"}function Ss(e){let n=zlib.gunzipSync(new Uint8Array(e)),t=zlib.gzipSync(new Uint8Array(n),{level:1});if(Buffer.compare(new Uint8Array(t),new Uint8Array(e))===0)throw new Error("publish: [E_MALFORMED] Re-gzipped upload bytes are identical to the original \u2014 tamper is a no-op");return t}function Ls(e){return e.replace(/\/+$/,"")}async function je(e){try{return await e.json()}catch{return null}}function Ni(e,n,t){let i=e;if(!i||i.success!==true||i.data===void 0)throw new Error(`publish: [E_MALFORMED] ${n} response envelope is malformed (expected { success: true, data }) \u2014 HTTP ${t}`);return i.data}function Us(e){if(!e||typeof e!="object"||Array.isArray(e))return;let n=e;if(typeof n.contentId=="string"&&n.contentId.length>0)return n.contentId;if(!n.data||typeof n.data!="object"||Array.isArray(n.data))return;let t=n.data;return typeof t.contentId=="string"&&t.contentId.length>0?t.contentId:void 0}function Rs(e){if(!e||typeof e!="object"||Array.isArray(e))return;let n=e;if(typeof n.slug=="string"&&n.slug.length>0)return n.slug;if(!n.data||typeof n.data!="object"||Array.isArray(n.data))return;let t=n.data;return typeof t.slug=="string"&&t.slug.length>0?t.slug:void 0}function Mi(e,n){if(!e||typeof e!="object"||Array.isArray(e))return;let t=e,i=t.data&&typeof t.data=="object"&&!Array.isArray(t.data)?t.data:void 0,o=[t.code,t.message,i?.code,i?.message];for(let r of o){if(typeof r!="string"||!Object.prototype.hasOwnProperty.call(bi,r))continue;let s=r,a=s==="APP_NAME_CONFLICT"?`marketplace name is already in use: ${n}`:void 0;return h(bi[s],a)}}async function Os(e){if(!e.baseUrl.trim())throw new Error("publish: [E_ENV_MISSING] Marketplace base URL is required");if(!e.accessToken.trim())throw new Error("publish: [E_AUTH_EXPIRED] A valid bearer token is required");let n=Ls(e.baseUrl),t=e.accessPolicy??"private",i=e.manifest.name,o=e.manifest.type==="app"?e.manifest:void 0,r=o!==void 0,s=o?.appId,a;try{a=await fetch(`${n}${Se}/publisher/items`,{method:"POST",headers:{Authorization:`Bearer ${e.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify({slug:i,displayName:i,description:e.manifest.description,type:e.manifest.type,version:e.manifest.version,accessPolicy:t,...s===void 0?{}:{appId:s}})});}catch{throw new Error("publish: [E_NETWORK] Submit request failed (network)")}let c=await je(a),p=Us(c),u=Rs(c),f=r&&u!==void 0?u:i,A;if(a.status===Ds)A="created";else if(r&&a.status===bs){if(p===void 0)throw h("PUBLISH_CONTENT_ID_MISSING","App republish did not return an opaque contentId");A="existing";}else if(a.status===Ns){if(r)throw Mi(c,i)??h("APP_NAME_CONFLICT",`marketplace name is already in use: ${i}`);A="existing";}else throw a.status===it?new Error("publish: [E_AUTH_EXPIRED] Authentication is expired or missing \u2014 please log in again (HTTP 401)"):new Error(`publish: [E_HTTP] Submit request failed \u2014 HTTP ${a.status}`);let m="not-needed",g=null;if(A==="existing"&&!r){let l;try{l=await fetch(`${n}${Se}/publisher/items`,{method:"GET",headers:{Authorization:`Bearer ${e.accessToken}`}});}catch{throw new Error("publish: [E_NETWORK] Publisher items request failed (network)")}let T=await je(l);if(l.status!==200)throw new Error(`publish: [E_HTTP] Publisher items request failed \u2014 HTTP ${l.status}`);let $=Ni(T,"publisher items",l.status)?.items;if(!Array.isArray($))throw new Error(`publish: [E_MALFORMED] Publisher items response is malformed (expected data.items[]) \u2014 HTTP ${l.status}`);let R=$.find(E=>!E||typeof E!="object"?false:E.slug===i);if(!R||typeof R.version!="string")throw new Error(`publish: [E_MALFORMED] Publisher items response does not contain slug "${i}" \u2014 HTTP ${l.status}`);if(g=R.version,g!==e.manifest.version){let E;try{E=await fetch(`${n}${Se}/publisher/items/${encodeURIComponent(i)}`,{method:"PUT",headers:{Authorization:`Bearer ${e.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify({version:e.manifest.version})});}catch{throw new Error("publish: [E_NETWORK] Version update request failed (network)")}if(!E.ok)throw await je(E),E.status===it?new Error(`publish: [E_AUTH_EXPIRED] Authentication is expired or missing \u2014 please log in again (HTTP ${E.status})`):E.status===403?new Error(`publish: [E_FORBIDDEN] Version update is forbidden; only the item owner can update an existing item (HTTP ${E.status})`):new Error(`publish: [E_HTTP] Version update failed \u2014 HTTP ${E.status}`);m="applied";}}let P=C__namespace.readFileSync(e.tgzPath),M=Ms()?Ss(P):P,L=new FormData;L.set("archive",new Blob([new Uint8Array(M)],{type:"application/gzip"}),`${f}-${e.manifest.version}.tgz`);let y=r&&p!==void 0?p:i,I;try{I=await fetch(`${n}${Se}/publisher/items/${encodeURIComponent(y)}/upload`,{method:"POST",headers:{Authorization:`Bearer ${e.accessToken}`},body:L});}catch{throw new Error("publish: [E_NETWORK] Upload request failed (network)")}if(I.status===it)throw new Error("publish: [E_AUTH_EXPIRED] Authentication is expired or missing \u2014 please log in again (HTTP 401)");if(!I.ok){let l=await je(I);if(r){let T=Mi(l,f);if(T)throw T}throw new Error(`publish: [E_HTTP] Upload request failed \u2014 HTTP ${I.status}`)}let D=await je(I),v=Ni(D,"upload",I.status),w=typeof v.contentId=="string"&&v.contentId.length>0?v.contentId:p;if(r&&w===void 0)throw h("PUBLISH_CONTENT_ID_MISSING","App upload did not return an opaque contentId");return {slug:f,version:e.manifest.version,...w===void 0?{}:{contentId:w},artifactChecksum:v.artifactChecksum,artifactSizeBytes:v.artifactSizeBytes,submitOutcome:A,versionUpdate:m,serverVersionBefore:g}}var ks=1e4,xs=100*1024*1024;function ot(e){return tt__namespace.createHash("sha256").update(e).digest("hex")}function ws(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function cn(e,n){if(!n||n.includes("\\")||n.includes("\0")||B__namespace.posix.isAbsolute(n)||n.split("/").some(r=>r===".."||r.length===0))throw h("PACKAGE_PATH_TRAVERSAL","workspace file path is not a safe relative path");let t=B__namespace.resolve(e,...n.split("/")),i=B__namespace.resolve(e);if(t!==i&&!t.startsWith(`${i}${B__namespace.sep}`))throw h("PACKAGE_PATH_TRAVERSAL","workspace file path escaped the workspace root");let o;try{o=C__namespace.lstatSync(t);}catch{throw h("PACKAGE_FILE_INVALID",`workspace file is missing: ${n}`)}if(o.isSymbolicLink())throw h("PACKAGE_SYMLINK",`symlink is not publishable: ${n}`);if(!o.isFile())throw h("PACKAGE_FILE_INVALID",`not a regular file: ${n}`);return new Uint8Array(C__namespace.readFileSync(t))}function pn(e,n){return e===n||e.startsWith(`${n}/`)}function Cs(e,n){return e.path<n.path?-1:e.path>n.path?1:e.rule.localeCompare(n.rule)}function Li(e,n,t){let i=e??n;if(!Number.isSafeInteger(i)||i<=0)throw new te("PACKAGE_SIZE_LIMIT",`${t} must be a positive integer`);return i}function Ri(e,n,t,i){let o=Li(t.maxFileCount??t.maxFiles,ks,"max file count"),r=Li(t.maxTotalBytes??t.maxBytes,xs,"max total bytes");if(n.length>o)throw new te("PACKAGE_SIZE_LIMIT",`package exceeds file count limit (${o})`);let s=0;for(let a of n){let c=i?.get(a);if(c!==void 0?s+=c.byteLength:s+=cn(e,a).byteLength,s>r)throw new te("PACKAGE_SIZE_LIMIT",`package exceeds byte limit (${r})`)}}function vs(e){return e.appId!==void 0||e.expectedDefinitionHash!==void 0}function js(e){let n=e.appId!==void 0,t=e.expectedDefinitionHash!==void 0;if(!n&&t)throw h("APP_ID_REQUIRED","appId is required with expectedDefinitionHash");if(n&&!t)throw h("APP_DEFINITION_HASH_REQUIRED","expectedDefinitionHash is required with appId");if(!n||!t)throw h("APP_ID_REQUIRED")}function Vs(e,n){let t=e.filter(i=>i.appId===n);if(t.length===0)throw h("APP_NOT_FOUND",`no publishable App matches ${n}`);if(t.length!==1)throw h("APP_AMBIGUOUS",`more than one App matches ${n}`);return t[0]}function Fs(e){let n=e.localDefinitionRef?.packageRoot;if(!n||!/^(?:apps|skills)\/[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(n))throw h("APP_PACKAGE_ROOT_INVALID","selected App is not rooted in apps/<safe-id> or skills/<safe-id>");return n}function Bs(e,n){let t=[];for(let i of e.excluded)t.push(pn(i.path,n)?i:{path:i.path,rule:"out-of-app-scope"});for(let i of e.included)pn(i,n)||t.push({path:i,rule:"out-of-app-scope"});return t.sort(Cs)}function Hs(e,n,t,i){let o=`${t}/ui-plugin.json`;if(!i.includes(o))throw h("APP_UI_MANIFEST_INVALID","selected screen App has no package ui-plugin.json");let r=cn(e,o),s=ot(r),a;try{a=JSON.parse(Buffer.from(r).toString("utf8"));}catch{throw h("APP_UI_MANIFEST_INVALID","ui-plugin.json is not valid JSON")}let c;try{let A=fe(a,{mode:"local"});if(A.manifestVersion!==2)throw new Error("screen App requires manifestVersion 2");c=A;}catch(A){throw A instanceof G?h("APP_UI_MANIFEST_INVALID",A.code):h("APP_UI_MANIFEST_INVALID")}if(c.pluginId!==n.appId)throw h("APP_DEFINITION_CONFLICT","ui-plugin.json pluginId no longer matches the selected App");let p=`${t}/ui/index.html`;if(!i.includes(p))throw h("APP_UI_MANIFEST_INVALID","screen entry is outside package scope");let u=ot(cn(e,p)),f=JSON.parse(JSON.stringify(a));if(f.entryHash=u,Object.prototype.hasOwnProperty.call(f,"initialState")){let A=f.initialState;if(!ws(A)||A.path!=="ui/state.json")throw h("APP_INITIAL_STATE_OUT_OF_SCOPE","initialState must reference ui/state.json inside the package");let m=`${t}/ui/state.json`;if(!i.includes(m))throw h("APP_INITIAL_STATE_OUT_OF_SCOPE","initialState reference is outside the selected package");let g=cn(e,m);f.initialState={...A,hash:ot(g)};}try{let A=fe(f,{mode:"published"});return {bytes:new Uint8Array(Buffer.from(An(A),"utf8")),sourceHash:s}}catch(A){throw A instanceof G?h("APP_UI_MANIFEST_INVALID",A.code):h("APP_UI_MANIFEST_INVALID")}}async function zs(e,n){let{included:t,excluded:i}=et(e);Ri(e,t,n);let o=gi(e,t,{version:n.version}),r=nt(e,t);return {plan:{manifest:o,included:t,excluded:i,secretFindings:r},archiveOptions:{}}}async function Gs(e,n){js(n);let t=await si(e),i=Vs(t.items,n.appId);if(i.definitionHash!==n.expectedDefinitionHash)throw h("APP_DEFINITION_CONFLICT",`definitionHash changed for ${n.appId}`);let o=Fs(i),r=et(e);if(r.excluded.some(m=>pn(m.path,o)&&(m.rule==="symlink"||m.rule==="symlink-dir")))throw h("PACKAGE_SYMLINK","selected App package contains a symlink");let s=r.included.filter(m=>pn(m,o)),a=Bs(r,o),c=new Map,p=new Map;if(i.capabilities.includes("screen")){let m=Hs(e,i,o,s);c.set(`${o}/ui-plugin.json`,m.bytes),p.set(`${o}/ui-plugin.json`,m.sourceHash);}if(i.capabilities.includes("skill")&&!s.includes(`${o}/SKILL.md`))throw h("APP_SKILL_MISSING","skill capability requires package-root SKILL.md");Ri(e,s,n,c);let u={appId:i.appId,version:n.version??"",description:i.description,capabilities:i.capabilities,packageRoot:o,...i.definition?.id===void 0?{}:{definitionId:i.definition.id},definitionHash:i.definitionHash,includedFiles:s,generatedFiles:c},f=Ii(e,u),A=nt(e,s,c);return {plan:{manifest:f,included:s,excluded:a,secretFindings:A},archiveOptions:{generatedFiles:c,sourceFileHashes:p}}}async function Oi(e,n){let t=B__namespace.resolve(e);if(vs(n))return Gs(t,n);if(n.expectedDefinitionHash!==void 0)throw h("APP_ID_REQUIRED");return zs(t,n)}async function mp(e,n={}){return (await Oi(e,n)).plan}function $s(e){let n=e.map(t=>`${t.path}:${t.line} (${t.rule})`).join(", ");throw new te("PUBLISH_SECRET_FINDINGS",`aborted \u2014 secret findings must be resolved before packing: ${n}`)}async function ki(e,n={}){let t=B__namespace.resolve(e),i=await Oi(t,n);i.plan.secretFindings.length>0&&$s(i.plan.secretFindings);let o=await Di(t,i.plan.manifest,i.archiveOptions);return {manifest:i.plan.manifest,tgzPath:o}}async function hp(e,n={}){return ki(e,n)}async function Ep(e,n){let t=await ki(e,n);if(t.manifest.type!=="app")throw new Error("publish: App pack unexpectedly produced a template manifest");return t}
2
+ exports.DEFAULT_PUBLISH_MAX_BYTES=xs;exports.DEFAULT_PUBLISH_MAX_FILES=ks;exports.EXCLUDE_RULES=ai;exports.MARKETPLACE_API_PREFIX=Se;exports.PublishError=te;exports.packApp=Ep;exports.packPublish=ki;exports.packTemplate=hp;exports.planPublish=mp;exports.uploadToMarketplace=Os;
@@ -140,6 +140,7 @@ export interface UiPluginManifestV2 {
140
140
  readonly surfaces: readonly UiPluginSurface[];
141
141
  readonly size: UiPluginSize;
142
142
  readonly stateProjection: UiPluginProjectionPolicy;
143
+ readonly summaryProjection?: UiPluginProjectionPolicy;
143
144
  readonly dataPaths?: readonly string[];
144
145
  readonly actions: readonly UiPluginAction[];
145
146
  readonly _meta?: JsonObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewx/sdk",
3
- "version": "0.9.0-rc.126",
3
+ "version": "0.9.0-rc.127",
4
4
  "license": "UNLICENSED",
5
5
  "engines": {
6
6
  "node": ">=20.19.0"