@maiaos/node 0.1.0-canary.12 → 0.1.0-canary.13

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.
@@ -253,7 +253,7 @@
253
253
  "version": "2.21.0"
254
254
  },
255
255
  {
256
- "bom-ref": "@maiaos/agent@0.1.0-canary.12",
256
+ "bom-ref": "@maiaos/agent@0.1.0-canary.13",
257
257
  "name": "@maiaos/agent",
258
258
  "properties": [
259
259
  {
@@ -265,13 +265,13 @@
265
265
  "value": "packages/agent"
266
266
  }
267
267
  ],
268
- "purl": "pkg:npm/%40maiaos/agent@0.1.0-canary.12",
268
+ "purl": "pkg:npm/%40maiaos/agent@0.1.0-canary.13",
269
269
  "scope": "required",
270
270
  "type": "library",
271
- "version": "0.1.0-canary.12"
271
+ "version": "0.1.0-canary.13"
272
272
  },
273
273
  {
274
- "bom-ref": "@maiaos/protocol@0.1.0-canary.12",
274
+ "bom-ref": "@maiaos/protocol@0.1.0-canary.13",
275
275
  "name": "@maiaos/protocol",
276
276
  "properties": [
277
277
  {
@@ -283,13 +283,13 @@
283
283
  "value": "packages/protocol"
284
284
  }
285
285
  ],
286
- "purl": "pkg:npm/%40maiaos/protocol@0.1.0-canary.12",
286
+ "purl": "pkg:npm/%40maiaos/protocol@0.1.0-canary.13",
287
287
  "scope": "required",
288
288
  "type": "library",
289
- "version": "0.1.0-canary.12"
289
+ "version": "0.1.0-canary.13"
290
290
  },
291
291
  {
292
- "bom-ref": "@maiaos/sdk@0.1.0-canary.12",
292
+ "bom-ref": "@maiaos/sdk@0.1.0-canary.13",
293
293
  "name": "@maiaos/sdk",
294
294
  "properties": [
295
295
  {
@@ -301,10 +301,10 @@
301
301
  "value": "packages/sdk"
302
302
  }
303
303
  ],
304
- "purl": "pkg:npm/%40maiaos/sdk@0.1.0-canary.12",
304
+ "purl": "pkg:npm/%40maiaos/sdk@0.1.0-canary.13",
305
305
  "scope": "required",
306
306
  "type": "library",
307
- "version": "0.1.0-canary.12"
307
+ "version": "0.1.0-canary.13"
308
308
  },
309
309
  {
310
310
  "bom-ref": "@silvia-odwyer/photon-node@0.3.4",
@@ -1908,7 +1908,7 @@
1908
1908
  },
1909
1909
  {
1910
1910
  "name": "maia:source-revision",
1911
- "value": "349404b24e33d6c130d9b352e4d3d6ccdfea8731"
1911
+ "value": "6ba12d869c441158b339971c20c02e21c32be894"
1912
1912
  },
1913
1913
  {
1914
1914
  "name": "maia:target-triple",
@@ -1949,7 +1949,7 @@
1949
1949
  ],
1950
1950
  "scope": "required",
1951
1951
  "type": "file",
1952
- "version": "0.1.0-canary.12"
1952
+ "version": "0.1.0-canary.13"
1953
1953
  },
1954
1954
  {
1955
1955
  "bom-ref": "file:maia-process-host-linux-x64@sha256:c4ee506fbfa9cac187f5e0e780ac13b594b5bf8ed576f8cceabbba0e6e6f1f4b",
@@ -1978,7 +1978,7 @@
1978
1978
  },
1979
1979
  {
1980
1980
  "name": "maia:source-revision",
1981
- "value": "349404b24e33d6c130d9b352e4d3d6ccdfea8731"
1981
+ "value": "6ba12d869c441158b339971c20c02e21c32be894"
1982
1982
  },
1983
1983
  {
1984
1984
  "name": "maia:target-triple",
@@ -2019,7 +2019,7 @@
2019
2019
  ],
2020
2020
  "scope": "required",
2021
2021
  "type": "file",
2022
- "version": "0.1.0-canary.12"
2022
+ "version": "0.1.0-canary.13"
2023
2023
  }
2024
2024
  ],
2025
2025
  "dependencies": [
@@ -2035,9 +2035,9 @@
2035
2035
  "@earendil-works/pi-tui@1.0.0",
2036
2036
  "@effect/platform-node-shared@4.0.0",
2037
2037
  "@google/genai@2.21.0",
2038
- "@maiaos/agent@0.1.0-canary.12",
2039
- "@maiaos/protocol@0.1.0-canary.12",
2040
- "@maiaos/sdk@0.1.0-canary.12",
2038
+ "@maiaos/agent@0.1.0-canary.13",
2039
+ "@maiaos/protocol@0.1.0-canary.13",
2040
+ "@maiaos/sdk@0.1.0-canary.13",
2041
2041
  "@silvia-odwyer/photon-node@0.3.4",
2042
2042
  "@stablelib/base64@1.0.1",
2043
2043
  "agent-base@7.1.4",
@@ -2104,7 +2104,7 @@
2104
2104
  "file:maia-process-host-darwin-arm64@sha256:26de48e2dfadc262dc48c5ae9bf91784603f6b1868e21216455918d022a721bc",
2105
2105
  "file:maia-process-host-linux-x64@sha256:c4ee506fbfa9cac187f5e0e780ac13b594b5bf8ed576f8cceabbba0e6e6f1f4b"
2106
2106
  ],
2107
- "ref": "@maiaos/node@0.1.0-canary.12"
2107
+ "ref": "@maiaos/node@0.1.0-canary.13"
2108
2108
  },
2109
2109
  {
2110
2110
  "dependsOn": [],
@@ -2148,15 +2148,15 @@
2148
2148
  },
2149
2149
  {
2150
2150
  "dependsOn": [],
2151
- "ref": "@maiaos/agent@0.1.0-canary.12"
2151
+ "ref": "@maiaos/agent@0.1.0-canary.13"
2152
2152
  },
2153
2153
  {
2154
2154
  "dependsOn": [],
2155
- "ref": "@maiaos/protocol@0.1.0-canary.12"
2155
+ "ref": "@maiaos/protocol@0.1.0-canary.13"
2156
2156
  },
2157
2157
  {
2158
2158
  "dependsOn": [],
2159
- "ref": "@maiaos/sdk@0.1.0-canary.12"
2159
+ "ref": "@maiaos/sdk@0.1.0-canary.13"
2160
2160
  },
2161
2161
  {
2162
2162
  "dependsOn": [],
@@ -2421,16 +2421,16 @@
2421
2421
  ],
