@autodevjapan/godd-mcp-alpha 3.9.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/native/godd-native-aarch64-apple-darwin +0 -0
- package/assets/native/godd-native-aarch64-apple-darwin.sha256 +1 -1
- package/assets/native/godd-native-x86_64-apple-darwin +0 -0
- package/assets/native/godd-native-x86_64-apple-darwin.sha256 +1 -1
- package/assets/native/godd-native-x86_64-pc-windows-msvc.exe +0 -0
- package/assets/native/godd-native-x86_64-pc-windows-msvc.exe.sha256 +1 -1
- package/assets/native/godd-native-x86_64-unknown-linux-musl +0 -0
- package/assets/native/godd-native-x86_64-unknown-linux-musl.sha256 +1 -1
- package/dist/compile-cache-runtime.cjs +4 -4
- package/dist/godd.cjs +24 -24
- package/native-assets.json +12 -12
- package/package.json +5 -5
- package/scripts/native-assets.js +5 -5
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
386f45f7c54a7d95db666a689c9d13db033065497082a1066aa9c5cab98fa454
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3a30595a8e27b8d79317f48efb331b97812a593b4c9f31692ac05dfef14b2c03
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
7a9d7ac8508391743fec45b08cf08072af407c05935cf0481fa58e7abeab7182
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
c79919dec7bf1a1653bed40d02b6a9dd8e397ab65f496d2c787d73bc64578475
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var B=Object.defineProperty;var
|
|
1
|
+
"use strict";var B=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var De=Object.prototype.hasOwnProperty;var ve=(t,e)=>{for(var r in e)B(t,r,{get:e[r],enumerable:!0})},Ie=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Ne(e))!De.call(t,o)&&o!==r&&B(t,o,{get:()=>e[o],enumerable:!(n=be(e,o))||n.enumerable});return t};var we=t=>Ie(B({},"__esModule",{value:!0}),t);var at={};ve(at,{CompileCacheRejectedError:()=>v,CompileCacheRuntime:()=>oe,CompileCacheRuntimeError:()=>p,createNdjsonCompileCacheEvaluator:()=>Te,spawnCompileCacheEvaluator:()=>it});module.exports=we(at);var Oe=require("node:child_process");var U={schemaVersion:3,releaseTag:"godd-native-v0.2.63",expectedVersion:"godd-native 0.2.63",sourceCommit:"6f10c8402b427ba857f4aedc1d85f40259a5e608",capabilities:["autonomy","cobol-evidence","codec-capability","compile-cache","content-generation","gateway-operations","mcp-stdio","operate","peer-summary","plan-audit","research"],handshakeProtocol:{supportedProtocolMajors:[1],minimumProtocolMinorByMajor:{"1":1}},capabilityCatalogDigest:"7fd64d8c567f76c32bb18711a8a0aa616df842da10d0e5ca4685a878fd68fb3d",routedCommands:["autonomy","codec-capability","compile-cache","content-generation","dataset-coverage","evidence-cobol","gateway-operations","godd-a-dir","learn-skill","managed-gitignore","operate","peer-summary","plan-audit","realtime-admission","realtime-admission-dev","research","shard-partition","test-evidence"],routedCommandEntryDigests:{autonomy:"9968e855a0dfbb8c861b41a9ef77c07b6bef6021e2b519098882a66c533df17f","codec-capability":"c42a0a334e7744fd47c040c2e5c09dff624eee02fbea1cd01a721f35b57520bd","compile-cache":"cd4949c86b20fa19a8ca83646424e2f2ab15a2b652c343c8b443b697c6fdc539","content-generation":"e4c5e1731fa9f3439e62a19a1d4c9cb21efdc28162731e51116a194cf6bf4b4f","dataset-coverage":"31be076baa2b47e7851adbd42d0885d3a6f902b56133ea3384991772df66a88b","evidence-cobol":"086ee7120c4db890b9e2de627fc00b2c843939b07e014553f2549ad219203f8b","gateway-operations":"97218eff67bfb58c600ee4988b3e1dcf7071fe15f0a9acdcf94fdb885e1d1a2f","godd-a-dir":"7810bf4642150849d45f6031cb4bfe7e8834c4000356d77e3f7d2f0e8f9dd1aa","learn-skill":"e8cb2f1bf1fe59cfa4ed2cee070ff753c8f2595e91f9eadf2f43d64812793f43","managed-gitignore":"487b7167c4f4d7691b105e550c1e06c71113a434258c4f8525b90a86f75db73e",operate:"2f619fe4b46c760b966bc1890f0380b048958fc70d27c79e3df38df79405170a","peer-summary":"b0f612e5b5c5f90c9a97486a5bdac22999dd21a609ccbf2e5431351a52c2d3c3","plan-audit":"9bc81d0ac70c62917cbd0d8c6b9723428c4a170e8fb48165e1fa64ced768a28c","realtime-admission":"200468566f677d5b82d1ef2d9ce76855bba5a40998a512a1539bb9dcadcd81c8","realtime-admission-dev":"cab9e64721cb7f9442797744a193a12d2aa3a5d4a71234f60173b291c19ed0a6",research:"a2b9cc8a7cf3499891f4d7fa4f4b603df2d28baf77a02397bd718224e7cfefad","shard-partition":"0f90efb80a81187e9031a3cf7779c238959ac706bf7742affe6e4a562da5d645","test-evidence":"12814a80813f56bf013729b8f01e520e94adbfc6561c607acfa952a9a56bf764"},baselineBytes:46581956,maximumAssetBytes:5e7,maximumTarballBytes:25e6,maximumUnpackedBytes:55e6,targets:{"darwin-arm64":{artifact:"godd-native-aarch64-apple-darwin",targetTriple:"aarch64-apple-darwin",bytes:9907744,sha256:"386f45f7c54a7d95db666a689c9d13db033065497082a1066aa9c5cab98fa454"},"darwin-x64":{artifact:"godd-native-x86_64-apple-darwin",targetTriple:"x86_64-apple-darwin",bytes:11002992,sha256:"3a30595a8e27b8d79317f48efb331b97812a593b4c9f31692ac05dfef14b2c03"},"linux-x64":{artifact:"godd-native-x86_64-unknown-linux-musl",targetTriple:"x86_64-unknown-linux-musl",bytes:12089136,sha256:"c79919dec7bf1a1653bed40d02b6a9dd8e397ab65f496d2c787d73bc64578475"},"win32-x64":{artifact:"godd-native-x86_64-pc-windows-msvc.exe",targetTriple:"x86_64-pc-windows-msvc",bytes:13581824,sha256:"7a9d7ac8508391743fec45b08cf08072af407c05935cf0481fa58e7abeab7182"}}};var j="3.10.0";var ee=require("node:crypto"),h=require("node:fs"),b=require("node:path"),pe=require("node:os"),me=require("node:child_process");var W=require("node:child_process");var V="advisory";var Pe=Object.freeze(["handshake","show","--json"]),Le=5e3,K=65536,Me=64,J=Object.freeze({1:1}),N=/^[0-9a-f]{64}$/,ce=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,ke=/^(?:<default>|[a-z0-9]+(?:-[a-z0-9]+)*|--[a-z0-9]+(?:-[a-z0-9]+)*|-[a-z0-9])$/,Y=/^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)*$/,$=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;function q(){return"63cc3a0d813e7db7e0a12bf63143a2b7e2ecd8f8950313d49f652e840cfd5cb3"}var He=Symbol("AdmittedLaunch"),F=Symbol("AuthorizedNativeLaunch");function R(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function M(t,e){return Object.keys(t).length===e.length&&e.every(n=>Object.hasOwn(t,n))}function k(t,e){return e.every(r=>Object.hasOwn(t,r))}function ie(t,e){if(!Array.isArray(t)||t.length===0)return!1;let r;for(let n of t){if(typeof n!="string"||!e.test(n)||r!==void 0&&r>=n)return!1;r=n}return!0}function xe(t){if(!Array.isArray(t)||t.length===0)return!1;let e=0;for(let r of t){if(!le(r)||r===0||r<=e)return!1;e=r}return!0}function ae(t){return typeof t=="string"&&t.length>0&&!/[\u0000-\u001f\u007f]/.test(t)}function le(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0}function G(t){return le(t)&&t<=65535}function Ue(t){if(!R(t)||Object.keys(t).length===0)return!1;for(let e of Object.values(t))if(!R(e)||typeof e.targetTriple!="string"||!$.test(e.targetTriple))return!1;return!0}function Ge(t,e){let r=Array.from(t,a=>a.codePointAt(0)),n=Array.from(e,a=>a.codePointAt(0)),o=Math.min(r.length,n.length);for(let a=0;a<o;a+=1)if(r[a]!==n[a])return r[a]-n[a];return r.length-n.length}function X(t,e,r,n){if(!R(t)||t.schemaVersion!==3)return null;let o=t.handshakeProtocol;if(!R(o)||!M(o,["supportedProtocolMajors","minimumProtocolMinorByMajor"]))return null;let a=o.supportedProtocolMajors,i=o.minimumProtocolMinorByMajor;if(!xe(a)||a.some(f=>!G(f))||a.some(f=>!Object.hasOwn(J,f))||!R(i))return null;let c=a.map(String),s=Object.keys(i);if(s.length!==c.length||s.some(f=>!c.includes(f)))return null;let _={};for(let f of a){let g=i[String(f)];if(!G(g))return null;_[f]=g}let u=t.capabilities,l=t.routedCommands,d=t.routedCommandEntryDigests;if(!ie(u,ce)||!ie(l,/^[a-z0-9]+(?:-[a-z0-9]+)*$/)||l.includes("<default>")||!R(d))return null;let E=Object.keys(d);if(E.length!==l.length||E.some(f=>!l.includes(f)))return null;let m={};for(let f of l){let g=d[f];if(typeof g!="string"||!N.test(g))return null;m[f]=g}if(typeof t.capabilityCatalogDigest!="string"||!N.test(t.capabilityCatalogDigest)||!N.test(n.manifestDigest??"")||!Y.test(n.packageVersion))return null;let O=t.targets;if(!Ue(O))return null;let T=O[`${e}-${r}`];return!T||typeof T.targetTriple!="string"||!$.test(T.targetTriple)?null:{supportedProtocolMajors:[...a],minimumProtocolMinorByMajor:_,expectedCapabilityIds:[...u],expectedTargetTriple:T.targetTriple,routedCommandNames:[...l],expectedRoutedCommandEntryDigests:m,expectedCapabilityCatalogDigest:t.capabilityCatalogDigest,packageVersion:n.packageVersion,manifestDigest:n.manifestDigest}}function Be(t){let e=0,r=()=>{if(t[e]!=='"')return null;let o=e;for(e+=1;e<t.length&&t[e]!=='"';){if(t.charCodeAt(e)<32)return null;if(t[e]==="\\"){e+=1;let i=t[e];if(i==='"'||i==="\\"||i==="b"||i==="f"||i==="n"||i==="r"||i==="t"){e+=1;continue}if(i!=="u")return null;let c=t.slice(e+1,e+5);if(!/^[0-9a-f]{4}$/.test(c))return null;let s=Number.parseInt(c,16);if(s>31||[8,9,10,12,13].includes(s))return null;e+=5;continue}e+=1}if(e>=t.length)return null;e+=1;try{return JSON.parse(t.slice(o,e))}catch{return null}},n=(o=0)=>{if(o>Me)return!1;let a=t[e];if(a==='"')return r()!==null;if(a==="{"){if(e+=1,t[e]==="}")return e+=1,!0;let c;for(;e<t.length;){let s=r();if(s===null||c!==void 0&&Ge(c,s)>=0||t[e]!==":"||(c=s,e+=1,!n(o+1)))return!1;if(t[e]==="}")return e+=1,!0;if(t[e]!==",")return!1;e+=1}return!1}if(a==="["){if(e+=1,t[e]==="]")return e+=1,!0;for(;e<t.length;){if(!n(o+1))return!1;if(t[e]==="]")return e+=1,!0;if(t[e]!==",")return!1;e+=1}return!1}if(a==="t"&&t.slice(e,e+4)==="true")return e+=4,!0;if(a==="f"&&t.slice(e,e+5)==="false")return e+=5,!0;if(a==="n"&&t.slice(e,e+4)==="null")return e+=4,!0;let i=e;if(t[e]==="-"&&(e+=1),t[e]==="0"){if(e+=1,/[0-9]/.test(t[e]??""))return!1}else{if(!/[1-9]/.test(t[e]??""))return!1;for(e+=1;/[0-9]/.test(t[e]??"");)e+=1}return e>i&&t.slice(i,e)!=="-0"&&!/[.eE]/.test(t[e]??"")};return n()?e===t.length:!1}function z(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function se(t,e){let r;for(let n of t){if(!e.test(n)||r!==void 0&&r>=n)return!1;r=n}return!0}function je(t){return!R(t)||!k(t,["major","minor"])||!G(t.major)||!G(t.minor)?null:{major:t.major,minor:t.minor}}function Ve(t){if(t.length>=3&&t[0]===239&&t[1]===187&&t[2]===191)return{status:"malformed"};let e;try{e=new TextDecoder("utf-8",{fatal:!0}).decode(t)}catch{return{status:"malformed"}}if(!e.endsWith(`
|
|
2
2
|
`)||e.endsWith(`
|
|
3
3
|
|
|
4
|
-
`)||e.includes("\r"))return{status:"malformed"};let r=e.slice(0,-1);if(!Be(r))return{status:"malformed"};let n;try{n=JSON.parse(r)}catch{return{status:"malformed"}}if(!R(n))return{status:"malformed"};let o=je(n.protocol_version);if(!o)return{status:"malformed"};if(o.major!==1)return{status:"valid",protocolVersion:o};let a=["build","capability_catalog_digest","capability_ids","protocol_version","surface_entries","surface_fingerprint","target"],i=["build","capability_catalog_digest","capability_ids","protocol_version","routed_commands","surface_entries","surface_fingerprint","surface_projection_digest","target"],c=J[o.major],s=c!==void 0&&o.minor>c,_=o.minor>=1?i:a;if(!(s?k(n,_):M(n,_)))return{status:"malformed"};let l=n.protocol_version;if(!R(l)||!(s?k(l,["major","minor"]):M(l,["major","minor"])))return{status:"malformed"};let d=n.build,E=n.target,m=n.surface_entries,O=n.capability_ids,
|
|
5
|
-
`}var te=U.targets;function Je(t,e){return te[`${t}-${e}`]?.artifact??null}function Ye(t){if(t.overridePath)return t.overridePath;let e=Je(t.platform,t.arch);if(!e||!t.entryPath)return null;let r=t.realpath?t.realpath(t.entryPath):(0,h.existsSync)(t.entryPath)?(0,h.realpathSync)(t.entryPath):t.entryPath,n=(0,T.resolve)((0,T.dirname)(r),"..");return(0,T.join)(n,"assets","native",e)}function _e(t,e,r){try{let n=te[`${e}-${r}`];return!n||(0,h.statSync)(t).size!==n.bytes?!1:(0,ee.createHash)("sha256").update((0,h.readFileSync)(t)).digest("hex")===n.sha256}catch{return!1}}function fe(t,e,r,n){let o=t.kind==="Blocked"?t.receipt:t.advisoryReceipt;if(o)try{if(r){r(o,e);return}if(!!0||process.env.GODD_NATIVE_HANDSHAKE_REPORTING!=="railway-aggregate-v2")return;let a=n?.path??Ye({platform:process.platform,arch:process.arch,entryPath:process.argv[1]});if(!a)return;let i=re(a,e,n?.arch??process.arch);if(!i)return;try{(0,me.spawnSync)(i.path,["anonymous-handshake-report"],{input:JSON.stringify(o),env:{...process.platform==="win32"&&process.env.SystemRoot?{SystemRoot:process.env.SystemRoot}:{},GODD_NATIVE_HANDSHAKE_REPORTING:"railway-aggregate-v2"},timeout:1500,windowsHide:!0,shell:!1,stdio:["pipe","ignore","ignore"]})}finally{i.cleanup()}}catch{}}function re(t,e,r,n=te){let o;try{let a=n[`${e}-${r}`];if(!a)return null;let i=(0,h.readFileSync)(t);if(i.length!==a.bytes||(0,ee.createHash)("sha256").update(i).digest("hex")!==a.sha256)return null;o=(0,h.mkdtempSync)((0,T.join)((0,pe.tmpdir)(),"godd-native-"));let c=(0,T.join)(o,`godd-native${(0,T.extname)(t)}`);return(0,h.writeFileSync)(c,i,{mode:448}),{path:c,cleanup:()=>{try{(0,h.rmSync)(o,{recursive:!0,force:!0})}catch{}}}}catch{if(o)try{(0,h.rmSync)(o,{recursive:!0,force:!0})}catch{}return null}}var Ee=require("node:crypto"),$e=/^sha256:[0-9a-f]{64}$/u,qe=1024,Xe=Object.freeze({owner:"nextjs-server",clock:"monotonic-milliseconds",trigger:"timer-and-after-lifecycle-event"});function y(t,e,r,n=0){return Object.freeze({action:t,disposition:e,max_retries:n,on_retry_exhausted:n===1?"REJECT":null,reason:r})}var I=Object.freeze({CACHE_HIT:y("USE_CACHED_MODULE","CONTINUE",null),CACHE_MISS_COMPILED:y("PUBLISH_COMPILED_MODULE","CONTINUE",null),SINGLE_FLIGHT_JOINED:y("WAIT_FOR_SINGLE_FLIGHT","CONTINUE",null),TOO_LARGE_FOR_CACHE:y("COMPILE_WITHOUT_CACHE","CONTINUE","ENTRY_LIMIT_EXCEEDED"),BUDGET_OVERFLOW:y("REJECT_CACHE_OPERATION","REJECT","ARITHMETIC_OVERFLOW"),BUDGET_UNRECLAIMABLE:y("RETRY_AFTER_RECONCILE","RETRY","RECLAIMABLE_ENTRIES_INSUFFICIENT",1),BUDGET_EVICTED_LRU:y("DROP_OPAQUE_HANDLE","CONTINUE","LRU_PRESSURE_EVICTION"),SUPERSEDED_BY_NEW_SOURCE:y("DROP_OPAQUE_HANDLE","CONTINUE","SOURCE_GENERATION_SUPERSEDED"),DECK_TOMBSTONED:y("DROP_OPAQUE_HANDLE","CONTINUE","DECK_LIFECYCLE_ENDED"),STALE_GENERATION_REJECTED:y("DISCARD_COMPILED_MODULE","CONTINUE","GENERATION_FENCE_CHANGED"),PREVIEW_LEASE_EXPIRED:y("DROP_OPAQUE_HANDLE","CONTINUE","PREVIEW_LEASE_ENDED"),AGE_EXPIRED:y("DROP_OPAQUE_HANDLE","CONTINUE","MAXIMUM_AGE_EXCEEDED"),IDLE_EXPIRED:y("DROP_OPAQUE_HANDLE","CONTINUE","MAXIMUM_IDLE_EXCEEDED"),RESERVATION_EXPIRED:y("DISCARD_COMPILED_MODULE","CONTINUE","RESERVATION_DEADLINE_EXCEEDED"),COMPILE_FAILED_ROLLED_BACK:y("RELEASE_FAILED_COMPILE","CONTINUE","COMPILE_DID_NOT_COMPLETE"),RECONCILE_CLOCK_REGRESSION:y("REJECT_CACHE_OPERATION","REJECT","RECONCILE_CLOCK_REGRESSED")});function w(t,e){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(`${e} must be an object`);return t}function S(t,e,r){let n=Object.keys(t).sort(),o=[...e].sort();if(n.length!==o.length||n.some((a,i)=>a!==o[i]))throw new TypeError(`${r} has an invalid field set`)}function D(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0}function H(t){return D(t)&&t>0}function x(t){return typeof t=="string"&&$e.test(t)}function he(t){return t==="unversioned"||x(t)}function ne(t){return typeof t=="string"&&t.length>0&&Buffer.byteLength(t,"utf8")<=qe&&!new RegExp("\\p{Cc}","u").test(t)}function Qe(t){let e=w(t,"compile cache manifest");if(S(e,["workspace_id","deck_id","deck_generation","slide_filename","canonical_source_digest","mdx_policy_generation","compiler_generation","runtime_abi"],"compile cache manifest"),!ne(e.workspace_id)||!ne(e.deck_id)||!ne(e.slide_filename)||!H(e.deck_generation)||!x(e.canonical_source_digest)||!he(e.mdx_policy_generation)||!x(e.compiler_generation)||e.runtime_abi!=="amaroad")throw new TypeError("compile cache manifest is invalid");return e}function Ze(t){let e=w(t,"compile cache register request");if(S(e,["schema_version","operation","manifest","source_bytes","declared_max_compiled_bytes","now_ms"],"compile cache register request"),Qe(e.manifest),e.schema_version!==1||e.operation!=="register"||!D(e.source_bytes)||!H(e.declared_max_compiled_bytes)||!D(e.now_ms))throw new TypeError("compile cache register request is invalid");return e}function ye(t){let e=w(t,"compile cache project input");S(e,["schema_version","manifest","canonical_source","declared_max_compiled_bytes","now_ms"],"compile cache project input");let r=w(e.manifest,"compile cache project manifest");if(S(r,["workspace_id","deck_id","deck_generation","slide_filename","mdx_policy_generation","compiler_generation","runtime_abi"],"compile cache project manifest"),typeof e.canonical_source!="string")throw new TypeError("compile cache canonical source is invalid");let n=Buffer.byteLength(e.canonical_source,"utf8"),o={schema_version:1,operation:"register",manifest:{...r,canonical_source_digest:`sha256:${(0,Ee.createHash)("sha256").update(e.canonical_source,"utf8").digest("hex")}`},source_bytes:n,declared_max_compiled_bytes:e.declared_max_compiled_bytes,now_ms:e.now_ms};return Ze(o)}function Ce(t){let e=w(t,"compile cache time budget");if(S(e,["age_ms","idle_ms","reservation_ttl_ms"],"compile cache time budget"),!H(e.age_ms)||!H(e.idle_ms)||!H(e.reservation_ttl_ms))throw new TypeError("compile cache time budget is invalid");return Object.freeze({...Xe,interval_ms:Math.min(e.age_ms,e.idle_ms,e.reservation_ttl_ms)})}function et(t){if(typeof t!="string"||!Object.hasOwn(I,t))throw new TypeError("compile cache receipt outcome is unsupported");let e=t;return[e,I[e]]}function tt(t){let e=w(t,"compile cache receipt");S(e,["schema_version","canonical_source_digest","deck_generation","mdx_policy_generation","compiler_generation","key_bytes","source_bytes","compiled_bytes","compiled_bytes_measured","outcome","reason"],"compile cache receipt");let[,r]=et(e.outcome);if(e.schema_version!==1||!x(e.canonical_source_digest)||!D(e.deck_generation)||!he(e.mdx_policy_generation)||!x(e.compiler_generation)||!D(e.key_bytes)||!D(e.source_bytes)||!D(e.compiled_bytes)||typeof e.compiled_bytes_measured!="boolean")throw new TypeError("compile cache receipt is invalid");if(e.reason!==r.reason)throw new TypeError("compile cache receipt reason does not match outcome");return e}function ge(t){let e=tt(t);return Object.freeze({action:I[e.outcome].action,disposition:I[e.outcome].disposition,max_retries:I[e.outcome].max_retries,on_retry_exhausted:I[e.outcome].on_retry_exhausted,outcome:e.outcome})}var p=class extends Error{code;handshakeReasonCode;constructor(e,r){super(e),this.name="CompileCacheRuntimeError",this.code=e,this.handshakeReasonCode=r??null}},v=class extends Error{outcome;action;disposition;retriesExhausted;constructor(e,r,n,o){super(e),this.name="CompileCacheRejectedError",this.outcome=e,this.action=r,this.disposition=n,this.retriesExhausted=o}},P=class{outcome;action;constructor(e,r){this.outcome=e,this.action=r}},Ae="";function rt(t){return[t.workspace_id,t.deck_id,String(t.deck_generation),t.slide_filename,t.canonical_source_digest,t.mdx_policy_generation,t.compiler_generation,t.runtime_abi].join(Ae)}function Re(t){return[t.canonical_source_digest,String(t.deck_generation),t.mdx_policy_generation,t.compiler_generation].join(Ae)}var oe=class{#s;#y;#c;#u;#p;#o=new Map;#i=new Map;#r=new Map;#m;#n=null;#l=!1;#_=0;#f=null;#d=!1;constructor(e){this.#s=e.evaluator,this.#y=e.budget,this.#c=e.compile,this.#u=e.now,this.#p=e.onReconcileError??(()=>{}),this.#m=Ce({age_ms:e.budget.age_ms,idle_ms:e.budget.idle_ms,reservation_ttl_ms:e.budget.reservation_ttl_ms})}get reconcilePolicy(){return this.#m}get retainedModuleCount(){return this.#o.size}get reconcileTimerStarted(){return this.#n!==null}startReconcileTimer(){if(this.#n!==null)throw new p("RECONCILE_TIMER_ALREADY_OWNED");this.#n=setInterval(()=>{this.#l||(this.#l=!0,this.reconcile().catch(e=>{this.#p(e)}).finally(()=>{this.#l=!1}))},this.#m.interval_ms),this.#n.unref?.()}stopReconcileTimer(){if(this.#n===null)throw new p("RECONCILE_TIMER_NOT_OWNED");clearInterval(this.#n),this.#n=null,this.#l=!1}async close(){this.#n!==null&&this.stopReconcileTimer(),this.#d=!0,this.#o.clear(),this.#i.clear(),this.#r.clear(),await this.#s.close()}async compile(e){await this.#h();let r=await this.#C(e,!1);if(!(r instanceof P))return r;await this.reconcile();let n=await this.#C(e,!0);if(n instanceof P)throw new v(n.outcome,n.action,"RETRY",!0);return n}async reconcile(){await this.#h();let e=await this.#a({schema_version:1,command:"reconcile",now_ms:this.#u()}),r=e.action==="REJECTED",n=this.#t(e.receipts,r);if(r)throw n===null?new p("EVALUATOR_PROTOCOL"):new v(n.outcome,n.action,n.disposition,!1);return e.receipts}async onDeckRemoved(e,r){await this.#E({schema_version:1,command:"tombstone_deck",workspace_id:e,deck_id:r})}async onPreviewLeaseExpired(e,r){await this.#E({schema_version:1,command:"expire_preview_lease",workspace_id:e,deck_id:r})}async onGenerationUpdated(e){await this.#E({schema_version:1,command:"fence_generations",...e})}async#E(e){await this.#h();let r=await this.#a(e);this.#t(r.receipts,!1),await this.reconcile()}async#C(e,r){let n=ye({schema_version:1,manifest:e.manifest,canonical_source:e.canonical_source,declared_max_compiled_bytes:e.declared_max_compiled_bytes,now_ms:this.#u()}),{operation:o,...a}=n,i=await this.#a({command:o,...a}),c=rt(n.manifest),s=Re(n.manifest);switch(i.action){case"HIT":return this.#O(e,i,c,s,r);case"JOINED":return this.#A(i,c,r);case"COMPILE_REQUESTED":return this.#b(e,i,c,s,r);case"REJECTED":return this.#T(e,i,r);default:try{this.#t(i.receipts,!1)}finally{await this.#e(i.lease)}throw new p("EVALUATOR_PROTOCOL")}}async#O(e,r,n,o,a){try{let i=this.#g(r,"USE_CACHED_MODULE"),c=this.#o.get(n),s=!0;if(c===void 0){let _=this.#_,u=await this.#c(e);c=u.module,s=!1;let l=r.receipts[r.receipts.length-1];if(u.compiled_bytes!==l.compiled_bytes||this.#_!==_)return{module:c,outcome:i.outcome,action:i.action,served_from_cache:!1,retained:!1,retried:a};this.#R(n,o,c)}return{module:c,outcome:i.outcome,action:i.action,served_from_cache:s,retained:!0,retried:a}}finally{await this.#e(r.lease)}}async#A(e,r,n){try{let o=this.#g(e,"WAIT_FOR_SINGLE_FLIGHT"),a=this.#r.get(r);if(a===void 0)throw new p("SINGLE_FLIGHT_MISSING");let i=await a;return{module:i.module,outcome:o.outcome,action:o.action,served_from_cache:!0,retained:i.retained,retried:n}}finally{await this.#e(e.lease)}}async#b(e,r,n,o,a){try{this.#t(r.receipts,!1)}catch(m){throw await this.#e(r.lease),m}if(r.compile_owner!==!0||r.lease===null)throw await this.#e(r.lease),new p("EVALUATOR_PROTOCOL");let i=r.lease,c,s,_=new Promise((m,O)=>{c=m,s=O});_.catch(()=>{}),this.#r.set(n,_);let u;try{u=await this.#c(e)}catch(m){s?.(m);try{let O=await this.#a({schema_version:1,command:"rollback",lease:i});this.#t(O.receipts,!1)}catch{}throw this.#r.delete(n),m}let l;try{l=await this.#a({schema_version:1,command:"commit",lease:i,compiled_bytes:u.compiled_bytes})}catch(m){throw s?.(m),await this.#e(i),this.#r.delete(n),m}let d;try{d=this.#t(l.receipts,!0)}catch(m){throw s?.(m),this.#r.delete(n),await this.#e(i),m}if(this.#r.delete(n),l.action==="NOOP"||d===null){let m=new p("COMMIT_NOT_ACCEPTED");throw s?.(m),await this.#e(i),m}if(d.action==="PUBLISH_COMPILED_MODULE")return this.#R(n,o,u.module),c?.({module:u.module,retained:!0}),await this.#e(i),{module:u.module,outcome:d.outcome,action:d.action,served_from_cache:!1,retained:!0,retried:a};if(d.action==="COMPILE_WITHOUT_CACHE")return c?.({module:u.module,retained:!1}),await this.#e(i),{module:u.module,outcome:d.outcome,action:d.action,served_from_cache:!1,retained:!1,retried:a};let E=new v(d.outcome,d.action,d.disposition,!1);if(s?.(E),await this.#e(i),d.disposition==="RETRY")return new P(d.outcome,d.action);throw E}async#T(e,r,n){let o=this.#t(r.receipts,!0);if(o===null)throw new p("EVALUATOR_PROTOCOL");if(o.disposition==="RETRY")return new P(o.outcome,o.action);if(o.action==="COMPILE_WITHOUT_CACHE")return{module:(await this.#c(e)).module,outcome:o.outcome,action:o.action,served_from_cache:!1,retained:!1,retried:n};throw new v(o.outcome,o.action,o.disposition,!1)}#t(e,r){let n=null;for(let o=0;o<e.length;o+=1){let a=ge(e[o]);o===e.length-1&&(n=a),e[o].compiled_bytes_measured&&(a.action==="DROP_OPAQUE_HANDLE"||a.action==="DISCARD_COMPILED_MODULE"||a.action==="RELEASE_FAILED_COMPILE")&&(this.#_+=1,this.#N(Re(e[o])))}return r?n:null}#g(e,r){let n=this.#t(e.receipts,!0);if(n===null||n.action!==r)throw new p("EVALUATOR_PROTOCOL");return n}#R(e,r,n){this.#o.set(e,n);let o=this.#i.get(r);if(o===void 0){this.#i.set(r,new Set([e]));return}o.add(e)}#N(e){let r=this.#i.get(e);if(r!==void 0){for(let n of r)this.#o.delete(n);this.#i.delete(e)}}async#e(e){if(e!==null)try{let r=await this.#a({schema_version:1,command:"release",lease:e});this.#t(r.receipts,!1)}catch(r){this.#p(r)}}async#h(){if(this.#d)throw new p("EVALUATOR_CLOSED");this.#f??=(async()=>{if((await this.#s.send({schema_version:1,command:"configure",budget:this.#y})).action!=="CONFIGURED")throw new p("EVALUATOR_PROTOCOL")})().catch(e=>{throw this.#f=null,e}),await this.#f}async#a(e){if(this.#d)throw new p("EVALUATOR_CLOSED");try{return await this.#s.send(e)}catch(r){throw r instanceof p&&r.code==="EVALUATOR_CLOSED"&&(this.#d=!0,this.#o.clear(),this.#i.clear(),this.#r.clear()),r}}};function nt(t){if(t===null||typeof t!="object"||Array.isArray(t))throw new p("EVALUATOR_PROTOCOL");let e=t;if(e.schema_version!==1||typeof e.action!="string")throw new p("EVALUATOR_PROTOCOL");if(!Array.isArray(e.receipts))throw new p("EVALUATOR_PROTOCOL");if(e.lease!==null&&(!Number.isSafeInteger(e.lease)||e.lease<1))throw new p("EVALUATOR_PROTOCOL");return t}function be(t){let e=[],r="",n=null;t.readable.setEncoding?.("utf8"),t.readable.on("data",a=>{r+=typeof a=="string"?a:a.toString("utf8");let i=r.indexOf(`
|
|
4
|
+
`)||e.includes("\r"))return{status:"malformed"};let r=e.slice(0,-1);if(!Be(r))return{status:"malformed"};let n;try{n=JSON.parse(r)}catch{return{status:"malformed"}}if(!R(n))return{status:"malformed"};let o=je(n.protocol_version);if(!o)return{status:"malformed"};if(o.major!==1)return{status:"valid",protocolVersion:o};let a=["build","capability_catalog_digest","capability_ids","protocol_version","surface_entries","surface_fingerprint","target"],i=["build","capability_catalog_digest","capability_ids","protocol_version","routed_commands","surface_entries","surface_fingerprint","surface_projection_digest","target"],c=J[o.major],s=c!==void 0&&o.minor>c,_=o.minor>=1?i:a;if(!(s?k(n,_):M(n,_)))return{status:"malformed"};let l=n.protocol_version;if(!R(l)||!(s?k(l,["major","minor"]):M(l,["major","minor"])))return{status:"malformed"};let d=n.build,E=n.target,m=n.surface_entries,O=n.capability_ids,T=n.routed_commands;return typeof n.surface_fingerprint=="string"&&N.test(n.surface_fingerprint)&&typeof n.capability_catalog_digest=="string"&&N.test(n.capability_catalog_digest)&&z(O)&&se(O,ce)&&R(m)&&Object.keys(m).length>0&&Object.entries(m).every(([g,L])=>ke.test(g)&&typeof L=="string"&&N.test(L))&&Object.hasOwn(m,"<default>")&&R(E)&&(s?k(E,["arch","os","target_triple"]):M(E,["arch","os","target_triple"]))&&typeof E.target_triple=="string"&&$.test(E.target_triple)&&ae(E.os)&&ae(E.arch)&&R(d)&&(s?k(d,["crate_version"]):M(d,["crate_version"]))&&typeof d.crate_version=="string"&&Y.test(d.crate_version)?o.minor>=1&&(!z(T)||!se(T,/^[a-z0-9]+(?:-[a-z0-9]+)*$/)||typeof n.surface_projection_digest!="string"||!N.test(n.surface_projection_digest))?{status:"malformed"}:o.minor>=1&&z(T)&&!T.every(g=>Object.hasOwn(m,g))?{status:"malformed"}:{status:"valid",document:n,protocolVersion:o}:{status:"malformed"}}function Ke(t){return Object.fromEntries(Object.entries(t).filter(([e])=>!/^GODD_/i.test(e)))}function de(t){return t?t.code:void 0}function Fe(t){let e=de(t);return e==="ENOBUFS"||e==="ERR_CHILD_PROCESS_STDIO_MAXBUFFER"}function ue(t,e,r,n,o,a,i=[]){let c=e?.packageVersion??t.packageVersion,s=e?.manifestDigest??t.manifestDigest??"";return{packageVersion:Y.test(c)?c:"",manifestDigest:N.test(s)?s:"",observedProtocolVersion:a??o?.protocol_version??null,observedSurfaceFingerprint:o?.surface_fingerprint??null,observedCapabilityCatalogDigest:o?.capability_catalog_digest??null,reasonCode:n,advisories:i,digestVerifiedPath:r}}function C(t,e,r,n,o,a){return{verdict:{kind:"Rejected",receipt:ue(t,e,r,n,o,a)},admittedLaunch:null}}function ze(t,e,r,n,o=W.spawnSync,a=process.env){if(!e)return C(r,null,n,"HSHAKE_EXPECTATION_ABSENT");let i;try{i=o(t,Pe,{encoding:null,timeout:Le,killSignal:"SIGKILL",maxBuffer:K,windowsHide:!0,stdio:["ignore","pipe","pipe"],env:Ke(a)})}catch{return C(r,e,n,"HSHAKE_PROBE_SPAWN_FAILED")}if(de(i.error)==="ETIMEDOUT")return C(r,e,n,"HSHAKE_PROBE_TIMEOUT");let s=i.stdout??Buffer.alloc(0),_=i.stderr??Buffer.alloc(0);if(Fe(i.error)){let A=_.length>0&&s.length<=K?"HSHAKE_DOCUMENT_MALFORMED":"HSHAKE_DOCUMENT_OVERSIZE";return C(r,e,n,A)}if(i.error)return C(r,e,n,"HSHAKE_PROBE_SPAWN_FAILED");if(i.status!==0||s.length===0)return C(r,e,n,"HSHAKE_DOCUMENT_ABSENT");if(s.length>K)return C(r,e,n,"HSHAKE_DOCUMENT_OVERSIZE");if(_.length>0)return C(r,e,n,"HSHAKE_DOCUMENT_MALFORMED");let u=Ve(s);if(u.status!=="valid"||!u.protocolVersion)return C(r,e,n,"HSHAKE_DOCUMENT_MALFORMED");let l=u.protocolVersion;if(!e.supportedProtocolMajors.includes(l.major))return C(r,e,n,"HSHAKE_PROTOCOL_MAJOR_UNSUPPORTED",void 0,l);let d=u.document;if(!d)return C(r,e,n,"HSHAKE_DOCUMENT_MALFORMED",void 0,l);let E=e.minimumProtocolMinorByMajor[l.major];if(E===void 0||l.minor<E)return C(r,e,n,"HSHAKE_PROTOCOL_MINOR_TOO_OLD",d,l);if(d.target.target_triple!==e.expectedTargetTriple)return C(r,e,n,"HSHAKE_TARGET_MISMATCH",d,l);let m=new Set(d.capability_ids);if(!e.expectedCapabilityIds.every(A=>m.has(A)))return C(r,e,n,"HSHAKE_CAPABILITY_MISSING",d,l);let O=new Set(d.routed_commands??[]);if(e.routedCommandNames.some(A=>!O.has(A)||d.surface_entries[A]!==e.expectedRoutedCommandEntryDigests[A]))return C(r,e,n,n?"HSHAKE_MANIFEST_SELF_INCONSISTENT":"HSHAKE_SURFACE_PROJECTION_MISMATCH",d,l);let f=[];d.capability_catalog_digest!==e.expectedCapabilityCatalogDigest&&f.push("HSHAKE_CAPABILITY_SURPLUS");let g=new Set(e.routedCommandNames);Object.keys(d.surface_entries).some(A=>A!=="<default>"&&!g.has(A))&&f.push("HSHAKE_SURFACE_SURPLUS");let L=J[l.major];return L!==void 0&&l.minor>L&&f.push("HSHAKE_PROTOCOL_MINOR_AHEAD"),{verdict:{kind:"Admitted",receipt:ue(r,e,n,"HSHAKE_ADMITTED",d,l,f)},admittedLaunch:{[He]:!0,binaryPath:t}}}function Q(t,e,r,n,o=W.spawnSync,a=process.env){if(V==="off")return{kind:"Allowed",launch:{[F]:!0,binaryPath:t},advisoryReceipt:null};let i=ze(t,e,r,n,o,a);return i.admittedLaunch?{kind:"Allowed",launch:{[F]:!0,binaryPath:i.admittedLaunch.binaryPath},advisoryReceipt:null}:V==="advisory"?{kind:"Allowed",launch:{[F]:!0,binaryPath:t},advisoryReceipt:i.verdict.receipt}:{kind:"Blocked",receipt:i.verdict.receipt}}function Z(t){return`[GoDD MCP \u03B1] Native handshake advisory: ${JSON.stringify(t)}
|
|
5
|
+
`}var te=U.targets;function Je(t,e){return te[`${t}-${e}`]?.artifact??null}function Ye(t){if(t.overridePath)return t.overridePath;let e=Je(t.platform,t.arch);if(!e||!t.entryPath)return null;let r=t.realpath?t.realpath(t.entryPath):(0,h.existsSync)(t.entryPath)?(0,h.realpathSync)(t.entryPath):t.entryPath,n=(0,b.resolve)((0,b.dirname)(r),"..");return(0,b.join)(n,"assets","native",e)}function _e(t,e,r){try{let n=te[`${e}-${r}`];return!n||(0,h.statSync)(t).size!==n.bytes?!1:(0,ee.createHash)("sha256").update((0,h.readFileSync)(t)).digest("hex")===n.sha256}catch{return!1}}function fe(t,e,r,n){let o=t.kind==="Blocked"?t.receipt:t.advisoryReceipt;if(o)try{if(r){r(o,e);return}if(!!0||process.env.GODD_NATIVE_HANDSHAKE_REPORTING!=="railway-aggregate-v2")return;let a=n?.path??Ye({platform:process.platform,arch:process.arch,entryPath:process.argv[1]});if(!a)return;let i=re(a,e,n?.arch??process.arch);if(!i)return;try{(0,me.spawnSync)(i.path,["anonymous-handshake-report"],{input:JSON.stringify(o),env:{...process.platform==="win32"&&process.env.SystemRoot?{SystemRoot:process.env.SystemRoot}:{},GODD_NATIVE_HANDSHAKE_REPORTING:"railway-aggregate-v2"},timeout:1500,windowsHide:!0,shell:!1,stdio:["pipe","ignore","ignore"]})}finally{i.cleanup()}}catch{}}function re(t,e,r,n=te){let o;try{let a=n[`${e}-${r}`];if(!a)return null;let i=(0,h.readFileSync)(t);if(i.length!==a.bytes||(0,ee.createHash)("sha256").update(i).digest("hex")!==a.sha256)return null;o=(0,h.mkdtempSync)((0,b.join)((0,pe.tmpdir)(),"godd-native-"));let c=(0,b.join)(o,`godd-native${(0,b.extname)(t)}`);return(0,h.writeFileSync)(c,i,{mode:448}),{path:c,cleanup:()=>{try{(0,h.rmSync)(o,{recursive:!0,force:!0})}catch{}}}}catch{if(o)try{(0,h.rmSync)(o,{recursive:!0,force:!0})}catch{}return null}}var Ee=require("node:crypto"),$e=/^sha256:[0-9a-f]{64}$/u,qe=1024,Xe=Object.freeze({owner:"nextjs-server",clock:"monotonic-milliseconds",trigger:"timer-and-after-lifecycle-event"});function y(t,e,r,n=0){return Object.freeze({action:t,disposition:e,max_retries:n,on_retry_exhausted:n===1?"REJECT":null,reason:r})}var I=Object.freeze({CACHE_HIT:y("USE_CACHED_MODULE","CONTINUE",null),CACHE_MISS_COMPILED:y("PUBLISH_COMPILED_MODULE","CONTINUE",null),SINGLE_FLIGHT_JOINED:y("WAIT_FOR_SINGLE_FLIGHT","CONTINUE",null),TOO_LARGE_FOR_CACHE:y("COMPILE_WITHOUT_CACHE","CONTINUE","ENTRY_LIMIT_EXCEEDED"),BUDGET_OVERFLOW:y("REJECT_CACHE_OPERATION","REJECT","ARITHMETIC_OVERFLOW"),BUDGET_UNRECLAIMABLE:y("RETRY_AFTER_RECONCILE","RETRY","RECLAIMABLE_ENTRIES_INSUFFICIENT",1),BUDGET_EVICTED_LRU:y("DROP_OPAQUE_HANDLE","CONTINUE","LRU_PRESSURE_EVICTION"),SUPERSEDED_BY_NEW_SOURCE:y("DROP_OPAQUE_HANDLE","CONTINUE","SOURCE_GENERATION_SUPERSEDED"),DECK_TOMBSTONED:y("DROP_OPAQUE_HANDLE","CONTINUE","DECK_LIFECYCLE_ENDED"),STALE_GENERATION_REJECTED:y("DISCARD_COMPILED_MODULE","CONTINUE","GENERATION_FENCE_CHANGED"),PREVIEW_LEASE_EXPIRED:y("DROP_OPAQUE_HANDLE","CONTINUE","PREVIEW_LEASE_ENDED"),AGE_EXPIRED:y("DROP_OPAQUE_HANDLE","CONTINUE","MAXIMUM_AGE_EXCEEDED"),IDLE_EXPIRED:y("DROP_OPAQUE_HANDLE","CONTINUE","MAXIMUM_IDLE_EXCEEDED"),RESERVATION_EXPIRED:y("DISCARD_COMPILED_MODULE","CONTINUE","RESERVATION_DEADLINE_EXCEEDED"),COMPILE_FAILED_ROLLED_BACK:y("RELEASE_FAILED_COMPILE","CONTINUE","COMPILE_DID_NOT_COMPLETE"),RECONCILE_CLOCK_REGRESSION:y("REJECT_CACHE_OPERATION","REJECT","RECONCILE_CLOCK_REGRESSED")});function w(t,e){if(t===null||typeof t!="object"||Array.isArray(t))throw new TypeError(`${e} must be an object`);return t}function S(t,e,r){let n=Object.keys(t).sort(),o=[...e].sort();if(n.length!==o.length||n.some((a,i)=>a!==o[i]))throw new TypeError(`${r} has an invalid field set`)}function D(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0}function H(t){return D(t)&&t>0}function x(t){return typeof t=="string"&&$e.test(t)}function he(t){return t==="unversioned"||x(t)}function ne(t){return typeof t=="string"&&t.length>0&&Buffer.byteLength(t,"utf8")<=qe&&!new RegExp("\\p{Cc}","u").test(t)}function Qe(t){let e=w(t,"compile cache manifest");if(S(e,["workspace_id","deck_id","deck_generation","slide_filename","canonical_source_digest","mdx_policy_generation","compiler_generation","runtime_abi"],"compile cache manifest"),!ne(e.workspace_id)||!ne(e.deck_id)||!ne(e.slide_filename)||!H(e.deck_generation)||!x(e.canonical_source_digest)||!he(e.mdx_policy_generation)||!x(e.compiler_generation)||e.runtime_abi!=="amaroad")throw new TypeError("compile cache manifest is invalid");return e}function Ze(t){let e=w(t,"compile cache register request");if(S(e,["schema_version","operation","manifest","source_bytes","declared_max_compiled_bytes","now_ms"],"compile cache register request"),Qe(e.manifest),e.schema_version!==1||e.operation!=="register"||!D(e.source_bytes)||!H(e.declared_max_compiled_bytes)||!D(e.now_ms))throw new TypeError("compile cache register request is invalid");return e}function ye(t){let e=w(t,"compile cache project input");S(e,["schema_version","manifest","canonical_source","declared_max_compiled_bytes","now_ms"],"compile cache project input");let r=w(e.manifest,"compile cache project manifest");if(S(r,["workspace_id","deck_id","deck_generation","slide_filename","mdx_policy_generation","compiler_generation","runtime_abi"],"compile cache project manifest"),typeof e.canonical_source!="string")throw new TypeError("compile cache canonical source is invalid");let n=Buffer.byteLength(e.canonical_source,"utf8"),o={schema_version:1,operation:"register",manifest:{...r,canonical_source_digest:`sha256:${(0,Ee.createHash)("sha256").update(e.canonical_source,"utf8").digest("hex")}`},source_bytes:n,declared_max_compiled_bytes:e.declared_max_compiled_bytes,now_ms:e.now_ms};return Ze(o)}function Ce(t){let e=w(t,"compile cache time budget");if(S(e,["age_ms","idle_ms","reservation_ttl_ms"],"compile cache time budget"),!H(e.age_ms)||!H(e.idle_ms)||!H(e.reservation_ttl_ms))throw new TypeError("compile cache time budget is invalid");return Object.freeze({...Xe,interval_ms:Math.min(e.age_ms,e.idle_ms,e.reservation_ttl_ms)})}function et(t){if(typeof t!="string"||!Object.hasOwn(I,t))throw new TypeError("compile cache receipt outcome is unsupported");let e=t;return[e,I[e]]}function tt(t){let e=w(t,"compile cache receipt");S(e,["schema_version","canonical_source_digest","deck_generation","mdx_policy_generation","compiler_generation","key_bytes","source_bytes","compiled_bytes","compiled_bytes_measured","outcome","reason"],"compile cache receipt");let[,r]=et(e.outcome);if(e.schema_version!==1||!x(e.canonical_source_digest)||!D(e.deck_generation)||!he(e.mdx_policy_generation)||!x(e.compiler_generation)||!D(e.key_bytes)||!D(e.source_bytes)||!D(e.compiled_bytes)||typeof e.compiled_bytes_measured!="boolean")throw new TypeError("compile cache receipt is invalid");if(e.reason!==r.reason)throw new TypeError("compile cache receipt reason does not match outcome");return e}function ge(t){let e=tt(t);return Object.freeze({action:I[e.outcome].action,disposition:I[e.outcome].disposition,max_retries:I[e.outcome].max_retries,on_retry_exhausted:I[e.outcome].on_retry_exhausted,outcome:e.outcome})}var p=class extends Error{code;handshakeReasonCode;constructor(e,r){super(e),this.name="CompileCacheRuntimeError",this.code=e,this.handshakeReasonCode=r??null}},v=class extends Error{outcome;action;disposition;retriesExhausted;constructor(e,r,n,o){super(e),this.name="CompileCacheRejectedError",this.outcome=e,this.action=r,this.disposition=n,this.retriesExhausted=o}},P=class{outcome;action;constructor(e,r){this.outcome=e,this.action=r}},Ae="";function rt(t){return[t.workspace_id,t.deck_id,String(t.deck_generation),t.slide_filename,t.canonical_source_digest,t.mdx_policy_generation,t.compiler_generation,t.runtime_abi].join(Ae)}function Re(t){return[t.canonical_source_digest,String(t.deck_generation),t.mdx_policy_generation,t.compiler_generation].join(Ae)}var oe=class{#s;#y;#c;#u;#p;#o=new Map;#i=new Map;#r=new Map;#m;#n=null;#l=!1;#_=0;#f=null;#d=!1;constructor(e){this.#s=e.evaluator,this.#y=e.budget,this.#c=e.compile,this.#u=e.now,this.#p=e.onReconcileError??(()=>{}),this.#m=Ce({age_ms:e.budget.age_ms,idle_ms:e.budget.idle_ms,reservation_ttl_ms:e.budget.reservation_ttl_ms})}get reconcilePolicy(){return this.#m}get retainedModuleCount(){return this.#o.size}get reconcileTimerStarted(){return this.#n!==null}startReconcileTimer(){if(this.#n!==null)throw new p("RECONCILE_TIMER_ALREADY_OWNED");this.#n=setInterval(()=>{this.#l||(this.#l=!0,this.reconcile().catch(e=>{this.#p(e)}).finally(()=>{this.#l=!1}))},this.#m.interval_ms),this.#n.unref?.()}stopReconcileTimer(){if(this.#n===null)throw new p("RECONCILE_TIMER_NOT_OWNED");clearInterval(this.#n),this.#n=null,this.#l=!1}async close(){this.#n!==null&&this.stopReconcileTimer(),this.#d=!0,this.#o.clear(),this.#i.clear(),this.#r.clear(),await this.#s.close()}async compile(e){await this.#h();let r=await this.#C(e,!1);if(!(r instanceof P))return r;await this.reconcile();let n=await this.#C(e,!0);if(n instanceof P)throw new v(n.outcome,n.action,"RETRY",!0);return n}async reconcile(){await this.#h();let e=await this.#a({schema_version:1,command:"reconcile",now_ms:this.#u()}),r=e.action==="REJECTED",n=this.#t(e.receipts,r);if(r)throw n===null?new p("EVALUATOR_PROTOCOL"):new v(n.outcome,n.action,n.disposition,!1);return e.receipts}async onDeckRemoved(e,r){await this.#E({schema_version:1,command:"tombstone_deck",workspace_id:e,deck_id:r})}async onPreviewLeaseExpired(e,r){await this.#E({schema_version:1,command:"expire_preview_lease",workspace_id:e,deck_id:r})}async onGenerationUpdated(e){await this.#E({schema_version:1,command:"fence_generations",...e})}async#E(e){await this.#h();let r=await this.#a(e);this.#t(r.receipts,!1),await this.reconcile()}async#C(e,r){let n=ye({schema_version:1,manifest:e.manifest,canonical_source:e.canonical_source,declared_max_compiled_bytes:e.declared_max_compiled_bytes,now_ms:this.#u()}),{operation:o,...a}=n,i=await this.#a({command:o,...a}),c=rt(n.manifest),s=Re(n.manifest);switch(i.action){case"HIT":return this.#O(e,i,c,s,r);case"JOINED":return this.#A(i,c,r);case"COMPILE_REQUESTED":return this.#T(e,i,c,s,r);case"REJECTED":return this.#b(e,i,r);default:try{this.#t(i.receipts,!1)}finally{await this.#e(i.lease)}throw new p("EVALUATOR_PROTOCOL")}}async#O(e,r,n,o,a){try{let i=this.#g(r,"USE_CACHED_MODULE"),c=this.#o.get(n),s=!0;if(c===void 0){let _=this.#_,u=await this.#c(e);c=u.module,s=!1;let l=r.receipts[r.receipts.length-1];if(u.compiled_bytes!==l.compiled_bytes||this.#_!==_)return{module:c,outcome:i.outcome,action:i.action,served_from_cache:!1,retained:!1,retried:a};this.#R(n,o,c)}return{module:c,outcome:i.outcome,action:i.action,served_from_cache:s,retained:!0,retried:a}}finally{await this.#e(r.lease)}}async#A(e,r,n){try{let o=this.#g(e,"WAIT_FOR_SINGLE_FLIGHT"),a=this.#r.get(r);if(a===void 0)throw new p("SINGLE_FLIGHT_MISSING");let i=await a;return{module:i.module,outcome:o.outcome,action:o.action,served_from_cache:!0,retained:i.retained,retried:n}}finally{await this.#e(e.lease)}}async#T(e,r,n,o,a){try{this.#t(r.receipts,!1)}catch(m){throw await this.#e(r.lease),m}if(r.compile_owner!==!0||r.lease===null)throw await this.#e(r.lease),new p("EVALUATOR_PROTOCOL");let i=r.lease,c,s,_=new Promise((m,O)=>{c=m,s=O});_.catch(()=>{}),this.#r.set(n,_);let u;try{u=await this.#c(e)}catch(m){s?.(m);try{let O=await this.#a({schema_version:1,command:"rollback",lease:i});this.#t(O.receipts,!1)}catch{}throw this.#r.delete(n),m}let l;try{l=await this.#a({schema_version:1,command:"commit",lease:i,compiled_bytes:u.compiled_bytes})}catch(m){throw s?.(m),await this.#e(i),this.#r.delete(n),m}let d;try{d=this.#t(l.receipts,!0)}catch(m){throw s?.(m),this.#r.delete(n),await this.#e(i),m}if(this.#r.delete(n),l.action==="NOOP"||d===null){let m=new p("COMMIT_NOT_ACCEPTED");throw s?.(m),await this.#e(i),m}if(d.action==="PUBLISH_COMPILED_MODULE")return this.#R(n,o,u.module),c?.({module:u.module,retained:!0}),await this.#e(i),{module:u.module,outcome:d.outcome,action:d.action,served_from_cache:!1,retained:!0,retried:a};if(d.action==="COMPILE_WITHOUT_CACHE")return c?.({module:u.module,retained:!1}),await this.#e(i),{module:u.module,outcome:d.outcome,action:d.action,served_from_cache:!1,retained:!1,retried:a};let E=new v(d.outcome,d.action,d.disposition,!1);if(s?.(E),await this.#e(i),d.disposition==="RETRY")return new P(d.outcome,d.action);throw E}async#b(e,r,n){let o=this.#t(r.receipts,!0);if(o===null)throw new p("EVALUATOR_PROTOCOL");if(o.disposition==="RETRY")return new P(o.outcome,o.action);if(o.action==="COMPILE_WITHOUT_CACHE")return{module:(await this.#c(e)).module,outcome:o.outcome,action:o.action,served_from_cache:!1,retained:!1,retried:n};throw new v(o.outcome,o.action,o.disposition,!1)}#t(e,r){let n=null;for(let o=0;o<e.length;o+=1){let a=ge(e[o]);o===e.length-1&&(n=a),e[o].compiled_bytes_measured&&(a.action==="DROP_OPAQUE_HANDLE"||a.action==="DISCARD_COMPILED_MODULE"||a.action==="RELEASE_FAILED_COMPILE")&&(this.#_+=1,this.#N(Re(e[o])))}return r?n:null}#g(e,r){let n=this.#t(e.receipts,!0);if(n===null||n.action!==r)throw new p("EVALUATOR_PROTOCOL");return n}#R(e,r,n){this.#o.set(e,n);let o=this.#i.get(r);if(o===void 0){this.#i.set(r,new Set([e]));return}o.add(e)}#N(e){let r=this.#i.get(e);if(r!==void 0){for(let n of r)this.#o.delete(n);this.#i.delete(e)}}async#e(e){if(e!==null)try{let r=await this.#a({schema_version:1,command:"release",lease:e});this.#t(r.receipts,!1)}catch(r){this.#p(r)}}async#h(){if(this.#d)throw new p("EVALUATOR_CLOSED");this.#f??=(async()=>{if((await this.#s.send({schema_version:1,command:"configure",budget:this.#y})).action!=="CONFIGURED")throw new p("EVALUATOR_PROTOCOL")})().catch(e=>{throw this.#f=null,e}),await this.#f}async#a(e){if(this.#d)throw new p("EVALUATOR_CLOSED");try{return await this.#s.send(e)}catch(r){throw r instanceof p&&r.code==="EVALUATOR_CLOSED"&&(this.#d=!0,this.#o.clear(),this.#i.clear(),this.#r.clear()),r}}};function nt(t){if(t===null||typeof t!="object"||Array.isArray(t))throw new p("EVALUATOR_PROTOCOL");let e=t;if(e.schema_version!==1||typeof e.action!="string")throw new p("EVALUATOR_PROTOCOL");if(!Array.isArray(e.receipts))throw new p("EVALUATOR_PROTOCOL");if(e.lease!==null&&(!Number.isSafeInteger(e.lease)||e.lease<1))throw new p("EVALUATOR_PROTOCOL");return t}function Te(t){let e=[],r="",n=null;t.readable.setEncoding?.("utf8"),t.readable.on("data",a=>{r+=typeof a=="string"?a:a.toString("utf8");let i=r.indexOf(`
|
|
6
6
|
`);for(;i>=0;){let c=r.slice(0,i).replace(/\r$/u,"");if(r=r.slice(i+1),i=r.indexOf(`
|
|
7
7
|
`),c.length===0)continue;let s=e.shift();if(s===void 0){n=new p("EVALUATOR_PROTOCOL");continue}try{s.resolve(nt(JSON.parse(c)))}catch(_){s.reject(_)}}});let o=a=>{n=a;for(let i of e.splice(0,e.length))i.reject(a)};return t.readable.on("end",()=>{o(new p("EVALUATOR_CLOSED"))}),t.readable.on("close",()=>{o(new p("EVALUATOR_CLOSED"))}),t.readable.on("error",()=>{o(new p("EVALUATOR_PROTOCOL"))}),{async send(a){if(n!==null)throw n;return new Promise((i,c)=>{let s={resolve:i,reject:c};e.push(s);try{t.writable.write(`${JSON.stringify(a)}
|
|
8
|
-
`)}catch(_){let u=e.indexOf(s);u>=0&&e.splice(u,1),c(_)}})},async close(){o(new p("EVALUATOR_CLOSED")),await t.close()}}}function ot(t,e,r){try{return(0,Oe.spawn)(t.binaryPath,[...e],{stdio:["pipe","pipe","ignore"],windowsHide:!0})}catch(n){throw r(),n}}function it(t){if(t.args!==void 0&&(!Array.isArray(t.args)||t.args.length!==2||t.args[0]!=="compile-cache"||t.args[1]!=="session"))throw new p("EVALUATOR_PROTOCOL");let e=q(),r={packageVersion:j,...e===void 0?{}:{manifestDigest:e}},n=X(U,process.platform,process.arch,r),o=process.platform,a=process.arch,i=!1;try{i=_e(t.command,o,a)}catch{i=!1}if(!i)throw new p("NATIVE_INTEGRITY_REJECTED");let c=re(t.command,o,a);if(!c)throw new p("NATIVE_INTEGRITY_REJECTED");let s=!1,_=()=>{s||(s=!0,c.cleanup())},u;try{u=Q(c.path,n,r,!0)}catch(E){throw _(),E}if(fe(u,o,void 0,{path:c.path,arch:a}),u.kind==="Blocked")throw _(),new p("NATIVE_HANDSHAKE_REJECTED",u.receipt.reasonCode);u.advisoryReceipt&&process.stderr.write(Z(u.advisoryReceipt));let l=ot(u.launch,t.args??["compile-cache","session"],_);if(l.once("close",_),l.once("error",_),l.stdin===null||l.stdout===null)throw l.stdin?.destroy(),l.stdout?.destroy(),l.kill(),_(),new p("EVALUATOR_PROTOCOL");let d=()=>{l.stdout?.destroy()};return l.on("error",d),l.stdin.on("error",d),
|
|
8
|
+
`)}catch(_){let u=e.indexOf(s);u>=0&&e.splice(u,1),c(_)}})},async close(){o(new p("EVALUATOR_CLOSED")),await t.close()}}}function ot(t,e,r){try{return(0,Oe.spawn)(t.binaryPath,[...e],{stdio:["pipe","pipe","ignore"],windowsHide:!0})}catch(n){throw r(),n}}function it(t){if(t.args!==void 0&&(!Array.isArray(t.args)||t.args.length!==2||t.args[0]!=="compile-cache"||t.args[1]!=="session"))throw new p("EVALUATOR_PROTOCOL");let e=q(),r={packageVersion:j,...e===void 0?{}:{manifestDigest:e}},n=X(U,process.platform,process.arch,r),o=process.platform,a=process.arch,i=!1;try{i=_e(t.command,o,a)}catch{i=!1}if(!i)throw new p("NATIVE_INTEGRITY_REJECTED");let c=re(t.command,o,a);if(!c)throw new p("NATIVE_INTEGRITY_REJECTED");let s=!1,_=()=>{s||(s=!0,c.cleanup())},u;try{u=Q(c.path,n,r,!0)}catch(E){throw _(),E}if(fe(u,o,void 0,{path:c.path,arch:a}),u.kind==="Blocked")throw _(),new p("NATIVE_HANDSHAKE_REJECTED",u.receipt.reasonCode);u.advisoryReceipt&&process.stderr.write(Z(u.advisoryReceipt));let l=ot(u.launch,t.args??["compile-cache","session"],_);if(l.once("close",_),l.once("error",_),l.stdin===null||l.stdout===null)throw l.stdin?.destroy(),l.stdout?.destroy(),l.kill(),_(),new p("EVALUATOR_PROTOCOL");let d=()=>{l.stdout?.destroy()};return l.on("error",d),l.stdin.on("error",d),Te({writable:l.stdin,readable:l.stdout,close:()=>{l.stdin?.end(),l.kill()}})}0&&(module.exports={CompileCacheRejectedError,CompileCacheRuntime,CompileCacheRuntimeError,createNdjsonCompileCacheEvaluator,spawnCompileCacheEvaluator});
|