@crewx/sdk 0.9.0-rc.130 → 0.9.0-rc.131

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.
@@ -144,7 +144,7 @@ ${r.join(`
144
144
  THEN COALESCE(t.cached_input_tokens, 0)
145
145
  ELSE 0
146
146
  END
147
- `,u=r?sql`WHERE ${i} AND t.started_at >= ${e} AND t.started_at < ${n} AND t.workspace_id = ${r}`:sql`WHERE ${i} AND t.started_at >= ${e} AND t.started_at < ${n}`,f=o.db.all(sql`
147
+ `,u=r?sql`WHERE ${i} AND t.started_at >= ${e} AND t.started_at < ${n} AND t.workspace_id = ${r} AND t.agent_id != 'workflow'`:sql`WHERE ${i} AND t.started_at >= ${e} AND t.started_at < ${n} AND t.agent_id != 'workflow'`,f=o.db.all(sql`
148
148
  SELECT
149
149
  t.agent_id,
150
150
  t.workspace_id,
@@ -184,6 +184,7 @@ ${r.join(`
184
184
  AND t.started_at >= ${e}
185
185
  AND t.started_at < ${n}
186
186
  AND t.workspace_id = ${r}
187
+ AND t.agent_id != 'workflow'
187
188
  GROUP BY date(t.started_at), t.agent_id
188
189
  ORDER BY date(t.started_at) ASC
189
190
  `:sql`
@@ -211,6 +212,7 @@ ${r.join(`
211
212
  WHERE ${s}
212
213
  AND t.started_at >= ${e}
213
214
  AND t.started_at < ${n}
215
+ AND t.agent_id != 'workflow'
214
216
  GROUP BY date(t.started_at), t.agent_id
215
217
  ORDER BY date(t.started_at) ASC
216
218
  `).map(c=>({date:c.date,agentId:c.agent_id,unavailableTaskCount:c.unavailable_task_count,inputTokens:c.input_tokens,outputTokens:c.output_tokens,cachedInputTokens:c.cached_input_tokens,costUsd:c.cost_usd,totalTokens:c.input_tokens+c.output_tokens}))}catch(s){throw new l("DB_ERROR","Failed to get agent usage trend",s)}finally{o.close();}}findTaskForStop(e,n){if(!this.dbExists())return;let r=this.openHandle(false);try{let o=r.db.select().from(a).where(and(eq(a.id,e),eq(a.workspace_id,n))).limit(1).get();return o?ot(o):void 0}catch(o){throw new l("DB_ERROR","Failed to find task for stop",o)}finally{r.close();}}findLatestTaskByMetadata(e){if(!this.dbExists())return null;let n=this.openHandle(false);try{return n.db.select({id:a.id,thread_id:a.thread_id,status:a.status,result:a.result,error:a.error,started_at:a.started_at,completed_at:a.completed_at,metadata:a.metadata}).from(a).where(and(eq(a.agent_id,e.agentId),eq(a.workspace_id,e.workspaceId),sql`${a.metadata} IS NOT NULL AND json_valid(${a.metadata}) AND json_extract(${a.metadata}, '$.' || ${e.metaKey}) = ${e.metaValue}`)).orderBy(desc(a.started_at)).limit(1).get()??null}catch(r){throw new l("DB_ERROR","Failed to find latest task by metadata",r)}finally{n.close();}}markTaskFailed(e,n,r,o="failed",s){if(!this.dbExists())return;let i=this.openHandle(true);try{let d=new Date().toISOString(),c=r?and(eq(a.id,e),eq(a.status,"running"),eq(a.workspace_id,r)):and(eq(a.id,e),eq(a.status,"running")),u=i.db.select({metadata:a.metadata}).from(a).where(c).limit(1).get();if(!u)return;let f={status:o,error:n,completed_at:d};if(s){let p=pe(u.metadata);p.terminalReason=s,f.metadata=JSON.stringify(p);}i.db.update(a).set(f).where(c).run();}catch(d){throw d instanceof l?d:new l("DB_ERROR","Failed to mark task failed",d)}finally{i.close();}}findTasksByPromptHint(e,n){let r=this.resolveDbPaths(),o=new Set,s=[];for(let i of r){if(!existsSync(i))continue;let d=P(i);try{let c=n?and(like(a.prompt,`%${e}%`),eq(a.workspace_id,n)):like(a.prompt,`%${e}%`),u=d.db.select().from(a).where(c).orderBy(asc(a.started_at)).all();for(let f of u)o.has(f.id)||(o.add(f.id),s.push(ot(f)));}catch(c){throw new l("DB_ERROR","Failed to find tasks by prompt hint",c)}finally{d.close();}}return s}getProviderUsage(e,n,r){if(!this.dbExists())return [];let o=this.openHandle(false);try{let s=Ms(),i=sr(a.status),d=to(a.metadata),c=sql`
@@ -416,6 +418,7 @@ ${r.join(`
416
418
  SELECT DISTINCT child.agent_id FROM tasks child
417
419
  WHERE child.thread_id = ${e}
418
420
  AND child.agent_id IS NOT NULL AND child.agent_id != ''
421
+ AND child.agent_id != 'workflow'
419
422
  AND ${this.topLevelTaskPredicateSql()}
420
423
  ${n?sql`AND child.workspace_id = ${n}`:sql``}
421
424
  `);for(let m of _)u.add(m.agent_id);}catch(g){throw new l("DB_ERROR","Failed to aggregate task stats",g)}finally{p.close();}}return {taskCount:o,inputTokens:s,outputTokens:i,cachedInputTokens:d,costUsd:c,agentIds:Array.from(u)}}findTopLevelTasks(e,n,r){let o=this.resolveDbPaths(),s=new Set,i=[];for(let d of o){if(!existsSync(d))continue;let c=P(d);try{let u;r!==void 0?u=c.db.all(sql`
@@ -1,2 +1,2 @@
1
- import {join,resolve,dirname,relative,sep,isAbsolute}from'path';import'url';import {createHash}from'crypto';import {existsSync,readFileSync,statSync,readdirSync,constants}from'fs';import {realpath,stat,readdir,open,lstat}from'fs/promises';import {load}from'js-yaml';var Ai=Object.defineProperty;var O=(e,n)=>()=>(e&&(n=e(e=0)),n);var Ii=(e,n)=>{for(var t in n)Ai(e,t,{get:n[t],enumerable:true});};var I=O(()=>{});var _,Be=O(()=>{I();_=class extends Error{constructor(t,i=t,o){super(i);this.code=t;this.currentRevision=o;}code;currentRevision;name="UiRuntimeError"};});function un(e){return gi.test(e)||mi.test(e)}function z(){throw new _("INPUT_INVALID","JSON value is not projection-safe")}function Di(e){let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function dn(e,n,t,i,o,r){if(n>i&&z(),e===null||typeof e=="string"||typeof e=="boolean")return typeof e=="string"&&(hi.test(e)||_i.test(e)&&!bi(o,r)||Ti.test(e))&&z(),e;if(typeof e=="number")return Number.isFinite(e)||z(),e;(typeof e!="object"||e===void 0||typeof e=="function"||typeof e=="bigint")&&z();let s=e;t.has(s)&&z(),t.add(s);try{if(Array.isArray(e))return e.map(d=>dn(d,n+1,t,i,o,r));Di(s)||z();let a={};for(let[d,p]of Object.entries(e))un(d)&&z(),a[d]=dn(p,n+1,t,i,[...o,d],r);return a}finally{t.delete(s);}}function ne(e,n=0,t=[]){(!Number.isInteger(n)||n<0||n>Ni)&&z(),(!Array.isArray(t)||t.some(o=>typeof o!="string"))&&z();let i=dn(e,0,new Set,Ei+n,[],t);return (i===null||Array.isArray(i)||typeof i!="object")&&z(),i}function ge(e,n){if(!e||!n)return false;let t=e.split("."),i=n.split(".");return t.length>=i.length&&i.every((o,r)=>t[r]===o)}function bi(e,n){if(e.length===0)return false;let t=e.join(".");return n.some(i=>ge(t,i))}function me(e){try{let n=JSON.stringify(e);return n===void 0&&z(),n}catch{z();}}function ln(e){return Array.isArray(e)?e.map(ln):e!==null&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,ln(e[n])])):e}function J(e){return me(ln(e))}function fn(e){return Buffer.byteLength(e,"utf8")}var gi,mi,hi,Ti,_i,Ei,Ni,pe=O(()=>{I();Be();gi=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,mi=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i,hi=/<\/?[A-Za-z][^>]*>/,Ti=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,_i=/^(?:https?|file|ftp|ws|wss):\/\//i;Ei=8,Ni=4;});function he(e){return Pi.has(e)||Mi.test(e)||Li.test(e)}var tt,Pi,Mi,Li,He,Se,te,yn,An,In,gn,mn,Te=O(()=>{I();tt=["__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"],Pi=new Set(tt),Mi=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,Li=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i;He=/^[A-Za-z0-9_]+$/,Se=/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/,te=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,yn=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,An=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,In=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/,gn=["blue","violet","emerald","amber","rose","sky","slate","indigo"],mn=["inline","panel"];});function hn(e){return typeof e=="string"&&it.includes(e)}var it,ot=O(()=>{I();Te();it=["text/plain","application/json"];});function ze(e){if(!Tn(e))return false;let n=Object.keys(e);return !(n.some(t=>t!=="in"&&t!=="out")||n.length===0||Object.hasOwn(e,"in")&&!Oi(e.in)||Object.hasOwn(e,"out")&&!Si(e.out))}function Oi(e){return Tn(e)?Object.keys(e).every(t=>t==="mediaType"||t==="required")&&Object.hasOwn(e,"mediaType")&&hn(e.mediaType)&&(!Object.hasOwn(e,"required")||typeof e.required=="boolean"):false}function Si(e){return Tn(e)?Object.keys(e).every(t=>t==="mediaType"||t==="range")&&Object.hasOwn(e,"mediaType")&&hn(e.mediaType)&&(!Object.hasOwn(e,"range")||typeof e.range=="boolean"):false}function Tn(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var _n=O(()=>{I();ot();new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});});function ie(e){let t=e.renderer!==void 0||e.surfaces!==void 0||e.stateProjection!==void 0||e.dataPaths!==void 0||e.usage!==void 0||e.detailPanel!==void 0||e.displayModes!==void 0||e.summaryProjection!==void 0||e.legacy!==void 0||Object.values(e.actions).some(o=>o.resultProjection!==void 0)?{id:e.id,version:e.version,...e.renderer===void 0?{}:{renderer:e.renderer},...e.surfaces===void 0?{}:{surfaces:e.surfaces},...e.stateProjection===void 0?{}:{stateProjection:e.stateProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.legacy===void 0?{}:{legacy:e.legacy},...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},actions:e.actions}:e.sourceHash===void 0?{id:e.id,version:e.version,actions:e.actions}:{id:e.id,version:e.version,sourceHash:e.sourceHash,actions:e.actions},i=ne(t);return createHash("sha256").update(J(i)).digest("hex")}function oe(e){if(!/^\d+$/.test(String(e.version))||e.version<1||e.id.length<1||e.id.length>128)throw new _("DEFINITION_UNSUPPORTED","UI definition is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!Ri.test(e.sourceHash)))throw new _("DEFINITION_UNSUPPORTED","UI definition source hash is invalid");if(!/^[0-9a-f]{64}$/.test(e.hash)||ie(e)!==e.hash)throw new _("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=>!Ci(i)))throw new _("DEFINITION_UNSUPPORTED","UI action declaration is invalid");if(t.confirmation!==void 0&&t.confirmation!=="none"&&t.confirmation!=="native")throw new _("DEFINITION_UNSUPPORTED","UI action confirmation is invalid");if(t.inputKeys&&(!Array.isArray(t.inputKeys)||t.inputKeys.some(i=>typeof i!="string"||!i)))throw new _("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 _("DEFINITION_UNSUPPORTED","UI action data input declaration is invalid");if(t.resultProjection&&Dn(t.resultProjection),t.content!==void 0&&!ze(t.content))throw new _("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 _("DEFINITION_UNSUPPORTED","UI action environment declaration is invalid")}if(e.renderer!==void 0&&(!e.renderer||e.renderer.length>128))throw new _("DEFINITION_UNSUPPORTED","UI definition renderer is invalid");if(e.surfaces&&(!Array.isArray(e.surfaces)||e.surfaces.some(n=>!n||n.length>64)))throw new _("DEFINITION_UNSUPPORTED","UI definition surfaces are invalid");if(e.usage!==void 0&&e.usage!=="card"&&e.usage!=="window")throw new _("DEFINITION_UNSUPPORTED","UI definition usage is invalid");if(e.detailPanel!==void 0&&typeof e.detailPanel!="boolean")throw new _("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 _("DEFINITION_UNSUPPORTED","UI definition displayModes are invalid");if(e.usage==="card"&&e.displayModes!==void 0)throw new _("DEFINITION_UNSUPPORTED","Card definitions cannot declare displayModes");if(e.usage==="window"&&e.detailPanel!==void 0)throw new _("DEFINITION_UNSUPPORTED","Window definitions cannot declare detailPanel");if(e.stateProjection&&Dn(e.stateProjection),e.summaryProjection){Dn(e.summaryProjection);let n=new Set(e.stateProjection?.allow??[]);if(e.summaryProjection.allow.some(t=>!n.has(t)))throw new _("DEFINITION_UNSUPPORTED","UI summary projection exceeds state projection")}if(e.legacy!==void 0){if(!e.legacy||typeof e.legacy!="object"||Array.isArray(e.legacy)||Object.keys(e.legacy).some(o=>!["readTool","actionTool","hostTools","agentAccess"].includes(o)))throw new _("DEFINITION_UNSUPPORTED","UI legacy metadata is invalid");let n=new Set;for(let[o,r]of [["readTool",e.legacy.readTool],["actionTool",e.legacy.actionTool]])if(r!==void 0){if(ki(r,o==="readTool"),n.has(r.name))throw new _("DEFINITION_UNSUPPORTED","UI legacy tool names collide");n.add(r.name);}let t=e.legacy.hostTools;if(t!==void 0){if(!t||typeof t!="object"||Array.isArray(t))throw new _("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");let o={"doc.open":"crewx_app_html_viewer_open","pty.connect":"crewx_app_terminal_connect"};for(let[r,s]of Object.entries(t)){if(!Object.hasOwn(o,r)||o[r]!==s||typeof s!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(s)||n.has(s))throw new _("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");n.add(s);}}let i=e.legacy.agentAccess;if(i!==void 0&&(!i||typeof i!="object"||Array.isArray(i)||Object.entries(i).some(([o,r])=>!o||!Object.hasOwn(e.actions,o)||r!=="allowed"&&r!=="denied")))throw new _("DEFINITION_UNSUPPORTED","UI legacy agent access is invalid");if(e.legacy.actionTool!==void 0&&(!i||Object.keys(i).length===0))throw new _("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=>ge(t,i))))throw new _("DEFINITION_UNSUPPORTED","UI definition dataPaths are invalid")}}function ki(e,n){if(!e||typeof e!="object"||Array.isArray(e))throw new _("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");let t=e,i=["name","description","inputSchema","textFallback","visibility"],o=Object.hasOwn(t,"fixedResult");if(Object.keys(t).some(r=>!i.includes(r)&&!(n&&r==="fixedResult"))||i.some(r=>!Object.hasOwn(t,r))||typeof t.name!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(t.name)||typeof t.description!="string"||t.description.trim().length===0||t.description.length>8192||typeof t.textFallback!="string"||t.textFallback.trim().length===0||t.textFallback.length>16384||!t.inputSchema||typeof t.inputSchema!="object"||Array.isArray(t.inputSchema)||!Array.isArray(t.visibility)||t.visibility.length===0||t.visibility.some(r=>r!=="model"&&r!=="app")||new Set(t.visibility).size!==t.visibility.length)throw new _("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");try{let r=ne(t.inputSchema);if(r.type!==void 0&&r.type!=="object")throw new Error("schema type");if(o){if(!n)throw new Error("fixed result location");let s=t.fixedResult;if(!s||typeof s!="object"||Array.isArray(s))throw new Error("fixed result");let a=s;if(Object.keys(a).sort().join(",")!=="argsPolicy,structuredContent"||a.argsPolicy!=="empty-only"&&a.argsPolicy!=="ignore"||!a.structuredContent||typeof a.structuredContent!="object"||Array.isArray(a.structuredContent))throw new Error("fixed result");let d=ne(a.structuredContent);if(fn(me(d))>4*1024)throw new Error("fixed result size")}}catch{throw new _("DEFINITION_UNSUPPORTED","UI legacy tool metadata is not projection-safe")}}function Dn(e){if(!Array.isArray(e.allow)||e.allow.some(n=>!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(n)))throw new _("DEFINITION_UNSUPPORTED","UI projection policy is invalid")}function Ci(e){return e.length>0&&e.length<=128&&e!=="*"&&e!=="all"&&!/[/*]/.test(e)}var Ri,_e=O(()=>{I();pe();Be();_n();Ri=/^[0-9a-f]{64}$/;});var rt=O(()=>{I();pe();});var Ue,st=O(()=>{I();Ue="window";});function c(e,n=e){throw new $(e,n)}function k(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function D(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function w(e,n,t=[]){let i=new Set([...n,...t]);Object.keys(e).some(o=>!i.has(o))&&c("MANIFEST_INVALID"),n.some(o=>!D(e,o))&&c("MANIFEST_INVALID");}function Xe(e,n=false,t=false,i=false){return ji.test(e)||!i&&Fi.test(e)||Vi.test(e)||t&&at.test(e)||Bi.test(e)&&!(n&&/^\s*data:/i.test(e)&&!at.test(e))}function We(e,n=new Set,t=0,i=false,o=false){if(typeof e=="string"){Xe(e,i,o)&&c("UNSAFE_VALUE");return}if(!(e===null||typeof e!="object")){(t>8||n.has(e))&&c("MANIFEST_INVALID"),n.add(e);try{if(Array.isArray(e)){for(let r of e)We(r,n,t+1);return}k(e)||c("MANIFEST_INVALID");for(let[r,s]of Object.entries(e))We(s,n,t+1,i&&t===0&&(r==="name"||r==="description"),o);}finally{n.delete(e);}}}function q(e,n){let t=e[n];return typeof t!="string"&&c("MANIFEST_INVALID"),t}function W(e,n,t){let i=e[n];return (!Number.isSafeInteger(i)||i<t)&&c("MANIFEST_INVALID"),i}function En(e){return vi.test(e)||c("MANIFEST_INVALID"),e}function De(e){return xi.test(e)||c("TOKEN_INVALID"),e}function ao(e){return It.test(e)||c("MANIFEST_INVALID"),e}function co(e){k(e)||c("MANIFEST_INVALID");let n={};for(let[t,i]of Object.entries(e)){let o=ao(t);k(i)||c("MANIFEST_INVALID");let r=i.type;if(r==="text"){w(i,["type","maxLength"]),n[o]={type:r,maxLength:W(i,"maxLength",1)};continue}if(r==="text-list"){w(i,["type","max","itemMaxLength"]),n[o]={type:r,max:W(i,"max",0),itemMaxLength:W(i,"itemMaxLength",1)};continue}if(r==="step-list"){w(i,["type","min","max","labelMaxLength","detailMaxLength"]);let s=W(i,"min",0),a=W(i,"max",1);s>a&&c("MANIFEST_INVALID"),n[o]={type:r,min:s,max:a,labelMaxLength:W(i,"labelMaxLength",1),detailMaxLength:W(i,"detailMaxLength",1)};continue}typeof r=="string"&&c("SCHEMA_TYPE_UNSUPPORTED"),c("MANIFEST_INVALID");}return n}function po(e,n,t){let i=e[n];(!i||i.type!==t)&&c("MANIFEST_INVALID");}function Ge(e,n,t){let i=q(e,"field");return It.test(i)||c("MANIFEST_INVALID"),po(n,i,t),i}function lo(e,n){k(e)||c("MANIFEST_INVALID");let t=e.primitive;switch(typeof t!="string"&&c("MANIFEST_INVALID"),so.includes(t)||c("PRIMITIVE_UNKNOWN"),t){case "card-shell":return w(e,["primitive"]),{primitive:t};case "meta-banner":return w(e,["primitive","badgeToken","noticeToken"]),{primitive:t,badgeToken:De(q(e,"badgeToken")),noticeToken:De(q(e,"noticeToken"))};case "heading":return w(e,["primitive","field"]),{primitive:t,field:Ge(e,n,"text")};case "labeled-text":return w(e,["primitive","titleToken","field","variant"]),e.variant!=="callout"&&c("MANIFEST_INVALID"),{primitive:t,titleToken:De(q(e,"titleToken")),field:Ge(e,n,"text"),variant:"callout"};case "step-flow":return w(e,["primitive","titleToken","field"]),{primitive:t,titleToken:De(q(e,"titleToken")),field:Ge(e,n,"step-list")};case "text-list":{w(e,["primitive","titleToken","field"],["emptyToken","hideWhenEmpty"]);let i={primitive:t,titleToken:De(q(e,"titleToken")),field:Ge(e,n,"text-list")};return D(e,"emptyToken")&&(i.emptyToken=De(q(e,"emptyToken"))),D(e,"hideWhenEmpty")&&(typeof e.hideWhenEmpty!="boolean"&&c("MANIFEST_INVALID"),i.hideWhenEmpty=e.hideWhenEmpty),i}}return c("MANIFEST_INVALID")}function uo(e,n){return Array.isArray(e)||c("MANIFEST_INVALID"),e.map(t=>lo(t,n))}function x(e="v2 manifest exceeds a contract limit"){return c("LIMIT_EXCEEDED",e)}function G(e="initial state is not projection-safe"){return c("INITIAL_STATE_INVALID",e)}function ct(e,n){return (typeof e!="string"||e.length===0||e.length>4096||e.trim().length===0||io.test(e)||oo.test(e))&&c("MANIFEST_INVALID",`${n} is invalid`),(Xe(e,true,true)||Hi.test(e)||zi.test(e)||Gi.test(e))&&c("UNSAFE_VALUE",`${n} contains an unsafe value`),e}function Nn(e,n){return (typeof e!="string"||!te.test(e))&&c("MANIFEST_INVALID",`${n} is invalid`),e}function fo(e){return (typeof e!="string"||!yn.test(e)||e==="*"||e==="all")&&c("MANIFEST_INVALID","action capability is invalid"),e}function gt(e){return (typeof e!="string"||!to.test(e))&&c("MANIFEST_INVALID","resource hash is invalid"),e}function bn(e,n=new Set,t=0){if(typeof e=="string"){e.length>4096&&x("v2 manifest string is too long");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||c("MANIFEST_INVALID","v2 manifest contains a non-finite number");return}(e===void 0||typeof e=="function"||typeof e=="bigint")&&c("MANIFEST_INVALID","v2 manifest contains a non-JSON value"),typeof e!="object"&&c("MANIFEST_INVALID"),t>8&&x("v2 manifest nesting is too deep"),n.has(e)&&c("MANIFEST_INVALID","v2 manifest contains a cycle"),n.add(e);try{if(Array.isArray(e)){e.length>128&&x("v2 manifest array is too long");for(let i of e)bn(i,n,t+1);return}k(e)||c("MANIFEST_INVALID","v2 manifest contains a non-plain object");for(let i of Object.values(e))bn(i,n,t+1);}finally{n.delete(e);}}}function mt(e){return (typeof e!="string"||e.length>4096||!Se.test(e))&&(typeof e=="string"&&e.length>4096&&x("projection path is too long"),c("MANIFEST_INVALID","projection paths must be canonical exact paths")),e.split(".").some(t=>he(t))&&c("MANIFEST_INVALID","projection paths cannot address reserved state keys"),e}function Pn(e){k(e)||c("MANIFEST_INVALID","projection policy must be an object"),w(e,["allow"]),Array.isArray(e.allow)||c("MANIFEST_INVALID","projection allow must be an array"),e.allow.length>128&&x("projection allowlist is too long");let n=[],t=new Set;for(let i of e.allow){let o=mt(i);t.has(o)&&c("MANIFEST_INVALID","projection allowlist contains a duplicate path"),t.add(o),n.push(o);}return {allow:n}}function yo(e,n){if(e===void 0)return;Array.isArray(e)||c("MANIFEST_INVALID","dataPaths must be an array"),e.length>ro&&x("dataPaths exceed the v2 limit");let t=[],i=new Set;for(let o of e){let r=mt(o);i.has(r)&&c("MANIFEST_INVALID","dataPaths contain a duplicate path"),n.some(s=>ge(r,s))||c("MANIFEST_INVALID","dataPaths must be projection-allowed"),i.add(r),t.push(r);}return t}function Ee(e,n,t=Number.MAX_SAFE_INTEGER){return (!Number.isSafeInteger(e)||e<0||e>t)&&c("MANIFEST_INVALID",`${n} is invalid`),e}function pt(e,n){return (typeof e!="number"||!Number.isFinite(e))&&c("MANIFEST_INVALID",`${n} is invalid`),e}function Mn(e,n=0,t=new Set){if(typeof e=="string")return (e.length>4096||Xe(e))&&c("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)||c("MANIFEST_INVALID","schema enum contains a non-finite number"),e;(n>8||typeof e!="object"||e===void 0)&&x("schema enum is too deep"),t.has(e)&&c("MANIFEST_INVALID","schema enum contains a cycle"),t.add(e);try{if(Array.isArray(e))return e.length>128&&x("schema enum array is too long"),e.map(o=>Mn(o,n+1,t));k(e)||c("MANIFEST_INVALID","schema enum contains a non-plain object");let i={};for(let[o,r]of Object.entries(e))he(o)&&c("MANIFEST_INVALID","schema enum contains a reserved key"),i[o]=Mn(r,n+1,t);return i}finally{t.delete(e);}}function Ao(e,n){if(e===void 0)return;Array.isArray(e)||c("MANIFEST_INVALID","schema required must be an array"),e.length>64&&x("schema required list is too long");let t=[],i=new Set;for(let o of e)(typeof o!="string"||!Se.test(o))&&c("MANIFEST_INVALID","schema required contains an invalid key"),o.length>4096&&x("schema required key is too long"),i.has(o)&&c("MANIFEST_INVALID","schema required contains a duplicate key"),n&&!Object.prototype.hasOwnProperty.call(n,o)&&c("MANIFEST_INVALID","schema required references an undeclared property"),i.add(o),t.push(o);return t}function Io(e,n){let t=n?Se:He;return e.length>4096&&x("schema property name is too long"),(!t.test(e)||e.split(".").some(i=>he(i)))&&c("MANIFEST_INVALID","schema property name is invalid"),e}function Ln(e,n=0,t=false){k(e)||c("MANIFEST_INVALID","action inputSchema must be an object"),n>8&&x("action inputSchema is too deep");let i=e.type;i!=="object"&&i!=="string"&&i!=="number"&&i!=="integer"&&i!=="boolean"&&i!=="array"&&i!=="null"&&(typeof i=="string"&&c("SCHEMA_TYPE_UNSUPPORTED","action inputSchema type is unsupported"),c("MANIFEST_INVALID","action inputSchema type is required"));let o=["type","enum"];i==="string"&&o.push("minLength","maxLength"),i==="array"&&o.push("minItems","maxItems","items"),i==="object"&&o.push("minProperties","maxProperties","properties","required","additionalProperties"),(i==="number"||i==="integer")&&o.push("minimum","maximum"),w(e,["type"],o.filter(a=>a!=="type"));let r={type:i};if(D(e,"enum")&&(Array.isArray(e.enum)||c("MANIFEST_INVALID","schema enum must be an array"),e.enum.length>128&&x("schema enum is too long"),r.enum=e.enum.map(a=>Mn(a))),i==="string"&&(D(e,"minLength")&&(r.minLength=Ee(e.minLength,"schema minLength",4096)),D(e,"maxLength")&&(r.maxLength=Ee(e.maxLength,"schema maxLength",4096)),r.minLength!==void 0&&r.maxLength!==void 0&&r.minLength>r.maxLength&&c("MANIFEST_INVALID","schema string length bounds are inverted")),(i==="number"||i==="integer")&&(D(e,"minimum")&&(r.minimum=pt(e.minimum,"schema minimum")),D(e,"maximum")&&(r.maximum=pt(e.maximum,"schema maximum")),r.minimum!==void 0&&r.maximum!==void 0&&r.minimum>r.maximum&&c("MANIFEST_INVALID","schema numeric bounds are inverted")),i==="array"&&(D(e,"minItems")&&(r.minItems=Ee(e.minItems,"schema minItems",128)),D(e,"maxItems")&&(r.maxItems=Ee(e.maxItems,"schema maxItems",128)),r.minItems!==void 0&&r.maxItems!==void 0&&r.minItems>r.maxItems&&c("MANIFEST_INVALID","schema array length bounds are inverted"),D(e,"items")&&(r.items=Ln(e.items,n+1,false))),i==="object"){let a;if(D(e,"properties")){k(e.properties)||c("MANIFEST_INVALID","schema properties must be an object");let p=Object.entries(e.properties);p.length>64&&x("schema properties are too many"),a={};for(let[u,y]of p){let b=Io(u,t);a[b]=Ln(y,n+1,false);}r.properties=a;}D(e,"minProperties")&&(r.minProperties=Ee(e.minProperties,"schema minProperties",64)),D(e,"maxProperties")&&(r.maxProperties=Ee(e.maxProperties,"schema maxProperties",64)),r.minProperties!==void 0&&r.maxProperties!==void 0&&r.minProperties>r.maxProperties&&c("MANIFEST_INVALID","schema object property bounds are inverted");let d=Ao(e.required,a);d!==void 0&&(r.required=d),D(e,"additionalProperties")&&(e.additionalProperties!==false&&c("MANIFEST_INVALID","schema additionalProperties must be false"),r.additionalProperties=false);}let s=JSON.stringify(r);return (s===void 0||Buffer.byteLength(s,"utf8")>65536)&&x("action inputSchema subtree is too large"),r}function go(e){let n=Ln(e,0,true);return (n.type!=="object"||!n.properties)&&c("MANIFEST_INVALID","action inputSchema must declare object properties"),n}function mo(e){if(k(e)||c("MANIFEST_INVALID","action backend must be an object"),e.type==="core"){w(e,qi);let n=e.handler;return (typeof n!="string"||!An.test(n))&&c("MANIFEST_INVALID","core backend handler is invalid"),{type:"core",handler:n}}if(e.type==="skill"){w(e,Zi,Qi),(!Array.isArray(e.command)||e.command.length===0||e.command.length>16)&&c("MANIFEST_INVALID","skill backend command is invalid");let n=[];for(let i of e.command)(typeof i!="string"||i.length===0||i.length>256||!In.test(i))&&c("MANIFEST_INVALID","skill backend command token is invalid"),n.push(i);let t=D(e,"env")?To(e.env):void 0;return {type:"skill",command:n,...t===void 0?{}:{env:t}}}c("MANIFEST_INVALID","action backend type is unsupported");}function ho(e){k(e)||c("MANIFEST_INVALID","action must be an object"),w(e,Xi,Yi),D(e,"_meta")&&ht(e._meta);let n=Nn(e.actionId,"actionId");un(n)&&c("MANIFEST_INVALID",`actionId "${n}" is not projection-safe`);let t=fo(e.capability),i=e.mutation;typeof i!="boolean"&&c("MANIFEST_INVALID","action mutation must be boolean");let o=go(e.inputSchema),r;if(D(e,"dataInputs")){Array.isArray(e.dataInputs)||c("MANIFEST_INVALID","action dataInputs must be an array");let u=o.properties,y=new Set,b=[];for(let g of e.dataInputs)(typeof g!="string"||!D(u,g)||y.has(g))&&c("MANIFEST_INVALID","action dataInputs must be unique declared properties"),y.add(g),b.push(g);r=b;}let s=Pn(e.resultProjection),a=mo(e.backend),d;D(e,"content")&&((a.type!=="skill"||!ze(e.content))&&c("MANIFEST_INVALID","action content declaration is invalid"),d=_o(e.content));let p;if(D(e,"confirmation")){let u=e.confirmation;u!=="none"&&u!=="native"&&c("MANIFEST_INVALID","action confirmation is invalid"),p=u;}return {actionId:n,capability:t,mutation:i,inputSchema:o,resultProjection:s,backend:a,...d===void 0?{}:{content:d},...r===void 0?{}:{dataInputs:r},...p===void 0?{}:{confirmation:p}}}function To(e){(!Array.isArray(e)||e.length===0)&&c("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))&&c("MANIFEST_INVALID","skill backend env is invalid"),n.add(i),t.push(i);return Object.freeze(t)}function _o(e){return Object.freeze({...e.in===void 0?{}:{in:Object.freeze({...e.in})},...e.out===void 0?{}:{out:Object.freeze({...e.out})}})}function Do(e){return k(e)||c("INITIAL_STATE_INVALID","initialState must be an object"),w(e,eo,no),e.path!=="ui/state.json"&&c("MANIFEST_INVALID","initialState path is not fixed"),D(e,"hash")?{path:"ui/state.json",hash:gt(e.hash)}:{path:"ui/state.json"}}function Eo(e){let n=["wasm","terminal","htmlDocuments"];return (!k(e)||Object.keys(e).length===0||Object.keys(e).some(t=>!n.includes(t)||e[t]!==true))&&c("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 No(e,n){We(e,new Set,0,true,true),bn(e),k(e)||c("MANIFEST_INVALID"),w(e,Wi,$i),D(e,"_meta")&&ht(e._meta),e.manifestVersion!==2&&c("MANIFEST_INVALID");let t;D(e,"runtime")&&(t=Eo(e.runtime));let i=Nn(e.pluginId,"pluginId"),o=Nn(e.definitionId,"definitionId"),r=W(e,"version",1),s=ct(e.name,"name"),a=ct(e.description,"description"),d;D(e,"icon")&&((typeof e.icon!="string"||!/^[a-z][a-z0-9-]{0,63}$/.test(e.icon))&&c("MANIFEST_INVALID","icon is invalid"),d=e.icon);let p;D(e,"tone")&&((typeof e.tone!="string"||!gn.includes(e.tone))&&c("MANIFEST_INVALID","tone is invalid"),p=e.tone),e.entry!=="ui/index.html"&&c("MANIFEST_INVALID","entry path is not fixed");let u;D(e,"entryHash")&&(u=gt(e.entryHash));let y;D(e,"initialState")&&(y=Do(e.initialState));let b;D(e,"usage")&&(e.usage!=="card"&&e.usage!=="window"&&c("MANIFEST_INVALID","usage is invalid"),b=e.usage);let g;D(e,"detailPanel")&&(typeof e.detailPanel!="boolean"&&c("MANIFEST_INVALID","detailPanel is invalid"),g=e.detailPanel);let f;if(D(e,"displayModes")){((b??Ue)!==Ue||!Array.isArray(e.displayModes)||e.displayModes.length===0)&&c("MANIFEST_INVALID","displayModes are only valid for window Apps");let M=new Set(["inline","floating","focused"]);(new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(l=>typeof l!="string"||!M.has(l)))&&c("MANIFEST_INVALID","displayModes are invalid"),f=e.displayModes;}(b??Ue)===Ue&&g!==void 0&&c("MANIFEST_INVALID","detailPanel is card-only");let T=n.mode??"local";T!=="local"&&T!=="installed"&&T!=="published"&&c("MANIFEST_INVALID","manifest mode is invalid"),T!=="local"&&u===void 0&&c("MANIFEST_INVALID","installed manifests require entryHash"),T!=="local"&&y!==void 0&&y.hash===void 0&&c("MANIFEST_INVALID","installed manifests require initialState.hash"),(!Array.isArray(e.surfaces)||e.surfaces.length===0)&&c("MANIFEST_INVALID","surfaces are invalid"),e.surfaces.length>2&&x("surfaces exceed the v2 limit");let C=[],j=new Set;for(let M of e.surfaces)(typeof M!="string"||!mn.includes(M))&&c("MANIFEST_INVALID","surface is unsupported"),j.has(M)&&c("MANIFEST_INVALID","surfaces contain a duplicate"),j.add(M),C.push(M);k(e.size)||c("MANIFEST_INVALID","size must be an object"),w(e.size,["height"]);let m=W(e.size,"height",1);m>720&&x("size.height exceeds the v2 limit");let N=Pn(e.stateProjection),S=e.summaryProjection===void 0?void 0:Pn(e.summaryProjection);S!==void 0&&S.allow.some(M=>!N.allow.includes(M))&&c("MANIFEST_INVALID","summaryProjection must be a subset of stateProjection.allow");let H=yo(e.dataPaths,N.allow);Array.isArray(e.actions)||c("MANIFEST_INVALID","actions must be an array"),e.actions.length>32&&x("actions exceed the v2 limit");let v=[],Y=new Set;for(let M of e.actions){let l=ho(M);if(Y.has(l.actionId)&&c("MANIFEST_INVALID","actions contain a duplicate actionId"),l.backend.type==="core"&&l.backend.handler==="state.set"){l.mutation||c("MANIFEST_INVALID","state.set actions must be mutations");for(let P of Object.keys(l.inputSchema.properties))N.allow.includes(P)||c("MANIFEST_INVALID","state.set input paths must be projection-allowed");}Y.add(l.actionId),v.push(l);}return {manifestVersion:2,pluginId:i,definitionId:o,version:r,name:s,description:a,...d===void 0?{}:{icon:d},...p===void 0?{}:{tone:p},entry:"ui/index.html",...u===void 0?{}:{entryHash:u},...t===void 0?{}:{runtime:t},...y===void 0?{}:{initialState:y},...b===void 0?{}:{usage:b},...g===void 0?{}:{detailPanel:g},...f===void 0?{}:{displayModes:f},surfaces:C,size:{height:m},stateProjection:N,...S===void 0?{}:{summaryProjection:S},...H===void 0?{}:{dataPaths:H},actions:v}}function ht(e){k(e)||c("MANIFEST_INVALID","_meta must be an object");let n=JSON.stringify(e);(n===void 0||Buffer.byteLength(n,"utf8")>Ki)&&x("_meta exceeds the 4 KiB limit");}function bo(e){let n={},t={};for(let r of e.actions){n[r.actionId]={capabilities:[r.capability],inputKeys:Object.keys(r.inputSchema.properties??{}),...r.dataInputs===void 0?{}:{dataInputs:r.dataInputs},resultProjection:r.resultProjection,...r.confirmation===void 0?{}:{confirmation:r.confirmation},...r.content===void 0?{}:{content:r.content},...r.backend.type!=="skill"||r.backend.env===void 0?{}:{env:r.backend.env}};let s=r.backend.type==="skill"||r.backend.type==="core"&&r.backend.handler==="state.set";t[r.actionId]={actionId:r.actionId,mutation:r.mutation,backend:r.backend,launchPolicy:s?"allowed":"denied",...s?{}:{denialCode:"EXEC_DENIED"}};}let i={id:e.definitionId,version:e.version,renderer:"sandbox-html",...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},surfaces:e.surfaces,stateProjection:e.stateProjection,...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},actions:n},o={entry:{path:"ui/index.html",...e.entryHash===void 0?{}:{hash:e.entryHash}},...e.initialState===void 0?{}:{initialState:e.initialState}};return {manifest:e,definition:i,handlers:t,resources:o}}function On(e,n,t,i,o,r){if(typeof e=="string"){let s=o.length>0&&r.some(a=>ge(o.join("."),a));return (e.length>4096||Xe(e,false,false,s))&&G("state contains an unsafe string"),e}if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||G("state contains a non-finite number"),e;(e===void 0||typeof e!="object"||typeof e=="function"||typeof e=="bigint")&&G("state contains a non-JSON value"),t>8&&G("state is too deep"),n.has(e)&&G("state contains a cycle"),n.add(e);try{let s;if(Array.isArray(e))e.length>128&&G("state array is too long"),s=e.map(d=>On(d,n,t+1,65536,o,r));else {k(e)||G("state contains a non-plain object");let d={};for(let[p,u]of Object.entries(e))(p.length>4096||!He.test(p)||he(p))&&(p.length>4096&&G("state key is too long"),G("state contains a reserved or invalid key")),d[p]=On(u,n,t+1,65536,[...o,p],r);s=d;}let a=JSON.stringify(s);return (a===void 0||Buffer.byteLength(a,"utf8")>i)&&G("state subtree is too large"),s}finally{n.delete(e);}}function Un(e,n=[]){k(e)||G("initial state must be a JSON object");let t=On(e,new Set,0,65536,[],n);return (t===null||Array.isArray(t)||typeof t!="object")&&G(),t}function Po(e,n={}){We(e),k(e)||c("MANIFEST_INVALID"),w(e,Ji),e.manifestVersion!==1&&c("MANIFEST_INVALID");let t=En(q(e,"pluginId")),i=En(q(e,"definitionId")),o=W(e,"version",1),r=W(e,"primitiveSet",1),s=n.supportedPrimitiveSet??wi;(!Number.isSafeInteger(s)||s<1)&&c("MANIFEST_INVALID"),r>s&&c("PRIMITIVE_SET_UNSUPPORTED"),k(e.activation)||c("MANIFEST_INVALID"),w(e.activation,["kind","language"]),e.activation.kind!=="fenced-code"&&c("MANIFEST_INVALID");let a=En(q(e.activation,"language")),d=co(e.schema),p=uo(e.layout,d);return {manifestVersion:1,pluginId:t,definitionId:i,version:o,primitiveSet:r,activation:{kind:"fenced-code",language:a},schema:d,layout:p}}function Mo(e,n={}){return k(e)||c("MANIFEST_INVALID"),Object.hasOwn(e,"lineage")&&c("MANIFEST_INVALID","lineage is only allowed in product bundle indexes"),e.manifestVersion===2?No(e,n):Po(e,n)}function Ye(e,n={}){try{return Mo(e,n)}catch(t){if(t instanceof $)throw t;return c("MANIFEST_INVALID")}}function Rn(e,n={}){let t=Ye(e,n);return t.manifestVersion===2?bo(t):t}var wi,xi,vi,It,ji,Vi,Fi,Bi,at,Hi,zi,Gi,Ji,Wi,$i,Xi,Yi,Ki,qi,Zi,Qi,eo,no,to,io,oo,ro,so,$,Tt=O(()=>{I();st();pe();_n();Te();wi=1,xi=/^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$/,vi=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,It=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,ji=/<\/?[A-Za-z][^>]*>/,Vi=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,Fi=/^(?:https?|file|ftp|ws|wss):\/\//i,Bi=/^\s*(?:javascript|data):/i,at=/data:[^,\s]*,/i,Hi=/(?:https?|file|ftp|ws|wss):\/\//i,zi=/javascript:/i,Gi=/(?:^[\s]*|[\s"'(=])(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)(?=[^\s"'<>])[^\s"'<>]*/,Ji=["manifestVersion","pluginId","definitionId","version","primitiveSet","activation","schema","layout"],Wi=["manifestVersion","pluginId","definitionId","version","name","description","entry","surfaces","size","stateProjection","actions"],$i=["_meta","icon","tone","entryHash","runtime","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths"],Xi=["actionId","capability","mutation","inputSchema","resultProjection","backend"],Yi=["confirmation","dataInputs","content","_meta"],Ki=4*1024,qi=["type","handler"],Zi=["type","command"],Qi=["env"],eo=["path"],no=["hash"],to=/^[0-9a-f]{64}$/,io=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/,oo=/[\r\n]/,ro=16,so=["card-shell","meta-banner","heading","labeled-text","step-flow","text-list"],$=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="UiPluginValidationError"};});var _t=O(()=>{I();rt();Tt();Te();});function Ze(e,n=e){throw new re(e,n)}var re,Qe=O(()=>{I();re=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="McpAppContractError"};});var Dt=O(()=>{I();});var Et=O(()=>{I();_e();pe();Qe();Dt();});function Nt(e,n){return Lo.add(e),n!==void 0&&Oo.set(e,n),e}var Lo,Oo,en=O(()=>{I();Lo=new WeakSet,Oo=new WeakMap;});function ke(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function kn(e,n,t=[]){let i=new Set([...n,...t]),o=Object.keys(e);return n.every(r=>Object.hasOwn(e,r))&&o.every(r=>i.has(r))}function Mt(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))Mt(n);return Object.freeze(e)}function V(e){throw new Z("LINEAGE_INVALID",e)}function xo(e){throw new Z("LINEAGE_STALE",e)}function Lt(e){if(!ke(e)||!kn(e,Ro,ko)||!ke(e.actions))return V("Lineage definition shape is invalid");for(let n of Object.values(e.actions))if(!ke(n)||!kn(n,Co,wo))return V("Lineage action definition shape is invalid");return e}function vo(e){if(!ke(e)||!kn(e,So,Uo))return V("Lineage entry shape is invalid");if(!Number.isSafeInteger(e.version)||e.version<1||typeof e.hash!="string"||!bt.test(e.hash))return V("Lineage entry identity is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!bt.test(e.sourceHash)))return V("Lineage source hash is invalid");if(e.compat!==void 0&&e.compat!=="break")return V("Lineage compatibility marker is invalid");let n=Lt(e.definition);if(n.version!==e.version)return V("Lineage version does not match its definition");if(e.sourceHash!==void 0&&n.sourceHash!==e.sourceHash)return V("Lineage source hash does not match its definition");let t;try{t=ie(n),oe({...n,hash:e.hash});}catch{return V("Lineage definition is invalid")}return t!==e.hash?V("Lineage definition hash does not match"):Mt({version:e.version,hash:e.hash,definition:n,...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},...e.compat===void 0?{}:{compat:e.compat}})}function Pt(e){return e.stateProjection?.allow??[]}function jo(e,n){let t=[],i=new Set(Pt(n));Pt(e).some(a=>!i.has(a))&&t.push("S1_STATE_PROJECTION");let o=new Set(n.dataPaths??[]);(e.dataPaths??[]).some(a=>!o.has(a))&&t.push("S2_DATA_PATHS");for(let[a,d]of Object.entries(e.actions)){let p=n.actions[a];if(p&&(d.confirmation??"native")==="native"&&(p.confirmation??"native")!=="native"){t.push("S3_ACTION_CONFIRMATION");break}}Object.keys(e.legacy?.agentAccess??{}).some(a=>!Object.hasOwn(n.actions,a))&&t.push("S4_LEGACY_AGENT_ACTIONS");let s=e.summaryProjection?.allow;if(s!==void 0){let a=new Set(n.summaryProjection?.allow??[]);s.some(d=>!a.has(d))&&t.push("S5_SUMMARY_PROJECTION");}return t}function Vo(e,n){return J(e)===J(n)}function Cn(e,n){if(!Array.isArray(e)||e.length===0)return V("Definition lineage is missing");if(!ke(n)||typeof n.hash!="string")return V("Current definition is invalid");let t,i;try{let{hash:a,...d}=n;i=Lt(d),t={...i,hash:a},oe(t);}catch{return V("Current definition is invalid")}let o=e.map(vo),r=o[0].definition.id;if(o.some(a=>a.definition.id!==r))return V("Lineage definition ids do not match");if(o.some((a,d)=>d>0&&a.version<=o[d-1].version))return V("Lineage generations are not in increasing version order");if(o.some((a,d)=>o.findIndex(p=>p.hash===a.hash)!==d))return V("Lineage contains a duplicate hash");let s=o[o.length-1];if(s.version!==t.version||s.hash!==t.hash||s.definition.id!==t.id||!Vo(s.definition,i))return xo("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 u of o)if(u.sourceHash===void 0)for(let y of Object.keys(u.definition.actions))a.has(y)&&d.add(y);let p=Object.keys(t.legacy.agentAccess??{});if(p.length!==d.size||p.some(u=>!d.has(u))){let u="S4_LEGACY_AGENT_ACCESS_COMPLETE";throw new Z("LINEAGE_INVALID",`Lineage compatibility failed: ${u}`,[u])}}for(let a=0;a<o.length-1;a+=1){if(o.slice(a,-1).some(u=>u.compat==="break"))continue;let p=jo(o[a].definition,t);if(p.length>0)throw new Z("LINEAGE_INVALID",`Lineage compatibility failed: ${p.join(", ")}`,p)}return Object.freeze({entries:Object.freeze(o),current:t})}var Z,bt,So,Uo,Ro,ko,Co,wo,wn=O(()=>{I();_e();pe();Z=class extends Error{constructor(t,i=t,o=[]){super(i);this.code=t;this.violations=o;}code;violations;name="UiDefinitionLineageError"},bt=/^[0-9a-f]{64}$/,So=["version","hash","definition"],Uo=["sourceHash","compat"],Ro=["id","version","actions"],ko=["sourceHash","usage","detailPanel","displayModes","renderer","surfaces","stateProjection","dataPaths","summaryProjection","legacy"],Co=["capabilities"],wo=["inputKeys","dataInputs","confirmation","resultProjection","content","env"];});var Ot,St,Ut=O(()=>{I();Ot=["crewx_app_terminal_connect","crewx_app_html_viewer_open"],St=["crewx_listWorkspaces","crewx_queryAgent","crewx_executeAgent","crewx_getTaskResult","crewx_listTasks","crewx_listAgents","callBrowser","openTab","listTabs","closeTab"];});var Rt=O(()=>{I();_e();en();});function xn(e,n=0){try{let t=ne(e,n);return t.type!==void 0&&t.type!=="object"&&Ze("TOOL_INVALID","MCP App inputSchema must describe an object"),t}catch(t){if(t instanceof re)throw t;Ze("TOOL_INVALID","MCP App inputSchema must be projection-safe JSON");}}function kt(e){if(e.length===0)return xn({type:"object",properties:{},additionalProperties:false});let n=e.map(i=>i.actionId),t=new Map;for(let i of e)t.set(i.actionId,xn(i.inputSchema));return xn(Ho(n,t),Bo)}function Ho(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 Ce,Bo,vn=O(()=>{I();Et();_e();pe();en();Qe();wn();Ut();Rt();Ce=8*1024*1024,new Set(Ot),new Set(St),Bo=4;});function se(e){let n=typeof e=="object"&&e!==null&&"code"in e?String(e.code):"";return n==="ENOENT"?new A("NOT_FOUND"):n==="ELOOP"?new A("PATH_ESCAPED"):n==="EFBIG"||n==="EOVERFLOW"?new A("LIMIT_EXCEEDED"):n==="EACCES"||n==="EPERM"||n==="ENOTDIR"?new A("READ_DENIED"):new A("READ_DENIED")}function Xo(e){if(typeof e!="string"||e.length===0||!isAbsolute(e))throw new A("READ_DENIED")}function Ct(e){if(typeof e!="string"||isAbsolute(e)||/[\\\u0000]/.test(e))throw new A("PATH_ESCAPED");if(e==="")return [];let n=e.split("/");if(n.some(t=>t.length===0||t==="."||t===".."))throw new A("PATH_ESCAPED");return n}function nn(e,n){let t=relative(e,n);return t===""||t!==".."&&!t.startsWith(`..${sep}`)&&!isAbsolute(t)}function tn(e){return {dev:e.dev,ino:e.ino,size:e.size,mtimeNs:e.mtimeNs,ctimeNs:e.ctimeNs}}function Fn(e,n){return e.dev===n.dev&&e.ino===n.ino}function Ft(e,n){return Fn(e,n)&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}async function wt(e){Xo(e);let n,t;try{n=await realpath(e),t=await stat(n,{bigint:!0});}catch(i){throw se(i)}if(!t.isDirectory())throw new A("READ_DENIED");return {realRoot:n,identity:tn(t)}}async function Yo(e,n,t){if(t.length<2||t[0]!=="apps"&&t[0]!=="skills")return;let i,o;try{if(i=resolve(e,t[0],t[1]),o=await realpath(i),!(await stat(o,{bigint:!0})).isDirectory())throw new A("READ_DENIED")}catch(r){throw r instanceof A?r:se(r)}if(!nn(n,o))throw new A("PATH_ESCAPED");return o}async function xt(e,n,t,i){let o,r,s;try{o=await lstat(e,{bigint:!0}),r=await realpath(e),s=await stat(r,{bigint:!0});}catch(a){throw se(a)}if(!nn(n,r)||t!==void 0&&!nn(t,r))throw new A("PATH_ESCAPED");if(!o.isFile()||!s.isFile())throw new A("READ_DENIED");if(!Fn(i,o)||!Fn(i,s)||i.dev!==s.dev)throw new A("PATH_ESCAPED")}async function jn(e,n){let t,i;try{t=await realpath(e),i=await stat(t,{bigint:!0});}catch{throw new A("PATH_ESCAPED")}if(t!==n.realRoot||!Ft(n.identity,tn(i)))throw new A("PATH_ESCAPED")}function Ko(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 A,Vt,Wo,$o,Pe,rn,Bt,Ht,Hn=O(()=>{I();A=class extends Error{constructor(t){super(t);this.code=t;}code;name="AppDiscoveryFsError"},Vt=constants.O_NOFOLLOW,Wo=constants.O_NONBLOCK,$o=constants.O_RDONLY|(Vt??0)|(Wo??0);Pe=class{async listDirectory(n,t){let i=Ct(t),o=await wt(n),r=resolve(n,...i),s,a;try{s=await realpath(r),a=await stat(s,{bigint:!0});}catch(d){let p=se(d);if(p.code==="NOT_FOUND")return [];throw p}if(!nn(o.realRoot,s)||!a.isDirectory())throw new A("PATH_ESCAPED");try{let d=await readdir(s,{withFileTypes:!0,encoding:"utf8"});return await jn(n,o),d.map(Ko)}catch(d){let p=se(d);if(p.code==="NOT_FOUND")return [];throw p}}async readdir(n,t){return this.listDirectory(n,t)}async readDirectory(n,t){return this.listDirectory(n,t)}async readVerifiedFile(n,t,i){if(!Number.isSafeInteger(i)||i<0)throw new A("READ_DENIED");if(Vt===void 0)throw new A("UNSUPPORTED");let o=Ct(t),r=await wt(n),s=resolve(n,...o),a=relative(n,s);if(a===".."||a.startsWith(`..${sep}`)||isAbsolute(a))throw new A("PATH_ESCAPED");let d;try{d=await open(s,$o);}catch(p){throw se(p)}try{let p;try{let f=await d.stat({bigint:!0});p=tn(f);}catch(f){throw se(f)}if(p.size>BigInt(i))throw new A("LIMIT_EXCEEDED");if(p.size>BigInt(Number.MAX_SAFE_INTEGER))throw new A("LIMIT_EXCEEDED");await jn(n,r);let u=await Yo(n,r.realRoot,o);await xt(s,r.realRoot,u,p);let y=new Uint8Array(new ArrayBuffer(Number(p.size))),b=0;for(;b<y.byteLength;){let f;try{f=(await d.read(y,b,y.byteLength-b,b)).bytesRead;}catch(T){throw se(T)}if(f<=0)throw new A("IDENTITY_CHANGED");b+=f;}let g;try{let f=await d.stat({bigint:!0});g=tn(f);}catch(f){throw se(f)}if(!Ft(p,g))throw new A("IDENTITY_CHANGED");return await xt(s,r.realRoot,u,g),await jn(n,r),new Uint8Array(y)}finally{await d.close().catch(()=>{});}}async readFileVerified(n,t,i){return this.readVerifiedFile(n,t,i)}},rn=new Pe,Bt=rn,Ht=Pe;});function ve(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 Gt(e){return typeof e=="string"&&te.test(e)?e:void 0}function ir(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function ye(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),o=Math.min(t.byteLength,i.byteLength);for(let r=0;r<o;r+=1){let s=t[r]-i[r];if(s!==0)return s}return t.byteLength-i.byteLength}function or(e){if(typeof e=="string")return {name:e,kind:"directory"};if(e===null||typeof e!="object")return null;let n=e;if(typeof n.name!="string")return null;if(n.kind==="file"||n.kind==="directory"||n.kind==="symlink"||n.kind==="other")return {name:n.name,kind:n.kind};if(n.type==="file"||n.type==="directory"||n.type==="symlink"||n.type==="other")return {name:n.name,kind:n.type};let t=n.isDirectory;if(typeof t=="function"&&t.call(e))return {name:n.name,kind:"directory"};let i=n.isSymbolicLink;if(typeof i=="function"&&i.call(e))return {name:n.name,kind:"symlink"};let o=n.isFile;return typeof o=="function"&&o.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function rr(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 sr(e){return nr.decode(e)}function ar(e){return JSON.parse(sr(e))}function Jt(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 cr(e){if(e instanceof A)return Jt(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return Jt(n)}}function ae(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function pr(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function dr(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 Wt(e,n,t,i){let o=pr(e);if(!o)throw new A("READ_DENIED");return rr(await o.call(e,n,t,i))}async function Jn(e,n,t){let i=dr(e);if(!i)throw new A("READ_DENIED");let o=await i.call(e,n,t);if(!Array.isArray(o))throw new A("READ_DENIED");return o.map(or).filter(r=>r!==null)}function lr(e,n,t,i){return Object.freeze({code:e,...{},source:n,relativePath:t})}function ur(e){if(!ve(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,o)=>{if(!Array.isArray(i))throw new TypeError("productBundle.reservedIds."+o+" must be an array");let r=[];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."+o+" must contain non-empty strings");r.push(a);}return Object.freeze([...new Set(r)].sort(ye))};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 fr(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 je(e){return Object.freeze({appIds:Object.freeze([...new Set(e.map(n=>n.appId))].sort(ye)),definitionIds:Object.freeze([...new Set(e.map(n=>n.definition.id))].sort(ye))})}function sn(e,n){let t=Object.keys(e).sort(ye),i=[...n].sort(ye);return t.length===i.length&&t.every((o,r)=>o===i[r])}function $t(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 yr(e){let n;try{n=ar(e);}catch{return}if(!ve(n)||!sn(n,["version","packages"])||n.version!==1||!Array.isArray(n.packages)||n.packages.length>Wn)return;let t=new Set,i=new Set,o=0,r=[];for(let s of n.packages){if(!ve(s))return;let a=["packageDir","appId","definition","files"],d=Object.hasOwn(s,"lineage"),p=Object.hasOwn(s,"launcher"),u=[...d?["lineage"]:[],...p?["launcher"]:[]];if(!sn(s,[...a,...u])||p&&s.launcher!==false)return;let y=$t(s.packageDir),b=Gt(s.appId);if(!y||y.length!==2||y[0]!=="apps"||!ir(y[1])||!b||t.has(s.packageDir)||!ve(s.definition)||!sn(s.definition,["id","version","hash"]))return;let g=Gt(s.definition.id),f=s.definition.version,T=s.definition.hash;if(!g||!Number.isSafeInteger(f)||f<1||typeof T!="string"||!Gn.test(T)||!Array.isArray(s.files)||s.files.length<2||s.files.length>$n)return;let C=new Set,j=[];for(let m of s.files){if(!ve(m)||!sn(m,["path","sha256"]))return;let N=$t(m.path);if(!N||typeof m.sha256!="string"||!Gn.test(m.sha256))return;let S=N.join("/"),H=`${s.packageDir}/${S}`;if(C.has(S)||i.has(H))return;C.add(S),i.add(H),j.push(Object.freeze({path:S,sha256:m.sha256}));}if(!C.has("ui-plugin.json")||!C.has("ui/index.html")||(o+=j.length,o>Zo))return;t.add(s.packageDir),r.push(Object.freeze({packageDir:s.packageDir,...p?{launcher:false}:{},appId:b,definition:Object.freeze({id:g,version:f,hash:T}),lineage:Array.isArray(s.lineage)?s.lineage:[],files:Object.freeze(j.sort((m,N)=>ye(m.path,N.path)))}));}return Object.freeze({version:1,packages:Object.freeze(r)})}function fe(e){let n=cr(e);return n==="PATH_ESCAPED"||n==="IDENTITY_CHANGED"||n==="TOCTOU"?"PATH_ESCAPED":n==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":"BUNDLE_INTEGRITY"}async function Ar(e,n,t,i,o){let r=[],s=async(a,d)=>{if(!ae(i,o))throw new A("LIMIT_EXCEEDED");if(d>2)throw new A("LIMIT_EXCEEDED");let p=await Jn(e,n,a);for(let u of p){if(typeof u.name!="string"||u.name.length===0||u.name==="."||u.name===".."||/[\\/\u0000]/.test(u.name))throw new A("PATH_ESCAPED");let y=`${a}/${u.name}`;if(u.kind==="file"){if(r.push(y.slice(t.length+1)),r.length>$n)throw new A("LIMIT_EXCEEDED")}else if(u.kind==="directory")await s(y,d+1);else throw u.kind==="symlink"?new A("PATH_ESCAPED"):new A("READ_DENIED")}};return await s(t,0),r.sort(ye)}function Ir(e){return e==="ui-plugin.json"?262144:e==="ui/index.html"?Ce:e==="ui/state.json"?65536:e.startsWith("ui/assets/")?er:Qo}async function Xt(e,n,t,i){if(e===void 0)return {packages:[],diagnostics:[],incomplete:false,reservedIds:tr};let o=ur(e.reservedIds),r=[],s=(l,P,F)=>lr(l,"bundled",P),a=(l=[],P=false,F)=>({...F===void 0?{}:{indexHash:F},packages:l,diagnostics:r,incomplete:P,reservedIds:o});if(typeof e.root!="string"||e.root.length===0||typeof e.expectedIndexHash!="string"||!Gn.test(e.expectedIndexHash))return r.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a();let d;try{d=await Wt(n,e.root,"bundle-index.json",qo);}catch(l){return r.push(s(fe(l),"bundle-index.json")),a()}let p=createHash("sha256").update(d).digest("hex");if(p!==e.expectedIndexHash)return r.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a();let u=yr(d);if(u===void 0)return r.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a();if(!fr(je(u.packages),o))return r.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a([],false,p);if(!ae(t,i))return r.push(s("LIMIT_EXCEEDED","bundle-index.json")),a(u.packages.map(l=>({indexEntry:l,failureCode:"LIMIT_EXCEEDED"})),true,p);let y;try{y=await Jn(n,e.root,"");}catch(l){return r.push(s(fe(l),"bundle-index.json")),a(u.packages.map(P=>({indexEntry:P,failureCode:fe(l)})),false,p)}if(!ae(t,i))return r.push(s("LIMIT_EXCEEDED","bundle-index.json")),a(u.packages.map(l=>({indexEntry:l,failureCode:"LIMIT_EXCEEDED"})),true,p);let b=y.find(l=>l.name==="bundle-index.json"&&l.kind==="file"),g=y.find(l=>l.name==="apps"&&l.kind==="directory"),f=l=>u.packages.map(P=>({indexEntry:P,failureCode:l}));if(!b)return r.push(s("BUNDLE_INTEGRITY","bundle-index.json")),a(f("BUNDLE_INTEGRITY"),false,p);let T=y.filter(l=>l.name!=="bundle-index.json"&&l.name!=="apps");if(T.length>0){let l=T.some(P=>P.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return r.push(s(l,"bundle-index.json")),a(f("BUNDLE_INTEGRITY"),false,p)}if(y.some(l=>l.name==="apps"&&l.kind!=="directory"))return r.push(s("PATH_ESCAPED","apps")),a(f("PATH_ESCAPED"),false,p);let C=[];if(g)try{C=await Jn(n,e.root,"apps");}catch(l){return r.push(s(fe(l),"apps")),a(f(fe(l)),false,p)}if(!ae(t,i)||C.length>Wn)return r.push(s("LIMIT_EXCEEDED","apps")),a(f("LIMIT_EXCEEDED"),true,p);let j=new Map(u.packages.map(l=>[l.packageDir.slice(5),l])),m=C.filter(l=>!j.has(l.name));for(let l of m)r.push(s(l.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY",`apps/${l.name}`));if(m.length>0){let l=m.some(P=>P.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return a(f(l),false,p)}let N=new Set,S=new Map,H=new Map;for(let l of u.packages){let P=S.get(l.appId)??[];P.push(l),S.set(l.appId,P);let F=`${l.definition.id}\0${String(l.definition.version)}`,h=H.get(F)??[];h.push(l),H.set(F,h);}for(let l of [...S.values(),...H.values()])if(l.length>1)for(let P of l)N.add(P);let v=[],Y=d.byteLength,M=false;for(let l of u.packages){if(!ae(t,i)){M=true,v.push({indexEntry:l,failureCode:"LIMIT_EXCEEDED"});continue}let P;try{let L=l.lineage[l.lineage.length-1];if(!L)throw new Z("LINEAGE_INVALID","Definition lineage is missing");if(L.definition.id!==l.definition.id||L.version!==l.definition.version||L.hash!==l.definition.hash)throw new Z("LINEAGE_STALE","Last lineage generation does not match bundle identity");P=Cn(l.lineage,{...L.definition,hash:L.hash}).entries;}catch(L){let Q=L instanceof Z?L.code:"LINEAGE_INVALID";r.push(s(Q,l.packageDir)),v.push({indexEntry:l,failureCode:Q});continue}let F=C.find(L=>L.name===l.packageDir.slice(5));if(!g||!F){v.push({indexEntry:l,failureCode:"BUNDLE_INTEGRITY"});continue}if(F.kind!=="directory"){v.push({indexEntry:l,failureCode:F.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY"});continue}let h;try{let L=await Ar(n,e.root,l.packageDir,t,i);if(!ae(t,i)){M=!0,v.push({indexEntry:l,failureCode:"LIMIT_EXCEEDED"});continue}let Q=l.files.map(K=>K.path);if(L.length!==Q.length||L.some((K,de)=>K!==Q[de])){v.push({indexEntry:l,failureCode:"BUNDLE_INTEGRITY"});continue}h=new Map;let ee;for(let K of l.files){if(!ae(t,i)){ee="LIMIT_EXCEEDED",M=!0;break}if(Y>=zn){ee="LIMIT_EXCEEDED";break}let de;try{de=await Wt(n,e.root,`${l.packageDir}/${K.path}`,Ir(K.path));}catch(yi){ee=fe(yi);break}if(!ae(t,i)){ee="LIMIT_EXCEEDED",M=!0;break}if(Y+de.byteLength>zn){Y=zn,ee="LIMIT_EXCEEDED";break}if(Y+=de.byteLength,createHash("sha256").update(de).digest("hex")!==K.sha256){ee="BUNDLE_INTEGRITY";break}h.set(K.path,de);}if(ee!==void 0){v.push({indexEntry:l,failureCode:ee});continue}}catch(L){ae(t,i)||(M=true),v.push({indexEntry:l,failureCode:fe(L)});continue}v.push({indexEntry:l,lineage:P,files:h,...N.has(l)?{failureCode:"DUPLICATE_ID"}:{}});}return a(v,M,p)}var qo,Wn,$n,Zo,Qo,er,zn,Gn,nr,tr,Xn=O(()=>{I();wn();Te();vn();Hn();qo=256*1024,Wn=64,$n=128,Zo=Wn*$n,Qo=2*1024*1024,er=8*1024*1024,zn=32*1024*1024,Gn=/^[0-9a-f]{64}$/,nr=new TextDecoder("utf-8",{fatal:true}),tr=Object.freeze({appIds:Object.freeze([]),definitionIds:Object.freeze([])});});var ai={};Ii(ai,{AppDiscoveryFsError:()=>A,LOCAL_APP_TOOL_PREFIX:()=>hr,MCP_APP_WORKSPACE_TOOL_PREFIX:()=>Tr,NodeAppDiscoveryFs:()=>Pe,NodeAppDiscoveryFsAdapter:()=>Ht,WORKSPACE_APP_TOOL_PREFIX:()=>Le,defaultAppDiscoveryFs:()=>rn,defaultNodeAppDiscoveryFs:()=>Bt,deriveWorkspaceAppToolName:()=>_r,deriveWorkspaceAppToolNames:()=>Zn,discoverWorkspaceAppCandidates:()=>$r,discoverWorkspaceApps:()=>et,isWorkspacePackage:()=>mr,productAppBundleReservations:()=>je,scanWorkspaceApps:()=>Xr});function mr(e,n){let t=n.split("/");return t.length===2&&t[0]===e&&/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(t[1])}function Zn(e){if(typeof e!="string"||!te.test(e))throw new TypeError("pluginId must be a safe UI plugin identifier");let n=`${Le}${e}`.length+7<=128?e:`hash_${createHash("sha256").update(e,"utf8").digest("hex")}`;return {read:`${Le}${n}_read`,action:`${Le}${n}_action`}}function _r(e,n="read"){let t=Zn(e);return n==="read"?t.read:t.action}function Ve(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 Kt(e){return typeof e=="string"&&te.test(e)?e:void 0}function Er(e,n){return n.length===0||n==="."||n===".."||/[\\/\u0000]/.test(n)?e==="skills"?"skills":"apps":`${e==="skills"?"skills":"apps"}/${n}`}function Nr(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function ti(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),o=Math.min(t.byteLength,i.byteLength);for(let r=0;r<o;r+=1){let s=t[r]-i[r];if(s!==0)return s}return t.byteLength-i.byteLength}function br(e){if(typeof e=="string")return {name:e,kind:"directory"};if(e===null||typeof e!="object")return null;let n=e;if(typeof n.name!="string")return null;if(n.kind==="file"||n.kind==="directory"||n.kind==="symlink"||n.kind==="other")return {name:n.name,kind:n.kind};if(n.type==="file"||n.type==="directory"||n.type==="symlink"||n.type==="other")return {name:n.name,kind:n.type};let t=n.isDirectory;if(typeof t=="function"&&t.call(e))return {name:n.name,kind:"directory"};let i=n.isSymbolicLink;if(typeof i=="function"&&i.call(e))return {name:n.name,kind:"symlink"};let o=n.isFile;return typeof o=="function"&&o.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function Pr(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 ii(e){return Dr.decode(e)}function oi(e){return JSON.parse(ii(e))}function Mr(e){if(!Ve(e))return;let n=Kt(e.pluginId);if(!n)return;let t=Kt(e.definitionId),i=e.version,o=t&&Number.isSafeInteger(i)&&i>=1?`${t}\0${String(i)}`:void 0;return {pluginId:n,...o===void 0?{}:{definitionKey:o}}}function Lr(e){let n=oi(e);return {value:n,identity:Mr(n)}}function Qn(e,n,t,i){let o={code:e,...i===void 0?{}:{pluginId:i},source:n,relativePath:t};return Object.freeze(o)}function qt(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 Ae(e){if(e instanceof A)return qt(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return qt(n)}}function Fe(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 Zt(e){switch(e.code){case "MANIFEST_INVALID":case "PRIMITIVE_UNKNOWN":case "PRIMITIVE_SET_UNSUPPORTED":case "SCHEMA_TYPE_UNSUPPORTED":case "TOKEN_INVALID":case "UNSAFE_VALUE":return "MANIFEST_INVALID";case "LIMIT_EXCEEDED":return "LIMIT_EXCEEDED";case "INITIAL_STATE_INVALID":return "INITIAL_STATE_INVALID";default:return ri("UiPluginValidationError",e.code)}}function ri(e,n){throw new Error(`Unmapped ${e} code: ${String(n)}`)}function Yn(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 ri("McpAppContractError",e)}}function Kn(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function Or(e){return {pluginId:e.appId,definitionKey:`${e.definition.id}\0${String(e.definition.version)}`}}function Sr(e,n){let t=n.get("package.json");if(t!==void 0)try{let o=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(t));if(Ve(o)){let r=o.bin,s=typeof r=="string"?r:Ve(r)?Object.values(r).find(a=>typeof a=="string"):void 0;for(let a of [s,o.main]){if(typeof a!="string")continue;let d=Ur(a);if(d&&n.has(d))return d}}}catch{}return [`${e.slice(e.lastIndexOf("/")+1)}.js`,"index.js","main.js"].find(o=>n.has(o))}function Ur(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 Rr(){return globalThis.performance?.now()??Date.now()}function Me(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))Me(n);return Object.freeze(e)}function Qt(e){return Object.freeze(Array.from(e))}async function qn(e,n,t,i){if(n.pinnedFiles!==void 0){let o=n.pinnedFiles.get(t);if(o===void 0)throw new A("NOT_FOUND");if(o.byteLength>i)throw new A("LIMIT_EXCEEDED");return new Uint8Array(o)}return si(e,n.root,`${n.relativePath}/${t}`,i)}function kr(e,n,t){let i=createHash("sha256"),o=new TextEncoder().encode(J(e)),r=s=>{let a=new Uint8Array(8);new DataView(a.buffer).setBigUint64(0,BigInt(s)),i.update(a);};return r(o.byteLength),i.update(o),r(n.byteLength),i.update(n),r(t.byteLength),i.update(t),i.digest("hex")}function Cr(e,n){let t={...e.definition,sourceHash:n},i;try{i=ie(t);}catch(r){throw r instanceof _&&r.code==="INPUT_INVALID"?new $("MANIFEST_INVALID","normalized definition is invalid"):r}let o={...t,hash:i};try{oe(o);}catch{throw new $("MANIFEST_INVALID","normalized definition is invalid")}return o}function wr(e){return e.actions.some(n=>n.backend.type==="core"&&n.backend.handler!=="state.set")}function xr(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function vr(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 si(e,n,t,i){let o=xr(e);if(!o)throw new A("READ_DENIED");return Pr(await o.call(e,n,t,i))}async function jr(e,n,t){let i=vr(e);if(!i)throw new A("READ_DENIED");let o=await i.call(e,n,t);if(!Array.isArray(o))throw new A("READ_DENIED");return o.map(br).filter(r=>r!==null)}function Vr(e){let n=[];for(let t of [e.reserved,e.builtin])t&&n.push(t);return e.builtins&&"listMcpApps"in e.builtins?n.push(ei(e.builtins)):e.builtins&&n.push(e.builtins),e.builtinCatalog&&n.push(ei(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 ei(e){let n=[],t=[],i=[];for(let o of e.listMcpApps())typeof o.appId=="string"&&n.push(o.appId),o.definition&&typeof o.definition.id=="string"&&t.push(o.definition.id);for(let o of e.listMcpAppTools())typeof o.name=="string"&&i.push(o.name);return {appIds:n,definitionIds:t,toolNames:i}}function ce(e,n){e.diagnostic||(e.diagnostic=Qn(n,e.source,e.relativePath,e.identity?.pluginId));}function Fr(e){let n=new Map;for(let i of e){let o=i.identity?.pluginId;if(o===void 0)continue;let r=n.get(o)??[];r.push(i),n.set(o,r);}for(let i of n.values()){if(i.length<2)continue;let o=i.filter(s=>s.provenance!==void 0);if(o.length>0){for(let s of i)s.provenance===void 0&&ce(s,"RESERVED_ID");if(o.length>1)for(let s of o)ce(s,"DUPLICATE_ID");continue}let r=i.filter(s=>s.source==="apps");if(r.length>1){for(let s of r)ce(s,"DUPLICATE_ID");for(let s of i.filter(a=>a.source==="skills"))ce(s,"DUPLICATE_ID");}else for(let s of i.filter(a=>a.source==="skills"))ce(s,"DUPLICATE_ID");}let t=new Map;for(let i of e){if(i.diagnostic?.code==="RESERVED_ID")continue;let o=i.identity?.definitionKey;if(o===void 0)continue;let r=t.get(o)??[];r.push(i),t.set(o,r);}for(let i of t.values())if(i.length>1)for(let o of i)ce(o,"DUPLICATE_ID");}function Br(e,n,t){let i=new Set,o=new Set,r=new Set,s=new Set(t.appIds),a=new Set(t.definitionIds);for(let d of Vr(n)){for(let p of d.appIds??[])typeof p=="string"&&i.add(p);for(let p of d.definitionIds??[])typeof p=="string"&&o.add(p);for(let p of d.toolNames??[])typeof p=="string"&&r.add(p);}for(let d of e){let p=d.candidate;if(!p)continue;if(i.has(p.pluginId)||o.has(p.definitionId)){ce(d,"RESERVED_ID");continue}if(d.provenance===void 0&&(s.has(p.pluginId)||a.has(p.definitionId))){ce(d,"RESERVED_ID");continue}[p.toolNames.read,p.toolNames.action].filter(y=>y!==void 0).some(y=>r.has(y))&&ce(d,"DUPLICATE_ID");}}function Hr(e){return [...e].sort((n,t)=>{let i=Yt.indexOf(n.source)-Yt.indexOf(t.source);return i!==0?i:ti(n.relativePath,t.relativePath)})}function E(e,n){e.diagnostic=Qn(n,e.source,e.relativePath,e.identity?.pluginId);}async function ni(e,n,t){if(t.byteLength>262144){E(n,"LIMIT_EXCEEDED");return}let i;try{i=Lr(t);}catch{E(n,"MANIFEST_INVALID");return}if(n.bundleIdentity===void 0)n.identity=i.identity;else if(i.identity?.pluginId!==n.bundleIdentity.appId||i.identity.definitionKey!==`${n.bundleIdentity.definitionId}\0${String(n.bundleIdentity.version)}`){E(n,"BUNDLE_INTEGRITY");return}if(Ve(i.value)&&i.value.builtinOnly===true){E(n,"RESERVED_ID");return}let o;try{let h=Ye(i.value,{mode:"local"});if(h.manifestVersion!==2)throw new $("MANIFEST_INVALID","workspace App requires v2");o=h;}catch(h){if(h instanceof $){E(n,Zt(h));return}if(h instanceof re){E(n,Yn(h.code));return}if(Ve(h)&&typeof h.code=="string"){E(n,Yn(h.code));return}throw h}let r={pluginId:o.pluginId,definitionKey:`${o.definitionId}\0${String(o.version)}`};if(n.bundleIdentity===void 0&&(n.identity=r),o.actions.length>0)try{kt(o.actions.map(h=>({actionId:h.actionId,inputSchema:h.inputSchema})));}catch(h){if(h instanceof re){E(n,Yn(h.code));return}throw h}let s;try{s=await qn(e,n,"ui/index.html",Ce);}catch(h){E(n,Fe(Ae(h),"entry"));return}if(s.byteLength>Ce){E(n,"LIMIT_EXCEEDED");return}let a;try{a=ii(s);}catch{E(n,"ENTRY_INVALID");return}if(s.byteLength===0||a.length===0){E(n,"ENTRY_INVALID");return}let d=createHash("sha256").update(s).digest("hex");if(o.entryHash!==void 0&&o.entryHash!==d){E(n,"ENTRY_INVALID");return}let p={},u,y;if(o.initialState!==void 0){try{u=await qn(e,n,"ui/state.json",65536);}catch(h){E(n,Fe(Ae(h),"initial"));return}if(u.byteLength>65536){E(n,"LIMIT_EXCEEDED");return}try{let h=oi(u),L=o.dataPaths??[],Q=Un(h,L);p=ne(Q,0,L),me(p);}catch{E(n,"INITIAL_STATE_INVALID");return}if(y=createHash("sha256").update(u).digest("hex"),o.initialState.hash!==void 0&&o.initialState.hash!==y){E(n,"INITIAL_STATE_INVALID");return}}let b={...o,entryHash:d,...o.initialState===void 0?{}:{initialState:{path:"ui/state.json",hash:y}}},g=Rn(b),f=kr(b,s,u??new Uint8Array),T;try{T=Cr(g,f);}catch(h){if(h instanceof $){E(n,Zt(h));return}throw h}let C;if(n.bundleLineage!==void 0){let h=n.bundleLineage[n.bundleLineage.length-1];if(!h){E(n,"LINEAGE_INVALID");return}let{legacy:L,...Q}=h.definition,{hash:ee,...K}=T;if(J(Q)!==J(K)){E(n,"LINEAGE_STALE");return}if(L!==void 0&&(T={...T,legacy:L}),L!==void 0)try{T={...T,hash:ie(T)},oe(T);}catch{E(n,"LINEAGE_INVALID");return}C=n.bundleLineage;}if(n.bundleIdentity!==void 0&&n.bundleIdentity.appId!==o.pluginId){E(n,"BUNDLE_INTEGRITY");return}if(n.bundleIdentity!==void 0&&(n.bundleIdentity.definitionId!==T.id||n.bundleIdentity.version!==T.version||n.bundleIdentity.definitionHash!==T.hash)){E(n,"LINEAGE_STALE");return}let j=Zn(o.pluginId),m=o.actions.length===0?{read:j.read}:j,N=Me(g),S=Me(b),H=Me(T),v=Me({...g.handlers}),Y=Qt(s),M=u===void 0?void 0:Qt(u),l=Object.freeze({...n.provenance===void 0?{}:{provenance:n.provenance},entry:Object.freeze({path:"ui/index.html",hash:d,bytes:Y}),...M===void 0?{}:{initialState:Object.freeze({path:"ui/state.json",hash:y,bytes:M})}}),P={appId:o.pluginId,pluginId:o.pluginId,definitionId:o.definitionId,version:o.version,relativePath:n.relativePath,manifest:S,normalized:N,name:o.name,description:o.description,...o.icon===void 0?{}:{icon:o.icon},...o.tone===void 0?{}:{tone:o.tone},definition:H,handlers:v,resources:l,html:a,entryBytes:Y,entryHash:d,initialState:Me(p),...M===void 0?{}:{initialStateBytes:M},...y===void 0?{}:{initialStateHash:y},sourceHash:f,toolNames:Object.freeze(m)},F=n.provenance===void 0?{...P,source:n.source}:{...P,provenance:n.provenance,lineage:C??[]};n.candidate=Object.freeze(F),wr(o)&&E(n,"EXEC_DENIED");}async function zr(e,n){try{return await qn(e,n,"ui-plugin.json",262144)}catch(t){if(Ae(t)==="NOT_FOUND")return;E(n,Fe(Ae(t),"manifest"));return}}function Gr(e,n,t,i=gr,o=false){let r=Hr(e);Fr(r);let s=Object.freeze(r.filter(u=>u.candidate!==void 0&&u.diagnostic===void 0).map(u=>u.candidate)),a=Object.freeze(r.filter(u=>u.diagnostic!==void 0).map(u=>u.diagnostic)),d=o?Object.freeze({...t===void 0?{}:{indexHash:t},diagnostics:Object.freeze(a.filter(u=>u.source==="bundled").map(u=>Object.freeze({...u}))),reservedAppIds:Object.freeze([...i.appIds]),reservedDefinitionIds:Object.freeze([...i.definitionIds])}):void 0,p={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(p,"candidates",{configurable:false,enumerable:false,get:()=>s}),Object.freeze(p)}function Jr(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 Wr(e,n){if(Jr(e))return {fs:e,options:n??{}};let t=e??n??{};return {fs:t.filesystem??t.fileSystem??t.fs??rn,options:t}}async function et(e,n,t){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");let{fs:i,options:o}=Wr(n,t),r=o.clock??Rr,s=r(),a=[],d=0,p,u=await Xt(o.productBundle,i,s,r);a.push(...u.diagnostics.map(g=>({source:g.source,root:o.productBundle?.root??e,name:"",relativePath:g.relativePath,diagnostic:g})));let y=u.reservedIds;u.incomplete&&(p="time_limit");for(let g of u.packages){let f=g.indexEntry,T=f.packageDir,C=g.files===void 0?void 0:Sr(T,g.files),j=u.indexHash===void 0?void 0:Nt(Object.freeze({kind:"bundled",launcher:f.launcher!==false,indexHash:u.indexHash,packageDir:T,appId:f.appId,definitionId:f.definition.id,version:f.definition.version,definitionHash:f.definition.hash,files:f.files}),C),m={source:"bundled",root:o.productBundle?.root??e,name:T.slice(5),relativePath:T,...j===void 0?{}:{provenance:j},...g.files===void 0?{}:{pinnedFiles:g.files},...g.lineage===void 0?{}:{bundleLineage:g.lineage},bundleIdentity:{appId:f.appId,definitionId:f.definition.id,version:f.definition.version,definitionHash:f.definition.hash},identity:Or(f)};if(a.push(m),d+=1,g.failureCode!==void 0){E(m,g.failureCode);continue}let N=g.files?.get("ui-plugin.json");if(N===void 0){E(m,"BUNDLE_INTEGRITY");continue}await ni(i,m,N),m.candidate!==void 0&&m.diagnostic===void 0&&d<64&&!Kn(s,r)&&(p="time_limit");}let b=[{source:"apps",directory:"apps"},{source:"skills",directory:"skills"}];for(let g of b){let{source:f,directory:T}=g,C;try{C=await jr(i,e,T);}catch(m){if(Ae(m)==="NOT_FOUND")continue;a.push({source:f,root:e,name:"",relativePath:f,diagnostic:Qn(Fe(Ae(m),"manifest"),f,f)});continue}let j=C.filter(m=>m.kind==="directory"||m.kind==="symlink").filter(m=>Nr(m.name)).map(m=>({source:f,root:e,name:m.name,relativePath:Er(f,m.name)})).sort((m,N)=>ti(m.relativePath,N.relativePath));for(let m of j){let N={...m};a.push(N);let S;if(f==="skills"&&(S=await zr(i,N),S===void 0))continue;if(d>=64){E(N,"LIMIT_EXCEEDED");continue}if(m.relativePath.split("/").length-1>2){E(N,"LIMIT_EXCEEDED");continue}if(p!==void 0||!Kn(s,r)){E(N,"LIMIT_EXCEEDED"),p="time_limit";continue}if(d+=1,S===void 0)try{S=await si(i,N.root,`${N.relativePath}/ui-plugin.json`,262144);}catch(v){E(N,Fe(Ae(v),"manifest"));continue}await ni(i,N,S),N.diagnostic===void 0&&d<64&&!Kn(s,r)&&(p="time_limit");}}return Br(a,o,y),Gr(a,p,u.indexHash,y,o.productBundle!==void 0)}var gr,Le,hr,Tr,Yt,Dr,$r,Xr,ci=O(()=>{I();_e();Be();pe();_t();Te();vn();Qe();Hn();en();Xn();Xn();gr=je([]);Le="crewx_local_app_",hr=Le,Tr=Le;Yt=["bundled","apps","skills"],Dr=new TextDecoder("utf-8",{fatal:true});$r=et,Xr=et;});I();var pi="SKILL.md",Qr=/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;function di(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function es(e){return e.isDirectory()||e.isSymbolicLink()}function fi(e){try{return existsSync(e)&&statSync(e).isDirectory()}catch{return false}}var ns=["index.js","main.js"];function Mc(e,n){let t=join(e,"package.json");if(existsSync(t))try{let o=JSON.parse(readFileSync(t,"utf8"));if(o.bin){let r=typeof o.bin=="string"?o.bin:Object.values(o.bin).find(s=>typeof s=="string");if(r){let s=resolve(e,r);if(existsSync(s))return s}}if(typeof o.main=="string"){let r=resolve(e,o.main);if(existsSync(r))return r}}catch{}let i=resolve(e,`${n}.js`);if(existsSync(i))return i;for(let o of ns){let r=resolve(e,o);if(existsSync(r))return r}}function ts(e){let n;try{n=readFileSync(e,"utf8");}catch{return {frontmatter:{},readable:false,valid:false,hasFrontmatter:false}}let t=n.match(Qr);if(!t)return {frontmatter:{},readable:true,valid:true,hasFrontmatter:false};try{let i=load(t[1]??"");if(!di(i))return {frontmatter:{},readable:!0,valid:!1,hasFrontmatter:!0};let o=di(i.metadata)?i.metadata:void 0;return {frontmatter:{...typeof i.name=="string"?{name:i.name}:{},...typeof(o?.version??i.version)=="string"?{version:o?.version??i.version}:{},...typeof i.description=="string"?{description:i.description}:{}},readable:!0,valid:!0,hasFrontmatter:!0}}catch{return {frontmatter:{},readable:true,valid:false,hasFrontmatter:true}}}function is(e){return [join(e,pi),join(e,"skill",pi)]}function cn(e,n){if(!fi(e))return null;for(let t of is(e)){if(!existsSync(t))continue;let o=ts(t).frontmatter;return {name:o.name??n,...o.version===void 0?{}:{version:o.version},...o.description===void 0?{}:{description:o.description},skillMdPath:t,dir:e}}return null}function nt(e){try{return readdirSync(e,{withFileTypes:!0}).filter(es)}catch{return []}}function os(e){return e.length===0||/[\\\u0000]/.test(e)?false:e.split("/").every(n=>n.length>0&&n!=="."&&n!=="..")}function li(e,n,t){!e||n.has(e.name)||(n.add(e.name),t.push(e));}function pn(e){let n=[],t=new Set;for(let i of e)if(fi(i))for(let o of nt(i)){if(o.name.startsWith("@")){let r=join(i,o.name);for(let s of nt(r))li(cn(join(r,s.name),s.name),t,n);continue}li(cn(join(i,o.name),o.name),t,n);}return n.sort((i,o)=>i.name.localeCompare(o.name))}function rs(e,n){if(!os(e))throw new Error(`Skill not found: ${e}`);for(let i of n){let o=cn(join(i,e),e);if(o)return o;for(let r of nt(i)){if(!r.name.startsWith("@"))continue;let s=cn(join(i,r.name,e),e);if(s)return s}}let t=pn(n).find(i=>i.name===e);if(t)return t;throw new Error(`Skill not found: ${e}`)}async function Lc(e){if(!e||e.root===null)return {skills:[],diagnostics:[]};let{discoverWorkspaceApps:n}=await Promise.resolve().then(()=>(ci(),ai)),t=await n(e.root,{productBundle:e}),i=[],o=new Set;for(let r of t.apps){let s=r.provenance?.kind==="bundled"?r.provenance.packageDir:void 0;if(!s)continue;let a=join(e.root,...s.split("/"));for(let d of pn([dirname(a)]))resolve(d.dir)!==resolve(a)||o.has(d.name)||(o.add(d.name),i.push(d));for(let d of [join(a,"skill"),join(a,"skills")])for(let p of pn([d]))o.has(p.name)||(o.add(p.name),i.push(p));}return {skills:i.sort((r,s)=>r.name.localeCompare(s.name)),diagnostics:t.diagnostics.filter(r=>r.source==="bundled")}}var Oc=pn,Sc=rs;
2
- export{pn as discover,Lc as discoverBundledProductSkills,Oc as discoverSkills,Mc as findEntrypoint,ts as readSkillFrontmatter,rs as resolve,Sc as resolveSkill};
1
+ import {join,resolve,dirname,relative,sep,isAbsolute}from'path';import'url';import {createHash}from'crypto';import {existsSync,readFileSync,statSync,readdirSync,constants}from'fs';import {realpath,stat,readdir,open,lstat}from'fs/promises';import {load}from'js-yaml';var Ui=Object.defineProperty;var k=(e,n)=>()=>(e&&(n=e(e=0)),n);var Ri=(e,n)=>{for(var t in n)Ui(e,t,{get:n[t],enumerable:true});};var _=k(()=>{});var P,Xe=k(()=>{_();P=class extends Error{constructor(t,i=t,o){super(i);this.code=t;this.currentRevision=o;}code;currentRevision;name="UiRuntimeError"};});function Tn(e){return ki.test(e)||Ci.test(e)}function W(){throw new P("INPUT_INVALID","JSON value is not projection-safe")}function ji(e){let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function mn(e,n,t,i,o,r){if(n>i&&W(),e===null||typeof e=="string"||typeof e=="boolean")return typeof e=="string"&&(wi.test(e)||vi.test(e)&&!Bi(o,r)||xi.test(e))&&W(),e;if(typeof e=="number")return Number.isFinite(e)||W(),e;(typeof e!="object"||e===void 0||typeof e=="function"||typeof e=="bigint")&&W();let a=e;t.has(a)&&W(),t.add(a);try{if(Array.isArray(e))return e.map(d=>mn(d,n+1,t,i,o,r));ji(a)||W();let s={};for(let[d,c]of Object.entries(e))Tn(d)&&W(),s[d]=mn(c,n+1,t,i,[...o,d],r);return s}finally{t.delete(a);}}function ie(e,n=0,t=[]){(!Number.isInteger(n)||n<0||n>Fi)&&W(),(!Array.isArray(t)||t.some(o=>typeof o!="string"))&&W();let i=mn(e,0,new Set,Vi+n,[],t);return (i===null||Array.isArray(i)||typeof i!="object")&&W(),i}function me(e,n){if(!e||!n)return false;let t=e.split("."),i=n.split(".");return t.length>=i.length&&i.every((o,r)=>t[r]===o)}function Bi(e,n){if(e.length===0)return false;let t=e.join(".");return n.some(i=>me(t,i))}function he(e){try{let n=JSON.stringify(e);return n===void 0&&W(),n}catch{W();}}function hn(e){return Array.isArray(e)?e.map(hn):e!==null&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,hn(e[n])])):e}function $(e){return he(hn(e))}function _n(e){return Buffer.byteLength(e,"utf8")}var ki,Ci,wi,xi,vi,Vi,Fi,le=k(()=>{_();Xe();ki=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,Ci=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i,wi=/<\/?[A-Za-z][^>]*>/,xi=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,vi=/^(?:https?|file|ftp|ws|wss):\/\//i;Vi=8,Fi=4;});function Te(e){return Hi.has(e)||zi.test(e)||Gi.test(e)}var ut,Hi,zi,Gi,$e,ke,oe,Dn,En,Nn,bn,Pn,_e=k(()=>{_();ut=["__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"],Hi=new Set(ut),zi=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,Gi=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i;$e=/^[A-Za-z0-9_]+$/,ke=/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/,oe=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,Dn=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,En=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,Nn=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/,bn=["blue","violet","emerald","amber","rose","sky","slate","indigo"],Pn=["inline","panel"];});function Mn(e){return typeof e=="string"&&ft.includes(e)}var ft,yt=k(()=>{_();_e();ft=["text/plain","application/json"];});function Ke(e){if(!Ln(e))return false;let n=Object.keys(e);return !(n.some(t=>t!=="in"&&t!=="out")||n.length===0||Object.hasOwn(e,"in")&&!Ji(e.in)||Object.hasOwn(e,"out")&&!Wi(e.out))}function Ji(e){return Ln(e)?Object.keys(e).every(t=>t==="mediaType"||t==="required")&&Object.hasOwn(e,"mediaType")&&Mn(e.mediaType)&&(!Object.hasOwn(e,"required")||typeof e.required=="boolean"):false}function Wi(e){return Ln(e)?Object.keys(e).every(t=>t==="mediaType"||t==="range")&&Object.hasOwn(e,"mediaType")&&Mn(e.mediaType)&&(!Object.hasOwn(e,"range")||typeof e.range=="boolean"):false}function Ln(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var Sn=k(()=>{_();yt();new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});});function re(e){let t=e.renderer!==void 0||e.surfaces!==void 0||e.stateProjection!==void 0||e.dataPaths!==void 0||e.usage!==void 0||e.detailPanel!==void 0||e.displayModes!==void 0||e.summaryProjection!==void 0||e.legacy!==void 0||Object.values(e.actions).some(o=>o.resultProjection!==void 0)?{id:e.id,version:e.version,...e.renderer===void 0?{}:{renderer:e.renderer},...e.surfaces===void 0?{}:{surfaces:e.surfaces},...e.stateProjection===void 0?{}:{stateProjection:e.stateProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.legacy===void 0?{}:{legacy:e.legacy},...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},actions:e.actions}:e.sourceHash===void 0?{id:e.id,version:e.version,actions:e.actions}:{id:e.id,version:e.version,sourceHash:e.sourceHash,actions:e.actions},i=ie(t);return createHash("sha256").update($(i)).digest("hex")}function ae(e){if(!/^\d+$/.test(String(e.version))||e.version<1||e.id.length<1||e.id.length>128)throw new P("DEFINITION_UNSUPPORTED","UI definition is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!$i.test(e.sourceHash)))throw new P("DEFINITION_UNSUPPORTED","UI definition source hash is invalid");if(!/^[0-9a-f]{64}$/.test(e.hash)||re(e)!==e.hash)throw new P("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=>!Yi(i)))throw new P("DEFINITION_UNSUPPORTED","UI action declaration is invalid");if(t.confirmation!==void 0&&t.confirmation!=="none"&&t.confirmation!=="native")throw new P("DEFINITION_UNSUPPORTED","UI action confirmation is invalid");if(t.inputKeys&&(!Array.isArray(t.inputKeys)||t.inputKeys.some(i=>typeof i!="string"||!i)))throw new P("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 P("DEFINITION_UNSUPPORTED","UI action data input declaration is invalid");if(t.resultProjection&&On(t.resultProjection),t.content!==void 0&&!Ke(t.content))throw new P("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 P("DEFINITION_UNSUPPORTED","UI action environment declaration is invalid")}if(e.renderer!==void 0&&(!e.renderer||e.renderer.length>128))throw new P("DEFINITION_UNSUPPORTED","UI definition renderer is invalid");if(e.surfaces&&(!Array.isArray(e.surfaces)||e.surfaces.some(n=>!n||n.length>64)))throw new P("DEFINITION_UNSUPPORTED","UI definition surfaces are invalid");if(e.usage!==void 0&&e.usage!=="card"&&e.usage!=="window")throw new P("DEFINITION_UNSUPPORTED","UI definition usage is invalid");if(e.detailPanel!==void 0&&typeof e.detailPanel!="boolean")throw new P("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 P("DEFINITION_UNSUPPORTED","UI definition displayModes are invalid");if(e.usage==="card"&&e.displayModes!==void 0)throw new P("DEFINITION_UNSUPPORTED","Card definitions cannot declare displayModes");if(e.usage==="window"&&e.detailPanel!==void 0)throw new P("DEFINITION_UNSUPPORTED","Window definitions cannot declare detailPanel");if(e.stateProjection&&On(e.stateProjection),e.summaryProjection){On(e.summaryProjection);let n=new Set(e.stateProjection?.allow??[]);if(e.summaryProjection.allow.some(t=>!n.has(t)))throw new P("DEFINITION_UNSUPPORTED","UI summary projection exceeds state projection")}if(e.legacy!==void 0){if(!e.legacy||typeof e.legacy!="object"||Array.isArray(e.legacy)||Object.keys(e.legacy).some(o=>!["readTool","actionTool","hostTools","agentAccess"].includes(o)))throw new P("DEFINITION_UNSUPPORTED","UI legacy metadata is invalid");let n=new Set;for(let[o,r]of [["readTool",e.legacy.readTool],["actionTool",e.legacy.actionTool]])if(r!==void 0){if(Ki(r,o==="readTool"),n.has(r.name))throw new P("DEFINITION_UNSUPPORTED","UI legacy tool names collide");n.add(r.name);}let t=e.legacy.hostTools;if(t!==void 0){if(!t||typeof t!="object"||Array.isArray(t))throw new P("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");let o={"doc.open":"crewx_app_html_viewer_open","pty.connect":"crewx_app_terminal_connect"};for(let[r,a]of Object.entries(t)){if(!Object.hasOwn(o,r)||o[r]!==a||typeof a!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(a)||n.has(a))throw new P("DEFINITION_UNSUPPORTED","UI legacy host tools are invalid");n.add(a);}}let i=e.legacy.agentAccess;if(i!==void 0&&(!i||typeof i!="object"||Array.isArray(i)||Object.entries(i).some(([o,r])=>!o||!Object.hasOwn(e.actions,o)||r!=="allowed"&&r!=="denied")))throw new P("DEFINITION_UNSUPPORTED","UI legacy agent access is invalid");if(e.legacy.actionTool!==void 0&&(!i||Object.keys(i).length===0))throw new P("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=>me(t,i))))throw new P("DEFINITION_UNSUPPORTED","UI definition dataPaths are invalid")}}function Ki(e,n){if(!e||typeof e!="object"||Array.isArray(e))throw new P("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");let t=e,i=["name","description","inputSchema","textFallback","visibility"],o=Object.hasOwn(t,"fixedResult");if(Object.keys(t).some(r=>!i.includes(r)&&!(n&&r==="fixedResult"))||i.some(r=>!Object.hasOwn(t,r))||typeof t.name!="string"||!/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(t.name)||typeof t.description!="string"||t.description.trim().length===0||t.description.length>8192||typeof t.textFallback!="string"||t.textFallback.trim().length===0||t.textFallback.length>16384||!t.inputSchema||typeof t.inputSchema!="object"||Array.isArray(t.inputSchema)||!Array.isArray(t.visibility)||t.visibility.length===0||t.visibility.some(r=>r!=="model"&&r!=="app")||new Set(t.visibility).size!==t.visibility.length)throw new P("DEFINITION_UNSUPPORTED","UI legacy tool metadata is invalid");try{let r=ie(t.inputSchema);if(r.type!==void 0&&r.type!=="object")throw new Error("schema type");if(o){if(!n)throw new Error("fixed result location");let a=t.fixedResult;if(!a||typeof a!="object"||Array.isArray(a))throw new Error("fixed result");let s=a;if(Object.keys(s).sort().join(",")!=="argsPolicy,structuredContent"||s.argsPolicy!=="empty-only"&&s.argsPolicy!=="ignore"||!s.structuredContent||typeof s.structuredContent!="object"||Array.isArray(s.structuredContent))throw new Error("fixed result");let d=ie(s.structuredContent);if(_n(he(d))>4*1024)throw new Error("fixed result size")}}catch{throw new P("DEFINITION_UNSUPPORTED","UI legacy tool metadata is not projection-safe")}}function On(e){if(!Array.isArray(e.allow)||e.allow.some(n=>!/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/.test(n)))throw new P("DEFINITION_UNSUPPORTED","UI projection policy is invalid")}function Yi(e){return e.length>0&&e.length<=128&&e!=="*"&&e!=="all"&&!/[/*]/.test(e)}var $i,De=k(()=>{_();le();Xe();Sn();$i=/^[0-9a-f]{64}$/;});var At=k(()=>{_();le();});var Ce,It=k(()=>{_();Ce="window";});function p(e,n=e){throw new Y(e,n)}function v(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 O(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function F(e,n,t=[]){let i=new Set([...n,...t]);Object.keys(e).some(o=>!i.has(o))&&p("MANIFEST_INVALID"),n.some(o=>!O(e,o))&&p("MANIFEST_INVALID");}function en(e,n=false,t=false,i=false){return eo.test(e)||!i&&to.test(e)||no.test(e)||t&&gt.test(e)||io.test(e)&&!(n&&/^\s*data:/i.test(e)&&!gt.test(e))}function Ze(e,n=new Set,t=0,i=false,o=false){if(typeof e=="string"){en(e,i,o)&&p("UNSAFE_VALUE");return}if(!(e===null||typeof e!="object")){(t>8||n.has(e))&&p("MANIFEST_INVALID"),n.add(e);try{if(Array.isArray(e)){for(let r of e)Ze(r,n,t+1);return}v(e)||p("MANIFEST_INVALID");for(let[r,a]of Object.entries(e))Ze(a,n,t+1,i&&t===0&&(r==="name"||r==="description"),o);}finally{n.delete(e);}}}function ne(e,n){let t=e[n];return typeof t!="string"&&p("MANIFEST_INVALID"),t}function K(e,n,t){let i=e[n];return (!Number.isSafeInteger(i)||i<t)&&p("MANIFEST_INVALID"),i}function Un(e){return Qi.test(e)||p("MANIFEST_INVALID"),e}function Ee(e){return Zi.test(e)||p("TOKEN_INVALID"),e}function No(e){return Pt.test(e)||p("MANIFEST_INVALID"),e}function bo(e){v(e)||p("MANIFEST_INVALID");let n={};for(let[t,i]of Object.entries(e)){let o=No(t);v(i)||p("MANIFEST_INVALID");let r=i.type;if(r==="text"){F(i,["type","maxLength"]),n[o]={type:r,maxLength:K(i,"maxLength",1)};continue}if(r==="text-list"){F(i,["type","max","itemMaxLength"]),n[o]={type:r,max:K(i,"max",0),itemMaxLength:K(i,"itemMaxLength",1)};continue}if(r==="step-list"){F(i,["type","min","max","labelMaxLength","detailMaxLength"]);let a=K(i,"min",0),s=K(i,"max",1);a>s&&p("MANIFEST_INVALID"),n[o]={type:r,min:a,max:s,labelMaxLength:K(i,"labelMaxLength",1),detailMaxLength:K(i,"detailMaxLength",1)};continue}typeof r=="string"&&p("SCHEMA_TYPE_UNSUPPORTED"),p("MANIFEST_INVALID");}return n}function Po(e,n,t){let i=e[n];(!i||i.type!==t)&&p("MANIFEST_INVALID");}function Ye(e,n,t){let i=ne(e,"field");return Pt.test(i)||p("MANIFEST_INVALID"),Po(n,i,t),i}function Mo(e,n){v(e)||p("MANIFEST_INVALID");let t=e.primitive;switch(typeof t!="string"&&p("MANIFEST_INVALID"),Eo.includes(t)||p("PRIMITIVE_UNKNOWN"),t){case "card-shell":return F(e,["primitive"]),{primitive:t};case "meta-banner":return F(e,["primitive","badgeToken","noticeToken"]),{primitive:t,badgeToken:Ee(ne(e,"badgeToken")),noticeToken:Ee(ne(e,"noticeToken"))};case "heading":return F(e,["primitive","field"]),{primitive:t,field:Ye(e,n,"text")};case "labeled-text":return F(e,["primitive","titleToken","field","variant"]),e.variant!=="callout"&&p("MANIFEST_INVALID"),{primitive:t,titleToken:Ee(ne(e,"titleToken")),field:Ye(e,n,"text"),variant:"callout"};case "step-flow":return F(e,["primitive","titleToken","field"]),{primitive:t,titleToken:Ee(ne(e,"titleToken")),field:Ye(e,n,"step-list")};case "text-list":{F(e,["primitive","titleToken","field"],["emptyToken","hideWhenEmpty"]);let i={primitive:t,titleToken:Ee(ne(e,"titleToken")),field:Ye(e,n,"text-list")};return O(e,"emptyToken")&&(i.emptyToken=Ee(ne(e,"emptyToken"))),O(e,"hideWhenEmpty")&&(typeof e.hideWhenEmpty!="boolean"&&p("MANIFEST_INVALID"),i.hideWhenEmpty=e.hideWhenEmpty),i}}return p("MANIFEST_INVALID")}function Lo(e,n){return Array.isArray(e)||p("MANIFEST_INVALID"),e.map(t=>Mo(t,n))}function B(e="v2 manifest exceeds a contract limit"){return p("LIMIT_EXCEEDED",e)}function X(e="initial state is not projection-safe"){return p("INITIAL_STATE_INVALID",e)}function mt(e,n){return (typeof e!="string"||e.length===0||e.length>4096||e.trim().length===0||To.test(e)||_o.test(e))&&p("MANIFEST_INVALID",`${n} is invalid`),(en(e,true,true)||oo.test(e)||ro.test(e)||ao.test(e))&&p("UNSAFE_VALUE",`${n} contains an unsafe value`),e}function Rn(e,n){return (typeof e!="string"||!oe.test(e))&&p("MANIFEST_INVALID",`${n} is invalid`),e}function So(e){return (typeof e!="string"||!Dn.test(e)||e==="*"||e==="all")&&p("MANIFEST_INVALID","action capability is invalid"),e}function Mt(e){return (typeof e!="string"||!ho.test(e))&&p("MANIFEST_INVALID","resource hash is invalid"),e}function kn(e,n=new Set,t=0){if(typeof e=="string"){e.length>4096&&B("v2 manifest string is too long");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||p("MANIFEST_INVALID","v2 manifest contains a non-finite number");return}(e===void 0||typeof e=="function"||typeof e=="bigint")&&p("MANIFEST_INVALID","v2 manifest contains a non-JSON value"),typeof e!="object"&&p("MANIFEST_INVALID"),t>8&&B("v2 manifest nesting is too deep"),n.has(e)&&p("MANIFEST_INVALID","v2 manifest contains a cycle"),n.add(e);try{if(Array.isArray(e)){e.length>128&&B("v2 manifest array is too long");for(let i of e)kn(i,n,t+1);return}v(e)||p("MANIFEST_INVALID","v2 manifest contains a non-plain object");for(let i of Object.values(e))kn(i,n,t+1);}finally{n.delete(e);}}}function Lt(e){return (typeof e!="string"||e.length>4096||!ke.test(e))&&(typeof e=="string"&&e.length>4096&&B("projection path is too long"),p("MANIFEST_INVALID","projection paths must be canonical exact paths")),e.split(".").some(t=>Te(t))&&p("MANIFEST_INVALID","projection paths cannot address reserved state keys"),e}function Cn(e){v(e)||p("MANIFEST_INVALID","projection policy must be an object"),F(e,["allow"]),Array.isArray(e.allow)||p("MANIFEST_INVALID","projection allow must be an array"),e.allow.length>128&&B("projection allowlist is too long");let n=[],t=new Set;for(let i of e.allow){let o=Lt(i);t.has(o)&&p("MANIFEST_INVALID","projection allowlist contains a duplicate path"),t.add(o),n.push(o);}return {allow:n}}function Oo(e,n){if(e===void 0)return;Array.isArray(e)||p("MANIFEST_INVALID","dataPaths must be an array"),e.length>Do&&B("dataPaths exceed the v2 limit");let t=[],i=new Set;for(let o of e){let r=Lt(o);i.has(r)&&p("MANIFEST_INVALID","dataPaths contain a duplicate path"),n.some(a=>me(r,a))||p("MANIFEST_INVALID","dataPaths must be projection-allowed"),i.add(r),t.push(r);}return t}function Ne(e,n,t=Number.MAX_SAFE_INTEGER){return (!Number.isSafeInteger(e)||e<0||e>t)&&p("MANIFEST_INVALID",`${n} is invalid`),e}function ht(e,n){return (typeof e!="number"||!Number.isFinite(e))&&p("MANIFEST_INVALID",`${n} is invalid`),e}function wn(e,n=0,t=new Set){if(typeof e=="string")return (e.length>4096||en(e))&&p("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)||p("MANIFEST_INVALID","schema enum contains a non-finite number"),e;(n>8||typeof e!="object"||e===void 0)&&B("schema enum is too deep"),t.has(e)&&p("MANIFEST_INVALID","schema enum contains a cycle"),t.add(e);try{if(Array.isArray(e))return e.length>128&&B("schema enum array is too long"),e.map(o=>wn(o,n+1,t));v(e)||p("MANIFEST_INVALID","schema enum contains a non-plain object");let i={};for(let[o,r]of Object.entries(e))Te(o)&&p("MANIFEST_INVALID","schema enum contains a reserved key"),i[o]=wn(r,n+1,t);return i}finally{t.delete(e);}}function Uo(e,n){if(e===void 0)return;Array.isArray(e)||p("MANIFEST_INVALID","schema required must be an array"),e.length>64&&B("schema required list is too long");let t=[],i=new Set;for(let o of e)(typeof o!="string"||!ke.test(o))&&p("MANIFEST_INVALID","schema required contains an invalid key"),o.length>4096&&B("schema required key is too long"),i.has(o)&&p("MANIFEST_INVALID","schema required contains a duplicate key"),n&&!Object.prototype.hasOwnProperty.call(n,o)&&p("MANIFEST_INVALID","schema required references an undeclared property"),i.add(o),t.push(o);return t}function Ro(e,n){let t=n?ke:$e;return e.length>4096&&B("schema property name is too long"),(!t.test(e)||e.split(".").some(i=>Te(i)))&&p("MANIFEST_INVALID","schema property name is invalid"),e}function xn(e,n=0,t=false){v(e)||p("MANIFEST_INVALID","action inputSchema must be an object"),n>8&&B("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"&&p("SCHEMA_TYPE_UNSUPPORTED","action inputSchema type is unsupported"),p("MANIFEST_INVALID","action inputSchema type is required"));let o=["type","enum"];i==="string"&&o.push("minLength","maxLength"),i==="array"&&o.push("minItems","maxItems","items"),i==="object"&&o.push("minProperties","maxProperties","properties","required","additionalProperties"),(i==="number"||i==="integer")&&o.push("minimum","maximum"),F(e,["type"],o.filter(s=>s!=="type"));let r={type:i};if(O(e,"enum")&&(Array.isArray(e.enum)||p("MANIFEST_INVALID","schema enum must be an array"),e.enum.length>128&&B("schema enum is too long"),r.enum=e.enum.map(s=>wn(s))),i==="string"&&(O(e,"minLength")&&(r.minLength=Ne(e.minLength,"schema minLength",4096)),O(e,"maxLength")&&(r.maxLength=Ne(e.maxLength,"schema maxLength",4096)),r.minLength!==void 0&&r.maxLength!==void 0&&r.minLength>r.maxLength&&p("MANIFEST_INVALID","schema string length bounds are inverted")),(i==="number"||i==="integer")&&(O(e,"minimum")&&(r.minimum=ht(e.minimum,"schema minimum")),O(e,"maximum")&&(r.maximum=ht(e.maximum,"schema maximum")),r.minimum!==void 0&&r.maximum!==void 0&&r.minimum>r.maximum&&p("MANIFEST_INVALID","schema numeric bounds are inverted")),i==="array"&&(O(e,"minItems")&&(r.minItems=Ne(e.minItems,"schema minItems",128)),O(e,"maxItems")&&(r.maxItems=Ne(e.maxItems,"schema maxItems",128)),r.minItems!==void 0&&r.maxItems!==void 0&&r.minItems>r.maxItems&&p("MANIFEST_INVALID","schema array length bounds are inverted"),O(e,"items")&&(r.items=xn(e.items,n+1,false))),i==="object"){let s;if(O(e,"properties")){v(e.properties)||p("MANIFEST_INVALID","schema properties must be an object");let c=Object.entries(e.properties);c.length>64&&B("schema properties are too many"),s={};for(let[l,y]of c){let I=Ro(l,t);s[I]=xn(y,n+1,false);}r.properties=s;}O(e,"minProperties")&&(r.minProperties=Ne(e.minProperties,"schema minProperties",64)),O(e,"maxProperties")&&(r.maxProperties=Ne(e.maxProperties,"schema maxProperties",64)),r.minProperties!==void 0&&r.maxProperties!==void 0&&r.minProperties>r.maxProperties&&p("MANIFEST_INVALID","schema object property bounds are inverted");let d=Uo(e.required,s);d!==void 0&&(r.required=d),O(e,"additionalProperties")&&(e.additionalProperties!==false&&p("MANIFEST_INVALID","schema additionalProperties must be false"),r.additionalProperties=false);}let a=JSON.stringify(r);return (a===void 0||Buffer.byteLength(a,"utf8")>65536)&&B("action inputSchema subtree is too large"),r}function ko(e){let n=xn(e,0,true);return (n.type!=="object"||!n.properties)&&p("MANIFEST_INVALID","action inputSchema must declare object properties"),n}function Co(e){if(v(e)||p("MANIFEST_INVALID","action backend must be an object"),e.type==="core"){F(e,yo);let n=e.handler;return (typeof n!="string"||!En.test(n))&&p("MANIFEST_INVALID","core backend handler is invalid"),{type:"core",handler:n}}if(e.type==="skill"){F(e,Ao,Io),(!Array.isArray(e.command)||e.command.length===0||e.command.length>16)&&p("MANIFEST_INVALID","skill backend command is invalid");let n=[];for(let i of e.command)(typeof i!="string"||i.length===0||i.length>256||!Nn.test(i))&&p("MANIFEST_INVALID","skill backend command token is invalid"),n.push(i);let t=O(e,"env")?xo(e.env):void 0;return {type:"skill",command:n,...t===void 0?{}:{env:t}}}p("MANIFEST_INVALID","action backend type is unsupported");}function wo(e){v(e)||p("MANIFEST_INVALID","action must be an object"),F(e,lo,uo),O(e,"_meta")&&St(e._meta);let n=Rn(e.actionId,"actionId");Tn(n)&&p("MANIFEST_INVALID",`actionId "${n}" is not projection-safe`);let t=So(e.capability),i=e.mutation;typeof i!="boolean"&&p("MANIFEST_INVALID","action mutation must be boolean");let o=ko(e.inputSchema),r;if(O(e,"dataInputs")){Array.isArray(e.dataInputs)||p("MANIFEST_INVALID","action dataInputs must be an array");let l=o.properties,y=new Set,I=[];for(let D of e.dataInputs)(typeof D!="string"||!O(l,D)||y.has(D))&&p("MANIFEST_INVALID","action dataInputs must be unique declared properties"),y.add(D),I.push(D);r=I;}let a=Cn(e.resultProjection),s=Co(e.backend),d;O(e,"content")&&((s.type!=="skill"||!Ke(e.content))&&p("MANIFEST_INVALID","action content declaration is invalid"),d=vo(e.content));let c;if(O(e,"confirmation")){let l=e.confirmation;l!=="none"&&l!=="native"&&p("MANIFEST_INVALID","action confirmation is invalid"),c=l;}return {actionId:n,capability:t,mutation:i,inputSchema:o,resultProjection:a,backend:s,...d===void 0?{}:{content:d},...r===void 0?{}:{dataInputs:r},...c===void 0?{}:{confirmation:c}}}function xo(e){(!Array.isArray(e)||e.length===0)&&p("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))&&p("MANIFEST_INVALID","skill backend env is invalid"),n.add(i),t.push(i);return Object.freeze(t)}function vo(e){return Object.freeze({...e.in===void 0?{}:{in:Object.freeze({...e.in})},...e.out===void 0?{}:{out:Object.freeze({...e.out})}})}function jo(e){return v(e)||p("INITIAL_STATE_INVALID","initialState must be an object"),F(e,go,mo),e.path!=="ui/state.json"&&p("MANIFEST_INVALID","initialState path is not fixed"),O(e,"hash")?{path:"ui/state.json",hash:Mt(e.hash)}:{path:"ui/state.json"}}function Vo(e){let n=["wasm","terminal","htmlDocuments"];return (!v(e)||Object.keys(e).length===0||Object.keys(e).some(t=>!n.includes(t)||e[t]!==true))&&p("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 Fo(e,n){Ze(e,new Set,0,true,true),kn(e),v(e)||p("MANIFEST_INVALID"),F(e,co,po),O(e,"_meta")&&St(e._meta),e.manifestVersion!==2&&p("MANIFEST_INVALID");let t;O(e,"runtime")&&(t=Vo(e.runtime));let i=Rn(e.pluginId,"pluginId"),o=Rn(e.definitionId,"definitionId"),r=K(e,"version",1),a=mt(e.name,"name"),s=mt(e.description,"description"),d;O(e,"icon")&&((typeof e.icon!="string"||!/^[a-z][a-z0-9-]{0,63}$/.test(e.icon))&&p("MANIFEST_INVALID","icon is invalid"),d=e.icon);let c;O(e,"tone")&&((typeof e.tone!="string"||!bn.includes(e.tone))&&p("MANIFEST_INVALID","tone is invalid"),c=e.tone),e.entry!=="ui/index.html"&&p("MANIFEST_INVALID","entry path is not fixed");let l;O(e,"entryHash")&&(l=Mt(e.entryHash));let y;O(e,"initialState")&&(y=jo(e.initialState));let I;O(e,"usage")&&(e.usage!=="card"&&e.usage!=="window"&&p("MANIFEST_INVALID","usage is invalid"),I=e.usage);let D;O(e,"detailPanel")&&(typeof e.detailPanel!="boolean"&&p("MANIFEST_INVALID","detailPanel is invalid"),D=e.detailPanel);let h;if(O(e,"displayModes")){((I??Ce)!==Ce||!Array.isArray(e.displayModes)||e.displayModes.length===0)&&p("MANIFEST_INVALID","displayModes are only valid for window Apps");let b=new Set(["inline","floating","focused"]);(new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(u=>typeof u!="string"||!b.has(u)))&&p("MANIFEST_INVALID","displayModes are invalid"),h=e.displayModes;}(I??Ce)===Ce&&D!==void 0&&p("MANIFEST_INVALID","detailPanel is card-only");let E=n.mode??"local";E!=="local"&&E!=="installed"&&E!=="published"&&p("MANIFEST_INVALID","manifest mode is invalid"),E!=="local"&&l===void 0&&p("MANIFEST_INVALID","installed manifests require entryHash"),E!=="local"&&y!==void 0&&y.hash===void 0&&p("MANIFEST_INVALID","installed manifests require initialState.hash"),(!Array.isArray(e.surfaces)||e.surfaces.length===0)&&p("MANIFEST_INVALID","surfaces are invalid"),e.surfaces.length>2&&B("surfaces exceed the v2 limit");let S=[],j=new Set;for(let b of e.surfaces)(typeof b!="string"||!Pn.includes(b))&&p("MANIFEST_INVALID","surface is unsupported"),j.has(b)&&p("MANIFEST_INVALID","surfaces contain a duplicate"),j.add(b),S.push(b);v(e.size)||p("MANIFEST_INVALID","size must be an object"),F(e.size,["height"]);let R=K(e.size,"height",1);R>720&&B("size.height exceeds the v2 limit");let C=Cn(e.stateProjection),V=e.summaryProjection===void 0?void 0:Cn(e.summaryProjection);V!==void 0&&V.allow.some(b=>!C.allow.includes(b))&&p("MANIFEST_INVALID","summaryProjection must be a subset of stateProjection.allow");let g=Oo(e.dataPaths,C.allow);Array.isArray(e.actions)||p("MANIFEST_INVALID","actions must be an array"),e.actions.length>32&&B("actions exceed the v2 limit");let f=[],M=new Set;for(let b of e.actions){let u=wo(b);if(M.has(u.actionId)&&p("MANIFEST_INVALID","actions contain a duplicate actionId"),u.backend.type==="core"&&u.backend.handler==="state.set"){u.mutation||p("MANIFEST_INVALID","state.set actions must be mutations");for(let m of Object.keys(u.inputSchema.properties))C.allow.includes(m)||p("MANIFEST_INVALID","state.set input paths must be projection-allowed");}M.add(u.actionId),f.push(u);}return {manifestVersion:2,pluginId:i,definitionId:o,version:r,name:a,description:s,...d===void 0?{}:{icon:d},...c===void 0?{}:{tone:c},entry:"ui/index.html",...l===void 0?{}:{entryHash:l},...t===void 0?{}:{runtime:t},...y===void 0?{}:{initialState:y},...I===void 0?{}:{usage:I},...D===void 0?{}:{detailPanel:D},...h===void 0?{}:{displayModes:h},surfaces:S,size:{height:R},stateProjection:C,...V===void 0?{}:{summaryProjection:V},...g===void 0?{}:{dataPaths:g},actions:f}}function St(e){v(e)||p("MANIFEST_INVALID","_meta must be an object");let n=JSON.stringify(e);(n===void 0||Buffer.byteLength(n,"utf8")>fo)&&B("_meta exceeds the 4 KiB limit");}function Bo(e){let n={},t={};for(let r of e.actions){n[r.actionId]={capabilities:[r.capability],inputKeys:Object.keys(r.inputSchema.properties??{}),...r.dataInputs===void 0?{}:{dataInputs:r.dataInputs},resultProjection:r.resultProjection,...r.confirmation===void 0?{}:{confirmation:r.confirmation},...r.content===void 0?{}:{content:r.content},...r.backend.type!=="skill"||r.backend.env===void 0?{}:{env:r.backend.env}};let a=r.backend.type==="skill"||r.backend.type==="core"&&r.backend.handler==="state.set";t[r.actionId]={actionId:r.actionId,mutation:r.mutation,backend:r.backend,launchPolicy:a?"allowed":"denied",...a?{}:{denialCode:"EXEC_DENIED"}};}let i={id:e.definitionId,version:e.version,renderer:"sandbox-html",...e.usage===void 0?{}:{usage:e.usage},...e.detailPanel===void 0?{}:{detailPanel:e.detailPanel},...e.displayModes===void 0?{}:{displayModes:e.displayModes},surfaces:e.surfaces,stateProjection:e.stateProjection,...e.summaryProjection===void 0?{}:{summaryProjection:e.summaryProjection},...e.dataPaths===void 0?{}:{dataPaths:e.dataPaths},actions:n},o={entry:{path:"ui/index.html",...e.entryHash===void 0?{}:{hash:e.entryHash}},...e.initialState===void 0?{}:{initialState:e.initialState}};return {manifest:e,definition:i,handlers:t,resources:o}}function vn(e,n,t,i,o,r){if(typeof e=="string"){let a=o.length>0&&r.some(s=>me(o.join("."),s));return (e.length>4096||en(e,false,false,a))&&X("state contains an unsafe string"),e}if(e===null||typeof e=="boolean")return e;if(typeof e=="number")return Number.isFinite(e)||X("state contains a non-finite number"),e;(e===void 0||typeof e!="object"||typeof e=="function"||typeof e=="bigint")&&X("state contains a non-JSON value"),t>8&&X("state is too deep"),n.has(e)&&X("state contains a cycle"),n.add(e);try{let a;if(Array.isArray(e))e.length>128&&X("state array is too long"),a=e.map(d=>vn(d,n,t+1,65536,o,r));else {v(e)||X("state contains a non-plain object");let d={};for(let[c,l]of Object.entries(e))(c.length>4096||!$e.test(c)||Te(c))&&(c.length>4096&&X("state key is too long"),X("state contains a reserved or invalid key")),d[c]=vn(l,n,t+1,65536,[...o,c],r);a=d;}let s=JSON.stringify(a);return (s===void 0||Buffer.byteLength(s,"utf8")>i)&&X("state subtree is too large"),a}finally{n.delete(e);}}function Vn(e,n=[]){v(e)||X("initial state must be a JSON object");let t=vn(e,new Set,0,65536,[],n);return (t===null||Array.isArray(t)||typeof t!="object")&&X(),t}function Ho(e,n={}){Ze(e),v(e)||p("MANIFEST_INVALID"),F(e,so),e.manifestVersion!==1&&p("MANIFEST_INVALID");let t=Un(ne(e,"pluginId")),i=Un(ne(e,"definitionId")),o=K(e,"version",1),r=K(e,"primitiveSet",1),a=n.supportedPrimitiveSet??qi;(!Number.isSafeInteger(a)||a<1)&&p("MANIFEST_INVALID"),r>a&&p("PRIMITIVE_SET_UNSUPPORTED"),v(e.activation)||p("MANIFEST_INVALID"),F(e.activation,["kind","language"]),e.activation.kind!=="fenced-code"&&p("MANIFEST_INVALID");let s=Un(ne(e.activation,"language")),d=bo(e.schema),c=Lo(e.layout,d);return {manifestVersion:1,pluginId:t,definitionId:i,version:o,primitiveSet:r,activation:{kind:"fenced-code",language:s},schema:d,layout:c}}function zo(e,n={}){return v(e)||p("MANIFEST_INVALID"),Object.hasOwn(e,"lineage")&&p("MANIFEST_INVALID","lineage is only allowed in product bundle indexes"),e.manifestVersion===2?Fo(e,n):Ho(e,n)}function nn(e,n={}){try{return zo(e,n)}catch(t){if(t instanceof Y)throw t;return p("MANIFEST_INVALID")}}function Fn(e,n={}){let t=nn(e,n);return t.manifestVersion===2?Bo(t):t}var qi,Zi,Qi,Pt,eo,no,to,io,gt,oo,ro,ao,so,co,po,lo,uo,fo,yo,Ao,Io,go,mo,ho,To,_o,Do,Eo,Y,Ot=k(()=>{_();It();le();Sn();_e();qi=1,Zi=/^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$/,Qi=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,Pt=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,eo=/<\/?[A-Za-z][^>]*>/,no=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,to=/^(?:https?|file|ftp|ws|wss):\/\//i,io=/^\s*(?:javascript|data):/i,gt=/data:[^,\s]*,/i,oo=/(?:https?|file|ftp|ws|wss):\/\//i,ro=/javascript:/i,ao=/(?:^[\s]*|[\s"'(=])(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)(?=[^\s"'<>])[^\s"'<>]*/,so=["manifestVersion","pluginId","definitionId","version","primitiveSet","activation","schema","layout"],co=["manifestVersion","pluginId","definitionId","version","name","description","entry","surfaces","size","stateProjection","actions"],po=["_meta","icon","tone","entryHash","runtime","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths"],lo=["actionId","capability","mutation","inputSchema","resultProjection","backend"],uo=["confirmation","dataInputs","content","_meta"],fo=4*1024,yo=["type","handler"],Ao=["type","command"],Io=["env"],go=["path"],mo=["hash"],ho=/^[0-9a-f]{64}$/,To=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/,_o=/[\r\n]/,Do=16,Eo=["card-shell","meta-banner","heading","labeled-text","step-flow","text-list"],Y=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="UiPluginValidationError"};});var Ut=k(()=>{_();At();Ot();_e();});function on(e,n=e){throw new se(e,n)}var se,rn=k(()=>{_();se=class extends Error{constructor(t,i=t){super(i);this.code=t;}code;name="McpAppContractError"};});var Rt=k(()=>{_();});var kt=k(()=>{_();De();le();rn();Rt();});function Ct(e,n){return Go.add(e),n!==void 0&&Jo.set(e,n),e}var Go,Jo,an=k(()=>{_();Go=new WeakSet,Jo=new WeakMap;});function je(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Bn(e,n,t=[]){let i=new Set([...n,...t]),o=Object.keys(e);return n.every(r=>Object.hasOwn(e,r))&&o.every(r=>i.has(r))}function vt(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))vt(n);return Object.freeze(e)}function z(e){throw new te("LINEAGE_INVALID",e)}function Zo(e){throw new te("LINEAGE_STALE",e)}function jt(e){if(!je(e)||!Bn(e,$o,Ko)||!je(e.actions))return z("Lineage definition shape is invalid");for(let n of Object.values(e.actions))if(!je(n)||!Bn(n,Yo,qo))return z("Lineage action definition shape is invalid");return e}function Qo(e){if(!je(e)||!Bn(e,Wo,Xo))return z("Lineage entry shape is invalid");if(!Number.isSafeInteger(e.version)||e.version<1||typeof e.hash!="string"||!wt.test(e.hash))return z("Lineage entry identity is invalid");if(e.sourceHash!==void 0&&(typeof e.sourceHash!="string"||!wt.test(e.sourceHash)))return z("Lineage source hash is invalid");if(e.compat!==void 0&&e.compat!=="break")return z("Lineage compatibility marker is invalid");let n=jt(e.definition);if(n.version!==e.version)return z("Lineage version does not match its definition");if(e.sourceHash!==void 0&&n.sourceHash!==e.sourceHash)return z("Lineage source hash does not match its definition");let t;try{t=re(n),ae({...n,hash:e.hash});}catch{return z("Lineage definition is invalid")}return t!==e.hash?z("Lineage definition hash does not match"):vt({version:e.version,hash:e.hash,definition:n,...e.sourceHash===void 0?{}:{sourceHash:e.sourceHash},...e.compat===void 0?{}:{compat:e.compat}})}function xt(e){return e.stateProjection?.allow??[]}function er(e,n){let t=[],i=new Set(xt(n));xt(e).some(s=>!i.has(s))&&t.push("S1_STATE_PROJECTION");let o=new Set(n.dataPaths??[]);(e.dataPaths??[]).some(s=>!o.has(s))&&t.push("S2_DATA_PATHS");for(let[s,d]of Object.entries(e.actions)){let c=n.actions[s];if(c&&(d.confirmation??"native")==="native"&&(c.confirmation??"native")!=="native"){t.push("S3_ACTION_CONFIRMATION");break}}Object.keys(e.legacy?.agentAccess??{}).some(s=>!Object.hasOwn(n.actions,s))&&t.push("S4_LEGACY_AGENT_ACTIONS");let a=e.summaryProjection?.allow;if(a!==void 0){let s=new Set(n.summaryProjection?.allow??[]);a.some(d=>!s.has(d))&&t.push("S5_SUMMARY_PROJECTION");}return t}function nr(e,n){return $(e)===$(n)}function Hn(e,n){if(!Array.isArray(e)||e.length===0)return z("Definition lineage is missing");if(!je(n)||typeof n.hash!="string")return z("Current definition is invalid");let t,i;try{let{hash:s,...d}=n;i=jt(d),t={...i,hash:s},ae(t);}catch{return z("Current definition is invalid")}let o=e.map(Qo),r=o[0].definition.id;if(o.some(s=>s.definition.id!==r))return z("Lineage definition ids do not match");if(o.some((s,d)=>d>0&&s.version<=o[d-1].version))return z("Lineage generations are not in increasing version order");if(o.some((s,d)=>o.findIndex(c=>c.hash===s.hash)!==d))return z("Lineage contains a duplicate hash");let a=o[o.length-1];if(a.version!==t.version||a.hash!==t.hash||a.definition.id!==t.id||!nr(a.definition,i))return Zo("The last lineage generation does not match the current package");if(t.legacy!==void 0){let s=new Set(Object.keys(t.actions)),d=new Set;for(let l of o)if(l.sourceHash===void 0)for(let y of Object.keys(l.definition.actions))s.has(y)&&d.add(y);let c=Object.keys(t.legacy.agentAccess??{});if(c.length!==d.size||c.some(l=>!d.has(l))){let l="S4_LEGACY_AGENT_ACCESS_COMPLETE";throw new te("LINEAGE_INVALID",`Lineage compatibility failed: ${l}`,[l])}}for(let s=0;s<o.length-1;s+=1){if(o.slice(s,-1).some(l=>l.compat==="break"))continue;let c=er(o[s].definition,t);if(c.length>0)throw new te("LINEAGE_INVALID",`Lineage compatibility failed: ${c.join(", ")}`,c)}return Object.freeze({entries:Object.freeze(o),current:t})}var te,wt,Wo,Xo,$o,Ko,Yo,qo,zn=k(()=>{_();De();le();te=class extends Error{constructor(t,i=t,o=[]){super(i);this.code=t;this.violations=o;}code;violations;name="UiDefinitionLineageError"},wt=/^[0-9a-f]{64}$/,Wo=["version","hash","definition"],Xo=["sourceHash","compat"],$o=["id","version","actions"],Ko=["sourceHash","usage","detailPanel","displayModes","renderer","surfaces","stateProjection","dataPaths","summaryProjection","legacy"],Yo=["capabilities"],qo=["inputKeys","dataInputs","confirmation","resultProjection","content","env"];});var Vt,Ft,Bt=k(()=>{_();Vt=["crewx_app_terminal_connect","crewx_app_html_viewer_open"],Ft=["crewx_listWorkspaces","crewx_queryAgent","crewx_executeAgent","crewx_getTaskResult","crewx_listTasks","crewx_listAgents","callBrowser","openTab","listTabs","closeTab"];});var Ht=k(()=>{_();De();an();});function Gn(e,n=0){try{let t=ie(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 se)throw t;on("TOOL_INVALID","MCP App inputSchema must be projection-safe JSON");}}function zt(e){if(e.length===0)return Gn({type:"object",properties:{},additionalProperties:false});let n=e.map(i=>i.actionId),t=new Map;for(let i of e)t.set(i.actionId,Gn(i.inputSchema));return Gn(or(n,t),ir)}function or(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 Ve,ir,Jn=k(()=>{_();kt();De();le();an();rn();zn();Bt();Ht();Ve=8*1024*1024,new Set(Vt),new Set(Ft),ir=4;});function Gt(){return Object.freeze({[Wn]:{candidates:new Map,assetCatalogs:new Map}})}function rr(e){if(e===null||typeof e!="object"||!(Wn in e))throw new TypeError("scanCache must be created by createWorkspaceAppScanCache");return e[Wn]}function Jt(e,n){let t=rr(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 Wn,Wt=k(()=>{_();Wn=Symbol("crewx.workspace-app-scan-cache.state");});function J(e){let n=typeof e=="object"&&e!==null&&"code"in e?String(e.code):"";return n==="ENOENT"?new A("NOT_FOUND"):n==="ELOOP"?new A("PATH_ESCAPED"):n==="EFBIG"||n==="EOVERFLOW"?new A("LIMIT_EXCEEDED"):n==="EACCES"||n==="EPERM"||n==="ENOTDIR"?new A("READ_DENIED"):new A("READ_DENIED")}function dr(e){if(typeof e!="string"||e.length===0||!isAbsolute(e))throw new A("READ_DENIED")}function Xn(e){if(typeof e!="string"||isAbsolute(e)||/[\\\u0000]/.test(e))throw new A("PATH_ESCAPED");if(e==="")return [];let n=e.split("/");if(n.some(t=>t.length===0||t==="."||t===".."))throw new A("PATH_ESCAPED");return n}function pn(e,n){let t=relative(e,n);return t===""||t!==".."&&!t.startsWith(`..${sep}`)&&!isAbsolute(t)}function Me(e){return {dev:e.dev,ino:e.ino,size:e.size,mtimeNs:e.mtimeNs,ctimeNs:e.ctimeNs}}function qn(e,n){return e.dev===n.dev&&e.ino===n.ino}function Zn(e,n){return qn(e,n)&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}async function sn(e){dr(e);let n,t;try{n=await realpath(e),t=await stat(n,{bigint:!0});}catch(i){throw J(i)}if(!t.isDirectory())throw new A("READ_DENIED");return {realRoot:n,identity:Me(t)}}async function Kt(e,n,t){if(t.length<2||t[0]!=="apps"&&t[0]!=="skills")return;let i,o;try{if(i=resolve(e,t[0],t[1]),o=await realpath(i),!(await stat(o,{bigint:!0})).isDirectory())throw new A("READ_DENIED")}catch(r){throw r instanceof A?r:J(r)}if(!pn(n,o))throw new A("PATH_ESCAPED");return o}async function cn(e,n,t,i){let o,r,a;try{o=await lstat(e,{bigint:!0}),r=await realpath(e),a=await stat(r,{bigint:!0});}catch(s){throw J(s)}if(!pn(n,r)||t!==void 0&&!pn(t,r))throw new A("PATH_ESCAPED");if(!o.isFile()||!a.isFile())throw new A("READ_DENIED");if(!qn(i,o)||!qn(i,a)||i.dev!==a.dev)throw new A("PATH_ESCAPED")}async function Pe(e,n){let t,i;try{t=await realpath(e),i=await stat(t,{bigint:!0});}catch{throw new A("PATH_ESCAPED")}if(t!==n.realRoot||!Zn(n.identity,Me(i)))throw new A("PATH_ESCAPED")}function pr(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 A,Yn,cr,$t,Le,ln,Yt,qt,et=k(()=>{_();A=class extends Error{constructor(t){super(t);this.code=t;}code;name="AppDiscoveryFsError"},Yn=constants.O_NOFOLLOW,cr=constants.O_NONBLOCK,$t=constants.O_RDONLY|(Yn??0)|(cr??0);Le=class{async getRootIdentity(n){let t=await sn(n);return await Pe(n,t),{dev:t.identity.dev,ino:t.identity.ino,realPath:t.realRoot}}async listDirectory(n,t){let i=Xn(t),o=await sn(n),r=resolve(n,...i),a,s;try{a=await realpath(r),s=await stat(a,{bigint:!0});}catch(d){let c=J(d);if(c.code==="NOT_FOUND")return [];throw c}if(!pn(o.realRoot,a)||!s.isDirectory())throw new A("PATH_ESCAPED");try{let d=await readdir(a,{withFileTypes:!0,encoding:"utf8"});return await Pe(n,o),d.map(pr)}catch(d){let c=J(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 A("READ_DENIED");if(Yn===void 0)throw new A("UNSUPPORTED");let o=Xn(t),r=await sn(n),a=resolve(n,...o),s=relative(n,a);if(s===".."||s.startsWith(`..${sep}`)||isAbsolute(s))throw new A("PATH_ESCAPED");let d;try{d=await open(a,$t);}catch(c){throw J(c)}try{let c;try{let h=await d.stat({bigint:!0});c=Me(h);}catch(h){throw J(h)}if(c.size>BigInt(i))throw new A("LIMIT_EXCEEDED");if(c.size>BigInt(Number.MAX_SAFE_INTEGER))throw new A("LIMIT_EXCEEDED");await Pe(n,r);let l=await Kt(n,r.realRoot,o);await cn(a,r.realRoot,l,c);let y=new Uint8Array(new ArrayBuffer(Number(c.size))),I=0;for(;I<y.byteLength;){let h;try{h=(await d.read(y,I,y.byteLength-I,I)).bytesRead;}catch(E){throw J(E)}if(h<=0)throw new A("IDENTITY_CHANGED");I+=h;}let D;try{let h=await d.stat({bigint:!0});D=Me(h);}catch(h){throw J(h)}if(!Zn(c,D))throw new A("IDENTITY_CHANGED");return await cn(a,r.realRoot,l,D),await Pe(n,r),new Uint8Array(y)}finally{await d.close().catch(()=>{});}}async fingerprintVerifiedFile(n,t,i){if(!Number.isSafeInteger(i)||i<0)throw new A("READ_DENIED");if(Yn===void 0)throw new A("UNSUPPORTED");let o=Xn(t),r=await sn(n),a=resolve(n,...o),s=relative(n,a);if(s===".."||s.startsWith(`..${sep}`)||isAbsolute(s))throw new A("PATH_ESCAPED");let d;try{d=await open(a,$t);}catch(c){throw J(c)}try{let c;try{let I=await d.stat({bigint:!0});c=Me(I);}catch(I){throw J(I)}if(c.size>BigInt(i)||c.size>BigInt(Number.MAX_SAFE_INTEGER))throw new A("LIMIT_EXCEEDED");await Pe(n,r);let l=await Kt(n,r.realRoot,o);await cn(a,r.realRoot,l,c);let y;try{let I=await d.stat({bigint:!0});y=Me(I);}catch(I){throw J(I)}if(!Zn(c,y))throw new A("IDENTITY_CHANGED");return await cn(a,r.realRoot,l,y),await Pe(n,r),{...y,candidateRealPath:l??r.realRoot}}catch(c){throw c instanceof A?c:J(c)}finally{await d.close().catch(()=>{});}}async readFileVerified(n,t,i){return this.readVerifiedFile(n,t,i)}},ln=new Le,Yt=ln,qt=Le;});function ze(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 Qt(e){return typeof e=="string"&&oe.test(e)?e:void 0}function gr(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function Ie(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),o=Math.min(t.byteLength,i.byteLength);for(let r=0;r<o;r+=1){let a=t[r]-i[r];if(a!==0)return a}return t.byteLength-i.byteLength}function mr(e){if(typeof e=="string")return {name:e,kind:"directory"};if(e===null||typeof e!="object")return null;let n=e;if(typeof n.name!="string")return null;if(n.kind==="file"||n.kind==="directory"||n.kind==="symlink"||n.kind==="other")return {name:n.name,kind:n.kind};if(n.type==="file"||n.type==="directory"||n.type==="symlink"||n.type==="other")return {name:n.name,kind:n.type};let t=n.isDirectory;if(typeof t=="function"&&t.call(e))return {name:n.name,kind:"directory"};let i=n.isSymbolicLink;if(typeof i=="function"&&i.call(e))return {name:n.name,kind:"symlink"};let o=n.isFile;return typeof o=="function"&&o.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function hr(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 Tr(e){return Ar.decode(e)}function _r(e){return JSON.parse(Tr(e))}function ei(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 Dr(e){if(e instanceof A)return ei(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return ei(n)}}function ce(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function Er(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function Nr(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 ni(e,n,t,i){let o=Er(e);if(!o)throw new A("READ_DENIED");return hr(await o.call(e,n,t,i))}async function it(e,n,t){let i=Nr(e);if(!i)throw new A("READ_DENIED");let o=await i.call(e,n,t);if(!Array.isArray(o))throw new A("READ_DENIED");return o.map(mr).filter(r=>r!==null)}function br(e,n,t,i){return Object.freeze({code:e,...{},source:n,relativePath:t})}function Pr(e){if(!ze(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,o)=>{if(!Array.isArray(i))throw new TypeError("productBundle.reservedIds."+o+" must be an array");let r=[];for(let a=0;a<i.length;a+=1){let s=i[a];if(typeof s!="string"||s.length===0)throw new TypeError("productBundle.reservedIds."+o+" must contain non-empty strings");r.push(s);}return Object.freeze([...new Set(r)].sort(Ie))};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 Mr(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 Ge(e){return Object.freeze({appIds:Object.freeze([...new Set(e.map(n=>n.appId))].sort(Ie)),definitionIds:Object.freeze([...new Set(e.map(n=>n.definition.id))].sort(Ie))})}function un(e,n){let t=Object.keys(e).sort(Ie),i=[...n].sort(Ie);return t.length===i.length&&t.every((o,r)=>o===i[r])}function ti(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 Lr(e){let n;try{n=_r(e);}catch{return}if(!ze(n)||!un(n,["version","packages"])||n.version!==1||!Array.isArray(n.packages)||n.packages.length>ot)return;let t=new Set,i=new Set,o=0,r=[];for(let a of n.packages){if(!ze(a))return;let s=["packageDir","appId","definition","files"],d=Object.hasOwn(a,"lineage"),c=Object.hasOwn(a,"launcher"),l=[...d?["lineage"]:[],...c?["launcher"]:[]];if(!un(a,[...s,...l])||c&&a.launcher!==false)return;let y=ti(a.packageDir),I=Qt(a.appId);if(!y||y.length!==2||y[0]!=="apps"||!gr(y[1])||!I||t.has(a.packageDir)||!ze(a.definition)||!un(a.definition,["id","version","hash"]))return;let D=Qt(a.definition.id),h=a.definition.version,E=a.definition.hash;if(!D||!Number.isSafeInteger(h)||h<1||typeof E!="string"||!tt.test(E)||!Array.isArray(a.files)||a.files.length<2||a.files.length>rt)return;let S=new Set,j=[];for(let R of a.files){if(!ze(R)||!un(R,["path","sha256"]))return;let C=ti(R.path);if(!C||typeof R.sha256!="string"||!tt.test(R.sha256))return;let V=C.join("/"),g=`${a.packageDir}/${V}`;if(S.has(V)||i.has(g))return;S.add(V),i.add(g),j.push(Object.freeze({path:V,sha256:R.sha256}));}if(!S.has("ui-plugin.json")||!S.has("ui/index.html")||(o+=j.length,o>ur))return;t.add(a.packageDir),r.push(Object.freeze({packageDir:a.packageDir,...c?{launcher:false}:{},appId:I,definition:Object.freeze({id:D,version:h,hash:E}),lineage:Array.isArray(a.lineage)?a.lineage:[],files:Object.freeze(j.sort((R,C)=>Ie(R.path,C.path)))}));}return Object.freeze({version:1,packages:Object.freeze(r)})}function Ae(e){let n=Dr(e);return n==="PATH_ESCAPED"||n==="IDENTITY_CHANGED"||n==="TOCTOU"?"PATH_ESCAPED":n==="LIMIT_EXCEEDED"?"LIMIT_EXCEEDED":"BUNDLE_INTEGRITY"}async function Sr(e,n,t,i,o){let r=[],a=async(s,d)=>{if(!ce(i,o))throw new A("LIMIT_EXCEEDED");if(d>2)throw new A("LIMIT_EXCEEDED");let c=await it(e,n,s);for(let l of c){if(typeof l.name!="string"||l.name.length===0||l.name==="."||l.name===".."||/[\\/\u0000]/.test(l.name))throw new A("PATH_ESCAPED");let y=`${s}/${l.name}`;if(l.kind==="file"){if(r.push(y.slice(t.length+1)),r.length>rt)throw new A("LIMIT_EXCEEDED")}else if(l.kind==="directory")await a(y,d+1);else throw l.kind==="symlink"?new A("PATH_ESCAPED"):new A("READ_DENIED")}};return await a(t,0),r.sort(Ie)}function Or(e){return e==="ui-plugin.json"?262144:e==="ui/index.html"?Ve:e==="ui/state.json"?65536:e.startsWith("ui/assets/")?yr:fr}async function ii(e,n,t,i){if(e===void 0)return {packages:[],diagnostics:[],incomplete:false,reservedIds:Ir};let o=Pr(e.reservedIds),r=[],a=(u,m,N)=>br(u,"bundled",m),s=(u=[],m=false,N)=>({...N===void 0?{}:{indexHash:N},packages:u,diagnostics:r,incomplete:m,reservedIds:o});if(typeof e.root!="string"||e.root.length===0||typeof e.expectedIndexHash!="string"||!tt.test(e.expectedIndexHash))return r.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s();let d;try{d=await ni(n,e.root,"bundle-index.json",lr);}catch(u){return r.push(a(Ae(u),"bundle-index.json")),s()}let c=createHash("sha256").update(d).digest("hex");if(c!==e.expectedIndexHash)return r.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s();let l=Lr(d);if(l===void 0)return r.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s();if(!Mr(Ge(l.packages),o))return r.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s([],false,c);if(!ce(t,i))return r.push(a("LIMIT_EXCEEDED","bundle-index.json")),s(l.packages.map(u=>({indexEntry:u,failureCode:"LIMIT_EXCEEDED"})),true,c);let y;try{y=await it(n,e.root,"");}catch(u){return r.push(a(Ae(u),"bundle-index.json")),s(l.packages.map(m=>({indexEntry:m,failureCode:Ae(u)})),false,c)}if(!ce(t,i))return r.push(a("LIMIT_EXCEEDED","bundle-index.json")),s(l.packages.map(u=>({indexEntry:u,failureCode:"LIMIT_EXCEEDED"})),true,c);let I=y.find(u=>u.name==="bundle-index.json"&&u.kind==="file"),D=y.find(u=>u.name==="apps"&&u.kind==="directory"),h=u=>l.packages.map(m=>({indexEntry:m,failureCode:u}));if(!I)return r.push(a("BUNDLE_INTEGRITY","bundle-index.json")),s(h("BUNDLE_INTEGRITY"),false,c);let E=y.filter(u=>u.name!=="bundle-index.json"&&u.name!=="apps");if(E.length>0){let u=E.some(m=>m.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return r.push(a(u,"bundle-index.json")),s(h("BUNDLE_INTEGRITY"),false,c)}if(y.some(u=>u.name==="apps"&&u.kind!=="directory"))return r.push(a("PATH_ESCAPED","apps")),s(h("PATH_ESCAPED"),false,c);let S=[];if(D)try{S=await it(n,e.root,"apps");}catch(u){return r.push(a(Ae(u),"apps")),s(h(Ae(u)),false,c)}if(!ce(t,i)||S.length>ot)return r.push(a("LIMIT_EXCEEDED","apps")),s(h("LIMIT_EXCEEDED"),true,c);let j=new Map(l.packages.map(u=>[u.packageDir.slice(5),u])),R=S.filter(u=>!j.has(u.name));for(let u of R)r.push(a(u.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY",`apps/${u.name}`));if(R.length>0){let u=R.some(m=>m.kind==="symlink")?"PATH_ESCAPED":"BUNDLE_INTEGRITY";return s(h(u),false,c)}let C=new Set,V=new Map,g=new Map;for(let u of l.packages){let m=V.get(u.appId)??[];m.push(u),V.set(u.appId,m);let N=`${u.definition.id}\0${String(u.definition.version)}`,T=g.get(N)??[];T.push(u),g.set(N,T);}for(let u of [...V.values(),...g.values()])if(u.length>1)for(let m of u)C.add(m);let f=[],M=d.byteLength,b=false;for(let u of l.packages){if(!ce(t,i)){b=true,f.push({indexEntry:u,failureCode:"LIMIT_EXCEEDED"});continue}let m;try{let U=u.lineage[u.lineage.length-1];if(!U)throw new te("LINEAGE_INVALID","Definition lineage is missing");if(U.definition.id!==u.definition.id||U.version!==u.definition.version||U.hash!==u.definition.hash)throw new te("LINEAGE_STALE","Last lineage generation does not match bundle identity");m=Hn(u.lineage,{...U.definition,hash:U.hash}).entries;}catch(U){let Q=U instanceof te?U.code:"LINEAGE_INVALID";r.push(a(Q,u.packageDir)),f.push({indexEntry:u,failureCode:Q});continue}let N=S.find(U=>U.name===u.packageDir.slice(5));if(!D||!N){f.push({indexEntry:u,failureCode:"BUNDLE_INTEGRITY"});continue}if(N.kind!=="directory"){f.push({indexEntry:u,failureCode:N.kind==="symlink"?"PATH_ESCAPED":"BUNDLE_INTEGRITY"});continue}let T;try{let U=await Sr(n,e.root,u.packageDir,t,i);if(!ce(t,i)){b=!0,f.push({indexEntry:u,failureCode:"LIMIT_EXCEEDED"});continue}let Q=u.files.map(ee=>ee.path);if(U.length!==Q.length||U.some((ee,ue)=>ee!==Q[ue])){f.push({indexEntry:u,failureCode:"BUNDLE_INTEGRITY"});continue}T=new Map;let H;for(let ee of u.files){if(!ce(t,i)){H="LIMIT_EXCEEDED",b=!0;break}if(M>=nt){H="LIMIT_EXCEEDED";break}let ue;try{ue=await ni(n,e.root,`${u.packageDir}/${ee.path}`,Or(ee.path));}catch(Oi){H=Ae(Oi);break}if(!ce(t,i)){H="LIMIT_EXCEEDED",b=!0;break}if(M+ue.byteLength>nt){M=nt,H="LIMIT_EXCEEDED";break}if(M+=ue.byteLength,createHash("sha256").update(ue).digest("hex")!==ee.sha256){H="BUNDLE_INTEGRITY";break}T.set(ee.path,ue);}if(H!==void 0){f.push({indexEntry:u,failureCode:H});continue}}catch(U){ce(t,i)||(b=true),f.push({indexEntry:u,failureCode:Ae(U)});continue}f.push({indexEntry:u,lineage:m,files:T,...C.has(u)?{failureCode:"DUPLICATE_ID"}:{}});}return s(f,b,c)}var lr,ot,rt,ur,fr,yr,nt,tt,Ar,Ir,at=k(()=>{_();zn();_e();Jn();et();lr=256*1024,ot=64,rt=128,ur=ot*rt,fr=2*1024*1024,yr=8*1024*1024,nt=32*1024*1024,tt=/^[0-9a-f]{64}$/,Ar=new TextDecoder("utf-8",{fatal:true}),Ir=Object.freeze({appIds:Object.freeze([]),definitionIds:Object.freeze([])});});var Ei={};Ri(Ei,{AppDiscoveryFsError:()=>A,LOCAL_APP_TOOL_PREFIX:()=>kr,MCP_APP_WORKSPACE_TOOL_PREFIX:()=>Cr,NodeAppDiscoveryFs:()=>Le,NodeAppDiscoveryFsAdapter:()=>qt,WORKSPACE_APP_TOOL_PREFIX:()=>Oe,createWorkspaceAppScanCache:()=>Gt,defaultAppDiscoveryFs:()=>ln,defaultNodeAppDiscoveryFs:()=>Yt,deriveWorkspaceAppToolName:()=>wr,deriveWorkspaceAppToolNames:()=>dt,discoverWorkspaceAppCandidates:()=>sa,discoverWorkspaceApps:()=>pt,isWorkspacePackage:()=>Rr,productAppBundleReservations:()=>Ge,scanWorkspaceApps:()=>ca});function Rr(e,n){let t=n.split("/");return t.length===2&&t[0]===e&&/^[A-Za-z][A-Za-z0-9._-]{0,127}$/.test(t[1])}function dt(e){if(typeof e!="string"||!oe.test(e))throw new TypeError("pluginId must be a safe UI plugin identifier");let n=`${Oe}${e}`.length+7<=128?e:`hash_${createHash("sha256").update(e,"utf8").digest("hex")}`;return {read:`${Oe}${n}_read`,action:`${Oe}${n}_action`}}function wr(e,n="read"){let t=dt(e);return n==="read"?t.read:t.action}function Je(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 ri(e){return typeof e=="string"&&oe.test(e)?e:void 0}function vr(e,n){return n.length===0||n==="."||n===".."||/[\\/\u0000]/.test(n)?e==="skills"?"skills":"apps":`${e==="skills"?"skills":"apps"}/${n}`}function jr(e){return e.length>0&&e!=="."&&e!==".."&&!/[\\/\u0000]/.test(e)}function We(e,n){let t=new TextEncoder().encode(e),i=new TextEncoder().encode(n),o=Math.min(t.byteLength,i.byteLength);for(let r=0;r<o;r+=1){let a=t[r]-i[r];if(a!==0)return a}return t.byteLength-i.byteLength}function Ai(e){if(typeof e=="string")return {name:e,kind:"directory"};if(e===null||typeof e!="object")return null;let n=e;if(typeof n.name!="string")return null;if(n.kind==="file"||n.kind==="directory"||n.kind==="symlink"||n.kind==="other")return {name:n.name,kind:n.kind};if(n.type==="file"||n.type==="directory"||n.type==="symlink"||n.type==="other")return {name:n.name,kind:n.type};let t=n.isDirectory;if(typeof t=="function"&&t.call(e))return {name:n.name,kind:"directory"};let i=n.isSymbolicLink;if(typeof i=="function"&&i.call(e))return {name:n.name,kind:"symlink"};let o=n.isFile;return typeof o=="function"&&o.call(e)?{name:n.name,kind:"file"}:{name:n.name,kind:"other"}}function Vr(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 Ii(e){return xr.decode(e)}function gi(e){return JSON.parse(Ii(e))}function Fr(e){if(!Je(e))return;let n=ri(e.pluginId);if(!n)return;let t=ri(e.definitionId),i=e.version,o=t&&Number.isSafeInteger(i)&&i>=1?`${t}\0${String(i)}`:void 0;return {pluginId:n,...o===void 0?{}:{definitionKey:o}}}function Br(e){let n=gi(e);return {value:n,identity:Fr(n)}}function yn(e,n,t,i){let o={code:e,...i===void 0?{}:{pluginId:i},source:n,relativePath:t};return Object.freeze(o)}function ai(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 q(e){if(e instanceof A)return ai(e.code);if(e!==null&&typeof e=="object"&&"code"in e){let n=e.code;if(typeof n=="string")return ai(n)}}function Ue(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 si(e){switch(e.code){case "MANIFEST_INVALID":case "PRIMITIVE_UNKNOWN":case "PRIMITIVE_SET_UNSUPPORTED":case "SCHEMA_TYPE_UNSUPPORTED":case "TOKEN_INVALID":case "UNSAFE_VALUE":return "MANIFEST_INVALID";case "LIMIT_EXCEEDED":return "LIMIT_EXCEEDED";case "INITIAL_STATE_INVALID":return "INITIAL_STATE_INVALID";default:return mi("UiPluginValidationError",e.code)}}function mi(e,n){throw new Error(`Unmapped ${e} code: ${String(n)}`)}function st(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 mi("McpAppContractError",e)}}function de(e,n){let t=n();return Number.isFinite(t)&&Number.isFinite(e)&&t-e<=5e3}function Hr(e){return {pluginId:e.appId,definitionKey:`${e.definition.id}\0${String(e.definition.version)}`}}function zr(e,n){let t=n.get("package.json");if(t!==void 0)try{let o=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(t));if(Je(o)){let r=o.bin,a=typeof r=="string"?r:Je(r)?Object.values(r).find(s=>typeof s=="string"):void 0;for(let s of [a,o.main]){if(typeof s!="string")continue;let d=Gr(s);if(d&&n.has(d))return d}}}catch{}return [`${e.slice(e.lastIndexOf("/")+1)}.js`,"index.js","main.js"].find(o=>n.has(o))}function Gr(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 Jr(){return globalThis.performance?.now()??Date.now()}function Se(e){if(e===null||typeof e!="object"||Object.isFrozen(e))return e;for(let n of Object.values(e))Se(n);return Object.freeze(e)}function ci(e){return Object.freeze(Array.from(e))}async function An(e,n,t,i){if(n.pinnedFiles!==void 0){let l=n.pinnedFiles.get(t);if(l===void 0)throw new A("NOT_FOUND");if(l.byteLength>i)throw new A("LIMIT_EXCEEDED");return new Uint8Array(l)}let o=`${n.relativePath}/${t}`,r=n.scanContext,a=e.fingerprintVerifiedFile;if(r===void 0||!r.cacheable||typeof a!="function")return ui(e,n.root,o,i);let s=r.priorFingerprints.get(o)??await a.call(e,r.workspaceRoot,o,i);r.candidateRealPath=s.candidateRealPath;let d=await ui(e,n.root,o,i),c=await a.call(e,r.workspaceRoot,o,i);return r.candidateRealPath=c.candidateRealPath,Ti(s,c)&&c.size===BigInt(d.byteLength)&&!_i(c,r.scanStartedAtNs)?r.files.set(o,{relativePath:o,byteLimit:i,fingerprint:c}):r.cacheable=false,d}function hi(e,n){return JSON.stringify([e.realPath,n.source,n.relativePath])}async function Wr(e,n,t,i,o,r,a,s){let d=e.fingerprintVerifiedFile,c=hi(t,i),l=o.candidates.get(c),y=i.relativePath,I;try{I=await li(e,n,y);}catch(g){if(q(g)!=="NOT_FOUND")throw g}let D=I===void 0?void 0:{relativePath:y,key:I};if(D!==void 0&&i.source==="skills"&&!Xr(D.key,"ui-plugin.json"))return de(a,s)?l!==void 0&&l.candidate===void 0&&l.diagnostic===void 0&&l.candidateRealPath===void 0&&l.files.length===0&&l.directoryListings.length===1&&l.directoryListings[0]?.relativePath===D.relativePath&&l.directoryListings[0]?.key===D.key&&typeof d=="function"?{memo:l}:typeof d!="function"?{}:{context:{state:o,cacheKey:c,workspaceRoot:n,scanStartedAtNs:r,directoryListings:Object.freeze([D]),priorFingerprints:new Map,files:new Map,cacheable:true}}:{timeLimitReached:true};let h=await Promise.all(di.map(async g=>{if(g==="")return D;let f=`${i.relativePath}${g}`;try{let M=await li(e,n,f);return M===void 0?void 0:{relativePath:f,key:M}}catch(M){if(q(M)==="NOT_FOUND")return;throw M}}));if(!de(a,s))return {timeLimitReached:true};let E=typeof d=="function"&&h.every(g=>g!==void 0),S=h.filter(g=>g!==void 0),j=new Map,R=l!==void 0&&E,C;if(l!==void 0&&typeof d=="function"){let g=await Promise.all(l.files.map(async f=>{if(!de(a,s))return {kind:"time",file:f};try{let M=await d.call(e,n,f.relativePath,f.byteLimit);return {kind:"fingerprint",file:f,current:M}}catch(M){return q(M)==="NOT_FOUND"?{kind:"missing",file:f}:{kind:"error",file:f,error:M}}}));if(g.some(f=>f.kind==="time"))return {timeLimitReached:true};for(let f of g){if(f.kind==="error")throw f.error;if(f.kind==="missing"){R=false;continue}if(f.kind!=="fingerprint")continue;let{file:M,current:b}=f;j.set(M.relativePath,b),C??=b.candidateRealPath,(b.candidateRealPath!==l.candidateRealPath||!Ti(b,M.fingerprint)||_i(b,r))&&(R=false);}}let V=l!==void 0&&l.directoryListings.length===S.length&&l.directoryListings.every((g,f)=>g.relativePath===S[f]?.relativePath&&g.key===S[f]?.key);return l!==void 0&&E&&V&&R&&C===l.candidateRealPath?{memo:l}:!E||S.length!==di.length?{}:{context:{state:o,cacheKey:c,workspaceRoot:n,scanStartedAtNs:r,directoryListings:Object.freeze(S),priorFingerprints:j,files:new Map,...C===void 0?{}:{candidateRealPath:C},cacheable:true}}}function Xr(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 li(e,n,t){let i=Di(e);if(typeof i!="function")return;let o=await i.call(e,n,t);if(!Array.isArray(o)||o.some(a=>typeof a=="string"))return;let r=o.map(Ai);if(!r.some(a=>a===null))return JSON.stringify(r.slice().sort((a,s)=>We(a.name,s.name)||We(a.kind,s.kind)).map(a=>[a.name,a.kind]))}function Ti(e,n){return e.dev===n.dev&&e.ino===n.ino&&e.size===n.size&&e.mtimeNs===n.mtimeNs&&e.ctimeNs===n.ctimeNs}function _i(e,n){let t=e.mtimeNs-n;return t>=-pi&&t<=pi}function ct(e){let n=e.scanContext,t=e.source==="skills"&&e.candidate===void 0&&e.diagnostic===void 0&&n?.files.size===0;if(n===void 0||!n.cacheable||n.candidateRealPath===void 0&&!t||n.files.size===0&&!t)return;let i=Object.freeze({...!t&&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,i);}function $r(e,n,t){let i=createHash("sha256"),o=new TextEncoder().encode($(e)),r=a=>{let s=new Uint8Array(8);new DataView(s.buffer).setBigUint64(0,BigInt(a)),i.update(s);};return r(o.byteLength),i.update(o),r(n.byteLength),i.update(n),r(t.byteLength),i.update(t),i.digest("hex")}function Kr(e,n){let t={...e.definition,sourceHash:n},i;try{i=re(t);}catch(r){throw r instanceof P&&r.code==="INPUT_INVALID"?new Y("MANIFEST_INVALID","normalized definition is invalid"):r}let o={...t,hash:i};try{ae(o);}catch{throw new Y("MANIFEST_INVALID","normalized definition is invalid")}return o}function Yr(e){return e.actions.some(n=>n.backend.type==="core"&&n.backend.handler!=="state.set")}function qr(e){if(typeof e.readVerifiedFile=="function")return e.readVerifiedFile;if(typeof e.readFileVerified=="function")return e.readFileVerified}function Di(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 ui(e,n,t,i){let o=qr(e);if(!o)throw new A("READ_DENIED");return Vr(await o.call(e,n,t,i))}async function Zr(e,n,t){let i=Di(e);if(!i)throw new A("READ_DENIED");let o=await i.call(e,n,t);if(!Array.isArray(o))throw new A("READ_DENIED");return o.map(Ai).filter(r=>r!==null)}function Qr(e){let n=[];for(let t of [e.reserved,e.builtin])t&&n.push(t);return e.builtins&&"listMcpApps"in e.builtins?n.push(fi(e.builtins)):e.builtins&&n.push(e.builtins),e.builtinCatalog&&n.push(fi(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 fi(e){let n=[],t=[],i=[];for(let o of e.listMcpApps())typeof o.appId=="string"&&n.push(o.appId),o.definition&&typeof o.definition.id=="string"&&t.push(o.definition.id);for(let o of e.listMcpAppTools())typeof o.name=="string"&&i.push(o.name);return {appIds:n,definitionIds:t,toolNames:i}}function pe(e,n){e.diagnostic||(e.diagnostic=yn(n,e.source,e.relativePath,e.identity?.pluginId));}function ea(e){let n=new Map;for(let i of e){let o=i.identity?.pluginId;if(o===void 0)continue;let r=n.get(o)??[];r.push(i),n.set(o,r);}for(let i of n.values()){if(i.length<2)continue;let o=i.filter(a=>a.provenance!==void 0);if(o.length>0){for(let a of i)a.provenance===void 0&&pe(a,"RESERVED_ID");if(o.length>1)for(let a of o)pe(a,"DUPLICATE_ID");continue}let r=i.filter(a=>a.source==="apps");if(r.length>1){for(let a of r)pe(a,"DUPLICATE_ID");for(let a of i.filter(s=>s.source==="skills"))pe(a,"DUPLICATE_ID");}else for(let a of i.filter(s=>s.source==="skills"))pe(a,"DUPLICATE_ID");}let t=new Map;for(let i of e){if(i.diagnostic?.code==="RESERVED_ID")continue;let o=i.identity?.definitionKey;if(o===void 0)continue;let r=t.get(o)??[];r.push(i),t.set(o,r);}for(let i of t.values())if(i.length>1)for(let o of i)pe(o,"DUPLICATE_ID");}function na(e,n,t){let i=new Set,o=new Set,r=new Set,a=new Set(t.appIds),s=new Set(t.definitionIds);for(let d of Qr(n)){for(let c of d.appIds??[])typeof c=="string"&&i.add(c);for(let c of d.definitionIds??[])typeof c=="string"&&o.add(c);for(let c of d.toolNames??[])typeof c=="string"&&r.add(c);}for(let d of e){let c=d.candidate;if(!c)continue;if(i.has(c.pluginId)||o.has(c.definitionId)){pe(d,"RESERVED_ID");continue}if(d.provenance===void 0&&(a.has(c.pluginId)||s.has(c.definitionId))){pe(d,"RESERVED_ID");continue}[c.toolNames.read,c.toolNames.action].filter(y=>y!==void 0).some(y=>r.has(y))&&pe(d,"DUPLICATE_ID");}}function ta(e){return [...e].sort((n,t)=>{let i=oi.indexOf(n.source)-oi.indexOf(t.source);return i!==0?i:We(n.relativePath,t.relativePath)})}function L(e,n){e.diagnostic=yn(n,e.source,e.relativePath,e.identity?.pluginId);}async function yi(e,n,t){if(t.byteLength>262144){L(n,"LIMIT_EXCEEDED");return}let i;try{i=Br(t);}catch{L(n,"MANIFEST_INVALID");return}if(n.bundleIdentity===void 0)n.identity=i.identity;else if(i.identity?.pluginId!==n.bundleIdentity.appId||i.identity.definitionKey!==`${n.bundleIdentity.definitionId}\0${String(n.bundleIdentity.version)}`){L(n,"BUNDLE_INTEGRITY");return}if(Je(i.value)&&i.value.builtinOnly===true){L(n,"RESERVED_ID");return}let o;try{let T=nn(i.value,{mode:"local"});if(T.manifestVersion!==2)throw new Y("MANIFEST_INVALID","workspace App requires v2");o=T;}catch(T){if(T instanceof Y){L(n,si(T));return}if(T instanceof se){L(n,st(T.code));return}if(Je(T)&&typeof T.code=="string"){L(n,st(T.code));return}throw T}let r={pluginId:o.pluginId,definitionKey:`${o.definitionId}\0${String(o.version)}`};if(n.bundleIdentity===void 0&&(n.identity=r),o.actions.length>0)try{zt(o.actions.map(T=>({actionId:T.actionId,inputSchema:T.inputSchema})));}catch(T){if(T instanceof se){L(n,st(T.code));return}throw T}let a;try{a=await An(e,n,"ui/index.html",Ve);}catch(T){L(n,Ue(q(T),"entry"));return}if(a.byteLength>Ve){L(n,"LIMIT_EXCEEDED");return}let s;try{s=Ii(a);}catch{L(n,"ENTRY_INVALID");return}if(a.byteLength===0||s.length===0){L(n,"ENTRY_INVALID");return}let d=createHash("sha256").update(a).digest("hex");if(o.entryHash!==void 0&&o.entryHash!==d){L(n,"ENTRY_INVALID");return}let c={},l,y;if(o.initialState!==void 0){try{l=await An(e,n,"ui/state.json",65536);}catch(T){L(n,Ue(q(T),"initial"));return}if(l.byteLength>65536){L(n,"LIMIT_EXCEEDED");return}try{let T=gi(l),U=o.dataPaths??[],Q=Vn(T,U);c=ie(Q,0,U),he(c);}catch{L(n,"INITIAL_STATE_INVALID");return}if(y=createHash("sha256").update(l).digest("hex"),o.initialState.hash!==void 0&&o.initialState.hash!==y){L(n,"INITIAL_STATE_INVALID");return}}let I={...o,entryHash:d,...o.initialState===void 0?{}:{initialState:{path:"ui/state.json",hash:y}}},D=Fn(I),h=$r(I,a,l??new Uint8Array),E;try{E=Kr(D,h);}catch(T){if(T instanceof Y){L(n,si(T));return}throw T}let S;if(n.bundleLineage!==void 0){let T=n.bundleLineage[n.bundleLineage.length-1];if(!T){L(n,"LINEAGE_INVALID");return}let{legacy:U,...Q}=T.definition,{hash:H,...ee}=E;if($(Q)!==$(ee)){L(n,"LINEAGE_STALE");return}if(U!==void 0&&(E={...E,legacy:U}),U!==void 0)try{E={...E,hash:re(E)},ae(E);}catch{L(n,"LINEAGE_INVALID");return}S=n.bundleLineage;}if(n.bundleIdentity!==void 0&&n.bundleIdentity.appId!==o.pluginId){L(n,"BUNDLE_INTEGRITY");return}if(n.bundleIdentity!==void 0&&(n.bundleIdentity.definitionId!==E.id||n.bundleIdentity.version!==E.version||n.bundleIdentity.definitionHash!==E.hash)){L(n,"LINEAGE_STALE");return}let j=dt(o.pluginId),R=o.actions.length===0?{read:j.read}:j,C=Se(D),V=Se(I),g=Se(E),f=Se({...D.handlers}),M=ci(a),b=l===void 0?void 0:ci(l),u=Object.freeze({...n.provenance===void 0?{}:{provenance:n.provenance},entry:Object.freeze({path:"ui/index.html",hash:d,bytes:M}),...b===void 0?{}:{initialState:Object.freeze({path:"ui/state.json",hash:y,bytes:b})}}),m={appId:o.pluginId,pluginId:o.pluginId,definitionId:o.definitionId,version:o.version,relativePath:n.relativePath,manifest:V,normalized:C,name:o.name,description:o.description,...o.icon===void 0?{}:{icon:o.icon},...o.tone===void 0?{}:{tone:o.tone},definition:g,handlers:f,resources:u,html:s,entryBytes:M,entryHash:d,initialState:Se(c),...b===void 0?{}:{initialStateBytes:b},...y===void 0?{}:{initialStateHash:y},sourceHash:h,toolNames:Object.freeze(R)},N=n.provenance===void 0?{...m,source:n.source}:{...m,provenance:n.provenance,lineage:S??[]};n.candidate=Object.freeze(N),Yr(o)&&L(n,"EXEC_DENIED");}async function ia(e,n){try{return await An(e,n,"ui-plugin.json",262144)}catch(t){if(q(t)==="NOT_FOUND")return;L(n,Ue(q(t),"manifest"));return}}function oa(e,n,t,i=Ur,o=false){let r=ta(e);ea(r);let a=Object.freeze(r.filter(l=>l.candidate!==void 0&&l.diagnostic===void 0).map(l=>l.candidate)),s=Object.freeze(r.filter(l=>l.diagnostic!==void 0).map(l=>l.diagnostic)),d=o?Object.freeze({...t===void 0?{}:{indexHash:t},diagnostics:Object.freeze(s.filter(l=>l.source==="bundled").map(l=>Object.freeze({...l}))),reservedAppIds:Object.freeze([...i.appIds]),reservedDefinitionIds:Object.freeze([...i.definitionIds])}):void 0,c={apps:a,diagnostics:s,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:()=>a}),Object.freeze(c)}function ra(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 aa(e,n){if(ra(e))return {fs:e,options:n??{}};let t=e??n??{};return {fs:t.filesystem??t.fileSystem??t.fs??ln,options:t}}async function pt(e,n,t){if(typeof e!="string"||e.length===0)throw new TypeError("workspaceRoot must be explicit");let{fs:i,options:o}=aa(n,t),r=o.clock??Jr,a=r(),s=await ii(o.productBundle,i,a,r),d=r(),c=BigInt(Date.now())*1000000n,l=[],y=0,I,D=false,h,E;o.scanCache!==void 0&&typeof i.getRootIdentity=="function"&&typeof i.fingerprintVerifiedFile=="function"&&(E=await i.getRootIdentity(e),h=Jt(o.scanCache,E),h.scanStartedAtNs=c);let S=h!==void 0&&o.productBundle===void 0&&s.packages.length===0&&s.diagnostics.length===0,j=new Set,R=true;l.push(...s.diagnostics.map(g=>({source:g.source,root:o.productBundle?.root??e,name:"",relativePath:g.relativePath,diagnostic:g})));let C=s.reservedIds;s.incomplete&&(I="time_limit");for(let g of s.packages){if(!de(d,r)){D=true,I="time_limit";break}let f=g.indexEntry,M=f.packageDir,b=g.files===void 0?void 0:zr(M,g.files),u=s.indexHash===void 0?void 0:Ct(Object.freeze({kind:"bundled",launcher:f.launcher!==false,indexHash:s.indexHash,packageDir:M,appId:f.appId,definitionId:f.definition.id,version:f.definition.version,definitionHash:f.definition.hash,files:f.files}),b),m={source:"bundled",root:o.productBundle?.root??e,name:M.slice(5),relativePath:M,...u===void 0?{}:{provenance:u},...g.files===void 0?{}:{pinnedFiles:g.files},...g.lineage===void 0?{}:{bundleLineage:g.lineage},bundleIdentity:{appId:f.appId,definitionId:f.definition.id,version:f.definition.version,definitionHash:f.definition.hash},identity:Hr(f)};if(l.push(m),y+=1,g.failureCode!==void 0){L(m,g.failureCode);continue}let N=g.files?.get("ui-plugin.json");if(N===void 0){L(m,"BUNDLE_INTEGRITY");continue}if(await yi(i,m,N),!de(d,r)){D=true,I="time_limit";break}}let V=[{source:"apps",directory:"apps"},{source:"skills",directory:"skills"}];e:for(let g of V){let{source:f,directory:M}=g,b;try{b=await Zr(i,e,M);}catch(m){if(q(m)==="NOT_FOUND")continue;S=false,R=false,l.push({source:f,root:e,name:"",relativePath:f,diagnostic:yn(Ue(q(m),"manifest"),f,f)});continue}let u=b.filter(m=>m.kind==="directory"||m.kind==="symlink").filter(m=>jr(m.name)).map(m=>({source:f,root:e,name:m.name,relativePath:vr(f,m.name)})).sort((m,N)=>We(m.relativePath,N.relativePath));for(let m of u){let N={...m};if(l.push(N),E!==void 0?j.add(hi(E,N)):S=false,!de(d,r)){D=true,I="time_limit";break e}let T;if(h!==void 0&&E!==void 0){try{let H=await Wr(i,e,E,N,h,c,d,r);if(H.timeLimitReached){D=!0,I="time_limit";break e}N.scanContext=H.context,T=H.memo;}catch(H){S=false,L(N,Ue(q(H),"manifest"));continue}T===void 0&&(S=false);}if(T!==void 0){if(N.candidate=T.candidate,N.diagnostic=T.diagnostic,N.identity=T.identity,f==="skills"&&T.candidate===void 0&&T.diagnostic===void 0)continue;if(y>=64){L(N,"LIMIT_EXCEEDED");continue}if(m.relativePath.split("/").length-1>2){L(N,"LIMIT_EXCEEDED");continue}if(y+=1,!de(d,r)){D=true,I="time_limit";break e}continue}let U;if(f==="skills"&&(U=await ia(i,N),U===void 0)){N.diagnostic===void 0&&ct(N);continue}if(y>=64){L(N,"LIMIT_EXCEEDED");continue}if(m.relativePath.split("/").length-1>2){L(N,"LIMIT_EXCEEDED");continue}if(!de(d,r)){D=true,I="time_limit";break e}if(y+=1,U===void 0)try{U=await An(i,N,"ui-plugin.json",262144);}catch(H){L(N,Ue(q(H),"manifest")),ct(N);continue}if(await yi(i,N,U),ct(N),!de(d,r)){D=true,I="time_limit";break e}}}if(h!==void 0&&E!==void 0){let g=[...j].sort(We),f=h.lastCandidateKeys,M=f!==void 0&&f.length===g.length&&f.every((u,m)=>u===g[m]);if(S=S&&M,R&&!D&&I===void 0)for(let u of h.candidates.keys())try{JSON.parse(u)[0]===E.realPath&&!j.has(u)&&h.candidates.delete(u);}catch{h.candidates.delete(u);}let b=[...h.candidates.keys()].filter(u=>{try{return JSON.parse(u)[0]===E.realPath}catch{return false}});S=S&&b.length===j.size&&b.every(u=>j.has(u))&&!D&&I===void 0,h.lastCandidateScanUnchanged=S,R&&!D&&I===void 0&&(h.lastCandidateKeys=Object.freeze(g));}return D&&l.push({source:"apps",root:e,name:"",relativePath:"apps",diagnostic:yn("DISCOVERY_TIME_LIMIT","apps","apps")}),na(l,o,C),oa(l,I,s.indexHash,C,o.productBundle!==void 0)}var Ur,Oe,kr,Cr,oi,xr,di,pi,sa,ca,Ni=k(()=>{_();De();Xe();le();Ut();_e();Jn();rn();Wt();et();an();at();at();Ur=Ge([]);Oe="crewx_local_app_",kr=Oe,Cr=Oe;oi=["bundled","apps","skills"],xr=new TextDecoder("utf-8",{fatal:true});di=["","/ui"],pi=2000000000n;sa=pt,ca=pt;});_();var bi="SKILL.md",fa=/^---\s*\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;function Pi(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}function ya(e){return e.isDirectory()||e.isSymbolicLink()}function Si(e){try{return existsSync(e)&&statSync(e).isDirectory()}catch{return false}}var Aa=["index.js","main.js"];function Jc(e,n){let t=join(e,"package.json");if(existsSync(t))try{let o=JSON.parse(readFileSync(t,"utf8"));if(o.bin){let r=typeof o.bin=="string"?o.bin:Object.values(o.bin).find(a=>typeof a=="string");if(r){let a=resolve(e,r);if(existsSync(a))return a}}if(typeof o.main=="string"){let r=resolve(e,o.main);if(existsSync(r))return r}}catch{}let i=resolve(e,`${n}.js`);if(existsSync(i))return i;for(let o of Aa){let r=resolve(e,o);if(existsSync(r))return r}}function Ia(e){let n;try{n=readFileSync(e,"utf8");}catch{return {frontmatter:{},readable:false,valid:false,hasFrontmatter:false}}let t=n.match(fa);if(!t)return {frontmatter:{},readable:true,valid:true,hasFrontmatter:false};try{let i=load(t[1]??"");if(!Pi(i))return {frontmatter:{},readable:!0,valid:!1,hasFrontmatter:!0};let o=Pi(i.metadata)?i.metadata:void 0;return {frontmatter:{...typeof i.name=="string"?{name:i.name}:{},...typeof(o?.version??i.version)=="string"?{version:o?.version??i.version}:{},...typeof i.description=="string"?{description:i.description}:{}},readable:!0,valid:!0,hasFrontmatter:!0}}catch{return {frontmatter:{},readable:true,valid:false,hasFrontmatter:true}}}function ga(e){return [join(e,bi),join(e,"skill",bi)]}function In(e,n){if(!Si(e))return null;for(let t of ga(e)){if(!existsSync(t))continue;let o=Ia(t).frontmatter;return {name:o.name??n,...o.version===void 0?{}:{version:o.version},...o.description===void 0?{}:{description:o.description},skillMdPath:t,dir:e}}return null}function lt(e){try{return readdirSync(e,{withFileTypes:!0}).filter(ya)}catch{return []}}function ma(e){return e.length===0||/[\\\u0000]/.test(e)?false:e.split("/").every(n=>n.length>0&&n!=="."&&n!=="..")}function Mi(e,n,t){!e||n.has(e.name)||(n.add(e.name),t.push(e));}function gn(e){let n=[],t=new Set;for(let i of e)if(Si(i))for(let o of lt(i)){if(o.name.startsWith("@")){let r=join(i,o.name);for(let a of lt(r))Mi(In(join(r,a.name),a.name),t,n);continue}Mi(In(join(i,o.name),o.name),t,n);}return n.sort((i,o)=>i.name.localeCompare(o.name))}function ha(e,n){if(!ma(e))throw new Error(`Skill not found: ${e}`);for(let i of n){let o=In(join(i,e),e);if(o)return o;for(let r of lt(i)){if(!r.name.startsWith("@"))continue;let a=In(join(i,r.name,e),e);if(a)return a}}let t=gn(n).find(i=>i.name===e);if(t)return t;throw new Error(`Skill not found: ${e}`)}async function Wc(e){if(!e||e.root===null)return {skills:[],diagnostics:[]};let{discoverWorkspaceApps:n}=await Promise.resolve().then(()=>(Ni(),Ei)),t=await n(e.root,{productBundle:e}),i=[],o=new Set;for(let r of t.apps){let a=r.provenance?.kind==="bundled"?r.provenance.packageDir:void 0;if(!a)continue;let s=join(e.root,...a.split("/"));for(let d of gn([dirname(s)]))resolve(d.dir)!==resolve(s)||o.has(d.name)||(o.add(d.name),i.push(d));for(let d of [join(s,"skill"),join(s,"skills")])for(let c of gn([d]))o.has(c.name)||(o.add(c.name),i.push(c));}return {skills:i.sort((r,a)=>r.name.localeCompare(a.name)),diagnostics:t.diagnostics.filter(r=>r.source==="bundled")}}var Xc=gn,$c=ha;
2
+ export{gn as discover,Wc as discoverBundledProductSkills,Xc as discoverSkills,Jc as findEntrypoint,Ia as readSkillFrontmatter,ha as resolve,$c as resolveSkill};