@cortex-agent/server 2026.10.28 → 2026.12.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (401) hide show
  1. package/LICENSE +255 -21
  2. package/README.md +36 -7
  3. package/THIRD_PARTY_NOTICES.txt +1990 -593
  4. package/defaults/hooks/cortex-hook-api.mjs +2 -1
  5. package/defaults/hooks/quota-stop.mjs +37 -0
  6. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +23 -15
  7. package/defaults/prompts/clean-workspace.md +5 -0
  8. package/dist/agent-adapter/claude/remote-mcp-proxy.js +1 -1
  9. package/dist/chunks/agent-runner-LVZVKBZX.js +4 -0
  10. package/dist/chunks/anthropic-messages-TT6454AA.js +8 -0
  11. package/dist/chunks/azure-openai-responses-52LR2XZD.js +4 -0
  12. package/dist/chunks/bedrock-converse-stream-EOZGYUNY.js +60 -0
  13. package/dist/chunks/bowser-MLGGLXTZ.js +20 -0
  14. package/dist/chunks/child-runner-SMG2VOU5.js +4 -0
  15. package/dist/chunks/chunk-24DH4IR5.js +4 -0
  16. package/dist/chunks/chunk-25XKBRDT.js +70 -0
  17. package/dist/chunks/chunk-2ABET62E.js +23 -0
  18. package/dist/chunks/chunk-2BVUA256.js +4 -0
  19. package/dist/chunks/{chunk-LEUENXI2.js → chunk-2WFL62UO.js} +1 -1
  20. package/dist/chunks/{chunk-OZGBWAT2.js → chunk-2YTYYG4K.js} +1 -1
  21. package/dist/chunks/chunk-335SSANX.js +4 -0
  22. package/dist/chunks/chunk-377OPTXX.js +17 -0
  23. package/dist/chunks/chunk-3EZNVLBF.js +129 -0
  24. package/dist/chunks/chunk-3O6ZG5HA.js +7 -0
  25. package/dist/chunks/{chunk-6AKUD3CF.js → chunk-3XLHL5YT.js} +1 -1
  26. package/dist/chunks/chunk-4HRI75GU.js +4 -0
  27. package/dist/chunks/chunk-4JBYLRPM.js +57 -0
  28. package/dist/chunks/chunk-4KKV7VKE.js +4 -0
  29. package/dist/chunks/chunk-4KQHDDC5.js +4 -0
  30. package/dist/chunks/chunk-4SWD4JMP.js +33 -0
  31. package/dist/chunks/chunk-52VCLZS5.js +4 -0
  32. package/dist/chunks/chunk-54P7TSY3.js +10 -0
  33. package/dist/chunks/chunk-5DVSAXOI.js +7 -0
  34. package/dist/chunks/chunk-5F3A62YS.js +4 -0
  35. package/dist/chunks/{chunk-XNSSUVT6.js → chunk-5FHETFZM.js} +1 -1
  36. package/dist/chunks/{chunk-A34TDMIC.js → chunk-5LBLRAHS.js} +1 -1
  37. package/dist/chunks/chunk-5UYVNA3W.js +4 -0
  38. package/dist/chunks/chunk-6G3OYMCV.js +21 -0
  39. package/dist/chunks/chunk-7GGPYU5E.js +30 -0
  40. package/dist/chunks/chunk-7TYSMLUV.js +4 -0
  41. package/dist/chunks/chunk-7W7VYUTK.js +5 -0
  42. package/dist/chunks/chunk-AXYAZTTN.js +6 -0
  43. package/dist/chunks/{chunk-BGVHA2D4.js → chunk-B3NB243Z.js} +1 -1
  44. package/dist/chunks/chunk-BKYP6AGM.js +8 -0
  45. package/dist/chunks/chunk-BVEDNESB.js +4 -0
  46. package/dist/chunks/chunk-BWDJS6A4.js +12 -0
  47. package/dist/chunks/chunk-C6YVF7EI.js +4 -0
  48. package/dist/chunks/chunk-CEJIYYVE.js +15 -0
  49. package/dist/chunks/chunk-CI2RHH74.js +50 -0
  50. package/dist/chunks/chunk-CMSOOLJB.js +4 -0
  51. package/dist/chunks/chunk-CSVTYYLP.js +4 -0
  52. package/dist/chunks/chunk-DE5EGVKG.js +6 -0
  53. package/dist/chunks/{chunk-E6BYRULL.js → chunk-DK3RPZOQ.js} +1 -1
  54. package/dist/chunks/{chunk-YPK2CAIZ.js → chunk-DK4UCK7L.js} +1 -1
  55. package/dist/chunks/chunk-DYLBVUAU.js +4 -0
  56. package/dist/chunks/chunk-FDC2GRBK.js +27 -0
  57. package/dist/chunks/chunk-FE7HH5JS.js +18 -0
  58. package/dist/chunks/chunk-FYD57YRO.js +436 -0
  59. package/dist/chunks/chunk-G264APQN.js +5 -0
  60. package/dist/chunks/chunk-G4JYZFEO.js +11 -0
  61. package/dist/chunks/chunk-GFFM56U2.js +4 -0
  62. package/dist/chunks/chunk-GOS3P7KS.js +132 -0
  63. package/dist/chunks/chunk-HVN37UXD.js +4 -0
  64. package/dist/chunks/chunk-IA6IODY3.js +4 -0
  65. package/dist/chunks/{chunk-HU6UIDEJ.js → chunk-IGZWZP7Z.js} +1 -1
  66. package/dist/chunks/{chunk-NR6U3WIZ.js → chunk-IJ7XFQMI.js} +1 -1
  67. package/dist/chunks/chunk-IMMGYDAB.js +6 -0
  68. package/dist/chunks/chunk-IOWBF7UK.js +10 -0
  69. package/dist/chunks/{chunk-HALUQ7ZF.js → chunk-ITGCWQFK.js} +1 -1
  70. package/dist/chunks/chunk-IVZ7QUEG.js +4 -0
  71. package/dist/chunks/{chunk-YAEVYJAR.js → chunk-IWY2HIFK.js} +1 -1
  72. package/dist/chunks/{chunk-KGJZAYQD.js → chunk-J7OBATRN.js} +1 -1
  73. package/dist/chunks/{chunk-QWAQHHRS.js → chunk-JGUEIW2W.js} +1 -1
  74. package/dist/chunks/chunk-JKL3AK5D.js +106 -0
  75. package/dist/chunks/chunk-JZ7U7RUK.js +351 -0
  76. package/dist/chunks/chunk-KJUQCCB5.js +4 -0
  77. package/dist/chunks/chunk-KST6OY76.js +10 -0
  78. package/dist/chunks/chunk-KZSAFVSY.js +129 -0
  79. package/dist/chunks/chunk-LD2ZSH3M.js +903 -0
  80. package/dist/chunks/chunk-LE6QPXN6.js +7 -0
  81. package/dist/chunks/chunk-LEAV3FFG.js +4 -0
  82. package/dist/chunks/chunk-LIIZI3HY.js +5 -0
  83. package/dist/chunks/chunk-LP72AF56.js +45 -0
  84. package/dist/chunks/{chunk-FXDIR3SQ.js → chunk-MJQ2D2OP.js} +1 -1
  85. package/dist/chunks/{chunk-6LZK4DDH.js → chunk-NHHR4DCF.js} +1 -1
  86. package/dist/chunks/chunk-NW4GW47L.js +4 -0
  87. package/dist/chunks/chunk-OALEJ6FG.js +60 -0
  88. package/dist/chunks/chunk-OIV4DIMB.js +4 -0
  89. package/dist/chunks/chunk-OJ37ZWBG.js +4 -0
  90. package/dist/chunks/chunk-OZXMPBUX.js +4 -0
  91. package/dist/chunks/{chunk-3THJYAEF.js → chunk-PG7452XE.js} +1 -1
  92. package/dist/chunks/chunk-PJCUB7YJ.js +4 -0
  93. package/dist/chunks/chunk-PTS3J4DQ.js +6 -0
  94. package/dist/chunks/{chunk-PXS5SHOV.js → chunk-PVVEEBUU.js} +1 -1
  95. package/dist/chunks/chunk-Q7BZLPBU.js +8 -0
  96. package/dist/chunks/{chunk-FOJQXLL2.js → chunk-QC66ZXPP.js} +1 -1
  97. package/dist/chunks/chunk-QXFWIL4C.js +4 -0
  98. package/dist/chunks/{chunk-PFMEUFJ7.js → chunk-R2CCD4OF.js} +1 -1
  99. package/dist/chunks/chunk-R6CGBSTC.js +22 -0
  100. package/dist/chunks/chunk-RG5GP4RB.js +5 -0
  101. package/dist/chunks/{chunk-D3NXKK2L.js → chunk-RW2F2QNP.js} +1 -1
  102. package/dist/chunks/{models-L5VF4I5O-XXNJYQMQ.js → chunk-RWPO3NZ3.js} +1 -1
  103. package/dist/chunks/chunk-SAJD4EKE.js +10 -0
  104. package/dist/chunks/chunk-SDUS2H3E.js +4 -0
  105. package/dist/chunks/chunk-SIHGKM4E.js +4 -0
  106. package/dist/chunks/chunk-SKHFU5DI.js +4 -0
  107. package/dist/chunks/{chunk-STUHNKQS.js → chunk-SM45TH22.js} +1 -1
  108. package/dist/chunks/chunk-T54CZKNJ.js +6 -0
  109. package/dist/chunks/chunk-TKFFQNAP.js +19 -0
  110. package/dist/chunks/chunk-TMV2ZDOI.js +18 -0
  111. package/dist/chunks/chunk-TRXLIL7V.js +4 -0
  112. package/dist/chunks/{chunk-SUFW24P4.js → chunk-UEEW2R4E.js} +1 -1
  113. package/dist/chunks/chunk-UHXPRU6G.js +10 -0
  114. package/dist/chunks/chunk-UPQVWHZ3.js +4 -0
  115. package/dist/chunks/{chunk-JERCOLY3.js → chunk-V35MFAUQ.js} +4 -6
  116. package/dist/chunks/chunk-V7K3KNDM.js +4 -0
  117. package/dist/chunks/chunk-VHX2GHBF.js +4 -0
  118. package/dist/chunks/chunk-VOAKRJ4R.js +4 -0
  119. package/dist/chunks/{chunk-X2GYYRVM.js → chunk-VW7TLY3P.js} +1 -1
  120. package/dist/chunks/chunk-W34AK4SK.js +65 -0
  121. package/dist/chunks/{chunk-REBNWCKI.js → chunk-WU7RNAZD.js} +1 -1
  122. package/dist/chunks/chunk-WZC4TDDM.js +6 -0
  123. package/dist/chunks/chunk-WZYS2HAK.js +4 -0
  124. package/dist/chunks/chunk-X2TKJ7KR.js +11 -0
  125. package/dist/chunks/{chunk-H2FP6DG4.js → chunk-X5ND4H4P.js} +1 -1
  126. package/dist/chunks/{chunk-4U7XXM4W.js → chunk-Y3AOGNDT.js} +1 -1
  127. package/dist/chunks/chunk-Y6DGVTKM.js +6 -0
  128. package/dist/chunks/{chunk-KENCMLRE.js → chunk-YAEHSSR4.js} +1 -1
  129. package/dist/chunks/chunk-YWPBE5LP.js +4 -0
  130. package/dist/chunks/chunk-ZAVX7G2M.js +15 -0
  131. package/dist/chunks/chunk-ZD2M73XA.js +19 -0
  132. package/dist/chunks/chunk-ZD4O6NPV.js +4 -0
  133. package/dist/chunks/chunk-ZNAMETPQ.js +4 -0
  134. package/dist/chunks/chunk-ZY6N5LVQ.js +4 -0
  135. package/dist/chunks/chunk-ZYQ4TDTT.js +81 -0
  136. package/dist/chunks/cli-VB2N7HEK.js +55 -0
  137. package/dist/chunks/cloudflare-workers-ai-system-one-YKU742EC.js +4 -0
  138. package/dist/chunks/context-CI2FKEQE.js +4 -0
  139. package/dist/chunks/cost-CZRRSIUF.js +5 -0
  140. package/dist/chunks/dist-QCNQN6DY.js +4 -0
  141. package/dist/chunks/easter-egg-3d-XR5S2O3T.js +4 -0
  142. package/dist/chunks/{event-streams-3JSFPOTZ.js → event-streams-AVE4MSS6.js} +1 -1
  143. package/dist/chunks/{execution-repo-ZLJTBWFC.js → execution-repo-5TLV2NM4.js} +1 -1
  144. package/dist/chunks/{executions-6ARGR3IO.js → executions-I3UUIGSL.js} +1 -1
  145. package/dist/chunks/file-Y5G56IUT.js +4 -0
  146. package/dist/chunks/github-copilot-BRU2SRRZ.js +4 -0
  147. package/dist/chunks/google-generative-ai-ZF5QEUZV.js +4 -0
  148. package/dist/chunks/google-vertex-4PJZZI3Y.js +4 -0
  149. package/dist/chunks/init-A6GY656J.js +4 -0
  150. package/dist/chunks/{install-cli-4IZCSDFZ.js → install-cli-FALWKQYO.js} +1 -1
  151. package/dist/chunks/{interaction-ask-G5T3H3CG.js → interaction-ask-O5HGF6CH.js} +1 -1
  152. package/dist/chunks/{interaction-plan-E5V42MUP.js → interaction-plan-JTVDN3BC.js} +1 -1
  153. package/dist/chunks/kimi-coding-ZCIBMDZ6.js +4 -0
  154. package/dist/chunks/{llama-cpp-classify-OTXZWCMW.js → llama-cpp-classify-NRUXAIGQ.js} +3 -3
  155. package/dist/chunks/local-client-stop-RS4AHNF4.js +4 -0
  156. package/dist/chunks/{memory-cli-PYOILNN5.js → memory-cli-DIT4DQF3.js} +1 -1
  157. package/dist/chunks/meta-JQH66YU7.js +4 -0
  158. package/dist/chunks/mistral-conversations-CXHOECUV.js +7 -0
  159. package/dist/chunks/model-resolver-GIBPYRKP.js +4 -0
  160. package/dist/chunks/monitor-Z2HKNY5E.js +4 -0
  161. package/dist/chunks/{node-PTK2HCDV.js → node-DAO3SX7O.js} +1 -1
  162. package/dist/chunks/{openai-codex-2REL6UQU.js → openai-codex-JULCKICT.js} +1 -1
  163. package/dist/chunks/openai-codex-responses-U6DGMGDK.js +12 -0
  164. package/dist/chunks/openai-completions-PP4XLLOM.js +9 -0
  165. package/dist/chunks/{openai-decisions-2N6ZRPZC.js → openai-decisions-JU6QQKEM.js} +1 -1
  166. package/dist/chunks/openai-responses-2SG757TL.js +6 -0
  167. package/dist/chunks/openrouter-images-32M7YZWC.js +4 -0
  168. package/dist/chunks/pi-messages-VSINMXN4.js +10 -0
  169. package/dist/chunks/radius-THYKWV4E.js +4 -0
  170. package/dist/chunks/remote-ops-2WBEFQ3E.js +14 -0
  171. package/dist/chunks/runner-5MKMRTIN.js +4 -0
  172. package/dist/chunks/runtime-DST3H5JP.js +4 -0
  173. package/dist/chunks/schedule-cli-V7Y2BBVY.js +4 -0
  174. package/dist/chunks/slack-R7SEJYMY.js +4 -0
  175. package/dist/chunks/start-ui-http-7K5JOLPU.js +43 -0
  176. package/dist/chunks/subagent-Z5IQ4L54.js +4 -0
  177. package/dist/chunks/{time-KEHDQT6K.js → time-P6PE52WL.js} +1 -1
  178. package/dist/chunks/tool-shims-YCXZWTST.js +4 -0
  179. package/dist/chunks/typesafe-system-one-M2DABJSZ.js +4 -0
  180. package/dist/chunks/ui-board-HQIE4RZG.js +5 -0
  181. package/dist/chunks/ui-decision-YBZDS4YW.js +4 -0
  182. package/dist/chunks/{ui-file-GVH53O3X.js → ui-file-SRD4ILBS.js} +1 -1
  183. package/dist/chunks/ui-view-Z25MTZT7.js +4 -0
  184. package/dist/chunks/virtual-modules-H4DXPJZB.js +4 -0
  185. package/dist/chunks/waitpoint-M6JZBSLT.js +5 -0
  186. package/dist/chunks/workers-SQ2R32TK.js +4 -0
  187. package/dist/client-bundle/client.mjs +273 -93
  188. package/dist/client-bundle/manifest.json +2 -2
  189. package/dist/core/pi-sdk.js +1 -1
  190. package/dist/domain/auth/cc-auth-cli.js +1 -1
  191. package/dist/domain/mcp/bundled-server.js +1 -1
  192. package/dist/domain/mcp/feishu/client.js +4 -0
  193. package/dist/entry/app.js +151 -559
  194. package/dist/entry/browser-cli.js +10 -10
  195. package/dist/entry/cli.js +1 -1
  196. package/dist/entry/cortex-cli.js +1 -1
  197. package/dist/entry/daemon.js +4 -4
  198. package/dist/entry/hook-cli.js +2 -2
  199. package/dist/entry/production-app-bootstrap.js +1 -1
  200. package/dist/entry/production-evidence-export-cli.js +1 -1
  201. package/dist/entry/signal-cli.js +2 -2
  202. package/dist/tui/index.js +41 -41
  203. package/package.json +3 -3
  204. package/vendor/pi/CHANGELOG.md +330 -0
  205. package/vendor/pi/dist/codemode-worker.js +2 -0
  206. package/vendor/pi/dist/core/export-html/ansi-to-html.js +57 -20
  207. package/vendor/pi/dist/core/export-html/template.css +9 -0
  208. package/vendor/pi/dist/core/export-html/template.js +166 -46
  209. package/vendor/pi/dist/core/export-html/tool-renderer.js +5 -3
  210. package/vendor/pi/dist/core/extensions/loader.js +1 -1
  211. package/vendor/pi/dist/extensions/codemode/execute.js +15 -13
  212. package/vendor/pi/dist/modes/interactive/theme/theme.js +36 -23
  213. package/vendor/pi/dist/utils/image-resize-worker.js +1 -1
  214. package/vendor/pi/dist/utils/image-resize.js +1 -1
  215. package/vendor/pi/docs/cli.md +35 -12
  216. package/vendor/pi/docs/custom-provider.md +2 -0
  217. package/vendor/pi/docs/environment-variables.md +2 -0
  218. package/vendor/pi/docs/extensions.md +3192 -225
  219. package/vendor/pi/docs/keybindings.md +2 -2
  220. package/vendor/pi/docs/llama-cpp.md +27 -19
  221. package/vendor/pi/docs/mcp.md +6 -4
  222. package/vendor/pi/docs/message-types.md +1 -1
  223. package/vendor/pi/docs/models-configuration.md +9 -3
  224. package/vendor/pi/docs/models.md +2 -1
  225. package/vendor/pi/docs/nvidia-rtx-llama-cpp.md +5 -5
  226. package/vendor/pi/docs/packages.md +24 -0
  227. package/vendor/pi/docs/prompt-templates.md +1 -1
  228. package/vendor/pi/docs/providers.md +4 -2
  229. package/vendor/pi/docs/quickstart.md +7 -3
  230. package/vendor/pi/docs/rpc-commands.md +1 -1
  231. package/vendor/pi/docs/rpc.md +4 -2
  232. package/vendor/pi/docs/sessions.md +17 -3
  233. package/vendor/pi/docs/settings.md +6 -5
  234. package/vendor/pi/docs/slash-commands.md +3 -2
  235. package/vendor/pi/docs/terminal-setup.md +3 -1
  236. package/vendor/pi/docs/tmux.md +6 -0
  237. package/vendor/pi/docs/tui.md +4 -0
  238. package/vendor/pi/docs/windows.md +27 -0
  239. package/vendor/pi/examples/extensions/README.md +2 -1
  240. package/vendor/pi/examples/extensions/custom-provider-anthropic/index.ts +27 -31
  241. package/vendor/pi/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  242. package/vendor/pi/examples/extensions/custom-provider-anthropic/package.json +1 -1
  243. package/vendor/pi/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  244. package/vendor/pi/examples/extensions/debug-provider.ts +2 -2
  245. package/vendor/pi/examples/extensions/gondolin/index.ts +4 -7
  246. package/vendor/pi/examples/extensions/gondolin/package-lock.json +19 -29
  247. package/vendor/pi/examples/extensions/gondolin/package.json +2 -2
  248. package/vendor/pi/examples/extensions/plan-mode/index.ts +23 -13
  249. package/vendor/pi/examples/extensions/plan-mode/utils.ts +42 -16
  250. package/vendor/pi/examples/extensions/preset.ts +2 -0
  251. package/vendor/pi/examples/extensions/reload-runtime.ts +17 -5
  252. package/vendor/pi/examples/extensions/subagent/README.md +14 -11
  253. package/vendor/pi/examples/extensions/subagent/index.ts +392 -171
  254. package/vendor/pi/examples/extensions/todo.ts +7 -0
  255. package/vendor/pi/examples/extensions/tools.ts +2 -0
  256. package/vendor/pi/examples/extensions/with-deps/package-lock.json +2 -2
  257. package/vendor/pi/examples/extensions/with-deps/package.json +1 -1
  258. package/vendor/pi/examples/tsconfig.json +208 -0
  259. package/vendor/pi/package.json +15 -16
  260. package/vendor/pi/schemas/models.schema.json +66 -37
  261. package/vendor/pi/schemas/settings.schema.json +18 -1
  262. package/vendor/pi-ai/bedrock.js +1 -1
  263. package/vendor/pi-ai/oauth-load.js +1 -1
  264. package/web/dist/assets/{board-math-css-BPXakv_3.js → board-math-css-DKX6FcUS.js} +1 -1
  265. package/web/dist/assets/index-D11wi0uG.js +540 -0
  266. package/web/dist/assets/index-JedYumhY.css +1 -0
  267. package/web/dist/assets/{index-WCm6wwmM.js → index-jl30Gy8P.js} +1 -1
  268. package/web/dist/assets/pdf-worker-DdZgk2mV.js +57 -0
  269. package/web/dist/assets/pdf.worker.min-Bz_KHX45.js +55 -0
  270. package/web/dist/index.html +2 -2
  271. package/web/dist/theme.css +22 -0
  272. package/dist/chunks/anthropic-messages-M3SMXACA.js +0 -8
  273. package/dist/chunks/api-GM53PHIL-GFHEXXE6.js +0 -4
  274. package/dist/chunks/azure-openai-responses-76YWXHSB.js +0 -4
  275. package/dist/chunks/bedrock-converse-stream-5UPX4NTQ.js +0 -58
  276. package/dist/chunks/child-runner-3GHOWGZP.js +0 -4
  277. package/dist/chunks/chunk-2ZNLUY2U.js +0 -128
  278. package/dist/chunks/chunk-3F6WW7HR.js +0 -13
  279. package/dist/chunks/chunk-3OKHUVEM.js +0 -7
  280. package/dist/chunks/chunk-3YHOCPQU.js +0 -10
  281. package/dist/chunks/chunk-4EX2JJWB.js +0 -4
  282. package/dist/chunks/chunk-4LLH5OWM.js +0 -10
  283. package/dist/chunks/chunk-52T37Y47.js +0 -8
  284. package/dist/chunks/chunk-7MU2AKNM.js +0 -4
  285. package/dist/chunks/chunk-AAA3UBIS.js +0 -4
  286. package/dist/chunks/chunk-ASYQHJVQ.js +0 -9
  287. package/dist/chunks/chunk-BKHDWCRT.js +0 -79
  288. package/dist/chunks/chunk-CQLH4UVX.js +0 -4
  289. package/dist/chunks/chunk-CVC66CFV.js +0 -33
  290. package/dist/chunks/chunk-D6UA4BZC.js +0 -19
  291. package/dist/chunks/chunk-DGMNI4AO.js +0 -4
  292. package/dist/chunks/chunk-DHSA5ACV.js +0 -125
  293. package/dist/chunks/chunk-DPQPXBTP.js +0 -68
  294. package/dist/chunks/chunk-DXBSQXJL.js +0 -18
  295. package/dist/chunks/chunk-E7ZMYIY6.js +0 -30
  296. package/dist/chunks/chunk-EQITBTJC.js +0 -10
  297. package/dist/chunks/chunk-EXJA5RIX.js +0 -357
  298. package/dist/chunks/chunk-FF7UELTU.js +0 -4
  299. package/dist/chunks/chunk-FH74NME3.js +0 -115
  300. package/dist/chunks/chunk-FOQ7VLIL.js +0 -17
  301. package/dist/chunks/chunk-FX6MOGLR.js +0 -11
  302. package/dist/chunks/chunk-G2V65UBA.js +0 -4
  303. package/dist/chunks/chunk-HGPBHTVD.js +0 -6
  304. package/dist/chunks/chunk-J5DVLUKY.js +0 -6
  305. package/dist/chunks/chunk-JW2HFMTF.js +0 -4
  306. package/dist/chunks/chunk-KDYEGGMW.js +0 -4
  307. package/dist/chunks/chunk-KIGMAATV.js +0 -23
  308. package/dist/chunks/chunk-KIU5FAPY.js +0 -5
  309. package/dist/chunks/chunk-KIWMQPH7.js +0 -739
  310. package/dist/chunks/chunk-L6VCIGWS.js +0 -11
  311. package/dist/chunks/chunk-LACGULCN.js +0 -10
  312. package/dist/chunks/chunk-LMSQZ6TQ.js +0 -4
  313. package/dist/chunks/chunk-MEPASGPP.js +0 -6
  314. package/dist/chunks/chunk-MFAEUHMV.js +0 -28
  315. package/dist/chunks/chunk-NAA7GF6Q.js +0 -5
  316. package/dist/chunks/chunk-NKDMKRSB.js +0 -68
  317. package/dist/chunks/chunk-NKXV32S6.js +0 -4
  318. package/dist/chunks/chunk-NVX5IPRN.js +0 -4
  319. package/dist/chunks/chunk-O3JW2F7D.js +0 -8
  320. package/dist/chunks/chunk-OE4KH3NJ.js +0 -4
  321. package/dist/chunks/chunk-OISO5JXB.js +0 -4
  322. package/dist/chunks/chunk-OPYXNSMY.js +0 -4
  323. package/dist/chunks/chunk-OSEIQ7SS.js +0 -4
  324. package/dist/chunks/chunk-P52RMIYX.js +0 -6
  325. package/dist/chunks/chunk-PBJ5MPPX.js +0 -60
  326. package/dist/chunks/chunk-PZMGBKUR.js +0 -13
  327. package/dist/chunks/chunk-PZMXHA6X.js +0 -9
  328. package/dist/chunks/chunk-Q7CE3UIE.js +0 -133
  329. package/dist/chunks/chunk-QBKCAIJG.js +0 -4
  330. package/dist/chunks/chunk-QEOFEETJ.js +0 -4
  331. package/dist/chunks/chunk-QUUEQRIT.js +0 -4
  332. package/dist/chunks/chunk-RA6HKFBV.js +0 -4
  333. package/dist/chunks/chunk-REPYBMQS.js +0 -4
  334. package/dist/chunks/chunk-SKHLZ6XY.js +0 -9
  335. package/dist/chunks/chunk-TAWLERZA.js +0 -4
  336. package/dist/chunks/chunk-TWAEABGG.js +0 -52
  337. package/dist/chunks/chunk-TZFLHVOQ.js +0 -7
  338. package/dist/chunks/chunk-UD3NMUHR.js +0 -12
  339. package/dist/chunks/chunk-UNVEZI57.js +0 -4
  340. package/dist/chunks/chunk-VQUPKMDR.js +0 -4
  341. package/dist/chunks/chunk-W25TB3PU.js +0 -4
  342. package/dist/chunks/chunk-W5LGYSPZ.js +0 -4
  343. package/dist/chunks/chunk-WEZWKMYU.js +0 -4
  344. package/dist/chunks/chunk-XAJLZR7C.js +0 -28
  345. package/dist/chunks/chunk-XH6FMP3N.js +0 -71
  346. package/dist/chunks/chunk-XSRZHN63.js +0 -4
  347. package/dist/chunks/chunk-Y3GFB5XM.js +0 -8
  348. package/dist/chunks/chunk-YG7OEPR2.js +0 -6
  349. package/dist/chunks/chunk-YHIWOGVL.js +0 -4
  350. package/dist/chunks/chunk-YKKEI5GI.js +0 -4
  351. package/dist/chunks/chunk-YZSHTWNM.js +0 -92
  352. package/dist/chunks/chunk-Z4H3VDHI.js +0 -4
  353. package/dist/chunks/cli-5DBTRMHU.js +0 -53
  354. package/dist/chunks/client-XOGYH5UR.js +0 -4
  355. package/dist/chunks/cloudflare-workers-ai-system-one-32JCFHI3.js +0 -4
  356. package/dist/chunks/config-DJSQI77S-335IXHSM.js +0 -4
  357. package/dist/chunks/context-VCQH5OB6.js +0 -4
  358. package/dist/chunks/cost-PGGFI7QJ.js +0 -5
  359. package/dist/chunks/dist-PUKMZ7GW.js +0 -4
  360. package/dist/chunks/easter-egg-3d-MO4MOEVF.js +0 -4
  361. package/dist/chunks/es5-VNTQPCKX.js +0 -4
  362. package/dist/chunks/file-7BN7RCAY.js +0 -4
  363. package/dist/chunks/gateway-UCRPMR75.js +0 -36
  364. package/dist/chunks/github-copilot-HAI2DA62.js +0 -4
  365. package/dist/chunks/google-generative-ai-2VXWLHWI.js +0 -4
  366. package/dist/chunks/google-vertex-UA36QP2U.js +0 -4
  367. package/dist/chunks/init-HA7FAQ73.js +0 -4
  368. package/dist/chunks/kimi-coding-HMJRKCPA.js +0 -4
  369. package/dist/chunks/local-client-stop-SQRU7ZZM.js +0 -4
  370. package/dist/chunks/meta-KY3LNFV2.js +0 -4
  371. package/dist/chunks/mistral-conversations-34F66L3O.js +0 -7
  372. package/dist/chunks/model-resolver-N3DTAQ2S.js +0 -4
  373. package/dist/chunks/openai-codex-responses-ZBVHREB3.js +0 -12
  374. package/dist/chunks/openai-completions-VVIB26SH.js +0 -9
  375. package/dist/chunks/openai-responses-735XA2ZX.js +0 -6
  376. package/dist/chunks/openrouter-images-3IKETHAC.js +0 -4
  377. package/dist/chunks/pi-messages-I3E4ZFHA.js +0 -10
  378. package/dist/chunks/radius-HXRZVBDB.js +0 -4
  379. package/dist/chunks/remote-ops-BALZYKH6.js +0 -14
  380. package/dist/chunks/runner-PLVZDGHB.js +0 -4
  381. package/dist/chunks/runtime-6YLTA2ZD.js +0 -4
  382. package/dist/chunks/schedule-cli-OLASBBYJ.js +0 -4
  383. package/dist/chunks/slack-WAGSPZUX.js +0 -4
  384. package/dist/chunks/start-ui-http-QALT7C3P.js +0 -43
  385. package/dist/chunks/subagent-E3UC7ZHC.js +0 -4
  386. package/dist/chunks/tool-shims-Q6P6UXVC.js +0 -4
  387. package/dist/chunks/typesafe-system-one-6ULACYD4.js +0 -4
  388. package/dist/chunks/ui-board-4GYW6KKW.js +0 -5
  389. package/dist/chunks/ui-decision-U2FXSEC2.js +0 -4
  390. package/dist/chunks/ui-view-O7PLANT7.js +0 -4
  391. package/dist/chunks/virtual-modules-IDC5YKZJ.js +0 -4
  392. package/dist/chunks/waitpoint-2FGQBIAC.js +0 -5
  393. package/dist/chunks/workers-XN4PSTH6.js +0 -4
  394. package/vendor/aistatus/gateway-cli.js +0 -21
  395. package/vendor/pi/examples/extensions/sandbox/index.ts +0 -321
  396. package/vendor/pi/examples/extensions/sandbox/package-lock.json +0 -92
  397. package/vendor/pi/examples/extensions/sandbox/package.json +0 -19
  398. package/web/dist/assets/index-BHZpFXhc.js +0 -525
  399. package/web/dist/assets/index-DqWMdMkh.css +0 -1
  400. package/web/dist/assets/pdf-worker-Hp15W1QJ.js +0 -57
  401. package/web/dist/assets/pdf.worker.min-DnhTvCwe.js +0 -55
