@xenosystem/agent-sdk 0.10.31 → 0.10.33

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 (50) hide show
  1. package/README.md +1 -1
  2. package/dist/artifacts/index.cjs +1 -1
  3. package/dist/artifacts/index.js +1 -1
  4. package/dist/automation/index.cjs +1 -1
  5. package/dist/automation/index.d.cts +14 -0
  6. package/dist/automation/index.d.ts +14 -0
  7. package/dist/automation/index.js +1 -1
  8. package/dist/control-plane/index.cjs +1 -1
  9. package/dist/control-plane/index.js +1 -1
  10. package/dist/electron/index.cjs +211 -198
  11. package/dist/electron/index.d.cts +60 -5
  12. package/dist/electron/index.d.ts +60 -5
  13. package/dist/electron/index.js +211 -198
  14. package/dist/electron/metafile-cjs.json +1 -1
  15. package/dist/electron/metafile-esm.json +1 -1
  16. package/dist/governance/index.cjs +24 -24
  17. package/dist/governance/index.js +24 -24
  18. package/dist/governance/metafile-cjs.json +1 -1
  19. package/dist/governance/metafile-esm.json +1 -1
  20. package/dist/hooks/index.cjs +4 -4
  21. package/dist/hooks/index.d.cts +18 -0
  22. package/dist/hooks/index.d.ts +18 -0
  23. package/dist/hooks/index.js +4 -4
  24. package/dist/hooks/metafile-cjs.json +1 -1
  25. package/dist/hooks/metafile-esm.json +1 -1
  26. package/dist/hosted/index.cjs +1 -1
  27. package/dist/hosted/index.d.cts +21 -3
  28. package/dist/hosted/index.d.ts +21 -3
  29. package/dist/hosted/index.js +1 -1
  30. package/dist/hosted/metafile-cjs.json +1 -1
  31. package/dist/hosted/metafile-esm.json +1 -1
  32. package/dist/index.cjs +420 -384
  33. package/dist/index.d.cts +331 -30
  34. package/dist/index.d.ts +331 -30
  35. package/dist/index.js +422 -386
  36. package/dist/mcp/index.cjs +21 -21
  37. package/dist/mcp/index.d.cts +253 -186
  38. package/dist/mcp/index.d.ts +253 -186
  39. package/dist/mcp/index.js +21 -21
  40. package/dist/mcp/metafile-cjs.json +1 -1
  41. package/dist/mcp/metafile-esm.json +1 -1
  42. package/dist/metafile-cjs.json +1 -1
  43. package/dist/metafile-esm.json +1 -1
  44. package/dist/session/index.cjs +15 -15
  45. package/dist/session/index.js +12 -12
  46. package/dist/session/metafile-cjs.json +1 -1
  47. package/dist/session/metafile-esm.json +1 -1
  48. package/dist/skills/index.d.cts +14 -0
  49. package/dist/skills/index.d.ts +14 -0
  50. package/package.json +2 -2
