@xenosystem/agent-sdk 0.9.21 → 0.9.22

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.
Files changed (46) hide show
  1. package/README.md +6 -3
  2. package/dist/artifacts/index.cjs +1 -1
  3. package/dist/artifacts/index.js +1 -1
  4. package/dist/automation/index.d.cts +28 -0
  5. package/dist/automation/index.d.ts +28 -0
  6. package/dist/control-plane/index.cjs +1 -1
  7. package/dist/control-plane/index.js +1 -1
  8. package/dist/electron/index.cjs +132 -128
  9. package/dist/electron/index.d.cts +56 -0
  10. package/dist/electron/index.d.ts +56 -0
  11. package/dist/electron/index.js +129 -125
  12. package/dist/electron/metafile-cjs.json +1 -1
  13. package/dist/electron/metafile-esm.json +1 -1
  14. package/dist/governance/index.d.cts +29 -0
  15. package/dist/governance/index.d.ts +29 -0
  16. package/dist/hosted/index.cjs +1 -1
  17. package/dist/hosted/index.js +1 -1
  18. package/dist/hosted/metafile-cjs.json +1 -1
  19. package/dist/hosted/metafile-esm.json +1 -1
  20. package/dist/index.cjs +336 -330
  21. package/dist/index.d.cts +165 -2
  22. package/dist/index.d.ts +165 -2
  23. package/dist/index.js +333 -327
  24. package/dist/mcp/index.d.cts +28 -0
  25. package/dist/mcp/index.d.ts +28 -0
  26. package/dist/metafile-cjs.json +1 -1
  27. package/dist/metafile-esm.json +1 -1
  28. package/dist/providers/metafile-cjs.json +1 -1
  29. package/dist/providers/metafile-esm.json +1 -1
  30. package/dist/session/index.cjs +56 -54
  31. package/dist/session/index.d.cts +63 -1
  32. package/dist/session/index.d.ts +63 -1
  33. package/dist/session/index.js +56 -54
  34. package/dist/session/metafile-cjs.json +1 -1
  35. package/dist/session/metafile-esm.json +1 -1
  36. package/dist/skills/index.d.cts +28 -0
  37. package/dist/skills/index.d.ts +28 -0
  38. package/dist/ui/index.d.cts +28 -0
  39. package/dist/ui/index.d.ts +28 -0
  40. package/dist/utils/index.cjs +17 -16
  41. package/dist/utils/index.d.cts +31 -1
  42. package/dist/utils/index.d.ts +31 -1
  43. package/dist/utils/index.js +14 -13
  44. package/dist/utils/metafile-cjs.json +1 -1
  45. package/dist/utils/metafile-esm.json +1 -1
  46. package/package.json +1 -1
