@cortex-agent/server 2026.11.17 → 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 (338) hide show
  1. package/README.md +5 -5
  2. package/THIRD_PARTY_NOTICES.txt +860 -294
  3. package/defaults/hooks/quota-stop.mjs +37 -0
  4. package/defaults/prompts/clean-workspace.md +5 -0
  5. package/dist/agent-adapter/claude/remote-mcp-proxy.js +1 -1
  6. package/dist/chunks/agent-runner-LVZVKBZX.js +4 -0
  7. package/dist/chunks/anthropic-messages-TT6454AA.js +8 -0
  8. package/dist/chunks/azure-openai-responses-52LR2XZD.js +4 -0
  9. package/dist/chunks/bedrock-converse-stream-EOZGYUNY.js +60 -0
  10. package/dist/chunks/child-runner-SMG2VOU5.js +4 -0
  11. package/dist/chunks/chunk-24DH4IR5.js +4 -0
  12. package/dist/chunks/chunk-25XKBRDT.js +70 -0
  13. package/dist/chunks/{chunk-VTL3Z2OP.js → chunk-2ABET62E.js} +1 -1
  14. package/dist/chunks/chunk-2BVUA256.js +4 -0
  15. package/dist/chunks/{chunk-4YLAGSDM.js → chunk-2WFL62UO.js} +1 -1
  16. package/dist/chunks/{chunk-LQTFDC67.js → chunk-335SSANX.js} +1 -1
  17. package/dist/chunks/chunk-377OPTXX.js +17 -0
  18. package/dist/chunks/chunk-3EZNVLBF.js +129 -0
  19. package/dist/chunks/{chunk-V6X7Y62J.js → chunk-3O6ZG5HA.js} +1 -1
  20. package/dist/chunks/{chunk-6AKUD3CF.js → chunk-3XLHL5YT.js} +1 -1
  21. package/dist/chunks/{chunk-2ATTYCRJ.js → chunk-4HRI75GU.js} +1 -1
  22. package/dist/chunks/chunk-4JBYLRPM.js +57 -0
  23. package/dist/chunks/chunk-4KKV7VKE.js +4 -0
  24. package/dist/chunks/chunk-4KQHDDC5.js +4 -0
  25. package/dist/chunks/chunk-4SWD4JMP.js +33 -0
  26. package/dist/chunks/chunk-52VCLZS5.js +4 -0
  27. package/dist/chunks/chunk-54P7TSY3.js +10 -0
  28. package/dist/chunks/chunk-5DVSAXOI.js +7 -0
  29. package/dist/chunks/chunk-5F3A62YS.js +4 -0
  30. package/dist/chunks/{chunk-S3MR37DL.js → chunk-5FHETFZM.js} +1 -1
  31. package/dist/chunks/{chunk-CEGSDGYQ.js → chunk-5LBLRAHS.js} +1 -1
  32. package/dist/chunks/chunk-5UYVNA3W.js +4 -0
  33. package/dist/chunks/chunk-6G3OYMCV.js +21 -0
  34. package/dist/chunks/chunk-7GGPYU5E.js +30 -0
  35. package/dist/chunks/chunk-7TYSMLUV.js +4 -0
  36. package/dist/chunks/chunk-7W7VYUTK.js +5 -0
  37. package/dist/chunks/chunk-AXYAZTTN.js +6 -0
  38. package/dist/chunks/chunk-B3NB243Z.js +4 -0
  39. package/dist/chunks/{chunk-XPPZ6Y3X.js → chunk-BKYP6AGM.js} +1 -1
  40. package/dist/chunks/{chunk-QUXPMNFQ.js → chunk-BVEDNESB.js} +1 -1
  41. package/dist/chunks/chunk-BWDJS6A4.js +12 -0
  42. package/dist/chunks/chunk-C6YVF7EI.js +4 -0
  43. package/dist/chunks/chunk-CEJIYYVE.js +15 -0
  44. package/dist/chunks/{chunk-5PAW3DEU.js → chunk-CI2RHH74.js} +4 -4
  45. package/dist/chunks/{chunk-OFEPDNRB.js → chunk-CMSOOLJB.js} +1 -1
  46. package/dist/chunks/chunk-CSVTYYLP.js +4 -0
  47. package/dist/chunks/chunk-DE5EGVKG.js +6 -0
  48. package/dist/chunks/{chunk-E6BYRULL.js → chunk-DK3RPZOQ.js} +1 -1
  49. package/dist/chunks/{chunk-ROVKOIHF.js → chunk-DK4UCK7L.js} +1 -1
  50. package/dist/chunks/chunk-DYLBVUAU.js +4 -0
  51. package/dist/chunks/{chunk-WBSE3EF3.js → chunk-FDC2GRBK.js} +1 -1
  52. package/dist/chunks/chunk-FE7HH5JS.js +18 -0
  53. package/dist/chunks/chunk-FYD57YRO.js +436 -0
  54. package/dist/chunks/chunk-G264APQN.js +5 -0
  55. package/dist/chunks/chunk-G4JYZFEO.js +11 -0
  56. package/dist/chunks/chunk-GFFM56U2.js +4 -0
  57. package/dist/chunks/chunk-GOS3P7KS.js +132 -0
  58. package/dist/chunks/{chunk-2VVRTJQN.js → chunk-HVN37UXD.js} +1 -1
  59. package/dist/chunks/{chunk-53TQNK7Z.js → chunk-IGZWZP7Z.js} +1 -1
  60. package/dist/chunks/{chunk-AFTBQRPN.js → chunk-IJ7XFQMI.js} +1 -1
  61. package/dist/chunks/{chunk-U23S37TT.js → chunk-IMMGYDAB.js} +1 -1
  62. package/dist/chunks/chunk-IOWBF7UK.js +10 -0
  63. package/dist/chunks/{chunk-MGYYSX7Y.js → chunk-ITGCWQFK.js} +1 -1
  64. package/dist/chunks/{chunk-QEL6CMLE.js → chunk-IVZ7QUEG.js} +1 -1
  65. package/dist/chunks/{chunk-EE3WT25T.js → chunk-IWY2HIFK.js} +1 -1
  66. package/dist/chunks/{chunk-KGJZAYQD.js → chunk-J7OBATRN.js} +1 -1
  67. package/dist/chunks/{chunk-NXZS5PEW.js → chunk-JGUEIW2W.js} +1 -1
  68. package/dist/chunks/chunk-JZ7U7RUK.js +351 -0
  69. package/dist/chunks/{chunk-VIMHSW6J.js → chunk-KJUQCCB5.js} +1 -1
  70. package/dist/chunks/{chunk-BUZQBTV2.js → chunk-KST6OY76.js} +1 -1
  71. package/dist/chunks/{chunk-KDPY2YA3.js → chunk-KZSAFVSY.js} +2 -2
  72. package/dist/chunks/chunk-LD2ZSH3M.js +903 -0
  73. package/dist/chunks/{chunk-RYLSRII6.js → chunk-LE6QPXN6.js} +1 -1
  74. package/dist/chunks/{chunk-TX46YMGI.js → chunk-LIIZI3HY.js} +1 -1
  75. package/dist/chunks/{chunk-3CZPBLB3.js → chunk-MJQ2D2OP.js} +1 -1
  76. package/dist/chunks/{chunk-P7TVR4GY.js → chunk-NHHR4DCF.js} +1 -1
  77. package/dist/chunks/chunk-NW4GW47L.js +4 -0
  78. package/dist/chunks/chunk-OALEJ6FG.js +60 -0
  79. package/dist/chunks/chunk-OIV4DIMB.js +4 -0
  80. package/dist/chunks/{chunk-T73GHMFB.js → chunk-OJ37ZWBG.js} +1 -1
  81. package/dist/chunks/{chunk-7GEBDPTT.js → chunk-OZXMPBUX.js} +1 -1
  82. package/dist/chunks/chunk-PG7452XE.js +4 -0
  83. package/dist/chunks/chunk-PJCUB7YJ.js +4 -0
  84. package/dist/chunks/{chunk-RA2BUYI3.js → chunk-PTS3J4DQ.js} +1 -1
  85. package/dist/chunks/{chunk-2ROGTDM2.js → chunk-PVVEEBUU.js} +1 -1
  86. package/dist/chunks/{chunk-W6AKCEYF.js → chunk-Q7BZLPBU.js} +1 -1
  87. package/dist/chunks/{chunk-SY2HV3V5.js → chunk-QC66ZXPP.js} +1 -1
  88. package/dist/chunks/chunk-QXFWIL4C.js +4 -0
  89. package/dist/chunks/{chunk-NRD57ICT.js → chunk-R2CCD4OF.js} +1 -1
  90. package/dist/chunks/{chunk-R52AVUQB.js → chunk-RG5GP4RB.js} +1 -1
  91. package/dist/chunks/{chunk-IKLTEWA3.js → chunk-RW2F2QNP.js} +1 -1
  92. package/dist/chunks/{chunk-XEBEWR6Y.js → chunk-RWPO3NZ3.js} +1 -1
  93. package/dist/chunks/chunk-SDUS2H3E.js +4 -0
  94. package/dist/chunks/chunk-SIHGKM4E.js +4 -0
  95. package/dist/chunks/{chunk-NNBSSISP.js → chunk-SKHFU5DI.js} +1 -1
  96. package/dist/chunks/{chunk-STUHNKQS.js → chunk-SM45TH22.js} +1 -1
  97. package/dist/chunks/chunk-T54CZKNJ.js +6 -0
  98. package/dist/chunks/chunk-TRXLIL7V.js +4 -0
  99. package/dist/chunks/{chunk-KUDK7GPS.js → chunk-UEEW2R4E.js} +1 -1
  100. package/dist/chunks/chunk-UHXPRU6G.js +10 -0
  101. package/dist/chunks/chunk-UPQVWHZ3.js +4 -0
  102. package/dist/chunks/{chunk-BDLKI2NT.js → chunk-VHX2GHBF.js} +1 -1
  103. package/dist/chunks/chunk-VOAKRJ4R.js +4 -0
  104. package/dist/chunks/{chunk-FP7ML72L.js → chunk-WU7RNAZD.js} +1 -1
  105. package/dist/chunks/chunk-WZC4TDDM.js +6 -0
  106. package/dist/chunks/chunk-X2TKJ7KR.js +11 -0
  107. package/dist/chunks/{chunk-H4QZ2P3Z.js → chunk-X5ND4H4P.js} +1 -1
  108. package/dist/chunks/{chunk-5A6CA5TM.js → chunk-Y3AOGNDT.js} +1 -1
  109. package/dist/chunks/chunk-Y6DGVTKM.js +6 -0
  110. package/dist/chunks/{chunk-LP7T32PW.js → chunk-YAEHSSR4.js} +1 -1
  111. package/dist/chunks/chunk-YWPBE5LP.js +4 -0
  112. package/dist/chunks/chunk-ZAVX7G2M.js +15 -0
  113. package/dist/chunks/chunk-ZD2M73XA.js +19 -0
  114. package/dist/chunks/chunk-ZD4O6NPV.js +4 -0
  115. package/dist/chunks/chunk-ZNAMETPQ.js +4 -0
  116. package/dist/chunks/chunk-ZY6N5LVQ.js +4 -0
  117. package/dist/chunks/chunk-ZYQ4TDTT.js +81 -0
  118. package/dist/chunks/cli-VB2N7HEK.js +55 -0
  119. package/dist/chunks/cloudflare-workers-ai-system-one-YKU742EC.js +4 -0
  120. package/dist/chunks/context-CI2FKEQE.js +4 -0
  121. package/dist/chunks/cost-CZRRSIUF.js +5 -0
  122. package/dist/chunks/dist-QCNQN6DY.js +4 -0
  123. package/dist/chunks/{easter-egg-3d-CZH7AYZ7.js → easter-egg-3d-XR5S2O3T.js} +1 -1
  124. package/dist/chunks/execution-repo-5TLV2NM4.js +4 -0
  125. package/dist/chunks/{executions-BN6OLLVM.js → executions-I3UUIGSL.js} +1 -1
  126. package/dist/chunks/file-Y5G56IUT.js +4 -0
  127. package/dist/chunks/github-copilot-BRU2SRRZ.js +4 -0
  128. package/dist/chunks/google-generative-ai-ZF5QEUZV.js +4 -0
  129. package/dist/chunks/google-vertex-4PJZZI3Y.js +4 -0
  130. package/dist/chunks/init-A6GY656J.js +4 -0
  131. package/dist/chunks/{install-cli-ABBD7DO5.js → install-cli-FALWKQYO.js} +1 -1
  132. package/dist/chunks/{interaction-ask-EE2UPR3Q.js → interaction-ask-O5HGF6CH.js} +1 -1
  133. package/dist/chunks/{interaction-plan-C446T2GZ.js → interaction-plan-JTVDN3BC.js} +1 -1
  134. package/dist/chunks/kimi-coding-ZCIBMDZ6.js +4 -0
  135. package/dist/chunks/{llama-cpp-classify-IA2F2H7A.js → llama-cpp-classify-NRUXAIGQ.js} +3 -3
  136. package/dist/chunks/local-client-stop-RS4AHNF4.js +4 -0
  137. package/dist/chunks/memory-cli-DIT4DQF3.js +11 -0
  138. package/dist/chunks/meta-JQH66YU7.js +4 -0
  139. package/dist/chunks/mistral-conversations-CXHOECUV.js +7 -0
  140. package/dist/chunks/model-resolver-GIBPYRKP.js +4 -0
  141. package/dist/chunks/monitor-Z2HKNY5E.js +4 -0
  142. package/dist/chunks/openai-codex-responses-U6DGMGDK.js +12 -0
  143. package/dist/chunks/openai-completions-PP4XLLOM.js +9 -0
  144. package/dist/chunks/{openai-decisions-P5UX7BWY.js → openai-decisions-JU6QQKEM.js} +1 -1
  145. package/dist/chunks/openai-responses-2SG757TL.js +6 -0
  146. package/dist/chunks/openrouter-images-32M7YZWC.js +4 -0
  147. package/dist/chunks/pi-messages-VSINMXN4.js +10 -0
  148. package/dist/chunks/radius-THYKWV4E.js +4 -0
  149. package/dist/chunks/remote-ops-2WBEFQ3E.js +14 -0
  150. package/dist/chunks/runner-5MKMRTIN.js +4 -0
  151. package/dist/chunks/runtime-DST3H5JP.js +4 -0
  152. package/dist/chunks/schedule-cli-V7Y2BBVY.js +4 -0
  153. package/dist/chunks/slack-R7SEJYMY.js +4 -0
  154. package/dist/chunks/start-ui-http-7K5JOLPU.js +43 -0
  155. package/dist/chunks/subagent-Z5IQ4L54.js +4 -0
  156. package/dist/chunks/tool-shims-YCXZWTST.js +4 -0
  157. package/dist/chunks/typesafe-system-one-M2DABJSZ.js +4 -0
  158. package/dist/chunks/ui-board-HQIE4RZG.js +5 -0
  159. package/dist/chunks/ui-decision-YBZDS4YW.js +4 -0
  160. package/dist/chunks/{ui-file-6PLXHSTB.js → ui-file-SRD4ILBS.js} +1 -1
  161. package/dist/chunks/ui-view-Z25MTZT7.js +4 -0
  162. package/dist/chunks/virtual-modules-H4DXPJZB.js +4 -0
  163. package/dist/chunks/{waitpoint-W5M3BE55.js → waitpoint-M6JZBSLT.js} +1 -1
  164. package/dist/chunks/workers-SQ2R32TK.js +4 -0
  165. package/dist/client-bundle/client.mjs +229 -62
  166. package/dist/client-bundle/manifest.json +2 -2
  167. package/dist/core/pi-sdk.js +1 -1
  168. package/dist/domain/auth/cc-auth-cli.js +1 -1
  169. package/dist/domain/mcp/bundled-server.js +1 -1
  170. package/dist/domain/mcp/feishu/client.js +1 -1
  171. package/dist/entry/app.js +138 -556
  172. package/dist/entry/browser-cli.js +1 -1
  173. package/dist/entry/cli.js +1 -1
  174. package/dist/entry/cortex-cli.js +1 -1
  175. package/dist/entry/daemon.js +3 -3
  176. package/dist/entry/hook-cli.js +1 -1
  177. package/dist/entry/production-app-bootstrap.js +1 -1
  178. package/dist/entry/production-evidence-export-cli.js +1 -1
  179. package/dist/entry/signal-cli.js +1 -1
  180. package/dist/tui/index.js +1 -1
  181. package/package.json +1 -1
  182. package/vendor/pi/CHANGELOG.md +330 -0
  183. package/vendor/pi/dist/codemode-worker.js +2 -0
  184. package/vendor/pi/dist/core/export-html/ansi-to-html.js +57 -20
  185. package/vendor/pi/dist/core/export-html/template.css +9 -0
  186. package/vendor/pi/dist/core/export-html/template.js +166 -46
  187. package/vendor/pi/dist/core/export-html/tool-renderer.js +5 -3
  188. package/vendor/pi/dist/core/extensions/loader.js +1 -1
  189. package/vendor/pi/dist/extensions/codemode/execute.js +15 -13
  190. package/vendor/pi/dist/modes/interactive/theme/theme.js +36 -23
  191. package/vendor/pi/dist/utils/image-resize-worker.js +1 -1
  192. package/vendor/pi/dist/utils/image-resize.js +1 -1
  193. package/vendor/pi/docs/cli.md +35 -12
  194. package/vendor/pi/docs/custom-provider.md +2 -0
  195. package/vendor/pi/docs/environment-variables.md +2 -0
  196. package/vendor/pi/docs/extensions.md +3192 -225
  197. package/vendor/pi/docs/keybindings.md +2 -2
  198. package/vendor/pi/docs/llama-cpp.md +27 -19
  199. package/vendor/pi/docs/mcp.md +6 -4
  200. package/vendor/pi/docs/message-types.md +1 -1
  201. package/vendor/pi/docs/models-configuration.md +9 -3
  202. package/vendor/pi/docs/models.md +2 -1
  203. package/vendor/pi/docs/nvidia-rtx-llama-cpp.md +5 -5
  204. package/vendor/pi/docs/packages.md +24 -0
  205. package/vendor/pi/docs/prompt-templates.md +1 -1
  206. package/vendor/pi/docs/providers.md +4 -2
  207. package/vendor/pi/docs/quickstart.md +7 -3
  208. package/vendor/pi/docs/rpc-commands.md +1 -1
  209. package/vendor/pi/docs/rpc.md +4 -2
  210. package/vendor/pi/docs/sessions.md +17 -3
  211. package/vendor/pi/docs/settings.md +6 -5
  212. package/vendor/pi/docs/slash-commands.md +3 -2
  213. package/vendor/pi/docs/terminal-setup.md +3 -1
  214. package/vendor/pi/docs/tmux.md +6 -0
  215. package/vendor/pi/docs/tui.md +4 -0
  216. package/vendor/pi/docs/windows.md +27 -0
  217. package/vendor/pi/examples/extensions/README.md +2 -1
  218. package/vendor/pi/examples/extensions/custom-provider-anthropic/index.ts +27 -31
  219. package/vendor/pi/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  220. package/vendor/pi/examples/extensions/custom-provider-anthropic/package.json +1 -1
  221. package/vendor/pi/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  222. package/vendor/pi/examples/extensions/debug-provider.ts +2 -2
  223. package/vendor/pi/examples/extensions/gondolin/index.ts +4 -7
  224. package/vendor/pi/examples/extensions/gondolin/package-lock.json +19 -29
  225. package/vendor/pi/examples/extensions/gondolin/package.json +2 -2
  226. package/vendor/pi/examples/extensions/plan-mode/index.ts +23 -13
  227. package/vendor/pi/examples/extensions/plan-mode/utils.ts +42 -16
  228. package/vendor/pi/examples/extensions/preset.ts +2 -0
  229. package/vendor/pi/examples/extensions/reload-runtime.ts +17 -5
  230. package/vendor/pi/examples/extensions/subagent/README.md +14 -11
  231. package/vendor/pi/examples/extensions/subagent/index.ts +392 -171
  232. package/vendor/pi/examples/extensions/todo.ts +7 -0
  233. package/vendor/pi/examples/extensions/tools.ts +2 -0
  234. package/vendor/pi/examples/extensions/with-deps/package-lock.json +2 -2
  235. package/vendor/pi/examples/extensions/with-deps/package.json +1 -1
  236. package/vendor/pi/examples/tsconfig.json +208 -0
  237. package/vendor/pi/package.json +15 -16
  238. package/vendor/pi/schemas/models.schema.json +66 -37
  239. package/vendor/pi/schemas/settings.schema.json +18 -1
  240. package/vendor/pi-ai/bedrock.js +1 -1
  241. package/vendor/pi-ai/oauth-load.js +1 -1
  242. package/web/dist/assets/{board-math-css-BgIyUG-C.js → board-math-css-DKX6FcUS.js} +1 -1
  243. package/web/dist/assets/index-D11wi0uG.js +540 -0
  244. package/web/dist/assets/index-JedYumhY.css +1 -0
  245. package/web/dist/assets/{index-C2eMpcuI.js → index-jl30Gy8P.js} +1 -1
  246. package/web/dist/index.html +2 -2
  247. package/dist/chunks/anthropic-messages-M732OMEE.js +0 -8
  248. package/dist/chunks/azure-openai-responses-RAKTV6JY.js +0 -4
  249. package/dist/chunks/bedrock-converse-stream-WNUGNZ27.js +0 -62
  250. package/dist/chunks/child-runner-MO5RT6FH.js +0 -4
  251. package/dist/chunks/chunk-3CPIMAYX.js +0 -30
  252. package/dist/chunks/chunk-3ORG56I5.js +0 -8
  253. package/dist/chunks/chunk-4EX2JJWB.js +0 -4
  254. package/dist/chunks/chunk-5DF5WJNM.js +0 -60
  255. package/dist/chunks/chunk-7GAYFN52.js +0 -18
  256. package/dist/chunks/chunk-AVXDF7AG.js +0 -4
  257. package/dist/chunks/chunk-BJGYGEZO.js +0 -6
  258. package/dist/chunks/chunk-BZDIAI5M.js +0 -125
  259. package/dist/chunks/chunk-CK3P345X.js +0 -133
  260. package/dist/chunks/chunk-CVC66CFV.js +0 -33
  261. package/dist/chunks/chunk-ETIBCA2S.js +0 -4
  262. package/dist/chunks/chunk-FF7UELTU.js +0 -4
  263. package/dist/chunks/chunk-FX6MOGLR.js +0 -11
  264. package/dist/chunks/chunk-G2V65UBA.js +0 -4
  265. package/dist/chunks/chunk-HGPBHTVD.js +0 -6
  266. package/dist/chunks/chunk-IYVZHGUQ.js +0 -5
  267. package/dist/chunks/chunk-JJDEQ6N2.js +0 -4
  268. package/dist/chunks/chunk-KDYEGGMW.js +0 -4
  269. package/dist/chunks/chunk-L6VCIGWS.js +0 -11
  270. package/dist/chunks/chunk-LACGULCN.js +0 -10
  271. package/dist/chunks/chunk-LAWOWPZX.js +0 -363
  272. package/dist/chunks/chunk-NNTQUHLO.js +0 -877
  273. package/dist/chunks/chunk-OE4KH3NJ.js +0 -4
  274. package/dist/chunks/chunk-OSEIQ7SS.js +0 -4
  275. package/dist/chunks/chunk-PZMGBKUR.js +0 -13
  276. package/dist/chunks/chunk-QBKCAIJG.js +0 -4
  277. package/dist/chunks/chunk-QMSSIDRQ.js +0 -70
  278. package/dist/chunks/chunk-QUUEQRIT.js +0 -4
  279. package/dist/chunks/chunk-RA6HKFBV.js +0 -4
  280. package/dist/chunks/chunk-RDW6FRF5.js +0 -4
  281. package/dist/chunks/chunk-RF4JLYBX.js +0 -6
  282. package/dist/chunks/chunk-SFX7V5O2.js +0 -10
  283. package/dist/chunks/chunk-SKHLZ6XY.js +0 -9
  284. package/dist/chunks/chunk-STCNHXPJ.js +0 -6
  285. package/dist/chunks/chunk-UT6DGZDO.js +0 -4
  286. package/dist/chunks/chunk-VBN2JSER.js +0 -5
  287. package/dist/chunks/chunk-VK5J556O.js +0 -4
  288. package/dist/chunks/chunk-VPVSKJGX.js +0 -6
  289. package/dist/chunks/chunk-VQUPKMDR.js +0 -4
  290. package/dist/chunks/chunk-WEZWKMYU.js +0 -4
  291. package/dist/chunks/chunk-XYSXL3KX.js +0 -4
  292. package/dist/chunks/chunk-Y3GFB5XM.js +0 -8
  293. package/dist/chunks/chunk-YAAKL3QS.js +0 -80
  294. package/dist/chunks/chunk-YB5LUJHS.js +0 -65
  295. package/dist/chunks/chunk-YKKEI5GI.js +0 -4
  296. package/dist/chunks/chunk-Z24SBRJK.js +0 -4
  297. package/dist/chunks/cli-5DBTRMHU.js +0 -53
  298. package/dist/chunks/cloudflare-workers-ai-system-one-32JCFHI3.js +0 -4
  299. package/dist/chunks/context-GQKWKFRM.js +0 -4
  300. package/dist/chunks/cost-OOO32GLC.js +0 -5
  301. package/dist/chunks/dist-V5FRMUFH.js +0 -4
  302. package/dist/chunks/execution-repo-XXL4FXC6.js +0 -4
  303. package/dist/chunks/file-H572PL2Z.js +0 -4
  304. package/dist/chunks/github-copilot-HAI2DA62.js +0 -4
  305. package/dist/chunks/google-generative-ai-2G4ITOZL.js +0 -4
  306. package/dist/chunks/google-vertex-PACHCMRZ.js +0 -4
  307. package/dist/chunks/init-75F4V7SK.js +0 -4
  308. package/dist/chunks/kimi-coding-HMJRKCPA.js +0 -4
  309. package/dist/chunks/local-client-stop-5YOLXGYT.js +0 -4
  310. package/dist/chunks/memory-cli-5SSF6YJM.js +0 -11
  311. package/dist/chunks/meta-KY3LNFV2.js +0 -4
  312. package/dist/chunks/mistral-conversations-VHP63CDS.js +0 -7
  313. package/dist/chunks/model-resolver-FVJNZ6NA.js +0 -4
  314. package/dist/chunks/openai-codex-responses-EHJ4AZBE.js +0 -12
  315. package/dist/chunks/openai-completions-CRAGQFCE.js +0 -9
  316. package/dist/chunks/openai-responses-IZ22NVQ7.js +0 -6
  317. package/dist/chunks/openrouter-images-W2JAMSRH.js +0 -4
  318. package/dist/chunks/pi-messages-MJEEQU2R.js +0 -10
  319. package/dist/chunks/radius-ZM7ZRMXF.js +0 -4
  320. package/dist/chunks/remote-ops-O5CR4RGA.js +0 -14
  321. package/dist/chunks/runner-S6R3US24.js +0 -4
  322. package/dist/chunks/runtime-6YLTA2ZD.js +0 -4
  323. package/dist/chunks/schedule-cli-4T4YC5V5.js +0 -4
  324. package/dist/chunks/slack-2CGM4SMY.js +0 -4
  325. package/dist/chunks/start-ui-http-3D7QNHGB.js +0 -43
  326. package/dist/chunks/subagent-OZGUOV3J.js +0 -4
  327. package/dist/chunks/tool-shims-IA2WELXJ.js +0 -4
  328. package/dist/chunks/typesafe-system-one-6ULACYD4.js +0 -4
  329. package/dist/chunks/ui-board-H4INJD6C.js +0 -5
  330. package/dist/chunks/ui-decision-6HHNROIT.js +0 -4
  331. package/dist/chunks/ui-view-6MDU4GXY.js +0 -4
  332. package/dist/chunks/virtual-modules-OFI7QKYH.js +0 -4
  333. package/dist/chunks/workers-GTFP75MS.js +0 -4
  334. package/vendor/pi/examples/extensions/sandbox/index.ts +0 -321
  335. package/vendor/pi/examples/extensions/sandbox/package-lock.json +0 -92
  336. package/vendor/pi/examples/extensions/sandbox/package.json +0 -19
  337. package/web/dist/assets/index-9lyu2S6W.css +0 -1
  338. package/web/dist/assets/index-C-hpzey7.js +0 -532