@@ -1,9 +1,9 @@
1
- import{spawn as X}from"node:child_process";var q=3e4,Y=64*1024,Z=/(^|_)(TOKEN|SECRET|PASSWORD|PASS|KEY|CREDENTIAL|COOKIE|AUTH|AUTHORIZATION)(_|$)/i,Q=new Set(["PATH","Path","PATHEXT","SystemRoot","WINDIR","ComSpec","TMP","TEMP","HOME","USERPROFILE"]);function v(){return Date.now()}function U(e,o){return!Number.isFinite(e)||e===void 0?o:Math.max(1,Math.floor(e))}function j(e,o,t){if(Buffer.byteLength(e)>=t)return{value:e,truncated:!0};let n=e+o.toString("utf8");return Buffer.byteLength(n)<=t?{value:n,truncated:!1}:{value:Buffer.from(n,"utf8").subarray(0,t).toString("utf8"),truncated:!0}}function M(e){return e.replace(/\r\n/g,`
1
+ import{spawn as ie}from"node:child_process";import{spawn as Q,spawnSync as Re}from"node:child_process";var ee=5e3,$=128;function oe(e,o,t){let n={tool:e,timeoutMs:t};return o.timedOut?{...n,terminated:!1,reason:"timeout",exitCode:null,detail:`${e} did not finish within ${t}ms`}:o.error!==void 0?{...n,terminated:!1,reason:"spawn-error",exitCode:null,detail:o.error}:o.status===0?{...n,terminated:!0,reason:"terminated",exitCode:0}:e==="taskkill"&&o.status===$?{...n,terminated:!0,reason:"not-running",exitCode:$}:{...n,terminated:!1,reason:"failed",exitCode:o.status,detail:`${e} exited with code ${o.status??"unknown"}`}}var te=(e,o,t)=>new Promise(n=>{let r=!1,s={},u=a=>{r||(r=!0,s.timer&&clearTimeout(s.timer),n(a))},i;try{i=Q(e,[...o],{stdio:"ignore",windowsHide:!0})}catch(a){u({status:null,timedOut:!1,error:a instanceof Error?a.message:String(a)});return}s.timer=setTimeout(()=>{try{i.kill("SIGKILL")}catch{}u({status:null,timedOut:!0})},t),s.timer.unref?.(),i.once("error",a=>{u({status:null,timedOut:!1,error:a.code??a.message})}),i.once("close",a=>{u(a===null?{status:null,timedOut:!1,error:"no exit status"}:{status:a,timedOut:!1})})});function U(e){return typeof e=="number"&&Number.isFinite(e)&&e>0?Math.floor(e):ee}function ne(e,o){return{terminated:!1,reason:"failed",tool:e,exitCode:null,timeoutMs:o,detail:"pid is not a positive integer"}}function re(e){return["/PID",String(e),"/T","/F"]}async function F(e,o={}){let t=U(o.timeoutMs);return!Number.isSafeInteger(e)||e<=0?ne("taskkill",t):se("taskkill","taskkill.exe",re(e),{timeoutMs:t,run:o.run})}async function se(e,o,t,n={}){let r=U(n.timeoutMs),s;try{s=await(n.run??te)(o,t,r)}catch(u){s={status:null,timedOut:!1,error:u instanceof Error?u.message:String(u)}}return oe(e,s,r)}var ae=3e4,ue=64*1024,le=/(^|_)(TOKEN|SECRET|PASSWORD|PASS|KEY|CREDENTIAL|COOKIE|AUTH|AUTHORIZATION)(_|$)/i,ce=new Set(["PATH","Path","PATHEXT","SystemRoot","WINDIR","ComSpec","TMP","TEMP","HOME","USERPROFILE"]);function x(){return Date.now()}function J(e,o){return!Number.isFinite(e)||e===void 0?o:Math.max(1,Math.floor(e))}function j(e,o,t){if(Buffer.byteLength(e)>=t)return{value:e,truncated:!0};let n=e+o.toString("utf8");return Buffer.byteLength(n)<=t?{value:n,truncated:!1}:{value:Buffer.from(n,"utf8").subarray(0,t).toString("utf8"),truncated:!0}}function b(e){return e.replace(/\r\n/g,`
2
2
  `).split(`
3
- `).map(o=>o.trim()).find(o=>o.length>0)}function D(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new Error("Hook stdout JSON must be an object");let o=e,t=o.decision;if(t==="allow")return{decision:t,...typeof o.systemMessage=="string"?{systemMessage:o.systemMessage}:{},...typeof o.context=="string"?{context:o.context}:{}};if(t==="block"){let n=typeof o.reason=="string"&&o.reason.trim()?o.reason.trim():"Hook blocked the operation";return{decision:t,reason:n,...typeof o.systemMessage=="string"?{systemMessage:o.systemMessage}:{}}}if(t==="ask"){let n=typeof o.reason=="string"&&o.reason.trim()?o.reason.trim():"Hook requested user confirmation",r=typeof o.prompt=="string"&&o.prompt.trim()?o.prompt.trim():n;return{decision:t,reason:n,prompt:r}}if(t==="modify")return{decision:t,patch:o.patch,...typeof o.reason=="string"?{reason:o.reason}:{}};if(t==="continue")return{decision:t,...typeof o.context=="string"?{context:o.context}:{},...typeof o.systemMessage=="string"?{systemMessage:o.systemMessage}:{}};throw new Error(`Unsupported hook decision: ${String(t)}`)}function ee(e){let o=e.trim();if(o)return D(JSON.parse(o))}function F(e,o,t=process.env){let n={};for(let[r,s]of Object.entries(t))s!==void 0&&(!Q.has(r)&&Z.test(r)||(n[r]=s));for(let[r,s]of Object.entries(o.env??{}))n[r]=s;return n.XENO_PROJECT_DIR=e.cwd,n.XENO_SESSION_ID=e.sessionId,n.XENO_RUN_ID=e.runId,n.XENO_ROOT_RUN_ID=e.rootRunId,n.XENO_AGENT_ID=e.agentId,n.XENO_HOOK_EVENT=e.event,n.XENO_PERMISSION_MODE=e.permissionMode,n.XENO_MODEL=e.model,e.effort&&(n.XENO_EFFORT=e.effort),e.parentAgentId&&(n.XENO_PARENT_AGENT_ID=e.parentAgentId),e.transcriptPath&&(n.XENO_TRANSCRIPT_PATH=e.transcriptPath),n}function oe(e){if(process.platform==="win32"){X("taskkill",["/PID",String(e),"/T","/F"],{stdio:"ignore",windowsHide:!0}).on("error",()=>{});return}try{process.kill(-e,"SIGTERM")}catch{try{process.kill(e,"SIGTERM")}catch{return}}setTimeout(()=>{try{process.kill(-e,"SIGKILL")}catch{try{process.kill(e,"SIGKILL")}catch{}}},1e3).unref()}function H(e){return e?e.decision==="block"?"blocked":e.decision==="ask"?"asked":e.decision==="modify"?"modified":e.decision==="continue"?"continued":"allowed":"allowed"}async function E(e,o,t={}){let n=v(),r=U(e.timeoutMs??t.defaultTimeoutMs,q),s=U(e.maxOutputBytes??t.defaultMaxOutputBytes,Y),u=F(o,e,t.env),i=e.cwd??o.cwd;return new Promise(l=>{let a="",c="",p=!1,d=!1,k=!1,w=!1,y=X(e.command,e.args??[],{cwd:i,env:u,shell:e.shell??!1,detached:process.platform!=="win32",windowsHide:!0,stdio:["pipe","pipe","pipe"]}),O=f=>{w||(w=!0,clearTimeout(W),l(f))},W=setTimeout(()=>{k=!0,y.pid&&oe(y.pid)},r);y.stdout.on("data",f=>{let m=j(a,f,s);a=m.value,p=p||m.truncated}),y.stderr.on("data",f=>{let m=j(c,f,s);c=m.value,d=d||m.truncated}),y.on("error",f=>{let m=e.failClosed?{decision:"block",reason:`Hook command failed: ${f.message}`}:void 0;O({hook:e,status:m?H(m):"errored",...m?{decision:m}:{},stdout:a,stderr:c,stdoutTruncated:p,stderrTruncated:d,timedOut:k,durationMs:v()-n,error:f.message})}),y.on("close",(f,m)=>{if(k){let g=e.failClosed?{decision:"block",reason:`Hook timed out after ${r}ms`}:void 0;O({hook:e,status:g?H(g):"timed_out",...g?{decision:g}:{},exitCode:f,signal:m,stdout:a,stderr:c,stdoutTruncated:p,stderrTruncated:d,timedOut:k,durationMs:v()-n,error:`Hook timed out after ${r}ms`});return}let P,h;if(f===0)try{P=ee(a)}catch(g){h=g instanceof Error?g.message:String(g),e.failClosed&&(P={decision:"block",reason:`Invalid hook output: ${h}`})}else f===2?P={decision:"block",reason:M(a)??M(c)??"Hook blocked the operation"}:e.failClosed&&(P={decision:"block",reason:M(c)??`Hook exited with code ${f??"unknown"}`});O({hook:e,status:h&&!P?"errored":H(P),...P?{decision:P}:{},exitCode:f,signal:m,stdout:a,stderr:c,stdoutTruncated:p,stderrTruncated:d,timedOut:k,durationMs:v()-n,...h?{error:h}:{}})}),y.stdin.end(JSON.stringify(o))})}function te(e){return e.trim().toLowerCase().replace(/\.+$/,"")}function J(e,o){let t=te(o);if(!t)return!1;if(t==="*")return!0;if(t.startsWith("*.")){let n=t.slice(2);return e===n||e.endsWith(`.${n}`)}return e===t||e.endsWith(`.${t}`)}function z(e,o){let t;try{t=new URL(o).hostname.toLowerCase().replace(/\.+$/,"")}catch{return{decision:"deny",allowed:!1,hostname:null,matchedDomain:null,reason:"network policy denied malformed URL"}}let n=e.network.denyDomains.find(s=>J(t,s));if(n)return{decision:"deny",allowed:!1,hostname:t,matchedDomain:n,reason:`network policy denied ${t} by ${n}`};let r=e.network.allowDomains.find(s=>J(t,s));return r?{decision:"allow",allowed:!0,hostname:t,matchedDomain:r,reason:`network policy allowed ${t} by ${r}`}:{decision:e.network.default,allowed:e.network.default!=="deny",hostname:t,matchedDomain:null,reason:`network policy default ${e.network.default} for ${t}`}}var ne=3e4,re=64*1024;function b(){return Date.now()}function K(e,o){return!Number.isFinite(e)||e===void 0?o:Math.max(1,Math.floor(e))}function V(e,o,t){if(Buffer.byteLength(e)>=t)return{value:e,truncated:!0};let n=e+o.toString("utf8");return Buffer.byteLength(n)<=t?{value:n,truncated:!1}:{value:Buffer.from(n,"utf8").subarray(0,t).toString("utf8"),truncated:!0}}function se(e){return e.replace(/\r\n/g,`
3
+ `).map(o=>o.trim()).find(o=>o.length>0)}function E(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new Error("Hook stdout JSON must be an object");let o=e,t=o.decision;if(t==="allow")return{decision:t,...typeof o.systemMessage=="string"?{systemMessage:o.systemMessage}:{},...typeof o.context=="string"?{context:o.context}:{}};if(t==="block"){let n=typeof o.reason=="string"&&o.reason.trim()?o.reason.trim():"Hook blocked the operation";return{decision:t,reason:n,...typeof o.systemMessage=="string"?{systemMessage:o.systemMessage}:{}}}if(t==="ask"){let n=typeof o.reason=="string"&&o.reason.trim()?o.reason.trim():"Hook requested user confirmation",r=typeof o.prompt=="string"&&o.prompt.trim()?o.prompt.trim():n;return{decision:t,reason:n,prompt:r}}if(t==="modify")return{decision:t,patch:o.patch,...typeof o.reason=="string"?{reason:o.reason}:{}};if(t==="continue")return{decision:t,...typeof o.context=="string"?{context:o.context}:{},...typeof o.systemMessage=="string"?{systemMessage:o.systemMessage}:{}};throw new Error(`Unsupported hook decision: ${String(t)}`)}function de(e){let o=e.trim();if(o)return E(JSON.parse(o))}function z(e,o,t=process.env){let n={};for(let[r,s]of Object.entries(t))s!==void 0&&(!ce.has(r)&&le.test(r)||(n[r]=s));for(let[r,s]of Object.entries(o.env??{}))n[r]=s;return n.XENO_PROJECT_DIR=e.cwd,n.XENO_SESSION_ID=e.sessionId,n.XENO_RUN_ID=e.runId,n.XENO_ROOT_RUN_ID=e.rootRunId,n.XENO_AGENT_ID=e.agentId,n.XENO_HOOK_EVENT=e.event,n.XENO_PERMISSION_MODE=e.permissionMode,n.XENO_MODEL=e.model,e.effort&&(n.XENO_EFFORT=e.effort),e.parentAgentId&&(n.XENO_PARENT_AGENT_ID=e.parentAgentId),e.transcriptPath&&(n.XENO_TRANSCRIPT_PATH=e.transcriptPath),n}var me=5e3;function fe(e,o,t,n){if(process.platform==="win32"){F(o,{timeoutMs:me,run:n}).then(r=>{if(t(r),!r.terminated&&e.exitCode===null&&e.signalCode===null)try{e.kill("SIGKILL")}catch{}});return}try{process.kill(-o,"SIGTERM")}catch{try{process.kill(o,"SIGTERM")}catch{return}}setTimeout(()=>{try{process.kill(-o,"SIGKILL")}catch{try{process.kill(o,"SIGKILL")}catch{}}},1e3).unref()}function P(e){return e?e.decision==="block"?"blocked":e.decision==="ask"?"asked":e.decision==="modify"?"modified":e.decision==="continue"?"continued":"allowed":"allowed"}async function O(e,o,t={}){let n=x(),r=J(e.timeoutMs??t.defaultTimeoutMs,ae),s=J(e.maxOutputBytes??t.defaultMaxOutputBytes,ue),u=z(o,e,t.env),i=e.cwd??o.cwd;return new Promise(a=>{let l="",c="",p=!1,m=!1,k=!1,w=!1,h,H=ie(e.command,e.args??[],{cwd:i,env:u,shell:e.shell??!1,detached:process.platform!=="win32",windowsHide:!0,stdio:["pipe","pipe","pipe"]}),S=d=>{w||(w=!0,clearTimeout(Z),a(d))},Z=setTimeout(()=>{k=!0,H.pid&&fe(H,H.pid,d=>{h=d},t.processTreeKillRunner)},r);H.stdout.on("data",d=>{let f=j(l,d,s);l=f.value,p=p||f.truncated}),H.stderr.on("data",d=>{let f=j(c,d,s);c=f.value,m=m||f.truncated}),H.on("error",d=>{let f=e.failClosed?{decision:"block",reason:`Hook command failed: ${d.message}`}:void 0;S({hook:e,status:f?P(f):"errored",...f?{decision:f}:{},stdout:l,stderr:c,stdoutTruncated:p,stderrTruncated:m,timedOut:k,durationMs:x()-n,error:d.message})}),H.on("close",(d,f)=>{if(k){let y=e.failClosed?{decision:"block",reason:`Hook timed out after ${r}ms`}:void 0;S({hook:e,status:y?P(y):"timed_out",...y?{decision:y}:{},exitCode:d,signal:f,stdout:l,stderr:c,stdoutTruncated:p,stderrTruncated:m,timedOut:k,durationMs:x()-n,error:h&&!h.terminated?`Hook timed out after ${r}ms; its process tree was not terminated (${h.reason})`:`Hook timed out after ${r}ms`,...h?{processTreeKill:h}:{}});return}let g,T;if(d===0)try{g=de(l)}catch(y){T=y instanceof Error?y.message:String(y),e.failClosed&&(g={decision:"block",reason:`Invalid hook output: ${T}`})}else d===2?g={decision:"block",reason:b(l)??b(c)??"Hook blocked the operation"}:e.failClosed&&(g={decision:"block",reason:b(c)??`Hook exited with code ${d??"unknown"}`});S({hook:e,status:T&&!g?"errored":P(g),...g?{decision:g}:{},exitCode:d,signal:f,stdout:l,stderr:c,stdoutTruncated:p,stderrTruncated:m,timedOut:k,durationMs:x()-n,...T?{error:T}:{}})}),H.stdin.end(JSON.stringify(o))})}function pe(e){return e.trim().toLowerCase().replace(/\.+$/,"")}function V(e,o){let t=pe(o);if(!t)return!1;if(t==="*")return!0;if(t.startsWith("*.")){let n=t.slice(2);return e===n||e.endsWith(`.${n}`)}return e===t||e.endsWith(`.${t}`)}function W(e,o){let t;try{t=new URL(o).hostname.toLowerCase().replace(/\.+$/,"")}catch{return{decision:"deny",allowed:!1,hostname:null,matchedDomain:null,reason:"network policy denied malformed URL"}}let n=e.network.denyDomains.find(s=>V(t,s));if(n)return{decision:"deny",allowed:!1,hostname:t,matchedDomain:n,reason:`network policy denied ${t} by ${n}`};let r=e.network.allowDomains.find(s=>V(t,s));return r?{decision:"allow",allowed:!0,hostname:t,matchedDomain:r,reason:`network policy allowed ${t} by ${r}`}:{decision:e.network.default,allowed:e.network.default!=="deny",hostname:t,matchedDomain:null,reason:`network policy default ${e.network.default} for ${t}`}}var ke=3e4,Pe=64*1024;function M(){return Date.now()}function G(e,o){return!Number.isFinite(e)||e===void 0?o:Math.max(1,Math.floor(e))}function q(e,o,t){if(Buffer.byteLength(e)>=t)return{value:e,truncated:!0};let n=e+o.toString("utf8");return Buffer.byteLength(n)<=t?{value:n,truncated:!1}:{value:Buffer.from(n,"utf8").subarray(0,t).toString("utf8"),truncated:!0}}function He(e){return e.replace(/\r\n/g,`
4
4
  `).split(`
5
- `).map(o=>o.trim()).find(o=>o.length>0)}function ie(e){let o=e.trim();if(o)return D(JSON.parse(o))}async function ae(e,o){if(!e.body){let s=await e.text(),u=V("",Buffer.from(s,"utf8"),o);return{stdout:u.value,stdoutTruncated:u.truncated}}let t=e.body.getReader(),n="",r=!1;try{for(;;){let{done:s,value:u}=await t.read();if(s)break;let i=V(n,Buffer.from(u),o);if(n=i.value,r=r||i.truncated,r){await t.cancel();break}}}finally{t.releaseLock()}return{stdout:n,stdoutTruncated:r}}function ue(e,o){let t=new Headers(e.headers??{});return t.has("content-type")||t.set("content-type","application/json"),t.has("accept")||t.set("accept","application/json"),t.set("x-xeno-hook-event",o.event),t.set("x-xeno-session-id",o.sessionId),t.set("x-xeno-run-id",o.runId),t}function ce(e,o){if(!o.permissionProfile)return;let t=z(o.permissionProfile,e.url);if(!t.allowed)throw new Error(`HTTP hook network policy denied: ${t.reason}`)}async function x(e,o,t={}){let n=b(),r=K(e.timeoutMs??t.defaultTimeoutMs,ne),s=K(e.maxOutputBytes??t.defaultMaxOutputBytes,re),u=new AbortController,i=!1,l=setTimeout(()=>{i=!0,u.abort()},r);try{ce(e,t);let a=await fetch(e.url,{method:e.method??"POST",headers:ue(e,o),body:JSON.stringify(o),signal:u.signal}),{stdout:c,stdoutTruncated:p}=await ae(a,s),d,k;if(a.ok)try{d=ie(c)}catch(w){k=w instanceof Error?w.message:String(w),e.failClosed&&(d={decision:"block",reason:`Invalid HTTP hook output: ${k}`})}else e.failClosed&&(d={decision:"block",reason:se(c)??`HTTP hook failed with status ${a.status}`});return{hook:e,status:k&&!d?"errored":a.ok||d?H(d):"errored",...d?{decision:d}:{},stdout:c,stderr:"",stdoutTruncated:p,stderrTruncated:!1,timedOut:i,durationMs:b()-n,...a.ok?{}:{error:`HTTP ${a.status} ${a.statusText}`.trim()},...k?{error:k}:{}}}catch(a){let c=a instanceof Error?a.message:String(a),p=e.failClosed?{decision:"block",reason:i?`HTTP hook timed out after ${r}ms`:`HTTP hook failed: ${c}`}:void 0;return{hook:e,status:p?H(p):i?"timed_out":"errored",...p?{decision:p}:{},stdout:"",stderr:"",stdoutTruncated:!1,stderrTruncated:!1,timedOut:i,durationMs:b()-n,error:i?`HTTP hook timed out after ${r}ms`:c}}finally{clearTimeout(l)}}import{performance as T}from"node:perf_hooks";async function G(e,o,t,n){let r=T.now();if(!t){let i=`No ${e.type} hook executor is configured.`,l=e.failClosed?{decision:"block",reason:i}:void 0;return{hook:e,status:l?H(l):"errored",...l?{decision:l}:{},stdout:"",stderr:i,stdoutTruncated:!1,stderrTruncated:!1,timedOut:!1,durationMs:T.now()-r,error:i}}let s=Math.max(1,Math.trunc(e.timeoutMs??n.defaultTimeoutMs??3e4)),u;try{let i=await Promise.race([t(e,o),new Promise((l,a)=>{u=setTimeout(()=>a(new Error(`Hook timed out after ${s}ms`)),s),u.unref?.()})]);return{hook:e,status:H(i),decision:i,stdout:JSON.stringify(i),stderr:"",stdoutTruncated:!1,stderrTruncated:!1,timedOut:!1,durationMs:T.now()-r}}catch(i){let l=i instanceof Error?i.message:String(i),a=/timed out/i.test(l),c=e.failClosed?{decision:"block",reason:l}:void 0;return{hook:e,status:c?H(c):a?"timed_out":"errored",...c?{decision:c}:{},stdout:"",stderr:l,stdoutTruncated:!1,stderrTruncated:!1,timedOut:a,durationMs:T.now()-r,error:l}}finally{u&&clearTimeout(u)}}function R(e,o,t={}){return G(e,o,t.promptExecutor,t)}function I(e,o,t={}){return G(e,o,t.agentExecutor,t)}var S=class{constructor(o,t={}){this.executor=o;this.options=t}executor;options;run(o,t){return R(o,t,{...this.options,promptExecutor:this.executor})}},N=class{constructor(o,t={}){this.executor=o;this.options=t}executor;options;run(o,t){return I(o,t,{...this.options,agentExecutor:this.executor})}};function le(e,o){return!e.events||e.events.length===0||e.events.includes(o)}function de(e,o,t){e&&("context"in e&&typeof e.context=="string"&&e.context.trim()&&o.push(e.context.trim()),"systemMessage"in e&&typeof e.systemMessage=="string"&&e.systemMessage.trim()&&t.push(e.systemMessage.trim()))}function fe(e){return e&&(e.decision==="block"||e.decision==="ask"||e.decision==="modify")?e:null}async function _(e,o,t={}){switch(e.type){case"command":return E(e,o,t);case"http":return x(e,o,t);case"prompt":return R(e,o,t);case"agent":return I(e,o,t);default:throw new Error(`Unsupported hook type: ${String(e.type??"unknown")}`)}}async function B(e,o,t={}){let n=[],r=[],s=[];for(let u of e){if(!le(u,o.event))continue;if(u.async){_(u,o,t).catch(()=>{});continue}let i=await _(u,o,t);n.push(i),de(i.decision,r,s);let l=fe(i.decision);if(l)return{decision:l,results:n,context:r,systemMessages:s}}return{decision:r.length>0||s.length>0?{decision:"continue",...r.length>0?{context:r.join(`
5
+ `).map(o=>o.trim()).find(o=>o.length>0)}function ge(e){let o=e.trim();if(o)return E(JSON.parse(o))}async function ye(e,o){if(!e.body){let s=await e.text(),u=q("",Buffer.from(s,"utf8"),o);return{stdout:u.value,stdoutTruncated:u.truncated}}let t=e.body.getReader(),n="",r=!1;try{for(;;){let{done:s,value:u}=await t.read();if(s)break;let i=q(n,Buffer.from(u),o);if(n=i.value,r=r||i.truncated,r){await t.cancel();break}}}finally{t.releaseLock()}return{stdout:n,stdoutTruncated:r}}function we(e,o){let t=new Headers(e.headers??{});return t.has("content-type")||t.set("content-type","application/json"),t.has("accept")||t.set("accept","application/json"),t.set("x-xeno-hook-event",o.event),t.set("x-xeno-session-id",o.sessionId),t.set("x-xeno-run-id",o.runId),t}function he(e,o){if(!o.permissionProfile)return;let t=W(o.permissionProfile,e.url);if(!t.allowed)throw new Error(`HTTP hook network policy denied: ${t.reason}`)}async function R(e,o,t={}){let n=M(),r=G(e.timeoutMs??t.defaultTimeoutMs,ke),s=G(e.maxOutputBytes??t.defaultMaxOutputBytes,Pe),u=new AbortController,i=!1,a=setTimeout(()=>{i=!0,u.abort()},r);try{he(e,t);let l=await fetch(e.url,{method:e.method??"POST",headers:we(e,o),body:JSON.stringify(o),signal:u.signal}),{stdout:c,stdoutTruncated:p}=await ye(l,s),m,k;if(l.ok)try{m=ge(c)}catch(w){k=w instanceof Error?w.message:String(w),e.failClosed&&(m={decision:"block",reason:`Invalid HTTP hook output: ${k}`})}else e.failClosed&&(m={decision:"block",reason:He(c)??`HTTP hook failed with status ${l.status}`});return{hook:e,status:k&&!m?"errored":l.ok||m?P(m):"errored",...m?{decision:m}:{},stdout:c,stderr:"",stdoutTruncated:p,stderrTruncated:!1,timedOut:i,durationMs:M()-n,...l.ok?{}:{error:`HTTP ${l.status} ${l.statusText}`.trim()},...k?{error:k}:{}}}catch(l){let c=l instanceof Error?l.message:String(l),p=e.failClosed?{decision:"block",reason:i?`HTTP hook timed out after ${r}ms`:`HTTP hook failed: ${c}`}:void 0;return{hook:e,status:p?P(p):i?"timed_out":"errored",...p?{decision:p}:{},stdout:"",stderr:"",stdoutTruncated:!1,stderrTruncated:!1,timedOut:i,durationMs:M()-n,error:i?`HTTP hook timed out after ${r}ms`:c}}finally{clearTimeout(a)}}import{performance as v}from"node:perf_hooks";async function Y(e,o,t,n){let r=v.now();if(!t){let i=`No ${e.type} hook executor is configured.`,a=e.failClosed?{decision:"block",reason:i}:void 0;return{hook:e,status:a?P(a):"errored",...a?{decision:a}:{},stdout:"",stderr:i,stdoutTruncated:!1,stderrTruncated:!1,timedOut:!1,durationMs:v.now()-r,error:i}}let s=Math.max(1,Math.trunc(e.timeoutMs??n.defaultTimeoutMs??3e4)),u;try{let i=await Promise.race([t(e,o),new Promise((a,l)=>{u=setTimeout(()=>l(new Error(`Hook timed out after ${s}ms`)),s),u.unref?.()})]);return{hook:e,status:P(i),decision:i,stdout:JSON.stringify(i),stderr:"",stdoutTruncated:!1,stderrTruncated:!1,timedOut:!1,durationMs:v.now()-r}}catch(i){let a=i instanceof Error?i.message:String(i),l=/timed out/i.test(a),c=e.failClosed?{decision:"block",reason:a}:void 0;return{hook:e,status:c?P(c):l?"timed_out":"errored",...c?{decision:c}:{},stdout:"",stderr:a,stdoutTruncated:!1,stderrTruncated:!1,timedOut:l,durationMs:v.now()-r,error:a}}finally{u&&clearTimeout(u)}}function D(e,o,t={}){return Y(e,o,t.promptExecutor,t)}function I(e,o,t={}){return Y(e,o,t.agentExecutor,t)}var N=class{constructor(o,t={}){this.executor=o;this.options=t}executor;options;run(o,t){return D(o,t,{...this.options,promptExecutor:this.executor})}},_=class{constructor(o,t={}){this.executor=o;this.options=t}executor;options;run(o,t){return I(o,t,{...this.options,agentExecutor:this.executor})}};function Te(e,o){return!e.events||e.events.length===0||e.events.includes(o)}function xe(e,o,t){e&&("context"in e&&typeof e.context=="string"&&e.context.trim()&&o.push(e.context.trim()),"systemMessage"in e&&typeof e.systemMessage=="string"&&e.systemMessage.trim()&&t.push(e.systemMessage.trim()))}function Ee(e){return e&&(e.decision==="block"||e.decision==="ask"||e.decision==="modify")?e:null}async function X(e,o,t={}){switch(e.type){case"command":return O(e,o,t);case"http":return R(e,o,t);case"prompt":return D(e,o,t);case"agent":return I(e,o,t);default:throw new Error(`Unsupported hook type: ${String(e.type??"unknown")}`)}}async function L(e,o,t={}){let n=[],r=[],s=[];for(let u of e){if(!Te(u,o.event))continue;if(u.async){X(u,o,t).catch(()=>{});continue}let i=await X(u,o,t);n.push(i),xe(i.decision,r,s);let a=Ee(i.decision);if(a)return{decision:a,results:n,context:r,systemMessages:s}}return{decision:r.length>0||s.length>0?{decision:"continue",...r.length>0?{context:r.join(`
6
6
 
7
7
  `)}:{},...s.length>0?{systemMessage:s.join(`
8
8
 
9
- `)}:{}}:{decision:"allow"},results:n,context:r,systemMessages:s}}var A=class{constructor(o,t={}){this.hooks=o;this.options=t}hooks;options;run(o){return B(this.hooks,o,this.options)}},C=class{constructor(o,t={}){this.config=o;this.options=t}config;options;run(o){let t=[...this.config.hooks??[],...this.config.events?.[o.event]??[]];return B([...new Set(t)],o,this.options)}},$=class{constructor(o={}){this.options=o}options;run(o,t){return E(o,t,this.options)}},L=class{constructor(o={}){this.options=o}options;run(o,t){return x(o,t,this.options)}};export{N as AgentHookRunner,$ as CommandHookRunner,A as HookRunner,C as HookRuntime,L as HttpHookRunner,S as PromptHookRunner,F as buildHookEnvironment,H as hookResultStatus,D as normalizeHookDecision,I as runAgentHook,E as runCommandHook,_ as runHookDefinition,B as runHooks,x as runHttpHook,R as runPromptHook};
9
+ `)}:{}}:{decision:"allow"},results:n,context:r,systemMessages:s}}var C=class{constructor(o,t={}){this.hooks=o;this.options=t}hooks;options;run(o){return L(this.hooks,o,this.options)}},A=class{constructor(o,t={}){this.config=o;this.options=t}config;options;run(o){let t=[...this.config.hooks??[],...this.config.events?.[o.event]??[]];return L([...new Set(t)],o,this.options)}},K=class{constructor(o={}){this.options=o}options;run(o,t){return O(o,t,this.options)}},B=class{constructor(o={}){this.options=o}options;run(o,t){return R(o,t,this.options)}};export{_ as AgentHookRunner,K as CommandHookRunner,C as HookRunner,A as HookRuntime,B as HttpHookRunner,N as PromptHookRunner,z as buildHookEnvironment,P as hookResultStatus,E as normalizeHookDecision,I as runAgentHook,O as runCommandHook,X as runHookDefinition,L as runHooks,R as runHttpHook,D as runPromptHook};
@@ -1 +1 @@
1
- {"inputs":{"src/hooks/command-hook.ts":{"bytes":9737,"imports":[{"path":"node:child_process","kind":"import-statement","external":true}],"format":"esm"},"src/security/permission-profile.ts":{"bytes":7737,"imports":[],"format":"esm"},"src/hooks/http-hook.ts":{"bytes":6142,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/security/permission-profile.ts","kind":"import-statement","original":"../security/permission-profile.js"}],"format":"esm"},"src/hooks/model-hook.ts":{"bytes":3723,"imports":[{"path":"node:perf_hooks","kind":"import-statement","external":true},{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"}],"format":"esm"},"src/hooks/runner.ts":{"bytes":4318,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/hooks/http-hook.ts","kind":"import-statement","original":"./http-hook.js"},{"path":"src/hooks/model-hook.ts","kind":"import-statement","original":"./model-hook.js"}],"format":"esm"},"src/hooks/index.ts":{"bytes":813,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/hooks/http-hook.ts","kind":"import-statement","original":"./http-hook.js"},{"path":"src/hooks/model-hook.ts","kind":"import-statement","original":"./model-hook.js"},{"path":"src/hooks/runner.ts","kind":"import-statement","original":"./runner.js"}],"format":"esm"}},"outputs":{"dist/hooks/index.cjs":{"imports":[{"path":"node:child_process","kind":"require-call","external":true},{"path":"node:perf_hooks","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/hooks/index.ts","inputs":{"src/hooks/index.ts":{"bytesInOutput":361},"src/hooks/command-hook.ts":{"bytesInOutput":4530},"src/security/permission-profile.ts":{"bytesInOutput":902},"src/hooks/http-hook.ts":{"bytesInOutput":2575},"src/hooks/model-hook.ts":{"bytesInOutput":1468},"src/hooks/runner.ts":{"bytesInOutput":1584}},"bytes":12102}}}
1
+ {"inputs":{"src/runtime/process-tree-kill.ts":{"bytes":9124,"imports":[{"path":"node:child_process","kind":"import-statement","external":true}],"format":"esm"},"src/hooks/command-hook.ts":{"bytes":10829,"imports":[{"path":"node:child_process","kind":"import-statement","external":true},{"path":"src/runtime/process-tree-kill.ts","kind":"import-statement","original":"../runtime/process-tree-kill.js"}],"format":"esm"},"src/security/permission-profile.ts":{"bytes":7737,"imports":[],"format":"esm"},"src/hooks/http-hook.ts":{"bytes":6142,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/security/permission-profile.ts","kind":"import-statement","original":"../security/permission-profile.js"}],"format":"esm"},"src/hooks/model-hook.ts":{"bytes":3723,"imports":[{"path":"node:perf_hooks","kind":"import-statement","external":true},{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"}],"format":"esm"},"src/hooks/runner.ts":{"bytes":4318,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/hooks/http-hook.ts","kind":"import-statement","original":"./http-hook.js"},{"path":"src/hooks/model-hook.ts","kind":"import-statement","original":"./model-hook.js"}],"format":"esm"},"src/hooks/index.ts":{"bytes":813,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/hooks/http-hook.ts","kind":"import-statement","original":"./http-hook.js"},{"path":"src/hooks/model-hook.ts","kind":"import-statement","original":"./model-hook.js"},{"path":"src/hooks/runner.ts","kind":"import-statement","original":"./runner.js"}],"format":"esm"}},"outputs":{"dist/hooks/index.cjs":{"imports":[{"path":"node:child_process","kind":"require-call","external":true},{"path":"node:child_process","kind":"require-call","external":true},{"path":"node:perf_hooks","kind":"require-call","external":true}],"exports":[],"entryPoint":"src/hooks/index.ts","inputs":{"src/hooks/index.ts":{"bytesInOutput":361},"src/hooks/command-hook.ts":{"bytesInOutput":4741},"src/runtime/process-tree-kill.ts":{"bytesInOutput":1689},"src/security/permission-profile.ts":{"bytesInOutput":902},"src/hooks/http-hook.ts":{"bytesInOutput":2575},"src/hooks/model-hook.ts":{"bytesInOutput":1471},"src/hooks/runner.ts":{"bytesInOutput":1584}},"bytes":14011}}}
@@ -1 +1 @@
1
- {"inputs":{"src/hooks/command-hook.ts":{"bytes":9737,"imports":[{"path":"node:child_process","kind":"import-statement","external":true}],"format":"esm"},"src/security/permission-profile.ts":{"bytes":7737,"imports":[],"format":"esm"},"src/hooks/http-hook.ts":{"bytes":6142,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/security/permission-profile.ts","kind":"import-statement","original":"../security/permission-profile.js"}],"format":"esm"},"src/hooks/model-hook.ts":{"bytes":3723,"imports":[{"path":"node:perf_hooks","kind":"import-statement","external":true},{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"}],"format":"esm"},"src/hooks/runner.ts":{"bytes":4318,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/hooks/http-hook.ts","kind":"import-statement","original":"./http-hook.js"},{"path":"src/hooks/model-hook.ts","kind":"import-statement","original":"./model-hook.js"}],"format":"esm"},"src/hooks/index.ts":{"bytes":813,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/hooks/http-hook.ts","kind":"import-statement","original":"./http-hook.js"},{"path":"src/hooks/model-hook.ts","kind":"import-statement","original":"./model-hook.js"},{"path":"src/hooks/runner.ts","kind":"import-statement","original":"./runner.js"}],"format":"esm"}},"outputs":{"dist/hooks/index.js":{"imports":[{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:perf_hooks","kind":"import-statement","external":true}],"exports":["AgentHookRunner","CommandHookRunner","HookRunner","HookRuntime","HttpHookRunner","PromptHookRunner","buildHookEnvironment","hookResultStatus","normalizeHookDecision","runAgentHook","runCommandHook","runHookDefinition","runHooks","runHttpHook","runPromptHook"],"entryPoint":"src/hooks/index.ts","inputs":{"src/hooks/command-hook.ts":{"bytesInOutput":4513},"src/hooks/index.ts":{"bytesInOutput":0},"src/security/permission-profile.ts":{"bytesInOutput":902},"src/hooks/http-hook.ts":{"bytesInOutput":2575},"src/hooks/model-hook.ts":{"bytesInOutput":1433},"src/hooks/runner.ts":{"bytesInOutput":1584}},"bytes":11321}}}
1
+ {"inputs":{"src/runtime/process-tree-kill.ts":{"bytes":9124,"imports":[{"path":"node:child_process","kind":"import-statement","external":true}],"format":"esm"},"src/hooks/command-hook.ts":{"bytes":10829,"imports":[{"path":"node:child_process","kind":"import-statement","external":true},{"path":"src/runtime/process-tree-kill.ts","kind":"import-statement","original":"../runtime/process-tree-kill.js"}],"format":"esm"},"src/security/permission-profile.ts":{"bytes":7737,"imports":[],"format":"esm"},"src/hooks/http-hook.ts":{"bytes":6142,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/security/permission-profile.ts","kind":"import-statement","original":"../security/permission-profile.js"}],"format":"esm"},"src/hooks/model-hook.ts":{"bytes":3723,"imports":[{"path":"node:perf_hooks","kind":"import-statement","external":true},{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"}],"format":"esm"},"src/hooks/runner.ts":{"bytes":4318,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/hooks/http-hook.ts","kind":"import-statement","original":"./http-hook.js"},{"path":"src/hooks/model-hook.ts","kind":"import-statement","original":"./model-hook.js"}],"format":"esm"},"src/hooks/index.ts":{"bytes":813,"imports":[{"path":"src/hooks/command-hook.ts","kind":"import-statement","original":"./command-hook.js"},{"path":"src/hooks/http-hook.ts","kind":"import-statement","original":"./http-hook.js"},{"path":"src/hooks/model-hook.ts","kind":"import-statement","original":"./model-hook.js"},{"path":"src/hooks/runner.ts","kind":"import-statement","original":"./runner.js"}],"format":"esm"}},"outputs":{"dist/hooks/index.js":{"imports":[{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:child_process","kind":"import-statement","external":true},{"path":"node:perf_hooks","kind":"import-statement","external":true}],"exports":["AgentHookRunner","CommandHookRunner","HookRunner","HookRuntime","HttpHookRunner","PromptHookRunner","buildHookEnvironment","hookResultStatus","normalizeHookDecision","runAgentHook","runCommandHook","runHookDefinition","runHooks","runHttpHook","runPromptHook"],"entryPoint":"src/hooks/index.ts","inputs":{"src/hooks/command-hook.ts":{"bytesInOutput":4738},"src/runtime/process-tree-kill.ts":{"bytesInOutput":1706},"src/hooks/index.ts":{"bytesInOutput":0},"src/security/permission-profile.ts":{"bytesInOutput":902},"src/hooks/http-hook.ts":{"bytesInOutput":2575},"src/hooks/model-hook.ts":{"bytesInOutput":1433},"src/hooks/runner.ts":{"bytesInOutput":1584}},"bytes":13252}}}
@@ -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 Ge={};ge(Ge,{XENO_HOSTED_CONTROL_SCHEMA_VERSION:()=>q,XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION:()=>v,XENO_HOSTED_EVENT_SCHEMA_VERSION:()=>P,XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA:()=>w,XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS:()=>G,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(Ge);var v=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(ke(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:W(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:ve(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)=>Te(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:T(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:W(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:He(e.repository.commit,"repository.commit")}:{},...e.repository.subdirectory?{subdirectory:T(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:T(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:T(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 ke(e){let{checksum:t,...r}=e;return r}function S(e){return(0,x.createHash)("sha256").update(u(e)).digest("hex")}function ve(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 Te(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 W(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 T(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 He(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,G=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=H(t.executableSha256,"executableSha256"),s=H(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>G)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}`);H(e.adapter.executableSha256,"adapter.executableSha256"),H(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 H(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"),k(C(e))!==k(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"),k(C(e))!==k(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:We(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 We(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(k(e)).digest("hex")}function k(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
+ "use strict";var P=Object.defineProperty;var he=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var xe=Object.prototype.hasOwnProperty;var we=(e,t)=>{for(var n in t)P(e,n,{get:t[n],enumerable:!0})},be=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ye(t))!xe.call(e,o)&&o!==n&&P(e,o,{get:()=>t[o],enumerable:!(r=he(t,o))||r.enumerable});return e};var Ee=e=>be(P({},"__esModule",{value:!0}),e);var nt={};we(nt,{XENO_HOSTED_CONTROL_SCHEMA_VERSION:()=>j,XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION:()=>v,XENO_HOSTED_EVENT_SCHEMA_VERSION:()=>N,XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA:()=>w,XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS:()=>Q,XENO_HOSTED_EXECUTION_ADAPTER_PROTOCOL_VERSION:()=>D,XENO_HOSTED_EXECUTION_PROTOCOL_VERSION:()=>ie,XENO_HOSTED_EXECUTION_TOOL_NAMES:()=>ae,XENO_HOSTED_RESULT_SCHEMA_VERSION:()=>U,XENO_HOSTED_RUN_SCHEMA_VERSION:()=>ot,XENO_HOSTED_TRIGGER_SCHEMA_VERSION:()=>st,XenoHostedExecutionJobError:()=>C,assertValidXenoHostedExecutionJob:()=>Le,createXenoHostedControlCommand:()=>pe,createXenoHostedEnvironmentManifest:()=>ke,createXenoHostedEvent:()=>ve,createXenoHostedExecutionBoundaryReceipt:()=>ce,createXenoHostedRunResult:()=>ge,deriveHostedIdempotencyKey:()=>_e,hostedEnvironmentIdentity:()=>Te,hostedSlashCommandRefusal:()=>de,normalizeXenoHostedControlAcknowledgement:()=>Ze,verifyXenoHostedControlCommand:()=>We,verifyXenoHostedEnvironmentManifest:()=>T,verifyXenoHostedEventChain:()=>Se,verifyXenoHostedExecutionAdapterCertification:()=>Ve,verifyXenoHostedExecutionJob:()=>ue,verifyXenoHostedRunResult:()=>Qe,verifyXenoHostedWebhook:()=>Ne,xenoHostedExecutionAdapterSigningPayload:()=>De});module.exports=Ee(nt);var v=1,ot=1,N=1,st=1;var x=require("node:crypto");function l(e){return JSON.stringify(M(e,new Set))}function M(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 r=e.map(o=>M(o,t));return t.delete(e),r}let n={};for(let r of Object.keys(e).sort((o,s)=>o.localeCompare(s))){let o=e[r];if(o===void 0)throw new TypeError(`Artifact JSON property ${r} is undefined`);n[r]=M(o,t)}return t.delete(e),n}function y(e,t={}){for(let n of e){let r=n.codePointAt(0);if(r===127)return!0;if(!(r>31)&&!(r===9&&t.allowTab===!0)&&!((r===10||r===13)&&t.allowLineBreaks===!0))return!0}return!1}function ke(e){let t={...K(e),schemaVersion:1,kind:"xeno-hosted-environment"};return{...t,checksum:{algorithm:"sha256",value:_(t)}}}function T(e){let t=[];if(e?.schemaVersion!==1||e.kind!=="xeno-hosted-environment")return t.push("Unsupported hosted environment manifest"),{valid:!1,errors:t};let n;try{let{checksum:r,schemaVersion:o,kind:s,...i}=e;n={...K(i),schemaVersion:1,kind:"xeno-hosted-environment"}}catch(r){return t.push(r instanceof Error?r.message:String(r)),{valid:!1,errors:t}}return l(n)!==l(Re(e))&&t.push("Hosted environment manifest is not normalized"),(e.checksum?.algorithm!=="sha256"||e.checksum.value!==_(n))&&t.push("Hosted environment checksum mismatch"),{valid:t.length===0,errors:t}}function ve(e){let t=p(e.streamId,"streamId"),n=W(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!==n)throw new Error("Hosted event sequence must be contiguous")}else if(n!==1)throw new Error("The first hosted event sequence must be 1");let r={schemaVersion:1,kind:"xeno-hosted-event",eventId:p(e.eventId??`hevt_${(0,x.randomUUID)()}`,"eventId"),streamId:t,sequence:n,timestamp:Z(e.timestamp??new Date().toISOString(),"timestamp"),type:G(e.type,"type"),actorId:p(e.actorId,"actorId"),...e.idempotencyKey?{idempotencyKey:c(e.idempotencyKey,"idempotencyKey",512)}:{},payload:He(e.payload??{},"payload"),previousHash:e.previous?.hash??null};return{...r,hash:_(r)}}function Se(e,t){let n=[],r,o=t?t.afterSequence+1:1,s=t?.lastHash??null;for(let a of e){if(a.schemaVersion!==1||a.kind!=="xeno-hosted-event"){n.push(`Unsupported hosted event at sequence ${String(a.sequence)}`);continue}a.sequence!==o&&n.push(`Hosted event sequence gap at ${a.sequence}; expected ${o}`),a.previousHash!==s&&n.push(`Hosted event previous hash mismatch at ${a.sequence}`);let{hash:d,...f}=a;d!==_(f)&&n.push(`Hosted event hash mismatch at ${a.sequence}`),r&&r.streamId!==a.streamId&&n.push(`Hosted event stream changed at ${a.sequence}`),r=a,o=a.sequence+1,s=a.hash}let i=e.at(-1);return{valid:n.length===0,errors:n,cursor:i?{streamId:i.streamId,afterSequence:i.sequence,lastHash:i.hash}:t??null}}function Te(e){let t=T(e);if(!t.valid)throw new Error(t.errors.join("; "));return`${e.environmentId}@${e.revision}:${e.checksum.value}`}function _e(...e){if(e.length===0)throw new Error("At least one idempotency-key part is required");let t=e.map((n,r)=>Ie(n,`parts[${r}]`));return`xeno:${(0,x.createHash)("sha256").update(t.join("\0")).digest("hex")}`}function K(e){let t=e.secrets.map((o,s)=>({ref:p(o.ref,`secrets[${s}].ref`),target:o.target.kind==="environment"?{kind:"environment",name:Ce(o.target.name)}:{kind:"file",path:S(o.target.path,`secrets[${s}].target.path`)},required:!!o.required,exposeToChildProcesses:!!o.exposeToChildProcesses})),n=new Set,r=new Set;for(let o of t){if(n.has(o.ref))throw new Error(`Duplicate secret ref: ${o.ref}`);n.add(o.ref);let s=`${o.target.kind}:${o.target.kind==="environment"?o.target.name:o.target.path}`;if(r.has(s))throw new Error(`Duplicate secret target: ${s}`);r.add(s)}if(e.network.default!=="deny")throw new Error("Hosted network policy must be default-deny");return{environmentId:p(e.environmentId,"environmentId"),revision:W(e.revision,"revision"),createdAt:Z(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:Xe(e.repository.commit,"repository.commit")}:{},...e.repository.subdirectory?{subdirectory:S(e.repository.subdirectory,"repository.subdirectory")}:{},...e.repository.shallow!==void 0?{shallow:!!e.repository.shallow}:{}},image:{reference:c(e.image.reference,"image.reference",2048),digest:Oe(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:S(o.workingDirectory,`setup[${s}].workingDirectory`)}:{},timeoutMs:u(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:S(o.path,`caches[${s}].path`),...o.restoreKeys?.length?{restoreKeys:Pe(o.restoreKeys,`caches[${s}].restoreKeys`,512)}:{},...o.readOnly!==void 0?{readOnly:!!o.readOnly}:{},...o.maxBytes!==void 0?{maxBytes:u(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:Ae(o.host,`network.destinations[${s}].host`),...o.ports?.length?{ports:[...new Set(o.ports.map(i=>u(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:u(e.network.maxResponseBytes,"network.maxResponseBytes",1,Number.MAX_SAFE_INTEGER)}:{}},secrets:t,resources:{cpuMillis:u(e.resources.cpuMillis,"resources.cpuMillis",10,1e6),memoryBytes:u(e.resources.memoryBytes,"resources.memoryBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),diskBytes:u(e.resources.diskBytes,"resources.diskBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),processLimit:u(e.resources.processLimit,"resources.processLimit",1,65535),wallTimeMs:u(e.resources.wallTimeMs,"resources.wallTimeMs",1e3,10080*60*1e3)},retention:{workspaceTtlMs:u(e.retention.workspaceTtlMs,"retention.workspaceTtlMs",0,365*24*60*60*1e3),eventTtlMs:u(e.retention.eventTtlMs,"retention.eventTtlMs",6e4,365*24*60*60*1e3),artifactTtlMs:u(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])=>[G(o,"label key"),c(s,`labels.${o}`,500)]).sort(([o],[s])=>o.localeCompare(s)))}}function Re(e){let{checksum:t,...n}=e;return n}function _(e){return(0,x.createHash)("sha256").update(l(e)).digest("hex")}function He(e,t){let n=l(e);if(Buffer.byteLength(n,"utf8")>256*1024)throw new Error(`${t} exceeds 262144 bytes`);return JSON.parse(n)}function p(e,t){let n=c(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(n))throw new Error(`${t} is invalid`);return n}function G(e,t){let n=c(e,t,160);if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(n))throw new Error(`${t} is invalid`);return n}function c(e,t,n){let r=e.trim();if(!r||r.length>n||y(r,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return r}function Ie(e,t){let n=e.trim();if(n.length>4096||y(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function W(e,t){return u(e,t,1,Number.MAX_SAFE_INTEGER)}function u(e,t,n,r){if(!Number.isSafeInteger(e)||e<n||e>r)throw new Error(`${t} must be an integer between ${n} and ${r}`);return e}function Z(e,t){let n=Date.parse(e);if(!Number.isFinite(n)||new Date(n).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return e}function Ae(e,t){let n=c(e.toLowerCase(),t,253);if(n==="localhost"||/^(?:\d{1,3}\.){3}\d{1,3}$/.test(n)||n.includes(":")||!/^(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(n))throw new Error(`${t} must be a public DNS hostname or wildcard hostname`);return n}function S(e,t){let n=c(e.replaceAll("\\","/"),t,4096);if(n.startsWith("/")||/^[A-Za-z]:\//.test(n)||n.split("/").includes(".."))throw new Error(`${t} must be workspace-relative`);return n.replace(/^\.\//,"")}function Ce(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 Oe(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 Xe(e,t){return c(e,t,512)}function Pe(e,t,n){return[...new Set(e.map((r,o)=>c(r,`${t}[${o}]`,n)))]}var g=require("node:crypto");function Ne(e){let t=typeof e.body=="string"?Buffer.from(e.body,"utf8"):Buffer.from(e.body),n=(0,g.createHash)("sha256").update(t).digest("hex"),r=e.signature?.trim();if(!r)return{valid:!1,source:e.source,bodySha256:n,error:"missing-signature"};if(!e.secret||e.secret.length<16)throw new Error("Webhook secret must contain at least 16 characters");let o,s=r;if(e.source==="slack"){if(!e.timestamp||!/^\d+$/.test(e.timestamp))return{valid:!1,source:e.source,bodySha256:n,error:"invalid-timestamp"};let a=Number(e.timestamp)*1e3,d=Math.abs((e.now??new Date).getTime()-a);if(!Number.isFinite(a)||d>(e.maxClockSkewMs??5*6e4))return{valid:!1,source:e.source,bodySha256:n,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=Me(o,s);return{valid:i,source:e.source,bodySha256:n,...e.timestamp?{timestamp:e.timestamp}:{},...i?{}:{error:"invalid-signature"}}}function Me(e,t){let n=Buffer.from(e,"utf8"),r=Buffer.from(t,"utf8");return n.length===r.length&&(0,g.timingSafeEqual)(n,r)}var A=require("node:crypto");var w="xeno.hosted-execution-adapter-certification.v2",D=2,Q=744*60*60*1e3;function De(e){return Y(e),Buffer.from(V(e),"utf8")}function Ve(e,t){if(e?.schemaVersion!==w)throw new Error(`Hosted execution adapter certificate must use ${w}`);let{signature:n,...r}=e;if(Y(r),n?.algorithm!=="ed25519")throw new Error("Hosted execution adapter signature must use ed25519");let o=H(t.executableSha256,"executableSha256"),s=H(t.controlPlaneCandidateSha256,"controlPlaneCandidateSha256");if(r.adapter.executableSha256!==o)throw new Error("Hosted execution adapter executable does not match its signed certificate");if(r.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(r.platform.os!==i||r.platform.architecture!==a)throw new Error(`Hosted execution adapter certificate targets ${r.platform.os}-${r.platform.architecture}, not ${i}-${a}`);let d=I(r.issuedAt,"issuedAt"),f=I(r.expiresAt,"expiresAt"),J=(t.now??new Date).getTime();if(d>J+5*6e4)throw new Error("Hosted execution adapter certificate is not yet valid");if(f<=J)throw new Error("Hosted execution adapter certificate has expired");if(f<=d||f-d>Q)throw new Error("Hosted execution adapter certificate lifetime must be positive and at most 31 days");let F=t.trustedKeys[r.reviewer.keyId];if(!F)throw new Error(`Hosted execution adapter reviewer key is not trusted: ${r.reviewer.keyId}`);if(!(0,A.verify)(null,Buffer.from(V(r),"utf8"),F,$e(n.value,"signature.value")))throw new Error("Hosted execution adapter certificate signature is invalid");return{certificationId:r.certificationId,adapterName:r.adapter.name,adapterVersion:r.adapter.version,protocolVersion:r.adapter.protocolVersion,executableSha256:o,controlPlaneCandidateSha256:s,certificateSha256:(0,A.createHash)("sha256").update(V(e)).digest("hex"),expiresAt:r.expiresAt,reviewerKeyId:r.reviewer.keyId}}function Y(e){if(e.schemaVersion!==w)throw new Error(`Hosted execution adapter certificate must use ${w}`);if(R(e.certificationId,"certificationId"),R(e.adapter?.name,"adapter.name"),R(e.adapter?.version,"adapter.version"),e.adapter?.protocolVersion!==D)throw new Error(`Hosted execution adapter protocol must be ${D}`);H(e.adapter.executableSha256,"adapter.executableSha256"),H(e.controlPlaneCandidateSha256,"controlPlaneCandidateSha256"),R(e.reviewer?.keyId,"reviewer.keyId");let t=["immutableImages","filesystemIsolation","networkDefaultDeny","destinationAllowlist","secretProjection","nonRootExecution","readOnlyRoot","processTreeCleanup","resourceLimits","interactiveControl","artifactProtocol","gitResultReporting"];if(!e.capabilities||t.some(n=>e.capabilities[n]!==!0))throw new Error("Hosted execution adapter certificate does not attest every required containment capability");I(e.issuedAt,"issuedAt"),I(e.expiresAt,"expiresAt")}function V(e){return l(e)}function H(e,t){let n=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(n))throw new Error(`${t} must be a lowercase SHA-256 digest`);return n}function R(e,t){let n=e?.trim();if(!n||n.length>256||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(n))throw new Error(`${t} is invalid`);return n}function I(e,t){let n=Date.parse(e);if(!Number.isFinite(n)||new Date(n).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return n}function $e(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 n=Buffer.from(e,"base64");if(n.toString("base64")!==e)throw new Error(`${t} is not canonical base64`);return n}var se=require("node:crypto");var ee=["low","medium","high","xhigh","max"],te=["default","plan","acceptEdits","auto","dontAsk","bypassPermissions"];var Be=/^\/([A-Za-z][A-Za-z0-9_.:-]*)(?=\s|$)/,$="Nothing was sent to the model.",ne="unsupported_slash_command",yt=Object.freeze({"thread.run":"prompt","turn.start":"input","turn.steer":"input","schedule.create":"prompt","schedule.update":"prompt"});function re(e){let t=e.trimStart();if(t==="/"||/^\/\s/.test(t))return"";let n=Be.exec(t);return n?n[1].toLowerCase():null}var ie=2,ae=["Read","Write","Edit","Glob","Grep","WebFetch"],qe=new Set(ae);function ce(e){if(!le(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:oe({authority:e.authority.network,policy:e.environment.network}),secretProjectionSha256:oe(e.environment.secrets.filter(n=>t.has(n.ref))),filesystem:e.authority.filesystem,network:e.authority.network==="deny"?"deny":"allowlist",immutableImage:!0,readOnlyRoot:!0,nonRoot:!0,processTreeCleanup:!0,resourceLimits:!0,inferenceGateway:"brokered"}}var C=class extends Error{code="INVALID_HOSTED_EXECUTION_JOB";errors;reason;command;field;constructor(t){super(`Invalid hosted execution job: ${t.errors.join("; ")}`),this.name="XenoHostedExecutionJobError",this.errors=[...t.errors],t.slashCommand&&(this.reason=t.slashCommand.reason,this.command=t.slashCommand.command,this.field=t.slashCommand.field)}};function de(e){if(typeof e!="string")return null;let t=re(e);if(t===null)return null;let n={reason:ne,field:"prompt"};if(!t)return{...n,command:"/",message:`prompt begins with a bare "/"; a hosted job prompt is sent to the model as text and hosted execution runs no commands. Rephrase the prompt so it does not begin with "/". ${$}`};let r=`/${t}`;return{...n,command:r,message:`prompt is the slash command ${r}; a hosted job prompt is sent to the model as text and hosted execution runs no commands, so slash commands are refused. Rephrase the prompt so it does not begin with "${r}". ${$}`}}function ue(e){let t=[];if(!Ke(e))return{valid:!1,errors:["Hosted execution job must be an object"]};let n=e;if(n.protocolVersion!==ie||n.kind!=="xeno-hosted-execution-job")return t.push("Unsupported hosted execution protocol"),{valid:!1,errors:t};b(n.runId,"runId",t),b(n.userId,"userId",t),b(n.workspaceId,"workspaceId",t),B(n.workspaceHostPath,"workspaceHostPath",4096,t),B(n.prompt,"prompt",512*1024,t),B(n.model,"model",512,t),n.effort!==void 0&&!ee.includes(n.effort)&&t.push("effort is invalid"),te.includes(n.permissionMode)||t.push("permissionMode is invalid"),(typeof n.runScopedToken!="string"||!n.runScopedToken.startsWith("xrun_")||n.runScopedToken.length>16*1024)&&t.push("runScopedToken is not a bounded run-scoped token");let r;try{r=new URL(n.inferenceBaseUrl),(r.protocol!=="https:"||r.username||r.password||r.hash)&&t.push("inferenceBaseUrl must be credential-free HTTPS")}catch{t.push("inferenceBaseUrl is invalid")}let o=T(n.environment);t.push(...o.errors.map(a=>`environment: ${a}`)),n.environment?.workspaceId!==n.workspaceId&&t.push("environment workspace does not match the job"),n.environment?.image?.os!=="linux"&&t.push("hosted execution image must target Linux");let s=n.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"),je(n.authority,t),Ue(n.budget,n.environment,t),ze(n.allowedTools,t),Je(n,t),Fe(n,t),r&&!n.environment?.network?.destinations?.some(a=>{let d=a.ports?.length?a.ports:[443];return a.host.toLowerCase()===r.hostname.toLowerCase()&&d.includes(Number(r.port||443))})&&t.push("inference origin is absent from the environment network allowlist");try{let a=Ge(n.environment?.repository);n.environment?.network?.destinations?.some(d=>{let f=d.ports?.length?d.ports:[443];return d.host.toLowerCase()===a.hostname&&f.includes(a.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")}let i=de(n.prompt);return i?(t.push(i.message),{valid:!1,errors:t,slashCommand:i}):{valid:t.length===0,errors:t}}function Le(e){let t=ue(e);if(!t.valid)throw new C(t)}function je(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((n,r)=>b(n,`authority.secretRefs[${r}]`,t))}function Ue(e,t,n){(!e||!Number.isFinite(e.maxCredits)||e.maxCredits<=0)&&n.push("budget.maxCredits is invalid"),(!e||!q(e.maxDurationMs)||e.maxDurationMs>(t?.resources?.wallTimeMs??0))&&n.push("budget.maxDurationMs is invalid or exceeds the environment limit"),e?.maxTokens!==void 0&&!q(e.maxTokens)&&n.push("budget.maxTokens is invalid"),e?.maxToolCalls!==void 0&&!q(e.maxToolCalls)&&n.push("budget.maxToolCalls is invalid")}function ze(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((n,r)=>{b(n,`allowedTools[${r}]`,t),qe.has(n)||t.push(`allowedTools[${r}] is not in the hosted v0.1 registry`)})}function Je(e,t){if(!Array.isArray(e.secrets)||e.secrets.length>128){t.push("secrets must be a bounded array");return}let n=new Set(e.authority?.secretRefs??[]),r=new Map((e.environment?.secrets??[]).map(s=>[s.ref,s])),o=new Set;for(let[s,i]of e.secrets.entries()){let a=r.get(i.ref);if(!a||!n.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&&(!n.has(s.ref)||!o.has(s.ref))&&t.push(`required secret ${s.ref} is absent or unauthorized`);[...n].some(s=>!r.has(s))&&t.push("authority references an undeclared secret")}function Fe(e,t){let n=e.expectedBoundary;if(!n){t.push("expectedBoundary is missing");return}let r;try{r=ce({certificationId:n.certificationId,environment:e.environment,authority:e.authority})}catch{t.push("expectedBoundary does not match the hosted execution contract");return}(!le(n.certificationId)||E(n)!==E(r))&&t.push("expectedBoundary does not match the hosted execution contract")}function b(e,t,n){(typeof e!="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e))&&n.push(`${t} is invalid`)}function B(e,t,n,r){(typeof e!="string"||e.length<1||e.length>n||e.includes("\0"))&&r.push(`${t} is invalid`)}function q(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0}function le(e){return typeof e=="string"&&/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e)}function Ke(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function E(e){return l(e)}function oe(e){return(0,se.createHash)("sha256").update(E(e)).digest("hex")}function Ge(e){if(!e)throw new Error("repository source is missing");let t=e.repository.replace(/^\/+|\/+$/g,""),n=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,r=new URL(n);if(r.protocol!=="https:"||r.username||r.password||r.hash)throw new Error("repository origin is not credential-free HTTPS");return{hostname:r.hostname.toLowerCase(),port:Number(r.port||443)}}var X=require("node:crypto");var j=1,U=1;function pe(e){let t={schemaVersion:j,kind:"xeno-hosted-control",controlId:m(e.controlId??`hctl_${(0,X.randomUUID)()}`,"controlId"),runId:m(e.runId,"runId"),workspaceId:m(e.workspaceId,"workspaceId"),actorId:m(e.actorId,"actorId"),idempotencyKey:h(e.idempotencyKey,"idempotencyKey",512),createdAt:z(e.createdAt,"createdAt"),action:Ye(e.action)};return{...t,hash:{algorithm:"sha256",value:fe(t)}}}function We(e){let t=[];try{let{hash:n,schemaVersion:r,kind:o,...s}=e,i=pe(s);(e.schemaVersion!==j||e.kind!=="xeno-hosted-control")&&t.push("Unsupported hosted control command"),k(O(e))!==k(O(i))&&t.push("Hosted control command is not normalized"),(n?.algorithm!=="sha256"||n.value!==i.hash.value)&&t.push("Hosted control command hash mismatch")}catch(n){t.push(n instanceof Error?n.message:String(n))}return{valid:t.length===0,errors:t}}function Ze(e){if(!["accepted","applied","rejected","unsupported"].includes(e.status))throw new Error("Hosted control acknowledgement status is invalid");return{controlId:m(e.controlId,"controlId"),status:e.status,acknowledgedAt:z(e.acknowledgedAt,"acknowledgedAt"),...e.reason?{reason:h(e.reason,"reason",2048)}:{}}}function ge(e){let t=e.git?{...e.git.branch?{branch:L(e.git.branch,"git.branch")}:{},...e.git.baseRef?{baseRef:L(e.git.baseRef,"git.baseRef")}:{},...e.git.commit?{commit:L(e.git.commit,"git.commit")}:{}}:void 0,n={schemaVersion:U,kind:"xeno-hosted-run-result",runId:m(e.runId,"runId"),workspaceId:m(e.workspaceId,"workspaceId"),completedAt:z(e.completedAt,"completedAt"),...t&&Object.keys(t).length>0?{git:t}:{},...e.pullRequest?{pullRequest:et(e.pullRequest)}:{},artifactIds:me(e.artifactIds,"artifactIds"),evidenceArtifactIds:me(e.evidenceArtifactIds,"evidenceArtifactIds")};return{...n,hash:{algorithm:"sha256",value:fe(n)}}}function Qe(e){let t=[];try{let{hash:n,schemaVersion:r,kind:o,...s}=e,i=ge(s);(e.schemaVersion!==U||e.kind!=="xeno-hosted-run-result")&&t.push("Unsupported hosted run result"),k(O(e))!==k(O(i))&&t.push("Hosted run result is not normalized"),(n?.algorithm!=="sha256"||n.value!==i.hash.value)&&t.push("Hosted run result hash mismatch")}catch(n){t.push(n instanceof Error?n.message:String(n))}return{valid:t.length===0,errors:t}}function Ye(e){if(e?.type==="message")return{type:"message",message:h(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:m(e.requestId,"action.requestId"),decision:e.decision,scopeHash:tt(e.scopeHash,"action.scopeHash"),...e.rationale?{rationale:h(e.rationale,"action.rationale",4096)}:{}}}throw new Error("Hosted control action is invalid")}function et(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:m(e.provider,"pullRequest.provider"),repository:h(e.repository,"pullRequest.repository",2048),number:e.number,url:t.toString()}}function me(e,t){if(!Array.isArray(e)||e.length>1e4)throw new Error(`${t} is invalid`);return[...new Set(e.map((n,r)=>m(n,`${t}[${r}]`)))].sort()}function L(e,t){return h(e,t,512)}function m(e,t){let n=h(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(n))throw new Error(`${t} is invalid`);return n}function h(e,t,n){let r=e?.trim();if(!r||r.length>n||y(r,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return r}function z(e,t){let n=Date.parse(e);if(!Number.isFinite(n)||new Date(n).toISOString()!==e)throw new Error(`${t} must be ISO-8601 UTC`);return e}function tt(e,t){let n=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(n))throw new Error(`${t} must be a lowercase SHA-256 digest`);return n}function fe(e){return(0,X.createHash)("sha256").update(k(e)).digest("hex")}function k(e){return l(e)}function O(e){let{hash:t,...n}=e;return n}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,XenoHostedExecutionJobError,assertValidXenoHostedExecutionJob,createXenoHostedControlCommand,createXenoHostedEnvironmentManifest,createXenoHostedEvent,createXenoHostedExecutionBoundaryReceipt,createXenoHostedRunResult,deriveHostedIdempotencyKey,hostedEnvironmentIdentity,hostedSlashCommandRefusal,normalizeXenoHostedControlAcknowledgement,verifyXenoHostedControlCommand,verifyXenoHostedEnvironmentManifest,verifyXenoHostedEventChain,verifyXenoHostedExecutionAdapterCertification,verifyXenoHostedExecutionJob,verifyXenoHostedRunResult,verifyXenoHostedWebhook,xenoHostedExecutionAdapterSigningPayload});
@@ -353,6 +353,7 @@ interface XenoVerifiedHostedExecutionAdapterCertification {
353
353
  }
354
354
  declare function xenoHostedExecutionAdapterSigningPayload(certificate: Omit<XenoHostedExecutionAdapterCertification, "signature">): Buffer;
355
355
  declare function verifyXenoHostedExecutionAdapterCertification(certificate: XenoHostedExecutionAdapterCertification, options: XenoHostedExecutionAdapterVerificationOptions): XenoVerifiedHostedExecutionAdapterCertification;
356
+ declare const XENO_UNSUPPORTED_SLASH_COMMAND_REASON = "unsupported_slash_command";
356
357
  declare const XENO_HOSTED_EXECUTION_PROTOCOL_VERSION: 2;
357
358
  declare const XENO_HOSTED_EXECUTION_TOOL_NAMES: readonly [
358
359
  "Read",
@@ -408,10 +409,27 @@ declare function createXenoHostedExecutionBoundaryReceipt(options: {
408
409
  environment: XenoHostedEnvironmentManifest;
409
410
  authority: XenoHostedAuthority;
410
411
  }): XenoHostedExecutionBoundaryReceipt;
411
- declare function verifyXenoHostedExecutionJob(value: unknown): {
412
+ interface XenoHostedSlashCommandRefusal {
413
+ reason: typeof XENO_UNSUPPORTED_SLASH_COMMAND_REASON;
414
+ command: string;
415
+ field: "prompt";
416
+ message: string;
417
+ }
418
+ interface XenoHostedExecutionJobVerification {
412
419
  valid: boolean;
413
420
  errors: string[];
414
- };
421
+ slashCommand?: XenoHostedSlashCommandRefusal;
422
+ }
423
+ declare class XenoHostedExecutionJobError extends Error {
424
+ readonly code: "INVALID_HOSTED_EXECUTION_JOB";
425
+ readonly errors: readonly string[];
426
+ readonly reason?: typeof XENO_UNSUPPORTED_SLASH_COMMAND_REASON;
427
+ readonly command?: string;
428
+ readonly field?: "prompt";
429
+ constructor(verification: XenoHostedExecutionJobVerification);
430
+ }
431
+ declare function hostedSlashCommandRefusal(prompt: unknown): XenoHostedSlashCommandRefusal | null;
432
+ declare function verifyXenoHostedExecutionJob(value: unknown): XenoHostedExecutionJobVerification;
415
433
  declare function assertValidXenoHostedExecutionJob(value: unknown): asserts value is XenoHostedExecutionJob;
416
434
  declare const XENO_HOSTED_CONTROL_SCHEMA_VERSION: 1;
417
435
  declare const XENO_HOSTED_RESULT_SCHEMA_VERSION: 1;
@@ -487,4 +505,4 @@ declare function verifyXenoHostedRunResult(result: XenoHostedRunResult): {
487
505
  valid: boolean;
488
506
  errors: string[];
489
507
  };
490
- export { type VerifyXenoHostedWebhookOptions, 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, type XenoHostedArchitecture, type XenoHostedAuthority, type XenoHostedBudget, type XenoHostedCacheMount, type XenoHostedControlAcknowledgement, type XenoHostedControlAction, type XenoHostedControlCommand, type XenoHostedControlCommandPayload, type XenoHostedEnvironmentManifest, type XenoHostedEnvironmentManifestPayload, type XenoHostedEventRecord, type XenoHostedExecutionAdapterCertification, type XenoHostedExecutionAdapterVerificationOptions, type XenoHostedExecutionBoundaryReceipt, type XenoHostedExecutionJob, type XenoHostedExecutionSecretValue, type XenoHostedImageReference, type XenoHostedNetworkDestination, type XenoHostedNetworkPolicy, type XenoHostedOs, type XenoHostedQuotaLease, type XenoHostedReplayCursor, type XenoHostedReplayPage, type XenoHostedRepositorySource, type XenoHostedResourceLimits, type XenoHostedRetentionPolicy, type XenoHostedRunRecord, type XenoHostedRunRequest, type XenoHostedRunResult, type XenoHostedRunResultPayload, type XenoHostedRunStatus, type XenoHostedSecretProjection, type XenoHostedSetupStep, type XenoHostedTriggerDefinition, type XenoHostedTriggerDelivery, type XenoHostedTriggerKind, type XenoHostedWebhookSource, type XenoHostedWebhookVerification, type XenoVerifiedHostedExecutionAdapterCertification, assertValidXenoHostedExecutionJob, createXenoHostedControlCommand, createXenoHostedEnvironmentManifest, createXenoHostedEvent, createXenoHostedExecutionBoundaryReceipt, createXenoHostedRunResult, deriveHostedIdempotencyKey, hostedEnvironmentIdentity, normalizeXenoHostedControlAcknowledgement, verifyXenoHostedControlCommand, verifyXenoHostedEnvironmentManifest, verifyXenoHostedEventChain, verifyXenoHostedExecutionAdapterCertification, verifyXenoHostedExecutionJob, verifyXenoHostedRunResult, verifyXenoHostedWebhook, xenoHostedExecutionAdapterSigningPayload };
508
+ export { type VerifyXenoHostedWebhookOptions, 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, type XenoHostedArchitecture, type XenoHostedAuthority, type XenoHostedBudget, type XenoHostedCacheMount, type XenoHostedControlAcknowledgement, type XenoHostedControlAction, type XenoHostedControlCommand, type XenoHostedControlCommandPayload, type XenoHostedEnvironmentManifest, type XenoHostedEnvironmentManifestPayload, type XenoHostedEventRecord, type XenoHostedExecutionAdapterCertification, type XenoHostedExecutionAdapterVerificationOptions, type XenoHostedExecutionBoundaryReceipt, type XenoHostedExecutionJob, XenoHostedExecutionJobError, type XenoHostedExecutionJobVerification, type XenoHostedExecutionSecretValue, type XenoHostedImageReference, type XenoHostedNetworkDestination, type XenoHostedNetworkPolicy, type XenoHostedOs, type XenoHostedQuotaLease, type XenoHostedReplayCursor, type XenoHostedReplayPage, type XenoHostedRepositorySource, type XenoHostedResourceLimits, type XenoHostedRetentionPolicy, type XenoHostedRunRecord, type XenoHostedRunRequest, type XenoHostedRunResult, type XenoHostedRunResultPayload, type XenoHostedRunStatus, type XenoHostedSecretProjection, type XenoHostedSetupStep, type XenoHostedSlashCommandRefusal, type XenoHostedTriggerDefinition, type XenoHostedTriggerDelivery, type XenoHostedTriggerKind, type XenoHostedWebhookSource, type XenoHostedWebhookVerification, type XenoVerifiedHostedExecutionAdapterCertification, assertValidXenoHostedExecutionJob, createXenoHostedControlCommand, createXenoHostedEnvironmentManifest, createXenoHostedEvent, createXenoHostedExecutionBoundaryReceipt, createXenoHostedRunResult, deriveHostedIdempotencyKey, hostedEnvironmentIdentity, hostedSlashCommandRefusal, normalizeXenoHostedControlAcknowledgement, verifyXenoHostedControlCommand, verifyXenoHostedEnvironmentManifest, verifyXenoHostedEventChain, verifyXenoHostedExecutionAdapterCertification, verifyXenoHostedExecutionJob, verifyXenoHostedRunResult, verifyXenoHostedWebhook, xenoHostedExecutionAdapterSigningPayload };
@@ -353,6 +353,7 @@ interface XenoVerifiedHostedExecutionAdapterCertification {
353
353
  }
354
354
  declare function xenoHostedExecutionAdapterSigningPayload(certificate: Omit<XenoHostedExecutionAdapterCertification, "signature">): Buffer;
355
355
  declare function verifyXenoHostedExecutionAdapterCertification(certificate: XenoHostedExecutionAdapterCertification, options: XenoHostedExecutionAdapterVerificationOptions): XenoVerifiedHostedExecutionAdapterCertification;
356
+ declare const XENO_UNSUPPORTED_SLASH_COMMAND_REASON = "unsupported_slash_command";
356
357
  declare const XENO_HOSTED_EXECUTION_PROTOCOL_VERSION: 2;
357
358
  declare const XENO_HOSTED_EXECUTION_TOOL_NAMES: readonly [
358
359
  "Read",
@@ -408,10 +409,27 @@ declare function createXenoHostedExecutionBoundaryReceipt(options: {
408
409
  environment: XenoHostedEnvironmentManifest;
409
410
  authority: XenoHostedAuthority;
410
411
  }): XenoHostedExecutionBoundaryReceipt;
411
- declare function verifyXenoHostedExecutionJob(value: unknown): {
412
+ interface XenoHostedSlashCommandRefusal {
413
+ reason: typeof XENO_UNSUPPORTED_SLASH_COMMAND_REASON;
414
+ command: string;
415
+ field: "prompt";
416
+ message: string;
417
+ }
418
+ interface XenoHostedExecutionJobVerification {
412
419
  valid: boolean;
413
420
  errors: string[];
414
- };
421
+ slashCommand?: XenoHostedSlashCommandRefusal;
422
+ }
423
+ declare class XenoHostedExecutionJobError extends Error {
424
+ readonly code: "INVALID_HOSTED_EXECUTION_JOB";
425
+ readonly errors: readonly string[];
426
+ readonly reason?: typeof XENO_UNSUPPORTED_SLASH_COMMAND_REASON;
427
+ readonly command?: string;
428
+ readonly field?: "prompt";
429
+ constructor(verification: XenoHostedExecutionJobVerification);
430
+ }
431
+ declare function hostedSlashCommandRefusal(prompt: unknown): XenoHostedSlashCommandRefusal | null;
432
+ declare function verifyXenoHostedExecutionJob(value: unknown): XenoHostedExecutionJobVerification;
415
433
  declare function assertValidXenoHostedExecutionJob(value: unknown): asserts value is XenoHostedExecutionJob;
416
434
  declare const XENO_HOSTED_CONTROL_SCHEMA_VERSION: 1;
417
435
  declare const XENO_HOSTED_RESULT_SCHEMA_VERSION: 1;
@@ -487,4 +505,4 @@ declare function verifyXenoHostedRunResult(result: XenoHostedRunResult): {
487
505
  valid: boolean;
488
506
  errors: string[];
489
507
  };
490
- export { type VerifyXenoHostedWebhookOptions, 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, type XenoHostedArchitecture, type XenoHostedAuthority, type XenoHostedBudget, type XenoHostedCacheMount, type XenoHostedControlAcknowledgement, type XenoHostedControlAction, type XenoHostedControlCommand, type XenoHostedControlCommandPayload, type XenoHostedEnvironmentManifest, type XenoHostedEnvironmentManifestPayload, type XenoHostedEventRecord, type XenoHostedExecutionAdapterCertification, type XenoHostedExecutionAdapterVerificationOptions, type XenoHostedExecutionBoundaryReceipt, type XenoHostedExecutionJob, type XenoHostedExecutionSecretValue, type XenoHostedImageReference, type XenoHostedNetworkDestination, type XenoHostedNetworkPolicy, type XenoHostedOs, type XenoHostedQuotaLease, type XenoHostedReplayCursor, type XenoHostedReplayPage, type XenoHostedRepositorySource, type XenoHostedResourceLimits, type XenoHostedRetentionPolicy, type XenoHostedRunRecord, type XenoHostedRunRequest, type XenoHostedRunResult, type XenoHostedRunResultPayload, type XenoHostedRunStatus, type XenoHostedSecretProjection, type XenoHostedSetupStep, type XenoHostedTriggerDefinition, type XenoHostedTriggerDelivery, type XenoHostedTriggerKind, type XenoHostedWebhookSource, type XenoHostedWebhookVerification, type XenoVerifiedHostedExecutionAdapterCertification, assertValidXenoHostedExecutionJob, createXenoHostedControlCommand, createXenoHostedEnvironmentManifest, createXenoHostedEvent, createXenoHostedExecutionBoundaryReceipt, createXenoHostedRunResult, deriveHostedIdempotencyKey, hostedEnvironmentIdentity, normalizeXenoHostedControlAcknowledgement, verifyXenoHostedControlCommand, verifyXenoHostedEnvironmentManifest, verifyXenoHostedEventChain, verifyXenoHostedExecutionAdapterCertification, verifyXenoHostedExecutionJob, verifyXenoHostedRunResult, verifyXenoHostedWebhook, xenoHostedExecutionAdapterSigningPayload };
508
+ export { type VerifyXenoHostedWebhookOptions, 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, type XenoHostedArchitecture, type XenoHostedAuthority, type XenoHostedBudget, type XenoHostedCacheMount, type XenoHostedControlAcknowledgement, type XenoHostedControlAction, type XenoHostedControlCommand, type XenoHostedControlCommandPayload, type XenoHostedEnvironmentManifest, type XenoHostedEnvironmentManifestPayload, type XenoHostedEventRecord, type XenoHostedExecutionAdapterCertification, type XenoHostedExecutionAdapterVerificationOptions, type XenoHostedExecutionBoundaryReceipt, type XenoHostedExecutionJob, XenoHostedExecutionJobError, type XenoHostedExecutionJobVerification, type XenoHostedExecutionSecretValue, type XenoHostedImageReference, type XenoHostedNetworkDestination, type XenoHostedNetworkPolicy, type XenoHostedOs, type XenoHostedQuotaLease, type XenoHostedReplayCursor, type XenoHostedReplayPage, type XenoHostedRepositorySource, type XenoHostedResourceLimits, type XenoHostedRetentionPolicy, type XenoHostedRunRecord, type XenoHostedRunRequest, type XenoHostedRunResult, type XenoHostedRunResultPayload, type XenoHostedRunStatus, type XenoHostedSecretProjection, type XenoHostedSetupStep, type XenoHostedSlashCommandRefusal, type XenoHostedTriggerDefinition, type XenoHostedTriggerDelivery, type XenoHostedTriggerKind, type XenoHostedWebhookSource, type XenoHostedWebhookVerification, type XenoVerifiedHostedExecutionAdapterCertification, assertValidXenoHostedExecutionJob, createXenoHostedControlCommand, createXenoHostedEnvironmentManifest, createXenoHostedEvent, createXenoHostedExecutionBoundaryReceipt, createXenoHostedRunResult, deriveHostedIdempotencyKey, hostedEnvironmentIdentity, hostedSlashCommandRefusal, normalizeXenoHostedControlAcknowledgement, verifyXenoHostedControlCommand, verifyXenoHostedEnvironmentManifest, verifyXenoHostedEventChain, verifyXenoHostedExecutionAdapterCertification, verifyXenoHostedExecutionJob, verifyXenoHostedRunResult, verifyXenoHostedWebhook, xenoHostedExecutionAdapterSigningPayload };
@@ -1 +1 @@
1
- var b=1,Me=1,H=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:k(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!==k(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:k(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!==k(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 We(...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 k(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 T="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!==T)throw new Error(`Hosted execution adapter certificate must use ${T}`);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!==T)throw new Error(`Hosted execution adapter certificate must use ${T}`);if(v(e.certificationId,"certificationId"),v(e.adapter?.name,"adapter.name"),v(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"),v(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 v(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(!W(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"),ke(r.authority,t),ve(r.budget,r.environment,t),Te(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=He(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 ke(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 ve(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 Te(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}(!W(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 W(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 He(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:G(e.artifactIds,"artifactIds"),evidenceArtifactIds:G(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 G(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,H as XENO_HOSTED_EVENT_SCHEMA_VERSION,T 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,We 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,Le=1,H=1,je=1;import{createHash as q,randomUUID as oe}from"node:crypto";function l(e){return JSON.stringify(I(e,new Set))}function I(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 r=e.map(o=>I(o,t));return t.delete(e),r}let n={};for(let r of Object.keys(e).sort((o,s)=>o.localeCompare(s))){let o=e[r];if(o===void 0)throw new TypeError(`Artifact JSON property ${r} is undefined`);n[r]=I(o,t)}return t.delete(e),n}function h(e,t={}){for(let n of e){let r=n.codePointAt(0);if(r===127)return!0;if(!(r>31)&&!(r===9&&t.allowTab===!0)&&!((r===10||r===13)&&t.allowLineBreaks===!0))return!0}return!1}function Ze(e){let t={...L(e),schemaVersion:1,kind:"xeno-hosted-environment"};return{...t,checksum:{algorithm:"sha256",value:k(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 n;try{let{checksum:r,schemaVersion:o,kind:s,...i}=e;n={...L(i),schemaVersion:1,kind:"xeno-hosted-environment"}}catch(r){return t.push(r instanceof Error?r.message:String(r)),{valid:!1,errors:t}}return l(n)!==l(se(e))&&t.push("Hosted environment manifest is not normalized"),(e.checksum?.algorithm!=="sha256"||e.checksum.value!==k(n))&&t.push("Hosted environment checksum mismatch"),{valid:t.length===0,errors:t}}function Qe(e){let t=p(e.streamId,"streamId"),n=U(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!==n)throw new Error("Hosted event sequence must be contiguous")}else if(n!==1)throw new Error("The first hosted event sequence must be 1");let r={schemaVersion:1,kind:"xeno-hosted-event",eventId:p(e.eventId??`hevt_${oe()}`,"eventId"),streamId:t,sequence:n,timestamp:z(e.timestamp??new Date().toISOString(),"timestamp"),type:j(e.type,"type"),actorId:p(e.actorId,"actorId"),...e.idempotencyKey?{idempotencyKey:c(e.idempotencyKey,"idempotencyKey",512)}:{},payload:ie(e.payload??{},"payload"),previousHash:e.previous?.hash??null};return{...r,hash:k(r)}}function Ye(e,t){let n=[],r,o=t?t.afterSequence+1:1,s=t?.lastHash??null;for(let a of e){if(a.schemaVersion!==1||a.kind!=="xeno-hosted-event"){n.push(`Unsupported hosted event at sequence ${String(a.sequence)}`);continue}a.sequence!==o&&n.push(`Hosted event sequence gap at ${a.sequence}; expected ${o}`),a.previousHash!==s&&n.push(`Hosted event previous hash mismatch at ${a.sequence}`);let{hash:d,...g}=a;d!==k(g)&&n.push(`Hosted event hash mismatch at ${a.sequence}`),r&&r.streamId!==a.streamId&&n.push(`Hosted event stream changed at ${a.sequence}`),r=a,o=a.sequence+1,s=a.hash}let i=e.at(-1);return{valid:n.length===0,errors:n,cursor:i?{streamId:i.streamId,afterSequence:i.sequence,lastHash:i.hash}:t??null}}function et(e){let t=A(e);if(!t.valid)throw new Error(t.errors.join("; "));return`${e.environmentId}@${e.revision}:${e.checksum.value}`}function tt(...e){if(e.length===0)throw new Error("At least one idempotency-key part is required");let t=e.map((n,r)=>ae(n,`parts[${r}]`));return`xeno:${q("sha256").update(t.join("\0")).digest("hex")}`}function L(e){let t=e.secrets.map((o,s)=>({ref:p(o.ref,`secrets[${s}].ref`),target:o.target.kind==="environment"?{kind:"environment",name:de(o.target.name)}:{kind:"file",path:E(o.target.path,`secrets[${s}].target.path`)},required:!!o.required,exposeToChildProcesses:!!o.exposeToChildProcesses})),n=new Set,r=new Set;for(let o of t){if(n.has(o.ref))throw new Error(`Duplicate secret ref: ${o.ref}`);n.add(o.ref);let s=`${o.target.kind}:${o.target.kind==="environment"?o.target.name:o.target.path}`;if(r.has(s))throw new Error(`Duplicate secret target: ${s}`);r.add(s)}if(e.network.default!=="deny")throw new Error("Hosted network policy must be default-deny");return{environmentId:p(e.environmentId,"environmentId"),revision:U(e.revision,"revision"),createdAt:z(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:le(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:ue(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:u(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:me(o.restoreKeys,`caches[${s}].restoreKeys`,512)}:{},...o.readOnly!==void 0?{readOnly:!!o.readOnly}:{},...o.maxBytes!==void 0?{maxBytes:u(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:ce(o.host,`network.destinations[${s}].host`),...o.ports?.length?{ports:[...new Set(o.ports.map(i=>u(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:u(e.network.maxResponseBytes,"network.maxResponseBytes",1,Number.MAX_SAFE_INTEGER)}:{}},secrets:t,resources:{cpuMillis:u(e.resources.cpuMillis,"resources.cpuMillis",10,1e6),memoryBytes:u(e.resources.memoryBytes,"resources.memoryBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),diskBytes:u(e.resources.diskBytes,"resources.diskBytes",16*1024*1024,Number.MAX_SAFE_INTEGER),processLimit:u(e.resources.processLimit,"resources.processLimit",1,65535),wallTimeMs:u(e.resources.wallTimeMs,"resources.wallTimeMs",1e3,10080*60*1e3)},retention:{workspaceTtlMs:u(e.retention.workspaceTtlMs,"retention.workspaceTtlMs",0,365*24*60*60*1e3),eventTtlMs:u(e.retention.eventTtlMs,"retention.eventTtlMs",6e4,365*24*60*60*1e3),artifactTtlMs:u(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])=>[j(o,"label key"),c(s,`labels.${o}`,500)]).sort(([o],[s])=>o.localeCompare(s)))}}function se(e){let{checksum:t,...n}=e;return n}function k(e){return q("sha256").update(l(e)).digest("hex")}function ie(e,t){let n=l(e);if(Buffer.byteLength(n,"utf8")>256*1024)throw new Error(`${t} exceeds 262144 bytes`);return JSON.parse(n)}function p(e,t){let n=c(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(n))throw new Error(`${t} is invalid`);return n}function j(e,t){let n=c(e,t,160);if(!/^[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(n))throw new Error(`${t} is invalid`);return n}function c(e,t,n){let r=e.trim();if(!r||r.length>n||h(r,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return r}function ae(e,t){let n=e.trim();if(n.length>4096||h(n,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return n}function U(e,t){return u(e,t,1,Number.MAX_SAFE_INTEGER)}function u(e,t,n,r){if(!Number.isSafeInteger(e)||e<n||e>r)throw new Error(`${t} must be an integer between ${n} and ${r}`);return e}function z(e,t){let n=Date.parse(e);if(!Number.isFinite(n)||new Date(n).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return e}function ce(e,t){let n=c(e.toLowerCase(),t,253);if(n==="localhost"||/^(?:\d{1,3}\.){3}\d{1,3}$/.test(n)||n.includes(":")||!/^(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(n))throw new Error(`${t} must be a public DNS hostname or wildcard hostname`);return n}function E(e,t){let n=c(e.replaceAll("\\","/"),t,4096);if(n.startsWith("/")||/^[A-Za-z]:\//.test(n)||n.split("/").includes(".."))throw new Error(`${t} must be workspace-relative`);return n.replace(/^\.\//,"")}function de(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 ue(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 le(e,t){return c(e,t,512)}function me(e,t,n){return[...new Set(e.map((r,o)=>c(r,`${t}[${o}]`,n)))]}import{createHash as pe,createHmac as C,timingSafeEqual as ge}from"node:crypto";function ot(e){let t=typeof e.body=="string"?Buffer.from(e.body,"utf8"):Buffer.from(e.body),n=pe("sha256").update(t).digest("hex"),r=e.signature?.trim();if(!r)return{valid:!1,source:e.source,bodySha256:n,error:"missing-signature"};if(!e.secret||e.secret.length<16)throw new Error("Webhook secret must contain at least 16 characters");let o,s=r;if(e.source==="slack"){if(!e.timestamp||!/^\d+$/.test(e.timestamp))return{valid:!1,source:e.source,bodySha256:n,error:"invalid-timestamp"};let a=Number(e.timestamp)*1e3,d=Math.abs((e.now??new Date).getTime()-a);if(!Number.isFinite(a)||d>(e.maxClockSkewMs??5*6e4))return{valid:!1,source:e.source,bodySha256:n,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=fe(o,s);return{valid:i,source:e.source,bodySha256:n,...e.timestamp?{timestamp:e.timestamp}:{},...i?{}:{error:"invalid-signature"}}}function fe(e,t){let n=Buffer.from(e,"utf8"),r=Buffer.from(t,"utf8");return n.length===r.length&&ge(n,r)}import{createHash as he,verify as ye}from"node:crypto";var S="xeno.hosted-execution-adapter-certification.v2",J=2,xe=744*60*60*1e3;function ct(e){return F(e),Buffer.from(O(e),"utf8")}function dt(e,t){if(e?.schemaVersion!==S)throw new Error(`Hosted execution adapter certificate must use ${S}`);let{signature:n,...r}=e;if(F(r),n?.algorithm!=="ed25519")throw new Error("Hosted execution adapter signature must use ed25519");let o=T(t.executableSha256,"executableSha256"),s=T(t.controlPlaneCandidateSha256,"controlPlaneCandidateSha256");if(r.adapter.executableSha256!==o)throw new Error("Hosted execution adapter executable does not match its signed certificate");if(r.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(r.platform.os!==i||r.platform.architecture!==a)throw new Error(`Hosted execution adapter certificate targets ${r.platform.os}-${r.platform.architecture}, not ${i}-${a}`);let d=_(r.issuedAt,"issuedAt"),g=_(r.expiresAt,"expiresAt"),$=(t.now??new Date).getTime();if(d>$+5*6e4)throw new Error("Hosted execution adapter certificate is not yet valid");if(g<=$)throw new Error("Hosted execution adapter certificate has expired");if(g<=d||g-d>xe)throw new Error("Hosted execution adapter certificate lifetime must be positive and at most 31 days");let B=t.trustedKeys[r.reviewer.keyId];if(!B)throw new Error(`Hosted execution adapter reviewer key is not trusted: ${r.reviewer.keyId}`);if(!ye(null,Buffer.from(O(r),"utf8"),B,we(n.value,"signature.value")))throw new Error("Hosted execution adapter certificate signature is invalid");return{certificationId:r.certificationId,adapterName:r.adapter.name,adapterVersion:r.adapter.version,protocolVersion:r.adapter.protocolVersion,executableSha256:o,controlPlaneCandidateSha256:s,certificateSha256:he("sha256").update(O(e)).digest("hex"),expiresAt:r.expiresAt,reviewerKeyId:r.reviewer.keyId}}function F(e){if(e.schemaVersion!==S)throw new Error(`Hosted execution adapter certificate must use ${S}`);if(v(e.certificationId,"certificationId"),v(e.adapter?.name,"adapter.name"),v(e.adapter?.version,"adapter.version"),e.adapter?.protocolVersion!==J)throw new Error(`Hosted execution adapter protocol must be ${J}`);T(e.adapter.executableSha256,"adapter.executableSha256"),T(e.controlPlaneCandidateSha256,"controlPlaneCandidateSha256"),v(e.reviewer?.keyId,"reviewer.keyId");let t=["immutableImages","filesystemIsolation","networkDefaultDeny","destinationAllowlist","secretProjection","nonRootExecution","readOnlyRoot","processTreeCleanup","resourceLimits","interactiveControl","artifactProtocol","gitResultReporting"];if(!e.capabilities||t.some(n=>e.capabilities[n]!==!0))throw new Error("Hosted execution adapter certificate does not attest every required containment capability");_(e.issuedAt,"issuedAt"),_(e.expiresAt,"expiresAt")}function O(e){return l(e)}function T(e,t){let n=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(n))throw new Error(`${t} must be a lowercase SHA-256 digest`);return n}function v(e,t){let n=e?.trim();if(!n||n.length>256||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(n))throw new Error(`${t} is invalid`);return n}function _(e,t){let n=Date.parse(e);if(!Number.isFinite(n)||new Date(n).toISOString()!==e)throw new Error(`${t} must be an ISO-8601 UTC timestamp`);return n}function we(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 n=Buffer.from(e,"base64");if(n.toString("base64")!==e)throw new Error(`${t} is not canonical base64`);return n}import{createHash as Ee}from"node:crypto";var K=["low","medium","high","xhigh","max"],G=["default","plan","acceptEdits","auto","dontAsk","bypassPermissions"];var be=/^\/([A-Za-z][A-Za-z0-9_.:-]*)(?=\s|$)/,X="Nothing was sent to the model.",W="unsupported_slash_command",mt=Object.freeze({"thread.run":"prompt","turn.start":"input","turn.steer":"input","schedule.create":"prompt","schedule.update":"prompt"});function Z(e){let t=e.trimStart();if(t==="/"||/^\/\s/.test(t))return"";let n=be.exec(t);return n?n[1].toLowerCase():null}var ke=2,ve=["Read","Write","Edit","Glob","Grep","WebFetch"],Se=new Set(ve);function Te(e){if(!Y(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:Q({authority:e.authority.network,policy:e.environment.network}),secretProjectionSha256:Q(e.environment.secrets.filter(n=>t.has(n.ref))),filesystem:e.authority.filesystem,network:e.authority.network==="deny"?"deny":"allowlist",immutableImage:!0,readOnlyRoot:!0,nonRoot:!0,processTreeCleanup:!0,resourceLimits:!0,inferenceGateway:"brokered"}}var M=class extends Error{code="INVALID_HOSTED_EXECUTION_JOB";errors;reason;command;field;constructor(t){super(`Invalid hosted execution job: ${t.errors.join("; ")}`),this.name="XenoHostedExecutionJobError",this.errors=[...t.errors],t.slashCommand&&(this.reason=t.slashCommand.reason,this.command=t.slashCommand.command,this.field=t.slashCommand.field)}};function _e(e){if(typeof e!="string")return null;let t=Z(e);if(t===null)return null;let n={reason:W,field:"prompt"};if(!t)return{...n,command:"/",message:`prompt begins with a bare "/"; a hosted job prompt is sent to the model as text and hosted execution runs no commands. Rephrase the prompt so it does not begin with "/". ${X}`};let r=`/${t}`;return{...n,command:r,message:`prompt is the slash command ${r}; a hosted job prompt is sent to the model as text and hosted execution runs no commands, so slash commands are refused. Rephrase the prompt so it does not begin with "${r}". ${X}`}}function Re(e){let t=[];if(!Xe(e))return{valid:!1,errors:["Hosted execution job must be an object"]};let n=e;if(n.protocolVersion!==ke||n.kind!=="xeno-hosted-execution-job")return t.push("Unsupported hosted execution protocol"),{valid:!1,errors:t};y(n.runId,"runId",t),y(n.userId,"userId",t),y(n.workspaceId,"workspaceId",t),P(n.workspaceHostPath,"workspaceHostPath",4096,t),P(n.prompt,"prompt",512*1024,t),P(n.model,"model",512,t),n.effort!==void 0&&!K.includes(n.effort)&&t.push("effort is invalid"),G.includes(n.permissionMode)||t.push("permissionMode is invalid"),(typeof n.runScopedToken!="string"||!n.runScopedToken.startsWith("xrun_")||n.runScopedToken.length>16*1024)&&t.push("runScopedToken is not a bounded run-scoped token");let r;try{r=new URL(n.inferenceBaseUrl),(r.protocol!=="https:"||r.username||r.password||r.hash)&&t.push("inferenceBaseUrl must be credential-free HTTPS")}catch{t.push("inferenceBaseUrl is invalid")}let o=A(n.environment);t.push(...o.errors.map(a=>`environment: ${a}`)),n.environment?.workspaceId!==n.workspaceId&&t.push("environment workspace does not match the job"),n.environment?.image?.os!=="linux"&&t.push("hosted execution image must target Linux");let s=n.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"),He(n.authority,t),Ie(n.budget,n.environment,t),Ae(n.allowedTools,t),Ce(n,t),Oe(n,t),r&&!n.environment?.network?.destinations?.some(a=>{let d=a.ports?.length?a.ports:[443];return a.host.toLowerCase()===r.hostname.toLowerCase()&&d.includes(Number(r.port||443))})&&t.push("inference origin is absent from the environment network allowlist");try{let a=Pe(n.environment?.repository);n.environment?.network?.destinations?.some(d=>{let g=d.ports?.length?d.ports:[443];return d.host.toLowerCase()===a.hostname&&g.includes(a.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")}let i=_e(n.prompt);return i?(t.push(i.message),{valid:!1,errors:t,slashCommand:i}):{valid:t.length===0,errors:t}}function wt(e){let t=Re(e);if(!t.valid)throw new M(t)}function He(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((n,r)=>y(n,`authority.secretRefs[${r}]`,t))}function Ie(e,t,n){(!e||!Number.isFinite(e.maxCredits)||e.maxCredits<=0)&&n.push("budget.maxCredits is invalid"),(!e||!N(e.maxDurationMs)||e.maxDurationMs>(t?.resources?.wallTimeMs??0))&&n.push("budget.maxDurationMs is invalid or exceeds the environment limit"),e?.maxTokens!==void 0&&!N(e.maxTokens)&&n.push("budget.maxTokens is invalid"),e?.maxToolCalls!==void 0&&!N(e.maxToolCalls)&&n.push("budget.maxToolCalls is invalid")}function Ae(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((n,r)=>{y(n,`allowedTools[${r}]`,t),Se.has(n)||t.push(`allowedTools[${r}] is not in the hosted v0.1 registry`)})}function Ce(e,t){if(!Array.isArray(e.secrets)||e.secrets.length>128){t.push("secrets must be a bounded array");return}let n=new Set(e.authority?.secretRefs??[]),r=new Map((e.environment?.secrets??[]).map(s=>[s.ref,s])),o=new Set;for(let[s,i]of e.secrets.entries()){let a=r.get(i.ref);if(!a||!n.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&&(!n.has(s.ref)||!o.has(s.ref))&&t.push(`required secret ${s.ref} is absent or unauthorized`);[...n].some(s=>!r.has(s))&&t.push("authority references an undeclared secret")}function Oe(e,t){let n=e.expectedBoundary;if(!n){t.push("expectedBoundary is missing");return}let r;try{r=Te({certificationId:n.certificationId,environment:e.environment,authority:e.authority})}catch{t.push("expectedBoundary does not match the hosted execution contract");return}(!Y(n.certificationId)||x(n)!==x(r))&&t.push("expectedBoundary does not match the hosted execution contract")}function y(e,t,n){(typeof e!="string"||!/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e))&&n.push(`${t} is invalid`)}function P(e,t,n,r){(typeof e!="string"||e.length<1||e.length>n||e.includes("\0"))&&r.push(`${t} is invalid`)}function N(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>0}function Y(e){return typeof e=="string"&&/^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,511}$/.test(e)}function Xe(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function x(e){return l(e)}function Q(e){return Ee("sha256").update(x(e)).digest("hex")}function Pe(e){if(!e)throw new Error("repository source is missing");let t=e.repository.replace(/^\/+|\/+$/g,""),n=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,r=new URL(n);if(r.protocol!=="https:"||r.username||r.password||r.hash)throw new Error("repository origin is not credential-free HTTPS");return{hostname:r.hostname.toLowerCase(),port:Number(r.port||443)}}import{createHash as Ne,randomUUID as Me}from"node:crypto";var te=1,ne=1;function De(e){let t={schemaVersion:te,kind:"xeno-hosted-control",controlId:m(e.controlId??`hctl_${Me()}`,"controlId"),runId:m(e.runId,"runId"),workspaceId:m(e.workspaceId,"workspaceId"),actorId:m(e.actorId,"actorId"),idempotencyKey:f(e.idempotencyKey,"idempotencyKey",512),createdAt:V(e.createdAt,"createdAt"),action:$e(e.action)};return{...t,hash:{algorithm:"sha256",value:re(t)}}}function St(e){let t=[];try{let{hash:n,schemaVersion:r,kind:o,...s}=e,i=De(s);(e.schemaVersion!==te||e.kind!=="xeno-hosted-control")&&t.push("Unsupported hosted control command"),w(R(e))!==w(R(i))&&t.push("Hosted control command is not normalized"),(n?.algorithm!=="sha256"||n.value!==i.hash.value)&&t.push("Hosted control command hash mismatch")}catch(n){t.push(n instanceof Error?n.message:String(n))}return{valid:t.length===0,errors:t}}function Tt(e){if(!["accepted","applied","rejected","unsupported"].includes(e.status))throw new Error("Hosted control acknowledgement status is invalid");return{controlId:m(e.controlId,"controlId"),status:e.status,acknowledgedAt:V(e.acknowledgedAt,"acknowledgedAt"),...e.reason?{reason:f(e.reason,"reason",2048)}:{}}}function Ve(e){let t=e.git?{...e.git.branch?{branch:D(e.git.branch,"git.branch")}:{},...e.git.baseRef?{baseRef:D(e.git.baseRef,"git.baseRef")}:{},...e.git.commit?{commit:D(e.git.commit,"git.commit")}:{}}:void 0,n={schemaVersion:ne,kind:"xeno-hosted-run-result",runId:m(e.runId,"runId"),workspaceId:m(e.workspaceId,"workspaceId"),completedAt:V(e.completedAt,"completedAt"),...t&&Object.keys(t).length>0?{git:t}:{},...e.pullRequest?{pullRequest:Be(e.pullRequest)}:{},artifactIds:ee(e.artifactIds,"artifactIds"),evidenceArtifactIds:ee(e.evidenceArtifactIds,"evidenceArtifactIds")};return{...n,hash:{algorithm:"sha256",value:re(n)}}}function _t(e){let t=[];try{let{hash:n,schemaVersion:r,kind:o,...s}=e,i=Ve(s);(e.schemaVersion!==ne||e.kind!=="xeno-hosted-run-result")&&t.push("Unsupported hosted run result"),w(R(e))!==w(R(i))&&t.push("Hosted run result is not normalized"),(n?.algorithm!=="sha256"||n.value!==i.hash.value)&&t.push("Hosted run result hash mismatch")}catch(n){t.push(n instanceof Error?n.message:String(n))}return{valid:t.length===0,errors:t}}function $e(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:m(e.requestId,"action.requestId"),decision:e.decision,scopeHash:qe(e.scopeHash,"action.scopeHash"),...e.rationale?{rationale:f(e.rationale,"action.rationale",4096)}:{}}}throw new Error("Hosted control action is invalid")}function Be(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:m(e.provider,"pullRequest.provider"),repository:f(e.repository,"pullRequest.repository",2048),number:e.number,url:t.toString()}}function ee(e,t){if(!Array.isArray(e)||e.length>1e4)throw new Error(`${t} is invalid`);return[...new Set(e.map((n,r)=>m(n,`${t}[${r}]`)))].sort()}function D(e,t){return f(e,t,512)}function m(e,t){let n=f(e,t,512);if(!/^[A-Za-z0-9][A-Za-z0-9._:@/-]*$/.test(n))throw new Error(`${t} is invalid`);return n}function f(e,t,n){let r=e?.trim();if(!r||r.length>n||h(r,{allowTab:!0,allowLineBreaks:!0}))throw new Error(`${t} is invalid`);return r}function V(e,t){let n=Date.parse(e);if(!Number.isFinite(n)||new Date(n).toISOString()!==e)throw new Error(`${t} must be ISO-8601 UTC`);return e}function qe(e,t){let n=e?.trim().toLowerCase();if(!/^[a-f0-9]{64}$/.test(n))throw new Error(`${t} must be a lowercase SHA-256 digest`);return n}function re(e){return Ne("sha256").update(w(e)).digest("hex")}function w(e){return l(e)}function R(e){let{hash:t,...n}=e;return n}export{te as XENO_HOSTED_CONTROL_SCHEMA_VERSION,b as XENO_HOSTED_ENVIRONMENT_SCHEMA_VERSION,H as XENO_HOSTED_EVENT_SCHEMA_VERSION,S as XENO_HOSTED_EXECUTION_ADAPTER_CERTIFICATION_SCHEMA,xe as XENO_HOSTED_EXECUTION_ADAPTER_MAX_CERTIFICATE_LIFETIME_MS,J as XENO_HOSTED_EXECUTION_ADAPTER_PROTOCOL_VERSION,ke as XENO_HOSTED_EXECUTION_PROTOCOL_VERSION,ve as XENO_HOSTED_EXECUTION_TOOL_NAMES,ne as XENO_HOSTED_RESULT_SCHEMA_VERSION,Le as XENO_HOSTED_RUN_SCHEMA_VERSION,je as XENO_HOSTED_TRIGGER_SCHEMA_VERSION,M as XenoHostedExecutionJobError,wt as assertValidXenoHostedExecutionJob,De as createXenoHostedControlCommand,Ze as createXenoHostedEnvironmentManifest,Qe as createXenoHostedEvent,Te as createXenoHostedExecutionBoundaryReceipt,Ve as createXenoHostedRunResult,tt as deriveHostedIdempotencyKey,et as hostedEnvironmentIdentity,_e as hostedSlashCommandRefusal,Tt as normalizeXenoHostedControlAcknowledgement,St as verifyXenoHostedControlCommand,A as verifyXenoHostedEnvironmentManifest,Ye as verifyXenoHostedEventChain,dt as verifyXenoHostedExecutionAdapterCertification,Re as verifyXenoHostedExecutionJob,_t as verifyXenoHostedRunResult,ot as verifyXenoHostedWebhook,ct 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":32150,"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":35541,"imports":[],"format":"esm"},"src/app-server/slash-input-guard.ts":{"bytes":5502,"imports":[],"format":"esm"},"src/hosted/execution-job.ts":{"bytes":17643,"imports":[{"path":"node:crypto","kind":"import-statement","external":true},{"path":"src/types.ts","kind":"import-statement","original":"../types.js"},{"path":"src/app-server/slash-input-guard.ts","kind":"import-statement","original":"../app-server/slash-input-guard.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":1276},"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":7568},"src/types.ts":{"bytesInOutput":118},"src/app-server/slash-input-guard.ts":{"bytesInOutput":373},"src/hosted/control.ts":{"bytesInOutput":4070}},"bytes":28927}}}