@cortex-agent/server 2026.10.28 → 2026.11.17

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 (258) hide show
  1. package/LICENSE +255 -21
  2. package/README.md +36 -7
  3. package/THIRD_PARTY_NOTICES.txt +1109 -278
  4. package/defaults/hooks/cortex-hook-api.mjs +2 -1
  5. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +23 -15
  6. package/dist/agent-adapter/claude/remote-mcp-proxy.js +1 -1
  7. package/dist/chunks/{anthropic-messages-M3SMXACA.js → anthropic-messages-M732OMEE.js} +1 -1
  8. package/dist/chunks/{azure-openai-responses-76YWXHSB.js → azure-openai-responses-RAKTV6JY.js} +1 -1
  9. package/dist/chunks/bedrock-converse-stream-WNUGNZ27.js +62 -0
  10. package/dist/chunks/bowser-MLGGLXTZ.js +20 -0
  11. package/dist/chunks/child-runner-MO5RT6FH.js +4 -0
  12. package/dist/chunks/chunk-2ATTYCRJ.js +4 -0
  13. package/dist/chunks/{chunk-PXS5SHOV.js → chunk-2ROGTDM2.js} +1 -1
  14. package/dist/chunks/chunk-2VVRTJQN.js +4 -0
  15. package/dist/chunks/{chunk-OZGBWAT2.js → chunk-2YTYYG4K.js} +1 -1
  16. package/dist/chunks/chunk-3CPIMAYX.js +30 -0
  17. package/dist/chunks/{chunk-FXDIR3SQ.js → chunk-3CZPBLB3.js} +1 -1
  18. package/dist/chunks/chunk-3ORG56I5.js +8 -0
  19. package/dist/chunks/{chunk-LEUENXI2.js → chunk-4YLAGSDM.js} +1 -1
  20. package/dist/chunks/{chunk-HU6UIDEJ.js → chunk-53TQNK7Z.js} +1 -1
  21. package/dist/chunks/{chunk-4U7XXM4W.js → chunk-5A6CA5TM.js} +1 -1
  22. package/dist/chunks/{chunk-PBJ5MPPX.js → chunk-5DF5WJNM.js} +1 -1
  23. package/dist/chunks/chunk-5PAW3DEU.js +50 -0
  24. package/dist/chunks/{chunk-DXBSQXJL.js → chunk-7GAYFN52.js} +1 -1
  25. package/dist/chunks/chunk-7GEBDPTT.js +4 -0
  26. package/dist/chunks/{chunk-NR6U3WIZ.js → chunk-AFTBQRPN.js} +1 -1
  27. package/dist/chunks/chunk-AVXDF7AG.js +4 -0
  28. package/dist/chunks/chunk-BDLKI2NT.js +4 -0
  29. package/dist/chunks/{chunk-P52RMIYX.js → chunk-BJGYGEZO.js} +1 -1
  30. package/dist/chunks/chunk-BUZQBTV2.js +10 -0
  31. package/dist/chunks/chunk-BZDIAI5M.js +125 -0
  32. package/dist/chunks/{chunk-A34TDMIC.js → chunk-CEGSDGYQ.js} +1 -1
  33. package/dist/chunks/{chunk-Q7CE3UIE.js → chunk-CK3P345X.js} +69 -69
  34. package/dist/chunks/{chunk-YAEVYJAR.js → chunk-EE3WT25T.js} +1 -1
  35. package/dist/chunks/chunk-ETIBCA2S.js +4 -0
  36. package/dist/chunks/{chunk-REBNWCKI.js → chunk-FP7ML72L.js} +1 -1
  37. package/dist/chunks/{chunk-H2FP6DG4.js → chunk-H4QZ2P3Z.js} +1 -1
  38. package/dist/chunks/chunk-IA6IODY3.js +4 -0
  39. package/dist/chunks/{chunk-D3NXKK2L.js → chunk-IKLTEWA3.js} +1 -1
  40. package/dist/chunks/chunk-IYVZHGUQ.js +5 -0
  41. package/dist/chunks/chunk-JJDEQ6N2.js +4 -0
  42. package/dist/chunks/chunk-JKL3AK5D.js +106 -0
  43. package/dist/chunks/chunk-KDPY2YA3.js +129 -0
  44. package/dist/chunks/{chunk-SUFW24P4.js → chunk-KUDK7GPS.js} +1 -1
  45. package/dist/chunks/chunk-LAWOWPZX.js +363 -0
  46. package/dist/chunks/chunk-LEAV3FFG.js +4 -0
  47. package/dist/chunks/chunk-LP72AF56.js +45 -0
  48. package/dist/chunks/{chunk-KENCMLRE.js → chunk-LP7T32PW.js} +1 -1
  49. package/dist/chunks/chunk-LQTFDC67.js +4 -0
  50. package/dist/chunks/{chunk-HALUQ7ZF.js → chunk-MGYYSX7Y.js} +1 -1
  51. package/dist/chunks/chunk-NNBSSISP.js +4 -0
  52. package/dist/chunks/chunk-NNTQUHLO.js +877 -0
  53. package/dist/chunks/{chunk-PFMEUFJ7.js → chunk-NRD57ICT.js} +1 -1
  54. package/dist/chunks/{chunk-QWAQHHRS.js → chunk-NXZS5PEW.js} +1 -1
  55. package/dist/chunks/chunk-OFEPDNRB.js +4 -0
  56. package/dist/chunks/{chunk-6LZK4DDH.js → chunk-P7TVR4GY.js} +1 -1
  57. package/dist/chunks/chunk-QEL6CMLE.js +4 -0
  58. package/dist/chunks/chunk-QMSSIDRQ.js +70 -0
  59. package/dist/chunks/chunk-QUXPMNFQ.js +4 -0
  60. package/dist/chunks/chunk-R52AVUQB.js +5 -0
  61. package/dist/chunks/chunk-R6CGBSTC.js +22 -0
  62. package/dist/chunks/chunk-RA2BUYI3.js +6 -0
  63. package/dist/chunks/chunk-RDW6FRF5.js +4 -0
  64. package/dist/chunks/chunk-RF4JLYBX.js +6 -0
  65. package/dist/chunks/{chunk-YPK2CAIZ.js → chunk-ROVKOIHF.js} +1 -1
  66. package/dist/chunks/chunk-RYLSRII6.js +7 -0
  67. package/dist/chunks/{chunk-XNSSUVT6.js → chunk-S3MR37DL.js} +1 -1
  68. package/dist/chunks/chunk-SAJD4EKE.js +10 -0
  69. package/dist/chunks/chunk-SFX7V5O2.js +10 -0
  70. package/dist/chunks/chunk-STCNHXPJ.js +6 -0
  71. package/dist/chunks/{chunk-FOJQXLL2.js → chunk-SY2HV3V5.js} +1 -1
  72. package/dist/chunks/chunk-T73GHMFB.js +4 -0
  73. package/dist/chunks/chunk-TKFFQNAP.js +19 -0
  74. package/dist/chunks/chunk-TMV2ZDOI.js +18 -0
  75. package/dist/chunks/chunk-TX46YMGI.js +5 -0
  76. package/dist/chunks/chunk-U23S37TT.js +6 -0
  77. package/dist/chunks/chunk-UT6DGZDO.js +4 -0
  78. package/dist/chunks/{chunk-JERCOLY3.js → chunk-V35MFAUQ.js} +4 -6
  79. package/dist/chunks/chunk-V6X7Y62J.js +7 -0
  80. package/dist/chunks/chunk-V7K3KNDM.js +4 -0
  81. package/dist/chunks/{chunk-NAA7GF6Q.js → chunk-VBN2JSER.js} +1 -1
  82. package/dist/chunks/chunk-VIMHSW6J.js +4 -0
  83. package/dist/chunks/chunk-VK5J556O.js +4 -0
  84. package/dist/chunks/chunk-VPVSKJGX.js +6 -0
  85. package/dist/chunks/chunk-VTL3Z2OP.js +23 -0
  86. package/dist/chunks/{chunk-X2GYYRVM.js → chunk-VW7TLY3P.js} +1 -1
  87. package/dist/chunks/chunk-W34AK4SK.js +65 -0
  88. package/dist/chunks/chunk-W6AKCEYF.js +8 -0
  89. package/dist/chunks/chunk-WBSE3EF3.js +27 -0
  90. package/dist/chunks/chunk-WZYS2HAK.js +4 -0
  91. package/dist/chunks/{chunk-UNVEZI57.js → chunk-XEBEWR6Y.js} +1 -1
  92. package/dist/chunks/chunk-XPPZ6Y3X.js +8 -0
  93. package/dist/chunks/chunk-XYSXL3KX.js +4 -0
  94. package/dist/chunks/chunk-YAAKL3QS.js +80 -0
  95. package/dist/chunks/chunk-YB5LUJHS.js +65 -0
  96. package/dist/chunks/chunk-Z24SBRJK.js +4 -0
  97. package/dist/chunks/cloudflare-workers-ai-system-one-32JCFHI3.js +1 -1
  98. package/dist/chunks/context-GQKWKFRM.js +4 -0
  99. package/dist/chunks/cost-OOO32GLC.js +5 -0
  100. package/dist/chunks/dist-V5FRMUFH.js +4 -0
  101. package/dist/chunks/easter-egg-3d-CZH7AYZ7.js +4 -0
  102. package/dist/chunks/{event-streams-3JSFPOTZ.js → event-streams-AVE4MSS6.js} +1 -1
  103. package/dist/chunks/execution-repo-XXL4FXC6.js +4 -0
  104. package/dist/chunks/{executions-6ARGR3IO.js → executions-BN6OLLVM.js} +1 -1
  105. package/dist/chunks/file-H572PL2Z.js +4 -0
  106. package/dist/chunks/google-generative-ai-2G4ITOZL.js +4 -0
  107. package/dist/chunks/google-vertex-PACHCMRZ.js +4 -0
  108. package/dist/chunks/init-75F4V7SK.js +4 -0
  109. package/dist/chunks/{install-cli-4IZCSDFZ.js → install-cli-ABBD7DO5.js} +1 -1
  110. package/dist/chunks/{interaction-ask-G5T3H3CG.js → interaction-ask-EE2UPR3Q.js} +1 -1
  111. package/dist/chunks/{interaction-plan-E5V42MUP.js → interaction-plan-C446T2GZ.js} +1 -1
  112. package/dist/chunks/{llama-cpp-classify-OTXZWCMW.js → llama-cpp-classify-IA2F2H7A.js} +1 -1
  113. package/dist/chunks/local-client-stop-5YOLXGYT.js +4 -0
  114. package/dist/chunks/memory-cli-5SSF6YJM.js +11 -0
  115. package/dist/chunks/{mistral-conversations-34F66L3O.js → mistral-conversations-VHP63CDS.js} +1 -1
  116. package/dist/chunks/{model-resolver-N3DTAQ2S.js → model-resolver-FVJNZ6NA.js} +1 -1
  117. package/dist/chunks/{node-PTK2HCDV.js → node-DAO3SX7O.js} +1 -1
  118. package/dist/chunks/{openai-codex-2REL6UQU.js → openai-codex-JULCKICT.js} +1 -1
  119. package/dist/chunks/{openai-codex-responses-ZBVHREB3.js → openai-codex-responses-EHJ4AZBE.js} +1 -1
  120. package/dist/chunks/{openai-completions-VVIB26SH.js → openai-completions-CRAGQFCE.js} +1 -1
  121. package/dist/chunks/{openai-decisions-2N6ZRPZC.js → openai-decisions-P5UX7BWY.js} +1 -1
  122. package/dist/chunks/{openai-responses-735XA2ZX.js → openai-responses-IZ22NVQ7.js} +1 -1
  123. package/dist/chunks/{openrouter-images-3IKETHAC.js → openrouter-images-W2JAMSRH.js} +1 -1
  124. package/dist/chunks/{pi-messages-I3E4ZFHA.js → pi-messages-MJEEQU2R.js} +1 -1
  125. package/dist/chunks/{radius-HXRZVBDB.js → radius-ZM7ZRMXF.js} +1 -1
  126. package/dist/chunks/{remote-ops-BALZYKH6.js → remote-ops-O5CR4RGA.js} +1 -1
  127. package/dist/chunks/runner-S6R3US24.js +4 -0
  128. package/dist/chunks/schedule-cli-4T4YC5V5.js +4 -0
  129. package/dist/chunks/slack-2CGM4SMY.js +4 -0
  130. package/dist/chunks/start-ui-http-3D7QNHGB.js +43 -0
  131. package/dist/chunks/subagent-OZGUOV3J.js +4 -0
  132. package/dist/chunks/{time-KEHDQT6K.js → time-P6PE52WL.js} +1 -1
  133. package/dist/chunks/tool-shims-IA2WELXJ.js +4 -0
  134. package/dist/chunks/typesafe-system-one-6ULACYD4.js +1 -1
  135. package/dist/chunks/ui-board-H4INJD6C.js +5 -0
  136. package/dist/chunks/ui-decision-6HHNROIT.js +4 -0
  137. package/dist/chunks/{ui-file-GVH53O3X.js → ui-file-6PLXHSTB.js} +1 -1
  138. package/dist/chunks/ui-view-6MDU4GXY.js +4 -0
  139. package/dist/chunks/virtual-modules-OFI7QKYH.js +4 -0
  140. package/dist/chunks/waitpoint-W5M3BE55.js +5 -0
  141. package/dist/chunks/workers-GTFP75MS.js +4 -0
  142. package/dist/client-bundle/client.mjs +44 -31
  143. package/dist/client-bundle/manifest.json +2 -2
  144. package/dist/core/pi-sdk.js +1 -1
  145. package/dist/domain/auth/cc-auth-cli.js +1 -1
  146. package/dist/domain/mcp/bundled-server.js +1 -1
  147. package/dist/domain/mcp/feishu/client.js +4 -0
  148. package/dist/entry/app.js +201 -191
  149. package/dist/entry/browser-cli.js +10 -10
  150. package/dist/entry/cli.js +1 -1
  151. package/dist/entry/cortex-cli.js +1 -1
  152. package/dist/entry/daemon.js +4 -4
  153. package/dist/entry/hook-cli.js +2 -2
  154. package/dist/entry/production-app-bootstrap.js +1 -1
  155. package/dist/entry/production-evidence-export-cli.js +1 -1
  156. package/dist/entry/signal-cli.js +2 -2
  157. package/dist/tui/index.js +41 -41
  158. package/package.json +3 -3
  159. package/vendor/pi/dist/core/extensions/loader.js +1 -1
  160. package/vendor/pi/dist/extensions/codemode/execute.js +1 -1
  161. package/vendor/pi-ai/bedrock.js +1 -1
  162. package/vendor/pi-ai/oauth-load.js +1 -1
  163. package/web/dist/assets/{board-math-css-BPXakv_3.js → board-math-css-BgIyUG-C.js} +1 -1
  164. package/web/dist/assets/index-9lyu2S6W.css +1 -0
  165. package/web/dist/assets/index-C-hpzey7.js +532 -0
  166. package/web/dist/assets/{index-WCm6wwmM.js → index-C2eMpcuI.js} +1 -1
  167. package/web/dist/assets/pdf-worker-DdZgk2mV.js +57 -0
  168. package/web/dist/assets/pdf.worker.min-Bz_KHX45.js +55 -0
  169. package/web/dist/index.html +2 -2
  170. package/web/dist/theme.css +22 -0
  171. package/dist/chunks/api-GM53PHIL-GFHEXXE6.js +0 -4
  172. package/dist/chunks/bedrock-converse-stream-5UPX4NTQ.js +0 -58
  173. package/dist/chunks/child-runner-3GHOWGZP.js +0 -4
  174. package/dist/chunks/chunk-2ZNLUY2U.js +0 -128
  175. package/dist/chunks/chunk-3F6WW7HR.js +0 -13
  176. package/dist/chunks/chunk-3OKHUVEM.js +0 -7
  177. package/dist/chunks/chunk-3THJYAEF.js +0 -4
  178. package/dist/chunks/chunk-3YHOCPQU.js +0 -10
  179. package/dist/chunks/chunk-4LLH5OWM.js +0 -10
  180. package/dist/chunks/chunk-52T37Y47.js +0 -8
  181. package/dist/chunks/chunk-7MU2AKNM.js +0 -4
  182. package/dist/chunks/chunk-AAA3UBIS.js +0 -4
  183. package/dist/chunks/chunk-ASYQHJVQ.js +0 -9
  184. package/dist/chunks/chunk-BGVHA2D4.js +0 -4
  185. package/dist/chunks/chunk-BKHDWCRT.js +0 -79
  186. package/dist/chunks/chunk-CQLH4UVX.js +0 -4
  187. package/dist/chunks/chunk-D6UA4BZC.js +0 -19
  188. package/dist/chunks/chunk-DGMNI4AO.js +0 -4
  189. package/dist/chunks/chunk-DHSA5ACV.js +0 -125
  190. package/dist/chunks/chunk-DPQPXBTP.js +0 -68
  191. package/dist/chunks/chunk-E7ZMYIY6.js +0 -30
  192. package/dist/chunks/chunk-EQITBTJC.js +0 -10
  193. package/dist/chunks/chunk-EXJA5RIX.js +0 -357
  194. package/dist/chunks/chunk-FH74NME3.js +0 -115
  195. package/dist/chunks/chunk-FOQ7VLIL.js +0 -17
  196. package/dist/chunks/chunk-J5DVLUKY.js +0 -6
  197. package/dist/chunks/chunk-JW2HFMTF.js +0 -4
  198. package/dist/chunks/chunk-KIGMAATV.js +0 -23
  199. package/dist/chunks/chunk-KIU5FAPY.js +0 -5
  200. package/dist/chunks/chunk-KIWMQPH7.js +0 -739
  201. package/dist/chunks/chunk-LMSQZ6TQ.js +0 -4
  202. package/dist/chunks/chunk-MEPASGPP.js +0 -6
  203. package/dist/chunks/chunk-MFAEUHMV.js +0 -28
  204. package/dist/chunks/chunk-NKDMKRSB.js +0 -68
  205. package/dist/chunks/chunk-NKXV32S6.js +0 -4
  206. package/dist/chunks/chunk-NVX5IPRN.js +0 -4
  207. package/dist/chunks/chunk-O3JW2F7D.js +0 -8
  208. package/dist/chunks/chunk-OISO5JXB.js +0 -4
  209. package/dist/chunks/chunk-OPYXNSMY.js +0 -4
  210. package/dist/chunks/chunk-PZMXHA6X.js +0 -9
  211. package/dist/chunks/chunk-QEOFEETJ.js +0 -4
  212. package/dist/chunks/chunk-REPYBMQS.js +0 -4
  213. package/dist/chunks/chunk-TAWLERZA.js +0 -4
  214. package/dist/chunks/chunk-TWAEABGG.js +0 -52
  215. package/dist/chunks/chunk-TZFLHVOQ.js +0 -7
  216. package/dist/chunks/chunk-UD3NMUHR.js +0 -12
  217. package/dist/chunks/chunk-W25TB3PU.js +0 -4
  218. package/dist/chunks/chunk-W5LGYSPZ.js +0 -4
  219. package/dist/chunks/chunk-XAJLZR7C.js +0 -28
  220. package/dist/chunks/chunk-XH6FMP3N.js +0 -71
  221. package/dist/chunks/chunk-XSRZHN63.js +0 -4
  222. package/dist/chunks/chunk-YG7OEPR2.js +0 -6
  223. package/dist/chunks/chunk-YHIWOGVL.js +0 -4
  224. package/dist/chunks/chunk-YZSHTWNM.js +0 -92
  225. package/dist/chunks/chunk-Z4H3VDHI.js +0 -4
  226. package/dist/chunks/client-XOGYH5UR.js +0 -4
  227. package/dist/chunks/config-DJSQI77S-335IXHSM.js +0 -4
  228. package/dist/chunks/context-VCQH5OB6.js +0 -4
  229. package/dist/chunks/cost-PGGFI7QJ.js +0 -5
  230. package/dist/chunks/dist-PUKMZ7GW.js +0 -4
  231. package/dist/chunks/easter-egg-3d-MO4MOEVF.js +0 -4
  232. package/dist/chunks/es5-VNTQPCKX.js +0 -4
  233. package/dist/chunks/execution-repo-ZLJTBWFC.js +0 -4
  234. package/dist/chunks/file-7BN7RCAY.js +0 -4
  235. package/dist/chunks/gateway-UCRPMR75.js +0 -36
  236. package/dist/chunks/google-generative-ai-2VXWLHWI.js +0 -4
  237. package/dist/chunks/google-vertex-UA36QP2U.js +0 -4
  238. package/dist/chunks/init-HA7FAQ73.js +0 -4
  239. package/dist/chunks/local-client-stop-SQRU7ZZM.js +0 -4
  240. package/dist/chunks/memory-cli-PYOILNN5.js +0 -11
  241. package/dist/chunks/models-L5VF4I5O-XXNJYQMQ.js +0 -4
  242. package/dist/chunks/runner-PLVZDGHB.js +0 -4
  243. package/dist/chunks/schedule-cli-OLASBBYJ.js +0 -4
  244. package/dist/chunks/slack-WAGSPZUX.js +0 -4
  245. package/dist/chunks/start-ui-http-QALT7C3P.js +0 -43
  246. package/dist/chunks/subagent-E3UC7ZHC.js +0 -4
  247. package/dist/chunks/tool-shims-Q6P6UXVC.js +0 -4
  248. package/dist/chunks/ui-board-4GYW6KKW.js +0 -5
  249. package/dist/chunks/ui-decision-U2FXSEC2.js +0 -4
  250. package/dist/chunks/ui-view-O7PLANT7.js +0 -4
  251. package/dist/chunks/virtual-modules-IDC5YKZJ.js +0 -4
  252. package/dist/chunks/waitpoint-2FGQBIAC.js +0 -5
  253. package/dist/chunks/workers-XN4PSTH6.js +0 -4
  254. package/vendor/aistatus/gateway-cli.js +0 -21
  255. package/web/dist/assets/index-BHZpFXhc.js +0 -525
  256. package/web/dist/assets/index-DqWMdMkh.css +0 -1
  257. package/web/dist/assets/pdf-worker-Hp15W1QJ.js +0 -57
  258. package/web/dist/assets/pdf.worker.min-DnhTvCwe.js +0 -55