@@ -0,0 +1,4 @@
1
+ import { createRequire as __cortexCreateRequire } from 'node:module';
2
+ const require = __cortexCreateRequire(import.meta.url);
3
+ const __cortexPackageRoot = new URL("../../", import.meta.url);
4
+ import a from"node:fs/promises";import m from"node:path";var M=10,A=3e4,g=2e4,O=1e3;function p(t){return`${t}.mutation-lock`}var w=class extends Error{filePath;timeoutMs;holderPid;constructor(e,r,n){let i=n===null?"":` held by pid ${n}`;super(`Timed out after ${r} ms waiting for the lock on ${e} (${p(e)}${i}).`),this.filePath=e,this.timeoutMs=r,this.holderPid=n,this.name="FileLockTimeoutError"}};function _(t){try{return process.kill(t,0),!0}catch(e){return e?.code!=="ESRCH"}}async function y(t){try{let e=await a.readFile(`/proc/${t}/stat`,"utf8");return e.slice(e.lastIndexOf(")")+2).split(" ")[19]??null}catch{return null}}async function u(t){try{let e=JSON.parse(await a.readFile(m.join(t,"owner.json"),"utf8"));return typeof e.pid!="number"||typeof e.token!="string"?null:{pid:e.pid,token:e.token,processStart:typeof e.processStart=="string"?e.processStart:null,acquiredAt:typeof e.acquiredAt=="number"?e.acquiredAt:null}}catch{return null}}async function R(t){if(!_(t.pid))return!0;let e=await y(t.pid);return t.processStart!==null&&e!==null&&t.processStart!==e}async function f(t){let e;try{e=Date.now()-(await a.stat(t)).mtimeMs}catch{return!1}let r=await u(t);return r?r.acquiredAt!==null&&Date.now()-r.acquiredAt>g?!0:R(r):e>O}async function I(t,e){if((await u(t))?.token!==e)return;let r=`${t}.released.${encodeURIComponent(e)}`;try{await a.rename(t,r),(await u(r))?.token===e&&await a.rm(r,{recursive:!0,force:!0})}catch{}}async function v(t){if(await f(t))try{let e=await a.stat(t);await a.writeFile(m.join(t,".reclaimed"),"");let r=await a.stat(t);if(r.dev!==e.dev||r.ino!==e.ino||await u(t)&&!await f(t))return;let n=`${r.dev}.${r.ino}.${String(r.ctimeMs).replace(".","-")}`,i=`${t}.reclaimed.${n}`;await a.rename(t,i),await a.rm(i,{recursive:!0,force:!0})}catch{}}async function L(t){let e=`${process.pid}:${Date.now()}:${Math.random()}`,r=`${t}.candidate.${encodeURIComponent(e)}`;try{await a.mkdir(r);let n={pid:process.pid,token:e,processStart:await y(process.pid),acquiredAt:Date.now()};return await a.writeFile(m.join(r,"owner.json"),JSON.stringify(n),{mode:384}),await a.rename(r,t),()=>I(t,e)}catch(n){if(await a.rm(r,{recursive:!0,force:!0}),n?.code==="EEXIST"||n?.code==="ENOTEMPTY"||n?.code==="EPERM"&&await a.stat(t).then(()=>!0,()=>!1))return null;throw n}}async function N(t,e){e.signal?.throwIfAborted(),await a.mkdir(m.dirname(t),{recursive:!0});let r=p(t),n=e.timeoutMs??A,i=Date.now()+n;for(;Date.now()<i;){e.signal?.throwIfAborted();let o=await L(r);if(o)return o;await f(r)?await v(r):await new Promise(T=>setTimeout(T,M))}throw new w(t,n,(await u(r))?.pid??null)}async function E(t,e,r={}){let n=await N(t,r);try{return await e()}finally{await n()}}import s from"node:fs/promises";import{writeFileSync as D,renameSync as $,mkdirSync as x,chmodSync as F}from"node:fs";import d from"node:path";import*as h from"node:os";import{setTimeout as b}from"node:timers/promises";function S(){return!!process.env.NODE_TEST_CONTEXT}var C=[".cortex",".pi",".aistatus"].map(t=>d.join(h.homedir(),t));function l(t){if(!S())return;let e=d.resolve(t),r=C.find(n=>e===n||e.startsWith(n+d.sep));if(r)throw new Error(`atomicWrite blocked: test process attempted to write under the real ${r} (${e}). Isolate state first: run the test through vitest \u2014 \`npm test\` / \`npm run test:file <file>\` \u2014 whose setup file points CORTEX_HOME at an isolated temp home; repoint HOME too for files under it.`)}function c(t){if(t?.aborted)throw t.reason instanceof Error?t.reason:new Error("Atomic write aborted.")}async function k(t){try{return await s.readFile(t,"utf8")}catch(e){if(e.code==="ENOENT")return"";throw e}}async function q(t,e){try{if(((await s.stat(t)).mode&511)===e)return;await s.chmod(t,e)}catch(r){if(r.code!=="ENOENT")throw r}}async function P(t,e,r={}){l(t),await E(t,async()=>{c(r.signal);let n=await k(t);c(r.signal);let i=await e(n);c(r.signal),i!==n?await U(t,i,r):r.mode!==void 0&&await q(t,r.mode)},{signal:r.signal})}var W=[50,100,150,200],j=new Set(["EPERM","EBUSY","EACCES"]);async function H(t,e,r=$,n=process.platform){for(let i of n==="win32"?W:[]){try{return r(t,e)}catch(o){if(!j.has(o.code??""))throw o}await b(i)}r(t,e)}async function U(t,e,r={}){l(t),c(r.signal),await s.mkdir(d.dirname(t),{recursive:!0}),c(r.signal);let n=Math.random().toString(36).slice(2,8),i=`${t}.tmp.${process.pid}.${Date.now()}.${n}`,o=!1;try{await s.writeFile(i,e,{encoding:"utf8",mode:r.mode}),c(r.signal),r.mode!==void 0&&await s.chmod(i,r.mode),c(r.signal),await H(i,t),o=!0}finally{o||await s.rm(i,{force:!0})}}function tt(t,e,r={}){l(t),x(d.dirname(t),{recursive:!0});let n=Math.random().toString(36).slice(2,8),i=`${t}.tmp.${process.pid}.${Date.now()}.${n}`;D(i,e,{encoding:"utf8",mode:r.mode}),r.mode!==void 0&&F(i,r.mode),$(i,t)}export{E as a,S as b,P as c,U as d,tt as e};
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __cortexCreateRequire } from 'node:module';
2
2
  const require = __cortexCreateRequire(import.meta.url);