@@ -1,4 +1,4 @@
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{b as _}from"./chunk-QEL6CMLE.js";import{a as x}from"./chunk-IA6IODY3.js";import{A as D,g as T,j as S}from"./chunk-RF4JLYBX.js";import{c as w}from"./chunk-MGYYSX7Y.js";import{q as g}from"./chunk-TX46YMGI.js";import{j as d}from"./chunk-Z24SBRJK.js";function b(e){if(!e||typeof e=="object")return!1;let t=typeof e=="string"?e:String(e);return!(!t.trim()||t==="null"||t==="undefined")}function Q(e,t){return e.some(n=>n.status==="running"&&n.kind==="scheduled"&&n.scheduleTaskId===t)}var E=["interval","daily","weekly","once"],A={sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6},a=class extends Error{field;value;constructor(t,n,r){super(n),this.field=t,this.value=r,this.name="ScheduleSpecError"}},N={s:1e3,m:6e4,h:36e5,d:864e5};function $(e){let t=e?.trim().match(/^(\d+(?:\.\d+)?)(s|m|h|d)$/i);return t?Math.round(parseFloat(t[1])*N[t[2].toLowerCase()]):null}function l(e,t){if(e===void 0||e==="")throw new a(t,`${t} is required (e.g. 30m, 2h, 1d)`);let n=typeof e=="number"?Math.round(e):$(e);if(n===null||!Number.isFinite(n)||n<=0)throw new a(t,`invalid ${t}: '${e}' (use 30s, 5m, 2h, 1d)`,e);return n}function f(e){if(!e)throw new a("time","time is required (HH:MM, 24-hour)");let t=e.trim().match(/^(\d{2}):(\d{2})$/);if(!t||Number(t[1])>23||Number(t[2])>59)throw new a("time",`invalid time: '${e}' (use HH:MM, 24-hour)`,e);return t[0]}function I(e){if(e===void 0||e==="")throw new a("dayOfWeek","dayOfWeek is required (sun..sat or 0-6)");let t=typeof e=="string"?e.trim().toLowerCase():e,n=typeof t=="number"||/^\d+$/.test(t)?Number(t):A[t];if(!Number.isInteger(n)||n<0||n>6)throw new a("dayOfWeek",`invalid dayOfWeek: '${e}' (use sun..sat or 0-6)`,e);return n}function O(e){let t=typeof e=="string"?e.trim():"";if(!b(t))throw new a("message","message must be a non-empty prompt",e);return t}function L(e){return E.includes(e)}var H={interval:e=>({type:"interval",intervalMs:l(e.interval,"interval")}),daily:e=>({type:"daily",time:f(e.time)}),weekly:e=>({type:"weekly",dayOfWeek:I(e.dayOfWeek),time:f(e.time)}),once:e=>({type:"once",delayMs:l(e.delay,"delay")})};function te(e){if(!L(e.type))throw new a("type",`invalid type: '${e.type}' (valid: ${E.join(", ")})`,e.type);let t=H[e.type](e),n=e.preCheck?.trim();return{...t,message:O(e.message),projectId:e.projectId?.trim()||"general",selection:e.selection?{...e.selection}:void 0,...n?{preCheck:n}:{}}}var v=new Set(["memory-index-regen"]),F=["message","projectId","selection","dispatchType","preCheck"],W={interval:["intervalMs"],daily:["time"],weekly:["dayOfWeek","time"],once:["runAt"]};function U(e,t){let n=Object.keys(t);if(n.length===0)throw new a("patch","nothing to update \u2014 provide at least one field");let r=new Set([...F,...W[e]]),s=n.filter(i=>!r.has(i));if(s.length)throw new a("patch",`invalid fields for ${e}: ${s.join(", ")}`,s)}function B(e){if(e.dispatchType&&v.has(e.dispatchType))throw new a("dispatchType",`built-in job dispatch type cannot be scheduled: ${e.dispatchType}`);if("intervalMs"in e&&l(e.intervalMs,"intervalMs"),"dayOfWeek"in e&&I(e.dayOfWeek),"runAt"in e&&!(Number.isFinite(e.runAt)&&e.runAt>0))throw new a("runAt","runAt must be a positive epoch ms",e.runAt)}function M(e,t){U(e,t),B(t);let n={...t};return"message"in t&&(n.message=O(t.message)),"time"in t&&(n.time=f(t.time)),n}function V(e,t){let[n,r]=e.split(":").map(Number),s=new Date(t);return s.setHours(n,r,0,0),s.getTime()<=t&&s.setDate(s.getDate()+1),s.getTime()-t}function z(e,t,n){let[r,s]=t.split(":").map(Number),i=new Date(n);i.setHours(r,s,0,0);let o=(e-i.getDay()+7)%7;return o===0&&i.getTime()<=n&&(o=7),i.setDate(i.getDate()+o),i.getTime()-n}function X(e,t=Date.now()){return e.type==="daily"?V(e.time,t):e.type==="weekly"?z(e.dayOfWeek,e.time,t):e.intervalMs||6e4}function u(e,t=Date.now()){e.type!=="once"&&(e.nextRun=e.isPaused?null:t+X(e,t))}function j(e,t,n,r){let{message:s,projectId:i,preCheck:o,selection:h,...c}=e,y={id:t,message:s,projectId:i,selection:{...r},preCheck:o,createdAt:n};if(c.type==="once")return{...y,type:"once",runAt:n+c.delayMs};let k={...y,...c,lastRun:null,nextRun:null};return u(k,n),k}function ue(e,t,n){if(e===void 0&&t===void 0)return;let r={...e!==void 0?S(e):{},...t!==void 0?{thinking:t}:{}},s=D({request:n},r);if(s.ok===!0)return s.selection;if(s.reason==="invalid-thinking"){let i=r.backend??n?.backend??s.base?.backend,o=(s.allowed??[]).join(", ");throw new a("thinking",`Invalid thinking '${t}' for ${i}. Valid values: ${o}`,t)}throw new a("model",`Cannot use model '${e??""}': ${s.reason}`,e)}function Y(e){let t=e.CORTEX_BACKEND;return t!=="claude"&&t!=="pi"||!e.CORTEX_MODEL?null:{backend:t,provider:e.CORTEX_PROVIDER||null,model:e.CORTEX_MODEL}}function ce(e,t,n=process.env){if(!(!e||!t||!n.CORTEX_SESSION_ID))try{_({backend:t.backend,model:x(t),parent:Y(n)})}catch(r){throw new a("model",r.message,e)}}import*as p from"path";import*as R from"fs";var q=p.join(d,"schedules.json"),K=p.join(d,"channel-registry.json");function C(){return{tasks:[]}}function P(e){try{let t=R.readFileSync(e??K,"utf8"),n=JSON.parse(t),r={};for(let[s,i]of Object.entries(n))r[i]=s;return r}catch{return{}}}function pe(e){return P()[e]??null}function G(e){return function(n){if(typeof n!="object"||n===null||!("tasks"in n))return C();let r=n,s=P(e);for(let i of r.tasks){let o=i;"channel"in o&&!("projectId"in o)?(o.projectId=s[String(o.channel)]??"general",delete o.channel):"projectId"in o&&"channel"in o&&delete o.channel}for(let i of r.tasks){let o=i;delete o.target,delete o.fallback,o.selection&&(o.selection=g(o.selection))}return r}}var m=class{_repo;constructor(t=q,n){this._repo=new w({filePath:t,defaultValue:C,migrate:G(n),sharedFile:!0})}async read(){return this._repo.read()}async addTask(t){await this._repo.mutate(n=>(n.tasks.push(t),{next:n,result:void 0}))}async removeTask(t){return this._repo.mutate(n=>{let r=n.tasks.findIndex(s=>s.id===t);return r===-1?{next:n,result:!1}:(n.tasks.splice(r,1),{next:n,result:!0})})}async updateTask(t,n){return this._repo.mutate(r=>{let s=r.tasks.find(i=>i.id===t);return s?(n(s),{next:r,result:s}):{next:r,result:null}})}async findTask(t){return(await this._repo.read()).tasks.find(r=>r.id===t)||null}async mutate(t){return this._repo.mutate(t)}invalidate(){this._repo.invalidate()}flush(){return this._repo.flush()}},he=new m,ye=new Set(["task-dispatch","task-archive"]);import{randomBytes as J}from"crypto";async function Te(e,t,n={}){let r=j(t,J(4).toString("hex"),Date.now(),t.selection??T()),s=n.idempotencyKey;return s&&(r.idempotencyKey=s),e.mutate(i=>{let o=s?i.tasks.find(h=>h.idempotencyKey===s):void 0;return o?{next:i,result:{task:o,created:!1}}:(i.tasks.push(r),{next:i,result:{task:r,created:!0}})})}function Se(e,t,n){return e.updateTask(t,r=>{Object.assign(r,M(r.type,n)),u(r)})}function _e(e,t){return e.updateTask(t,n=>{if(n.type==="once")throw new Error(`cannot pause once schedule ${t}`);n.isPaused||Object.assign(n,{isPaused:!0,pausedAt:Date.now(),pausedBy:"user",nextRun:null})})}function De(e,t){return e.updateTask(t,n=>{if(n.type==="once")throw new Error(`cannot resume once schedule ${t}`);n.isPaused&&(Object.assign(n,{isPaused:!1,pausedAt:null,pausedBy:null}),u(n))})}export{b as a,Q as b,E as c,a as d,l as e,I as f,L as g,te as h,M as i,X as j,ue as k,ce as l,q as m,pe as n,m as o,he as p,ye as q,Te as r,Se as s,_e as t,De as u};
4
+ import{b as _}from"./chunk-IVZ7QUEG.js";import{a as x}from"./chunk-IA6IODY3.js";import{A as D,g as T,j as S}from"./chunk-Y6DGVTKM.js";import{c as w}from"./chunk-ITGCWQFK.js";import{q as g}from"./chunk-LIIZI3HY.js";import{k as d}from"./chunk-T54CZKNJ.js";function b(e){if(!e||typeof e=="object")return!1;let t=typeof e=="string"?e:String(e);return!(!t.trim()||t==="null"||t==="undefined")}function Q(e,t){return e.some(n=>n.status==="running"&&n.kind==="scheduled"&&n.scheduleTaskId===t)}var E=["interval","daily","weekly","once"],A={sun:0,mon:1,tue:2,wed:3,thu:4,fri:5,sat:6},a=class extends Error{field;value;constructor(t,n,r){super(n),this.field=t,this.value=r,this.name="ScheduleSpecError"}},N={s:1e3,m:6e4,h:36e5,d:864e5};function $(e){let t=e?.trim().match(/^(\d+(?:\.\d+)?)(s|m|h|d)$/i);return t?Math.round(parseFloat(t[1])*N[t[2].toLowerCase()]):null}function l(e,t){if(e===void 0||e==="")throw new a(t,`${t} is required (e.g. 30m, 2h, 1d)`);let n=typeof e=="number"?Math.round(e):$(e);if(n===null||!Number.isFinite(n)||n<=0)throw new a(t,`invalid ${t}: '${e}' (use 30s, 5m, 2h, 1d)`,e);return n}function f(e){if(!e)throw new a("time","time is required (HH:MM, 24-hour)");let t=e.trim().match(/^(\d{2}):(\d{2})$/);if(!t||Number(t[1])>23||Number(t[2])>59)throw new a("time",`invalid time: '${e}' (use HH:MM, 24-hour)`,e);return t[0]}function I(e){if(e===void 0||e==="")throw new a("dayOfWeek","dayOfWeek is required (sun..sat or 0-6)");let t=typeof e=="string"?e.trim().toLowerCase():e,n=typeof t=="number"||/^\d+$/.test(t)?Number(t):A[t];if(!Number.isInteger(n)||n<0||n>6)throw new a("dayOfWeek",`invalid dayOfWeek: '${e}' (use sun..sat or 0-6)`,e);return n}function O(e){let t=typeof e=="string"?e.trim():"";if(!b(t))throw new a("message","message must be a non-empty prompt",e);return t}function L(e){return E.includes(e)}var H={interval:e=>({type:"interval",intervalMs:l(e.interval,"interval")}),daily:e=>({type:"daily",time:f(e.time)}),weekly:e=>({type:"weekly",dayOfWeek:I(e.dayOfWeek),time:f(e.time)}),once:e=>({type:"once",delayMs:l(e.delay,"delay")})};function te(e){if(!L(e.type))throw new a("type",`invalid type: '${e.type}' (valid: ${E.join(", ")})`,e.type);let t=H[e.type](e),n=e.preCheck?.trim();return{...t,message:O(e.message),projectId:e.projectId?.trim()||"general",selection:e.selection?{...e.selection}:void 0,...n?{preCheck:n}:{}}}var v=new Set(["memory-index-regen"]),F=["message","projectId","selection","dispatchType","preCheck"],W={interval:["intervalMs"],daily:["time"],weekly:["dayOfWeek","time"],once:["runAt"]};function U(e,t){let n=Object.keys(t);if(n.length===0)throw new a("patch","nothing to update \u2014 provide at least one field");let r=new Set([...F,...W[e]]),s=n.filter(i=>!r.has(i));if(s.length)throw new a("patch",`invalid fields for ${e}: ${s.join(", ")}`,s)}function B(e){if(e.dispatchType&&v.has(e.dispatchType))throw new a("dispatchType",`built-in job dispatch type cannot be scheduled: ${e.dispatchType}`);if("intervalMs"in e&&l(e.intervalMs,"intervalMs"),"dayOfWeek"in e&&I(e.dayOfWeek),"runAt"in e&&!(Number.isFinite(e.runAt)&&e.runAt>0))throw new a("runAt","runAt must be a positive epoch ms",e.runAt)}function M(e,t){U(e,t),B(t);let n={...t};return"message"in t&&(n.message=O(t.message)),"time"in t&&(n.time=f(t.time)),n}function V(e,t){let[n,r]=e.split(":").map(Number),s=new Date(t);return s.setHours(n,r,0,0),s.getTime()<=t&&s.setDate(s.getDate()+1),s.getTime()-t}function z(e,t,n){let[r,s]=t.split(":").map(Number),i=new Date(n);i.setHours(r,s,0,0);let o=(e-i.getDay()+7)%7;return o===0&&i.getTime()<=n&&(o=7),i.setDate(i.getDate()+o),i.getTime()-n}function X(e,t=Date.now()){return e.type==="daily"?V(e.time,t):e.type==="weekly"?z(e.dayOfWeek,e.time,t):e.intervalMs||6e4}function u(e,t=Date.now()){e.type!=="once"&&(e.nextRun=e.isPaused?null:t+X(e,t))}function j(e,t,n,r){let{message:s,projectId:i,preCheck:o,selection:h,...c}=e,y={id:t,message:s,projectId:i,selection:{...r},preCheck:o,createdAt:n};if(c.type==="once")return{...y,type:"once",runAt:n+c.delayMs};let k={...y,...c,lastRun:null,nextRun:null};return u(k,n),k}function ue(e,t,n){if(e===void 0&&t===void 0)return;let r={...e!==void 0?S(e):{},...t!==void 0?{thinking:t}:{}},s=D({request:n},r);if(s.ok===!0)return s.selection;if(s.reason==="invalid-thinking"){let i=r.backend??n?.backend??s.base?.backend,o=(s.allowed??[]).join(", ");throw new a("thinking",`Invalid thinking '${t}' for ${i}. Valid values: ${o}`,t)}throw new a("model",`Cannot use model '${e??""}': ${s.reason}`,e)}function Y(e){let t=e.CORTEX_BACKEND;return t!=="claude"&&t!=="pi"||!e.CORTEX_MODEL?null:{backend:t,provider:e.CORTEX_PROVIDER||null,model:e.CORTEX_MODEL}}function ce(e,t,n=process.env){if(!(!e||!t||!n.CORTEX_SESSION_ID))try{_({backend:t.backend,model:x(t),parent:Y(n)})}catch(r){throw new a("model",r.message,e)}}import*as p from"path";import*as R from"fs";var q=p.join(d,"schedules.json"),K=p.join(d,"channel-registry.json");function C(){return{tasks:[]}}function P(e){try{let t=R.readFileSync(e??K,"utf8"),n=JSON.parse(t),r={};for(let[s,i]of Object.entries(n))r[i]=s;return r}catch{return{}}}function pe(e){return P()[e]??null}function G(e){return function(n){if(typeof n!="object"||n===null||!("tasks"in n))return C();let r=n,s=P(e);for(let i of r.tasks){let o=i;"channel"in o&&!("projectId"in o)?(o.projectId=s[String(o.channel)]??"general",delete o.channel):"projectId"in o&&"channel"in o&&delete o.channel}for(let i of r.tasks){let o=i;delete o.target,delete o.fallback,o.selection&&(o.selection=g(o.selection))}return r}}var m=class{_repo;constructor(t=q,n){this._repo=new w({filePath:t,defaultValue:C,migrate:G(n),sharedFile:!0})}async read(){return this._repo.read()}async addTask(t){await this._repo.mutate(n=>(n.tasks.push(t),{next:n,result:void 0}))}async removeTask(t){return this._repo.mutate(n=>{let r=n.tasks.findIndex(s=>s.id===t);return r===-1?{next:n,result:!1}:(n.tasks.splice(r,1),{next:n,result:!0})})}async updateTask(t,n){return this._repo.mutate(r=>{let s=r.tasks.find(i=>i.id===t);return s?(n(s),{next:r,result:s}):{next:r,result:null}})}async findTask(t){return(await this._repo.read()).tasks.find(r=>r.id===t)||null}async mutate(t){return this._repo.mutate(t)}invalidate(){this._repo.invalidate()}flush(){return this._repo.flush()}},he=new m,ye=new Set(["task-dispatch","task-archive"]);import{randomBytes as J}from"crypto";async function Te(e,t,n={}){let r=j(t,J(4).toString("hex"),Date.now(),t.selection??T()),s=n.idempotencyKey;return s&&(r.idempotencyKey=s),e.mutate(i=>{let o=s?i.tasks.find(h=>h.idempotencyKey===s):void 0;return o?{next:i,result:{task:o,created:!1}}:(i.tasks.push(r),{next:i,result:{task:r,created:!0}})})}function Se(e,t,n){return e.updateTask(t,r=>{Object.assign(r,M(r.type,n)),u(r)})}function _e(e,t){return e.updateTask(t,n=>{if(n.type==="once")throw new Error(`cannot pause once schedule ${t}`);n.isPaused||Object.assign(n,{isPaused:!0,pausedAt:Date.now(),pausedBy:"user",nextRun:null})})}function De(e,t){return e.updateTask(t,n=>{if(n.type==="once")throw new Error(`cannot resume once schedule ${t}`);n.isPaused&&(Object.assign(n,{isPaused:!1,pausedAt:null,pausedBy:null}),u(n))})}export{b as a,Q as b,E as c,a as d,l as e,I as f,L as g,te as h,M as i,X as j,ue as k,ce as l,q as m,pe as n,m as o,he as p,ye as q,Te as r,Se as s,_e as t,De as u};
@@ -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 K,g as V}from"./chunk-STCNHXPJ.js";import{a as J}from"./chunk-NRD57ICT.js";import{K as t}from"./chunk-W34AK4SK.js";import{d as G}from"./chunk-3CPIMAYX.js";import{e as $}from"./chunk-VBN2JSER.js";import{e as z}from"./chunk-NXZS5PEW.js";import{a as _,j as X}from"./chunk-Z24SBRJK.js";var A=1,q=64*1024,O=200,Yt="other",Ht="custom",Xt="mcp_other",l=t.string().regex(/^[A-Za-z0-9._:/@[\]-]{1,80}$/),o=t.number().int().nonnegative(),u=t.number().nonnegative(),f=t.iso.datetime(),ye=t.string().regex(/^\d{4}-\d{2}-\d{2}$/),x=t.string().max(40),y=t.string().max(300),I={ttftMs:[500,1e3,2e3,5e3,1e4,3e4,6e4],turnDurationS:[5,15,30,60,120,300,600,1800,3600],contextPct:[10,25,50,75,90,100],turnsPerSession:[1,2,5,10,20,50,100],webLoadMs:[200,500,1e3,2e3,5e3,1e4]};function d(e){return t.array(o).length(I[e].length+1)}function $t(e,n){let r=I[e],s=r.findIndex(i=>n<=i);return s===-1?r.length:s}function Kt(e){return new Array(I[e].length+1).fill(0)}var ge=t.object({schema:t.literal(A),installId:t.uuid(),sentAt:f,version:x,channel:t.enum(["release","dev"]),installForm:t.enum(["desktop","npm","other"]),os:t.enum(["linux","darwin","win32","android","other"]),osRelease:t.string().max(20),arch:t.string().max(20),nodeMajor:t.number().int().nullable(),uiLang:t.enum(["en","zh","other"])}),Re=["server","daemon","web","desktop","android"],Le=["uncaughtException","unhandledRejection","childExit","renderError","windowError","panic"],ve=["desktop","android","browser"],we=t.object({type:t.literal("crash"),at:f,component:t.enum(Re),kind:t.enum(Le),errorName:t.string().max(80),message:y,stack:t.string().max(8e3),groupKey:t.string().max(200),uptimeS:u.nullable(),route:t.string().max(80).nullable(),buildStamp:t.string().max(60).nullable(),client:t.enum(ve).nullable(),exit:t.object({code:t.number().int().nullable(),signal:t.string().max(20).nullable(),backoffMs:o}).nullable(),suppressed:o,version:x.optional()}),Ae=t.object({type:t.literal("heartbeat"),at:f,backends:t.array(t.enum(["claude","pi"])).max(2),claudeBilling:t.enum(["plan","api","none"]),piProviders:t.array(l).max(60),projects:o,onlineClients:o,clientPlatforms:t.partialRecord(t.enum(["linux","darwin","win32","other"]),o),activeSessions24h:o,uptimeH:u,settings:t.record(l,t.boolean())}),Oe=["network","permission","npm","disk","timeout","other"],Ie=t.object({type:t.literal("upgrade"),at:f,from:x,to:x,method:t.enum(["auto","prompt","manual"]),stage:t.enum(["installed","failed","confirmed","unconfirmed","version-changed"]),durationS:u.nullable(),failure:t.object({class:t.enum(Oe),message:y}).nullable()}),Me=t.object({type:t.literal("migration_failure"),at:f,migration:l,errorClass:t.enum(["io","parse","permission","other"]),message:y}),ke=["setup_started","server_installed","server_install_failed","init_completed","init_failed","daemon_started","daemon_start_failed"],Ne=["server_init_completed","provider_authed","first_session","first_turn_completed","first_remote_client","first_worker","first_schedule"],je=["existing_install"];var Ce=t.object({type:t.literal("funnel"),at:f,source:t.enum(["desktop-setup","server"]),step:t.enum([...ke,...Ne,...je]),detail:l.nullable()}),De=["auth","rate_limit","network","adapter_crash","timeout","other"],Fe=t.object({backend:t.enum(["claude","pi"]),provider:l,model:l,billing:t.enum(["plan","api"]).nullable(),customApi:l.nullable(),outcomes:t.object({completed:o,failed:o,cancelled:o,rateLimited:o}),failures:t.partialRecord(t.enum(De),o),retries:o,fallbacks:o,ttftMs:d("ttftMs"),durationS:d("turnDurationS"),contextPctAtEnd:d("contextPct"),compactions:t.object({auto:o,manual:o}),tokens:t.object({input:o,output:o,cacheRead:o,cacheWrite:o})}),Ue=["session_created","worker_spawned","subagent_run","board_opened","schedule_created","schedule_fired","waitpoint_created","waitpoint_signaled","browser_session","plan_submitted","plan_approved","plan_rejected","ask_user_asked","ask_user_answered","remote_client_connected"],Pe=["desktop","android","browser","feishu","slack","tui","other"],W=t.object({completed:o,failed:o,cancelled:o}),Be=t.object({type:t.literal("daily"),day:ye,turns:t.array(Fe).max(100),features:t.partialRecord(t.enum(Ue),o),messagesByChannel:t.partialRecord(t.enum(Pe),o),uiOps:t.record(l,o),tools:t.array(t.object({name:l,calls:o,errors:o})).max(200),agent:t.object({userInterrupts:o,superseded:o,turnsPerSession:d("turnsPerSession"),workers:W,subagents:W}),perf:t.object({startups:t.array(t.record(l,u)).max(10),eventLoop:t.object({windows:o,p99MedianMs:u,p99MaxMs:u}),web:t.object({loads:o,ttfbMs:d("webLoadMs"),firstRenderMs:d("webLoadMs"),interactiveMs:d("webLoadMs")}),sseReconnects:o,remoteClientDisconnects:o}),errors:t.object({byModule:t.record(l,o),samples:t.array(t.object({module:l,groupKey:t.string().max(200),message:y,count:o})).max(5)})}),g=t.discriminatedUnion("type",[we,Ae,Ie,Me,Ce,Be]),Z=t.object({envelope:ge,events:t.array(g).min(1).max(O)}),Vt=t.discriminatedUnion("kind",[t.object({kind:t.literal("crash"),crashKind:t.enum(["renderError","windowError","unhandledRejection"]),errorName:t.string().max(200),message:t.string().max(2e3),stack:t.string().max(2e4),route:t.string().max(80).nullable(),buildStamp:t.string().max(60).nullable(),uptimeS:u.nullable()}),t.object({kind:t.literal("native_crash"),component:t.enum(["desktop","android"]),at:f,message:t.string().max(2e3),stack:t.string().max(2e4),appVersion:x}),t.object({kind:t.literal("load"),ttfbMs:u.nullable(),firstRenderMs:u.nullable(),interactiveMs:u.nullable()}),t.object({kind:t.literal("sse_reconnect"),count:t.number().int().min(1).max(1e3)})]),Gt="x-cortex-client",Jt=t.object({enabled:t.boolean(),installId:t.uuid().optional()});import T from"node:path";var R=T.join(X,"telemetry"),M=T.join(R,"install-id"),S=T.join(R,"outbox.jsonl"),k=T.join(R,"state.json"),Ye="rollup-";function Zt(e,n=R){return T.join(n,`${Ye}${e}.json`)}import{randomUUID as He}from"node:crypto";import{mkdirSync as Xe,readFileSync as $e,writeFileSync as Ke}from"node:fs";import Ve from"node:path";var N=new Map,Ge=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Q(e){return typeof e=="string"&&Ge.test(e)}function Je(e){try{let n=$e(e,"utf8").trim();return Q(n)?n.toLowerCase():null}catch{return null}}function ee(e,n){Xe(Ve.dirname(e),{recursive:!0}),Ke(e,`${n}
4
+ import{f as K,h as V}from"./chunk-AXYAZTTN.js";import{a as J}from"./chunk-R2CCD4OF.js";import{K as t}from"./chunk-W34AK4SK.js";import{d as G}from"./chunk-7GGPYU5E.js";import{e as $}from"./chunk-7W7VYUTK.js";import{e as z}from"./chunk-JGUEIW2W.js";import{b as _,k as X}from"./chunk-T54CZKNJ.js";var A=1,q=64*1024,O=200,Yt="other",Ht="custom",Xt="mcp_other",l=t.string().regex(/^[A-Za-z0-9._:/@[\]-]{1,80}$/),o=t.number().int().nonnegative(),u=t.number().nonnegative(),f=t.iso.datetime(),ye=t.string().regex(/^\d{4}-\d{2}-\d{2}$/),x=t.string().max(40),y=t.string().max(300),I={ttftMs:[500,1e3,2e3,5e3,1e4,3e4,6e4],turnDurationS:[5,15,30,60,120,300,600,1800,3600],contextPct:[10,25,50,75,90,100],turnsPerSession:[1,2,5,10,20,50,100],webLoadMs:[200,500,1e3,2e3,5e3,1e4]};function d(e){return t.array(o).length(I[e].length+1)}function $t(e,n){let r=I[e],s=r.findIndex(i=>n<=i);return s===-1?r.length:s}function Kt(e){return new Array(I[e].length+1).fill(0)}var ge=t.object({schema:t.literal(A),installId:t.uuid(),sentAt:f,version:x,channel:t.enum(["release","dev"]),installForm:t.enum(["desktop","npm","other"]),os:t.enum(["linux","darwin","win32","android","other"]),osRelease:t.string().max(20),arch:t.string().max(20),nodeMajor:t.number().int().nullable(),uiLang:t.enum(["en","zh","other"])}),Re=["server","daemon","web","desktop","android"],Le=["uncaughtException","unhandledRejection","childExit","renderError","windowError","panic"],ve=["desktop","android","browser"],we=t.object({type:t.literal("crash"),at:f,component:t.enum(Re),kind:t.enum(Le),errorName:t.string().max(80),message:y,stack:t.string().max(8e3),groupKey:t.string().max(200),uptimeS:u.nullable(),route:t.string().max(80).nullable(),buildStamp:t.string().max(60).nullable(),client:t.enum(ve).nullable(),exit:t.object({code:t.number().int().nullable(),signal:t.string().max(20).nullable(),backoffMs:o}).nullable(),suppressed:o,version:x.optional()}),Ae=t.object({type:t.literal("heartbeat"),at:f,backends:t.array(t.enum(["claude","pi"])).max(2),claudeBilling:t.enum(["plan","api","none"]),piProviders:t.array(l).max(60),projects:o,onlineClients:o,clientPlatforms:t.partialRecord(t.enum(["linux","darwin","win32","other"]),o),activeSessions24h:o,uptimeH:u,settings:t.record(l,t.boolean())}),Oe=["network","permission","npm","disk","timeout","other"],Ie=t.object({type:t.literal("upgrade"),at:f,from:x,to:x,method:t.enum(["auto","prompt","manual"]),stage:t.enum(["installed","failed","confirmed","unconfirmed","version-changed"]),durationS:u.nullable(),failure:t.object({class:t.enum(Oe),message:y}).nullable()}),Me=t.object({type:t.literal("migration_failure"),at:f,migration:l,errorClass:t.enum(["io","parse","permission","other"]),message:y}),ke=["setup_started","server_installed","server_install_failed","init_completed","init_failed","daemon_started","daemon_start_failed"],Ne=["server_init_completed","provider_authed","first_session","first_turn_completed","first_remote_client","first_worker","first_schedule"],je=["existing_install"];var Ce=t.object({type:t.literal("funnel"),at:f,source:t.enum(["desktop-setup","server"]),step:t.enum([...ke,...Ne,...je]),detail:l.nullable()}),De=["auth","rate_limit","network","adapter_crash","timeout","other"],Fe=t.object({backend:t.enum(["claude","pi"]),provider:l,model:l,billing:t.enum(["plan","api"]).nullable(),customApi:l.nullable(),outcomes:t.object({completed:o,failed:o,cancelled:o,rateLimited:o}),failures:t.partialRecord(t.enum(De),o),retries:o,fallbacks:o,ttftMs:d("ttftMs"),durationS:d("turnDurationS"),contextPctAtEnd:d("contextPct"),compactions:t.object({auto:o,manual:o}),tokens:t.object({input:o,output:o,cacheRead:o,cacheWrite:o})}),Ue=["session_created","worker_spawned","subagent_run","board_opened","schedule_created","schedule_fired","waitpoint_created","waitpoint_signaled","browser_session","plan_submitted","plan_approved","plan_rejected","ask_user_asked","ask_user_answered","remote_client_connected"],Pe=["desktop","android","browser","feishu","slack","tui","other"],W=t.object({completed:o,failed:o,cancelled:o}),Be=t.object({type:t.literal("daily"),day:ye,turns:t.array(Fe).max(100),features:t.partialRecord(t.enum(Ue),o),messagesByChannel:t.partialRecord(t.enum(Pe),o),uiOps:t.record(l,o),tools:t.array(t.object({name:l,calls:o,errors:o})).max(200),agent:t.object({userInterrupts:o,superseded:o,turnsPerSession:d("turnsPerSession"),workers:W,subagents:W}),perf:t.object({startups:t.array(t.record(l,u)).max(10),eventLoop:t.object({windows:o,p99MedianMs:u,p99MaxMs:u}),web:t.object({loads:o,ttfbMs:d("webLoadMs"),firstRenderMs:d("webLoadMs"),interactiveMs:d("webLoadMs")}),sseReconnects:o,remoteClientDisconnects:o}),errors:t.object({byModule:t.record(l,o),samples:t.array(t.object({module:l,groupKey:t.string().max(200),message:y,count:o})).max(5)})}),g=t.discriminatedUnion("type",[we,Ae,Ie,Me,Ce,Be]),Z=t.object({envelope:ge,events:t.array(g).min(1).max(O)}),Vt=t.discriminatedUnion("kind",[t.object({kind:t.literal("crash"),crashKind:t.enum(["renderError","windowError","unhandledRejection"]),errorName:t.string().max(200),message:t.string().max(2e3),stack:t.string().max(2e4),route:t.string().max(80).nullable(),buildStamp:t.string().max(60).nullable(),uptimeS:u.nullable()}),t.object({kind:t.literal("native_crash"),component:t.enum(["desktop","android"]),at:f,message:t.string().max(2e3),stack:t.string().max(2e4),appVersion:x}),t.object({kind:t.literal("load"),ttfbMs:u.nullable(),firstRenderMs:u.nullable(),interactiveMs:u.nullable()}),t.object({kind:t.literal("sse_reconnect"),count:t.number().int().min(1).max(1e3)})]),Gt="x-cortex-client",Jt=t.object({enabled:t.boolean(),installId:t.uuid().optional()});import T from"node:path";var R=T.join(X,"telemetry"),M=T.join(R,"install-id"),S=T.join(R,"outbox.jsonl"),k=T.join(R,"state.json"),Ye="rollup-";function Zt(e,n=R){return T.join(n,`${Ye}${e}.json`)}import{randomUUID as He}from"node:crypto";import{mkdirSync as Xe,readFileSync as $e,writeFileSync as Ke}from"node:fs";import Ve from"node:path";var N=new Map,Ge=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Q(e){return typeof e=="string"&&Ge.test(e)}function Je(e){try{let n=$e(e,"utf8").trim();return Q(n)?n.toLowerCase():null}catch{return null}}function ee(e,n){Xe(Ve.dirname(e),{recursive:!0}),Ke(e,`${n}
5
5
  `,{encoding:"utf8",mode:384})}function te(e=M){let n=Je(e),r=n??N.get(e)??He();if(!n)try{ee(e,r)}catch{}return N.set(e,r),r}function on(e,n=M){if(!Q(e))throw new Error("install id must be a UUID");ee(n,e.toLowerCase()),N.set(n,e.toLowerCase())}import{existsSync as qe,statSync as Ze}from"node:fs";import Qe from"node:path";import{readFileSync as ze}from"node:fs";import We from"node:path";var ne=We.join(_,"dist","build-info.json"),j;function oe(e){if(typeof e!="string"||e.trim()==="")return null;try{let n=new URL(e.trim());return n.protocol==="https:"||n.protocol==="http:"?n.toString():null}catch{return null}}function re(e){try{let n=JSON.parse(ze(e,"utf8"));return oe(n.telemetryEndpoint)}catch{return null}}function se(e=process.env,n=ne){let r=oe(e.CORTEX_TELEMETRY_ENDPOINT);return r||(n!==ne?re(n):(j===void 0&&(j=re(n)),j))}function et(e){if(e===void 0)return!1;let n=e.trim().toLowerCase();return n!==""&&n!=="0"&&n!=="false"&&n!=="no"&&n!=="off"}function tt(e){return e.CORTEX_TELEMETRY?.trim()==="0"?"env":et(e.DO_NOT_TRACK)?"do-not-track":e.CORTEX_CONFIG_IMMUTABLE==="1"?"sealed":null}function nt(e){let n=e.env.CORTEX_TELEMETRY?.trim()==="1",r=e.devCheckout?"dev":"release",s=c=>({active:!1,reason:c,channel:r,endpoint:e.endpoint}),i=tt(e.env);return i?s(i):e.settingEnabled?e.devCheckout&&!n?s("dev"):e.endpoint?{active:!0,reason:null,channel:r,endpoint:e.endpoint}:s("no-endpoint"):s("setting")}var ie;function rt(){let e=process.env.CORTEX_REPO;try{return!!e&&Ze(e).isDirectory()}catch{return!1}}function ot(){return ie??=qe(Qe.join(_,"src","entry"))||rt(),ie}function C(e=process.env){return nt({settingEnabled:K().telemetryEnabled,env:e,devCheckout:ot(),endpoint:se(e)})}function h(){return C().active}import{mkdirSync as st,readFileSync as it,writeFileSync as at}from"node:fs";import ct from"node:path";var ae={lastHeartbeatAt:null,lastVersion:null,funnelSent:[],pendingUpgrade:null,funnelBaseline:null};function lt(e){return e==="fresh"||e==="existing"?e:null}function D(e=k){try{let n=JSON.parse(it(e,"utf8"));return{...ae,...n,funnelSent:Array.isArray(n.funnelSent)?n.funnelSent.filter(r=>typeof r=="string"):[],funnelBaseline:lt(n.funnelBaseline)}}catch{return{...ae}}}function ce(e,n=k){let r=e(D(n));try{st(ct.dirname(n),{recursive:!0}),at(n,`${JSON.stringify(r,null,2)}
6
6
  `,"utf8")}catch{}return r}import ut from"node:os";var pt=["linux","darwin","win32","android"];function mt(e=process.env,n=_){return e.CORTEX_NPM_PREFIX?.trim()?"desktop":z(n,"@cortex-agent/server")?"npm":"other"}function dt(e){return pt.includes(e)?e:"other"}function ft(e){return(e.split(".")[0]??"").slice(0,20)}function le(e,n=new Date){return{schema:A,installId:te(),sentAt:n.toISOString(),version:J.slice(0,40),channel:e,installForm:mt(),os:dt(process.platform),osRelease:ft(ut.release()),arch:process.arch.slice(0,20),nodeMajor:Number.parseInt(process.versions.node,10),uiLang:G()}}import{appendFileSync as Et,existsSync as _t,mkdirSync as ht,readFileSync as xt,renameSync as Tt,rmSync as v,statSync as St,writeFileSync as bt}from"node:fs";import yt from"node:path";var ue=2*1024*1024,gt=Math.floor(ue*.75);function F(e){return`${e.slice(0,-6)}.sending.jsonl`}function L(e){try{return xt(e,"utf8").split(`
7
7
  `).filter(n=>n.trim()!=="")}catch{return[]}}function pe(e,n){let r=0,s=e.length;for(;s>0&&r+Buffer.byteLength(e[s-1])+1<=n;)s-=1,r+=Buffer.byteLength(e[s])+1;return e.slice(s)}function U(e,n){if(n.length===0)return void v(e,{force:!0});bt(e,`${n.join(`
@@ -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{a as Ke,b as Je,c as Xe,d as qe,e as ze,f as Ye,g as Ze,h as Ht,i as Qe,j as ti}from"./chunk-P7TVR4GY.js";import{C as si,D as ni,F as ri,G as oi,H as Bt,I as ai,J as ci,K as ui,a as Wt,k as ei,z as ii}from"./chunk-3ORG56I5.js";import{b as je,c as Le,d as Ue,e as Ve}from"./chunk-2VVRTJQN.js";import{e as li,h as hi}from"./chunk-53TQNK7Z.js";import{a as Fe,b as Pe}from"./chunk-2ATTYCRJ.js";import{g as xe}from"./chunk-7GEBDPTT.js";import{b as _e,h as Ce}from"./chunk-KUDK7GPS.js";import{d as Be}from"./chunk-BDLKI2NT.js";import{M as Ge,N as He,P as We}from"./chunk-JJDEQ6N2.js";import{a as Vt,b as Ae,c as Re,d as Oe,g as Gt,l as De,m as Ne}from"./chunk-QUXPMNFQ.js";import{a as di}from"./chunk-PMG4YGDU.js";import{d as Me}from"./chunk-LP7T32PW.js";import{m as Se,r as Te,t as Ee}from"./chunk-BUZQBTV2.js";import{a as ke}from"./chunk-NRD57ICT.js";import{c as It}from"./chunk-AVXDF7AG.js";import{a as Ut,b as bt,c as be,e as c}from"./chunk-3CPIMAYX.js";import{c as we,e as Ie}from"./chunk-VBN2JSER.js";import{a as ht,b as U,d as ve,i as Lt}from"./chunk-Z24SBRJK.js";import{a as jt}from"./chunk-VPVSKJGX.js";import{c as Os,e as lt}from"./chunk-WHC7AYZD.js";var zt=Os((Hr,Ti)=>{"use strict";var qt={to(t,e){return e?`\x1B[${e+1};${t+1}H`:`\x1B[${t+1}G`},move(t,e){let i="";return t<0?i+=`\x1B[${-t}D`:t>0&&(i+=`\x1B[${t}C`),e<0?i+=`\x1B[${-e}A`:e>0&&(i+=`\x1B[${e}B`),i},up:(t=1)=>`\x1B[${t}A`,down:(t=1)=>`\x1B[${t}B`,forward:(t=1)=>`\x1B[${t}C`,backward:(t=1)=>`\x1B[${t}D`,nextLine:(t=1)=>"\x1B[E".repeat(t),prevLine:(t=1)=>"\x1B[F".repeat(t),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},Ks={up:(t=1)=>"\x1B[S".repeat(t),down:(t=1)=>"\x1B[T".repeat(t)},Js={screen:"\x1B[2J",up:(t=1)=>"\x1B[1J".repeat(t),down:(t=1)=>"\x1B[J".repeat(t),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(t){let e="";for(let i=0;i<t;i++)e+=this.line+(i<t-1?qt.up():"");return t&&(e+=qt.left),e}};Ti.exports={cursor:qt,scroll:Ks,erase:Js,beep:"\x07"}});var Ts=lt(jt(),1);import{mkdirSync as yt,writeFileSync as B,copyFileSync as ks,existsSync as L,readFileSync as ge,readdirSync as zn}from"fs";import{randomBytes as Is}from"crypto";import{execSync as ct}from"child_process";import*as d from"path";import*as W from"os";import{createInterface as Yn}from"readline/promises";import{stdin as Mt}from"process";import{existsSync as vn}from"node:fs";import{execSync as wn}from"node:child_process";import*as Ji from"node:path";import{styleText as Yt}from"node:util";import{stdout as Zt,stdin as xi}from"node:process";import*as Y from"node:readline";import Xs from"node:readline";var pi=(()=>{let t=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return e=>{let i=0;for(t.lastIndex=0;t.test(e);)i+=1;return e.length-i}})(),mi=t=>t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510,fi=t=>t===8987||t===9001||t>=12272&&t<=12287||t>=12289&&t<=12350||t>=12441&&t<=12543||t>=12549&&t<=12591||t>=12593&&t<=12686||t>=12688&&t<=12771||t>=12783&&t<=12830||t>=12832&&t<=12871||t>=12880&&t<=19903||t>=65040&&t<=65049||t>=65072&&t<=65106||t>=65108&&t<=65126||t>=65128&&t<=65131||t>=127488&&t<=127490||t>=127504&&t<=127547||t>=127552&&t<=127560||t>=131072&&t<=196605||t>=196608&&t<=262141;var Ds=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Ns=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,gi=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Fs=/\t{1,1000}/y,$i=new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*","yu"),Ps=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Ms=new RegExp("\\p{M}+","gu"),js={limit:1/0,ellipsis:""},yi=(t,e={},i={})=>{let s=e.limit??1/0,n=e.ellipsis??"",r=e?.ellipsisWidth??(n?yi(n,js,i).width:0),o=0,a=i.controlWidth??0,l=i.tabWidth??8,h=i.emojiWidth??2,f=2,p=i.regularWidth??1,g=i.wideWidth??f,$=[[Ps,p],[Ds,o],[Ns,a],[Fs,l],[$i,h],[gi,g]],m=0,w=0,C=t.length,O=0,M=!1,A=C,j=Math.max(0,s-r),S=0,R=0,k=0,x=0;t:for(;;){if(R>S||w>=C&&w>m){let D=t.slice(S,R)||t.slice(m,w);O=0;for(let K of D.replaceAll(Ms,"")){let F=K.codePointAt(0)||0;if(mi(F)?x=f:fi(F)?x=g:x=p,k+x>j&&(A=Math.min(A,Math.max(S,m)+O)),k+x>s){M=!0;break t}O+=K.length,k+=x}S=R=0}if(w>=C)break t;for(let D=0,K=$.length;D<K;D++){let[F,vt]=$[D];if(F.lastIndex=w,F.test(t)){if(O=F===gi?pi(t.slice(w,F.lastIndex)):F===$i?1:F.lastIndex-w,x=O*vt,k+x>j&&(A=Math.min(A,w+Math.floor((j-k)/vt))),k+x>s){M=!0;break t}k+=x,S=m,R=w,w=m=F.lastIndex;continue t}}w+=1}return{width:M?j:k,index:M?A:C,truncated:M,ellipsed:M&&s>=r}},vi=yi;var Ls={limit:1/0,ellipsis:"",ellipsisWidth:0},Us=(t,e={})=>vi(t,Ls,e).width,P=Us;var St="\x1B",_i="\x9B",Vs=39,Jt="\x07",Ci="[",Gs="]",ki="m",Xt=`${Gs}8;;`,wi=new RegExp(`(?:\\${Ci}(?<code>\\d+)m|\\${Xt}(?<uri>.*)${Jt})`,"y"),Ii=t=>{if(t>=30&&t<=37||t>=90&&t<=97)return 39;if(t>=40&&t<=47||t>=100&&t<=107)return 49;if(t===1||t===2)return 22;if(t===3)return 23;if(t===4)return 24;if(t===7)return 27;if(t===8)return 28;if(t===9)return 29;if(t===0)return 0},bi=t=>`${St}${Ci}${t}${ki}`,Si=t=>`${St}${Xt}${t}${Jt}`,Kt=(t,e,i)=>{let s=e[Symbol.iterator](),n=!1,r=!1,o=t.at(-1),a=o===void 0?0:P(o),l=s.next(),h=s.next(),f=0;for(;!l.done;){let p=l.value,g=P(p);a+g<=i?t[t.length-1]+=p:(t.push(p),a=0),(p===St||p===_i)&&(n=!0,r=e.startsWith(Xt,f+1)),n?r?p===Jt&&(n=!1,r=!1):p===ki&&(n=!1):(a+=g,a===i&&!h.done&&(t.push(""),a=0)),l=h,h=s.next(),f+=p.length}o=t.at(-1),!a&&o!==void 0&&o.length&&t.length>1&&(t[t.length-2]+=t.pop())},Hs=t=>{let e=t.split(" "),i=e.length;for(;i&&!P(e[i-1]);)i--;return i===e.length?t:e.slice(0,i).join(" ")+e.slice(i).join("")},Ws=(t,e,i={})=>{if(i.trim!==!1&&t.trim()==="")return"";let s="",n,r,o=t.split(" "),a=[""],l=0;for(let p=0;p<o.length;p++){let g=o[p];if(i.trim!==!1){let m=a.at(-1)??"",w=m.trimStart();m.length!==w.length&&(a[a.length-1]=w,l=P(w))}p!==0&&(l>=e&&(i.wordWrap===!1||i.trim===!1)&&(a.push(""),l=0),(l||i.trim===!1)&&(a[a.length-1]+=" ",l++));let $=P(g);if(i.hard&&$>e){let m=e-l,w=1+Math.floor(($-m-1)/e);Math.floor(($-1)/e)<w&&a.push(""),Kt(a,g,e),l=P(a.at(-1)??"");continue}if(l+$>e&&l&&$){if(i.wordWrap===!1&&l<e){Kt(a,g,e),l=P(a.at(-1)??"");continue}a.push(""),l=0}if(l+$>e&&i.wordWrap===!1){Kt(a,g,e),l=P(a.at(-1)??"");continue}a[a.length-1]+=g,l+=$}i.trim!==!1&&(a=a.map(p=>Hs(p)));let h=a.join(`
4
+ import{a as Ke,b as Je,c as Xe,d as qe,e as ze,f as Ye,g as Ze,h as Ht,i as Qe,j as ti}from"./chunk-NHHR4DCF.js";import{f as ii,i as si,j as ni,l as ri,m as oi,n as Bt,o as ai,p as ci,q as ui}from"./chunk-G264APQN.js";import{a as Wt,k as ei}from"./chunk-5DVSAXOI.js";import{b as je,c as Le,d as Ue,e as Ve}from"./chunk-HVN37UXD.js";import{e as li,h as hi}from"./chunk-IGZWZP7Z.js";import{a as Fe,b as Pe}from"./chunk-4HRI75GU.js";import{g as xe}from"./chunk-OZXMPBUX.js";import{b as _e,h as Ce}from"./chunk-UEEW2R4E.js";import{g as Be}from"./chunk-VHX2GHBF.js";import{M as Ge,N as He,P as We}from"./chunk-C6YVF7EI.js";import{a as Vt,b as Ae,c as Re,d as Oe,g as Gt,l as De,m as Ne}from"./chunk-BVEDNESB.js";import{a as di}from"./chunk-PMG4YGDU.js";import{d as Me}from"./chunk-YAEHSSR4.js";import{m as Se,r as Te,t as Ee}from"./chunk-KST6OY76.js";import{a as ke}from"./chunk-R2CCD4OF.js";import{c as It}from"./chunk-TRXLIL7V.js";import{a as Ut,b as bt,c as be,e as c}from"./chunk-7GGPYU5E.js";import{c as we,e as Ie}from"./chunk-7W7VYUTK.js";import{a as jt,b as ht,c as U,e as ve,j as Lt}from"./chunk-T54CZKNJ.js";import{c as Os,e as lt}from"./chunk-WHC7AYZD.js";var zt=Os((Hr,Ti)=>{"use strict";var qt={to(t,e){return e?`\x1B[${e+1};${t+1}H`:`\x1B[${t+1}G`},move(t,e){let i="";return t<0?i+=`\x1B[${-t}D`:t>0&&(i+=`\x1B[${t}C`),e<0?i+=`\x1B[${-e}A`:e>0&&(i+=`\x1B[${e}B`),i},up:(t=1)=>`\x1B[${t}A`,down:(t=1)=>`\x1B[${t}B`,forward:(t=1)=>`\x1B[${t}C`,backward:(t=1)=>`\x1B[${t}D`,nextLine:(t=1)=>"\x1B[E".repeat(t),prevLine:(t=1)=>"\x1B[F".repeat(t),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},Ks={up:(t=1)=>"\x1B[S".repeat(t),down:(t=1)=>"\x1B[T".repeat(t)},Js={screen:"\x1B[2J",up:(t=1)=>"\x1B[1J".repeat(t),down:(t=1)=>"\x1B[J".repeat(t),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(t){let e="";for(let i=0;i<t;i++)e+=this.line+(i<t-1?qt.up():"");return t&&(e+=qt.left),e}};Ti.exports={cursor:qt,scroll:Ks,erase:Js,beep:"\x07"}});var Ts=lt(jt(),1);import{mkdirSync as yt,writeFileSync as B,copyFileSync as ks,existsSync as L,readFileSync as ge,readdirSync as zn}from"fs";import{randomBytes as Is}from"crypto";import{execSync as ct}from"child_process";import*as d from"path";import*as W from"os";import{createInterface as Yn}from"readline/promises";import{stdin as Mt}from"process";import{existsSync as vn}from"node:fs";import{execSync as wn}from"node:child_process";import*as Ji from"node:path";import{styleText as Yt}from"node:util";import{stdout as Zt,stdin as xi}from"node:process";import*as Y from"node:readline";import Xs from"node:readline";var pi=(()=>{let t=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return e=>{let i=0;for(t.lastIndex=0;t.test(e);)i+=1;return e.length-i}})(),mi=t=>t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510,fi=t=>t===8987||t===9001||t>=12272&&t<=12287||t>=12289&&t<=12350||t>=12441&&t<=12543||t>=12549&&t<=12591||t>=12593&&t<=12686||t>=12688&&t<=12771||t>=12783&&t<=12830||t>=12832&&t<=12871||t>=12880&&t<=19903||t>=65040&&t<=65049||t>=65072&&t<=65106||t>=65108&&t<=65126||t>=65128&&t<=65131||t>=127488&&t<=127490||t>=127504&&t<=127547||t>=127552&&t<=127560||t>=131072&&t<=196605||t>=196608&&t<=262141;var Ds=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,Ns=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,gi=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,Fs=/\t{1,1000}/y,$i=new RegExp("[\\u{1F1E6}-\\u{1F1FF}]{2}|\\u{1F3F4}[\\u{E0061}-\\u{E007A}]{2}[\\u{E0030}-\\u{E0039}\\u{E0061}-\\u{E007A}]{1,3}\\u{E007F}|(?:\\p{Emoji}\\uFE0F\\u20E3?|\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation})(?:\\u200D(?:\\p{Emoji_Modifier_Base}\\p{Emoji_Modifier}?|\\p{Emoji_Presentation}|\\p{Emoji}\\uFE0F\\u20E3?))*","yu"),Ps=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,Ms=new RegExp("\\p{M}+","gu"),js={limit:1/0,ellipsis:""},yi=(t,e={},i={})=>{let s=e.limit??1/0,n=e.ellipsis??"",r=e?.ellipsisWidth??(n?yi(n,js,i).width:0),o=0,a=i.controlWidth??0,l=i.tabWidth??8,h=i.emojiWidth??2,f=2,p=i.regularWidth??1,g=i.wideWidth??f,$=[[Ps,p],[Ds,o],[Ns,a],[Fs,l],[$i,h],[gi,g]],m=0,w=0,C=t.length,O=0,M=!1,A=C,j=Math.max(0,s-r),S=0,R=0,k=0,x=0;t:for(;;){if(R>S||w>=C&&w>m){let D=t.slice(S,R)||t.slice(m,w);O=0;for(let K of D.replaceAll(Ms,"")){let F=K.codePointAt(0)||0;if(mi(F)?x=f:fi(F)?x=g:x=p,k+x>j&&(A=Math.min(A,Math.max(S,m)+O)),k+x>s){M=!0;break t}O+=K.length,k+=x}S=R=0}if(w>=C)break t;for(let D=0,K=$.length;D<K;D++){let[F,vt]=$[D];if(F.lastIndex=w,F.test(t)){if(O=F===gi?pi(t.slice(w,F.lastIndex)):F===$i?1:F.lastIndex-w,x=O*vt,k+x>j&&(A=Math.min(A,w+Math.floor((j-k)/vt))),k+x>s){M=!0;break t}k+=x,S=m,R=w,w=m=F.lastIndex;continue t}}w+=1}return{width:M?j:k,index:M?A:C,truncated:M,ellipsed:M&&s>=r}},vi=yi;var Ls={limit:1/0,ellipsis:"",ellipsisWidth:0},Us=(t,e={})=>vi(t,Ls,e).width,P=Us;var St="\x1B",_i="\x9B",Vs=39,Jt="\x07",Ci="[",Gs="]",ki="m",Xt=`${Gs}8;;`,wi=new RegExp(`(?:\\${Ci}(?<code>\\d+)m|\\${Xt}(?<uri>.*)${Jt})`,"y"),Ii=t=>{if(t>=30&&t<=37||t>=90&&t<=97)return 39;if(t>=40&&t<=47||t>=100&&t<=107)return 49;if(t===1||t===2)return 22;if(t===3)return 23;if(t===4)return 24;if(t===7)return 27;if(t===8)return 28;if(t===9)return 29;if(t===0)return 0},bi=t=>`${St}${Ci}${t}${ki}`,Si=t=>`${St}${Xt}${t}${Jt}`,Kt=(t,e,i)=>{let s=e[Symbol.iterator](),n=!1,r=!1,o=t.at(-1),a=o===void 0?0:P(o),l=s.next(),h=s.next(),f=0;for(;!l.done;){let p=l.value,g=P(p);a+g<=i?t[t.length-1]+=p:(t.push(p),a=0),(p===St||p===_i)&&(n=!0,r=e.startsWith(Xt,f+1)),n?r?p===Jt&&(n=!1,r=!1):p===ki&&(n=!1):(a+=g,a===i&&!h.done&&(t.push(""),a=0)),l=h,h=s.next(),f+=p.length}o=t.at(-1),!a&&o!==void 0&&o.length&&t.length>1&&(t[t.length-2]+=t.pop())},Hs=t=>{let e=t.split(" "),i=e.length;for(;i&&!P(e[i-1]);)i--;return i===e.length?t:e.slice(0,i).join(" ")+e.slice(i).join("")},Ws=(t,e,i={})=>{if(i.trim!==!1&&t.trim()==="")return"";let s="",n,r,o=t.split(" "),a=[""],l=0;for(let p=0;p<o.length;p++){let g=o[p];if(i.trim!==!1){let m=a.at(-1)??"",w=m.trimStart();m.length!==w.length&&(a[a.length-1]=w,l=P(w))}p!==0&&(l>=e&&(i.wordWrap===!1||i.trim===!1)&&(a.push(""),l=0),(l||i.trim===!1)&&(a[a.length-1]+=" ",l++));let $=P(g);if(i.hard&&$>e){let m=e-l,w=1+Math.floor(($-m-1)/e);Math.floor(($-1)/e)<w&&a.push(""),Kt(a,g,e),l=P(a.at(-1)??"");continue}if(l+$>e&&l&&$){if(i.wordWrap===!1&&l<e){Kt(a,g,e),l=P(a.at(-1)??"");continue}a.push(""),l=0}if(l+$>e&&i.wordWrap===!1){Kt(a,g,e),l=P(a.at(-1)??"");continue}a[a.length-1]+=g,l+=$}i.trim!==!1&&(a=a.map(p=>Hs(p)));let h=a.join(`
5
5
  `),f=!1;for(let p=0;p<h.length;p++){let g=h[p];if(s+=g,f)f=!1;else if(f=g>="\uD800"&&g<="\uDBFF",f)continue;if(g===St||g===_i){wi.lastIndex=p+1;let m=wi.exec(h)?.groups;if(m?.code!==void 0){let w=Number.parseFloat(m.code);n=w===Vs?void 0:w}else m?.uri!==void 0&&(r=m.uri.length===0?void 0:m.uri)}if(h[p+1]===`
6
6
  `){r&&(s+=Si(""));let $=n?Ii(n):void 0;n&&$&&(s+=bi($))}else g===`
7
7
  `&&(n&&Ii(n)&&(s+=bi(n)),r&&(s+=Si(r)))}return s},Bs=/\r?\n/;function J(t,e,i){return String(t).normalize().split(Bs).map(s=>Ws(s,e,i)).join(`
@@ -91,7 +91,7 @@ ${l}${o}
91
91
  ${a}`:""}`}default:{let o=e?`${u("cyan",y)} `:"",a=e?u("cyan",H):"";return`${i}${o}${n}
92
92
  ${a}
93
93
  `}}}}).prompt();var Xi=Fe;function qi(){return process.platform==="win32"?"https://git-scm.com/download/win (Git for Windows, including Git Bash)":process.platform==="darwin"?"xcode-select --install (or brew install git if you use Homebrew)":"Install Git via your package manager or https://git-scm.com/downloads"}function ne(){return Xi()?!0:process.platform!=="win32"?(v.info(c("init.git.optional")),!1):(v.warn(c("init.git.required")),v.info(c("init.git.manualHint",{hint:qi()})),!1)}function zi(t){if(!vn(Ji.join(t,".git")))try{wn("git init",{cwd:t,stdio:"pipe"})}catch(e){v.warn(c("init.git.initFailed",{message:e instanceof Error?e.message:String(e)}))}}import{randomUUID as Sn}from"node:crypto";import{execSync as In}from"node:child_process";function re(t){if(rt(t))throw new b(c("init.auth.cancelled"),130);return t}function bn(t){let e=i=>process.stderr.write(`${i}
94
- `);if(t.kind==="auth_url"){e(c("init.auth.openBrowser",{url:t.url}));return}if(t.kind==="device_code"){e(c("init.auth.deviceCode",{url:t.verificationUri,code:t.userCode}));return}if(e(t.message),t.kind==="info")for(let i of t.links??[])e(i.url)}function Yi(){let t=process.stderr;return{async select(e,i,s){if(!i.length)throw new b(c("init.auth.noCapabilities"));return re(await st({message:e,options:i,output:t,signal:s}))},async secret(e,i){return re(await it({message:e,output:t,signal:i}))},async confirm(e){return re(await Q({message:e,initialValue:!1,output:t}))},notify:bn}}async function Zi(t,e){let i=e?null:await import("./init-75F4V7SK.js"),s=e??{installed:()=>i.isBackendInstalled("claude"),install:()=>In(i.getInstallCommand("claude"),{stdio:"pipe",timeout:12e4})};if(s.installed())return!0;if(!await t.confirm(c("init.auth.installPrompt")))return!1;try{s.install()}catch{throw new b(c("init.auth.installFailed"))}if(!s.installed())throw new b(c("init.auth.pathMissing"));return!0}var b=class extends Error{exitCode;constructor(e,i=1){super(e),this.exitCode=i}};function _n(){return di({name:"cortex auth login",description:c("init.auth.help"),usage:"cortex auth login [--backend pi|claude] [--provider ID] [--auth-type oauth|api_key]",options:[{flag:"--backend pi|claude",description:c("init.auth.backendOption")},{flag:"--provider ID",description:c("init.auth.providerOption")},{flag:"--auth-type oauth|api_key",description:c("init.auth.typeOption")},{flag:"--help, -h",description:c("cmd.auth.cli.helpDescription")}],examples:[{description:c("init.auth.exampleProvider"),command:"cortex auth login"},{description:c("init.auth.exampleClaude"),command:"cortex auth login --backend claude --provider anthropic --auth-type oauth"}],labels:{usage:c("cmd.auth.cli.helpUsage"),commands:c("cmd.auth.cli.helpCommands"),options:c("cmd.auth.cli.helpOptions"),examples:c("cmd.auth.cli.helpExamples")}})}function Cn(t){let e={},i={"--backend":"backend","--provider":"provider","--auth-type":"authType"};for(let s=0;s<t.length;s+=2){let n=i[t[s]];if(!n||!t[s+1]||t[s+1].startsWith("--")||e[n])throw new b(c("init.auth.invalidOptions"));e[n]=t[s+1]}if(e.backend&&!["pi","claude"].includes(e.backend))throw new b(c("init.auth.invalidBackend"));if(e.authType&&!["oauth","api_key"].includes(e.authType))throw new b(c("init.auth.invalidType"));return e}async function kn(t,e){let i=t.backend??await e.ui.select(c("init.auth.backend"),[{value:"pi",label:c("init.auth.bundled")},{value:"claude",label:"Claude Code"}]),n=(await e.readStatus()).accounts.filter(l=>l.backend===i&&l.capabilities.length),r=t.provider??await e.ui.select(c("init.auth.provider"),n.map(l=>({value:l.provider,label:`${l.label} (${c(`cmd.auth.state.${l.state}`)})`}))),o=n.find(l=>l.provider===r);if(!o)throw new b(c("init.auth.unavailable"));let a=t.authType??await e.ui.select(c("init.auth.type"),o.capabilities.map(l=>({value:l,label:c(`init.auth.${l}`)})));if(!o.capabilities.includes(a))throw new b(c("init.auth.unsupported",{values:o.capabilities.join(", ")}));if(i==="claude"&&!await e.ensureClaude())throw new b(c("init.auth.installDeclined"),130);return{backend:i,provider:r,authType:a,channel:"cli",sessionId:Sn()}}async function Tn(t,e,i){let s=t.pendingPrompt,n=AbortSignal.any([i,AbortSignal.timeout(Math.max(1,Date.parse(t.expiresAt)-Date.now()))]),r;try{r=s.kind==="select"?await e.ui.select(s.message,(s.options??[]).map(o=>({value:o.id,label:o.label})),n):await e.ui.secret(s.message,n),n.throwIfAborted()}catch(o){throw i.aborted?new b(c("init.auth.cancelled"),130):n.aborted?new b(c("init.auth.expired")):o}return e.service.respond(t.flowId,r)}async function En(t,e,i){let s=t,n="";for(;!["done","failed","cancelled"].includes(s.step);){if(i.aborted)throw new b(c("init.auth.cancelled"),130);if(Date.now()>=Date.parse(s.expiresAt))throw new b(c("init.auth.expired"));let r=JSON.stringify(s.notice);if(s.notice&&n!==r&&e.ui.notify(s.notice),n=r,s.pendingPrompt){s=await Tn(s,e,i);continue}await new Promise(a=>setTimeout(a,150));let o=e.service.getState(s.flowId);if(!o)throw new b(c("init.auth.expired"));s=o}return s}async function xn(t,e){let i=await kn(t,e),s=await e.service.start(i),n,r=new AbortController,o=()=>r.abort();process.once("SIGINT",o);try{n=await En(s,e,r.signal)}catch(l){throw await e.service.cancel(s.flowId).catch(()=>{}),r.signal.aborted?new b(c("init.auth.cancelled"),130):l}finally{process.removeListener("SIGINT",o)}if(n.step!=="done")throw new b(c(n.step==="cancelled"?"init.auth.cancelled":"init.auth.failed"),n.step==="cancelled"?130:1);let a=await e.sync(i.backend);return{exitCode:0,stderr:"",stdout:JSON.stringify({ok:!0,backend:i.backend,provider:i.provider,authType:i.authType,state:"done",sync:a,inferenceVerified:!1})}}function oe(){let t=Yi();return{tty:!!process.stdin.isTTY&&!!process.stderr.isTTY,readStatus:si,ui:t,service:ii,ensureClaude:()=>Zi(t),sync:async e=>{let i=await ui({backends:[e]});return{...i,reason:i.reason&&i.reason!=="no-routes"?"sync-failed":i.reason}}}}async function Qi(t,e=oe()){if(t.includes("--help")||t.includes("-h"))return{exitCode:0,stdout:_n(),stderr:""};let i=we({consoleToStderr:!0,files:!1,console:!1});try{let s=Cn(t);if(!e.tty)throw new b(c("init.auth.ttyRequired"));return await xn(s,e)}catch(s){let n=s instanceof b?s:new b(c("init.auth.failed"));return{exitCode:n.exitCode,stdout:JSON.stringify({ok:!1,state:n.exitCode===130?"cancelled":"failed"}),stderr:n.message}}finally{i()}}function ae(t){return[...new Set(t.accounts.filter(e=>[e,...e.credentials??[]].some(i=>i.state==="logged-in"||i.state==="expiring")).map(e=>e.backend))]}async function ts(t,e){try{let i=await t.readStatus();return e({step:"auth",state:ae(i).length?"configured":!i.piRuntime.available||i.accounts.some(s=>s.state==="unknown")?"unknown":"needs-login",inferenceVerified:!1,accounts:i.accounts.map(s=>({backend:s.backend,provider:s.provider,state:s.state})),runtimeAvailable:i.piRuntime.available}),i}catch{return e({step:"auth",state:"unknown",reason:"detection-failed",inferenceVerified:!1}),null}}async function es(t,e,i=oe()){let s=await ts(i,e);if(!t)return s?ae(s):[];for(;;){let n=s?ae(s):[];i.ui.notify({kind:"info",message:s?s.accounts.map(o=>`${o.backend} / ${o.label}: ${c(`cmd.auth.state.${o.state}`)}`).join(`
94
+ `);if(t.kind==="auth_url"){e(c("init.auth.openBrowser",{url:t.url}));return}if(t.kind==="device_code"){e(c("init.auth.deviceCode",{url:t.verificationUri,code:t.userCode}));return}if(e(t.message),t.kind==="info")for(let i of t.links??[])e(i.url)}function Yi(){let t=process.stderr;return{async select(e,i,s){if(!i.length)throw new b(c("init.auth.noCapabilities"));return re(await st({message:e,options:i,output:t,signal:s}))},async secret(e,i){return re(await it({message:e,output:t,signal:i}))},async confirm(e){return re(await Q({message:e,initialValue:!1,output:t}))},notify:bn}}async function Zi(t,e){let i=e?null:await import("./init-A6GY656J.js"),s=e??{installed:()=>i.isBackendInstalled("claude"),install:()=>In(i.getInstallCommand("claude"),{stdio:"pipe",timeout:12e4})};if(s.installed())return!0;if(!await t.confirm(c("init.auth.installPrompt")))return!1;try{s.install()}catch{throw new b(c("init.auth.installFailed"))}if(!s.installed())throw new b(c("init.auth.pathMissing"));return!0}var b=class extends Error{exitCode;constructor(e,i=1){super(e),this.exitCode=i}};function _n(){return di({name:"cortex auth login",description:c("init.auth.help"),usage:"cortex auth login [--backend pi|claude] [--provider ID] [--auth-type oauth|api_key]",options:[{flag:"--backend pi|claude",description:c("init.auth.backendOption")},{flag:"--provider ID",description:c("init.auth.providerOption")},{flag:"--auth-type oauth|api_key",description:c("init.auth.typeOption")},{flag:"--help, -h",description:c("cmd.auth.cli.helpDescription")}],examples:[{description:c("init.auth.exampleProvider"),command:"cortex auth login"},{description:c("init.auth.exampleClaude"),command:"cortex auth login --backend claude --provider anthropic --auth-type oauth"}],labels:{usage:c("cmd.auth.cli.helpUsage"),commands:c("cmd.auth.cli.helpCommands"),options:c("cmd.auth.cli.helpOptions"),examples:c("cmd.auth.cli.helpExamples")}})}function Cn(t){let e={},i={"--backend":"backend","--provider":"provider","--auth-type":"authType"};for(let s=0;s<t.length;s+=2){let n=i[t[s]];if(!n||!t[s+1]||t[s+1].startsWith("--")||e[n])throw new b(c("init.auth.invalidOptions"));e[n]=t[s+1]}if(e.backend&&!["pi","claude"].includes(e.backend))throw new b(c("init.auth.invalidBackend"));if(e.authType&&!["oauth","api_key"].includes(e.authType))throw new b(c("init.auth.invalidType"));return e}async function kn(t,e){let i=t.backend??await e.ui.select(c("init.auth.backend"),[{value:"pi",label:c("init.auth.bundled")},{value:"claude",label:"Claude Code"}]),n=(await e.readStatus()).accounts.filter(l=>l.backend===i&&l.capabilities.length),r=t.provider??await e.ui.select(c("init.auth.provider"),n.map(l=>({value:l.provider,label:`${l.label} (${c(`cmd.auth.state.${l.state}`)})`}))),o=n.find(l=>l.provider===r);if(!o)throw new b(c("init.auth.unavailable"));let a=t.authType??await e.ui.select(c("init.auth.type"),o.capabilities.map(l=>({value:l,label:c(`init.auth.${l}`)})));if(!o.capabilities.includes(a))throw new b(c("init.auth.unsupported",{values:o.capabilities.join(", ")}));if(i==="claude"&&!await e.ensureClaude())throw new b(c("init.auth.installDeclined"),130);return{backend:i,provider:r,authType:a,channel:"cli",sessionId:Sn()}}async function Tn(t,e,i){let s=t.pendingPrompt,n=AbortSignal.any([i,AbortSignal.timeout(Math.max(1,Date.parse(t.expiresAt)-Date.now()))]),r;try{r=s.kind==="select"?await e.ui.select(s.message,(s.options??[]).map(o=>({value:o.id,label:o.label})),n):await e.ui.secret(s.message,n),n.throwIfAborted()}catch(o){throw i.aborted?new b(c("init.auth.cancelled"),130):n.aborted?new b(c("init.auth.expired")):o}return e.service.respond(t.flowId,r)}async function En(t,e,i){let s=t,n="";for(;!["done","failed","cancelled"].includes(s.step);){if(i.aborted)throw new b(c("init.auth.cancelled"),130);if(Date.now()>=Date.parse(s.expiresAt))throw new b(c("init.auth.expired"));let r=JSON.stringify(s.notice);if(s.notice&&n!==r&&e.ui.notify(s.notice),n=r,s.pendingPrompt){s=await Tn(s,e,i);continue}await new Promise(a=>setTimeout(a,150));let o=e.service.getState(s.flowId);if(!o)throw new b(c("init.auth.expired"));s=o}return s}async function xn(t,e){let i=await kn(t,e),s=await e.service.start(i),n,r=new AbortController,o=()=>r.abort();process.once("SIGINT",o);try{n=await En(s,e,r.signal)}catch(l){throw await e.service.cancel(s.flowId).catch(()=>{}),r.signal.aborted?new b(c("init.auth.cancelled"),130):l}finally{process.removeListener("SIGINT",o)}if(n.step!=="done")throw new b(c(n.step==="cancelled"?"init.auth.cancelled":"init.auth.failed"),n.step==="cancelled"?130:1);let a=await e.sync(i.backend);return{exitCode:0,stderr:"",stdout:JSON.stringify({ok:!0,backend:i.backend,provider:i.provider,authType:i.authType,state:"done",sync:a,inferenceVerified:!1})}}function oe(){let t=Yi();return{tty:!!process.stdin.isTTY&&!!process.stderr.isTTY,readStatus:si,ui:t,service:ii,ensureClaude:()=>Zi(t),sync:async e=>{let i=await ui({backends:[e]});return{...i,reason:i.reason&&i.reason!=="no-routes"?"sync-failed":i.reason}}}}async function Qi(t,e=oe()){if(t.includes("--help")||t.includes("-h"))return{exitCode:0,stdout:_n(),stderr:""};let i=we({consoleToStderr:!0,files:!1,console:!1});try{let s=Cn(t);if(!e.tty)throw new b(c("init.auth.ttyRequired"));return await xn(s,e)}catch(s){let n=s instanceof b?s:new b(c("init.auth.failed"));return{exitCode:n.exitCode,stdout:JSON.stringify({ok:!1,state:n.exitCode===130?"cancelled":"failed"}),stderr:n.message}}finally{i()}}function ae(t){return[...new Set(t.accounts.filter(e=>[e,...e.credentials??[]].some(i=>i.state==="logged-in"||i.state==="expiring")).map(e=>e.backend))]}async function ts(t,e){try{let i=await t.readStatus();return e({step:"auth",state:ae(i).length?"configured":!i.piRuntime.available||i.accounts.some(s=>s.state==="unknown")?"unknown":"needs-login",inferenceVerified:!1,accounts:i.accounts.map(s=>({backend:s.backend,provider:s.provider,state:s.state})),runtimeAvailable:i.piRuntime.available}),i}catch{return e({step:"auth",state:"unknown",reason:"detection-failed",inferenceVerified:!1}),null}}async function es(t,e,i=oe()){let s=await ts(i,e);if(!t)return s?ae(s):[];for(;;){let n=s?ae(s):[];i.ui.notify({kind:"info",message:s?s.accounts.map(o=>`${o.backend} / ${o.label}: ${c(`cmd.auth.state.${o.state}`)}`).join(`
95
95
  `):c("init.auth.detectionFailed")});let r=await i.ui.select(c("init.auth.setup"),[...n.length?[{value:"continue",label:c("init.auth.continue")}]:[],{value:"login",label:c("init.auth.login")},{value:"rescan",label:c("init.auth.rescan")},{value:"skip",label:c("init.auth.skip")}]);if(r==="skip")return[];if(r==="continue")return n;if(r==="login"){let o=await Qi([],{...i,sync:async()=>({configured:!1,routes:0,defaultSet:!1,favorites:[],reason:"deferred-to-init"})});if(o.exitCode===130)throw new b(c("init.cancel"),130);i.ui.notify({kind:"info",message:o.stderr||c("init.auth.saved")})}s=await ts(i,e)}}function E(t){rt(t)&&(Hi(c("init.cancel")),process.exit(0))}var An=new Set(["claude","plan","api","subscription"]),Rn={"pi-anthropic":"anthropic"};function Dt(t){return typeof t=="string"&&t.trim()?t.trim():void 0}function On(t){return t.backend==="claude"?"claude":t.backend==="pi"?Dt(t.provider):Dt(t.mode)}function ce(t){if(!t||typeof t!="object")return;let e=t,i=On(e),s=Dt(e.model);if(!i||!s)return;let n=e.backend==="claude"?Dt(e.connection):void 0;return n?{route:i,model:s,connection:n}:{route:i,model:s}}function ue(t){let e=t?.trim(),i=e?e.indexOf(":"):-1;if(!(!e||i<=0||i===e.length-1))return{route:e.substring(0,i).trim(),model:e.substring(i+1).trim()}}function ns(t){let e=(t?.trim()?t.split(","):[]).map(i=>ue(i.trim())).filter(i=>!!i);return e.length>0?e:void 0}function Dn(t,e){let i=He(t,{backend:"claude",provider:null})?.connections??[];return e.connection!==void 0?i.includes(e.connection)?e.connection:void 0:An.has(e.route)?null:i.includes(e.route)?e.route:void 0}function is(t,e){let i=We(t,e.model),s=Dn(t,e),n=Rn[e.route]??e.route,r=s!==void 0?i.find(o=>o.backend==="claude"):i.find(o=>o.backend==="pi"&&o.provider===n);if(!r)throw new Error(`(${e.route}, ${e.model}) is not among the models this host can run`);return{...r,thinking:null,connection:s??null}}function Nn(t,e){let i=e?.defaultChoice?is(t,e.defaultChoice):void 0,s=(e?.favorites??[]).map(n=>is(t,n));return{default:i,favorites:s}}function rs(t){return t.backend==="claude"?"claude":t.provider??"pi"}function Fn(t){return t.flatMap(e=>e.models.map(i=>({value:JSON.stringify([e.backend,e.provider,i]),label:`${rs(e)} / ${i}`})))}function ss(t){let[e,i,s]=JSON.parse(t);return{backend:e,provider:i,model:s}}async function Pn(t){if(!Bt(t)?.default)return!0;let e=await Q({message:c("init.modelSetup.overwritePrompt"),initialValue:!1});return E(e),e}async function Mn(t,e,i){if(!await Pn(i))return{};let s=Fn(t),n=e[0]?JSON.stringify([e[0].backend,e[0].provider,e[0].model]):s[0].value,r=await st({message:c("init.modelSetup.defaultPrompt"),options:s,initialValue:n});E(r);let o=await Ot({message:c("init.modelSetup.favoritesPrompt"),options:s,required:!1,initialValues:[r]});return E(o),{default:{...ss(r),thinking:null,connection:null},favorites:o.map(ss)}}function jn(t){let e=t.map(i=>{let s=i.models.slice(0,3).join(", ");return` ${rs(i)}: ${s}${i.models.length>3?", ...":""}`}).join(`
96
96
  `);v.success(c("init.modelSetup.discovered",{count:t.length,summary:e}))}function Ln(t,e){v.success(c("init.modelSetup.modelsWritten",{path:e})),v.info(c("init.modelSetup.generatedModels",{names:t.favorites.map(i=>i.model).join(", "),default:t.default.model}))}async function le(t){let e=await Ge.reload(),i=e.routes.filter(o=>t.backends.includes(o.backend)&&o.models.length>0);if(i.length===0)return v.warn(c("init.modelSetup.noModels")),v.info(c("init.modelSetup.rerunHint")),!1;jn(i);let s=await ci(e,{backends:t.backends}),n=t.interactive?await Mn(i,s,t.configDir):Nn(e,t.answers),r=ri(oi(Bt(t.configDir),s).file,n);return Ln(r,ai(t.configDir,r)),!0}import{existsSync as Un,mkdirSync as Vn,readFileSync as as,writeFileSync as Gn}from"node:fs";import os from"node:path";function cs(t){if(t===void 0)return;let e=Se.safeParse(t);return e.success?e.data:void 0}function Hn(t){if(!Un(t))return{};let e=JSON.parse(as(t,"utf8"));if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`${t} must contain a JSON object`);return e}function us(t,e){let i=os.join(e.configDir,"settings.json"),s=Hn(i);Vn(e.configDir,{recursive:!0}),Gn(i,`${JSON.stringify({...s,telemetryEnabled:t.enabled},null,2)}
97
97
  `,"utf8");let n=os.join(e.storeDir,"telemetry","install-id");t.installId&&!Wn(n)&&Ee(t.installId,n)}function Wn(t){try{return Te(as(t,"utf8").trim())}catch{return!1}}var ps=lt(jt(),1);import*as ds from"readline";import*as he from"path";function Nt(t,e,i){let s=`${e}=${i}`,n=t===""?[]:t.replace(/\n+$/,"").split(`