@@ -1 +1 @@
1
- "use strict";var O=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var ge=(e,t)=>{for(var r in t)O(e,r,{get:t[r],enumerable:!0})},fe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of me(t))!pe.call(e,o)&&o!==r&&O(e,o,{get:()=>t[o],enumerable:!(n=le(t,o))||n.enumerable});return e};var he=e=>fe(O({},"__esModule",{value:!0}),e);var We={};ge(We,{XENO_HOSTED_CONTROL_SCHEMA_VERSION:()=>q,XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION:()=>k,XENO_HOSTED_EVENT_SCHEMA_VERSION:()=>P,XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA:()=>w,XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS:()=>W,XENO_HOSTED_EXECUTION_ADAPTER_PROTOCOL_VERSION:()=>M,XENO_HOSTED_EXECUTION_PROTOCOL_VERSION:()=>re,XENO_HOSTED_EXECUTION_TOOL_NAMES:()=>ne,XENO_HOSTED_RESULT_SCHEMA_VERSION:()=>L,XENO_HOSTED_RUN_SCHEMA_VERSION:()=>Qe,XENO_HOSTED_TRIGGER_SCHEMA_VERSION:()=>Ye,assertValidXenoHostedExecutionJob:()=>Me,createXenoHostedControlCommand:()=>ce,createXenoHostedEnvironmentManifest:()=>ye,createXenoHostedEvent:()=>xe,createXenoHostedExecutionBoundaryReceipt:()=>oe,createXenoHostedRunResult:()=>de,deriveHostedIdempotencyKey:()=>Ee,hostedEnvironmentIdentity:()=>be,normalizeXenoHostedControlAcknowledgement:()=>Ue,verifyXenoHostedControlCommand:()=>ze,verifyXenoHostedEnvironmentManifest:()=>I,verifyXenoHostedEventChain:()=>we,verifyXenoHostedExecutionAdapterCertification:()=>Oe,verifyXenoHostedExecutionJob:()=>se,verifyXenoHostedRunResult:()=>Je,verifyXenoHostedWebhook:()=>Ae,xenoHostedExecutionAdapterSigningPayload:()=>Ce});module.exports=he(We);var k=1,Qe=1,P=1,Ye=1;var x=require("node:crypto");function u(e){return JSON.stringify(N(e,new Set))}function N(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(o=>N(o,t));return t.delete(e),n}let r={};for(let n of Object.keys(e).sort((o,s)=>o.localeCompare(s))){let o=e[n];if(o===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);r[n]=N(o,t)}return t.delete(e),r}function y(e,t={}){for(let r of e){let n=r.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&t.allowTab===!0)&&!((n===10||n===13)&&t.allowLineBreaks===!0))return!0}return!1}function ye(e){let t={...J(e),schemaVersion:1,kind:"xeno-hosted-environment"};return{...t,checksum:{algorithm:"sha256",value:S(t)}}}function I(e){let t=[];if(e?.schemaVersion!==1||e.kind!=="xeno-hosted-environment")return t.push("Unsupported hosted environment manifest"),{valid:!1,errors:t};let r;try{let{checksum:n,schemaVersion:o,kind:s,...i}=e;r={...J(i),schemaVersion:1,kind:"xeno-hosted-environment"}}catch(n){return t.push(n instanceof Error?n.message:String(n)),{valid:!1,errors:t}}return u(r)!==u(ve(e))&&t.push("Hosted environment manifest is not normalized"),(e.checksum?.algorithm!=="sha256"||e.checksum.value!==S(r))&&t.push("Hosted environment checksum mismatch"),{valid:t.length===0,errors:t}}function xe(e){let t=p(e.streamId,"streamId"),r=K(e.sequence,"sequence");if(e.previous){if(e.previous.streamId!==t)throw new Error("Previous event belongs to another stream");if(e.previous.sequence+1!==r)throw new Error("Hosted event sequence must be contiguous")}else if(r!==1)throw new Error("The first hosted event sequence must be 1");let n={schemaVersion:1,kind:"xeno-hosted-event",eventId:p(e.eventId??`hevt_${(0,x.randomUUID)()}`,"eventId"),streamId:t,sequence:r,timestamp:G(e.timestamp??new Date().toISOString(),"timestamp"),type:F(e.type,"type"),actorId:p(e.actorId,"actorId"),...e.idempotencyKey?{idempotencyKey:c(e.idempotencyKey,"idempotencyKey",512)}:{},payload:ke(e.payload??{},"payload"),previousHash:e.previous?.hash??null};return{...n,hash:S(n)}}function we(e,t){let r=[],n,o=t?t.afterSequence+1:1,s=t?.lastHash??null;for(let a of e){if(a.schemaVersion!==1||a.kind!=="xeno-hosted-event"){r.push(`Unsupported hosted event at sequence ${String(a.sequence)}`);continue}a.sequence!==o&&r.push(`Hosted event sequence gap at ${a.sequence}; expected ${o}`),a.previousHash!==s&&r.push(`Hosted event previous hash mismatch at ${a.sequence}`);let{hash:m,...h}=a;m!==S(h)&&r.push(`Hosted event hash mismatch at ${a.sequence}`),n&&n.streamId!==a.streamId&&r.push(`Hosted event stream changed at ${a.sequence}`),n=a,o=a.sequence+1,s=a.hash}let i=e.at(-1);return{valid:r.length===0,errors:r,cursor:i?{streamId:i.streamId,afterSequence:i.sequence,lastHash:i.hash}:t??null}}function be(e){let t=I(e);if(!t.valid)throw new Error(t.errors.join("; "));return`${e.environmentId}@${e.revision}:${e.checksum.value}`}function Ee(...e){if(e.length===0)throw new Error("At least one idempotency-key part is required");let t=e.map((r,n)=>He(r,`parts[${n}]`));return`xeno:${(0,x.createHash)("sha256").update(t.join("\0")).digest("hex")}`}function J(e){let t=e.secrets.map((o,s)=>({ref:p(o.ref,`secrets[${s}].ref`),target:o.target.kind==="environment"?{kind:"environment",name:Se(o.target.name)}:{kind:"file",path:H(o.target.path,`secrets[${s}].target.path`)},required:!!o.required,exposeToChildProcesses:!!o.exposeToChildProcesses})),r=new Set,n=new Set;for(let o of t){if(r.has(o.ref))throw new Error(`Duplicate secret ref: ${o.ref}`);r.add(o.ref);let s=`${o.target.kind}:${o.target.kind==="environment"?o.target.name:o.target.path}`;if(n.has(s))throw new Error(`Duplicate secret target: ${s}`);n.add(s)}if(e.network.default!=="deny")throw new Error("Hosted network policy must be default-deny");return{environmentId:p(e.environmentId,"environmentId"),revision:K(e.revision,"revision"),createdAt:G(e.createdAt,"createdAt"),createdBy:p(e.createdBy,"createdBy"),workspaceId:p(e.workspaceId,"workspaceId"),name:c(e.name,"name",160),repository:{provider:e.repository.provider,repository:c(e.repository.repository,"repository.repository",2048),ref:c(e.repository.ref,"repository.ref",512),...e.repository.commit?{commit:Te(e.repository.commit,"repository.commit")}:{},...e.repository.subdirectory?{subdirectory:H(e.repository.subdirectory,"repository.subdirectory")}:{},...e.repository.shallow!==void 0?{shallow:!!e.repository.shallow}:{}},image:{reference:c(e.image.reference,"image.reference",2048),digest:_e(e.image.digest),os:e.image.os,architecture:e.image.architecture},setup:e.setup.map((o,s)=>({id:p(o.id,`setup[${s}].id`),command:c(o.command,`setup[${s}].command`,32768),...o.workingDirectory?{workingDirectory:H(o.workingDirectory,`setup[${s}].workingDirectory`)}:{},timeoutMs:d(o.timeoutMs,`setup[${s}].timeoutMs`,1e3,36e5),network:o.network})),caches:e.caches.map((o,s)=>({key:c(o.key,`caches[${s}].key`,512),path:H(o.path,`caches[${s}].path`),...o.restoreKeys?.length?{restoreKeys:Re(o.restoreKeys,`caches[${s}].restoreKeys`,512)}:{},...o.readOnly!==void 0?{readOnly:!!o.readOnly}:{},...o.maxBytes!==void 0?{maxBytes:d(o.maxBytes,`caches[${s}].maxBytes`,1,Number.MAX_SAFE_INTEGER)}:{}})),network:{default:"deny",dns:e.network.dns,destinations:e.network.destinations.map((o,s)=>({host:Ie(o.host,`network.destinations[${s}].host`),...o.ports?.length?{ports:[...new Set(o.ports.map(i=>d(i,"port",1,65535)))].sort((i,a)=>i-a)}:{},...o.protocols?.length?{protocols:[...new Set(o.protocols)].sort()}:{},reason:c(o.reason,`network.destinations[${s}].reason`,500)})).sort((o,s)=>o.host.localeCompare(s.host)),...e.network.maxResponseBytes!==void 0?{maxResponseBytes:d(e.network.maxResponseBytes,"network.maxResponseBytes",1,Number.MAX_SAFE_INTEGER)}:{}},secrets:t,resources:{cpuMillis:d(e.resources.cpuMillis,"resources.cpuMillis",10,1e6),memoryBytes:d(e.resources.memoryBytes,"resources.memoryBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),diskBytes:d(e.resources.diskBytes,"resources.diskBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),processLimit:d(e.resources.processLimit,"resources.processLimit",1,65535),wallTimeMs:d(e.resources.wallTimeMs,"resources.wallTimeMs",1e3,10080*60*1e3)},retention:{workspaceTtlMs:d(e.retention.workspaceTtlMs,"retention.workspaceTtlMs",0,365*24*60*60*1e3),eventTtlMs:d(e.retention.eventTtlMs,"retention.eventTtlMs",6e4,365*24*60*60*1e3),artifactTtlMs:d(e.retention.artifactTtlMs,"retention.artifactTtlMs",6e4,365*24*60*60*1e3),wipeWorkspace:!!e.retention.wipeWorkspace},labels:Object.fromEntries(Object.entries(e.labels).map(([o,s])=>[F(o,"label key"),c(s,`labels.${o}`,500)]).sort(([o],[s])=>o.localeCompare(s)))}}function ve(e){let{checksum:t,...r}=e;return r}function S(e){return(0,x.createHash)("sha256").update(u(e)).digest("hex")}function ke(e,t){let r=u(e);if(Buffer.byteLength(r,"utf8")>256*1024)throw new Error(`${t} exceeds 262144 bytes`);return JSON.parse(r)}function p(e,t){let r=c(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function F(e,t){let r=c(e,t,160);if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function c(e,t,r){let n=e.trim();if(!n||n.length>r||y(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function He(e,t){let r=e.trim();if(r.length>4096||y(r,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return r}function K(e,t){return d(e,t,1,Number.MAX_SAFE_INTEGER)}function d(e,t,r,n){if(!Number.isSafeInteger(e)||e<r||e>n)throw new Error(`${t} must be an integer between ${r} and ${n}`);return e}function G(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return e}function Ie(e,t){let r=c(e.toLowerCase(),t,253);if(r==="localhost"||/^(?:\d{1,3}\.){3}\d{1,3}$/.test(r)||r.includes(":")||!/^(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(r))throw new Error(`${t} must be a public DNS hostname or wildcard hostname`);return r}function H(e,t){let r=c(e.replaceAll("\\","/"),t,4096);if(r.startsWith("/")||/^[A-Za-z]:\//.test(r)||r.split("/").includes(".."))throw new Error(`${t} must be workspace-relative`);return r.replace(/^\.\//,"")}function Se(e){let t=c(e,"secret environment name",256);if(!/^[A-Z_][A-Z0-9_]*$/.test(t))throw new Error("Secret environment target must be an uppercase environment variable name");return t}function _e(e){let t=e.trim().toLowerCase();if(!/^sha256:[a-f0-9]{64}$/.test(t))throw new Error("image.digest must be a sha256 OCI digest");return t}function Te(e,t){return c(e,t,512)}function Re(e,t,r){return[...new Set(e.map((n,o)=>c(n,`${t}[${o}]`,r)))]}var g=require("node:crypto");function Ae(e){let t=typeof e.body=="string"?Buffer.from(e.body,"utf8"):Buffer.from(e.body),r=(0,g.createHash)("sha256").update(t).digest("hex"),n=e.signature?.trim();if(!n)return{valid:!1,source:e.source,bodySha256:r,error:"missing-signature"};if(!e.secret||e.secret.length<16)throw new Error("Webhook secret must contain at least 16 characters");let o,s=n;if(e.source==="slack"){if(!e.timestamp||!/^\d+$/.test(e.timestamp))return{valid:!1,source:e.source,bodySha256:r,error:"invalid-timestamp"};let a=Number(e.timestamp)*1e3,m=Math.abs((e.now??new Date).getTime()-a);if(!Number.isFinite(a)||m>(e.maxClockSkewMs??5*6e4))return{valid:!1,source:e.source,bodySha256:r,timestamp:e.timestamp,error:"stale-timestamp"};o=`v0=${(0,g.createHmac)("sha256",e.secret).update(`v0:${e.timestamp}:`).update(t).digest("hex")}`}else e.source==="gitlab"?o=e.secret:e.source==="teams"?o=`HMAC ${(0,g.createHmac)("sha256",Buffer.from(e.secret,"base64")).update(t).digest("base64")}`:(o=`${e.source==="github"||e.source==="jira"?"sha256=":e.source==="xeno"?"v1=":""}${(0,g.createHmac)("sha256",e.secret).update(t).digest("hex")}`,e.source==="linear"&&s.startsWith("sha256=")&&(s=s.slice(7)));let i=Xe(o,s);return{valid:i,source:e.source,bodySha256:r,...e.timestamp?{timestamp:e.timestamp}:{},...i?{}:{error:"invalid-signature"}}}function Xe(e,t){let r=Buffer.from(e,"utf8"),n=Buffer.from(t,"utf8");return r.length===n.length&&(0,g.timingSafeEqual)(r,n)}var A=require("node:crypto");var w="xeno.hosted-execution-adapter-certification.v2",M=2,W=744*60*60*1e3;function Ce(e){return Z(e),Buffer.from(D(e),"utf8")}function Oe(e,t){if(e?.schemaVersion!==w)throw new Error(`Hosted execution adapter certificate must use ${w}`);let{signature:r,...n}=e;if(Z(n),r?.algorithm!=="ed25519")throw new Error("Hosted execution adapter signature must use ed25519");let o=T(t.executableSha256,"executableSha256"),s=T(t.controlPlaneCandidateSha256,"controlPlaneCandidateSha256");if(n.adapter.executableSha256!==o)throw new Error("Hosted execution adapter executable does not match its signed certificate");if(n.controlPlaneCandidateSha256!==s)throw new Error("Hosted execution adapter certificate is bound to another control-plane candidate");let i=t.platform??process.platform,a=t.architecture??process.arch;if(n.platform.os!==i||n.platform.architecture!==a)throw new Error(`Hosted execution adapter certificate targets ${n.platform.os}-${n.platform.architecture}, not ${i}-${a}`);let m=R(n.issuedAt,"issuedAt"),h=R(n.expiresAt,"expiresAt"),z=(t.now??new Date).getTime();if(m>z+5*6e4)throw new Error("Hosted execution adapter certificate is not yet valid");if(h<=z)throw new Error("Hosted execution adapter certificate has expired");if(h<=m||h-m>W)throw new Error("Hosted execution adapter certificate lifetime must be positive and at most 31 days");let U=t.trustedKeys[n.reviewer.keyId];if(!U)throw new Error(`Hosted execution adapter reviewer key is not trusted: ${n.reviewer.keyId}`);if(!(0,A.verify)(null,Buffer.from(D(n),"utf8"),U,Pe(r.value,"signature.value")))throw new Error("Hosted execution adapter certificate signature is invalid");return{certificationId:n.certificationId,adapterName:n.adapter.name,adapterVersion:n.adapter.version,protocolVersion:n.adapter.protocolVersion,executableSha256:o,controlPlaneCandidateSha256:s,certificateSha256:(0,A.createHash)("sha256").update(D(e)).digest("hex"),expiresAt:n.expiresAt,reviewerKeyId:n.reviewer.keyId}}function Z(e){if(e.schemaVersion!==w)throw new Error(`Hosted execution adapter certificate must use ${w}`);if(_(e.certificationId,"certificationId"),_(e.adapter?.name,"adapter.name"),_(e.adapter?.version,"adapter.version"),e.adapter?.protocolVersion!==M)throw new Error(`Hosted execution adapter protocol must be ${M}`);T(e.adapter.executableSha256,"adapter.executableSha256"),T(e.controlPlaneCandidateSha256,"controlPlaneCandidateSha256"),_(e.reviewer?.keyId,"reviewer.keyId");let t=["immutableImages","filesystemIsolation","networkDefaultDeny","destinationAllowlist","secretProjection","nonRootExecution","readOnlyRoot","processTreeCleanup","resourceLimits","interactiveControl","artifactProtocol","gitResultReporting"];if(!e.capabilities||t.some(r=>e.capabilities[r]!==!0))throw new Error("Hosted execution adapter certificate does not attest every required containment capability");R(e.issuedAt,"issuedAt"),R(e.expiresAt,"expiresAt")}function D(e){return u(e)}function T(e,t){let r=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(r))throw new Error(`${t} must be a lowercase SHA-256 digest`);return r}function _(e,t){let r=e?.trim();if(!r||r.length>256||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function R(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return r}function Pe(e,t){if(typeof e!="string"||e.length===0||e.length>4096||!/^[A-Za-z0-9+/]+={0,2}$/.test(e))throw new Error(`${t} must be bounded base64`);let r=Buffer.from(e,"base64");if(r.toString("base64")!==e)throw new Error(`${t} is not canonical base64`);return r}var te=require("node:crypto");var Q=["low","medium","high","xhigh","max"],Y=["default","plan","acceptEdits","auto","dontAsk","bypassPermissions"];var re=2,ne=["Read","Write","Edit","Glob","Grep","WebFetch"],Ne=new Set(ne);function oe(e){if(!ie(e.certificationId))throw new Error("certificationId is invalid");let t=new Set(e.authority.secretRefs);return{certificationId:e.certificationId,environmentChecksum:e.environment.checksum.value,imageDigest:e.environment.image.digest,networkPolicySha256:ee({authority:e.authority.network,policy:e.environment.network}),secretProjectionSha256:ee(e.environment.secrets.filter(r=>t.has(r.ref))),filesystem:e.authority.filesystem,network:e.authority.network==="deny"?"deny":"allowlist",immutableImage:!0,readOnlyRoot:!0,nonRoot:!0,processTreeCleanup:!0,resourceLimits:!0,inferenceGateway:"brokered"}}function se(e){let t=[];if(!Le(e))return{valid:!1,errors:["Hosted execution job must be an object"]};let r=e;if(r.protocolVersion!==re||r.kind!=="xeno-hosted-execution-job")return t.push("Unsupported hosted execution protocol"),{valid:!1,errors:t};b(r.runId,"runId",t),b(r.userId,"userId",t),b(r.workspaceId,"workspaceId",t),V(r.workspaceHostPath,"workspaceHostPath",4096,t),V(r.prompt,"prompt",512*1024,t),V(r.model,"model",512,t),r.effort!==void 0&&!Q.includes(r.effort)&&t.push("effort is invalid"),Y.includes(r.permissionMode)||t.push("permissionMode is invalid"),(typeof r.runScopedToken!="string"||!r.runScopedToken.startsWith("xrun_")||r.runScopedToken.length>16*1024)&&t.push("runScopedToken is not a bounded run-scoped token");let n;try{n=new URL(r.inferenceBaseUrl),(n.protocol!=="https:"||n.username||n.password||n.hash)&&t.push("inferenceBaseUrl must be credential-free HTTPS")}catch{t.push("inferenceBaseUrl is invalid")}let o=I(r.environment);t.push(...o.errors.map(i=>`environment: ${i}`)),r.environment?.workspaceId!==r.workspaceId&&t.push("environment workspace does not match the job"),r.environment?.image?.os!=="linux"&&t.push("hosted execution image must target Linux");let s=r.environment?.repository?.commit;(typeof s!="string"||!/^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(s))&&t.push("environment repository requires a full 40- or 64-character commit object id"),De(r.authority,t),Ve(r.budget,r.environment,t),Be(r.allowedTools,t),$e(r,t),qe(r,t),n&&!r.environment?.network?.destinations?.some(i=>{let a=i.ports?.length?i.ports:[443];return i.host.toLowerCase()===n.hostname.toLowerCase()&&a.includes(Number(n.port||443))})&&t.push("inference origin is absent from the environment network allowlist");try{let i=je(r.environment?.repository);r.environment?.network?.destinations?.some(a=>{let m=a.ports?.length?a.ports:[443];return a.host.toLowerCase()===i.hostname&&m.includes(i.port)})||t.push("repository origin is absent from the environment network allowlist")}catch{t.push("environment repository must resolve to a credential-free HTTPS origin")}return{valid:t.length===0,errors:t}}function Me(e){let t=se(e);if(!t.valid)throw new Error(`Invalid hosted execution job: ${t.errors.join("; ")}`)}function De(e,t){(!e||!["read","workspace-write"].includes(e.filesystem))&&t.push("authority.filesystem is invalid"),(!e||!["deny","environment-policy"].includes(e.network))&&t.push("authority.network is invalid"),(!e||!["deny","approval-required"].includes(e.externalActions))&&t.push("authority.externalActions is invalid"),!Array.isArray(e?.secretRefs)||new Set(e.secretRefs).size!==e.secretRefs.length?t.push("authority.secretRefs must be a unique array"):e.secretRefs.forEach((r,n)=>b(r,`authority.secretRefs[${n}]`,t))}function Ve(e,t,r){(!e||!Number.isFinite(e.maxCredits)||e.maxCredits<=0)&&r.push("budget.maxCredits is invalid"),(!e||!B(e.maxDurationMs)||e.maxDurationMs>(t?.resources?.wallTimeMs??0))&&r.push("budget.maxDurationMs is invalid or exceeds the environment limit"),e?.maxTokens!==void 0&&!B(e.maxTokens)&&r.push("budget.maxTokens is invalid"),e?.maxToolCalls!==void 0&&!B(e.maxToolCalls)&&r.push("budget.maxToolCalls is invalid")}function Be(e,t){if(!Array.isArray(e)||e.length<1||e.length>512||new Set(e).size!==e.length){t.push("allowedTools must contain 1..512 unique tool names");return}e.forEach((r,n)=>{b(r,`allowedTools[${n}]`,t),Ne.has(r)||t.push(`allowedTools[${n}] is not in the hosted v0.1 registry`)})}function $e(e,t){if(!Array.isArray(e.secrets)||e.secrets.length>128){t.push("secrets must be a bounded array");return}let r=new Set(e.authority?.secretRefs??[]),n=new Map((e.environment?.secrets??[]).map(s=>[s.ref,s])),o=new Set;for(let[s,i]of e.secrets.entries()){let a=n.get(i.ref);if(!a||!r.has(i.ref)||o.has(i.ref)){t.push(`secrets[${s}] is undeclared, unauthorized, or duplicated`);continue}o.add(i.ref),(E(a.target)!==E(i.target)||a.exposeToChildProcesses!==i.exposeToChildProcesses)&&t.push(`secrets[${s}] does not match its declared projection`),(typeof i.value!="string"||i.value.length<1||Buffer.byteLength(i.value,"utf8")>1024*1024)&&t.push(`secrets[${s}] value is empty or too large`)}for(let s of e.environment?.secrets??[])s.required&&(!r.has(s.ref)||!o.has(s.ref))&&t.push(`required secret ${s.ref} is absent or unauthorized`);[...r].some(s=>!n.has(s))&&t.push("authority references an undeclared secret")}function qe(e,t){let r=e.expectedBoundary;if(!r){t.push("expectedBoundary is missing");return}let n;try{n=oe({certificationId:r.certificationId,environment:e.environment,authority:e.authority})}catch{t.push("expectedBoundary does not match the hosted execution contract");return}(!ie(r.certificationId)||E(r)!==E(n))&&t.push("expectedBoundary does not match the hosted execution contract")}function b(e,t,r){(typeof e!="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e))&&r.push(`${t} is invalid`)}function V(e,t,r,n){(typeof e!="string"||e.length<1||e.length>r||e.includes("\0"))&&n.push(`${t} is invalid`)}function B(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0}function ie(e){return typeof e=="string"&&/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e)}function Le(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function E(e){return u(e)}function ee(e){return(0,te.createHash)("sha256").update(E(e)).digest("hex")}function je(e){if(!e)throw new Error("repository source is missing");let t=e.repository.replace(/^\/+|\/+$/g,""),r=e.provider==="github"&&!t.includes("://")?`https://github.com/${t}.git`:e.provider==="gitlab"&&!t.includes("://")?`https://gitlab.com/${t}.git`:e.provider==="bitbucket"&&!t.includes("://")?`https://bitbucket.org/${t}.git`:e.repository,n=new URL(r);if(n.protocol!=="https:"||n.username||n.password||n.hash)throw new Error("repository origin is not credential-free HTTPS");return{hostname:n.hostname.toLowerCase(),port:Number(n.port||443)}}var C=require("node:crypto");var q=1,L=1;function ce(e){let t={schemaVersion:q,kind:"xeno-hosted-control",controlId:l(e.controlId??`hctl_${(0,C.randomUUID)()}`,"controlId"),runId:l(e.runId,"runId"),workspaceId:l(e.workspaceId,"workspaceId"),actorId:l(e.actorId,"actorId"),idempotencyKey:f(e.idempotencyKey,"idempotencyKey",512),createdAt:j(e.createdAt,"createdAt"),action:Fe(e.action)};return{...t,hash:{algorithm:"sha256",value:ue(t)}}}function ze(e){let t=[];try{let{hash:r,schemaVersion:n,kind:o,...s}=e,i=ce(s);(e.schemaVersion!==q||e.kind!=="xeno-hosted-control")&&t.push("Unsupported hosted control command"),v(X(e))!==v(X(i))&&t.push("Hosted control command is not normalized"),(r?.algorithm!=="sha256"||r.value!==i.hash.value)&&t.push("Hosted control command hash mismatch")}catch(r){t.push(r instanceof Error?r.message:String(r))}return{valid:t.length===0,errors:t}}function Ue(e){if(!["accepted","applied","rejected","unsupported"].includes(e.status))throw new Error("Hosted control acknowledgement status is invalid");return{controlId:l(e.controlId,"controlId"),status:e.status,acknowledgedAt:j(e.acknowledgedAt,"acknowledgedAt"),...e.reason?{reason:f(e.reason,"reason",2048)}:{}}}function de(e){let t=e.git?{...e.git.branch?{branch:$(e.git.branch,"git.branch")}:{},...e.git.baseRef?{baseRef:$(e.git.baseRef,"git.baseRef")}:{},...e.git.commit?{commit:$(e.git.commit,"git.commit")}:{}}:void 0,r={schemaVersion:L,kind:"xeno-hosted-run-result",runId:l(e.runId,"runId"),workspaceId:l(e.workspaceId,"workspaceId"),completedAt:j(e.completedAt,"completedAt"),...t&&Object.keys(t).length>0?{git:t}:{},...e.pullRequest?{pullRequest:Ke(e.pullRequest)}:{},artifactIds:ae(e.artifactIds,"artifactIds"),evidenceArtifactIds:ae(e.evidenceArtifactIds,"evidenceArtifactIds")};return{...r,hash:{algorithm:"sha256",value:ue(r)}}}function Je(e){let t=[];try{let{hash:r,schemaVersion:n,kind:o,...s}=e,i=de(s);(e.schemaVersion!==L||e.kind!=="xeno-hosted-run-result")&&t.push("Unsupported hosted run result"),v(X(e))!==v(X(i))&&t.push("Hosted run result is not normalized"),(r?.algorithm!=="sha256"||r.value!==i.hash.value)&&t.push("Hosted run result hash mismatch")}catch(r){t.push(r instanceof Error?r.message:String(r))}return{valid:t.length===0,errors:t}}function Fe(e){if(e?.type==="message")return{type:"message",message:f(e.message,"action.message",32768)};if(e?.type==="approval"){if(e.decision!=="approved"&&e.decision!=="rejected")throw new Error("Hosted approval decision is invalid");return{type:"approval",requestId:l(e.requestId,"action.requestId"),decision:e.decision,scopeHash:Ge(e.scopeHash,"action.scopeHash"),...e.rationale?{rationale:f(e.rationale,"action.rationale",4096)}:{}}}throw new Error("Hosted control action is invalid")}function Ke(e){let t;try{t=new URL(e.url)}catch{throw new Error("pullRequest.url is invalid")}if(t.protocol!=="https:"||t.username||t.password)throw new Error("pullRequest.url must be credential-free HTTPS");if(!Number.isSafeInteger(e.number)||e.number<1)throw new Error("pullRequest.number must be a positive integer");return{provider:l(e.provider,"pullRequest.provider"),repository:f(e.repository,"pullRequest.repository",2048),number:e.number,url:t.toString()}}function ae(e,t){if(!Array.isArray(e)||e.length>1e4)throw new Error(`${t} is invalid`);return[...new Set(e.map((r,n)=>l(r,`${t}[${n}]`)))].sort()}function $(e,t){return f(e,t,512)}function l(e,t){let r=f(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function f(e,t,r){let n=e?.trim();if(!n||n.length>r||y(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function j(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be ISO-8601 UTC`);return e}function Ge(e,t){let r=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(r))throw new Error(`${t} must be a lowercase SHA-256 digest`);return r}function ue(e){return(0,C.createHash)("sha256").update(v(e)).digest("hex")}function v(e){return u(e)}function X(e){let{hash:t,...r}=e;return r}0&&(module.exports={XENO_HOSTED_CONTROL_SCHEMA_VERSION,XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION,XENO_HOSTED_EVENT_SCHEMA_VERSION,XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA,XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS,XENO_HOSTED_EXECUTION_ADAPTER_PROTOCOL_VERSION,XENO_HOSTED_EXECUTION_PROTOCOL_VERSION,XENO_HOSTED_EXECUTION_TOOL_NAMES,XENO_HOSTED_RESULT_SCHEMA_VERSION,XENO_HOSTED_RUN_SCHEMA_VERSION,XENO_HOSTED_TRIGGER_SCHEMA_VERSION,assertValidXenoHostedExecutionJob,createXenoHostedControlCommand,createXenoHostedEnvironmentManifest,createXenoHostedEvent,createXenoHostedExecutionBoundaryReceipt,createXenoHostedRunResult,deriveHostedIdempotencyKey,hostedEnvironmentIdentity,normalizeXenoHostedControlAcknowledgement,verifyXenoHostedControlCommand,verifyXenoHostedEnvironmentManifest,verifyXenoHostedEventChain,verifyXenoHostedExecutionAdapterCertification,verifyXenoHostedExecutionJob,verifyXenoHostedRunResult,verifyXenoHostedWebhook,xenoHostedExecutionAdapterSigningPayload});
1
+ "use strict";var O=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var ge=(e,t)=>{for(var r in t)O(e,r,{get:t[r],enumerable:!0})},fe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of me(t))!pe.call(e,o)&&o!==r&&O(e,o,{get:()=>t[o],enumerable:!(n=le(t,o))||n.enumerable});return e};var he=e=>fe(O({},"__esModule",{value:!0}),e);var We={};ge(We,{XENO_HOSTED_CONTROL_SCHEMA_VERSION:()=>q,XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION:()=>k,XENO_HOSTED_EVENT_SCHEMA_VERSION:()=>P,XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA:()=>w,XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS:()=>W,XENO_HOSTED_EXECUTION_ADAPTER_PROTOCOL_VERSION:()=>M,XENO_HOSTED_EXECUTION_PROTOCOL_VERSION:()=>re,XENO_HOSTED_EXECUTION_TOOL_NAMES:()=>ne,XENO_HOSTED_RESULT_SCHEMA_VERSION:()=>L,XENO_HOSTED_RUN_SCHEMA_VERSION:()=>Qe,XENO_HOSTED_TRIGGER_SCHEMA_VERSION:()=>Ye,assertValidXenoHostedExecutionJob:()=>Me,createXenoHostedControlCommand:()=>ce,createXenoHostedEnvironmentManifest:()=>ye,createXenoHostedEvent:()=>xe,createXenoHostedExecutionBoundaryReceipt:()=>oe,createXenoHostedRunResult:()=>de,deriveHostedIdempotencyKey:()=>Ee,hostedEnvironmentIdentity:()=>be,normalizeXenoHostedControlAcknowledgement:()=>Ue,verifyXenoHostedControlCommand:()=>ze,verifyXenoHostedEnvironmentManifest:()=>I,verifyXenoHostedEventChain:()=>we,verifyXenoHostedExecutionAdapterCertification:()=>Oe,verifyXenoHostedExecutionJob:()=>se,verifyXenoHostedRunResult:()=>Je,verifyXenoHostedWebhook:()=>Ae,xenoHostedExecutionAdapterSigningPayload:()=>Xe});module.exports=he(We);var k=1,Qe=1,P=1,Ye=1;var x=require("node:crypto");function u(e){return JSON.stringify(N(e,new Set))}function N(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(o=>N(o,t));return t.delete(e),n}let r={};for(let n of Object.keys(e).sort((o,s)=>o.localeCompare(s))){let o=e[n];if(o===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);r[n]=N(o,t)}return t.delete(e),r}function y(e,t={}){for(let r of e){let n=r.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&t.allowTab===!0)&&!((n===10||n===13)&&t.allowLineBreaks===!0))return!0}return!1}function ye(e){let t={...J(e),schemaVersion:1,kind:"xeno-hosted-environment"};return{...t,checksum:{algorithm:"sha256",value:S(t)}}}function I(e){let t=[];if(e?.schemaVersion!==1||e.kind!=="xeno-hosted-environment")return t.push("Unsupported hosted environment manifest"),{valid:!1,errors:t};let r;try{let{checksum:n,schemaVersion:o,kind:s,...i}=e;r={...J(i),schemaVersion:1,kind:"xeno-hosted-environment"}}catch(n){return t.push(n instanceof Error?n.message:String(n)),{valid:!1,errors:t}}return u(r)!==u(ve(e))&&t.push("Hosted environment manifest is not normalized"),(e.checksum?.algorithm!=="sha256"||e.checksum.value!==S(r))&&t.push("Hosted environment checksum mismatch"),{valid:t.length===0,errors:t}}function xe(e){let t=p(e.streamId,"streamId"),r=K(e.sequence,"sequence");if(e.previous){if(e.previous.streamId!==t)throw new Error("Previous event belongs to another stream");if(e.previous.sequence+1!==r)throw new Error("Hosted event sequence must be contiguous")}else if(r!==1)throw new Error("The first hosted event sequence must be 1");let n={schemaVersion:1,kind:"xeno-hosted-event",eventId:p(e.eventId??`hevt_${(0,x.randomUUID)()}`,"eventId"),streamId:t,sequence:r,timestamp:G(e.timestamp??new Date().toISOString(),"timestamp"),type:F(e.type,"type"),actorId:p(e.actorId,"actorId"),...e.idempotencyKey?{idempotencyKey:c(e.idempotencyKey,"idempotencyKey",512)}:{},payload:ke(e.payload??{},"payload"),previousHash:e.previous?.hash??null};return{...n,hash:S(n)}}function we(e,t){let r=[],n,o=t?t.afterSequence+1:1,s=t?.lastHash??null;for(let a of e){if(a.schemaVersion!==1||a.kind!=="xeno-hosted-event"){r.push(`Unsupported hosted event at sequence ${String(a.sequence)}`);continue}a.sequence!==o&&r.push(`Hosted event sequence gap at ${a.sequence}; expected ${o}`),a.previousHash!==s&&r.push(`Hosted event previous hash mismatch at ${a.sequence}`);let{hash:m,...h}=a;m!==S(h)&&r.push(`Hosted event hash mismatch at ${a.sequence}`),n&&n.streamId!==a.streamId&&r.push(`Hosted event stream changed at ${a.sequence}`),n=a,o=a.sequence+1,s=a.hash}let i=e.at(-1);return{valid:r.length===0,errors:r,cursor:i?{streamId:i.streamId,afterSequence:i.sequence,lastHash:i.hash}:t??null}}function be(e){let t=I(e);if(!t.valid)throw new Error(t.errors.join("; "));return`${e.environmentId}@${e.revision}:${e.checksum.value}`}function Ee(...e){if(e.length===0)throw new Error("At least one idempotency-key part is required");let t=e.map((r,n)=>He(r,`parts[${n}]`));return`xeno:${(0,x.createHash)("sha256").update(t.join("\0")).digest("hex")}`}function J(e){let t=e.secrets.map((o,s)=>({ref:p(o.ref,`secrets[${s}].ref`),target:o.target.kind==="environment"?{kind:"environment",name:Se(o.target.name)}:{kind:"file",path:H(o.target.path,`secrets[${s}].target.path`)},required:!!o.required,exposeToChildProcesses:!!o.exposeToChildProcesses})),r=new Set,n=new Set;for(let o of t){if(r.has(o.ref))throw new Error(`Duplicate secret ref: ${o.ref}`);r.add(o.ref);let s=`${o.target.kind}:${o.target.kind==="environment"?o.target.name:o.target.path}`;if(n.has(s))throw new Error(`Duplicate secret target: ${s}`);n.add(s)}if(e.network.default!=="deny")throw new Error("Hosted network policy must be default-deny");return{environmentId:p(e.environmentId,"environmentId"),revision:K(e.revision,"revision"),createdAt:G(e.createdAt,"createdAt"),createdBy:p(e.createdBy,"createdBy"),workspaceId:p(e.workspaceId,"workspaceId"),name:c(e.name,"name",160),repository:{provider:e.repository.provider,repository:c(e.repository.repository,"repository.repository",2048),ref:c(e.repository.ref,"repository.ref",512),...e.repository.commit?{commit:Te(e.repository.commit,"repository.commit")}:{},...e.repository.subdirectory?{subdirectory:H(e.repository.subdirectory,"repository.subdirectory")}:{},...e.repository.shallow!==void 0?{shallow:!!e.repository.shallow}:{}},image:{reference:c(e.image.reference,"image.reference",2048),digest:_e(e.image.digest),os:e.image.os,architecture:e.image.architecture},setup:e.setup.map((o,s)=>({id:p(o.id,`setup[${s}].id`),command:c(o.command,`setup[${s}].command`,32768),...o.workingDirectory?{workingDirectory:H(o.workingDirectory,`setup[${s}].workingDirectory`)}:{},timeoutMs:d(o.timeoutMs,`setup[${s}].timeoutMs`,1e3,36e5),network:o.network})),caches:e.caches.map((o,s)=>({key:c(o.key,`caches[${s}].key`,512),path:H(o.path,`caches[${s}].path`),...o.restoreKeys?.length?{restoreKeys:Re(o.restoreKeys,`caches[${s}].restoreKeys`,512)}:{},...o.readOnly!==void 0?{readOnly:!!o.readOnly}:{},...o.maxBytes!==void 0?{maxBytes:d(o.maxBytes,`caches[${s}].maxBytes`,1,Number.MAX_SAFE_INTEGER)}:{}})),network:{default:"deny",dns:e.network.dns,destinations:e.network.destinations.map((o,s)=>({host:Ie(o.host,`network.destinations[${s}].host`),...o.ports?.length?{ports:[...new Set(o.ports.map(i=>d(i,"port",1,65535)))].sort((i,a)=>i-a)}:{},...o.protocols?.length?{protocols:[...new Set(o.protocols)].sort()}:{},reason:c(o.reason,`network.destinations[${s}].reason`,500)})).sort((o,s)=>o.host.localeCompare(s.host)),...e.network.maxResponseBytes!==void 0?{maxResponseBytes:d(e.network.maxResponseBytes,"network.maxResponseBytes",1,Number.MAX_SAFE_INTEGER)}:{}},secrets:t,resources:{cpuMillis:d(e.resources.cpuMillis,"resources.cpuMillis",10,1e6),memoryBytes:d(e.resources.memoryBytes,"resources.memoryBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),diskBytes:d(e.resources.diskBytes,"resources.diskBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),processLimit:d(e.resources.processLimit,"resources.processLimit",1,65535),wallTimeMs:d(e.resources.wallTimeMs,"resources.wallTimeMs",1e3,10080*60*1e3)},retention:{workspaceTtlMs:d(e.retention.workspaceTtlMs,"retention.workspaceTtlMs",0,365*24*60*60*1e3),eventTtlMs:d(e.retention.eventTtlMs,"retention.eventTtlMs",6e4,365*24*60*60*1e3),artifactTtlMs:d(e.retention.artifactTtlMs,"retention.artifactTtlMs",6e4,365*24*60*60*1e3),wipeWorkspace:!!e.retention.wipeWorkspace},labels:Object.fromEntries(Object.entries(e.labels).map(([o,s])=>[F(o,"label key"),c(s,`labels.${o}`,500)]).sort(([o],[s])=>o.localeCompare(s)))}}function ve(e){let{checksum:t,...r}=e;return r}function S(e){return(0,x.createHash)("sha256").update(u(e)).digest("hex")}function ke(e,t){let r=u(e);if(Buffer.byteLength(r,"utf8")>256*1024)throw new Error(`${t} exceeds 262144 bytes`);return JSON.parse(r)}function p(e,t){let r=c(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function F(e,t){let r=c(e,t,160);if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function c(e,t,r){let n=e.trim();if(!n||n.length>r||y(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function He(e,t){let r=e.trim();if(r.length>4096||y(r,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return r}function K(e,t){return d(e,t,1,Number.MAX_SAFE_INTEGER)}function d(e,t,r,n){if(!Number.isSafeInteger(e)||e<r||e>n)throw new Error(`${t} must be an integer between ${r} and ${n}`);return e}function G(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return e}function Ie(e,t){let r=c(e.toLowerCase(),t,253);if(r==="localhost"||/^(?:\d{1,3}\.){3}\d{1,3}$/.test(r)||r.includes(":")||!/^(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(r))throw new Error(`${t} must be a public DNS hostname or wildcard hostname`);return r}function H(e,t){let r=c(e.replaceAll("\\","/"),t,4096);if(r.startsWith("/")||/^[A-Za-z]:\//.test(r)||r.split("/").includes(".."))throw new Error(`${t} must be workspace-relative`);return r.replace(/^\.\//,"")}function Se(e){let t=c(e,"secret environment name",256);if(!/^[A-Z_][A-Z0-9_]*$/.test(t))throw new Error("Secret environment target must be an uppercase environment variable name");return t}function _e(e){let t=e.trim().toLowerCase();if(!/^sha256:[a-f0-9]{64}$/.test(t))throw new Error("image.digest must be a sha256 OCI digest");return t}function Te(e,t){return c(e,t,512)}function Re(e,t,r){return[...new Set(e.map((n,o)=>c(n,`${t}[${o}]`,r)))]}var g=require("node:crypto");function Ae(e){let t=typeof e.body=="string"?Buffer.from(e.body,"utf8"):Buffer.from(e.body),r=(0,g.createHash)("sha256").update(t).digest("hex"),n=e.signature?.trim();if(!n)return{valid:!1,source:e.source,bodySha256:r,error:"missing-signature"};if(!e.secret||e.secret.length<16)throw new Error("Webhook secret must contain at least 16 characters");let o,s=n;if(e.source==="slack"){if(!e.timestamp||!/^\d+$/.test(e.timestamp))return{valid:!1,source:e.source,bodySha256:r,error:"invalid-timestamp"};let a=Number(e.timestamp)*1e3,m=Math.abs((e.now??new Date).getTime()-a);if(!Number.isFinite(a)||m>(e.maxClockSkewMs??5*6e4))return{valid:!1,source:e.source,bodySha256:r,timestamp:e.timestamp,error:"stale-timestamp"};o=`v0=${(0,g.createHmac)("sha256",e.secret).update(`v0:${e.timestamp}:`).update(t).digest("hex")}`}else e.source==="gitlab"?o=e.secret:e.source==="teams"?o=`HMAC ${(0,g.createHmac)("sha256",Buffer.from(e.secret,"base64")).update(t).digest("base64")}`:(o=`${e.source==="github"||e.source==="jira"?"sha256=":e.source==="xeno"?"v1=":""}${(0,g.createHmac)("sha256",e.secret).update(t).digest("hex")}`,e.source==="linear"&&s.startsWith("sha256=")&&(s=s.slice(7)));let i=Ce(o,s);return{valid:i,source:e.source,bodySha256:r,...e.timestamp?{timestamp:e.timestamp}:{},...i?{}:{error:"invalid-signature"}}}function Ce(e,t){let r=Buffer.from(e,"utf8"),n=Buffer.from(t,"utf8");return r.length===n.length&&(0,g.timingSafeEqual)(r,n)}var A=require("node:crypto");var w="xeno.hosted-execution-adapter-certification.v2",M=2,W=744*60*60*1e3;function Xe(e){return Z(e),Buffer.from(D(e),"utf8")}function Oe(e,t){if(e?.schemaVersion!==w)throw new Error(`Hosted execution adapter certificate must use ${w}`);let{signature:r,...n}=e;if(Z(n),r?.algorithm!=="ed25519")throw new Error("Hosted execution adapter signature must use ed25519");let o=T(t.executableSha256,"executableSha256"),s=T(t.controlPlaneCandidateSha256,"controlPlaneCandidateSha256");if(n.adapter.executableSha256!==o)throw new Error("Hosted execution adapter executable does not match its signed certificate");if(n.controlPlaneCandidateSha256!==s)throw new Error("Hosted execution adapter certificate is bound to another control-plane candidate");let i=t.platform??process.platform,a=t.architecture??process.arch;if(n.platform.os!==i||n.platform.architecture!==a)throw new Error(`Hosted execution adapter certificate targets ${n.platform.os}-${n.platform.architecture}, not ${i}-${a}`);let m=R(n.issuedAt,"issuedAt"),h=R(n.expiresAt,"expiresAt"),z=(t.now??new Date).getTime();if(m>z+5*6e4)throw new Error("Hosted execution adapter certificate is not yet valid");if(h<=z)throw new Error("Hosted execution adapter certificate has expired");if(h<=m||h-m>W)throw new Error("Hosted execution adapter certificate lifetime must be positive and at most 31 days");let U=t.trustedKeys[n.reviewer.keyId];if(!U)throw new Error(`Hosted execution adapter reviewer key is not trusted: ${n.reviewer.keyId}`);if(!(0,A.verify)(null,Buffer.from(D(n),"utf8"),U,Pe(r.value,"signature.value")))throw new Error("Hosted execution adapter certificate signature is invalid");return{certificationId:n.certificationId,adapterName:n.adapter.name,adapterVersion:n.adapter.version,protocolVersion:n.adapter.protocolVersion,executableSha256:o,controlPlaneCandidateSha256:s,certificateSha256:(0,A.createHash)("sha256").update(D(e)).digest("hex"),expiresAt:n.expiresAt,reviewerKeyId:n.reviewer.keyId}}function Z(e){if(e.schemaVersion!==w)throw new Error(`Hosted execution adapter certificate must use ${w}`);if(_(e.certificationId,"certificationId"),_(e.adapter?.name,"adapter.name"),_(e.adapter?.version,"adapter.version"),e.adapter?.protocolVersion!==M)throw new Error(`Hosted execution adapter protocol must be ${M}`);T(e.adapter.executableSha256,"adapter.executableSha256"),T(e.controlPlaneCandidateSha256,"controlPlaneCandidateSha256"),_(e.reviewer?.keyId,"reviewer.keyId");let t=["immutableImages","filesystemIsolation","networkDefaultDeny","destinationAllowlist","secretProjection","nonRootExecution","readOnlyRoot","processTreeCleanup","resourceLimits","interactiveControl","artifactProtocol","gitResultReporting"];if(!e.capabilities||t.some(r=>e.capabilities[r]!==!0))throw new Error("Hosted execution adapter certificate does not attest every required containment capability");R(e.issuedAt,"issuedAt"),R(e.expiresAt,"expiresAt")}function D(e){return u(e)}function T(e,t){let r=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(r))throw new Error(`${t} must be a lowercase SHA-256 digest`);return r}function _(e,t){let r=e?.trim();if(!r||r.length>256||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function R(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return r}function Pe(e,t){if(typeof e!="string"||e.length===0||e.length>4096||!/^[A-Za-z0-9+/]+={0,2}$/.test(e))throw new Error(`${t} must be bounded base64`);let r=Buffer.from(e,"base64");if(r.toString("base64")!==e)throw new Error(`${t} is not canonical base64`);return r}var te=require("node:crypto");var Q=["low","medium","high","xhigh","max"],Y=["default","plan","acceptEdits","auto","dontAsk","bypassPermissions"];var re=2,ne=["Read","Write","Edit","Glob","Grep","WebFetch"],Ne=new Set(ne);function oe(e){if(!ie(e.certificationId))throw new Error("certificationId is invalid");let t=new Set(e.authority.secretRefs);return{certificationId:e.certificationId,environmentChecksum:e.environment.checksum.value,imageDigest:e.environment.image.digest,networkPolicySha256:ee({authority:e.authority.network,policy:e.environment.network}),secretProjectionSha256:ee(e.environment.secrets.filter(r=>t.has(r.ref))),filesystem:e.authority.filesystem,network:e.authority.network==="deny"?"deny":"allowlist",immutableImage:!0,readOnlyRoot:!0,nonRoot:!0,processTreeCleanup:!0,resourceLimits:!0,inferenceGateway:"brokered"}}function se(e){let t=[];if(!Le(e))return{valid:!1,errors:["Hosted execution job must be an object"]};let r=e;if(r.protocolVersion!==re||r.kind!=="xeno-hosted-execution-job")return t.push("Unsupported hosted execution protocol"),{valid:!1,errors:t};b(r.runId,"runId",t),b(r.userId,"userId",t),b(r.workspaceId,"workspaceId",t),V(r.workspaceHostPath,"workspaceHostPath",4096,t),V(r.prompt,"prompt",512*1024,t),V(r.model,"model",512,t),r.effort!==void 0&&!Q.includes(r.effort)&&t.push("effort is invalid"),Y.includes(r.permissionMode)||t.push("permissionMode is invalid"),(typeof r.runScopedToken!="string"||!r.runScopedToken.startsWith("xrun_")||r.runScopedToken.length>16*1024)&&t.push("runScopedToken is not a bounded run-scoped token");let n;try{n=new URL(r.inferenceBaseUrl),(n.protocol!=="https:"||n.username||n.password||n.hash)&&t.push("inferenceBaseUrl must be credential-free HTTPS")}catch{t.push("inferenceBaseUrl is invalid")}let o=I(r.environment);t.push(...o.errors.map(i=>`environment: ${i}`)),r.environment?.workspaceId!==r.workspaceId&&t.push("environment workspace does not match the job"),r.environment?.image?.os!=="linux"&&t.push("hosted execution image must target Linux");let s=r.environment?.repository?.commit;(typeof s!="string"||!/^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(s))&&t.push("environment repository requires a full 40- or 64-character commit object id"),De(r.authority,t),Ve(r.budget,r.environment,t),Be(r.allowedTools,t),$e(r,t),qe(r,t),n&&!r.environment?.network?.destinations?.some(i=>{let a=i.ports?.length?i.ports:[443];return i.host.toLowerCase()===n.hostname.toLowerCase()&&a.includes(Number(n.port||443))})&&t.push("inference origin is absent from the environment network allowlist");try{let i=je(r.environment?.repository);r.environment?.network?.destinations?.some(a=>{let m=a.ports?.length?a.ports:[443];return a.host.toLowerCase()===i.hostname&&m.includes(i.port)})||t.push("repository origin is absent from the environment network allowlist")}catch{t.push("environment repository must resolve to a credential-free HTTPS origin")}return{valid:t.length===0,errors:t}}function Me(e){let t=se(e);if(!t.valid)throw new Error(`Invalid hosted execution job: ${t.errors.join("; ")}`)}function De(e,t){(!e||!["read","workspace-write"].includes(e.filesystem))&&t.push("authority.filesystem is invalid"),(!e||!["deny","environment-policy"].includes(e.network))&&t.push("authority.network is invalid"),(!e||!["deny","approval-required"].includes(e.externalActions))&&t.push("authority.externalActions is invalid"),!Array.isArray(e?.secretRefs)||new Set(e.secretRefs).size!==e.secretRefs.length?t.push("authority.secretRefs must be a unique array"):e.secretRefs.forEach((r,n)=>b(r,`authority.secretRefs[${n}]`,t))}function Ve(e,t,r){(!e||!Number.isFinite(e.maxCredits)||e.maxCredits<=0)&&r.push("budget.maxCredits is invalid"),(!e||!B(e.maxDurationMs)||e.maxDurationMs>(t?.resources?.wallTimeMs??0))&&r.push("budget.maxDurationMs is invalid or exceeds the environment limit"),e?.maxTokens!==void 0&&!B(e.maxTokens)&&r.push("budget.maxTokens is invalid"),e?.maxToolCalls!==void 0&&!B(e.maxToolCalls)&&r.push("budget.maxToolCalls is invalid")}function Be(e,t){if(!Array.isArray(e)||e.length<1||e.length>512||new Set(e).size!==e.length){t.push("allowedTools must contain 1..512 unique tool names");return}e.forEach((r,n)=>{b(r,`allowedTools[${n}]`,t),Ne.has(r)||t.push(`allowedTools[${n}] is not in the hosted v0.1 registry`)})}function $e(e,t){if(!Array.isArray(e.secrets)||e.secrets.length>128){t.push("secrets must be a bounded array");return}let r=new Set(e.authority?.secretRefs??[]),n=new Map((e.environment?.secrets??[]).map(s=>[s.ref,s])),o=new Set;for(let[s,i]of e.secrets.entries()){let a=n.get(i.ref);if(!a||!r.has(i.ref)||o.has(i.ref)){t.push(`secrets[${s}] is undeclared, unauthorized, or duplicated`);continue}o.add(i.ref),(E(a.target)!==E(i.target)||a.exposeToChildProcesses!==i.exposeToChildProcesses)&&t.push(`secrets[${s}] does not match its declared projection`),(typeof i.value!="string"||i.value.length<1||Buffer.byteLength(i.value,"utf8")>1024*1024)&&t.push(`secrets[${s}] value is empty or too large`)}for(let s of e.environment?.secrets??[])s.required&&(!r.has(s.ref)||!o.has(s.ref))&&t.push(`required secret ${s.ref} is absent or unauthorized`);[...r].some(s=>!n.has(s))&&t.push("authority references an undeclared secret")}function qe(e,t){let r=e.expectedBoundary;if(!r){t.push("expectedBoundary is missing");return}let n;try{n=oe({certificationId:r.certificationId,environment:e.environment,authority:e.authority})}catch{t.push("expectedBoundary does not match the hosted execution contract");return}(!ie(r.certificationId)||E(r)!==E(n))&&t.push("expectedBoundary does not match the hosted execution contract")}function b(e,t,r){(typeof e!="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e))&&r.push(`${t} is invalid`)}function V(e,t,r,n){(typeof e!="string"||e.length<1||e.length>r||e.includes("\0"))&&n.push(`${t} is invalid`)}function B(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0}function ie(e){return typeof e=="string"&&/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e)}function Le(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function E(e){return u(e)}function ee(e){return(0,te.createHash)("sha256").update(E(e)).digest("hex")}function je(e){if(!e)throw new Error("repository source is missing");let t=e.repository.replace(/^\/+|\/+$/g,""),r=e.provider==="github"&&!t.includes("://")?`https://github.com/${t}.git`:e.provider==="gitlab"&&!t.includes("://")?`https://gitlab.com/${t}.git`:e.provider==="bitbucket"&&!t.includes("://")?`https://bitbucket.org/${t}.git`:e.repository,n=new URL(r);if(n.protocol!=="https:"||n.username||n.password||n.hash)throw new Error("repository origin is not credential-free HTTPS");return{hostname:n.hostname.toLowerCase(),port:Number(n.port||443)}}var X=require("node:crypto");var q=1,L=1;function ce(e){let t={schemaVersion:q,kind:"xeno-hosted-control",controlId:l(e.controlId??`hctl_${(0,X.randomUUID)()}`,"controlId"),runId:l(e.runId,"runId"),workspaceId:l(e.workspaceId,"workspaceId"),actorId:l(e.actorId,"actorId"),idempotencyKey:f(e.idempotencyKey,"idempotencyKey",512),createdAt:j(e.createdAt,"createdAt"),action:Fe(e.action)};return{...t,hash:{algorithm:"sha256",value:ue(t)}}}function ze(e){let t=[];try{let{hash:r,schemaVersion:n,kind:o,...s}=e,i=ce(s);(e.schemaVersion!==q||e.kind!=="xeno-hosted-control")&&t.push("Unsupported hosted control command"),v(C(e))!==v(C(i))&&t.push("Hosted control command is not normalized"),(r?.algorithm!=="sha256"||r.value!==i.hash.value)&&t.push("Hosted control command hash mismatch")}catch(r){t.push(r instanceof Error?r.message:String(r))}return{valid:t.length===0,errors:t}}function Ue(e){if(!["accepted","applied","rejected","unsupported"].includes(e.status))throw new Error("Hosted control acknowledgement status is invalid");return{controlId:l(e.controlId,"controlId"),status:e.status,acknowledgedAt:j(e.acknowledgedAt,"acknowledgedAt"),...e.reason?{reason:f(e.reason,"reason",2048)}:{}}}function de(e){let t=e.git?{...e.git.branch?{branch:$(e.git.branch,"git.branch")}:{},...e.git.baseRef?{baseRef:$(e.git.baseRef,"git.baseRef")}:{},...e.git.commit?{commit:$(e.git.commit,"git.commit")}:{}}:void 0,r={schemaVersion:L,kind:"xeno-hosted-run-result",runId:l(e.runId,"runId"),workspaceId:l(e.workspaceId,"workspaceId"),completedAt:j(e.completedAt,"completedAt"),...t&&Object.keys(t).length>0?{git:t}:{},...e.pullRequest?{pullRequest:Ke(e.pullRequest)}:{},artifactIds:ae(e.artifactIds,"artifactIds"),evidenceArtifactIds:ae(e.evidenceArtifactIds,"evidenceArtifactIds")};return{...r,hash:{algorithm:"sha256",value:ue(r)}}}function Je(e){let t=[];try{let{hash:r,schemaVersion:n,kind:o,...s}=e,i=de(s);(e.schemaVersion!==L||e.kind!=="xeno-hosted-run-result")&&t.push("Unsupported hosted run result"),v(C(e))!==v(C(i))&&t.push("Hosted run result is not normalized"),(r?.algorithm!=="sha256"||r.value!==i.hash.value)&&t.push("Hosted run result hash mismatch")}catch(r){t.push(r instanceof Error?r.message:String(r))}return{valid:t.length===0,errors:t}}function Fe(e){if(e?.type==="message")return{type:"message",message:f(e.message,"action.message",32768)};if(e?.type==="approval"){if(e.decision!=="approved"&&e.decision!=="rejected")throw new Error("Hosted approval decision is invalid");return{type:"approval",requestId:l(e.requestId,"action.requestId"),decision:e.decision,scopeHash:Ge(e.scopeHash,"action.scopeHash"),...e.rationale?{rationale:f(e.rationale,"action.rationale",4096)}:{}}}throw new Error("Hosted control action is invalid")}function Ke(e){let t;try{t=new URL(e.url)}catch{throw new Error("pullRequest.url is invalid")}if(t.protocol!=="https:"||t.username||t.password)throw new Error("pullRequest.url must be credential-free HTTPS");if(!Number.isSafeInteger(e.number)||e.number<1)throw new Error("pullRequest.number must be a positive integer");return{provider:l(e.provider,"pullRequest.provider"),repository:f(e.repository,"pullRequest.repository",2048),number:e.number,url:t.toString()}}function ae(e,t){if(!Array.isArray(e)||e.length>1e4)throw new Error(`${t} is invalid`);return[...new Set(e.map((r,n)=>l(r,`${t}[${n}]`)))].sort()}function $(e,t){return f(e,t,512)}function l(e,t){let r=f(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function f(e,t,r){let n=e?.trim();if(!n||n.length>r||y(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function j(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be ISO-8601 UTC`);return e}function Ge(e,t){let r=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(r))throw new Error(`${t} must be a lowercase SHA-256 digest`);return r}function ue(e){return(0,X.createHash)("sha256").update(v(e)).digest("hex")}function v(e){return u(e)}function C(e){let{hash:t,...r}=e;return r}0&&(module.exports={XENO_HOSTED_CONTROL_SCHEMA_VERSION,XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION,XENO_HOSTED_EVENT_SCHEMA_VERSION,XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA,XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS,XENO_HOSTED_EXECUTION_ADAPTER_PROTOCOL_VERSION,XENO_HOSTED_EXECUTION_PROTOCOL_VERSION,XENO_HOSTED_EXECUTION_TOOL_NAMES,XENO_HOSTED_RESULT_SCHEMA_VERSION,XENO_HOSTED_RUN_SCHEMA_VERSION,XENO_HOSTED_TRIGGER_SCHEMA_VERSION,assertValidXenoHostedExecutionJob,createXenoHostedControlCommand,createXenoHostedEnvironmentManifest,createXenoHostedEvent,createXenoHostedExecutionBoundaryReceipt,createXenoHostedRunResult,deriveHostedIdempotencyKey,hostedEnvironmentIdentity,normalizeXenoHostedControlAcknowledgement,verifyXenoHostedControlCommand,verifyXenoHostedEnvironmentManifest,verifyXenoHostedEventChain,verifyXenoHostedExecutionAdapterCertification,verifyXenoHostedExecutionJob,verifyXenoHostedRunResult,verifyXenoHostedWebhook,xenoHostedExecutionAdapterSigningPayload});
@@ -1 +1 @@
1
- var b=1,Me=1,T=1,De=1;import{createHash as B,randomUUID as ee}from"node:crypto";function u(e){return JSON.stringify(R(e,new Set))}function R(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(o=>R(o,t));return t.delete(e),n}let r={};for(let n of Object.keys(e).sort((o,s)=>o.localeCompare(s))){let o=e[n];if(o===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);r[n]=R(o,t)}return t.delete(e),r}function h(e,t={}){for(let r of e){let n=r.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&t.allowTab===!0)&&!((n===10||n===13)&&t.allowLineBreaks===!0))return!0}return!1}function Ue(e){let t={...$(e),schemaVersion:1,kind:"xeno-hosted-environment"};return{...t,checksum:{algorithm:"sha256",value:v(t)}}}function A(e){let t=[];if(e?.schemaVersion!==1||e.kind!=="xeno-hosted-environment")return t.push("Unsupported hosted environment manifest"),{valid:!1,errors:t};let r;try{let{checksum:n,schemaVersion:o,kind:s,...i}=e;r={...$(i),schemaVersion:1,kind:"xeno-hosted-environment"}}catch(n){return t.push(n instanceof Error?n.message:String(n)),{valid:!1,errors:t}}return u(r)!==u(te(e))&&t.push("Hosted environment manifest is not normalized"),(e.checksum?.algorithm!=="sha256"||e.checksum.value!==v(r))&&t.push("Hosted environment checksum mismatch"),{valid:t.length===0,errors:t}}function Je(e){let t=p(e.streamId,"streamId"),r=L(e.sequence,"sequence");if(e.previous){if(e.previous.streamId!==t)throw new Error("Previous event belongs to another stream");if(e.previous.sequence+1!==r)throw new Error("Hosted event sequence must be contiguous")}else if(r!==1)throw new Error("The first hosted event sequence must be 1");let n={schemaVersion:1,kind:"xeno-hosted-event",eventId:p(e.eventId??`hevt_${ee()}`,"eventId"),streamId:t,sequence:r,timestamp:j(e.timestamp??new Date().toISOString(),"timestamp"),type:q(e.type,"type"),actorId:p(e.actorId,"actorId"),...e.idempotencyKey?{idempotencyKey:c(e.idempotencyKey,"idempotencyKey",512)}:{},payload:re(e.payload??{},"payload"),previousHash:e.previous?.hash??null};return{...n,hash:v(n)}}function Fe(e,t){let r=[],n,o=t?t.afterSequence+1:1,s=t?.lastHash??null;for(let a of e){if(a.schemaVersion!==1||a.kind!=="xeno-hosted-event"){r.push(`Unsupported hosted event at sequence ${String(a.sequence)}`);continue}a.sequence!==o&&r.push(`Hosted event sequence gap at ${a.sequence}; expected ${o}`),a.previousHash!==s&&r.push(`Hosted event previous hash mismatch at ${a.sequence}`);let{hash:m,...f}=a;m!==v(f)&&r.push(`Hosted event hash mismatch at ${a.sequence}`),n&&n.streamId!==a.streamId&&r.push(`Hosted event stream changed at ${a.sequence}`),n=a,o=a.sequence+1,s=a.hash}let i=e.at(-1);return{valid:r.length===0,errors:r,cursor:i?{streamId:i.streamId,afterSequence:i.sequence,lastHash:i.hash}:t??null}}function Ke(e){let t=A(e);if(!t.valid)throw new Error(t.errors.join("; "));return`${e.environmentId}@${e.revision}:${e.checksum.value}`}function Ge(...e){if(e.length===0)throw new Error("At least one idempotency-key part is required");let t=e.map((r,n)=>ne(r,`parts[${n}]`));return`xeno:${B("sha256").update(t.join("\0")).digest("hex")}`}function $(e){let t=e.secrets.map((o,s)=>({ref:p(o.ref,`secrets[${s}].ref`),target:o.target.kind==="environment"?{kind:"environment",name:se(o.target.name)}:{kind:"file",path:E(o.target.path,`secrets[${s}].target.path`)},required:!!o.required,exposeToChildProcesses:!!o.exposeToChildProcesses})),r=new Set,n=new Set;for(let o of t){if(r.has(o.ref))throw new Error(`Duplicate secret ref: ${o.ref}`);r.add(o.ref);let s=`${o.target.kind}:${o.target.kind==="environment"?o.target.name:o.target.path}`;if(n.has(s))throw new Error(`Duplicate secret target: ${s}`);n.add(s)}if(e.network.default!=="deny")throw new Error("Hosted network policy must be default-deny");return{environmentId:p(e.environmentId,"environmentId"),revision:L(e.revision,"revision"),createdAt:j(e.createdAt,"createdAt"),createdBy:p(e.createdBy,"createdBy"),workspaceId:p(e.workspaceId,"workspaceId"),name:c(e.name,"name",160),repository:{provider:e.repository.provider,repository:c(e.repository.repository,"repository.repository",2048),ref:c(e.repository.ref,"repository.ref",512),...e.repository.commit?{commit:ae(e.repository.commit,"repository.commit")}:{},...e.repository.subdirectory?{subdirectory:E(e.repository.subdirectory,"repository.subdirectory")}:{},...e.repository.shallow!==void 0?{shallow:!!e.repository.shallow}:{}},image:{reference:c(e.image.reference,"image.reference",2048),digest:ie(e.image.digest),os:e.image.os,architecture:e.image.architecture},setup:e.setup.map((o,s)=>({id:p(o.id,`setup[${s}].id`),command:c(o.command,`setup[${s}].command`,32768),...o.workingDirectory?{workingDirectory:E(o.workingDirectory,`setup[${s}].workingDirectory`)}:{},timeoutMs:d(o.timeoutMs,`setup[${s}].timeoutMs`,1e3,36e5),network:o.network})),caches:e.caches.map((o,s)=>({key:c(o.key,`caches[${s}].key`,512),path:E(o.path,`caches[${s}].path`),...o.restoreKeys?.length?{restoreKeys:ce(o.restoreKeys,`caches[${s}].restoreKeys`,512)}:{},...o.readOnly!==void 0?{readOnly:!!o.readOnly}:{},...o.maxBytes!==void 0?{maxBytes:d(o.maxBytes,`caches[${s}].maxBytes`,1,Number.MAX_SAFE_INTEGER)}:{}})),network:{default:"deny",dns:e.network.dns,destinations:e.network.destinations.map((o,s)=>({host:oe(o.host,`network.destinations[${s}].host`),...o.ports?.length?{ports:[...new Set(o.ports.map(i=>d(i,"port",1,65535)))].sort((i,a)=>i-a)}:{},...o.protocols?.length?{protocols:[...new Set(o.protocols)].sort()}:{},reason:c(o.reason,`network.destinations[${s}].reason`,500)})).sort((o,s)=>o.host.localeCompare(s.host)),...e.network.maxResponseBytes!==void 0?{maxResponseBytes:d(e.network.maxResponseBytes,"network.maxResponseBytes",1,Number.MAX_SAFE_INTEGER)}:{}},secrets:t,resources:{cpuMillis:d(e.resources.cpuMillis,"resources.cpuMillis",10,1e6),memoryBytes:d(e.resources.memoryBytes,"resources.memoryBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),diskBytes:d(e.resources.diskBytes,"resources.diskBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),processLimit:d(e.resources.processLimit,"resources.processLimit",1,65535),wallTimeMs:d(e.resources.wallTimeMs,"resources.wallTimeMs",1e3,10080*60*1e3)},retention:{workspaceTtlMs:d(e.retention.workspaceTtlMs,"retention.workspaceTtlMs",0,365*24*60*60*1e3),eventTtlMs:d(e.retention.eventTtlMs,"retention.eventTtlMs",6e4,365*24*60*60*1e3),artifactTtlMs:d(e.retention.artifactTtlMs,"retention.artifactTtlMs",6e4,365*24*60*60*1e3),wipeWorkspace:!!e.retention.wipeWorkspace},labels:Object.fromEntries(Object.entries(e.labels).map(([o,s])=>[q(o,"label key"),c(s,`labels.${o}`,500)]).sort(([o],[s])=>o.localeCompare(s)))}}function te(e){let{checksum:t,...r}=e;return r}function v(e){return B("sha256").update(u(e)).digest("hex")}function re(e,t){let r=u(e);if(Buffer.byteLength(r,"utf8")>256*1024)throw new Error(`${t} exceeds 262144 bytes`);return JSON.parse(r)}function p(e,t){let r=c(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function q(e,t){let r=c(e,t,160);if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function c(e,t,r){let n=e.trim();if(!n||n.length>r||h(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function ne(e,t){let r=e.trim();if(r.length>4096||h(r,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return r}function L(e,t){return d(e,t,1,Number.MAX_SAFE_INTEGER)}function d(e,t,r,n){if(!Number.isSafeInteger(e)||e<r||e>n)throw new Error(`${t} must be an integer between ${r} and ${n}`);return e}function j(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return e}function oe(e,t){let r=c(e.toLowerCase(),t,253);if(r==="localhost"||/^(?:\d{1,3}\.){3}\d{1,3}$/.test(r)||r.includes(":")||!/^(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(r))throw new Error(`${t} must be a public DNS hostname or wildcard hostname`);return r}function E(e,t){let r=c(e.replaceAll("\\","/"),t,4096);if(r.startsWith("/")||/^[A-Za-z]:\//.test(r)||r.split("/").includes(".."))throw new Error(`${t} must be workspace-relative`);return r.replace(/^\.\//,"")}function se(e){let t=c(e,"secret environment name",256);if(!/^[A-Z_][A-Z0-9_]*$/.test(t))throw new Error("Secret environment target must be an uppercase environment variable name");return t}function ie(e){let t=e.trim().toLowerCase();if(!/^sha256:[a-f0-9]{64}$/.test(t))throw new Error("image.digest must be a sha256 OCI digest");return t}function ae(e,t){return c(e,t,512)}function ce(e,t,r){return[...new Set(e.map((n,o)=>c(n,`${t}[${o}]`,r)))]}import{createHash as de,createHmac as X,timingSafeEqual as ue}from"node:crypto";function Qe(e){let t=typeof e.body=="string"?Buffer.from(e.body,"utf8"):Buffer.from(e.body),r=de("sha256").update(t).digest("hex"),n=e.signature?.trim();if(!n)return{valid:!1,source:e.source,bodySha256:r,error:"missing-signature"};if(!e.secret||e.secret.length<16)throw new Error("Webhook secret must contain at least 16 characters");let o,s=n;if(e.source==="slack"){if(!e.timestamp||!/^\d+$/.test(e.timestamp))return{valid:!1,source:e.source,bodySha256:r,error:"invalid-timestamp"};let a=Number(e.timestamp)*1e3,m=Math.abs((e.now??new Date).getTime()-a);if(!Number.isFinite(a)||m>(e.maxClockSkewMs??5*6e4))return{valid:!1,source:e.source,bodySha256:r,timestamp:e.timestamp,error:"stale-timestamp"};o=`v0=${X("sha256",e.secret).update(`v0:${e.timestamp}:`).update(t).digest("hex")}`}else e.source==="gitlab"?o=e.secret:e.source==="teams"?o=`HMAC ${X("sha256",Buffer.from(e.secret,"base64")).update(t).digest("base64")}`:(o=`${e.source==="github"||e.source==="jira"?"sha256=":e.source==="xeno"?"v1=":""}${X("sha256",e.secret).update(t).digest("hex")}`,e.source==="linear"&&s.startsWith("sha256=")&&(s=s.slice(7)));let i=le(o,s);return{valid:i,source:e.source,bodySha256:r,...e.timestamp?{timestamp:e.timestamp}:{},...i?{}:{error:"invalid-signature"}}}function le(e,t){let r=Buffer.from(e,"utf8"),n=Buffer.from(t,"utf8");return r.length===n.length&&ue(r,n)}import{createHash as me,verify as pe}from"node:crypto";var H="xeno.hosted-execution-adapter-certification.v2",z=2,ge=744*60*60*1e3;function rt(e){return U(e),Buffer.from(C(e),"utf8")}function nt(e,t){if(e?.schemaVersion!==H)throw new Error(`Hosted execution adapter certificate must use ${H}`);let{signature:r,...n}=e;if(U(n),r?.algorithm!=="ed25519")throw new Error("Hosted execution adapter signature must use ed25519");let o=I(t.executableSha256,"executableSha256"),s=I(t.controlPlaneCandidateSha256,"controlPlaneCandidateSha256");if(n.adapter.executableSha256!==o)throw new Error("Hosted execution adapter executable does not match its signed certificate");if(n.controlPlaneCandidateSha256!==s)throw new Error("Hosted execution adapter certificate is bound to another control-plane candidate");let i=t.platform??process.platform,a=t.architecture??process.arch;if(n.platform.os!==i||n.platform.architecture!==a)throw new Error(`Hosted execution adapter certificate targets ${n.platform.os}-${n.platform.architecture}, not ${i}-${a}`);let m=S(n.issuedAt,"issuedAt"),f=S(n.expiresAt,"expiresAt"),D=(t.now??new Date).getTime();if(m>D+5*6e4)throw new Error("Hosted execution adapter certificate is not yet valid");if(f<=D)throw new Error("Hosted execution adapter certificate has expired");if(f<=m||f-m>ge)throw new Error("Hosted execution adapter certificate lifetime must be positive and at most 31 days");let V=t.trustedKeys[n.reviewer.keyId];if(!V)throw new Error(`Hosted execution adapter reviewer key is not trusted: ${n.reviewer.keyId}`);if(!pe(null,Buffer.from(C(n),"utf8"),V,fe(r.value,"signature.value")))throw new Error("Hosted execution adapter certificate signature is invalid");return{certificationId:n.certificationId,adapterName:n.adapter.name,adapterVersion:n.adapter.version,protocolVersion:n.adapter.protocolVersion,executableSha256:o,controlPlaneCandidateSha256:s,certificateSha256:me("sha256").update(C(e)).digest("hex"),expiresAt:n.expiresAt,reviewerKeyId:n.reviewer.keyId}}function U(e){if(e.schemaVersion!==H)throw new Error(`Hosted execution adapter certificate must use ${H}`);if(k(e.certificationId,"certificationId"),k(e.adapter?.name,"adapter.name"),k(e.adapter?.version,"adapter.version"),e.adapter?.protocolVersion!==z)throw new Error(`Hosted execution adapter protocol must be ${z}`);I(e.adapter.executableSha256,"adapter.executableSha256"),I(e.controlPlaneCandidateSha256,"controlPlaneCandidateSha256"),k(e.reviewer?.keyId,"reviewer.keyId");let t=["immutableImages","filesystemIsolation","networkDefaultDeny","destinationAllowlist","secretProjection","nonRootExecution","readOnlyRoot","processTreeCleanup","resourceLimits","interactiveControl","artifactProtocol","gitResultReporting"];if(!e.capabilities||t.some(r=>e.capabilities[r]!==!0))throw new Error("Hosted execution adapter certificate does not attest every required containment capability");S(e.issuedAt,"issuedAt"),S(e.expiresAt,"expiresAt")}function C(e){return u(e)}function I(e,t){let r=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(r))throw new Error(`${t} must be a lowercase SHA-256 digest`);return r}function k(e,t){let r=e?.trim();if(!r||r.length>256||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function S(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return r}function fe(e,t){if(typeof e!="string"||e.length===0||e.length>4096||!/^[A-Za-z0-9+/]+={0,2}$/.test(e))throw new Error(`${t} must be bounded base64`);let r=Buffer.from(e,"base64");if(r.toString("base64")!==e)throw new Error(`${t} is not canonical base64`);return r}import{createHash as he}from"node:crypto";var J=["low","medium","high","xhigh","max"],F=["default","plan","acceptEdits","auto","dontAsk","bypassPermissions"];var ye=2,xe=["Read","Write","Edit","Glob","Grep","WebFetch"],we=new Set(xe);function be(e){if(!G(e.certificationId))throw new Error("certificationId is invalid");let t=new Set(e.authority.secretRefs);return{certificationId:e.certificationId,environmentChecksum:e.environment.checksum.value,imageDigest:e.environment.image.digest,networkPolicySha256:K({authority:e.authority.network,policy:e.environment.network}),secretProjectionSha256:K(e.environment.secrets.filter(r=>t.has(r.ref))),filesystem:e.authority.filesystem,network:e.authority.network==="deny"?"deny":"allowlist",immutableImage:!0,readOnlyRoot:!0,nonRoot:!0,processTreeCleanup:!0,resourceLimits:!0,inferenceGateway:"brokered"}}function Ee(e){let t=[];if(!_e(e))return{valid:!1,errors:["Hosted execution job must be an object"]};let r=e;if(r.protocolVersion!==ye||r.kind!=="xeno-hosted-execution-job")return t.push("Unsupported hosted execution protocol"),{valid:!1,errors:t};y(r.runId,"runId",t),y(r.userId,"userId",t),y(r.workspaceId,"workspaceId",t),O(r.workspaceHostPath,"workspaceHostPath",4096,t),O(r.prompt,"prompt",512*1024,t),O(r.model,"model",512,t),r.effort!==void 0&&!J.includes(r.effort)&&t.push("effort is invalid"),F.includes(r.permissionMode)||t.push("permissionMode is invalid"),(typeof r.runScopedToken!="string"||!r.runScopedToken.startsWith("xrun_")||r.runScopedToken.length>16*1024)&&t.push("runScopedToken is not a bounded run-scoped token");let n;try{n=new URL(r.inferenceBaseUrl),(n.protocol!=="https:"||n.username||n.password||n.hash)&&t.push("inferenceBaseUrl must be credential-free HTTPS")}catch{t.push("inferenceBaseUrl is invalid")}let o=A(r.environment);t.push(...o.errors.map(i=>`environment: ${i}`)),r.environment?.workspaceId!==r.workspaceId&&t.push("environment workspace does not match the job"),r.environment?.image?.os!=="linux"&&t.push("hosted execution image must target Linux");let s=r.environment?.repository?.commit;(typeof s!="string"||!/^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(s))&&t.push("environment repository requires a full 40- or 64-character commit object id"),ve(r.authority,t),ke(r.budget,r.environment,t),He(r.allowedTools,t),Ie(r,t),Se(r,t),n&&!r.environment?.network?.destinations?.some(i=>{let a=i.ports?.length?i.ports:[443];return i.host.toLowerCase()===n.hostname.toLowerCase()&&a.includes(Number(n.port||443))})&&t.push("inference origin is absent from the environment network allowlist");try{let i=Te(r.environment?.repository);r.environment?.network?.destinations?.some(a=>{let m=a.ports?.length?a.ports:[443];return a.host.toLowerCase()===i.hostname&&m.includes(i.port)})||t.push("repository origin is absent from the environment network allowlist")}catch{t.push("environment repository must resolve to a credential-free HTTPS origin")}return{valid:t.length===0,errors:t}}function ut(e){let t=Ee(e);if(!t.valid)throw new Error(`Invalid hosted execution job: ${t.errors.join("; ")}`)}function ve(e,t){(!e||!["read","workspace-write"].includes(e.filesystem))&&t.push("authority.filesystem is invalid"),(!e||!["deny","environment-policy"].includes(e.network))&&t.push("authority.network is invalid"),(!e||!["deny","approval-required"].includes(e.externalActions))&&t.push("authority.externalActions is invalid"),!Array.isArray(e?.secretRefs)||new Set(e.secretRefs).size!==e.secretRefs.length?t.push("authority.secretRefs must be a unique array"):e.secretRefs.forEach((r,n)=>y(r,`authority.secretRefs[${n}]`,t))}function ke(e,t,r){(!e||!Number.isFinite(e.maxCredits)||e.maxCredits<=0)&&r.push("budget.maxCredits is invalid"),(!e||!P(e.maxDurationMs)||e.maxDurationMs>(t?.resources?.wallTimeMs??0))&&r.push("budget.maxDurationMs is invalid or exceeds the environment limit"),e?.maxTokens!==void 0&&!P(e.maxTokens)&&r.push("budget.maxTokens is invalid"),e?.maxToolCalls!==void 0&&!P(e.maxToolCalls)&&r.push("budget.maxToolCalls is invalid")}function He(e,t){if(!Array.isArray(e)||e.length<1||e.length>512||new Set(e).size!==e.length){t.push("allowedTools must contain 1..512 unique tool names");return}e.forEach((r,n)=>{y(r,`allowedTools[${n}]`,t),we.has(r)||t.push(`allowedTools[${n}] is not in the hosted v0.1 registry`)})}function Ie(e,t){if(!Array.isArray(e.secrets)||e.secrets.length>128){t.push("secrets must be a bounded array");return}let r=new Set(e.authority?.secretRefs??[]),n=new Map((e.environment?.secrets??[]).map(s=>[s.ref,s])),o=new Set;for(let[s,i]of e.secrets.entries()){let a=n.get(i.ref);if(!a||!r.has(i.ref)||o.has(i.ref)){t.push(`secrets[${s}] is undeclared, unauthorized, or duplicated`);continue}o.add(i.ref),(x(a.target)!==x(i.target)||a.exposeToChildProcesses!==i.exposeToChildProcesses)&&t.push(`secrets[${s}] does not match its declared projection`),(typeof i.value!="string"||i.value.length<1||Buffer.byteLength(i.value,"utf8")>1024*1024)&&t.push(`secrets[${s}] value is empty or too large`)}for(let s of e.environment?.secrets??[])s.required&&(!r.has(s.ref)||!o.has(s.ref))&&t.push(`required secret ${s.ref} is absent or unauthorized`);[...r].some(s=>!n.has(s))&&t.push("authority references an undeclared secret")}function Se(e,t){let r=e.expectedBoundary;if(!r){t.push("expectedBoundary is missing");return}let n;try{n=be({certificationId:r.certificationId,environment:e.environment,authority:e.authority})}catch{t.push("expectedBoundary does not match the hosted execution contract");return}(!G(r.certificationId)||x(r)!==x(n))&&t.push("expectedBoundary does not match the hosted execution contract")}function y(e,t,r){(typeof e!="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e))&&r.push(`${t} is invalid`)}function O(e,t,r,n){(typeof e!="string"||e.length<1||e.length>r||e.includes("\0"))&&n.push(`${t} is invalid`)}function P(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0}function G(e){return typeof e=="string"&&/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e)}function _e(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function x(e){return u(e)}function K(e){return he("sha256").update(x(e)).digest("hex")}function Te(e){if(!e)throw new Error("repository source is missing");let t=e.repository.replace(/^\/+|\/+$/g,""),r=e.provider==="github"&&!t.includes("://")?`https://github.com/${t}.git`:e.provider==="gitlab"&&!t.includes("://")?`https://gitlab.com/${t}.git`:e.provider==="bitbucket"&&!t.includes("://")?`https://bitbucket.org/${t}.git`:e.repository,n=new URL(r);if(n.protocol!=="https:"||n.username||n.password||n.hash)throw new Error("repository origin is not credential-free HTTPS");return{hostname:n.hostname.toLowerCase(),port:Number(n.port||443)}}import{createHash as Re,randomUUID as Ae}from"node:crypto";var Z=1,Q=1;function Xe(e){let t={schemaVersion:Z,kind:"xeno-hosted-control",controlId:l(e.controlId??`hctl_${Ae()}`,"controlId"),runId:l(e.runId,"runId"),workspaceId:l(e.workspaceId,"workspaceId"),actorId:l(e.actorId,"actorId"),idempotencyKey:g(e.idempotencyKey,"idempotencyKey",512),createdAt:M(e.createdAt,"createdAt"),action:Oe(e.action)};return{...t,hash:{algorithm:"sha256",value:Y(t)}}}function ft(e){let t=[];try{let{hash:r,schemaVersion:n,kind:o,...s}=e,i=Xe(s);(e.schemaVersion!==Z||e.kind!=="xeno-hosted-control")&&t.push("Unsupported hosted control command"),w(_(e))!==w(_(i))&&t.push("Hosted control command is not normalized"),(r?.algorithm!=="sha256"||r.value!==i.hash.value)&&t.push("Hosted control command hash mismatch")}catch(r){t.push(r instanceof Error?r.message:String(r))}return{valid:t.length===0,errors:t}}function ht(e){if(!["accepted","applied","rejected","unsupported"].includes(e.status))throw new Error("Hosted control acknowledgement status is invalid");return{controlId:l(e.controlId,"controlId"),status:e.status,acknowledgedAt:M(e.acknowledgedAt,"acknowledgedAt"),...e.reason?{reason:g(e.reason,"reason",2048)}:{}}}function Ce(e){let t=e.git?{...e.git.branch?{branch:N(e.git.branch,"git.branch")}:{},...e.git.baseRef?{baseRef:N(e.git.baseRef,"git.baseRef")}:{},...e.git.commit?{commit:N(e.git.commit,"git.commit")}:{}}:void 0,r={schemaVersion:Q,kind:"xeno-hosted-run-result",runId:l(e.runId,"runId"),workspaceId:l(e.workspaceId,"workspaceId"),completedAt:M(e.completedAt,"completedAt"),...t&&Object.keys(t).length>0?{git:t}:{},...e.pullRequest?{pullRequest:Pe(e.pullRequest)}:{},artifactIds:W(e.artifactIds,"artifactIds"),evidenceArtifactIds:W(e.evidenceArtifactIds,"evidenceArtifactIds")};return{...r,hash:{algorithm:"sha256",value:Y(r)}}}function yt(e){let t=[];try{let{hash:r,schemaVersion:n,kind:o,...s}=e,i=Ce(s);(e.schemaVersion!==Q||e.kind!=="xeno-hosted-run-result")&&t.push("Unsupported hosted run result"),w(_(e))!==w(_(i))&&t.push("Hosted run result is not normalized"),(r?.algorithm!=="sha256"||r.value!==i.hash.value)&&t.push("Hosted run result hash mismatch")}catch(r){t.push(r instanceof Error?r.message:String(r))}return{valid:t.length===0,errors:t}}function Oe(e){if(e?.type==="message")return{type:"message",message:g(e.message,"action.message",32768)};if(e?.type==="approval"){if(e.decision!=="approved"&&e.decision!=="rejected")throw new Error("Hosted approval decision is invalid");return{type:"approval",requestId:l(e.requestId,"action.requestId"),decision:e.decision,scopeHash:Ne(e.scopeHash,"action.scopeHash"),...e.rationale?{rationale:g(e.rationale,"action.rationale",4096)}:{}}}throw new Error("Hosted control action is invalid")}function Pe(e){let t;try{t=new URL(e.url)}catch{throw new Error("pullRequest.url is invalid")}if(t.protocol!=="https:"||t.username||t.password)throw new Error("pullRequest.url must be credential-free HTTPS");if(!Number.isSafeInteger(e.number)||e.number<1)throw new Error("pullRequest.number must be a positive integer");return{provider:l(e.provider,"pullRequest.provider"),repository:g(e.repository,"pullRequest.repository",2048),number:e.number,url:t.toString()}}function W(e,t){if(!Array.isArray(e)||e.length>1e4)throw new Error(`${t} is invalid`);return[...new Set(e.map((r,n)=>l(r,`${t}[${n}]`)))].sort()}function N(e,t){return g(e,t,512)}function l(e,t){let r=g(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function g(e,t,r){let n=e?.trim();if(!n||n.length>r||h(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function M(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be ISO-8601 UTC`);return e}function Ne(e,t){let r=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(r))throw new Error(`${t} must be a lowercase SHA-256 digest`);return r}function Y(e){return Re("sha256").update(w(e)).digest("hex")}function w(e){return u(e)}function _(e){let{hash:t,...r}=e;return r}export{Z as XENO_HOSTED_CONTROL_SCHEMA_VERSION,b as XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION,T as XENO_HOSTED_EVENT_SCHEMA_VERSION,H as XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA,ge as XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS,z as XENO_HOSTED_EXECUTION_ADAPTER_PROTOCOL_VERSION,ye as XENO_HOSTED_EXECUTION_PROTOCOL_VERSION,xe as XENO_HOSTED_EXECUTION_TOOL_NAMES,Q as XENO_HOSTED_RESULT_SCHEMA_VERSION,Me as XENO_HOSTED_RUN_SCHEMA_VERSION,De as XENO_HOSTED_TRIGGER_SCHEMA_VERSION,ut as assertValidXenoHostedExecutionJob,Xe as createXenoHostedControlCommand,Ue as createXenoHostedEnvironmentManifest,Je as createXenoHostedEvent,be as createXenoHostedExecutionBoundaryReceipt,Ce as createXenoHostedRunResult,Ge as deriveHostedIdempotencyKey,Ke as hostedEnvironmentIdentity,ht as normalizeXenoHostedControlAcknowledgement,ft as verifyXenoHostedControlCommand,A as verifyXenoHostedEnvironmentManifest,Fe as verifyXenoHostedEventChain,nt as verifyXenoHostedExecutionAdapterCertification,Ee as verifyXenoHostedExecutionJob,yt as verifyXenoHostedRunResult,Qe as verifyXenoHostedWebhook,rt as xenoHostedExecutionAdapterSigningPayload};
1
+ var b=1,Me=1,T=1,De=1;import{createHash as B,randomUUID as ee}from"node:crypto";function u(e){return JSON.stringify(R(e,new Set))}function R(e,t){if(e===null||typeof e!="object"){if(typeof e=="number"&&!Number.isFinite(e))throw new TypeError("Artifact JSON cannot contain non-finite numbers");return e}if(t.has(e))throw new TypeError("Artifact JSON cannot contain cycles");if(t.add(e),Array.isArray(e)){let n=e.map(o=>R(o,t));return t.delete(e),n}let r={};for(let n of Object.keys(e).sort((o,s)=>o.localeCompare(s))){let o=e[n];if(o===void 0)throw new TypeError(`Artifact JSON property ${n} is undefined`);r[n]=R(o,t)}return t.delete(e),r}function h(e,t={}){for(let r of e){let n=r.codePointAt(0);if(n===127)return!0;if(!(n>31)&&!(n===9&&t.allowTab===!0)&&!((n===10||n===13)&&t.allowLineBreaks===!0))return!0}return!1}function Ue(e){let t={...$(e),schemaVersion:1,kind:"xeno-hosted-environment"};return{...t,checksum:{algorithm:"sha256",value:v(t)}}}function A(e){let t=[];if(e?.schemaVersion!==1||e.kind!=="xeno-hosted-environment")return t.push("Unsupported hosted environment manifest"),{valid:!1,errors:t};let r;try{let{checksum:n,schemaVersion:o,kind:s,...i}=e;r={...$(i),schemaVersion:1,kind:"xeno-hosted-environment"}}catch(n){return t.push(n instanceof Error?n.message:String(n)),{valid:!1,errors:t}}return u(r)!==u(te(e))&&t.push("Hosted environment manifest is not normalized"),(e.checksum?.algorithm!=="sha256"||e.checksum.value!==v(r))&&t.push("Hosted environment checksum mismatch"),{valid:t.length===0,errors:t}}function Je(e){let t=p(e.streamId,"streamId"),r=L(e.sequence,"sequence");if(e.previous){if(e.previous.streamId!==t)throw new Error("Previous event belongs to another stream");if(e.previous.sequence+1!==r)throw new Error("Hosted event sequence must be contiguous")}else if(r!==1)throw new Error("The first hosted event sequence must be 1");let n={schemaVersion:1,kind:"xeno-hosted-event",eventId:p(e.eventId??`hevt_${ee()}`,"eventId"),streamId:t,sequence:r,timestamp:j(e.timestamp??new Date().toISOString(),"timestamp"),type:q(e.type,"type"),actorId:p(e.actorId,"actorId"),...e.idempotencyKey?{idempotencyKey:c(e.idempotencyKey,"idempotencyKey",512)}:{},payload:re(e.payload??{},"payload"),previousHash:e.previous?.hash??null};return{...n,hash:v(n)}}function Fe(e,t){let r=[],n,o=t?t.afterSequence+1:1,s=t?.lastHash??null;for(let a of e){if(a.schemaVersion!==1||a.kind!=="xeno-hosted-event"){r.push(`Unsupported hosted event at sequence ${String(a.sequence)}`);continue}a.sequence!==o&&r.push(`Hosted event sequence gap at ${a.sequence}; expected ${o}`),a.previousHash!==s&&r.push(`Hosted event previous hash mismatch at ${a.sequence}`);let{hash:m,...f}=a;m!==v(f)&&r.push(`Hosted event hash mismatch at ${a.sequence}`),n&&n.streamId!==a.streamId&&r.push(`Hosted event stream changed at ${a.sequence}`),n=a,o=a.sequence+1,s=a.hash}let i=e.at(-1);return{valid:r.length===0,errors:r,cursor:i?{streamId:i.streamId,afterSequence:i.sequence,lastHash:i.hash}:t??null}}function Ke(e){let t=A(e);if(!t.valid)throw new Error(t.errors.join("; "));return`${e.environmentId}@${e.revision}:${e.checksum.value}`}function Ge(...e){if(e.length===0)throw new Error("At least one idempotency-key part is required");let t=e.map((r,n)=>ne(r,`parts[${n}]`));return`xeno:${B("sha256").update(t.join("\0")).digest("hex")}`}function $(e){let t=e.secrets.map((o,s)=>({ref:p(o.ref,`secrets[${s}].ref`),target:o.target.kind==="environment"?{kind:"environment",name:se(o.target.name)}:{kind:"file",path:E(o.target.path,`secrets[${s}].target.path`)},required:!!o.required,exposeToChildProcesses:!!o.exposeToChildProcesses})),r=new Set,n=new Set;for(let o of t){if(r.has(o.ref))throw new Error(`Duplicate secret ref: ${o.ref}`);r.add(o.ref);let s=`${o.target.kind}:${o.target.kind==="environment"?o.target.name:o.target.path}`;if(n.has(s))throw new Error(`Duplicate secret target: ${s}`);n.add(s)}if(e.network.default!=="deny")throw new Error("Hosted network policy must be default-deny");return{environmentId:p(e.environmentId,"environmentId"),revision:L(e.revision,"revision"),createdAt:j(e.createdAt,"createdAt"),createdBy:p(e.createdBy,"createdBy"),workspaceId:p(e.workspaceId,"workspaceId"),name:c(e.name,"name",160),repository:{provider:e.repository.provider,repository:c(e.repository.repository,"repository.repository",2048),ref:c(e.repository.ref,"repository.ref",512),...e.repository.commit?{commit:ae(e.repository.commit,"repository.commit")}:{},...e.repository.subdirectory?{subdirectory:E(e.repository.subdirectory,"repository.subdirectory")}:{},...e.repository.shallow!==void 0?{shallow:!!e.repository.shallow}:{}},image:{reference:c(e.image.reference,"image.reference",2048),digest:ie(e.image.digest),os:e.image.os,architecture:e.image.architecture},setup:e.setup.map((o,s)=>({id:p(o.id,`setup[${s}].id`),command:c(o.command,`setup[${s}].command`,32768),...o.workingDirectory?{workingDirectory:E(o.workingDirectory,`setup[${s}].workingDirectory`)}:{},timeoutMs:d(o.timeoutMs,`setup[${s}].timeoutMs`,1e3,36e5),network:o.network})),caches:e.caches.map((o,s)=>({key:c(o.key,`caches[${s}].key`,512),path:E(o.path,`caches[${s}].path`),...o.restoreKeys?.length?{restoreKeys:ce(o.restoreKeys,`caches[${s}].restoreKeys`,512)}:{},...o.readOnly!==void 0?{readOnly:!!o.readOnly}:{},...o.maxBytes!==void 0?{maxBytes:d(o.maxBytes,`caches[${s}].maxBytes`,1,Number.MAX_SAFE_INTEGER)}:{}})),network:{default:"deny",dns:e.network.dns,destinations:e.network.destinations.map((o,s)=>({host:oe(o.host,`network.destinations[${s}].host`),...o.ports?.length?{ports:[...new Set(o.ports.map(i=>d(i,"port",1,65535)))].sort((i,a)=>i-a)}:{},...o.protocols?.length?{protocols:[...new Set(o.protocols)].sort()}:{},reason:c(o.reason,`network.destinations[${s}].reason`,500)})).sort((o,s)=>o.host.localeCompare(s.host)),...e.network.maxResponseBytes!==void 0?{maxResponseBytes:d(e.network.maxResponseBytes,"network.maxResponseBytes",1,Number.MAX_SAFE_INTEGER)}:{}},secrets:t,resources:{cpuMillis:d(e.resources.cpuMillis,"resources.cpuMillis",10,1e6),memoryBytes:d(e.resources.memoryBytes,"resources.memoryBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),diskBytes:d(e.resources.diskBytes,"resources.diskBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),processLimit:d(e.resources.processLimit,"resources.processLimit",1,65535),wallTimeMs:d(e.resources.wallTimeMs,"resources.wallTimeMs",1e3,10080*60*1e3)},retention:{workspaceTtlMs:d(e.retention.workspaceTtlMs,"retention.workspaceTtlMs",0,365*24*60*60*1e3),eventTtlMs:d(e.retention.eventTtlMs,"retention.eventTtlMs",6e4,365*24*60*60*1e3),artifactTtlMs:d(e.retention.artifactTtlMs,"retention.artifactTtlMs",6e4,365*24*60*60*1e3),wipeWorkspace:!!e.retention.wipeWorkspace},labels:Object.fromEntries(Object.entries(e.labels).map(([o,s])=>[q(o,"label key"),c(s,`labels.${o}`,500)]).sort(([o],[s])=>o.localeCompare(s)))}}function te(e){let{checksum:t,...r}=e;return r}function v(e){return B("sha256").update(u(e)).digest("hex")}function re(e,t){let r=u(e);if(Buffer.byteLength(r,"utf8")>256*1024)throw new Error(`${t} exceeds 262144 bytes`);return JSON.parse(r)}function p(e,t){let r=c(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function q(e,t){let r=c(e,t,160);if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function c(e,t,r){let n=e.trim();if(!n||n.length>r||h(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function ne(e,t){let r=e.trim();if(r.length>4096||h(r,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return r}function L(e,t){return d(e,t,1,Number.MAX_SAFE_INTEGER)}function d(e,t,r,n){if(!Number.isSafeInteger(e)||e<r||e>n)throw new Error(`${t} must be an integer between ${r} and ${n}`);return e}function j(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return e}function oe(e,t){let r=c(e.toLowerCase(),t,253);if(r==="localhost"||/^(?:\d{1,3}\.){3}\d{1,3}$/.test(r)||r.includes(":")||!/^(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(r))throw new Error(`${t} must be a public DNS hostname or wildcard hostname`);return r}function E(e,t){let r=c(e.replaceAll("\\","/"),t,4096);if(r.startsWith("/")||/^[A-Za-z]:\//.test(r)||r.split("/").includes(".."))throw new Error(`${t} must be workspace-relative`);return r.replace(/^\.\//,"")}function se(e){let t=c(e,"secret environment name",256);if(!/^[A-Z_][A-Z0-9_]*$/.test(t))throw new Error("Secret environment target must be an uppercase environment variable name");return t}function ie(e){let t=e.trim().toLowerCase();if(!/^sha256:[a-f0-9]{64}$/.test(t))throw new Error("image.digest must be a sha256 OCI digest");return t}function ae(e,t){return c(e,t,512)}function ce(e,t,r){return[...new Set(e.map((n,o)=>c(n,`${t}[${o}]`,r)))]}import{createHash as de,createHmac as C,timingSafeEqual as ue}from"node:crypto";function Qe(e){let t=typeof e.body=="string"?Buffer.from(e.body,"utf8"):Buffer.from(e.body),r=de("sha256").update(t).digest("hex"),n=e.signature?.trim();if(!n)return{valid:!1,source:e.source,bodySha256:r,error:"missing-signature"};if(!e.secret||e.secret.length<16)throw new Error("Webhook secret must contain at least 16 characters");let o,s=n;if(e.source==="slack"){if(!e.timestamp||!/^\d+$/.test(e.timestamp))return{valid:!1,source:e.source,bodySha256:r,error:"invalid-timestamp"};let a=Number(e.timestamp)*1e3,m=Math.abs((e.now??new Date).getTime()-a);if(!Number.isFinite(a)||m>(e.maxClockSkewMs??5*6e4))return{valid:!1,source:e.source,bodySha256:r,timestamp:e.timestamp,error:"stale-timestamp"};o=`v0=${C("sha256",e.secret).update(`v0:${e.timestamp}:`).update(t).digest("hex")}`}else e.source==="gitlab"?o=e.secret:e.source==="teams"?o=`HMAC ${C("sha256",Buffer.from(e.secret,"base64")).update(t).digest("base64")}`:(o=`${e.source==="github"||e.source==="jira"?"sha256=":e.source==="xeno"?"v1=":""}${C("sha256",e.secret).update(t).digest("hex")}`,e.source==="linear"&&s.startsWith("sha256=")&&(s=s.slice(7)));let i=le(o,s);return{valid:i,source:e.source,bodySha256:r,...e.timestamp?{timestamp:e.timestamp}:{},...i?{}:{error:"invalid-signature"}}}function le(e,t){let r=Buffer.from(e,"utf8"),n=Buffer.from(t,"utf8");return r.length===n.length&&ue(r,n)}import{createHash as me,verify as pe}from"node:crypto";var H="xeno.hosted-execution-adapter-certification.v2",z=2,ge=744*60*60*1e3;function rt(e){return U(e),Buffer.from(X(e),"utf8")}function nt(e,t){if(e?.schemaVersion!==H)throw new Error(`Hosted execution adapter certificate must use ${H}`);let{signature:r,...n}=e;if(U(n),r?.algorithm!=="ed25519")throw new Error("Hosted execution adapter signature must use ed25519");let o=I(t.executableSha256,"executableSha256"),s=I(t.controlPlaneCandidateSha256,"controlPlaneCandidateSha256");if(n.adapter.executableSha256!==o)throw new Error("Hosted execution adapter executable does not match its signed certificate");if(n.controlPlaneCandidateSha256!==s)throw new Error("Hosted execution adapter certificate is bound to another control-plane candidate");let i=t.platform??process.platform,a=t.architecture??process.arch;if(n.platform.os!==i||n.platform.architecture!==a)throw new Error(`Hosted execution adapter certificate targets ${n.platform.os}-${n.platform.architecture}, not ${i}-${a}`);let m=S(n.issuedAt,"issuedAt"),f=S(n.expiresAt,"expiresAt"),D=(t.now??new Date).getTime();if(m>D+5*6e4)throw new Error("Hosted execution adapter certificate is not yet valid");if(f<=D)throw new Error("Hosted execution adapter certificate has expired");if(f<=m||f-m>ge)throw new Error("Hosted execution adapter certificate lifetime must be positive and at most 31 days");let V=t.trustedKeys[n.reviewer.keyId];if(!V)throw new Error(`Hosted execution adapter reviewer key is not trusted: ${n.reviewer.keyId}`);if(!pe(null,Buffer.from(X(n),"utf8"),V,fe(r.value,"signature.value")))throw new Error("Hosted execution adapter certificate signature is invalid");return{certificationId:n.certificationId,adapterName:n.adapter.name,adapterVersion:n.adapter.version,protocolVersion:n.adapter.protocolVersion,executableSha256:o,controlPlaneCandidateSha256:s,certificateSha256:me("sha256").update(X(e)).digest("hex"),expiresAt:n.expiresAt,reviewerKeyId:n.reviewer.keyId}}function U(e){if(e.schemaVersion!==H)throw new Error(`Hosted execution adapter certificate must use ${H}`);if(k(e.certificationId,"certificationId"),k(e.adapter?.name,"adapter.name"),k(e.adapter?.version,"adapter.version"),e.adapter?.protocolVersion!==z)throw new Error(`Hosted execution adapter protocol must be ${z}`);I(e.adapter.executableSha256,"adapter.executableSha256"),I(e.controlPlaneCandidateSha256,"controlPlaneCandidateSha256"),k(e.reviewer?.keyId,"reviewer.keyId");let t=["immutableImages","filesystemIsolation","networkDefaultDeny","destinationAllowlist","secretProjection","nonRootExecution","readOnlyRoot","processTreeCleanup","resourceLimits","interactiveControl","artifactProtocol","gitResultReporting"];if(!e.capabilities||t.some(r=>e.capabilities[r]!==!0))throw new Error("Hosted execution adapter certificate does not attest every required containment capability");S(e.issuedAt,"issuedAt"),S(e.expiresAt,"expiresAt")}function X(e){return u(e)}function I(e,t){let r=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(r))throw new Error(`${t} must be a lowercase SHA-256 digest`);return r}function k(e,t){let r=e?.trim();if(!r||r.length>256||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function S(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return r}function fe(e,t){if(typeof e!="string"||e.length===0||e.length>4096||!/^[A-Za-z0-9+/]+={0,2}$/.test(e))throw new Error(`${t} must be bounded base64`);let r=Buffer.from(e,"base64");if(r.toString("base64")!==e)throw new Error(`${t} is not canonical base64`);return r}import{createHash as he}from"node:crypto";var J=["low","medium","high","xhigh","max"],F=["default","plan","acceptEdits","auto","dontAsk","bypassPermissions"];var ye=2,xe=["Read","Write","Edit","Glob","Grep","WebFetch"],we=new Set(xe);function be(e){if(!G(e.certificationId))throw new Error("certificationId is invalid");let t=new Set(e.authority.secretRefs);return{certificationId:e.certificationId,environmentChecksum:e.environment.checksum.value,imageDigest:e.environment.image.digest,networkPolicySha256:K({authority:e.authority.network,policy:e.environment.network}),secretProjectionSha256:K(e.environment.secrets.filter(r=>t.has(r.ref))),filesystem:e.authority.filesystem,network:e.authority.network==="deny"?"deny":"allowlist",immutableImage:!0,readOnlyRoot:!0,nonRoot:!0,processTreeCleanup:!0,resourceLimits:!0,inferenceGateway:"brokered"}}function Ee(e){let t=[];if(!_e(e))return{valid:!1,errors:["Hosted execution job must be an object"]};let r=e;if(r.protocolVersion!==ye||r.kind!=="xeno-hosted-execution-job")return t.push("Unsupported hosted execution protocol"),{valid:!1,errors:t};y(r.runId,"runId",t),y(r.userId,"userId",t),y(r.workspaceId,"workspaceId",t),O(r.workspaceHostPath,"workspaceHostPath",4096,t),O(r.prompt,"prompt",512*1024,t),O(r.model,"model",512,t),r.effort!==void 0&&!J.includes(r.effort)&&t.push("effort is invalid"),F.includes(r.permissionMode)||t.push("permissionMode is invalid"),(typeof r.runScopedToken!="string"||!r.runScopedToken.startsWith("xrun_")||r.runScopedToken.length>16*1024)&&t.push("runScopedToken is not a bounded run-scoped token");let n;try{n=new URL(r.inferenceBaseUrl),(n.protocol!=="https:"||n.username||n.password||n.hash)&&t.push("inferenceBaseUrl must be credential-free HTTPS")}catch{t.push("inferenceBaseUrl is invalid")}let o=A(r.environment);t.push(...o.errors.map(i=>`environment: ${i}`)),r.environment?.workspaceId!==r.workspaceId&&t.push("environment workspace does not match the job"),r.environment?.image?.os!=="linux"&&t.push("hosted execution image must target Linux");let s=r.environment?.repository?.commit;(typeof s!="string"||!/^(?:[a-fA-F0-9]{40}|[a-fA-F0-9]{64})$/.test(s))&&t.push("environment repository requires a full 40- or 64-character commit object id"),ve(r.authority,t),ke(r.budget,r.environment,t),He(r.allowedTools,t),Ie(r,t),Se(r,t),n&&!r.environment?.network?.destinations?.some(i=>{let a=i.ports?.length?i.ports:[443];return i.host.toLowerCase()===n.hostname.toLowerCase()&&a.includes(Number(n.port||443))})&&t.push("inference origin is absent from the environment network allowlist");try{let i=Te(r.environment?.repository);r.environment?.network?.destinations?.some(a=>{let m=a.ports?.length?a.ports:[443];return a.host.toLowerCase()===i.hostname&&m.includes(i.port)})||t.push("repository origin is absent from the environment network allowlist")}catch{t.push("environment repository must resolve to a credential-free HTTPS origin")}return{valid:t.length===0,errors:t}}function ut(e){let t=Ee(e);if(!t.valid)throw new Error(`Invalid hosted execution job: ${t.errors.join("; ")}`)}function ve(e,t){(!e||!["read","workspace-write"].includes(e.filesystem))&&t.push("authority.filesystem is invalid"),(!e||!["deny","environment-policy"].includes(e.network))&&t.push("authority.network is invalid"),(!e||!["deny","approval-required"].includes(e.externalActions))&&t.push("authority.externalActions is invalid"),!Array.isArray(e?.secretRefs)||new Set(e.secretRefs).size!==e.secretRefs.length?t.push("authority.secretRefs must be a unique array"):e.secretRefs.forEach((r,n)=>y(r,`authority.secretRefs[${n}]`,t))}function ke(e,t,r){(!e||!Number.isFinite(e.maxCredits)||e.maxCredits<=0)&&r.push("budget.maxCredits is invalid"),(!e||!P(e.maxDurationMs)||e.maxDurationMs>(t?.resources?.wallTimeMs??0))&&r.push("budget.maxDurationMs is invalid or exceeds the environment limit"),e?.maxTokens!==void 0&&!P(e.maxTokens)&&r.push("budget.maxTokens is invalid"),e?.maxToolCalls!==void 0&&!P(e.maxToolCalls)&&r.push("budget.maxToolCalls is invalid")}function He(e,t){if(!Array.isArray(e)||e.length<1||e.length>512||new Set(e).size!==e.length){t.push("allowedTools must contain 1..512 unique tool names");return}e.forEach((r,n)=>{y(r,`allowedTools[${n}]`,t),we.has(r)||t.push(`allowedTools[${n}] is not in the hosted v0.1 registry`)})}function Ie(e,t){if(!Array.isArray(e.secrets)||e.secrets.length>128){t.push("secrets must be a bounded array");return}let r=new Set(e.authority?.secretRefs??[]),n=new Map((e.environment?.secrets??[]).map(s=>[s.ref,s])),o=new Set;for(let[s,i]of e.secrets.entries()){let a=n.get(i.ref);if(!a||!r.has(i.ref)||o.has(i.ref)){t.push(`secrets[${s}] is undeclared, unauthorized, or duplicated`);continue}o.add(i.ref),(x(a.target)!==x(i.target)||a.exposeToChildProcesses!==i.exposeToChildProcesses)&&t.push(`secrets[${s}] does not match its declared projection`),(typeof i.value!="string"||i.value.length<1||Buffer.byteLength(i.value,"utf8")>1024*1024)&&t.push(`secrets[${s}] value is empty or too large`)}for(let s of e.environment?.secrets??[])s.required&&(!r.has(s.ref)||!o.has(s.ref))&&t.push(`required secret ${s.ref} is absent or unauthorized`);[...r].some(s=>!n.has(s))&&t.push("authority references an undeclared secret")}function Se(e,t){let r=e.expectedBoundary;if(!r){t.push("expectedBoundary is missing");return}let n;try{n=be({certificationId:r.certificationId,environment:e.environment,authority:e.authority})}catch{t.push("expectedBoundary does not match the hosted execution contract");return}(!G(r.certificationId)||x(r)!==x(n))&&t.push("expectedBoundary does not match the hosted execution contract")}function y(e,t,r){(typeof e!="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e))&&r.push(`${t} is invalid`)}function O(e,t,r,n){(typeof e!="string"||e.length<1||e.length>r||e.includes("\0"))&&n.push(`${t} is invalid`)}function P(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0}function G(e){return typeof e=="string"&&/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e)}function _e(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function x(e){return u(e)}function K(e){return he("sha256").update(x(e)).digest("hex")}function Te(e){if(!e)throw new Error("repository source is missing");let t=e.repository.replace(/^\/+|\/+$/g,""),r=e.provider==="github"&&!t.includes("://")?`https://github.com/${t}.git`:e.provider==="gitlab"&&!t.includes("://")?`https://gitlab.com/${t}.git`:e.provider==="bitbucket"&&!t.includes("://")?`https://bitbucket.org/${t}.git`:e.repository,n=new URL(r);if(n.protocol!=="https:"||n.username||n.password||n.hash)throw new Error("repository origin is not credential-free HTTPS");return{hostname:n.hostname.toLowerCase(),port:Number(n.port||443)}}import{createHash as Re,randomUUID as Ae}from"node:crypto";var Z=1,Q=1;function Ce(e){let t={schemaVersion:Z,kind:"xeno-hosted-control",controlId:l(e.controlId??`hctl_${Ae()}`,"controlId"),runId:l(e.runId,"runId"),workspaceId:l(e.workspaceId,"workspaceId"),actorId:l(e.actorId,"actorId"),idempotencyKey:g(e.idempotencyKey,"idempotencyKey",512),createdAt:M(e.createdAt,"createdAt"),action:Oe(e.action)};return{...t,hash:{algorithm:"sha256",value:Y(t)}}}function ft(e){let t=[];try{let{hash:r,schemaVersion:n,kind:o,...s}=e,i=Ce(s);(e.schemaVersion!==Z||e.kind!=="xeno-hosted-control")&&t.push("Unsupported hosted control command"),w(_(e))!==w(_(i))&&t.push("Hosted control command is not normalized"),(r?.algorithm!=="sha256"||r.value!==i.hash.value)&&t.push("Hosted control command hash mismatch")}catch(r){t.push(r instanceof Error?r.message:String(r))}return{valid:t.length===0,errors:t}}function ht(e){if(!["accepted","applied","rejected","unsupported"].includes(e.status))throw new Error("Hosted control acknowledgement status is invalid");return{controlId:l(e.controlId,"controlId"),status:e.status,acknowledgedAt:M(e.acknowledgedAt,"acknowledgedAt"),...e.reason?{reason:g(e.reason,"reason",2048)}:{}}}function Xe(e){let t=e.git?{...e.git.branch?{branch:N(e.git.branch,"git.branch")}:{},...e.git.baseRef?{baseRef:N(e.git.baseRef,"git.baseRef")}:{},...e.git.commit?{commit:N(e.git.commit,"git.commit")}:{}}:void 0,r={schemaVersion:Q,kind:"xeno-hosted-run-result",runId:l(e.runId,"runId"),workspaceId:l(e.workspaceId,"workspaceId"),completedAt:M(e.completedAt,"completedAt"),...t&&Object.keys(t).length>0?{git:t}:{},...e.pullRequest?{pullRequest:Pe(e.pullRequest)}:{},artifactIds:W(e.artifactIds,"artifactIds"),evidenceArtifactIds:W(e.evidenceArtifactIds,"evidenceArtifactIds")};return{...r,hash:{algorithm:"sha256",value:Y(r)}}}function yt(e){let t=[];try{let{hash:r,schemaVersion:n,kind:o,...s}=e,i=Xe(s);(e.schemaVersion!==Q||e.kind!=="xeno-hosted-run-result")&&t.push("Unsupported hosted run result"),w(_(e))!==w(_(i))&&t.push("Hosted run result is not normalized"),(r?.algorithm!=="sha256"||r.value!==i.hash.value)&&t.push("Hosted run result hash mismatch")}catch(r){t.push(r instanceof Error?r.message:String(r))}return{valid:t.length===0,errors:t}}function Oe(e){if(e?.type==="message")return{type:"message",message:g(e.message,"action.message",32768)};if(e?.type==="approval"){if(e.decision!=="approved"&&e.decision!=="rejected")throw new Error("Hosted approval decision is invalid");return{type:"approval",requestId:l(e.requestId,"action.requestId"),decision:e.decision,scopeHash:Ne(e.scopeHash,"action.scopeHash"),...e.rationale?{rationale:g(e.rationale,"action.rationale",4096)}:{}}}throw new Error("Hosted control action is invalid")}function Pe(e){let t;try{t=new URL(e.url)}catch{throw new Error("pullRequest.url is invalid")}if(t.protocol!=="https:"||t.username||t.password)throw new Error("pullRequest.url must be credential-free HTTPS");if(!Number.isSafeInteger(e.number)||e.number<1)throw new Error("pullRequest.number must be a positive integer");return{provider:l(e.provider,"pullRequest.provider"),repository:g(e.repository,"pullRequest.repository",2048),number:e.number,url:t.toString()}}function W(e,t){if(!Array.isArray(e)||e.length>1e4)throw new Error(`${t} is invalid`);return[...new Set(e.map((r,n)=>l(r,`${t}[${n}]`)))].sort()}function N(e,t){return g(e,t,512)}function l(e,t){let r=g(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(r))throw new Error(`${t} is invalid`);return r}function g(e,t,r){let n=e?.trim();if(!n||n.length>r||h(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function M(e,t){let r=Date.parse(e);if(!Number.isFinite(r)||new Date(r).toISOString()!==e)throw new Error(`${t} must be ISO-8601 UTC`);return e}function Ne(e,t){let r=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(r))throw new Error(`${t} must be a lowercase SHA-256 digest`);return r}function Y(e){return Re("sha256").update(w(e)).digest("hex")}function w(e){return u(e)}function _(e){let{hash:t,...r}=e;return r}export{Z as XENO_HOSTED_CONTROL_SCHEMA_VERSION,b as XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION,T as XENO_HOSTED_EVENT_SCHEMA_VERSION,H as XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA,ge as XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS,z as XENO_HOSTED_EXECUTION_ADAPTER_PROTOCOL_VERSION,ye as XENO_HOSTED_EXECUTION_PROTOCOL_VERSION,xe as XENO_HOSTED_EXECUTION_TOOL_NAMES,Q as XENO_HOSTED_RESULT_SCHEMA_VERSION,Me as XENO_HOSTED_RUN_SCHEMA_VERSION,De as XENO_HOSTED_TRIGGER_SCHEMA_VERSION,ut as assertValidXenoHostedExecutionJob,Ce as createXenoHostedControlCommand,Ue as createXenoHostedEnvironmentManifest,Je as createXenoHostedEvent,be as createXenoHostedExecutionBoundaryReceipt,Xe as createXenoHostedRunResult,Ge as deriveHostedIdempotencyKey,Ke as hostedEnvironmentIdentity,ht as normalizeXenoHostedControlAcknowledgement,ft as verifyXenoHostedControlCommand,A as verifyXenoHostedEnvironmentManifest,Fe as verifyXenoHostedEventChain,nt as verifyXenoHostedExecutionAdapterCertification,Ee as verifyXenoHostedExecutionJob,yt as verifyXenoHostedRunResult,Qe as verifyXenoHostedWebhook,rt as xenoHostedExecutionAdapterSigningPayload};
@@ -1 +1 @@
1
- {"inputs":{"src/hosted/types.ts":{"bytes":7060,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/hosted/protocol.ts":{"bytes":15483,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/hosted/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/hosted/webhook.ts":{"bytes":3148,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/hosted/execution-adapter.ts":{"bytes":8090,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"}],"format":"esm"},"src/types.ts":{"bytes":26059,"imports":[],"format":"esm"},"src/hosted/execution-job.ts":{"bytes":13830,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"../types.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/hosted/protocol.ts","kind":"import-statement","original":"./protocol.js"}],"format":"esm"},"src/hosted/control.ts":{"bytes":9553,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"}],"format":"esm"},"src/hosted/index.ts":{"bytes":195,"imports":[{"path":"src/hosted/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/hosted/protocol.ts","kind":"import-statement","original":"./protocol.js"},{"path":"src/hosted/webhook.ts","kind":"import-statement","original":"./webhook.js"},{"path":"src/hosted/execution-adapter.ts","kind":"import-statement","original":"./execution-adapter.js"},{"path":"src/hosted/execution-job.ts","kind":"import-statement","original":"./execution-job.js"},{"path":"src/hosted/control.ts","kind":"import-statement","original":"./control.js"}],"format":"esm"}},"outputs":{"dist/hosted/index.cjs":{"imports":[{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/hosted/index.ts","inputs":{"src/hosted/index.ts":{"bytesInOutput":1209},"src/hosted/types.ts":{"bytesInOutput":22},"src/hosted/protocol.ts":{"bytesInOutput":8148},"src/artifacts/hash.ts":{"bytesInOutput":559},"src/utils/text-security.ts":{"bytesInOutput":179},"src/hosted/webhook.ts":{"bytesInOutput":1462},"src/hosted/execution-adapter.ts":{"bytesInOutput":3660},"src/hosted/execution-job.ts":{"bytesInOutput":6598},"src/types.ts":{"bytesInOutput":116},"src/hosted/control.ts":{"bytesInOutput":4070}},"bytes":27461}}}
1
+ {"inputs":{"src/hosted/types.ts":{"bytes":7060,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/hosted/protocol.ts":{"bytes":15483,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/hosted/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/hosted/webhook.ts":{"bytes":3148,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/hosted/execution-adapter.ts":{"bytes":8090,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"}],"format":"esm"},"src/types.ts":{"bytes":26200,"imports":[],"format":"esm"},"src/hosted/execution-job.ts":{"bytes":13830,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"../types.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/hosted/protocol.ts","kind":"import-statement","original":"./protocol.js"}],"format":"esm"},"src/hosted/control.ts":{"bytes":9553,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"}],"format":"esm"},"src/hosted/index.ts":{"bytes":195,"imports":[{"path":"src/hosted/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/hosted/protocol.ts","kind":"import-statement","original":"./protocol.js"},{"path":"src/hosted/webhook.ts","kind":"import-statement","original":"./webhook.js"},{"path":"src/hosted/execution-adapter.ts","kind":"import-statement","original":"./execution-adapter.js"},{"path":"src/hosted/execution-job.ts","kind":"import-statement","original":"./execution-job.js"},{"path":"src/hosted/control.ts","kind":"import-statement","original":"./control.js"}],"format":"esm"}},"outputs":{"dist/hosted/index.cjs":{"imports":[{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true},{"path":"node:crypto","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/hosted/index.ts","inputs":{"src/hosted/index.ts":{"bytesInOutput":1209},"src/hosted/types.ts":{"bytesInOutput":22},"src/hosted/protocol.ts":{"bytesInOutput":8148},"src/artifacts/hash.ts":{"bytesInOutput":559},"src/utils/text-security.ts":{"bytesInOutput":179},"src/hosted/webhook.ts":{"bytesInOutput":1462},"src/hosted/execution-adapter.ts":{"bytesInOutput":3660},"src/hosted/execution-job.ts":{"bytesInOutput":6598},"src/types.ts":{"bytesInOutput":116},"src/hosted/control.ts":{"bytesInOutput":4070}},"bytes":27461}}}
@@ -1 +1 @@
1
- {"inputs":{"src/hosted/types.ts":{"bytes":7060,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/hosted/protocol.ts":{"bytes":15483,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/hosted/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/hosted/webhook.ts":{"bytes":3148,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/hosted/execution-adapter.ts":{"bytes":8090,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"}],"format":"esm"},"src/types.ts":{"bytes":26059,"imports":[],"format":"esm"},"src/hosted/execution-job.ts":{"bytes":13830,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"../types.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/hosted/protocol.ts","kind":"import-statement","original":"./protocol.js"}],"format":"esm"},"src/hosted/control.ts":{"bytes":9553,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"}],"format":"esm"},"src/hosted/index.ts":{"bytes":195,"imports":[{"path":"src/hosted/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/hosted/protocol.ts","kind":"import-statement","original":"./protocol.js"},{"path":"src/hosted/webhook.ts","kind":"import-statement","original":"./webhook.js"},{"path":"src/hosted/execution-adapter.ts","kind":"import-statement","original":"./execution-adapter.js"},{"path":"src/hosted/execution-job.ts","kind":"import-statement","original":"./execution-job.js"},{"path":"src/hosted/control.ts","kind":"import-statement","original":"./control.js"}],"format":"esm"}},"outputs":{"dist/hosted/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true}],"exports":["XENO_HOSTED_CONTROL_SCHEMA_VERSION","XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION","XENO_HOSTED_EVENT_SCHEMA_VERSION","XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA","XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS","XENO_HOSTED_EXECUTION_ADAPTER_PROTOCOL_VERSION","XENO_HOSTED_EXECUTION_PROTOCOL_VERSION","XENO_HOSTED_EXECUTION_TOOL_NAMES","XENO_HOSTED_RESULT_SCHEMA_VERSION","XENO_HOSTED_RUN_SCHEMA_VERSION","XENO_HOSTED_TRIGGER_SCHEMA_VERSION","assertValidXenoHostedExecutionJob","createXenoHostedControlCommand","createXenoHostedEnvironmentManifest","createXenoHostedEvent","createXenoHostedExecutionBoundaryReceipt","createXenoHostedRunResult","deriveHostedIdempotencyKey","hostedEnvironmentIdentity","normalizeXenoHostedControlAcknowledgement","verifyXenoHostedControlCommand","verifyXenoHostedEnvironmentManifest","verifyXenoHostedEventChain","verifyXenoHostedExecutionAdapterCertification","verifyXenoHostedExecutionJob","verifyXenoHostedRunResult","verifyXenoHostedWebhook","xenoHostedExecutionAdapterSigningPayload"],"entryPoint":"src/hosted/index.ts","inputs":{"src/hosted/types.ts":{"bytesInOutput":22},"src/hosted/index.ts":{"bytesInOutput":0},"src/hosted/protocol.ts":{"bytesInOutput":8134},"src/artifacts/hash.ts":{"bytesInOutput":559},"src/utils/text-security.ts":{"bytesInOutput":179},"src/hosted/webhook.ts":{"bytesInOutput":1435},"src/hosted/execution-adapter.ts":{"bytesInOutput":3664},"src/hosted/execution-job.ts":{"bytesInOutput":6590},"src/types.ts":{"bytesInOutput":116},"src/hosted/control.ts":{"bytesInOutput":4067}},"bytes":25916}}}
1
+ {"inputs":{"src/hosted/types.ts":{"bytes":7060,"imports":[],"format":"esm"},"src/artifacts/hash.ts":{"bytes":1489,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/utils/text-security.ts":{"bytes":809,"imports":[],"format":"esm"},"src/hosted/protocol.ts":{"bytes":15483,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"},{"path":"src/hosted/types.ts","kind":"import-statement","original":"./types.js"}],"format":"esm"},"src/hosted/webhook.ts":{"bytes":3148,"imports":[{"path":"node:crypto","kind":"import-statement","external":true}],"format":"esm"},"src/hosted/execution-adapter.ts":{"bytes":8090,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"}],"format":"esm"},"src/types.ts":{"bytes":26200,"imports":[],"format":"esm"},"src/hosted/execution-job.ts":{"bytes":13830,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"../types.js"},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/hosted/protocol.ts","kind":"import-statement","original":"./protocol.js"}],"format":"esm"},"src/hosted/control.ts":{"bytes":9553,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/artifacts/hash.ts","kind":"import-statement","original":"../artifacts/hash.js"},{"path":"src/utils/text-security.ts","kind":"import-statement","original":"../utils/text-security.js"}],"format":"esm"},"src/hosted/index.ts":{"bytes":195,"imports":[{"path":"src/hosted/types.ts","kind":"import-statement","original":"./types.js"},{"path":"src/hosted/protocol.ts","kind":"import-statement","original":"./protocol.js"},{"path":"src/hosted/webhook.ts","kind":"import-statement","original":"./webhook.js"},{"path":"src/hosted/execution-adapter.ts","kind":"import-statement","original":"./execution-adapter.js"},{"path":"src/hosted/execution-job.ts","kind":"import-statement","original":"./execution-job.js"},{"path":"src/hosted/control.ts","kind":"import-statement","original":"./control.js"}],"format":"esm"}},"outputs":{"dist/hosted/index.js":{"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true},{"path":"node:crypto","kind":"import-statement","external":true}],"exports":["XENO_HOSTED_CONTROL_SCHEMA_VERSION","XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION","XENO_HOSTED_EVENT_SCHEMA_VERSION","XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA","XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS","XENO_HOSTED_EXECUTION_ADAPTER_PROTOCOL_VERSION","XENO_HOSTED_EXECUTION_PROTOCOL_VERSION","XENO_HOSTED_EXECUTION_TOOL_NAMES","XENO_HOSTED_RESULT_SCHEMA_VERSION","XENO_HOSTED_RUN_SCHEMA_VERSION","XENO_HOSTED_TRIGGER_SCHEMA_VERSION","assertValidXenoHostedExecutionJob","createXenoHostedControlCommand","createXenoHostedEnvironmentManifest","createXenoHostedEvent","createXenoHostedExecutionBoundaryReceipt","createXenoHostedRunResult","deriveHostedIdempotencyKey","hostedEnvironmentIdentity","normalizeXenoHostedControlAcknowledgement","verifyXenoHostedControlCommand","verifyXenoHostedEnvironmentManifest","verifyXenoHostedEventChain","verifyXenoHostedExecutionAdapterCertification","verifyXenoHostedExecutionJob","verifyXenoHostedRunResult","verifyXenoHostedWebhook","xenoHostedExecutionAdapterSigningPayload"],"entryPoint":"src/hosted/index.ts","inputs":{"src/hosted/types.ts":{"bytesInOutput":22},"src/hosted/index.ts":{"bytesInOutput":0},"src/hosted/protocol.ts":{"bytesInOutput":8134},"src/artifacts/hash.ts":{"bytesInOutput":559},"src/utils/text-security.ts":{"bytesInOutput":179},"src/hosted/webhook.ts":{"bytesInOutput":1435},"src/hosted/execution-adapter.ts":{"bytesInOutput":3664},"src/hosted/execution-job.ts":{"bytesInOutput":6590},"src/types.ts":{"bytesInOutput":116},"src/hosted/control.ts":{"bytesInOutput":4067}},"bytes":25916}}}