@@ -0,0 +1,8 @@
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 t}from"./chunk-PMG4YGDU.js";import{e}from"./chunk-3CPIMAYX.js";function a(){return["Initialize Cortex data directory","","Usage: cortex init [--home <path>] [--force] [--answers <file>] [--json]","","Creates the CORTEX_HOME directory structure and asks for the language, interaction","platform (Slack / Feishu), machine name, usage leaderboard sharing and system service.","Writes .env, copies default configs and generates mcp-config*.json, machines.json","and agent-state.json. It then detects provider logins, offers to log in, and picks","the default model and favorites from the models those logins can run.","","Options:"," --home <path> Set CORTEX_HOME (default: $CORTEX_HOME or ~/.cortex/)"," --force Overwrite existing configs (.env, budget.json, agent-state.json, etc.)"," --answers <file> Read answers from a JSON file instead of prompting; omitted fields use defaults"," --json Print NDJSON progress events on stdout and send human output to stderr"," --help, -h Show this help","","With --answers or --json, init does not prompt or start provider login; it reports","credential status and can finish before any provider is set up.","","Examples:"," cortex init"," cortex init --home /data/cortex"," cortex init --answers answers.json --json"].join(`
5
+ `)}function s(){return["Start the Cortex TUI (terminal UI) client","","Usage: cortex tui [options]","","Connects to a running Cortex daemon via WebSocket and opens","a terminal-based chat interface.","","Options:"," --resume Open the resume-session picker on connect"," --project <id> Start a fresh session in the named project"," --port <n> Server port (default: CORTEX_UI_PORT from the environment or .env, else 26789)"," --help, -h Show this help"].join(`
6
+ `)}function c(){return t({name:"cortex ui",description:"Manage the Web UI endpoint used by the Cortex apps and browsers",usage:"cortex ui <enable|pair> [--port <port>] [--home <path>] [--json]",commands:[{name:"enable",description:"Turn on the loopback Web UI endpoint and print how to reach it"},{name:"pair",description:"Print a one-time pairing code (10 minutes) for a new app or browser"}],options:[{flag:"--port <port>",description:"enable: TCP port this install serves on (must be free)",default:"the configured CORTEX_UI_PORT, else the first free port from 26789"},{flag:"--home <path>",description:"CORTEX_HOME to use",default:"$CORTEX_HOME or ~/.cortex"},{flag:"--json",description:"Print the result as JSON (enable: endpoint, token, change state; pair: code, expiry)"},{flag:"--help, -h",description:"Show this help"}],examples:[{description:"Enable the endpoint, keeping the configured port",command:"cortex ui enable"},{description:"Serve on another port",command:"cortex ui enable --port 4000"},{description:"Machine-readable output for the desktop setup flow",command:"cortex ui enable --json"},{description:"Get a code to connect a phone or another computer",command:"cortex ui pair"}]})}function d(){return t({name:"cortex path",description:"Make this install's commands (cortex, cortex-signal, \u2026) available in new terminals",usage:"cortex path <install|remove|status> [--home <path>] [--dry-run] [--json]",commands:[{name:"install",description:"Write launchers that use this install's Node into <home>/runtime/bin and put that directory on PATH (shell profiles on Linux/macOS, the user Path on Windows)"},{name:"remove",description:"Delete the launchers and undo the PATH change"},{name:"status",description:"Show whether the launchers exist, are current, and are on PATH"}],options:[{flag:"--home <path>",description:"CORTEX_HOME the launchers belong to",default:"$CORTEX_HOME or ~/.cortex"},{flag:"--dry-run",description:"Report what install or remove would change and change nothing"},{flag:"--json",description:"Print the result as JSON"},{flag:"--help, -h",description:"Show this help"}],examples:[{description:"Add cortex to new terminals",command:"cortex path install"},{description:"Preview the change",command:"cortex path install --dry-run --json"},{description:"Check the current state",command:"cortex path status"},{description:"Undo it",command:"cortex path remove"}]})}function m(){return t({name:"cortex client",description:"Manage the cortex-client installs on remote machines",usage:"cortex client remove --device <name> [--keep-remote] [--dry-run] [--home <path>]",commands:[{name:"remove",description:"Unregister a machine from machines.json, stop and uninstall its client over SSH, and drop its runtime state"}],options:[{flag:"--device <name>",description:"Machine name as registered in machines.json (required)"},{flag:"--keep-remote",description:"Only unregister locally; leave the remote process and files alone"},{flag:"--dry-run",description:"Print what would be removed as JSON and change nothing"},{flag:"--home <path>",description:"CORTEX_HOME of the server",default:"$CORTEX_HOME or ~/.cortex"},{flag:"--help, -h",description:"Show this help"}],examples:[{description:"Preview the removal",command:"cortex client remove --device trainer --dry-run"},{description:"Remove a machine and uninstall its client",command:"cortex client remove --device trainer"},{description:"Unregister a machine that no longer exists",command:"cortex client remove --device trainer --keep-remote"}]})}function p(){return t({name:"cortex memory",description:`Project memory under $CORTEX_HOME/context/projects (experiments/, knowledge/, patterns/).
7
+ regen rewrites only the generated index.md files; the EXP/K/PAT files are never modified. Output is JSON.`,usage:"cortex memory <command> [--project <name>]... [options]",commands:[{name:"regen",description:"Rebuild experiments/knowledge/patterns index.md from frontmatter and the access log"},{name:"consolidate",description:"Report contradictions, stale entries, anti-pattern signals and consolidation candidates"}],options:[{flag:"--project <name>",description:"Limit to one project; repeat for several",default:"every project with memory directories"},{flag:"--text",description:"consolidate: print a human-readable summary instead of JSON"},{flag:"--help, -h",description:"Show this help"}],examples:[{description:"Rebuild every index",command:"cortex memory regen"},{description:"Rebuild one project's indexes",command:"cortex memory regen --project wm-align"},{description:"Lifecycle report for all projects",command:"cortex memory consolidate --text"},{description:"Lifecycle report as JSON for one project",command:"cortex memory consolidate --project wm-align"}]})}function l(){return t({name:"cortex schedule",description:`Manage scheduled tasks. Each fire opens a new session in the schedule's project and sends it the message.
8
+ Changes land in schedules.json; a running daemon picks them up within a second. Output is JSON.`,usage:"cortex schedule <command> [<id>] [options]",commands:[{name:"list",description:"List schedules (--project to filter)"},{name:"get <id>",description:"Show one schedule"},{name:"add --type <type>",description:"Create a schedule"},{name:"edit <id>",description:"Change message, project, model, thinking, pre-check or timing (the type is fixed)"},{name:"pause <id>",description:"Pause a recurring schedule"},{name:"resume <id>",description:"Resume a paused schedule"},{name:"remove <id>",description:"Delete a schedule (--dry-run to preview)"}],options:[{flag:"--type <type>",description:"add: interval | daily | weekly | once"},{flag:"--interval <duration>",description:"interval: repeat period, e.g. 30m, 2h, 1d"},{flag:"--time <HH:MM>",description:"daily/weekly: time of day, 24-hour, server local time"},{flag:"--day <day>",description:"weekly: sun..sat or 0-6"},{flag:"--delay <duration>",description:"once: fire this long from now, e.g. 90m, 2h"},{flag:"--message <text|->",description:'Prompt for the fired session; "-" reads stdin'},{flag:"--project <id>",description:"Project the fired session belongs to",default:"general"},{flag:"--model [provider/]model",description:"Model to run",default:"the default model"},{flag:"--thinking <level>",description:"Thinking level for the selected model"},{flag:"--pre-check <cmd>",description:"Shell gate run before each fire; non-zero exit skips it"},{flag:"--idempotency-key <key>",description:"add: return the schedule already created with this key"},{flag:"--dry-run",description:"remove: show what would be removed"},{flag:"--help, -h",description:"Show this help"}],examples:[{description:"Every 30 minutes in a project",command:'cortex schedule add --type interval --interval 30m --project nimbus --message "Check GPU usage on lab2 and report a one-line summary"'},{description:"Every day at 09:00",command:`cortex schedule add --type daily --time 09:00 --message "Summarize yesterday's sessions"`},{description:"Every Monday at 21:00",command:'cortex schedule add --type weekly --day mon --time 21:00 --message "Weekly review"'},{description:"Once, two hours from now, prompt from stdin",command:'echo "Check training run r42 on lab2" | cortex schedule add --type once --delay 2h --message -'},{description:"List one project's schedules",command:"cortex schedule list --project nimbus"},{description:"Move a daily schedule to 10:30",command:"cortex schedule edit a1b2c3d4 --time 10:30"},{description:"Preview a removal",command:"cortex schedule remove a1b2c3d4 --dry-run"}]})}function n(){return[{name:"init",description:"Initialize CORTEX_HOME directory with configs and API keys"},{name:"start",description:"Start the Cortex server (node dist/entry/app.js)"},{name:"daemon",description:"Start daemon mode with file watching and auto-restart"},{name:"daemon stop",description:"Stop the running daemon (SIGTERM) and the local client it launched"},{name:"daemon status",description:"Check daemon + child status (PID, uptime)"},{name:"daemon restart",description:"Graceful restart \u2014 signal daemon to drain and respawn app.js"},{name:"daemon restart --hard",description:"Hard restart \u2014 send SIGTERM directly to app.js (daemon auto-recovers)"},{name:"daemon restart --force",description:"Force restart \u2014 send SIGKILL immediately to app.js"},{name:"daemon restart-self",description:"Stop and restart the daemon process itself"},{name:"restart",description:"Legacy alias for daemon restart (touches $STORE_DIR/.restart)"},{name:"install latest",description:"Install the latest version of Cortex from npm"},{name:"config",description:"Show resolved paths and initialization status"},{name:"doctor",description:"Health-check the install (runtime, login, platform); --fix to repair"},{name:"auth status",description:e("cmd.auth.cli.statusDescription")},{name:"feishu",description:"Manage Feishu user-identity login (login / status / logout)"},{name:"ui enable",description:"Enable the local Web UI endpoint the desktop app connects to"},{name:"client remove",description:"Unregister a remote machine and uninstall its cortex-client"},{name:"path install",description:"Make cortex available in new terminals (remove / status to undo or check)"},{name:"schedule",description:"List, add, edit, pause, resume and remove scheduled tasks"},{name:"memory",description:"Rebuild project memory indexes; report knowledge lifecycle findings"},{name:"tui",description:"Start the Terminal UI (TUI) client for local interaction"}]}function o(){return[{description:"Interactive init",command:"cortex init"},{description:"Init to custom directory",command:"cortex init --home /tmp/my-cortex"},{description:"Show resolved paths",command:"cortex config"},{description:"Health-check the install",command:"cortex doctor"},{description:e("cmd.auth.cli.exampleSummary"),command:"cortex auth status"},{description:e("cmd.auth.cli.exampleJson"),command:"cortex auth status --json"},{description:"Diagnose and auto-repair",command:"cortex doctor --fix"},{description:"Enable the local Web UI endpoint",command:"cortex ui enable"},{description:"Remove a remote machine and its client",command:"cortex client remove --device trainer"},{description:"Add cortex to new terminals",command:"cortex path install"},{description:"List scheduled tasks",command:"cortex schedule list"},{description:"Rebuild every project memory index",command:"cortex memory regen"},{description:"Start the server",command:"cortex start"},{description:"Stop the daemon",command:"cortex daemon stop"},{description:"Check daemon status",command:"cortex daemon status"},{description:"Graceful restart",command:"cortex daemon restart"},{description:"Hard restart app.js",command:"cortex daemon restart --hard"},{description:"Restart daemon itself",command:"cortex daemon restart-self"}]}function h(){return t({name:"cortex",description:"Cortex CLI \u2014 server management and initialization",usage:"cortex <command> [options]",commands:n(),options:[{flag:"--help, -h",description:"Show this help"}],examples:o()})}function u(){return t({name:"cortex auth",description:e("cmd.auth.cli.description"),usage:"cortex auth <status|login|provider> [options]",commands:[{name:"status",description:e("cmd.auth.cli.statusDescription")},{name:"login",description:e("init.auth.loginDescription")},{name:"provider",description:e("provider.cli.description")}],options:[{flag:"--json",description:e("cmd.auth.cli.jsonDescription")},{flag:"--help, -h",description:e("cmd.auth.cli.helpDescription")}],examples:[{description:e("cmd.auth.cli.exampleSummary"),command:"cortex auth status"},{description:e("cmd.auth.cli.exampleJson"),command:"cortex auth status --json"},{description:e("provider.cli.exampleList"),command:"cortex auth provider list"}],labels:{usage:e("cmd.auth.cli.helpUsage"),commands:e("cmd.auth.cli.helpCommands"),options:e("cmd.auth.cli.helpOptions"),examples:e("cmd.auth.cli.helpExamples")}})}export{a,s as b,c,d,m as e,p as f,l as g,h,u as i};
@@ -0,0 +1,27 @@
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{c as D,d as L,e as z}from"./chunk-LEAV3FFG.js";import{k as K}from"./chunk-JJDEQ6N2.js";import{f as B}from"./chunk-R52AVUQB.js";import{a as I,e as U,h as H,j,l as M,m as N}from"./chunk-TX46YMGI.js";import{e as s}from"./chunk-3CPIMAYX.js";import{e as A}from"./chunk-VBN2JSER.js";import{e as F}from"./chunk-NXZS5PEW.js";import{a as _}from"./chunk-Z24SBRJK.js";var V=A("pi-custom-providers");function Se(){return{connectionsPath:I,onChanged:()=>K.refresh()}}function $(e){let t={name:e.provider,api:e.api,models:z({models:e.models}),upstreamUrl:e.baseUrl,hasApiKey:!!e.key,routed:!0};return e.headers&&(t.headers=e.headers),e.compat&&(t.compat=e.compat),t}function W(e){return H(j(e.connectionsPath)).filter(t=>U(t))}function w(e,t){return W(e).find(n=>n.provider===t)??null}function xe(e){return W(e).map($)}function ye(e,t){let n=w(e,t);return n?$(n):null}function Ce(e,t){let n=new Map((e?.models??[]).map(r=>[r.id,r]));return t.map(r=>({...n.get(r.id),...r}))}function Pe(e,t,n){let r={id:e.name,backend:"pi",provider:e.name,api:e.api,baseUrl:e.upstreamUrl,models:Ce(t,e.models)};n&&(r.key=n);let o=e.headers!==void 0?e.headers:t?.headers,i=e.compat!==void 0?e.compat:t?.compat;return o&&Object.keys(o).length>0&&(r.headers=o),i&&Object.keys(i).length>0&&(r.compat=i),r}function ve(e,t){let n=L(t),r=D(n);if(r.length>0)return{ok:!1,errors:r};let o=w(e,n.name),i=t.apiKey===void 0?o?.key:t.apiKey||void 0,m=Pe(n,o,i);try{M(m,e.connectionsPath)}catch(c){return V.warn(`Failed to save custom provider '${n.name}': ${c.message}`),{ok:!1,errors:["write-failed"]}}return e.onChanged?.(),{ok:!0,provider:$(m)}}function $e(e,t){if(!w(e,t))return{ok:!1,errors:["not-found"]};try{N({backend:"pi",id:t},e.connectionsPath)}catch(n){return V.warn(`Failed to remove custom provider '${t}': ${n.message}`),{ok:!1,errors:["write-failed"]}}return e.onChanged?.(),{ok:!0}}import*as b from"fs";import*as le from"os";import*as v from"path";var p=e=>e.before!==e.after;import*as S from"fs";import*as g from"path";var we="# >>> cortex >>>",Te="# <<< cortex <<<",T=/# >>> cortex >>>\n[\s\S]*?\n# <<< cortex <<<\n?/,Ee=e=>`'${e.replace(/'/g,"'\\''")}'`;function ke(e){let t=Ee(e);return`${we}
5
+ case ":\${PATH}:" in *:${t}:*) ;; *) PATH=${t}:"$PATH"; export PATH ;; esac
6
+ ${Te}
7
+ `}function be(e,t,n){return T.test(e)?e.replace(T,()=>t):e?n==="top"?`${t}
8
+ ${e}`:`${e}${e.endsWith(`
9
+ `)?"":`
10
+ `}
11
+ ${t}`:t}function Oe(e){let t=T.exec(e);if(!t)return e;let n=e.slice(0,t.index),r=e.slice(t.index+t[0].length);return n===""?r.replace(/^\n/,""):(n.endsWith(`
12
+
13
+ `)?n.slice(0,-1):n)+r}function Re(e){let t=i=>g.join(e.home,i),n=[{file:t(".profile"),position:"bottom"}];e.exists(t(".bashrc"))&&n.push({file:t(".bashrc"),position:"top"}),e.exists(t(".bash_profile"))&&n.push({file:t(".bash_profile"),position:"bottom"});let r=e.zdotdir||e.home;return(e.platform==="darwin"||e.hasZsh||e.exists(g.join(r,".zshrc")))&&n.push({file:g.join(r,".zshenv"),position:"bottom"}),n}function _e(e){try{return S.readFileSync(e,"utf8")}catch{return null}}function Ae(e,t,n,r){let o=_e(e);return r==="remove"?{target:e,before:o,after:o===null?null:Oe(o)}:{target:e,before:o,after:be(o??"",ke(n),t)}}function X(e){return{plan:(t,n)=>Re(e).map(({file:r,position:o})=>Ae(r,o,t,n)),apply:t=>{for(let n of t.filter(p))n.after!==null&&S.writeFileSync(n.target,n.after)}}}import{spawnSync as Ie}from"child_process";import*as G from"path";var Ue="HKCU\\Environment\\Path",Z=e=>G.win32.normalize(e.trim()).replace(/\\+$/,"").toLowerCase(),J=(e,t)=>e.trim()!==""&&Z(e)===Z(t);function He(e,t){return e?e.split(";").some(n=>J(n,t))?e:`${t};${e}`:t}function je(e,t){if(e===null)return null;let n=e.split(";"),r=n.filter(o=>!J(o,t));return r.length===n.length?e:r.join(";")}var Me=`
14
+ [Console]::OutputEncoding = [Text.Encoding]::UTF8
15
+ $k = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey('Environment')
16
+ if ($k -and ($k.GetValueNames() -contains 'Path')) { [Console]::Out.Write('=' + $k.GetValue('Path', '', 'DoNotExpandEnvironmentNames')) }`,Ne=`
17
+ $k = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Environment')
18
+ $kind = [Microsoft.Win32.RegistryValueKind]::ExpandString
19
+ if ($k.GetValueNames() -contains 'Path') { $kind = $k.GetValueKind('Path') }
20
+ if ($env:CORTEX_USER_PATH) { $k.SetValue('Path', $env:CORTEX_USER_PATH, $kind) } else { $k.DeleteValue('Path', $false) }
21
+ Add-Type -Namespace CortexEnv -Name Native -MemberDefinition '[DllImport("user32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr SendMessageTimeout(IntPtr h, uint m, UIntPtr w, string l, uint f, uint t, out UIntPtr r);'
22
+ $r = [UIntPtr]::Zero
23
+ [void][CortexEnv.Native]::SendMessageTimeout([IntPtr]0xffff, 0x1A, [UIntPtr]::Zero, 'Environment', 2, 5000, [ref]$r)`;function Q(e,t={}){let n=Ie("powershell.exe",["-NoProfile","-NonInteractive","-ExecutionPolicy","Bypass","-Command",e],{encoding:"utf8",windowsHide:!0,env:{...process.env,...t}});if(n.status!==0)throw new Error(`powershell failed: ${(n.stderr||String(n.error??"")).trim()}`);return n.stdout}function De(){let e=Q(Me);return e.startsWith("=")?e.slice(1):null}function Le(e){Q(Ne,{CORTEX_USER_PATH:e??""})}function q(e={read:De,write:Le}){return{plan:(t,n)=>{let r=e.read(),o=n==="add"?He(r,t):je(r,t);return[{target:Ue,before:r,after:o}]},apply:t=>{for(let n of t.filter(p))e.write(n.after)}}}import*as a from"fs";import*as u from"path";var ee="cortex-managed-shim",te=`${ee}: written by \`cortex path install\`, refreshed when the daemon starts.`;function h(e){return u.join(e,"runtime","bin")}function ne(e){let t=JSON.parse(a.readFileSync(u.join(e,"package.json"),"utf8"));return Object.entries(t.bin??{}).map(([n,r])=>({name:n,entry:u.join(e,r)}))}var x=e=>`'${e.replace(/'/g,"'\\''")}'`;function Y(e,t,n,r){return["#!/bin/sh",`# ${te}`,`if [ -z "\${CORTEX_HOME:-}" ]; then CORTEX_HOME=${x(n)}; fi`,"export CORTEX_HOME",`PATH=${x(r)}:"$PATH"; export PATH`,`exec ${x(e)} ${x(t)} "$@"`,""].join(`
24
+ `)}function ze(e,t,n){let r=o=>o.replace(/%/g,"%%");return["@echo off",`rem ${te}`,"setlocal",`if not defined CORTEX_HOME set "CORTEX_HOME=${r(n)}"`,`set "PATH=${r(u.win32.dirname(e))};%PATH%"`,`"${r(e)}" "${r(t)}" %*`,""].join(`\r
25
+ `)}var y=e=>e.replace(/\\/g,"/"),Fe=e=>y(e).replace(/^([A-Za-z]):/,(t,n)=>`/${n.toLowerCase()}`);function re(e,t=process.platform){if(t!=="win32"){let n=u.posix.dirname(e.node);return e.bins.map(({name:r,entry:o})=>({file:r,content:Y(e.node,o,e.home,n)}))}return e.bins.flatMap(({name:n,entry:r})=>[{file:`${n}.cmd`,content:ze(e.node,r,e.home)},{file:n,content:Y(y(e.node),y(r),y(e.home),Fe(u.win32.dirname(e.node)))}])}function oe(e){try{return a.readFileSync(e,"utf8")}catch{return null}}function d(e){let t;try{t=a.readdirSync(e)}catch{return[]}return t.filter(n=>oe(u.join(e,n))?.includes(ee)).sort()}function C(e,t){return t.filter(n=>oe(u.join(e,n.file))!==n.content).map(n=>n.file)}function E(e,t){a.mkdirSync(e,{recursive:!0});let n=C(e,t);for(let o of n){let i=t.find(m=>m.file===o);a.writeFileSync(u.join(e,o),i.content,{mode:493}),a.chmodSync(u.join(e,o),493)}let r=new Set(t.map(o=>o.file));for(let o of d(e))r.has(o)||a.unlinkSync(u.join(e,o));return n}function ie(e){let t=d(e);for(let n of t)a.unlinkSync(u.join(e,n));try{a.readdirSync(e).length===0&&a.rmdirSync(e)}catch{}return t}function se(e,t){return d(e).length===0?[]:E(e,t)}import*as f from"fs";import*as l from"path";var me=e=>l.join(e,"runtime","terminal-cli.json");function ue(e){try{let t=JSON.parse(f.readFileSync(me(e),"utf8"))?.state;return t==="installed"||t==="removed"?t:null}catch{return null}}function k(e,t){let n=me(e);f.mkdirSync(l.dirname(n),{recursive:!0}),f.writeFileSync(n,`${JSON.stringify({state:t,updated_at:new Date().toISOString()},null,2)}
26
+ `)}function ae(e,t){let n=e;try{n=f.realpathSync(e)}catch{}let o=(t==="win32"?l.win32:l.posix).normalize(n).replace(/[\\/]+$/,"");return t==="win32"?o.toLowerCase():o}function ce(e,t,n){let r=F(t,"@cortex-agent/server",n);if(!r)return!1;let o=n==="win32"?l.win32:l.posix;return ae(r,n)===ae(o.join(e,"runtime","prefix"),n)}var O=e=>e==="win32"?v.win32:v.posix,P=(e,t)=>{let n=O(t).normalize(e).replace(/[\\/]+$/,"");return t==="win32"?n.toLowerCase():n};function fe(e,t,n,r=[]){let o=O(n),i=new Set(r.map(c=>P(c,n)));return t.split(o.delimiter).filter(c=>c&&!i.has(P(c,n))).flatMap(c=>e.map(ge=>o.join(c,ge))).filter(c=>b.existsSync(c))}function Ke(e,t){return e==="win32"?q():X({home:le.homedir(),platform:e,zdotdir:process.env.ZDOTDIR,exists:b.existsSync,hasZsh:fe(["zsh"],t,e).length>0})}function Et(e){let t=process.platform,n=process.env.PATH??"";return{home:e,node:process.execPath,installRoot:_,platform:t,pathEnv:n,registrar:Ke(t,n)}}function R(e){return re({node:e.node,home:e.home,bins:ne(e.installRoot)},e.platform)}var pe=e=>e.map(t=>({target:t.target,changed:p(t)}));function Be(e,t){let n=e.platform==="win32"?["cortex.cmd","cortex.exe","cortex"]:["cortex"];return fe(n,e.pathEnv,e.platform,[t,...B(e.node,e.installRoot,e.platform)])}function Ve(e,t,n,r){e.registrar.apply(r);let o=E(t,n);return k(e.home,"installed"),o}function We(e,t){let n=h(e.home),r=R(e),o=e.registrar.plan(n,"add"),i=t?C(n,r):Ve(e,n,r,o);return{ok:!0,action:"install",dry_run:t,dir:n,shims:r.map(m=>m.file),written:i,path_targets:pe(o),shadowed:Be(e,n)}}function kt(e,t){let n=h(e.home),r=e.registrar.plan(n,"remove"),o=t?d(n):ie(n);return t||(e.registrar.apply(r),k(e.home,"removed")),{ok:!0,action:"remove",dry_run:t,dir:n,removed:o,path_targets:pe(r)}}function bt(e){let t=h(e.home),n=d(t),r=n.length>0?C(t,R(e)):[],o=e.registrar.plan(t,"add").map(m=>({target:m.target,registered:!p(m)})),i=e.pathEnv.split(O(e.platform).delimiter).some(m=>m&&P(m,e.platform)===P(t,e.platform));return{ok:!0,dir:t,installed:n.length>0,shims:n,stale:r,path_targets:o,on_current_path:i}}function Ot(e){if(ue(e.home)==="removed")return{action:"skipped",files:[]};let t=h(e.home);return d(t).length===0&&ce(e.home,e.installRoot,e.platform)?{action:"installed",files:We(e,!1).written}:{action:"refreshed",files:se(t,R(e))}}function de(e){return s(`cmd.auth.state.${e}`)}function he(e){return s(`cmd.auth.type.${e??"none"}`)}function Xe(e){return e?s("cmd.auth.expires",{time:e}):""}function Ze(e){return s("cmd.auth.credentialLine",{authType:he(e.authType),state:de(e.state),source:e.source??"\u2014",expires:Xe(e.expiresAt)})}function Ge(e){return e.connection?s("cmd.auth.accountName",{label:e.label,id:e.connection}):e.label}function Je(e){let t=s(`cmd.auth.backend.${e.backend}`),n=e.identity?.email,r=s("cmd.auth.accountLine",{backend:t,label:Ge(e),authType:he(e.authType),state:de(e.state),identity:n?s("cmd.auth.identity",{email:n}):"",inUse:e.inUse&&!e.connection?s("cmd.auth.inUse"):""});return e.credentials.length===0?[r]:[r,s("cmd.auth.credentials"),...e.credentials.map(Ze)]}function Qe(e){return e.backend==="claude"||!!e.connection||e.inUse||e.state!=="logged-out"||e.credentials.length>0}function At(e){let t=e.piRuntime.available?s("cmd.auth.runtimeAvailable"):s("cmd.auth.runtimeUnavailable"),n=e.piRuntime.version?s("cmd.auth.runtimeVersion",{version:e.piRuntime.version}):"",r=e.accounts.filter(Qe),o=e.accounts.length-r.length,i=[s("cmd.auth.heading"),s("cmd.auth.generatedAt",{time:e.generatedAt}),s("cmd.auth.runtimeLine",{status:t,version:n}),...r.flatMap(Je)];return o>0&&i.push(s("cmd.auth.hiddenLoggedOut",{n:o})),i.join(`
27
+ `)}import{execFile as qe}from"node:child_process";var Ye=["-o","BatchMode=yes","-o","ConnectTimeout=5","-o","StrictHostKeyChecking=no"];function et(e,t){return new Promise((n,r)=>{qe("ssh",[...e],{timeout:t},(o,i,m)=>{if(!o)return n(i.trim());r(new Error(m.trim()||(o.killed?`ssh timed out after ${t}ms`:o.message)))})})}function Ht(e,t,n=15e3){return et([...Ye,e,t],n)}export{At as a,Se as b,xe as c,ye as d,ve as e,$e as f,Ye as g,et as h,Ht as i,Et as j,We as k,kt as l,bt as m,Ot as n};
@@ -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{$ as z,J as L,K as M,N as C,O as V,Q as w,R as P,T as m,Y as $,Z as d,aa as O,b as _,ba as A,ca as U,d as E,da as x,ea as B,fa as H,i as S,j as v,k,n as f,p as R,q,s as I,u as T}from"./chunk-TMV2ZDOI.js";var b=class{constructor(e){this._server=e}requestStream(e,t,i){return this._server.requestStream(e,t,i)}createMessageStream(e,t){let i=this._server.getClientCapabilities();if((e.tools||e.toolChoice)&&!i?.sampling?.tools)throw new Error("Client does not support sampling tools capability.");if(e.messages.length>0){let s=e.messages[e.messages.length-1],r=Array.isArray(s.content)?s.content:[s.content],a=r.some(o=>o.type==="tool_result"),n=e.messages.length>1?e.messages[e.messages.length-2]:void 0,p=n?Array.isArray(n.content)?n.content:[n.content]:[],c=p.some(o=>o.type==="tool_use");if(a){if(r.some(o=>o.type!=="tool_result"))throw new Error("The last message must contain only tool_result content if any is present");if(!c)throw new Error("tool_result blocks are not matching any tool_use from the previous message")}if(c){let o=new Set(p.filter(h=>h.type==="tool_use").map(h=>h.id)),l=new Set(r.filter(h=>h.type==="tool_result").map(h=>h.toolUseId));if(o.size!==l.size||![...o].every(h=>l.has(h)))throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match")}}return this.requestStream({method:"sampling/createMessage",params:e},w,t)}elicitInputStream(e,t){let i=this._server.getClientCapabilities(),s=e.mode??"form";switch(s){case"url":{if(!i?.elicitation?.url)throw new Error("Client does not support url elicitation.");break}case"form":{if(!i?.elicitation?.form)throw new Error("Client does not support form elicitation.");break}}let r=s==="form"&&e.mode===void 0?{...e,mode:"form"}:e;return this.requestStream({method:"elicitation/create",params:r},m,t)}async getTask(e,t){return this._server.getTask({taskId:e},t)}async getTaskResult(e,t,i){return this._server.getTaskResult({taskId:e},t,i)}async listTasks(e,t){return this._server.listTasks(e?{cursor:e}:void 0,t)}async cancelTask(e,t){return this._server.cancelTask({taskId:e},t)}};var j=class extends z{constructor(e,t){super(t),this._serverInfo=e,this._loggingLevels=new Map,this.LOG_LEVEL_SEVERITY=new Map(C.options.map((i,s)=>[i,s])),this.isMessageIgnored=(i,s)=>{let r=this._loggingLevels.get(s);return r?this.LOG_LEVEL_SEVERITY.get(i)<this.LOG_LEVEL_SEVERITY.get(r):!1},this._capabilities=t?.capabilities??{},this._instructions=t?.instructions,this._jsonSchemaValidator=t?.jsonSchemaValidator??new A,this.setRequestHandler(q,i=>this._oninitialize(i)),this.setNotificationHandler(I,()=>this.oninitialized?.()),this._capabilities.logging&&this.setRequestHandler(V,async(i,s)=>{let r=s.sessionId||s.requestInfo?.headers["mcp-session-id"]||void 0,{level:a}=i.params,n=C.safeParse(a);return n.success&&this._loggingLevels.set(r,n.data),{}})}get experimental(){return this._experimental||(this._experimental={tasks:new b(this)}),this._experimental}registerCapabilities(e){if(this.transport)throw new Error("Cannot register capabilities after connecting to transport");this._capabilities=O(this._capabilities,e)}setRequestHandler(e,t){let s=E(e)?.method;if(!s)throw new Error("Schema is missing a method literal");let r=S(s);if(typeof r!="string")throw new Error("Schema method literal must be a string");if(r==="tools/call"){let n=async(p,c)=>{let o=_(M,p);if(!o.success){let u=o.error instanceof Error?o.error.message:String(o.error);throw new d(f.InvalidParams,`Invalid tools/call request: ${u}`)}let{params:l}=o.data,h=await Promise.resolve(t(p,c));if(l.task){let u=_(T,h);if(!u.success){let G=u.error instanceof Error?u.error.message:String(u.error);throw new d(f.InvalidParams,`Invalid task creation result: ${G}`)}return u.data}let g=_(L,h);if(!g.success){let u=g.error instanceof Error?g.error.message:String(g.error);throw new d(f.InvalidParams,`Invalid tools/call result: ${u}`)}return g.data};return super.setRequestHandler(e,n)}return super.setRequestHandler(e,t)}assertCapabilityForMethod(e){switch(e){case"sampling/createMessage":if(!this._clientCapabilities?.sampling)throw new Error(`Client does not support sampling (required for ${e})`);break;case"elicitation/create":if(!this._clientCapabilities?.elicitation)throw new Error(`Client does not support elicitation (required for ${e})`);break;case"roots/list":if(!this._clientCapabilities?.roots)throw new Error(`Client does not support listing roots (required for ${e})`);break;case"ping":break}}assertNotificationCapability(e){switch(e){case"notifications/message":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"notifications/resources/updated":case"notifications/resources/list_changed":if(!this._capabilities.resources)throw new Error(`Server does not support notifying about resources (required for ${e})`);break;case"notifications/tools/list_changed":if(!this._capabilities.tools)throw new Error(`Server does not support notifying of tool list changes (required for ${e})`);break;case"notifications/prompts/list_changed":if(!this._capabilities.prompts)throw new Error(`Server does not support notifying of prompt list changes (required for ${e})`);break;case"notifications/elicitation/complete":if(!this._clientCapabilities?.elicitation?.url)throw new Error(`Client does not support URL elicitation (required for ${e})`);break;case"notifications/cancelled":break;case"notifications/progress":break}}assertRequestHandlerCapability(e){if(this._capabilities)switch(e){case"completion/complete":if(!this._capabilities.completions)throw new Error(`Server does not support completions (required for ${e})`);break;case"logging/setLevel":if(!this._capabilities.logging)throw new Error(`Server does not support logging (required for ${e})`);break;case"prompts/get":case"prompts/list":if(!this._capabilities.prompts)throw new Error(`Server does not support prompts (required for ${e})`);break;case"resources/list":case"resources/templates/list":case"resources/read":if(!this._capabilities.resources)throw new Error(`Server does not support resources (required for ${e})`);break;case"tools/call":case"tools/list":if(!this._capabilities.tools)throw new Error(`Server does not support tools (required for ${e})`);break;case"tasks/get":case"tasks/list":case"tasks/result":case"tasks/cancel":if(!this._capabilities.tasks)throw new Error(`Server does not support tasks capability (required for ${e})`);break;case"ping":case"initialize":break}}assertTaskCapability(e){x(this._clientCapabilities?.tasks?.requests,e,"Client")}assertTaskHandlerCapability(e){this._capabilities&&U(this._capabilities.tasks?.requests,e,"Server")}async _oninitialize(e){let t=e.params.protocolVersion;return this._clientCapabilities=e.params.capabilities,this._clientVersion=e.params.clientInfo,{protocolVersion:k.includes(t)?t:v,capabilities:this.getCapabilities(),serverInfo:this._serverInfo,...this._instructions&&{instructions:this._instructions}}}getClientCapabilities(){return this._clientCapabilities}getClientVersion(){return this._clientVersion}getCapabilities(){return this._capabilities}async ping(){return this.request({method:"ping"},R)}async createMessage(e,t){if((e.tools||e.toolChoice)&&!this._clientCapabilities?.sampling?.tools)throw new Error("Client does not support sampling tools capability.");if(e.messages.length>0){let i=e.messages[e.messages.length-1],s=Array.isArray(i.content)?i.content:[i.content],r=s.some(c=>c.type==="tool_result"),a=e.messages.length>1?e.messages[e.messages.length-2]:void 0,n=a?Array.isArray(a.content)?a.content:[a.content]:[],p=n.some(c=>c.type==="tool_use");if(r){if(s.some(c=>c.type!=="tool_result"))throw new Error("The last message must contain only tool_result content if any is present");if(!p)throw new Error("tool_result blocks are not matching any tool_use from the previous message")}if(p){let c=new Set(n.filter(l=>l.type==="tool_use").map(l=>l.id)),o=new Set(s.filter(l=>l.type==="tool_result").map(l=>l.toolUseId));if(c.size!==o.size||![...c].every(l=>o.has(l)))throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match")}}return e.tools?this.request({method:"sampling/createMessage",params:e},P,t):this.request({method:"sampling/createMessage",params:e},w,t)}async elicitInput(e,t){switch(e.mode??"form"){case"url":{if(!this._clientCapabilities?.elicitation?.url)throw new Error("Client does not support url elicitation.");let s=e;return this.request({method:"elicitation/create",params:s},m,t)}case"form":{if(!this._clientCapabilities?.elicitation?.form)throw new Error("Client does not support form elicitation.");let s=e.mode==="form"?e:{...e,mode:"form"},r=await this.request({method:"elicitation/create",params:s},m,t);if(r.action==="accept"&&r.content&&s.requestedSchema)try{let n=this._jsonSchemaValidator.getValidator(s.requestedSchema)(r.content);if(!n.valid)throw new d(f.InvalidParams,`Elicitation response content does not match requested schema: ${n.errorMessage}`)}catch(a){throw a instanceof d?a:new d(f.InternalError,`Error validating elicitation response: ${a instanceof Error?a.message:String(a)}`)}return r}}}createElicitationCompletionNotifier(e,t){if(!this._clientCapabilities?.elicitation?.url)throw new Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");return()=>this.notification({method:"notifications/elicitation/complete",params:{elicitationId:e}},t)}async listRoots(e,t){return this.request({method:"roots/list",params:e},$,t)}async sendLoggingMessage(e,t){if(this._capabilities.logging&&!this.isMessageIgnored(e.level,t))return this.notification({method:"notifications/message",params:e})}async sendResourceUpdated(e){return this.notification({method:"notifications/resources/updated",params:e})}async sendResourceListChanged(){return this.notification({method:"notifications/resources/list_changed"})}async sendToolListChanged(){return this.notification({method:"notifications/tools/list_changed"})}async sendPromptListChanged(){return this.notification({method:"notifications/prompts/list_changed"})}};import N from"node:process";var D=class{constructor(e=N.stdin,t=N.stdout,i){this._stdin=e,this._stdout=t,this._started=!1,this._ondata=s=>{try{this._readBuffer.append(s),this.processReadBuffer()}catch(r){this.onerror?.(r),this.close().catch(()=>{})}},this._onerror=s=>{this.onerror?.(s)},this._readBuffer=new B({maxBufferSize:i?.maxBufferSize})}async start(){if(this._started)throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");this._started=!0,this._stdin.on("data",this._ondata),this._stdin.on("error",this._onerror)}processReadBuffer(){for(;;)try{let e=this._readBuffer.readMessage();if(e===null)break;this.onmessage?.(e)}catch(e){this.onerror?.(e)}}async close(){this._stdin.off("data",this._ondata),this._stdin.off("error",this._onerror),this._stdin.listenerCount("data")===0&&this._stdin.pause(),this._readBuffer.clear(),this.onclose?.()}send(e){return new Promise(t=>{let i=H(e);this._stdout.write(i)?t():this._stdout.once("drain",t)})}};export{j as a,D as b};
@@ -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 e}from"./chunk-OSEIQ7SS.js";var r;function i(t){r=t}var n=()=>e(async()=>r??await import("./bedrock-converse-stream-5UPX4NTQ.js"));export{i as a,n as b};
4
+ import{b as e}from"./chunk-OSEIQ7SS.js";var r;function i(t){r=t}var n=()=>e(async()=>r??await import("./bedrock-converse-stream-WNUGNZ27.js"));export{i as a,n as b};
@@ -0,0 +1,8 @@
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{n as f,v as d,y as m,z as g}from"./chunk-BUZQBTV2.js";import{a as l}from"./chunk-NRD57ICT.js";import{a as p}from"./chunk-Z24SBRJK.js";import{mkdirSync as M,readFileSync as z,rmSync as N,writeFileSync as F}from"node:fs";import _ from"node:path";var h=3600*1e3,H=20,A=_.join(f,"crash-limits.json");function P(e,t){try{let r=JSON.parse(z(e,"utf8"));return r.day===t&&r.groups&&typeof r.sentToday=="number"?r:{day:t,sentToday:0,groups:r.groups??{}}}catch{return{day:t,sentToday:0,groups:{}}}}function E(e,t,r){for(let[s,n]of Object.entries(t.groups))r-n.lastSentAt>24*h&&n.suppressed===0&&delete t.groups[s];try{M(_.dirname(e),{recursive:!0}),F(e,JSON.stringify(t),"utf8")}catch{}}function S(e,t=Date.now(),r=A){let s=P(r,new Date(t).toISOString().slice(0,10)),n=s.groups[e]??{lastSentAt:0,suppressed:0};return t-n.lastSentAt<h||s.sentToday>=H?(s.groups[e]={...n,suppressed:n.suppressed+1},E(r,s,t),{send:!1,suppressed:n.suppressed+1}):(s.groups[e]={lastSentAt:t,suppressed:0},s.sentToday+=1,E(r,s,t),{send:!0,suppressed:n.suppressed})}function R(e=A){N(e,{force:!0})}var Z=/ at (\S+):(\d+):\d+\s*$/,K=/^\s*at (\S+):(\d+):\d+\s*$/,v=/^[A-Za-z0-9._-]+$/,D=/^[A-Za-z0-9_-]+-\d+\.\d+\.\d+[A-Za-z0-9.+-]*$/,G=/^(?:core|std|alloc|proc_macro|test)$/;function x(e){return!/^(?:[A-Za-z]:\/|\/|~)/.test(e)}function X(e){return e.split("/").every(s=>v.test(s)&&s!=="..")&&e.length<=120?e:null}function j(e){let t=e.lastIndexOf("/src/");if(t<0)return null;let r=e.slice(0,t).split("/").pop()??"";return D.test(r)||e.includes("/library/")&&G.test(r)?`${r}/${e.slice(t+1)}`:e.slice(t+1)}function U(e){let t=e.replace(/\\/g,"/").replace(/^\.\//,"");return X(x(t)?t:j(t)??"")}function T(e){let t=e?U(e[1]):null;return t?`panic@${t}:${e[2]}`:null}function W(e){for(let t of e.split(`
5
+ `)){let r=K.exec(t);if(r&&x(r[1].replace(/\\/g,"/")))return T(r)}return null}function y(e,t){return T(Z.exec(e))??W(t)??"panic@unknown"}import i from"node:os";var V=300,C=30,Y=8e3;function B(){try{return i.userInfo().username}catch{return""}}function J(){return{installRoot:p,homeDir:i.homedir(),username:B(),hostname:i.hostname()}}function I(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function $(e){let t=e.replace(/\\/g,"/").replace(/\/+$/,""),r=t.replace(/\//g,"\\");return[...new Set([t,r])].filter(s=>s.length>1)}function q(e,t){let r=e;for(let s of $(t)){let n=new RegExp(`(?:file:\\/\\/\\/?)?${I(s)}([\\\\/][^\\s:'"()<>]*)`,"g");r=r.replace(n,(o,c)=>c.slice(1).replace(/\\/g,"/"))}return r}var Q=/\b([a-z][a-z0-9+.-]*):\/\/([^\s/?#'"()<>]*)([^\s?#'"()<>]*)(?:[?#][^\s'"()<>]*)?/gi,ee=new Set(["localhost","127.0.0.1","[::1]"]);function te(e){return e.replace(Q,(t,r,s,n)=>{let o=s.replace(/^[^@]*@/,""),c=o.replace(/:\d+$/,"").toLowerCase(),a=r.toLowerCase()==="cortexui"||ee.has(c);return r.toLowerCase()==="file"?"<path>":`${r}://${a?o:"<host>"}${n}`})}var re=/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g,se=/\b(?:sk|pk|rk|ghp|gho|ghs|ghu|github_pat|xox[abposr]|glpat|AKIA|AIza)[-_A-Za-z0-9]{8,}/g,ne=/\b[0-9a-fA-F]{32,}\b/g,oe=/[A-Za-z0-9+_=-]{32,}/g,ce=/\b(?!127\.0\.0\.1\b)(?!0\.0\.0\.0\b)(?:\d{1,3}\.){3}\d{1,3}\b/g;function ae(e){return e.replace(re,"<email>").replace(se,"<secret>").replace(ne,"<secret>").replace(oe,t=>/\d/.test(t)&&/[A-Za-z]/.test(t)?"<secret>":t).replace(ce,"<ip>")}var ie=/(?<![\w.:/\\<>-])\/(?:[^\s:'"()<>,;]+)/g,ue=/\b[A-Za-z]:[\\/][^\s:'"()<>,;]*/g,pe=/\\\\[^\s\\:'"()<>]+\\[^\s:'"()<>,;]*/g;function le(e){return e.replace(pe,"<path>").replace(ue,"<path>").replace(ie,"<path>")}function fe(e,t){let r=e;for(let n of $(t.homeDir))r=r.split(n).join("<home>");let s=[[t.hostname,"<host>"],[t.username,"<user>"]];for(let[n,o]of[...s].sort((c,a)=>a[0].length-c[0].length))n.length<3||(r=r.replace(new RegExp(`(?<![A-Za-z0-9])${I(n)}(?![A-Za-z0-9])`,"gi"),o));return r}function b(e,t=J()){let r=q(e,t.installRoot);return fe(le(ae(te(r))),t)}function u(e,t){return b(e,t).slice(0,V)}function k(e,t){let r=b(e,t).split(`
6
+ `),s=r.findIndex(o=>/^\s*at\s/.test(o));return(s===-1?r.slice(0,C+1):r.slice(0,s+C)).join(`
7
+ `).slice(0,Y)}var de=/^\s*at\s+(?:(\S+)\s+)?\(?((?:dist|src)\/[^\s:()]+)/,me=/(?:^|[\s@(])((?:[a-z]+:\/\/[^\s/]+)?\/assets\/[^\s:()]+)/;function O(e,t){for(let r of t.split(`
8
+ `)){let s=de.exec(r);if(s)return`${e}@${s[2]}${s[1]?`#${s[1]}`:""}`.slice(0,200);let n=me.exec(r);if(n)return`${e}@${n[1].replace(/^[a-z]+:\/\/[^/]+/,"")}`.slice(0,200)}return`${e}@unknown`.slice(0,200)}m({wipe:()=>R()});function L(e){return e instanceof Error?e.name||e.constructor?.name||"Error":typeof e=="object"&&e!==null?"NonErrorObject":`Non${typeof e}`}var w="running";function ze(e){w=e}function ge(e){return e instanceof Error?{errorName:L(e),message:e.message??"",stack:e.stack??""}:{errorName:L(e),message:`phase:${w}`,stack:""}}function Ee(e,t=0){let r=u(e.errorName).slice(0,80)||"Error",s=k(e.stack);return{type:"crash",at:(e.at??new Date).toISOString(),component:e.component,kind:e.kind,errorName:r,message:u(e.message),stack:s,groupKey:he(e,r,s),uptimeS:e.uptimeS??null,route:e.route?.slice(0,80)??null,buildStamp:e.buildStamp?.slice(0,60)??null,client:e.client??null,exit:e.exit??null,suppressed:t,version:l.slice(0,40)}}function _e(e){return e?.signal?`ChildExit@${e.signal}`:`ChildExit@code:${e?.code??"unknown"}`}function he(e,t,r){return e.kind==="childExit"?_e(e.exit):e.kind==="panic"?y(e.message,e.stack):O(t,r)}function Ae(e){try{if(!d())return;let t=Ee(e),r=S(t.groupKey);if(!r.send)return;g({...t,suppressed:r.suppressed},{urgent:!0})}catch{}}function Ne(e,t,r){Ae({component:e,kind:t,...ge(r),uptimeS:Math.round(process.uptime())})}export{u as a,k as b,O as c,ze as d,Ae as e,Ne as f};
@@ -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{e as c}from"./chunk-XPPZ6Y3X.js";import{e as a}from"./chunk-AVXDF7AG.js";import{j as l}from"./chunk-Z24SBRJK.js";import{a as S}from"./chunk-VPVSKJGX.js";import{e as g}from"./chunk-WHC7AYZD.js";var u=g(S(),1),E=new Set(["CLAUDE_CODE_OAUTH_TOKEN_EXPIRES_AT"]);function O(n,t=process.env){let e={};u.config({path:n,processEnv:e});for(let r of E)delete e[r];u.populate(t,e)}var x="CORTEX_CHILD_EXIT";function I(n){return JSON.stringify(n)}function y(n){if(!n)return null;try{let t=JSON.parse(n);if(typeof t.uptimeMs!="number"||typeof t.backoffMs!="number")return null;let e=Number.isInteger(t.code)?t.code:null,r=typeof t.signal=="string"?t.signal.slice(0,20):null;return{code:e,signal:r,uptimeMs:Math.max(0,t.uptimeMs),backoffMs:Math.max(0,Math.round(t.backoffMs))}}catch{return null}}function M(n=process.env){let t=y(n[x]);!t||t.code===0&&!t.signal||c({component:"server",kind:"childExit",errorName:"ChildExit",message:t.signal?`signal ${t.signal}`:`exit code ${t.code??"unknown"}`,stack:"",uptimeS:Math.round(t.uptimeMs/1e3),exit:{code:t.code,signal:t.signal,backoffMs:t.backoffMs}})}import{existsSync as b,readFileSync as h}from"node:fs";import*as d from"node:path";var p=d.join(l,"daemon-rebuild.json");function C(n){let t=(n.now??(()=>new Date))().toISOString();return{status:"running",reason:n.reason,current:null,steps:n.names.map(e=>({name:e,status:"pending",detail:null,startedAt:null,endedAt:null})),startedAt:t,updatedAt:t,endedAt:null,detail:null,daemonPid:n.daemonPid}}function f(n,t,e,r){return{...n,updatedAt:r,steps:n.steps.map(o=>o.name===t?{...o,...e}:o)}}function P(n,t,e=()=>new Date){let r=e().toISOString();return{...f(n,t,{status:"running",startedAt:r,endedAt:null},r),current:t}}function w(n,t,e,r=null,o=()=>new Date){let s=o().toISOString(),i=f(n,t,{status:e,detail:r,endedAt:s},s);return i.current!==t?i:{...i,current:i.steps.filter(m=>m.status==="running").at(-1)?.name??null}}function L(n,t,e=null,r=()=>new Date){let o=r().toISOString();return{...n,status:t,current:null,detail:e,updatedAt:o,endedAt:o,steps:n.steps.map(s=>s.status==="pending"?{...s,status:"skipped"}:s)}}function A(n){if(!n||typeof n!="object")return!1;let t=n;return typeof t.status=="string"&&typeof t.reason=="string"&&typeof t.startedAt=="string"&&Array.isArray(t.steps)}function T(n=p){try{if(!b(n))return null;let t=JSON.parse(h(n,"utf8"));return A(t)?t:null}catch{return null}}function F(n,t=p){try{return a(t,JSON.stringify(n,null,2)),!0}catch{return!1}}export{O as a,x as b,I as c,M as d,C as e,P as f,w as g,L as h,T as i,F as j};