@crewx/sdk 0.9.0-rc.138 → 0.9.0-rc.139
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.
- package/dist/activity-log/builder.d.ts +3 -0
- package/dist/app/app.d.ts +8 -1
- package/dist/app/backend-env.d.ts +3 -0
- package/dist/app/index.d.ts +4 -2
- package/dist/app/index.js +9 -9
- package/dist/app/runtime.d.ts +7 -2
- package/dist/conversation/sqlite-provider.d.ts +0 -1
- package/dist/conversation/types.d.ts +1 -0
- package/dist/esm/app/index.js +9 -9
- package/dist/esm/index.js +280 -230
- package/dist/esm/plugins/index.js +157 -108
- package/dist/esm/publish/index.js +2 -2
- package/dist/esm/repository/index.js +174 -125
- package/dist/esm/skills/index.js +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +285 -235
- package/dist/plugins/index.js +157 -108
- package/dist/publish/index.js +2 -2
- package/dist/repository/index.d.ts +2 -2
- package/dist/repository/index.js +174 -125
- package/dist/repository/task-status.d.ts +9 -2
- package/dist/repository/task.repository.d.ts +7 -2
- package/dist/repository/thread.repository.d.ts +23 -1
- package/dist/skills/index.js +2 -2
- package/dist/types/task-log.types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import*as ee from'path';import {resolve,relative,sep,isAbsolute,join}from'path';import'url';import*as ri from'crypto';import {createHash}from'crypto';import {isIP}from'net';import*as X from'fs';import {constants,readFileSync,existsSync,statSync,readdirSync}from'fs';import {realpath,stat,readdir,open,lstat}from'fs/promises';import*as sr from'js-yaml';import {load}from'js-yaml';import*as yr from'os';import*as Ir from'tar';import {gunzipSync,gzipSync}from'zlib';var V=(e,n)=>()=>(e&&(n=e(e=0)),n);var m=V(()=>{});var R,hn=V(()=>{m();R=class extends Error{constructor(t,i=t,r){super(i);this.code=t;this.currentRevision=r;}code;currentRevision;name="UiRuntimeError"};});function Qn(e){return Lr.test(e)||Or.test(e)}function se(){throw new R("INPUT_INVALID","JSON value is not projection-safe")}function Cr(e){let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function qn(e,n,t,i,r,o){if(n>i&&se(),e===null||typeof e=="string"||typeof e=="boolean")return typeof e=="string"&&(Rr.test(e)||Ur.test(e)&&!vr(r,o)||wr.test(e))&&se(),e;if(typeof e=="number")return Number.isFinite(e)||se(),e;(typeof e!="object"||e===void 0||typeof e=="function"||typeof e=="bigint")&&se();let s=e;t.has(s)&&se(),t.add(s);try{if(Array.isArray(e))return e.map(d=>qn(d,n+1,t,i,r,o));Cr(s)||se();let a={};for(let[d,c]of Object.entries(e))Qn(d)&&se(),a[d]=qn(c,n+1,t,i,[...r,d],o);return a}finally{t.delete(s);}}function he(e,n=0,t=[]){(!Number.isInteger(n)||n<0||n>xr)&&se(),(!Array.isArray(t)||t.some(r=>typeof r!="string"))&&se();let i=qn(e,0,new Set,kr+n,[],t);return (i===null||Array.isArray(i)||typeof i!="object")&&se(),i}function He(e,n){if(!e||!n)return false;let t=e.split("."),i=n.split(".");return t.length>=i.length&&i.every((r,o)=>t[o]===r)}function vr(e,n){if(e.length===0)return false;let t=e.join(".");return n.some(i=>He(t,i))}function ze(e){try{let n=JSON.stringify(e);return n===void 0&&se(),n}catch{se();}}function Zn(e){return Array.isArray(e)?e.map(Zn):e!==null&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,Zn(e[n])])):e}function ne(e){return ze(Zn(e))}function et(e){return Buffer.byteLength(e,"utf8")}var Lr,Or,Rr,wr,Ur,kr,xr,_e=V(()=>{m();hn();Lr=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,Or=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i,Rr=/<\/?[A-Za-z][^>]*>/,wr=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,Ur=/^(?:https?|file|ftp|ws|wss):\/\//i;kr=8,xr=4;});var di=V(()=>{m();_e();});function $e(e){return jr.has(e)||Vr.test(e)||Fr.test(e)}var pi,jr,Vr,Fr,_n,tn,fe,nt,tt,it,ot,rt,Ue=V(()=>{m();pi=["__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"],jr=new Set(pi),Vr=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,Fr=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i;_n=/^[A-Za-z0-9_]+$/,tn=/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/,fe=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,nt=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,tt=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,it=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/,ot=["blue","violet","emerald","amber","rose","sky","slate","indigo"],rt=["inline","panel"];});function st(e){return typeof e=="string"&&li.includes(e)}var li,ui=V(()=>{m();Ue();li=["text/plain","application/json"];});function En(e){if(!at(e))return false;let n=Object.keys(e);return !(n.some(t=>t!=="in"&&t!=="out")||n.length===0||Object.hasOwn(e,"in")&&!Br(e.in)||Object.hasOwn(e,"out")&&!Hr(e.out))}function Br(e){return at(e)?Object.keys(e).every(t=>t==="mediaType"||t==="required")&&Object.hasOwn(e,"mediaType")&&st(e.mediaType)&&(!Object.hasOwn(e,"required")||typeof e.required=="boolean"):false}function Hr(e){return at(e)?Object.keys(e).every(t=>t==="mediaType"||t==="range")&&Object.hasOwn(e,"mediaType")&&st(e.mediaType)&&(!Object.hasOwn(e,"range")||typeof e.range=="boolean"):false}function at(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var ct=V(()=>{m();ui();new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});});function pe(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(r=>r.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=he(t);return createHash("sha256").update(ne(i)).digest("hex")}function Ee(e){if(!/^\d+$/.test(String(e.version))||e.version<1||e.id.length<1||e.id.length>128)throw new R("DEFINITION_UNSUPPORTED","UI definition is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!$r.test(e.sourceHash)))throw new R("DEFINITION_UNSUPPORTED","UI definition source hash is invalid");if(!/^[0-9a-f]{64}$/.test(e.hash)||pe(e)!==e.hash)throw new R("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=>!Wr(i)))throw new R("DEFINITION_UNSUPPORTED","UI action declaration is invalid");if(t.confirmation!==void 0&&t.confirmation!=="none"&&t.confirmation!=="native")throw new R("DEFINITION_UNSUPPORTED","UI action confirmation is invalid");if(t.inputKeys&&(!Array.isArray(t.inputKeys)||t.inputKeys.some(i=>typeof i!="string"||!i)))throw new R("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 R("DEFINITION_UNSUPPORTED","UI action data input declaration is invalid");if(t.resultProjection&&dt(t.resultProjection),t.content!==void 0&&!En(t.content))throw new R("DEFINITION_UNSUPPORTED","UI action content declaration is invalid");if(t.env!==void 0&&(!Array.isArray(t.env)||t.env.length===0||new Set(t.env).size!==t.env.length||t.env.some(i=>i!=="CREWX_APP_INSTANCE_ID"&&i!=="CREWX_THREAD_ID")))throw new R("DEFINITION_UNSUPPORTED","UI action environment declaration is invalid")}if(e.renderer!==void 0&&(!e.renderer||e.renderer.length>128))throw new R("DEFINITION_UNSUPPORTED","UI definition renderer is invalid");if(e.surfaces&&(!Array.isArray(e.surfaces)||e.surfaces.some(n=>!n||n.length>64)))throw new R("DEFINITION_UNSUPPORTED","UI definition surfaces are invalid");if(e.usage!==void 0&&e.usage!=="card"&&e.usage!=="window")throw new R("DEFINITION_UNSUPPORTED","UI definition usage is invalid");if(e.detailPanel!==void 0&&typeof e.detailPanel!="boolean")throw new R("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 R("DEFINITION_UNSUPPORTED","UI definition displayModes are invalid");if(e.usage==="card"&&e.displayModes!==void 0)throw new R("DEFINITION_UNSUPPORTED","Card definitions cannot declare displayModes");if(e.usage==="window"&&e.detailPanel!==void 0)throw new R("DEFINITION_UNSUPPORTED","Window definitions cannot declare detailPanel");if(e.stateProjection&&dt(e.stateProjection),e.summaryProjection){dt(e.summaryProjection);let n=new Set(e.stateProjection?.allow??[]);if(e.summaryProjection.allow.some(t=>!n.has(t)))throw new R("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(r=>!["readTool","actionTool","hostTools","agentAccess"].includes(r)))throw new R("DEFINITION_UNSUPPORTED","UI legacy metadata is invalid");let n=new Set;for(let[r,o]of [["readTool",e.legacy.readTool],["actionTool",e.legacy.actionTool]])if(o!==void 0){if(Gr(o,r==="readTool"),n.has(o.name))throw new R("DEFINITION_UNSUPPORTED","UI legacy tool names collide");n.add(o.name);}let t=e.legacy.hostTools;if(t!==void 0){if(!t||typeof t!="object"||Array.isArray(t))throw new R("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");let r={"doc.open":"crewx_app_html_viewer_open","pty.connect":"crewx_app_terminal_connect"};for(let[o,s]of Object.entries(t)){if(!Object.hasOwn(r,o)||r[o]!==s||typeof s!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(s)||n.has(s))throw new R("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(([r,o])=>!r||!Object.hasOwn(e.actions,r)||o!=="allowed"&&o!=="denied")))throw new R("DEFINITION_UNSUPPORTED","UI legacy agent access is invalid");if(e.legacy.actionTool!==void 0&&(!i||Object.keys(i).length===0))throw new R("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=>He(t,i))))throw new R("DEFINITION_UNSUPPORTED","UI definition dataPaths are invalid")}}function Gr(e,n){if(!e||typeof e!="object"||Array.isArray(e))throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");let t=e,i=["name","description","inputSchema","textFallback","visibility"],r=Object.hasOwn(t,"fixedResult");if(Object.keys(t).some(o=>!i.includes(o)&&!(n&&o==="fixedResult"))||i.some(o=>!Object.hasOwn(t,o))||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(o=>o!=="model"&&o!=="app")||new Set(t.visibility).size!==t.visibility.length)throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");try{let o=he(t.inputSchema);if(o.type!==void 0&&o.type!=="object")throw new Error("schema type");if(r){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 d=he(a.structuredContent);if(et(ze(d))>4*1024)throw new Error("fixed result size")}}catch{throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is not projection-safe")}}function dt(e){if(!Array.isArray(e.allow)||e.allow.some(n=>!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(n)))throw new R("DEFINITION_UNSUPPORTED","UI projection policy is invalid")}function Wr(e){return e.length>0&&e.length<=128&&e!=="*"&&e!=="all"&&!/[/*]/.test(e)}var $r,Ce=V(()=>{m();_e();hn();ct();$r=/^[0-9a-f]{64}$/;});var Oe,pt=V(()=>{m();Oe="window";});function F(e){throw new lt(e)}function os(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 rs(e,n){let t=Object.getOwnPropertyDescriptor(e,n);return (!t||!("value"in t))&&F("CSP_ORIGIN_INVALID"),t.value}function Tn(e,n){if(!Object.prototype.hasOwnProperty.call(e,n))return [];let t=rs(e,n);Array.isArray(t)||F("CSP_ORIGIN_INVALID"),Reflect.ownKeys(t).some(o=>typeof o!="string"||o!=="length"&&!/^(?:0|[1-9][0-9]*)$/.test(o))&&F("CSP_ORIGIN_INVALID");let r=[];for(let o=0;o<t.length;o+=1)(!Object.prototype.hasOwnProperty.call(t,o)||typeof t[o]!="string")&&F("CSP_ORIGIN_INVALID"),r.push(t[o]);return Object.keys(t).length!==t.length&&F("CSP_ORIGIN_INVALID"),r}function ss(e){let n;try{n=JSON.stringify(e);}catch{F("CSP_ORIGIN_INVALID");}return n===void 0&&F("CSP_ORIGIN_INVALID"),new TextEncoder().encode(n).byteLength}function Ai(e,n){/\s|\\/u.test(e)&&F("CSP_ORIGIN_INVALID");let t=Qr.exec(e);t||F("CSP_ORIGIN_INVALID");let i=t[1].toLowerCase(),r=t[2];(r.includes("@")||r.includes("%")||r.includes("*"))&&F("CSP_ORIGIN_INVALID"),(r.startsWith("[")?es:ns).test(r)||F("CSP_ORIGIN_INVALID"),i==="wss"&&n!=="connectDomains"&&F("CSP_ORIGIN_INVALID");let s;try{s=new URL(e);}catch{F("CSP_ORIGIN_INVALID");}(s.protocol!==`${i}:`||s.username!==""||s.password!==""||s.search!==""||s.hash!=="")&&F("CSP_ORIGIN_INVALID");let a=s.hostname.toLowerCase();if((!a||a.includes("%"))&&F("CSP_ORIGIN_INVALID"),!a.startsWith("[")){let c=a.endsWith(".")?a.slice(0,-1):a;(c.length===0||c.length>253)&&F("CSP_ORIGIN_INVALID"),c.split(".").some(y=>y.length>63||!ts.test(y))&&F("CSP_ORIGIN_INVALID");}let d=s.origin;return (d==="null"||!d.startsWith(`${i}://`))&&F("CSP_ORIGIN_INVALID"),{origin:d,hostname:a}}function as(e){let n=e.split(".").map(Number);return ((n[0]*256+n[1])*256+n[2])*256+n[3]}function Ii(e,n,t){let i=4294967295<<32-t>>>0;return (e&i)===(n&i)}function hi(e){let n=as(e);return Ii(n,3221225472,24)?n!==3221225481&&n!==3221225482:is.some(([t,i])=>Ii(n,t,i))}function cs(e){let n=e.indexOf("::"),t=(n<0?e:e.slice(0,n)).split(":").filter(Boolean),i=n<0?[]:e.slice(n+2).split(":").filter(Boolean);return (n<0?t:[...t,...Array(8-t.length-i.length).fill("0"),...i]).reduce((o,s)=>o<<16n|BigInt(Number.parseInt(s,16)),0n)}function ds(e){let n=cs(e),t=Number(n>>112n),i=Number(n>>96n&0xffffn);if(n>>32n===0xffffn){let r=Number(n&0xffffffffn);return hi([r>>>24&255,r>>>16&255,r>>>8&255,r&255].join("."))}return t<8192||t>16383||t===8193&&i<=511||t===8193&&i===3512||t===8194||t===16383&&i<=4095}function ps(e,n){let t=e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e,i=isIP(t);if(i===4)return hi(t);if(i===6)return ds(t);let r=e.toLowerCase().replace(/\.$/,"");return !r||!r.includes(".")||n.has(r)?true:Zr.some(o=>r===o||r.endsWith(`.${o}`))}function gi(e){return Object.freeze([...new Set(e.map(n=>n.origin))].sort())}function mi(e){return JSON.stringify({baseUriDomains:[],connectDomains:e.connectDomains,declared:e.declared,frameDomains:e.frameDomains,resourceDomains:[]})}function _i(e,n={}){if(e===void 0){let I=mi({declared:false,connectDomains:[],frameDomains:[]});return Object.freeze({declared:false,connectDomains:Object.freeze([]),frameDomains:Object.freeze([]),resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:createHash("sha256").update(I,"utf8").digest("hex")})}os(e)||F("CSP_ORIGIN_INVALID");let t=Reflect.ownKeys(e);t.some(I=>typeof I!="string")&&F("CSP_ORIGIN_INVALID"),t.some(I=>!qr.has(I))&&F("CSP_AXIS_UNKNOWN");let i=Tn(e,"connectDomains"),r=Tn(e,"frameDomains"),o=Tn(e,"resourceDomains"),s=Tn(e,"baseUriDomains");(o.length>0||s.length>0)&&F("CSP_AXIS_UNSUPPORTED"),(ss(e)>Kr||i.length>yi||r.length>yi||i.length+r.length>Xr||[...i,...r].some(I=>new TextEncoder().encode(I).byteLength>Yr))&&F("CSP_LIMIT_EXCEEDED");let d=i.map(I=>Ai(I,"connectDomains")),c=r.map(I=>Ai(I,"frameDomains")),p=new Set((n.runtimeHostnames??[]).map(I=>I.toLowerCase().replace(/\.$/,"")));[...d,...c].some(I=>ps(I.hostname,p))&&F("CSP_ORIGIN_FORBIDDEN");let y={declared:true,connectDomains:gi(d),frameDomains:gi(c)},A=mi(y);return Object.freeze({...y,resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:createHash("sha256").update(A,"utf8").digest("hex")})}var Kr,yi,Xr,Yr,qr,Zr,Qr,es,ns,ts,is,lt,Ei=V(()=>{m();Kr=4096,yi=16,Xr=32,Yr=512,qr=new Set(["connectDomains","frameDomains","resourceDomains","baseUriDomains"]),Zr=["localhost","local","internal","home.arpa","test","example","invalid","onion","lan","corp","home","intranet","private","localdomain"],Qr=/^(https|wss):\/\/([^/?#]+)$/i,es=/^\[[^\]]+\](?::[0-9]+)?$/,ns=/^[^:\[\]]+(?::[0-9]+)?$/,ts=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/,is=[[0,8],[1681915904,10],[167772160,8],[2130706432,8],[2851995648,16],[2886729728,12],[3221225984,24],[3227017984,24],[3232235520,16],[3323068416,15],[3325256704,24],[3405803776,24],[3758096384,4],[4026531840,4]],lt=class extends Error{constructor(t){super(t);this.code=t;}code;name="UiPluginCspNormalizationError"};});function rn(e,n){return n===void 0||n===""?e:e===""?n:n.startsWith("[")?`${e}${n}`:`${e}.${n}`}function l(e,n=e,t,i){throw new Q(e,n,t,i)}function z(e,n){try{return n()}catch(t){throw t instanceof Q?t.withPathPrefix(e):t}}function $(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 U(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function vs(e,n){let t={};for(let[i,r]of Object.entries(e))i!==n&&(t[i]=r);return t}function G(e,n,t=[]){let i=new Set([...n,...t]),r=Object.keys(e).find(s=>!i.has(s));r!==void 0&&l("MANIFEST_INVALID","MANIFEST_INVALID",r,"unknown-key");let o=n.find(s=>!U(e,s));o!==void 0&&l("MANIFEST_INVALID","MANIFEST_INVALID",o,"missing-key");}function Nn(e,n=false,t=false,i=false){return ys.test(e)||!i&&Is.test(e)||As.test(e)||t&&Ti.test(e)||gs.test(e)&&!(n&&/^\s*data:/i.test(e)&&!Ti.test(e))}function bn(e,n=new Set,t=0,i=false,r=false,o=""){if(typeof e=="string"){Nn(e,i,r)&&l("UNSAFE_VALUE","UNSAFE_VALUE",o,"unsafe-value");return}if(!(e===null||typeof e!="object")){(t>8||n.has(e))&&l("MANIFEST_INVALID","MANIFEST_INVALID",o),n.add(e);try{if(Array.isArray(e)){e.forEach((s,a)=>bn(s,n,t+1,!1,!1,rn(o,`[${a}]`)));return}$(e)||l("MANIFEST_INVALID","MANIFEST_INVALID",o);for(let[s,a]of Object.entries(e))bn(a,n,t+1,i&&t===0&&(s==="name"||s==="description"),r,rn(o,s));}finally{n.delete(e);}}}function ye(e,n){let t=e[n];return typeof t!="string"&&l("MANIFEST_INVALID"),t}function le(e,n,t){let i=e[n];return (!Number.isSafeInteger(i)||i<t)&&l("MANIFEST_INVALID"),i}function ut(e){return fs.test(e)||l("MANIFEST_INVALID"),e}function Ge(e){return us.test(e)||l("TOKEN_INVALID"),e}function js(e){return Ri.test(e)||l("MANIFEST_INVALID"),e}function Vs(e){$(e)||l("MANIFEST_INVALID");let n={};for(let[t,i]of Object.entries(e)){let r=js(t);$(i)||l("MANIFEST_INVALID");let o=i.type;if(o==="text"){G(i,["type","maxLength"]),n[r]={type:o,maxLength:le(i,"maxLength",1)};continue}if(o==="text-list"){G(i,["type","max","itemMaxLength"]),n[r]={type:o,max:le(i,"max",0),itemMaxLength:le(i,"itemMaxLength",1)};continue}if(o==="step-list"){G(i,["type","min","max","labelMaxLength","detailMaxLength"]);let s=le(i,"min",0),a=le(i,"max",1);s>a&&l("MANIFEST_INVALID"),n[r]={type:o,min:s,max:a,labelMaxLength:le(i,"labelMaxLength",1),detailMaxLength:le(i,"detailMaxLength",1)};continue}typeof o=="string"&&l("SCHEMA_TYPE_UNSUPPORTED"),l("MANIFEST_INVALID");}return n}function Fs(e,n,t){let i=e[n];(!i||i.type!==t)&&l("MANIFEST_INVALID");}function Pn(e,n,t){let i=ye(e,"field");return Ri.test(i)||l("MANIFEST_INVALID"),Fs(n,i,t),i}function Bs(e,n){$(e)||l("MANIFEST_INVALID");let t=e.primitive;switch(typeof t!="string"&&l("MANIFEST_INVALID"),xs.includes(t)||l("PRIMITIVE_UNKNOWN"),t){case "card-shell":return G(e,["primitive"]),{primitive:t};case "meta-banner":return G(e,["primitive","badgeToken","noticeToken"]),{primitive:t,badgeToken:Ge(ye(e,"badgeToken")),noticeToken:Ge(ye(e,"noticeToken"))};case "heading":return G(e,["primitive","field"]),{primitive:t,field:Pn(e,n,"text")};case "labeled-text":return G(e,["primitive","titleToken","field","variant"]),e.variant!=="callout"&&l("MANIFEST_INVALID"),{primitive:t,titleToken:Ge(ye(e,"titleToken")),field:Pn(e,n,"text"),variant:"callout"};case "step-flow":return G(e,["primitive","titleToken","field"]),{primitive:t,titleToken:Ge(ye(e,"titleToken")),field:Pn(e,n,"step-list")};case "text-list":{G(e,["primitive","titleToken","field"],["emptyToken","hideWhenEmpty"]);let i={primitive:t,titleToken:Ge(ye(e,"titleToken")),field:Pn(e,n,"text-list")};return U(e,"emptyToken")&&(i.emptyToken=Ge(ye(e,"emptyToken"))),U(e,"hideWhenEmpty")&&(typeof e.hideWhenEmpty!="boolean"&&l("MANIFEST_INVALID"),i.hideWhenEmpty=e.hideWhenEmpty),i}}return l("MANIFEST_INVALID")}function Hs(e,n){return Array.isArray(e)||l("MANIFEST_INVALID"),e.map(t=>Bs(t,n))}function W(e="v2 manifest exceeds a contract limit",n,t){return l("LIMIT_EXCEEDED",e,n,t)}function ae(e="initial state is not projection-safe"){return l("INITIAL_STATE_INVALID",e)}function Pi(e,n){return (typeof e!="string"||e.length===0||e.length>4096||e.trim().length===0||Us.test(e)||Cs.test(e))&&l("MANIFEST_INVALID",`${n} is invalid`),(Nn(e,true,true)||ms.test(e)||hs.test(e)||_s.test(e))&&l("UNSAFE_VALUE",`${n} contains an unsafe value`),e}function ft(e,n){return (typeof e!="string"||!fe.test(e))&&l("MANIFEST_INVALID",`${n} is invalid`),e}function zs(e){return (typeof e!="string"||!nt.test(e)||e==="*"||e==="all")&&l("MANIFEST_INVALID","action capability is invalid"),e}function wi(e){return (typeof e!="string"||!ws.test(e))&&l("MANIFEST_INVALID","resource hash is invalid"),e}function yt(e,n=new Set,t=0,i=""){if(typeof e=="string"){e.length>4096&&W("v2 manifest string is too long",i,"string-too-long");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||l("MANIFEST_INVALID","v2 manifest contains a non-finite number",i,"non-finite-number");return}(e===void 0||typeof e=="function"||typeof e=="bigint")&&l("MANIFEST_INVALID","v2 manifest contains a non-JSON value",i,"non-json-value"),typeof e!="object"&&l("MANIFEST_INVALID","MANIFEST_INVALID",i),t>8&&W("v2 manifest nesting is too deep",i,"too-deep"),n.has(e)&&l("MANIFEST_INVALID","v2 manifest contains a cycle",i,"cycle"),n.add(e);try{if(Array.isArray(e)){e.length>128&&W("v2 manifest array is too long",i,"array-too-long"),e.forEach((r,o)=>yt(r,n,t+1,rn(i,`[${o}]`)));return}$(e)||l("MANIFEST_INVALID","v2 manifest contains a non-plain object",i,"non-plain-object");for(let[r,o]of Object.entries(e))yt(o,n,t+1,rn(i,r));}finally{n.delete(e);}}}function Ui(e){return (typeof e!="string"||e.length>4096||!tn.test(e))&&(typeof e=="string"&&e.length>4096&&W("projection path is too long"),l("MANIFEST_INVALID","projection paths must be canonical exact paths")),e.split(".").some(t=>$e(t))&&l("MANIFEST_INVALID","projection paths cannot address reserved state keys"),e}function At(e){$(e)||l("MANIFEST_INVALID","projection policy must be an object"),G(e,["allow"]),Array.isArray(e.allow)||l("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 r=Ui(i);t.has(r)&&l("MANIFEST_INVALID","projection allowlist contains a duplicate path"),t.add(r),n.push(r);}return {allow:n}}function $s(e,n){if(e===void 0)return;Array.isArray(e)||l("MANIFEST_INVALID","dataPaths must be an array"),e.length>ks&&W("dataPaths exceed the v2 limit");let t=[],i=new Set;for(let r of e){let o=Ui(r);i.has(o)&&l("MANIFEST_INVALID","dataPaths contain a duplicate path"),n.some(s=>He(o,s))||l("MANIFEST_INVALID","dataPaths must be projection-allowed"),i.add(o),t.push(o);}return t}function We(e,n,t=Number.MAX_SAFE_INTEGER){return (!Number.isSafeInteger(e)||e<0||e>t)&&l("MANIFEST_INVALID",`${n} is invalid`),e}function Di(e,n){return (typeof e!="number"||!Number.isFinite(e))&&l("MANIFEST_INVALID",`${n} is invalid`),e}function It(e,n=0,t=new Set){if(typeof e=="string")return (e.length>4096||Nn(e))&&l("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)||l("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)&&l("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(r=>It(r,n+1,t));$(e)||l("MANIFEST_INVALID","schema enum contains a non-plain object");let i={};for(let[r,o]of Object.entries(e))$e(r)&&l("MANIFEST_INVALID","schema enum contains a reserved key"),i[r]=It(o,n+1,t);return i}finally{t.delete(e);}}function Gs(e,n){if(e===void 0)return;Array.isArray(e)||l("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 r of e)(typeof r!="string"||!tn.test(r))&&l("MANIFEST_INVALID","schema required contains an invalid key"),r.length>4096&&W("schema required key is too long"),i.has(r)&&l("MANIFEST_INVALID","schema required contains a duplicate key"),n&&!Object.prototype.hasOwnProperty.call(n,r)&&l("MANIFEST_INVALID","schema required references an undeclared property"),i.add(r),t.push(r);return t}function Ws(e,n){let t=n?tn:_n;return e.length>4096&&W("schema property name is too long"),(!t.test(e)||e.split(".").some(i=>$e(i)))&&l("MANIFEST_INVALID","schema property name is invalid"),e}function gt(e,n=0,t=false){$(e)||l("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"&&l("SCHEMA_TYPE_UNSUPPORTED","action inputSchema type is unsupported"),l("MANIFEST_INVALID","action inputSchema type is required"));let r=["type","enum"];i==="string"&&r.push("minLength","maxLength"),i==="array"&&r.push("minItems","maxItems","items"),i==="object"&&r.push("minProperties","maxProperties","properties","required","additionalProperties"),(i==="number"||i==="integer")&&r.push("minimum","maximum"),G(e,["type"],r.filter(a=>a!=="type"));let o={type:i};if(U(e,"enum")&&(Array.isArray(e.enum)||l("MANIFEST_INVALID","schema enum must be an array"),e.enum.length>128&&W("schema enum is too long"),o.enum=e.enum.map(a=>It(a))),i==="string"&&(U(e,"minLength")&&(o.minLength=We(e.minLength,"schema minLength",4096)),U(e,"maxLength")&&(o.maxLength=We(e.maxLength,"schema maxLength",4096)),o.minLength!==void 0&&o.maxLength!==void 0&&o.minLength>o.maxLength&&l("MANIFEST_INVALID","schema string length bounds are inverted")),(i==="number"||i==="integer")&&(U(e,"minimum")&&(o.minimum=Di(e.minimum,"schema minimum")),U(e,"maximum")&&(o.maximum=Di(e.maximum,"schema maximum")),o.minimum!==void 0&&o.maximum!==void 0&&o.minimum>o.maximum&&l("MANIFEST_INVALID","schema numeric bounds are inverted")),i==="array"&&(U(e,"minItems")&&(o.minItems=We(e.minItems,"schema minItems",128)),U(e,"maxItems")&&(o.maxItems=We(e.maxItems,"schema maxItems",128)),o.minItems!==void 0&&o.maxItems!==void 0&&o.minItems>o.maxItems&&l("MANIFEST_INVALID","schema array length bounds are inverted"),U(e,"items")&&(o.items=gt(e.items,n+1,false))),i==="object"){let a;if(U(e,"properties")){$(e.properties)||l("MANIFEST_INVALID","schema properties must be an object");let c=Object.entries(e.properties);c.length>64&&W("schema properties are too many"),a={};for(let[p,y]of c){let A=Ws(p,t);a[A]=gt(y,n+1,false);}o.properties=a;}U(e,"minProperties")&&(o.minProperties=We(e.minProperties,"schema minProperties",64)),U(e,"maxProperties")&&(o.maxProperties=We(e.maxProperties,"schema maxProperties",64)),o.minProperties!==void 0&&o.maxProperties!==void 0&&o.minProperties>o.maxProperties&&l("MANIFEST_INVALID","schema object property bounds are inverted");let d=Gs(e.required,a);d!==void 0&&(o.required=d),U(e,"additionalProperties")&&(e.additionalProperties!==false&&l("MANIFEST_INVALID","schema additionalProperties must be false"),o.additionalProperties=false);}let s=JSON.stringify(o);return (s===void 0||Buffer.byteLength(s,"utf8")>65536)&&W("action inputSchema subtree is too large"),o}function Js(e){let n=gt(e,0,true);return (n.type!=="object"||!n.properties)&&l("MANIFEST_INVALID","action inputSchema must declare object properties"),n}function Ks(e){if($(e)||l("MANIFEST_INVALID","action backend must be an object"),e.type==="core"){G(e,Ss);let n=e.handler;return (typeof n!="string"||!tt.test(n))&&l("MANIFEST_INVALID","core backend handler is invalid"),{type:"core",handler:n}}if(e.type==="skill"){G(e,Ms,Ls),(!Array.isArray(e.command)||e.command.length===0||e.command.length>16)&&l("MANIFEST_INVALID","skill backend command is invalid");let n=[];for(let i of e.command)(typeof i!="string"||i.length===0||i.length>256||!it.test(i))&&l("MANIFEST_INVALID","skill backend command token is invalid"),n.push(i);let t=U(e,"env")?Ys(e.env):void 0;return {type:"skill",command:n,...t===void 0?{}:{env:t}}}l("MANIFEST_INVALID","action backend type is unsupported");}function Xs(e){$(e)||l("MANIFEST_INVALID","action must be an object"),G(e,Ds,bs),U(e,"_meta")&&z("_meta",()=>Ci(e._meta));let n=z("actionId",()=>ft(e.actionId,"actionId"));Qn(n)&&l("MANIFEST_INVALID",`actionId "${n}" is not projection-safe`,"actionId");let t=z("capability",()=>zs(e.capability)),i=e.mutation;typeof i!="boolean"&&l("MANIFEST_INVALID","action mutation must be boolean","mutation");let r=z("inputSchema",()=>Js(e.inputSchema)),o;if(U(e,"dataInputs")){Array.isArray(e.dataInputs)||l("MANIFEST_INVALID","action dataInputs must be an array","dataInputs");let p=r.properties,y=new Set,A=[];for(let I of e.dataInputs)(typeof I!="string"||!U(p,I)||y.has(I))&&l("MANIFEST_INVALID","action dataInputs must be unique declared properties","dataInputs"),y.add(I),A.push(I);o=A;}let s=z("resultProjection",()=>At(e.resultProjection)),a=z("backend",()=>Ks(e.backend)),d;U(e,"content")&&((a.type!=="skill"||!En(e.content))&&l("MANIFEST_INVALID","action content declaration is invalid","content"),d=qs(e.content));let c;if(U(e,"confirmation")){let p=e.confirmation;p!=="none"&&p!=="native"&&l("MANIFEST_INVALID","action confirmation is invalid","confirmation"),c=p;}return {actionId:n,capability:t,mutation:i,inputSchema:r,resultProjection:s,backend:a,...d===void 0?{}:{content:d},...o===void 0?{}:{dataInputs:o},...c===void 0?{}:{confirmation:c}}}function Ys(e){(!Array.isArray(e)||e.length===0)&&l("MANIFEST_INVALID","skill backend env is invalid");let n=new Set,t=[];for(let i of e)(i!=="CREWX_APP_INSTANCE_ID"&&i!=="CREWX_THREAD_ID"||n.has(i))&&l("MANIFEST_INVALID","skill backend env is invalid"),n.add(i),t.push(i);return Object.freeze(t)}function qs(e){return Object.freeze({...e.in===void 0?{}:{in:Object.freeze({...e.in})},...e.out===void 0?{}:{out:Object.freeze({...e.out})}})}function Zs(e){return $(e)||l("INITIAL_STATE_INVALID","initialState must be an object"),G(e,Os,Rs),e.path!=="ui/state.json"&&l("MANIFEST_INVALID","initialState path is not fixed"),U(e,"hash")?{path:"ui/state.json",hash:wi(e.hash)}:{path:"ui/state.json"}}function Qs(e){let n=["wasm","terminal","htmlDocuments"];return (!$(e)||Object.keys(e).length===0||Object.keys(e).some(t=>!n.includes(t)||e[t]!==true))&&l("MANIFEST_INVALID","runtime must contain only known capability flags set to true"),{...e.wasm===true?{wasm:true}:{},...e.terminal===true?{terminal:true}:{},...e.htmlDocuments===true?{htmlDocuments:true}:{}}}function ea(e,n){let t;try{t=_i(e);}catch(i){let r=i!==null&&typeof i=="object"&&"code"in i&&typeof i.code=="string"?i.code:"CSP_ORIGIN_INVALID";return l("MANIFEST_INVALID",r,void 0,r.toLowerCase().replace(/_/g,"-"))}if(t.frameDomains.length>0&&l("MANIFEST_INVALID","external origins in csp are not enabled in this rollout",void 0,"csp-not-enabled"),t.connectDomains.length!==0)return n?.terminal===true&&l("MANIFEST_INVALID","runtime.terminal cannot be combined with csp.connectDomains","connectDomains","terminal-with-connect-domains"),Object.freeze({connectDomains:t.connectDomains})}function na(e,n){bn($(e)&&U(e,"csp")?vs(e,"csp"):e,new Set,0,true,true),yt(e),$(e)||l("MANIFEST_INVALID"),G(e,Ts,Ps),U(e,"_meta")&&z("_meta",()=>Ci(e._meta)),e.manifestVersion!==2&&l("MANIFEST_INVALID");let t;U(e,"runtime")&&(t=z("runtime",()=>Qs(e.runtime)));let i;U(e,"csp")&&(i=z("csp",()=>ea(e.csp,t)));let r=z("pluginId",()=>ft(e.pluginId,"pluginId")),o=z("definitionId",()=>ft(e.definitionId,"definitionId")),s=z("version",()=>le(e,"version",1)),a=z("name",()=>Pi(e.name,"name")),d=z("description",()=>Pi(e.description,"description")),c;U(e,"icon")&&((typeof e.icon!="string"||!/^[a-z][a-z0-9-]{0,63}$/.test(e.icon))&&l("MANIFEST_INVALID","icon is invalid","icon"),c=e.icon);let p;U(e,"tone")&&((typeof e.tone!="string"||!ot.includes(e.tone))&&l("MANIFEST_INVALID","tone is invalid","tone"),p=e.tone),e.entry!=="ui/index.html"&&l("MANIFEST_INVALID","entry path is not fixed","entry","fixed-value");let y;U(e,"entryHash")&&(y=z("entryHash",()=>wi(e.entryHash)));let A;U(e,"initialState")&&(A=z("initialState",()=>Zs(e.initialState)));let I;U(e,"usage")&&(e.usage!=="card"&&e.usage!=="window"&&l("MANIFEST_INVALID","usage is invalid","usage"),I=e.usage);let E;U(e,"detailPanel")&&(typeof e.detailPanel!="boolean"&&l("MANIFEST_INVALID","detailPanel is invalid","detailPanel"),E=e.detailPanel);let O;if(U(e,"displayModes")){((I??Oe)!==Oe||!Array.isArray(e.displayModes)||e.displayModes.length===0)&&l("MANIFEST_INVALID","displayModes are only valid for window Apps","displayModes");let u=new Set(["inline","floating","focused"]);(new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(f=>typeof f!="string"||!u.has(f)))&&l("MANIFEST_INVALID","displayModes are invalid","displayModes"),O=e.displayModes;}(I??Oe)===Oe&&E!==void 0&&l("MANIFEST_INVALID","detailPanel is card-only","detailPanel");let b=n.mode??"local";b!=="local"&&b!=="installed"&&b!=="published"&&l("MANIFEST_INVALID","manifest mode is invalid"),b!=="local"&&y===void 0&&l("MANIFEST_INVALID","installed manifests require entryHash","entryHash","required-when-installed"),b!=="local"&&A!==void 0&&A.hash===void 0&&l("MANIFEST_INVALID","installed manifests require initialState.hash","initialState.hash","required-when-installed"),(!Array.isArray(e.surfaces)||e.surfaces.length===0)&&l("MANIFEST_INVALID","surfaces are invalid","surfaces"),e.surfaces.length>2&&W("surfaces exceed the v2 limit","surfaces","too-many-items");let j=[],C=new Set;for(let u of e.surfaces)(typeof u!="string"||!rt.includes(u))&&l("MANIFEST_INVALID","surface is unsupported","surfaces"),C.has(u)&&l("MANIFEST_INVALID","surfaces contain a duplicate","surfaces","duplicate-item"),C.add(u),j.push(u);$(e.size)||l("MANIFEST_INVALID","size must be an object","size"),z("size",()=>G(e.size,["height"]));let x=z("size",()=>le(e.size,"height",1));x>720&&W("size.height exceeds the v2 limit","size.height","too-large");let B=z("stateProjection",()=>At(e.stateProjection)),_=e.summaryProjection===void 0?void 0:z("summaryProjection",()=>At(e.summaryProjection));_!==void 0&&_.allow.some(u=>!B.allow.includes(u))&&l("MANIFEST_INVALID","summaryProjection must be a subset of stateProjection.allow","summaryProjection");let h=z("dataPaths",()=>$s(e.dataPaths,B.allow));Array.isArray(e.actions)||l("MANIFEST_INVALID","actions must be an array","actions"),e.actions.length>32&&W("actions exceed the v2 limit","actions","too-many-items");let S=[],w=new Set;for(let[u,f]of e.actions.entries()){let g=`actions[${u}]`,P=z(g,()=>Xs(f));if(w.has(P.actionId)&&l("MANIFEST_INVALID","actions contain a duplicate actionId",`${g}.actionId`,"duplicate-item"),P.backend.type==="core"&&P.backend.handler==="state.set"){P.mutation||l("MANIFEST_INVALID","state.set actions must be mutations",`${g}.mutation`);for(let N of Object.keys(P.inputSchema.properties))B.allow.includes(N)||l("MANIFEST_INVALID","state.set input paths must be projection-allowed",`${g}.inputSchema.properties`);}w.add(P.actionId),S.push(P);}return {manifestVersion:2,pluginId:r,definitionId:o,version:s,name:a,description:d,...c===void 0?{}:{icon:c},...p===void 0?{}:{tone:p},entry:"ui/index.html",...y===void 0?{}:{entryHash:y},...t===void 0?{}:{runtime:t},...i===void 0?{}:{csp:i},...A===void 0?{}:{initialState:A},...I===void 0?{}:{usage:I},...E===void 0?{}:{detailPanel:E},...O===void 0?{}:{displayModes:O},surfaces:j,size:{height:x},stateProjection:B,..._===void 0?{}:{summaryProjection:_},...h===void 0?{}:{dataPaths:h},actions:S}}function Ci(e){$(e)||l("MANIFEST_INVALID","_meta must be an object");let n=JSON.stringify(e);(n===void 0||Buffer.byteLength(n,"utf8")>Ns)&&W("_meta exceeds the 4 KiB limit",void 0,"meta-too-large");}function ta(e){let n={},t={};for(let o of e.actions){n[o.actionId]={capabilities:[o.capability],inputKeys:Object.keys(o.inputSchema.properties??{}),...o.dataInputs===void 0?{}:{dataInputs:o.dataInputs},resultProjection:o.resultProjection,...o.confirmation===void 0?{}:{confirmation:o.confirmation},...o.content===void 0?{}:{content:o.content},...o.backend.type!=="skill"||o.backend.env===void 0?{}:{env:o.backend.env}};let s=o.backend.type==="skill"||o.backend.type==="core"&&o.backend.handler==="state.set";t[o.actionId]={actionId:o.actionId,mutation:o.mutation,backend:o.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},r={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:r}}function mt(e,n,t,i,r,o){if(typeof e=="string"){let s=r.length>0&&o.some(a=>He(r.join("."),a));return (e.length>4096||Nn(e,false,false,s))&&ae("state contains an unsafe string"),e}if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||ae("state contains a non-finite number"),e;(e===void 0||typeof e!="object"||typeof e=="function"||typeof e=="bigint")&&ae("state contains a non-JSON value"),t>8&&ae("state is too deep"),n.has(e)&&ae("state contains a cycle"),n.add(e);try{let s;if(Array.isArray(e))e.length>128&&ae("state array is too long"),s=e.map(d=>mt(d,n,t+1,65536,r,o));else {$(e)||ae("state contains a non-plain object");let d={};for(let[c,p]of Object.entries(e))(c.length>4096||!_n.test(c)||$e(c))&&(c.length>4096&&ae("state key is too long"),ae("state contains a reserved or invalid key")),d[c]=mt(p,n,t+1,65536,[...r,c],o);s=d;}let a=JSON.stringify(s);return (a===void 0||Buffer.byteLength(a,"utf8")>i)&&ae("state subtree is too large"),s}finally{n.delete(e);}}function _t(e,n=[]){$(e)||ae("initial state must be a JSON object");let t=mt(e,new Set,0,65536,[],n);return (t===null||Array.isArray(t)||typeof t!="object")&&ae(),t}function ia(e,n={}){bn(e),$(e)||l("MANIFEST_INVALID"),G(e,Es),e.manifestVersion!==1&&l("MANIFEST_INVALID");let t=ut(ye(e,"pluginId")),i=ut(ye(e,"definitionId")),r=le(e,"version",1),o=le(e,"primitiveSet",1),s=n.supportedPrimitiveSet??ls;(!Number.isSafeInteger(s)||s<1)&&l("MANIFEST_INVALID"),o>s&&l("PRIMITIVE_SET_UNSUPPORTED"),$(e.activation)||l("MANIFEST_INVALID"),G(e.activation,["kind","language"]),e.activation.kind!=="fenced-code"&&l("MANIFEST_INVALID");let a=ut(ye(e.activation,"language")),d=Vs(e.schema),c=Hs(e.layout,d);return {manifestVersion:1,pluginId:t,definitionId:i,version:r,primitiveSet:o,activation:{kind:"fenced-code",language:a},schema:d,layout:c}}function oa(e,n={}){return $(e)||l("MANIFEST_INVALID"),Object.hasOwn(e,"lineage")&&l("MANIFEST_INVALID","lineage is only allowed in product bundle indexes"),e.manifestVersion===2?na(e,n):ia(e,n)}function xe(e,n={}){try{return oa(e,n)}catch(t){if(t instanceof Q)throw t;return l("MANIFEST_INVALID")}}function sn(e,n={}){let t=xe(e,n);return t.manifestVersion===2?ta(t):t}var ls,us,fs,Ri,ys,As,Is,gs,Ti,ms,hs,_s,Es,Ts,Ps,Ds,bs,Ns,Ss,Ms,Ls,Os,Rs,ws,Us,Cs,ks,xs,Q,Et=V(()=>{m();pt();_e();ct();Ei();Ue();ls=1,us=/^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$/,fs=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,Ri=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,ys=/<\/?[A-Za-z][^>]*>/,As=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,Is=/^(?:https?|file|ftp|ws|wss):\/\//i,gs=/^\s*(?:javascript|data):/i,Ti=/data:[^,\s]*,/i,ms=/(?:https?|file|ftp|ws|wss):\/\//i,hs=/javascript:/i,_s=/(?:^[\s]*|[\s"'(=])(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)(?=[^\s"'<>])[^\s"'<>]*/,Es=["manifestVersion","pluginId","definitionId","version","primitiveSet","activation","schema","layout"],Ts=["manifestVersion","pluginId","definitionId","version","name","description","entry","surfaces","size","stateProjection","actions"],Ps=["_meta","icon","tone","entryHash","runtime","csp","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths"],Ds=["actionId","capability","mutation","inputSchema","resultProjection","backend"],bs=["confirmation","dataInputs","content","_meta"],Ns=4*1024,Ss=["type","handler"],Ms=["type","command"],Ls=["env"],Os=["path"],Rs=["hash"],ws=/^[0-9a-f]{64}$/,Us=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/,Cs=/[\r\n]/,ks=16,xs=["card-shell","meta-banner","heading","labeled-text","step-flow","text-list"],Q=class e extends Error{constructor(t,i=t,r,o){super(i);this.code=t;this.path=r;this.rule=o;}code;path;rule;name="UiPluginValidationError";withPathPrefix(t){return new e(this.code,this.message,rn(t,this.path),this.rule)}};});function ji(e){return typeof e=="string"&&e.length<=sa&&ra.test(e)}function k(e,n,t,i,r){throw new Ae(e,{path:n,rule:t,...i===void 0?{}:{message:i},...r===void 0?{}:{file:r}})}function ce(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 te(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Pe(e){let n=`_meta["${Re}"]`;return e===void 0||e===""?n:e.startsWith("[")?`${n}${e}`:`${n}.${e}`}function pa(e){return e.toLowerCase().replace(/_/g,"-")}function la(e){if(e===void 0||e==="")return "";let n=/^([^.[]+)(.*)$/.exec(e);if(!n)return Pe(e);let[,t,i]=n;switch(t){case "pluginId":return `name${i}`;case "name":return `display_name${i}`;case "description":return `description${i}`;case "_meta":return `_meta${i}`;case "version":return Pe("definitionVersion");case "definitionId":return Pe("definitionId");default:return Pe(`${t}${i}`)}}function Vi(e,n,t){return {path:t(e.path),rule:e.rule??pa(e.code),...e.message!==e.code?{message:e.message}:{},file:n}}function Fi(e){return JSON.parse(JSON.stringify(e))}function Dt(e,n,t=0,i=new Set){if(typeof e=="string"){e.length>4096&&k("LIMIT_EXCEEDED",n,"string-too-long"),(aa.test(e)||ca.test(e)||da.test(e))&&k("UNSAFE_VALUE",n,"unsafe-value");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||k("MANIFEST_INVALID",n,"non-finite-number");return}typeof e!="object"&&k("MANIFEST_INVALID",n,"non-json-value"),t>8&&k("LIMIT_EXCEEDED",n,"too-deep"),i.has(e)&&k("MANIFEST_INVALID",n,"cycle"),i.add(e);try{if(Array.isArray(e)){e.length>128&&k("LIMIT_EXCEEDED",n,"array-too-long"),e.forEach((r,o)=>Dt(r,`${n}[${o}]`,t+1,i));return}ce(e)||k("MANIFEST_INVALID",n,"non-plain-object");for(let[r,o]of Object.entries(e))Dt(o,n===""?r:`${n}.${r}`,t+1,i);}finally{i.delete(e);}}}function ue(e,n){return (typeof e!="string"||e.length===0)&&k("MANIFEST_INVALID",n,"string"),e}function Ke(e,n){return ce(e)||k("MANIFEST_INVALID",n,"object"),e}function ua(e,n){Array.isArray(e)||k("MANIFEST_INVALID",n,"array"),e.forEach((t,i)=>ue(t,`${n}[${i}]`));}function fa(e,n){typeof e!="boolean"&&k("MANIFEST_INVALID",n,"boolean");}function an(e,n,t,i){for(let r of Object.keys(e))!t.includes(r)&&!i.includes(r)&&k("MANIFEST_INVALID",`${n}.${r}`,"unknown-key");for(let r of t)te(e,r)||k("MANIFEST_INVALID",`${n}.${r}`,"missing-key");}function ya(e,n){switch(Dt(n,e),e){case "long_description":case "homepage":case "documentation":case "support":case "icon":case "license":ue(n,e);return;case "author":{let t=Ke(n,e);an(t,e,["name"],["email","url"]);for(let i of Object.keys(t))ue(t[i],`${e}.${i}`);return}case "repository":{let t=Ke(n,e);an(t,e,[],["type","url"]);for(let i of Object.keys(t))ue(t[i],`${e}.${i}`);return}case "icons":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=Ke(t,r);an(o,r,["src","size"],["theme"]),ue(o.src,`${r}.src`),ue(o.size,`${r}.size`),te(o,"theme")&&ue(o.theme,`${r}.theme`);});return}case "screenshots":case "keywords":case "privacy_policies":ua(n,e);return;case "tools":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=Ke(t,r);an(o,r,["name"],["description"]),ue(o.name,`${r}.name`),te(o,"description")&&ue(o.description,`${r}.description`);});return}case "prompts":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=Ke(t,r);an(o,r,["name","text"],["description","arguments"]),ue(o.name,`${r}.name`),ue(o.text,`${r}.text`);});return}case "tools_generated":case "prompts_generated":fa(n,e);return;case "localization":case "compatibility":case "user_config":Ke(n,e);return;default:k("MANIFEST_INVALID",e,"unknown-key");}}function Sn(e){return typeof e=="string"&&fe.test(e)?e:void 0}function Bi(e){return Number.isSafeInteger(e)&&e>=1?e:void 0}function Aa(e){let n=Sn(e.name);if(n===void 0)return;let t=e._meta,i=ce(t)?t[Re]:void 0,r=ce(i)?i:{},o=te(r,"definitionId")?Sn(r.definitionId):n,s=te(r,"definitionVersion")?Bi(r.definitionVersion):1;return {pluginId:n,...o===void 0?{}:{definitionId:o},...s===void 0?{}:{definitionVersion:s}}}function Ia(e){let n=Sn(e.pluginId);if(n===void 0)return;let t=Sn(e.definitionId),i=Bi(e.version);return {pluginId:n,...t===void 0?{}:{definitionId:t},...i===void 0?{}:{definitionVersion:i}}}function St(e){try{let n=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e));if(!ce(n))return !1;let t=n._meta;return ce(t)&&te(t,Re)}catch{return false}}function ga(e,n){if(e===ie)return n.builtinOnly===true;let t=n._meta,i=ce(t)?t[Re]:void 0;return ce(i)&&i.builtinOnly===true}function ma(e){te(e,"server")&&k("MANIFEST_INVALID","server","server-unsupported","phase 1 runs CrewX-owned Apps only");for(let s of Object.keys(e))bt.includes(s)||k("MANIFEST_INVALID",s,"unknown-key");for(let s of Nt)te(e,s)||k("MANIFEST_INVALID",s,"missing-key");e.manifest_version!==Tt&&k("MANIFEST_INVALID","manifest_version","unsupported-version",`manifest_version must be "${Tt}"`),ji(e.version)||k("MANIFEST_INVALID","version","semver","version must be a semver.org version such as 0.1.0");let n=e._meta;ce(n)||k("MANIFEST_INVALID","_meta","object"),te(n,Re)||k("MANIFEST_INVALID",Pe(),"missing-key");let t=n[Re];ce(t)||k("MANIFEST_INVALID",Pe(),"object");for(let s of Object.keys(t))Pt.includes(s)||vi.includes(s)||k("MANIFEST_INVALID",Pe(s),"unknown-key");for(let s of Pt)te(t,s)||k("MANIFEST_INVALID",Pe(s),"missing-key");if(te(t,"definitionVersion")){let s=t.definitionVersion;(!Number.isSafeInteger(s)||s<1)&&k("MANIFEST_INVALID",Pe("definitionVersion"),"positive-integer");}let i={};for(let s of xi)te(e,s)&&(ya(s,e[s]),i[s]=Fi(e[s]));let r={};for(let[s,a]of Object.entries(n))s!==Re&&(r[s]=a);let o={manifestVersion:2,pluginId:e.name,definitionId:te(t,"definitionId")?t.definitionId:e.name,version:te(t,"definitionVersion")?t.definitionVersion:1,name:e.display_name,description:e.description};for(let[s,a]of Object.entries(t))s==="definitionId"||s==="definitionVersion"||(o[s]=a);return Object.keys(r).length>0&&(o._meta=r),{v2Input:o,...Object.keys(r).length>0?{vendorMeta:r}:{},passthrough:i}}function ha(e,n){ce(e)||k("MANIFEST_INVALID","","not-object","manifest.json must be a JSON object",Y);let t;try{t=ma(e);}catch(o){throw o instanceof Ae?new Ae(o.code,{...o.reason,file:Y}):o}let i;try{let o=xe(t.v2Input,{mode:n.mode??"local"});o.manifestVersion!==2&&k("MANIFEST_INVALID","","v2-required"),i=o;}catch(o){throw o instanceof Q?new Ae(o.code,Vi(o,Y,la)):o}let r=e.tools;if(Array.isArray(r)){let o=new Set(i.actions.map(s=>s.actionId));r.forEach((s,a)=>{let d=s.name;if(!o.has(d))throw new Ae("MANIFEST_INVALID",{path:`tools[${a}].name`,rule:"tool-not-action",message:"every tools[].name must be an action id",file:Y})});}return {file:Y,manifest:i,v2Input:t.v2Input,releaseVersion:e.version,...Object.keys(t.passthrough).length>0?{mcpb:t.passthrough}:{}}}function _a(e,n){try{let t=xe(e,{mode:n.mode??"local"});if(t.manifestVersion!==2)throw new Ae("MANIFEST_INVALID",{path:"manifestVersion",rule:"v2-required",message:"a workspace App requires manifestVersion 2",file:ie});return {file:ie,manifest:t,v2Input:e}}catch(t){throw t instanceof Q?new Ae(t.code,Vi(t,ie,i=>i??"")):t}}function Xe(e){return pe(sn(e).definition)}function ki(e){let{entryHash:n,initialState:t,...i}=e,r={...i};return t!==void 0&&(r.initialState={path:t.path}),Fi(r)}function Ea(e,n){let t=ki(e),i=ki(n);return [...new Set([...Object.keys(t),...Object.keys(i)])].sort().filter(o=>ne(t[o]??null)!==ne(i[o]??null))}function Ta(e,n){return e.entryHash!==void 0&&n.entryHash!==void 0&&e.entryHash!==n.entryHash||e.initialState?.hash!==void 0&&n.initialState?.hash!==void 0&&e.initialState.hash!==n.initialState.hash}function Pa(e,n){let t=Ea(e,n),i=Ta(e,n),r="";try{let o=Xe(e),s=Xe(n);i=i||o!==s,r=` (definition hash ${o.slice(0,12)} vs ${s.slice(0,12)})`;}catch{i=true;}t.length===0&&!i||k("MANIFEST_DUAL_MISMATCH","","dual-manifest-mismatch",`${Y} and ${ie} normalize to different definitions${r}`+(t.length>0?`; differing fields: ${t.join(", ")}`:""));}function Da(e,n){let t=n.maxBytes??262144,i=[],r=new TextDecoder("utf-8",{fatal:true});for(let o of J){let s=e[o];if(s===void 0)continue;if(s.byteLength>t)return {parsed:i,failure:{code:"LIMIT_EXCEEDED",reason:{path:"",rule:"file-too-large",file:o},files:[o]}};let a;try{a=JSON.parse(r.decode(s));}catch{return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"invalid-json",file:o},files:[o]}}}if(!ce(a))return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"not-object",message:`${o} must be a JSON object`,file:o},files:[o]}};i.push({file:o,raw:a});}return {parsed:i}}function ve(e,n={}){let{parsed:t,failure:i}=Da(e,n),r=J.filter(p=>e[p]!==void 0);if(i!==void 0)return {ok:false,rejection:i,parseFailure:true,builtinOnly:false};if(t.length===0)return {ok:false,rejection:{code:"MANIFEST_INVALID",reason:{path:"",rule:"no-manifest-file",message:"neither manifest.json nor ui-plugin.json is present"},files:[]},parseFailure:true,builtinOnly:false};let o=t[0],s=o.file===Y?Aa(o.raw):Ia(o.raw),a=t.some(p=>ga(p.file,p.raw)),d=[];try{for(let p of t)d.push(p.file===Y?ha(p.raw,n):_a(p.raw,n));d.length===2&&Pa(d[0].manifest,d[1].manifest);}catch(p){if(p instanceof Ae)return {ok:false,rejection:{code:p.code,reason:p.reason,files:p.code==="MANIFEST_DUAL_MISMATCH"?[...J]:p.reason.file===void 0?r:[p.reason.file]},parseFailure:false,...s===void 0?{}:{identity:s},builtinOnly:a};throw p}let c=d[0];return {ok:true,...c,identity:s??{pluginId:c.manifest.pluginId},files:r}}var Y,ie,J,Tt,Re,bt,Nt,xi,Pt,vi,ra,sa,aa,ca,da,Ae,Mn=V(()=>{m();Ce();_e();Ue();Et();Y="manifest.json",ie="ui-plugin.json",J=[Y,ie],Tt="0.3",Re="dev.crewx",bt=Object.freeze(["manifest_version","name","display_name","version","description","long_description","author","repository","homepage","documentation","support","icon","icons","screenshots","localization","server","tools","tools_generated","prompts","prompts_generated","keywords","license","privacy_policies","compatibility","user_config","_meta"]),Nt=Object.freeze(["manifest_version","name","display_name","version","description","_meta"]),xi=Object.freeze(bt.filter(e=>e!=="server"&&!Nt.includes(e))),Pt=Object.freeze(["entry","surfaces","size","stateProjection","actions"]),vi=Object.freeze(["definitionId","definitionVersion","icon","tone","entryHash","runtime","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths","csp"]),ra=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,sa=256,aa=/<\/?[A-Za-z][^>]*>/,ca=/^\s*javascript:/i,da=/data:[^,\s]*,/i;Ae=class extends Error{constructor(t,i){super(`${t}: ${i.path||"<file>"} (${i.rule})`);this.code=t;this.reason=i;}code;reason};});var Mt=V(()=>{m();di();Mn();Et();Ue();});function On(e,n=e){throw new we(e,n)}var we,Rn=V(()=>{m();we=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="McpAppContractError"};});var Zi=V(()=>{m();});var Qi=V(()=>{m();Ce();_e();Rn();Zi();});function eo(e,n){return xa.add(e),n!==void 0&&va.set(e,n),e}var xa,va,wn=V(()=>{m();xa=new WeakSet,va=new WeakMap;});function ln(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Ot(e,n,t=[]){let i=new Set([...n,...t]),r=Object.keys(e);return n.every(o=>Object.hasOwn(e,o))&&r.every(o=>i.has(o))}function io(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))io(n);return Object.freeze(e)}function q(e){throw new Ie("LINEAGE_INVALID",e)}function $a(e){throw new Ie("LINEAGE_STALE",e)}function oo(e){if(!ln(e)||!Ot(e,Fa,Ba)||!ln(e.actions))return q("Lineage definition shape is invalid");for(let n of Object.values(e.actions))if(!ln(n)||!Ot(n,Ha,za))return q("Lineage action definition shape is invalid");return e}function Ga(e){if(!ln(e)||!Ot(e,ja,Va))return q("Lineage entry shape is invalid");if(!Number.isSafeInteger(e.version)||e.version<1||typeof e.hash!="string"||!no.test(e.hash))return q("Lineage entry identity is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!no.test(e.sourceHash)))return q("Lineage source hash is invalid");if(e.compat!==void 0&&e.compat!=="break")return q("Lineage compatibility marker is invalid");let n=oo(e.definition);if(n.version!==e.version)return q("Lineage version does not match its definition");if(e.sourceHash!==void 0&&n.sourceHash!==e.sourceHash)return q("Lineage source hash does not match its definition");let t;try{t=pe(n),Ee({...n,hash:e.hash});}catch{return q("Lineage definition is invalid")}return t!==e.hash?q("Lineage definition hash does not match"):io({version:e.version,hash:e.hash,definition:n,...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},...e.compat===void 0?{}:{compat:e.compat}})}function to(e){return e.stateProjection?.allow??[]}function Wa(e,n){let t=[],i=new Set(to(n));to(e).some(a=>!i.has(a))&&t.push("S1_STATE_PROJECTION");let r=new Set(n.dataPaths??[]);(e.dataPaths??[]).some(a=>!r.has(a))&&t.push("S2_DATA_PATHS");for(let[a,d]of Object.entries(e.actions)){let c=n.actions[a];if(c&&(d.confirmation??"native")==="native"&&(c.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(d=>!a.has(d))&&t.push("S5_SUMMARY_PROJECTION");}return t}function Ja(e,n){return ne(e)===ne(n)}function Rt(e,n){if(!Array.isArray(e)||e.length===0)return q("Definition lineage is missing");if(!ln(n)||typeof n.hash!="string")return q("Current definition is invalid");let t,i;try{let{hash:a,...d}=n;i=oo(d),t={...i,hash:a},Ee(t);}catch{return q("Current definition is invalid")}let r=e.map(Ga),o=r[0].definition.id;if(r.some(a=>a.definition.id!==o))return q("Lineage definition ids do not match");if(r.some((a,d)=>d>0&&a.version<=r[d-1].version))return q("Lineage generations are not in increasing version order");if(r.some((a,d)=>r.findIndex(c=>c.hash===a.hash)!==d))return q("Lineage contains a duplicate hash");let s=r[r.length-1];if(s.version!==t.version||s.hash!==t.hash||s.definition.id!==t.id||!Ja(s.definition,i))return $a("The last lineage generation does not match the current package");if(t.legacy!==void 0){let a=new Set(Object.keys(t.actions)),d=new Set;for(let p of r)if(p.sourceHash===void 0)for(let y of Object.keys(p.definition.actions))a.has(y)&&d.add(y);let c=Object.keys(t.legacy.agentAccess??{});if(c.length!==d.size||c.some(p=>!d.has(p))){let p="S4_LEGACY_AGENT_ACCESS_COMPLETE";throw new Ie("LINEAGE_INVALID",`Lineage compatibility failed: ${p}`,[p])}}for(let a=0;a<r.length-1;a+=1){if(r.slice(a,-1).some(p=>p.compat==="break"))continue;let c=Wa(r[a].definition,t);if(c.length>0)throw new Ie("LINEAGE_INVALID",`Lineage compatibility failed: ${c.join(", ")}`,c)}return Object.freeze({entries:Object.freeze(r),current:t})}var Ie,no,ja,Va,Fa,Ba,Ha,za,wt=V(()=>{m();Ce();_e();Ie=class extends Error{constructor(t,i=t,r=[]){super(i);this.code=t;this.violations=r;}code;violations;name="UiDefinitionLineageError"},no=/^[0-9a-f]{64}$/,ja=["version","hash","definition"],Va=["sourceHash","compat"],Fa=["id","version","actions"],Ba=["sourceHash","usage","detailPanel","displayModes","renderer","surfaces","stateProjection","dataPaths","summaryProjection","legacy"],Ha=["capabilities"],za=["inputKeys","dataInputs","confirmation","resultProjection","content","env"];});var ro,so,ao=V(()=>{m();ro=["crewx_app_terminal_connect","crewx_app_html_viewer_open"],so=["crewx_listWorkspaces","crewx_queryAgent","crewx_executeAgent","crewx_getTaskResult","crewx_listTasks","crewx_listAgents","callBrowser","openTab","listTabs","closeTab"];});var co=V(()=>{m();Ce();wn();});function Ut(e,n=0){try{let t=he(e,n);return t.type!==void 0&&t.type!=="object"&&On("TOOL_INVALID","MCP App inputSchema must describe an object"),t}catch(t){if(t instanceof we)throw t;On("TOOL_INVALID","MCP App inputSchema must be projection-safe JSON");}}function po(e){if(e.length===0)return Ut({type:"object",properties:{},additionalProperties:false});let n=e.map(i=>i.actionId),t=new Map;for(let i of e)t.set(i.actionId,Ut(i.inputSchema));return Ut(Ya(n,t),Xa)}function Ya(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 un,Xa,Ct=V(()=>{m();Qi();Ce();_e();wn();Rn();wt();ao();co();un=8*1024*1024,new Set(ro),new Set(so),Xa=4;});function qa(e){if(e===null||typeof e!="object"||!(lo in e))throw new TypeError("scanCache must be created by createWorkspaceAppScanCache");return e[lo]}function uo(e,n){let t=qa(e),i=t.rootIdentity;return i!==void 0&&(i.dev!==n.dev||i.ino!==n.ino||i.realPath!==n.realPath)&&(t.candidates.clear(),t.assetCatalogs.clear(),t.lastCandidateScanUnchanged=void 0,t.lastCandidateKeys=void 0,t.scanStartedAtNs=void 0,t.lastAssetCatalogsUnchanged=void 0,t.lastSnapshot=void 0,t.lastSnapshotBuildInputs=void 0),t.rootIdentity=n,t}var lo,fo=V(()=>{m();lo=Symbol("crewx.workspace-app-scan-cache.state");});function re(e){let n=typeof e=="object"&&e!==null&&"code"in e?String(e.code):"";return n==="ENOENT"?new D("NOT_FOUND"):n==="ELOOP"?new D("PATH_ESCAPED"):n==="EFBIG"||n==="EOVERFLOW"?new D("LIMIT_EXCEEDED"):n==="EACCES"||n==="EPERM"||n==="ENOTDIR"?new D("READ_DENIED"):new D("READ_DENIED")}function nc(e){if(typeof e!="string"||e.length===0||!isAbsolute(e))throw new D("READ_DENIED")}function kt(e){if(typeof e!="string"||isAbsolute(e)||/[\\\u0000]/.test(e))throw new D("PATH_ESCAPED");if(e==="")return [];let n=e.split("/");if(n.some(t=>t.length===0||t==="."||t===".."))throw new D("PATH_ESCAPED");return n}function xn(e,n){let t=relative(e,n);return t===""||t!==".."&&!t.startsWith(`..${sep}`)&&!isAbsolute(t)}function Ze(e){return {dev:e.dev,ino:e.ino,size:e.size,mtimeNs:e.mtimeNs,ctimeNs:e.ctimeNs}}function Vt(e,n){return e.dev===n.dev&&e.ino===n.ino}function Ft(e,n){return Vt(e,n)&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}async function Un(e){nc(e);let n,t;try{n=await realpath(e),t=await stat(n,{bigint:!0});}catch(i){throw re(i)}if(!t.isDirectory())throw new D("READ_DENIED");return {realRoot:n,identity:Ze(t)}}async function Io(e,n,t){if(t.length<2||t[0]!=="apps"&&t[0]!=="skills")return;let i,r;try{if(i=resolve(e,t[0],t[1]),r=await realpath(i),!(await stat(r,{bigint:!0})).isDirectory())throw new D("READ_DENIED")}catch(o){throw o instanceof D?o:re(o)}if(!xn(n,r))throw new D("PATH_ESCAPED");return r}async function Cn(e,n,t,i){let r,o,s;try{r=await lstat(e,{bigint:!0}),o=await realpath(e),s=await stat(o,{bigint:!0});}catch(a){throw re(a)}if(!xn(n,o)||t!==void 0&&!xn(t,o))throw new D("PATH_ESCAPED");if(!r.isFile()||!s.isFile())throw new D("READ_DENIED");if(!Vt(i,r)||!Vt(i,s)||i.dev!==s.dev)throw new D("PATH_ESCAPED")}async function qe(e,n){let t,i;try{t=await realpath(e),i=await stat(t,{bigint:!0});}catch{throw new D("PATH_ESCAPED")}if(t!==n.realRoot||!Ft(n.identity,Ze(i)))throw new D("PATH_ESCAPED")}function tc(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 D,jt,ec,Ao,vn,go,Ht=V(()=>{m();D=class extends Error{constructor(t){super(t);this.code=t;}code;name="AppDiscoveryFsError"},jt=constants.O_NOFOLLOW,ec=constants.O_NONBLOCK,Ao=constants.O_RDONLY|(jt??0)|(ec??0);vn=class{async getRootIdentity(n){let t=await Un(n);return await qe(n,t),{dev:t.identity.dev,ino:t.identity.ino,realPath:t.realRoot}}async listDirectory(n,t){let i=kt(t),r=await Un(n),o=resolve(n,...i),s,a;try{s=await realpath(o),a=await stat(s,{bigint:!0});}catch(d){let c=re(d);if(c.code==="NOT_FOUND")return [];throw c}if(!xn(r.realRoot,s)||!a.isDirectory())throw new D("PATH_ESCAPED");try{let d=await readdir(s,{withFileTypes:!0,encoding:"utf8"});return await qe(n,r),d.map(tc)}catch(d){let c=re(d);if(c.code==="NOT_FOUND")return [];throw c}}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 D("READ_DENIED");if(jt===void 0)throw new D("UNSUPPORTED");let r=kt(t),o=await Un(n),s=resolve(n,...r),a=relative(n,s);if(a===".."||a.startsWith(`..${sep}`)||isAbsolute(a))throw new D("PATH_ESCAPED");let d;try{d=await open(s,Ao);}catch(c){throw re(c)}try{let c;try{let E=await d.stat({bigint:!0});c=Ze(E);}catch(E){throw re(E)}if(c.size>BigInt(i))throw new D("LIMIT_EXCEEDED");if(c.size>BigInt(Number.MAX_SAFE_INTEGER))throw new D("LIMIT_EXCEEDED");await qe(n,o);let p=await Io(n,o.realRoot,r);await Cn(s,o.realRoot,p,c);let y=new Uint8Array(new ArrayBuffer(Number(c.size))),A=0;for(;A<y.byteLength;){let E;try{E=(await d.read(y,A,y.byteLength-A,A)).bytesRead;}catch(O){throw re(O)}if(E<=0)throw new D("IDENTITY_CHANGED");A+=E;}let I;try{let E=await d.stat({bigint:!0});I=Ze(E);}catch(E){throw re(E)}if(!Ft(c,I))throw new D("IDENTITY_CHANGED");return await Cn(s,o.realRoot,p,I),await qe(n,o),new Uint8Array(y)}finally{await d.close().catch(()=>{});}}async fingerprintVerifiedFile(n,t,i){if(!Number.isSafeInteger(i)||i<0)throw new D("READ_DENIED");if(jt===void 0)throw new D("UNSUPPORTED");let r=kt(t),o=await Un(n),s=resolve(n,...r),a=relative(n,s);if(a===".."||a.startsWith(`..${sep}`)||isAbsolute(a))throw new D("PATH_ESCAPED");let d;try{d=await open(s,Ao);}catch(c){throw re(c)}try{let c;try{let A=await d.stat({bigint:!0});c=Ze(A);}catch(A){throw re(A)}if(c.size>BigInt(i)||c.size>BigInt(Number.MAX_SAFE_INTEGER))throw new D("LIMIT_EXCEEDED");await qe(n,o);let p=await Io(n,o.realRoot,r);await Cn(s,o.realRoot,p,c);let y;try{let A=await d.stat({bigint:!0});y=Ze(A);}catch(A){throw re(A)}if(!Ft(c,y))throw new D("IDENTITY_CHANGED");return await Cn(s,o.realRoot,p,y),await qe(n,o),{...y,candidateRealPath:p??o.realRoot}}catch(c){throw c instanceof D?c:re(c)}finally{await d.close().catch(()=>{});}}async readFileVerified(n,t,i){return this.readVerifiedFile(n,t,i)}},go=new vn;});function In(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 ho(e){return typeof e=="string"&&fe.test(e)?e:void 0}function dc(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function Ve(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let s=t[o]-i[o];if(s!==0)return s}return t.byteLength-i.byteLength}function pc(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 r=n.isFile;return typeof r=="function"&&r.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function lc(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 uc(e){return ac.decode(e)}function fc(e){return JSON.parse(uc(e))}function _o(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 yc(e){if(e instanceof D)return _o(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return _o(n)}}function De(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function Ac(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function Ic(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 Eo(e,n,t,i){let r=Ac(e);if(!r)throw new D("READ_DENIED");return lc(await r.call(e,n,t,i))}async function Gt(e,n,t){let i=Ic(e);if(!i)throw new D("READ_DENIED");let r=await i.call(e,n,t);if(!Array.isArray(r))throw new D("READ_DENIED");return r.map(pc).filter(o=>o!==null)}function gc(e,n,t,i){return Object.freeze({code:e,...{},source:n,relativePath:t})}function mc(e){if(!In(e))throw new TypeError("productBundle.reservedIds must be an object with appIds and definitionIds arrays");try{let n=Reflect.ownKeys(e);if(n.length!==2||!n.includes("appIds")||!n.includes("definitionIds"))throw new TypeError("productBundle.reservedIds must contain exactly appIds and definitionIds");let t=(i,r)=>{if(!Array.isArray(i))throw new TypeError("productBundle.reservedIds."+r+" must be an array");let o=[];for(let s=0;s<i.length;s+=1){let a=i[s];if(typeof a!="string"||a.length===0)throw new TypeError("productBundle.reservedIds."+r+" must contain non-empty strings");o.push(a);}return Object.freeze([...new Set(o)].sort(Ve))};return Object.freeze({appIds:t(e.appIds,"appIds"),definitionIds:t(e.definitionIds,"definitionIds")})}catch(n){throw n instanceof TypeError?n:new TypeError("productBundle.reservedIds must be a valid reservation object")}}function hc(e,n){return e.appIds.length===n.appIds.length&&e.appIds.every((t,i)=>t===n.appIds[i])&&e.definitionIds.length===n.definitionIds.length&&e.definitionIds.every((t,i)=>t===n.definitionIds[i])}function Vn(e){return Object.freeze({appIds:Object.freeze([...new Set(e.map(n=>n.appId))].sort(Ve)),definitionIds:Object.freeze([...new Set(e.map(n=>n.definition.id))].sort(Ve))})}function jn(e,n){let t=Object.keys(e).sort(Ve),i=[...n].sort(Ve);return t.length===i.length&&t.every((r,o)=>r===i[o])}function To(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 _c(e){let n;try{n=fc(e);}catch{return}if(!In(n)||!jn(n,["version","packages"])||n.version!==1||!Array.isArray(n.packages)||n.packages.length>Wt)return;let t=new Set,i=new Set,r=0,o=[];for(let s of n.packages){if(!In(s))return;let a=["packageDir","appId","definition","files"],d=Object.hasOwn(s,"lineage"),c=Object.hasOwn(s,"launcher"),p=[...d?["lineage"]:[],...c?["launcher"]:[]];if(!jn(s,[...a,...p])||c&&s.launcher!==false)return;let y=To(s.packageDir),A=ho(s.appId);if(!y||y.length!==2||y[0]!=="apps"||!dc(y[1])||!A||t.has(s.packageDir)||!In(s.definition)||!jn(s.definition,["id","version","hash"]))return;let I=ho(s.definition.id),E=s.definition.version,O=s.definition.hash;if(!I||!Number.isSafeInteger(E)||E<1||typeof O!="string"||!$t.test(O)||!Array.isArray(s.files)||s.files.length<2||s.files.length>Jt)return;let b=new Set,j=[];for(let C of s.files){if(!In(C)||!jn(C,["path","sha256"]))return;let x=To(C.path);if(!x||typeof C.sha256!="string"||!$t.test(C.sha256))return;let B=x.join("/"),_=`${s.packageDir}/${B}`;if(b.has(B)||i.has(_))return;b.add(B),i.add(_),j.push(Object.freeze({path:B,sha256:C.sha256}));}if(!J.some(C=>b.has(C))||!b.has("ui/index.html")||(r+=j.length,r>oc))return;t.add(s.packageDir),o.push(Object.freeze({packageDir:s.packageDir,...c?{launcher:false}:{},appId:A,definition:Object.freeze({id:I,version:E,hash:O}),lineage:Array.isArray(s.lineage)?s.lineage:[],files:Object.freeze(j.sort((C,x)=>Ve(C.path,x.path)))}));}return Object.freeze({version:1,packages:Object.freeze(o)})}function je(e){let n=yc(e);return n==="PATH_ESCAPED"||n==="IDENTITY_CHANGED"||n==="TOCTOU"?"PATH_ESCAPED":n==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":"BUNDLE_INTEGRITY"}async function Ec(e,n,t,i,r){let o=[],s=async(a,d)=>{if(!De(i,r))throw new D("LIMIT_EXCEEDED");if(d>2)throw new D("LIMIT_EXCEEDED");let c=await Gt(e,n,a);for(let p of c){if(typeof p.name!="string"||p.name.length===0||p.name==="."||p.name===".."||/[\\/\u0000]/.test(p.name))throw new D("PATH_ESCAPED");let y=`${a}/${p.name}`;if(p.kind==="file"){if(o.push(y.slice(t.length+1)),o.length>Jt)throw new D("LIMIT_EXCEEDED")}else if(p.kind==="directory")await s(y,d+1);else throw p.kind==="symlink"?new D("PATH_ESCAPED"):new D("READ_DENIED")}};return await s(t,0),o.sort(Ve)}function Tc(e){return J.includes(e)?262144:e==="ui/index.html"?un:e==="ui/state.json"?65536:e.startsWith("ui/assets/")?sc:rc}async function Po(e,n,t,i){if(e===void 0)return {packages:[],diagnostics:[],incomplete:false,reservedIds:cc};let r=mc(e.reservedIds),o=[],s=(u,f,g)=>gc(u,"bundled",f),a=(u=[],f=false,g)=>({...g===void 0?{}:{indexHash:g},packages:u,diagnostics:o,incomplete:f,reservedIds:r});if(typeof e.root!="string"||e.root.length===0||typeof e.expectedIndexHash!="string"||!$t.test(e.expectedIndexHash))return o.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a();let d;try{d=await Eo(n,e.root,"bundle-index.json",ic);}catch(u){return o.push(s(je(u),"bundle-index.json")),a()}let c=createHash("sha256").update(d).digest("hex");if(c!==e.expectedIndexHash)return o.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a();let p=_c(d);if(p===void 0)return o.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a();if(!hc(Vn(p.packages),r))return o.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a([],false,c);if(!De(t,i))return o.push(s("LIMIT_EXCEEDED","bundle-index.json")),a(p.packages.map(u=>({indexEntry:u,failureCode:"LIMIT_EXCEEDED"})),true,c);let y;try{y=await Gt(n,e.root,"");}catch(u){return o.push(s(je(u),"bundle-index.json")),a(p.packages.map(f=>({indexEntry:f,failureCode:je(u)})),false,c)}if(!De(t,i))return o.push(s("LIMIT_EXCEEDED","bundle-index.json")),a(p.packages.map(u=>({indexEntry:u,failureCode:"LIMIT_EXCEEDED"})),true,c);let A=y.find(u=>u.name==="bundle-index.json"&&u.kind==="file"),I=y.find(u=>u.name==="apps"&&u.kind==="directory"),E=u=>p.packages.map(f=>({indexEntry:f,failureCode:u}));if(!A)return o.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a(E("BUNDLE_INTEGRITY"),false,c);let O=y.filter(u=>u.name!=="bundle-index.json"&&u.name!=="apps");if(O.length>0){let u=O.some(f=>f.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return o.push(s(u,"bundle-index.json")),a(E("BUNDLE_INTEGRITY"),false,c)}if(y.some(u=>u.name==="apps"&&u.kind!=="directory"))return o.push(s("PATH_ESCAPED","apps")),a(E("PATH_ESCAPED"),false,c);let b=[];if(I)try{b=await Gt(n,e.root,"apps");}catch(u){return o.push(s(je(u),"apps")),a(E(je(u)),false,c)}if(!De(t,i)||b.length>Wt)return o.push(s("LIMIT_EXCEEDED","apps")),a(E("LIMIT_EXCEEDED"),true,c);let j=new Map(p.packages.map(u=>[u.packageDir.slice(5),u])),C=b.filter(u=>!j.has(u.name));for(let u of C)o.push(s(u.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY",`apps/${u.name}`));if(C.length>0){let u=C.some(f=>f.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return a(E(u),false,c)}let x=new Set,B=new Map,_=new Map;for(let u of p.packages){let f=B.get(u.appId)??[];f.push(u),B.set(u.appId,f);let g=`${u.definition.id}\0${String(u.definition.version)}`,P=_.get(g)??[];P.push(u),_.set(g,P);}for(let u of [...B.values(),..._.values()])if(u.length>1)for(let f of u)x.add(f);let h=[],S=d.byteLength,w=false;for(let u of p.packages){if(!De(t,i)){w=true,h.push({indexEntry:u,failureCode:"LIMIT_EXCEEDED"});continue}let f;try{let N=u.lineage[u.lineage.length-1];if(!N)throw new Ie("LINEAGE_INVALID","Definition lineage is missing");if(N.definition.id!==u.definition.id||N.version!==u.definition.version||N.hash!==u.definition.hash)throw new Ie("LINEAGE_STALE","Last lineage generation does not match bundle identity");f=Rt(u.lineage,{...N.definition,hash:N.hash}).entries;}catch(N){let oe=N instanceof Ie?N.code:"LINEAGE_INVALID";o.push(s(oe,u.packageDir)),h.push({indexEntry:u,failureCode:oe});continue}let g=b.find(N=>N.name===u.packageDir.slice(5));if(!I||!g){h.push({indexEntry:u,failureCode:"BUNDLE_INTEGRITY"});continue}if(g.kind!=="directory"){h.push({indexEntry:u,failureCode:g.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY"});continue}let P;try{let N=await Ec(n,e.root,u.packageDir,t,i);if(!De(t,i)){w=!0,h.push({indexEntry:u,failureCode:"LIMIT_EXCEEDED"});continue}let oe=u.files.map(ge=>ge.path);if(N.length!==oe.length||N.some((ge,me)=>ge!==oe[me])){h.push({indexEntry:u,failureCode:"BUNDLE_INTEGRITY"});continue}P=new Map;let H;for(let ge of u.files){if(!De(t,i)){H="LIMIT_EXCEEDED",w=!0;break}if(S>=zt){H="LIMIT_EXCEEDED";break}let me;try{me=await Eo(n,e.root,`${u.packageDir}/${ge.path}`,Tc(ge.path));}catch(Mr){H=je(Mr);break}if(!De(t,i)){H="LIMIT_EXCEEDED",w=!0;break}if(S+me.byteLength>zt){S=zt,H="LIMIT_EXCEEDED";break}if(S+=me.byteLength,createHash("sha256").update(me).digest("hex")!==ge.sha256){H="BUNDLE_INTEGRITY";break}P.set(ge.path,me);}if(H!==void 0){h.push({indexEntry:u,failureCode:H});continue}}catch(N){De(t,i)||(w=true),h.push({indexEntry:u,failureCode:je(N)});continue}h.push({indexEntry:u,lineage:f,files:P,...x.has(u)?{failureCode:"DUPLICATE_ID"}:{}});}return a(h,w,c)}var ic,Wt,Jt,oc,rc,sc,zt,$t,ac,cc,Kt=V(()=>{m();wt();Ue();Mn();Ct();Ht();ic=256*1024,Wt=64,Jt=128,oc=Wt*Jt,rc=2*1024*1024,sc=8*1024*1024,zt=32*1024*1024,$t=/^[0-9a-f]{64}$/,ac=new TextDecoder("utf-8",{fatal:true}),cc=Object.freeze({appIds:Object.freeze([]),definitionIds:Object.freeze([])});});function Dc(e){if(typeof e!="string"||!fe.test(e))throw new TypeError("pluginId must be a safe UI plugin identifier");let n=`${Xt}${e}`.length+7<=128?e:`hash_${createHash("sha256").update(e,"utf8").digest("hex")}`;return {read:`${Xt}${n}_read`,action:`${Xt}${n}_action`}}function bo(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 Nc(e,n){return n.length===0||n==="."||n===".."||/[\\/\u0000]/.test(n)?e==="skills"?"skills":"apps":`${e==="skills"?"skills":"apps"}/${n}`}function Sc(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function gn(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let s=t[o]-i[o];if(s!==0)return s}return t.byteLength-i.byteLength}function xo(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 r=n.isFile;return typeof r=="function"&&r.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function Mc(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 vo(e){return bc.decode(e)}function Lc(e){return JSON.parse(vo(e))}function Oc(e){if(e===void 0)return;let n=e.definitionId!==void 0&&e.definitionVersion!==void 0?`${e.definitionId}\0${String(e.definitionVersion)}`:void 0;return {pluginId:e.pluginId,...n===void 0?{}:{definitionKey:n}}}function Bn(e,n,t,i,r){let o={code:e,...i===void 0?{}:{pluginId:i},source:n,relativePath:t,...r?.reason===void 0?{}:{reason:Object.freeze({...r.reason})},...r?.files===void 0?{}:{files:Object.freeze([...r.files])}};return Object.freeze(o)}function No(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 de(e){if(e instanceof D)return No(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return No(n)}}function Qe(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 So(e){return {reason:e.reason,...e.code==="MANIFEST_DUAL_MISMATCH"?{files:e.files}:{}}}function Mo(e){return e==="MANIFEST_DUAL_MISMATCH"?e:jo(e)}function Rc(e){return jo(e.code)}function jo(e){switch(e){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 Vo("UiPluginValidationError",e)}}function Vo(e,n){throw new Error(`Unmapped ${e} code: ${String(n)}`)}function wc(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 Vo("McpAppContractError",e)}}function be(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function Uc(e){return {pluginId:e.appId,definitionKey:`${e.definition.id}\0${String(e.definition.version)}`}}function Cc(e,n){let t=n.get("package.json");if(t!==void 0)try{let r=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(t));if(bo(r)){let o=r.bin,s=typeof o=="string"?o:bo(o)?Object.values(o).find(a=>typeof a=="string"):void 0;for(let a of [s,r.main]){if(typeof a!="string")continue;let d=kc(a);if(d&&n.has(d))return d}}}catch{}return [`${e.slice(e.lastIndexOf("/")+1)}.js`,"index.js","main.js"].find(r=>n.has(r))}function kc(e){if(e.startsWith("/")||e.includes("\\")||e.includes("\0"))return;let n=e.split("/").filter(t=>t!==".");if(!(n.length===0||n.some(t=>t.length===0||t==="..")))return n.join("/")}function xc(){return globalThis.performance?.now()??Date.now()}function Fe(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))Fe(n);return Object.freeze(e)}function Lo(e){return Object.freeze(Array.from(e))}async function qt(e,n,t,i){if(n.pinnedFiles!==void 0){let a=n.pinnedFiles.get(t);if(a===void 0)throw new D("NOT_FOUND");if(a.byteLength>i)throw new D("LIMIT_EXCEEDED");return new Uint8Array(a)}let r=`${n.relativePath}/${t}`,o=n.scanContext,s=e.fingerprintVerifiedFile;if(o===void 0||!o.cacheable||typeof s!="function")return Uo(e,n.root,r,i);try{let a=o.priorFingerprints.get(r)??await s.call(e,o.workspaceRoot,r,i);o.candidateRealPath=a.candidateRealPath;let d=await Uo(e,n.root,r,i),c=await s.call(e,o.workspaceRoot,r,i);return o.candidateRealPath=c.candidateRealPath,Ho(a,c)&&c.size===BigInt(d.byteLength)&&!zo(c,o.scanStartedAtNs)?o.files.set(r,{relativePath:r,byteLimit:i,fingerprint:c}):o.cacheable=!1,d}catch(a){throw J.includes(t)&&de(a)==="NOT_FOUND"&&o.directoryListings.some(c=>c.relativePath===n.relativePath&&!Bo(c.key,t))||(o.cacheable=false),a}}function Fo(e,n){return JSON.stringify([e.realPath,n.source,n.relativePath])}async function vc(e,n,t,i,r,o,s,a){let d=e.fingerprintVerifiedFile,c=Fo(t,i),p=r.candidates.get(c),y=i.relativePath,A;try{A=await wo(e,n,y);}catch(_){if(de(_)!=="NOT_FOUND")throw _}let I=A===void 0?void 0:{relativePath:y,key:A};if(I!==void 0&&(i.source==="apps"||i.source==="skills")&&!J.some(_=>Bo(I.key,_)))return be(s,a)?p!==void 0&&p.candidate===void 0&&p.candidateRealPath===void 0&&p.files.length===0&&p.directoryListings.length===1&&p.directoryListings[0]?.relativePath===I.relativePath&&p.directoryListings[0]?.key===I.key&&(i.source==="apps"?p.diagnostic?.code==="MANIFEST_MISSING":p.diagnostic===void 0)&&typeof d=="function"?{memo:p}:typeof d!="function"?{}:{context:{state:r,cacheKey:c,workspaceRoot:n,scanStartedAtNs:o,directoryListings:Object.freeze([I]),priorFingerprints:new Map,files:new Map,cacheable:true}}:{timeLimitReached:true};let E=await Promise.all(Oo.map(async _=>{if(_==="")return I;let h=`${i.relativePath}${_}`;try{let S=await wo(e,n,h);return S===void 0?void 0:{relativePath:h,key:S}}catch(S){if(de(S)==="NOT_FOUND")return;throw S}}));if(!be(s,a))return {timeLimitReached:true};let O=typeof d=="function"&&E.every(_=>_!==void 0),b=E.filter(_=>_!==void 0),j=new Map,C=p!==void 0&&O,x;if(p!==void 0&&typeof d=="function"){let _=await Promise.all(p.files.map(async h=>{if(!be(s,a))return {kind:"time",file:h};try{let S=await d.call(e,n,h.relativePath,h.byteLimit);return {kind:"fingerprint",file:h,current:S}}catch(S){return de(S)==="NOT_FOUND"?{kind:"missing",file:h}:{kind:"error",file:h,error:S}}}));if(_.some(h=>h.kind==="time"))return {timeLimitReached:true};for(let h of _){if(h.kind==="error")throw h.error;if(h.kind==="missing"){C=false;continue}if(h.kind!=="fingerprint")continue;let{file:S,current:w}=h;j.set(S.relativePath,w),x??=w.candidateRealPath,(w.candidateRealPath!==p.candidateRealPath||!Ho(w,S.fingerprint)||zo(w,o))&&(C=false);}}let B=p!==void 0&&p.directoryListings.length===b.length&&p.directoryListings.every((_,h)=>_.relativePath===b[h]?.relativePath&&_.key===b[h]?.key);return p!==void 0&&O&&B&&C&&x===p.candidateRealPath?{memo:p}:!O||b.length!==Oo.length?{}:{context:{state:r,cacheKey:c,workspaceRoot:n,scanStartedAtNs:o,directoryListings:Object.freeze(b),priorFingerprints:j,files:new Map,...x===void 0?{}:{candidateRealPath:x},cacheable:true}}}function Bo(e,n){try{let t=JSON.parse(e);return Array.isArray(t)&&t.some(i=>Array.isArray(i)&&i[0]===n)}catch{return true}}async function wo(e,n,t){let i=$o(e);if(typeof i!="function")return;let r=await i.call(e,n,t);if(!Array.isArray(r)||r.some(s=>typeof s=="string"))return;let o=r.map(xo);if(!o.some(s=>s===null))return JSON.stringify(o.slice().sort((s,a)=>gn(s.name,a.name)||gn(s.kind,a.kind)).map(s=>[s.name,s.kind]))}function Ho(e,n){return e.dev===n.dev&&e.ino===n.ino&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}function zo(e,n){let t=e.mtimeNs-n;return t>=-Ro&&t<=Ro}function Yt(e){let n=e.scanContext,t=e.source==="skills"&&e.candidate===void 0&&e.diagnostic===void 0&&n?.files.size===0,i=e.source==="apps"&&e.candidate===void 0&&e.diagnostic?.code==="MANIFEST_MISSING"&&n?.files.size===0,r=t||i;if(n===void 0||!n.cacheable||n.candidateRealPath===void 0&&!r||n.files.size===0&&!r)return;let o=Object.freeze({...!r&&n.candidateRealPath!==void 0?{candidateRealPath:n.candidateRealPath}:{},directoryListings:n.directoryListings,files:Object.freeze([...n.files.values()]),...e.candidate===void 0?{}:{candidate:e.candidate},...e.diagnostic===void 0?{}:{diagnostic:e.diagnostic},...e.identity===void 0?{}:{identity:e.identity},...e.provenance===void 0?{}:{provenance:e.provenance}});n.state.candidates.set(n.cacheKey,o);}function jc(e,n,t){let i=createHash("sha256"),r=new TextEncoder().encode(ne(e)),o=s=>{let a=new Uint8Array(8);new DataView(a.buffer).setBigUint64(0,BigInt(s)),i.update(a);};return o(r.byteLength),i.update(r),o(n.byteLength),i.update(n),o(t.byteLength),i.update(t),i.digest("hex")}function Vc(e,n){let t={...e.definition,sourceHash:n},i;try{i=pe(t);}catch(o){throw o instanceof R&&o.code==="INPUT_INVALID"?new Q("MANIFEST_INVALID","normalized definition is invalid"):o}let r={...t,hash:i};try{Ee(r);}catch{throw new Q("MANIFEST_INVALID","normalized definition is invalid")}return r}function Fc(e){return e.actions.some(n=>n.backend.type==="core"&&n.backend.handler!=="state.set")}function Bc(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function $o(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 Uo(e,n,t,i){let r=Bc(e);if(!r)throw new D("READ_DENIED");return Mc(await r.call(e,n,t,i))}async function Hc(e,n,t){let i=$o(e);if(!i)throw new D("READ_DENIED");let r=await i.call(e,n,t);if(!Array.isArray(r))throw new D("READ_DENIED");return r.map(xo).filter(o=>o!==null)}function zc(e){let n=[];for(let t of [e.reserved,e.builtin])t&&n.push(t);return e.builtins&&"listMcpApps"in e.builtins?n.push(Co(e.builtins)):e.builtins&&n.push(e.builtins),e.builtinCatalog&&n.push(Co(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 Co(e){let n=[],t=[],i=[];for(let r of e.listMcpApps())typeof r.appId=="string"&&n.push(r.appId),r.definition&&typeof r.definition.id=="string"&&t.push(r.definition.id);for(let r of e.listMcpAppTools())typeof r.name=="string"&&i.push(r.name);return {appIds:n,definitionIds:t,toolNames:i}}function Ne(e,n){e.diagnostic||(e.diagnostic=Bn(n,e.source,e.relativePath,e.identity?.pluginId));}function $c(e){let n=new Map;for(let i of e){let r=i.identity?.pluginId;if(r===void 0)continue;let o=n.get(r)??[];o.push(i),n.set(r,o);}for(let i of n.values()){if(i.length<2)continue;let r=i.filter(s=>s.provenance!==void 0);if(r.length>0){for(let s of i)s.provenance===void 0&&Ne(s,"RESERVED_ID");if(r.length>1)for(let s of r)Ne(s,"DUPLICATE_ID");continue}let o=i.filter(s=>s.source==="apps");if(o.length>1){for(let s of o)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 r=i.identity?.definitionKey;if(r===void 0)continue;let o=t.get(r)??[];o.push(i),t.set(r,o);}for(let i of t.values())if(i.length>1)for(let r of i)Ne(r,"DUPLICATE_ID");}function Gc(e,n,t){let i=new Set,r=new Set,o=new Set,s=new Set(t.appIds),a=new Set(t.definitionIds);for(let d of zc(n)){for(let c of d.appIds??[])typeof c=="string"&&i.add(c);for(let c of d.definitionIds??[])typeof c=="string"&&r.add(c);for(let c of d.toolNames??[])typeof c=="string"&&o.add(c);}for(let d of e){let c=d.candidate;if(!c)continue;if(i.has(c.pluginId)||r.has(c.definitionId)){Ne(d,"RESERVED_ID");continue}if(d.provenance===void 0&&(s.has(c.pluginId)||a.has(c.definitionId))){Ne(d,"RESERVED_ID");continue}[c.toolNames.read,c.toolNames.action].filter(y=>y!==void 0).some(y=>o.has(y))&&Ne(d,"DUPLICATE_ID");}}function Wc(e){return [...e].sort((n,t)=>{let i=Do.indexOf(n.source)-Do.indexOf(t.source);return i!==0?i:gn(n.relativePath,t.relativePath)})}function v(e,n,t){e.diagnostic=Bn(n,e.source,e.relativePath,e.identity?.pluginId,t);}async function ko(e,n,t){let i=ve(t,{mode:"local"});if(!i.ok&&i.parseFailure){v(n,Mo(i.rejection.code),So(i.rejection));return}let r=Oc(i.identity);if(n.bundleIdentity===void 0)n.identity=r;else if(r?.pluginId!==n.bundleIdentity.appId||r.definitionKey!==`${n.bundleIdentity.definitionId}\0${String(n.bundleIdentity.version)}`){v(n,"BUNDLE_INTEGRITY");return}if(!i.ok&&i.builtinOnly){v(n,"RESERVED_ID");return}if(!i.ok){v(n,Mo(i.rejection.code),So(i.rejection));return}let o=i.manifest,s={pluginId:o.pluginId,definitionKey:`${o.definitionId}\0${String(o.version)}`};if(n.bundleIdentity===void 0&&(n.identity=s),o.actions.length>0)try{po(o.actions.map(N=>({actionId:N.actionId,inputSchema:N.inputSchema})));}catch(N){if(N instanceof we){v(n,wc(N.code));return}throw N}let a;try{a=await qt(e,n,"ui/index.html",un);}catch(N){v(n,Qe(de(N),"entry"));return}if(a.byteLength>un){v(n,"LIMIT_EXCEEDED");return}let d;try{d=vo(a);}catch{v(n,"ENTRY_INVALID");return}if(a.byteLength===0||d.length===0){v(n,"ENTRY_INVALID");return}let c=createHash("sha256").update(a).digest("hex");if(o.entryHash!==void 0&&o.entryHash!==c){v(n,"ENTRY_INVALID");return}let p={},y,A;if(o.initialState!==void 0){try{y=await qt(e,n,"ui/state.json",65536);}catch(N){v(n,Qe(de(N),"initial"));return}if(y.byteLength>65536){v(n,"LIMIT_EXCEEDED");return}try{let N=Lc(y),oe=o.dataPaths??[],H=_t(N,oe);p=he(H,0,oe),ze(p);}catch{v(n,"INITIAL_STATE_INVALID");return}if(A=createHash("sha256").update(y).digest("hex"),o.initialState.hash!==void 0&&o.initialState.hash!==A){v(n,"INITIAL_STATE_INVALID");return}}let I={...o,entryHash:c,...o.initialState===void 0?{}:{initialState:{path:"ui/state.json",hash:A}}},E=sn(I),O=jc(I,a,y??new Uint8Array),b;try{b=Vc(E,O);}catch(N){if(N instanceof Q){v(n,Rc(N));return}throw N}let j;if(n.bundleLineage!==void 0){let N=n.bundleLineage[n.bundleLineage.length-1];if(!N){v(n,"LINEAGE_INVALID");return}let{legacy:oe,...H}=N.definition,{hash:ge,...me}=b;if(ne(H)!==ne(me)){v(n,"LINEAGE_STALE");return}if(oe!==void 0&&(b={...b,legacy:oe}),oe!==void 0)try{b={...b,hash:pe(b)},Ee(b);}catch{v(n,"LINEAGE_INVALID");return}j=n.bundleLineage;}if(n.bundleIdentity!==void 0&&n.bundleIdentity.appId!==o.pluginId){v(n,"BUNDLE_INTEGRITY");return}if(n.bundleIdentity!==void 0&&(n.bundleIdentity.definitionId!==b.id||n.bundleIdentity.version!==b.version||n.bundleIdentity.definitionHash!==b.hash)){v(n,"LINEAGE_STALE");return}let C=Dc(o.pluginId),x=o.actions.length===0?{read:C.read}:C,B=Fe(E),_=Fe(I),h=Fe(b),S=Fe({...E.handlers}),w=Lo(a),u=y===void 0?void 0:Lo(y),f=Object.freeze({...n.provenance===void 0?{}:{provenance:n.provenance},entry:Object.freeze({path:"ui/index.html",hash:c,bytes:w}),...u===void 0?{}:{initialState:Object.freeze({path:"ui/state.json",hash:A,bytes:u})}}),g={appId:o.pluginId,pluginId:o.pluginId,definitionId:o.definitionId,version:o.version,...i.releaseVersion===void 0?{}:{releaseVersion:i.releaseVersion},manifestFile:i.file,...i.mcpb===void 0?{}:{mcpb:Fe(i.mcpb)},relativePath:n.relativePath,manifest:_,normalized:B,name:o.name,description:o.description,...o.icon===void 0?{}:{icon:o.icon},...o.tone===void 0?{}:{tone:o.tone},definition:h,handlers:S,resources:f,html:d,entryBytes:w,entryHash:c,initialState:Fe(p),...u===void 0?{}:{initialStateBytes:u},...A===void 0?{}:{initialStateHash:A},sourceHash:O,toolNames:Object.freeze(x)},P=n.provenance===void 0?{...g,source:n.source}:{...g,provenance:n.provenance,lineage:j??[]};n.candidate=Object.freeze(P),Fc(o)&&v(n,"EXEC_DENIED");}async function Go(e,n){let t={};for(let i of J)try{t[i]=await qt(e,n,i,262144);}catch(r){if(de(r)==="NOT_FOUND")continue;return {files:t,failure:Qe(de(r),"manifest")}}return {files:t}}function Zt(e){return J.some(n=>e[n]!==void 0)}async function Jc(e,n){let{files:t,failure:i}=await Go(e,n);if(i!==void 0){v(n,i);return}let r=t[Y];return r!==void 0&&!St(r)&&delete t[Y],Zt(t)?t:void 0}function Kc(e,n,t,i=Pc,r=false){let o=Wc(e);$c(o);let s=Object.freeze(o.filter(p=>p.candidate!==void 0&&p.diagnostic===void 0).map(p=>p.candidate)),a=Object.freeze(o.filter(p=>p.diagnostic!==void 0).map(p=>p.diagnostic)),d=r?Object.freeze({...t===void 0?{}:{indexHash:t},candidates:Object.freeze(o.filter(p=>p.source==="bundled"&&p.diagnostic===void 0&&t!==void 0&&p.candidate?.provenance?.indexHash===t).map(p=>p.candidate)),diagnostics:Object.freeze(a.filter(p=>p.source==="bundled").map(p=>Object.freeze({...p}))),reservedAppIds:Object.freeze([...i.appIds]),reservedDefinitionIds:Object.freeze([...i.definitionIds])}):void 0,c={apps:s,diagnostics:a,complete:n===void 0,...n===void 0?{}:{incompleteReason:n},...t===void 0?{}:{productBundleIndexHash:t},...d===void 0?{}:{productBundleSnapshotMetadata:d}};return Object.defineProperty(c,"candidates",{configurable:false,enumerable:false,get:()=>s}),Object.freeze(c)}function Xc(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 Yc(e,n){if(Xc(e))return {fs:e,options:{}};let t=e??n??{};return {fs:t.filesystem??t.fileSystem??t.fs??go,options:t}}async function Wo(e,n,t){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");let{fs:i,options:r}=Yc(n,t),o=r.clock??xc,s=o(),a=await Po(r.productBundle,i,s,o),d=o(),c=BigInt(Date.now())*1000000n,p=[],y=0,A,I=false,E,O;if(r.scanCache!==void 0&&typeof i.getRootIdentity=="function"&&typeof i.fingerprintVerifiedFile=="function")try{O=await i.getRootIdentity(e),E=uo(r.scanCache,O),E.scanStartedAtNs=c;}catch(_){if(de(_)!=="NOT_FOUND")throw _}let b=E!==void 0&&r.productBundle===void 0&&a.packages.length===0&&a.diagnostics.length===0,j=new Set,C=true;p.push(...a.diagnostics.map(_=>({source:_.source,root:r.productBundle?.root??e,name:"",relativePath:_.relativePath,diagnostic:_})));let x=a.reservedIds;a.incomplete&&(A="time_limit");for(let _ of a.packages){if(!be(d,o)){I=true,A="time_limit";break}let h=_.indexEntry,S=h.packageDir,w=_.files===void 0?void 0:Cc(S,_.files),u=a.indexHash===void 0?void 0:eo(Object.freeze({kind:"bundled",launcher:h.launcher!==false,indexHash:a.indexHash,packageDir:S,appId:h.appId,definitionId:h.definition.id,version:h.definition.version,definitionHash:h.definition.hash,files:h.files}),w),f={source:"bundled",root:r.productBundle?.root??e,name:S.slice(5),relativePath:S,...u===void 0?{}:{provenance:u},..._.files===void 0?{}:{pinnedFiles:_.files},..._.lineage===void 0?{}:{bundleLineage:_.lineage},bundleIdentity:{appId:h.appId,definitionId:h.definition.id,version:h.definition.version,definitionHash:h.definition.hash},identity:Uc(h)};if(p.push(f),y+=1,_.failureCode!==void 0){v(f,_.failureCode);continue}let g={};for(let P of J){let N=_.files?.get(P);N!==void 0&&(g[P]=N);}if(!Zt(g)){v(f,"BUNDLE_INTEGRITY");continue}if(await ko(i,f,g),!be(d,o)){I=true,A="time_limit";break}}let B=[{source:"apps",directory:"apps"},{source:"skills",directory:"skills"}];e:for(let _ of B){let{source:h,directory:S}=_,w;try{w=await Hc(i,e,S);}catch(f){if(de(f)==="NOT_FOUND")continue;b=false,C=false,p.push({source:h,root:e,name:"",relativePath:h,diagnostic:Bn(Qe(de(f),"manifest"),h,h)});continue}let u=w.filter(f=>f.kind==="directory"||f.kind==="symlink").filter(f=>Sc(f.name)).map(f=>({source:h,root:e,name:f.name,relativePath:Nc(h,f.name)})).sort((f,g)=>gn(f.relativePath,g.relativePath));for(let f of u){let g={...f};if(p.push(g),O!==void 0?j.add(Fo(O,g)):b=false,!be(d,o)){I=true,A="time_limit";break e}let P;if(E!==void 0&&O!==void 0){try{let H=await vc(i,e,O,g,E,c,d,o);if(H.timeLimitReached){I=!0,A="time_limit";break e}g.scanContext=H.context,P=H.memo;}catch(H){b=false,v(g,Qe(de(H),"manifest"));continue}P===void 0&&(b=false);}if(P!==void 0){if(g.candidate=P.candidate,g.diagnostic=P.diagnostic,g.identity=P.identity,h==="skills"&&P.candidate===void 0&&P.diagnostic===void 0)continue;if(y>=64){v(g,"LIMIT_EXCEEDED");continue}if(f.relativePath.split("/").length-1>2){v(g,"LIMIT_EXCEEDED");continue}if(y+=1,!be(d,o)){I=true,A="time_limit";break e}continue}let N;if(h==="skills"&&(N=await Jc(i,g),N===void 0)){g.diagnostic===void 0&&Yt(g);continue}if(y>=64){v(g,"LIMIT_EXCEEDED");continue}if(f.relativePath.split("/").length-1>2){v(g,"LIMIT_EXCEEDED");continue}if(!be(d,o)){I=true,A="time_limit";break e}if(y+=1,N===void 0){let H=await Go(i,g);if(H.failure!==void 0||!Zt(H.files)){v(g,H.failure??Qe("NOT_FOUND","manifest")),Yt(g);continue}N=H.files;}if(await ko(i,g,N),Yt(g),!be(d,o)){I=true,A="time_limit";break e}}}if(E!==void 0&&O!==void 0){let _=[...j].sort(gn),h=E.lastCandidateKeys,S=h!==void 0&&h.length===_.length&&h.every((u,f)=>u===_[f]);if(b=b&&S,C&&!I&&A===void 0)for(let u of E.candidates.keys())try{JSON.parse(u)[0]===O.realPath&&!j.has(u)&&E.candidates.delete(u);}catch{E.candidates.delete(u);}let w=[...E.candidates.keys()].filter(u=>{try{return JSON.parse(u)[0]===O.realPath}catch{return false}});b=b&&w.length===j.size&&w.every(u=>j.has(u))&&!I&&A===void 0,E.lastCandidateScanUnchanged=b,C&&!I&&A===void 0&&(E.lastCandidateKeys=Object.freeze(_));}return I&&p.push({source:"apps",root:e,name:"",relativePath:"apps",diagnostic:Bn("DISCOVERY_TIME_LIMIT","apps","apps")}),Gc(p,r,x),Kc(p,A,a.indexHash,x,r.productBundle!==void 0)}var Pc,Xt,Do,bc,Oo,Ro,Jo=V(()=>{m();Ce();hn();_e();Mt();Ue();Ct();Rn();fo();Ht();wn();Kt();Kt();Pc=Vn([]),Xt="crewx_local_app_";Do=["bundled","apps","skills"],bc=new TextDecoder("utf-8",{fatal:true});Oo=["","/ui"],Ro=2000000000n;});m();Mt();m();pt();m();var Hi="SKILL.md",La=/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;function zi(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function Oa(e){return e.isDirectory()||e.isSymbolicLink()}function Ki(e){try{return existsSync(e)&&statSync(e).isDirectory()}catch{return false}}function Lt(e){let n;try{n=readFileSync(e,"utf8");}catch{return {frontmatter:{},readable:false,valid:false,hasFrontmatter:false}}let t=n.match(La);if(!t)return {frontmatter:{},readable:true,valid:true,hasFrontmatter:false};try{let i=load(t[1]??"");if(!zi(i))return {frontmatter:{},readable:!0,valid:!1,hasFrontmatter:!0};let r=zi(i.metadata)?i.metadata:void 0;return {frontmatter:{...typeof i.name=="string"?{name:i.name}:{},...typeof(r?.version??i.version)=="string"?{version:r?.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 Ra(e){return [join(e,Hi),join(e,"skill",Hi)]}function $i(e,n){if(!Ki(e))return null;for(let t of Ra(e)){if(!existsSync(t))continue;let r=Lt(t).frontmatter;return {name:r.name??n,...r.version===void 0?{}:{version:r.version},...r.description===void 0?{}:{description:r.description},skillMdPath:t,dir:e}}return null}function Gi(e){try{return readdirSync(e,{withFileTypes:!0}).filter(Oa)}catch{return []}}function Wi(e,n,t){!e||n.has(e.name)||(n.add(e.name),t.push(e));}function Xi(e){let n=[],t=new Set;for(let i of e)if(Ki(i))for(let r of Gi(i)){if(r.name.startsWith("@")){let o=join(i,r.name);for(let s of Gi(o))Wi($i(join(o,s.name),s.name),t,n);continue}Wi($i(join(i,r.name),r.name),t,n);}return n.sort((i,r)=>i.name.localeCompare(r.name))}m();Mn();var wa=/^[A-Za-z0-9_$.[\]"-]{0,200}$/,Ua=/^[a-z][a-z0-9-]{0,63}$/,Ca="<unknown>";function ka(e){return typeof e=="string"&&J.includes(e)}function Yi(e){if(typeof e!="object"||e===null)return;let{file:n,path:t,rule:i}=e;if(!(typeof i!="string"||!Ua.test(i)))return {...ka(n)?{file:n}:{},path:typeof t=="string"&&wa.test(t)?t:Ca,rule:i}}function qi(e){if(!Array.isArray(e))return;let n=J.filter(t=>e.includes(t));return n.length>0?n:void 0}Jo();var Zc=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/;function zn(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?Qc(e.relativePath,e.fileBytes):void 0);if(n!==void 0&&i!==void 0){let r=JSON.stringify({screenHash:n,skillHash:i});return createHash("sha256").update(r,"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 Qc(e,n){let t=new TextEncoder().encode($n(e)),i=ed(n),r=new Uint8Array(t.byteLength+1+i.byteLength);return r.set(t,0),r[t.byteLength]=0,r.set(i,t.byteLength+1),createHash("sha256").update(r).digest("hex")}function ed(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 $n(e){if(typeof e!="string"||e.length===0||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 Hn(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let s=t[o]-i[o];if(s!==0)return s}return t.byteLength-i.byteLength}function Yo(e,n){let t=relative(e,n).split(sep).join("/");return !t||t===".."||t.startsWith("../")||isAbsolute(t)?null:$n(t)}function nd(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 qo(e){return Object.freeze({packageRoot:e})}function td(e){return Object.freeze({id:e.definition.id,version:e.definition.version,hash:e.definition.hash,usage:e.definition.usage??Oe,...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 Zo(e){return {capabilities:Object.freeze([...e]),origin:"local",ownership:"unknown",shareability:"unknown",sharingAvailability:"unavailable"}}function id(e,n){let t=e.candidate,i=t.provenance!==void 0,r=n&&!i?["screen","skill"]:["screen"],o=td(t),s=zn(n?{screenHash:o.hash,skillHash:n.skillHash}:{screenHash:o.hash}),a=t.description||n?.skill.description||"",d=t.releaseVersion??String(t.version),c={appId:t.pluginId,name:t.name,description:a,version:d,...Zo(r),definition:o,...n===void 0||i?{}:{skillName:n.skill.name},...i?{provenance:t.provenance}:{localDefinitionRef:qo(e.packageRoot)},definitionHash:s,...t.manifest.csp===void 0?{}:{connectDomains:Object.freeze([...t.manifest.csp.connectDomains])}};return {...i?{}:{packageRoot:e.packageRoot},source:i?"bundled":t.source,appId:c.appId,capabilities:r,summary:Object.freeze(c)}}function od(e){let n=rd(e.skill.name),t={appId:n,name:e.skill.name,description:e.skill.description??"",...e.skill.version===void 0?{}:{version:e.skill.version},...Zo(["skill"]),skillName:e.skill.name,localDefinitionRef:qo(e.packageRoot),definitionHash:zn({skillHash:e.skillHash})};return {packageRoot:e.packageRoot,source:e.source,appId:n,capabilities:["skill"],summary:Object.freeze(t)}}function rd(e){return `skill.${e.replace(/^@/,"").replace(/\//g,".").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,122)||"unnamed"}`}function K(e,n,t,i,r){let o=Yi(r?.reason),s=qi(r?.files);return Object.freeze({code:e,source:n,relativePath:sd(t),...i===void 0?{}:{appId:i},...o===void 0?{}:{reason:o},...s===void 0?{}:{files:s}})}function sd(e){if(typeof e!="string"||e.length===0||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 Qo(e){return K(e.code,e.source,e.relativePath,e.pluginId,e)}function ad(e,n){let t=Yo(e,n.dir);if(!t)return {diagnostic:K("PATH_ESCAPED","node_modules","node_modules")};let i=nd(t);if(!i)return {diagnostic:K("PATH_ESCAPED","node_modules",t)};let r=Lt(n.skillMdPath);if(!r.readable)return {diagnostic:K("SKILL_READ_FAILED",i,t)};if(!r.valid)return {diagnostic:K("SKILL_INVALID",i,t)};let o=cd(n.dir,n.skillMdPath);if(!o)return {diagnostic:K("PATH_ESCAPED",i,t)};try{let s=new Uint8Array(readFileSync(n.skillMdPath));return {skill:n,packageRoot:t,relativeSkillPath:o,skillHash:zn({relativePath:o,fileBytes:s}),source:i}}catch{return {diagnostic:K("SKILL_READ_FAILED",i,t)}}}function cd(e,n){let t=relative(e,n).split(sep).join("/");try{return $n(t)}catch{return null}}function dd(e){if(!Zc.test(e.appId))return {diagnostic:K("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??Oe,...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??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 pd(e){return e.builtinCatalog}function ld(e){let n=e.packageRoot??e.relativePath??e.packageRootPath;if(n===void 0)return null;try{return $n(n)}catch{return null}}function ud(e){let n=e.marketplaceContentId;return typeof n=="string"&&n.length>0?n:void 0}function fd(e,n,t){let i=n.installed??[],r=new Map;for(let s of i){let a=ld(s);if(!a){t.push(K("INSTALLED_IDENTITY_MISMATCH","installed","installed"));continue}let d=r.get(a);if(d&&JSON.stringify(d)!==JSON.stringify(s)){t.push(K("INSTALLED_IDENTITY_MISMATCH","installed",a));continue}r.set(a,s);}let o=new Map;for(let s of e)s.packageRoot!==void 0&&o.set(s.packageRoot,s);for(let[s,a]of r){let d=o.get(s);if(!d){t.push(K("INSTALLED_MISSING","installed",s,a.appId));continue}let c=ud(a);if(!c){t.push(K("INSTALLED_CONTENT_ID_MISSING","installed",s,a.appId));continue}if(a.appId!==void 0&&a.appId!==d.appId||a.definitionHash!==void 0&&a.definitionHash!==d.summary.definitionHash){t.push(K("INSTALLED_IDENTITY_MISMATCH","installed",s,a.appId));continue}let p={...d.summary,origin:"installed",...a.slug===void 0?{}:{slug:a.slug},marketplaceContentId:c},y=e.indexOf(d);y>=0&&(e[y]={...d,summary:Object.freeze(p)});}}function yd(e,n){let t=new Map;for(let r of e){let o=t.get(r.appId)??[];o.push(r),t.set(r.appId,o);}let i=new Set;for(let r of t.values()){if(r.length<2)continue;let o=r.some(s=>s.source==="builtin")?"builtin":r.some(s=>s.source==="bundled")?"bundled":void 0;if(o!==void 0){let s=r.filter(a=>a.source===o);for(let a of r.filter(d=>d.source!==o))i.add(a),n.push(K("RESERVED_ID",a.source,ei(a),a.appId));if(s.length>1)for(let a of s)i.add(a),n.push(K("DUPLICATE_ID",a.source,ei(a),a.appId));continue}for(let s of r)i.add(s),n.push(K("DUPLICATE_ID",s.source,ei(s),s.appId));}return e.filter(r=>!i.has(r))}function ei(e){return e.packageRoot??e.summary.provenance?.packageDir??`builtin/${e.appId}`}function Ad(e,n){return e.filter(t=>!(t.code==="MANIFEST_MISSING"&&n.has(t.relativePath))).map(Qo)}function Id(e){return e.filesystem}function gd(e,n){let t=Id(e),i=e.registeredProductBundle;return {...t===void 0?{}:{filesystem:t},...e.productBundle===void 0?{}:{productBundle:e.productBundle},...n===void 0?{}:{builtinCatalog:n},...i===void 0?{}:{reservedAppIds:i.reservedAppIds,reservedDefinitionIds:i.reservedDefinitionIds}}}async function er(e,n={}){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");if(n.productBundle!==void 0&&n.registeredProductBundle!==void 0)throw new TypeError("registeredProductBundle cannot be combined with product bundle discovery");let t=pd(n),i=await Wo(e,gd(n,t)),r=n.registeredProductBundle??i.productBundleSnapshotMetadata,o=[join(e,"skills"),join(e,"node_modules"),join(e,"apps")],s=[],a=[],d=[],c=new Set;for(let f of o)for(let g of Xi([f])){let P=Yo(e,g.dir);(P===null||!c.has(P))&&(d.push(g),P!==null&&c.add(P));}for(let f of d){let g=ad(e,f);"diagnostic"in g?s.push(g.diagnostic):a.push(g);}let p=new Map,y=n.registeredProductBundle?.indexHash,A=(n.registeredProductBundle?.candidates??[]).filter(f=>y!==void 0&&f.provenance?.indexHash===y),I=[...i.apps??i.candidates??[],...A],E=new Set(A),O=new Set(y===void 0?[]:(t?.listMcpApps()??[]).filter(f=>f.provenance?.indexHash===y).map(f=>f.appId));for(let f of I){if(E.has(f)&&f.provenance?.indexHash===y&&O.has(f.appId))continue;let g=f.provenance===void 0?`workspace\0${f.relativePath}`:`bundled\0${f.provenance.indexHash}\0${f.provenance.packageDir}`;p.set(g,{candidate:f,packageRoot:f.relativePath});}let b=new Map(a.map(f=>[f.packageRoot,f])),j=[];for(let f of p.values()){let g=f.candidate.provenance===void 0?b.get(f.packageRoot):void 0,P=id(f,g);j.push({...P.packageRoot===void 0?{}:{packageRoot:P.packageRoot},source:P.source,appId:P.appId,summary:P.summary});}let C=new Set([...p.values()].filter(f=>f.candidate.provenance===void 0).map(f=>f.packageRoot)),x=r===void 0?new Set:new Set(i.diagnostics.filter(f=>f.code==="RESERVED_ID"&&f.source!=="bundled").map(f=>f.relativePath)),B=new Set(r?.reservedAppIds??[]);for(let f of a){let g=od(f);if(!(C.has(f.packageRoot)||x.has(f.packageRoot))){if(B.has(g.appId)){s.push(K("RESERVED_ID",f.source,f.packageRoot,g.appId));continue}j.push({packageRoot:g.packageRoot,source:g.source,appId:g.appId,summary:g.summary});}}let _=[...Ad(i.diagnostics,new Set(a.map(f=>f.packageRoot))),...s,...n.registeredProductBundle?.diagnostics.filter(f=>f.source==="bundled").map(Qo)??[]],h=[];if(t)for(let f of t.listMcpApps()){let g=dd(f);"diagnostic"in g?_.push(g.diagnostic):h.push(g);}let S=yd([...j,...h],_);fd(S,n,_);let w=S.map(f=>f.summary).sort((f,g)=>Hn(f.appId,g.appId)),u=[..._].sort((f,g)=>Hn(f.relativePath,g.relativePath)||Hn(f.code,g.code)||Hn(f.appId??"",g.appId??""));return Object.freeze({items:Object.freeze(w),diagnostics:Object.freeze(u)})}m();m();m();function md(e){let n=r=>r.replace(/[.+^${}()|[\]\\]/g,"\\$&"),i=e.split("/").map(r=>r==="**"?".*":r.split("*").map(n).join("[^/]*"));return new RegExp(`^${i.join("\\/")}$`)}function en(e,n){try{return md(n).test(e)}catch{return false}}function Gn(e,...n){let t=e.split("/");if(t.length<n.length)return false;let i=t.length-n.length;return n.every((r,o)=>en(t[i+o],r))}function hd(e,n){return e.split("/").some(t=>en(t,n))}var nr=[{label:".env*",test:e=>en(e,".env*")},{label:".git/",test:(e,n,t)=>t&&e===".git"},{label:"memory/",test:(e,n,t)=>t&&e==="memory"},{label:"*.key",test:e=>en(e,"*.key")},{label:"*.pem",test:e=>en(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&&Gn(n,".crewx","threads")},{label:".crewx/crewx.db",test:(e,n,t)=>!t&&Gn(n,".crewx","crewx.db")},{label:".crewx/*.log",test:(e,n,t)=>!t&&Gn(n,".crewx","*.log")},{label:".crewx/publish/",test:(e,n,t)=>t&&Gn(n,".crewx","publish")},{label:".crewx/",test:(e,n)=>hd(n,".crewx")}];function Wn(e,n,t){for(let i of nr)if(i.test(e,n,t))return i.label;return null}function ii(e){let n=[],t=[];function i(r,o,s){let a;try{a=X.readdirSync(r,{withFileTypes:!0});}catch{return}a.sort((d,c)=>d.name.localeCompare(c.name));for(let d of a){let c=o?`${o}/${d.name}`:d.name,p=ee.join(r,d.name);if(d.isSymbolicLink()){let y;try{y=X.statSync(p);}catch{t.push({path:c,rule:"symlink"});continue}if(y.isDirectory()){t.push({path:c,rule:s??"symlink-dir"});continue}let A=s??Wn(d.name,c,false);A?t.push({path:c,rule:A}):t.push({path:c,rule:"symlink"});continue}if(d.isDirectory()){let y=s??Wn(d.name,c,true);i(p,c,y);continue}if(d.isFile()){let y=s??Wn(d.name,c,false);y?t.push({path:c,rule:y}):n.push(c);}}}return i(e,"",null),n.sort(),t.sort((r,o)=>r.path<o.path?-1:r.path>o.path?1:0),{included:n,excluded:t}}m();var _d=[{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 Ed(e){return e.includes(0)}function oi(e,n,t){let i=[];for(let r of n){let o=ee.join(e,r),s;try{let d=t?.get(r);s=d===void 0?X.readFileSync(o):Buffer.from(d);}catch{continue}if(Ed(s))continue;s.toString("utf8").split(/\r\n|\r|\n/).forEach((d,c)=>{for(let{rule:p,regex:y}of _d)y.test(d)&&i.push({path:r,line:c+1,rule:p});});}return i}m();m();var Se=class extends Error{constructor(t,i){super(`publish: [${t}]${i?` ${i}`:""}`);this.code=t;}code;name="PublishError"};function T(e,n){return new Se(e,n)}var rr=/^[a-z0-9-]+$/,Td=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/,Pd=/^[A-Za-z_][A-Za-z0-9_]*$/;function Dd(e){let n=ee.join(e,"crewx.yaml");if(!X.existsSync(n))return {};let t;try{t=sr.load(X.readFileSync(n,"utf8"));}catch{return {}}if(!t||typeof t!="object")return {};let i=t.metadata;if(!i||typeof i!="object")return {};let r=i;return {name:typeof r.name=="string"?r.name:void 0,version:typeof r.version=="string"?r.version:void 0,description:typeof r.description=="string"?r.description:void 0,requiredEnv:r.requiredEnv,crewxMinVersion:typeof r.crewxMinVersion=="string"?r.crewxMinVersion:void 0}}function bd(e){return ri.createHash("sha256").update(e).digest("hex")}function ar(e){let n;try{n=X.lstatSync(e);}catch{throw T("PACKAGE_FILE_INVALID",`file is not readable: ${ee.basename(e)}`)}if(n.isSymbolicLink())throw T("PACKAGE_SYMLINK","symlink content is not publishable");if(!n.isFile())throw T("PACKAGE_FILE_INVALID","only regular files are publishable");return ri.createHash("sha256").update(new Uint8Array(X.readFileSync(e))).digest("hex")}function Nd(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let s=t[o]-i[o];if(s!==0)return s}return t.byteLength-i.byteLength}function cr(e){if(typeof e!="string"||e.length===0||e.includes("\\")||e.includes("\0")||ee.posix.isAbsolute(e)||e.split("/").some(n=>n===".."||n.length===0))throw T("PACKAGE_PATH_TRAVERSAL","manifest file path must be a non-empty POSIX relative path")}function Sd(e){if(!/^(?:apps|skills)\/[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(e))throw T("APP_PACKAGE_ROOT_INVALID","packageRoot must be apps/<safe-id> or skills/<safe-id>")}function dr(e){if(!Td.test(e))throw new Error(`publish: invalid version "${e}" \u2014 must be semver (e.g. 1.0.0)`)}function pr(e,n,t={}){let i=Dd(e),r=i.name??ee.basename(e);if(!rr.test(r))throw new Error(`publish: invalid name "${r}" \u2014 must match ${rr} (lowercase letters, numbers, hyphen only)`);let o=t.version??i.version;if(!o)throw new Error("publish: version is required \u2014 set crewx.yaml metadata.version or pass opts.version");dr(o);let s=Array.isArray(i.requiredEnv)?i.requiredEnv:[],a=[];for(let p of s){if(typeof p!="string"||!Pd.test(p))throw new Error(`publish: requiredEnv must contain names only (no values), got "${String(p)}"`);a.push(p);}let d=n.map(p=>(cr(p),{path:p,sha256:ar(ee.join(e,p))})).sort((p,y)=>p.path<y.path?-1:p.path>y.path?1:0),c={name:r,version:o,type:"template",description:i.description??"",files:d,requiredEnv:a};return i.crewxMinVersion&&(c.crewxMinVersion=i.crewxMinVersion),c}function Md(e){let n=e.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"");if(!n)throw T("APP_PACKAGE_ROOT_INVALID","appId cannot produce a marketplace name");return n}function lr(e,n){if(Sd(n.packageRoot),!n.version)throw new Error("publish: version is required for App publishing \u2014 pass opts.version");if(dr(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 T("APP_UI_MANIFEST_INVALID","screen App manifests require definitionId");let s=n.includedFiles.includes(`${i}manifest.json`),a=n.includedFiles.includes(`${i}ui-plugin.json`);if(!s&&!a)throw T("APP_UI_MANIFEST_INVALID","screen App is missing manifest.json or ui-plugin.json");if(s&&!a)throw T("APP_UI_MANIFEST_INVALID","a manifest.json App must also ship a generated ui-plugin.json");if(!n.includedFiles.includes(`${i}ui/index.html`))throw T("APP_UI_MANIFEST_INVALID","screen App is missing ui/index.html")}if(t.includes("skill")&&!n.includedFiles.includes(`${i}SKILL.md`))throw T("APP_SKILL_MISSING","skill capability requires package-root SKILL.md");let r=new Set,o=n.includedFiles.map(s=>{if(cr(s),!s.startsWith(i))throw T("PACKAGE_PATH_TRAVERSAL","App manifest file is outside packageRoot");let a=n.generatedFiles?.get(s);return a!==void 0&&r.add(s),{path:s,sha256:a===void 0?ar(ee.join(e,s)):bd(a),...a===void 0?{}:{generated:true}}}).sort((s,a)=>Nd(s.path,a.path));if(r.size>0&&(r.size!==1||!r.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:Md(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:o,requiredEnv:[]}}m();function ur(e){return ri.createHash("sha256").update(e).digest("hex")}function gr(e,n){if(typeof n!="string"||n.length===0||n.includes("\\")||n.includes("\0")||ee.posix.isAbsolute(n)||n.split("/").some(r=>r===".."||r.length===0))throw T("PACKAGE_PATH_TRAVERSAL","archive paths must be non-empty POSIX relative paths");let t=ee.resolve(e),i=ee.resolve(t,...n.split("/"));if(i!==t&&!i.startsWith(`${t}${ee.sep}`))throw T("PACKAGE_PATH_TRAVERSAL","archive path escaped its root");return i}function fr(e,n){let t=gr(e,n),i;try{i=X.lstatSync(t);}catch{throw T("PACKAGE_FILE_INVALID","manifest file is missing")}if(i.isSymbolicLink())throw T("PACKAGE_SYMLINK","symlink content is not publishable");if(!i.isFile())throw T("PACKAGE_FILE_INVALID","only regular files are publishable");return new Uint8Array(X.readFileSync(t))}async function mr(e,n,t={}){let i=ee.join(e,".crewx","publish");X.mkdirSync(i,{recursive:true});let r=ee.join(i,`${n.name}-${n.version}.tgz`),o=ee.join(i,`.${n.name}-${n.version}.${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}.tmp.tgz`),s=X.mkdtempSync(ee.join(yr.tmpdir(),"crewx-publish-"));try{let a=new Set,d=[];for(let c of n.files){if(a.has(c.path))throw T("PACKAGE_PATH_TRAVERSAL","manifest contains duplicate file paths");a.add(c.path);let p=t.generatedFiles?.get(c.path);if(c.generated===!0&&p===void 0)throw T("PACKAGE_GENERATED_FILE_MISSING","generated manifest file bytes are missing");if(t.sourceFileHashes?.has(c.path)){let I=fr(e,c.path);if(t.sourceFileHashes.get(c.path)!==ur(I))throw T("PACKAGE_STAGED_BYTES_MISMATCH","workspace source changed before staging")}let y=p??fr(e,c.path);if(ur(y)!==c.sha256)throw T("PACKAGE_STAGED_BYTES_MISMATCH",`staged bytes differ for ${c.path}`);let A=gr(s,c.path);X.mkdirSync(ee.dirname(A),{recursive:!0}),X.writeFileSync(A,new Uint8Array(y)),d.push(c.path);}X.writeFileSync(ee.join(s,"manifest.json"),JSON.stringify(n,null,2)),await Ir.create({gzip:!0,file:o,cwd:s,portable:!0,noMtime:!0},["manifest.json",...d]),X.renameSync(o,r);}finally{try{X.rmSync(o,{force:!0});}catch{}X.rmSync(s,{recursive:true,force:true});}return r}m();m();var nn="/api/v1";var Rd=201,wd=200,Ud=409,si=401,hr={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 Cd(){return process.env.WI013_FAKE_UPLOAD==="1"}function kd(e){let n=gunzipSync(new Uint8Array(e)),t=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 xd(e){return e.replace(/\/+$/,"")}async function mn(e){try{return await e.json()}catch{return null}}function _r(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 vd(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 jd(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 Er(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,r=[t.code,t.message,i?.code,i?.message];for(let o of r){if(typeof o!="string"||!Object.prototype.hasOwnProperty.call(hr,o))continue;let s=o,a=s==="APP_NAME_CONFLICT"?`marketplace name is already in use: ${n}`:void 0;return T(hr[s],a)}}async function Vd(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=xd(e.baseUrl),t=e.accessPolicy??"private",i=e.manifest.name,r=e.manifest.type==="app"?e.manifest:void 0,o=r!==void 0,s=r?.appId,a;try{a=await fetch(`${n}${nn}/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 d=await mn(a),c=vd(d),p=jd(d),y=o&&p!==void 0?p:i,A;if(a.status===Rd)A="created";else if(o&&a.status===wd){if(c===void 0)throw T("PUBLISH_CONTENT_ID_MISSING","App republish did not return an opaque contentId");A="existing";}else if(a.status===Ud){if(o)throw Er(d,i)??T("APP_NAME_CONFLICT",`marketplace name is already in use: ${i}`);A="existing";}else throw a.status===si?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 I="not-needed",E=null;if(A==="existing"&&!o){let S;try{S=await fetch(`${n}${nn}/publisher/items`,{method:"GET",headers:{Authorization:`Bearer ${e.accessToken}`}});}catch{throw new Error("publish: [E_NETWORK] Publisher items request failed (network)")}let w=await mn(S);if(S.status!==200)throw new Error(`publish: [E_HTTP] Publisher items request failed \u2014 HTTP ${S.status}`);let f=_r(w,"publisher items",S.status)?.items;if(!Array.isArray(f))throw new Error(`publish: [E_MALFORMED] Publisher items response is malformed (expected data.items[]) \u2014 HTTP ${S.status}`);let g=f.find(P=>!P||typeof P!="object"?false:P.slug===i);if(!g||typeof g.version!="string")throw new Error(`publish: [E_MALFORMED] Publisher items response does not contain slug "${i}" \u2014 HTTP ${S.status}`);if(E=g.version,E!==e.manifest.version){let P;try{P=await fetch(`${n}${nn}/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(!P.ok)throw await mn(P),P.status===si?new Error(`publish: [E_AUTH_EXPIRED] Authentication is expired or missing \u2014 please log in again (HTTP ${P.status})`):P.status===403?new Error(`publish: [E_FORBIDDEN] Version update is forbidden; only the item owner can update an existing item (HTTP ${P.status})`):new Error(`publish: [E_HTTP] Version update failed \u2014 HTTP ${P.status}`);I="applied";}}let O=X.readFileSync(e.tgzPath),b=Cd()?kd(O):O,j=new FormData;j.set("archive",new Blob([new Uint8Array(b)],{type:"application/gzip"}),`${y}-${e.manifest.version}.tgz`);let C=o&&c!==void 0?c:i,x;try{x=await fetch(`${n}${nn}/publisher/items/${encodeURIComponent(C)}/upload`,{method:"POST",headers:{Authorization:`Bearer ${e.accessToken}`},body:j});}catch{throw new Error("publish: [E_NETWORK] Upload request failed (network)")}if(x.status===si)throw new Error("publish: [E_AUTH_EXPIRED] Authentication is expired or missing \u2014 please log in again (HTTP 401)");if(!x.ok){let S=await mn(x);if(o){let w=Er(S,y);if(w)throw w}throw new Error(`publish: [E_HTTP] Upload request failed \u2014 HTTP ${x.status}`)}let B=await mn(x),_=_r(B,"upload",x.status),h=typeof _.contentId=="string"&&_.contentId.length>0?_.contentId:c;if(o&&h===void 0)throw T("PUBLISH_CONTENT_ID_MISSING","App upload did not return an opaque contentId");return {slug:y,version:e.manifest.version,...h===void 0?{}:{contentId:h},artifactChecksum:_.artifactChecksum,artifactSizeBytes:_.artifactSizeBytes,submitOutcome:A,versionUpdate:I,serverVersionBefore:E}}var Fd=1e4,Bd=100*1024*1024;function ai(e){return ri.createHash("sha256").update(e).digest("hex")}function Hd(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function Kn(e,n){if(!n||n.includes("\\")||n.includes("\0")||ee.posix.isAbsolute(n)||n.split("/").some(o=>o===".."||o.length===0))throw T("PACKAGE_PATH_TRAVERSAL","workspace file path is not a safe relative path");let t=ee.resolve(e,...n.split("/")),i=ee.resolve(e);if(t!==i&&!t.startsWith(`${i}${ee.sep}`))throw T("PACKAGE_PATH_TRAVERSAL","workspace file path escaped the workspace root");let r;try{r=X.lstatSync(t);}catch{throw T("PACKAGE_FILE_INVALID",`workspace file is missing: ${n}`)}if(r.isSymbolicLink())throw T("PACKAGE_SYMLINK",`symlink is not publishable: ${n}`);if(!r.isFile())throw T("PACKAGE_FILE_INVALID",`not a regular file: ${n}`);return new Uint8Array(X.readFileSync(t))}function Xn(e,n){return e===n||e.startsWith(`${n}/`)}function zd(e,n){return e.path<n.path?-1:e.path>n.path?1:e.rule.localeCompare(n.rule)}function Pr(e,n,t){let i=e??n;if(!Number.isSafeInteger(i)||i<=0)throw new Se("PACKAGE_SIZE_LIMIT",`${t} must be a positive integer`);return i}function br(e,n,t,i){let r=Pr(t.maxFileCount??t.maxFiles,Fd,"max file count"),o=Pr(t.maxTotalBytes??t.maxBytes,Bd,"max total bytes");if(n.length>r)throw new Se("PACKAGE_SIZE_LIMIT",`package exceeds file count limit (${r})`);let s=0;for(let a of n){let d=i?.get(a);if(d!==void 0?s+=d.byteLength:s+=Kn(e,a).byteLength,s>o)throw new Se("PACKAGE_SIZE_LIMIT",`package exceeds byte limit (${o})`)}}function $d(e){return e.appId!==void 0||e.expectedDefinitionHash!==void 0}function Gd(e){let n=e.appId!==void 0,t=e.expectedDefinitionHash!==void 0;if(!n&&t)throw T("APP_ID_REQUIRED","appId is required with expectedDefinitionHash");if(n&&!t)throw T("APP_DEFINITION_HASH_REQUIRED","expectedDefinitionHash is required with appId");if(!n||!t)throw T("APP_ID_REQUIRED")}function Wd(e,n){let t=e.filter(i=>i.appId===n);if(t.length===0)throw T("APP_NOT_FOUND",`no publishable App matches ${n}`);if(t.length!==1)throw T("APP_AMBIGUOUS",`more than one App matches ${n}`);return t[0]}function Jd(e){let n=e.localDefinitionRef?.packageRoot;if(!n||!/^(?:apps|skills)\/[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(n))throw T("APP_PACKAGE_ROOT_INVALID","selected App is not rooted in apps/<safe-id> or skills/<safe-id>");return n}function Kd(e,n){let t=[];for(let i of e.excluded)t.push(Xn(i.path,n)?i:{path:i.path,rule:"out-of-app-scope"});for(let i of e.included)Xn(i,n)||t.push({path:i,rule:"out-of-app-scope"});return t.sort(zd)}function ci(e){let{path:n,rule:t}=e.reason;return `${e.code} at ${n===""?"<file>":n} (${t})`+(e.files.length>0?` [${e.files.join(", ")}]`:"")}function Xd(e,n,t){let i=ve({[ie]:t},{mode:"published"});if(!i.ok)throw T("APP_UI_MANIFEST_INVALID",`generated ${ie} does not read: ${ci(i.rejection)}`);if(Xe(i.manifest)!==Xe(n))throw T("APP_UI_MANIFEST_INVALID",`generated ${ie} normalizes to a different definition hash than the source`);let r=e[Y];if(r===void 0)return;let o=ve({[Y]:r,[ie]:t},{mode:"local"});if(!o.ok)throw T("APP_UI_MANIFEST_INVALID",ci(o.rejection))}function Yd(e,n,t,i){let r={};for(let A of J){let I=`${t}/${A}`;i.includes(I)&&(r[A]=Kn(e,I));}if(Object.keys(r).length===0)throw T("APP_UI_MANIFEST_INVALID","selected screen App has no package manifest.json or ui-plugin.json");let o=ve(r,{mode:"local"});if(!o.ok)throw T("APP_UI_MANIFEST_INVALID",ci(o.rejection));if(o.manifest.pluginId!==n.appId)throw T("APP_DEFINITION_CONFLICT",`${o.file} identity no longer matches the selected App`);let s=r[ie],a=s===void 0?void 0:ai(s),d=`${t}/ui/index.html`;if(!i.includes(d))throw T("APP_UI_MANIFEST_INVALID","screen entry is outside package scope");let c=ai(Kn(e,d)),p=JSON.parse(JSON.stringify(o.v2Input));if(p.entryHash=c,Object.prototype.hasOwnProperty.call(p,"initialState")){let A=p.initialState;if(!Hd(A)||A.path!=="ui/state.json")throw T("APP_INITIAL_STATE_OUT_OF_SCOPE","initialState must reference ui/state.json inside the package");let I=`${t}/ui/state.json`;if(!i.includes(I))throw T("APP_INITIAL_STATE_OUT_OF_SCOPE","initialState reference is outside the selected package");let E=Kn(e,I);p.initialState={...A,hash:ai(E)};}let y;try{let A=xe(p,{mode:"published"});y=new Uint8Array(Buffer.from(JSON.stringify(A),"utf8"));}catch(A){throw A instanceof Q?T("APP_UI_MANIFEST_INVALID",A.code):T("APP_UI_MANIFEST_INVALID")}return Xd(r,o.manifest,y),{bytes:y,...a===void 0?{}:{legacySourceHash:a}}}async function qd(e,n){let{included:t,excluded:i}=ii(e);br(e,t,n);let r=pr(e,t,{version:n.version}),o=oi(e,t);return {plan:{manifest:r,included:t,excluded:i,secretFindings:o},archiveOptions:{}}}async function Zd(e,n){Gd(n);let t=await er(e),i=Wd(t.items,n.appId);if(i.definitionHash!==n.expectedDefinitionHash)throw T("APP_DEFINITION_CONFLICT",`definitionHash changed for ${n.appId}`);let r=Jd(i),o=ii(e);if(o.excluded.some(I=>Xn(I.path,r)&&(I.rule==="symlink"||I.rule==="symlink-dir")))throw T("PACKAGE_SYMLINK","selected App package contains a symlink");let s=o.included.filter(I=>Xn(I,r)),a=Kd(o,r),d=new Map,c=new Map;if(i.capabilities.includes("screen")){let I=Yd(e,i,r,s),E=`${r}/${ie}`;d.set(E,I.bytes),I.legacySourceHash!==void 0?c.set(E,I.legacySourceHash):(s.push(E),s.sort());}if(i.capabilities.includes("skill")&&!s.includes(`${r}/SKILL.md`))throw T("APP_SKILL_MISSING","skill capability requires package-root SKILL.md");br(e,s,n,d);let p={appId:i.appId,version:n.version??"",description:i.description,capabilities:i.capabilities,packageRoot:r,...i.definition?.id===void 0?{}:{definitionId:i.definition.id},definitionHash:i.definitionHash,includedFiles:s,generatedFiles:d},y=lr(e,p),A=oi(e,s,d);return {plan:{manifest:y,included:s,excluded:a,secretFindings:A},archiveOptions:{generatedFiles:d,sourceFileHashes:c}}}async function Nr(e,n){let t=ee.resolve(e);if($d(n))return Zd(t,n);if(n.expectedDefinitionHash!==void 0)throw T("APP_ID_REQUIRED");return qd(t,n)}async function Vf(e,n={}){return (await Nr(e,n)).plan}function Qd(e){let n=e.map(t=>`${t.path}:${t.line} (${t.rule})`).join(", ");throw new Se("PUBLISH_SECRET_FINDINGS",`aborted \u2014 secret findings must be resolved before packing: ${n}`)}async function Sr(e,n={}){let t=ee.resolve(e),i=await Nr(t,n);i.plan.secretFindings.length>0&&Qd(i.plan.secretFindings);let r=await mr(t,i.plan.manifest,i.archiveOptions);return {manifest:i.plan.manifest,tgzPath:r}}async function Ff(e,n={}){return Sr(e,n)}async function Bf(e,n){let t=await Sr(e,n);if(t.manifest.type!=="app")throw new Error("publish: App pack unexpectedly produced a template manifest");return t}
|
|
2
|
-
export{
|
|
1
|
+
import*as ee from'path';import {resolve,relative,sep,isAbsolute,join}from'path';import'url';import*as ri from'crypto';import {createHash}from'crypto';import {isIP}from'net';import*as X from'fs';import {constants,readFileSync,existsSync,statSync,readdirSync}from'fs';import {realpath,stat,readdir,open,lstat}from'fs/promises';import*as cr from'js-yaml';import {load}from'js-yaml';import*as Ir from'os';import*as mr from'tar';import {gunzipSync,gzipSync}from'zlib';var V=(e,n)=>()=>(e&&(n=e(e=0)),n);var m=V(()=>{});var R,hn=V(()=>{m();R=class extends Error{constructor(t,i=t,r){super(i);this.code=t;this.currentRevision=r;}code;currentRevision;name="UiRuntimeError"};});function Qn(e){return Rr.test(e)||wr.test(e)}function se(){throw new R("INPUT_INVALID","JSON value is not projection-safe")}function xr(e){let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function qn(e,n,t,i,r,o){if(n>i&&se(),e===null||typeof e=="string"||typeof e=="boolean")return typeof e=="string"&&(Ur.test(e)||kr.test(e)&&!Vr(r,o)||Cr.test(e))&&se(),e;if(typeof e=="number")return Number.isFinite(e)||se(),e;(typeof e!="object"||e===void 0||typeof e=="function"||typeof e=="bigint")&&se();let s=e;t.has(s)&&se(),t.add(s);try{if(Array.isArray(e))return e.map(d=>qn(d,n+1,t,i,r,o));xr(s)||se();let a={};for(let[d,c]of Object.entries(e))Qn(d)&&se(),a[d]=qn(c,n+1,t,i,[...r,d],o);return a}finally{t.delete(s);}}function he(e,n=0,t=[]){(!Number.isInteger(n)||n<0||n>jr)&&se(),(!Array.isArray(t)||t.some(r=>typeof r!="string"))&&se();let i=qn(e,0,new Set,vr+n,[],t);return (i===null||Array.isArray(i)||typeof i!="object")&&se(),i}function He(e,n){if(!e||!n)return false;let t=e.split("."),i=n.split(".");return t.length>=i.length&&i.every((r,o)=>t[o]===r)}function Vr(e,n){if(e.length===0)return false;let t=e.join(".");return n.some(i=>He(t,i))}function ze(e){try{let n=JSON.stringify(e);return n===void 0&&se(),n}catch{se();}}function Zn(e){return Array.isArray(e)?e.map(Zn):e!==null&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,Zn(e[n])])):e}function ne(e){return ze(Zn(e))}function et(e){return Buffer.byteLength(e,"utf8")}var Rr,wr,Ur,Cr,kr,vr,jr,_e=V(()=>{m();hn();Rr=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,wr=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i,Ur=/<\/?[A-Za-z][^>]*>/,Cr=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,kr=/^(?:https?|file|ftp|ws|wss):\/\//i;vr=8,jr=4;});var di=V(()=>{m();_e();});function $e(e){return Fr.has(e)||Br.test(e)||Hr.test(e)}var pi,Fr,Br,Hr,_n,tn,fe,nt,tt,it,ot,rt,Ue=V(()=>{m();pi=["__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"],Fr=new Set(pi),Br=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,Hr=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i;_n=/^[A-Za-z0-9_]+$/,tn=/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/,fe=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,nt=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,tt=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,it=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/,ot=["blue","violet","emerald","amber","rose","sky","slate","indigo"],rt=["inline","panel"];});function st(e){return typeof e=="string"&&li.includes(e)}var li,ui=V(()=>{m();Ue();li=["text/plain","application/json"];});function En(e){if(!at(e))return false;let n=Object.keys(e);return !(n.some(t=>t!=="in"&&t!=="out")||n.length===0||Object.hasOwn(e,"in")&&!zr(e.in)||Object.hasOwn(e,"out")&&!$r(e.out))}function zr(e){return at(e)?Object.keys(e).every(t=>t==="mediaType"||t==="required")&&Object.hasOwn(e,"mediaType")&&st(e.mediaType)&&(!Object.hasOwn(e,"required")||typeof e.required=="boolean"):false}function $r(e){return at(e)?Object.keys(e).every(t=>t==="mediaType"||t==="range")&&Object.hasOwn(e,"mediaType")&&st(e.mediaType)&&(!Object.hasOwn(e,"range")||typeof e.range=="boolean"):false}function at(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var ct=V(()=>{m();ui();new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});});function pe(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(r=>r.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=he(t);return createHash("sha256").update(ne(i)).digest("hex")}function Ee(e){if(!/^\d+$/.test(String(e.version))||e.version<1||e.id.length<1||e.id.length>128)throw new R("DEFINITION_UNSUPPORTED","UI definition is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!Wr.test(e.sourceHash)))throw new R("DEFINITION_UNSUPPORTED","UI definition source hash is invalid");if(!/^[0-9a-f]{64}$/.test(e.hash)||pe(e)!==e.hash)throw new R("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=>!Kr(i)))throw new R("DEFINITION_UNSUPPORTED","UI action declaration is invalid");if(t.confirmation!==void 0&&t.confirmation!=="none"&&t.confirmation!=="native")throw new R("DEFINITION_UNSUPPORTED","UI action confirmation is invalid");if(t.inputKeys&&(!Array.isArray(t.inputKeys)||t.inputKeys.some(i=>typeof i!="string"||!i)))throw new R("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 R("DEFINITION_UNSUPPORTED","UI action data input declaration is invalid");if(t.resultProjection&&dt(t.resultProjection),t.content!==void 0&&!En(t.content))throw new R("DEFINITION_UNSUPPORTED","UI action content declaration is invalid");if(t.env!==void 0&&(!Array.isArray(t.env)||t.env.length===0||new Set(t.env).size!==t.env.length||t.env.some(i=>i!=="CREWX_APP_INSTANCE_ID"&&i!=="CREWX_THREAD_ID")))throw new R("DEFINITION_UNSUPPORTED","UI action environment declaration is invalid")}if(e.renderer!==void 0&&(!e.renderer||e.renderer.length>128))throw new R("DEFINITION_UNSUPPORTED","UI definition renderer is invalid");if(e.surfaces&&(!Array.isArray(e.surfaces)||e.surfaces.some(n=>!n||n.length>64)))throw new R("DEFINITION_UNSUPPORTED","UI definition surfaces are invalid");if(e.usage!==void 0&&e.usage!=="card"&&e.usage!=="window")throw new R("DEFINITION_UNSUPPORTED","UI definition usage is invalid");if(e.detailPanel!==void 0&&typeof e.detailPanel!="boolean")throw new R("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 R("DEFINITION_UNSUPPORTED","UI definition displayModes are invalid");if(e.usage==="card"&&e.displayModes!==void 0)throw new R("DEFINITION_UNSUPPORTED","Card definitions cannot declare displayModes");if(e.usage==="window"&&e.detailPanel!==void 0)throw new R("DEFINITION_UNSUPPORTED","Window definitions cannot declare detailPanel");if(e.stateProjection&&dt(e.stateProjection),e.summaryProjection){dt(e.summaryProjection);let n=new Set(e.stateProjection?.allow??[]);if(e.summaryProjection.allow.some(t=>!n.has(t)))throw new R("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(r=>!["readTool","actionTool","hostTools","agentAccess"].includes(r)))throw new R("DEFINITION_UNSUPPORTED","UI legacy metadata is invalid");let n=new Set;for(let[r,o]of [["readTool",e.legacy.readTool],["actionTool",e.legacy.actionTool]])if(o!==void 0){if(Jr(o,r==="readTool"),n.has(o.name))throw new R("DEFINITION_UNSUPPORTED","UI legacy tool names collide");n.add(o.name);}let t=e.legacy.hostTools;if(t!==void 0){if(!t||typeof t!="object"||Array.isArray(t))throw new R("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");let r={"doc.open":"crewx_app_html_viewer_open","pty.connect":"crewx_app_terminal_connect"};for(let[o,s]of Object.entries(t)){if(!Object.hasOwn(r,o)||r[o]!==s||typeof s!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(s)||n.has(s))throw new R("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(([r,o])=>!r||!Object.hasOwn(e.actions,r)||o!=="allowed"&&o!=="denied")))throw new R("DEFINITION_UNSUPPORTED","UI legacy agent access is invalid");if(e.legacy.actionTool!==void 0&&(!i||Object.keys(i).length===0))throw new R("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=>He(t,i))))throw new R("DEFINITION_UNSUPPORTED","UI definition dataPaths are invalid")}}function Jr(e,n){if(!e||typeof e!="object"||Array.isArray(e))throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");let t=e,i=["name","description","inputSchema","textFallback","visibility"],r=Object.hasOwn(t,"fixedResult");if(Object.keys(t).some(o=>!i.includes(o)&&!(n&&o==="fixedResult"))||i.some(o=>!Object.hasOwn(t,o))||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(o=>o!=="model"&&o!=="app")||new Set(t.visibility).size!==t.visibility.length)throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");try{let o=he(t.inputSchema);if(o.type!==void 0&&o.type!=="object")throw new Error("schema type");if(r){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 d=he(a.structuredContent);if(et(ze(d))>4*1024)throw new Error("fixed result size")}}catch{throw new R("DEFINITION_UNSUPPORTED","UI legacy tool metadata is not projection-safe")}}function dt(e){if(!Array.isArray(e.allow)||e.allow.some(n=>!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(n)))throw new R("DEFINITION_UNSUPPORTED","UI projection policy is invalid")}function Kr(e){return e.length>0&&e.length<=128&&e!=="*"&&e!=="all"&&!/[/*]/.test(e)}var Wr,Ce=V(()=>{m();_e();hn();ct();Wr=/^[0-9a-f]{64}$/;});var Oe,pt=V(()=>{m();Oe="window";});function fi(e){if(!Array.isArray(e)||e.length===0)return false;let n=new Set;for(let t of e){if(!Xr.some(i=>i===t)||n.has(t))return false;n.add(t);}return true}var Xr,yi=V(()=>{m();Xr=["CREWX_APP_INSTANCE_ID","CREWX_THREAD_ID"];});function F(e){throw new lt(e)}function as(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 cs(e,n){let t=Object.getOwnPropertyDescriptor(e,n);return (!t||!("value"in t))&&F("CSP_ORIGIN_INVALID"),t.value}function Tn(e,n){if(!Object.prototype.hasOwnProperty.call(e,n))return [];let t=cs(e,n);Array.isArray(t)||F("CSP_ORIGIN_INVALID"),Reflect.ownKeys(t).some(o=>typeof o!="string"||o!=="length"&&!/^(?:0|[1-9][0-9]*)$/.test(o))&&F("CSP_ORIGIN_INVALID");let r=[];for(let o=0;o<t.length;o+=1)(!Object.prototype.hasOwnProperty.call(t,o)||typeof t[o]!="string")&&F("CSP_ORIGIN_INVALID"),r.push(t[o]);return Object.keys(t).length!==t.length&&F("CSP_ORIGIN_INVALID"),r}function ds(e){let n;try{n=JSON.stringify(e);}catch{F("CSP_ORIGIN_INVALID");}return n===void 0&&F("CSP_ORIGIN_INVALID"),new TextEncoder().encode(n).byteLength}function gi(e,n){/\s|\\/u.test(e)&&F("CSP_ORIGIN_INVALID");let t=ts.exec(e);t||F("CSP_ORIGIN_INVALID");let i=t[1].toLowerCase(),r=t[2];(r.includes("@")||r.includes("%")||r.includes("*"))&&F("CSP_ORIGIN_INVALID"),(r.startsWith("[")?is:os).test(r)||F("CSP_ORIGIN_INVALID"),i==="wss"&&n!=="connectDomains"&&F("CSP_ORIGIN_INVALID");let s;try{s=new URL(e);}catch{F("CSP_ORIGIN_INVALID");}(s.protocol!==`${i}:`||s.username!==""||s.password!==""||s.search!==""||s.hash!=="")&&F("CSP_ORIGIN_INVALID");let a=s.hostname.toLowerCase();if((!a||a.includes("%"))&&F("CSP_ORIGIN_INVALID"),!a.startsWith("[")){let c=a.endsWith(".")?a.slice(0,-1):a;(c.length===0||c.length>253)&&F("CSP_ORIGIN_INVALID"),c.split(".").some(y=>y.length>63||!rs.test(y))&&F("CSP_ORIGIN_INVALID");}let d=s.origin;return (d==="null"||!d.startsWith(`${i}://`))&&F("CSP_ORIGIN_INVALID"),{origin:d,hostname:a}}function ps(e){let n=e.split(".").map(Number);return ((n[0]*256+n[1])*256+n[2])*256+n[3]}function mi(e,n,t){let i=4294967295<<32-t>>>0;return (e&i)===(n&i)}function Ei(e){let n=ps(e);return mi(n,3221225472,24)?n!==3221225481&&n!==3221225482:ss.some(([t,i])=>mi(n,t,i))}function ls(e){let n=e.indexOf("::"),t=(n<0?e:e.slice(0,n)).split(":").filter(Boolean),i=n<0?[]:e.slice(n+2).split(":").filter(Boolean);return (n<0?t:[...t,...Array(8-t.length-i.length).fill("0"),...i]).reduce((o,s)=>o<<16n|BigInt(Number.parseInt(s,16)),0n)}function us(e){let n=ls(e),t=Number(n>>112n),i=Number(n>>96n&0xffffn);if(n>>32n===0xffffn){let r=Number(n&0xffffffffn);return Ei([r>>>24&255,r>>>16&255,r>>>8&255,r&255].join("."))}return t<8192||t>16383||t===8193&&i<=511||t===8193&&i===3512||t===8194||t===16383&&i<=4095}function fs(e,n){let t=e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e,i=isIP(t);if(i===4)return Ei(t);if(i===6)return us(t);let r=e.toLowerCase().replace(/\.$/,"");return !r||!r.includes(".")||n.has(r)?true:ns.some(o=>r===o||r.endsWith(`.${o}`))}function hi(e){return Object.freeze([...new Set(e.map(n=>n.origin))].sort())}function _i(e){return JSON.stringify({baseUriDomains:[],connectDomains:e.connectDomains,declared:e.declared,frameDomains:e.frameDomains,resourceDomains:[]})}function Ti(e,n={}){if(e===void 0){let I=_i({declared:false,connectDomains:[],frameDomains:[]});return Object.freeze({declared:false,connectDomains:Object.freeze([]),frameDomains:Object.freeze([]),resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:createHash("sha256").update(I,"utf8").digest("hex")})}as(e)||F("CSP_ORIGIN_INVALID");let t=Reflect.ownKeys(e);t.some(I=>typeof I!="string")&&F("CSP_ORIGIN_INVALID"),t.some(I=>!es.has(I))&&F("CSP_AXIS_UNKNOWN");let i=Tn(e,"connectDomains"),r=Tn(e,"frameDomains"),o=Tn(e,"resourceDomains"),s=Tn(e,"baseUriDomains");(o.length>0||s.length>0)&&F("CSP_AXIS_UNSUPPORTED"),(ds(e)>qr||i.length>Ii||r.length>Ii||i.length+r.length>Zr||[...i,...r].some(I=>new TextEncoder().encode(I).byteLength>Qr))&&F("CSP_LIMIT_EXCEEDED");let d=i.map(I=>gi(I,"connectDomains")),c=r.map(I=>gi(I,"frameDomains")),p=new Set((n.runtimeHostnames??[]).map(I=>I.toLowerCase().replace(/\.$/,"")));[...d,...c].some(I=>fs(I.hostname,p))&&F("CSP_ORIGIN_FORBIDDEN");let y={declared:true,connectDomains:hi(d),frameDomains:hi(c)},A=_i(y);return Object.freeze({...y,resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:createHash("sha256").update(A,"utf8").digest("hex")})}var qr,Ii,Zr,Qr,es,ns,ts,is,os,rs,ss,lt,Pi=V(()=>{m();qr=4096,Ii=16,Zr=32,Qr=512,es=new Set(["connectDomains","frameDomains","resourceDomains","baseUriDomains"]),ns=["localhost","local","internal","home.arpa","test","example","invalid","onion","lan","corp","home","intranet","private","localdomain"],ts=/^(https|wss):\/\/([^/?#]+)$/i,is=/^\[[^\]]+\](?::[0-9]+)?$/,os=/^[^:\[\]]+(?::[0-9]+)?$/,rs=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/,ss=[[0,8],[1681915904,10],[167772160,8],[2130706432,8],[2851995648,16],[2886729728,12],[3221225984,24],[3227017984,24],[3232235520,16],[3323068416,15],[3325256704,24],[3405803776,24],[3758096384,4],[4026531840,4]],lt=class extends Error{constructor(t){super(t);this.code=t;}code;name="UiPluginCspNormalizationError"};});function rn(e,n){return n===void 0||n===""?e:e===""?n:n.startsWith("[")?`${e}${n}`:`${e}.${n}`}function l(e,n=e,t,i){throw new Q(e,n,t,i)}function z(e,n){try{return n()}catch(t){throw t instanceof Q?t.withPathPrefix(e):t}}function $(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 U(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Fs(e,n){let t={};for(let[i,r]of Object.entries(e))i!==n&&(t[i]=r);return t}function G(e,n,t=[]){let i=new Set([...n,...t]),r=Object.keys(e).find(s=>!i.has(s));r!==void 0&&l("MANIFEST_INVALID","MANIFEST_INVALID",r,"unknown-key");let o=n.find(s=>!U(e,s));o!==void 0&&l("MANIFEST_INVALID","MANIFEST_INVALID",o,"missing-key");}function Nn(e,n=false,t=false,i=false){return gs.test(e)||!i&&hs.test(e)||ms.test(e)||t&&Di.test(e)||_s.test(e)&&!(n&&/^\s*data:/i.test(e)&&!Di.test(e))}function bn(e,n=new Set,t=0,i=false,r=false,o=""){if(typeof e=="string"){Nn(e,i,r)&&l("UNSAFE_VALUE","UNSAFE_VALUE",o,"unsafe-value");return}if(!(e===null||typeof e!="object")){(t>8||n.has(e))&&l("MANIFEST_INVALID","MANIFEST_INVALID",o),n.add(e);try{if(Array.isArray(e)){e.forEach((s,a)=>bn(s,n,t+1,!1,!1,rn(o,`[${a}]`)));return}$(e)||l("MANIFEST_INVALID","MANIFEST_INVALID",o);for(let[s,a]of Object.entries(e))bn(a,n,t+1,i&&t===0&&(s==="name"||s==="description"),r,rn(o,s));}finally{n.delete(e);}}}function ye(e,n){let t=e[n];return typeof t!="string"&&l("MANIFEST_INVALID"),t}function le(e,n,t){let i=e[n];return (!Number.isSafeInteger(i)||i<t)&&l("MANIFEST_INVALID"),i}function ut(e){return Is.test(e)||l("MANIFEST_INVALID"),e}function Ge(e){return As.test(e)||l("TOKEN_INVALID"),e}function Bs(e){return Ui.test(e)||l("MANIFEST_INVALID"),e}function Hs(e){$(e)||l("MANIFEST_INVALID");let n={};for(let[t,i]of Object.entries(e)){let r=Bs(t);$(i)||l("MANIFEST_INVALID");let o=i.type;if(o==="text"){G(i,["type","maxLength"]),n[r]={type:o,maxLength:le(i,"maxLength",1)};continue}if(o==="text-list"){G(i,["type","max","itemMaxLength"]),n[r]={type:o,max:le(i,"max",0),itemMaxLength:le(i,"itemMaxLength",1)};continue}if(o==="step-list"){G(i,["type","min","max","labelMaxLength","detailMaxLength"]);let s=le(i,"min",0),a=le(i,"max",1);s>a&&l("MANIFEST_INVALID"),n[r]={type:o,min:s,max:a,labelMaxLength:le(i,"labelMaxLength",1),detailMaxLength:le(i,"detailMaxLength",1)};continue}typeof o=="string"&&l("SCHEMA_TYPE_UNSUPPORTED"),l("MANIFEST_INVALID");}return n}function zs(e,n,t){let i=e[n];(!i||i.type!==t)&&l("MANIFEST_INVALID");}function Pn(e,n,t){let i=ye(e,"field");return Ui.test(i)||l("MANIFEST_INVALID"),zs(n,i,t),i}function $s(e,n){$(e)||l("MANIFEST_INVALID");let t=e.primitive;switch(typeof t!="string"&&l("MANIFEST_INVALID"),Vs.includes(t)||l("PRIMITIVE_UNKNOWN"),t){case "card-shell":return G(e,["primitive"]),{primitive:t};case "meta-banner":return G(e,["primitive","badgeToken","noticeToken"]),{primitive:t,badgeToken:Ge(ye(e,"badgeToken")),noticeToken:Ge(ye(e,"noticeToken"))};case "heading":return G(e,["primitive","field"]),{primitive:t,field:Pn(e,n,"text")};case "labeled-text":return G(e,["primitive","titleToken","field","variant"]),e.variant!=="callout"&&l("MANIFEST_INVALID"),{primitive:t,titleToken:Ge(ye(e,"titleToken")),field:Pn(e,n,"text"),variant:"callout"};case "step-flow":return G(e,["primitive","titleToken","field"]),{primitive:t,titleToken:Ge(ye(e,"titleToken")),field:Pn(e,n,"step-list")};case "text-list":{G(e,["primitive","titleToken","field"],["emptyToken","hideWhenEmpty"]);let i={primitive:t,titleToken:Ge(ye(e,"titleToken")),field:Pn(e,n,"text-list")};return U(e,"emptyToken")&&(i.emptyToken=Ge(ye(e,"emptyToken"))),U(e,"hideWhenEmpty")&&(typeof e.hideWhenEmpty!="boolean"&&l("MANIFEST_INVALID"),i.hideWhenEmpty=e.hideWhenEmpty),i}}return l("MANIFEST_INVALID")}function Gs(e,n){return Array.isArray(e)||l("MANIFEST_INVALID"),e.map(t=>$s(t,n))}function W(e="v2 manifest exceeds a contract limit",n,t){return l("LIMIT_EXCEEDED",e,n,t)}function ae(e="initial state is not projection-safe"){return l("INITIAL_STATE_INVALID",e)}function bi(e,n){return (typeof e!="string"||e.length===0||e.length>4096||e.trim().length===0||xs.test(e)||vs.test(e))&&l("MANIFEST_INVALID",`${n} is invalid`),(Nn(e,true,true)||Es.test(e)||Ts.test(e)||Ps.test(e))&&l("UNSAFE_VALUE",`${n} contains an unsafe value`),e}function ft(e,n){return (typeof e!="string"||!fe.test(e))&&l("MANIFEST_INVALID",`${n} is invalid`),e}function Ws(e){return (typeof e!="string"||!nt.test(e)||e==="*"||e==="all")&&l("MANIFEST_INVALID","action capability is invalid"),e}function Ci(e){return (typeof e!="string"||!ks.test(e))&&l("MANIFEST_INVALID","resource hash is invalid"),e}function yt(e,n=new Set,t=0,i=""){if(typeof e=="string"){e.length>4096&&W("v2 manifest string is too long",i,"string-too-long");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||l("MANIFEST_INVALID","v2 manifest contains a non-finite number",i,"non-finite-number");return}(e===void 0||typeof e=="function"||typeof e=="bigint")&&l("MANIFEST_INVALID","v2 manifest contains a non-JSON value",i,"non-json-value"),typeof e!="object"&&l("MANIFEST_INVALID","MANIFEST_INVALID",i),t>8&&W("v2 manifest nesting is too deep",i,"too-deep"),n.has(e)&&l("MANIFEST_INVALID","v2 manifest contains a cycle",i,"cycle"),n.add(e);try{if(Array.isArray(e)){e.length>128&&W("v2 manifest array is too long",i,"array-too-long"),e.forEach((r,o)=>yt(r,n,t+1,rn(i,`[${o}]`)));return}$(e)||l("MANIFEST_INVALID","v2 manifest contains a non-plain object",i,"non-plain-object");for(let[r,o]of Object.entries(e))yt(o,n,t+1,rn(i,r));}finally{n.delete(e);}}}function ki(e){return (typeof e!="string"||e.length>4096||!tn.test(e))&&(typeof e=="string"&&e.length>4096&&W("projection path is too long"),l("MANIFEST_INVALID","projection paths must be canonical exact paths")),e.split(".").some(t=>$e(t))&&l("MANIFEST_INVALID","projection paths cannot address reserved state keys"),e}function At(e){$(e)||l("MANIFEST_INVALID","projection policy must be an object"),G(e,["allow"]),Array.isArray(e.allow)||l("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 r=ki(i);t.has(r)&&l("MANIFEST_INVALID","projection allowlist contains a duplicate path"),t.add(r),n.push(r);}return {allow:n}}function Js(e,n){if(e===void 0)return;Array.isArray(e)||l("MANIFEST_INVALID","dataPaths must be an array"),e.length>js&&W("dataPaths exceed the v2 limit");let t=[],i=new Set;for(let r of e){let o=ki(r);i.has(o)&&l("MANIFEST_INVALID","dataPaths contain a duplicate path"),n.some(s=>He(o,s))||l("MANIFEST_INVALID","dataPaths must be projection-allowed"),i.add(o),t.push(o);}return t}function We(e,n,t=Number.MAX_SAFE_INTEGER){return (!Number.isSafeInteger(e)||e<0||e>t)&&l("MANIFEST_INVALID",`${n} is invalid`),e}function Ni(e,n){return (typeof e!="number"||!Number.isFinite(e))&&l("MANIFEST_INVALID",`${n} is invalid`),e}function It(e,n=0,t=new Set){if(typeof e=="string")return (e.length>4096||Nn(e))&&l("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)||l("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)&&l("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(r=>It(r,n+1,t));$(e)||l("MANIFEST_INVALID","schema enum contains a non-plain object");let i={};for(let[r,o]of Object.entries(e))$e(r)&&l("MANIFEST_INVALID","schema enum contains a reserved key"),i[r]=It(o,n+1,t);return i}finally{t.delete(e);}}function Ks(e,n){if(e===void 0)return;Array.isArray(e)||l("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 r of e)(typeof r!="string"||!tn.test(r))&&l("MANIFEST_INVALID","schema required contains an invalid key"),r.length>4096&&W("schema required key is too long"),i.has(r)&&l("MANIFEST_INVALID","schema required contains a duplicate key"),n&&!Object.prototype.hasOwnProperty.call(n,r)&&l("MANIFEST_INVALID","schema required references an undeclared property"),i.add(r),t.push(r);return t}function Xs(e,n){let t=n?tn:_n;return e.length>4096&&W("schema property name is too long"),(!t.test(e)||e.split(".").some(i=>$e(i)))&&l("MANIFEST_INVALID","schema property name is invalid"),e}function gt(e,n=0,t=false){$(e)||l("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"&&l("SCHEMA_TYPE_UNSUPPORTED","action inputSchema type is unsupported"),l("MANIFEST_INVALID","action inputSchema type is required"));let r=["type","enum"];i==="string"&&r.push("minLength","maxLength"),i==="array"&&r.push("minItems","maxItems","items"),i==="object"&&r.push("minProperties","maxProperties","properties","required","additionalProperties"),(i==="number"||i==="integer")&&r.push("minimum","maximum"),G(e,["type"],r.filter(a=>a!=="type"));let o={type:i};if(U(e,"enum")&&(Array.isArray(e.enum)||l("MANIFEST_INVALID","schema enum must be an array"),e.enum.length>128&&W("schema enum is too long"),o.enum=e.enum.map(a=>It(a))),i==="string"&&(U(e,"minLength")&&(o.minLength=We(e.minLength,"schema minLength",4096)),U(e,"maxLength")&&(o.maxLength=We(e.maxLength,"schema maxLength",4096)),o.minLength!==void 0&&o.maxLength!==void 0&&o.minLength>o.maxLength&&l("MANIFEST_INVALID","schema string length bounds are inverted")),(i==="number"||i==="integer")&&(U(e,"minimum")&&(o.minimum=Ni(e.minimum,"schema minimum")),U(e,"maximum")&&(o.maximum=Ni(e.maximum,"schema maximum")),o.minimum!==void 0&&o.maximum!==void 0&&o.minimum>o.maximum&&l("MANIFEST_INVALID","schema numeric bounds are inverted")),i==="array"&&(U(e,"minItems")&&(o.minItems=We(e.minItems,"schema minItems",128)),U(e,"maxItems")&&(o.maxItems=We(e.maxItems,"schema maxItems",128)),o.minItems!==void 0&&o.maxItems!==void 0&&o.minItems>o.maxItems&&l("MANIFEST_INVALID","schema array length bounds are inverted"),U(e,"items")&&(o.items=gt(e.items,n+1,false))),i==="object"){let a;if(U(e,"properties")){$(e.properties)||l("MANIFEST_INVALID","schema properties must be an object");let c=Object.entries(e.properties);c.length>64&&W("schema properties are too many"),a={};for(let[p,y]of c){let A=Xs(p,t);a[A]=gt(y,n+1,false);}o.properties=a;}U(e,"minProperties")&&(o.minProperties=We(e.minProperties,"schema minProperties",64)),U(e,"maxProperties")&&(o.maxProperties=We(e.maxProperties,"schema maxProperties",64)),o.minProperties!==void 0&&o.maxProperties!==void 0&&o.minProperties>o.maxProperties&&l("MANIFEST_INVALID","schema object property bounds are inverted");let d=Ks(e.required,a);d!==void 0&&(o.required=d),U(e,"additionalProperties")&&(e.additionalProperties!==false&&l("MANIFEST_INVALID","schema additionalProperties must be false"),o.additionalProperties=false);}let s=JSON.stringify(o);return (s===void 0||Buffer.byteLength(s,"utf8")>65536)&&W("action inputSchema subtree is too large"),o}function Ys(e){let n=gt(e,0,true);return (n.type!=="object"||!n.properties)&&l("MANIFEST_INVALID","action inputSchema must declare object properties"),n}function qs(e){if($(e)||l("MANIFEST_INVALID","action backend must be an object"),e.type==="core"){G(e,Os);let n=e.handler;return (typeof n!="string"||!tt.test(n))&&l("MANIFEST_INVALID","core backend handler is invalid"),{type:"core",handler:n}}if(e.type==="skill"){G(e,Rs,ws),(!Array.isArray(e.command)||e.command.length===0||e.command.length>16)&&l("MANIFEST_INVALID","skill backend command is invalid");let n=[];for(let i of e.command)(typeof i!="string"||i.length===0||i.length>256||!it.test(i))&&l("MANIFEST_INVALID","skill backend command token is invalid"),n.push(i);let t=U(e,"env")?Qs(e.env):void 0;return {type:"skill",command:n,...t===void 0?{}:{env:t}}}l("MANIFEST_INVALID","action backend type is unsupported");}function Zs(e){$(e)||l("MANIFEST_INVALID","action must be an object"),G(e,Ss,Ms),U(e,"_meta")&&z("_meta",()=>xi(e._meta));let n=z("actionId",()=>ft(e.actionId,"actionId"));Qn(n)&&l("MANIFEST_INVALID",`actionId "${n}" is not projection-safe`,"actionId");let t=z("capability",()=>Ws(e.capability)),i=e.mutation;typeof i!="boolean"&&l("MANIFEST_INVALID","action mutation must be boolean","mutation");let r=z("inputSchema",()=>Ys(e.inputSchema)),o;if(U(e,"dataInputs")){Array.isArray(e.dataInputs)||l("MANIFEST_INVALID","action dataInputs must be an array","dataInputs");let p=r.properties,y=new Set,A=[];for(let I of e.dataInputs)(typeof I!="string"||!U(p,I)||y.has(I))&&l("MANIFEST_INVALID","action dataInputs must be unique declared properties","dataInputs"),y.add(I),A.push(I);o=A;}let s=z("resultProjection",()=>At(e.resultProjection)),a=z("backend",()=>qs(e.backend)),d;U(e,"content")&&((a.type!=="skill"||!En(e.content))&&l("MANIFEST_INVALID","action content declaration is invalid","content"),d=ea(e.content));let c;if(U(e,"confirmation")){let p=e.confirmation;p!=="none"&&p!=="native"&&l("MANIFEST_INVALID","action confirmation is invalid","confirmation"),c=p;}return {actionId:n,capability:t,mutation:i,inputSchema:r,resultProjection:s,backend:a,...d===void 0?{}:{content:d},...o===void 0?{}:{dataInputs:o},...c===void 0?{}:{confirmation:c}}}function Qs(e){return fi(e)||l("MANIFEST_INVALID","skill backend env is invalid"),Object.freeze([...e])}function ea(e){return Object.freeze({...e.in===void 0?{}:{in:Object.freeze({...e.in})},...e.out===void 0?{}:{out:Object.freeze({...e.out})}})}function na(e){return $(e)||l("INITIAL_STATE_INVALID","initialState must be an object"),G(e,Us,Cs),e.path!=="ui/state.json"&&l("MANIFEST_INVALID","initialState path is not fixed"),U(e,"hash")?{path:"ui/state.json",hash:Ci(e.hash)}:{path:"ui/state.json"}}function ta(e){let n=["wasm","terminal","htmlDocuments"];return (!$(e)||Object.keys(e).length===0||Object.keys(e).some(t=>!n.includes(t)||e[t]!==true))&&l("MANIFEST_INVALID","runtime must contain only known capability flags set to true"),{...e.wasm===true?{wasm:true}:{},...e.terminal===true?{terminal:true}:{},...e.htmlDocuments===true?{htmlDocuments:true}:{}}}function ia(e,n){let t;try{t=Ti(e);}catch(i){let r=i!==null&&typeof i=="object"&&"code"in i&&typeof i.code=="string"?i.code:"CSP_ORIGIN_INVALID";return l("MANIFEST_INVALID",r,void 0,r.toLowerCase().replace(/_/g,"-"))}if(t.frameDomains.length>0&&l("MANIFEST_INVALID","external origins in csp are not enabled in this rollout",void 0,"csp-not-enabled"),t.connectDomains.length!==0)return n?.terminal===true&&l("MANIFEST_INVALID","runtime.terminal cannot be combined with csp.connectDomains","connectDomains","terminal-with-connect-domains"),Object.freeze({connectDomains:t.connectDomains})}function oa(e,n){bn($(e)&&U(e,"csp")?Fs(e,"csp"):e,new Set,0,true,true),yt(e),$(e)||l("MANIFEST_INVALID"),G(e,bs,Ns),U(e,"_meta")&&z("_meta",()=>xi(e._meta)),e.manifestVersion!==2&&l("MANIFEST_INVALID");let t;U(e,"runtime")&&(t=z("runtime",()=>ta(e.runtime)));let i;U(e,"csp")&&(i=z("csp",()=>ia(e.csp,t)));let r=z("pluginId",()=>ft(e.pluginId,"pluginId")),o=z("definitionId",()=>ft(e.definitionId,"definitionId")),s=z("version",()=>le(e,"version",1)),a=z("name",()=>bi(e.name,"name")),d=z("description",()=>bi(e.description,"description")),c;U(e,"icon")&&((typeof e.icon!="string"||!/^[a-z][a-z0-9-]{0,63}$/.test(e.icon))&&l("MANIFEST_INVALID","icon is invalid","icon"),c=e.icon);let p;U(e,"tone")&&((typeof e.tone!="string"||!ot.includes(e.tone))&&l("MANIFEST_INVALID","tone is invalid","tone"),p=e.tone),e.entry!=="ui/index.html"&&l("MANIFEST_INVALID","entry path is not fixed","entry","fixed-value");let y;U(e,"entryHash")&&(y=z("entryHash",()=>Ci(e.entryHash)));let A;U(e,"initialState")&&(A=z("initialState",()=>na(e.initialState)));let I;U(e,"usage")&&(e.usage!=="card"&&e.usage!=="window"&&l("MANIFEST_INVALID","usage is invalid","usage"),I=e.usage);let E;U(e,"detailPanel")&&(typeof e.detailPanel!="boolean"&&l("MANIFEST_INVALID","detailPanel is invalid","detailPanel"),E=e.detailPanel);let O;if(U(e,"displayModes")){((I??Oe)!==Oe||!Array.isArray(e.displayModes)||e.displayModes.length===0)&&l("MANIFEST_INVALID","displayModes are only valid for window Apps","displayModes");let u=new Set(["inline","floating","focused"]);(new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(f=>typeof f!="string"||!u.has(f)))&&l("MANIFEST_INVALID","displayModes are invalid","displayModes"),O=e.displayModes;}(I??Oe)===Oe&&E!==void 0&&l("MANIFEST_INVALID","detailPanel is card-only","detailPanel");let b=n.mode??"local";b!=="local"&&b!=="installed"&&b!=="published"&&l("MANIFEST_INVALID","manifest mode is invalid"),b!=="local"&&y===void 0&&l("MANIFEST_INVALID","installed manifests require entryHash","entryHash","required-when-installed"),b!=="local"&&A!==void 0&&A.hash===void 0&&l("MANIFEST_INVALID","installed manifests require initialState.hash","initialState.hash","required-when-installed"),(!Array.isArray(e.surfaces)||e.surfaces.length===0)&&l("MANIFEST_INVALID","surfaces are invalid","surfaces"),e.surfaces.length>2&&W("surfaces exceed the v2 limit","surfaces","too-many-items");let j=[],C=new Set;for(let u of e.surfaces)(typeof u!="string"||!rt.includes(u))&&l("MANIFEST_INVALID","surface is unsupported","surfaces"),C.has(u)&&l("MANIFEST_INVALID","surfaces contain a duplicate","surfaces","duplicate-item"),C.add(u),j.push(u);$(e.size)||l("MANIFEST_INVALID","size must be an object","size"),z("size",()=>G(e.size,["height"]));let x=z("size",()=>le(e.size,"height",1));x>720&&W("size.height exceeds the v2 limit","size.height","too-large");let B=z("stateProjection",()=>At(e.stateProjection)),_=e.summaryProjection===void 0?void 0:z("summaryProjection",()=>At(e.summaryProjection));_!==void 0&&_.allow.some(u=>!B.allow.includes(u))&&l("MANIFEST_INVALID","summaryProjection must be a subset of stateProjection.allow","summaryProjection");let h=z("dataPaths",()=>Js(e.dataPaths,B.allow));Array.isArray(e.actions)||l("MANIFEST_INVALID","actions must be an array","actions"),e.actions.length>32&&W("actions exceed the v2 limit","actions","too-many-items");let S=[],w=new Set;for(let[u,f]of e.actions.entries()){let g=`actions[${u}]`,P=z(g,()=>Zs(f));if(w.has(P.actionId)&&l("MANIFEST_INVALID","actions contain a duplicate actionId",`${g}.actionId`,"duplicate-item"),P.backend.type==="core"&&P.backend.handler==="state.set"){P.mutation||l("MANIFEST_INVALID","state.set actions must be mutations",`${g}.mutation`);for(let N of Object.keys(P.inputSchema.properties))B.allow.includes(N)||l("MANIFEST_INVALID","state.set input paths must be projection-allowed",`${g}.inputSchema.properties`);}w.add(P.actionId),S.push(P);}return {manifestVersion:2,pluginId:r,definitionId:o,version:s,name:a,description:d,...c===void 0?{}:{icon:c},...p===void 0?{}:{tone:p},entry:"ui/index.html",...y===void 0?{}:{entryHash:y},...t===void 0?{}:{runtime:t},...i===void 0?{}:{csp:i},...A===void 0?{}:{initialState:A},...I===void 0?{}:{usage:I},...E===void 0?{}:{detailPanel:E},...O===void 0?{}:{displayModes:O},surfaces:j,size:{height:x},stateProjection:B,..._===void 0?{}:{summaryProjection:_},...h===void 0?{}:{dataPaths:h},actions:S}}function xi(e){$(e)||l("MANIFEST_INVALID","_meta must be an object");let n=JSON.stringify(e);(n===void 0||Buffer.byteLength(n,"utf8")>Ls)&&W("_meta exceeds the 4 KiB limit",void 0,"meta-too-large");}function ra(e){let n={},t={};for(let o of e.actions){n[o.actionId]={capabilities:[o.capability],inputKeys:Object.keys(o.inputSchema.properties??{}),...o.dataInputs===void 0?{}:{dataInputs:o.dataInputs},resultProjection:o.resultProjection,...o.confirmation===void 0?{}:{confirmation:o.confirmation},...o.content===void 0?{}:{content:o.content},...o.backend.type!=="skill"||o.backend.env===void 0?{}:{env:o.backend.env}};let s=o.backend.type==="skill"||o.backend.type==="core"&&o.backend.handler==="state.set";t[o.actionId]={actionId:o.actionId,mutation:o.mutation,backend:o.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},r={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:r}}function mt(e,n,t,i,r,o){if(typeof e=="string"){let s=r.length>0&&o.some(a=>He(r.join("."),a));return (e.length>4096||Nn(e,false,false,s))&&ae("state contains an unsafe string"),e}if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||ae("state contains a non-finite number"),e;(e===void 0||typeof e!="object"||typeof e=="function"||typeof e=="bigint")&&ae("state contains a non-JSON value"),t>8&&ae("state is too deep"),n.has(e)&&ae("state contains a cycle"),n.add(e);try{let s;if(Array.isArray(e))e.length>128&&ae("state array is too long"),s=e.map(d=>mt(d,n,t+1,65536,r,o));else {$(e)||ae("state contains a non-plain object");let d={};for(let[c,p]of Object.entries(e))(c.length>4096||!_n.test(c)||$e(c))&&(c.length>4096&&ae("state key is too long"),ae("state contains a reserved or invalid key")),d[c]=mt(p,n,t+1,65536,[...r,c],o);s=d;}let a=JSON.stringify(s);return (a===void 0||Buffer.byteLength(a,"utf8")>i)&&ae("state subtree is too large"),s}finally{n.delete(e);}}function _t(e,n=[]){$(e)||ae("initial state must be a JSON object");let t=mt(e,new Set,0,65536,[],n);return (t===null||Array.isArray(t)||typeof t!="object")&&ae(),t}function sa(e,n={}){bn(e),$(e)||l("MANIFEST_INVALID"),G(e,Ds),e.manifestVersion!==1&&l("MANIFEST_INVALID");let t=ut(ye(e,"pluginId")),i=ut(ye(e,"definitionId")),r=le(e,"version",1),o=le(e,"primitiveSet",1),s=n.supportedPrimitiveSet??ys;(!Number.isSafeInteger(s)||s<1)&&l("MANIFEST_INVALID"),o>s&&l("PRIMITIVE_SET_UNSUPPORTED"),$(e.activation)||l("MANIFEST_INVALID"),G(e.activation,["kind","language"]),e.activation.kind!=="fenced-code"&&l("MANIFEST_INVALID");let a=ut(ye(e.activation,"language")),d=Hs(e.schema),c=Gs(e.layout,d);return {manifestVersion:1,pluginId:t,definitionId:i,version:r,primitiveSet:o,activation:{kind:"fenced-code",language:a},schema:d,layout:c}}function aa(e,n={}){return $(e)||l("MANIFEST_INVALID"),Object.hasOwn(e,"lineage")&&l("MANIFEST_INVALID","lineage is only allowed in product bundle indexes"),e.manifestVersion===2?oa(e,n):sa(e,n)}function xe(e,n={}){try{return aa(e,n)}catch(t){if(t instanceof Q)throw t;return l("MANIFEST_INVALID")}}function sn(e,n={}){let t=xe(e,n);return t.manifestVersion===2?ra(t):t}var ys,As,Is,Ui,gs,ms,hs,_s,Di,Es,Ts,Ps,Ds,bs,Ns,Ss,Ms,Ls,Os,Rs,ws,Us,Cs,ks,xs,vs,js,Vs,Q,Et=V(()=>{m();pt();_e();ct();yi();Pi();Ue();ys=1,As=/^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$/,Is=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,Ui=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,gs=/<\/?[A-Za-z][^>]*>/,ms=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,hs=/^(?:https?|file|ftp|ws|wss):\/\//i,_s=/^\s*(?:javascript|data):/i,Di=/data:[^,\s]*,/i,Es=/(?:https?|file|ftp|ws|wss):\/\//i,Ts=/javascript:/i,Ps=/(?:^[\s]*|[\s"'(=])(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)(?=[^\s"'<>])[^\s"'<>]*/,Ds=["manifestVersion","pluginId","definitionId","version","primitiveSet","activation","schema","layout"],bs=["manifestVersion","pluginId","definitionId","version","name","description","entry","surfaces","size","stateProjection","actions"],Ns=["_meta","icon","tone","entryHash","runtime","csp","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths"],Ss=["actionId","capability","mutation","inputSchema","resultProjection","backend"],Ms=["confirmation","dataInputs","content","_meta"],Ls=4*1024,Os=["type","handler"],Rs=["type","command"],ws=["env"],Us=["path"],Cs=["hash"],ks=/^[0-9a-f]{64}$/,xs=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/,vs=/[\r\n]/,js=16,Vs=["card-shell","meta-banner","heading","labeled-text","step-flow","text-list"],Q=class e extends Error{constructor(t,i=t,r,o){super(i);this.code=t;this.path=r;this.rule=o;}code;path;rule;name="UiPluginValidationError";withPathPrefix(t){return new e(this.code,this.message,rn(t,this.path),this.rule)}};});function Fi(e){return typeof e=="string"&&e.length<=da&&ca.test(e)}function k(e,n,t,i,r){throw new Ae(e,{path:n,rule:t,...i===void 0?{}:{message:i},...r===void 0?{}:{file:r}})}function ce(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 te(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Pe(e){let n=`_meta["${Re}"]`;return e===void 0||e===""?n:e.startsWith("[")?`${n}${e}`:`${n}.${e}`}function fa(e){return e.toLowerCase().replace(/_/g,"-")}function ya(e){if(e===void 0||e==="")return "";let n=/^([^.[]+)(.*)$/.exec(e);if(!n)return Pe(e);let[,t,i]=n;switch(t){case "pluginId":return `name${i}`;case "name":return `display_name${i}`;case "description":return `description${i}`;case "_meta":return `_meta${i}`;case "version":return Pe("definitionVersion");case "definitionId":return Pe("definitionId");default:return Pe(`${t}${i}`)}}function Bi(e,n,t){return {path:t(e.path),rule:e.rule??fa(e.code),...e.message!==e.code?{message:e.message}:{},file:n}}function Hi(e){return JSON.parse(JSON.stringify(e))}function Dt(e,n,t=0,i=new Set){if(typeof e=="string"){e.length>4096&&k("LIMIT_EXCEEDED",n,"string-too-long"),(pa.test(e)||la.test(e)||ua.test(e))&&k("UNSAFE_VALUE",n,"unsafe-value");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||k("MANIFEST_INVALID",n,"non-finite-number");return}typeof e!="object"&&k("MANIFEST_INVALID",n,"non-json-value"),t>8&&k("LIMIT_EXCEEDED",n,"too-deep"),i.has(e)&&k("MANIFEST_INVALID",n,"cycle"),i.add(e);try{if(Array.isArray(e)){e.length>128&&k("LIMIT_EXCEEDED",n,"array-too-long"),e.forEach((r,o)=>Dt(r,`${n}[${o}]`,t+1,i));return}ce(e)||k("MANIFEST_INVALID",n,"non-plain-object");for(let[r,o]of Object.entries(e))Dt(o,n===""?r:`${n}.${r}`,t+1,i);}finally{i.delete(e);}}}function ue(e,n){return (typeof e!="string"||e.length===0)&&k("MANIFEST_INVALID",n,"string"),e}function Ke(e,n){return ce(e)||k("MANIFEST_INVALID",n,"object"),e}function Aa(e,n){Array.isArray(e)||k("MANIFEST_INVALID",n,"array"),e.forEach((t,i)=>ue(t,`${n}[${i}]`));}function Ia(e,n){typeof e!="boolean"&&k("MANIFEST_INVALID",n,"boolean");}function an(e,n,t,i){for(let r of Object.keys(e))!t.includes(r)&&!i.includes(r)&&k("MANIFEST_INVALID",`${n}.${r}`,"unknown-key");for(let r of t)te(e,r)||k("MANIFEST_INVALID",`${n}.${r}`,"missing-key");}function ga(e,n){switch(Dt(n,e),e){case "long_description":case "homepage":case "documentation":case "support":case "icon":case "license":ue(n,e);return;case "author":{let t=Ke(n,e);an(t,e,["name"],["email","url"]);for(let i of Object.keys(t))ue(t[i],`${e}.${i}`);return}case "repository":{let t=Ke(n,e);an(t,e,[],["type","url"]);for(let i of Object.keys(t))ue(t[i],`${e}.${i}`);return}case "icons":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=Ke(t,r);an(o,r,["src","size"],["theme"]),ue(o.src,`${r}.src`),ue(o.size,`${r}.size`),te(o,"theme")&&ue(o.theme,`${r}.theme`);});return}case "screenshots":case "keywords":case "privacy_policies":Aa(n,e);return;case "tools":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=Ke(t,r);an(o,r,["name"],["description"]),ue(o.name,`${r}.name`),te(o,"description")&&ue(o.description,`${r}.description`);});return}case "prompts":{Array.isArray(n)||k("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let r=`${e}[${i}]`,o=Ke(t,r);an(o,r,["name","text"],["description","arguments"]),ue(o.name,`${r}.name`),ue(o.text,`${r}.text`);});return}case "tools_generated":case "prompts_generated":Ia(n,e);return;case "localization":case "compatibility":case "user_config":Ke(n,e);return;default:k("MANIFEST_INVALID",e,"unknown-key");}}function Sn(e){return typeof e=="string"&&fe.test(e)?e:void 0}function zi(e){return Number.isSafeInteger(e)&&e>=1?e:void 0}function ma(e){let n=Sn(e.name);if(n===void 0)return;let t=e._meta,i=ce(t)?t[Re]:void 0,r=ce(i)?i:{},o=te(r,"definitionId")?Sn(r.definitionId):n,s=te(r,"definitionVersion")?zi(r.definitionVersion):1;return {pluginId:n,...o===void 0?{}:{definitionId:o},...s===void 0?{}:{definitionVersion:s}}}function ha(e){let n=Sn(e.pluginId);if(n===void 0)return;let t=Sn(e.definitionId),i=zi(e.version);return {pluginId:n,...t===void 0?{}:{definitionId:t},...i===void 0?{}:{definitionVersion:i}}}function St(e){try{let n=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e));if(!ce(n))return !1;let t=n._meta;return ce(t)&&te(t,Re)}catch{return false}}function _a(e,n){if(e===ie)return n.builtinOnly===true;let t=n._meta,i=ce(t)?t[Re]:void 0;return ce(i)&&i.builtinOnly===true}function Ea(e){te(e,"server")&&k("MANIFEST_INVALID","server","server-unsupported","phase 1 runs CrewX-owned Apps only");for(let s of Object.keys(e))bt.includes(s)||k("MANIFEST_INVALID",s,"unknown-key");for(let s of Nt)te(e,s)||k("MANIFEST_INVALID",s,"missing-key");e.manifest_version!==Tt&&k("MANIFEST_INVALID","manifest_version","unsupported-version",`manifest_version must be "${Tt}"`),Fi(e.version)||k("MANIFEST_INVALID","version","semver","version must be a semver.org version such as 0.1.0");let n=e._meta;ce(n)||k("MANIFEST_INVALID","_meta","object"),te(n,Re)||k("MANIFEST_INVALID",Pe(),"missing-key");let t=n[Re];ce(t)||k("MANIFEST_INVALID",Pe(),"object");for(let s of Object.keys(t))Pt.includes(s)||Vi.includes(s)||k("MANIFEST_INVALID",Pe(s),"unknown-key");for(let s of Pt)te(t,s)||k("MANIFEST_INVALID",Pe(s),"missing-key");if(te(t,"definitionVersion")){let s=t.definitionVersion;(!Number.isSafeInteger(s)||s<1)&&k("MANIFEST_INVALID",Pe("definitionVersion"),"positive-integer");}let i={};for(let s of ji)te(e,s)&&(ga(s,e[s]),i[s]=Hi(e[s]));let r={};for(let[s,a]of Object.entries(n))s!==Re&&(r[s]=a);let o={manifestVersion:2,pluginId:e.name,definitionId:te(t,"definitionId")?t.definitionId:e.name,version:te(t,"definitionVersion")?t.definitionVersion:1,name:e.display_name,description:e.description};for(let[s,a]of Object.entries(t))s==="definitionId"||s==="definitionVersion"||(o[s]=a);return Object.keys(r).length>0&&(o._meta=r),{v2Input:o,...Object.keys(r).length>0?{vendorMeta:r}:{},passthrough:i}}function Ta(e,n){ce(e)||k("MANIFEST_INVALID","","not-object","manifest.json must be a JSON object",Y);let t;try{t=Ea(e);}catch(o){throw o instanceof Ae?new Ae(o.code,{...o.reason,file:Y}):o}let i;try{let o=xe(t.v2Input,{mode:n.mode??"local"});o.manifestVersion!==2&&k("MANIFEST_INVALID","","v2-required"),i=o;}catch(o){throw o instanceof Q?new Ae(o.code,Bi(o,Y,ya)):o}let r=e.tools;if(Array.isArray(r)){let o=new Set(i.actions.map(s=>s.actionId));r.forEach((s,a)=>{let d=s.name;if(!o.has(d))throw new Ae("MANIFEST_INVALID",{path:`tools[${a}].name`,rule:"tool-not-action",message:"every tools[].name must be an action id",file:Y})});}return {file:Y,manifest:i,v2Input:t.v2Input,releaseVersion:e.version,...Object.keys(t.passthrough).length>0?{mcpb:t.passthrough}:{}}}function Pa(e,n){try{let t=xe(e,{mode:n.mode??"local"});if(t.manifestVersion!==2)throw new Ae("MANIFEST_INVALID",{path:"manifestVersion",rule:"v2-required",message:"a workspace App requires manifestVersion 2",file:ie});return {file:ie,manifest:t,v2Input:e}}catch(t){throw t instanceof Q?new Ae(t.code,Bi(t,ie,i=>i??"")):t}}function Xe(e){return pe(sn(e).definition)}function vi(e){let{entryHash:n,initialState:t,...i}=e,r={...i};return t!==void 0&&(r.initialState={path:t.path}),Hi(r)}function Da(e,n){let t=vi(e),i=vi(n);return [...new Set([...Object.keys(t),...Object.keys(i)])].sort().filter(o=>ne(t[o]??null)!==ne(i[o]??null))}function ba(e,n){return e.entryHash!==void 0&&n.entryHash!==void 0&&e.entryHash!==n.entryHash||e.initialState?.hash!==void 0&&n.initialState?.hash!==void 0&&e.initialState.hash!==n.initialState.hash}function Na(e,n){let t=Da(e,n),i=ba(e,n),r="";try{let o=Xe(e),s=Xe(n);i=i||o!==s,r=` (definition hash ${o.slice(0,12)} vs ${s.slice(0,12)})`;}catch{i=true;}t.length===0&&!i||k("MANIFEST_DUAL_MISMATCH","","dual-manifest-mismatch",`${Y} and ${ie} normalize to different definitions${r}`+(t.length>0?`; differing fields: ${t.join(", ")}`:""));}function Sa(e,n){let t=n.maxBytes??262144,i=[],r=new TextDecoder("utf-8",{fatal:true});for(let o of J){let s=e[o];if(s===void 0)continue;if(s.byteLength>t)return {parsed:i,failure:{code:"LIMIT_EXCEEDED",reason:{path:"",rule:"file-too-large",file:o},files:[o]}};let a;try{a=JSON.parse(r.decode(s));}catch{return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"invalid-json",file:o},files:[o]}}}if(!ce(a))return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"not-object",message:`${o} must be a JSON object`,file:o},files:[o]}};i.push({file:o,raw:a});}return {parsed:i}}function ve(e,n={}){let{parsed:t,failure:i}=Sa(e,n),r=J.filter(p=>e[p]!==void 0);if(i!==void 0)return {ok:false,rejection:i,parseFailure:true,builtinOnly:false};if(t.length===0)return {ok:false,rejection:{code:"MANIFEST_INVALID",reason:{path:"",rule:"no-manifest-file",message:"neither manifest.json nor ui-plugin.json is present"},files:[]},parseFailure:true,builtinOnly:false};let o=t[0],s=o.file===Y?ma(o.raw):ha(o.raw),a=t.some(p=>_a(p.file,p.raw)),d=[];try{for(let p of t)d.push(p.file===Y?Ta(p.raw,n):Pa(p.raw,n));d.length===2&&Na(d[0].manifest,d[1].manifest);}catch(p){if(p instanceof Ae)return {ok:false,rejection:{code:p.code,reason:p.reason,files:p.code==="MANIFEST_DUAL_MISMATCH"?[...J]:p.reason.file===void 0?r:[p.reason.file]},parseFailure:false,...s===void 0?{}:{identity:s},builtinOnly:a};throw p}let c=d[0];return {ok:true,...c,identity:s??{pluginId:c.manifest.pluginId},files:r}}var Y,ie,J,Tt,Re,bt,Nt,ji,Pt,Vi,ca,da,pa,la,ua,Ae,Mn=V(()=>{m();Ce();_e();Ue();Et();Y="manifest.json",ie="ui-plugin.json",J=[Y,ie],Tt="0.3",Re="dev.crewx",bt=Object.freeze(["manifest_version","name","display_name","version","description","long_description","author","repository","homepage","documentation","support","icon","icons","screenshots","localization","server","tools","tools_generated","prompts","prompts_generated","keywords","license","privacy_policies","compatibility","user_config","_meta"]),Nt=Object.freeze(["manifest_version","name","display_name","version","description","_meta"]),ji=Object.freeze(bt.filter(e=>e!=="server"&&!Nt.includes(e))),Pt=Object.freeze(["entry","surfaces","size","stateProjection","actions"]),Vi=Object.freeze(["definitionId","definitionVersion","icon","tone","entryHash","runtime","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths","csp"]),ca=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,da=256,pa=/<\/?[A-Za-z][^>]*>/,la=/^\s*javascript:/i,ua=/data:[^,\s]*,/i;Ae=class extends Error{constructor(t,i){super(`${t}: ${i.path||"<file>"} (${i.rule})`);this.code=t;this.reason=i;}code;reason};});var Mt=V(()=>{m();di();Mn();Et();Ue();});function On(e,n=e){throw new we(e,n)}var we,Rn=V(()=>{m();we=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="McpAppContractError"};});var eo=V(()=>{m();});var no=V(()=>{m();Ce();_e();Rn();eo();});function to(e,n){return Va.add(e),n!==void 0&&Fa.set(e,n),e}var Va,Fa,wn=V(()=>{m();Va=new WeakSet,Fa=new WeakMap;});function ln(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Ot(e,n,t=[]){let i=new Set([...n,...t]),r=Object.keys(e);return n.every(o=>Object.hasOwn(e,o))&&r.every(o=>i.has(o))}function ro(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))ro(n);return Object.freeze(e)}function q(e){throw new Ie("LINEAGE_INVALID",e)}function Ja(e){throw new Ie("LINEAGE_STALE",e)}function so(e){if(!ln(e)||!Ot(e,za,$a)||!ln(e.actions))return q("Lineage definition shape is invalid");for(let n of Object.values(e.actions))if(!ln(n)||!Ot(n,Ga,Wa))return q("Lineage action definition shape is invalid");return e}function Ka(e){if(!ln(e)||!Ot(e,Ba,Ha))return q("Lineage entry shape is invalid");if(!Number.isSafeInteger(e.version)||e.version<1||typeof e.hash!="string"||!io.test(e.hash))return q("Lineage entry identity is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!io.test(e.sourceHash)))return q("Lineage source hash is invalid");if(e.compat!==void 0&&e.compat!=="break")return q("Lineage compatibility marker is invalid");let n=so(e.definition);if(n.version!==e.version)return q("Lineage version does not match its definition");if(e.sourceHash!==void 0&&n.sourceHash!==e.sourceHash)return q("Lineage source hash does not match its definition");let t;try{t=pe(n),Ee({...n,hash:e.hash});}catch{return q("Lineage definition is invalid")}return t!==e.hash?q("Lineage definition hash does not match"):ro({version:e.version,hash:e.hash,definition:n,...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},...e.compat===void 0?{}:{compat:e.compat}})}function oo(e){return e.stateProjection?.allow??[]}function Xa(e,n){let t=[],i=new Set(oo(n));oo(e).some(a=>!i.has(a))&&t.push("S1_STATE_PROJECTION");let r=new Set(n.dataPaths??[]);(e.dataPaths??[]).some(a=>!r.has(a))&&t.push("S2_DATA_PATHS");for(let[a,d]of Object.entries(e.actions)){let c=n.actions[a];if(c&&(d.confirmation??"native")==="native"&&(c.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(d=>!a.has(d))&&t.push("S5_SUMMARY_PROJECTION");}return t}function Ya(e,n){return ne(e)===ne(n)}function Rt(e,n){if(!Array.isArray(e)||e.length===0)return q("Definition lineage is missing");if(!ln(n)||typeof n.hash!="string")return q("Current definition is invalid");let t,i;try{let{hash:a,...d}=n;i=so(d),t={...i,hash:a},Ee(t);}catch{return q("Current definition is invalid")}let r=e.map(Ka),o=r[0].definition.id;if(r.some(a=>a.definition.id!==o))return q("Lineage definition ids do not match");if(r.some((a,d)=>d>0&&a.version<=r[d-1].version))return q("Lineage generations are not in increasing version order");if(r.some((a,d)=>r.findIndex(c=>c.hash===a.hash)!==d))return q("Lineage contains a duplicate hash");let s=r[r.length-1];if(s.version!==t.version||s.hash!==t.hash||s.definition.id!==t.id||!Ya(s.definition,i))return Ja("The last lineage generation does not match the current package");if(t.legacy!==void 0){let a=new Set(Object.keys(t.actions)),d=new Set;for(let p of r)if(p.sourceHash===void 0)for(let y of Object.keys(p.definition.actions))a.has(y)&&d.add(y);let c=Object.keys(t.legacy.agentAccess??{});if(c.length!==d.size||c.some(p=>!d.has(p))){let p="S4_LEGACY_AGENT_ACCESS_COMPLETE";throw new Ie("LINEAGE_INVALID",`Lineage compatibility failed: ${p}`,[p])}}for(let a=0;a<r.length-1;a+=1){if(r.slice(a,-1).some(p=>p.compat==="break"))continue;let c=Xa(r[a].definition,t);if(c.length>0)throw new Ie("LINEAGE_INVALID",`Lineage compatibility failed: ${c.join(", ")}`,c)}return Object.freeze({entries:Object.freeze(r),current:t})}var Ie,io,Ba,Ha,za,$a,Ga,Wa,wt=V(()=>{m();Ce();_e();Ie=class extends Error{constructor(t,i=t,r=[]){super(i);this.code=t;this.violations=r;}code;violations;name="UiDefinitionLineageError"},io=/^[0-9a-f]{64}$/,Ba=["version","hash","definition"],Ha=["sourceHash","compat"],za=["id","version","actions"],$a=["sourceHash","usage","detailPanel","displayModes","renderer","surfaces","stateProjection","dataPaths","summaryProjection","legacy"],Ga=["capabilities"],Wa=["inputKeys","dataInputs","confirmation","resultProjection","content","env"];});var ao,co,po=V(()=>{m();ao=["crewx_app_terminal_connect","crewx_app_html_viewer_open"],co=["crewx_listWorkspaces","crewx_queryAgent","crewx_executeAgent","crewx_getTaskResult","crewx_listTasks","crewx_listAgents","callBrowser","openTab","listTabs","closeTab"];});var lo=V(()=>{m();Ce();wn();});function Ut(e,n=0){try{let t=he(e,n);return t.type!==void 0&&t.type!=="object"&&On("TOOL_INVALID","MCP App inputSchema must describe an object"),t}catch(t){if(t instanceof we)throw t;On("TOOL_INVALID","MCP App inputSchema must be projection-safe JSON");}}function uo(e){if(e.length===0)return Ut({type:"object",properties:{},additionalProperties:false});let n=e.map(i=>i.actionId),t=new Map;for(let i of e)t.set(i.actionId,Ut(i.inputSchema));return Ut(Qa(n,t),Za)}function Qa(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 un,Za,Ct=V(()=>{m();no();Ce();_e();wn();Rn();wt();po();lo();un=8*1024*1024,new Set(ao),new Set(co),Za=4;});function ec(e){if(e===null||typeof e!="object"||!(fo in e))throw new TypeError("scanCache must be created by createWorkspaceAppScanCache");return e[fo]}function yo(e,n){let t=ec(e),i=t.rootIdentity;return i!==void 0&&(i.dev!==n.dev||i.ino!==n.ino||i.realPath!==n.realPath)&&(t.candidates.clear(),t.assetCatalogs.clear(),t.lastCandidateScanUnchanged=void 0,t.lastCandidateKeys=void 0,t.scanStartedAtNs=void 0,t.lastAssetCatalogsUnchanged=void 0,t.lastSnapshot=void 0,t.lastSnapshotBuildInputs=void 0),t.rootIdentity=n,t}var fo,Ao=V(()=>{m();fo=Symbol("crewx.workspace-app-scan-cache.state");});function re(e){let n=typeof e=="object"&&e!==null&&"code"in e?String(e.code):"";return n==="ENOENT"?new D("NOT_FOUND"):n==="ELOOP"?new D("PATH_ESCAPED"):n==="EFBIG"||n==="EOVERFLOW"?new D("LIMIT_EXCEEDED"):n==="EACCES"||n==="EPERM"||n==="ENOTDIR"?new D("READ_DENIED"):new D("READ_DENIED")}function oc(e){if(typeof e!="string"||e.length===0||!isAbsolute(e))throw new D("READ_DENIED")}function kt(e){if(typeof e!="string"||isAbsolute(e)||/[\\\u0000]/.test(e))throw new D("PATH_ESCAPED");if(e==="")return [];let n=e.split("/");if(n.some(t=>t.length===0||t==="."||t===".."))throw new D("PATH_ESCAPED");return n}function xn(e,n){let t=relative(e,n);return t===""||t!==".."&&!t.startsWith(`..${sep}`)&&!isAbsolute(t)}function Ze(e){return {dev:e.dev,ino:e.ino,size:e.size,mtimeNs:e.mtimeNs,ctimeNs:e.ctimeNs}}function Vt(e,n){return e.dev===n.dev&&e.ino===n.ino}function Ft(e,n){return Vt(e,n)&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}async function Un(e){oc(e);let n,t;try{n=await realpath(e),t=await stat(n,{bigint:!0});}catch(i){throw re(i)}if(!t.isDirectory())throw new D("READ_DENIED");return {realRoot:n,identity:Ze(t)}}async function mo(e,n,t){if(t.length<2||t[0]!=="apps"&&t[0]!=="skills")return;let i,r;try{if(i=resolve(e,t[0],t[1]),r=await realpath(i),!(await stat(r,{bigint:!0})).isDirectory())throw new D("READ_DENIED")}catch(o){throw o instanceof D?o:re(o)}if(!xn(n,r))throw new D("PATH_ESCAPED");return r}async function Cn(e,n,t,i){let r,o,s;try{r=await lstat(e,{bigint:!0}),o=await realpath(e),s=await stat(o,{bigint:!0});}catch(a){throw re(a)}if(!xn(n,o)||t!==void 0&&!xn(t,o))throw new D("PATH_ESCAPED");if(!r.isFile()||!s.isFile())throw new D("READ_DENIED");if(!Vt(i,r)||!Vt(i,s)||i.dev!==s.dev)throw new D("PATH_ESCAPED")}async function qe(e,n){let t,i;try{t=await realpath(e),i=await stat(t,{bigint:!0});}catch{throw new D("PATH_ESCAPED")}if(t!==n.realRoot||!Ft(n.identity,Ze(i)))throw new D("PATH_ESCAPED")}function rc(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 D,jt,ic,go,vn,ho,Ht=V(()=>{m();D=class extends Error{constructor(t){super(t);this.code=t;}code;name="AppDiscoveryFsError"},jt=constants.O_NOFOLLOW,ic=constants.O_NONBLOCK,go=constants.O_RDONLY|(jt??0)|(ic??0);vn=class{async getRootIdentity(n){let t=await Un(n);return await qe(n,t),{dev:t.identity.dev,ino:t.identity.ino,realPath:t.realRoot}}async listDirectory(n,t){let i=kt(t),r=await Un(n),o=resolve(n,...i),s,a;try{s=await realpath(o),a=await stat(s,{bigint:!0});}catch(d){let c=re(d);if(c.code==="NOT_FOUND")return [];throw c}if(!xn(r.realRoot,s)||!a.isDirectory())throw new D("PATH_ESCAPED");try{let d=await readdir(s,{withFileTypes:!0,encoding:"utf8"});return await qe(n,r),d.map(rc)}catch(d){let c=re(d);if(c.code==="NOT_FOUND")return [];throw c}}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 D("READ_DENIED");if(jt===void 0)throw new D("UNSUPPORTED");let r=kt(t),o=await Un(n),s=resolve(n,...r),a=relative(n,s);if(a===".."||a.startsWith(`..${sep}`)||isAbsolute(a))throw new D("PATH_ESCAPED");let d;try{d=await open(s,go);}catch(c){throw re(c)}try{let c;try{let E=await d.stat({bigint:!0});c=Ze(E);}catch(E){throw re(E)}if(c.size>BigInt(i))throw new D("LIMIT_EXCEEDED");if(c.size>BigInt(Number.MAX_SAFE_INTEGER))throw new D("LIMIT_EXCEEDED");await qe(n,o);let p=await mo(n,o.realRoot,r);await Cn(s,o.realRoot,p,c);let y=new Uint8Array(new ArrayBuffer(Number(c.size))),A=0;for(;A<y.byteLength;){let E;try{E=(await d.read(y,A,y.byteLength-A,A)).bytesRead;}catch(O){throw re(O)}if(E<=0)throw new D("IDENTITY_CHANGED");A+=E;}let I;try{let E=await d.stat({bigint:!0});I=Ze(E);}catch(E){throw re(E)}if(!Ft(c,I))throw new D("IDENTITY_CHANGED");return await Cn(s,o.realRoot,p,I),await qe(n,o),new Uint8Array(y)}finally{await d.close().catch(()=>{});}}async fingerprintVerifiedFile(n,t,i){if(!Number.isSafeInteger(i)||i<0)throw new D("READ_DENIED");if(jt===void 0)throw new D("UNSUPPORTED");let r=kt(t),o=await Un(n),s=resolve(n,...r),a=relative(n,s);if(a===".."||a.startsWith(`..${sep}`)||isAbsolute(a))throw new D("PATH_ESCAPED");let d;try{d=await open(s,go);}catch(c){throw re(c)}try{let c;try{let A=await d.stat({bigint:!0});c=Ze(A);}catch(A){throw re(A)}if(c.size>BigInt(i)||c.size>BigInt(Number.MAX_SAFE_INTEGER))throw new D("LIMIT_EXCEEDED");await qe(n,o);let p=await mo(n,o.realRoot,r);await Cn(s,o.realRoot,p,c);let y;try{let A=await d.stat({bigint:!0});y=Ze(A);}catch(A){throw re(A)}if(!Ft(c,y))throw new D("IDENTITY_CHANGED");return await Cn(s,o.realRoot,p,y),await qe(n,o),{...y,candidateRealPath:p??o.realRoot}}catch(c){throw c instanceof D?c:re(c)}finally{await d.close().catch(()=>{});}}async readFileVerified(n,t,i){return this.readVerifiedFile(n,t,i)}},ho=new vn;});function In(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 Eo(e){return typeof e=="string"&&fe.test(e)?e:void 0}function uc(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function Ve(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let s=t[o]-i[o];if(s!==0)return s}return t.byteLength-i.byteLength}function fc(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 r=n.isFile;return typeof r=="function"&&r.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function yc(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 Ac(e){return pc.decode(e)}function Ic(e){return JSON.parse(Ac(e))}function To(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 gc(e){if(e instanceof D)return To(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return To(n)}}function De(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function mc(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function hc(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 Po(e,n,t,i){let r=mc(e);if(!r)throw new D("READ_DENIED");return yc(await r.call(e,n,t,i))}async function Gt(e,n,t){let i=hc(e);if(!i)throw new D("READ_DENIED");let r=await i.call(e,n,t);if(!Array.isArray(r))throw new D("READ_DENIED");return r.map(fc).filter(o=>o!==null)}function _c(e,n,t,i){return Object.freeze({code:e,...{},source:n,relativePath:t})}function Ec(e){if(!In(e))throw new TypeError("productBundle.reservedIds must be an object with appIds and definitionIds arrays");try{let n=Reflect.ownKeys(e);if(n.length!==2||!n.includes("appIds")||!n.includes("definitionIds"))throw new TypeError("productBundle.reservedIds must contain exactly appIds and definitionIds");let t=(i,r)=>{if(!Array.isArray(i))throw new TypeError("productBundle.reservedIds."+r+" must be an array");let o=[];for(let s=0;s<i.length;s+=1){let a=i[s];if(typeof a!="string"||a.length===0)throw new TypeError("productBundle.reservedIds."+r+" must contain non-empty strings");o.push(a);}return Object.freeze([...new Set(o)].sort(Ve))};return Object.freeze({appIds:t(e.appIds,"appIds"),definitionIds:t(e.definitionIds,"definitionIds")})}catch(n){throw n instanceof TypeError?n:new TypeError("productBundle.reservedIds must be a valid reservation object")}}function Tc(e,n){return e.appIds.length===n.appIds.length&&e.appIds.every((t,i)=>t===n.appIds[i])&&e.definitionIds.length===n.definitionIds.length&&e.definitionIds.every((t,i)=>t===n.definitionIds[i])}function Vn(e){return Object.freeze({appIds:Object.freeze([...new Set(e.map(n=>n.appId))].sort(Ve)),definitionIds:Object.freeze([...new Set(e.map(n=>n.definition.id))].sort(Ve))})}function jn(e,n){let t=Object.keys(e).sort(Ve),i=[...n].sort(Ve);return t.length===i.length&&t.every((r,o)=>r===i[o])}function Do(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 Pc(e){let n;try{n=Ic(e);}catch{return}if(!In(n)||!jn(n,["version","packages"])||n.version!==1||!Array.isArray(n.packages)||n.packages.length>Wt)return;let t=new Set,i=new Set,r=0,o=[];for(let s of n.packages){if(!In(s))return;let a=["packageDir","appId","definition","files"],d=Object.hasOwn(s,"lineage"),c=Object.hasOwn(s,"launcher"),p=[...d?["lineage"]:[],...c?["launcher"]:[]];if(!jn(s,[...a,...p])||c&&s.launcher!==false)return;let y=Do(s.packageDir),A=Eo(s.appId);if(!y||y.length!==2||y[0]!=="apps"||!uc(y[1])||!A||t.has(s.packageDir)||!In(s.definition)||!jn(s.definition,["id","version","hash"]))return;let I=Eo(s.definition.id),E=s.definition.version,O=s.definition.hash;if(!I||!Number.isSafeInteger(E)||E<1||typeof O!="string"||!$t.test(O)||!Array.isArray(s.files)||s.files.length<2||s.files.length>Jt)return;let b=new Set,j=[];for(let C of s.files){if(!In(C)||!jn(C,["path","sha256"]))return;let x=Do(C.path);if(!x||typeof C.sha256!="string"||!$t.test(C.sha256))return;let B=x.join("/"),_=`${s.packageDir}/${B}`;if(b.has(B)||i.has(_))return;b.add(B),i.add(_),j.push(Object.freeze({path:B,sha256:C.sha256}));}if(!J.some(C=>b.has(C))||!b.has("ui/index.html")||(r+=j.length,r>ac))return;t.add(s.packageDir),o.push(Object.freeze({packageDir:s.packageDir,...c?{launcher:false}:{},appId:A,definition:Object.freeze({id:I,version:E,hash:O}),lineage:Array.isArray(s.lineage)?s.lineage:[],files:Object.freeze(j.sort((C,x)=>Ve(C.path,x.path)))}));}return Object.freeze({version:1,packages:Object.freeze(o)})}function je(e){let n=gc(e);return n==="PATH_ESCAPED"||n==="IDENTITY_CHANGED"||n==="TOCTOU"?"PATH_ESCAPED":n==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":"BUNDLE_INTEGRITY"}async function Dc(e,n,t,i,r){let o=[],s=async(a,d)=>{if(!De(i,r))throw new D("LIMIT_EXCEEDED");if(d>2)throw new D("LIMIT_EXCEEDED");let c=await Gt(e,n,a);for(let p of c){if(typeof p.name!="string"||p.name.length===0||p.name==="."||p.name===".."||/[\\/\u0000]/.test(p.name))throw new D("PATH_ESCAPED");let y=`${a}/${p.name}`;if(p.kind==="file"){if(o.push(y.slice(t.length+1)),o.length>Jt)throw new D("LIMIT_EXCEEDED")}else if(p.kind==="directory")await s(y,d+1);else throw p.kind==="symlink"?new D("PATH_ESCAPED"):new D("READ_DENIED")}};return await s(t,0),o.sort(Ve)}function bc(e){return J.includes(e)?262144:e==="ui/index.html"?un:e==="ui/state.json"?65536:e.startsWith("ui/assets/")?dc:cc}async function bo(e,n,t,i){if(e===void 0)return {packages:[],diagnostics:[],incomplete:false,reservedIds:lc};let r=Ec(e.reservedIds),o=[],s=(u,f,g)=>_c(u,"bundled",f),a=(u=[],f=false,g)=>({...g===void 0?{}:{indexHash:g},packages:u,diagnostics:o,incomplete:f,reservedIds:r});if(typeof e.root!="string"||e.root.length===0||typeof e.expectedIndexHash!="string"||!$t.test(e.expectedIndexHash))return o.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a();let d;try{d=await Po(n,e.root,"bundle-index.json",sc);}catch(u){return o.push(s(je(u),"bundle-index.json")),a()}let c=createHash("sha256").update(d).digest("hex");if(c!==e.expectedIndexHash)return o.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a();let p=Pc(d);if(p===void 0)return o.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a();if(!Tc(Vn(p.packages),r))return o.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a([],false,c);if(!De(t,i))return o.push(s("LIMIT_EXCEEDED","bundle-index.json")),a(p.packages.map(u=>({indexEntry:u,failureCode:"LIMIT_EXCEEDED"})),true,c);let y;try{y=await Gt(n,e.root,"");}catch(u){return o.push(s(je(u),"bundle-index.json")),a(p.packages.map(f=>({indexEntry:f,failureCode:je(u)})),false,c)}if(!De(t,i))return o.push(s("LIMIT_EXCEEDED","bundle-index.json")),a(p.packages.map(u=>({indexEntry:u,failureCode:"LIMIT_EXCEEDED"})),true,c);let A=y.find(u=>u.name==="bundle-index.json"&&u.kind==="file"),I=y.find(u=>u.name==="apps"&&u.kind==="directory"),E=u=>p.packages.map(f=>({indexEntry:f,failureCode:u}));if(!A)return o.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a(E("BUNDLE_INTEGRITY"),false,c);let O=y.filter(u=>u.name!=="bundle-index.json"&&u.name!=="apps");if(O.length>0){let u=O.some(f=>f.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return o.push(s(u,"bundle-index.json")),a(E("BUNDLE_INTEGRITY"),false,c)}if(y.some(u=>u.name==="apps"&&u.kind!=="directory"))return o.push(s("PATH_ESCAPED","apps")),a(E("PATH_ESCAPED"),false,c);let b=[];if(I)try{b=await Gt(n,e.root,"apps");}catch(u){return o.push(s(je(u),"apps")),a(E(je(u)),false,c)}if(!De(t,i)||b.length>Wt)return o.push(s("LIMIT_EXCEEDED","apps")),a(E("LIMIT_EXCEEDED"),true,c);let j=new Map(p.packages.map(u=>[u.packageDir.slice(5),u])),C=b.filter(u=>!j.has(u.name));for(let u of C)o.push(s(u.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY",`apps/${u.name}`));if(C.length>0){let u=C.some(f=>f.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return a(E(u),false,c)}let x=new Set,B=new Map,_=new Map;for(let u of p.packages){let f=B.get(u.appId)??[];f.push(u),B.set(u.appId,f);let g=`${u.definition.id}\0${String(u.definition.version)}`,P=_.get(g)??[];P.push(u),_.set(g,P);}for(let u of [...B.values(),..._.values()])if(u.length>1)for(let f of u)x.add(f);let h=[],S=d.byteLength,w=false;for(let u of p.packages){if(!De(t,i)){w=true,h.push({indexEntry:u,failureCode:"LIMIT_EXCEEDED"});continue}let f;try{let N=u.lineage[u.lineage.length-1];if(!N)throw new Ie("LINEAGE_INVALID","Definition lineage is missing");if(N.definition.id!==u.definition.id||N.version!==u.definition.version||N.hash!==u.definition.hash)throw new Ie("LINEAGE_STALE","Last lineage generation does not match bundle identity");f=Rt(u.lineage,{...N.definition,hash:N.hash}).entries;}catch(N){let oe=N instanceof Ie?N.code:"LINEAGE_INVALID";o.push(s(oe,u.packageDir)),h.push({indexEntry:u,failureCode:oe});continue}let g=b.find(N=>N.name===u.packageDir.slice(5));if(!I||!g){h.push({indexEntry:u,failureCode:"BUNDLE_INTEGRITY"});continue}if(g.kind!=="directory"){h.push({indexEntry:u,failureCode:g.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY"});continue}let P;try{let N=await Dc(n,e.root,u.packageDir,t,i);if(!De(t,i)){w=!0,h.push({indexEntry:u,failureCode:"LIMIT_EXCEEDED"});continue}let oe=u.files.map(ge=>ge.path);if(N.length!==oe.length||N.some((ge,me)=>ge!==oe[me])){h.push({indexEntry:u,failureCode:"BUNDLE_INTEGRITY"});continue}P=new Map;let H;for(let ge of u.files){if(!De(t,i)){H="LIMIT_EXCEEDED",w=!0;break}if(S>=zt){H="LIMIT_EXCEEDED";break}let me;try{me=await Po(n,e.root,`${u.packageDir}/${ge.path}`,bc(ge.path));}catch(Or){H=je(Or);break}if(!De(t,i)){H="LIMIT_EXCEEDED",w=!0;break}if(S+me.byteLength>zt){S=zt,H="LIMIT_EXCEEDED";break}if(S+=me.byteLength,createHash("sha256").update(me).digest("hex")!==ge.sha256){H="BUNDLE_INTEGRITY";break}P.set(ge.path,me);}if(H!==void 0){h.push({indexEntry:u,failureCode:H});continue}}catch(N){De(t,i)||(w=true),h.push({indexEntry:u,failureCode:je(N)});continue}h.push({indexEntry:u,lineage:f,files:P,...x.has(u)?{failureCode:"DUPLICATE_ID"}:{}});}return a(h,w,c)}var sc,Wt,Jt,ac,cc,dc,zt,$t,pc,lc,Kt=V(()=>{m();wt();Ue();Mn();Ct();Ht();sc=256*1024,Wt=64,Jt=128,ac=Wt*Jt,cc=2*1024*1024,dc=8*1024*1024,zt=32*1024*1024,$t=/^[0-9a-f]{64}$/,pc=new TextDecoder("utf-8",{fatal:true}),lc=Object.freeze({appIds:Object.freeze([]),definitionIds:Object.freeze([])});});function Sc(e){if(typeof e!="string"||!fe.test(e))throw new TypeError("pluginId must be a safe UI plugin identifier");let n=`${Xt}${e}`.length+7<=128?e:`hash_${createHash("sha256").update(e,"utf8").digest("hex")}`;return {read:`${Xt}${n}_read`,action:`${Xt}${n}_action`}}function So(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 Lc(e,n){return n.length===0||n==="."||n===".."||/[\\/\u0000]/.test(n)?e==="skills"?"skills":"apps":`${e==="skills"?"skills":"apps"}/${n}`}function Oc(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function gn(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let s=t[o]-i[o];if(s!==0)return s}return t.byteLength-i.byteLength}function jo(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 r=n.isFile;return typeof r=="function"&&r.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function Rc(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 Vo(e){return Mc.decode(e)}function wc(e){return JSON.parse(Vo(e))}function Uc(e){if(e===void 0)return;let n=e.definitionId!==void 0&&e.definitionVersion!==void 0?`${e.definitionId}\0${String(e.definitionVersion)}`:void 0;return {pluginId:e.pluginId,...n===void 0?{}:{definitionKey:n}}}function Bn(e,n,t,i,r){let o={code:e,...i===void 0?{}:{pluginId:i},source:n,relativePath:t,...r?.reason===void 0?{}:{reason:Object.freeze({...r.reason})},...r?.files===void 0?{}:{files:Object.freeze([...r.files])}};return Object.freeze(o)}function Mo(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 de(e){if(e instanceof D)return Mo(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return Mo(n)}}function Qe(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 Lo(e){return {reason:e.reason,...e.code==="MANIFEST_DUAL_MISMATCH"?{files:e.files}:{}}}function Oo(e){return e==="MANIFEST_DUAL_MISMATCH"?e:Fo(e)}function Cc(e){return Fo(e.code)}function Fo(e){switch(e){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 Bo("UiPluginValidationError",e)}}function Bo(e,n){throw new Error(`Unmapped ${e} code: ${String(n)}`)}function kc(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 Bo("McpAppContractError",e)}}function be(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function xc(e){return {pluginId:e.appId,definitionKey:`${e.definition.id}\0${String(e.definition.version)}`}}function vc(e,n){let t=n.get("package.json");if(t!==void 0)try{let r=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(t));if(So(r)){let o=r.bin,s=typeof o=="string"?o:So(o)?Object.values(o).find(a=>typeof a=="string"):void 0;for(let a of [s,r.main]){if(typeof a!="string")continue;let d=jc(a);if(d&&n.has(d))return d}}}catch{}return [`${e.slice(e.lastIndexOf("/")+1)}.js`,"index.js","main.js"].find(r=>n.has(r))}function jc(e){if(e.startsWith("/")||e.includes("\\")||e.includes("\0"))return;let n=e.split("/").filter(t=>t!==".");if(!(n.length===0||n.some(t=>t.length===0||t==="..")))return n.join("/")}function Vc(){return globalThis.performance?.now()??Date.now()}function Fe(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))Fe(n);return Object.freeze(e)}function Ro(e){return Object.freeze(Array.from(e))}async function qt(e,n,t,i){if(n.pinnedFiles!==void 0){let a=n.pinnedFiles.get(t);if(a===void 0)throw new D("NOT_FOUND");if(a.byteLength>i)throw new D("LIMIT_EXCEEDED");return new Uint8Array(a)}let r=`${n.relativePath}/${t}`,o=n.scanContext,s=e.fingerprintVerifiedFile;if(o===void 0||!o.cacheable||typeof s!="function")return ko(e,n.root,r,i);try{let a=o.priorFingerprints.get(r)??await s.call(e,o.workspaceRoot,r,i);o.candidateRealPath=a.candidateRealPath;let d=await ko(e,n.root,r,i),c=await s.call(e,o.workspaceRoot,r,i);return o.candidateRealPath=c.candidateRealPath,$o(a,c)&&c.size===BigInt(d.byteLength)&&!Go(c,o.scanStartedAtNs)?o.files.set(r,{relativePath:r,byteLimit:i,fingerprint:c}):o.cacheable=!1,d}catch(a){throw J.includes(t)&&de(a)==="NOT_FOUND"&&o.directoryListings.some(c=>c.relativePath===n.relativePath&&!zo(c.key,t))||(o.cacheable=false),a}}function Ho(e,n){return JSON.stringify([e.realPath,n.source,n.relativePath])}async function Fc(e,n,t,i,r,o,s,a){let d=e.fingerprintVerifiedFile,c=Ho(t,i),p=r.candidates.get(c),y=i.relativePath,A;try{A=await Co(e,n,y);}catch(_){if(de(_)!=="NOT_FOUND")throw _}let I=A===void 0?void 0:{relativePath:y,key:A};if(I!==void 0&&(i.source==="apps"||i.source==="skills")&&!J.some(_=>zo(I.key,_)))return be(s,a)?p!==void 0&&p.candidate===void 0&&p.candidateRealPath===void 0&&p.files.length===0&&p.directoryListings.length===1&&p.directoryListings[0]?.relativePath===I.relativePath&&p.directoryListings[0]?.key===I.key&&(i.source==="apps"?p.diagnostic?.code==="MANIFEST_MISSING":p.diagnostic===void 0)&&typeof d=="function"?{memo:p}:typeof d!="function"?{}:{context:{state:r,cacheKey:c,workspaceRoot:n,scanStartedAtNs:o,directoryListings:Object.freeze([I]),priorFingerprints:new Map,files:new Map,cacheable:true}}:{timeLimitReached:true};let E=await Promise.all(wo.map(async _=>{if(_==="")return I;let h=`${i.relativePath}${_}`;try{let S=await Co(e,n,h);return S===void 0?void 0:{relativePath:h,key:S}}catch(S){if(de(S)==="NOT_FOUND")return;throw S}}));if(!be(s,a))return {timeLimitReached:true};let O=typeof d=="function"&&E.every(_=>_!==void 0),b=E.filter(_=>_!==void 0),j=new Map,C=p!==void 0&&O,x;if(p!==void 0&&typeof d=="function"){let _=await Promise.all(p.files.map(async h=>{if(!be(s,a))return {kind:"time",file:h};try{let S=await d.call(e,n,h.relativePath,h.byteLimit);return {kind:"fingerprint",file:h,current:S}}catch(S){return de(S)==="NOT_FOUND"?{kind:"missing",file:h}:{kind:"error",file:h,error:S}}}));if(_.some(h=>h.kind==="time"))return {timeLimitReached:true};for(let h of _){if(h.kind==="error")throw h.error;if(h.kind==="missing"){C=false;continue}if(h.kind!=="fingerprint")continue;let{file:S,current:w}=h;j.set(S.relativePath,w),x??=w.candidateRealPath,(w.candidateRealPath!==p.candidateRealPath||!$o(w,S.fingerprint)||Go(w,o))&&(C=false);}}let B=p!==void 0&&p.directoryListings.length===b.length&&p.directoryListings.every((_,h)=>_.relativePath===b[h]?.relativePath&&_.key===b[h]?.key);return p!==void 0&&O&&B&&C&&x===p.candidateRealPath?{memo:p}:!O||b.length!==wo.length?{}:{context:{state:r,cacheKey:c,workspaceRoot:n,scanStartedAtNs:o,directoryListings:Object.freeze(b),priorFingerprints:j,files:new Map,...x===void 0?{}:{candidateRealPath:x},cacheable:true}}}function zo(e,n){try{let t=JSON.parse(e);return Array.isArray(t)&&t.some(i=>Array.isArray(i)&&i[0]===n)}catch{return true}}async function Co(e,n,t){let i=Wo(e);if(typeof i!="function")return;let r=await i.call(e,n,t);if(!Array.isArray(r)||r.some(s=>typeof s=="string"))return;let o=r.map(jo);if(!o.some(s=>s===null))return JSON.stringify(o.slice().sort((s,a)=>gn(s.name,a.name)||gn(s.kind,a.kind)).map(s=>[s.name,s.kind]))}function $o(e,n){return e.dev===n.dev&&e.ino===n.ino&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}function Go(e,n){let t=e.mtimeNs-n;return t>=-Uo&&t<=Uo}function Yt(e){let n=e.scanContext,t=e.source==="skills"&&e.candidate===void 0&&e.diagnostic===void 0&&n?.files.size===0,i=e.source==="apps"&&e.candidate===void 0&&e.diagnostic?.code==="MANIFEST_MISSING"&&n?.files.size===0,r=t||i;if(n===void 0||!n.cacheable||n.candidateRealPath===void 0&&!r||n.files.size===0&&!r)return;let o=Object.freeze({...!r&&n.candidateRealPath!==void 0?{candidateRealPath:n.candidateRealPath}:{},directoryListings:n.directoryListings,files:Object.freeze([...n.files.values()]),...e.candidate===void 0?{}:{candidate:e.candidate},...e.diagnostic===void 0?{}:{diagnostic:e.diagnostic},...e.identity===void 0?{}:{identity:e.identity},...e.provenance===void 0?{}:{provenance:e.provenance}});n.state.candidates.set(n.cacheKey,o);}function Bc(e,n,t){let i=createHash("sha256"),r=new TextEncoder().encode(ne(e)),o=s=>{let a=new Uint8Array(8);new DataView(a.buffer).setBigUint64(0,BigInt(s)),i.update(a);};return o(r.byteLength),i.update(r),o(n.byteLength),i.update(n),o(t.byteLength),i.update(t),i.digest("hex")}function Hc(e,n){let t={...e.definition,sourceHash:n},i;try{i=pe(t);}catch(o){throw o instanceof R&&o.code==="INPUT_INVALID"?new Q("MANIFEST_INVALID","normalized definition is invalid"):o}let r={...t,hash:i};try{Ee(r);}catch{throw new Q("MANIFEST_INVALID","normalized definition is invalid")}return r}function zc(e){return e.actions.some(n=>n.backend.type==="core"&&n.backend.handler!=="state.set")}function $c(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function Wo(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 ko(e,n,t,i){let r=$c(e);if(!r)throw new D("READ_DENIED");return Rc(await r.call(e,n,t,i))}async function Gc(e,n,t){let i=Wo(e);if(!i)throw new D("READ_DENIED");let r=await i.call(e,n,t);if(!Array.isArray(r))throw new D("READ_DENIED");return r.map(jo).filter(o=>o!==null)}function Wc(e){let n=[];for(let t of [e.reserved,e.builtin])t&&n.push(t);return e.builtins&&"listMcpApps"in e.builtins?n.push(xo(e.builtins)):e.builtins&&n.push(e.builtins),e.builtinCatalog&&n.push(xo(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 xo(e){let n=[],t=[],i=[];for(let r of e.listMcpApps())typeof r.appId=="string"&&n.push(r.appId),r.definition&&typeof r.definition.id=="string"&&t.push(r.definition.id);for(let r of e.listMcpAppTools())typeof r.name=="string"&&i.push(r.name);return {appIds:n,definitionIds:t,toolNames:i}}function Ne(e,n){e.diagnostic||(e.diagnostic=Bn(n,e.source,e.relativePath,e.identity?.pluginId));}function Jc(e){let n=new Map;for(let i of e){let r=i.identity?.pluginId;if(r===void 0)continue;let o=n.get(r)??[];o.push(i),n.set(r,o);}for(let i of n.values()){if(i.length<2)continue;let r=i.filter(s=>s.provenance!==void 0);if(r.length>0){for(let s of i)s.provenance===void 0&&Ne(s,"RESERVED_ID");if(r.length>1)for(let s of r)Ne(s,"DUPLICATE_ID");continue}let o=i.filter(s=>s.source==="apps");if(o.length>1){for(let s of o)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 r=i.identity?.definitionKey;if(r===void 0)continue;let o=t.get(r)??[];o.push(i),t.set(r,o);}for(let i of t.values())if(i.length>1)for(let r of i)Ne(r,"DUPLICATE_ID");}function Kc(e,n,t){let i=new Set,r=new Set,o=new Set,s=new Set(t.appIds),a=new Set(t.definitionIds);for(let d of Wc(n)){for(let c of d.appIds??[])typeof c=="string"&&i.add(c);for(let c of d.definitionIds??[])typeof c=="string"&&r.add(c);for(let c of d.toolNames??[])typeof c=="string"&&o.add(c);}for(let d of e){let c=d.candidate;if(!c)continue;if(i.has(c.pluginId)||r.has(c.definitionId)){Ne(d,"RESERVED_ID");continue}if(d.provenance===void 0&&(s.has(c.pluginId)||a.has(c.definitionId))){Ne(d,"RESERVED_ID");continue}[c.toolNames.read,c.toolNames.action].filter(y=>y!==void 0).some(y=>o.has(y))&&Ne(d,"DUPLICATE_ID");}}function Xc(e){return [...e].sort((n,t)=>{let i=No.indexOf(n.source)-No.indexOf(t.source);return i!==0?i:gn(n.relativePath,t.relativePath)})}function v(e,n,t){e.diagnostic=Bn(n,e.source,e.relativePath,e.identity?.pluginId,t);}async function vo(e,n,t){let i=ve(t,{mode:"local"});if(!i.ok&&i.parseFailure){v(n,Oo(i.rejection.code),Lo(i.rejection));return}let r=Uc(i.identity);if(n.bundleIdentity===void 0)n.identity=r;else if(r?.pluginId!==n.bundleIdentity.appId||r.definitionKey!==`${n.bundleIdentity.definitionId}\0${String(n.bundleIdentity.version)}`){v(n,"BUNDLE_INTEGRITY");return}if(!i.ok&&i.builtinOnly){v(n,"RESERVED_ID");return}if(!i.ok){v(n,Oo(i.rejection.code),Lo(i.rejection));return}let o=i.manifest,s={pluginId:o.pluginId,definitionKey:`${o.definitionId}\0${String(o.version)}`};if(n.bundleIdentity===void 0&&(n.identity=s),o.actions.length>0)try{uo(o.actions.map(N=>({actionId:N.actionId,inputSchema:N.inputSchema})));}catch(N){if(N instanceof we){v(n,kc(N.code));return}throw N}let a;try{a=await qt(e,n,"ui/index.html",un);}catch(N){v(n,Qe(de(N),"entry"));return}if(a.byteLength>un){v(n,"LIMIT_EXCEEDED");return}let d;try{d=Vo(a);}catch{v(n,"ENTRY_INVALID");return}if(a.byteLength===0||d.length===0){v(n,"ENTRY_INVALID");return}let c=createHash("sha256").update(a).digest("hex");if(o.entryHash!==void 0&&o.entryHash!==c){v(n,"ENTRY_INVALID");return}let p={},y,A;if(o.initialState!==void 0){try{y=await qt(e,n,"ui/state.json",65536);}catch(N){v(n,Qe(de(N),"initial"));return}if(y.byteLength>65536){v(n,"LIMIT_EXCEEDED");return}try{let N=wc(y),oe=o.dataPaths??[],H=_t(N,oe);p=he(H,0,oe),ze(p);}catch{v(n,"INITIAL_STATE_INVALID");return}if(A=createHash("sha256").update(y).digest("hex"),o.initialState.hash!==void 0&&o.initialState.hash!==A){v(n,"INITIAL_STATE_INVALID");return}}let I={...o,entryHash:c,...o.initialState===void 0?{}:{initialState:{path:"ui/state.json",hash:A}}},E=sn(I),O=Bc(I,a,y??new Uint8Array),b;try{b=Hc(E,O);}catch(N){if(N instanceof Q){v(n,Cc(N));return}throw N}let j;if(n.bundleLineage!==void 0){let N=n.bundleLineage[n.bundleLineage.length-1];if(!N){v(n,"LINEAGE_INVALID");return}let{legacy:oe,...H}=N.definition,{hash:ge,...me}=b;if(ne(H)!==ne(me)){v(n,"LINEAGE_STALE");return}if(oe!==void 0&&(b={...b,legacy:oe}),oe!==void 0)try{b={...b,hash:pe(b)},Ee(b);}catch{v(n,"LINEAGE_INVALID");return}j=n.bundleLineage;}if(n.bundleIdentity!==void 0&&n.bundleIdentity.appId!==o.pluginId){v(n,"BUNDLE_INTEGRITY");return}if(n.bundleIdentity!==void 0&&(n.bundleIdentity.definitionId!==b.id||n.bundleIdentity.version!==b.version||n.bundleIdentity.definitionHash!==b.hash)){v(n,"LINEAGE_STALE");return}let C=Sc(o.pluginId),x=o.actions.length===0?{read:C.read}:C,B=Fe(E),_=Fe(I),h=Fe(b),S=Fe({...E.handlers}),w=Ro(a),u=y===void 0?void 0:Ro(y),f=Object.freeze({...n.provenance===void 0?{}:{provenance:n.provenance},entry:Object.freeze({path:"ui/index.html",hash:c,bytes:w}),...u===void 0?{}:{initialState:Object.freeze({path:"ui/state.json",hash:A,bytes:u})}}),g={appId:o.pluginId,pluginId:o.pluginId,definitionId:o.definitionId,version:o.version,...i.releaseVersion===void 0?{}:{releaseVersion:i.releaseVersion},manifestFile:i.file,...i.mcpb===void 0?{}:{mcpb:Fe(i.mcpb)},relativePath:n.relativePath,manifest:_,normalized:B,name:o.name,description:o.description,...o.icon===void 0?{}:{icon:o.icon},...o.tone===void 0?{}:{tone:o.tone},definition:h,handlers:S,resources:f,html:d,entryBytes:w,entryHash:c,initialState:Fe(p),...u===void 0?{}:{initialStateBytes:u},...A===void 0?{}:{initialStateHash:A},sourceHash:O,toolNames:Object.freeze(x)},P=n.provenance===void 0?{...g,source:n.source}:{...g,provenance:n.provenance,lineage:j??[]};n.candidate=Object.freeze(P),zc(o)&&v(n,"EXEC_DENIED");}async function Jo(e,n){let t={};for(let i of J)try{t[i]=await qt(e,n,i,262144);}catch(r){if(de(r)==="NOT_FOUND")continue;return {files:t,failure:Qe(de(r),"manifest")}}return {files:t}}function Zt(e){return J.some(n=>e[n]!==void 0)}async function Yc(e,n){let{files:t,failure:i}=await Jo(e,n);if(i!==void 0){v(n,i);return}let r=t[Y];return r!==void 0&&!St(r)&&delete t[Y],Zt(t)?t:void 0}function qc(e,n,t,i=Nc,r=false){let o=Xc(e);Jc(o);let s=Object.freeze(o.filter(p=>p.candidate!==void 0&&p.diagnostic===void 0).map(p=>p.candidate)),a=Object.freeze(o.filter(p=>p.diagnostic!==void 0).map(p=>p.diagnostic)),d=r?Object.freeze({...t===void 0?{}:{indexHash:t},candidates:Object.freeze(o.filter(p=>p.source==="bundled"&&p.diagnostic===void 0&&t!==void 0&&p.candidate?.provenance?.indexHash===t).map(p=>p.candidate)),diagnostics:Object.freeze(a.filter(p=>p.source==="bundled").map(p=>Object.freeze({...p}))),reservedAppIds:Object.freeze([...i.appIds]),reservedDefinitionIds:Object.freeze([...i.definitionIds])}):void 0,c={apps:s,diagnostics:a,complete:n===void 0,...n===void 0?{}:{incompleteReason:n},...t===void 0?{}:{productBundleIndexHash:t},...d===void 0?{}:{productBundleSnapshotMetadata:d}};return Object.defineProperty(c,"candidates",{configurable:false,enumerable:false,get:()=>s}),Object.freeze(c)}function Zc(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 Qc(e,n){if(Zc(e))return {fs:e,options:{}};let t=e??n??{};return {fs:t.filesystem??t.fileSystem??t.fs??ho,options:t}}async function Ko(e,n,t){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");let{fs:i,options:r}=Qc(n,t),o=r.clock??Vc,s=o(),a=await bo(r.productBundle,i,s,o),d=o(),c=BigInt(Date.now())*1000000n,p=[],y=0,A,I=false,E,O;if(r.scanCache!==void 0&&typeof i.getRootIdentity=="function"&&typeof i.fingerprintVerifiedFile=="function")try{O=await i.getRootIdentity(e),E=yo(r.scanCache,O),E.scanStartedAtNs=c;}catch(_){if(de(_)!=="NOT_FOUND")throw _}let b=E!==void 0&&r.productBundle===void 0&&a.packages.length===0&&a.diagnostics.length===0,j=new Set,C=true;p.push(...a.diagnostics.map(_=>({source:_.source,root:r.productBundle?.root??e,name:"",relativePath:_.relativePath,diagnostic:_})));let x=a.reservedIds;a.incomplete&&(A="time_limit");for(let _ of a.packages){if(!be(d,o)){I=true,A="time_limit";break}let h=_.indexEntry,S=h.packageDir,w=_.files===void 0?void 0:vc(S,_.files),u=a.indexHash===void 0?void 0:to(Object.freeze({kind:"bundled",launcher:h.launcher!==false,indexHash:a.indexHash,packageDir:S,appId:h.appId,definitionId:h.definition.id,version:h.definition.version,definitionHash:h.definition.hash,files:h.files}),w),f={source:"bundled",root:r.productBundle?.root??e,name:S.slice(5),relativePath:S,...u===void 0?{}:{provenance:u},..._.files===void 0?{}:{pinnedFiles:_.files},..._.lineage===void 0?{}:{bundleLineage:_.lineage},bundleIdentity:{appId:h.appId,definitionId:h.definition.id,version:h.definition.version,definitionHash:h.definition.hash},identity:xc(h)};if(p.push(f),y+=1,_.failureCode!==void 0){v(f,_.failureCode);continue}let g={};for(let P of J){let N=_.files?.get(P);N!==void 0&&(g[P]=N);}if(!Zt(g)){v(f,"BUNDLE_INTEGRITY");continue}if(await vo(i,f,g),!be(d,o)){I=true,A="time_limit";break}}let B=[{source:"apps",directory:"apps"},{source:"skills",directory:"skills"}];e:for(let _ of B){let{source:h,directory:S}=_,w;try{w=await Gc(i,e,S);}catch(f){if(de(f)==="NOT_FOUND")continue;b=false,C=false,p.push({source:h,root:e,name:"",relativePath:h,diagnostic:Bn(Qe(de(f),"manifest"),h,h)});continue}let u=w.filter(f=>f.kind==="directory"||f.kind==="symlink").filter(f=>Oc(f.name)).map(f=>({source:h,root:e,name:f.name,relativePath:Lc(h,f.name)})).sort((f,g)=>gn(f.relativePath,g.relativePath));for(let f of u){let g={...f};if(p.push(g),O!==void 0?j.add(Ho(O,g)):b=false,!be(d,o)){I=true,A="time_limit";break e}let P;if(E!==void 0&&O!==void 0){try{let H=await Fc(i,e,O,g,E,c,d,o);if(H.timeLimitReached){I=!0,A="time_limit";break e}g.scanContext=H.context,P=H.memo;}catch(H){b=false,v(g,Qe(de(H),"manifest"));continue}P===void 0&&(b=false);}if(P!==void 0){if(g.candidate=P.candidate,g.diagnostic=P.diagnostic,g.identity=P.identity,h==="skills"&&P.candidate===void 0&&P.diagnostic===void 0)continue;if(y>=64){v(g,"LIMIT_EXCEEDED");continue}if(f.relativePath.split("/").length-1>2){v(g,"LIMIT_EXCEEDED");continue}if(y+=1,!be(d,o)){I=true,A="time_limit";break e}continue}let N;if(h==="skills"&&(N=await Yc(i,g),N===void 0)){g.diagnostic===void 0&&Yt(g);continue}if(y>=64){v(g,"LIMIT_EXCEEDED");continue}if(f.relativePath.split("/").length-1>2){v(g,"LIMIT_EXCEEDED");continue}if(!be(d,o)){I=true,A="time_limit";break e}if(y+=1,N===void 0){let H=await Jo(i,g);if(H.failure!==void 0||!Zt(H.files)){v(g,H.failure??Qe("NOT_FOUND","manifest")),Yt(g);continue}N=H.files;}if(await vo(i,g,N),Yt(g),!be(d,o)){I=true,A="time_limit";break e}}}if(E!==void 0&&O!==void 0){let _=[...j].sort(gn),h=E.lastCandidateKeys,S=h!==void 0&&h.length===_.length&&h.every((u,f)=>u===_[f]);if(b=b&&S,C&&!I&&A===void 0)for(let u of E.candidates.keys())try{JSON.parse(u)[0]===O.realPath&&!j.has(u)&&E.candidates.delete(u);}catch{E.candidates.delete(u);}let w=[...E.candidates.keys()].filter(u=>{try{return JSON.parse(u)[0]===O.realPath}catch{return false}});b=b&&w.length===j.size&&w.every(u=>j.has(u))&&!I&&A===void 0,E.lastCandidateScanUnchanged=b,C&&!I&&A===void 0&&(E.lastCandidateKeys=Object.freeze(_));}return I&&p.push({source:"apps",root:e,name:"",relativePath:"apps",diagnostic:Bn("DISCOVERY_TIME_LIMIT","apps","apps")}),Kc(p,r,x),qc(p,A,a.indexHash,x,r.productBundle!==void 0)}var Nc,Xt,No,Mc,wo,Uo,Xo=V(()=>{m();Ce();hn();_e();Mt();Ue();Ct();Rn();Ao();Ht();wn();Kt();Kt();Nc=Vn([]),Xt="crewx_local_app_";No=["bundled","apps","skills"],Mc=new TextDecoder("utf-8",{fatal:true});wo=["","/ui"],Uo=2000000000n;});m();Mt();m();pt();m();var $i="SKILL.md",wa=/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;function Gi(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function Ua(e){return e.isDirectory()||e.isSymbolicLink()}function Yi(e){try{return existsSync(e)&&statSync(e).isDirectory()}catch{return false}}function Lt(e){let n;try{n=readFileSync(e,"utf8");}catch{return {frontmatter:{},readable:false,valid:false,hasFrontmatter:false}}let t=n.match(wa);if(!t)return {frontmatter:{},readable:true,valid:true,hasFrontmatter:false};try{let i=load(t[1]??"");if(!Gi(i))return {frontmatter:{},readable:!0,valid:!1,hasFrontmatter:!0};let r=Gi(i.metadata)?i.metadata:void 0;return {frontmatter:{...typeof i.name=="string"?{name:i.name}:{},...typeof(r?.version??i.version)=="string"?{version:r?.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 Ca(e){return [join(e,$i),join(e,"skill",$i)]}function Wi(e,n){if(!Yi(e))return null;for(let t of Ca(e)){if(!existsSync(t))continue;let r=Lt(t).frontmatter;return {name:r.name??n,...r.version===void 0?{}:{version:r.version},...r.description===void 0?{}:{description:r.description},skillMdPath:t,dir:e}}return null}function Ji(e){try{return readdirSync(e,{withFileTypes:!0}).filter(Ua)}catch{return []}}function Ki(e,n,t){!e||n.has(e.name)||(n.add(e.name),t.push(e));}function qi(e){let n=[],t=new Set;for(let i of e)if(Yi(i))for(let r of Ji(i)){if(r.name.startsWith("@")){let o=join(i,r.name);for(let s of Ji(o))Ki(Wi(join(o,s.name),s.name),t,n);continue}Ki(Wi(join(i,r.name),r.name),t,n);}return n.sort((i,r)=>i.name.localeCompare(r.name))}m();Mn();var ka=/^[A-Za-z0-9_$.[\]"-]{0,200}$/,xa=/^[a-z][a-z0-9-]{0,63}$/,va="<unknown>";function ja(e){return typeof e=="string"&&J.includes(e)}function Zi(e){if(typeof e!="object"||e===null)return;let{file:n,path:t,rule:i}=e;if(!(typeof i!="string"||!xa.test(i)))return {...ja(n)?{file:n}:{},path:typeof t=="string"&&ka.test(t)?t:va,rule:i}}function Qi(e){if(!Array.isArray(e))return;let n=J.filter(t=>e.includes(t));return n.length>0?n:void 0}Xo();var nd=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/;function zn(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?td(e.relativePath,e.fileBytes):void 0);if(n!==void 0&&i!==void 0){let r=JSON.stringify({screenHash:n,skillHash:i});return createHash("sha256").update(r,"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 td(e,n){let t=new TextEncoder().encode($n(e)),i=id(n),r=new Uint8Array(t.byteLength+1+i.byteLength);return r.set(t,0),r[t.byteLength]=0,r.set(i,t.byteLength+1),createHash("sha256").update(r).digest("hex")}function id(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 $n(e){if(typeof e!="string"||e.length===0||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 Hn(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let s=t[o]-i[o];if(s!==0)return s}return t.byteLength-i.byteLength}function Zo(e,n){let t=relative(e,n).split(sep).join("/");return !t||t===".."||t.startsWith("../")||isAbsolute(t)?null:$n(t)}function od(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 Qo(e){return Object.freeze({packageRoot:e})}function rd(e){return Object.freeze({id:e.definition.id,version:e.definition.version,hash:e.definition.hash,usage:e.definition.usage??Oe,...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 er(e){return {capabilities:Object.freeze([...e]),origin:"local",ownership:"unknown",shareability:"unknown",sharingAvailability:"unavailable"}}function sd(e,n){let t=e.candidate,i=t.provenance!==void 0,r=n&&!i?["screen","skill"]:["screen"],o=rd(t),s=zn(n?{screenHash:o.hash,skillHash:n.skillHash}:{screenHash:o.hash}),a=t.description||n?.skill.description||"",d=t.releaseVersion??String(t.version),c={appId:t.pluginId,name:t.name,description:a,version:d,...er(r),definition:o,...n===void 0||i?{}:{skillName:n.skill.name},...i?{provenance:t.provenance}:{localDefinitionRef:Qo(e.packageRoot)},definitionHash:s,...t.manifest.csp===void 0?{}:{connectDomains:Object.freeze([...t.manifest.csp.connectDomains])}};return {...i?{}:{packageRoot:e.packageRoot},source:i?"bundled":t.source,appId:c.appId,capabilities:r,summary:Object.freeze(c)}}function ad(e){let n=cd(e.skill.name),t={appId:n,name:e.skill.name,description:e.skill.description??"",...e.skill.version===void 0?{}:{version:e.skill.version},...er(["skill"]),skillName:e.skill.name,localDefinitionRef:Qo(e.packageRoot),definitionHash:zn({skillHash:e.skillHash})};return {packageRoot:e.packageRoot,source:e.source,appId:n,capabilities:["skill"],summary:Object.freeze(t)}}function cd(e){return `skill.${e.replace(/^@/,"").replace(/\//g,".").replace(/[^A-Za-z0-9._-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,122)||"unnamed"}`}function K(e,n,t,i,r){let o=Zi(r?.reason),s=Qi(r?.files);return Object.freeze({code:e,source:n,relativePath:dd(t),...i===void 0?{}:{appId:i},...o===void 0?{}:{reason:o},...s===void 0?{}:{files:s}})}function dd(e){if(typeof e!="string"||e.length===0||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 nr(e){return K(e.code,e.source,e.relativePath,e.pluginId,e)}function pd(e,n){let t=Zo(e,n.dir);if(!t)return {diagnostic:K("PATH_ESCAPED","node_modules","node_modules")};let i=od(t);if(!i)return {diagnostic:K("PATH_ESCAPED","node_modules",t)};let r=Lt(n.skillMdPath);if(!r.readable)return {diagnostic:K("SKILL_READ_FAILED",i,t)};if(!r.valid)return {diagnostic:K("SKILL_INVALID",i,t)};let o=ld(n.dir,n.skillMdPath);if(!o)return {diagnostic:K("PATH_ESCAPED",i,t)};try{let s=new Uint8Array(readFileSync(n.skillMdPath));return {skill:n,packageRoot:t,relativeSkillPath:o,skillHash:zn({relativePath:o,fileBytes:s}),source:i}}catch{return {diagnostic:K("SKILL_READ_FAILED",i,t)}}}function ld(e,n){let t=relative(e,n).split(sep).join("/");try{return $n(t)}catch{return null}}function ud(e){if(!nd.test(e.appId))return {diagnostic:K("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??Oe,...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??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 fd(e){return e.builtinCatalog}function yd(e){let n=e.packageRoot??e.relativePath??e.packageRootPath;if(n===void 0)return null;try{return $n(n)}catch{return null}}function Ad(e){let n=e.marketplaceContentId;return typeof n=="string"&&n.length>0?n:void 0}function Id(e,n,t){let i=n.installed??[],r=new Map;for(let s of i){let a=yd(s);if(!a){t.push(K("INSTALLED_IDENTITY_MISMATCH","installed","installed"));continue}let d=r.get(a);if(d&&JSON.stringify(d)!==JSON.stringify(s)){t.push(K("INSTALLED_IDENTITY_MISMATCH","installed",a));continue}r.set(a,s);}let o=new Map;for(let s of e)s.packageRoot!==void 0&&o.set(s.packageRoot,s);for(let[s,a]of r){let d=o.get(s);if(!d){t.push(K("INSTALLED_MISSING","installed",s,a.appId));continue}let c=Ad(a);if(!c){t.push(K("INSTALLED_CONTENT_ID_MISSING","installed",s,a.appId));continue}if(a.appId!==void 0&&a.appId!==d.appId||a.definitionHash!==void 0&&a.definitionHash!==d.summary.definitionHash){t.push(K("INSTALLED_IDENTITY_MISMATCH","installed",s,a.appId));continue}let p={...d.summary,origin:"installed",...a.slug===void 0?{}:{slug:a.slug},marketplaceContentId:c},y=e.indexOf(d);y>=0&&(e[y]={...d,summary:Object.freeze(p)});}}function gd(e,n){let t=new Map;for(let r of e){let o=t.get(r.appId)??[];o.push(r),t.set(r.appId,o);}let i=new Set;for(let r of t.values()){if(r.length<2)continue;let o=r.some(s=>s.source==="builtin")?"builtin":r.some(s=>s.source==="bundled")?"bundled":void 0;if(o!==void 0){let s=r.filter(a=>a.source===o);for(let a of r.filter(d=>d.source!==o))i.add(a),n.push(K("RESERVED_ID",a.source,ei(a),a.appId));if(s.length>1)for(let a of s)i.add(a),n.push(K("DUPLICATE_ID",a.source,ei(a),a.appId));continue}for(let s of r)i.add(s),n.push(K("DUPLICATE_ID",s.source,ei(s),s.appId));}return e.filter(r=>!i.has(r))}function ei(e){return e.packageRoot??e.summary.provenance?.packageDir??`builtin/${e.appId}`}function md(e,n){return e.filter(t=>!(t.code==="MANIFEST_MISSING"&&n.has(t.relativePath))).map(nr)}function hd(e){return e.filesystem}function _d(e,n){let t=hd(e),i=e.registeredProductBundle;return {...t===void 0?{}:{filesystem:t},...e.productBundle===void 0?{}:{productBundle:e.productBundle},...n===void 0?{}:{builtinCatalog:n},...i===void 0?{}:{reservedAppIds:i.reservedAppIds,reservedDefinitionIds:i.reservedDefinitionIds}}}async function tr(e,n={}){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");if(n.productBundle!==void 0&&n.registeredProductBundle!==void 0)throw new TypeError("registeredProductBundle cannot be combined with product bundle discovery");let t=fd(n),i=await Ko(e,_d(n,t)),r=n.registeredProductBundle??i.productBundleSnapshotMetadata,o=[join(e,"skills"),join(e,"node_modules"),join(e,"apps")],s=[],a=[],d=[],c=new Set;for(let f of o)for(let g of qi([f])){let P=Zo(e,g.dir);(P===null||!c.has(P))&&(d.push(g),P!==null&&c.add(P));}for(let f of d){let g=pd(e,f);"diagnostic"in g?s.push(g.diagnostic):a.push(g);}let p=new Map,y=n.registeredProductBundle?.indexHash,A=(n.registeredProductBundle?.candidates??[]).filter(f=>y!==void 0&&f.provenance?.indexHash===y),I=[...i.apps??i.candidates??[],...A],E=new Set(A),O=new Set(y===void 0?[]:(t?.listMcpApps()??[]).filter(f=>f.provenance?.indexHash===y).map(f=>f.appId));for(let f of I){if(E.has(f)&&f.provenance?.indexHash===y&&O.has(f.appId))continue;let g=f.provenance===void 0?`workspace\0${f.relativePath}`:`bundled\0${f.provenance.indexHash}\0${f.provenance.packageDir}`;p.set(g,{candidate:f,packageRoot:f.relativePath});}let b=new Map(a.map(f=>[f.packageRoot,f])),j=[];for(let f of p.values()){let g=f.candidate.provenance===void 0?b.get(f.packageRoot):void 0,P=sd(f,g);j.push({...P.packageRoot===void 0?{}:{packageRoot:P.packageRoot},source:P.source,appId:P.appId,summary:P.summary});}let C=new Set([...p.values()].filter(f=>f.candidate.provenance===void 0).map(f=>f.packageRoot)),x=r===void 0?new Set:new Set(i.diagnostics.filter(f=>f.code==="RESERVED_ID"&&f.source!=="bundled").map(f=>f.relativePath)),B=new Set(r?.reservedAppIds??[]);for(let f of a){let g=ad(f);if(!(C.has(f.packageRoot)||x.has(f.packageRoot))){if(B.has(g.appId)){s.push(K("RESERVED_ID",f.source,f.packageRoot,g.appId));continue}j.push({packageRoot:g.packageRoot,source:g.source,appId:g.appId,summary:g.summary});}}let _=[...md(i.diagnostics,new Set(a.map(f=>f.packageRoot))),...s,...n.registeredProductBundle?.diagnostics.filter(f=>f.source==="bundled").map(nr)??[]],h=[];if(t)for(let f of t.listMcpApps()){let g=ud(f);"diagnostic"in g?_.push(g.diagnostic):h.push(g);}let S=gd([...j,...h],_);Id(S,n,_);let w=S.map(f=>f.summary).sort((f,g)=>Hn(f.appId,g.appId)),u=[..._].sort((f,g)=>Hn(f.relativePath,g.relativePath)||Hn(f.code,g.code)||Hn(f.appId??"",g.appId??""));return Object.freeze({items:Object.freeze(w),diagnostics:Object.freeze(u)})}m();m();m();function Ed(e){let n=r=>r.replace(/[.+^${}()|[\]\\]/g,"\\$&"),i=e.split("/").map(r=>r==="**"?".*":r.split("*").map(n).join("[^/]*"));return new RegExp(`^${i.join("\\/")}$`)}function en(e,n){try{return Ed(n).test(e)}catch{return false}}function Gn(e,...n){let t=e.split("/");if(t.length<n.length)return false;let i=t.length-n.length;return n.every((r,o)=>en(t[i+o],r))}function Td(e,n){return e.split("/").some(t=>en(t,n))}var ir=[{label:".env*",test:e=>en(e,".env*")},{label:".git/",test:(e,n,t)=>t&&e===".git"},{label:"memory/",test:(e,n,t)=>t&&e==="memory"},{label:"*.key",test:e=>en(e,"*.key")},{label:"*.pem",test:e=>en(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&&Gn(n,".crewx","threads")},{label:".crewx/crewx.db",test:(e,n,t)=>!t&&Gn(n,".crewx","crewx.db")},{label:".crewx/*.log",test:(e,n,t)=>!t&&Gn(n,".crewx","*.log")},{label:".crewx/publish/",test:(e,n,t)=>t&&Gn(n,".crewx","publish")},{label:".crewx/",test:(e,n)=>Td(n,".crewx")}];function Wn(e,n,t){for(let i of ir)if(i.test(e,n,t))return i.label;return null}function ii(e){let n=[],t=[];function i(r,o,s){let a;try{a=X.readdirSync(r,{withFileTypes:!0});}catch{return}a.sort((d,c)=>d.name.localeCompare(c.name));for(let d of a){let c=o?`${o}/${d.name}`:d.name,p=ee.join(r,d.name);if(d.isSymbolicLink()){let y;try{y=X.statSync(p);}catch{t.push({path:c,rule:"symlink"});continue}if(y.isDirectory()){t.push({path:c,rule:s??"symlink-dir"});continue}let A=s??Wn(d.name,c,false);A?t.push({path:c,rule:A}):t.push({path:c,rule:"symlink"});continue}if(d.isDirectory()){let y=s??Wn(d.name,c,true);i(p,c,y);continue}if(d.isFile()){let y=s??Wn(d.name,c,false);y?t.push({path:c,rule:y}):n.push(c);}}}return i(e,"",null),n.sort(),t.sort((r,o)=>r.path<o.path?-1:r.path>o.path?1:0),{included:n,excluded:t}}m();var Pd=[{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 Dd(e){return e.includes(0)}function oi(e,n,t){let i=[];for(let r of n){let o=ee.join(e,r),s;try{let d=t?.get(r);s=d===void 0?X.readFileSync(o):Buffer.from(d);}catch{continue}if(Dd(s))continue;s.toString("utf8").split(/\r\n|\r|\n/).forEach((d,c)=>{for(let{rule:p,regex:y}of Pd)y.test(d)&&i.push({path:r,line:c+1,rule:p});});}return i}m();m();var Se=class extends Error{constructor(t,i){super(`publish: [${t}]${i?` ${i}`:""}`);this.code=t;}code;name="PublishError"};function T(e,n){return new Se(e,n)}var ar=/^[a-z0-9-]+$/,bd=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/,Nd=/^[A-Za-z_][A-Za-z0-9_]*$/;function Sd(e){let n=ee.join(e,"crewx.yaml");if(!X.existsSync(n))return {};let t;try{t=cr.load(X.readFileSync(n,"utf8"));}catch{return {}}if(!t||typeof t!="object")return {};let i=t.metadata;if(!i||typeof i!="object")return {};let r=i;return {name:typeof r.name=="string"?r.name:void 0,version:typeof r.version=="string"?r.version:void 0,description:typeof r.description=="string"?r.description:void 0,requiredEnv:r.requiredEnv,crewxMinVersion:typeof r.crewxMinVersion=="string"?r.crewxMinVersion:void 0}}function Md(e){return ri.createHash("sha256").update(e).digest("hex")}function dr(e){let n;try{n=X.lstatSync(e);}catch{throw T("PACKAGE_FILE_INVALID",`file is not readable: ${ee.basename(e)}`)}if(n.isSymbolicLink())throw T("PACKAGE_SYMLINK","symlink content is not publishable");if(!n.isFile())throw T("PACKAGE_FILE_INVALID","only regular files are publishable");return ri.createHash("sha256").update(new Uint8Array(X.readFileSync(e))).digest("hex")}function Ld(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),r=Math.min(t.byteLength,i.byteLength);for(let o=0;o<r;o+=1){let s=t[o]-i[o];if(s!==0)return s}return t.byteLength-i.byteLength}function pr(e){if(typeof e!="string"||e.length===0||e.includes("\\")||e.includes("\0")||ee.posix.isAbsolute(e)||e.split("/").some(n=>n===".."||n.length===0))throw T("PACKAGE_PATH_TRAVERSAL","manifest file path must be a non-empty POSIX relative path")}function Od(e){if(!/^(?:apps|skills)\/[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(e))throw T("APP_PACKAGE_ROOT_INVALID","packageRoot must be apps/<safe-id> or skills/<safe-id>")}function lr(e){if(!bd.test(e))throw new Error(`publish: invalid version "${e}" \u2014 must be semver (e.g. 1.0.0)`)}function ur(e,n,t={}){let i=Sd(e),r=i.name??ee.basename(e);if(!ar.test(r))throw new Error(`publish: invalid name "${r}" \u2014 must match ${ar} (lowercase letters, numbers, hyphen only)`);let o=t.version??i.version;if(!o)throw new Error("publish: version is required \u2014 set crewx.yaml metadata.version or pass opts.version");lr(o);let s=Array.isArray(i.requiredEnv)?i.requiredEnv:[],a=[];for(let p of s){if(typeof p!="string"||!Nd.test(p))throw new Error(`publish: requiredEnv must contain names only (no values), got "${String(p)}"`);a.push(p);}let d=n.map(p=>(pr(p),{path:p,sha256:dr(ee.join(e,p))})).sort((p,y)=>p.path<y.path?-1:p.path>y.path?1:0),c={name:r,version:o,type:"template",description:i.description??"",files:d,requiredEnv:a};return i.crewxMinVersion&&(c.crewxMinVersion=i.crewxMinVersion),c}function Rd(e){let n=e.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/-+/g,"-").replace(/^-+|-+$/g,"");if(!n)throw T("APP_PACKAGE_ROOT_INVALID","appId cannot produce a marketplace name");return n}function fr(e,n){if(Od(n.packageRoot),!n.version)throw new Error("publish: version is required for App publishing \u2014 pass opts.version");if(lr(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 T("APP_UI_MANIFEST_INVALID","screen App manifests require definitionId");let s=n.includedFiles.includes(`${i}manifest.json`),a=n.includedFiles.includes(`${i}ui-plugin.json`);if(!s&&!a)throw T("APP_UI_MANIFEST_INVALID","screen App is missing manifest.json or ui-plugin.json");if(s&&!a)throw T("APP_UI_MANIFEST_INVALID","a manifest.json App must also ship a generated ui-plugin.json");if(!n.includedFiles.includes(`${i}ui/index.html`))throw T("APP_UI_MANIFEST_INVALID","screen App is missing ui/index.html")}if(t.includes("skill")&&!n.includedFiles.includes(`${i}SKILL.md`))throw T("APP_SKILL_MISSING","skill capability requires package-root SKILL.md");let r=new Set,o=n.includedFiles.map(s=>{if(pr(s),!s.startsWith(i))throw T("PACKAGE_PATH_TRAVERSAL","App manifest file is outside packageRoot");let a=n.generatedFiles?.get(s);return a!==void 0&&r.add(s),{path:s,sha256:a===void 0?dr(ee.join(e,s)):Md(a),...a===void 0?{}:{generated:true}}}).sort((s,a)=>Ld(s.path,a.path));if(r.size>0&&(r.size!==1||!r.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:Rd(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:o,requiredEnv:[]}}m();function yr(e){return ri.createHash("sha256").update(e).digest("hex")}function hr(e,n){if(typeof n!="string"||n.length===0||n.includes("\\")||n.includes("\0")||ee.posix.isAbsolute(n)||n.split("/").some(r=>r===".."||r.length===0))throw T("PACKAGE_PATH_TRAVERSAL","archive paths must be non-empty POSIX relative paths");let t=ee.resolve(e),i=ee.resolve(t,...n.split("/"));if(i!==t&&!i.startsWith(`${t}${ee.sep}`))throw T("PACKAGE_PATH_TRAVERSAL","archive path escaped its root");return i}function Ar(e,n){let t=hr(e,n),i;try{i=X.lstatSync(t);}catch{throw T("PACKAGE_FILE_INVALID","manifest file is missing")}if(i.isSymbolicLink())throw T("PACKAGE_SYMLINK","symlink content is not publishable");if(!i.isFile())throw T("PACKAGE_FILE_INVALID","only regular files are publishable");return new Uint8Array(X.readFileSync(t))}async function _r(e,n,t={}){let i=ee.join(e,".crewx","publish");X.mkdirSync(i,{recursive:true});let r=ee.join(i,`${n.name}-${n.version}.tgz`),o=ee.join(i,`.${n.name}-${n.version}.${process.pid}-${Date.now()}-${Math.random().toString(16).slice(2)}.tmp.tgz`),s=X.mkdtempSync(ee.join(Ir.tmpdir(),"crewx-publish-"));try{let a=new Set,d=[];for(let c of n.files){if(a.has(c.path))throw T("PACKAGE_PATH_TRAVERSAL","manifest contains duplicate file paths");a.add(c.path);let p=t.generatedFiles?.get(c.path);if(c.generated===!0&&p===void 0)throw T("PACKAGE_GENERATED_FILE_MISSING","generated manifest file bytes are missing");if(t.sourceFileHashes?.has(c.path)){let I=Ar(e,c.path);if(t.sourceFileHashes.get(c.path)!==yr(I))throw T("PACKAGE_STAGED_BYTES_MISMATCH","workspace source changed before staging")}let y=p??Ar(e,c.path);if(yr(y)!==c.sha256)throw T("PACKAGE_STAGED_BYTES_MISMATCH",`staged bytes differ for ${c.path}`);let A=hr(s,c.path);X.mkdirSync(ee.dirname(A),{recursive:!0}),X.writeFileSync(A,new Uint8Array(y)),d.push(c.path);}X.writeFileSync(ee.join(s,"manifest.json"),JSON.stringify(n,null,2)),await mr.create({gzip:!0,file:o,cwd:s,portable:!0,noMtime:!0},["manifest.json",...d]),X.renameSync(o,r);}finally{try{X.rmSync(o,{force:!0});}catch{}X.rmSync(s,{recursive:true,force:true});}return r}m();m();var nn="/api/v1";var Cd=201,kd=200,xd=409,si=401,Er={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 vd(){return process.env.WI013_FAKE_UPLOAD==="1"}function jd(e){let n=gunzipSync(new Uint8Array(e)),t=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 Vd(e){return e.replace(/\/+$/,"")}async function mn(e){try{return await e.json()}catch{return null}}function Tr(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 Fd(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 Bd(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 Pr(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,r=[t.code,t.message,i?.code,i?.message];for(let o of r){if(typeof o!="string"||!Object.prototype.hasOwnProperty.call(Er,o))continue;let s=o,a=s==="APP_NAME_CONFLICT"?`marketplace name is already in use: ${n}`:void 0;return T(Er[s],a)}}async function Hd(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=Vd(e.baseUrl),t=e.accessPolicy??"private",i=e.manifest.name,r=e.manifest.type==="app"?e.manifest:void 0,o=r!==void 0,s=r?.appId,a;try{a=await fetch(`${n}${nn}/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 d=await mn(a),c=Fd(d),p=Bd(d),y=o&&p!==void 0?p:i,A;if(a.status===Cd)A="created";else if(o&&a.status===kd){if(c===void 0)throw T("PUBLISH_CONTENT_ID_MISSING","App republish did not return an opaque contentId");A="existing";}else if(a.status===xd){if(o)throw Pr(d,i)??T("APP_NAME_CONFLICT",`marketplace name is already in use: ${i}`);A="existing";}else throw a.status===si?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 I="not-needed",E=null;if(A==="existing"&&!o){let S;try{S=await fetch(`${n}${nn}/publisher/items`,{method:"GET",headers:{Authorization:`Bearer ${e.accessToken}`}});}catch{throw new Error("publish: [E_NETWORK] Publisher items request failed (network)")}let w=await mn(S);if(S.status!==200)throw new Error(`publish: [E_HTTP] Publisher items request failed \u2014 HTTP ${S.status}`);let f=Tr(w,"publisher items",S.status)?.items;if(!Array.isArray(f))throw new Error(`publish: [E_MALFORMED] Publisher items response is malformed (expected data.items[]) \u2014 HTTP ${S.status}`);let g=f.find(P=>!P||typeof P!="object"?false:P.slug===i);if(!g||typeof g.version!="string")throw new Error(`publish: [E_MALFORMED] Publisher items response does not contain slug "${i}" \u2014 HTTP ${S.status}`);if(E=g.version,E!==e.manifest.version){let P;try{P=await fetch(`${n}${nn}/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(!P.ok)throw await mn(P),P.status===si?new Error(`publish: [E_AUTH_EXPIRED] Authentication is expired or missing \u2014 please log in again (HTTP ${P.status})`):P.status===403?new Error(`publish: [E_FORBIDDEN] Version update is forbidden; only the item owner can update an existing item (HTTP ${P.status})`):new Error(`publish: [E_HTTP] Version update failed \u2014 HTTP ${P.status}`);I="applied";}}let O=X.readFileSync(e.tgzPath),b=vd()?jd(O):O,j=new FormData;j.set("archive",new Blob([new Uint8Array(b)],{type:"application/gzip"}),`${y}-${e.manifest.version}.tgz`);let C=o&&c!==void 0?c:i,x;try{x=await fetch(`${n}${nn}/publisher/items/${encodeURIComponent(C)}/upload`,{method:"POST",headers:{Authorization:`Bearer ${e.accessToken}`},body:j});}catch{throw new Error("publish: [E_NETWORK] Upload request failed (network)")}if(x.status===si)throw new Error("publish: [E_AUTH_EXPIRED] Authentication is expired or missing \u2014 please log in again (HTTP 401)");if(!x.ok){let S=await mn(x);if(o){let w=Pr(S,y);if(w)throw w}throw new Error(`publish: [E_HTTP] Upload request failed \u2014 HTTP ${x.status}`)}let B=await mn(x),_=Tr(B,"upload",x.status),h=typeof _.contentId=="string"&&_.contentId.length>0?_.contentId:c;if(o&&h===void 0)throw T("PUBLISH_CONTENT_ID_MISSING","App upload did not return an opaque contentId");return {slug:y,version:e.manifest.version,...h===void 0?{}:{contentId:h},artifactChecksum:_.artifactChecksum,artifactSizeBytes:_.artifactSizeBytes,submitOutcome:A,versionUpdate:I,serverVersionBefore:E}}var zd=1e4,$d=100*1024*1024;function ai(e){return ri.createHash("sha256").update(e).digest("hex")}function Gd(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function Kn(e,n){if(!n||n.includes("\\")||n.includes("\0")||ee.posix.isAbsolute(n)||n.split("/").some(o=>o===".."||o.length===0))throw T("PACKAGE_PATH_TRAVERSAL","workspace file path is not a safe relative path");let t=ee.resolve(e,...n.split("/")),i=ee.resolve(e);if(t!==i&&!t.startsWith(`${i}${ee.sep}`))throw T("PACKAGE_PATH_TRAVERSAL","workspace file path escaped the workspace root");let r;try{r=X.lstatSync(t);}catch{throw T("PACKAGE_FILE_INVALID",`workspace file is missing: ${n}`)}if(r.isSymbolicLink())throw T("PACKAGE_SYMLINK",`symlink is not publishable: ${n}`);if(!r.isFile())throw T("PACKAGE_FILE_INVALID",`not a regular file: ${n}`);return new Uint8Array(X.readFileSync(t))}function Xn(e,n){return e===n||e.startsWith(`${n}/`)}function Wd(e,n){return e.path<n.path?-1:e.path>n.path?1:e.rule.localeCompare(n.rule)}function br(e,n,t){let i=e??n;if(!Number.isSafeInteger(i)||i<=0)throw new Se("PACKAGE_SIZE_LIMIT",`${t} must be a positive integer`);return i}function Sr(e,n,t,i){let r=br(t.maxFileCount??t.maxFiles,zd,"max file count"),o=br(t.maxTotalBytes??t.maxBytes,$d,"max total bytes");if(n.length>r)throw new Se("PACKAGE_SIZE_LIMIT",`package exceeds file count limit (${r})`);let s=0;for(let a of n){let d=i?.get(a);if(d!==void 0?s+=d.byteLength:s+=Kn(e,a).byteLength,s>o)throw new Se("PACKAGE_SIZE_LIMIT",`package exceeds byte limit (${o})`)}}function Jd(e){return e.appId!==void 0||e.expectedDefinitionHash!==void 0}function Kd(e){let n=e.appId!==void 0,t=e.expectedDefinitionHash!==void 0;if(!n&&t)throw T("APP_ID_REQUIRED","appId is required with expectedDefinitionHash");if(n&&!t)throw T("APP_DEFINITION_HASH_REQUIRED","expectedDefinitionHash is required with appId");if(!n||!t)throw T("APP_ID_REQUIRED")}function Xd(e,n){let t=e.filter(i=>i.appId===n);if(t.length===0)throw T("APP_NOT_FOUND",`no publishable App matches ${n}`);if(t.length!==1)throw T("APP_AMBIGUOUS",`more than one App matches ${n}`);return t[0]}function Yd(e){let n=e.localDefinitionRef?.packageRoot;if(!n||!/^(?:apps|skills)\/[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(n))throw T("APP_PACKAGE_ROOT_INVALID","selected App is not rooted in apps/<safe-id> or skills/<safe-id>");return n}function qd(e,n){let t=[];for(let i of e.excluded)t.push(Xn(i.path,n)?i:{path:i.path,rule:"out-of-app-scope"});for(let i of e.included)Xn(i,n)||t.push({path:i,rule:"out-of-app-scope"});return t.sort(Wd)}function ci(e){let{path:n,rule:t}=e.reason;return `${e.code} at ${n===""?"<file>":n} (${t})`+(e.files.length>0?` [${e.files.join(", ")}]`:"")}function Zd(e,n,t){let i=ve({[ie]:t},{mode:"published"});if(!i.ok)throw T("APP_UI_MANIFEST_INVALID",`generated ${ie} does not read: ${ci(i.rejection)}`);if(Xe(i.manifest)!==Xe(n))throw T("APP_UI_MANIFEST_INVALID",`generated ${ie} normalizes to a different definition hash than the source`);let r=e[Y];if(r===void 0)return;let o=ve({[Y]:r,[ie]:t},{mode:"local"});if(!o.ok)throw T("APP_UI_MANIFEST_INVALID",ci(o.rejection))}function Qd(e,n,t,i){let r={};for(let A of J){let I=`${t}/${A}`;i.includes(I)&&(r[A]=Kn(e,I));}if(Object.keys(r).length===0)throw T("APP_UI_MANIFEST_INVALID","selected screen App has no package manifest.json or ui-plugin.json");let o=ve(r,{mode:"local"});if(!o.ok)throw T("APP_UI_MANIFEST_INVALID",ci(o.rejection));if(o.manifest.pluginId!==n.appId)throw T("APP_DEFINITION_CONFLICT",`${o.file} identity no longer matches the selected App`);let s=r[ie],a=s===void 0?void 0:ai(s),d=`${t}/ui/index.html`;if(!i.includes(d))throw T("APP_UI_MANIFEST_INVALID","screen entry is outside package scope");let c=ai(Kn(e,d)),p=JSON.parse(JSON.stringify(o.v2Input));if(p.entryHash=c,Object.prototype.hasOwnProperty.call(p,"initialState")){let A=p.initialState;if(!Gd(A)||A.path!=="ui/state.json")throw T("APP_INITIAL_STATE_OUT_OF_SCOPE","initialState must reference ui/state.json inside the package");let I=`${t}/ui/state.json`;if(!i.includes(I))throw T("APP_INITIAL_STATE_OUT_OF_SCOPE","initialState reference is outside the selected package");let E=Kn(e,I);p.initialState={...A,hash:ai(E)};}let y;try{let A=xe(p,{mode:"published"});y=new Uint8Array(Buffer.from(JSON.stringify(A),"utf8"));}catch(A){throw A instanceof Q?T("APP_UI_MANIFEST_INVALID",A.code):T("APP_UI_MANIFEST_INVALID")}return Zd(r,o.manifest,y),{bytes:y,...a===void 0?{}:{legacySourceHash:a}}}async function ep(e,n){let{included:t,excluded:i}=ii(e);Sr(e,t,n);let r=ur(e,t,{version:n.version}),o=oi(e,t);return {plan:{manifest:r,included:t,excluded:i,secretFindings:o},archiveOptions:{}}}async function np(e,n){Kd(n);let t=await tr(e),i=Xd(t.items,n.appId);if(i.definitionHash!==n.expectedDefinitionHash)throw T("APP_DEFINITION_CONFLICT",`definitionHash changed for ${n.appId}`);let r=Yd(i),o=ii(e);if(o.excluded.some(I=>Xn(I.path,r)&&(I.rule==="symlink"||I.rule==="symlink-dir")))throw T("PACKAGE_SYMLINK","selected App package contains a symlink");let s=o.included.filter(I=>Xn(I,r)),a=qd(o,r),d=new Map,c=new Map;if(i.capabilities.includes("screen")){let I=Qd(e,i,r,s),E=`${r}/${ie}`;d.set(E,I.bytes),I.legacySourceHash!==void 0?c.set(E,I.legacySourceHash):(s.push(E),s.sort());}if(i.capabilities.includes("skill")&&!s.includes(`${r}/SKILL.md`))throw T("APP_SKILL_MISSING","skill capability requires package-root SKILL.md");Sr(e,s,n,d);let p={appId:i.appId,version:n.version??"",description:i.description,capabilities:i.capabilities,packageRoot:r,...i.definition?.id===void 0?{}:{definitionId:i.definition.id},definitionHash:i.definitionHash,includedFiles:s,generatedFiles:d},y=fr(e,p),A=oi(e,s,d);return {plan:{manifest:y,included:s,excluded:a,secretFindings:A},archiveOptions:{generatedFiles:d,sourceFileHashes:c}}}async function Mr(e,n){let t=ee.resolve(e);if(Jd(n))return np(t,n);if(n.expectedDefinitionHash!==void 0)throw T("APP_ID_REQUIRED");return ep(t,n)}async function Gf(e,n={}){return (await Mr(e,n)).plan}function tp(e){let n=e.map(t=>`${t.path}:${t.line} (${t.rule})`).join(", ");throw new Se("PUBLISH_SECRET_FINDINGS",`aborted \u2014 secret findings must be resolved before packing: ${n}`)}async function Lr(e,n={}){let t=ee.resolve(e),i=await Mr(t,n);i.plan.secretFindings.length>0&&tp(i.plan.secretFindings);let r=await _r(t,i.plan.manifest,i.archiveOptions);return {manifest:i.plan.manifest,tgzPath:r}}async function Wf(e,n={}){return Lr(e,n)}async function Jf(e,n){let t=await Lr(e,n);if(t.manifest.type!=="app")throw new Error("publish: App pack unexpectedly produced a template manifest");return t}
|
|
2
|
+
export{$d as DEFAULT_PUBLISH_MAX_BYTES,zd as DEFAULT_PUBLISH_MAX_FILES,ir as EXCLUDE_RULES,nn as MARKETPLACE_API_PREFIX,Se as PublishError,Jf as packApp,Lr as packPublish,Wf as packTemplate,Gf as planPublish,Hd as uploadToMarketplace};
|