3
3
  const __cortexPackageRoot = new URL("../../", import.meta.url);
4
- import{e as T}from"./chunk-NAA7GF6Q.js";import{l as m}from"./chunk-J5DVLUKY.js";import*as f from"crypto";import{readFileSync as g,appendFileSync as E,mkdirSync as d}from"fs";import*as a from"path";var v=T("auth"),y="x-cortex-token",c="CORTEX_CLIENT_TOKEN",u="CORTEX_WEBHOOK_TOKEN",s=null;function S(t,n){let o=Buffer.from(t||""),e=Buffer.from(n||"");return o.length===0||e.length!==o.length?!1:f.timingSafeEqual(o,e)}function B(){return s?.clientToken??(process.env[c]||"").trim()}function w(){return s?.webhookToken??(process.env[u]||"").trim()}function A(t={}){let n=t.env??process.env,o=n[c]?.trim(),e=n[u]?.trim();if(!o||!e)throw new Error("cannot capture missing auth tokens");let r=s;return s={clientToken:o,webhookToken:e},t.scrubEnv&&(delete n[c],delete n[u]),()=>{s=r}}function x(){return f.randomBytes(32).toString("hex")}function O(t,n,o){let e="";try{e=g(t,"utf-8")}catch{}let r=["","# Auth tokens (auto-generated) \u2014 WS client + webhook bearer"];for(let i of n)r.push(`${i}=${o[i]}`);r.push("");let p=(e.length>0&&!e.endsWith(`
4
+ import{e as T}from"./chunk-7W7VYUTK.js";import{j as m}from"./chunk-T54CZKNJ.js";import*as f from"crypto";import{readFileSync as g,appendFileSync as E,mkdirSync as d}from"fs";import*as a from"path";var v=T("auth"),y="x-cortex-token",c="CORTEX_CLIENT_TOKEN",u="CORTEX_WEBHOOK_TOKEN",s=null;function S(t,n){let o=Buffer.from(t||""),e=Buffer.from(n||"");return o.length===0||e.length!==o.length?!1:f.timingSafeEqual(o,e)}function B(){return s?.clientToken??(process.env[c]||"").trim()}function w(){return s?.webhookToken??(process.env[u]||"").trim()}function A(t={}){let n=t.env??process.env,o=n[c]?.trim(),e=n[u]?.trim();if(!o||!e)throw new Error("cannot capture missing auth tokens");let r=s;return s={clientToken:o,webhookToken:e},t.scrubEnv&&(delete n[c],delete n[u]),()=>{s=r}}function x(){return f.randomBytes(32).toString("hex")}function O(t,n,o){let e="";try{e=g(t,"utf-8")}catch{}let r=["","# Auth tokens (auto-generated) \u2014 WS client + webhook bearer"];for(let i of n)r.push(`${i}=${o[i]}`);r.push("");let p=(e.length>0&&!e.endsWith(`
5
5
  `)?`
6
6
  `:"")+r.join(`
7
7
  `);d(a.dirname(t),{recursive:!0}),E(t,p)}function C(t={}){let n=t.env??process.env,o=t.envPath??a.join(m,".env"),e=[],r=i=>{let h=n[i]?.trim();if(h)return h;let k=x();return n[i]=k,e.push(i),k},l=r(c),p=r(u);return e.length>0&&(O(o,e,n),v.info(`Generated auth token(s): ${e.join(", ")} \u2192 ${o}`)),{clientToken:l,webhookToken:p,generated:e}}export{y as a,c as b,u as c,S as d,B as e,w as f,A as g,C as h};
@@ -0,0 +1,10 @@
1
+ import { createRequire as __cortexCreateRequire } from 'node:module';
2
+ const require = __cortexCreateRequire(import.meta.url);
3
+ const __cortexPackageRoot = new URL("../../", import.meta.url);
4
+ import{a as _,c as j,d as B,e as O,f as F}from"./chunk-QXFWIL4C.js";import{d as H}from"./chunk-IMMGYDAB.js";import{f as v}from"./chunk-OJ37ZWBG.js";import{a as g,b as W,e as $}from"./chunk-SKHFU5DI.js";import{a as A}from"./chunk-52VCLZS5.js";import{a as X}from"./chunk-B3NB243Z.js";import{f as L}from"./chunk-AXYAZTTN.js";import{e as D}from"./chunk-7W7VYUTK.js";function b(){return{input:0,output:0,cacheRead:0,cacheWrite:0,cost:0,contextTokens:0,turns:0}}function m(t){return typeof t=="number"&&Number.isFinite(t)?t:0}function K(t,e){t.input+=e.input,t.output+=e.output,t.cacheRead+=e.cacheRead,t.cacheWrite+=e.cacheWrite,t.cost+=e.cost,t.contextTokens=e.contextTokens||t.contextTokens,t.turns+=e.turns}function lt(t,e){t.input+=e.input,t.output+=e.output,t.cacheRead+=e.cacheRead,t.cacheWrite+=e.cacheWrite,t.cost+=e.cost,t.contextTokens+=e.contextTokens,t.turns+=e.turns}function he(t){let e=b();for(let n of t)lt(e,n.usage);return e}import*as G from"node:path";function dt(t,e,n){return t.hasTrustRequiringProjectResources(e)?new t.ProjectTrustStore(n).get(e)===!0:!0}function pt(t,e,n){return n===null||!e||e<=n?t:e-n+Math.min(t,Math.floor(n/2))}function ft(t){let e=t.getCompactionReserveTokens.bind(t);t.getCompactionReserveTokens=n=>pt(e(n),n?.contextWindow,L().maxContextTokens)}function mt(t){if(process.platform!=="win32")return;let e=process.env.CORTEX_GIT_BASH_PATH;if(!e)return;let n=t.getShellPath.bind(t);t.getShellPath=()=>n()??e}function V(t,e,n){let o=t.SettingsManager.create(e,n,{projectTrusted:dt(t,e,n)});return o.getCacheWarmingMode=()=>"off",ft(o),mt(o),o}var N=D("pi-subagent");function gt(t,e,n){if(!e.model)return{model:void 0,thinkingLevel:void 0};let o=e.provider?`${e.provider}/${e.model}`:e.model,r=t.resolveCliModel({cliModel:e.thinking?`${o}:${e.thinking}`:o,modelRuntime:n});if(r.error)throw new Error(r.error);return r.warning&&N.warn(`PI subagent model resolution: ${r.warning}`),{model:r.model,thinkingLevel:r.thinkingLevel}}async function _t(t,e){let n=V(t,e.cwd,e.agentDir),o=await t.ModelRuntime.create({authPath:v(e.agentDir),modelsPath:G.join(e.agentDir,"models.json"),allowModelNetwork:!1});return await H(o,e.agentDir),t.createAgentSessionServices({cwd:e.cwd,agentDir:e.agentDir,settingsManager:n,modelRuntime:o,resourceLoaderOptions:{noExtensions:!0,extensionFactories:e.extensions,appendSystemPrompt:e.appendSystemPrompt,noContextFiles:e.noContextFiles===!0}})}async function z(t){let e=await X(),n=await _t(e,t);for(let i of n.diagnostics)i.type==="error"&&N.warn(`PI subagent session: ${i.message}`);let{model:o,thinkingLevel:r}=gt(e,t,n.modelRuntime),s=await e.createAgentSessionFromServices({services:n,sessionManager:e.SessionManager.inMemory(t.cwd),model:o,thinkingLevel:r,tools:t.tools});return await s.session.bindExtensions({mode:"print",onError:i=>N.warn(`PI subagent extension ${i.extensionPath} failed on ${i.event}: ${String(i.error)}`)}),{session:s.session,dispose:()=>s.session.dispose()}}function E(t){if(!Array.isArray(t))return[];let e=[];for(let n of t){if(!n||typeof n!="object"||n.type!=="image")continue;let o=n,r=o.source;r&&r.type==="base64"&&typeof r.data=="string"&&r.data?e.push({mimeType:typeof r.media_type=="string"?r.media_type:"",data:r.data}):typeof o.data=="string"&&o.data&&e.push({mimeType:typeof o.mimeType=="string"?o.mimeType:"",data:o.data})}return e}function J(t){if(!t||typeof t!="object")return!1;let e=t;return typeof e.mimeType=="string"&&typeof e.data=="string"&&e.data.length>0}function Ne(t,e,n=!1){if(!e||!t)return;let o=r=>{try{e(r)}catch{}};return{forChild(r,s){let i=`${t}#${r}`,c=n&&r>0;return(a,f)=>{let d=Et(i,s,f,a);for(let p=0;p<d.length;p++)o(c&&p===0?{...d[p],prompt:s.prompt}:d[p]);d.length&&(c=!1)}}}}function ht(t,e,n){return{ref:t,type:e.subagent_type,description:e.description,model:n.model??null,backend:"pi",...e.clean?{clean:!0}:{}}}function Et(t,e,n,o){let r=ht(t,e,n),s=o.type;if(s==="tool_execution_start"){let f=o.toolCallId,d=o.toolName;return typeof f!="string"||typeof d!="string"?[]:[{...r,kind:"tool_use",toolUseId:`${t}:${f}`,name:d,input:o.args??{}}]}if(s==="tool_execution_end")return Tt(r,o);let i=S(o);if(!i||i.role!=="assistant")return[];let c=typeof i.model=="string"?i.model:r.model,a=P(i);return a?[{...r,model:c,kind:"assistant_text",text:a}]:[]}function Tt(t,e){let n=e.toolCallId;if(typeof n!="string")return[];let o=E(e.result?.content);return[{...t,kind:"tool_result",toolUseId:`${t.ref}:${n}`,ok:e.isError!==!0,content:yt(e.result),...o.length?{images:o}:{}}]}function S(t){return t.type!=="message_end"||!t.message||typeof t.message!="object"?null:t.message}function P(t){let e=t.content;return typeof e=="string"?e:Array.isArray(e)?e.filter(n=>!!n&&typeof n=="object"&&n.type==="text"&&typeof n.text=="string").map(n=>n.text).join(`
5
+ `):""}function yt(t){if(typeof t=="string")return t;if(!t||typeof t!="object")return"";let e=t.content;return typeof e=="string"?e:Array.isArray(e)?e.filter(n=>n&&typeof n=="object"&&n.type==="text").map(n=>String(n.text??"")).join(""):""}function we(t,e,n,o){return{ref:t,type:e.subagent_type,description:e.description,model:null,backend:n,kind:"end",status:o}}function Ct(t){let e=t.name;return t.backend==="claude"?e:g("pi",e)??e}function Y(t){if(t.kind==="end")return t.status?[{type:"subagent_end",parentToolUseId:t.ref,status:t.status}]:[];let e={parentToolUseId:t.ref,type:t.type||null,description:t.description||null,...t.prompt?{prompt:t.prompt}:{},model:t.model,...t.clean?{clean:!0}:{}};return t.kind==="tool_use"?[{type:"tool_use",toolUseId:t.toolUseId,name:Ct(t),input:t.input??{},subagent:e}]:t.kind==="tool_result"?[{type:"tool_result",toolUseId:t.toolUseId,ok:t.ok!==!1,content:t.content??"",subagent:e,...t.images?.length?{images:t.images}:{}}]:[{type:"assistant_text",text:t.text,subagent:e}]}var It=new Set(["pending","in_progress","completed"]);function Q(t){return typeof t=="string"?t:""}function Rt(t){return typeof t=="string"&&It.has(t)?t:"pending"}function kt(t){if(!t||typeof t!="object")return null;let e=t,n=Q(e.content).trim(),o=Q(e.activeForm).trim()||n;return!n&&!o?null:{content:n||o,activeForm:o,status:Rt(e.status)}}function xt(t,e=Date.now()){if(!t||typeof t!="object")return null;let n=t.todos;if(!Array.isArray(n))return null;let o=[];for(let i of n){let c=kt(i);c&&o.push(c)}let r=0,s=null;for(let i of o)i.status==="completed"?r+=1:i.status==="in_progress"&&s===null&&(s=i.activeForm);return{items:o,total:o.length,completed:r,activeLabel:s,updatedAt:e}}function Z(t,e,n,o=Date.now()){return g(t,e)!=="todo_write"?null:xt(n,o)}function Le(t,e=40){if(!t||t.total===0)return"";let n=`${t.completed}/${t.total}`,o=t.activeLabel?.trim();if(!o)return n;let r=o.length>e?`${o.slice(0,e-1).trimEnd()}\u2026`:o;return`${n} \xB7 ${r}`}function Be(){return{turnProgressCount:0,pendingCompletion:U()}}function Fe(t,e){let n=t;if(typeof n.type!="string")return[];let o=n.type;if(o==="message_update")return bt(n);if(o==="tool_execution_start")return Nt(n);if(o==="tool_execution_end")return St(n);if(o==="agent_end")return wt(n,e);if(o==="agent_settled")return Ut(e);if(o==="compaction_start")return[{type:"context_compacted",trigger:typeof n.reason=="string"&&n.reason.length>0?n.reason:"auto"}];if(o==="message_end")return e.turnProgressCount++,[{type:"turn_progress",numTurns:e.turnProgressCount}];if(o==="cortex_subagent_event"){let r=Ft(n.notice);return r?Y(r):[]}if(o==="cortex_subagent_usage")return jt(n.report,e);if(o==="auto_retry_start")return Ot(n);if(o==="extension_error"){let r=n.error;return[{type:"error",message:typeof r=="string"&&r.length>0?r:"extension error",fatal:!1}]}return o==="extension_ui_request"?Ht(n):[]}function C(t){return t!==null&&typeof t=="object"?t:void 0}function tt(t){let e=C(t),n=e?.id??e?.responseId;return typeof n=="string"?n:void 0}function q(t,e){let n=C(t)?.content;return!Array.isArray(n)||typeof e!="number"?!1:C(n[e])?.redacted===!0}function At(t,e){let n=e.redacted===!0||q(t.message,e.contentIndex)||q(e.partial,e.contentIndex),o=e.type==="thinking_end"?e.content:e.delta;if(n||typeof o!="string"||o.length===0)return[];let r=tt(t.message),s=r!==void 0&&typeof e.contentIndex=="number"?`${r}:t${e.contentIndex}`:void 0;return e.type==="thinking_end"?[{type:"assistant_thinking",text:o,...s!==void 0?{blockId:s}:{}}]:s!==void 0?[{type:"assistant_thinking_delta",text:o,blockId:s}]:[]}function Ot(t){let e=t.attempt;if(typeof e!="number")return[];let n=typeof t.errorMessage=="string"?t.errorMessage:null;return[{type:"api_retry",attempt:e,error:n}]}function bt(t){let e=C(t.assistantMessageEvent);if(!e)return[];if(e.type==="thinking_delta"||e.type==="thinking_end")return At(t,e);if(e.type!=="text_delta"||typeof e.delta!="string"||e.delta.length===0)return[];let n=tt(t.message);return[{type:"assistant_text",text:e.delta,...n!==void 0?{blockId:n}:{}}]}function Nt(t){let e=t.toolCallId,n=t.toolName,o=t.args??{};if(typeof e!="string"||typeof n!="string")return[];let r=g("pi",n)??n,s=[{type:"tool_use",toolUseId:e,name:r,input:o}],i=Z("pi",n,o);return i&&s.push({type:"todo_update",toolUseId:e,snapshot:i}),s}function St(t){let e=t.toolCallId;if(typeof e!="string")return[];let n=t.isError===!0,o=t.result,r="",s=[];if(o&&typeof o=="object"){let c=o.content;Array.isArray(c)?(r=c.filter(a=>l(a).type==="text").map(a=>String(l(a).text??"")).join(""),s=E(c)):typeof c=="string"&&(r=c)}return[{type:"tool_result",toolUseId:e,ok:!n,content:r,...s.length?{images:s}:{}}]}function et(t,e){if(t.type!=="tool_execution_end"||!e?.input||e.input.includes("image"))return t;let n=l(t.result),o=n.content;return!Array.isArray(o)||!o.some(r=>l(r).type==="image")?t:{...t,result:{...n,content:o.filter(r=>l(r).type!=="image")}}}function U(){return{numTurns:0,totalCostUsd:null,error:null}}function Pt(){return{...U(),provider:"",model:"",tokensIn:0,tokensOut:0,cacheReadTokens:0,cacheWriteTokens:0,inputReported:!0,outputReported:!0,cacheReadReported:!0,cacheWriteReported:!0}}function wt(t,e){let n=Array.isArray(t.messages)?t.messages:[],o=Mt(n);if(vt(e,o),o.provider==="")return[];let r=y(o.tokensIn,o.inputReported),s=y(o.tokensOut,o.outputReported),i=y(o.cacheReadTokens,o.cacheReadReported),c=y(o.cacheWriteTokens,o.cacheWriteReported),a=$t(r,i,c);return[{type:"cost_record",provider:o.provider,model:o.model,tokens_in:o.tokensIn,tokens_out:o.tokensOut,prompt_tokens:a,cached_tokens:i,input_tokens:r,output_tokens:s,cache_read_tokens:i,cache_creation_tokens:c,provider_requests:o.numTurns>0?o.numTurns:null,cost_usd:o.totalCostUsd}]}function Ut(t){let e=t.pendingCompletion;t.pendingCompletion=U();let n={type:"turn_complete",numTurns:e.numTurns,totalCostUsd:e.totalCostUsd};return e.error===null?[n]:[{...n,error:e.error}]}function Mt(t){let e=Pt();for(let n of t){let o=l(n);o.role==="assistant"&&(e.numTurns++,Dt(e,o),Lt(e,o),Xt(e,o))}return e}function Dt(t,e){let n=e.provider,o=e.model;t.provider===""&&typeof n=="string"&&n.length>0&&(t.provider=n),t.model===""&&typeof o=="string"&&o.length>0&&(t.model=o)}function Lt(t,e){if(t.error!==null||e.stopReason!=="error")return;let n=e.errorMessage;t.error=typeof n=="string"&&n.length>0?n:"PI agent reported an error during execution"}function Wt(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0}function T(t,e,n){return Wt(n)?[t+n,e]:[t,!1]}function Xt(t,e){let n=l(e.usage);[t.tokensIn,t.inputReported]=T(t.tokensIn,t.inputReported,n.input),[t.tokensOut,t.outputReported]=T(t.tokensOut,t.outputReported,n.output),[t.cacheReadTokens,t.cacheReadReported]=T(t.cacheReadTokens,t.cacheReadReported,n.cacheRead),[t.cacheWriteTokens,t.cacheWriteReported]=T(t.cacheWriteTokens,t.cacheWriteReported,n.cacheWrite);let o=l(n.cost).total;typeof o=="number"&&isFinite(o)&&(t.totalCostUsd=(t.totalCostUsd??0)+o)}function y(t,e){return e?t:null}function $t(...t){return t.some(e=>e===null)?null:t.reduce((e,n)=>e+n,0)}function vt(t,e){let n=t.pendingCompletion;n.numTurns+=e.numTurns,n.totalCostUsd=nt(n.totalCostUsd,e.totalCostUsd),n.error=e.error}function nt(t,e){return t===null&&e===null?null:(t??0)+(e??0)}function jt(t,e){let n=l(t),o=n.provider;if(typeof o!="string"||o==="")return[];let r=l(n.usage),s=h(r.input),i=h(r.output),c=h(r.cacheRead),a=h(r.cacheWrite),f=h(r.turns),d=w(r.cost);e.pendingCompletion.totalCostUsd=nt(e.pendingCompletion.totalCostUsd,d);let p=n.model,x=n.connection;return[{type:"cost_record",provider:o,connection:typeof x=="string"&&x!==""?x:o,model:typeof p=="string"?p:"",tokens_in:s,tokens_out:i,prompt_tokens:s+c+a,cached_tokens:c,input_tokens:s,output_tokens:i,cache_read_tokens:c,cache_creation_tokens:a,provider_requests:f>0?f:null,cost_usd:d}]}function Bt(t){return t==="completed"||t==="failed"||t==="killed"}function Ft(t){if(!t||typeof t!="object"||Array.isArray(t))return null;let e=t,{ref:n,kind:o}=e;if(typeof n!="string"||!n||o!=="tool_use"&&o!=="tool_result"&&o!=="assistant_text"&&o!=="end")return null;let r={ref:n,kind:o,type:typeof e.type=="string"?e.type:"",description:typeof e.description=="string"?e.description:"",...typeof e.prompt=="string"?{prompt:e.prompt}:{},model:typeof e.model=="string"?e.model:null};if(o==="tool_use")return typeof e.name!="string"||typeof e.toolUseId!="string"?null:(r.name=e.name,r.toolUseId=e.toolUseId,r.input=e.input??{},r);if(o==="tool_result"){if(typeof e.toolUseId!="string")return null;r.toolUseId=e.toolUseId,r.ok=e.ok!==!1,r.content=typeof e.content=="string"?e.content:"";let s=Array.isArray(e.images)?e.images.filter(J):[];return s.length&&(r.images=s),r}return o==="end"?Bt(e.status)?(r.status=e.status,r):null:typeof e.text!="string"||!e.text?null:(r.text=e.text,r)}function Ht(t){let e=t.id,n=t.method;if(typeof e!="string"||typeof n!="string")return[];if(n!=="select"&&n!=="confirm"&&n!=="input"&&n!=="editor")return[];let o=t.title,r=typeof o=="string"&&o.length>0?o:`${n} request`,s;if(n==="select"){let i=t.options,c=Array.isArray(i)?i.map(String):void 0;s={question:r},c&&(s.options=c)}else if(n==="confirm"){let i=t.message,c=typeof i=="string"&&i.length>0?`: ${i}`:"";s={question:r+c,options:["Yes","No"]}}else n==="editor"?s={question:r,multi:!0}:s={question:r};return[{type:"ask_user_question",toolUseId:e,questions:[s]}]}function He(t,e=null){let n=l(l(t).contextUsage),o=n.contextWindow;if(typeof o!="number"||!Number.isFinite(o)||o<=0)return null;let r=w(n.tokens);if(e===null||o<=e){let i=w(n.percent);return{usedTokens:r,contextWindow:o,percent:i,accuracy:"estimate"}}let s=r===null?null:r/e*100;return{usedTokens:r,contextWindow:e,percent:s,accuracy:"estimate"}}function h(t){return typeof t=="number"&&Number.isFinite(t)&&t>0?Math.floor(t):0}function w(t){return typeof t=="number"&&Number.isFinite(t)&&t>=0?t:null}function l(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:{}}function ot(t){return t??"direct"}var rt="CORTEX_PI_MCP_COMPOSITION",I="CORTEX_PI_INTERACTION_BRIDGE",R="CORTEX_PI_TEAM_LEAD",k="CORTEX_PI_TEAM_WORKER",st="CORTEX_PI_CLEAN_WORKSPACE",it="CORTEX_PI_HOME_AGENT_DIR",Kt=["SLACK_CHANNEL","FEISHU_CHANNEL","CORTEX_SESSION_ID","CORTEX_PROFILE","CORTEX_MODE","CORTEX_BACKEND","CORTEX_MODEL","CORTEX_PROVIDER","CORTEX_THINKING","CORTEX_CONNECTION","CORTEX_PROJECT","CORTEX_SESSION_NAME","CORTEX_EXECUTION_ID","CORTEX_CALLBACK_SOURCE","CORTEX_SCHEDULE_TASK_ID","CORTEX_CONFIG_IMMUTABLE","CORTEX_PRODUCTION_AUTH_FILE","CORTEX_WEBHOOK_BENCHMARK_ONLY","CORTEX_PI_ALLOWED_TOOLS","CORTEX_PI_SUBAGENT",rt,I,R,k,st,it,A,_];function u(t,e,n){n!=null&&n!==""&&(t[e]=String(n))}function Vt(t,e){let n=e.context;u(t,"CORTEX_MODEL",n?.selection?.model),u(t,"CORTEX_PROVIDER",n?.selection?.provider),u(t,"CORTEX_THINKING",n?.selection?.thinking),u(t,"CORTEX_CONNECTION",n?.selection?.connection),u(t,"CORTEX_SESSION_ID",n?.trackSessionId??e.sessionId),u(t,"CORTEX_CALLBACK_SOURCE",e.callbackSource),u(t,"CORTEX_SCHEDULE_TASK_ID",e.scheduleTaskId),u(t,"CORTEX_PROJECT",n?.project),u(t,"CORTEX_EXECUTION_ID",n?.executionId),u(t,_,n?.clean?"1":null)}function Gt(t,e=process.env){let n={...e,...t.routeEnv??{}};for(let o of Kt)delete n[o];for(let o of t.unsetEnv??[])delete n[o];return n.PI_CODING_AGENT_DIR=t.piAgentDir,t.piHomeAgentDir&&t.piHomeAgentDir!==t.piAgentDir&&(n[it]=t.piHomeAgentDir),n.CORTEX_BACKEND="pi",t.channel&&(n.SLACK_CHANNEL=t.channel,n.FEISHU_CHANNEL=t.channel),u(n,"CORTEX_PI_ALLOWED_TOOLS",t.allowedTools),u(n,rt,t.mcpComposition),t.mcpToolAllowlist!==void 0&&t.mcpToolAllowlist!==null&&(n[A]=JSON.stringify(t.mcpToolAllowlist)),t.enableInteractionBridge===!0&&(n[I]="1"),t.enableTeamLead===!0&&(n[R]="1"),t.enableTeamWorker===!0&&(n[k]="1"),u(n,"CORTEX_PI_SUBAGENT",t.subagentMarker),u(n,st,t.cleanWorkspace),Vt(n,t),n}function zt(t){return t.replace(/\[.*?\]$/,"")}function Jt(t){return t?(Array.isArray(t)?t:[t]).filter(e=>e.length>0):[]}function Yt(t){let e=t.tools.canonical&&t.tools.canonical.length>0?t.tools.canonical.map(n=>W("claude",n)).filter(n=>!!n).join(","):void 0;return t.tools.rawClaude??e}function Qt(t){return t.env.sets?.CORTEX_PI_SUBAGENT==="1"?"1":void 0}function Zt(t,e){return e!=="direct"?[]:[...t.mcp.servers??[]]}function Qe(t,e){let n=ot(t.mcp.composition),o=Qt(t),r=Gt({sessionId:t.resume.backendSessionId,channel:t.context.channel,callbackSource:t.context.callbackSource,scheduleTaskId:t.context.scheduleTaskId,routeEnv:t.env.sets,unsetEnv:t.env.unsets,context:t.env.context,piAgentDir:e.agentDir,piHomeAgentDir:e.homeAgentDir,allowedTools:Yt(t),mcpComposition:n,mcpToolAllowlist:t.mcp.allowlist,enableInteractionBridge:n==="direct"&&t.flags.isUserInitiated===!0&&t.flags.teamWorker!==!0&&o===void 0,enableTeamLead:n==="direct"&&t.flags.teamLead===!0&&o===void 0,enableTeamWorker:n==="direct"&&t.flags.teamWorker===!0&&o===void 0,subagentMarker:o,cleanWorkspace:t.flags.clean?e.cwd:null},t.env.pinned);return{sessionKey:t.engineKey,cwd:e.cwd,agentDir:e.agentDir,sessionDir:e.sessionDir,sessionPath:e.sessionPath,provider:t.model.provider??null,model:t.model.id?zt(t.model.id):null,benchmarkMaxOutputTokens:t.model.benchmarkMaxOutputTokens,thinking:t.model.thinking??null,systemPrompt:t.prompt.system||null,appendSystemPrompt:Jt(t.prompt.append),skillPaths:t.flags.disableSkills?[]:[...t.plugins.skillDirs??[],...t.plugins.dirs??[]],disableHooks:t.flags.disableHooks===!0,...t.flags.clean?{noContextFiles:!0}:{},reportsProviderQuota:!0,pluginMcpServers:Zt(t,n),env:r,streamDeltas:e.streamDeltas}}var qt=new Set(["CORTEX_EXECUTION_ID"]);function Ze(t){let{sessionPath:e,env:n,...o}=t,r=Object.entries(n).filter(([s])=>!qt.has(s)).sort(([s],[i])=>s<i?-1:s>i?1:0);return JSON.stringify({...o,env:r})}import{existsSync as re}from"node:fs";function te(t){return t.device?`${t.device}:${t.path}`:t.path}function ee(t,e){return(t.device||null)===(e.device||null)&&t.path===e.path}function ne(t){let e=t.write?"read, write":"read only";return t.device?`${e}; on device ${t.device}, use the remote_* tools`:e}function ct(t){return["[Authorized Paths]",...t.length>0?t.map(n=>`- ${te(n)} (${ne(n)})`):["- (none)"]].join(`
6
+ `)}function oe(t){return t.length===0?null:JSON.stringify(t.map(e=>[e.device??null,e.path,e.write]))}function tn(t,e,n){return n?t.length>0?[...t]:null:oe(t)===(e??null)?null:[...t]}function at(t,e){let n=[...t];for(let o of e)n.some(r=>ee(r,o))||n.push(o);return n}function sn(t,e){return{...t,tasks:t.tasks.map(n=>se(n,e))}}function se(t,e){let n=(t.files??[]).map(i=>{let c=O(i,e.cwd);if(!re(c))throw new Error(`Agent task file not found: ${i}`);return c}),o=t.clean===!0||n.length>0||e.parentWorkspace!==null,r=ae(t,e),s=r.length>0?{...t,allow:r}:ie(t);return o?{...s,clean:!0,...n.length>0?{files:n}:{}}:s}function ie(t){let{allow:e,...n}=t;return n}function ce(t,e){return t.device?{device:t.device,path:t.path.trim(),write:t.write!==!1}:{path:O(t.path.trim(),e),write:t.write!==!1}}function ae(t,e){let n=(t.allow??[]).map(r=>ce(r,e.cwd)),o=e.parentWorkspace!==null?e.parentAllowed??[]:[];return at(o,n)}function ut(t){let e=t.allow??[];return`${e.length>0?`${ct(e)}
7
+
8
+ `:""}Task: ${t.prompt}`}function ue(t){return t.replace(/[^A-Za-z0-9_-]/g,"").slice(0,32)||"run"}async function cn(t,e){if(!t.clean)return null;let n=e.parentWorkspace??j(`sub-${ue(e.runId)}-${e.index}`);for(let o of t.files??[])await B(n,o);return n}function an(t,e){if(!e)return t;let n=`Workspace: ${e}`;return{...t,output:t.output?`${t.output}
9
+
10
+ ${n}`:n}}function le(t,e,n=!1){let o={...t,PI_CODING_AGENT_DIR:e,CORTEX_PI_SUBAGENT:"1"};return delete o[I],delete o[R],delete o[k],n&&(o[_]="1"),o}async function En(t){let{task:e,role:n}=t,o=t.model??{},r=t.createSession??z,s=t.workspace??null,i=await r({cwd:s??t.cwd,agentDir:t.agentDir,provider:o.provider??null,model:o.model??null,thinking:o.thinking??null,tools:$(n,"pi"),appendSystemPrompt:[...n.systemPrompt?[n.systemPrompt]:[],...s?[F(s)]:[]],...s?{noContextFiles:!0}:{},extensions:t.childExtensions(le(t.parentEnv,t.agentDir,s!==null),o.provider??null)});try{let c=await de(i,e,t.signal,t.forward);return c.model||(c.model=o.model),c}finally{i.dispose()}}async function de(t,e,n,o){if(n?.aborted)throw new Error("Subagent was aborted.");let r={output:"",usage:b()},s=t.session.subscribe(c=>{fe(r,et(c,t.session.model),o)}),i=()=>{t.session.abort().catch(()=>{})};n?.addEventListener("abort",i,{once:!0});try{await t.session.prompt(ut(e))}finally{n?.removeEventListener("abort",i),s()}if(n?.aborted)throw new Error("Subagent was aborted.");return pe(e,r)}function pe(t,e){return{description:t.description,prompt:t.prompt,subagentType:t.subagent_type,output:e.output,usage:e.usage,model:e.model,provider:e.provider,backend:"pi",stopReason:e.stopReason,errorMessage:e.errorMessage}}function fe(t,e,n){if(n)try{n(e,t)}catch{}let o=S(e);o&&(me(t,o),_e(t,o))}function me(t,e){if(e.role!=="assistant")return;let n=e.usage,o=n?.cost;K(t.usage,{input:m(n?.input),output:m(n?.output),cacheRead:m(n?.cacheRead),cacheWrite:m(n?.cacheWrite),cost:m(o?.total),contextTokens:m(n?.totalTokens),turns:1})}function M(t,e){return typeof t=="string"?t:e}function ge(t,e){let n=typeof e.stopReason=="string"?e.stopReason:void 0;if(!n){t.errorMessage=M(e.errorMessage,t.errorMessage);return}t.stopReason=n,t.errorMessage=typeof e.errorMessage=="string"?e.errorMessage:void 0}function _e(t,e){e.role==="assistant"&&(t.output=P(e)||t.output,t.model=M(e.model,t.model),t.provider=M(e.provider,t.provider),ge(t,e))}export{xt as a,Z as b,Le as c,ot as d,E as e,we as f,Y as g,Be as h,Fe as i,et as j,He as k,rt as l,I as m,R as n,k as o,st as p,it as q,Qe as r,Ze as s,V as t,z as u,b as v,he as w,Ne as x,Et as y,ee as z,ct as A,oe as B,tn as C,sn as D,ut as E,cn as F,an as G,le as H,En as I,pe as J};
@@ -0,0 +1,4 @@
1
+ import { createRequire as __cortexCreateRequire } from 'node:module';
2
+ const require = __cortexCreateRequire(import.meta.url);
3
+ const __cortexPackageRoot = new URL("../../", import.meta.url);
4
+ function n(t){return typeof t=="number"&&Number.isFinite(t)&&t>=0}function i(t){return t.provider==="openrouter"||t.baseUrl.includes("openrouter.ai")}function s(t,e){if(n(e.cost)){if(e.is_byok===!1){t.cost.total=e.cost,t.cost.totalFromProvider=!0;return}if(e.is_byok===!0){let o=e.cost_details;if(!o)return;let r=o.upstream_inference_cost;if(r===null){if(!n(o.upstream_inference_prompt_cost)||!n(o.upstream_inference_completions_cost))return;r=o.upstream_inference_prompt_cost+o.upstream_inference_completions_cost}if(!n(r))return;t.cost.total=e.cost+r,t.cost.totalFromProvider=!0}}}export{i as a,s as b};
@@ -2,7 +2,7 @@ import { createRequire as __cortexCreateRequire } from 'node:module';
2
2
  const require = __cortexCreateRequire(import.meta.url);
3
3
  const __cortexPackageRoot = new URL("../../", import.meta.url);
4
4
  import{a as We,c as g}from"./chunk-WHC7AYZD.js";var q=g(P=>{"use strict";var Qt=Symbol.for("yaml.alias"),Li=Symbol.for("yaml.document"),Ge=Symbol.for("yaml.map"),Ei=Symbol.for("yaml.pair"),Wt=Symbol.for("yaml.scalar"),He=Symbol.for("yaml.seq"),F=Symbol.for("yaml.node.type"),ga=s=>!!s&&typeof s=="object"&&s[F]===Qt,ya=s=>!!s&&typeof s=="object"&&s[F]===Li,ba=s=>!!s&&typeof s=="object"&&s[F]===Ge,Sa=s=>!!s&&typeof s=="object"&&s[F]===Ei,Ti=s=>!!s&&typeof s=="object"&&s[F]===Wt,wa=s=>!!s&&typeof s=="object"&&s[F]===He;function Ci(s){if(s&&typeof s=="object")switch(s[F]){case Ge:case He:return!0}return!1}function va(s){if(s&&typeof s=="object")switch(s[F]){case Qt:case Ge:case Wt:case He:return!0}return!1}var ka=s=>(Ti(s)||Ci(s))&&!!s.anchor;P.ALIAS=Qt;P.DOC=Li;P.MAP=Ge;P.NODE_TYPE=F;P.PAIR=Ei;P.SCALAR=Wt;P.SEQ=He;P.hasAnchor=ka;P.isAlias=ga;P.isCollection=Ci;P.isDocument=ya;P.isMap=ba;P.isNode=va;P.isPair=Sa;P.isScalar=Ti;P.isSeq=wa});var ye=g(Gt=>{"use strict";var I=q(),M=Symbol("break visit"),Ii=Symbol("skip children"),K=Symbol("remove node");function Xe(s,e){let t=Pi(e);I.isDocument(s)?ae(null,s.contents,t,Object.freeze([s]))===K&&(s.contents=null):ae(null,s,t,Object.freeze([]))}Xe.BREAK=M;Xe.SKIP=Ii;Xe.REMOVE=K;function ae(s,e,t,i){let n=Mi(s,e,t,i);if(I.isNode(n)||I.isPair(n))return _i(s,i,n),ae(s,n,t,i);if(typeof n!="symbol"){if(I.isCollection(e)){i=Object.freeze(i.concat(e));for(let r=0;r<e.items.length;++r){let a=ae(r,e.items[r],t,i);if(typeof a=="number")r=a-1;else{if(a===M)return M;a===K&&(e.items.splice(r,1),r-=1)}}}else if(I.isPair(e)){i=Object.freeze(i.concat(e));let r=ae("key",e.key,t,i);if(r===M)return M;r===K&&(e.key=null);let a=ae("value",e.value,t,i);if(a===M)return M;a===K&&(e.value=null)}}return n}async function xe(s,e){let t=Pi(e);I.isDocument(s)?await oe(null,s.contents,t,Object.freeze([s]))===K&&(s.contents=null):await oe(null,s,t,Object.freeze([]))}xe.BREAK=M;xe.SKIP=Ii;xe.REMOVE=K;async function oe(s,e,t,i){let n=await Mi(s,e,t,i);if(I.isNode(n)||I.isPair(n))return _i(s,i,n),oe(s,n,t,i);if(typeof n!="symbol"){if(I.isCollection(e)){i=Object.freeze(i.concat(e));for(let r=0;r<e.items.length;++r){let a=await oe(r,e.items[r],t,i);if(typeof a=="number")r=a-1;else{if(a===M)return M;a===K&&(e.items.splice(r,1),r-=1)}}}else if(I.isPair(e)){i=Object.freeze(i.concat(e));let r=await oe("key",e.key,t,i);if(r===M)return M;r===K&&(e.key=null);let a=await oe("value",e.value,t,i);if(a===M)return M;a===K&&(e.value=null)}}return n}function Pi(s){return typeof s=="object"&&(s.Collection||s.Node||s.Value)?Object.assign({Alias:s.Node,Map:s.Node,Scalar:s.Node,Seq:s.Node},s.Value&&{Map:s.Value,Scalar:s.Value,Seq:s.Value},s.Collection&&{Map:s.Collection,Seq:s.Collection},s):s}function Mi(s,e,t,i){if(typeof t=="function")return t(s,e,i);if(I.isMap(e))return t.Map?.(s,e,i);if(I.isSeq(e))return t.Seq?.(s,e,i);if(I.isPair(e))return t.Pair?.(s,e,i);if(I.isScalar(e))return t.Scalar?.(s,e,i);if(I.isAlias(e))return t.Alias?.(s,e,i)}function _i(s,e,t){let i=e[e.length-1];if(I.isCollection(i))i.items[s]=t;else if(I.isPair(i))s==="key"?i.key=t:i.value=t;else if(I.isDocument(i))i.contents=t;else{let n=I.isAlias(i)?"alias":"scalar";throw new Error(`Cannot replace node with ${n} parent`)}}Gt.visit=Xe;Gt.visitAsync=xe});var Ht=g(Di=>{"use strict";var $i=q(),Na=ye(),Aa={"!":"%21",",":"%2C","[":"%5B","]":"%5D","{":"%7B","}":"%7D"},qa=s=>s.replace(/[!,[\]{}]/g,e=>Aa[e]),be=class s{constructor(e,t){this.docStart=null,this.docEnd=!1,this.yaml=Object.assign({},s.defaultYaml,e),this.tags=Object.assign({},s.defaultTags,t)}clone(){let e=new s(this.yaml,this.tags);return e.docStart=this.docStart,e}atDocument(){let e=new s(this.yaml,this.tags);switch(this.yaml.version){case"1.1":this.atNextDocument=!0;break;case"1.2":this.atNextDocument=!1,this.yaml={explicit:s.defaultYaml.explicit,version:"1.2"},this.tags=Object.assign({},s.defaultTags);break}return e}add(e,t){this.atNextDocument&&(this.yaml={explicit:s.defaultYaml.explicit,version:"1.1"},this.tags=Object.assign({},s.defaultTags),this.atNextDocument=!1);let i=e.trim().split(/[ \t]+/),n=i.shift();switch(n){case"%TAG":{if(i.length!==2&&(t(0,"%TAG directive should contain exactly two parts"),i.length<2))return!1;let[r,a]=i;return this.tags[r]=a,!0}case"%YAML":{if(this.yaml.explicit=!0,i.length!==1)return t(0,"%YAML directive should contain exactly one part"),!1;let[r]=i;if(r==="1.1"||r==="1.2")return this.yaml.version=r,!0;{let a=/^\d+\.\d+$/.test(r);return t(6,`Unsupported YAML version ${r}`,a),!1}}default:return t(0,`Unknown directive ${n}`,!0),!1}}tagName(e,t){if(e==="!")return"!";if(e[0]!=="!")return t(`Not a valid tag: ${e}`),null;if(e[1]==="<"){let a=e.slice(2,-1);return a==="!"||a==="!!"?(t(`Verbatim tags aren't resolved, so ${e} is invalid.`),null):(e[e.length-1]!==">"&&t("Verbatim tags must end with a >"),a)}let[,i,n]=e.match(/^(.*!)([^!]*)$/s);n||t(`The ${e} tag has no suffix`);let r=this.tags[i];if(r)try{return r+decodeURIComponent(n)}catch(a){return t(String(a)),null}return i==="!"?e:(t(`Could not resolve tag: ${e}`),null)}tagString(e){for(let[t,i]of Object.entries(this.tags))if(e.startsWith(i))return t+qa(e.substring(i.length));return e[0]==="!"?e:`!<${e}>`}toString(e){let t=this.yaml.explicit?[`%YAML ${this.yaml.version||"1.2"}`]:[],i=Object.entries(this.tags),n;if(e&&i.length>0&&$i.isNode(e.contents)){let r={};Na.visit(e.contents,(a,o)=>{$i.isNode(o)&&o.tag&&(r[o.tag]=!0)}),n=Object.keys(r)}else n=[];for(let[r,a]of i)r==="!!"&&a==="tag:yaml.org,2002:"||(!e||n.some(o=>o.startsWith(a)))&&t.push(`%TAG ${r} ${a}`);return t.join(`
5
- `)}};be.defaultYaml={explicit:!1,version:"1.2"};be.defaultTags={"!!":"tag:yaml.org,2002:"};Di.Directives=be});var ze=g(Se=>{"use strict";var Bi=q(),Oa=ye();function La(s){if(/[\x00-\x19\s,[\]{}]/.test(s)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(s)}`;throw new Error(t)}return!0}function Ki(s){let e=new Set;return Oa.visit(s,{Value(t,i){i.anchor&&e.add(i.anchor)}}),e}function ji(s,e){for(let t=1;;++t){let i=`${s}${t}`;if(!e.has(i))return i}}function Ea(s,e){let t=[],i=new Map,n=null;return{onAnchor:r=>{t.push(r),n??(n=Ki(s));let a=ji(e,n);return n.add(a),a},setAnchors:()=>{for(let r of t){let a=i.get(r);if(typeof a=="object"&&a.anchor&&(Bi.isScalar(a.node)||Bi.isCollection(a.node)))a.node.anchor=a.anchor;else{let o=new Error("Failed to resolve repeated object (this should not happen)");throw o.source=r,o}}},sourceObjects:i}}Se.anchorIsValid=La;Se.anchorNames=Ki;Se.createNodeAnchors=Ea;Se.findNewAnchor=ji});var Xt=g(Fi=>{"use strict";function we(s,e,t,i){if(i&&typeof i=="object")if(Array.isArray(i))for(let n=0,r=i.length;n<r;++n){let a=i[n],o=we(s,i,String(n),a);o===void 0?delete i[n]:o!==a&&(i[n]=o)}else if(i instanceof Map)for(let n of Array.from(i.keys())){let r=i.get(n),a=we(s,i,n,r);a===void 0?i.delete(n):a!==r&&i.set(n,a)}else if(i instanceof Set)for(let n of Array.from(i)){let r=we(s,i,n,n);r===void 0?i.delete(n):r!==n&&(i.delete(n),i.add(r))}else for(let[n,r]of Object.entries(i)){let a=we(s,i,n,r);a===void 0?delete i[n]:a!==r&&(i[n]=a)}return s.call(e,t,i)}Fi.applyReviver=we});var Y=g(Ui=>{"use strict";var Ta=q();function Ri(s,e,t){if(Array.isArray(s))return s.map((i,n)=>Ri(i,String(n),t));if(s&&typeof s.toJSON=="function"){if(!t||!Ta.hasAnchor(s))return s.toJSON(e,t);let i={aliasCount:0,count:1,res:void 0};t.anchors.set(s,i),t.onCreate=r=>{i.res=r,delete t.onCreate};let n=s.toJSON(e,t);return t.onCreate&&t.onCreate(n),n}return typeof s=="bigint"&&!t?.keep?Number(s):s}Ui.toJS=Ri});var Ze=g(Vi=>{"use strict";var Ca=Xt(),Yi=q(),Ia=Y(),xt=class{constructor(e){Object.defineProperty(this,Yi.NODE_TYPE,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:i,onAnchor:n,reviver:r}={}){if(!Yi.isDocument(e))throw new TypeError("A document argument is required");let a={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof i=="number"?i:100},o=Ia.toJS(this,"",a);if(typeof n=="function")for(let{count:l,res:c}of a.anchors.values())n(c,l);return typeof r=="function"?Ca.applyReviver(r,{"":o},"",o):o}};Vi.NodeBase=xt});var ve=g(Ji=>{"use strict";var Pa=ze(),Ma=ye(),le=q(),_a=Ze(),$a=Y(),zt=class extends _a.NodeBase{constructor(e){super(le.ALIAS),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e,t){if(t?.maxAliasCount===0)throw new ReferenceError("Alias resolution is disabled");let i;t?.aliasResolveCache?i=t.aliasResolveCache:(i=[],Ma.visit(e,{Node:(r,a)=>{(le.isAlias(a)||le.hasAnchor(a))&&i.push(a)}}),t&&(t.aliasResolveCache=i));let n;for(let r of i){if(r===this)break;r.anchor===this.source&&(n=r)}return n}toJSON(e,t){if(!t)return{source:this.source};let{anchors:i,doc:n,maxAliasCount:r}=t,a=this.resolve(n,t);if(!a){let l=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(l)}let o=i.get(a);if(o||($a.toJS(a,null,t),o=i.get(a)),o?.res===void 0){let l="This should not happen: Alias anchor was not resolved?";throw new ReferenceError(l)}if(r>=0&&(o.count+=1,o.aliasCount===0&&(o.aliasCount=et(n,a,i)),o.count*o.aliasCount>r)){let l="Excessive alias count indicates a resource exhaustion attack";throw new ReferenceError(l)}return o.res}toString(e,t,i){let n=`*${this.source}`;if(e){if(Pa.anchorIsValid(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let r=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(r)}if(e.implicitKey)return`${n} `}return n}};function et(s,e,t){if(le.isAlias(e)){let i=e.resolve(s),n=t&&i&&t.get(i);return n?n.count*n.aliasCount:0}else if(le.isCollection(e)){let i=0;for(let n of e.items){let r=et(s,n,t);r>i&&(i=r)}return i}else if(le.isPair(e)){let i=et(s,e.key,t),n=et(s,e.value,t);return Math.max(i,n)}return 1}Ji.Alias=zt});var E=g(Zt=>{"use strict";var Da=q(),Ba=Ze(),Ka=Y(),ja=s=>!s||typeof s!="function"&&typeof s!="object",V=class extends Ba.NodeBase{constructor(e){super(Da.SCALAR),this.value=e}toJSON(e,t){return t?.keep?this.value:Ka.toJS(this.value,e,t)}toString(){return String(this.value)}};V.BLOCK_FOLDED="BLOCK_FOLDED";V.BLOCK_LITERAL="BLOCK_LITERAL";V.PLAIN="PLAIN";V.QUOTE_DOUBLE="QUOTE_DOUBLE";V.QUOTE_SINGLE="QUOTE_SINGLE";Zt.Scalar=V;Zt.isScalarValue=ja});var ke=g(Wi=>{"use strict";var Fa=ve(),Z=q(),Qi=E(),Ra="tag:yaml.org,2002:";function Ua(s,e,t){if(e){let i=t.filter(r=>r.tag===e),n=i.find(r=>!r.format)??i[0];if(!n)throw new Error(`Tag ${e} not found`);return n}return t.find(i=>i.identify?.(s)&&!i.format)}function Ya(s,e,t){if(Z.isDocument(s)&&(s=s.contents),Z.isNode(s))return s;if(Z.isPair(s)){let f=t.schema[Z.MAP].createNode?.(t.schema,null,t);return f.items.push(s),f}(s instanceof String||s instanceof Number||s instanceof Boolean||typeof BigInt<"u"&&s instanceof BigInt)&&(s=s.valueOf());let{aliasDuplicateObjects:i,onAnchor:n,onTagObj:r,schema:a,sourceObjects:o}=t,l;if(i&&s&&typeof s=="object"){if(l=o.get(s),l)return l.anchor??(l.anchor=n(s)),new Fa.Alias(l.anchor);l={anchor:null,node:null},o.set(s,l)}e?.startsWith("!!")&&(e=Ra+e.slice(2));let c=Ua(s,e,a.tags);if(!c){if(s&&typeof s.toJSON=="function"&&(s=s.toJSON()),!s||typeof s!="object"){let f=new Qi.Scalar(s);return l&&(l.node=f),f}c=s instanceof Map?a[Z.MAP]:Symbol.iterator in Object(s)?a[Z.SEQ]:a[Z.MAP]}r&&(r(c),delete t.onTagObj);let d=c?.createNode?c.createNode(t.schema,s,t):typeof c?.nodeClass?.from=="function"?c.nodeClass.from(t.schema,s,t):new Qi.Scalar(s);return e?d.tag=e:c.default||(d.tag=c.tag),l&&(l.node=d),d}Wi.createNode=Ya});var st=g(tt=>{"use strict";var Va=ke(),j=q(),Ja=Ze();function es(s,e,t){let i=t;for(let n=e.length-1;n>=0;--n){let r=e[n];if(typeof r=="number"&&Number.isInteger(r)&&r>=0){let a=[];a[r]=i,i=a}else i=new Map([[r,i]])}return Va.createNode(i,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:s,sourceObjects:new Map})}var Gi=s=>s==null||typeof s=="object"&&!!s[Symbol.iterator]().next().done,ts=class extends Ja.NodeBase{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(i=>j.isNode(i)||j.isPair(i)?i.clone(e):i),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(Gi(e))this.add(t);else{let[i,...n]=e,r=this.get(i,!0);if(j.isCollection(r))r.addIn(n,t);else if(r===void 0&&this.schema)this.set(i,es(this.schema,n,t));else throw new Error(`Expected YAML collection at ${i}. Remaining path: ${n}`)}}deleteIn(e){let[t,...i]=e;if(i.length===0)return this.delete(t);let n=this.get(t,!0);if(j.isCollection(n))return n.deleteIn(i);throw new Error(`Expected YAML collection at ${t}. Remaining path: ${i}`)}getIn(e,t){let[i,...n]=e,r=this.get(i,!0);return n.length===0?!t&&j.isScalar(r)?r.value:r:j.isCollection(r)?r.getIn(n,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!j.isPair(t))return!1;let i=t.value;return i==null||e&&j.isScalar(i)&&i.value==null&&!i.commentBefore&&!i.comment&&!i.tag})}hasIn(e){let[t,...i]=e;if(i.length===0)return this.has(t);let n=this.get(t,!0);return j.isCollection(n)?n.hasIn(i):!1}setIn(e,t){let[i,...n]=e;if(n.length===0)this.set(i,t);else{let r=this.get(i,!0);if(j.isCollection(r))r.setIn(n,t);else if(r===void 0&&this.schema)this.set(i,es(this.schema,n,t));else throw new Error(`Expected YAML collection at ${i}. Remaining path: ${n}`)}}};tt.Collection=ts;tt.collectionFromPath=es;tt.isEmptyPath=Gi});var Ne=g(it=>{"use strict";var Qa=s=>s.replace(/^(?!$)(?: $)?/gm,"#");function ss(s,e){return/^\n+$/.test(s)?s.substring(1):e?s.replace(/^(?! *$)/gm,e):s}var Wa=(s,e,t)=>s.endsWith(`
5
+ `)}};be.defaultYaml={explicit:!1,version:"1.2"};be.defaultTags={"!!":"tag:yaml.org,2002:"};Di.Directives=be});var ze=g(Se=>{"use strict";var Bi=q(),Oa=ye();function La(s){if(/[\x00-\x19\s,[\]{}]/.test(s)){let t=`Anchor must not contain whitespace or control characters: ${JSON.stringify(s)}`;throw new Error(t)}return!0}function Ki(s){let e=new Set;return Oa.visit(s,{Value(t,i){i.anchor&&e.add(i.anchor)}}),e}function ji(s,e){for(let t=1;;++t){let i=`${s}${t}`;if(!e.has(i))return i}}function Ea(s,e){let t=[],i=new Map,n=null;return{onAnchor:r=>{t.push(r),n??(n=Ki(s));let a=ji(e,n);return n.add(a),a},setAnchors:()=>{for(let r of t){let a=i.get(r);if(typeof a=="object"&&a.anchor&&(Bi.isScalar(a.node)||Bi.isCollection(a.node)))a.node.anchor=a.anchor;else{let o=new Error("Failed to resolve repeated object (this should not happen)");throw o.source=r,o}}},sourceObjects:i}}Se.anchorIsValid=La;Se.anchorNames=Ki;Se.createNodeAnchors=Ea;Se.findNewAnchor=ji});var Xt=g(Fi=>{"use strict";function we(s,e,t,i){if(i&&typeof i=="object")if(Array.isArray(i))for(let n=0,r=i.length;n<r;++n){let a=i[n],o=we(s,i,String(n),a);o===void 0?delete i[n]:o!==a&&(i[n]=o)}else if(i instanceof Map)for(let n of Array.from(i.keys())){let r=i.get(n),a=we(s,i,n,r);a===void 0?i.delete(n):a!==r&&i.set(n,a)}else if(i instanceof Set)for(let n of Array.from(i)){let r=we(s,i,n,n);r===void 0?i.delete(n):r!==n&&(i.delete(n),i.add(r))}else for(let[n,r]of Object.entries(i)){let a=we(s,i,n,r);a===void 0?delete i[n]:a!==r&&(i[n]=a)}return s.call(e,t,i)}Fi.applyReviver=we});var Y=g(Ui=>{"use strict";var Ta=q();function Ri(s,e,t){if(Array.isArray(s))return s.map((i,n)=>Ri(i,String(n),t));if(s&&typeof s.toJSON=="function"){if(!t||!Ta.hasAnchor(s))return s.toJSON(e,t);let i={aliasCount:0,count:1,res:void 0};t.anchors.set(s,i),t.onCreate=r=>{i.res=r,delete t.onCreate};let n=s.toJSON(e,t);return t.onCreate&&t.onCreate(n),n}return typeof s=="bigint"&&!t?.keep?Number(s):s}Ui.toJS=Ri});var Ze=g(Vi=>{"use strict";var Ca=Xt(),Yi=q(),Ia=Y(),xt=class{constructor(e){Object.defineProperty(this,Yi.NODE_TYPE,{value:e})}clone(){let e=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return this.range&&(e.range=this.range.slice()),e}toJS(e,{mapAsMap:t,maxAliasCount:i,onAnchor:n,reviver:r}={}){if(!Yi.isDocument(e))throw new TypeError("A document argument is required");let a={anchors:new Map,doc:e,keep:!0,mapAsMap:t===!0,mapKeyWarned:!1,maxAliasCount:typeof i=="number"?i:100},o=Ia.toJS(this,"",a);if(typeof n=="function")for(let{count:l,res:c}of a.anchors.values())n(c,l);return typeof r=="function"?Ca.applyReviver(r,{"":o},"",o):o}};Vi.NodeBase=xt});var ve=g(Ji=>{"use strict";var Pa=ze(),Ma=ye(),le=q(),_a=Ze(),$a=Y(),zt=class extends _a.NodeBase{constructor(e){super(le.ALIAS),this.source=e,Object.defineProperty(this,"tag",{set(){throw new Error("Alias nodes cannot have tags")}})}resolve(e,t){if(t?.maxAliasCount===0)throw new ReferenceError("Alias resolution is disabled");let i;t?.aliasResolveCache?i=t.aliasResolveCache:(i=[],Ma.visit(e,{Node:(r,a)=>{(le.isAlias(a)||le.hasAnchor(a))&&i.push(a)}}),t&&(t.aliasResolveCache=i));let n;for(let r of i){if(r===this)break;r.anchor===this.source&&(n=r)}if(n&&t){let{anchors:r,doc:a,maxAliasCount:o}=t,l=r.get(n);if(l||($a.toJS(n,null,t),l=r.get(n)),l?.res===void 0){let c="This should not happen: Alias anchor was not resolved?";throw new ReferenceError(c)}if(o>=0&&(l.count+=1,l.aliasCount===0&&(l.aliasCount=et(a,n,r)),l.count*l.aliasCount>o)){let c="Excessive alias count indicates a resource exhaustion attack";throw new ReferenceError(c)}}return n}toJSON(e,t){if(!t)return{source:this.source};let i=this.resolve(t.doc,t);if(!i){let n=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new ReferenceError(n)}return t.anchors.get(i).res}toString(e,t,i){let n=`*${this.source}`;if(e){if(Pa.anchorIsValid(this.source),e.options.verifyAliasOrder&&!e.anchors.has(this.source)){let r=`Unresolved alias (the anchor must be set before the alias): ${this.source}`;throw new Error(r)}if(e.implicitKey)return`${n} `}return n}};function et(s,e,t){if(le.isAlias(e)){let i=e.resolve(s),n=t&&i&&t.get(i);return n?n.count*n.aliasCount:0}else if(le.isCollection(e)){let i=0;for(let n of e.items){let r=et(s,n,t);r>i&&(i=r)}return i}else if(le.isPair(e)){let i=et(s,e.key,t),n=et(s,e.value,t);return Math.max(i,n)}return 1}Ji.Alias=zt});var E=g(Zt=>{"use strict";var Da=q(),Ba=Ze(),Ka=Y(),ja=s=>!s||typeof s!="function"&&typeof s!="object",V=class extends Ba.NodeBase{constructor(e){super(Da.SCALAR),this.value=e}toJSON(e,t){return t?.keep?this.value:Ka.toJS(this.value,e,t)}toString(){return String(this.value)}};V.BLOCK_FOLDED="BLOCK_FOLDED";V.BLOCK_LITERAL="BLOCK_LITERAL";V.PLAIN="PLAIN";V.QUOTE_DOUBLE="QUOTE_DOUBLE";V.QUOTE_SINGLE="QUOTE_SINGLE";Zt.Scalar=V;Zt.isScalarValue=ja});var ke=g(Wi=>{"use strict";var Fa=ve(),Z=q(),Qi=E(),Ra="tag:yaml.org,2002:";function Ua(s,e,t){if(e){let i=t.filter(r=>r.tag===e),n=i.find(r=>!r.format)??i[0];if(!n)throw new Error(`Tag ${e} not found`);return n}return t.find(i=>i.identify?.(s)&&!i.format)}function Ya(s,e,t){if(Z.isDocument(s)&&(s=s.contents),Z.isNode(s))return s;if(Z.isPair(s)){let f=t.schema[Z.MAP].createNode?.(t.schema,null,t);return f.items.push(s),f}(s instanceof String||s instanceof Number||s instanceof Boolean||typeof BigInt<"u"&&s instanceof BigInt)&&(s=s.valueOf());let{aliasDuplicateObjects:i,onAnchor:n,onTagObj:r,schema:a,sourceObjects:o}=t,l;if(i&&s&&typeof s=="object"){if(l=o.get(s),l)return l.anchor??(l.anchor=n(s)),new Fa.Alias(l.anchor);l={anchor:null,node:null},o.set(s,l)}e?.startsWith("!!")&&(e=Ra+e.slice(2));let c=Ua(s,e,a.tags);if(!c){if(s&&typeof s.toJSON=="function"&&(s=s.toJSON()),!s||typeof s!="object"){let f=new Qi.Scalar(s);return l&&(l.node=f),f}c=s instanceof Map?a[Z.MAP]:Symbol.iterator in Object(s)?a[Z.SEQ]:a[Z.MAP]}r&&(r(c),delete t.onTagObj);let d=c?.createNode?c.createNode(t.schema,s,t):typeof c?.nodeClass?.from=="function"?c.nodeClass.from(t.schema,s,t):new Qi.Scalar(s);return e?d.tag=e:c.default||(d.tag=c.tag),l&&(l.node=d),d}Wi.createNode=Ya});var st=g(tt=>{"use strict";var Va=ke(),j=q(),Ja=Ze();function es(s,e,t){let i=t;for(let n=e.length-1;n>=0;--n){let r=e[n];if(typeof r=="number"&&Number.isInteger(r)&&r>=0){let a=[];a[r]=i,i=a}else i=new Map([[r,i]])}return Va.createNode(i,void 0,{aliasDuplicateObjects:!1,keepUndefined:!1,onAnchor:()=>{throw new Error("This should not happen, please report a bug.")},schema:s,sourceObjects:new Map})}var Gi=s=>s==null||typeof s=="object"&&!!s[Symbol.iterator]().next().done,ts=class extends Ja.NodeBase{constructor(e,t){super(e),Object.defineProperty(this,"schema",{value:t,configurable:!0,enumerable:!1,writable:!0})}clone(e){let t=Object.create(Object.getPrototypeOf(this),Object.getOwnPropertyDescriptors(this));return e&&(t.schema=e),t.items=t.items.map(i=>j.isNode(i)||j.isPair(i)?i.clone(e):i),this.range&&(t.range=this.range.slice()),t}addIn(e,t){if(Gi(e))this.add(t);else{let[i,...n]=e,r=this.get(i,!0);if(j.isCollection(r))r.addIn(n,t);else if(r===void 0&&this.schema)this.set(i,es(this.schema,n,t));else throw new Error(`Expected YAML collection at ${i}. Remaining path: ${n}`)}}deleteIn(e){let[t,...i]=e;if(i.length===0)return this.delete(t);let n=this.get(t,!0);if(j.isCollection(n))return n.deleteIn(i);throw new Error(`Expected YAML collection at ${t}. Remaining path: ${i}`)}getIn(e,t){let[i,...n]=e,r=this.get(i,!0);return n.length===0?!t&&j.isScalar(r)?r.value:r:j.isCollection(r)?r.getIn(n,t):void 0}hasAllNullValues(e){return this.items.every(t=>{if(!j.isPair(t))return!1;let i=t.value;return i==null||e&&j.isScalar(i)&&i.value==null&&!i.commentBefore&&!i.comment&&!i.tag})}hasIn(e){let[t,...i]=e;if(i.length===0)return this.has(t);let n=this.get(t,!0);return j.isCollection(n)?n.hasIn(i):!1}setIn(e,t){let[i,...n]=e;if(n.length===0)this.set(i,t);else{let r=this.get(i,!0);if(j.isCollection(r))r.setIn(n,t);else if(r===void 0&&this.schema)this.set(i,es(this.schema,n,t));else throw new Error(`Expected YAML collection at ${i}. Remaining path: ${n}`)}}};tt.Collection=ts;tt.collectionFromPath=es;tt.isEmptyPath=Gi});var Ne=g(it=>{"use strict";var Qa=s=>s.replace(/^(?!$)(?: $)?/gm,"#");function ss(s,e){return/^\n+$/.test(s)?s.substring(1):e?s.replace(/^(?! *$)/gm,e):s}var Wa=(s,e,t)=>s.endsWith(`
6
6
  `)?ss(t,e):t.includes(`
7
7
  `)?`
8
8
  `+ss(t,e):(s.endsWith(" ")?"":" ")+t;it.indentComment=ss;it.lineComment=Wa;it.stringifyComment=Qa});var Xi=g(Ae=>{"use strict";var Ga="flow",is="block",nt="quoted";function Ha(s,e,t="flow",{indentAtStart:i,lineWidth:n=80,minContentWidth:r=20,onFold:a,onOverflow:o}={}){if(!n||n<0)return s;n<r&&(r=0);let l=Math.max(1+r,1+n-e.length);if(s.length<=l)return s;let c=[],d={},f=n-e.length;typeof i=="number"&&(i>n-Math.max(2,r)?c.push(0):f=n-i);let u,m,y=!1,h=-1,p=-1,S=-1;t===is&&(h=Hi(s,h,e.length),h!==-1&&(f=h+l));for(let v;v=s[h+=1];){if(t===nt&&v==="\\"){switch(p=h,s[h+1]){case"x":h+=3;break;case"u":h+=5;break;case"U":h+=9;break;default:h+=1}S=h}if(v===`
@@ -84,11 +84,9 @@ ${c}
84
84
  `+a[h][0].slice(l);f[f.length-1]!==`
85
85
  `&&(f+=`
86
86
  `);break;default:f+=`
87
- `}let y=i+n.length+e.source.length;return{value:f,type:r,comment:n.comment,range:[i,y,y]}}function Ec({offset:s,props:e},t,i){if(e[0].type!=="block-scalar-header")return i(e[0],"IMPOSSIBLE","Block scalar header not found"),null;let{source:n}=e[0],r=n[0],a=0,o="",l=-1;for(let u=1;u<n.length;++u){let m=n[u];if(!o&&(m==="-"||m==="+"))o=m;else{let y=Number(m);!a&&y?a=y:l===-1&&(l=s+u)}}l!==-1&&i(l,"UNEXPECTED_TOKEN",`Block scalar header includes extra characters: ${n}`);let c=!1,d="",f=n.length;for(let u=1;u<e.length;++u){let m=e[u];switch(m.type){case"space":c=!0;case"newline":f+=m.source.length;break;case"comment":t&&!c&&i(m,"MISSING_CHAR","Comments must be separated from other tokens by white space characters"),f+=m.source.length,d=m.source.substring(1);break;case"error":i(m,"UNEXPECTED_TOKEN",m.message),f+=m.source.length;break;default:{let y=`Unexpected token in block scalar header: ${m.type}`;i(m,"UNEXPECTED_TOKEN",y);let h=m.source;h&&typeof h=="string"&&(f+=h.length)}}}return{mode:r,indent:a,chomp:o,comment:d,length:f}}function Tc(s){let e=s.split(/\n( *)/),t=e[0],i=t.match(/^( *)/),r=[i?.[1]?[i[1],t.slice(i[1].length)]:["",t]];for(let a=1;a<e.length;a+=2)r.push([e[a],e[a+1]]);return r}Cr.resolveBlockScalar=Lc});var ai=g(Pr=>{"use strict";var ri=E(),Cc=me();function Ic(s,e,t){let{offset:i,type:n,source:r,end:a}=s,o,l,c=(u,m,y)=>t(i+u,m,y);switch(n){case"scalar":o=ri.Scalar.PLAIN,l=Pc(r,c);break;case"single-quoted-scalar":o=ri.Scalar.QUOTE_SINGLE,l=Mc(r,c);break;case"double-quoted-scalar":o=ri.Scalar.QUOTE_DOUBLE,l=_c(r,c);break;default:return t(s,"UNEXPECTED_TOKEN",`Expected a flow scalar value, but found: ${n}`),{value:"",type:null,comment:"",range:[i,i+r.length,i+r.length]}}let d=i+r.length,f=Cc.resolveEnd(a,d,e,t);return{value:l,type:o,comment:f.comment,range:[i,d,f.offset]}}function Pc(s,e){let t="";switch(s[0]){case" ":t="a tab character";break;case",":t="flow indicator character ,";break;case"%":t="directive indicator character %";break;case"|":case">":{t=`block scalar indicator ${s[0]}`;break}case"@":case"`":{t=`reserved character ${s[0]}`;break}}return t&&e(0,"BAD_SCALAR_START",`Plain value cannot start with ${t}`),Ir(s)}function Mc(s,e){return(s[s.length-1]!=="'"||s.length===1)&&e(s.length,"MISSING_CHAR","Missing closing 'quote"),Ir(s.slice(1,-1)).replace(/''/g,"'")}function Ir(s){let e,t;try{e=new RegExp(`(.*?)(?<![ ])[ ]*\r?
88
- `,"sy"),t=new RegExp(`[ ]*(.*?)(?:(?<![ ])[ ]*)?\r?
89
- `,"sy")}catch{e=/(.*?)[ \t]*\r?\n/sy,t=/[ \t]*(.*?)[ \t]*\r?\n/sy}let i=e.exec(s);if(!i)return s;let n=i[1],r=" ",a=e.lastIndex;for(t.lastIndex=a;i=t.exec(s);)i[1]===""?r===`
90
- `?n+=r:r=`
91
- `:(n+=r+i[1],r=" "),a=t.lastIndex;let o=/[ \t]*(.*)/sy;return o.lastIndex=a,i=o.exec(s),n+r+(i?.[1]??"")}function _c(s,e){let t="";for(let i=1;i<s.length-1;++i){let n=s[i];if(!(n==="\r"&&s[i+1]===`
87
+ `}let y=i+n.length+e.source.length;return{value:f,type:r,comment:n.comment,range:[i,y,y]}}function Ec({offset:s,props:e},t,i){if(e[0].type!=="block-scalar-header")return i(e[0],"IMPOSSIBLE","Block scalar header not found"),null;let{source:n}=e[0],r=n[0],a=0,o="",l=-1;for(let u=1;u<n.length;++u){let m=n[u];if(!o&&(m==="-"||m==="+"))o=m;else{let y=Number(m);!a&&y?a=y:l===-1&&(l=s+u)}}l!==-1&&i(l,"UNEXPECTED_TOKEN",`Block scalar header includes extra characters: ${n}`);let c=!1,d="",f=n.length;for(let u=1;u<e.length;++u){let m=e[u];switch(m.type){case"space":c=!0;case"newline":f+=m.source.length;break;case"comment":t&&!c&&i(m,"MISSING_CHAR","Comments must be separated from other tokens by white space characters"),f+=m.source.length,d=m.source.substring(1);break;case"error":i(m,"UNEXPECTED_TOKEN",m.message),f+=m.source.length;break;default:{let y=`Unexpected token in block scalar header: ${m.type}`;i(m,"UNEXPECTED_TOKEN",y);let h=m.source;h&&typeof h=="string"&&(f+=h.length)}}}return{mode:r,indent:a,chomp:o,comment:d,length:f}}function Tc(s){let e=s.split(/\n( *)/),t=e[0],i=t.match(/^( *)/),r=[i?.[1]?[i[1],t.slice(i[1].length)]:["",t]];for(let a=1;a<e.length;a+=2)r.push([e[a],e[a+1]]);return r}Cr.resolveBlockScalar=Lc});var ai=g(Pr=>{"use strict";var ri=E(),Cc=me();function Ic(s,e,t){let{offset:i,type:n,source:r,end:a}=s,o,l,c=(u,m,y)=>t(i+u,m,y);switch(n){case"scalar":o=ri.Scalar.PLAIN,l=Pc(r,c);break;case"single-quoted-scalar":o=ri.Scalar.QUOTE_SINGLE,l=Mc(r,c);break;case"double-quoted-scalar":o=ri.Scalar.QUOTE_DOUBLE,l=_c(r,c);break;default:return t(s,"UNEXPECTED_TOKEN",`Expected a flow scalar value, but found: ${n}`),{value:"",type:null,comment:"",range:[i,i+r.length,i+r.length]}}let d=i+r.length,f=Cc.resolveEnd(a,d,e,t);return{value:l,type:o,comment:f.comment,range:[i,d,f.offset]}}function Pc(s,e){let t="";switch(s[0]){case" ":t="a tab character";break;case",":t="flow indicator character ,";break;case"%":t="directive indicator character %";break;case"|":case">":{t=`block scalar indicator ${s[0]}`;break}case"@":case"`":{t=`reserved character ${s[0]}`;break}}return t&&e(0,"BAD_SCALAR_START",`Plain value cannot start with ${t}`),Ir(s)}function Mc(s,e){return(s[s.length-1]!=="'"||s.length===1)&&e(s.length,"MISSING_CHAR","Missing closing 'quote"),Ir(s.slice(1,-1)).replace(/''/g,"'")}function Ir(s){let e=/(.*?)\r?\n/sy,t=e.exec(s);if(!t)return s;let i,n;try{i=new RegExp("(?<![ ])[ ]+$"),n=new RegExp("^[ ]+|(?<![ ])[ ]+$","g")}catch{i=/[ \t]+$/,n=/^[ \t]+|[ \t]+$/g}let r=t[1].replace(i,""),a=" ",o=e.lastIndex;for(;t=e.exec(s);){let c=t[1].replace(n,"");c===""?a===`
88
+ `?r+=a:a=`
89
+ `:(r+=a+c,a=" "),o=e.lastIndex}let l=/[ \t]*(.*)/sy;return l.lastIndex=o,t=l.exec(s),r+a+(t?.[1]??"")}function _c(s,e){let t="";for(let i=1;i<s.length-1;++i){let n=s[i];if(!(n==="\r"&&s[i+1]===`
92
90
  `))if(n===`
93
91
  `){let{fold:r,offset:a}=$c(s,i);t+=r,i=a}else if(n==="\\"){let r=s[++i],a=Dc[r];if(a)t+=a;else if(r===`
94
92
  `)for(r=s[i+1];r===" "||r===" ";)r=s[++i+1];else if(r==="\r"&&s[i+1]===`
@@ -0,0 +1,4 @@
1
+ import { createRequire as __cortexCreateRequire } from 'node:module';
2
+ const require = __cortexCreateRequire(import.meta.url);
3
+ const __cortexPackageRoot = new URL("../../", import.meta.url);
4
+ function r(n){let t=n.split(".")[1];if(!t)return null;try{return JSON.parse(Buffer.from(t,"base64url").toString("utf8"))}catch{return null}}function i(n){let t=[n];for(;t.length>0;){let e=t.shift();if(!e||typeof e!="object")continue;let o=e;if(typeof o.chatgpt_account_id=="string")return o.chatgpt_account_id;t.push(...Object.values(o))}}function c(n,t){let e=[n];for(;e.length>0;){let o=e.shift();if(!o||typeof o!="object")continue;let u=o;if(typeof u[t]=="string")return u[t];e.push(...Object.values(u))}return null}function a(n){let t=r(n);return{email:c(t,"email"),plan:c(t,"chatgpt_plan_type")}}export{r as a,i as b,a as c};
@@ -0,0 +1,4 @@
1
+ import { createRequire as __cortexCreateRequire } from 'node:module';
2
+ const require = __cortexCreateRequire(import.meta.url);
3
+ const __cortexPackageRoot = new URL("../../", import.meta.url);
4
+ import{A as l,K as d,R as N,e as I,r as m}from"./chunk-C6YVF7EI.js";import{a as _}from"./chunk-PTS3J4DQ.js";import{b as O}from"./chunk-OJ37ZWBG.js";import{a as v}from"./chunk-V35MFAUQ.js";import{a as c,b as i,e as A,g as C,h as E,j as u}from"./chunk-LIIZI3HY.js";import{i as f}from"./chunk-T54CZKNJ.js";import{e as h}from"./chunk-WHC7AYZD.js";var a=h(v(),1);import{existsSync as S,mkdirSync as D,readFileSync as U,writeFileSync as k}from"fs";import*as T from"path";var x=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function b(e){return T.join(e,"config.yaml")}function P(e){if(!S(e))return{};try{let r=a.parse(U(e,"utf-8"));return r&&typeof r=="object"&&!Array.isArray(r)?r:{}}catch{return{}}}function p(e){return typeof e=="string"?e:""}function J(e=f){let r=P(b(e));return{enabled:r.uploadEnabled===!0,name:p(r.name),org:p(r.org),email:p(r.email)}}function Q(e){if(!e.enabled)return[];let r=[];return e.name?.trim()||r.push("name-required"),x.test(e.email?.trim()??"")||r.push("email-invalid"),r}function X(e,r=f){let t=b(r);D(r,{recursive:!0});let n=P(t),o=e.enabled?{name:e.name||"",org:e.org||"",email:e.email||""}:{name:n.name??"",org:n.org??"",email:n.email??""};k(t,a.stringify({...n,...o,uploadEnabled:e.enabled}))}var K="cortex-gateway",w=/^http:\/\/(?:127\.0\.0\.1|localhost):\d+\/m\//;function g(e){if(!e||typeof e!="object"||Array.isArray(e))return!1;let{apiKey:r,baseUrl:t}=e;return r===K||typeof t=="string"&&w.test(t)}function L(e){if(!e)return{};let r={};for(let[t,n]of Object.entries(O(e)))!n||typeof n!="object"||Array.isArray(n)||g(n)||(r[t]=n);return r}function H(e){let r={baseUrl:e.baseUrl};return e.key&&(r.apiKey=e.key),A(e)&&(r.api=e.api,r.models=e.models.map(t=>({...t})),e.headers&&(r.headers={...e.headers}),e.compat&&(r.compat={...e.compat})),r}function B(e={}){let r=L(e.userModelsPath===void 0?_:e.userModelsPath),t={};for(let n of E(u(e.file??c)))r[n.provider]=H(n),n.key&&(t[n.provider]=n.key);return e.accountProvider?j({providers:r,runtimeKeys:t},e.accountProvider):{providers:r,runtimeKeys:t}}function j(e,r){let{[r]:t,...n}=e.runtimeKeys,o=e.providers[r];if(!o||!("apiKey"in o))return{providers:e.providers,runtimeKeys:n};let{apiKey:s,...R}=o;return{providers:{...e.providers,[r]:R},runtimeKeys:n}}var F=["ANTHROPIC_API_KEY","ANTHROPIC_AUTH_TOKEN","CLAUDE_CODE_OAUTH_TOKEN"];function y(e){let r=F.filter(t=>e.sets[t]===void 0);return{...e,unsets:r}}function Y(e){let r=I(e)?.token;return y({connection:i,sets:r?{CLAUDE_CODE_OAUTH_TOKEN:r}:{}})}function G(e){let r=e.authStyle==="bearer"?"ANTHROPIC_AUTH_TOKEN":"ANTHROPIC_API_KEY";return y({connection:e.id,...e.baseUrl?{baseUrl:e.baseUrl}:{},sets:{[r]:e.key}})}function M(e,r){return y({connection:e,sets:{},configDir:m(e,r.accountDir)})}function W(e,r){return C(u(r)).find(t=>t.id===e)??null}function $(e,r={}){let t=r.file??c,n=r.claude??{},o=e??d({file:t,claude:n,claudeAccountsDir:r.accountDir?.accountsDir}).defaultClaudeConnection()??i;if(o===i)return Y(n);let s=W(o,t);if(s)return G(s);if(l({backend:"claude",id:o},t))return M(o,r);throw new Error(`Claude connection '${o}' is not configured`)}function q(e,r={}){return e.backend==="pi"?e.connection||e.provider||"pi":e.connection??N(e,r)??i}function ge(e,r){return e.backend==="claude"&&r?r.connection:q(e)}export{B as a,$ as b,q as c,ge as d,J as e,Q as f,X as g};
@@ -0,0 +1,4 @@
1
+ import { createRequire as __cortexCreateRequire } from 'node:module';
2
+ const require = __cortexCreateRequire(import.meta.url);
3
+ const __cortexPackageRoot = new URL("../../", import.meta.url);
4
+ import{Sa as y,Va as _,Wa as E,Ya as I,Za as x,c as g,d as h,ea as C}from"./chunk-ZYQ4TDTT.js";import{e as m,f}from"./chunk-IA6IODY3.js";import{E as w,v as k,y as b}from"./chunk-UHXPRU6G.js";import{d as S}from"./chunk-CMSOOLJB.js";import{A as l}from"./chunk-Y6DGVTKM.js";import{I as p}from"./chunk-C6YVF7EI.js";import{e as u}from"./chunk-52VCLZS5.js";import{e as d}from"./chunk-7W7VYUTK.js";import{randomUUID as L}from"node:crypto";var P=d("subagent-runner"),T=["cortex-core","cortex-ext"],U=new Set(["monitor_start","monitor_stop"]);function $(n){return m(n.task.model?.trim()||n.role.model?.trim())}function M(n){return!!h[n]?.has(g.Subagents)}async function pn(n){if(n.signal?.aborted)throw new Error("Subagent was aborted.");if(!M(n.backend))throw new Error(`Backend "${n.backend}" cannot run subagents.`);return n.backend==="pi"?N(n):W(n)}async function N(n){let[{runPiChild:t},{childExtensions:o}]=await Promise.all([import("./child-runner-SMG2VOU5.js"),import("./tool-shims-YCXZWTST.js")]),e=B(n),i=I(),a=v(n.parent,e)??i.agentDir;try{i.ensureCatalog(a)}catch(c){P.warn(`Could not write the PI catalog for a pi subagent: ${c.message}`)}return t({task:n.task,role:n.role,cwd:n.cwd,workspace:n.workspace??null,agentDir:a,parentEnv:n.parent.env??process.env,model:e,childExtensions:c=>o(c,S),signal:n.signal,forward:O(n)})}function v(n,t){if(n.backend!=="pi"||!n.connection)return;let o=t.provider??n.provider??null;if(o===n.provider)return p({backend:"pi",provider:o,connection:n.connection})?.agentDir}function B(n){let t=n.parent.backend==="pi"?n.parent:null,o=f(n.task,n.role,t);if(o.model)return o;let e=l({},{backend:"pi"});if(e.ok===!1)return{};let{provider:i,model:a}=e.selection;return{model:a,...i?{provider:i}:{}}}function O(n){let t=n.onNotice;if(!t)return;let{ref:o,task:e}=n,i=!1;return(a,c)=>{let r=b(o,e,c,a);for(let s of r)try{t(i?s:{...s,prompt:e.prompt}),i=!0}catch{}}}function K(n){return n.backend!=="claude"||!n.model?null:{backend:"claude",provider:null,model:n.model,thinking:null,connection:n.connection??null}}function A(n,t){let o=K(n.parent),e=l({request:o},{...o?{}:{backend:"claude"},...t.model?{model:t.model}:{},thinking:t.thinking??null});if(e.ok===!1)throw new Error(`A claude subagent cannot run (${e.reason}); favorite a Claude model or fix its thinking level.`);return e.effective}function j(n,t){return`${n.parent.channel||"default"}#sub:${t}`}function F(n){return n&&C.getAll().some(o=>!o.subagent&&o.trackSessionId===n&&o.quotaPurpose==="human")?"human":"automatic"}function R(n,t){let o=H(n,t);return n.workspace?{...o,cwd:n.workspace,policy:E(o.policy)}:o}function H(n,t){let o=u(void 0,T).filter(i=>!U.has(i)),e=L();return{runId:e,session:{sessionId:null,backendSessionId:null,engineKey:j(n,e)},selection:t,cwd:n.cwd,spec:_(n.role,"claude",{mcpAllowlist:o??null}),prompt:{text:w(n.task),attachments:[]},context:{channel:n.parent.channel??"",project:n.parent.project??"general",trigger:"subagent",ownerSessionId:n.parent.sessionId??null,executionKind:"local",isUserInitiated:!1,quotaPurpose:F(n.parent.sessionId),scheduleTaskId:null},policy:{background:"none",recordCost:!0,hooks:!1,loadRules:!1,mcpComposition:"direct",mcpToolAllowlist:o,captureTranscripts:!1}}}function Q(n,t){n.catch(()=>{}).then(()=>x.close(t)).catch(o=>P.warn(`releasing child engine ${t} failed: ${o.message}`))}async function W(n){let t=$(n),o=A(n,t);if(!o.model)throw new Error("A claude subagent needs a model: set one on the task or the role.");let e=R(n,o),i=y(e,n.onNotice?[D(n)]:[]);Q(i.settled,e.session.engineKey);let a=()=>{i.cancel("user")};n.signal?.addEventListener("abort",a,{once:!0});let c;try{c=await i.result}finally{n.signal?.removeEventListener("abort",a)}if(n.signal?.aborted)throw new Error("Subagent was aborted.");return Y(n,c,o.model)}function X(n){let t=n.reportedAccounting,o=k();return o.input=t?.inputTokens??0,o.output=t?.outputTokens??0,o.cacheRead=t?.cacheReadTokens??0,o.cacheWrite=t?.cacheCreationTokens??0,o.cost=n.total_cost_usd??0,o.turns=n.num_turns??0,o}function Y(n,t,o){let e=t.rateLimited||!t.finalOutput&&!!t.rateLimitMessage;return{description:n.task.description,prompt:n.task.prompt,subagentType:n.task.subagent_type,output:t.finalOutput??"",usage:X(t),model:t.reportedAccounting?.model??o,backend:"claude",...e?{stopReason:"error",errorMessage:t.rateLimitMessage??"Subagent run failed."}:{}}}function D(n){let t=n.onNotice,o=n.ref,e={ref:o,type:n.task.subagent_type,description:n.task.description,backend:"claude",...n.task.clean?{clean:!0}:{}},i=null,a=!1,c=r=>{try{t(a?r:{...r,prompt:n.task.prompt}),a=!0}catch{}};return{onEvent(r){if(!("subagent"in r&&r.subagent)){if(r.type==="assistant_text"){r.model&&(i=r.model),r.text&&c({...e,model:i,kind:"assistant_text",text:r.text});return}if(r.type==="tool_use"){c({...e,model:i,kind:"tool_use",toolUseId:`${o}:${r.toolUseId}`,name:r.name,input:r.input});return}r.type==="tool_result"&&c({...e,model:i,kind:"tool_result",toolUseId:`${o}:${r.toolUseId}`,ok:r.ok,content:r.content,...r.images?.length?{images:r.images}:{}})}}}}var mn={claudeChildConfig:A,claudeChildRequest:R,claudeNoticeObserver:D};export{M as a,pn as b,F as c,mn as d};