2422
2422
  "metadata": {
2423
2423
  "component": {
2424
- "bom-ref": "@maiaos/node@0.1.0-canary.12",
2424
+ "bom-ref": "@maiaos/node@0.1.0-canary.13",
2425
2425
  "hashes": [
2426
2426
  {
2427
2427
  "alg": "SHA-256",
2428
- "content": "808b43807c21a4921bbdb91add3fd2f58b442bc2600f6acdf6ff800d33a33e67"
2428
+ "content": "da1d3731dbde70b70deee8c166accba128b6c9baca1e435de080fd2575d49b87"
2429
2429
  }
2430
2430
  ],
2431
2431
  "name": "@maiaos/node",
2432
2432
  "type": "application",
2433
- "version": "0.1.0-canary.12"
2433
+ "version": "0.1.0-canary.13"
2434
2434
  },
2435
2435
  "properties": [
2436
2436
  {
@@ -240,7 +240,7 @@ DO UPDATE SET count = count + excluded.count`,Gsn="DELETE FROM integration_autho
240
240
  ) VALUES (?, ?, 1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(...n)},Fcn=(e,t)=>{let r=jD(e,t);if(r!==void 0)return r;throw m("storage_corrupt","The integration plan was not persisted.")},Hcn=(e,t)=>{let r=`integration.plan.${t.integration}`,n=Lcn(t),o=jD(e,n.planId);if(o!==void 0)return Dcn(o,n),{method:r,plan:fne(o,t.integration)};Ucn(e,t.recordedAt,n);let i=Fcn(e,n.planId);return{method:r,plan:fne(i,t.integration)}},jHe=(e,t)=>wm(e,{...t,method:`integration.plan.${t.integration}`},()=>Hcn(e,t)),WHe=(e,t)=>{let r=Od(t.planId,"The integration plan identifier"),n=jD(e,r);if(n?.integration===t.integration)return fne(n,t.integration)}});var $D=M(()=>{"use strict";X0t();BD();eUt();nUt();Mg();NHe()});var Rhn,tM,N1t=M(()=>{"use strict";Rhn=/^SIG[A-Z\d]{1,8}$/u,tM=e=>e.state==="failed"?e.hostFailure===void 0?"its process host failed":`its process host failed at ${e.hostFailure.phase}/${e.hostFailure.code}`:e.code!==null?`exit code ${String(e.code)}`:e.signal!==null&&Rhn.test(e.signal)?`ended by ${e.signal}`:"exited"});var Hc,ch,dh,lh,Zne,Fg,rM,nM,oM,P1t=M(()=>{"use strict";Hc=Symbol("@maiaos/node/runtime/process/resource/authorized-spawn"),ch=Symbol("@maiaos/node/runtime/process/resource/revoke-codex-authorization"),dh=Symbol("@maiaos/node/runtime/process/resource/revoke-integration-authorization"),lh=Symbol("@maiaos/node/runtime/process/resource/revoke-pi-rpc-authorization"),Zne=Symbol("@maiaos/node/runtime/process/resource/verify-invocation-attachment-owner"),Fg=e=>Hc in e,rM=e=>ch in e,nM=e=>dh in e,oM=e=>lh in e});var iM,eoe,SG,O1t,sM,toe,cqe,vhn,L1t,dqe=M(()=>{"use strict";iM=["/bin/bash","/bin/zsh","/usr/bin/bash","/usr/bin/zsh"],eoe=["claude","codex"],SG="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",O1t='exec "$0" "$@"',sM=e=>iM.includes(e),toe=e=>eoe.includes(e),cqe=e=>e===void 0?["-l"]:["-l","-i","-c",O1t,e.name,...e.argv],vhn=e=>!e.includes("\0")&&Buffer.byteLength(e,"utf8")<=1024,L1t=e=>{if(e.length===1)return e[0]==="-l";let[t,r,n,o,i,...a]=e;return t==="-l"&&r==="-i"&&n==="-c"&&o===O1t&&i!==void 0&&toe(i)&&a.length<=32&&a.every(vhn)}});import{isAbsolute as aM,posix as Thn}from"node:path";var $e,cM,EG,Ihn,lqe,xhn,Ahn,Chn,bhn,whn,khn,Nhn,Phn,D1t,Ohn,Lhn,Dhn,Mhn,Uhn,Fhn,Hhn,Bhn,qhn,Bg,uqe,jhn,Whn,$hn,RA,Ghn,zhn,Vhn,roe,Jn,Hg,Z_,M1t,Khn,Xhn,Jhn,Yhn,Qhn,Zhn,eyn,tyn,ryn,nyn,oyn,iyn,syn,ayn,cyn,dyn,lyn,Pm,U1t=M(()=>{"use strict";q();$();dqe();$e={admissionWarningAvailableTrees:8,cleanupDeadlineMilliseconds:2e3,launchAcknowledgementDeadline:"2 seconds",maximumActiveTrees:128,maximumArgumentBytes:64*1024,maximumArguments:128,maximumCleanupAttempts:2,maximumConcurrentProcfsIdentityOpens:8,maximumCpuTimeMilliseconds:720*60*60*1e3,maximumDataChunkBytes:16*1024,maximumEnvironmentBytes:64*1024,maximumEnvironmentEntries:64,maximumEnvironmentKeyBytes:256,maximumFileDescriptorsPerProcess:65536,maximumIdentifierBytes:128,maximumIndividualArgumentBytes:16*1024,maximumInteractiveDataChunkBytes:32*1024,maximumMemoryBytes:64*1024*1024*1024,maximumPathBytes:4096,maximumPendingInputBytes:64*1024,maximumPendingOutputBytes:1024*1024,maximumPendingOutputChunks:256,maximumProcessCount:1024,maximumProcfsIoBytes:4096,maximumPsOutputBytes:8*1024*1024,maximumPsRows:65536,maximumRawSamplesPerTree:60,maximumTrackedMembersPerTree:1024,maximumWallTimeMilliseconds:10080*60*1e3,sampleInterval:"1 second",samplerDeadline:"500 millis",streamOfferDeadline:"250 millis",terminalAcknowledgementDeadline:"2 seconds",terminalCloseAcknowledgementDeadline:"4 seconds"},cM=e=>Buffer.byteLength(e,"utf8"),EG=(e,t)=>e.length>0&&cM(e)<=t&&!e.includes("\0"),Ihn=e=>[e.commandId,e.sessionId,e.taskId,e.terminalId,e.workspaceId],lqe=(e,t)=>e.commandId!==void 0&&e.sessionId!==void 0&&e.taskId===void 0&&e.terminalId===void 0&&(t?e.workspaceId!==void 0:e.workspaceId===void 0),xhn=e=>e.commandId!==void 0&&e.workspaceId!==void 0&&e.sessionId===void 0&&e.terminalId===void 0,Ahn=e=>e.commandId!==void 0&&e.sessionId===void 0&&e.taskId===void 0&&e.terminalId===void 0&&e.workspaceId===void 0,Chn=e=>Ihn(e).every(t=>t===void 0||EG(t,$e.maximumIdentifierBytes)),bhn=e=>{if(!Chn(e))return!1;switch(e.kind){case"claude-code-session":case"codex-session":return e.sessionId!==void 0&&e.workspaceId!==void 0;case"codex-probe":return e.commandId!==void 0&&e.sessionId===void 0;case"execution-command":return xhn(e);case"git-inspection":return e.commandId!==void 0||e.workspaceId!==void 0;case"interactive-terminal":return e.terminalId!==void 0&&e.workspaceId!==void 0&&e.sessionId===void 0;case"pi-managed-session":return lqe(e,!0);case"pi-rpc-probe":return lqe(e,!1);case"pi-rpc-session":return lqe(e,!0);case"secret-store":return Ahn(e)}},whn=new Set(["COLORTERM","HOME","LANG","LC_ALL","LC_COLLATE","LC_CTYPE","LC_MESSAGES","LC_MONETARY","LC_NUMERIC","LC_TIME","LOGNAME","MAIA_TERMINAL_PANE","PATH","SHELL","TERM","USER"]),khn=new Set(["LANG","LC_ALL","LC_COLLATE","LC_CTYPE","LC_MESSAGES","LC_MONETARY","LC_NUMERIC","LC_TIME"]),Nhn=e=>e!==void 0&&cM(e)<=64&&/^(?:C|POSIX|[A-Za-z]{2,3}(?:_[A-Za-z]{2})?(?:\.[A-Za-z0-9-]+)?(?:@[A-Za-z0-9-]+)?)$/u.test(e),Phn=e=>Number.isSafeInteger(e.columns)&&e.columns>=2&&e.columns<=500&&Number.isSafeInteger(e.generation)&&e.generation>=1&&e.generation<=65535&&Number.isSafeInteger(e.nativeOperationSequence)&&e.nativeOperationSequence>=1&&e.nativeOperationSequence<=2147483647&&Number.isSafeInteger(e.rows)&&e.rows>=2&&e.rows<=300,D1t=e=>{let t=e.repositoryAuthority;return t?.rootPath===e.workingDirectory&&aM(t.rootPath)&&aM(t.gitCommonDirectory)&&[t.rootDevice,t.rootInode,t.gitCommonDevice,t.gitCommonInode].every(r=>/^(?:0|[1-9]\d*)$/u.test(r))},Ohn=(e,t)=>{let r=Object.keys(e),n=e.USER;return typeof e.HOME=="string"&&aM(e.HOME)&&typeof n=="string"&&/^[A-Za-z0-9._-]{1,128}$/u.test(n)&&e.LOGNAME===n&&e.SHELL===t&&e.PATH===SG&&e.TERM==="xterm-256color"&&e.COLORTERM==="truecolor"&&(e.MAIA_TERMINAL_PANE??"1")==="1"&&r.filter(o=>khn.has(o)).every(o=>Nhn(e[o]))&&r.every(o=>whn.has(o))},Lhn=e=>{let t=e.interactiveTerminal;return e.owner.kind!=="interactive-terminal"?t===void 0:t===void 0?!1:sM(e.executable)&&L1t(e.arguments_)&&e.standardInput==="pipe"&&Phn(t)&&t.terminalId===e.owner.terminalId&&D1t(e)&&Ohn(e.environment,e.executable)},Dhn=/^secret_store_[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/u,Mhn=new Map([["/usr/bin/security",[["-i"]]],["/usr/bin/systemd-creds",[["--version"],["--user","--name=maia.secret.v1","--with-key=host","encrypt","-","-"],["--user","--name=maia.secret.v1","decrypt","-","-"]]]]),Uhn=(e,t)=>e.length===t.length&&e.every((r,n)=>r===t[n]),Fhn=e=>e.owner.kind!=="secret-store"||(Mhn.get(e.executable)??[]).some(t=>Uhn(t,e.arguments_))&&Object.keys(e.environment).length===0&&e.standardInput==="pipe"&&e.workingDirectory==="/"&&Dhn.test(e.owner.commandId??""),Hhn=e=>{if(!Wt.isObjectOrArray(e)||Z_(e)!=="non_array")return;let t=Jn(e,"gitCommonDirectory"),r=Jn(e,"gitCommonDevice"),n=Jn(e,"gitCommonInode"),o=Jn(e,"rootDevice"),i=Jn(e,"rootInode"),a=Jn(e,"rootPath");if(!(typeof t!="string"||typeof r!="string"||typeof n!="string"||typeof o!="string"||typeof i!="string"||typeof a!="string"))return Object.freeze({gitCommonDevice:r,gitCommonDirectory:t,gitCommonInode:n,rootDevice:o,rootInode:i,rootPath:a})},Bhn=e=>Object.entries(e).reduce((t,[r,n])=>t+cM(r)+(n===void 0?0:cM(n)),0),qhn=e=>e.reduce((t,r)=>t+cM(r),0),Bg=e=>m("transport_failed",e),uqe=()=>Bg("The managed process launch request is invalid."),jhn=e=>aM(e.executable)&&aM(e.workingDirectory)&&EG(e.executable,$e.maximumPathBytes)&&EG(e.workingDirectory,$e.maximumPathBytes)?void 0:Bg("The managed process path is invalid."),Whn=e=>e.arguments_.length<=$e.maximumArguments&&qhn(e.arguments_)<=$e.maximumArgumentBytes&&e.arguments_.every(t=>cM(t)<=$e.maximumIndividualArgumentBytes&&!t.includes("\0"))?void 0:Bg("The managed process arguments exceed their bound."),$hn=e=>{let t=Object.entries(e.environment);return t.length>$e.maximumEnvironmentEntries||Bhn(e.environment)>$e.maximumEnvironmentBytes||t.some(([n,o])=>!EG(n,$e.maximumEnvironmentKeyBytes)||!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(n)||o?.includes("\0")===!0)?Bg("The managed process environment exceeds its bound."):void 0},RA=(e,t)=>Number.isSafeInteger(e)&&e>0&&e<=t,Ghn=e=>{let{limits:t}=e;return RA(t.maximumCpuTimeMilliseconds,$e.maximumCpuTimeMilliseconds)&&RA(t.maximumProcessCount,$e.maximumProcessCount)&&RA(t.maximumMemoryBytes,$e.maximumMemoryBytes)&&RA(t.maximumWallTimeMilliseconds,$e.maximumWallTimeMilliseconds)?void 0:Bg("The managed process limits are invalid.")},zhn=e=>{let{owner:t,streamLimits:r}=e,n=t.kind==="interactive-terminal"?$e.maximumInteractiveDataChunkBytes:$e.maximumDataChunkBytes;return RA(r.maximumDataChunkBytes,n)&&RA(r.maximumPendingInputBytes,$e.maximumPendingInputBytes)&&RA(r.maximumPendingOutputBytes,$e.maximumPendingOutputBytes)?void 0:Bg("The managed process stream limits are invalid.")},Vhn=e=>{let t=jhn(e)??Whn(e)??$hn(e)??syn(e)??ayn(e)??Ghn(e)??zhn(e);if(t!==void 0)return t;let r=e.owner.kind!=="execution-command"||D1t(e);return bhn(e.owner)&&Lhn(e)&&Fhn(e)&&r?void 0:Bg("The managed process owner is invalid.")},roe=Symbol("invalid process launch value"),Jn=(e,t)=>{try{let r=Object.getOwnPropertyDescriptor(e,t);return r!==void 0&&"value"in r?r.value:roe}catch{return roe}},Hg=(e,t)=>{try{let r=Object.getOwnPropertyDescriptor(e,t);return r===void 0?void 0:"value"in r?r.value:roe}catch{return roe}},Z_=e=>{try{return Array.isArray(e)?"array":"non_array"}catch{return"uninspectable"}},M1t=e=>{if(!Wt.isObjectOrArray(e)||Z_(e)!=="array")return;let t=Jn(e,"length");if(typeof t!="number"||!Number.isSafeInteger(t)||t<0||t>$e.maximumArguments)return;let r=Array.from({length:t},(n,o)=>Jn(e,String(o)));if(r.every(n=>typeof n=="string"))return Object.freeze(r)},Khn=e=>{try{return Reflect.ownKeys(e)}catch{return}},Xhn=e=>{if(!Wt.isObjectOrArray(e)||Z_(e)!=="non_array")return;let t=Khn(e);if(t===void 0||t.length>$e.maximumEnvironmentEntries||t.some(o=>typeof o!="string"))return;let r=t.map(o=>[o,Jn(e,o)]);if(!r.some(([,o])=>o!==void 0&&typeof o!="string"))return Object.freeze(Object.fromEntries(r.filter(o=>typeof o[1]=="string")))},Jhn=e=>{if(!Wt.isObjectOrArray(e)||Z_(e)!=="non_array")return;let t=Jn(e,"maximumCpuTimeMilliseconds"),r=Jn(e,"maximumProcessCount"),n=Jn(e,"maximumMemoryBytes"),o=Jn(e,"maximumWallTimeMilliseconds");if(!(typeof t!="number"||typeof r!="number"||typeof n!="number"||typeof o!="number"))return Object.freeze({maximumCpuTimeMilliseconds:t,maximumMemoryBytes:n,maximumProcessCount:r,maximumWallTimeMilliseconds:o})},Yhn=e=>{if(!Wt.isObjectOrArray(e)||Z_(e)!=="non_array")return;let t=Jn(e,"maximumDataChunkBytes"),r=Jn(e,"maximumPendingInputBytes"),n=Jn(e,"maximumPendingOutputBytes");if(!(typeof t!="number"||typeof r!="number"||typeof n!="number"))return Object.freeze({maximumDataChunkBytes:t,maximumPendingInputBytes:r,maximumPendingOutputBytes:n})},Qhn=e=>e===void 0||typeof e=="string",Zhn=e=>e==="claude-code-session"||e==="codex-probe"||e==="codex-session"||e==="execution-command"||e==="git-inspection"||e==="interactive-terminal"||e==="pi-managed-session"||e==="pi-rpc-probe"||e==="pi-rpc-session"||e==="secret-store",eyn=(e,t)=>{let[r,n,o,i,a]=t;return Object.freeze({...r===void 0?{}:{commandId:r},kind:e,...n===void 0?{}:{sessionId:n},...o===void 0?{}:{taskId:o},...i===void 0?{}:{terminalId:i},...a===void 0?{}:{workspaceId:a}})},tyn=e=>{if(!Wt.isObjectOrArray(e)||Z_(e)!=="non_array")return;let t=Jn(e,"kind"),r=Hg(e,"commandId"),n=Hg(e,"sessionId"),o=Hg(e,"taskId"),i=Hg(e,"terminalId"),a=Hg(e,"workspaceId"),c=[r,n,o,i,a];if(!(!Zhn(t)||!c.every(Qhn)))return eyn(t,c)},ryn=e=>{if(!Wt.isObjectOrArray(e)||Z_(e)!=="non_array")return;let t=Jn(e,"columns"),r=Jn(e,"generation"),n=Jn(e,"nativeOperationSequence"),o=Jn(e,"rows"),i=Jn(e,"terminalId");if(!(typeof t!="number"||typeof r!="number"||typeof n!="number"||typeof o!="number"||typeof i!="string"))return Object.freeze({columns:t,generation:r,nativeOperationSequence:n,rows:o,terminalId:i})},nyn=8,oyn=e=>{let t=M1t(e);return t!==void 0&&t.length>0&&t.length<=nyn?t:void 0},iyn=new Set(["claude-code-session"]),syn=e=>e.readDenials===void 0||iyn.has(e.owner.kind)&&e.readDenials.every(t=>aM(t)&&t!=="/"&&Thn.normalize(t)===t&&!t.endsWith("/")&&EG(t,$e.maximumPathBytes)&&!t.includes("\0")&&!t.includes(`
241
241
  `))?void 0:Bg("The managed process read denials are invalid."),ayn=e=>e.filesystem===void 0||e.filesystem==="vendor-sandbox"&&e.owner.kind==="claude-code-session"&&e.readDenials===void 0?void 0:Bg("The managed process filesystem mode is invalid."),cyn=(e,t)=>({arguments_:M1t(Jn(e,"arguments_")),environment:Xhn(Jn(e,"environment")),executable:Jn(e,"executable"),...t.filesystemValue===void 0?{}:{filesystem:t.filesystemValue},interactiveTerminal:ryn(t.interactiveTerminalValue),limits:Jhn(Jn(e,"limits")),owner:tyn(Jn(e,"owner")),...t.readDenialsValue===void 0?{}:{readDenials:oyn(t.readDenialsValue)},repositoryAuthority:Hhn(t.repositoryAuthorityValue),standardInput:Jn(e,"standardInput"),streamLimits:Yhn(Jn(e,"streamLimits")),workingDirectory:Jn(e,"workingDirectory")}),dyn=(e,t)=>e.arguments_!==void 0&&e.environment!==void 0&&typeof e.executable=="string"&&e.limits!==void 0&&e.owner!==void 0&&(e.standardInput==="ignore"||e.standardInput==="pipe")&&e.streamLimits!==void 0&&typeof e.workingDirectory=="string"&&(t.interactiveTerminalValue===void 0||e.interactiveTerminal!==void 0)&&(t.repositoryAuthorityValue===void 0||e.repositoryAuthority!==void 0)&&(t.readDenialsValue===void 0||e.readDenials!==void 0),lyn=e=>{let t={filesystemValue:Hg(e,"filesystem"),interactiveTerminalValue:Hg(e,"interactiveTerminal"),readDenialsValue:Hg(e,"readDenials"),repositoryAuthorityValue:Hg(e,"repositoryAuthority")},r=cyn(e,t);return dyn(r,t)?r:void 0},Pm=e=>{if(!Wt.isObjectOrArray(e))return{error:uqe(),state:"invalid"};if(Z_(e)!=="non_array")return{error:uqe(),state:"invalid"};let t=lyn(e);if(t===void 0)return{error:uqe(),state:"invalid"};let r=Object.freeze(t),n=Vhn(r);return n===void 0?{request:r,state:"valid"}:{error:n,state:"invalid"}}});var gi=M(()=>{"use strict";N1t();P1t();U1t();dqe()});import{lstat as pIn,realpath as mIn}from"node:fs/promises";var qqt,jqt,Bie,Wqt=M(()=>{"use strict";q();$();qqt=()=>m("repository_invalid","The repository authority changed at the process launch boundary."),jqt=s.fn("ProcessResourceManager.verifyDirectory")(function*(e,t){let[r,n]=yield*s.tryPromise({catch:qqt,try:()=>Promise.all([mIn(e),pIn(e,{bigint:!0})])}),o=typeof process.getuid!="function"||n.uid===BigInt(process.getuid());if(r!==e||!n.isDirectory()||n.isSymbolicLink()||!o||n.dev!==BigInt(t.device)||n.ino!==BigInt(t.inode))return yield*s.fail(qqt())}),Bie=s.fn("ProcessResourceManager.verifyLaunchAuthority")(function*(e){if(e.owner.kind!=="interactive-terminal"&&e.owner.kind!=="execution-command")return;let t=e.repositoryAuthority;if(e.workingDirectory!==t?.rootPath)return yield*s.fail(m("repository_invalid","The managed process repository authority is unavailable."));yield*jqt(t.rootPath,{device:t.rootDevice,inode:t.rootInode}),yield*jqt(t.gitCommonDirectory,{device:t.gitCommonDevice,inode:t.gitCommonInode})})});import{userInfo as fIn}from"node:os";var hIn,yIn,Vqt,$qt,gIn,Gqt,SIn,zqt,EIn,vje,JG,YG,Tje=M(()=>{"use strict";md();q();$();hIn=16,yIn=2,Vqt=(e,t)=>{if(e.uid!==t.uid&&e.uid!==0)return"foreign_owner";if((e.mode&yIn)!==0)return"writable_by_others";if((e.mode&hIn)!==0)return e.gid===t.privateGroupId?void 0:"writable_by_others"},$qt=e=>e.split(`
242
242
  `).filter(t=>t.length>0).map(t=>t.split(":")),gIn=/^\d+$/u,Gqt=(e,t)=>e!==void 0&&gIn.test(e)&&Number(e)===t,SIn=e=>{if(e.user.length===0)return;let t=$qt(e.group).filter(i=>Gqt(i[2],e.gid)),r=t[0],n=r?.[3]??"";return t.length!==1||r?.[0]!==e.user||n!==""&&n!==e.user||$qt(e.passwd).some(i=>Gqt(i[3],e.gid)&&i[0]!==e.user)?void 0:e.gid},zqt=(e,t)=>e.readFileString(t).pipe(s.option),EIn=s.fnUntraced(function*(e){let t=yield*s.try(()=>fIn().username).pipe(s.option),r=yield*Ue.FileSystem,n=yield*zqt(r,"/etc/passwd"),o=yield*zqt(r,"/etc/group");if(K.isNone(t)||K.isNone(n)||K.isNone(o))return{};let i=SIn({gid:e,group:o.value,passwd:n.value,user:t.value});return i===void 0?{}:{privateGroupId:i}}),vje=s.gen(function*(){if(typeof process.geteuid!="function"||typeof process.getegid!="function")return yield*s.fail(m("configuration_invalid","The vouch policy needs POSIX user ids, which this platform lacks."));let e=process.geteuid();return{...yield*EIn(process.getegid()),uid:e}}).pipe(s.provide(On)),JG=["private_gid() {",' [ -n "$3" ] && [ -n "$4" ] || return 1',` u="$3" g="$4" awk -F: '$3 ~ /^[0-9]+$/ && $3 == ENVIRON["g"] + 0 { n++; if ($1 != ENVIRON["u"] "" || ($4 != "" && $4 != ENVIRON["u"] "")) bad = 1 } END { exit (n == 1 && !bad) ? 0 : 1 }' "$2" || return 1`,` u="$3" g="$4" awk -F: '$4 ~ /^[0-9]+$/ && $4 == ENVIRON["g"] + 0 && $1 != ENVIRON["u"] "" { bad = 1 } END { exit bad ? 1 : 0 }' "$1" || return 1`,` printf '%s' "$4"`,"}"].join(`
243
- `),YG='user_writes_only() { { [ "$1" = "$uid" ] || [ "$1" = 0 ]; } && [ $(( 0$3 & 002 )) -eq 0 ] && { [ $(( 0$3 & 020 )) -eq 0 ] || { [ -n "$upg" ] && [ "$2" = "$upg" ]; }; }; }'});import{createHash as _In,timingSafeEqual as RIn}from"node:crypto";import{constants as qie,fstatSync as vIn,lstatSync as TIn}from"node:fs";import{lstat as jie,open as Kqt}from"node:fs/promises";import{isAbsolute as Ije,resolve as xje}from"node:path";var IIn,xIn,Xqt,AIn,CIn,bIn,Jqt,jg,Yqt,wA,wIn,kIn,NIn,PIn,QG,OIn,LIn,DIn,MIn,UIn,FIn,Qqt,HIn,BIn,qIn,jIn,WIn,$In,GIn,lR,Zqt,zIn,VIn,ZG,e2,Wie,ejt=M(()=>{"use strict";q();$();Tje();IIn=256*1024*1024,xIn=64*1024,Xqt=/^[0-9a-f]{64}$/u,AIn=64,CIn=4095,bIn=new Set(["claude-code","codex"]),Jqt=e=>{switch(e){case"claude-code":return["claude-code-session"];case"codex":return["codex-probe","codex-session"];case"pi-rpc":return["pi-rpc-probe","pi-rpc-session"];case"git":case"security":case"systemd-creds":case"terminal":return[]}},jg=()=>m("transport_failed","The requested executable is not admitted by the vouch policy."),Yqt=e=>({changedAtNanoseconds:e.ctimeNs,device:e.dev,inode:e.ino,modifiedAtNanoseconds:e.mtimeNs,size:e.size}),wA=(e,t)=>e.ctimeNs===t.changedAtNanoseconds&&e.dev===t.device&&e.ino===t.inode&&e.mtimeNs===t.modifiedAtNanoseconds&&e.size===t.size,wIn=e=>e.uid===0n?e.nlink>0n:e.nlink===1n,kIn=e=>`0${(Number(e.mode)&CIn).toString(8)}`,NIn=({adapter:e,path:t},r)=>{if(r.isSymbolicLink())return`${t}: a symbolic link; fix: approve the file it points to.`;if(!r.isFile())return`${t}: not a regular file.`;if(r.size===0n)return`${t}: an empty file.`;if(!bIn.has(e)&&r.size>BigInt(IIn))return`${t}: ${r.size.toString()} bytes, over the 256 MiB limit.`},PIn=(e,t,r)=>{let n=NIn(e,t);if(n!==void 0)return n;let{path:o}=e,i=kIn(t),a=Vqt({gid:Number(t.gid),mode:Number(t.mode),uid:Number(t.uid)},r);if(a==="foreign_owner")return`${o}: mode ${i}, owner uid ${t.uid.toString()}, not this user (${String(r.uid)}) or root; fix: install it as this user.`;if(a==="writable_by_others")return`${o}: mode ${i}, gid ${t.gid.toString()}, writable by others or a shared group; fix: chmod go-w on it.`;if(!wIn(t))return`${o}: ${t.nlink.toString()} hard links; fix: approve a copy with one link.`;if((Number(t.mode)&AIn)===0)return`${o}: mode ${i}, not executable by its owner; fix: chmod u+x on it.`},QG=(e,t,r)=>{let n=PIn(e,t,r);if(n!==void 0)throw m("configuration_invalid",`The vouch policy refuses ${n}`)},OIn=(e,t)=>{let r=Buffer.from(t,"hex");return e.byteLength===r.byteLength&&RIn(e,r)},LIn=(e,t)=>{switch(e.adapter){case"git":return t==="git-inspection";case"security":case"systemd-creds":return t==="secret-store";case"terminal":return t==="interactive-terminal";case"claude-code":case"codex":case"pi-rpc":return Jqt(e.adapter).includes(t)}},DIn=(e,t)=>{switch(e.adapter){case"git":return t.selectedTier==="vouched_runtime"||t.selectedTier==="hard_containment";case"security":return t.selectedTier==="vouched_runtime";case"systemd-creds":return t.selectedTier==="hard_containment";case"terminal":return t.selectedTier==="local_user_interactive_terminal";case"claude-code":case"codex":return t.selectedTier==="cooperative_multi_pgid"||t.selectedTier==="hard_containment";case"pi-rpc":return t.selectedTier==="cooperative_pi_rpc_conversation"}},MIn=(e,t)=>{let r=t.find(n=>n.executablePath===e.executable&&n.ownerKinds.includes(e.owner.kind));if(r===void 0||!LIn(r,e.owner.kind)||!DIn(r,e)||!Ije(r.executablePath)||xje(r.executablePath)!==r.executablePath||!Xqt.test(r.sha256)||r.adapterVersion.length===0||r.sandboxPolicyRevision.length===0||r.adapter==="pi-rpc"&&(r.conversationPolicyRevision===void 0||r.conversationPolicyRevision.length===0)||r.vouchPolicyRevision.length===0)throw jg();return r},UIn=e=>{QG(e,e.openedMetadata,e.user);let t=Yqt(e.openedMetadata);if(!wA(e.pathMetadata,t)||!wA(e.currentMetadata,t)||!OIn(e.digest,e.expectedDigest))throw jg();return t},FIn=async e=>UIn({adapter:e.expectation.adapter,currentMetadata:await jie(e.expectation.executablePath,{bigint:!0}),digest:await Qqt(e.handle,e.pathMetadata.size,e.signal),expectedDigest:e.expectation.sha256,openedMetadata:await e.handle.stat({bigint:!0}),path:e.expectation.executablePath,pathMetadata:e.pathMetadata,user:e.user}),Qqt=async(e,t,r)=>{let n=_In("sha256"),o=Buffer.allocUnsafe(xIn),i=Number(t),a=async c=>{if(c>=i)return;r.throwIfAborted();let{bytesRead:l}=await e.read(o,0,Math.min(o.byteLength,i-c),c);if(l<=0)throw jg();n.update(o.subarray(0,l)),await a(c+l)};return await a(0),r.throwIfAborted(),n.digest()},HIn=async(e,t)=>{let[r,n]=await Promise.all([e.handle.stat({bigint:!0}),jie(e.path,{bigint:!0})]);if(!wA(r,t)||!wA(n,t))throw jg()},BIn=(e,t,r)=>({device:t.device.toString(),inode:t.inode.toString(),path:e,sha256:r.toString("hex"),sizeBytes:t.size.toString()}),qIn=async e=>{let t=await e.handle.stat({bigint:!0});QG(e,t,e.user);let r=Yqt(t);if(!wA(e.pathMetadata,r))throw jg();let n=await Qqt(e.handle,t.size,e.signal);return await HIn(e,r),BIn(e.path,r,n)},jIn=async(e,t,r)=>{let{path:n}=e;if(!Ije(n)||xje(n)!==n)throw jg();let o=await jie(n,{bigint:!0});QG(e,o,t);let i=await Kqt(n,qie.O_RDONLY|qie.O_NOFOLLOW);try{return await qIn({...e,handle:i,pathMetadata:o,signal:r,user:t})}finally{await i.close()}},WIn=e=>({adapter:e.adapter,path:e.executablePath}),$In=async(e,t,r)=>{let n=await jie(e.executablePath,{bigint:!0});QG(WIn(e),n,t);let o=await Kqt(e.executablePath,qie.O_RDONLY|qie.O_NOFOLLOW);try{let i=await FIn({expectation:e,handle:o,pathMetadata:n,signal:r,user:t});return{handle:o,identity:i}}catch(i){throw await o.close(),i}},GIn=(e,t,r)=>({adapter:e.adapter,adapterVersion:e.adapterVersion,descriptor:t.handle.fd,identity:t.identity,path:e.executablePath,sandboxPolicyRevision:e.sandboxPolicyRevision,sha256:e.sha256,user:r,vouchPolicyRevision:e.vouchPolicyRevision}),lR=s.fn("DarwinVouch.inspectTarget")(function*(e,t){let r=yield*vje;return yield*s.tryPromise({catch:n=>Ie(n,"transport_failed","The requested executable is not admitted by the vouch policy."),try:n=>jIn({adapter:t,path:e},r,n)})}),Zqt=s.fnUntraced(function*(e){let t=yield*vje,r=yield*s.acquireRelease(s.tryPromise({catch:n=>Ie(n,"transport_failed","The requested executable is not admitted by the vouch policy."),try:n=>$In(e,t,n)}),({handle:n})=>s.promise(()=>n.close()).pipe(s.ignore));return GIn(e,r,t)}),zIn=e=>{let t=Jqt(e.adapter);return e.ownerKinds.length>0&&e.ownerKinds.every(r=>t.includes(r))},VIn=e=>zIn(e)&&Ije(e.executablePath)&&xje(e.executablePath)===e.executablePath&&Xqt.test(e.sha256)&&e.adapterVersion.length>0&&e.sandboxPolicyRevision.length>0&&(e.adapter!=="pi-rpc"||e.conversationPolicyRevision!==void 0&&e.conversationPolicyRevision.length>0)&&e.vouchPolicyRevision.length>0,ZG=s.fnUntraced(function*(e){return VIn(e)?yield*Zqt(e):yield*s.fail(jg())}),e2=e=>{try{let t=vIn(e.descriptor,{bigint:!0}),r=TIn(e.path,{bigint:!0});if(!wA(t,e.identity)||!wA(r,e.identity))throw jg();QG(e,t,e.user)}catch(t){throw Ie(t,"transport_failed","The requested executable is not admitted by the vouch policy.")}},Wie=s.fnUntraced(function*(e,t){let r=yield*s.try({catch:()=>jg(),try:()=>MIn(e,t)});return yield*Zqt(r)})});import{createHash as KIn,randomUUID as XIn}from"node:crypto";var Aje,tjt,uR,Cje,$ie,Gie,rjt=M(()=>{"use strict";q();$();Aje=new WeakMap,tjt=()=>m("authentication_failed","The Invocation attachment launch authorization is invalid."),uR=e=>`process_${KIn("sha256").update(JSON.stringify({commandId:e.commandId,kind:e.kind,sessionId:e.sessionId,taskId:e.taskId,terminalId:e.terminalId,workspaceId:e.workspaceId})).digest("hex")}`,Cje=e=>{let t=uR(e.owner),r=Object.freeze({attachmentId:e.attachmentId,...e.parentProcessOwnerId===void 0?{}:{parentProcessOwnerId:e.parentProcessOwnerId},processOwnerId:t,slotId:`invocation-slot-${XIn().replaceAll("-","")}`});return Aje.set(r,{lease:e.lease,processOwnerId:t,state:"available"}),r},$ie=(e,t)=>{let r=Aje.get(e),n=uR(t);return r?.state!=="available"||r.processOwnerId!==n||e.processOwnerId!==n?s.fail(tjt()):s.void},Gie=s.fn("ProcessResourceManager.consumeInvocationAttachmentLease")(function*(e,t){let r=Aje.get(e),n=uR(t);return r?.state!=="available"||r.processOwnerId!==n?yield*s.fail(tjt()):(r.state="consumed",r.lease)})});import{mkdtemp as JIn,open as YIn,rmdir as njt,unlink as ojt}from"node:fs/promises";import{tmpdir as QIn}from"node:os";import{join as ijt}from"node:path";var ZIn,sjt,bje,wje,exn,kje,ajt=M(()=>{"use strict";q();$();ZIn=32,sjt=e=>Ie(e,"transport_failed","The protected Invocation attachment handle could not be created."),bje=()=>{},wje=e=>e.close().catch(bje),exn=async e=>{let t=Buffer.from(e),r=await JIn(ijt(QIn(),"maia-ic1-")),n=ijt(r,"attachment");try{let o=await YIn(n,"wx+",384);try{return await o.write(t,0,t.byteLength,0),await ojt(n),await njt(r),o}catch(i){throw await wje(o),i}}finally{t.fill(0),await ojt(n).catch(bje),await njt(r).catch(bje)}},kje=s.fn("ProcessResourceManager.openInvocationAttachmentNativeLease")(function*(e){return e.byteLength!==ZIn?yield*s.fail(sjt(new Error("credential size invalid"))):yield*s.acquireRelease(s.tryPromise({catch:sjt,try:()=>exn(e)}),t=>s.promise(()=>wje(t)).pipe(s.asVoid)).pipe(s.map(t=>({close:s.promise(()=>wje(t)).pipe(s.asVoid),descriptor:t.fd})))})});import{createHash as txn}from"node:crypto";import{closeSync as rxn,constants as cjt,existsSync as nxn,fstatSync as mjt,lstatSync as oxn,openSync as ixn,readdirSync as sxn,readFileSync as axn,realpathSync as fjt}from"node:fs";import{builtinModules as djt}from"node:module";import{dirname as Pje,isAbsolute as hjt,join as pR,relative as cxn,resolve as yjt,sep as Dje}from"node:path";var Vie,Kie,dxn,ljt,lxn,uxn,Mje,gjt,ujt,Sjt,mR,PM,Oo,Ejt,_jt,pxn,Xie,mxn,Uje,NA,t2,fxn,hxn,Yie,Jie,yxn,gxn,Qie,Rjt,Sxn,vjt,Oje,Tjt,kA,Exn,_xn,Rxn,vxn,Txn,Ijt,Ixn,xxn,Axn,Cxn,bxn,wxn,xjt,kxn,Nxn,Pxn,Oxn,Lxn,Zie,Lje,Nje,pjt,ese,Fje,Dxn,Mxn,Hje,zie,r2,Ajt=M(()=>{"use strict";$();Vie="@maiaos/agent",Kie="dist/managed-worker/main.js",dxn="maia-agent-worker",ljt=["README.md","dist"],lxn="dist/managed-worker/main.meta.json",uxn=["bin","engines","exports","files","imports","name","piConfig","type"],Mje="package.json",gjt="24.22.1",ujt=/^[0-9a-f]{64}$/u,Sjt=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u,mR=Object.freeze({maximumFileBytes:32*1024*1024,maximumFiles:4096,maximumInterpreterBytes:256*1024*1024,maximumPathBytes:4096,maximumTotalBytes:64*1024*1024}),PM=()=>m("transport_failed","The packaged managed Pi worker artifact is invalid."),Oo=()=>{throw PM()},Ejt=e=>{try{return e()}catch(t){if(t instanceof Ke)throw t;return Oo()}},_jt=e=>txn("sha256").update(e).digest("hex"),pxn=e=>e.length>0&&!e.includes("\0")&&Buffer.byteLength(e,"utf8")<=mR.maximumPathBytes&&hjt(e)&&yjt(e)===e,Xie=e=>pxn(e)?e:Oo(),mxn=e=>e.isFile()?"file":e.isDirectory()?"directory":e.isSymbolicLink()?"symlink":Oo(),Uje=e=>Object.freeze({changedAtNanoseconds:e.ctimeNs,device:e.dev,groupId:e.gid,inode:e.ino,linkCount:e.nlink,mode:Number(e.mode),modifiedAtNanoseconds:e.mtimeNs,size:e.size,type:mxn(e),userId:e.uid}),NA=e=>Uje(oxn(e,{bigint:!0})),t2=(e,t)=>e.changedAtNanoseconds===t.changedAtNanoseconds&&e.device===t.device&&e.groupId===t.groupId&&e.inode===t.inode&&e.linkCount===t.linkCount&&e.mode===t.mode&&e.modifiedAtNanoseconds===t.modifiedAtNanoseconds&&e.size===t.size&&e.type===t.type&&e.userId===t.userId,fxn=(e,t)=>{let r=NA(e),n=typeof process.getuid=="function"?process.getuid():void 0,o=n===void 0||r.userId===0n||r.userId===BigInt(n);return t2(t,r)&&o&&(t.mode&18)===0},hxn={package:"A path of the managed Pi worker package is writable by group or others; reinstall under umask 022 or remove group and other write access.",runtime:"The Node.js runtime is writable by group or others; use a Node.js installation that only you or root can write."},Yie=(e,t,r="package")=>{if(!fxn(e,t))throw(t.mode&18)===0?PM():m("path_invalid",hxn[r])},Jie=(e,t,{allowSelectedSymlink:r,kind:n="package"})=>{let o=Xie(e),i=NA(o);if(i.type!==t&&!(r&&i.type==="symlink"))return Oo();let a=Xie(fjt.native(o)),c=NA(a);return c.type!==t?Oo():(Yie(a,c,n),Object.freeze({nofollow:Object.freeze({identity:i,path:o}),realpath:Object.freeze({identity:c,path:a})}))},yxn=(e,t,r)=>{let n=NA(e);return n.type!=="file"||n.linkCount!==1n||n.size<0n||n.size>BigInt(t)?Oo():(Yie(e,n,r),n)},gxn=e=>{let t=Uje(mjt(e.descriptor,{bigint:!0}));(!t2(e.before,e.opened)||e.bytes.byteLength!==Number(e.opened.size)||!t2(e.opened,t)||!t2(e.opened,NA(e.path)))&&Oo()},Qie=(e,t,r="package")=>{let n=yxn(e,t,r),o=ixn(e,cjt.O_RDONLY|(process.platform==="win32"?0:cjt.O_NOFOLLOW));try{let i=Uje(mjt(o,{bigint:!0})),a=axn(o);return gxn({before:n,bytes:a,descriptor:o,opened:i,path:e}),Object.freeze({bytes:a,identity:i,sha256:_jt(a)})}finally{rxn(o)}},Rjt=e=>{let t=e.split(Dje).join("/"),r=t.split("/");return t.length===0||t.startsWith("/")||t.includes("\\")||t.includes("\0")||r.some(n=>n.length===0||n==="."||n==="..")?Oo():t},Sxn=(e,t)=>{let r=cxn(e,t);return r===""||r===".."||r.startsWith(`..${Dje}`)||hjt(r)?Oo():Rjt(r)},vjt=(e,t,r)=>{e.observations.push({identity:r,path:t}),e.observations.length>mR.maximumFiles*2&&Oo()},Oje=(e,t,r)=>{let n=Qie(t,mR.maximumFileBytes);vjt(r,t,n.identity),r.totalBytes+=n.bytes.byteLength,(r.entries.length>=mR.maximumFiles||r.totalBytes>mR.maximumTotalBytes)&&Oo(),r.entries.push(Object.freeze({byteCount:n.bytes.byteLength,executable:(n.identity.mode&73)!==0,relativePath:Sxn(e,t),sha256:n.sha256}))},Tjt=(e,t,r)=>{let n=NA(t);n.type!=="directory"&&Oo(),Yie(t,n),vjt(r,t,n),sxn(t).toSorted().forEach(o=>{Rjt(o);let i=pR(t,o),a=NA(i);a.type==="directory"?Tjt(e,i,r):a.type==="file"?Oje(e,i,r):Oo()})},kA=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Exn=e=>Array.isArray(e),_xn=new Set([...djt,...djt.map(e=>`node:${e}`)]),Rxn=e=>{let t=Qie(pR(e,lxn),mR.maximumFileBytes).bytes.toString("utf8"),r=JSON.parse(t);if(!kA(r))throw PM();let n=Reflect.get(r,"outputs");if(!kA(n))throw PM();Object.values(n).flatMap(a=>{if(!kA(a))throw PM();let c=Reflect.get(a,"imports");if(!Exn(c))throw PM();return c}).some(a=>!kA(a)||typeof a.path!="string"||typeof a.external!="boolean"||a.external&&!_xn.has(a.path))&&Oo()},vxn=e=>{if(!kA(e)||!kA(e.exports)||!kA(e.bin))return Oo();let t=e.files;return e.name!==Vie||typeof e.version!="string"||!Sjt.test(e.version)||e.exports["./managed-worker"]!==`./${Kie}`||e.bin[dxn]!==`./${Kie}`||!Array.isArray(t)||t.length!==ljt.length||!ljt.every(r=>t.includes(r))?Oo():{loading:Object.fromEntries(uxn.map(r=>[r,e[r]])),name:Vie,version:e.version}},Txn=e=>vxn(JSON.parse(Qie(pR(e,Mje),mR.maximumFileBytes).bytes.toString("utf8"))),Ijt=(e,t)=>e===t||Pje(e)===e?Oo():nxn(pR(e,"package.json"))?e:Ijt(Pje(e),t),Ixn=e=>Ijt(Pje(e),yjt(e,Dje)),xxn=e=>{e.forEach(({identity:t,path:r})=>{Yie(r,t)})},Axn=(e,t)=>e.relativePath<t.relativePath?-1:e.relativePath>t.relativePath?1:0,Cxn=(e,t)=>_jt(JSON.stringify({entries:e.filter(({relativePath:r})=>r!==Mje),manifest:t.loading})),bxn=e=>{let t={entries:[],observations:[],totalBytes:0};Oje(e,pR(e,Mje),t),Oje(e,pR(e,"README.md"),t),Tjt(e,pR(e,"dist"),t);let r=Object.freeze(t.entries.toSorted(Axn)),n=Txn(e);Rxn(e),xxn(t.observations);let o=Object.freeze([...t.observations]);return Object.freeze({entries:r,observations:o,packageClosureSha256:Cxn(r,n),packageName:n.name,packageVersion:n.version})},wxn=e=>{if(process.versions.node!==gjt)return Oo();let t=Jie(e,"file",{allowSelectedSymlink:!0,kind:"runtime"}),r=Jie(process.execPath,"file",{allowSelectedSymlink:!0,kind:"runtime"});if(t.realpath.path!==r.realpath.path)return Oo();let n=Qie(t.realpath.path,mR.maximumInterpreterBytes,"runtime");return t2(n.identity,t.realpath.identity)?{binding:t,sha256:n.sha256}:Oo()},xjt=e=>e.packageName===Vie&&Sjt.test(e.packageVersion)&&ujt.test(e.entrySha256)&&ujt.test(e.packageClosureSha256),kxn=e=>{let t=Xie(e),r=Jie(t,"file",{allowSelectedSymlink:!0}),n=Xie(fjt.native(Ixn(r.realpath.path))),o=Jie(n,"directory",{allowSelectedSymlink:!1}),i=pR(n,...Kie.split("/"));if(r.realpath.path!==i)return Oo();let a=bxn(n),c=a.entries.find(({relativePath:l})=>l===Kie);return c===void 0?Oo():{closure:a,entry:r,entryRecord:c,packageRoot:o,packageRootPath:n,selectedEntryPath:t}},Nxn=e=>({entrySha256:e.entryRecord.sha256,packageClosureSha256:e.closure.packageClosureSha256,packageName:e.closure.packageName,packageVersion:e.closure.packageVersion}),Pxn=(e,t)=>e.entrySha256===t.entrySha256&&e.packageClosureSha256===t.packageClosureSha256&&e.packageName===t.packageName&&e.packageVersion===t.packageVersion,Oxn=(e,t)=>{(!xjt(e)||t!==void 0&&!Pxn(e,t))&&Oo()},Lxn=e=>Object.freeze({...e.releaseIdentity,closurePhysicalIdentities:e.inspected.closure.observations,entries:e.inspected.closure.entries,entryPath:e.inspected.entry.realpath.path,entryPhysicalIdentity:e.inspected.entry,interpreterPath:e.interpreter.binding.realpath.path,interpreterPhysicalIdentity:e.interpreter.binding,interpreterSha256:e.interpreter.sha256,interpreterVersion:gjt,packageRootPath:e.inspected.packageRootPath,packageRootPhysicalIdentity:e.inspected.packageRoot,selectedEntryPath:e.inspected.selectedEntryPath,selectedInterpreterPath:e.selectedInterpreterPath}),Zie=e=>Ejt(()=>{let t=kxn(e.entryPath),r=Nxn(t);Oxn(r,e.expectedRelease);let n=e.interpreterPath??process.execPath,o=wxn(n);return Lxn({inspected:t,interpreter:o,releaseIdentity:r,selectedInterpreterPath:n})}),Lje=e=>({...e,changedAtNanoseconds:e.changedAtNanoseconds.toString(),device:e.device.toString(),groupId:e.groupId.toString(),inode:e.inode.toString(),linkCount:e.linkCount.toString(),modifiedAtNanoseconds:e.modifiedAtNanoseconds.toString(),size:e.size.toString(),userId:e.userId.toString()}),Nje=e=>({nofollow:{identity:Lje(e.nofollow.identity),path:e.nofollow.path},realpath:{identity:Lje(e.realpath.identity),path:e.realpath.path}}),pjt=e=>JSON.stringify({...e,closurePhysicalIdentities:e.closurePhysicalIdentities.map(({identity:t,path:r})=>({identity:Lje(t),path:r})),entryPhysicalIdentity:Nje(e.entryPhysicalIdentity),interpreterPhysicalIdentity:Nje(e.interpreterPhysicalIdentity),packageRootPhysicalIdentity:Nje(e.packageRootPhysicalIdentity)}),ese=e=>{Ejt(()=>{let t=Zie({entryPath:e.selectedEntryPath,expectedRelease:{entrySha256:e.entrySha256,packageClosureSha256:e.packageClosureSha256,packageName:e.packageName,packageVersion:e.packageVersion},interpreterPath:e.selectedInterpreterPath});if(pjt(t)!==pjt(e))return Oo()})},Fje=e=>Object.freeze({entrySha256:e.entrySha256,packageClosureSha256:e.packageClosureSha256,packageName:e.packageName,packageVersion:e.packageVersion}),Dxn=["MAIA_NODE_MANAGED_PI_WORKER_CLOSURE_SHA256","MAIA_NODE_MANAGED_PI_WORKER_ENTRY_SHA256","MAIA_NODE_MANAGED_PI_WORKER_PACKAGE_NAME","MAIA_NODE_MANAGED_PI_WORKER_PACKAGE_VERSION"],Mxn=e=>JSON.stringify(e)??"undefined",Hje=e=>Object.fromEntries(Dxn.map((t,r)=>[t,Mxn([e?.packageClosureSha256,e?.entrySha256,e?.packageName,e?.packageVersion][r])])),zie=e=>{try{return e()}catch(t){if(t instanceof ReferenceError)return;throw t}},r2=()=>{let e=[zie(()=>"e1cd9c225663ca465ce406a8900267614b8b01a6a8baf838abaf71fde821b855"),zie(()=>"3a494adbfac145581e8e4d55e706b209b16fc23ecc0fa27f42097be0e5c97354"),zie(()=>"@maiaos/agent"),zie(()=>"0.1.0-canary.12")];if(e.every(a=>a===void 0))return;let[t,r,n,o]=e,i={entrySha256:r,packageClosureSha256:t,packageName:n,packageVersion:o};return typeof r!="string"||typeof t!="string"||n!==Vie||typeof o!="string"||!xjt(i)?Oo():Object.freeze(i)}});import{isAbsolute as Uxn,resolve as Fxn}from"node:path";var Cjt,Hxn,Bxn,qxn,jxn,Wxn,$xn,tse,bjt=M(()=>{"use strict";gi();Cjt=([e],[t])=>e<t?-1:e>t?1:0,Hxn=(e,t)=>{let r=Object.entries(e).toSorted(Cjt),n=Object.entries(t).toSorted(Cjt);return r.length===n.length&&r.every(([o,i],a)=>n[a]?.[0]===o&&n[a]?.[1]===i)},Bxn=(e,t)=>e.kind===t.kind&&e.commandId===t.commandId&&e.sessionId===t.sessionId&&e.taskId===t.taskId&&e.terminalId===t.terminalId&&e.workspaceId===t.workspaceId,qxn=(e,t)=>e.executable===t.executable&&e.workingDirectory===t.workingDirectory&&e.standardInput===t.standardInput&&e.arguments_.length===t.arguments_.length&&e.arguments_.every((r,n)=>t.arguments_[n]===r)&&Hxn(e.environment,t.environment)&&Bxn(e.owner,t.owner)&&e.limits.maximumCpuTimeMilliseconds===t.limits.maximumCpuTimeMilliseconds&&e.limits.maximumMemoryBytes===t.limits.maximumMemoryBytes&&e.limits.maximumProcessCount===t.limits.maximumProcessCount&&e.limits.maximumWallTimeMilliseconds===t.limits.maximumWallTimeMilliseconds&&e.streamLimits.maximumDataChunkBytes===t.streamLimits.maximumDataChunkBytes&&e.streamLimits.maximumPendingInputBytes===t.streamLimits.maximumPendingInputBytes&&e.streamLimits.maximumPendingOutputBytes===t.streamLimits.maximumPendingOutputBytes&&e.interactiveTerminal===void 0&&t.interactiveTerminal===void 0&&e.repositoryAuthority===void 0&&t.repositoryAuthority===void 0,jxn=e=>e.interpreterVersion==="24.22.1"&&e.packageName==="@maiaos/agent"&&/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u.test(e.packageVersion)&&[e.entryPath,e.interpreterPath].every(t=>Uxn(t)&&Fxn(t)===t)&&[e.entrySha256,e.interpreterSha256,e.packageClosureSha256].every(t=>/^[0-9a-f]{64}$/u.test(t)),Wxn=e=>{let t=Object.keys(e).toSorted();return t.length===2&&t[0]==="LANG"&&t[1]==="LC_ALL"&&e.LANG==="C"&&e.LC_ALL==="C"},$xn=(e,t)=>{let r=Pm(e.launchRequest);return r.state==="valid"&&t.owner.kind==="pi-managed-session"&&t.owner.commandId!==void 0&&t.owner.sessionId!==void 0&&t.owner.workspaceId!==void 0&&jxn(e.artifact)&&e.artifact.interpreterPath===t.executable&&t.arguments_.length===1&&t.arguments_[0]===e.artifact.entryPath&&t.standardInput==="pipe"&&Wxn(t.environment)&&qxn(r.request,t)},tse=(e,t)=>{if(e.owner.kind!=="pi-managed-session")return;let r=t?.managedPi;return r!==void 0&&$xn(r,e)?r:void 0}});import{dirname as wjt,isAbsolute as kjt,join as n2,normalize as Gxn,relative as zxn,resolve as Vxn,sep as Kxn}from"node:path";var o2,hh,ic,Xxn,Jxn,Wn,vt,Yxn,Qxn,Zxn,eAn,$u,rse,i2,Bje,tAn,rAn,nAn,oAn,iAn,sAn,aAn,cAn,OM,qje=M(()=>{"use strict";q();o2="24.22.1",hh="1.0.0",ic={exitDrainDeadline:"1 second",maximumInputRecordBytes:64*1024,maximumMessageEndRecords:16,maximumOutputRecordBytes:1024*1024,maximumOutputRecordsPerChunk:4096,maximumOutstandingRequests:8,maximumPendingInputBytes:128*1024,maximumPendingInputRecords:8,maximumPromptBytes:48*1024,maximumRequestIdBytes:128,maximumStderrBytes:64*1024,maximumStdoutBytes:16*1024*1024,requestDeadline:"10 seconds"},Xxn=d.Literals(["command_rejected","cleanup_unknown","input_limit_exceeded","invalid_request","lifecycle_invalid","output_limit_exceeded","prompt_acceptance_unknown","protocol_invalid","request_outcome_unknown","runtime_exited","saturated","transport_failed"]),Jxn=d.TaggedError,Wn=class extends Jxn("@maiaos/node/pi-rpc-failure")("PiRpcFailure",{message:d.String,reason:Xxn}){},vt=(e,t)=>new Wn({message:t,reason:e}),Yxn=/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/u,Qxn=/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/u,Zxn=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u,eAn=/^[0-9a-f]{64}$/u,$u=e=>{throw vt("invalid_request",e)},rse=(e,t,r)=>e.length===0||e.includes("\0")||Buffer.byteLength(e,"utf8")>r?$u(`The Pi RPC ${t} is invalid.`):e,i2=(e,t)=>(rse(e,t,4096),!kjt(e)||Gxn(e)!==e||Vxn(e)!==e?$u(`The Pi RPC ${t} must be an absolute normalized path.`):e),Bje=(e,t)=>eAn.test(e)?e:$u(`The Pi RPC ${t} must be a lowercase SHA-256.`),tAn=e=>(rse(e,"session id",128),Yxn.test(e)?e:$u("The Pi RPC session id is invalid.")),rAn=(e,t)=>{let r=zxn(e,t);return r.length>0&&r!==".."&&!r.startsWith(`..${Kxn}`)&&!kjt(r)},nAn=e=>e.interpreterVersion!==o2?$u(`Pi RPC requires the exact Node ${o2} interpreter.`):(i2(e.interpreterPath,"interpreter path"),i2(e.entryPath,"entry path"),Bje(e.interpreterSha256,"interpreter digest"),Bje(e.entrySha256,"entry digest"),Bje(e.packageClosureSha256,"package-closure digest"),rse(e.packageName,"package name",214),rse(e.packageVersion,"package version",128),Qxn.test(e.packageName)?Zxn.test(e.packageVersion)?Object.freeze({...e}):$u("The Pi RPC package version is invalid."):$u("The Pi RPC package name is invalid.")),oAn=(e,t)=>{let r=n2(e,"harness","pi-rpc",t);return{agentDirectory:n2(r,"agent"),homeDirectory:n2(r,"home"),sessionDirectory:n2(r,"sessions"),temporaryDirectory:n2(r,"tmp")}},iAn=(e,t,r)=>{if(e.kind==="fresh"&&e.sessionFile===void 0)return{kind:"fresh",sessionId:r};if(e.sessionFile===void 0)return $u("The Pi RPC session file is missing.");let n=i2(e.sessionFile,e.kind==="fresh"?"prepared fresh session file":"resume session file");return(wjt(n)!==t.sessionDirectory||!rAn(t.sessionDirectory,n)||!n.endsWith(".jsonl"))&&$u("The Pi RPC resume file must be an exact file in its node-private session directory."),{kind:e.kind,sessionFile:n,sessionId:r}},sAn=(e,t,r)=>{let n;if(t.kind==="fresh"&&t.sessionFile===void 0)n=["--session-id",t.sessionId];else{if(t.sessionFile===void 0)return $u("The Pi RPC session file is missing.");n=["--session",t.sessionFile]}return Object.freeze([e.entryPath,"--mode","rpc","--session-dir",r,...n,"--no-tools","--no-extensions","--no-skills","--no-prompt-templates","--no-themes","--no-context-files","--no-approve","--offline"])},aAn=e=>Object.freeze({HOME:e.homeDirectory,LANG:"C",LC_ALL:"C",NO_COLOR:"1",NODE_DISABLE_COMPILE_CACHE:"1",PI_CODING_AGENT_DIR:e.agentDirectory,PI_CODING_AGENT_SESSION_DIR:e.sessionDirectory,PI_OFFLINE:"1",PI_TELEMETRY:"0",TMPDIR:e.temporaryDirectory}),cAn=e=>{let t=i2(e.nodePrivateRoot,"node-private root");wjt(t)===t&&$u("The Pi RPC node-private root cannot be a filesystem root.");let r=i2(e.workingDirectory,"working directory"),n=tAn(e.activation.sessionId),o=oAn(t,n);return{activation:iAn(e.activation,o,n),paths:o,workingDirectory:r}},OM=e=>{let t=nAn(e.artifact),{activation:r,paths:n,workingDirectory:o}=cAn(e);return r.sessionFile!==void 0&&t.packageVersion!==hh&&$u(`Pi RPC persistent sessions require the exact ${hh} package format.`),Object.freeze({activation:r,...n,arguments_:sAn(t,r,n.sessionDirectory),artifact:t,environment:aAn(n),executable:t.interpreterPath,workingDirectory:o})}});var LM,jje=M(()=>{"use strict";LM=(e,t)=>e===t?0:e<t?-1:1});import{createHash as dAn}from"node:crypto";import{closeSync as lAn,constants as Njt,existsSync as uAn,fstatSync as Pjt,lstatSync as Ljt,openSync as pAn,readdirSync as Djt,readFileSync as mAn,realpathSync as Vje}from"node:fs";import{dirname as Wje,isAbsolute as Mjt,join as Kje,normalize as fAn,relative as hAn,resolve as Xje,sep as $je}from"node:path";var yAn,gAn,SAn,Wg,EAn,_An,Ujt,fo,RAn,Fjt,nse,vAn,Gje,PA,yh,ose,zje,TAn,ise,Jje,Yje,Hjt,IAn,Ojt,Bjt,xAn,AAn,CAn,bAn,wAn,qjt,jjt,kAn,NAn,PAn,OAn,LAn,DAn,MAn,UAn,FAn,HAn,$g,Wjt=M(()=>{"use strict";q();qje();jje();yAn="@earendil-works/pi-coding-agent",gAn=/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/u,SAn=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u,Wg=Object.freeze({maximumExcludedBinEntries:256,maximumFileBytes:16*1024*1024,maximumFiles:16384,maximumFilesystemEntries:16384,maximumInterpreterBytes:256*1024*1024,maximumManifestBytes:8*1024*1024,maximumPathBytes:4096,maximumTotalBytes:256*1024*1024}),EAn=d.Struct({bin:d.Struct({pi:d.String}),name:d.String,version:d.String}),_An=d.decodeUnknownSync(d.fromJsonString(EAn)),Ujt=()=>vt("invalid_request","The selected Pi RPC artifact is invalid."),fo=()=>{throw Ujt()},RAn=e=>{try{return e()}catch(t){throw t instanceof Wn?t:Ujt()}},Fjt=e=>dAn("sha256").update(e).digest("hex"),nse=e=>e.length===0||e.includes("\0")||Buffer.byteLength(e,"utf8")>Wg.maximumPathBytes||!Mjt(e)||fAn(e)!==e||Xje(e)!==e?fo():e,vAn=e=>e.isFile()?"file":e.isDirectory()?"directory":e.isSymbolicLink()?"symlink":fo(),Gje=e=>Object.freeze({changedAtNanoseconds:e.ctimeNs,device:e.dev,inode:e.ino,linkCount:e.nlink,mode:Number(e.mode),modifiedAtNanoseconds:e.mtimeNs,size:e.size,type:vAn(e)}),PA=(e,t)=>e.changedAtNanoseconds===t.changedAtNanoseconds&&e.device===t.device&&e.inode===t.inode&&e.linkCount===t.linkCount&&e.mode===t.mode&&e.modifiedAtNanoseconds===t.modifiedAtNanoseconds&&e.size===t.size&&e.type===t.type,yh=e=>Gje(Ljt(e,{bigint:!0})),ose=(e,t,r)=>{let n=nse(e),o=yh(n);if(o.type!==t&&!(r&&o.type==="symlink"))return fo();let i=nse(Vje.native(n)),a=yh(i);return a.type!==t?fo():Object.freeze({nofollow:Object.freeze({identity:o,path:n}),realpath:Object.freeze({identity:a,path:i})})},zje=e=>{let t=yh(e.nofollow.path),r=nse(Vje.native(e.nofollow.path)),n=yh(e.realpath.path);(r!==e.realpath.path||!PA(t,e.nofollow.identity)||!PA(n,e.realpath.identity))&&fo()},TAn=e=>Buffer.from(e,"utf8").some(t=>t<=31||t===127),ise=e=>{let t=e.split("/");return e.length===0||e.includes("\\")||e.startsWith("/")||Buffer.byteLength(e,"utf8")>Wg.maximumPathBytes||TAn(e)||t.some(r=>r.length===0||r==="."||r==="..")?fo():e},Jje=(e,t)=>{let r=hAn(e,t);return r.length===0||r===".."||r.startsWith(`..${$je}`)||Mjt(r)?fo():ise(r.split($je).join("/"))},Yje=(e,t,r)=>{Hjt(e),e.observed.push({identity:r,path:t})},Hjt=e=>{e.filesystemEntryCount+=1,e.filesystemEntryCount>Wg.maximumFilesystemEntries&&fo()},IAn=e=>{e.excludedBinEntryCount+=1,e.excludedBinEntryCount>Wg.maximumExcludedBinEntries&&fo()},Ojt=(e,t)=>{(e.type!=="file"||e.linkCount!==1n||e.size<0n||e.size>BigInt(t))&&fo()},Bjt=(e,t)=>{let r=yh(e);Ojt(r,t);let n=pAn(e,Njt.O_RDONLY|Njt.O_NOFOLLOW);try{let o=Gje(Pjt(n,{bigint:!0}));Ojt(o,t),PA(r,o)||fo();let i=mAn(n),a=Gje(Pjt(n,{bigint:!0})),c=yh(e);return(i.byteLength!==Number(o.size)||!PA(o,a)||!PA(o,c))&&fo(),{bytes:i,identity:o,sha256:Fjt(i)}}finally{lAn(n)}},xAn=(e,t)=>LM(e.relativePath,t.relativePath),AAn=(e,t,r)=>{t==="package.json"&&(e.state.packageManifestText=new TextDecoder("utf-8",{fatal:!0}).decode(r.bytes)),t===e.entryRelativePath&&(e.state.entrySha256=r.sha256)},CAn=(e,t,r)=>{e.entries.push(Object.freeze({byteCount:r.bytes.byteLength,executable:(r.identity.mode&73)!==0,relativePath:t,sha256:r.sha256}))},bAn=(e,t)=>{let r=Jje(e.root,t),n=Bjt(t,Wg.maximumFileBytes);Yje(e.state,t,n.identity),e.state.fileCount+=1,e.state.totalBytes+=n.bytes.byteLength,(e.state.fileCount>Wg.maximumFiles||e.state.totalBytes>Wg.maximumTotalBytes)&&fo(),CAn(e.state,r,n),AAn(e,r,n)},wAn=(e,t)=>{let r=Jje(e,t);return r==="node_modules/.bin"||r.startsWith("node_modules/")&&r.endsWith("/node_modules/.bin")},qjt=(e,t)=>{let r=yh(t);r.type!=="directory"&&fo(),Yje(e,t,r),Djt(t).forEach(n=>{ise(n);let o=Kje(t,n),i=Ljt(o,{bigint:!0});i.isDirectory()&&!i.isSymbolicLink()?qjt(e,o):(Hjt(e),IAn(e))})},jjt=(e,t)=>{let r=yh(t);r.type!=="directory"&&fo(),Yje(e.state,t,r),Djt(t).sort().forEach(o=>{ise(o);let i=Kje(t,o),a=yh(i);a.type==="directory"?wAn(e.root,i)?qjt(e.state,i):jjt(e,i):a.type==="file"?bAn(e,i):fo()})},kAn=e=>{e.forEach(t=>{PA(yh(t.path),t.identity)||fo()})},NAn=()=>({entries:[],entrySha256:void 0,excludedBinEntryCount:0,fileCount:0,filesystemEntryCount:0,observed:[],packageManifestText:void 0,totalBytes:0}),PAn=e=>{let t=Xje(e,$je),r=n=>uAn(Kje(n,"package.json"))?n:n===t||Wje(n)===n?fo():r(Wje(n));return r(Wje(e))},OAn=(e,t,r)=>{if(e===void 0)return fo();let n=_An(e);if(n.name!==yAn||!gAn.test(n.name)||!SAn.test(n.version))return fo();let o=ise(n.bin.pi.startsWith("./")?n.bin.pi.slice(2):n.bin.pi);return Xje(t,o)!==r?fo():{name:n.name,version:n.version}},LAn=e=>{let t=JSON.stringify(e.map(({byteCount:n,executable:o,relativePath:i,sha256:a})=>({byteCount:n,executable:o,relativePath:i,sha256:a}))),r=Buffer.byteLength(t,"utf8");return r>Wg.maximumManifestBytes&&fo(),{bytes:r,sha256:Fjt(t)}},DAn=e=>Object.freeze(e.entries.sort(xAn).map((t,r)=>Object.freeze({...t,ordinal:r}))),MAn=(e,t)=>{let r=Jje(e,t),n=NAn();jjt({entryRelativePath:r,root:e,state:n},e),kAn(n.observed);let o=DAn(n),i=OAn(n.packageManifestText,e,t);if(n.entrySha256===void 0)return fo();let a=LAn(o);return{entries:o,entrySha256:n.entrySha256,excludedBinEntryCount:n.excludedBinEntryCount,fileCount:n.fileCount,manifestBytes:a.bytes,packageClosureSha256:a.sha256,packageName:i.name,packageVersion:i.version,totalBytes:n.totalBytes}},UAn=e=>Object.freeze({closureSha256:e.closure.packageClosureSha256,entries:e.closure.entries,entryPath:e.entry.realpath.path,entryPhysicalIdentity:e.entry,entrySha256:e.closure.entrySha256,excludedBinEntryCount:e.closure.excludedBinEntryCount,fileCount:e.closure.fileCount,interpreterPath:e.interpreter.binding.realpath.path,interpreterPhysicalIdentity:e.interpreter.binding,interpreterSha256:e.interpreter.sha256,interpreterVersion:o2,manifestBytes:e.closure.manifestBytes,packageClosureSha256:e.closure.packageClosureSha256,packageName:e.closure.packageName,packageRootPath:e.packageRootPath,packageRootPhysicalIdentity:e.packageRoot,packageVersion:e.closure.packageVersion,totalBytes:e.closure.totalBytes}),FAn=e=>{process.versions.node!==o2&&fo();let t=ose(e,"file",!0),r=ose(process.execPath,"file",!0);t.realpath.path!==r.realpath.path&&fo();let n=Bjt(t.realpath.path,Wg.maximumInterpreterBytes);return PA(n.identity,t.realpath.identity)||fo(),zje(t),{binding:t,sha256:n.sha256}},HAn=e=>{let t=FAn(e.interpreterPath),r=ose(e.piExecutablePath,"file",!0),n=nse(Vje.native(PAn(r.realpath.path))),o=ose(n,"directory",!1);o.realpath.path!==n&&fo();let i=MAn(n,r.realpath.path);return zje(r),zje(o),UAn({closure:i,entry:r,interpreter:t,packageRoot:o,packageRootPath:n})},$g=e=>RAn(()=>HAn(e))});var jc=M(()=>{"use strict";Wjt();qje();jje()});import{dirname as BAn,isAbsolute as s2,resolve as a2}from"node:path";var zjt,$jt,qAn,jAn,WAn,$An,GAn,Gjt,zAn,DM,VAn,KAn,XAn,JAn,sse,Vjt=M(()=>{"use strict";jc();gi();zjt=e=>(e.kind==="pi-rpc-probe"||e.kind==="pi-rpc-session")&&e.commandId!==void 0&&e.sessionId!==void 0,$jt=(e,t)=>e<t?-1:e>t?1:0,qAn=(e,t)=>{let r=Object.entries(e).sort(([o],[i])=>$jt(o,i)),n=Object.entries(t).sort(([o],[i])=>$jt(o,i));return r.length===n.length&&r.every(([o,i],a)=>n[a]?.[0]===o&&n[a]?.[1]===i)},jAn=(e,t)=>e.kind===t.kind&&e.commandId===t.commandId&&e.sessionId===t.sessionId&&e.taskId===t.taskId&&e.terminalId===t.terminalId&&e.workspaceId===t.workspaceId,WAn=(e,t)=>e.executable===t.executable&&e.workingDirectory===t.workingDirectory&&e.standardInput===t.standardInput&&e.arguments_.length===t.arguments_.length&&e.arguments_.every((r,n)=>t.arguments_[n]===r)&&qAn(e.environment,t.environment)&&jAn(e.owner,t.owner)&&e.limits.maximumCpuTimeMilliseconds===t.limits.maximumCpuTimeMilliseconds&&e.limits.maximumMemoryBytes===t.limits.maximumMemoryBytes&&e.limits.maximumProcessCount===t.limits.maximumProcessCount&&e.limits.maximumWallTimeMilliseconds===t.limits.maximumWallTimeMilliseconds&&e.streamLimits.maximumDataChunkBytes===t.streamLimits.maximumDataChunkBytes&&e.streamLimits.maximumPendingInputBytes===t.streamLimits.maximumPendingInputBytes&&e.streamLimits.maximumPendingOutputBytes===t.streamLimits.maximumPendingOutputBytes&&e.interactiveTerminal===void 0&&t.interactiveTerminal===void 0&&e.repositoryAuthority===void 0&&t.repositoryAuthority===void 0,$An=e=>{let t=e.nativeSession.activation,r=t.sessionFile===void 0?["--session-id",e.nativeSession.id]:["--session",t.sessionFile];return[e.artifact.entryPath,"--mode","rpc","--session-dir",e.nativeSession.directory,...r,"--no-tools","--no-extensions","--no-skills","--no-prompt-templates","--no-themes","--no-context-files","--no-approve","--offline"]},GAn=(e,t)=>e.length===t.length&&e.every((r,n)=>t[n]===r),Gjt=new Set(["HOME","LANG","LC_ALL","NODE_DISABLE_COMPILE_CACHE","NO_COLOR","PI_CODING_AGENT_DIR","PI_CODING_AGENT_SESSION_DIR","PI_OFFLINE","PI_TELEMETRY","TMPDIR"]),zAn=(e,t)=>{let r=e.environment,n=Object.keys(r);return n.length===Gjt.size&&n.every(o=>Gjt.has(o))&&r.LANG==="C"&&r.LC_ALL==="C"&&r.NODE_DISABLE_COMPILE_CACHE==="1"&&r.NO_COLOR==="1"&&r.PI_CODING_AGENT_SESSION_DIR===t&&r.PI_OFFLINE==="1"&&r.PI_TELEMETRY==="0"&&[r.HOME,r.PI_CODING_AGENT_DIR,r.TMPDIR].every(o=>o!==void 0&&s2(o)&&a2(o)===o)},DM=e=>e.length>0&&!e.includes("\0")&&Buffer.byteLength(e,"utf8")<=128,VAn=e=>e.interpreterVersion==="24.22.1"&&s2(e.interpreterPath)&&a2(e.interpreterPath)===e.interpreterPath&&s2(e.entryPath)&&a2(e.entryPath)===e.entryPath&&[e.interpreterSha256,e.entrySha256,e.packageClosureSha256].every(t=>/^[0-9a-f]{64}$/u.test(t))&&/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/u.test(e.packageName)&&/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u.test(e.packageVersion),KAn=e=>s2(e.directory)&&a2(e.directory)===e.directory&&/^(?:[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?)$/u.test(e.id)&&(e.activation.sessionFile===void 0||s2(e.activation.sessionFile)&&a2(e.activation.sessionFile)===e.activation.sessionFile&&BAn(e.activation.sessionFile)===e.directory),XAn=e=>{let{artifact:t,authorizationRevision:r,fenceId:n,nativeSession:o,permitId:i,policy:a}=e;return DM(r)&&DM(n)&&DM(i)&&VAn(t)&&KAn(o)&&DM(a.adapterVersion)&&DM(a.conversationPolicyRevision)&&DM(a.vouchPolicyRevision)},JAn=(e,t)=>{let r=Pm(e.launchRequest);return r.state==="valid"&&zjt(t.owner)&&XAn(e)&&(t.owner.kind!=="pi-rpc-session"||e.nativeSession.activation.sessionFile!==void 0&&e.artifact.packageVersion===hh)&&e.launchRequest.owner.kind===t.owner.kind&&e.launchRequest.owner.commandId===t.owner.commandId&&e.launchRequest.owner.sessionId===t.owner.sessionId&&e.artifact.interpreterPath===t.executable&&GAn(t.arguments_,$An(e))&&zAn(t,e.nativeSession.directory)&&WAn(r.request,t)},sse=(e,t)=>{if(!zjt(e.owner))return;let r=t?.piRpc;return r!==void 0&&JAn(r,e)?r:void 0}});var fR,YAn,OA,Gg,ase,MM,Kjt=M(()=>{"use strict";$D();fR=Object.freeze(HD.map(({integration:e})=>e)),YAn=e=>Uu(e).ownerKinds,OA=e=>fR.find(t=>YAn(t).includes(e)),Gg=(e,t)=>{switch(t){case"claude-code":return e?.claudeCode;case"codex":return e?.codex}},ase=(e,t)=>{let r=Object.freeze(t);switch(e){case"claude-code":return Object.freeze({claudeCode:r});case"codex":return Object.freeze({codex:r})}},MM=e=>fR.flatMap(t=>{let r=Gg(e,t);return r===void 0?[]:[r]})});var Xjt={};Vr(Xjt,{PRIVATE_GROUP_SHELL_FUNCTION:()=>JG,USER_WRITES_ONLY_SHELL_FUNCTION:()=>YG,consumeInvocationAttachmentNativeLease:()=>Gie,embeddedManagedPiWorkerDefines:()=>Hje,inspectDarwinVouchedTarget:()=>lR,inspectManagedPiWorkerArtifact:()=>Zie,invocationAttachmentProcessOwnerId:()=>uR,issueInvocationAttachmentLaunchAuthorization:()=>Cje,managedPiAuthorizationForRequest:()=>tse,openDarwinVouchedTarget:()=>Wie,openInvocationAttachmentNativeLease:()=>kje,piRpcAuthorizationForRequest:()=>sse,readEmbeddedManagedPiWorkerReleaseIdentity:()=>r2,releaseIdentityOf:()=>Fje,requireInvocationAttachmentLaunchAuthorization:()=>$ie,retainDarwinVouchedAuthorizationTarget:()=>ZG,suppliedVendorLaunchAuthorizations:()=>MM,vendorIntegrationForOwner:()=>OA,vendorLaunchAuthorization:()=>Gg,vendorLaunchAuthorizationGrant:()=>ase,vendorLaunchIntegrations:()=>fR,verifyProcessLaunchAuthority:()=>Bie,verifyResolvedManagedPiWorkerArtifact:()=>ese,verifyRetainedDarwinVouchedTargetPath:()=>e2});var zg=M(()=>{"use strict";Wqt();ejt();rjt();ajt();Ajt();bjt();Vjt();Tje();Kjt()});var FGe,rVt=M(()=>{"use strict";at();Yt();lr();fq();FGe=w(y({definitionRef:fm,grantedOperationIds:se(Pi),reason:g("explicit_agent_grant_unavailable"),schemaVersion:g("maia.agent-permission-preflight/v1"),sessionId:R,sessionRevision:le,status:g("denied"),workspaceId:R,workspaceRevision:le}))});var q2,HGe,nVt=M(()=>{"use strict";at();Yt();lr();lg();q2=w(y({method:g("session.show"),requestId:R,schemaVersion:g("maia.agent-worker-operation/v1")})),HGe=w(y({requestId:R,result:kq,schemaVersion:g("maia.agent-worker-operation/v1")}).check(B(e=>new TextEncoder().encode(JSON.stringify(e)).byteLength<=65536)))});var xGn,AGn,CGn,oVt,wae,iVt,kae,bGn,QM,Nae,TR=M(()=>{"use strict";at();dg();lr();fq();dg();rVt();nVt();xGn="maia.agent-definition/v1",AGn=W.check(ve(1,128),ee(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/u)),CGn=W.check(ve(1,128),ee(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/u)),oVt=e=>W.check(ve(1,e),ee(/^[^\0]*$/u),B(t=>t.trim().length>0&&new TextEncoder().encode(t).byteLength<=e)),wae=fm,iVt=y({key:AGn,name:oVt(128),prompt:oVt(16384),provenance:y({kind:V(["distribution","user"]),source:wae}),requestedOperationIds:se(V(ym)).check(ye(32),B(e=>new Set(e).size===e.length)),schemaVersion:g(xGn),skillRefs:se(wae).check(ye(32),B(e=>new Set(e.map(t=>t.key)).size===e.length)),version:CGn}),kae=w(wae),bGn=w(iVt),QM=w(y({definition:iVt,reference:wae}).check(B(e=>e.reference.key===e.definition.key&&e.reference.version===e.definition.version))),Nae=e=>{let t=bGn.parse(e);return JSON.stringify(t,(r,n)=>{if(typeof n!="object"||n===null||Array.isArray(n))return n;let o=n;return Object.fromEntries(Object.keys(o).sort().map(i=>[i,o[i]]))})}});var AKt={};Vr(AKt,{MANAGED_PI_WORKER_MAX_CREDENTIAL_TOKEN_BYTES:()=>bXn,MANAGED_PI_WORKER_MAX_HISTORY_BYTES:()=>_Kt,MANAGED_PI_WORKER_MAX_HISTORY_INPUT_BYTES:()=>RKt,MANAGED_PI_WORKER_MAX_HISTORY_TURNS:()=>vKt,MANAGED_PI_WORKER_MAX_INPUT_BYTES:()=>AXn,MANAGED_PI_WORKER_MAX_OUTPUT_BYTES:()=>Jae,MANAGED_PI_WORKER_MAX_PROMPT_BYTES:()=>CXn,MANAGED_PI_WORKER_MAX_RESPONSE_BYTES:()=>EKt,MANAGED_PI_WORKER_PROTOCOL_VERSION:()=>xXn,ManagedPiWorkerProtocolError:()=>vo,encodeManagedPiWorkerCommand:()=>VXn,encodeManagedPiWorkerEvent:()=>KXn,parseManagedPiWorkerCommand:()=>xKt,parseManagedPiWorkerEvent:()=>nze});var xXn,AXn,Jae,CXn,EKt,_Kt,RKt,vKt,bXn,vo,c0,Xae,wXn,Fd,Ih,tp,kXn,NXn,PXn,rze,TKt,OXn,LXn,DXn,MXn,UXn,FXn,HXn,BXn,qXn,IKt,xKt,jXn,WXn,$Xn,GXn,zXn,nze,VXn,KXn,oze=M(()=>{"use strict";xXn=1,AXn=65536,Jae=1048576,CXn=49152,EKt=32768,_Kt=32768,RKt=16384,vKt=32,bXn=24576,vo=class extends Error{constructor(t){super(t),this.name="ManagedPiWorkerProtocolError"}},c0=e=>Buffer.byteLength(e,"utf8"),Xae=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),wXn=/^[A-Za-z0-9](?:[A-Za-z0-9._:-]{0,126}[A-Za-z0-9])?$/u,Fd=(e,t)=>{if(typeof e!="string"||!wXn.test(e))throw new vo(`The ${t} is invalid.`);return e},Ih=(e,t,r)=>{if(typeof e!="string"||e.length===0||e.includes("\0")||c0(e)>r)throw new vo(`The ${t} is invalid.`);return e},tp=(e,t,r=[])=>{let n=new Set([...t,...r]);if(t.some(o=>!Object.hasOwn(e,o))||Object.keys(e).some(o=>!n.has(o)))throw new vo("The worker command shape is invalid.")},kXn=e=>{if(!Xae(e))throw new vo("The Maia turn history is invalid.");return tp(e,["inputText","responseText"]),{inputText:Ih(e.inputText,"history input",16384),responseText:Ih(e.responseText,"history response",32*1024)}},NXn=e=>{if(!Array.isArray(e)||e.length>32)throw new vo("The Maia turn history is invalid.");let t=e.map(kXn);if(c0(JSON.stringify(t))>32768)throw new vo("The Maia turn history is too large.");return t},PXn=new Set(["off","minimal","low","medium","high","xhigh"]),rze=()=>new vo("The provider credential is invalid."),TKt=(e,t)=>Ih(e,t,24576),OXn=e=>e===""?e:TKt(e,"provider refresh token"),LXn=e=>{if(tp(e,["access","accountId","expires","refresh","type"]),e.type!=="oauth"||typeof e.expires!="number"||!Number.isSafeInteger(e.expires)||e.expires<0)throw rze();return{access:TKt(e.access,"provider access token"),accountId:Ih(e.accountId,"provider account id",512),expires:e.expires,refresh:OXn(e.refresh),type:"oauth"}},DXn=(e,t)=>{if(!Xae(e)||!Xae(e.auth))throw rze();tp(e,["auth","providerId"]);let r=Fd(e.providerId,"provider id");if(typeof t!="string"||!t.startsWith(`${r}/`))throw rze();return{auth:LXn(e.auth),providerId:r}},MXn=e=>{if(e!==void 0&&e!=="session.show/v1")throw new vo("The worker tool projection is unsupported.")},UXn=e=>{if(tp(e,["agentDirectory","history","protocolVersion","requestId","sessionId","type","workingDirectory"],["model","providerCredential","thinkingLevel","toolProjection"]),e.protocolVersion!==1)throw new vo("The worker protocol version is unsupported.");if(MXn(e.toolProjection),e.thinkingLevel!==void 0&&!PXn.has(e.thinkingLevel))throw new vo("The thinking level is invalid.")},FXn=e=>({...e.toolProjection===void 0?{}:{toolProjection:"session.show/v1"},...e.model===void 0?{}:{model:Ih(e.model,"model",256)},...e.providerCredential===void 0?{}:{providerCredential:DXn(e.providerCredential,e.model)},...e.thinkingLevel===void 0?{}:{thinkingLevel:e.thinkingLevel}}),HXn=e=>(UXn(e),{agentDirectory:Ih(e.agentDirectory,"agent directory",4096),history:NXn(e.history),...FXn(e),protocolVersion:1,requestId:Fd(e.requestId,"request id"),sessionId:Fd(e.sessionId,"session id"),type:"initialize",workingDirectory:Ih(e.workingDirectory,"working directory",4096)}),BXn=e=>(tp(e,["requestId","text","turnId","type"]),{requestId:Fd(e.requestId,"request id"),text:Ih(e.text,"prompt",49152),turnId:Fd(e.turnId,"turn id"),type:"prompt"}),qXn=e=>e.type==="interrupt"?(tp(e,["requestId","turnId","type"]),{requestId:Fd(e.requestId,"request id"),turnId:Fd(e.turnId,"turn id"),type:"interrupt"}):(tp(e,["requestId","type"]),{requestId:Fd(e.requestId,"request id"),type:"shutdown"}),IKt=e=>{try{let t=JSON.parse(e);if(Xae(t)&&typeof t.type=="string")return t}catch{throw new vo("The worker command is not valid JSON.")}throw new vo("The worker command is invalid.")},xKt=e=>{if(e.length===0||e.includes("\r")||e.includes(`
243
+ `),YG='user_writes_only() { { [ "$1" = "$uid" ] || [ "$1" = 0 ]; } && [ $(( 0$3 & 002 )) -eq 0 ] && { [ $(( 0$3 & 020 )) -eq 0 ] || { [ -n "$upg" ] && [ "$2" = "$upg" ]; }; }; }'});import{createHash as _In,timingSafeEqual as RIn}from"node:crypto";import{constants as qie,fstatSync as vIn,lstatSync as TIn}from"node:fs";import{lstat as jie,open as Kqt}from"node:fs/promises";import{isAbsolute as Ije,resolve as xje}from"node:path";var IIn,xIn,Xqt,AIn,CIn,bIn,Jqt,jg,Yqt,wA,wIn,kIn,NIn,PIn,QG,OIn,LIn,DIn,MIn,UIn,FIn,Qqt,HIn,BIn,qIn,jIn,WIn,$In,GIn,lR,Zqt,zIn,VIn,ZG,e2,Wie,ejt=M(()=>{"use strict";q();$();Tje();IIn=256*1024*1024,xIn=64*1024,Xqt=/^[0-9a-f]{64}$/u,AIn=64,CIn=4095,bIn=new Set(["claude-code","codex"]),Jqt=e=>{switch(e){case"claude-code":return["claude-code-session"];case"codex":return["codex-probe","codex-session"];case"pi-rpc":return["pi-rpc-probe","pi-rpc-session"];case"git":case"security":case"systemd-creds":case"terminal":return[]}},jg=()=>m("transport_failed","The requested executable is not admitted by the vouch policy."),Yqt=e=>({changedAtNanoseconds:e.ctimeNs,device:e.dev,inode:e.ino,modifiedAtNanoseconds:e.mtimeNs,size:e.size}),wA=(e,t)=>e.ctimeNs===t.changedAtNanoseconds&&e.dev===t.device&&e.ino===t.inode&&e.mtimeNs===t.modifiedAtNanoseconds&&e.size===t.size,wIn=e=>e.uid===0n?e.nlink>0n:e.nlink===1n,kIn=e=>`0${(Number(e.mode)&CIn).toString(8)}`,NIn=({adapter:e,path:t},r)=>{if(r.isSymbolicLink())return`${t}: a symbolic link; fix: approve the file it points to.`;if(!r.isFile())return`${t}: not a regular file.`;if(r.size===0n)return`${t}: an empty file.`;if(!bIn.has(e)&&r.size>BigInt(IIn))return`${t}: ${r.size.toString()} bytes, over the 256 MiB limit.`},PIn=(e,t,r)=>{let n=NIn(e,t);if(n!==void 0)return n;let{path:o}=e,i=kIn(t),a=Vqt({gid:Number(t.gid),mode:Number(t.mode),uid:Number(t.uid)},r);if(a==="foreign_owner")return`${o}: mode ${i}, owner uid ${t.uid.toString()}, not this user (${String(r.uid)}) or root; fix: install it as this user.`;if(a==="writable_by_others")return`${o}: mode ${i}, gid ${t.gid.toString()}, writable by others or a shared group; fix: chmod go-w on it.`;if(!wIn(t))return`${o}: ${t.nlink.toString()} hard links; fix: approve a copy with one link.`;if((Number(t.mode)&AIn)===0)return`${o}: mode ${i}, not executable by its owner; fix: chmod u+x on it.`},QG=(e,t,r)=>{let n=PIn(e,t,r);if(n!==void 0)throw m("configuration_invalid",`The vouch policy refuses ${n}`)},OIn=(e,t)=>{let r=Buffer.from(t,"hex");return e.byteLength===r.byteLength&&RIn(e,r)},LIn=(e,t)=>{switch(e.adapter){case"git":return t==="git-inspection";case"security":case"systemd-creds":return t==="secret-store";case"terminal":return t==="interactive-terminal";case"claude-code":case"codex":case"pi-rpc":return Jqt(e.adapter).includes(t)}},DIn=(e,t)=>{switch(e.adapter){case"git":return t.selectedTier==="vouched_runtime"||t.selectedTier==="hard_containment";case"security":return t.selectedTier==="vouched_runtime";case"systemd-creds":return t.selectedTier==="hard_containment";case"terminal":return t.selectedTier==="local_user_interactive_terminal";case"claude-code":case"codex":return t.selectedTier==="cooperative_multi_pgid"||t.selectedTier==="hard_containment";case"pi-rpc":return t.selectedTier==="cooperative_pi_rpc_conversation"}},MIn=(e,t)=>{let r=t.find(n=>n.executablePath===e.executable&&n.ownerKinds.includes(e.owner.kind));if(r===void 0||!LIn(r,e.owner.kind)||!DIn(r,e)||!Ije(r.executablePath)||xje(r.executablePath)!==r.executablePath||!Xqt.test(r.sha256)||r.adapterVersion.length===0||r.sandboxPolicyRevision.length===0||r.adapter==="pi-rpc"&&(r.conversationPolicyRevision===void 0||r.conversationPolicyRevision.length===0)||r.vouchPolicyRevision.length===0)throw jg();return r},UIn=e=>{QG(e,e.openedMetadata,e.user);let t=Yqt(e.openedMetadata);if(!wA(e.pathMetadata,t)||!wA(e.currentMetadata,t)||!OIn(e.digest,e.expectedDigest))throw jg();return t},FIn=async e=>UIn({adapter:e.expectation.adapter,currentMetadata:await jie(e.expectation.executablePath,{bigint:!0}),digest:await Qqt(e.handle,e.pathMetadata.size,e.signal),expectedDigest:e.expectation.sha256,openedMetadata:await e.handle.stat({bigint:!0}),path:e.expectation.executablePath,pathMetadata:e.pathMetadata,user:e.user}),Qqt=async(e,t,r)=>{let n=_In("sha256"),o=Buffer.allocUnsafe(xIn),i=Number(t),a=async c=>{if(c>=i)return;r.throwIfAborted();let{bytesRead:l}=await e.read(o,0,Math.min(o.byteLength,i-c),c);if(l<=0)throw jg();n.update(o.subarray(0,l)),await a(c+l)};return await a(0),r.throwIfAborted(),n.digest()},HIn=async(e,t)=>{let[r,n]=await Promise.all([e.handle.stat({bigint:!0}),jie(e.path,{bigint:!0})]);if(!wA(r,t)||!wA(n,t))throw jg()},BIn=(e,t,r)=>({device:t.device.toString(),inode:t.inode.toString(),path:e,sha256:r.toString("hex"),sizeBytes:t.size.toString()}),qIn=async e=>{let t=await e.handle.stat({bigint:!0});QG(e,t,e.user);let r=Yqt(t);if(!wA(e.pathMetadata,r))throw jg();let n=await Qqt(e.handle,t.size,e.signal);return await HIn(e,r),BIn(e.path,r,n)},jIn=async(e,t,r)=>{let{path:n}=e;if(!Ije(n)||xje(n)!==n)throw jg();let o=await jie(n,{bigint:!0});QG(e,o,t);let i=await Kqt(n,qie.O_RDONLY|qie.O_NOFOLLOW);try{return await qIn({...e,handle:i,pathMetadata:o,signal:r,user:t})}finally{await i.close()}},WIn=e=>({adapter:e.adapter,path:e.executablePath}),$In=async(e,t,r)=>{let n=await jie(e.executablePath,{bigint:!0});QG(WIn(e),n,t);let o=await Kqt(e.executablePath,qie.O_RDONLY|qie.O_NOFOLLOW);try{let i=await FIn({expectation:e,handle:o,pathMetadata:n,signal:r,user:t});return{handle:o,identity:i}}catch(i){throw await o.close(),i}},GIn=(e,t,r)=>({adapter:e.adapter,adapterVersion:e.adapterVersion,descriptor:t.handle.fd,identity:t.identity,path:e.executablePath,sandboxPolicyRevision:e.sandboxPolicyRevision,sha256:e.sha256,user:r,vouchPolicyRevision:e.vouchPolicyRevision}),lR=s.fn("DarwinVouch.inspectTarget")(function*(e,t){let r=yield*vje;return yield*s.tryPromise({catch:n=>Ie(n,"transport_failed","The requested executable is not admitted by the vouch policy."),try:n=>jIn({adapter:t,path:e},r,n)})}),Zqt=s.fnUntraced(function*(e){let t=yield*vje,r=yield*s.acquireRelease(s.tryPromise({catch:n=>Ie(n,"transport_failed","The requested executable is not admitted by the vouch policy."),try:n=>$In(e,t,n)}),({handle:n})=>s.promise(()=>n.close()).pipe(s.ignore));return GIn(e,r,t)}),zIn=e=>{let t=Jqt(e.adapter);return e.ownerKinds.length>0&&e.ownerKinds.every(r=>t.includes(r))},VIn=e=>zIn(e)&&Ije(e.executablePath)&&xje(e.executablePath)===e.executablePath&&Xqt.test(e.sha256)&&e.adapterVersion.length>0&&e.sandboxPolicyRevision.length>0&&(e.adapter!=="pi-rpc"||e.conversationPolicyRevision!==void 0&&e.conversationPolicyRevision.length>0)&&e.vouchPolicyRevision.length>0,ZG=s.fnUntraced(function*(e){return VIn(e)?yield*Zqt(e):yield*s.fail(jg())}),e2=e=>{try{let t=vIn(e.descriptor,{bigint:!0}),r=TIn(e.path,{bigint:!0});if(!wA(t,e.identity)||!wA(r,e.identity))throw jg();QG(e,t,e.user)}catch(t){throw Ie(t,"transport_failed","The requested executable is not admitted by the vouch policy.")}},Wie=s.fnUntraced(function*(e,t){let r=yield*s.try({catch:()=>jg(),try:()=>MIn(e,t)});return yield*Zqt(r)})});import{createHash as KIn,randomUUID as XIn}from"node:crypto";var Aje,tjt,uR,Cje,$ie,Gie,rjt=M(()=>{"use strict";q();$();Aje=new WeakMap,tjt=()=>m("authentication_failed","The Invocation attachment launch authorization is invalid."),uR=e=>`process_${KIn("sha256").update(JSON.stringify({commandId:e.commandId,kind:e.kind,sessionId:e.sessionId,taskId:e.taskId,terminalId:e.terminalId,workspaceId:e.workspaceId})).digest("hex")}`,Cje=e=>{let t=uR(e.owner),r=Object.freeze({attachmentId:e.attachmentId,...e.parentProcessOwnerId===void 0?{}:{parentProcessOwnerId:e.parentProcessOwnerId},processOwnerId:t,slotId:`invocation-slot-${XIn().replaceAll("-","")}`});return Aje.set(r,{lease:e.lease,processOwnerId:t,state:"available"}),r},$ie=(e,t)=>{let r=Aje.get(e),n=uR(t);return r?.state!=="available"||r.processOwnerId!==n||e.processOwnerId!==n?s.fail(tjt()):s.void},Gie=s.fn("ProcessResourceManager.consumeInvocationAttachmentLease")(function*(e,t){let r=Aje.get(e),n=uR(t);return r?.state!=="available"||r.processOwnerId!==n?yield*s.fail(tjt()):(r.state="consumed",r.lease)})});import{mkdtemp as JIn,open as YIn,rmdir as njt,unlink as ojt}from"node:fs/promises";import{tmpdir as QIn}from"node:os";import{join as ijt}from"node:path";var ZIn,sjt,bje,wje,exn,kje,ajt=M(()=>{"use strict";q();$();ZIn=32,sjt=e=>Ie(e,"transport_failed","The protected Invocation attachment handle could not be created."),bje=()=>{},wje=e=>e.close().catch(bje),exn=async e=>{let t=Buffer.from(e),r=await JIn(ijt(QIn(),"maia-ic1-")),n=ijt(r,"attachment");try{let o=await YIn(n,"wx+",384);try{return await o.write(t,0,t.byteLength,0),await ojt(n),await njt(r),o}catch(i){throw await wje(o),i}}finally{t.fill(0),await ojt(n).catch(bje),await njt(r).catch(bje)}},kje=s.fn("ProcessResourceManager.openInvocationAttachmentNativeLease")(function*(e){return e.byteLength!==ZIn?yield*s.fail(sjt(new Error("credential size invalid"))):yield*s.acquireRelease(s.tryPromise({catch:sjt,try:()=>exn(e)}),t=>s.promise(()=>wje(t)).pipe(s.asVoid)).pipe(s.map(t=>({close:s.promise(()=>wje(t)).pipe(s.asVoid),descriptor:t.fd})))})});import{createHash as txn}from"node:crypto";import{closeSync as rxn,constants as cjt,existsSync as nxn,fstatSync as mjt,lstatSync as oxn,openSync as ixn,readdirSync as sxn,readFileSync as axn,realpathSync as fjt}from"node:fs";import{builtinModules as djt}from"node:module";import{dirname as Pje,isAbsolute as hjt,join as pR,relative as cxn,resolve as yjt,sep as Dje}from"node:path";var Vie,Kie,dxn,ljt,lxn,uxn,Mje,gjt,ujt,Sjt,mR,PM,Oo,Ejt,_jt,pxn,Xie,mxn,Uje,NA,t2,fxn,hxn,Yie,Jie,yxn,gxn,Qie,Rjt,Sxn,vjt,Oje,Tjt,kA,Exn,_xn,Rxn,vxn,Txn,Ijt,Ixn,xxn,Axn,Cxn,bxn,wxn,xjt,kxn,Nxn,Pxn,Oxn,Lxn,Zie,Lje,Nje,pjt,ese,Fje,Dxn,Mxn,Hje,zie,r2,Ajt=M(()=>{"use strict";$();Vie="@maiaos/agent",Kie="dist/managed-worker/main.js",dxn="maia-agent-worker",ljt=["README.md","dist"],lxn="dist/managed-worker/main.meta.json",uxn=["bin","engines","exports","files","imports","name","piConfig","type"],Mje="package.json",gjt="24.22.1",ujt=/^[0-9a-f]{64}$/u,Sjt=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u,mR=Object.freeze({maximumFileBytes:32*1024*1024,maximumFiles:4096,maximumInterpreterBytes:256*1024*1024,maximumPathBytes:4096,maximumTotalBytes:64*1024*1024}),PM=()=>m("transport_failed","The packaged managed Pi worker artifact is invalid."),Oo=()=>{throw PM()},Ejt=e=>{try{return e()}catch(t){if(t instanceof Ke)throw t;return Oo()}},_jt=e=>txn("sha256").update(e).digest("hex"),pxn=e=>e.length>0&&!e.includes("\0")&&Buffer.byteLength(e,"utf8")<=mR.maximumPathBytes&&hjt(e)&&yjt(e)===e,Xie=e=>pxn(e)?e:Oo(),mxn=e=>e.isFile()?"file":e.isDirectory()?"directory":e.isSymbolicLink()?"symlink":Oo(),Uje=e=>Object.freeze({changedAtNanoseconds:e.ctimeNs,device:e.dev,groupId:e.gid,inode:e.ino,linkCount:e.nlink,mode:Number(e.mode),modifiedAtNanoseconds:e.mtimeNs,size:e.size,type:mxn(e),userId:e.uid}),NA=e=>Uje(oxn(e,{bigint:!0})),t2=(e,t)=>e.changedAtNanoseconds===t.changedAtNanoseconds&&e.device===t.device&&e.groupId===t.groupId&&e.inode===t.inode&&e.linkCount===t.linkCount&&e.mode===t.mode&&e.modifiedAtNanoseconds===t.modifiedAtNanoseconds&&e.size===t.size&&e.type===t.type&&e.userId===t.userId,fxn=(e,t)=>{let r=NA(e),n=typeof process.getuid=="function"?process.getuid():void 0,o=n===void 0||r.userId===0n||r.userId===BigInt(n);return t2(t,r)&&o&&(t.mode&18)===0},hxn={package:"A path of the managed Pi worker package is writable by group or others; reinstall under umask 022 or remove group and other write access.",runtime:"The Node.js runtime is writable by group or others; use a Node.js installation that only you or root can write."},Yie=(e,t,r="package")=>{if(!fxn(e,t))throw(t.mode&18)===0?PM():m("path_invalid",hxn[r])},Jie=(e,t,{allowSelectedSymlink:r,kind:n="package"})=>{let o=Xie(e),i=NA(o);if(i.type!==t&&!(r&&i.type==="symlink"))return Oo();let a=Xie(fjt.native(o)),c=NA(a);return c.type!==t?Oo():(Yie(a,c,n),Object.freeze({nofollow:Object.freeze({identity:i,path:o}),realpath:Object.freeze({identity:c,path:a})}))},yxn=(e,t,r)=>{let n=NA(e);return n.type!=="file"||n.linkCount!==1n||n.size<0n||n.size>BigInt(t)?Oo():(Yie(e,n,r),n)},gxn=e=>{let t=Uje(mjt(e.descriptor,{bigint:!0}));(!t2(e.before,e.opened)||e.bytes.byteLength!==Number(e.opened.size)||!t2(e.opened,t)||!t2(e.opened,NA(e.path)))&&Oo()},Qie=(e,t,r="package")=>{let n=yxn(e,t,r),o=ixn(e,cjt.O_RDONLY|(process.platform==="win32"?0:cjt.O_NOFOLLOW));try{let i=Uje(mjt(o,{bigint:!0})),a=axn(o);return gxn({before:n,bytes:a,descriptor:o,opened:i,path:e}),Object.freeze({bytes:a,identity:i,sha256:_jt(a)})}finally{rxn(o)}},Rjt=e=>{let t=e.split(Dje).join("/"),r=t.split("/");return t.length===0||t.startsWith("/")||t.includes("\\")||t.includes("\0")||r.some(n=>n.length===0||n==="."||n==="..")?Oo():t},Sxn=(e,t)=>{let r=cxn(e,t);return r===""||r===".."||r.startsWith(`..${Dje}`)||hjt(r)?Oo():Rjt(r)},vjt=(e,t,r)=>{e.observations.push({identity:r,path:t}),e.observations.length>mR.maximumFiles*2&&Oo()},Oje=(e,t,r)=>{let n=Qie(t,mR.maximumFileBytes);vjt(r,t,n.identity),r.totalBytes+=n.bytes.byteLength,(r.entries.length>=mR.maximumFiles||r.totalBytes>mR.maximumTotalBytes)&&Oo(),r.entries.push(Object.freeze({byteCount:n.bytes.byteLength,executable:(n.identity.mode&73)!==0,relativePath:Sxn(e,t),sha256:n.sha256}))},Tjt=(e,t,r)=>{let n=NA(t);n.type!=="directory"&&Oo(),Yie(t,n),vjt(r,t,n),sxn(t).toSorted().forEach(o=>{Rjt(o);let i=pR(t,o),a=NA(i);a.type==="directory"?Tjt(e,i,r):a.type==="file"?Oje(e,i,r):Oo()})},kA=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),Exn=e=>Array.isArray(e),_xn=new Set([...djt,...djt.map(e=>`node:${e}`)]),Rxn=e=>{let t=Qie(pR(e,lxn),mR.maximumFileBytes).bytes.toString("utf8"),r=JSON.parse(t);if(!kA(r))throw PM();let n=Reflect.get(r,"outputs");if(!kA(n))throw PM();Object.values(n).flatMap(a=>{if(!kA(a))throw PM();let c=Reflect.get(a,"imports");if(!Exn(c))throw PM();return c}).some(a=>!kA(a)||typeof a.path!="string"||typeof a.external!="boolean"||a.external&&!_xn.has(a.path))&&Oo()},vxn=e=>{if(!kA(e)||!kA(e.exports)||!kA(e.bin))return Oo();let t=e.files;return e.name!==Vie||typeof e.version!="string"||!Sjt.test(e.version)||e.exports["./managed-worker"]!==`./${Kie}`||e.bin[dxn]!==`./${Kie}`||!Array.isArray(t)||t.length!==ljt.length||!ljt.every(r=>t.includes(r))?Oo():{loading:Object.fromEntries(uxn.map(r=>[r,e[r]])),name:Vie,version:e.version}},Txn=e=>vxn(JSON.parse(Qie(pR(e,Mje),mR.maximumFileBytes).bytes.toString("utf8"))),Ijt=(e,t)=>e===t||Pje(e)===e?Oo():nxn(pR(e,"package.json"))?e:Ijt(Pje(e),t),Ixn=e=>Ijt(Pje(e),yjt(e,Dje)),xxn=e=>{e.forEach(({identity:t,path:r})=>{Yie(r,t)})},Axn=(e,t)=>e.relativePath<t.relativePath?-1:e.relativePath>t.relativePath?1:0,Cxn=(e,t)=>_jt(JSON.stringify({entries:e.filter(({relativePath:r})=>r!==Mje),manifest:t.loading})),bxn=e=>{let t={entries:[],observations:[],totalBytes:0};Oje(e,pR(e,Mje),t),Oje(e,pR(e,"README.md"),t),Tjt(e,pR(e,"dist"),t);let r=Object.freeze(t.entries.toSorted(Axn)),n=Txn(e);Rxn(e),xxn(t.observations);let o=Object.freeze([...t.observations]);return Object.freeze({entries:r,observations:o,packageClosureSha256:Cxn(r,n),packageName:n.name,packageVersion:n.version})},wxn=e=>{if(process.versions.node!==gjt)return Oo();let t=Jie(e,"file",{allowSelectedSymlink:!0,kind:"runtime"}),r=Jie(process.execPath,"file",{allowSelectedSymlink:!0,kind:"runtime"});if(t.realpath.path!==r.realpath.path)return Oo();let n=Qie(t.realpath.path,mR.maximumInterpreterBytes,"runtime");return t2(n.identity,t.realpath.identity)?{binding:t,sha256:n.sha256}:Oo()},xjt=e=>e.packageName===Vie&&Sjt.test(e.packageVersion)&&ujt.test(e.entrySha256)&&ujt.test(e.packageClosureSha256),kxn=e=>{let t=Xie(e),r=Jie(t,"file",{allowSelectedSymlink:!0}),n=Xie(fjt.native(Ixn(r.realpath.path))),o=Jie(n,"directory",{allowSelectedSymlink:!1}),i=pR(n,...Kie.split("/"));if(r.realpath.path!==i)return Oo();let a=bxn(n),c=a.entries.find(({relativePath:l})=>l===Kie);return c===void 0?Oo():{closure:a,entry:r,entryRecord:c,packageRoot:o,packageRootPath:n,selectedEntryPath:t}},Nxn=e=>({entrySha256:e.entryRecord.sha256,packageClosureSha256:e.closure.packageClosureSha256,packageName:e.closure.packageName,packageVersion:e.closure.packageVersion}),Pxn=(e,t)=>e.entrySha256===t.entrySha256&&e.packageClosureSha256===t.packageClosureSha256&&e.packageName===t.packageName&&e.packageVersion===t.packageVersion,Oxn=(e,t)=>{(!xjt(e)||t!==void 0&&!Pxn(e,t))&&Oo()},Lxn=e=>Object.freeze({...e.releaseIdentity,closurePhysicalIdentities:e.inspected.closure.observations,entries:e.inspected.closure.entries,entryPath:e.inspected.entry.realpath.path,entryPhysicalIdentity:e.inspected.entry,interpreterPath:e.interpreter.binding.realpath.path,interpreterPhysicalIdentity:e.interpreter.binding,interpreterSha256:e.interpreter.sha256,interpreterVersion:gjt,packageRootPath:e.inspected.packageRootPath,packageRootPhysicalIdentity:e.inspected.packageRoot,selectedEntryPath:e.inspected.selectedEntryPath,selectedInterpreterPath:e.selectedInterpreterPath}),Zie=e=>Ejt(()=>{let t=kxn(e.entryPath),r=Nxn(t);Oxn(r,e.expectedRelease);let n=e.interpreterPath??process.execPath,o=wxn(n);return Lxn({inspected:t,interpreter:o,releaseIdentity:r,selectedInterpreterPath:n})}),Lje=e=>({...e,changedAtNanoseconds:e.changedAtNanoseconds.toString(),device:e.device.toString(),groupId:e.groupId.toString(),inode:e.inode.toString(),linkCount:e.linkCount.toString(),modifiedAtNanoseconds:e.modifiedAtNanoseconds.toString(),size:e.size.toString(),userId:e.userId.toString()}),Nje=e=>({nofollow:{identity:Lje(e.nofollow.identity),path:e.nofollow.path},realpath:{identity:Lje(e.realpath.identity),path:e.realpath.path}}),pjt=e=>JSON.stringify({...e,closurePhysicalIdentities:e.closurePhysicalIdentities.map(({identity:t,path:r})=>({identity:Lje(t),path:r})),entryPhysicalIdentity:Nje(e.entryPhysicalIdentity),interpreterPhysicalIdentity:Nje(e.interpreterPhysicalIdentity),packageRootPhysicalIdentity:Nje(e.packageRootPhysicalIdentity)}),ese=e=>{Ejt(()=>{let t=Zie({entryPath:e.selectedEntryPath,expectedRelease:{entrySha256:e.entrySha256,packageClosureSha256:e.packageClosureSha256,packageName:e.packageName,packageVersion:e.packageVersion},interpreterPath:e.selectedInterpreterPath});if(pjt(t)!==pjt(e))return Oo()})},Fje=e=>Object.freeze({entrySha256:e.entrySha256,packageClosureSha256:e.packageClosureSha256,packageName:e.packageName,packageVersion:e.packageVersion}),Dxn=["MAIA_NODE_MANAGED_PI_WORKER_CLOSURE_SHA256","MAIA_NODE_MANAGED_PI_WORKER_ENTRY_SHA256","MAIA_NODE_MANAGED_PI_WORKER_PACKAGE_NAME","MAIA_NODE_MANAGED_PI_WORKER_PACKAGE_VERSION"],Mxn=e=>JSON.stringify(e)??"undefined",Hje=e=>Object.fromEntries(Dxn.map((t,r)=>[t,Mxn([e?.packageClosureSha256,e?.entrySha256,e?.packageName,e?.packageVersion][r])])),zie=e=>{try{return e()}catch(t){if(t instanceof ReferenceError)return;throw t}},r2=()=>{let e=[zie(()=>"e1cd9c225663ca465ce406a8900267614b8b01a6a8baf838abaf71fde821b855"),zie(()=>"3a494adbfac145581e8e4d55e706b209b16fc23ecc0fa27f42097be0e5c97354"),zie(()=>"@maiaos/agent"),zie(()=>"0.1.0-canary.13")];if(e.every(a=>a===void 0))return;let[t,r,n,o]=e,i={entrySha256:r,packageClosureSha256:t,packageName:n,packageVersion:o};return typeof r!="string"||typeof t!="string"||n!==Vie||typeof o!="string"||!xjt(i)?Oo():Object.freeze(i)}});import{isAbsolute as Uxn,resolve as Fxn}from"node:path";var Cjt,Hxn,Bxn,qxn,jxn,Wxn,$xn,tse,bjt=M(()=>{"use strict";gi();Cjt=([e],[t])=>e<t?-1:e>t?1:0,Hxn=(e,t)=>{let r=Object.entries(e).toSorted(Cjt),n=Object.entries(t).toSorted(Cjt);return r.length===n.length&&r.every(([o,i],a)=>n[a]?.[0]===o&&n[a]?.[1]===i)},Bxn=(e,t)=>e.kind===t.kind&&e.commandId===t.commandId&&e.sessionId===t.sessionId&&e.taskId===t.taskId&&e.terminalId===t.terminalId&&e.workspaceId===t.workspaceId,qxn=(e,t)=>e.executable===t.executable&&e.workingDirectory===t.workingDirectory&&e.standardInput===t.standardInput&&e.arguments_.length===t.arguments_.length&&e.arguments_.every((r,n)=>t.arguments_[n]===r)&&Hxn(e.environment,t.environment)&&Bxn(e.owner,t.owner)&&e.limits.maximumCpuTimeMilliseconds===t.limits.maximumCpuTimeMilliseconds&&e.limits.maximumMemoryBytes===t.limits.maximumMemoryBytes&&e.limits.maximumProcessCount===t.limits.maximumProcessCount&&e.limits.maximumWallTimeMilliseconds===t.limits.maximumWallTimeMilliseconds&&e.streamLimits.maximumDataChunkBytes===t.streamLimits.maximumDataChunkBytes&&e.streamLimits.maximumPendingInputBytes===t.streamLimits.maximumPendingInputBytes&&e.streamLimits.maximumPendingOutputBytes===t.streamLimits.maximumPendingOutputBytes&&e.interactiveTerminal===void 0&&t.interactiveTerminal===void 0&&e.repositoryAuthority===void 0&&t.repositoryAuthority===void 0,jxn=e=>e.interpreterVersion==="24.22.1"&&e.packageName==="@maiaos/agent"&&/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u.test(e.packageVersion)&&[e.entryPath,e.interpreterPath].every(t=>Uxn(t)&&Fxn(t)===t)&&[e.entrySha256,e.interpreterSha256,e.packageClosureSha256].every(t=>/^[0-9a-f]{64}$/u.test(t)),Wxn=e=>{let t=Object.keys(e).toSorted();return t.length===2&&t[0]==="LANG"&&t[1]==="LC_ALL"&&e.LANG==="C"&&e.LC_ALL==="C"},$xn=(e,t)=>{let r=Pm(e.launchRequest);return r.state==="valid"&&t.owner.kind==="pi-managed-session"&&t.owner.commandId!==void 0&&t.owner.sessionId!==void 0&&t.owner.workspaceId!==void 0&&jxn(e.artifact)&&e.artifact.interpreterPath===t.executable&&t.arguments_.length===1&&t.arguments_[0]===e.artifact.entryPath&&t.standardInput==="pipe"&&Wxn(t.environment)&&qxn(r.request,t)},tse=(e,t)=>{if(e.owner.kind!=="pi-managed-session")return;let r=t?.managedPi;return r!==void 0&&$xn(r,e)?r:void 0}});import{dirname as wjt,isAbsolute as kjt,join as n2,normalize as Gxn,relative as zxn,resolve as Vxn,sep as Kxn}from"node:path";var o2,hh,ic,Xxn,Jxn,Wn,vt,Yxn,Qxn,Zxn,eAn,$u,rse,i2,Bje,tAn,rAn,nAn,oAn,iAn,sAn,aAn,cAn,OM,qje=M(()=>{"use strict";q();o2="24.22.1",hh="1.0.0",ic={exitDrainDeadline:"1 second",maximumInputRecordBytes:64*1024,maximumMessageEndRecords:16,maximumOutputRecordBytes:1024*1024,maximumOutputRecordsPerChunk:4096,maximumOutstandingRequests:8,maximumPendingInputBytes:128*1024,maximumPendingInputRecords:8,maximumPromptBytes:48*1024,maximumRequestIdBytes:128,maximumStderrBytes:64*1024,maximumStdoutBytes:16*1024*1024,requestDeadline:"10 seconds"},Xxn=d.Literals(["command_rejected","cleanup_unknown","input_limit_exceeded","invalid_request","lifecycle_invalid","output_limit_exceeded","prompt_acceptance_unknown","protocol_invalid","request_outcome_unknown","runtime_exited","saturated","transport_failed"]),Jxn=d.TaggedError,Wn=class extends Jxn("@maiaos/node/pi-rpc-failure")("PiRpcFailure",{message:d.String,reason:Xxn}){},vt=(e,t)=>new Wn({message:t,reason:e}),Yxn=/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/u,Qxn=/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/u,Zxn=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u,eAn=/^[0-9a-f]{64}$/u,$u=e=>{throw vt("invalid_request",e)},rse=(e,t,r)=>e.length===0||e.includes("\0")||Buffer.byteLength(e,"utf8")>r?$u(`The Pi RPC ${t} is invalid.`):e,i2=(e,t)=>(rse(e,t,4096),!kjt(e)||Gxn(e)!==e||Vxn(e)!==e?$u(`The Pi RPC ${t} must be an absolute normalized path.`):e),Bje=(e,t)=>eAn.test(e)?e:$u(`The Pi RPC ${t} must be a lowercase SHA-256.`),tAn=e=>(rse(e,"session id",128),Yxn.test(e)?e:$u("The Pi RPC session id is invalid.")),rAn=(e,t)=>{let r=zxn(e,t);return r.length>0&&r!==".."&&!r.startsWith(`..${Kxn}`)&&!kjt(r)},nAn=e=>e.interpreterVersion!==o2?$u(`Pi RPC requires the exact Node ${o2} interpreter.`):(i2(e.interpreterPath,"interpreter path"),i2(e.entryPath,"entry path"),Bje(e.interpreterSha256,"interpreter digest"),Bje(e.entrySha256,"entry digest"),Bje(e.packageClosureSha256,"package-closure digest"),rse(e.packageName,"package name",214),rse(e.packageVersion,"package version",128),Qxn.test(e.packageName)?Zxn.test(e.packageVersion)?Object.freeze({...e}):$u("The Pi RPC package version is invalid."):$u("The Pi RPC package name is invalid.")),oAn=(e,t)=>{let r=n2(e,"harness","pi-rpc",t);return{agentDirectory:n2(r,"agent"),homeDirectory:n2(r,"home"),sessionDirectory:n2(r,"sessions"),temporaryDirectory:n2(r,"tmp")}},iAn=(e,t,r)=>{if(e.kind==="fresh"&&e.sessionFile===void 0)return{kind:"fresh",sessionId:r};if(e.sessionFile===void 0)return $u("The Pi RPC session file is missing.");let n=i2(e.sessionFile,e.kind==="fresh"?"prepared fresh session file":"resume session file");return(wjt(n)!==t.sessionDirectory||!rAn(t.sessionDirectory,n)||!n.endsWith(".jsonl"))&&$u("The Pi RPC resume file must be an exact file in its node-private session directory."),{kind:e.kind,sessionFile:n,sessionId:r}},sAn=(e,t,r)=>{let n;if(t.kind==="fresh"&&t.sessionFile===void 0)n=["--session-id",t.sessionId];else{if(t.sessionFile===void 0)return $u("The Pi RPC session file is missing.");n=["--session",t.sessionFile]}return Object.freeze([e.entryPath,"--mode","rpc","--session-dir",r,...n,"--no-tools","--no-extensions","--no-skills","--no-prompt-templates","--no-themes","--no-context-files","--no-approve","--offline"])},aAn=e=>Object.freeze({HOME:e.homeDirectory,LANG:"C",LC_ALL:"C",NO_COLOR:"1",NODE_DISABLE_COMPILE_CACHE:"1",PI_CODING_AGENT_DIR:e.agentDirectory,PI_CODING_AGENT_SESSION_DIR:e.sessionDirectory,PI_OFFLINE:"1",PI_TELEMETRY:"0",TMPDIR:e.temporaryDirectory}),cAn=e=>{let t=i2(e.nodePrivateRoot,"node-private root");wjt(t)===t&&$u("The Pi RPC node-private root cannot be a filesystem root.");let r=i2(e.workingDirectory,"working directory"),n=tAn(e.activation.sessionId),o=oAn(t,n);return{activation:iAn(e.activation,o,n),paths:o,workingDirectory:r}},OM=e=>{let t=nAn(e.artifact),{activation:r,paths:n,workingDirectory:o}=cAn(e);return r.sessionFile!==void 0&&t.packageVersion!==hh&&$u(`Pi RPC persistent sessions require the exact ${hh} package format.`),Object.freeze({activation:r,...n,arguments_:sAn(t,r,n.sessionDirectory),artifact:t,environment:aAn(n),executable:t.interpreterPath,workingDirectory:o})}});var LM,jje=M(()=>{"use strict";LM=(e,t)=>e===t?0:e<t?-1:1});import{createHash as dAn}from"node:crypto";import{closeSync as lAn,constants as Njt,existsSync as uAn,fstatSync as Pjt,lstatSync as Ljt,openSync as pAn,readdirSync as Djt,readFileSync as mAn,realpathSync as Vje}from"node:fs";import{dirname as Wje,isAbsolute as Mjt,join as Kje,normalize as fAn,relative as hAn,resolve as Xje,sep as $je}from"node:path";var yAn,gAn,SAn,Wg,EAn,_An,Ujt,fo,RAn,Fjt,nse,vAn,Gje,PA,yh,ose,zje,TAn,ise,Jje,Yje,Hjt,IAn,Ojt,Bjt,xAn,AAn,CAn,bAn,wAn,qjt,jjt,kAn,NAn,PAn,OAn,LAn,DAn,MAn,UAn,FAn,HAn,$g,Wjt=M(()=>{"use strict";q();qje();jje();yAn="@earendil-works/pi-coding-agent",gAn=/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/u,SAn=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u,Wg=Object.freeze({maximumExcludedBinEntries:256,maximumFileBytes:16*1024*1024,maximumFiles:16384,maximumFilesystemEntries:16384,maximumInterpreterBytes:256*1024*1024,maximumManifestBytes:8*1024*1024,maximumPathBytes:4096,maximumTotalBytes:256*1024*1024}),EAn=d.Struct({bin:d.Struct({pi:d.String}),name:d.String,version:d.String}),_An=d.decodeUnknownSync(d.fromJsonString(EAn)),Ujt=()=>vt("invalid_request","The selected Pi RPC artifact is invalid."),fo=()=>{throw Ujt()},RAn=e=>{try{return e()}catch(t){throw t instanceof Wn?t:Ujt()}},Fjt=e=>dAn("sha256").update(e).digest("hex"),nse=e=>e.length===0||e.includes("\0")||Buffer.byteLength(e,"utf8")>Wg.maximumPathBytes||!Mjt(e)||fAn(e)!==e||Xje(e)!==e?fo():e,vAn=e=>e.isFile()?"file":e.isDirectory()?"directory":e.isSymbolicLink()?"symlink":fo(),Gje=e=>Object.freeze({changedAtNanoseconds:e.ctimeNs,device:e.dev,inode:e.ino,linkCount:e.nlink,mode:Number(e.mode),modifiedAtNanoseconds:e.mtimeNs,size:e.size,type:vAn(e)}),PA=(e,t)=>e.changedAtNanoseconds===t.changedAtNanoseconds&&e.device===t.device&&e.inode===t.inode&&e.linkCount===t.linkCount&&e.mode===t.mode&&e.modifiedAtNanoseconds===t.modifiedAtNanoseconds&&e.size===t.size&&e.type===t.type,yh=e=>Gje(Ljt(e,{bigint:!0})),ose=(e,t,r)=>{let n=nse(e),o=yh(n);if(o.type!==t&&!(r&&o.type==="symlink"))return fo();let i=nse(Vje.native(n)),a=yh(i);return a.type!==t?fo():Object.freeze({nofollow:Object.freeze({identity:o,path:n}),realpath:Object.freeze({identity:a,path:i})})},zje=e=>{let t=yh(e.nofollow.path),r=nse(Vje.native(e.nofollow.path)),n=yh(e.realpath.path);(r!==e.realpath.path||!PA(t,e.nofollow.identity)||!PA(n,e.realpath.identity))&&fo()},TAn=e=>Buffer.from(e,"utf8").some(t=>t<=31||t===127),ise=e=>{let t=e.split("/");return e.length===0||e.includes("\\")||e.startsWith("/")||Buffer.byteLength(e,"utf8")>Wg.maximumPathBytes||TAn(e)||t.some(r=>r.length===0||r==="."||r==="..")?fo():e},Jje=(e,t)=>{let r=hAn(e,t);return r.length===0||r===".."||r.startsWith(`..${$je}`)||Mjt(r)?fo():ise(r.split($je).join("/"))},Yje=(e,t,r)=>{Hjt(e),e.observed.push({identity:r,path:t})},Hjt=e=>{e.filesystemEntryCount+=1,e.filesystemEntryCount>Wg.maximumFilesystemEntries&&fo()},IAn=e=>{e.excludedBinEntryCount+=1,e.excludedBinEntryCount>Wg.maximumExcludedBinEntries&&fo()},Ojt=(e,t)=>{(e.type!=="file"||e.linkCount!==1n||e.size<0n||e.size>BigInt(t))&&fo()},Bjt=(e,t)=>{let r=yh(e);Ojt(r,t);let n=pAn(e,Njt.O_RDONLY|Njt.O_NOFOLLOW);try{let o=Gje(Pjt(n,{bigint:!0}));Ojt(o,t),PA(r,o)||fo();let i=mAn(n),a=Gje(Pjt(n,{bigint:!0})),c=yh(e);return(i.byteLength!==Number(o.size)||!PA(o,a)||!PA(o,c))&&fo(),{bytes:i,identity:o,sha256:Fjt(i)}}finally{lAn(n)}},xAn=(e,t)=>LM(e.relativePath,t.relativePath),AAn=(e,t,r)=>{t==="package.json"&&(e.state.packageManifestText=new TextDecoder("utf-8",{fatal:!0}).decode(r.bytes)),t===e.entryRelativePath&&(e.state.entrySha256=r.sha256)},CAn=(e,t,r)=>{e.entries.push(Object.freeze({byteCount:r.bytes.byteLength,executable:(r.identity.mode&73)!==0,relativePath:t,sha256:r.sha256}))},bAn=(e,t)=>{let r=Jje(e.root,t),n=Bjt(t,Wg.maximumFileBytes);Yje(e.state,t,n.identity),e.state.fileCount+=1,e.state.totalBytes+=n.bytes.byteLength,(e.state.fileCount>Wg.maximumFiles||e.state.totalBytes>Wg.maximumTotalBytes)&&fo(),CAn(e.state,r,n),AAn(e,r,n)},wAn=(e,t)=>{let r=Jje(e,t);return r==="node_modules/.bin"||r.startsWith("node_modules/")&&r.endsWith("/node_modules/.bin")},qjt=(e,t)=>{let r=yh(t);r.type!=="directory"&&fo(),Yje(e,t,r),Djt(t).forEach(n=>{ise(n);let o=Kje(t,n),i=Ljt(o,{bigint:!0});i.isDirectory()&&!i.isSymbolicLink()?qjt(e,o):(Hjt(e),IAn(e))})},jjt=(e,t)=>{let r=yh(t);r.type!=="directory"&&fo(),Yje(e.state,t,r),Djt(t).sort().forEach(o=>{ise(o);let i=Kje(t,o),a=yh(i);a.type==="directory"?wAn(e.root,i)?qjt(e.state,i):jjt(e,i):a.type==="file"?bAn(e,i):fo()})},kAn=e=>{e.forEach(t=>{PA(yh(t.path),t.identity)||fo()})},NAn=()=>({entries:[],entrySha256:void 0,excludedBinEntryCount:0,fileCount:0,filesystemEntryCount:0,observed:[],packageManifestText:void 0,totalBytes:0}),PAn=e=>{let t=Xje(e,$je),r=n=>uAn(Kje(n,"package.json"))?n:n===t||Wje(n)===n?fo():r(Wje(n));return r(Wje(e))},OAn=(e,t,r)=>{if(e===void 0)return fo();let n=_An(e);if(n.name!==yAn||!gAn.test(n.name)||!SAn.test(n.version))return fo();let o=ise(n.bin.pi.startsWith("./")?n.bin.pi.slice(2):n.bin.pi);return Xje(t,o)!==r?fo():{name:n.name,version:n.version}},LAn=e=>{let t=JSON.stringify(e.map(({byteCount:n,executable:o,relativePath:i,sha256:a})=>({byteCount:n,executable:o,relativePath:i,sha256:a}))),r=Buffer.byteLength(t,"utf8");return r>Wg.maximumManifestBytes&&fo(),{bytes:r,sha256:Fjt(t)}},DAn=e=>Object.freeze(e.entries.sort(xAn).map((t,r)=>Object.freeze({...t,ordinal:r}))),MAn=(e,t)=>{let r=Jje(e,t),n=NAn();jjt({entryRelativePath:r,root:e,state:n},e),kAn(n.observed);let o=DAn(n),i=OAn(n.packageManifestText,e,t);if(n.entrySha256===void 0)return fo();let a=LAn(o);return{entries:o,entrySha256:n.entrySha256,excludedBinEntryCount:n.excludedBinEntryCount,fileCount:n.fileCount,manifestBytes:a.bytes,packageClosureSha256:a.sha256,packageName:i.name,packageVersion:i.version,totalBytes:n.totalBytes}},UAn=e=>Object.freeze({closureSha256:e.closure.packageClosureSha256,entries:e.closure.entries,entryPath:e.entry.realpath.path,entryPhysicalIdentity:e.entry,entrySha256:e.closure.entrySha256,excludedBinEntryCount:e.closure.excludedBinEntryCount,fileCount:e.closure.fileCount,interpreterPath:e.interpreter.binding.realpath.path,interpreterPhysicalIdentity:e.interpreter.binding,interpreterSha256:e.interpreter.sha256,interpreterVersion:o2,manifestBytes:e.closure.manifestBytes,packageClosureSha256:e.closure.packageClosureSha256,packageName:e.closure.packageName,packageRootPath:e.packageRootPath,packageRootPhysicalIdentity:e.packageRoot,packageVersion:e.closure.packageVersion,totalBytes:e.closure.totalBytes}),FAn=e=>{process.versions.node!==o2&&fo();let t=ose(e,"file",!0),r=ose(process.execPath,"file",!0);t.realpath.path!==r.realpath.path&&fo();let n=Bjt(t.realpath.path,Wg.maximumInterpreterBytes);return PA(n.identity,t.realpath.identity)||fo(),zje(t),{binding:t,sha256:n.sha256}},HAn=e=>{let t=FAn(e.interpreterPath),r=ose(e.piExecutablePath,"file",!0),n=nse(Vje.native(PAn(r.realpath.path))),o=ose(n,"directory",!1);o.realpath.path!==n&&fo();let i=MAn(n,r.realpath.path);return zje(r),zje(o),UAn({closure:i,entry:r,interpreter:t,packageRoot:o,packageRootPath:n})},$g=e=>RAn(()=>HAn(e))});var jc=M(()=>{"use strict";Wjt();qje();jje()});import{dirname as BAn,isAbsolute as s2,resolve as a2}from"node:path";var zjt,$jt,qAn,jAn,WAn,$An,GAn,Gjt,zAn,DM,VAn,KAn,XAn,JAn,sse,Vjt=M(()=>{"use strict";jc();gi();zjt=e=>(e.kind==="pi-rpc-probe"||e.kind==="pi-rpc-session")&&e.commandId!==void 0&&e.sessionId!==void 0,$jt=(e,t)=>e<t?-1:e>t?1:0,qAn=(e,t)=>{let r=Object.entries(e).sort(([o],[i])=>$jt(o,i)),n=Object.entries(t).sort(([o],[i])=>$jt(o,i));return r.length===n.length&&r.every(([o,i],a)=>n[a]?.[0]===o&&n[a]?.[1]===i)},jAn=(e,t)=>e.kind===t.kind&&e.commandId===t.commandId&&e.sessionId===t.sessionId&&e.taskId===t.taskId&&e.terminalId===t.terminalId&&e.workspaceId===t.workspaceId,WAn=(e,t)=>e.executable===t.executable&&e.workingDirectory===t.workingDirectory&&e.standardInput===t.standardInput&&e.arguments_.length===t.arguments_.length&&e.arguments_.every((r,n)=>t.arguments_[n]===r)&&qAn(e.environment,t.environment)&&jAn(e.owner,t.owner)&&e.limits.maximumCpuTimeMilliseconds===t.limits.maximumCpuTimeMilliseconds&&e.limits.maximumMemoryBytes===t.limits.maximumMemoryBytes&&e.limits.maximumProcessCount===t.limits.maximumProcessCount&&e.limits.maximumWallTimeMilliseconds===t.limits.maximumWallTimeMilliseconds&&e.streamLimits.maximumDataChunkBytes===t.streamLimits.maximumDataChunkBytes&&e.streamLimits.maximumPendingInputBytes===t.streamLimits.maximumPendingInputBytes&&e.streamLimits.maximumPendingOutputBytes===t.streamLimits.maximumPendingOutputBytes&&e.interactiveTerminal===void 0&&t.interactiveTerminal===void 0&&e.repositoryAuthority===void 0&&t.repositoryAuthority===void 0,$An=e=>{let t=e.nativeSession.activation,r=t.sessionFile===void 0?["--session-id",e.nativeSession.id]:["--session",t.sessionFile];return[e.artifact.entryPath,"--mode","rpc","--session-dir",e.nativeSession.directory,...r,"--no-tools","--no-extensions","--no-skills","--no-prompt-templates","--no-themes","--no-context-files","--no-approve","--offline"]},GAn=(e,t)=>e.length===t.length&&e.every((r,n)=>t[n]===r),Gjt=new Set(["HOME","LANG","LC_ALL","NODE_DISABLE_COMPILE_CACHE","NO_COLOR","PI_CODING_AGENT_DIR","PI_CODING_AGENT_SESSION_DIR","PI_OFFLINE","PI_TELEMETRY","TMPDIR"]),zAn=(e,t)=>{let r=e.environment,n=Object.keys(r);return n.length===Gjt.size&&n.every(o=>Gjt.has(o))&&r.LANG==="C"&&r.LC_ALL==="C"&&r.NODE_DISABLE_COMPILE_CACHE==="1"&&r.NO_COLOR==="1"&&r.PI_CODING_AGENT_SESSION_DIR===t&&r.PI_OFFLINE==="1"&&r.PI_TELEMETRY==="0"&&[r.HOME,r.PI_CODING_AGENT_DIR,r.TMPDIR].every(o=>o!==void 0&&s2(o)&&a2(o)===o)},DM=e=>e.length>0&&!e.includes("\0")&&Buffer.byteLength(e,"utf8")<=128,VAn=e=>e.interpreterVersion==="24.22.1"&&s2(e.interpreterPath)&&a2(e.interpreterPath)===e.interpreterPath&&s2(e.entryPath)&&a2(e.entryPath)===e.entryPath&&[e.interpreterSha256,e.entrySha256,e.packageClosureSha256].every(t=>/^[0-9a-f]{64}$/u.test(t))&&/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/u.test(e.packageName)&&/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/u.test(e.packageVersion),KAn=e=>s2(e.directory)&&a2(e.directory)===e.directory&&/^(?:[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?)$/u.test(e.id)&&(e.activation.sessionFile===void 0||s2(e.activation.sessionFile)&&a2(e.activation.sessionFile)===e.activation.sessionFile&&BAn(e.activation.sessionFile)===e.directory),XAn=e=>{let{artifact:t,authorizationRevision:r,fenceId:n,nativeSession:o,permitId:i,policy:a}=e;return DM(r)&&DM(n)&&DM(i)&&VAn(t)&&KAn(o)&&DM(a.adapterVersion)&&DM(a.conversationPolicyRevision)&&DM(a.vouchPolicyRevision)},JAn=(e,t)=>{let r=Pm(e.launchRequest);return r.state==="valid"&&zjt(t.owner)&&XAn(e)&&(t.owner.kind!=="pi-rpc-session"||e.nativeSession.activation.sessionFile!==void 0&&e.artifact.packageVersion===hh)&&e.launchRequest.owner.kind===t.owner.kind&&e.launchRequest.owner.commandId===t.owner.commandId&&e.launchRequest.owner.sessionId===t.owner.sessionId&&e.artifact.interpreterPath===t.executable&&GAn(t.arguments_,$An(e))&&zAn(t,e.nativeSession.directory)&&WAn(r.request,t)},sse=(e,t)=>{if(!zjt(e.owner))return;let r=t?.piRpc;return r!==void 0&&JAn(r,e)?r:void 0}});var fR,YAn,OA,Gg,ase,MM,Kjt=M(()=>{"use strict";$D();fR=Object.freeze(HD.map(({integration:e})=>e)),YAn=e=>Uu(e).ownerKinds,OA=e=>fR.find(t=>YAn(t).includes(e)),Gg=(e,t)=>{switch(t){case"claude-code":return e?.claudeCode;case"codex":return e?.codex}},ase=(e,t)=>{let r=Object.freeze(t);switch(e){case"claude-code":return Object.freeze({claudeCode:r});case"codex":return Object.freeze({codex:r})}},MM=e=>fR.flatMap(t=>{let r=Gg(e,t);return r===void 0?[]:[r]})});var Xjt={};Vr(Xjt,{PRIVATE_GROUP_SHELL_FUNCTION:()=>JG,USER_WRITES_ONLY_SHELL_FUNCTION:()=>YG,consumeInvocationAttachmentNativeLease:()=>Gie,embeddedManagedPiWorkerDefines:()=>Hje,inspectDarwinVouchedTarget:()=>lR,inspectManagedPiWorkerArtifact:()=>Zie,invocationAttachmentProcessOwnerId:()=>uR,issueInvocationAttachmentLaunchAuthorization:()=>Cje,managedPiAuthorizationForRequest:()=>tse,openDarwinVouchedTarget:()=>Wie,openInvocationAttachmentNativeLease:()=>kje,piRpcAuthorizationForRequest:()=>sse,readEmbeddedManagedPiWorkerReleaseIdentity:()=>r2,releaseIdentityOf:()=>Fje,requireInvocationAttachmentLaunchAuthorization:()=>$ie,retainDarwinVouchedAuthorizationTarget:()=>ZG,suppliedVendorLaunchAuthorizations:()=>MM,vendorIntegrationForOwner:()=>OA,vendorLaunchAuthorization:()=>Gg,vendorLaunchAuthorizationGrant:()=>ase,vendorLaunchIntegrations:()=>fR,verifyProcessLaunchAuthority:()=>Bie,verifyResolvedManagedPiWorkerArtifact:()=>ese,verifyRetainedDarwinVouchedTargetPath:()=>e2});var zg=M(()=>{"use strict";Wqt();ejt();rjt();ajt();Ajt();bjt();Vjt();Tje();Kjt()});var FGe,rVt=M(()=>{"use strict";at();Yt();lr();fq();FGe=w(y({definitionRef:fm,grantedOperationIds:se(Pi),reason:g("explicit_agent_grant_unavailable"),schemaVersion:g("maia.agent-permission-preflight/v1"),sessionId:R,sessionRevision:le,status:g("denied"),workspaceId:R,workspaceRevision:le}))});var q2,HGe,nVt=M(()=>{"use strict";at();Yt();lr();lg();q2=w(y({method:g("session.show"),requestId:R,schemaVersion:g("maia.agent-worker-operation/v1")})),HGe=w(y({requestId:R,result:kq,schemaVersion:g("maia.agent-worker-operation/v1")}).check(B(e=>new TextEncoder().encode(JSON.stringify(e)).byteLength<=65536)))});var xGn,AGn,CGn,oVt,wae,iVt,kae,bGn,QM,Nae,TR=M(()=>{"use strict";at();dg();lr();fq();dg();rVt();nVt();xGn="maia.agent-definition/v1",AGn=W.check(ve(1,128),ee(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/u)),CGn=W.check(ve(1,128),ee(/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/u)),oVt=e=>W.check(ve(1,e),ee(/^[^\0]*$/u),B(t=>t.trim().length>0&&new TextEncoder().encode(t).byteLength<=e)),wae=fm,iVt=y({key:AGn,name:oVt(128),prompt:oVt(16384),provenance:y({kind:V(["distribution","user"]),source:wae}),requestedOperationIds:se(V(ym)).check(ye(32),B(e=>new Set(e).size===e.length)),schemaVersion:g(xGn),skillRefs:se(wae).check(ye(32),B(e=>new Set(e.map(t=>t.key)).size===e.length)),version:CGn}),kae=w(wae),bGn=w(iVt),QM=w(y({definition:iVt,reference:wae}).check(B(e=>e.reference.key===e.definition.key&&e.reference.version===e.definition.version))),Nae=e=>{let t=bGn.parse(e);return JSON.stringify(t,(r,n)=>{if(typeof n!="object"||n===null||Array.isArray(n))return n;let o=n;return Object.fromEntries(Object.keys(o).sort().map(i=>[i,o[i]]))})}});var AKt={};Vr(AKt,{MANAGED_PI_WORKER_MAX_CREDENTIAL_TOKEN_BYTES:()=>bXn,MANAGED_PI_WORKER_MAX_HISTORY_BYTES:()=>_Kt,MANAGED_PI_WORKER_MAX_HISTORY_INPUT_BYTES:()=>RKt,MANAGED_PI_WORKER_MAX_HISTORY_TURNS:()=>vKt,MANAGED_PI_WORKER_MAX_INPUT_BYTES:()=>AXn,MANAGED_PI_WORKER_MAX_OUTPUT_BYTES:()=>Jae,MANAGED_PI_WORKER_MAX_PROMPT_BYTES:()=>CXn,MANAGED_PI_WORKER_MAX_RESPONSE_BYTES:()=>EKt,MANAGED_PI_WORKER_PROTOCOL_VERSION:()=>xXn,ManagedPiWorkerProtocolError:()=>vo,encodeManagedPiWorkerCommand:()=>VXn,encodeManagedPiWorkerEvent:()=>KXn,parseManagedPiWorkerCommand:()=>xKt,parseManagedPiWorkerEvent:()=>nze});var xXn,AXn,Jae,CXn,EKt,_Kt,RKt,vKt,bXn,vo,c0,Xae,wXn,Fd,Ih,tp,kXn,NXn,PXn,rze,TKt,OXn,LXn,DXn,MXn,UXn,FXn,HXn,BXn,qXn,IKt,xKt,jXn,WXn,$Xn,GXn,zXn,nze,VXn,KXn,oze=M(()=>{"use strict";xXn=1,AXn=65536,Jae=1048576,CXn=49152,EKt=32768,_Kt=32768,RKt=16384,vKt=32,bXn=24576,vo=class extends Error{constructor(t){super(t),this.name="ManagedPiWorkerProtocolError"}},c0=e=>Buffer.byteLength(e,"utf8"),Xae=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),wXn=/^[A-Za-z0-9](?:[A-Za-z0-9._:-]{0,126}[A-Za-z0-9])?$/u,Fd=(e,t)=>{if(typeof e!="string"||!wXn.test(e))throw new vo(`The ${t} is invalid.`);return e},Ih=(e,t,r)=>{if(typeof e!="string"||e.length===0||e.includes("\0")||c0(e)>r)throw new vo(`The ${t} is invalid.`);return e},tp=(e,t,r=[])=>{let n=new Set([...t,...r]);if(t.some(o=>!Object.hasOwn(e,o))||Object.keys(e).some(o=>!n.has(o)))throw new vo("The worker command shape is invalid.")},kXn=e=>{if(!Xae(e))throw new vo("The Maia turn history is invalid.");return tp(e,["inputText","responseText"]),{inputText:Ih(e.inputText,"history input",16384),responseText:Ih(e.responseText,"history response",32*1024)}},NXn=e=>{if(!Array.isArray(e)||e.length>32)throw new vo("The Maia turn history is invalid.");let t=e.map(kXn);if(c0(JSON.stringify(t))>32768)throw new vo("The Maia turn history is too large.");return t},PXn=new Set(["off","minimal","low","medium","high","xhigh"]),rze=()=>new vo("The provider credential is invalid."),TKt=(e,t)=>Ih(e,t,24576),OXn=e=>e===""?e:TKt(e,"provider refresh token"),LXn=e=>{if(tp(e,["access","accountId","expires","refresh","type"]),e.type!=="oauth"||typeof e.expires!="number"||!Number.isSafeInteger(e.expires)||e.expires<0)throw rze();return{access:TKt(e.access,"provider access token"),accountId:Ih(e.accountId,"provider account id",512),expires:e.expires,refresh:OXn(e.refresh),type:"oauth"}},DXn=(e,t)=>{if(!Xae(e)||!Xae(e.auth))throw rze();tp(e,["auth","providerId"]);let r=Fd(e.providerId,"provider id");if(typeof t!="string"||!t.startsWith(`${r}/`))throw rze();return{auth:LXn(e.auth),providerId:r}},MXn=e=>{if(e!==void 0&&e!=="session.show/v1")throw new vo("The worker tool projection is unsupported.")},UXn=e=>{if(tp(e,["agentDirectory","history","protocolVersion","requestId","sessionId","type","workingDirectory"],["model","providerCredential","thinkingLevel","toolProjection"]),e.protocolVersion!==1)throw new vo("The worker protocol version is unsupported.");if(MXn(e.toolProjection),e.thinkingLevel!==void 0&&!PXn.has(e.thinkingLevel))throw new vo("The thinking level is invalid.")},FXn=e=>({...e.toolProjection===void 0?{}:{toolProjection:"session.show/v1"},...e.model===void 0?{}:{model:Ih(e.model,"model",256)},...e.providerCredential===void 0?{}:{providerCredential:DXn(e.providerCredential,e.model)},...e.thinkingLevel===void 0?{}:{thinkingLevel:e.thinkingLevel}}),HXn=e=>(UXn(e),{agentDirectory:Ih(e.agentDirectory,"agent directory",4096),history:NXn(e.history),...FXn(e),protocolVersion:1,requestId:Fd(e.requestId,"request id"),sessionId:Fd(e.sessionId,"session id"),type:"initialize",workingDirectory:Ih(e.workingDirectory,"working directory",4096)}),BXn=e=>(tp(e,["requestId","text","turnId","type"]),{requestId:Fd(e.requestId,"request id"),text:Ih(e.text,"prompt",49152),turnId:Fd(e.turnId,"turn id"),type:"prompt"}),qXn=e=>e.type==="interrupt"?(tp(e,["requestId","turnId","type"]),{requestId:Fd(e.requestId,"request id"),turnId:Fd(e.turnId,"turn id"),type:"interrupt"}):(tp(e,["requestId","type"]),{requestId:Fd(e.requestId,"request id"),type:"shutdown"}),IKt=e=>{try{let t=JSON.parse(e);if(Xae(t)&&typeof t.type=="string")return t}catch{throw new vo("The worker command is not valid JSON.")}throw new vo("The worker command is invalid.")},xKt=e=>{if(e.length===0||e.includes("\r")||e.includes(`
244
244
  `)||c0(e)>65536)throw new vo("The worker command is too large.");let t=IKt(e);if(t.type==="initialize")return HXn(t);if(t.type==="prompt")return BXn(t);if(t.type==="interrupt"||t.type==="shutdown")return qXn(t);throw new vo("The worker command type is unsupported.")},jXn=e=>{let t={requestId:Fd(e.requestId,"request id"),turnId:Fd(e.turnId,"turn id")};return e.type==="turn.completed"?(tp(e,["requestId","responseText","turnId","type"]),{...t,responseText:Ih(e.responseText,"response text",32768),type:"turn.completed"}):(tp(e,["requestId","turnId","type"]),{...t,type:e.type})},WXn=e=>{if(tp(e,["protocolVersion","requestId","type","workerSessionId"]),e.protocolVersion!==1)throw new vo("The worker protocol version is unsupported.");return{protocolVersion:1,requestId:Fd(e.requestId,"request id"),type:"initialized",workerSessionId:Fd(e.workerSessionId,"worker session id")}},$Xn=new Set(["invalid_request","invalid_state","request_conflict","runtime_failed"]),GXn=e=>{if(tp(e,["code","fatal","message","type"],["requestId"]),typeof e.code!="string"||!$Xn.has(e.code)||typeof e.fatal!="boolean")throw new vo("The worker error event is invalid.");return{code:e.code,fatal:e.fatal,message:Ih(e.message,"error message",512),...e.requestId===void 0?{}:{requestId:Fd(e.requestId,"request id")},type:"error"}},zXn=e=>{if(e.type==="initialized")return WXn(e);if(e.type==="error")return GXn(e);if(e.type==="shutdown.complete")return tp(e,["requestId","type"]),{requestId:Fd(e.requestId,"request id"),type:"shutdown.complete"};if(e.type==="turn.completed"||e.type==="turn.interrupted"||e.type==="turn.started")return jXn(e);throw new vo("The worker event type is unsupported.")},nze=e=>{if(e.length===0||e.includes("\r")||e.includes(`
245
245
  `)||c0(e)>1048576)throw new vo("The worker event is too large.");return zXn(IKt(e))},VXn=e=>{let t;try{t=JSON.stringify(e)}catch{throw new vo("The worker command cannot be encoded.")}xKt(t);let r=`${t}
246
246
  `;if(c0(r)>65536)throw new vo("The worker command is too large.");return r},KXn=e=>{let t=`${JSON.stringify(e)}
@@ -9080,6 +9080,6 @@ planned and unavailable.
9080
9080
  `);return}r.stdout(BRi(e))},qRi=(e,t,r)=>{if(t){r.stderr(`${JSON.stringify({error:e,ok:!1})}
9081
9081
  `);return}r.stderr(`maia-node: ${e.message}
9082
9082
  Run 'maia-node --help' for usage.
9083
- `)},uc=e=>({code:"invalid_argument",message:e,retryable:!1}),jRi=e=>({code:"command_not_implemented",message:`Command '${e.replaceAll(/[\p{C}]/gu,"\uFFFD")}' is not implemented.`,retryable:!1}),WRi=e=>{if(e.length>nur)return uc(`At most ${String(nur)} arguments are allowed.`);if(e.some(t=>t.length>our))return uc(`Arguments must be at most ${String(our)} characters.`)},sur=()=>uc(Nme),$Ri=(e,t)=>{let[r,n,o,i,...a]=e;if(r==="state")return n!=="check"?uc("Use 'maia-node state check [--profile <name>] [--json]'."):o===void 0?{command:"state-check",json:t,profile:NRi}:o!=="--profile"||a.length>0?uc("State check accepts only '--profile <name>' and '--json', each once."):i===void 0?uc("Option '--profile' requires a profile name."):HX(i)?{command:"state-check",json:t,profile:i}:sur()},GRi=(e,t)=>{let r=e.filter(a=>a==="--profile").length;if(r===0)return;if(r>1)return uc("Option '--profile' may be used only once.");let n=e.indexOf("--profile"),o=e[n+1];if(o===void 0)return uc("Option '--profile' requires a profile name.");if(!HX(o))return sur();let i=e.filter((a,c)=>c!==n&&c!==n+1);return i.length===1&&i[0]==="--desktop"?{command:"desktop",json:t,profile:o}:uc("Option '--profile' may be used only with '--desktop'.")},zRi=(e,t)=>{let r=$Ri(e,t)??GRi(e,t);if(r!==void 0)return r;if(e.length>1)return uc("Desktop, help, and version do not accept additional arguments.");let n=e[0];return n===void 0||ORi.has(n)?{command:"help",json:t}:LRi.has(n)?{command:"version",json:t}:n==="--desktop"?{command:"desktop",json:t}:n.startsWith("-")?uc(`Unknown option '${n.replaceAll(/[\p{C}]/gu,"\uFFFD")}'.`):jRi(n)},VRi=e=>{let t=e.filter(o=>o==="--json").length;if(t>1)return uc("Option '--json' may be used only once.");let r=e.filter(o=>o===Ome).length;if(r>1)return uc(`Option '${Ome}' may be used only once.`);let n=zRi(e.filter(o=>o!=="--json"&&o!==Ome),t===1);return r===0||aur(n)?n:n.command==="desktop"?{...n,bootstrapChannel:!0}:uc(`Option '${Ome}' may be used only with '--desktop'.`)},aur=e=>"code"in e,_b=e=>(qRi(e.error,e.json,e.io),e.exitCode??PRi),KRi=(e,t)=>({...e.bootstrapChannel===!0?{bootstrapChannel:!0}:{},io:t.io,...t.nativeProcessHostIdentity===void 0?{}:{nativeProcessHostIdentity:t.nativeProcessHostIdentity},...t.nodeExecutablePath===void 0?{}:{nodeExecutablePath:t.nodeExecutablePath},...t.portLeaseRange===void 0?{}:{portLeaseRange:t.portLeaseRange},...e.profile===void 0?{}:{profile:e.profile},version:t.version,...t.runtimeRootOverride===void 0?{}:{runtimeRootOverride:t.runtimeRootOverride}}),XRi=(e,t)=>(t.dependencies??{startDesktop:OF}).startDesktop(KRi(e,t)).pipe(s.as(0),s.catch(n=>s.sync(()=>_b({error:Am(n),exitCode:n.retryable?iur:oQe,io:t.io,json:e.json})))),JRi=(e,t)=>tur({profile:e.profile,...t.runtimeRootOverride===void 0?{}:{runtimeRootOverride:t.runtimeRootOverride},version:t.version}).pipe(s.provide(On),s.map(r=>(iQe(r,e.json,t.io),0)),s.catch(r=>s.sync(()=>_b({error:Am(r),exitCode:oQe,io:t.io,json:e.json})))),YRi=(e,t)=>Qlr(e,{...t.releaseHome===void 0?{}:{home:t.releaseHome},...t.releasePlatform===void 0?{}:{platform:t.releasePlatform},...t.runtimeRootOverride===void 0?{}:{runtimeRootOverride:t.runtimeRootOverride}}).pipe(s.provide(t.releaseServices??Zlr),s.map(r=>(iQe(r,e.json,t.io),0)),s.catch(r=>s.sync(()=>_b({error:Am(r),exitCode:r.retryable?iur:oQe,io:t.io,json:e.json})))),QRi=(e,t)=>{let r=Ylr(e);if(typeof r!="string")return YRi(r,t);let n=e.includes("--json");return s.sync(()=>_b({error:uc(r),io:t.io,json:n}))},ZRi=(e,t)=>e.command==="desktop"?XRi(e,t):e.command==="state-check"?JRi(e,t):s.sync(()=>{let r=e.command==="help"?URi(t.version):FRi(t.version);return iQe(r,e.json,t.io),0}),evi=(e,t)=>{let r=x8e(e);return typeof r=="string"?s.sync(()=>_b({error:uc(r),io:t.io,json:e.includes("--json")})):A8e(r,{io:t.io,...t.runtimeRootOverride===void 0?{}:{runtimeRootOverride:t.runtimeRootOverride},version:t.version}).pipe(s.provide(t.remotePlatform??AF))},Lme=(e,t)=>{if(e[0]==="bridge"||e[0]==="remote")return evi(e,t);let r=WRi(e);if(r!==void 0)return s.sync(()=>_b({error:r,io:t.io,json:e.includes("--json")}));if(e[0]==="release")return QRi(e,t);let n=VRi(e);return aur(n)?s.sync(()=>_b({error:n,io:t.io,json:e.includes("--json")})):ZRi(n,t)};q();var cur=1e4,DF=class extends dt.Service()("maia/ShutdownDeadline"){},BX=class extends dt.Service()("maia/DesktopParent"){static layer=Ve.effect(this,s.gen(function*(){return{closed:(yield*II.Stdio).stdin.pipe(Qe.runDrain,s.ignore,s.ensuring(s.sync(()=>{process.stdin.destroy()}))),forceExit:s.sync(()=>{process.kill(process.pid,"SIGKILL")})}})).pipe(Ve.provide(hme))},dur=e=>s.gen(function*(){let t=yield*BX,r=yield*e.pipe(s.forkChild),n=s.gen(function*(){yield*t.closed;let o=yield*s.serviceOption(DF);if(K.isSome(o)){let i=Number((yield*lt.monotonicTimeNanos)/1000000n);yield*Ce.set(o.value,i+cur)}return yield*_o.interrupt(r).pipe(s.forkChild),yield*s.sleep(cur),yield*t.forceExit,yield*s.never});return yield*_o.join(r).pipe(s.raceFirst(n))}),sQe=e=>s.gen(function*(){return yield*(yield*Oi.String("MAIA_DESKTOP_PARENT_PIPE").pipe(Oi.withDefault("0"),s.orDie))==="1"?dur(e).pipe(s.provide(BX.layer)):e});$();NTe();var lur=kTe(({fiber:e,teardown:t})=>{let r=!1;e.addObserver(o=>{process.removeListener("SIGINT",n),process.removeListener("SIGTERM",n),t(o,i=>{(r||i!==0)&&process.exit(i)})});function n(){r=!0,e.interruptUnsafe(e.id)}process.on("SIGINT",n),process.on("SIGTERM",n)});q();var rvi=5e3,uur=e=>s.gen(function*(){let t=yield*J.make(),r=()=>{J.doneUnsafe(t,s.succeed(!0))};e.on("error",r),e.on("close",r);let n=s.callback(o=>{if(e.writableLength===0){o(s.succeed(!0));return}e.write("",()=>{o(s.succeed(!0))})});return s.raceFirst(J.await(t),n)}),nvi=e=>Bt.isSuccess(e)?e.value:Er.hasInterruptsOnly(e.cause)?0:sN.getErrorExitCode(Er.squash(e.cause)),ovi=(e,t)=>s.gen(function*(){let r=Number((yield*lt.monotonicTimeNanos)/1000000n),n=(yield*Ce.get(t))-r;return yield*s.all(e,{concurrency:"unbounded",discard:!0}).pipe(s.timeoutOption(Math.min(rvi,n)))}),ivi=(e,t)=>s.uninterruptibleMask(r=>s.gen(function*(){let n=[yield*uur(t.stdout),yield*uur(t.stderr)];yield*s.yieldNow;let o=yield*J.make(),i=yield*Ce.make(Number.POSITIVE_INFINITY),a=yield*s.forkChild(e.pipe(s.onExit(p=>J.succeed(o,p)),s.provideService(DF,i)),{startImmediately:!0});yield*s.exit(r(_o.await(a))),yield*_o.interrupt(a);let c=yield*J.await(o),l=nvi(c),u=yield*ovi(n,i);(l!==0||Bt.isFailure(c)||K.isNone(u))&&t.exit(l)})),svi=(e,t)=>{if(Bt.isFailure(e)&&!Er.hasInterruptsOnly(e.cause)){sN.defaultTeardown(e,t);return}t(0)},pur=(e,t)=>{lur(ivi(e,t),{disableErrorReporting:!0,teardown:svi})};var cvi=()=>({nodeVersion:"24.22.1",version:"0.1.0-canary.12"}),Dme=cvi(),mur={stderr(e){process.stderr.write(e)},stdout(e){process.stdout.write(e)}},fur=process.env.MAIA_NODE_TEST_MODE==="1"?process.env.MAIA_NODE_TEST_RUNTIME_ROOT:void 0,hur=process.env.MAIA_PORT_RANGE,yur=avi(import.meta.url),dvi=e=>s.try({catch:t=>m("transport_failed",t instanceof Error?t.message:String(t)),try:xse}).pipe(s.flatMap(t=>OF({...e,afterProfileLock:r=>B1e({modulePath:yur,profile:r,running:Dme.version}).pipe(s.provide(On)),...t===void 0?{}:{nativeProcessHostIdentity:t,nodeExecutablePath:yur}})));if(process.versions.node===Dme.nodeVersion){let e=Lme(process.argv.slice(2),{dependencies:{startDesktop:t=>dvi(t).pipe(sQe)},io:mur,...hur===void 0?{}:{portLeaseRange:hur},...fur===void 0?{}:{runtimeRootOverride:fur},version:Dme.version});pur(e,process)}else mur.stderr(`Maia Node requires Node ${Dme.nodeVersion}; received ${process.versions.node}.
9083
+ `)},uc=e=>({code:"invalid_argument",message:e,retryable:!1}),jRi=e=>({code:"command_not_implemented",message:`Command '${e.replaceAll(/[\p{C}]/gu,"\uFFFD")}' is not implemented.`,retryable:!1}),WRi=e=>{if(e.length>nur)return uc(`At most ${String(nur)} arguments are allowed.`);if(e.some(t=>t.length>our))return uc(`Arguments must be at most ${String(our)} characters.`)},sur=()=>uc(Nme),$Ri=(e,t)=>{let[r,n,o,i,...a]=e;if(r==="state")return n!=="check"?uc("Use 'maia-node state check [--profile <name>] [--json]'."):o===void 0?{command:"state-check",json:t,profile:NRi}:o!=="--profile"||a.length>0?uc("State check accepts only '--profile <name>' and '--json', each once."):i===void 0?uc("Option '--profile' requires a profile name."):HX(i)?{command:"state-check",json:t,profile:i}:sur()},GRi=(e,t)=>{let r=e.filter(a=>a==="--profile").length;if(r===0)return;if(r>1)return uc("Option '--profile' may be used only once.");let n=e.indexOf("--profile"),o=e[n+1];if(o===void 0)return uc("Option '--profile' requires a profile name.");if(!HX(o))return sur();let i=e.filter((a,c)=>c!==n&&c!==n+1);return i.length===1&&i[0]==="--desktop"?{command:"desktop",json:t,profile:o}:uc("Option '--profile' may be used only with '--desktop'.")},zRi=(e,t)=>{let r=$Ri(e,t)??GRi(e,t);if(r!==void 0)return r;if(e.length>1)return uc("Desktop, help, and version do not accept additional arguments.");let n=e[0];return n===void 0||ORi.has(n)?{command:"help",json:t}:LRi.has(n)?{command:"version",json:t}:n==="--desktop"?{command:"desktop",json:t}:n.startsWith("-")?uc(`Unknown option '${n.replaceAll(/[\p{C}]/gu,"\uFFFD")}'.`):jRi(n)},VRi=e=>{let t=e.filter(o=>o==="--json").length;if(t>1)return uc("Option '--json' may be used only once.");let r=e.filter(o=>o===Ome).length;if(r>1)return uc(`Option '${Ome}' may be used only once.`);let n=zRi(e.filter(o=>o!=="--json"&&o!==Ome),t===1);return r===0||aur(n)?n:n.command==="desktop"?{...n,bootstrapChannel:!0}:uc(`Option '${Ome}' may be used only with '--desktop'.`)},aur=e=>"code"in e,_b=e=>(qRi(e.error,e.json,e.io),e.exitCode??PRi),KRi=(e,t)=>({...e.bootstrapChannel===!0?{bootstrapChannel:!0}:{},io:t.io,...t.nativeProcessHostIdentity===void 0?{}:{nativeProcessHostIdentity:t.nativeProcessHostIdentity},...t.nodeExecutablePath===void 0?{}:{nodeExecutablePath:t.nodeExecutablePath},...t.portLeaseRange===void 0?{}:{portLeaseRange:t.portLeaseRange},...e.profile===void 0?{}:{profile:e.profile},version:t.version,...t.runtimeRootOverride===void 0?{}:{runtimeRootOverride:t.runtimeRootOverride}}),XRi=(e,t)=>(t.dependencies??{startDesktop:OF}).startDesktop(KRi(e,t)).pipe(s.as(0),s.catch(n=>s.sync(()=>_b({error:Am(n),exitCode:n.retryable?iur:oQe,io:t.io,json:e.json})))),JRi=(e,t)=>tur({profile:e.profile,...t.runtimeRootOverride===void 0?{}:{runtimeRootOverride:t.runtimeRootOverride},version:t.version}).pipe(s.provide(On),s.map(r=>(iQe(r,e.json,t.io),0)),s.catch(r=>s.sync(()=>_b({error:Am(r),exitCode:oQe,io:t.io,json:e.json})))),YRi=(e,t)=>Qlr(e,{...t.releaseHome===void 0?{}:{home:t.releaseHome},...t.releasePlatform===void 0?{}:{platform:t.releasePlatform},...t.runtimeRootOverride===void 0?{}:{runtimeRootOverride:t.runtimeRootOverride}}).pipe(s.provide(t.releaseServices??Zlr),s.map(r=>(iQe(r,e.json,t.io),0)),s.catch(r=>s.sync(()=>_b({error:Am(r),exitCode:r.retryable?iur:oQe,io:t.io,json:e.json})))),QRi=(e,t)=>{let r=Ylr(e);if(typeof r!="string")return YRi(r,t);let n=e.includes("--json");return s.sync(()=>_b({error:uc(r),io:t.io,json:n}))},ZRi=(e,t)=>e.command==="desktop"?XRi(e,t):e.command==="state-check"?JRi(e,t):s.sync(()=>{let r=e.command==="help"?URi(t.version):FRi(t.version);return iQe(r,e.json,t.io),0}),evi=(e,t)=>{let r=x8e(e);return typeof r=="string"?s.sync(()=>_b({error:uc(r),io:t.io,json:e.includes("--json")})):A8e(r,{io:t.io,...t.runtimeRootOverride===void 0?{}:{runtimeRootOverride:t.runtimeRootOverride},version:t.version}).pipe(s.provide(t.remotePlatform??AF))},Lme=(e,t)=>{if(e[0]==="bridge"||e[0]==="remote")return evi(e,t);let r=WRi(e);if(r!==void 0)return s.sync(()=>_b({error:r,io:t.io,json:e.includes("--json")}));if(e[0]==="release")return QRi(e,t);let n=VRi(e);return aur(n)?s.sync(()=>_b({error:n,io:t.io,json:e.includes("--json")})):ZRi(n,t)};q();var cur=1e4,DF=class extends dt.Service()("maia/ShutdownDeadline"){},BX=class extends dt.Service()("maia/DesktopParent"){static layer=Ve.effect(this,s.gen(function*(){return{closed:(yield*II.Stdio).stdin.pipe(Qe.runDrain,s.ignore,s.ensuring(s.sync(()=>{process.stdin.destroy()}))),forceExit:s.sync(()=>{process.kill(process.pid,"SIGKILL")})}})).pipe(Ve.provide(hme))},dur=e=>s.gen(function*(){let t=yield*BX,r=yield*e.pipe(s.forkChild),n=s.gen(function*(){yield*t.closed;let o=yield*s.serviceOption(DF);if(K.isSome(o)){let i=Number((yield*lt.monotonicTimeNanos)/1000000n);yield*Ce.set(o.value,i+cur)}return yield*_o.interrupt(r).pipe(s.forkChild),yield*s.sleep(cur),yield*t.forceExit,yield*s.never});return yield*_o.join(r).pipe(s.raceFirst(n))}),sQe=e=>s.gen(function*(){return yield*(yield*Oi.String("MAIA_DESKTOP_PARENT_PIPE").pipe(Oi.withDefault("0"),s.orDie))==="1"?dur(e).pipe(s.provide(BX.layer)):e});$();NTe();var lur=kTe(({fiber:e,teardown:t})=>{let r=!1;e.addObserver(o=>{process.removeListener("SIGINT",n),process.removeListener("SIGTERM",n),t(o,i=>{(r||i!==0)&&process.exit(i)})});function n(){r=!0,e.interruptUnsafe(e.id)}process.on("SIGINT",n),process.on("SIGTERM",n)});q();var rvi=5e3,uur=e=>s.gen(function*(){let t=yield*J.make(),r=()=>{J.doneUnsafe(t,s.succeed(!0))};e.on("error",r),e.on("close",r);let n=s.callback(o=>{if(e.writableLength===0){o(s.succeed(!0));return}e.write("",()=>{o(s.succeed(!0))})});return s.raceFirst(J.await(t),n)}),nvi=e=>Bt.isSuccess(e)?e.value:Er.hasInterruptsOnly(e.cause)?0:sN.getErrorExitCode(Er.squash(e.cause)),ovi=(e,t)=>s.gen(function*(){let r=Number((yield*lt.monotonicTimeNanos)/1000000n),n=(yield*Ce.get(t))-r;return yield*s.all(e,{concurrency:"unbounded",discard:!0}).pipe(s.timeoutOption(Math.min(rvi,n)))}),ivi=(e,t)=>s.uninterruptibleMask(r=>s.gen(function*(){let n=[yield*uur(t.stdout),yield*uur(t.stderr)];yield*s.yieldNow;let o=yield*J.make(),i=yield*Ce.make(Number.POSITIVE_INFINITY),a=yield*s.forkChild(e.pipe(s.onExit(p=>J.succeed(o,p)),s.provideService(DF,i)),{startImmediately:!0});yield*s.exit(r(_o.await(a))),yield*_o.interrupt(a);let c=yield*J.await(o),l=nvi(c),u=yield*ovi(n,i);(l!==0||Bt.isFailure(c)||K.isNone(u))&&t.exit(l)})),svi=(e,t)=>{if(Bt.isFailure(e)&&!Er.hasInterruptsOnly(e.cause)){sN.defaultTeardown(e,t);return}t(0)},pur=(e,t)=>{lur(ivi(e,t),{disableErrorReporting:!0,teardown:svi})};var cvi=()=>({nodeVersion:"24.22.1",version:"0.1.0-canary.13"}),Dme=cvi(),mur={stderr(e){process.stderr.write(e)},stdout(e){process.stdout.write(e)}},fur=process.env.MAIA_NODE_TEST_MODE==="1"?process.env.MAIA_NODE_TEST_RUNTIME_ROOT:void 0,hur=process.env.MAIA_PORT_RANGE,yur=avi(import.meta.url),dvi=e=>s.try({catch:t=>m("transport_failed",t instanceof Error?t.message:String(t)),try:xse}).pipe(s.flatMap(t=>OF({...e,afterProfileLock:r=>B1e({modulePath:yur,profile:r,running:Dme.version}).pipe(s.provide(On)),...t===void 0?{}:{nativeProcessHostIdentity:t,nodeExecutablePath:yur}})));if(process.versions.node===Dme.nodeVersion){let e=Lme(process.argv.slice(2),{dependencies:{startDesktop:t=>dvi(t).pipe(sQe)},io:mur,...hur===void 0?{}:{portLeaseRange:hur},...fur===void 0?{}:{runtimeRootOverride:fur},version:Dme.version});pur(e,process)}else mur.stderr(`Maia Node requires Node ${Dme.nodeVersion}; received ${process.versions.node}.
9084
9084
  `),process.exitCode=69;
9085
9085
  //# sourceMappingURL=maia-node.mjs.map
@@ -2,15 +2,15 @@
2
2
  "application": {
3
3
  "name": "@maiaos/node",
4
4
  "path": "services/node/dist/bin/maia-node.mjs",
5
- "sha256": "808b43807c21a4921bbdb91add3fd2f58b442bc2600f6acdf6ff800d33a33e67",
6
- "version": "0.1.0-canary.12"
5
+ "sha256": "da1d3731dbde70b70deee8c166accba128b6c9baca1e435de080fd2575d49b87",
6
+ "version": "0.1.0-canary.13"
7
7
  },
8
8
  "artifacts": [
9
9
  {
10
10
  "bytes": 59960,
11
11
  "path": "services/node/dist/bin/maia-node.cdx.json",
12
12
  "role": "sbom",
13
- "sha256": "fae501783b908099e2072060a7f6db5dc3902c29c5edf90157fa2d82feadec36"
13
+ "sha256": "0c2b819a9a151166a568670007cf2cba761ebf3af38a8b933e48ce58adfe1379"
14
14
  },
15
15
  {
16
16
  "bytes": 2720549,
@@ -22,7 +22,7 @@
22
22
  "bytes": 3941097,
23
23
  "path": "services/node/dist/bin/maia-node.mjs",
24
24
  "role": "application",
25
- "sha256": "808b43807c21a4921bbdb91add3fd2f58b442bc2600f6acdf6ff800d33a33e67"
25
+ "sha256": "da1d3731dbde70b70deee8c166accba128b6c9baca1e435de080fd2575d49b87"
26
26
  },
27
27
  {
28
28
  "bytes": 4967655,
@@ -46,7 +46,7 @@
46
46
  "bytes": 2143,
47
47
  "path": "services/node/dist/bin/maia-process-host-darwin-arm64.build.json",
48
48
  "role": "native-build-metadata",
49
- "sha256": "fcc19950a83b10ad2b326e7e90db7af39a3a53b5ebcb88c5c03457c16c9d45af"
49
+ "sha256": "71dbb7d86e7b510db411c29e820ecef4d9519f16916e64245b1df8d9b47b08a5"
50
50
  },
51
51
  {
52
52
  "bytes": 76896,
@@ -58,7 +58,7 @@
58
58
  "bytes": 2135,
59
59
  "path": "services/node/dist/bin/maia-process-host-linux-x64.build.json",
60
60
  "role": "native-build-metadata",
61
- "sha256": "4a2017c9e7c46e38203bfe120ea078b55ec126b1db1c36cb195cb634f2d072a6"
61
+ "sha256": "7b4470f11fa68978df5db2b231e772c06be7260f4aa2a711b29b34d7af255ac1"
62
62
  }
63
63
  ],
64
64
  "footprint": {
@@ -53,7 +53,7 @@
53
53
  "services/node/native/process-host/darwin.c": "078dfb946de49fd985f8dad8b0a49e72176a2880100d0ab803dcf06bc34a94bd",
54
54
  "services/node/native/process-host/protocol.h": "00da3b9839edc922b867981ff263691ebffeadee1c1b5f4f35658a8d5ddbc989"
55
55
  },
56
- "revision": "349404b24e33d6c130d9b352e4d3d6ccdfea8731"
56
+ "revision": "6ba12d869c441158b339971c20c02e21c32be894"
57
57
  },
58
58
  "targetTriple": "darwin-arm64"
59
59
  }
@@ -58,7 +58,7 @@
58
58
  "services/node/native/process-host/protocol.h": "00da3b9839edc922b867981ff263691ebffeadee1c1b5f4f35658a8d5ddbc989",
59
59
  "services/node/native/process-host/sha256.h": "b2a686bbe44f7a67b14b9550fd5166db560fbb23104654ae818a92a69b07f819"
60
60
  },
61
- "revision": "349404b24e33d6c130d9b352e4d3d6ccdfea8731"
61
+ "revision": "6ba12d869c441158b339971c20c02e21c32be894"
62
62
  },
63
63
  "targetTriple": "linux-x64"
64
64
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiaos/node",
3
- "version": "0.1.0-canary.12",
3
+ "version": "0.1.0-canary.13",
4
4
  "description": "Maia Node: the local authority that owns Sessions, worker accounts, durable state, events and receipts for swarms of AI coding agents.",
5
5
  "keywords": [
6
6
  "maia",
@@ -44,8 +44,8 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@effect/vitest": "4.0.0",
47
- "@maiaos/cli": "0.1.0-canary.12",
48
- "@maiaos/sdk": "0.1.0-canary.12",
47
+ "@maiaos/cli": "0.1.0-canary.13",
48
+ "@maiaos/sdk": "0.1.0-canary.13",
49
49
  "@types/node": "24.13.3",
50
50
  "@typescript/native": "npm:typescript@7.0.2",
51
51
  "@vitest/coverage-v8": "5.0.3",
@@ -59,8 +59,8 @@
59
59
  "dependencies": {
60
60
  "@anthropic-ai/claude-agent-sdk": "0.3.285",
61
61
  "@effect/platform-node-shared": "4.0.0",
62
- "@maiaos/agent": "0.1.0-canary.12",
63
- "@maiaos/protocol": "0.1.0-canary.12",
62
+ "@maiaos/agent": "0.1.0-canary.13",
63
+ "@maiaos/protocol": "0.1.0-canary.13",
64
64
  "effect": "4.0.0",
65
65
  "jsonc-parser": "3.3.1",
66
66
  "xstate": "5.32.5"