@crewx/sdk 0.9.0-rc.225 → 0.9.0-rc.227

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.
@@ -0,0 +1,30 @@
1
+ import { type AppInstallRunner } from './process.js';
2
+ export interface AppInstallProgress {
3
+ readonly step: 'dependencies' | 'verify';
4
+ readonly message: string;
5
+ }
6
+ export interface AppInstallRuntime {
7
+ readonly execPath?: string;
8
+ readonly isElectronRuntime?: () => boolean;
9
+ readonly workspaceRoot?: string;
10
+ }
11
+ export interface PrepareAppDependenciesOptions {
12
+ readonly onProgress?: (progress: AppInstallProgress) => void;
13
+ readonly signal?: AbortSignal;
14
+ readonly retry?: boolean;
15
+ readonly runner?: AppInstallRunner;
16
+ readonly runtime?: AppInstallRuntime;
17
+ readonly timeoutMs?: number;
18
+ readonly noOutputTimeoutMs?: number;
19
+ }
20
+ export interface ResolveNpmCliOptions {
21
+ readonly env?: NodeJS.ProcessEnv;
22
+ readonly log?: (message: string) => void;
23
+ }
24
+ export declare function validateAppDependencyLockfile(stagedDir: string): 'skipped' | 'ready';
25
+ export declare function resolveNpmCli(options?: ResolveNpmCliOptions): string;
26
+ export declare function prepareAppDependencies(stagedDir: string, options?: PrepareAppDependenciesOptions): Promise<{
27
+ readonly state: 'done' | 'skipped';
28
+ }>;
29
+ export declare const APP_INSTALL_TIMEOUT_MS: number;
30
+ export declare const APP_INSTALL_NO_OUTPUT_TIMEOUT_MS: number;
@@ -0,0 +1,9 @@
1
+ export type AppInstallErrorCode = 'DOWNLOAD_FAILED' | 'DEPS_LOCKFILE_MISSING' | 'DEPS_REGISTRY_REFUSED' | 'DEPS_NETWORK' | 'DEPS_TIMEOUT' | 'DEPS_DISK_FULL' | 'DEPS_INSTALL_FAILED' | 'VERIFY_IMPORT_FAILED' | 'VERIFY_TIMEOUT';
2
+ export type AppInstallStep = 'download' | 'dependencies' | 'verify';
3
+ export declare class AppInstallError extends Error {
4
+ readonly code: AppInstallErrorCode;
5
+ readonly step: AppInstallStep;
6
+ readonly detail?: string | undefined;
7
+ constructor(code: AppInstallErrorCode, step: AppInstallStep, message?: string, detail?: string | undefined);
8
+ }
9
+ export declare function firstErrorLine(value: string | undefined): string | undefined;
@@ -0,0 +1,9 @@
1
+ export { AppInstallError } from './errors.js';
2
+ export type { AppInstallErrorCode, AppInstallStep } from './errors.js';
3
+ export { buildAppRuntimeEnv } from './runtime-env.js';
4
+ export type { AppElectronRuntimeCheck } from './runtime-env.js';
5
+ export { APP_INSTALL_NO_OUTPUT_TIMEOUT_MS, APP_INSTALL_TIMEOUT_MS, prepareAppDependencies, resolveNpmCli, } from './dependencies.js';
6
+ export type { AppInstallProgress, AppInstallRuntime, PrepareAppDependenciesOptions, ResolveNpmCliOptions, } from './dependencies.js';
7
+ export { APP_VERIFY_TIMEOUT_MS, verifyAppLaunch } from './verify.js';
8
+ export type { VerifyAppLaunchOptions } from './verify.js';
9
+ export type { AppInstallCommandHandle, AppInstallCommandOptions, AppInstallCommandResult, AppInstallRunner, } from './process.js';
@@ -0,0 +1,7 @@
1
+ 'use strict';var L=require('fs'),P=require('path'),Rn=require('os'),child_process=require('child_process'),crypto=require('crypto'),net=require('net');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var L__namespace=/*#__PURE__*/_interopNamespace(L);var P__namespace=/*#__PURE__*/_interopNamespace(P);var Rn__namespace=/*#__PURE__*/_interopNamespace(Rn);var T=class extends Error{constructor(t,i,o=t,r){super(o);this.code=t;this.step=i;this.detail=r;this.name="AppInstallError";}code;step;detail};function On(e){if(!e)return;let n=e.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/gu," ").split(/[\r\n]/u).map(i=>i.replace(/\s+/gu," ").trim()).filter(Boolean),t=n.find(i=>/cannot find package/iu.test(i))??n.find(i=>/\b(?:error|exception)(?:\s+\[[^\]]+\])?:/iu.test(i))??n.find(i=>/module_not_found/iu.test(i))??n[0];if(t)return t.length>500?`${t.slice(0,497)}...`:t}var Ht=["CREWX_HOME","CREWX_DB","XDG_CONFIG_HOME"];function re(e,n=Jt){let t={};for(let i of Ht){let o=process.env[i];o!==void 0&&(t[i]=o);}return t.CREWX_WORKSPACE_ROOT=e,n()&&(t.ELECTRON_RUN_AS_NODE="1"),t}function Jt(){return typeof process.versions.electron=="string"&&process.versions.electron.length>0}function wn(){if(process.env.CREWX_HOME){let e=P__namespace.resolve(process.env.CREWX_HOME);try{return L__namespace.realpathSync(e)}catch(n){if(n instanceof Error&&"code"in n&&n.code==="ENOENT")return e;throw n}}return process.platform!=="win32"&&process.env.XDG_CONFIG_HOME?P__namespace.join(process.env.XDG_CONFIG_HOME,"crewx"):P__namespace.join(Rn__namespace.homedir(),".crewx")}var Dn=3e3;var kn=2e3,xn=25,jn=100;function Fn(e){return e instanceof Error?e:e===void 0?void 0:new Error(String(e))}function Ln(e){return typeof e=="object"&&e!==null&&"code"in e?String(e.code):void 0}function Bt(e){return Number.isSafeInteger(e)&&e>0}function zt(e,n){return new Promise(t=>{let i;try{i=child_process.spawn(e,n,{windowsHide:!0});}catch(l){t({status:null,stdout:"",stderr:"",error:Fn(l)});return}let o="",r="",c=false,a,d=setTimeout(()=>{try{i.kill();}catch{}a({status:null,stdout:o,stderr:r,error:new Error(`Command timed out after ${Dn}ms`)});},Dn);a=l=>{c||(c=true,clearTimeout(d),t(l));},i.stdout?.setEncoding("utf8"),i.stderr?.setEncoding("utf8"),i.stdout?.on("data",l=>{o+=String(l);}),i.stderr?.on("data",l=>{r+=String(l);}),i.once("error",l=>{a({status:null,stdout:o,stderr:r,error:l});}),i.once("close",l=>{a({status:l,stdout:o,stderr:r});});})}async function Kt(e,n,t){return t.runCommandAsync?t.runCommandAsync(e,n):t.runCommand?t.runCommand(e,n):zt(e,n)}function Xt(e){return new Promise(n=>{setTimeout(n,Math.max(0,e));})}function Yt(){return new Promise(e=>{setImmediate(e);})}function ae(e,n=process.kill){try{return n(e,0),"alive"}catch(t){return Ln(t)==="ESRCH"?"not_found":Ln(t)==="EPERM"?"alive":"unknown"}}function qt(e,n){let t=ae(-e,n),i=ae(e,n);return t==="alive"||i==="alive"?"alive":t==="unknown"||i==="unknown"?"unknown":"not_found"}async function Vn(e,n,t,i){let o=Math.max(0,t),r=Math.max(1,i.pollIntervalMs??xn),c=Date.now()+o,a,d=o===0,l=i.sleep?Promise.resolve().then(()=>i.sleep(o)).then(()=>{},()=>{}):new Promise(f=>{a=setTimeout(f,o);});l.then(()=>{d=true;});try{for(await Yt();;){let f=qt(e,n);if(f==="not_found")return f;let m=c-Date.now();if(d||m<=0)return f;await Promise.race([l,Xt(Math.min(r,m))]);}}finally{a!==void 0&&clearTimeout(a);}}async function Cn(e,n,t,i,o){let r=await Vn(e,n,o.hardConfirmMs??jn,{...o,sleep:void 0});return r==="not_found"?t?{status:"not_found",pid:e,method:i}:{status:"terminated",pid:e,method:i}:r==="alive"?{status:"failed",pid:e,method:i,error:"Process is still running after termination attempt"}:{status:"failed",pid:e,method:i,error:"Unable to verify process termination"}}async function Ee(e,n={}){let t=n.platform??process.platform,i=t==="win32"?"taskkill":"process-group",o=y=>({status:"failed",pid:e,method:i,error:y});if(!Bt(e))return o("Invalid process ID");let r=n.kill??process.kill,c=ae(e,r);if(c==="not_found")return {status:"not_found",pid:e,method:i};if(c!=="alive")return o("Unable to determine whether the process is alive");if(t==="win32"){let y;try{y=await Kt("taskkill",["/PID",String(e),"/T","/F"],n);}catch(O){y={status:null,stdout:"",stderr:"",error:Fn(O)};}let u=ae(e,r);return u==="not_found"?y.status===0&&!y.error?{status:"terminated",pid:e,method:i}:{status:"not_found",pid:e,method:i}:o(u==="alive"?"Process is still running after termination attempt":"Unable to verify process termination")}let a,d=n.signal??"SIGKILL";try{r(-e,d);}catch(y){a=y;}if(d==="SIGKILL")return Cn(e,r,a,i,n);if(await Vn(e,r,n.graceMs??kn,n)==="not_found")return a?{status:"not_found",pid:e,method:i}:{status:"terminated",pid:e,method:i};let f;try{r(-e,"SIGKILL");}catch(y){f=y;}let m=await Cn(e,r,f,i,n);return m.status==="terminated"?m:m.status==="not_found"?a?m:{status:"terminated",pid:e,method:i}:o(m.error??"Process termination failed")}var vn=64*1024;function Gn(e,n){let t=e+n;return Buffer.byteLength(t,"utf8")<=vn?t:Buffer.from(t,"utf8").subarray(-vn).toString("utf8")}function De(e){return e instanceof Error?e:e===void 0?void 0:new Error(String(e))}function Ne(e){return {status:null,stdout:"",stderr:"",...De(e)===void 0?{}:{error:De(e)}}}var Zt=(e,n,t)=>{let i;try{i=child_process.spawn(e,[...n],{cwd:t.cwd,env:t.env,shell:!1,detached:process.platform!=="win32",windowsHide:!0,stdio:["ignore","pipe","pipe"]});}catch(f){return {completion:Promise.resolve(Ne(f)),terminate:async()=>{}}}let o="",r="",c=false,a,d=new Promise(f=>{a=f;}),l=f=>{c||(c=true,a(f));};return i.stdout?.setEncoding("utf8"),i.stderr?.setEncoding("utf8"),i.stdout?.on("data",f=>{let m=String(f);o=Gn(o,m),t.onStdout?.(m);}),i.stderr?.on("data",f=>{let m=String(f);r=Gn(r,m),t.onStderr?.(m);}),i.once("error",f=>l({status:null,stdout:o,stderr:r,error:f})),i.once("close",f=>l({status:f,stdout:o,stderr:r})),{...i.pid===void 0?{}:{pid:i.pid},completion:d,terminate:async()=>{if(i.pid===void 0)return;if((await Ee(i.pid)).status==="failed"){try{i.kill("SIGKILL");}catch{}let m=await Ee(i.pid);if(m.status==="failed")throw new Error(m.error??"process tree termination failed")}}}};async function he(e){if(e.signal?.aborted)throw new T("DEPS_INSTALL_FAILED",e.step,"App operation was cancelled.");let n,t,i,o,r=false,c=new Promise(A=>{o=A;}),a=A=>{r||(r=true,n!==void 0&&clearTimeout(n),t!==void 0&&clearTimeout(t),i&&e.signal?.removeEventListener("abort",i),o(A));},d=()=>{e.noOutputTimeoutMs===void 0||e.noOutputTimeoutMs<=0||(n!==void 0&&clearTimeout(n),n=setTimeout(()=>a({type:"timeout"}),e.noOutputTimeoutMs));},l=A=>{A.length>0&&d();try{e.onOutput?.(A);}catch{}},f;try{f=(e.runner??Zt)(e.command,e.args,{cwd:e.cwd,env:e.env,onStdout:l,onStderr:l});}catch(A){return Ne(A)}f.completion.then(A=>a({type:"completed",result:A}),A=>a({type:"completed",result:Ne(A)}));d(),t=setTimeout(()=>a({type:"timeout"}),e.timeoutMs),e.signal&&(i=()=>a({type:"abort"}),e.signal.addEventListener("abort",i,{once:true}));let y=await c;if(y.type==="completed")return y.result;let u;try{await f.terminate();}catch(A){u=De(A);}let O;try{O=await f.completion;}catch(A){O=Ne(A);}if(y.type==="abort"){let A=u?`Could not confirm process tree termination: ${u.message}`:void 0;throw new T("DEPS_INSTALL_FAILED",e.step,"App operation was cancelled.",A)}let z=[O?.stderr,u?.message].filter(Boolean).join(`
2
+ `);throw new T(e.onTimeoutCode,e.step,"App operation timed out.",z||void 0)}var Qt=["dependencies","devDependencies","optionalDependencies","peerDependencies"],Bn=300*1e3,zn=90*1e3,Hn=false;function K(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function U(e,n){return new T(e,"dependencies",n)}function Jn(e,n){try{let t=L__namespace.lstatSync(e);if(t.isSymbolicLink()||!t.isFile())throw new Error("not a regular file");return JSON.parse(L__namespace.readFileSync(e,"utf8"))}catch(t){let i=t!==null&&typeof t=="object"&&"code"in t?String(t.code):"";throw n==="package-lock.json"?U("DEPS_LOCKFILE_MISSING","package-lock.json is missing or invalid."):i==="ENOENT"?U("DEPS_INSTALL_FAILED","package.json is missing."):U("DEPS_INSTALL_FAILED","package.json is invalid.")}}function ei(e){let n=e.dependencies;if(n!==void 0){if(!K(n)||Object.values(n).some(t=>typeof t!="string"))throw U("DEPS_INSTALL_FAILED","package.json dependencies must be a string map.");return Object.keys(n).length===0?void 0:n}}function ni(e,n){let t=K(e)?e:{},i=K(n)?n:{},o=Object.keys(t).sort(),r=Object.keys(i).sort();return o.length===r.length&&o.every((c,a)=>c===r[a]&&t[c]===i[c])}function ti(e,n){for(let t of Qt){let i=e[t];if(!ni(i,n[t]))throw U("DEPS_LOCKFILE_MISSING","package-lock.json is out of sync with package.json.")}if(typeof e.name=="string"&&typeof n.name=="string"&&e.name!==n.name||typeof e.version=="string"&&typeof n.version=="string"&&e.version!==n.version)throw U("DEPS_LOCKFILE_MISSING","package-lock.json is out of sync with package.json.")}function ii(e){let n=P__namespace.join(e,"package.json");if(!L__namespace.existsSync(n))return "skipped";let t=Jn(n,"package.json");if(!K(t))throw U("DEPS_INSTALL_FAILED","package.json must contain an object.");if(ei(t)===void 0)return "skipped";let i=P__namespace.join(e,"package-lock.json"),o=Jn(i,"package-lock.json");if(!K(o)||!Number.isInteger(o.lockfileVersion)||o.lockfileVersion<2||!K(o.packages))throw U("DEPS_LOCKFILE_MISSING","package-lock.json is missing a supported npm lockfile package map.");let r=o.packages,c=r[""];if(!K(c))throw U("DEPS_LOCKFILE_MISSING","package-lock.json has no root package entry.");ti(t,c);for(let[a,d]of Object.entries(r)){if(a==="")continue;if(!K(d))throw U("DEPS_LOCKFILE_MISSING","package-lock.json contains an invalid package entry.");let l=d;if(l.link===true)throw U("DEPS_REGISTRY_REFUSED",`package-lock.json contains a linked dependency at ${a}.`);if(typeof l.resolved=="string"&&!l.resolved.startsWith("https://registry.npmjs.org/"))throw U("DEPS_REGISTRY_REFUSED",`package-lock.json contains a non-registry dependency at ${a}.`);if(typeof l.integrity!="string"||l.integrity.trim().length===0)throw U("DEPS_REGISTRY_REFUSED",`package-lock.json has no integrity for ${a}.`)}return "ready"}function oi(e){let n=P__namespace.join(e,".npmrc");try{L__namespace.rmSync(n,{force:!0,recursive:!0});}catch{throw U("DEPS_INSTALL_FAILED","Could not remove the package .npmrc file.")}}function $n(e){try{let n=L__namespace.realpathSync(e);return L__namespace.statSync(n).isFile()?n:void 0}catch{return}}function ri(e){let n=P__namespace.resolve(e||".");return [P__namespace.join(n,"npm-cli.js"),P__namespace.join(n,"npm"),P__namespace.join(n,"npm.cmd"),P__namespace.join(n,"node_modules","npm","bin","npm-cli.js"),P__namespace.resolve(n,"..","lib","node_modules","npm","bin","npm-cli.js"),P__namespace.resolve(n,"..","node_modules","npm","bin","npm-cli.js")]}function Kn(e={}){let n=e.env??process.env,t=n.CREWX_NPM_CLI_JS;if(t!==void 0){let o=P__namespace.isAbsolute(t)?$n(t):void 0;if(o===void 0||P__namespace.basename(o).toLowerCase()!=="npm-cli.js")throw U("DEPS_INSTALL_FAILED","CREWX_NPM_CLI_JS must name an existing absolute npm-cli.js file.");return o}Hn||(Hn=true,(e.log??(o=>console.warn(o)))("CREWX_NPM_CLI_JS is unset; resolving npm-cli.js from PATH."));let i=n.PATH??n.Path??"";for(let o of i.split(P__namespace.delimiter))for(let r of ri(o)){let c=$n(r);if(c!==void 0&&P__namespace.basename(c).toLowerCase()==="npm-cli.js")return c}throw U("DEPS_INSTALL_FAILED","npm-cli.js was not found on PATH.")}function si(e){let n=`${e.error?.message??""}
3
+ ${e.stdout}
4
+ ${e.stderr}`,t=e.error!==void 0&&"code"in e.error?String(e.error.code??""):"";return /ENOTFOUND|ECONNRESET|EAI_AGAIN|ETIMEDOUT|ECONNREFUSED/iu.test(`${t}
5
+ ${n}`)?new T("DEPS_NETWORK","dependencies","The npm registry could not be reached.",e.stderr):/ENOSPC/iu.test(`${t}
6
+ ${n}`)?new T("DEPS_DISK_FULL","dependencies","There is not enough disk space to install App dependencies.",e.stderr):/package\.json.{0,80}package-lock\.json.{0,80}not in sync|Missing: .+ from lock file|Invalid: .+ from lock file|EUSAGE/iu.test(n)?new T("DEPS_LOCKFILE_MISSING","dependencies","package-lock.json is out of sync with package.json.",e.stderr):new T("DEPS_INSTALL_FAILED","dependencies","npm ci could not install App dependencies.",e.stderr||e.error?.message)}function ai(e,n){let t=re(n?.workspaceRoot??e,n?.isElectronRuntime);for(let i of ["PATH","Path","HOME","USERPROFILE","TMPDIR","TMP","TEMP","SystemRoot"]){let o=process.env[i];o!==void 0&&(t[i]=o);}return t}async function ci(e,n={}){if(oi(e),ii(e)==="skipped")return {state:"skipped"};let i=n.runtime,r=[Kn(),"ci","--omit=dev","--include=optional","--ignore-scripts","--no-audit","--no-fund","--cache",P__namespace.join(wn(),"npm-cache")];n.retry&&r.push("--prefer-offline");let c="",a=l=>{let f=l.replace(/[\r\n]+/gu," ").replace(/\s+/gu," ").trim().slice(-400);if(!(!f||f===c)){c=f;try{n.onProgress?.({step:"dependencies",message:f});}catch{}}},d=await he({command:i?.execPath??process.execPath,args:r,cwd:e,env:ai(e,i),runner:n.runner,signal:n.signal,timeoutMs:n.timeoutMs??Bn,noOutputTimeoutMs:n.noOutputTimeoutMs??zn,onTimeoutCode:"DEPS_TIMEOUT",step:"dependencies",onOutput:a});if(d.error!==void 0||d.status!==0)throw si(d);return {state:"done"}}var di=Bn,li=zn;var ce=class extends Error{constructor(t,i=t,o){super(i);this.code=t;this.currentRevision=o;}code;currentRevision;name="UiRuntimeError"};var ui=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,fi=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i,pi=/<\/?[A-Za-z][^>]*>/,mi=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,Ii=/^(?:https?|file|ftp|ws|wss):\/\//i;function ke(e){return ui.test(e)||fi.test(e)}function C(){throw new ce("INPUT_INVALID","JSON value is not projection-safe")}function yi(e){let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var Ai=8,gi=4;function Le(e,n,t,i,o,r){if(n>i&&C(),e===null||typeof e=="string"||typeof e=="boolean")return typeof e=="string"&&(pi.test(e)||Ii.test(e)&&!_i(o,r)||mi.test(e))&&C(),e;if(typeof e=="number")return Number.isFinite(e)||C(),e;(typeof e!="object"||e===void 0||typeof e=="function"||typeof e=="bigint")&&C();let c=e;t.has(c)&&C(),t.add(c);try{if(Array.isArray(e))return e.map(d=>Le(d,n+1,t,i,o,r));yi(c)||C();let a={};for(let[d,l]of Object.entries(e))ke(d)&&C(),a[d]=Le(l,n+1,t,i,[...o,d],r);return a}finally{t.delete(c);}}function Xn(e,n=0,t=[]){(!Number.isInteger(n)||n<0||n>gi)&&C(),(!Array.isArray(t)||t.some(o=>typeof o!="string"))&&C();let i=Le(e,0,new Set,Ai+n,[],t);return (i===null||Array.isArray(i)||typeof i!="object")&&C(),i}function Pe(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 _i(e,n){if(e.length===0)return false;let t=e.join(".");return n.some(i=>Pe(t,i))}function Yn(e){try{let n=JSON.stringify(e);return n===void 0&&C(),n}catch{C();}}function Ce(e){return Array.isArray(e)?e.map(Ce):e!==null&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,Ce(e[n])])):e}function Q(e){return Yn(Ce(e))}var Te=["text/plain","application/json"];var qn=["__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"],Ni=new Set(qn),hi=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,Pi=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i;function de(e){return Ni.has(e)||hi.test(e)||Pi.test(e)}var xe=/^[A-Za-z0-9_]+$/,le=/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/,ee=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,je=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,Fe=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,Ve=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/,ve=["blue","violet","emerald","amber","rose","sky","slate","indigo"],Ge=["inline","panel"];function He(e){return typeof e=="string"&&Te.includes(e)}new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});function Je(e){if(!$e(e))return false;let n=Object.keys(e);return !(n.some(t=>t!=="in"&&t!=="out")||n.length===0||Object.hasOwn(e,"in")&&!Ti(e.in)||Object.hasOwn(e,"out")&&!Si(e.out))}function Ti(e){return $e(e)?Object.keys(e).every(t=>t==="mediaType"||t==="required")&&Object.hasOwn(e,"mediaType")&&He(e.mediaType)&&(!Object.hasOwn(e,"required")||typeof e.required=="boolean"):false}function Si(e){return $e(e)?Object.keys(e).every(t=>t==="mediaType"||t==="range")&&Object.hasOwn(e,"mediaType")&&He(e.mediaType)&&(!Object.hasOwn(e,"range")||typeof e.range=="boolean"):false}function $e(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var bi=[5,15,30,60],Se=Object.freeze({min:15e3,max:6e5,default:3e5}),Wn=1;function Be(e){return bi.includes(e)}function ze(e){return Number.isSafeInteger(e)&&e>=Se.min&&e<=Se.max}var be=Object.freeze({min:6e4,max:18e5,default:6e5}),Zn=1;var Ui=["start","status","cancel"];function Ke(e){return Number.isSafeInteger(e)&&e>=be.min&&e<=be.max}function Xe(e){return Ui.includes(e)}function Qn(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.downloads!==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.downloads===void 0?{}:{downloads:e.downloads},...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=Xn(t);return crypto.createHash("sha256").update(Q(i)).digest("hex")}var w="dist/tools.json";var j="dist/main.mjs";var Ue="view.call",et="crewxImage",q="window";var Ri=["CREWX_APP_INSTANCE_ID","CREWX_THREAD_ID"];function nt(e){if(!Array.isArray(e)||e.length===0)return false;let n=new Set;for(let t of e){if(!Ri.some(i=>i===t)||n.has(t))return false;n.add(t);}return true}var wi=4096,it=16,Di=32,Li=512,Ci=new Set(["connectDomains","frameDomains","resourceDomains","baseUriDomains"]),ki=["localhost","local","internal","home.arpa","test","example","invalid","onion","lan","corp","home","intranet","private","localdomain"];var xi=/^(https|wss):\/\/([^/?#]+)$/i,ji=/^\[[^\]]+\](?::[0-9]+)?$/,Fi=/^[^:\[\]]+(?::[0-9]+)?$/,Vi=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/,vi=[[0,8],[1681915904,10],[167772160,8],[2130706432,8],[2851995648,16],[2886729728,12],[3221225984,24],[3227017984,24],[3232235520,16],[3323068416,15],[3325256704,24],[3405803776,24],[3758096384,4],[4026531840,4]],Ye=class extends Error{constructor(t){super(t);this.code=t;}code;name="UiPluginCspNormalizationError"};function E(e){throw new Ye(e)}function Gi(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 Hi(e,n){let t=Object.getOwnPropertyDescriptor(e,n);return (!t||!("value"in t))&&E("CSP_ORIGIN_INVALID"),t.value}function Oe(e,n){if(!Object.prototype.hasOwnProperty.call(e,n))return [];let t=Hi(e,n);Array.isArray(t)||E("CSP_ORIGIN_INVALID"),Reflect.ownKeys(t).some(r=>typeof r!="string"||r!=="length"&&!/^(?:0|[1-9][0-9]*)$/.test(r))&&E("CSP_ORIGIN_INVALID");let o=[];for(let r=0;r<t.length;r+=1)(!Object.prototype.hasOwnProperty.call(t,r)||typeof t[r]!="string")&&E("CSP_ORIGIN_INVALID"),o.push(t[r]);return Object.keys(t).length!==t.length&&E("CSP_ORIGIN_INVALID"),o}function Ji(e){let n;try{n=JSON.stringify(e);}catch{E("CSP_ORIGIN_INVALID");}return n===void 0&&E("CSP_ORIGIN_INVALID"),new TextEncoder().encode(n).byteLength}function ot(e,n){/\s|\\/u.test(e)&&E("CSP_ORIGIN_INVALID");let t=xi.exec(e);t||E("CSP_ORIGIN_INVALID");let i=t[1].toLowerCase(),o=t[2];(o.includes("@")||o.includes("%")||o.includes("*"))&&E("CSP_ORIGIN_INVALID"),(o.startsWith("[")?ji:Fi).test(o)||E("CSP_ORIGIN_INVALID"),i==="wss"&&n!=="connectDomains"&&E("CSP_ORIGIN_INVALID");let c;try{c=new URL(e);}catch{E("CSP_ORIGIN_INVALID");}(c.protocol!==`${i}:`||c.username!==""||c.password!==""||c.search!==""||c.hash!=="")&&E("CSP_ORIGIN_INVALID");let a=c.hostname.toLowerCase();if((!a||a.includes("%"))&&E("CSP_ORIGIN_INVALID"),!a.startsWith("[")){let l=a.endsWith(".")?a.slice(0,-1):a;(l.length===0||l.length>253)&&E("CSP_ORIGIN_INVALID"),l.split(".").some(m=>m.length>63||!Vi.test(m))&&E("CSP_ORIGIN_INVALID");}let d=c.origin;return (d==="null"||!d.startsWith(`${i}://`))&&E("CSP_ORIGIN_INVALID"),{origin:d,hostname:a}}function $i(e){let n=e.split(".").map(Number);return ((n[0]*256+n[1])*256+n[2])*256+n[3]}function rt(e,n,t){let i=4294967295<<32-t>>>0;return (e&i)===(n&i)}function ct(e){let n=$i(e);return rt(n,3221225472,24)?n!==3221225481&&n!==3221225482:vi.some(([t,i])=>rt(n,t,i))}function Bi(e){let n=e.indexOf("::"),t=(n<0?e:e.slice(0,n)).split(":").filter(Boolean),i=n<0?[]:e.slice(n+2).split(":").filter(Boolean);return (n<0?t:[...t,...Array(8-t.length-i.length).fill("0"),...i]).reduce((r,c)=>r<<16n|BigInt(Number.parseInt(c,16)),0n)}function zi(e){let n=Bi(e),t=Number(n>>112n),i=Number(n>>96n&0xffffn);if(n>>32n===0xffffn){let o=Number(n&0xffffffffn);return ct([o>>>24&255,o>>>16&255,o>>>8&255,o&255].join("."))}return t<8192||t>16383||t===8193&&i<=511||t===8193&&i===3512||t===8194||t===16383&&i<=4095}function Ki(e,n){let t=e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e,i=net.isIP(t);if(i===4)return ct(t);if(i===6)return zi(t);let o=e.toLowerCase().replace(/\.$/,"");return !o||!o.includes(".")||n.has(o)?true:ki.some(r=>o===r||o.endsWith(`.${r}`))}function st(e){return Object.freeze([...new Set(e.map(n=>n.origin))].sort())}function at(e){return JSON.stringify({baseUriDomains:[],connectDomains:e.connectDomains,declared:e.declared,frameDomains:e.frameDomains,resourceDomains:[]})}function dt(e,n={}){if(e===void 0){let u=at({declared:false,connectDomains:[],frameDomains:[]});return Object.freeze({declared:false,connectDomains:Object.freeze([]),frameDomains:Object.freeze([]),resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:crypto.createHash("sha256").update(u,"utf8").digest("hex")})}Gi(e)||E("CSP_ORIGIN_INVALID");let t=Reflect.ownKeys(e);t.some(u=>typeof u!="string")&&E("CSP_ORIGIN_INVALID"),t.some(u=>!Ci.has(u))&&E("CSP_AXIS_UNKNOWN");let i=Oe(e,"connectDomains"),o=Oe(e,"frameDomains"),r=Oe(e,"resourceDomains"),c=Oe(e,"baseUriDomains");(r.length>0||c.length>0)&&E("CSP_AXIS_UNSUPPORTED"),(Ji(e)>wi||i.length>it||o.length>it||i.length+o.length>Di||[...i,...o].some(u=>new TextEncoder().encode(u).byteLength>Li))&&E("CSP_LIMIT_EXCEEDED");let d=i.map(u=>ot(u,"connectDomains")),l=o.map(u=>ot(u,"frameDomains")),f=new Set((n.runtimeHostnames??[]).map(u=>u.toLowerCase().replace(/\.$/,"")));[...d,...l].some(u=>Ki(u.hostname,f))&&E("CSP_ORIGIN_FORBIDDEN");let m={declared:true,connectDomains:st(d),frameDomains:st(l)},y=at(m);return Object.freeze({...m,resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:crypto.createHash("sha256").update(y,"utf8").digest("hex")})}var Yi=1,qi=/^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$/,Wi=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,St=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,Zi=/<\/?[A-Za-z][^>]*>/,Qi=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,eo=/^(?:https?|file|ftp|ws|wss):\/\//i,no=/^\s*(?:javascript|data):/i,lt=/data:[^,\s]*,/i,to=/(?:https?|file|ftp|ws|wss):\/\//i,io=/javascript:/i,oo=/(?:^[\s]*|[\s"'(=])(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)(?=[^\s"'<>])[^\s"'<>]*/,ro=["manifestVersion","pluginId","definitionId","version","primitiveSet","activation","schema","layout"],so=["manifestVersion","pluginId","definitionId","version","name","description","entry","surfaces","size","stateProjection","actions"],ao=["_meta","icon","tone","entryHash","runtime","csp","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths","deviceFeatures","downloads","share","files","desktopOnly"],co=["actionId","capability","mutation","inputSchema","resultProjection","backend"],lo=["confirmation","dataInputs","content","schedule","job","jobAccess","_meta"],uo=["everyMinutes"],fo=["timeoutMs"],po=["deadlineMs"],mo=4*1024,Io=["type","handler"],yo=["type","command"],Ao=["env"],go=["type","entry"],_o=["path"],Eo=["hash"],No=/^[0-9a-f]{64}$/,ho=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/,Po=/[\r\n]/,To=16,So=16,bo=32,Uo=/^[a-z][A-Za-z0-9]{0,31}$/,Oo=["card-shell","meta-banner","heading","labeled-text","step-flow","text-list"],B=class e extends Error{constructor(t,i=t,o,r){super(i);this.code=t;this.path=o;this.rule=r;}code;path;rule;name="UiPluginValidationError";withPathPrefix(t){return new e(this.code,this.message,fe(t,this.path),this.rule)}};function fe(e,n){return n===void 0||n===""?e:e===""?n:n.startsWith("[")?`${e}${n}`:`${e}.${n}`}function s(e,n=e,t,i){throw new B(e,n,t,i)}function g(e,n){try{return n()}catch(t){throw t instanceof B?t.withPathPrefix(e):t}}function N(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 p(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Ro(e,n){let t={};for(let[i,o]of Object.entries(e))n.includes(i)||(t[i]=o);return t}function h(e,n,t=[]){let i=new Set([...n,...t]),o=Object.keys(e).find(c=>!i.has(c));o!==void 0&&s("MANIFEST_INVALID","MANIFEST_INVALID",o,"unknown-key");let r=n.find(c=>!p(e,c));r!==void 0&&s("MANIFEST_INVALID","MANIFEST_INVALID",r,"missing-key");}function on(e,n=false,t=false,i=false){return Zi.test(e)||!i&&eo.test(e)||Qi.test(e)||t&&lt.test(e)||no.test(e)&&!(n&&/^\s*data:/i.test(e)&&!lt.test(e))}function Me(e,n=new Set,t=0,i=false,o=false,r=""){if(typeof e=="string"){on(e,i,o)&&s("UNSAFE_VALUE","UNSAFE_VALUE",r,"unsafe-value");return}if(!(e===null||typeof e!="object")){(t>8||n.has(e))&&s("MANIFEST_INVALID","MANIFEST_INVALID",r),n.add(e);try{if(Array.isArray(e)){e.forEach((c,a)=>Me(c,n,t+1,!1,!1,fe(r,`[${a}]`)));return}N(e)||s("MANIFEST_INVALID","MANIFEST_INVALID",r);for(let[c,a]of Object.entries(e))Me(a,n,t+1,i&&t===0&&(c==="name"||c==="description"),o,fe(r,c));}finally{n.delete(e);}}}function J(e,n){let t=e[n];return typeof t!="string"&&s("MANIFEST_INVALID"),t}function F(e,n,t){let i=e[n];return (!Number.isSafeInteger(i)||i<t)&&s("MANIFEST_INVALID"),i}function qe(e){return Wi.test(e)||s("MANIFEST_INVALID"),e}function ne(e){return qi.test(e)||s("TOKEN_INVALID"),e}function Mo(e){return St.test(e)||s("MANIFEST_INVALID"),e}function wo(e){N(e)||s("MANIFEST_INVALID");let n={};for(let[t,i]of Object.entries(e)){let o=Mo(t);N(i)||s("MANIFEST_INVALID");let r=i.type;if(r==="text"){h(i,["type","maxLength"]),n[o]={type:r,maxLength:F(i,"maxLength",1)};continue}if(r==="text-list"){h(i,["type","max","itemMaxLength"]),n[o]={type:r,max:F(i,"max",0),itemMaxLength:F(i,"itemMaxLength",1)};continue}if(r==="step-list"){h(i,["type","min","max","labelMaxLength","detailMaxLength"]);let c=F(i,"min",0),a=F(i,"max",1);c>a&&s("MANIFEST_INVALID"),n[o]={type:r,min:c,max:a,labelMaxLength:F(i,"labelMaxLength",1),detailMaxLength:F(i,"detailMaxLength",1)};continue}typeof r=="string"&&s("SCHEMA_TYPE_UNSUPPORTED"),s("MANIFEST_INVALID");}return n}function Do(e,n,t){let i=e[n];(!i||i.type!==t)&&s("MANIFEST_INVALID");}function Re(e,n,t){let i=J(e,"field");return St.test(i)||s("MANIFEST_INVALID"),Do(n,i,t),i}function Lo(e,n){N(e)||s("MANIFEST_INVALID");let t=e.primitive;switch(typeof t!="string"&&s("MANIFEST_INVALID"),Oo.includes(t)||s("PRIMITIVE_UNKNOWN"),t){case "card-shell":return h(e,["primitive"]),{primitive:t};case "meta-banner":return h(e,["primitive","badgeToken","noticeToken"]),{primitive:t,badgeToken:ne(J(e,"badgeToken")),noticeToken:ne(J(e,"noticeToken"))};case "heading":return h(e,["primitive","field"]),{primitive:t,field:Re(e,n,"text")};case "labeled-text":return h(e,["primitive","titleToken","field","variant"]),e.variant!=="callout"&&s("MANIFEST_INVALID"),{primitive:t,titleToken:ne(J(e,"titleToken")),field:Re(e,n,"text"),variant:"callout"};case "step-flow":return h(e,["primitive","titleToken","field"]),{primitive:t,titleToken:ne(J(e,"titleToken")),field:Re(e,n,"step-list")};case "text-list":{h(e,["primitive","titleToken","field"],["emptyToken","hideWhenEmpty"]);let i={primitive:t,titleToken:ne(J(e,"titleToken")),field:Re(e,n,"text-list")};return p(e,"emptyToken")&&(i.emptyToken=ne(J(e,"emptyToken"))),p(e,"hideWhenEmpty")&&(typeof e.hideWhenEmpty!="boolean"&&s("MANIFEST_INVALID"),i.hideWhenEmpty=e.hideWhenEmpty),i}}return s("MANIFEST_INVALID")}function Co(e,n){return Array.isArray(e)||s("MANIFEST_INVALID"),e.map(t=>Lo(t,n))}function S(e="v2 manifest exceeds a contract limit",n,t){return s("LIMIT_EXCEEDED",e,n,t)}function ut(e,n){return (typeof e!="string"||e.length===0||e.length>4096||e.trim().length===0||ho.test(e)||Po.test(e))&&s("MANIFEST_INVALID",`${n} is invalid`),(on(e,true,true)||to.test(e)||io.test(e)||oo.test(e))&&s("UNSAFE_VALUE",`${n} contains an unsafe value`),e}function We(e,n){return (typeof e!="string"||!ee.test(e))&&s("MANIFEST_INVALID",`${n} is invalid`),e}function ko(e){return (typeof e!="string"||!je.test(e)||e==="*"||e==="all")&&s("MANIFEST_INVALID","action capability is invalid"),e}function bt(e){return (typeof e!="string"||!No.test(e))&&s("MANIFEST_INVALID","resource hash is invalid"),e}function Ze(e,n=new Set,t=0,i=""){if(typeof e=="string"){e.length>4096&&S("v2 manifest string is too long",i,"string-too-long");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||s("MANIFEST_INVALID","v2 manifest contains a non-finite number",i,"non-finite-number");return}(e===void 0||typeof e=="function"||typeof e=="bigint")&&s("MANIFEST_INVALID","v2 manifest contains a non-JSON value",i,"non-json-value"),typeof e!="object"&&s("MANIFEST_INVALID","MANIFEST_INVALID",i),t>8&&S("v2 manifest nesting is too deep",i,"too-deep"),n.has(e)&&s("MANIFEST_INVALID","v2 manifest contains a cycle",i,"cycle"),n.add(e);try{if(Array.isArray(e)){e.length>128&&S("v2 manifest array is too long",i,"array-too-long"),e.forEach((o,r)=>Ze(o,n,t+1,fe(i,`[${r}]`)));return}N(e)||s("MANIFEST_INVALID","v2 manifest contains a non-plain object",i,"non-plain-object");for(let[o,r]of Object.entries(e))Ze(r,n,t+1,fe(i,o));}finally{n.delete(e);}}}function Ut(e){return (typeof e!="string"||e.length>4096||!le.test(e))&&(typeof e=="string"&&e.length>4096&&S("projection path is too long"),s("MANIFEST_INVALID","projection paths must be canonical exact paths")),e.split(".").some(t=>de(t)||t===et)&&s("MANIFEST_INVALID","projection paths cannot address reserved state keys"),e}function Qe(e){N(e)||s("MANIFEST_INVALID","projection policy must be an object"),h(e,["allow"]),Array.isArray(e.allow)||s("MANIFEST_INVALID","projection allow must be an array"),e.allow.length>128&&S("projection allowlist is too long");let n=[],t=new Set;for(let i of e.allow){let o=Ut(i);t.has(o)&&s("MANIFEST_INVALID","projection allowlist contains a duplicate path"),t.add(o),n.push(o);}return {allow:n}}function xo(e,n){if(e===void 0)return;Array.isArray(e)||s("MANIFEST_INVALID","dataPaths must be an array"),e.length>To&&S("dataPaths exceed the v2 limit");let t=[],i=new Set;for(let o of e){let r=Ut(o);i.has(r)&&s("MANIFEST_INVALID","dataPaths contain a duplicate path"),n.some(c=>Pe(r,c))||s("MANIFEST_INVALID","dataPaths must be projection-allowed"),i.add(r),t.push(r);}return t}function jo(e){Array.isArray(e)||s("MANIFEST_INVALID","deviceFeatures must be an array",void 0,"array"),e.length>So&&s("MANIFEST_INVALID","deviceFeatures allow at most 16 names",void 0,"too-many-items");let n=[],t=new Set;for(let[i,o]of e.entries()){let r=`[${i}]`;typeof o!="string"&&s("MANIFEST_INVALID","a device feature name must be a string",r,"string"),o.length===0&&s("MANIFEST_INVALID","a device feature name must not be empty",r,"empty"),o.length>bo&&s("MANIFEST_INVALID","a device feature name is at most 32 characters",r,"too-long"),Uo.test(o)||s("MANIFEST_INVALID","a device feature name starts with a lowercase letter and holds only letters and digits",r,"format"),t.has(o)&&s("MANIFEST_INVALID","deviceFeatures contain a duplicate name",r,"duplicate-item"),t.add(o),n.push(o);}return n}function Fo(e){if(e!==false)return e!==true&&s("MANIFEST_INVALID","downloads must be true or false",void 0,"boolean"),true}function Vo(e){return typeof e!="boolean"&&s("MANIFEST_INVALID","desktopOnly must be true or false",void 0,"boolean"),e}function vo(e){return (!N(e)||e.view!==true||Object.keys(e).some(n=>n!=="view"&&n!=="entry"))&&s("MANIFEST_INVALID",'share must be { "view": true } or { "view": true, "entry": "<path>" }',void 0,"share-shape"),p(e,"entry")?{view:true,entry:Ho(e.entry)}:{view:true}}var ft=200,pt=3,Go=/^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;function Ho(e){typeof e!="string"&&s("MANIFEST_INVALID","share.entry must be a string","entry","entry-shape");let n=(i,o)=>s("MANIFEST_INVALID",`share.entry ${o}`,"entry",i);e.length===0&&n("empty","must not be empty"),e.length>ft&&n("too-long",`must be at most ${ft} characters`),e.startsWith("/")&&n("absolute","must be relative to the App folder");let t=e.split("/");t.length>pt&&n("too-many-segments",`must have at most ${pt} segments`);for(let i of t)i.length===0&&n("empty-segment","must not contain an empty segment"),(i==="."||i==="..")&&n("dot-segment",'must not contain "." or ".." segments'),Go.test(i)||n("segment-shape",'segments start with an ASCII letter or digit, then use only letters, digits, ".", "_" and "-"');return t[t.length-1].endsWith(".html")||n("extension","must name a file ending in .html"),e}function Jo(e){return (!N(e)||Object.keys(e).length!==1||typeof e.root!="string")&&s("MANIFEST_INVALID",'files must be exactly { "root": "<workspace folder>" }',void 0,"files-shape"),{root:Xo(e.root)}}var mt=200,$o=2,It=4,yt=100,Bo=/^[\p{L}\p{N}][\p{L}\p{N}\p{M}_-]*$/u,zo=[".git",".crewx","node_modules","apps","skills"],Ko=/[\u0000-\u001f\u007f-\u009f\\:<>"|?*]/;function Xo(e){let n=e.normalize("NFC"),t=(r,c)=>s("MANIFEST_INVALID",`files.root ${c}`,"root",r);n.length===0&&t("empty","must not be empty"),Ko.test(n)&&t("forbidden-character","must not contain control characters, backslash or colon"),(n.startsWith("/")||n.startsWith("~"))&&t("absolute","must be relative to the workspace"),Array.from(n).length>mt&&t("too-long",`must be at most ${mt} characters`);let i=n.split("/"),o=i[0].toLowerCase().replace(/[. ]+$/,"");zo.includes(o)&&t("reserved-folder","must not start in an App code folder or a tool folder"),i.length<$o&&t("too-shallow","must name a folder inside a top-level folder, such as docs/trips"),i.length>It&&t("too-many-segments",`must have at most ${It} segments`);for(let r of i)r.length===0&&t("empty-segment","must not contain an empty segment"),(r==="."||r==="..")&&t("dot-segment",'must not contain "." or ".." segments'),Array.from(r).length>yt&&t("segment-too-long",`segments must be at most ${yt} characters`),Bo.test(r)||t("segment-shape",'segments must start with a letter or digit and contain only letters, digits, combining marks, "_" or "-"');return n}function te(e,n,t=Number.MAX_SAFE_INTEGER){return (!Number.isSafeInteger(e)||e<0||e>t)&&s("MANIFEST_INVALID",`${n} is invalid`),e}function At(e,n){return (typeof e!="number"||!Number.isFinite(e))&&s("MANIFEST_INVALID",`${n} is invalid`),e}function en(e,n=0,t=new Set){if(typeof e=="string")return (e.length>4096||on(e))&&s("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)||s("MANIFEST_INVALID","schema enum contains a non-finite number"),e;(n>8||typeof e!="object"||e===void 0)&&S("schema enum is too deep"),t.has(e)&&s("MANIFEST_INVALID","schema enum contains a cycle"),t.add(e);try{if(Array.isArray(e))return e.length>128&&S("schema enum array is too long"),e.map(o=>en(o,n+1,t));N(e)||s("MANIFEST_INVALID","schema enum contains a non-plain object");let i={};for(let[o,r]of Object.entries(e))de(o)&&s("MANIFEST_INVALID","schema enum contains a reserved key"),i[o]=en(r,n+1,t);return i}finally{t.delete(e);}}function Yo(e,n){if(e===void 0)return;Array.isArray(e)||s("MANIFEST_INVALID","schema required must be an array"),e.length>64&&S("schema required list is too long");let t=[],i=new Set;for(let o of e)(typeof o!="string"||!le.test(o))&&s("MANIFEST_INVALID","schema required contains an invalid key"),o.length>4096&&S("schema required key is too long"),i.has(o)&&s("MANIFEST_INVALID","schema required contains a duplicate key"),n&&!Object.prototype.hasOwnProperty.call(n,o)&&s("MANIFEST_INVALID","schema required references an undeclared property"),i.add(o),t.push(o);return t}function qo(e,n){let t=n?le:xe;return e.length>4096&&S("schema property name is too long"),(!t.test(e)||e.split(".").some(i=>de(i)))&&s("MANIFEST_INVALID","schema property name is invalid"),e}function nn(e,n=0,t=false){N(e)||s("MANIFEST_INVALID","action inputSchema must be an object"),n>8&&S("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"&&s("SCHEMA_TYPE_UNSUPPORTED","action inputSchema type is unsupported"),s("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"),h(e,["type"],o.filter(a=>a!=="type"));let r={type:i};if(p(e,"enum")&&(Array.isArray(e.enum)||s("MANIFEST_INVALID","schema enum must be an array"),e.enum.length>128&&S("schema enum is too long"),r.enum=e.enum.map(a=>en(a))),i==="string"&&(p(e,"minLength")&&(r.minLength=te(e.minLength,"schema minLength",4096)),p(e,"maxLength")&&(r.maxLength=te(e.maxLength,"schema maxLength",4096)),r.minLength!==void 0&&r.maxLength!==void 0&&r.minLength>r.maxLength&&s("MANIFEST_INVALID","schema string length bounds are inverted")),(i==="number"||i==="integer")&&(p(e,"minimum")&&(r.minimum=At(e.minimum,"schema minimum")),p(e,"maximum")&&(r.maximum=At(e.maximum,"schema maximum")),r.minimum!==void 0&&r.maximum!==void 0&&r.minimum>r.maximum&&s("MANIFEST_INVALID","schema numeric bounds are inverted")),i==="array"&&(p(e,"minItems")&&(r.minItems=te(e.minItems,"schema minItems",128)),p(e,"maxItems")&&(r.maxItems=te(e.maxItems,"schema maxItems",128)),r.minItems!==void 0&&r.maxItems!==void 0&&r.minItems>r.maxItems&&s("MANIFEST_INVALID","schema array length bounds are inverted"),p(e,"items")&&(r.items=nn(e.items,n+1,false))),i==="object"){let a;if(p(e,"properties")){N(e.properties)||s("MANIFEST_INVALID","schema properties must be an object");let l=Object.entries(e.properties);l.length>64&&S("schema properties are too many"),a={};for(let[f,m]of l){let y=qo(f,t);a[y]=nn(m,n+1,false);}r.properties=a;}p(e,"minProperties")&&(r.minProperties=te(e.minProperties,"schema minProperties",64)),p(e,"maxProperties")&&(r.maxProperties=te(e.maxProperties,"schema maxProperties",64)),r.minProperties!==void 0&&r.maxProperties!==void 0&&r.minProperties>r.maxProperties&&s("MANIFEST_INVALID","schema object property bounds are inverted");let d=Yo(e.required,a);d!==void 0&&(r.required=d),p(e,"additionalProperties")&&(e.additionalProperties!==false&&s("MANIFEST_INVALID","schema additionalProperties must be false"),r.additionalProperties=false);}let c=JSON.stringify(r);return (c===void 0||Buffer.byteLength(c,"utf8")>2097152)&&S("action inputSchema subtree is too large"),r}function Wo(e){let n=nn(e,0,true);return (n.type!=="object"||!n.properties)&&s("MANIFEST_INVALID","action inputSchema must declare object properties"),n}function Zo(e){if(N(e)||s("MANIFEST_INVALID","action backend must be an object"),e.type==="core"){h(e,Io);let n=e.handler;return (typeof n!="string"||!Fe.test(n))&&s("MANIFEST_INVALID","core backend handler is invalid"),{type:"core",handler:n}}if(e.type==="skill"&&p(e,"entry"))return h(e,go),e.entry!==j&&s("MANIFEST_INVALID",`skill backend entry must be ${j}`),{type:"skill",entry:j};if(e.type==="skill"){h(e,yo,Ao),(!Array.isArray(e.command)||e.command.length===0||e.command.length>16)&&s("MANIFEST_INVALID","skill backend command is invalid");let n=[];for(let i of e.command)(typeof i!="string"||i.length===0||i.length>256||!Ve.test(i))&&s("MANIFEST_INVALID","skill backend command token is invalid"),n.push(i);let t=p(e,"env")?or(e.env):void 0;return {type:"skill",command:n,...t===void 0?{}:{env:t}}}s("MANIFEST_INVALID","action backend type is unsupported");}function Qo(e){N(e)||s("MANIFEST_INVALID","action must be an object"),h(e,co,lo),p(e,"_meta")&&g("_meta",()=>Ot(e._meta));let n=g("actionId",()=>We(e.actionId,"actionId"));ke(n)&&s("MANIFEST_INVALID",`actionId "${n}" is not projection-safe`,"actionId");let t=g("capability",()=>ko(e.capability)),i=e.mutation;typeof i!="boolean"&&s("MANIFEST_INVALID","action mutation must be boolean","mutation");let o=g("inputSchema",()=>Wo(e.inputSchema)),r;if(p(e,"dataInputs")){Array.isArray(e.dataInputs)||s("MANIFEST_INVALID","action dataInputs must be an array","dataInputs");let u=o.properties,O=new Set,z=[];for(let A of e.dataInputs)(typeof A!="string"||!p(u,A)||O.has(A))&&s("MANIFEST_INVALID","action dataInputs must be unique declared properties","dataInputs"),O.add(A),z.push(A);r=z;}let c=g("resultProjection",()=>Qe(e.resultProjection)),a=g("backend",()=>Zo(e.backend)),d;p(e,"content")&&((a.type!=="skill"||!Je(e.content))&&s("MANIFEST_INVALID","action content declaration is invalid","content"),d=rr(e.content));let l;if(p(e,"confirmation")){let u=e.confirmation;u!=="none"&&u!=="native"&&s("MANIFEST_INVALID","action confirmation is invalid","confirmation"),l=u;}let f;p(e,"schedule")&&(f=g("schedule",()=>ir(e.schedule,{backend:a,inputSchema:o,hasContent:d!==void 0,hasDataInputs:r!==void 0,confirmation:l})));let m;p(e,"job")&&(f!==void 0&&s("MANIFEST_INVALID","an action is either the scheduled run or a job, not both","job"),m=g("job",()=>tr(e.job,{backend:a,inputSchema:o,hasContent:d!==void 0,hasDataInputs:r!==void 0,confirmation:l})));let y;return p(e,"jobAccess")&&(m!==void 0&&s("MANIFEST_INVALID","an action is either the job or a job control, not both","jobAccess"),y=g("jobAccess",()=>nr(e.jobAccess,{backend:a,hasContent:d!==void 0}))),{actionId:n,capability:t,mutation:i,inputSchema:o,resultProjection:c,backend:a,...d===void 0?{}:{content:d},...r===void 0?{}:{dataInputs:r},...l===void 0?{}:{confirmation:l},...f===void 0?{}:{schedule:f},...m===void 0?{}:{job:m},...y===void 0?{}:{jobAccess:y}}}function er(e,n,t){e.backend.type!=="core"||e.backend.handler!==Ue||((n??q)!==q&&s("MANIFEST_INVALID","view.call is only available to screen Apps",`${t}.backend.handler`),e.mutation!==false&&s("MANIFEST_INVALID","view.call must be read-only",`${t}.mutation`),e.confirmation!=="none"&&s("MANIFEST_INVALID","view.call requires confirmation none",`${t}.confirmation`),(e.content!==void 0||e.schedule!==void 0||e.job!==void 0||e.jobAccess!==void 0)&&s("MANIFEST_INVALID","view.call cannot declare content, jobs, or schedules",t),e.resultProjection===void 0&&s("MANIFEST_INVALID","view.call requires resultProjection",`${t}.resultProjection`));}function nr(e,n){return (n.backend.type!=="skill"||!("entry"in n.backend)||n.backend.entry!==j)&&s("MANIFEST_INVALID","jobAccess needs a tool-mode action","jobAccess"),n.hasContent&&s("MANIFEST_INVALID","a job control action takes no content","jobAccess"),(!Array.isArray(e)||e.length===0)&&s("MANIFEST_INVALID","jobAccess must list at least one operation","jobAccess"),(new Set(e).size!==e.length||!e.every(Xe))&&s("MANIFEST_INVALID","jobAccess must name each operation once: start, status or cancel","jobAccess"),Object.freeze([...e])}function tr(e,n){(n.backend.type!=="skill"||!("entry"in n.backend)||n.backend.entry!==j)&&s("MANIFEST_INVALID","job needs a tool-mode action","job"),(n.hasContent||n.hasDataInputs||n.confirmation!==void 0&&n.confirmation!=="none")&&s("MANIFEST_INVALID","a job action takes no content, dataInputs or native confirmation","job"),(n.inputSchema.required??[]).length>0&&s("MANIFEST_INVALID","a job action input must accept {}","inputSchema.required"),N(e)||s("MANIFEST_INVALID","job must be an object","job"),h(e,[],po);let t=p(e,"deadlineMs")?e.deadlineMs:be.default;return Ke(t)||s("MANIFEST_INVALID","job deadlineMs is invalid","job.deadlineMs"),{deadlineMs:t}}function ir(e,n){(n.backend.type!=="skill"||!("entry"in n.backend)||n.backend.entry!==j)&&s("MANIFEST_INVALID","schedule needs a tool-mode action","schedule"),(n.hasContent||n.hasDataInputs||n.confirmation!==void 0&&n.confirmation!=="none")&&s("MANIFEST_INVALID","a scheduled action takes no content, dataInputs or native confirmation","schedule"),(n.inputSchema.required??[]).length>0&&s("MANIFEST_INVALID","a scheduled action input must accept {}","inputSchema.required"),N(e)||s("MANIFEST_INVALID","schedule must be an object","schedule"),h(e,uo,fo),Be(e.everyMinutes)||s("MANIFEST_INVALID","schedule everyMinutes is invalid","schedule.everyMinutes");let t=p(e,"timeoutMs")?e.timeoutMs:Se.default;return ze(t)||s("MANIFEST_INVALID","schedule timeoutMs is invalid","schedule.timeoutMs"),{everyMinutes:e.everyMinutes,timeoutMs:t}}function or(e){return nt(e)||s("MANIFEST_INVALID","skill backend env is invalid"),Object.freeze([...e])}function rr(e){return Object.freeze({...e.in===void 0?{}:{in:Object.freeze({...e.in})},...e.out===void 0?{}:{out:Object.freeze({...e.out})}})}function sr(e){return N(e)||s("INITIAL_STATE_INVALID","initialState must be an object"),h(e,_o,Eo),e.path!=="ui/state.json"&&s("MANIFEST_INVALID","initialState path is not fixed"),p(e,"hash")?{path:"ui/state.json",hash:bt(e.hash)}:{path:"ui/state.json"}}function ar(e){let n=["wasm","terminal","htmlDocuments","appBrowser"];return (!N(e)||Object.keys(e).length===0||Object.keys(e).some(t=>!n.includes(t)||e[t]!==true))&&s("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}:{},...e.appBrowser===true?{appBrowser:true}:{}}}function cr(e,n){let t;try{t=dt(e);}catch(i){let o=i!==null&&typeof i=="object"&&"code"in i&&typeof i.code=="string"?i.code:"CSP_ORIGIN_INVALID";return s("MANIFEST_INVALID",o,void 0,o.toLowerCase().replace(/_/g,"-"))}if(t.frameDomains.length>0&&s("MANIFEST_INVALID","external origins in csp are not enabled in this rollout",void 0,"csp-not-enabled"),t.connectDomains.length!==0)return n?.terminal===true&&s("MANIFEST_INVALID","runtime.terminal cannot be combined with csp.connectDomains","connectDomains","terminal-with-connect-domains"),Object.freeze({connectDomains:t.connectDomains})}function dr(e,n){Me(N(e)?Ro(e,["csp","downloads","files","share"]):e,new Set,0,true,true),Ze(e),N(e)||s("MANIFEST_INVALID"),h(e,so,ao),p(e,"_meta")&&g("_meta",()=>Ot(e._meta)),e.manifestVersion!==2&&s("MANIFEST_INVALID");let t;p(e,"runtime")&&(t=g("runtime",()=>ar(e.runtime)));let i;p(e,"csp")&&(i=g("csp",()=>cr(e.csp,t)));let o=g("pluginId",()=>We(e.pluginId,"pluginId")),r=g("definitionId",()=>We(e.definitionId,"definitionId")),c=g("version",()=>F(e,"version",1)),a=g("name",()=>ut(e.name,"name")),d=g("description",()=>ut(e.description,"description")),l;p(e,"icon")&&((typeof e.icon!="string"||!/^[a-z][a-z0-9-]{0,63}$/.test(e.icon))&&s("MANIFEST_INVALID","icon is invalid","icon"),l=e.icon);let f;p(e,"tone")&&((typeof e.tone!="string"||!ve.includes(e.tone))&&s("MANIFEST_INVALID","tone is invalid","tone"),f=e.tone),e.entry!=="ui/index.html"&&s("MANIFEST_INVALID","entry path is not fixed","entry","fixed-value");let m;p(e,"entryHash")&&(m=g("entryHash",()=>bt(e.entryHash)));let y;p(e,"initialState")&&(y=g("initialState",()=>sr(e.initialState)));let u;p(e,"usage")&&(e.usage!=="card"&&e.usage!=="window"&&s("MANIFEST_INVALID","usage is invalid","usage"),u=e.usage);let O;p(e,"detailPanel")&&(typeof e.detailPanel!="boolean"&&s("MANIFEST_INVALID","detailPanel is invalid","detailPanel"),O=e.detailPanel);let z;if(p(e,"displayModes")){((u??q)!==q||!Array.isArray(e.displayModes)||e.displayModes.length===0)&&s("MANIFEST_INVALID","displayModes are only valid for window Apps","displayModes");let x=new Set(["inline","floating","focused"]);(new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(_e=>typeof _e!="string"||!x.has(_e)))&&s("MANIFEST_INVALID","displayModes are invalid","displayModes"),z=e.displayModes;}(u??q)===q&&O!==void 0&&s("MANIFEST_INVALID","detailPanel is card-only","detailPanel");let A=n.mode??"local";A!=="local"&&A!=="installed"&&A!=="published"&&s("MANIFEST_INVALID","manifest mode is invalid"),A!=="local"&&m===void 0&&s("MANIFEST_INVALID","installed manifests require entryHash","entryHash","required-when-installed"),A!=="local"&&y!==void 0&&y.hash===void 0&&s("MANIFEST_INVALID","installed manifests require initialState.hash","initialState.hash","required-when-installed"),(!Array.isArray(e.surfaces)||e.surfaces.length===0)&&s("MANIFEST_INVALID","surfaces are invalid","surfaces"),e.surfaces.length>2&&S("surfaces exceed the v2 limit","surfaces","too-many-items");let In=[],yn=new Set;for(let x of e.surfaces)(typeof x!="string"||!Ge.includes(x))&&s("MANIFEST_INVALID","surface is unsupported","surfaces"),yn.has(x)&&s("MANIFEST_INVALID","surfaces contain a duplicate","surfaces","duplicate-item"),yn.add(x),In.push(x);N(e.size)||s("MANIFEST_INVALID","size must be an object","size"),g("size",()=>h(e.size,["height"]));let An=g("size",()=>F(e.size,"height",1));An>720&&S("size.height exceeds the v2 limit","size.height","too-large");let Ae=g("stateProjection",()=>Qe(e.stateProjection)),ge=e.summaryProjection===void 0?void 0:g("summaryProjection",()=>Qe(e.summaryProjection));ge!==void 0&&ge.allow.some(x=>!Ae.allow.includes(x))&&s("MANIFEST_INVALID","summaryProjection must be a subset of stateProjection.allow","summaryProjection");let gn=g("dataPaths",()=>xo(e.dataPaths,Ae.allow)),_n=p(e,"deviceFeatures")?g("deviceFeatures",()=>jo(e.deviceFeatures)):void 0,En=p(e,"downloads")?g("downloads",()=>Fo(e.downloads)):void 0,Nn=p(e,"share")?g("share",()=>vo(e.share)):void 0,hn=p(e,"files")?g("files",()=>Jo(e.files)):void 0,Pn=p(e,"desktopOnly")?g("desktopOnly",()=>Vo(e.desktopOnly)):void 0;Array.isArray(e.actions)||s("MANIFEST_INVALID","actions must be an array","actions"),e.actions.length>32&&S("actions exceed the v2 limit","actions","too-many-items");let Tn=[],Sn=new Set,bn=0,Un=0;for(let[x,_e]of e.actions.entries()){let Y=`actions[${x}]`,H=g(Y,()=>Qo(_e));if(er(H,u,Y),Sn.has(H.actionId)&&s("MANIFEST_INVALID","actions contain a duplicate actionId",`${Y}.actionId`,"duplicate-item"),H.schedule!==void 0&&(bn+=1,bn>Wn&&s("MANIFEST_INVALID","an App declares at most one scheduled action",`${Y}.schedule`,"duplicate-item")),H.job!==void 0&&(Un+=1,Un>Zn&&s("MANIFEST_INVALID","an App declares at most one job action",`${Y}.job`,"duplicate-item")),H.backend.type==="core"&&H.backend.handler==="state.set"){H.mutation||s("MANIFEST_INVALID","state.set actions must be mutations",`${Y}.mutation`);for(let Gt of Object.keys(H.inputSchema.properties))Ae.allow.includes(Gt)||s("MANIFEST_INVALID","state.set input paths must be projection-allowed",`${Y}.inputSchema.properties`);}Sn.add(H.actionId),Tn.push(H);}return {manifestVersion:2,pluginId:o,definitionId:r,version:c,name:a,description:d,...l===void 0?{}:{icon:l},...f===void 0?{}:{tone:f},entry:"ui/index.html",...m===void 0?{}:{entryHash:m},...t===void 0?{}:{runtime:t},...i===void 0?{}:{csp:i},...y===void 0?{}:{initialState:y},...u===void 0?{}:{usage:u},...O===void 0?{}:{detailPanel:O},...z===void 0?{}:{displayModes:z},surfaces:In,size:{height:An},stateProjection:Ae,...ge===void 0?{}:{summaryProjection:ge},...gn===void 0?{}:{dataPaths:gn},..._n===void 0?{}:{deviceFeatures:_n},...En===void 0?{}:{downloads:En},...Nn===void 0?{}:{share:Nn},...hn===void 0?{}:{files:hn},...Pn===void 0?{}:{desktopOnly:Pn},actions:Tn}}function Ot(e){N(e)||s("MANIFEST_INVALID","_meta must be an object");let n=JSON.stringify(e);(n===void 0||Buffer.byteLength(n,"utf8")>mo)&&S("_meta exceeds the 4 KiB limit",void 0,"meta-too-large");}function lr(e){let n={},t={};for(let r of e.actions){n[r.actionId]={capabilities:[r.capability],inputKeys:Object.keys(r.inputSchema.properties??{}),...r.backend.type==="core"&&r.backend.handler===Ue?{mutation:r.mutation}:{},...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.schedule===void 0?{}:{schedule:r.schedule},...r.job===void 0?{}:{job:r.job},...r.jobAccess===void 0?{}:{jobAccess:r.jobAccess},...r.backend.type!=="skill"||r.backend.env===void 0?{}:{env:r.backend.env}};let c=r.backend.type==="skill"||r.backend.type==="core"&&(r.backend.handler==="state.set"||r.backend.handler===Ue);t[r.actionId]={actionId:r.actionId,mutation:r.mutation,backend:r.backend,launchPolicy:c?"allowed":"denied",...c?{}:{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},...e.downloads===void 0?{}:{downloads:e.downloads},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 ur(e,n={}){Me(e),N(e)||s("MANIFEST_INVALID"),h(e,ro),e.manifestVersion!==1&&s("MANIFEST_INVALID");let t=qe(J(e,"pluginId")),i=qe(J(e,"definitionId")),o=F(e,"version",1),r=F(e,"primitiveSet",1),c=n.supportedPrimitiveSet??Yi;(!Number.isSafeInteger(c)||c<1)&&s("MANIFEST_INVALID"),r>c&&s("PRIMITIVE_SET_UNSUPPORTED"),N(e.activation)||s("MANIFEST_INVALID"),h(e.activation,["kind","language"]),e.activation.kind!=="fenced-code"&&s("MANIFEST_INVALID");let a=qe(J(e.activation,"language")),d=wo(e.schema),l=Co(e.layout,d);return {manifestVersion:1,pluginId:t,definitionId:i,version:o,primitiveSet:r,activation:{kind:"fenced-code",language:a},schema:d,layout:l}}function fr(e,n={}){return N(e)||s("MANIFEST_INVALID"),Object.hasOwn(e,"lineage")&&s("MANIFEST_INVALID","lineage is only allowed in product bundle indexes"),e.manifestVersion===2?dr(e,n):ur(e,n)}function me(e,n={}){try{return fr(e,n)}catch(t){if(t instanceof B)throw t;return s("MANIFEST_INVALID")}}function rn(e,n={}){let t=me(e,n);return t.manifestVersion===2?lr(t):t}var R="manifest.json",W="ui-plugin.json",oe=[R,W];var sn="0.3",Z="dev.crewx",un=Object.freeze(["manifest_version","name","display_name","version","description","long_description","author","repository","homepage","documentation","support","icon","icons","screenshots","localization","server","tools","tools_generated","prompts","prompts_generated","keywords","license","privacy_policies","compatibility","user_config","_meta"]),fn=Object.freeze(["manifest_version","name","display_name","version","description","_meta"]),Dt=Object.freeze(un.filter(e=>e!=="server"&&!fn.includes(e))),an=Object.freeze(["entry","surfaces","size","stateProjection","actions"]),Lt=Object.freeze(["definitionId","definitionVersion","icon","tone","entryHash","runtime","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths","csp","deviceFeatures","downloads","share","files","desktopOnly"]),pr=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,mr=256,Ir=/<\/?[A-Za-z][^>]*>/,yr=/^\s*javascript:/i,Ar=/data:[^,\s]*,/i;function Ct(e){return typeof e=="string"&&e.length<=mr&&pr.test(e)}var $=class extends Error{constructor(t,i){super(`${t}: ${i.path||"<file>"} (${i.rule})`);this.code=t;this.reason=i;}code;reason};function I(e,n,t,i,o){throw new $(e,{path:n,rule:t,...i===void 0?{}:{message:i},...o===void 0?{}:{file:o}})}function M(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 b(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function G(e){let n=`_meta["${Z}"]`;return e===void 0||e===""?n:e.startsWith("[")?`${n}${e}`:`${n}.${e}`}function gr(e){return e.toLowerCase().replace(/_/g,"-")}function _r(e){if(e===void 0||e==="")return "";let n=/^([^.[]+)(.*)$/.exec(e);if(!n)return G(e);let[,t,i]=n;switch(t){case "pluginId":return `name${i}`;case "name":return `display_name${i}`;case "description":return `description${i}`;case "_meta":return `_meta${i}`;case "version":return G("definitionVersion");case "definitionId":return G("definitionId");default:return G(`${t}${i}`)}}function kt(e,n,t){return {path:t(e.path),rule:e.rule??gr(e.code),...e.message!==e.code?{message:e.message}:{},file:n}}function xt(e){return JSON.parse(JSON.stringify(e))}function cn(e,n,t=0,i=new Set){if(typeof e=="string"){e.length>4096&&I("LIMIT_EXCEEDED",n,"string-too-long"),(Ir.test(e)||yr.test(e)||Ar.test(e))&&I("UNSAFE_VALUE",n,"unsafe-value");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||I("MANIFEST_INVALID",n,"non-finite-number");return}typeof e!="object"&&I("MANIFEST_INVALID",n,"non-json-value"),t>8&&I("LIMIT_EXCEEDED",n,"too-deep"),i.has(e)&&I("MANIFEST_INVALID",n,"cycle"),i.add(e);try{if(Array.isArray(e)){e.length>128&&I("LIMIT_EXCEEDED",n,"array-too-long"),e.forEach((o,r)=>cn(o,`${n}[${r}]`,t+1,i));return}M(e)||I("MANIFEST_INVALID",n,"non-plain-object");for(let[o,r]of Object.entries(e))cn(r,n===""?o:`${n}.${o}`,t+1,i);}finally{i.delete(e);}}}function V(e,n){return (typeof e!="string"||e.length===0)&&I("MANIFEST_INVALID",n,"string"),e}function ie(e,n){return M(e)||I("MANIFEST_INVALID",n,"object"),e}function Er(e,n){Array.isArray(e)||I("MANIFEST_INVALID",n,"array"),e.forEach((t,i)=>V(t,`${n}[${i}]`));}function Nr(e,n){typeof e!="boolean"&&I("MANIFEST_INVALID",n,"boolean");}function Ie(e,n,t,i){for(let o of Object.keys(e))!t.includes(o)&&!i.includes(o)&&I("MANIFEST_INVALID",`${n}.${o}`,"unknown-key");for(let o of t)b(e,o)||I("MANIFEST_INVALID",`${n}.${o}`,"missing-key");}function hr(e,n){if(e!=="icon")switch(cn(n,e),e){case "long_description":case "homepage":case "documentation":case "support":case "license":V(n,e);return;case "author":{let t=ie(n,e);Ie(t,e,["name"],["email","url"]);for(let i of Object.keys(t))V(t[i],`${e}.${i}`);return}case "repository":{let t=ie(n,e);Ie(t,e,[],["type","url"]);for(let i of Object.keys(t))V(t[i],`${e}.${i}`);return}case "icons":{Array.isArray(n)||I("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let o=`${e}[${i}]`,r=ie(t,o);Ie(r,o,["src","size"],["theme"]),V(r.src,`${o}.src`),V(r.size,`${o}.size`),b(r,"theme")&&V(r.theme,`${o}.theme`);});return}case "screenshots":case "keywords":case "privacy_policies":Er(n,e);return;case "tools":{Array.isArray(n)||I("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let o=`${e}[${i}]`,r=ie(t,o);Ie(r,o,["name"],["description"]),V(r.name,`${o}.name`),b(r,"description")&&V(r.description,`${o}.description`);});return}case "prompts":{Array.isArray(n)||I("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let o=`${e}[${i}]`,r=ie(t,o);Ie(r,o,["name","text"],["description","arguments"]),V(r.name,`${o}.name`),V(r.text,`${o}.text`);});return}case "tools_generated":case "prompts_generated":Nr(n,e);return;case "localization":case "compatibility":case "user_config":ie(n,e);return;default:I("MANIFEST_INVALID",e,"unknown-key");}}function we(e){return typeof e=="string"&&ee.test(e)?e:void 0}function jt(e){return Number.isSafeInteger(e)&&e>=1?e:void 0}function Pr(e){let n=we(e.name);if(n===void 0)return;let t=e._meta,i=M(t)?t[Z]:void 0,o=M(i)?i:{},r=b(o,"definitionId")?we(o.definitionId):n,c=b(o,"definitionVersion")?jt(o.definitionVersion):1;return {pluginId:n,...r===void 0?{}:{definitionId:r},...c===void 0?{}:{definitionVersion:c}}}function Tr(e){let n=we(e.pluginId);if(n===void 0)return;let t=we(e.definitionId),i=jt(e.version);return {pluginId:n,...t===void 0?{}:{definitionId:t},...i===void 0?{}:{definitionVersion:i}}}function Sr(e,n){if(e===W)return n.builtinOnly===true;let t=n._meta,i=M(t)?t[Z]:void 0;return M(i)&&i.builtinOnly===true}function br(e,n){b(e,"server")&&I("MANIFEST_INVALID","server","server-unsupported","phase 1 runs CrewX-owned Apps only");for(let a of Object.keys(e))un.includes(a)||I("MANIFEST_INVALID",a,"unknown-key");for(let a of fn)b(e,a)||I("MANIFEST_INVALID",a,"missing-key");e.manifest_version!==sn&&I("MANIFEST_INVALID","manifest_version","unsupported-version",`manifest_version must be "${sn}"`),Ct(e.version)||I("MANIFEST_INVALID","version","semver","version must be a semver.org version such as 0.1.0");let t=e._meta;M(t)||I("MANIFEST_INVALID","_meta","object"),b(t,Z)||I("MANIFEST_INVALID",G(),"missing-key");let i=t[Z];M(i)||I("MANIFEST_INVALID",G(),"object");for(let a of Object.keys(i))an.includes(a)||Lt.includes(a)||I("MANIFEST_INVALID",G(a),"unknown-key");for(let a of an)a==="actions"&&n!==void 0||b(i,a)||I("MANIFEST_INVALID",G(a),"missing-key");if(n!==void 0&&b(i,"actions")&&I("MANIFEST_INVALID",G("actions"),"two-truths",`actions are declared in both ${R} and ${w}; a server.ts App keeps them in the tools file only`),Ur(i.actions),b(i,"definitionVersion")){let a=i.definitionVersion;(!Number.isSafeInteger(a)||a<1)&&I("MANIFEST_INVALID",G("definitionVersion"),"positive-integer");}let o={};for(let a of Dt)b(e,a)&&(hr(a,e[a]),o[a]=xt(e[a]));let r={};for(let[a,d]of Object.entries(t))a!==Z&&(r[a]=d);let c={manifestVersion:2,pluginId:e.name,definitionId:b(i,"definitionId")?i.definitionId:e.name,version:b(i,"definitionVersion")?i.definitionVersion:1,name:e.display_name,description:e.description};for(let[a,d]of Object.entries(i))a==="definitionId"||a==="definitionVersion"||(c[a]=d);return n!==void 0&&(c.actions=n.map(a=>{let{viewCall:d,...l}=a;return {...l,backend:d===true?{type:"core",handler:"view.call"}:{type:"skill",entry:j}}})),Object.keys(r).length>0&&(c._meta=r),{v2Input:c,...Object.keys(r).length>0?{vendorMeta:r}:{},passthrough:o}}function Ur(e){Array.isArray(e)&&e.forEach((n,t)=>{let i=M(n)?n.backend:void 0;M(i)&&b(i,"entry")&&I("MANIFEST_INVALID",G(`actions[${t}].backend.entry`),"entry-not-authorable",`an action in ${R} cannot name an entry; a server.ts App declares its actions in ${w}`);});}function Or(e,n,t){M(e)||I("MANIFEST_INVALID","","not-object","manifest.json must be a JSON object",R);let i;try{i=br(e,t);}catch(c){throw c instanceof $?new $(c.code,{...c.reason,file:R}):c}let o;try{let c=me(i.v2Input,{mode:n.mode??"local"});c.manifestVersion!==2&&I("MANIFEST_INVALID","","v2-required"),o=c;}catch(c){throw c instanceof B?new $(c.code,kt(c,R,_r)):c}let r=e.tools;if(Array.isArray(r)){let c=new Set(o.actions.map(a=>a.actionId));r.forEach((a,d)=>{let l=a.name;if(!c.has(l))throw new $("MANIFEST_INVALID",{path:`tools[${d}].name`,rule:"tool-not-action",message:"every tools[].name must be an action id",file:R})});}return {file:R,manifest:o,v2Input:i.v2Input,releaseVersion:e.version,...Object.keys(i.passthrough).length>0?{mcpb:i.passthrough}:{}}}function Rr(e,n){try{let t=me(e,{mode:n.mode??"local"});if(t.manifestVersion!==2)throw new $("MANIFEST_INVALID",{path:"manifestVersion",rule:"v2-required",message:"a workspace App requires manifestVersion 2",file:W});return {file:W,manifest:t,v2Input:e}}catch(t){throw t instanceof B?new $(t.code,kt(t,W,i=>i??"")):t}}function dn(e){return Qn(rn(e).definition)}function Mt(e){let{entryHash:n,initialState:t,...i}=e,o={...i};return t!==void 0&&(o.initialState={path:t.path}),xt(o)}function Mr(e,n){let t=Mt(e),i=Mt(n);return [...new Set([...Object.keys(t),...Object.keys(i)])].sort().filter(r=>Q(t[r]??null)!==Q(i[r]??null))}function wr(e,n){return e.entryHash!==void 0&&n.entryHash!==void 0&&e.entryHash!==n.entryHash||e.initialState?.hash!==void 0&&n.initialState?.hash!==void 0&&e.initialState.hash!==n.initialState.hash}function Dr(e,n){let t=Mr(e,n),i=wr(e,n),o="";try{let r=dn(e),c=dn(n);i=i||r!==c,o=` (definition hash ${r.slice(0,12)} vs ${c.slice(0,12)})`;}catch{i=true;}t.length===0&&!i||I("MANIFEST_DUAL_MISMATCH","","dual-manifest-mismatch",`${R} and ${W} normalize to different definitions${o}`+(t.length>0?`; differing fields: ${t.join(", ")}`:""));}function v(e,n,t="MANIFEST_INVALID",i){return {code:t,reason:{path:e,rule:n,...i===void 0?{}:{message:i},file:w},files:[]}}function wt(e){return {...v("","tools-needs-manifest-json","MANIFEST_INVALID",`${w} is read with ${R} only`),files:e}}function Lr(e,n){if(e.byteLength>n)return {failure:v("","file-too-large","LIMIT_EXCEEDED")};let t;try{t=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e));}catch{return {failure:v("","invalid-json")}}if(!M(t))return {failure:v("","not-object","MANIFEST_INVALID",`${w} must be a JSON object`)};for(let o of Object.keys(t))if(o!=="schemaVersion"&&o!=="actions")return {failure:v(o,"unknown-key")};for(let o of ["schemaVersion","actions"])if(!b(t,o))return {failure:v(o,"missing-key")};if(t.schemaVersion!==1)return {failure:v("schemaVersion","unsupported-version","MANIFEST_INVALID",`schemaVersion must be ${1}`)};let i=t.actions;if(!Array.isArray(i))return {failure:v("actions","array")};for(let[o,r]of i.entries()){if(!M(r))return {failure:v(`actions[${o}]`,"object")};if(b(r,"backend"))return {failure:v(`actions[${o}].backend`,"tools-backend","MANIFEST_INVALID",`an action in ${w} cannot carry a backend`)};if(b(r,"viewCall")&&r.viewCall!==true)return {failure:v(`actions[${o}].viewCall`,"view-call-marker","MANIFEST_INVALID","viewCall must be the exact marker true")}}return {actions:i}}function Cr(e,n){let t=n.maxBytes??262144,i=[],o=new TextDecoder("utf-8",{fatal:true});for(let r of oe){let c=e[r];if(c===void 0)continue;if(c.byteLength>t)return {parsed:i,failure:{code:"LIMIT_EXCEEDED",reason:{path:"",rule:"file-too-large",file:r},files:[r]}};let a;try{a=JSON.parse(o.decode(c));}catch{return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"invalid-json",file:r},files:[r]}}}if(!M(a))return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"not-object",message:`${r} must be a JSON object`,file:r},files:[r]}};i.push({file:r,raw:a});}return {parsed:i}}function pn(e,n={}){let{parsed:t,failure:i}=Cr(e,n),o=oe.filter(u=>e[u]!==void 0);if(i!==void 0)return {ok:false,rejection:i,parseFailure:true,builtinOnly:false};let r=e[w],c=r===void 0?void 0:Lr(r,n.maxBytes??262144);if(t.length===0)return {ok:false,rejection:c===void 0?{code:"MANIFEST_INVALID",reason:{path:"",rule:"no-manifest-file",message:"neither manifest.json nor ui-plugin.json is present"},files:[]}:wt(o),parseFailure:true,builtinOnly:false};let a=t[0],d=a.file===R?Pr(a.raw):Tr(a.raw),l=t.some(u=>Sr(u.file,u.raw)),f;if(c!==void 0){let u=t.some(O=>O.file===R)?c.failure:wt(o);if(u!==void 0)return {ok:false,rejection:u,parseFailure:false,...d===void 0?{}:{identity:d},builtinOnly:l};f=c.actions;}let m=[];try{for(let u of t)m.push(u.file===R?Or(u.raw,n,f):Rr(u.raw,n));m.length===2&&Dr(m[0].manifest,m[1].manifest);}catch(u){if(u instanceof $)return {ok:false,rejection:{code:u.code,reason:u.reason,files:u.code==="MANIFEST_DUAL_MISMATCH"?[...oe]:u.reason.file===void 0||u.reason.file===w?o:[u.reason.file]},parseFailure:false,...d===void 0?{}:{identity:d},builtinOnly:l};throw u}let y=m[0];return {ok:true,...y,identity:d??{pluginId:y.manifest.pluginId},files:o}}new TextDecoder("utf-8",{fatal:true});var Ft=20*1e3;function Vt(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function mn(e){try{let n=L__namespace.lstatSync(e);return n.isSymbolicLink()||!n.isFile()?void 0:new Uint8Array(L__namespace.readFileSync(e))}catch{return}}function kr(e){let n=mn(P__namespace.join(e,"package.json"));if(n)try{let t=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(n));return Vt(t)?t:void 0}catch{return}}function xr(e){let n={};for(let i of oe){let o=mn(P__namespace.join(e,i));o&&(n[i]=o);}let t=mn(P__namespace.join(e,w));if(t&&(n[w]=t),Object.keys(n).length!==0)try{let i=pn(n,{mode:"local"});if(!i.ok)return;for(let o of i.manifest.actions){let r=o.backend;if(r.type==="skill"&&"entry"in r&&r.entry)return vt(r.entry)}return "dist/server.mjs"}catch{return}}function jr(e){let n=e.main;if(typeof n=="string")return n;let t=e.bin;if(typeof t=="string")return t;if(Vt(t)){let i=Object.values(t).find(o=>typeof o=="string");if(i)return i}}function vt(e){return e===j||e.endsWith("/main.mjs")||e.endsWith("/entry.mjs")?P__namespace.posix.join(P__namespace.posix.dirname(e),"server.mjs"):e}function Fr(e){let n=kr(e),t=xr(e),i=n?jr(n):void 0,o=t??(i?vt(i):void 0);if(!o)throw new T("VERIFY_IMPORT_FAILED","verify","The App manifest does not declare a server entry.");if(!o||o.includes("\\")||o.includes("\0")||P__namespace.posix.isAbsolute(o)||o.split("/").some(a=>a===".."||a.length===0))throw new T("VERIFY_IMPORT_FAILED","verify","The App manifest has an unsafe server entry.");let r=P__namespace.resolve(e),c=P__namespace.resolve(r,...o.split("/"));if(c!==r&&!c.startsWith(`${r}${P__namespace.sep}`))throw new T("VERIFY_IMPORT_FAILED","verify","The App manifest server entry escaped the package.");try{let a=L__namespace.lstatSync(c);if(a.isSymbolicLink()||!a.isFile())throw new Error("not a regular file")}catch{throw new T("VERIFY_IMPORT_FAILED","verify",`The App server entry is missing: ${o}`)}return c}async function Vr(e,n={}){let t=n.runtime,i=t?.workspaceRoot??e,o=Fr(e),c=await he({command:t?.execPath??process.execPath,args:["--input-type=module","-e",'import { pathToFileURL } from "node:url"; await import(pathToFileURL(process.argv[1]).href);',o],cwd:e,env:re(i,t?.isElectronRuntime),runner:n.runner,timeoutMs:n.timeoutMs??Ft,onTimeoutCode:"VERIFY_TIMEOUT",step:"verify",onOutput:a=>{let d=a.replace(/[\r\n]+/gu," ").replace(/\s+/gu," ").trim().slice(-400);if(d)try{n.onProgress?.({step:"verify",message:d});}catch{}}});if(c.error!==void 0||c.status!==0){let a=On(c.stderr||c.error?.message);throw new T("VERIFY_IMPORT_FAILED","verify","The App server module could not be imported.",a)}}var vr=Ft;
7
+ exports.APP_INSTALL_NO_OUTPUT_TIMEOUT_MS=li;exports.APP_INSTALL_TIMEOUT_MS=di;exports.APP_VERIFY_TIMEOUT_MS=vr;exports.AppInstallError=T;exports.buildAppRuntimeEnv=re;exports.prepareAppDependencies=ci;exports.resolveNpmCli=Kn;exports.verifyAppLaunch=Vr;
@@ -0,0 +1,33 @@
1
+ export interface AppInstallCommandResult {
2
+ readonly status: number | null;
3
+ readonly stdout: string;
4
+ readonly stderr: string;
5
+ readonly error?: Error;
6
+ }
7
+ export interface AppInstallCommandOptions {
8
+ readonly cwd: string;
9
+ readonly env: NodeJS.ProcessEnv;
10
+ readonly onStdout?: (chunk: string) => void;
11
+ readonly onStderr?: (chunk: string) => void;
12
+ }
13
+ export interface AppInstallCommandHandle {
14
+ readonly pid?: number;
15
+ readonly completion: Promise<AppInstallCommandResult>;
16
+ terminate(): Promise<void>;
17
+ }
18
+ export type AppInstallRunner = (command: string, args: readonly string[], options: AppInstallCommandOptions) => AppInstallCommandHandle;
19
+ export declare const spawnAppInstallCommand: AppInstallRunner;
20
+ export interface RunAppInstallCommandOptions {
21
+ readonly command: string;
22
+ readonly args: readonly string[];
23
+ readonly cwd: string;
24
+ readonly env: NodeJS.ProcessEnv;
25
+ readonly runner?: AppInstallRunner;
26
+ readonly signal?: AbortSignal;
27
+ readonly timeoutMs: number;
28
+ readonly noOutputTimeoutMs?: number;
29
+ readonly onTimeoutCode: 'DEPS_TIMEOUT' | 'VERIFY_TIMEOUT';
30
+ readonly step: 'dependencies' | 'verify';
31
+ readonly onOutput?: (chunk: string) => void;
32
+ }
33
+ export declare function runAppInstallCommand(options: RunAppInstallCommandOptions): Promise<AppInstallCommandResult>;
@@ -0,0 +1,2 @@
1
+ export type AppElectronRuntimeCheck = () => boolean;
2
+ export declare function buildAppRuntimeEnv(workspaceRoot: string, isElectronRuntime?: AppElectronRuntimeCheck): NodeJS.ProcessEnv;
@@ -0,0 +1,10 @@
1
+ import type { AppInstallRuntime, AppInstallProgress } from './dependencies.js';
2
+ import { type AppInstallRunner } from './process.js';
3
+ export interface VerifyAppLaunchOptions {
4
+ readonly runtime?: AppInstallRuntime;
5
+ readonly runner?: AppInstallRunner;
6
+ readonly timeoutMs?: number;
7
+ readonly onProgress?: (progress: AppInstallProgress) => void;
8
+ }
9
+ export declare function verifyAppLaunch(stagedDir: string, options?: VerifyAppLaunchOptions): Promise<void>;
10
+ export declare const APP_VERIFY_TIMEOUT_MS: number;
@@ -0,0 +1,7 @@
1
+ import*as C from'fs';import*as T from'path';import*as Mn from'os';import {spawn}from'child_process';import {createHash}from'crypto';import {isIP}from'net';var S=class extends Error{constructor(t,i,o=t,r){super(o);this.code=t;this.step=i;this.detail=r;this.name="AppInstallError";}code;step;detail};function Rn(e){if(!e)return;let n=e.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/gu," ").split(/[\r\n]/u).map(i=>i.replace(/\s+/gu," ").trim()).filter(Boolean),t=n.find(i=>/cannot find package/iu.test(i))??n.find(i=>/\b(?:error|exception)(?:\s+\[[^\]]+\])?:/iu.test(i))??n.find(i=>/module_not_found/iu.test(i))??n[0];if(t)return t.length>500?`${t.slice(0,497)}...`:t}var Jt=["CREWX_HOME","CREWX_DB","XDG_CONFIG_HOME"];function se(e,n=$t){let t={};for(let i of Jt){let o=process.env[i];o!==void 0&&(t[i]=o);}return t.CREWX_WORKSPACE_ROOT=e,n()&&(t.ELECTRON_RUN_AS_NODE="1"),t}function $t(){return typeof process.versions.electron=="string"&&process.versions.electron.length>0}function Dn(){if(process.env.CREWX_HOME){let e=T.resolve(process.env.CREWX_HOME);try{return C.realpathSync(e)}catch(n){if(n instanceof Error&&"code"in n&&n.code==="ENOENT")return e;throw n}}return process.platform!=="win32"&&process.env.XDG_CONFIG_HOME?T.join(process.env.XDG_CONFIG_HOME,"crewx"):T.join(Mn.homedir(),".crewx")}var Ln=3e3;var xn=2e3,jn=25,Fn=100;function Vn(e){return e instanceof Error?e:e===void 0?void 0:new Error(String(e))}function Cn(e){return typeof e=="object"&&e!==null&&"code"in e?String(e.code):void 0}function zt(e){return Number.isSafeInteger(e)&&e>0}function Kt(e,n){return new Promise(t=>{let i;try{i=spawn(e,n,{windowsHide:!0});}catch(l){t({status:null,stdout:"",stderr:"",error:Vn(l)});return}let o="",r="",c=false,a,d=setTimeout(()=>{try{i.kill();}catch{}a({status:null,stdout:o,stderr:r,error:new Error(`Command timed out after ${Ln}ms`)});},Ln);a=l=>{c||(c=true,clearTimeout(d),t(l));},i.stdout?.setEncoding("utf8"),i.stderr?.setEncoding("utf8"),i.stdout?.on("data",l=>{o+=String(l);}),i.stderr?.on("data",l=>{r+=String(l);}),i.once("error",l=>{a({status:null,stdout:o,stderr:r,error:l});}),i.once("close",l=>{a({status:l,stdout:o,stderr:r});});})}async function Xt(e,n,t){return t.runCommandAsync?t.runCommandAsync(e,n):t.runCommand?t.runCommand(e,n):Kt(e,n)}function Yt(e){return new Promise(n=>{setTimeout(n,Math.max(0,e));})}function qt(){return new Promise(e=>{setImmediate(e);})}function ce(e,n=process.kill){try{return n(e,0),"alive"}catch(t){return Cn(t)==="ESRCH"?"not_found":Cn(t)==="EPERM"?"alive":"unknown"}}function Wt(e,n){let t=ce(-e,n),i=ce(e,n);return t==="alive"||i==="alive"?"alive":t==="unknown"||i==="unknown"?"unknown":"not_found"}async function vn(e,n,t,i){let o=Math.max(0,t),r=Math.max(1,i.pollIntervalMs??jn),c=Date.now()+o,a,d=o===0,l=i.sleep?Promise.resolve().then(()=>i.sleep(o)).then(()=>{},()=>{}):new Promise(f=>{a=setTimeout(f,o);});l.then(()=>{d=true;});try{for(await qt();;){let f=Wt(e,n);if(f==="not_found")return f;let m=c-Date.now();if(d||m<=0)return f;await Promise.race([l,Yt(Math.min(r,m))]);}}finally{a!==void 0&&clearTimeout(a);}}async function kn(e,n,t,i,o){let r=await vn(e,n,o.hardConfirmMs??Fn,{...o,sleep:void 0});return r==="not_found"?t?{status:"not_found",pid:e,method:i}:{status:"terminated",pid:e,method:i}:r==="alive"?{status:"failed",pid:e,method:i,error:"Process is still running after termination attempt"}:{status:"failed",pid:e,method:i,error:"Unable to verify process termination"}}async function Ne(e,n={}){let t=n.platform??process.platform,i=t==="win32"?"taskkill":"process-group",o=y=>({status:"failed",pid:e,method:i,error:y});if(!zt(e))return o("Invalid process ID");let r=n.kill??process.kill,c=ce(e,r);if(c==="not_found")return {status:"not_found",pid:e,method:i};if(c!=="alive")return o("Unable to determine whether the process is alive");if(t==="win32"){let y;try{y=await Xt("taskkill",["/PID",String(e),"/T","/F"],n);}catch(R){y={status:null,stdout:"",stderr:"",error:Vn(R)};}let u=ce(e,r);return u==="not_found"?y.status===0&&!y.error?{status:"terminated",pid:e,method:i}:{status:"not_found",pid:e,method:i}:o(u==="alive"?"Process is still running after termination attempt":"Unable to verify process termination")}let a,d=n.signal??"SIGKILL";try{r(-e,d);}catch(y){a=y;}if(d==="SIGKILL")return kn(e,r,a,i,n);if(await vn(e,r,n.graceMs??xn,n)==="not_found")return a?{status:"not_found",pid:e,method:i}:{status:"terminated",pid:e,method:i};let f;try{r(-e,"SIGKILL");}catch(y){f=y;}let m=await kn(e,r,f,i,n);return m.status==="terminated"?m:m.status==="not_found"?a?m:{status:"terminated",pid:e,method:i}:o(m.error??"Process termination failed")}var Gn=64*1024;function Hn(e,n){let t=e+n;return Buffer.byteLength(t,"utf8")<=Gn?t:Buffer.from(t,"utf8").subarray(-Gn).toString("utf8")}function Le(e){return e instanceof Error?e:e===void 0?void 0:new Error(String(e))}function he(e){return {status:null,stdout:"",stderr:"",...Le(e)===void 0?{}:{error:Le(e)}}}var Qt=(e,n,t)=>{let i;try{i=spawn(e,[...n],{cwd:t.cwd,env:t.env,shell:!1,detached:process.platform!=="win32",windowsHide:!0,stdio:["ignore","pipe","pipe"]});}catch(f){return {completion:Promise.resolve(he(f)),terminate:async()=>{}}}let o="",r="",c=false,a,d=new Promise(f=>{a=f;}),l=f=>{c||(c=true,a(f));};return i.stdout?.setEncoding("utf8"),i.stderr?.setEncoding("utf8"),i.stdout?.on("data",f=>{let m=String(f);o=Hn(o,m),t.onStdout?.(m);}),i.stderr?.on("data",f=>{let m=String(f);r=Hn(r,m),t.onStderr?.(m);}),i.once("error",f=>l({status:null,stdout:o,stderr:r,error:f})),i.once("close",f=>l({status:f,stdout:o,stderr:r})),{...i.pid===void 0?{}:{pid:i.pid},completion:d,terminate:async()=>{if(i.pid===void 0)return;if((await Ne(i.pid)).status==="failed"){try{i.kill("SIGKILL");}catch{}let m=await Ne(i.pid);if(m.status==="failed")throw new Error(m.error??"process tree termination failed")}}}};async function Pe(e){if(e.signal?.aborted)throw new S("DEPS_INSTALL_FAILED",e.step,"App operation was cancelled.");let n,t,i,o,r=false,c=new Promise(A=>{o=A;}),a=A=>{r||(r=true,n!==void 0&&clearTimeout(n),t!==void 0&&clearTimeout(t),i&&e.signal?.removeEventListener("abort",i),o(A));},d=()=>{e.noOutputTimeoutMs===void 0||e.noOutputTimeoutMs<=0||(n!==void 0&&clearTimeout(n),n=setTimeout(()=>a({type:"timeout"}),e.noOutputTimeoutMs));},l=A=>{A.length>0&&d();try{e.onOutput?.(A);}catch{}},f;try{f=(e.runner??Qt)(e.command,e.args,{cwd:e.cwd,env:e.env,onStdout:l,onStderr:l});}catch(A){return he(A)}f.completion.then(A=>a({type:"completed",result:A}),A=>a({type:"completed",result:he(A)}));d(),t=setTimeout(()=>a({type:"timeout"}),e.timeoutMs),e.signal&&(i=()=>a({type:"abort"}),e.signal.addEventListener("abort",i,{once:true}));let y=await c;if(y.type==="completed")return y.result;let u;try{await f.terminate();}catch(A){u=Le(A);}let R;try{R=await f.completion;}catch(A){R=he(A);}if(y.type==="abort"){let A=u?`Could not confirm process tree termination: ${u.message}`:void 0;throw new S("DEPS_INSTALL_FAILED",e.step,"App operation was cancelled.",A)}let K=[R?.stderr,u?.message].filter(Boolean).join(`
2
+ `);throw new S(e.onTimeoutCode,e.step,"App operation timed out.",K||void 0)}var ei=["dependencies","devDependencies","optionalDependencies","peerDependencies"],zn=300*1e3,Kn=90*1e3,Jn=false;function X(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function O(e,n){return new S(e,"dependencies",n)}function $n(e,n){try{let t=C.lstatSync(e);if(t.isSymbolicLink()||!t.isFile())throw new Error("not a regular file");return JSON.parse(C.readFileSync(e,"utf8"))}catch(t){let i=t!==null&&typeof t=="object"&&"code"in t?String(t.code):"";throw n==="package-lock.json"?O("DEPS_LOCKFILE_MISSING","package-lock.json is missing or invalid."):i==="ENOENT"?O("DEPS_INSTALL_FAILED","package.json is missing."):O("DEPS_INSTALL_FAILED","package.json is invalid.")}}function ni(e){let n=e.dependencies;if(n!==void 0){if(!X(n)||Object.values(n).some(t=>typeof t!="string"))throw O("DEPS_INSTALL_FAILED","package.json dependencies must be a string map.");return Object.keys(n).length===0?void 0:n}}function ti(e,n){let t=X(e)?e:{},i=X(n)?n:{},o=Object.keys(t).sort(),r=Object.keys(i).sort();return o.length===r.length&&o.every((c,a)=>c===r[a]&&t[c]===i[c])}function ii(e,n){for(let t of ei){let i=e[t];if(!ti(i,n[t]))throw O("DEPS_LOCKFILE_MISSING","package-lock.json is out of sync with package.json.")}if(typeof e.name=="string"&&typeof n.name=="string"&&e.name!==n.name||typeof e.version=="string"&&typeof n.version=="string"&&e.version!==n.version)throw O("DEPS_LOCKFILE_MISSING","package-lock.json is out of sync with package.json.")}function oi(e){let n=T.join(e,"package.json");if(!C.existsSync(n))return "skipped";let t=$n(n,"package.json");if(!X(t))throw O("DEPS_INSTALL_FAILED","package.json must contain an object.");if(ni(t)===void 0)return "skipped";let i=T.join(e,"package-lock.json"),o=$n(i,"package-lock.json");if(!X(o)||!Number.isInteger(o.lockfileVersion)||o.lockfileVersion<2||!X(o.packages))throw O("DEPS_LOCKFILE_MISSING","package-lock.json is missing a supported npm lockfile package map.");let r=o.packages,c=r[""];if(!X(c))throw O("DEPS_LOCKFILE_MISSING","package-lock.json has no root package entry.");ii(t,c);for(let[a,d]of Object.entries(r)){if(a==="")continue;if(!X(d))throw O("DEPS_LOCKFILE_MISSING","package-lock.json contains an invalid package entry.");let l=d;if(l.link===true)throw O("DEPS_REGISTRY_REFUSED",`package-lock.json contains a linked dependency at ${a}.`);if(typeof l.resolved=="string"&&!l.resolved.startsWith("https://registry.npmjs.org/"))throw O("DEPS_REGISTRY_REFUSED",`package-lock.json contains a non-registry dependency at ${a}.`);if(typeof l.integrity!="string"||l.integrity.trim().length===0)throw O("DEPS_REGISTRY_REFUSED",`package-lock.json has no integrity for ${a}.`)}return "ready"}function ri(e){let n=T.join(e,".npmrc");try{C.rmSync(n,{force:!0,recursive:!0});}catch{throw O("DEPS_INSTALL_FAILED","Could not remove the package .npmrc file.")}}function Bn(e){try{let n=C.realpathSync(e);return C.statSync(n).isFile()?n:void 0}catch{return}}function si(e){let n=T.resolve(e||".");return [T.join(n,"npm-cli.js"),T.join(n,"npm"),T.join(n,"npm.cmd"),T.join(n,"node_modules","npm","bin","npm-cli.js"),T.resolve(n,"..","lib","node_modules","npm","bin","npm-cli.js"),T.resolve(n,"..","node_modules","npm","bin","npm-cli.js")]}function Xn(e={}){let n=e.env??process.env,t=n.CREWX_NPM_CLI_JS;if(t!==void 0){let o=T.isAbsolute(t)?Bn(t):void 0;if(o===void 0||T.basename(o).toLowerCase()!=="npm-cli.js")throw O("DEPS_INSTALL_FAILED","CREWX_NPM_CLI_JS must name an existing absolute npm-cli.js file.");return o}Jn||(Jn=true,(e.log??(o=>console.warn(o)))("CREWX_NPM_CLI_JS is unset; resolving npm-cli.js from PATH."));let i=n.PATH??n.Path??"";for(let o of i.split(T.delimiter))for(let r of si(o)){let c=Bn(r);if(c!==void 0&&T.basename(c).toLowerCase()==="npm-cli.js")return c}throw O("DEPS_INSTALL_FAILED","npm-cli.js was not found on PATH.")}function ai(e){let n=`${e.error?.message??""}
3
+ ${e.stdout}
4
+ ${e.stderr}`,t=e.error!==void 0&&"code"in e.error?String(e.error.code??""):"";return /ENOTFOUND|ECONNRESET|EAI_AGAIN|ETIMEDOUT|ECONNREFUSED/iu.test(`${t}
5
+ ${n}`)?new S("DEPS_NETWORK","dependencies","The npm registry could not be reached.",e.stderr):/ENOSPC/iu.test(`${t}
6
+ ${n}`)?new S("DEPS_DISK_FULL","dependencies","There is not enough disk space to install App dependencies.",e.stderr):/package\.json.{0,80}package-lock\.json.{0,80}not in sync|Missing: .+ from lock file|Invalid: .+ from lock file|EUSAGE/iu.test(n)?new S("DEPS_LOCKFILE_MISSING","dependencies","package-lock.json is out of sync with package.json.",e.stderr):new S("DEPS_INSTALL_FAILED","dependencies","npm ci could not install App dependencies.",e.stderr||e.error?.message)}function ci(e,n){let t=se(n?.workspaceRoot??e,n?.isElectronRuntime);for(let i of ["PATH","Path","HOME","USERPROFILE","TMPDIR","TMP","TEMP","SystemRoot"]){let o=process.env[i];o!==void 0&&(t[i]=o);}return t}async function di(e,n={}){if(ri(e),oi(e)==="skipped")return {state:"skipped"};let i=n.runtime,r=[Xn(),"ci","--omit=dev","--include=optional","--ignore-scripts","--no-audit","--no-fund","--cache",T.join(Dn(),"npm-cache")];n.retry&&r.push("--prefer-offline");let c="",a=l=>{let f=l.replace(/[\r\n]+/gu," ").replace(/\s+/gu," ").trim().slice(-400);if(!(!f||f===c)){c=f;try{n.onProgress?.({step:"dependencies",message:f});}catch{}}},d=await Pe({command:i?.execPath??process.execPath,args:r,cwd:e,env:ci(e,i),runner:n.runner,signal:n.signal,timeoutMs:n.timeoutMs??zn,noOutputTimeoutMs:n.noOutputTimeoutMs??Kn,onTimeoutCode:"DEPS_TIMEOUT",step:"dependencies",onOutput:a});if(d.error!==void 0||d.status!==0)throw ai(d);return {state:"done"}}var li=zn,ui=Kn;var de=class extends Error{constructor(t,i=t,o){super(i);this.code=t;this.currentRevision=o;}code;currentRevision;name="UiRuntimeError"};var fi=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,pi=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i,mi=/<\/?[A-Za-z][^>]*>/,Ii=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,yi=/^(?:https?|file|ftp|ws|wss):\/\//i;function xe(e){return fi.test(e)||pi.test(e)}function k(){throw new de("INPUT_INVALID","JSON value is not projection-safe")}function Ai(e){let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var gi=8,_i=4;function Ce(e,n,t,i,o,r){if(n>i&&k(),e===null||typeof e=="string"||typeof e=="boolean")return typeof e=="string"&&(mi.test(e)||yi.test(e)&&!Ei(o,r)||Ii.test(e))&&k(),e;if(typeof e=="number")return Number.isFinite(e)||k(),e;(typeof e!="object"||e===void 0||typeof e=="function"||typeof e=="bigint")&&k();let c=e;t.has(c)&&k(),t.add(c);try{if(Array.isArray(e))return e.map(d=>Ce(d,n+1,t,i,o,r));Ai(c)||k();let a={};for(let[d,l]of Object.entries(e))xe(d)&&k(),a[d]=Ce(l,n+1,t,i,[...o,d],r);return a}finally{t.delete(c);}}function Yn(e,n=0,t=[]){(!Number.isInteger(n)||n<0||n>_i)&&k(),(!Array.isArray(t)||t.some(o=>typeof o!="string"))&&k();let i=Ce(e,0,new Set,gi+n,[],t);return (i===null||Array.isArray(i)||typeof i!="object")&&k(),i}function Te(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 Ei(e,n){if(e.length===0)return false;let t=e.join(".");return n.some(i=>Te(t,i))}function qn(e){try{let n=JSON.stringify(e);return n===void 0&&k(),n}catch{k();}}function ke(e){return Array.isArray(e)?e.map(ke):e!==null&&typeof e=="object"?Object.fromEntries(Object.keys(e).sort().map(n=>[n,ke(e[n])])):e}function ee(e){return qn(ke(e))}var Se=["text/plain","application/json"];var Wn=["__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(Wn),Pi=/(?:proof|token|secret|password|cookie|authorization|private[_-]?key|stack|exception|plugin[_-]?text)/i,Ti=/(?:url|uri|endpoint|path|file(?:name|path)?|cwd|shell|directory|dir|folder)$/i;function le(e){return hi.has(e)||Pi.test(e)||Ti.test(e)}var je=/^[A-Za-z0-9_]+$/,ue=/^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)*$/,ne=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,Fe=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,Ve=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,ve=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/,Ge=["blue","violet","emerald","amber","rose","sky","slate","indigo"],He=["inline","panel"];function Je(e){return typeof e=="string"&&Se.includes(e)}new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});function $e(e){if(!Be(e))return false;let n=Object.keys(e);return !(n.some(t=>t!=="in"&&t!=="out")||n.length===0||Object.hasOwn(e,"in")&&!Si(e.in)||Object.hasOwn(e,"out")&&!bi(e.out))}function Si(e){return Be(e)?Object.keys(e).every(t=>t==="mediaType"||t==="required")&&Object.hasOwn(e,"mediaType")&&Je(e.mediaType)&&(!Object.hasOwn(e,"required")||typeof e.required=="boolean"):false}function bi(e){return Be(e)?Object.keys(e).every(t=>t==="mediaType"||t==="range")&&Object.hasOwn(e,"mediaType")&&Je(e.mediaType)&&(!Object.hasOwn(e,"range")||typeof e.range=="boolean"):false}function Be(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}var Ui=[5,15,30,60],be=Object.freeze({min:15e3,max:6e5,default:3e5}),Zn=1;function ze(e){return Ui.includes(e)}function Ke(e){return Number.isSafeInteger(e)&&e>=be.min&&e<=be.max}var Ue=Object.freeze({min:6e4,max:18e5,default:6e5}),Qn=1;var Oi=["start","status","cancel"];function Xe(e){return Number.isSafeInteger(e)&&e>=Ue.min&&e<=Ue.max}function Ye(e){return Oi.includes(e)}function et(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.downloads!==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.downloads===void 0?{}:{downloads:e.downloads},...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=Yn(t);return createHash("sha256").update(ee(i)).digest("hex")}var D="dist/tools.json";var F="dist/main.mjs";var Oe="view.call",nt="crewxImage",W="window";var Mi=["CREWX_APP_INSTANCE_ID","CREWX_THREAD_ID"];function tt(e){if(!Array.isArray(e)||e.length===0)return false;let n=new Set;for(let t of e){if(!Mi.some(i=>i===t)||n.has(t))return false;n.add(t);}return true}var Di=4096,ot=16,Li=32,Ci=512,ki=new Set(["connectDomains","frameDomains","resourceDomains","baseUriDomains"]),xi=["localhost","local","internal","home.arpa","test","example","invalid","onion","lan","corp","home","intranet","private","localdomain"];var ji=/^(https|wss):\/\/([^/?#]+)$/i,Fi=/^\[[^\]]+\](?::[0-9]+)?$/,Vi=/^[^:\[\]]+(?::[0-9]+)?$/,vi=/^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/,Gi=[[0,8],[1681915904,10],[167772160,8],[2130706432,8],[2851995648,16],[2886729728,12],[3221225984,24],[3227017984,24],[3232235520,16],[3323068416,15],[3325256704,24],[3405803776,24],[3758096384,4],[4026531840,4]],qe=class extends Error{constructor(t){super(t);this.code=t;}code;name="UiPluginCspNormalizationError"};function N(e){throw new qe(e)}function Hi(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 Ji(e,n){let t=Object.getOwnPropertyDescriptor(e,n);return (!t||!("value"in t))&&N("CSP_ORIGIN_INVALID"),t.value}function Re(e,n){if(!Object.prototype.hasOwnProperty.call(e,n))return [];let t=Ji(e,n);Array.isArray(t)||N("CSP_ORIGIN_INVALID"),Reflect.ownKeys(t).some(r=>typeof r!="string"||r!=="length"&&!/^(?:0|[1-9][0-9]*)$/.test(r))&&N("CSP_ORIGIN_INVALID");let o=[];for(let r=0;r<t.length;r+=1)(!Object.prototype.hasOwnProperty.call(t,r)||typeof t[r]!="string")&&N("CSP_ORIGIN_INVALID"),o.push(t[r]);return Object.keys(t).length!==t.length&&N("CSP_ORIGIN_INVALID"),o}function $i(e){let n;try{n=JSON.stringify(e);}catch{N("CSP_ORIGIN_INVALID");}return n===void 0&&N("CSP_ORIGIN_INVALID"),new TextEncoder().encode(n).byteLength}function rt(e,n){/\s|\\/u.test(e)&&N("CSP_ORIGIN_INVALID");let t=ji.exec(e);t||N("CSP_ORIGIN_INVALID");let i=t[1].toLowerCase(),o=t[2];(o.includes("@")||o.includes("%")||o.includes("*"))&&N("CSP_ORIGIN_INVALID"),(o.startsWith("[")?Fi:Vi).test(o)||N("CSP_ORIGIN_INVALID"),i==="wss"&&n!=="connectDomains"&&N("CSP_ORIGIN_INVALID");let c;try{c=new URL(e);}catch{N("CSP_ORIGIN_INVALID");}(c.protocol!==`${i}:`||c.username!==""||c.password!==""||c.search!==""||c.hash!=="")&&N("CSP_ORIGIN_INVALID");let a=c.hostname.toLowerCase();if((!a||a.includes("%"))&&N("CSP_ORIGIN_INVALID"),!a.startsWith("[")){let l=a.endsWith(".")?a.slice(0,-1):a;(l.length===0||l.length>253)&&N("CSP_ORIGIN_INVALID"),l.split(".").some(m=>m.length>63||!vi.test(m))&&N("CSP_ORIGIN_INVALID");}let d=c.origin;return (d==="null"||!d.startsWith(`${i}://`))&&N("CSP_ORIGIN_INVALID"),{origin:d,hostname:a}}function Bi(e){let n=e.split(".").map(Number);return ((n[0]*256+n[1])*256+n[2])*256+n[3]}function st(e,n,t){let i=4294967295<<32-t>>>0;return (e&i)===(n&i)}function dt(e){let n=Bi(e);return st(n,3221225472,24)?n!==3221225481&&n!==3221225482:Gi.some(([t,i])=>st(n,t,i))}function zi(e){let n=e.indexOf("::"),t=(n<0?e:e.slice(0,n)).split(":").filter(Boolean),i=n<0?[]:e.slice(n+2).split(":").filter(Boolean);return (n<0?t:[...t,...Array(8-t.length-i.length).fill("0"),...i]).reduce((r,c)=>r<<16n|BigInt(Number.parseInt(c,16)),0n)}function Ki(e){let n=zi(e),t=Number(n>>112n),i=Number(n>>96n&0xffffn);if(n>>32n===0xffffn){let o=Number(n&0xffffffffn);return dt([o>>>24&255,o>>>16&255,o>>>8&255,o&255].join("."))}return t<8192||t>16383||t===8193&&i<=511||t===8193&&i===3512||t===8194||t===16383&&i<=4095}function Xi(e,n){let t=e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):e,i=isIP(t);if(i===4)return dt(t);if(i===6)return Ki(t);let o=e.toLowerCase().replace(/\.$/,"");return !o||!o.includes(".")||n.has(o)?true:xi.some(r=>o===r||o.endsWith(`.${r}`))}function at(e){return Object.freeze([...new Set(e.map(n=>n.origin))].sort())}function ct(e){return JSON.stringify({baseUriDomains:[],connectDomains:e.connectDomains,declared:e.declared,frameDomains:e.frameDomains,resourceDomains:[]})}function lt(e,n={}){if(e===void 0){let u=ct({declared:false,connectDomains:[],frameDomains:[]});return Object.freeze({declared:false,connectDomains:Object.freeze([]),frameDomains:Object.freeze([]),resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:createHash("sha256").update(u,"utf8").digest("hex")})}Hi(e)||N("CSP_ORIGIN_INVALID");let t=Reflect.ownKeys(e);t.some(u=>typeof u!="string")&&N("CSP_ORIGIN_INVALID"),t.some(u=>!ki.has(u))&&N("CSP_AXIS_UNKNOWN");let i=Re(e,"connectDomains"),o=Re(e,"frameDomains"),r=Re(e,"resourceDomains"),c=Re(e,"baseUriDomains");(r.length>0||c.length>0)&&N("CSP_AXIS_UNSUPPORTED"),($i(e)>Di||i.length>ot||o.length>ot||i.length+o.length>Li||[...i,...o].some(u=>new TextEncoder().encode(u).byteLength>Ci))&&N("CSP_LIMIT_EXCEEDED");let d=i.map(u=>rt(u,"connectDomains")),l=o.map(u=>rt(u,"frameDomains")),f=new Set((n.runtimeHostnames??[]).map(u=>u.toLowerCase().replace(/\.$/,"")));[...d,...l].some(u=>Xi(u.hostname,f))&&N("CSP_ORIGIN_FORBIDDEN");let m={declared:true,connectDomains:at(d),frameDomains:at(l)},y=ct(m);return Object.freeze({...m,resourceDomains:Object.freeze([]),baseUriDomains:Object.freeze([]),cspHash:createHash("sha256").update(y,"utf8").digest("hex")})}var qi=1,Wi=/^[a-z][a-zA-Z0-9]*(\.[a-zA-Z0-9]+)+$/,Zi=/^[A-Za-z][A-Za-z0-9._-]{0,127}$/,bt=/^[A-Za-z][A-Za-z0-9_-]{0,63}$/,Qi=/<\/?[A-Za-z][^>]*>/,eo=/^(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)/,no=/^(?:https?|file|ftp|ws|wss):\/\//i,to=/^\s*(?:javascript|data):/i,ut=/data:[^,\s]*,/i,io=/(?:https?|file|ftp|ws|wss):\/\//i,oo=/javascript:/i,ro=/(?:^[\s]*|[\s"'(=])(?:[A-Za-z]:[\\/]|\\\\|~[\\/]|\/)(?=[^\s"'<>])[^\s"'<>]*/,so=["manifestVersion","pluginId","definitionId","version","primitiveSet","activation","schema","layout"],ao=["manifestVersion","pluginId","definitionId","version","name","description","entry","surfaces","size","stateProjection","actions"],co=["_meta","icon","tone","entryHash","runtime","csp","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths","deviceFeatures","downloads","share","files","desktopOnly"],lo=["actionId","capability","mutation","inputSchema","resultProjection","backend"],uo=["confirmation","dataInputs","content","schedule","job","jobAccess","_meta"],fo=["everyMinutes"],po=["timeoutMs"],mo=["deadlineMs"],Io=4*1024,yo=["type","handler"],Ao=["type","command"],go=["env"],_o=["type","entry"],Eo=["path"],No=["hash"],ho=/^[0-9a-f]{64}$/,Po=/[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/,To=/[\r\n]/,So=16,bo=16,Uo=32,Oo=/^[a-z][A-Za-z0-9]{0,31}$/,Ro=["card-shell","meta-banner","heading","labeled-text","step-flow","text-list"],z=class e extends Error{constructor(t,i=t,o,r){super(i);this.code=t;this.path=o;this.rule=r;}code;path;rule;name="UiPluginValidationError";withPathPrefix(t){return new e(this.code,this.message,pe(t,this.path),this.rule)}};function pe(e,n){return n===void 0||n===""?e:e===""?n:n.startsWith("[")?`${e}${n}`:`${e}.${n}`}function s(e,n=e,t,i){throw new z(e,n,t,i)}function g(e,n){try{return n()}catch(t){throw t instanceof z?t.withPathPrefix(e):t}}function h(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 p(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Mo(e,n){let t={};for(let[i,o]of Object.entries(e))n.includes(i)||(t[i]=o);return t}function P(e,n,t=[]){let i=new Set([...n,...t]),o=Object.keys(e).find(c=>!i.has(c));o!==void 0&&s("MANIFEST_INVALID","MANIFEST_INVALID",o,"unknown-key");let r=n.find(c=>!p(e,c));r!==void 0&&s("MANIFEST_INVALID","MANIFEST_INVALID",r,"missing-key");}function rn(e,n=false,t=false,i=false){return Qi.test(e)||!i&&no.test(e)||eo.test(e)||t&&ut.test(e)||to.test(e)&&!(n&&/^\s*data:/i.test(e)&&!ut.test(e))}function we(e,n=new Set,t=0,i=false,o=false,r=""){if(typeof e=="string"){rn(e,i,o)&&s("UNSAFE_VALUE","UNSAFE_VALUE",r,"unsafe-value");return}if(!(e===null||typeof e!="object")){(t>8||n.has(e))&&s("MANIFEST_INVALID","MANIFEST_INVALID",r),n.add(e);try{if(Array.isArray(e)){e.forEach((c,a)=>we(c,n,t+1,!1,!1,pe(r,`[${a}]`)));return}h(e)||s("MANIFEST_INVALID","MANIFEST_INVALID",r);for(let[c,a]of Object.entries(e))we(a,n,t+1,i&&t===0&&(c==="name"||c==="description"),o,pe(r,c));}finally{n.delete(e);}}}function $(e,n){let t=e[n];return typeof t!="string"&&s("MANIFEST_INVALID"),t}function V(e,n,t){let i=e[n];return (!Number.isSafeInteger(i)||i<t)&&s("MANIFEST_INVALID"),i}function We(e){return Zi.test(e)||s("MANIFEST_INVALID"),e}function te(e){return Wi.test(e)||s("TOKEN_INVALID"),e}function wo(e){return bt.test(e)||s("MANIFEST_INVALID"),e}function Do(e){h(e)||s("MANIFEST_INVALID");let n={};for(let[t,i]of Object.entries(e)){let o=wo(t);h(i)||s("MANIFEST_INVALID");let r=i.type;if(r==="text"){P(i,["type","maxLength"]),n[o]={type:r,maxLength:V(i,"maxLength",1)};continue}if(r==="text-list"){P(i,["type","max","itemMaxLength"]),n[o]={type:r,max:V(i,"max",0),itemMaxLength:V(i,"itemMaxLength",1)};continue}if(r==="step-list"){P(i,["type","min","max","labelMaxLength","detailMaxLength"]);let c=V(i,"min",0),a=V(i,"max",1);c>a&&s("MANIFEST_INVALID"),n[o]={type:r,min:c,max:a,labelMaxLength:V(i,"labelMaxLength",1),detailMaxLength:V(i,"detailMaxLength",1)};continue}typeof r=="string"&&s("SCHEMA_TYPE_UNSUPPORTED"),s("MANIFEST_INVALID");}return n}function Lo(e,n,t){let i=e[n];(!i||i.type!==t)&&s("MANIFEST_INVALID");}function Me(e,n,t){let i=$(e,"field");return bt.test(i)||s("MANIFEST_INVALID"),Lo(n,i,t),i}function Co(e,n){h(e)||s("MANIFEST_INVALID");let t=e.primitive;switch(typeof t!="string"&&s("MANIFEST_INVALID"),Ro.includes(t)||s("PRIMITIVE_UNKNOWN"),t){case "card-shell":return P(e,["primitive"]),{primitive:t};case "meta-banner":return P(e,["primitive","badgeToken","noticeToken"]),{primitive:t,badgeToken:te($(e,"badgeToken")),noticeToken:te($(e,"noticeToken"))};case "heading":return P(e,["primitive","field"]),{primitive:t,field:Me(e,n,"text")};case "labeled-text":return P(e,["primitive","titleToken","field","variant"]),e.variant!=="callout"&&s("MANIFEST_INVALID"),{primitive:t,titleToken:te($(e,"titleToken")),field:Me(e,n,"text"),variant:"callout"};case "step-flow":return P(e,["primitive","titleToken","field"]),{primitive:t,titleToken:te($(e,"titleToken")),field:Me(e,n,"step-list")};case "text-list":{P(e,["primitive","titleToken","field"],["emptyToken","hideWhenEmpty"]);let i={primitive:t,titleToken:te($(e,"titleToken")),field:Me(e,n,"text-list")};return p(e,"emptyToken")&&(i.emptyToken=te($(e,"emptyToken"))),p(e,"hideWhenEmpty")&&(typeof e.hideWhenEmpty!="boolean"&&s("MANIFEST_INVALID"),i.hideWhenEmpty=e.hideWhenEmpty),i}}return s("MANIFEST_INVALID")}function ko(e,n){return Array.isArray(e)||s("MANIFEST_INVALID"),e.map(t=>Co(t,n))}function b(e="v2 manifest exceeds a contract limit",n,t){return s("LIMIT_EXCEEDED",e,n,t)}function ft(e,n){return (typeof e!="string"||e.length===0||e.length>4096||e.trim().length===0||Po.test(e)||To.test(e))&&s("MANIFEST_INVALID",`${n} is invalid`),(rn(e,true,true)||io.test(e)||oo.test(e)||ro.test(e))&&s("UNSAFE_VALUE",`${n} contains an unsafe value`),e}function Ze(e,n){return (typeof e!="string"||!ne.test(e))&&s("MANIFEST_INVALID",`${n} is invalid`),e}function xo(e){return (typeof e!="string"||!Fe.test(e)||e==="*"||e==="all")&&s("MANIFEST_INVALID","action capability is invalid"),e}function Ut(e){return (typeof e!="string"||!ho.test(e))&&s("MANIFEST_INVALID","resource hash is invalid"),e}function Qe(e,n=new Set,t=0,i=""){if(typeof e=="string"){e.length>4096&&b("v2 manifest string is too long",i,"string-too-long");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||s("MANIFEST_INVALID","v2 manifest contains a non-finite number",i,"non-finite-number");return}(e===void 0||typeof e=="function"||typeof e=="bigint")&&s("MANIFEST_INVALID","v2 manifest contains a non-JSON value",i,"non-json-value"),typeof e!="object"&&s("MANIFEST_INVALID","MANIFEST_INVALID",i),t>8&&b("v2 manifest nesting is too deep",i,"too-deep"),n.has(e)&&s("MANIFEST_INVALID","v2 manifest contains a cycle",i,"cycle"),n.add(e);try{if(Array.isArray(e)){e.length>128&&b("v2 manifest array is too long",i,"array-too-long"),e.forEach((o,r)=>Qe(o,n,t+1,pe(i,`[${r}]`)));return}h(e)||s("MANIFEST_INVALID","v2 manifest contains a non-plain object",i,"non-plain-object");for(let[o,r]of Object.entries(e))Qe(r,n,t+1,pe(i,o));}finally{n.delete(e);}}}function Ot(e){return (typeof e!="string"||e.length>4096||!ue.test(e))&&(typeof e=="string"&&e.length>4096&&b("projection path is too long"),s("MANIFEST_INVALID","projection paths must be canonical exact paths")),e.split(".").some(t=>le(t)||t===nt)&&s("MANIFEST_INVALID","projection paths cannot address reserved state keys"),e}function en(e){h(e)||s("MANIFEST_INVALID","projection policy must be an object"),P(e,["allow"]),Array.isArray(e.allow)||s("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=Ot(i);t.has(o)&&s("MANIFEST_INVALID","projection allowlist contains a duplicate path"),t.add(o),n.push(o);}return {allow:n}}function jo(e,n){if(e===void 0)return;Array.isArray(e)||s("MANIFEST_INVALID","dataPaths must be an array"),e.length>So&&b("dataPaths exceed the v2 limit");let t=[],i=new Set;for(let o of e){let r=Ot(o);i.has(r)&&s("MANIFEST_INVALID","dataPaths contain a duplicate path"),n.some(c=>Te(r,c))||s("MANIFEST_INVALID","dataPaths must be projection-allowed"),i.add(r),t.push(r);}return t}function Fo(e){Array.isArray(e)||s("MANIFEST_INVALID","deviceFeatures must be an array",void 0,"array"),e.length>bo&&s("MANIFEST_INVALID","deviceFeatures allow at most 16 names",void 0,"too-many-items");let n=[],t=new Set;for(let[i,o]of e.entries()){let r=`[${i}]`;typeof o!="string"&&s("MANIFEST_INVALID","a device feature name must be a string",r,"string"),o.length===0&&s("MANIFEST_INVALID","a device feature name must not be empty",r,"empty"),o.length>Uo&&s("MANIFEST_INVALID","a device feature name is at most 32 characters",r,"too-long"),Oo.test(o)||s("MANIFEST_INVALID","a device feature name starts with a lowercase letter and holds only letters and digits",r,"format"),t.has(o)&&s("MANIFEST_INVALID","deviceFeatures contain a duplicate name",r,"duplicate-item"),t.add(o),n.push(o);}return n}function Vo(e){if(e!==false)return e!==true&&s("MANIFEST_INVALID","downloads must be true or false",void 0,"boolean"),true}function vo(e){return typeof e!="boolean"&&s("MANIFEST_INVALID","desktopOnly must be true or false",void 0,"boolean"),e}function Go(e){return (!h(e)||e.view!==true||Object.keys(e).some(n=>n!=="view"&&n!=="entry"))&&s("MANIFEST_INVALID",'share must be { "view": true } or { "view": true, "entry": "<path>" }',void 0,"share-shape"),p(e,"entry")?{view:true,entry:Jo(e.entry)}:{view:true}}var pt=200,mt=3,Ho=/^[A-Za-z0-9][A-Za-z0-9._-]{0,99}$/;function Jo(e){typeof e!="string"&&s("MANIFEST_INVALID","share.entry must be a string","entry","entry-shape");let n=(i,o)=>s("MANIFEST_INVALID",`share.entry ${o}`,"entry",i);e.length===0&&n("empty","must not be empty"),e.length>pt&&n("too-long",`must be at most ${pt} characters`),e.startsWith("/")&&n("absolute","must be relative to the App folder");let t=e.split("/");t.length>mt&&n("too-many-segments",`must have at most ${mt} segments`);for(let i of t)i.length===0&&n("empty-segment","must not contain an empty segment"),(i==="."||i==="..")&&n("dot-segment",'must not contain "." or ".." segments'),Ho.test(i)||n("segment-shape",'segments start with an ASCII letter or digit, then use only letters, digits, ".", "_" and "-"');return t[t.length-1].endsWith(".html")||n("extension","must name a file ending in .html"),e}function $o(e){return (!h(e)||Object.keys(e).length!==1||typeof e.root!="string")&&s("MANIFEST_INVALID",'files must be exactly { "root": "<workspace folder>" }',void 0,"files-shape"),{root:Yo(e.root)}}var It=200,Bo=2,yt=4,At=100,zo=/^[\p{L}\p{N}][\p{L}\p{N}\p{M}_-]*$/u,Ko=[".git",".crewx","node_modules","apps","skills"],Xo=/[\u0000-\u001f\u007f-\u009f\\:<>"|?*]/;function Yo(e){let n=e.normalize("NFC"),t=(r,c)=>s("MANIFEST_INVALID",`files.root ${c}`,"root",r);n.length===0&&t("empty","must not be empty"),Xo.test(n)&&t("forbidden-character","must not contain control characters, backslash or colon"),(n.startsWith("/")||n.startsWith("~"))&&t("absolute","must be relative to the workspace"),Array.from(n).length>It&&t("too-long",`must be at most ${It} characters`);let i=n.split("/"),o=i[0].toLowerCase().replace(/[. ]+$/,"");Ko.includes(o)&&t("reserved-folder","must not start in an App code folder or a tool folder"),i.length<Bo&&t("too-shallow","must name a folder inside a top-level folder, such as docs/trips"),i.length>yt&&t("too-many-segments",`must have at most ${yt} segments`);for(let r of i)r.length===0&&t("empty-segment","must not contain an empty segment"),(r==="."||r==="..")&&t("dot-segment",'must not contain "." or ".." segments'),Array.from(r).length>At&&t("segment-too-long",`segments must be at most ${At} characters`),zo.test(r)||t("segment-shape",'segments must start with a letter or digit and contain only letters, digits, combining marks, "_" or "-"');return n}function ie(e,n,t=Number.MAX_SAFE_INTEGER){return (!Number.isSafeInteger(e)||e<0||e>t)&&s("MANIFEST_INVALID",`${n} is invalid`),e}function gt(e,n){return (typeof e!="number"||!Number.isFinite(e))&&s("MANIFEST_INVALID",`${n} is invalid`),e}function nn(e,n=0,t=new Set){if(typeof e=="string")return (e.length>4096||rn(e))&&s("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)||s("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)&&s("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=>nn(o,n+1,t));h(e)||s("MANIFEST_INVALID","schema enum contains a non-plain object");let i={};for(let[o,r]of Object.entries(e))le(o)&&s("MANIFEST_INVALID","schema enum contains a reserved key"),i[o]=nn(r,n+1,t);return i}finally{t.delete(e);}}function qo(e,n){if(e===void 0)return;Array.isArray(e)||s("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"||!ue.test(o))&&s("MANIFEST_INVALID","schema required contains an invalid key"),o.length>4096&&b("schema required key is too long"),i.has(o)&&s("MANIFEST_INVALID","schema required contains a duplicate key"),n&&!Object.prototype.hasOwnProperty.call(n,o)&&s("MANIFEST_INVALID","schema required references an undeclared property"),i.add(o),t.push(o);return t}function Wo(e,n){let t=n?ue:je;return e.length>4096&&b("schema property name is too long"),(!t.test(e)||e.split(".").some(i=>le(i)))&&s("MANIFEST_INVALID","schema property name is invalid"),e}function tn(e,n=0,t=false){h(e)||s("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"&&s("SCHEMA_TYPE_UNSUPPORTED","action inputSchema type is unsupported"),s("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"),P(e,["type"],o.filter(a=>a!=="type"));let r={type:i};if(p(e,"enum")&&(Array.isArray(e.enum)||s("MANIFEST_INVALID","schema enum must be an array"),e.enum.length>128&&b("schema enum is too long"),r.enum=e.enum.map(a=>nn(a))),i==="string"&&(p(e,"minLength")&&(r.minLength=ie(e.minLength,"schema minLength",4096)),p(e,"maxLength")&&(r.maxLength=ie(e.maxLength,"schema maxLength",4096)),r.minLength!==void 0&&r.maxLength!==void 0&&r.minLength>r.maxLength&&s("MANIFEST_INVALID","schema string length bounds are inverted")),(i==="number"||i==="integer")&&(p(e,"minimum")&&(r.minimum=gt(e.minimum,"schema minimum")),p(e,"maximum")&&(r.maximum=gt(e.maximum,"schema maximum")),r.minimum!==void 0&&r.maximum!==void 0&&r.minimum>r.maximum&&s("MANIFEST_INVALID","schema numeric bounds are inverted")),i==="array"&&(p(e,"minItems")&&(r.minItems=ie(e.minItems,"schema minItems",128)),p(e,"maxItems")&&(r.maxItems=ie(e.maxItems,"schema maxItems",128)),r.minItems!==void 0&&r.maxItems!==void 0&&r.minItems>r.maxItems&&s("MANIFEST_INVALID","schema array length bounds are inverted"),p(e,"items")&&(r.items=tn(e.items,n+1,false))),i==="object"){let a;if(p(e,"properties")){h(e.properties)||s("MANIFEST_INVALID","schema properties must be an object");let l=Object.entries(e.properties);l.length>64&&b("schema properties are too many"),a={};for(let[f,m]of l){let y=Wo(f,t);a[y]=tn(m,n+1,false);}r.properties=a;}p(e,"minProperties")&&(r.minProperties=ie(e.minProperties,"schema minProperties",64)),p(e,"maxProperties")&&(r.maxProperties=ie(e.maxProperties,"schema maxProperties",64)),r.minProperties!==void 0&&r.maxProperties!==void 0&&r.minProperties>r.maxProperties&&s("MANIFEST_INVALID","schema object property bounds are inverted");let d=qo(e.required,a);d!==void 0&&(r.required=d),p(e,"additionalProperties")&&(e.additionalProperties!==false&&s("MANIFEST_INVALID","schema additionalProperties must be false"),r.additionalProperties=false);}let c=JSON.stringify(r);return (c===void 0||Buffer.byteLength(c,"utf8")>2097152)&&b("action inputSchema subtree is too large"),r}function Zo(e){let n=tn(e,0,true);return (n.type!=="object"||!n.properties)&&s("MANIFEST_INVALID","action inputSchema must declare object properties"),n}function Qo(e){if(h(e)||s("MANIFEST_INVALID","action backend must be an object"),e.type==="core"){P(e,yo);let n=e.handler;return (typeof n!="string"||!Ve.test(n))&&s("MANIFEST_INVALID","core backend handler is invalid"),{type:"core",handler:n}}if(e.type==="skill"&&p(e,"entry"))return P(e,_o),e.entry!==F&&s("MANIFEST_INVALID",`skill backend entry must be ${F}`),{type:"skill",entry:F};if(e.type==="skill"){P(e,Ao,go),(!Array.isArray(e.command)||e.command.length===0||e.command.length>16)&&s("MANIFEST_INVALID","skill backend command is invalid");let n=[];for(let i of e.command)(typeof i!="string"||i.length===0||i.length>256||!ve.test(i))&&s("MANIFEST_INVALID","skill backend command token is invalid"),n.push(i);let t=p(e,"env")?rr(e.env):void 0;return {type:"skill",command:n,...t===void 0?{}:{env:t}}}s("MANIFEST_INVALID","action backend type is unsupported");}function er(e){h(e)||s("MANIFEST_INVALID","action must be an object"),P(e,lo,uo),p(e,"_meta")&&g("_meta",()=>Rt(e._meta));let n=g("actionId",()=>Ze(e.actionId,"actionId"));xe(n)&&s("MANIFEST_INVALID",`actionId "${n}" is not projection-safe`,"actionId");let t=g("capability",()=>xo(e.capability)),i=e.mutation;typeof i!="boolean"&&s("MANIFEST_INVALID","action mutation must be boolean","mutation");let o=g("inputSchema",()=>Zo(e.inputSchema)),r;if(p(e,"dataInputs")){Array.isArray(e.dataInputs)||s("MANIFEST_INVALID","action dataInputs must be an array","dataInputs");let u=o.properties,R=new Set,K=[];for(let A of e.dataInputs)(typeof A!="string"||!p(u,A)||R.has(A))&&s("MANIFEST_INVALID","action dataInputs must be unique declared properties","dataInputs"),R.add(A),K.push(A);r=K;}let c=g("resultProjection",()=>en(e.resultProjection)),a=g("backend",()=>Qo(e.backend)),d;p(e,"content")&&((a.type!=="skill"||!$e(e.content))&&s("MANIFEST_INVALID","action content declaration is invalid","content"),d=sr(e.content));let l;if(p(e,"confirmation")){let u=e.confirmation;u!=="none"&&u!=="native"&&s("MANIFEST_INVALID","action confirmation is invalid","confirmation"),l=u;}let f;p(e,"schedule")&&(f=g("schedule",()=>or(e.schedule,{backend:a,inputSchema:o,hasContent:d!==void 0,hasDataInputs:r!==void 0,confirmation:l})));let m;p(e,"job")&&(f!==void 0&&s("MANIFEST_INVALID","an action is either the scheduled run or a job, not both","job"),m=g("job",()=>ir(e.job,{backend:a,inputSchema:o,hasContent:d!==void 0,hasDataInputs:r!==void 0,confirmation:l})));let y;return p(e,"jobAccess")&&(m!==void 0&&s("MANIFEST_INVALID","an action is either the job or a job control, not both","jobAccess"),y=g("jobAccess",()=>tr(e.jobAccess,{backend:a,hasContent:d!==void 0}))),{actionId:n,capability:t,mutation:i,inputSchema:o,resultProjection:c,backend:a,...d===void 0?{}:{content:d},...r===void 0?{}:{dataInputs:r},...l===void 0?{}:{confirmation:l},...f===void 0?{}:{schedule:f},...m===void 0?{}:{job:m},...y===void 0?{}:{jobAccess:y}}}function nr(e,n,t){e.backend.type!=="core"||e.backend.handler!==Oe||((n??W)!==W&&s("MANIFEST_INVALID","view.call is only available to screen Apps",`${t}.backend.handler`),e.mutation!==false&&s("MANIFEST_INVALID","view.call must be read-only",`${t}.mutation`),e.confirmation!=="none"&&s("MANIFEST_INVALID","view.call requires confirmation none",`${t}.confirmation`),(e.content!==void 0||e.schedule!==void 0||e.job!==void 0||e.jobAccess!==void 0)&&s("MANIFEST_INVALID","view.call cannot declare content, jobs, or schedules",t),e.resultProjection===void 0&&s("MANIFEST_INVALID","view.call requires resultProjection",`${t}.resultProjection`));}function tr(e,n){return (n.backend.type!=="skill"||!("entry"in n.backend)||n.backend.entry!==F)&&s("MANIFEST_INVALID","jobAccess needs a tool-mode action","jobAccess"),n.hasContent&&s("MANIFEST_INVALID","a job control action takes no content","jobAccess"),(!Array.isArray(e)||e.length===0)&&s("MANIFEST_INVALID","jobAccess must list at least one operation","jobAccess"),(new Set(e).size!==e.length||!e.every(Ye))&&s("MANIFEST_INVALID","jobAccess must name each operation once: start, status or cancel","jobAccess"),Object.freeze([...e])}function ir(e,n){(n.backend.type!=="skill"||!("entry"in n.backend)||n.backend.entry!==F)&&s("MANIFEST_INVALID","job needs a tool-mode action","job"),(n.hasContent||n.hasDataInputs||n.confirmation!==void 0&&n.confirmation!=="none")&&s("MANIFEST_INVALID","a job action takes no content, dataInputs or native confirmation","job"),(n.inputSchema.required??[]).length>0&&s("MANIFEST_INVALID","a job action input must accept {}","inputSchema.required"),h(e)||s("MANIFEST_INVALID","job must be an object","job"),P(e,[],mo);let t=p(e,"deadlineMs")?e.deadlineMs:Ue.default;return Xe(t)||s("MANIFEST_INVALID","job deadlineMs is invalid","job.deadlineMs"),{deadlineMs:t}}function or(e,n){(n.backend.type!=="skill"||!("entry"in n.backend)||n.backend.entry!==F)&&s("MANIFEST_INVALID","schedule needs a tool-mode action","schedule"),(n.hasContent||n.hasDataInputs||n.confirmation!==void 0&&n.confirmation!=="none")&&s("MANIFEST_INVALID","a scheduled action takes no content, dataInputs or native confirmation","schedule"),(n.inputSchema.required??[]).length>0&&s("MANIFEST_INVALID","a scheduled action input must accept {}","inputSchema.required"),h(e)||s("MANIFEST_INVALID","schedule must be an object","schedule"),P(e,fo,po),ze(e.everyMinutes)||s("MANIFEST_INVALID","schedule everyMinutes is invalid","schedule.everyMinutes");let t=p(e,"timeoutMs")?e.timeoutMs:be.default;return Ke(t)||s("MANIFEST_INVALID","schedule timeoutMs is invalid","schedule.timeoutMs"),{everyMinutes:e.everyMinutes,timeoutMs:t}}function rr(e){return tt(e)||s("MANIFEST_INVALID","skill backend env is invalid"),Object.freeze([...e])}function sr(e){return Object.freeze({...e.in===void 0?{}:{in:Object.freeze({...e.in})},...e.out===void 0?{}:{out:Object.freeze({...e.out})}})}function ar(e){return h(e)||s("INITIAL_STATE_INVALID","initialState must be an object"),P(e,Eo,No),e.path!=="ui/state.json"&&s("MANIFEST_INVALID","initialState path is not fixed"),p(e,"hash")?{path:"ui/state.json",hash:Ut(e.hash)}:{path:"ui/state.json"}}function cr(e){let n=["wasm","terminal","htmlDocuments","appBrowser"];return (!h(e)||Object.keys(e).length===0||Object.keys(e).some(t=>!n.includes(t)||e[t]!==true))&&s("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}:{},...e.appBrowser===true?{appBrowser:true}:{}}}function dr(e,n){let t;try{t=lt(e);}catch(i){let o=i!==null&&typeof i=="object"&&"code"in i&&typeof i.code=="string"?i.code:"CSP_ORIGIN_INVALID";return s("MANIFEST_INVALID",o,void 0,o.toLowerCase().replace(/_/g,"-"))}if(t.frameDomains.length>0&&s("MANIFEST_INVALID","external origins in csp are not enabled in this rollout",void 0,"csp-not-enabled"),t.connectDomains.length!==0)return n?.terminal===true&&s("MANIFEST_INVALID","runtime.terminal cannot be combined with csp.connectDomains","connectDomains","terminal-with-connect-domains"),Object.freeze({connectDomains:t.connectDomains})}function lr(e,n){we(h(e)?Mo(e,["csp","downloads","files","share"]):e,new Set,0,true,true),Qe(e),h(e)||s("MANIFEST_INVALID"),P(e,ao,co),p(e,"_meta")&&g("_meta",()=>Rt(e._meta)),e.manifestVersion!==2&&s("MANIFEST_INVALID");let t;p(e,"runtime")&&(t=g("runtime",()=>cr(e.runtime)));let i;p(e,"csp")&&(i=g("csp",()=>dr(e.csp,t)));let o=g("pluginId",()=>Ze(e.pluginId,"pluginId")),r=g("definitionId",()=>Ze(e.definitionId,"definitionId")),c=g("version",()=>V(e,"version",1)),a=g("name",()=>ft(e.name,"name")),d=g("description",()=>ft(e.description,"description")),l;p(e,"icon")&&((typeof e.icon!="string"||!/^[a-z][a-z0-9-]{0,63}$/.test(e.icon))&&s("MANIFEST_INVALID","icon is invalid","icon"),l=e.icon);let f;p(e,"tone")&&((typeof e.tone!="string"||!Ge.includes(e.tone))&&s("MANIFEST_INVALID","tone is invalid","tone"),f=e.tone),e.entry!=="ui/index.html"&&s("MANIFEST_INVALID","entry path is not fixed","entry","fixed-value");let m;p(e,"entryHash")&&(m=g("entryHash",()=>Ut(e.entryHash)));let y;p(e,"initialState")&&(y=g("initialState",()=>ar(e.initialState)));let u;p(e,"usage")&&(e.usage!=="card"&&e.usage!=="window"&&s("MANIFEST_INVALID","usage is invalid","usage"),u=e.usage);let R;p(e,"detailPanel")&&(typeof e.detailPanel!="boolean"&&s("MANIFEST_INVALID","detailPanel is invalid","detailPanel"),R=e.detailPanel);let K;if(p(e,"displayModes")){((u??W)!==W||!Array.isArray(e.displayModes)||e.displayModes.length===0)&&s("MANIFEST_INVALID","displayModes are only valid for window Apps","displayModes");let j=new Set(["inline","floating","focused"]);(new Set(e.displayModes).size!==e.displayModes.length||e.displayModes.some(Ee=>typeof Ee!="string"||!j.has(Ee)))&&s("MANIFEST_INVALID","displayModes are invalid","displayModes"),K=e.displayModes;}(u??W)===W&&R!==void 0&&s("MANIFEST_INVALID","detailPanel is card-only","detailPanel");let A=n.mode??"local";A!=="local"&&A!=="installed"&&A!=="published"&&s("MANIFEST_INVALID","manifest mode is invalid"),A!=="local"&&m===void 0&&s("MANIFEST_INVALID","installed manifests require entryHash","entryHash","required-when-installed"),A!=="local"&&y!==void 0&&y.hash===void 0&&s("MANIFEST_INVALID","installed manifests require initialState.hash","initialState.hash","required-when-installed"),(!Array.isArray(e.surfaces)||e.surfaces.length===0)&&s("MANIFEST_INVALID","surfaces are invalid","surfaces"),e.surfaces.length>2&&b("surfaces exceed the v2 limit","surfaces","too-many-items");let yn=[],An=new Set;for(let j of e.surfaces)(typeof j!="string"||!He.includes(j))&&s("MANIFEST_INVALID","surface is unsupported","surfaces"),An.has(j)&&s("MANIFEST_INVALID","surfaces contain a duplicate","surfaces","duplicate-item"),An.add(j),yn.push(j);h(e.size)||s("MANIFEST_INVALID","size must be an object","size"),g("size",()=>P(e.size,["height"]));let gn=g("size",()=>V(e.size,"height",1));gn>720&&b("size.height exceeds the v2 limit","size.height","too-large");let ge=g("stateProjection",()=>en(e.stateProjection)),_e=e.summaryProjection===void 0?void 0:g("summaryProjection",()=>en(e.summaryProjection));_e!==void 0&&_e.allow.some(j=>!ge.allow.includes(j))&&s("MANIFEST_INVALID","summaryProjection must be a subset of stateProjection.allow","summaryProjection");let _n=g("dataPaths",()=>jo(e.dataPaths,ge.allow)),En=p(e,"deviceFeatures")?g("deviceFeatures",()=>Fo(e.deviceFeatures)):void 0,Nn=p(e,"downloads")?g("downloads",()=>Vo(e.downloads)):void 0,hn=p(e,"share")?g("share",()=>Go(e.share)):void 0,Pn=p(e,"files")?g("files",()=>$o(e.files)):void 0,Tn=p(e,"desktopOnly")?g("desktopOnly",()=>vo(e.desktopOnly)):void 0;Array.isArray(e.actions)||s("MANIFEST_INVALID","actions must be an array","actions"),e.actions.length>32&&b("actions exceed the v2 limit","actions","too-many-items");let Sn=[],bn=new Set,Un=0,On=0;for(let[j,Ee]of e.actions.entries()){let q=`actions[${j}]`,J=g(q,()=>er(Ee));if(nr(J,u,q),bn.has(J.actionId)&&s("MANIFEST_INVALID","actions contain a duplicate actionId",`${q}.actionId`,"duplicate-item"),J.schedule!==void 0&&(Un+=1,Un>Zn&&s("MANIFEST_INVALID","an App declares at most one scheduled action",`${q}.schedule`,"duplicate-item")),J.job!==void 0&&(On+=1,On>Qn&&s("MANIFEST_INVALID","an App declares at most one job action",`${q}.job`,"duplicate-item")),J.backend.type==="core"&&J.backend.handler==="state.set"){J.mutation||s("MANIFEST_INVALID","state.set actions must be mutations",`${q}.mutation`);for(let Ht of Object.keys(J.inputSchema.properties))ge.allow.includes(Ht)||s("MANIFEST_INVALID","state.set input paths must be projection-allowed",`${q}.inputSchema.properties`);}bn.add(J.actionId),Sn.push(J);}return {manifestVersion:2,pluginId:o,definitionId:r,version:c,name:a,description:d,...l===void 0?{}:{icon:l},...f===void 0?{}:{tone:f},entry:"ui/index.html",...m===void 0?{}:{entryHash:m},...t===void 0?{}:{runtime:t},...i===void 0?{}:{csp:i},...y===void 0?{}:{initialState:y},...u===void 0?{}:{usage:u},...R===void 0?{}:{detailPanel:R},...K===void 0?{}:{displayModes:K},surfaces:yn,size:{height:gn},stateProjection:ge,..._e===void 0?{}:{summaryProjection:_e},..._n===void 0?{}:{dataPaths:_n},...En===void 0?{}:{deviceFeatures:En},...Nn===void 0?{}:{downloads:Nn},...hn===void 0?{}:{share:hn},...Pn===void 0?{}:{files:Pn},...Tn===void 0?{}:{desktopOnly:Tn},actions:Sn}}function Rt(e){h(e)||s("MANIFEST_INVALID","_meta must be an object");let n=JSON.stringify(e);(n===void 0||Buffer.byteLength(n,"utf8")>Io)&&b("_meta exceeds the 4 KiB limit",void 0,"meta-too-large");}function ur(e){let n={},t={};for(let r of e.actions){n[r.actionId]={capabilities:[r.capability],inputKeys:Object.keys(r.inputSchema.properties??{}),...r.backend.type==="core"&&r.backend.handler===Oe?{mutation:r.mutation}:{},...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.schedule===void 0?{}:{schedule:r.schedule},...r.job===void 0?{}:{job:r.job},...r.jobAccess===void 0?{}:{jobAccess:r.jobAccess},...r.backend.type!=="skill"||r.backend.env===void 0?{}:{env:r.backend.env}};let c=r.backend.type==="skill"||r.backend.type==="core"&&(r.backend.handler==="state.set"||r.backend.handler===Oe);t[r.actionId]={actionId:r.actionId,mutation:r.mutation,backend:r.backend,launchPolicy:c?"allowed":"denied",...c?{}:{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},...e.downloads===void 0?{}:{downloads:e.downloads},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 fr(e,n={}){we(e),h(e)||s("MANIFEST_INVALID"),P(e,so),e.manifestVersion!==1&&s("MANIFEST_INVALID");let t=We($(e,"pluginId")),i=We($(e,"definitionId")),o=V(e,"version",1),r=V(e,"primitiveSet",1),c=n.supportedPrimitiveSet??qi;(!Number.isSafeInteger(c)||c<1)&&s("MANIFEST_INVALID"),r>c&&s("PRIMITIVE_SET_UNSUPPORTED"),h(e.activation)||s("MANIFEST_INVALID"),P(e.activation,["kind","language"]),e.activation.kind!=="fenced-code"&&s("MANIFEST_INVALID");let a=We($(e.activation,"language")),d=Do(e.schema),l=ko(e.layout,d);return {manifestVersion:1,pluginId:t,definitionId:i,version:o,primitiveSet:r,activation:{kind:"fenced-code",language:a},schema:d,layout:l}}function pr(e,n={}){return h(e)||s("MANIFEST_INVALID"),Object.hasOwn(e,"lineage")&&s("MANIFEST_INVALID","lineage is only allowed in product bundle indexes"),e.manifestVersion===2?lr(e,n):fr(e,n)}function Ie(e,n={}){try{return pr(e,n)}catch(t){if(t instanceof z)throw t;return s("MANIFEST_INVALID")}}function sn(e,n={}){let t=Ie(e,n);return t.manifestVersion===2?ur(t):t}var M="manifest.json",Z="ui-plugin.json",re=[M,Z];var an="0.3",Q="dev.crewx",fn=Object.freeze(["manifest_version","name","display_name","version","description","long_description","author","repository","homepage","documentation","support","icon","icons","screenshots","localization","server","tools","tools_generated","prompts","prompts_generated","keywords","license","privacy_policies","compatibility","user_config","_meta"]),pn=Object.freeze(["manifest_version","name","display_name","version","description","_meta"]),Lt=Object.freeze(fn.filter(e=>e!=="server"&&!pn.includes(e))),cn=Object.freeze(["entry","surfaces","size","stateProjection","actions"]),Ct=Object.freeze(["definitionId","definitionVersion","icon","tone","entryHash","runtime","initialState","usage","detailPanel","displayModes","summaryProjection","dataPaths","focusedAiDataPaths","csp","deviceFeatures","downloads","share","files","desktopOnly"]),mr=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,Ir=256,yr=/<\/?[A-Za-z][^>]*>/,Ar=/^\s*javascript:/i,gr=/data:[^,\s]*,/i;function kt(e){return typeof e=="string"&&e.length<=Ir&&mr.test(e)}var B=class extends Error{constructor(t,i){super(`${t}: ${i.path||"<file>"} (${i.rule})`);this.code=t;this.reason=i;}code;reason};function I(e,n,t,i,o){throw new B(e,{path:n,rule:t,...i===void 0?{}:{message:i},...o===void 0?{}:{file:o}})}function w(e){if(e===null||typeof e!="object"||Array.isArray(e))return false;try{let n=Object.getPrototypeOf(e);return n===Object.prototype||n===null}catch{return false}}function U(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function H(e){let n=`_meta["${Q}"]`;return e===void 0||e===""?n:e.startsWith("[")?`${n}${e}`:`${n}.${e}`}function _r(e){return e.toLowerCase().replace(/_/g,"-")}function Er(e){if(e===void 0||e==="")return "";let n=/^([^.[]+)(.*)$/.exec(e);if(!n)return H(e);let[,t,i]=n;switch(t){case "pluginId":return `name${i}`;case "name":return `display_name${i}`;case "description":return `description${i}`;case "_meta":return `_meta${i}`;case "version":return H("definitionVersion");case "definitionId":return H("definitionId");default:return H(`${t}${i}`)}}function xt(e,n,t){return {path:t(e.path),rule:e.rule??_r(e.code),...e.message!==e.code?{message:e.message}:{},file:n}}function jt(e){return JSON.parse(JSON.stringify(e))}function dn(e,n,t=0,i=new Set){if(typeof e=="string"){e.length>4096&&I("LIMIT_EXCEEDED",n,"string-too-long"),(yr.test(e)||Ar.test(e)||gr.test(e))&&I("UNSAFE_VALUE",n,"unsafe-value");return}if(!(e===null||typeof e=="boolean")){if(typeof e=="number"){Number.isFinite(e)||I("MANIFEST_INVALID",n,"non-finite-number");return}typeof e!="object"&&I("MANIFEST_INVALID",n,"non-json-value"),t>8&&I("LIMIT_EXCEEDED",n,"too-deep"),i.has(e)&&I("MANIFEST_INVALID",n,"cycle"),i.add(e);try{if(Array.isArray(e)){e.length>128&&I("LIMIT_EXCEEDED",n,"array-too-long"),e.forEach((o,r)=>dn(o,`${n}[${r}]`,t+1,i));return}w(e)||I("MANIFEST_INVALID",n,"non-plain-object");for(let[o,r]of Object.entries(e))dn(r,n===""?o:`${n}.${o}`,t+1,i);}finally{i.delete(e);}}}function v(e,n){return (typeof e!="string"||e.length===0)&&I("MANIFEST_INVALID",n,"string"),e}function oe(e,n){return w(e)||I("MANIFEST_INVALID",n,"object"),e}function Nr(e,n){Array.isArray(e)||I("MANIFEST_INVALID",n,"array"),e.forEach((t,i)=>v(t,`${n}[${i}]`));}function hr(e,n){typeof e!="boolean"&&I("MANIFEST_INVALID",n,"boolean");}function ye(e,n,t,i){for(let o of Object.keys(e))!t.includes(o)&&!i.includes(o)&&I("MANIFEST_INVALID",`${n}.${o}`,"unknown-key");for(let o of t)U(e,o)||I("MANIFEST_INVALID",`${n}.${o}`,"missing-key");}function Pr(e,n){if(e!=="icon")switch(dn(n,e),e){case "long_description":case "homepage":case "documentation":case "support":case "license":v(n,e);return;case "author":{let t=oe(n,e);ye(t,e,["name"],["email","url"]);for(let i of Object.keys(t))v(t[i],`${e}.${i}`);return}case "repository":{let t=oe(n,e);ye(t,e,[],["type","url"]);for(let i of Object.keys(t))v(t[i],`${e}.${i}`);return}case "icons":{Array.isArray(n)||I("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let o=`${e}[${i}]`,r=oe(t,o);ye(r,o,["src","size"],["theme"]),v(r.src,`${o}.src`),v(r.size,`${o}.size`),U(r,"theme")&&v(r.theme,`${o}.theme`);});return}case "screenshots":case "keywords":case "privacy_policies":Nr(n,e);return;case "tools":{Array.isArray(n)||I("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let o=`${e}[${i}]`,r=oe(t,o);ye(r,o,["name"],["description"]),v(r.name,`${o}.name`),U(r,"description")&&v(r.description,`${o}.description`);});return}case "prompts":{Array.isArray(n)||I("MANIFEST_INVALID",e,"array"),n.forEach((t,i)=>{let o=`${e}[${i}]`,r=oe(t,o);ye(r,o,["name","text"],["description","arguments"]),v(r.name,`${o}.name`),v(r.text,`${o}.text`);});return}case "tools_generated":case "prompts_generated":hr(n,e);return;case "localization":case "compatibility":case "user_config":oe(n,e);return;default:I("MANIFEST_INVALID",e,"unknown-key");}}function De(e){return typeof e=="string"&&ne.test(e)?e:void 0}function Ft(e){return Number.isSafeInteger(e)&&e>=1?e:void 0}function Tr(e){let n=De(e.name);if(n===void 0)return;let t=e._meta,i=w(t)?t[Q]:void 0,o=w(i)?i:{},r=U(o,"definitionId")?De(o.definitionId):n,c=U(o,"definitionVersion")?Ft(o.definitionVersion):1;return {pluginId:n,...r===void 0?{}:{definitionId:r},...c===void 0?{}:{definitionVersion:c}}}function Sr(e){let n=De(e.pluginId);if(n===void 0)return;let t=De(e.definitionId),i=Ft(e.version);return {pluginId:n,...t===void 0?{}:{definitionId:t},...i===void 0?{}:{definitionVersion:i}}}function br(e,n){if(e===Z)return n.builtinOnly===true;let t=n._meta,i=w(t)?t[Q]:void 0;return w(i)&&i.builtinOnly===true}function Ur(e,n){U(e,"server")&&I("MANIFEST_INVALID","server","server-unsupported","phase 1 runs CrewX-owned Apps only");for(let a of Object.keys(e))fn.includes(a)||I("MANIFEST_INVALID",a,"unknown-key");for(let a of pn)U(e,a)||I("MANIFEST_INVALID",a,"missing-key");e.manifest_version!==an&&I("MANIFEST_INVALID","manifest_version","unsupported-version",`manifest_version must be "${an}"`),kt(e.version)||I("MANIFEST_INVALID","version","semver","version must be a semver.org version such as 0.1.0");let t=e._meta;w(t)||I("MANIFEST_INVALID","_meta","object"),U(t,Q)||I("MANIFEST_INVALID",H(),"missing-key");let i=t[Q];w(i)||I("MANIFEST_INVALID",H(),"object");for(let a of Object.keys(i))cn.includes(a)||Ct.includes(a)||I("MANIFEST_INVALID",H(a),"unknown-key");for(let a of cn)a==="actions"&&n!==void 0||U(i,a)||I("MANIFEST_INVALID",H(a),"missing-key");if(n!==void 0&&U(i,"actions")&&I("MANIFEST_INVALID",H("actions"),"two-truths",`actions are declared in both ${M} and ${D}; a server.ts App keeps them in the tools file only`),Or(i.actions),U(i,"definitionVersion")){let a=i.definitionVersion;(!Number.isSafeInteger(a)||a<1)&&I("MANIFEST_INVALID",H("definitionVersion"),"positive-integer");}let o={};for(let a of Lt)U(e,a)&&(Pr(a,e[a]),o[a]=jt(e[a]));let r={};for(let[a,d]of Object.entries(t))a!==Q&&(r[a]=d);let c={manifestVersion:2,pluginId:e.name,definitionId:U(i,"definitionId")?i.definitionId:e.name,version:U(i,"definitionVersion")?i.definitionVersion:1,name:e.display_name,description:e.description};for(let[a,d]of Object.entries(i))a==="definitionId"||a==="definitionVersion"||(c[a]=d);return n!==void 0&&(c.actions=n.map(a=>{let{viewCall:d,...l}=a;return {...l,backend:d===true?{type:"core",handler:"view.call"}:{type:"skill",entry:F}}})),Object.keys(r).length>0&&(c._meta=r),{v2Input:c,...Object.keys(r).length>0?{vendorMeta:r}:{},passthrough:o}}function Or(e){Array.isArray(e)&&e.forEach((n,t)=>{let i=w(n)?n.backend:void 0;w(i)&&U(i,"entry")&&I("MANIFEST_INVALID",H(`actions[${t}].backend.entry`),"entry-not-authorable",`an action in ${M} cannot name an entry; a server.ts App declares its actions in ${D}`);});}function Rr(e,n,t){w(e)||I("MANIFEST_INVALID","","not-object","manifest.json must be a JSON object",M);let i;try{i=Ur(e,t);}catch(c){throw c instanceof B?new B(c.code,{...c.reason,file:M}):c}let o;try{let c=Ie(i.v2Input,{mode:n.mode??"local"});c.manifestVersion!==2&&I("MANIFEST_INVALID","","v2-required"),o=c;}catch(c){throw c instanceof z?new B(c.code,xt(c,M,Er)):c}let r=e.tools;if(Array.isArray(r)){let c=new Set(o.actions.map(a=>a.actionId));r.forEach((a,d)=>{let l=a.name;if(!c.has(l))throw new B("MANIFEST_INVALID",{path:`tools[${d}].name`,rule:"tool-not-action",message:"every tools[].name must be an action id",file:M})});}return {file:M,manifest:o,v2Input:i.v2Input,releaseVersion:e.version,...Object.keys(i.passthrough).length>0?{mcpb:i.passthrough}:{}}}function Mr(e,n){try{let t=Ie(e,{mode:n.mode??"local"});if(t.manifestVersion!==2)throw new B("MANIFEST_INVALID",{path:"manifestVersion",rule:"v2-required",message:"a workspace App requires manifestVersion 2",file:Z});return {file:Z,manifest:t,v2Input:e}}catch(t){throw t instanceof z?new B(t.code,xt(t,Z,i=>i??"")):t}}function ln(e){return et(sn(e).definition)}function wt(e){let{entryHash:n,initialState:t,...i}=e,o={...i};return t!==void 0&&(o.initialState={path:t.path}),jt(o)}function wr(e,n){let t=wt(e),i=wt(n);return [...new Set([...Object.keys(t),...Object.keys(i)])].sort().filter(r=>ee(t[r]??null)!==ee(i[r]??null))}function Dr(e,n){return e.entryHash!==void 0&&n.entryHash!==void 0&&e.entryHash!==n.entryHash||e.initialState?.hash!==void 0&&n.initialState?.hash!==void 0&&e.initialState.hash!==n.initialState.hash}function Lr(e,n){let t=wr(e,n),i=Dr(e,n),o="";try{let r=ln(e),c=ln(n);i=i||r!==c,o=` (definition hash ${r.slice(0,12)} vs ${c.slice(0,12)})`;}catch{i=true;}t.length===0&&!i||I("MANIFEST_DUAL_MISMATCH","","dual-manifest-mismatch",`${M} and ${Z} normalize to different definitions${o}`+(t.length>0?`; differing fields: ${t.join(", ")}`:""));}function G(e,n,t="MANIFEST_INVALID",i){return {code:t,reason:{path:e,rule:n,...i===void 0?{}:{message:i},file:D},files:[]}}function Dt(e){return {...G("","tools-needs-manifest-json","MANIFEST_INVALID",`${D} is read with ${M} only`),files:e}}function Cr(e,n){if(e.byteLength>n)return {failure:G("","file-too-large","LIMIT_EXCEEDED")};let t;try{t=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(e));}catch{return {failure:G("","invalid-json")}}if(!w(t))return {failure:G("","not-object","MANIFEST_INVALID",`${D} must be a JSON object`)};for(let o of Object.keys(t))if(o!=="schemaVersion"&&o!=="actions")return {failure:G(o,"unknown-key")};for(let o of ["schemaVersion","actions"])if(!U(t,o))return {failure:G(o,"missing-key")};if(t.schemaVersion!==1)return {failure:G("schemaVersion","unsupported-version","MANIFEST_INVALID",`schemaVersion must be ${1}`)};let i=t.actions;if(!Array.isArray(i))return {failure:G("actions","array")};for(let[o,r]of i.entries()){if(!w(r))return {failure:G(`actions[${o}]`,"object")};if(U(r,"backend"))return {failure:G(`actions[${o}].backend`,"tools-backend","MANIFEST_INVALID",`an action in ${D} cannot carry a backend`)};if(U(r,"viewCall")&&r.viewCall!==true)return {failure:G(`actions[${o}].viewCall`,"view-call-marker","MANIFEST_INVALID","viewCall must be the exact marker true")}}return {actions:i}}function kr(e,n){let t=n.maxBytes??262144,i=[],o=new TextDecoder("utf-8",{fatal:true});for(let r of re){let c=e[r];if(c===void 0)continue;if(c.byteLength>t)return {parsed:i,failure:{code:"LIMIT_EXCEEDED",reason:{path:"",rule:"file-too-large",file:r},files:[r]}};let a;try{a=JSON.parse(o.decode(c));}catch{return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"invalid-json",file:r},files:[r]}}}if(!w(a))return {parsed:i,failure:{code:"MANIFEST_INVALID",reason:{path:"",rule:"not-object",message:`${r} must be a JSON object`,file:r},files:[r]}};i.push({file:r,raw:a});}return {parsed:i}}function mn(e,n={}){let{parsed:t,failure:i}=kr(e,n),o=re.filter(u=>e[u]!==void 0);if(i!==void 0)return {ok:false,rejection:i,parseFailure:true,builtinOnly:false};let r=e[D],c=r===void 0?void 0:Cr(r,n.maxBytes??262144);if(t.length===0)return {ok:false,rejection:c===void 0?{code:"MANIFEST_INVALID",reason:{path:"",rule:"no-manifest-file",message:"neither manifest.json nor ui-plugin.json is present"},files:[]}:Dt(o),parseFailure:true,builtinOnly:false};let a=t[0],d=a.file===M?Tr(a.raw):Sr(a.raw),l=t.some(u=>br(u.file,u.raw)),f;if(c!==void 0){let u=t.some(R=>R.file===M)?c.failure:Dt(o);if(u!==void 0)return {ok:false,rejection:u,parseFailure:false,...d===void 0?{}:{identity:d},builtinOnly:l};f=c.actions;}let m=[];try{for(let u of t)m.push(u.file===M?Rr(u.raw,n,f):Mr(u.raw,n));m.length===2&&Lr(m[0].manifest,m[1].manifest);}catch(u){if(u instanceof B)return {ok:false,rejection:{code:u.code,reason:u.reason,files:u.code==="MANIFEST_DUAL_MISMATCH"?[...re]:u.reason.file===void 0||u.reason.file===D?o:[u.reason.file]},parseFailure:false,...d===void 0?{}:{identity:d},builtinOnly:l};throw u}let y=m[0];return {ok:true,...y,identity:d??{pluginId:y.manifest.pluginId},files:o}}new TextDecoder("utf-8",{fatal:true});var Vt=20*1e3;function vt(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function In(e){try{let n=C.lstatSync(e);return n.isSymbolicLink()||!n.isFile()?void 0:new Uint8Array(C.readFileSync(e))}catch{return}}function xr(e){let n=In(T.join(e,"package.json"));if(n)try{let t=JSON.parse(new TextDecoder("utf-8",{fatal:!0}).decode(n));return vt(t)?t:void 0}catch{return}}function jr(e){let n={};for(let i of re){let o=In(T.join(e,i));o&&(n[i]=o);}let t=In(T.join(e,D));if(t&&(n[D]=t),Object.keys(n).length!==0)try{let i=mn(n,{mode:"local"});if(!i.ok)return;for(let o of i.manifest.actions){let r=o.backend;if(r.type==="skill"&&"entry"in r&&r.entry)return Gt(r.entry)}return "dist/server.mjs"}catch{return}}function Fr(e){let n=e.main;if(typeof n=="string")return n;let t=e.bin;if(typeof t=="string")return t;if(vt(t)){let i=Object.values(t).find(o=>typeof o=="string");if(i)return i}}function Gt(e){return e===F||e.endsWith("/main.mjs")||e.endsWith("/entry.mjs")?T.posix.join(T.posix.dirname(e),"server.mjs"):e}function Vr(e){let n=xr(e),t=jr(e),i=n?Fr(n):void 0,o=t??(i?Gt(i):void 0);if(!o)throw new S("VERIFY_IMPORT_FAILED","verify","The App manifest does not declare a server entry.");if(!o||o.includes("\\")||o.includes("\0")||T.posix.isAbsolute(o)||o.split("/").some(a=>a===".."||a.length===0))throw new S("VERIFY_IMPORT_FAILED","verify","The App manifest has an unsafe server entry.");let r=T.resolve(e),c=T.resolve(r,...o.split("/"));if(c!==r&&!c.startsWith(`${r}${T.sep}`))throw new S("VERIFY_IMPORT_FAILED","verify","The App manifest server entry escaped the package.");try{let a=C.lstatSync(c);if(a.isSymbolicLink()||!a.isFile())throw new Error("not a regular file")}catch{throw new S("VERIFY_IMPORT_FAILED","verify",`The App server entry is missing: ${o}`)}return c}async function vr(e,n={}){let t=n.runtime,i=t?.workspaceRoot??e,o=Vr(e),c=await Pe({command:t?.execPath??process.execPath,args:["--input-type=module","-e",'import { pathToFileURL } from "node:url"; await import(pathToFileURL(process.argv[1]).href);',o],cwd:e,env:se(i,t?.isElectronRuntime),runner:n.runner,timeoutMs:n.timeoutMs??Vt,onTimeoutCode:"VERIFY_TIMEOUT",step:"verify",onOutput:a=>{let d=a.replace(/[\r\n]+/gu," ").replace(/\s+/gu," ").trim().slice(-400);if(d)try{n.onProgress?.({step:"verify",message:d});}catch{}}});if(c.error!==void 0||c.status!==0){let a=Rn(c.stderr||c.error?.message);throw new S("VERIFY_IMPORT_FAILED","verify","The App server module could not be imported.",a)}}var Gr=Vt;
7
+ export{ui as APP_INSTALL_NO_OUTPUT_TIMEOUT_MS,li as APP_INSTALL_TIMEOUT_MS,Gr as APP_VERIFY_TIMEOUT_MS,S as AppInstallError,se as buildAppRuntimeEnv,di as prepareAppDependencies,Xn as resolveNpmCli,vr as verifyAppLaunch};