@wirecat/cli-core 3.1.0-dev → 3.2.0-dev

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 (351) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/dist/background/daily-archive-timer.d.ts +1 -1
  3. package/dist/bundle/{agent-RMLBQXJF-CuqJBQqf.js → agent-J75WGZEV-K_l-bQ-h.js} +5 -5
  4. package/dist/bundle/{all-profiles-3GEKS7PR-Bi_zb5_-.js → all-profiles-3GEKS7PR-BohqgNvP.js} +6 -6
  5. package/dist/bundle/{anthropic-EVM6I7MZ-BWI01JgC.js → anthropic-EVM6I7MZ-CqB3j7dB.js} +2 -2
  6. package/dist/bundle/{app-server-76XGUZHU-__6SrMhc.js → app-server-5BL62GAL-Osw_tMej.js} +20 -15
  7. package/dist/bundle/{bun-AWMVU72K-COHrAYHA.js → bun-AWMVU72K-Bk0oN5Sm.js} +2 -2
  8. package/dist/bundle/{bun-sqlite-CYFVVXXR-r_kJOwku.js → bun-sqlite-CYFVVXXR-4iGlaI9X.js} +3 -3
  9. package/dist/bundle/{chunk-4ZM6SE7G-DNDxhi8l.js → chunk-4HGRFFTO-fNvELOjI.js} +330 -56
  10. package/dist/bundle/{chunk-6G6TIMKP-CoVYG_I3.js → chunk-6G6TIMKP-Byea1UGV.js} +4 -4
  11. package/dist/bundle/{chunk-M5CHOMME-BIcASmVb.js → chunk-6OLVBOBX-Ch2rblZk.js} +17 -11
  12. package/dist/bundle/{chunk-CCFBHR4O-DAuKd8rI.js → chunk-CCFBHR4O-Bhxq5eaI.js} +1 -1
  13. package/dist/bundle/{chunk-DDXCCEI4-CHLrblc1.js → chunk-DDXCCEI4-CBg_l4Ro.js} +2 -2
  14. package/dist/bundle/{chunk-DZPIGAKP-nrRAPNTz.js → chunk-DZPIGAKP-BZy6DShN.js} +1 -1
  15. package/dist/bundle/{chunk-ERNCGLKE-4JdU74o6.js → chunk-ERNCGLKE-D3HStkJC.js} +1 -1
  16. package/dist/bundle/{chunk-GBNNGOIB-DVUFOYzA.js → chunk-GBNNGOIB-DS3rusdH.js} +5 -5
  17. package/dist/bundle/{chunk-GJTANPFI-5L6Owk-H.js → chunk-GJTANPFI-DlUMnFUQ.js} +3 -3
  18. package/dist/bundle/{chunk-6ZUQA7OL-ofpF0AvH.js → chunk-GRGGW52W-Fkw6omOx.js} +5 -5
  19. package/dist/bundle/{chunk-KSUALCA7-DB6cYuSU.js → chunk-KSUALCA7-SMNQ85c6.js} +1 -1
  20. package/dist/bundle/{chunk-LBVI4Z2X-COUoJmWU.js → chunk-LBVI4Z2X-D9_8iC1S.js} +1 -1
  21. package/dist/bundle/{chunk-M23BPYSL-ChiHsEsy.js → chunk-M23BPYSL-ByTcRixP.js} +3 -3
  22. package/dist/bundle/{chunk-Z3ZVBBWR-whNBW-iH.js → chunk-M4KMNZN6-CBeUwDlF.js} +2 -2
  23. package/dist/bundle/{chunk-NG7F5L7N-BKCEXGxy.js → chunk-NG7F5L7N-Ch_ERSNz.js} +1 -1
  24. package/dist/bundle/{chunk-NX2VS2ER-DS6Urg3e.js → chunk-NX2VS2ER-CWN0zXqZ.js} +1 -1
  25. package/dist/bundle/{chunk-O2HOOK7X-Dboq6vxP.js → chunk-O2HOOK7X-Dyw_Dcql.js} +4 -4
  26. package/dist/bundle/{chunk-PSD6373C-wlicX185.js → chunk-PSD6373C-DgL0rhKe.js} +1 -1
  27. package/dist/bundle/{chunk-RTCT4N7Y-Dn-lP1zF.js → chunk-RTCT4N7Y-BEZ3cJ5d.js} +1 -1
  28. package/dist/bundle/{chunk-S34BE7ZC-p6NeYmqQ.js → chunk-S34BE7ZC-BO0yaVoX.js} +1 -1
  29. package/dist/bundle/{chunk-E6KETVFF-wOOXf4op.js → chunk-SRAGL5LI-CKhhwRrx.js} +5 -5
  30. package/dist/bundle/{chunk-T6V6LFHT-Dwv7XUuC.js → chunk-T6V6LFHT-BazTZ25Y.js} +1 -1
  31. package/dist/bundle/{chunk-ACWFPMZF-DkR70AOW.js → chunk-TFRAD7RO-BVAK9frq.js} +50 -4
  32. package/dist/bundle/{chunk-UH2H3OLE-R_6H5D7o.js → chunk-UH2H3OLE-QNxQo07O.js} +1 -1
  33. package/dist/bundle/{chunk-UQJGYQ56-CANeLx5l.js → chunk-UQJGYQ56-PoYTv6WX.js} +1 -1
  34. package/dist/bundle/{chunk-VKZDPPVI-d7RS_QOW.js → chunk-VKZDPPVI-BOmnhxVJ.js} +2 -2
  35. package/dist/bundle/{chunk-UNGNJ255-CtLEiDap.js → chunk-W3AAOYWE-Cyx1kZsd.js} +7 -7
  36. package/dist/bundle/{chunk-WXEJSLMO-DbSxVCq9.js → chunk-WXEJSLMO-DCjDRcYe.js} +8 -8
  37. package/dist/bundle/{chunk-XW3IHFDH-CjmXc8aI.js → chunk-XW3IHFDH-CA9Bby7o.js} +1 -1
  38. package/dist/bundle/{chunk-YHBBPJW6-jAof9asy.js → chunk-YHBBPJW6-DKIU2gC4.js} +2 -2
  39. package/dist/bundle/{chunk-YITG2CE5-Bg4SA8X1.js → chunk-YITG2CE5-o18mzaka.js} +1 -1
  40. package/dist/bundle/{chunk-ZMRSCVFX-Dwxb-Yg1.js → chunk-ZMRSCVFX-uhwzmZUP.js} +1 -1
  41. package/dist/bundle/chunks.json +83 -83
  42. package/dist/bundle/{command-contract-4X4JDKH7-BsU8tW9N.js → command-contract-DHFUF6RM-Bnc6nJSk.js} +2 -2
  43. package/dist/bundle/{command-server-entry-3JEJBUK5-CF-VyCRd.js → command-server-entry-UQSMAHYK-DzjTaTCZ.js} +2 -2
  44. package/dist/bundle/{decode-KVUA3TLF-Ds0C1R9U.js → decode-KVUA3TLF-BoJfgCpS.js} +2 -2
  45. package/dist/bundle/{dist-TPSNLFVO-D1tJd0aB.js → dist-TPSNLFVO-55jBf4N-.js} +2 -2
  46. package/dist/bundle/documents.js +5 -5
  47. package/dist/bundle/{echarts-6Q4CQ2DC-BvZMDYNl.js → echarts-6Q4CQ2DC-w9WhKUJu.js} +1 -1
  48. package/dist/bundle/{embed-JGGK2WKR-h5ppwooq.js → embed-JGGK2WKR-Cl3meWl4.js} +2 -2
  49. package/dist/bundle/{embedder-5SIVKVWO-D4yt4YCy.js → embedder-5SIVKVWO-DJEa9hBn.js} +2 -2
  50. package/dist/bundle/{first-run-FFHXPGFC-CyHZ4KM3.js → first-run-BT3X33BP-JikrW5_w.js} +2 -2
  51. package/dist/bundle/{first-screen-2NGQNWIN-BkvwnUdE.js → first-screen-KGQQK446-D2MchUuo.js} +2 -2
  52. package/dist/bundle/{hast-util-from-html-WLAUHN53-BfAYjYKc.js → hast-util-from-html-WLAUHN53-BOWgHBLv.js} +4 -4
  53. package/dist/bundle/{hast-util-to-html-PJC36XDP-C8DGIyzU.js → hast-util-to-html-PJC36XDP-QwbM5c4F.js} +5 -5
  54. package/dist/bundle/{hast-util-to-mdast-ZQ5OFYUM-9p6MJEBi.js → hast-util-to-mdast-ZQ5OFYUM-BidjUANu.js} +6 -6
  55. package/dist/bundle/{index-BOgkxLir.js → index-CTvUjqLX.js} +331 -345
  56. package/dist/bundle/index.js +66 -66
  57. package/dist/bundle/install-IPXFNLYZ-BGKW94IA.js +5 -0
  58. package/dist/bundle/{instructions-NHSD6EUE-BfefgySD.js → instructions-34FSWDC6-BR7mbjJH.js} +2 -2
  59. package/dist/bundle/mail.js +3 -3
  60. package/dist/bundle/{mcp-server-5FM4GA2C-CNWjKPAi.js → mcp-server-5FM4GA2C-B4Sqou0Z.js} +2 -2
  61. package/dist/bundle/mcp.js +12 -12
  62. package/dist/bundle/{mdast-util-from-markdown-Y7N3XA5A-ZkhTz5VO.js → mdast-util-from-markdown-Y7N3XA5A-CBCtetYX.js} +8 -8
  63. package/dist/bundle/{mdast-util-gfm-52PMOHWQ-gfhFQVZ5.js → mdast-util-gfm-52PMOHWQ-Bv-Hkixb.js} +12 -12
  64. package/dist/bundle/{mdast-util-to-hast-4MTEM3TB-Bomsq1EU.js → mdast-util-to-hast-4MTEM3TB-40gSN0gV.js} +6 -6
  65. package/dist/bundle/mdast-util-to-markdown-UGCOLDXA-DnYraMQX.js +12 -0
  66. package/dist/bundle/{meeting-combined-G3OVTNM6-CFHWFlT-.js → meeting-combined-G3OVTNM6-C4Jdctiy.js} +2 -2
  67. package/dist/bundle/{meeting-model-RINL42I5-Bab4crMQ.js → meeting-model-RINL42I5-BLAAT6mv.js} +2 -2
  68. package/dist/bundle/meeting-semantic-I7AZQTEI-DQ19wjn5.js +5 -0
  69. package/dist/bundle/{micromark-extension-gfm-FRHRNOIW-81l4O6kr.js → micromark-extension-gfm-FRHRNOIW-BvJCT_wq.js} +6 -6
  70. package/dist/bundle/{node-ZIYT5JOL-WfCpdwZ2.js → node-ZIYT5JOL-DoWqiI0I.js} +2 -2
  71. package/dist/bundle/{node-sqlite-VFGFD4MA-CrKdzJgw.js → node-sqlite-VFGFD4MA-QH9swjUN.js} +3 -3
  72. package/dist/bundle/notes-search-2Q3C65PA-D2HqYyaY.js +5 -0
  73. package/dist/bundle/oauth-TVUNW3GM-uN6u_RWy.js +7 -0
  74. package/dist/bundle/{open-36SZHLGF-kGan0BjP.js → open-36SZHLGF-CPBs6fdy.js} +1 -1
  75. package/dist/bundle/{openai-Z2WIZ6AC-D-aH-As-.js → openai-Z2WIZ6AC-CcEngcFj.js} +2 -2
  76. package/dist/bundle/preload.js +1 -1
  77. package/dist/bundle/{process-KJQOPRSP-C6W_P1_I.js → process-KJQOPRSP-BNqvUqBZ.js} +2 -2
  78. package/dist/bundle/{prompt-S2W33X57-BEDbCA8B.js → prompt-S2W33X57-BiF1939t.js} +2 -2
  79. package/dist/bundle/{recognize-NBWDLXLD-B2LTlDUy.js → recognize-NBWDLXLD-BCqQ8iG1.js} +2 -2
  80. package/dist/bundle/{remote-O54ANXYL-DOEubnhV.js → remote-O54ANXYL-BixLG9XM.js} +2 -2
  81. package/dist/bundle/{rerank-HTCSXPM6-CVIU4cUa.js → rerank-HTCSXPM6-FGYUs2VW.js} +2 -2
  82. package/dist/bundle/serve-7KRXCBBZ-EVSG16Mc.js +8 -0
  83. package/dist/bundle/server-BFD6QUV7-OmgCCeuX.js +11 -0
  84. package/dist/bundle/server-G7VWUBA2-C3Gq_HlM.js +12 -0
  85. package/dist/bundle/{sqlite-runtime-KC3NKKRB-DYslMC-g.js → sqlite-runtime-KC3NKKRB-y_O8PNsQ.js} +1 -1
  86. package/dist/bundle/{start-Dtq56YXe.js → start-CqQGB7xI.js} +5 -5
  87. package/dist/bundle/start.js +1 -1
  88. package/dist/bundle/state-3CFS2SAC-CYYQ103I.js +5 -0
  89. package/dist/bundle/store-BSVRVKTV-Uot4OGm0.js +5 -0
  90. package/dist/bundle/{store-6CM2A3HP-CtnMVUVK.js → store-LGAEGNFF-BzNIKnoK.js} +2 -2
  91. package/dist/bundle/{store-maintenance-command-WYO5PN4V-B0wefBHZ.js → store-maintenance-command-Z27R7URJ-CoJCYGVq.js} +2 -2
  92. package/dist/bundle/surface-ZEEHYD5Q-DRIV3XG3.js +8 -0
  93. package/dist/bundle/testing.js +8 -8
  94. package/dist/cli/app-doctor-command.d.ts +187 -1
  95. package/dist/cli/app-doctor-command.d.ts.map +1 -1
  96. package/dist/cli/app-doctor-command.js +3 -2
  97. package/dist/cli/app-doctor-command.js.map +1 -1
  98. package/dist/cli/app-mcp-command.d.ts +187 -2
  99. package/dist/cli/app-mcp-command.d.ts.map +1 -1
  100. package/dist/cli/app-mcp-command.js +3 -2
  101. package/dist/cli/app-mcp-command.js.map +1 -1
  102. package/dist/cli/built-commands.d.ts +10 -0
  103. package/dist/cli/built-commands.d.ts.map +1 -0
  104. package/dist/cli/built-commands.js +33 -0
  105. package/dist/cli/built-commands.js.map +1 -0
  106. package/dist/cli/commands-command.d.ts.map +1 -1
  107. package/dist/cli/commands-command.js +3 -2
  108. package/dist/cli/commands-command.js.map +1 -1
  109. package/dist/cli/complete-command.d.ts +187 -2
  110. package/dist/cli/complete-command.d.ts.map +1 -1
  111. package/dist/cli/complete-command.js +3 -2
  112. package/dist/cli/complete-command.js.map +1 -1
  113. package/dist/cli/config-command.d.ts +189 -3
  114. package/dist/cli/config-command.d.ts.map +1 -1
  115. package/dist/cli/config-command.js +3 -2
  116. package/dist/cli/config-command.js.map +1 -1
  117. package/dist/cli/context.d.ts +8 -0
  118. package/dist/cli/context.d.ts.map +1 -1
  119. package/dist/cli/context.js +39 -2
  120. package/dist/cli/context.js.map +1 -1
  121. package/dist/cli/documents/words.d.ts +1 -1
  122. package/dist/cli/dry-run-guard.d.ts.map +1 -1
  123. package/dist/cli/dry-run-guard.js +6 -28
  124. package/dist/cli/dry-run-guard.js.map +1 -1
  125. package/dist/cli/first-run.js +1 -1
  126. package/dist/cli/first-run.js.map +1 -1
  127. package/dist/cli/guide.d.ts.map +1 -1
  128. package/dist/cli/guide.js +3 -2
  129. package/dist/cli/guide.js.map +1 -1
  130. package/dist/cli/messenger/archive-commands.d.ts.map +1 -1
  131. package/dist/cli/messenger/archive-commands.js +3 -2
  132. package/dist/cli/messenger/archive-commands.js.map +1 -1
  133. package/dist/cli/messenger/complete-command.d.ts +187 -2
  134. package/dist/cli/messenger/complete-command.d.ts.map +1 -1
  135. package/dist/cli/messenger/complete-command.js +3 -2
  136. package/dist/cli/messenger/complete-command.js.map +1 -1
  137. package/dist/cli/messenger/doctor-command.d.ts.map +1 -1
  138. package/dist/cli/messenger/doctor-command.js +3 -2
  139. package/dist/cli/messenger/doctor-command.js.map +1 -1
  140. package/dist/cli/messenger/flood-command.d.ts.map +1 -1
  141. package/dist/cli/messenger/flood-command.js +3 -2
  142. package/dist/cli/messenger/flood-command.js.map +1 -1
  143. package/dist/cli/messenger/mcp-command.d.ts.map +1 -1
  144. package/dist/cli/messenger/mcp-command.js +3 -2
  145. package/dist/cli/messenger/mcp-command.js.map +1 -1
  146. package/dist/cli/messenger/metadata-command.d.ts.map +1 -1
  147. package/dist/cli/messenger/metadata-command.js +3 -2
  148. package/dist/cli/messenger/metadata-command.js.map +1 -1
  149. package/dist/cli/messenger/models-command.d.ts.map +1 -1
  150. package/dist/cli/messenger/models-command.js +3 -2
  151. package/dist/cli/messenger/models-command.js.map +1 -1
  152. package/dist/cli/messenger/server-command.d.ts +1 -1
  153. package/dist/cli/messenger/server-command.d.ts.map +1 -1
  154. package/dist/cli/messenger/server-command.js +3 -2
  155. package/dist/cli/messenger/server-command.js.map +1 -1
  156. package/dist/cli/messenger/session-commands.d.ts.map +1 -1
  157. package/dist/cli/messenger/session-commands.js +3 -2
  158. package/dist/cli/messenger/session-commands.js.map +1 -1
  159. package/dist/cli/messenger/store-maintenance-command.d.ts.map +1 -1
  160. package/dist/cli/messenger/store-maintenance-command.js +11 -5
  161. package/dist/cli/messenger/store-maintenance-command.js.map +1 -1
  162. package/dist/cli/model-catalogue-command.d.ts.map +1 -1
  163. package/dist/cli/model-catalogue-command.js +3 -2
  164. package/dist/cli/model-catalogue-command.js.map +1 -1
  165. package/dist/cli/oauth-session.d.ts.map +1 -1
  166. package/dist/cli/oauth-session.js +3 -2
  167. package/dist/cli/oauth-session.js.map +1 -1
  168. package/dist/cli/runs/command.d.ts.map +1 -1
  169. package/dist/cli/runs/command.js +3 -2
  170. package/dist/cli/runs/command.js.map +1 -1
  171. package/dist/cli/schedule/schedule-command.d.ts +1 -1
  172. package/dist/cli/schedule/schedule-command.d.ts.map +1 -1
  173. package/dist/cli/schedule/schedule-command.js +5 -3
  174. package/dist/cli/schedule/schedule-command.js.map +1 -1
  175. package/dist/cli/setup-command.d.ts.map +1 -1
  176. package/dist/cli/setup-command.js +3 -2
  177. package/dist/cli/setup-command.js.map +1 -1
  178. package/dist/cli/skill-command.d.ts.map +1 -1
  179. package/dist/cli/skill-command.js +3 -2
  180. package/dist/cli/skill-command.js.map +1 -1
  181. package/dist/cli/store-info.d.ts.map +1 -1
  182. package/dist/cli/store-info.js +5 -4
  183. package/dist/cli/store-info.js.map +1 -1
  184. package/dist/cli/token-session.d.ts.map +1 -1
  185. package/dist/cli/token-session.js +2 -1
  186. package/dist/cli/token-session.js.map +1 -1
  187. package/dist/cli/upgrade-command.d.ts.map +1 -1
  188. package/dist/cli/upgrade-command.js +4 -5
  189. package/dist/cli/upgrade-command.js.map +1 -1
  190. package/dist/cli/upkeep.d.ts +8 -0
  191. package/dist/cli/upkeep.d.ts.map +1 -0
  192. package/dist/cli/upkeep.js +11 -0
  193. package/dist/cli/upkeep.js.map +1 -0
  194. package/dist/entities/attachment.d.ts +0 -8
  195. package/dist/entities/attachment.d.ts.map +1 -1
  196. package/dist/entities/attachment.js +22 -20
  197. package/dist/entities/attachment.js.map +1 -1
  198. package/dist/entities/chat.d.ts +0 -4
  199. package/dist/entities/chat.d.ts.map +1 -1
  200. package/dist/entities/chat.js +6 -10
  201. package/dist/entities/chat.js.map +1 -1
  202. package/dist/entities/contact.d.ts +0 -7
  203. package/dist/entities/contact.d.ts.map +1 -1
  204. package/dist/entities/contact.js +9 -16
  205. package/dist/entities/contact.js.map +1 -1
  206. package/dist/entities/deal.d.ts +0 -36
  207. package/dist/entities/deal.d.ts.map +1 -1
  208. package/dist/entities/deal.js +22 -48
  209. package/dist/entities/deal.js.map +1 -1
  210. package/dist/entities/document.d.ts +0 -2
  211. package/dist/entities/document.d.ts.map +1 -1
  212. package/dist/entities/document.js +3 -5
  213. package/dist/entities/document.js.map +1 -1
  214. package/dist/entities/fields.d.ts +5 -1
  215. package/dist/entities/fields.d.ts.map +1 -1
  216. package/dist/entities/fields.js +6 -2
  217. package/dist/entities/fields.js.map +1 -1
  218. package/dist/entities/hit.d.ts +0 -18
  219. package/dist/entities/hit.d.ts.map +1 -1
  220. package/dist/entities/hit.js +19 -37
  221. package/dist/entities/hit.js.map +1 -1
  222. package/dist/entities/index.d.ts +0 -1
  223. package/dist/entities/index.d.ts.map +1 -1
  224. package/dist/entities/index.js +2 -3
  225. package/dist/entities/index.js.map +1 -1
  226. package/dist/entities/message.d.ts +2 -34
  227. package/dist/entities/message.d.ts.map +1 -1
  228. package/dist/entities/message.js +35 -67
  229. package/dist/entities/message.js.map +1 -1
  230. package/dist/entities/task.d.ts +0 -19
  231. package/dist/entities/task.d.ts.map +1 -1
  232. package/dist/entities/task.js +18 -35
  233. package/dist/entities/task.js.map +1 -1
  234. package/dist/mcp/agent.d.ts +3 -0
  235. package/dist/mcp/agent.d.ts.map +1 -1
  236. package/dist/mcp/agent.js +48 -1
  237. package/dist/mcp/agent.js.map +1 -1
  238. package/dist/mcp/app-server.d.ts.map +1 -1
  239. package/dist/mcp/app-server.js +8 -5
  240. package/dist/mcp/app-server.js.map +1 -1
  241. package/dist/mcp/bot/instructions.js +1 -1
  242. package/dist/mcp/bot/instructions.js.map +1 -1
  243. package/dist/mcp/index.d.ts +4 -0
  244. package/dist/mcp/index.d.ts.map +1 -1
  245. package/dist/mcp/index.js +4 -0
  246. package/dist/mcp/index.js.map +1 -1
  247. package/dist/mcp/instructions.js +4 -4
  248. package/dist/mcp/instructions.js.map +1 -1
  249. package/dist/mcp/lean.d.ts +9 -0
  250. package/dist/mcp/lean.d.ts.map +1 -0
  251. package/dist/mcp/lean.js +7 -0
  252. package/dist/mcp/lean.js.map +1 -0
  253. package/dist/mcp/server.d.ts.map +1 -1
  254. package/dist/mcp/server.js +6 -2
  255. package/dist/mcp/server.js.map +1 -1
  256. package/dist/mcp/surface.d.ts +51 -2
  257. package/dist/mcp/surface.d.ts.map +1 -1
  258. package/dist/mcp/surface.js +379 -52
  259. package/dist/mcp/surface.js.map +1 -1
  260. package/dist/mcp/tool.d.ts +9 -1
  261. package/dist/mcp/tool.d.ts.map +1 -1
  262. package/dist/mcp/tool.js +20 -6
  263. package/dist/mcp/tool.js.map +1 -1
  264. package/dist/output-detail.d.ts +8 -0
  265. package/dist/output-detail.d.ts.map +1 -1
  266. package/dist/output-detail.js +55 -0
  267. package/dist/output-detail.js.map +1 -1
  268. package/dist/services/package-upgrade.d.ts.map +1 -1
  269. package/dist/services/package-upgrade.js +3 -1
  270. package/dist/services/package-upgrade.js.map +1 -1
  271. package/dist/store/compatibility.d.ts +2 -0
  272. package/dist/store/compatibility.d.ts.map +1 -1
  273. package/dist/store/compatibility.js +12 -0
  274. package/dist/store/compatibility.js.map +1 -1
  275. package/dist/store/migrations.d.ts +3 -3
  276. package/dist/store/migrations.js +3 -3
  277. package/dist/store/sqlite/clients.d.ts +6 -0
  278. package/dist/store/sqlite/clients.d.ts.map +1 -1
  279. package/dist/store/sqlite/clients.js +6 -4
  280. package/dist/store/sqlite/clients.js.map +1 -1
  281. package/dist/store/sqlite/manifest.d.ts +4 -0
  282. package/dist/store/sqlite/manifest.d.ts.map +1 -1
  283. package/dist/store/sqlite/manifest.js.map +1 -1
  284. package/package.json +1 -1
  285. package/skills/link-conversations/SKILL.md +1 -1
  286. package/src/cli/app-doctor-command.ts +41 -42
  287. package/src/cli/app-mcp-command.ts +55 -52
  288. package/src/cli/built-commands.ts +32 -0
  289. package/src/cli/commands-command.ts +3 -2
  290. package/src/cli/complete-command.ts +53 -48
  291. package/src/cli/config-command.ts +180 -177
  292. package/src/cli/context.ts +44 -2
  293. package/src/cli/dry-run-guard.ts +11 -23
  294. package/src/cli/first-run.ts +1 -1
  295. package/src/cli/guide.ts +3 -2
  296. package/src/cli/messenger/archive-commands.ts +3 -2
  297. package/src/cli/messenger/complete-command.ts +30 -30
  298. package/src/cli/messenger/doctor-command.ts +3 -2
  299. package/src/cli/messenger/flood-command.ts +3 -2
  300. package/src/cli/messenger/mcp-command.ts +3 -2
  301. package/src/cli/messenger/metadata-command.ts +3 -2
  302. package/src/cli/messenger/models-command.ts +3 -2
  303. package/src/cli/messenger/server-command.ts +3 -2
  304. package/src/cli/messenger/session-commands.ts +3 -2
  305. package/src/cli/messenger/store-maintenance-command.ts +18 -12
  306. package/src/cli/model-catalogue-command.ts +3 -2
  307. package/src/cli/oauth-session.ts +3 -2
  308. package/src/cli/runs/command.ts +3 -2
  309. package/src/cli/schedule/schedule-command.ts +412 -410
  310. package/src/cli/setup-command.ts +3 -2
  311. package/src/cli/skill-command.ts +3 -2
  312. package/src/cli/store-info.ts +21 -16
  313. package/src/cli/token-session.ts +3 -2
  314. package/src/cli/upgrade-command.ts +59 -62
  315. package/src/cli/upkeep.ts +15 -0
  316. package/src/entities/attachment.ts +44 -30
  317. package/src/entities/chat.ts +9 -10
  318. package/src/entities/contact.ts +20 -21
  319. package/src/entities/deal.ts +66 -53
  320. package/src/entities/document.ts +3 -5
  321. package/src/entities/fields.ts +11 -2
  322. package/src/entities/hit.ts +52 -37
  323. package/src/entities/index.ts +2 -3
  324. package/src/entities/message.ts +101 -80
  325. package/src/entities/task.ts +37 -38
  326. package/src/mcp/agent.ts +51 -1
  327. package/src/mcp/app-server.ts +8 -5
  328. package/src/mcp/bot/instructions.ts +1 -1
  329. package/src/mcp/index.ts +4 -0
  330. package/src/mcp/instructions.ts +4 -4
  331. package/src/mcp/lean.ts +8 -0
  332. package/src/mcp/server.ts +6 -2
  333. package/src/mcp/surface.ts +436 -64
  334. package/src/mcp/tool.ts +27 -4
  335. package/src/output-detail.ts +61 -0
  336. package/src/services/package-upgrade.ts +3 -1
  337. package/src/store/compatibility.ts +12 -0
  338. package/src/store/migrations.ts +3 -3
  339. package/src/store/sqlite/clients.ts +17 -6
  340. package/src/store/sqlite/manifest.ts +4 -0
  341. package/dist/bundle/install-IPXFNLYZ-BSWiztYR.js +0 -5
  342. package/dist/bundle/mdast-util-to-markdown-UGCOLDXA-7D6EJn9r.js +0 -12
  343. package/dist/bundle/meeting-semantic-I7AZQTEI-BgZ3ZzQB.js +0 -5
  344. package/dist/bundle/notes-search-2Q3C65PA-CWKHboCy.js +0 -5
  345. package/dist/bundle/oauth-TVUNW3GM-BqlyhUfp.js +0 -7
  346. package/dist/bundle/serve-7KRXCBBZ-BO9BKhWL.js +0 -8
  347. package/dist/bundle/server-PIT6UZRZ-C6I-VrDd.js +0 -11
  348. package/dist/bundle/server-ZL4FMEHH-DP1oYgCn.js +0 -12
  349. package/dist/bundle/state-3CFS2SAC-xptBCfut.js +0 -5
  350. package/dist/bundle/store-ASWYHJ4Q-C7EFfvzB.js +0 -5
  351. package/dist/bundle/surface-DDH4HGT3-CBZnEqH_.js +0 -8
@@ -1,9 +1,12 @@
1
1
  import type { CallToolResult, McpServer, ServerContext } from "@modelcontextprotocol/server";
2
2
  import type { CommandOutput } from "@wirecat/cli-base/commands";
3
+ import { type Meta } from "@wirecat/cli-base/standards";
3
4
  import * as v from "valibot";
4
5
  import type { AppErrors } from "../errors/reasons.js";
5
6
  import type { CommandAvailability } from "./agent.js";
6
7
  import { type AnyTool, type Registration } from "./tool.js";
8
+ /** About 10,000 tokens, where Claude Code starts to warn; an answer past it is cut where a page can carry the rest. */
9
+ export declare const AGENT_ANSWER_CHARS = 40000;
7
10
  type Input = v.ObjectSchema<v.ObjectEntries, undefined> | v.StrictObjectSchema<v.ObjectEntries, undefined>;
8
11
  /** One command an agent can find and run: its arguments are checked against `input` before `run`. @experimental */
9
12
  export interface McpCommand {
@@ -16,8 +19,12 @@ export interface McpCommand {
16
19
  keywords?: readonly string[];
17
20
  writes: boolean;
18
21
  input: Input;
19
- /** The envelope it answers with, when it declares its entity; any envelope otherwise. */
22
+ /** The envelope it answers with; else the one of `answers`; any envelope otherwise. */
20
23
  output?: v.GenericSchema;
24
+ /** The name of the entity it answers with, `message_write`, when it declares one. */
25
+ answers?: string;
26
+ /** One of cli-core's commands that run the CLI itself (config, sign-in, the store): one name in the listing. */
27
+ upkeep?: boolean;
21
28
  /** `run` checks the arguments itself, and records a refusal. */
22
29
  checked?: boolean;
23
30
  run: (args: Record<string, unknown>, ctx: ServerContext) => Promise<CallToolResult>;
@@ -29,6 +36,46 @@ export declare const normal: (command: string) => string;
29
36
  * named exactly ranks first. No word lists everything.
30
37
  */
31
38
  export declare const search: (commands: Record<string, McpCommand>, query: string) => [string, McpCommand][];
39
+ /**
40
+ * The commands a task most likely means, best first. Generated `api *` commands rank below the hand-written ones and
41
+ * come in only when the task names `api` or no hand-written command scores near them: in hubspot "find contact" gave
42
+ * eight `api contacts-*` and no `people` command. When no hand-written command matched every word, the best `api *`
43
+ * one still takes the last place: gcal's "free time" is `calendars busy` or `api calendar-freebusy-query`.
44
+ */
45
+ export declare const matchesOf: (commands: Record<string, McpCommand>, query: string) => [string, McpCommand][];
46
+ /** A command's arguments as an agent needs them to call it: type, description, enum, default, required. */
47
+ export declare const argumentsOf: (one: McpCommand) => unknown;
48
+ /**
49
+ * The answer of `<prefix>_tools_search`: the first matches with their arguments, the rest a line each; with no
50
+ * words, the listing; with `schema` and a command's exact name, that command's answer schema too.
51
+ * @experimental
52
+ */
53
+ export declare const searchAnswer: (commands: Record<string, McpCommand>, prefix: string, { query, schema }?: {
54
+ query?: string;
55
+ schema?: boolean;
56
+ }) => {
57
+ items: unknown[];
58
+ missing?: import("@wirecat/cli-base/standards").Missing[];
59
+ meta?: Partial<Meta>;
60
+ page: {
61
+ mode: "page";
62
+ limit: number;
63
+ has_more: boolean;
64
+ total?: {
65
+ value: number;
66
+ relation: "eq" | "gte";
67
+ } | undefined;
68
+ } | {
69
+ mode: "cursor";
70
+ limit: number;
71
+ has_more: boolean;
72
+ next_cursor?: string | undefined;
73
+ total?: {
74
+ value: number;
75
+ relation: "eq" | "gte";
76
+ } | undefined;
77
+ };
78
+ };
32
79
  /**
33
80
  * **Three tools in place of one per command**: search the commands, then run one
34
81
  * with `read` or `write`. A command keeps its CLI path and its arguments, and runs as its own tool
@@ -42,7 +89,9 @@ withheld?: (command: string) => void,
42
89
  isMessenger?: boolean) => void;
43
90
  /** The definitions no command answers — a picture for the model, the server's own status — as commands. */
44
91
  export declare const surfaceCommands: (tools: Record<string, AnyTool>, registration: Registration) => Record<string, McpCommand>;
92
+ /** The name of the entity a command declares: `message`, `message.hit`. */
93
+ export declare const answersOf: ({ entity, view }: CommandOutput) => string;
45
94
  /** The envelope a command answers with, from the entity it declares (`annotate(…, { output })`). */
46
- export declare const outputOf: ({ entity, view }: CommandOutput) => v.GenericSchema;
95
+ export declare const outputOf: (output: CommandOutput) => v.GenericSchema;
47
96
  export {};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;AAwGD;;;;GAIG;AACH,eAAO,MAAM,YAAY,aACb,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,UAC5B,MAAM,sBACkB;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;CA6BrE,CAAA;AA8ID;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,WACnB,SAAS,UACT,MAAM,YACJ,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,WAC3B,SAAS;AAClB,8GAA8G;WACnG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI;AACpC,0GAA0G;cAC5F,OAAO,SAoHtB,CAAA;AAED,2GAA2G;AAC3G,eAAO,MAAM,eAAe,UACnB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,gBAChB,YAAY,KACzB,MAAM,CAAC,MAAM,EAAE,UAAU,CAgB3B,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,SAAS,qBAAsB,aAAa,KAAG,MAA+C,CAAA;AAE3G,oGAAoG;AACpG,eAAO,MAAM,QAAQ,WAAY,aAAa,KAAG,CAAC,CAAC,aAAgD,CAAA"}
@@ -1,18 +1,28 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { toJsonSchema, toStandardJsonSchema } from "@valibot/to-json-schema";
3
3
  import { CliError } from "@wirecat/cli-base";
4
+ import { MAX_NEXT_STEPS } from "@wirecat/cli-base/standards";
4
5
  import * as v from "valibot";
5
6
  import { answerSchema, listOf } from "../cli/envelope.js";
7
+ import { nextStep } from "../cli/steps.js";
6
8
  import { ENTITIES } from "../entities/index.js";
7
9
  import { callerOf, currentCaller, withCaller } from "./caller.js";
10
+ import { leansRead } from "./lean.js";
8
11
  import { agentArguments } from "./text.js";
9
12
  import { answered, commandOf, entryRunner, failed, inputOf, outputSchemaOf, READ, syncAllowedFor, UNTRUSTED, UNTRUSTED_NEUTRAL, WRITE, } from "./tool.js";
10
- const MATCHES = 8;
13
+ // Claude Code saves an answer over 25,000 tokens to a file the agent never reads: one match with 14 arguments is
14
+ // 1,700 characters, a match's answer schema was up to 60,000.
15
+ const MATCHES = 5;
16
+ const FULL_MATCHES = 2;
17
+ /** A match scoring under 45% of the best one answers another task: `polls create` for "messages send". */
18
+ const NEAR = 0.45;
19
+ /** About 10,000 tokens, where Claude Code starts to warn; an answer past it is cut where a page can carry the rest. */
20
+ export const AGENT_ANSWER_CHARS = 40_000;
11
21
  const ANSWER = answerSchema();
12
22
  // The listing shows an agent only what it acts on; the server still checks every answer against the full envelope,
13
- // and tools_search gives each command's full answer. meta.ranking alone took 2,800 characters of every connect.
23
+ // and tools_search with `schema` gives one command's. meta.ranking alone took 2,800 characters of every connect.
14
24
  const agentAnswer = (prefix, writes) => {
15
- const meta = v.pipe(v.looseObject({}), v.description(`run facts; ${prefix}_tools_search shows the full answer`));
25
+ const meta = v.pipe(v.looseObject({}), v.description(`run facts; ${prefix}_tools_search with schema: true shows the full answer`));
16
26
  const next = v.optional(v.pipe(v.array(v.looseObject({})), v.description("steps to run next: command and args")));
17
27
  return v.looseObject(writes
18
28
  ? { item: v.optional(v.unknown()), next, meta }
@@ -48,16 +58,20 @@ const stem = (word) => {
48
58
  const bare = word.replace(/'s$/u, "");
49
59
  if (bare.length > 4 && bare.endsWith("ies"))
50
60
  return `${bare.slice(0, -3)}y`;
51
- for (const ending of ["ing", "ed", "es", "s"])
61
+ // `es` only after a hiss, so `notes` is `note` as the task's "note" is: `matches` is `match`.
62
+ if (bare.length > 5 && /(?:[sxz]|ch|sh)es$/u.test(bare))
63
+ return bare.slice(0, -2);
64
+ for (const ending of ["ing", "ed", "s"])
52
65
  if (bare.length - ending.length >= 3 && bare.endsWith(ending))
53
66
  return bare.slice(0, -ending.length);
54
67
  return bare;
55
68
  };
56
- const sameWord = (asked, known) => {
69
+ /** 1 for the same word, ½ for one that starts the other (`time` in `timer`), 0 for another word. */
70
+ const likeness = (asked, known) => {
57
71
  if (asked === known)
58
- return true;
72
+ return 1;
59
73
  const [short, long] = asked.length <= known.length ? [asked, known] : [known, asked];
60
- return short.length >= 3 && long.startsWith(short);
74
+ return short.length >= 3 && long.startsWith(short) ? 0.5 : 0;
61
75
  };
62
76
  /** Where a word of the task is found, by how much it says about the command: its own name says the most. */
63
77
  const fieldsOf = (command, one) => [
@@ -65,35 +79,275 @@ const fieldsOf = (command, one) => [
65
79
  [2, wordsOf(one.title)],
66
80
  [1, [...wordsOf(one.description), ...(one.keywords ?? []).flatMap(wordsOf), ...Object.keys(one.input.entries)]],
67
81
  ].map(([weight, words]) => [weight, [...new Set(words.map(stem))]]);
82
+ /** Each two words in a row, stemmed, that hold a telling word: `reports to`, `a person`, not `to a`. */
83
+ const pairsOf = (text) => {
84
+ const words = wordsOf(text);
85
+ return words.slice(1).flatMap((word, at) => {
86
+ const before = words[at] ?? "";
87
+ return STOP_WORDS.has(before) && STOP_WORDS.has(word) ? [] : [`${stem(before)} ${stem(word)}`];
88
+ });
89
+ };
90
+ /** A task often says what the help says: "who reports to whom" is a phrase of `relationships list`'s help. */
91
+ const PAIR = 3;
68
92
  /**
69
93
  * Ranks by how many words of the task a command matches, then by where they matched: its name, then its title, then
70
94
  * its help, examples and arguments. A task is typed in its own words, so no single word is required. The command
71
95
  * named exactly ranks first. No word lists everything.
72
96
  */
73
97
  export const search = (commands, query) => {
98
+ if (!normal(query))
99
+ return Object.entries(commands).sort((a, b) => a[0].localeCompare(b[0]));
100
+ return scored(commands, query).map(({ entry }) => entry);
101
+ };
102
+ const scored = (commands, query) => {
74
103
  const named = normal(query);
75
104
  const all = Object.entries(commands);
76
- if (!named)
77
- return all.map((entry) => entry).sort((a, b) => a[0].localeCompare(b[0]));
78
- const words = [
105
+ const asked = [
79
106
  ...new Set(wordsOf(query)
80
107
  .filter((word) => word.length > 1 && !STOP_WORDS.has(word))
81
108
  .map(stem)),
82
109
  ];
83
- return (all
84
- .map((entry) => {
110
+ const pairs = [...new Set(pairsOf(query))];
111
+ const phrased = all.map(([command, one]) => {
112
+ // A name's words come in either order, "list events" for `events list`; examples' words are no phrase.
113
+ const names = [command, ...(one.aliases ?? [])].flatMap((name) => [name, wordsOf(name).reverse().join(" ")]);
114
+ const known = new Set([...names, one.title, one.description].flatMap(pairsOf));
115
+ return pairs.filter((pair) => known.has(pair)).length;
116
+ });
117
+ // Per word: the best field's weight, and how many fields hold the word itself, which breaks a tie.
118
+ const weighed = all.map((entry) => {
85
119
  const fields = fieldsOf(entry[0], entry[1]);
86
- const weights = words.map((word) => fields.reduce((best, [weight, known]) => (known.some((one) => sameWord(word, one)) ? Math.max(best, weight) : best), 0));
87
- const matched = weights.filter((weight) => weight > 0).length;
88
- const exact = normal(entry[0]) === named || (entry[1].aliases ?? []).some((alias) => normal(alias) === named);
89
- return { entry, matched, rank: (exact ? 1000 : 0) + matched * 10 + weights.reduce((a, b) => a + b, 0) };
120
+ return asked.map((word) => {
121
+ const likes = fields.map(([weight, known]) => ({
122
+ weight: weight * known.reduce((most, one) => Math.max(most, likeness(word, one)), 0),
123
+ same: known.includes(word),
124
+ }));
125
+ return {
126
+ weight: likes.reduce((best, one) => Math.max(best, one.weight), 0),
127
+ fields: likes.filter(({ same }) => same).length,
128
+ };
129
+ });
130
+ });
131
+ return (all
132
+ .map((entry, index) => {
133
+ const found = weighed[index] ?? [];
134
+ const matched = found.filter(({ weight }) => weight > 0).length;
135
+ const exact = isNamed(entry, named);
136
+ return {
137
+ entry,
138
+ exact,
139
+ whole: matched === found.length,
140
+ score: matched * 10 +
141
+ found.reduce((sum, { weight }) => sum + weight, 0) +
142
+ (matched ? PAIR * (phrased[index] ?? 0) : 0),
143
+ evidence: found.reduce((sum, { fields }) => sum + fields, 0),
144
+ };
90
145
  })
91
- .filter(({ matched, rank }) => matched > 0 || rank >= 1000)
92
- // A tie goes to the shorter name, which holds less the task did not ask for: `messages send` first.
93
- .sort((a, b) => b.rank - a.rank ||
146
+ .filter(({ score, exact }) => score > 0 || exact)
147
+ // A tie goes to the command that holds the words in more places, then to the shorter name, which holds less the
148
+ // task did not ask for: `messages send` first.
149
+ .sort((a, b) => Number(b.exact) - Number(a.exact) ||
150
+ b.score - a.score ||
151
+ b.evidence - a.evidence ||
94
152
  wordsOf(a.entry[0]).length - wordsOf(b.entry[0]).length ||
95
- a.entry[0].localeCompare(b.entry[0]))
96
- .map(({ entry }) => entry));
153
+ a.entry[0].localeCompare(b.entry[0])));
154
+ };
155
+ const isApi = (command) => command.split(" ")[0] === "api";
156
+ /**
157
+ * The commands a task most likely means, best first. Generated `api *` commands rank below the hand-written ones and
158
+ * come in only when the task names `api` or no hand-written command scores near them: in hubspot "find contact" gave
159
+ * eight `api contacts-*` and no `people` command. When no hand-written command matched every word, the best `api *`
160
+ * one still takes the last place: gcal's "free time" is `calendars busy` or `api calendar-freebusy-query`.
161
+ */
162
+ export const matchesOf = (commands, query) => {
163
+ const ranked = scored(commands, query);
164
+ const groups = new Set(wordsOf(query).map(stem));
165
+ if (normal(query).split(" ")[0] === "api")
166
+ return near(ranked, groups);
167
+ const own = ranked.filter(({ entry, exact }) => exact || !isApi(entry[0]));
168
+ const api = ranked.filter(({ entry, exact }) => !exact && isApi(entry[0]));
169
+ const best = bestOf(own);
170
+ if (best < NEAR * (api[0]?.score ?? 0))
171
+ return near([...own, ...api], groups);
172
+ const shown = near(own, groups);
173
+ const fallback = api[0];
174
+ if (!fallback || own.some(({ whole }) => whole) || fallback.score < NEAR * best)
175
+ return shown;
176
+ return [...shown.slice(0, MATCHES - 1), fallback.entry, ...shown.slice(MATCHES - 1)];
177
+ };
178
+ const bestOf = (ranked) => ranked.reduce((best, { score }) => Math.max(best, score), 0);
179
+ /** At most 2 of one group the task does not name: five `schedule *` siblings hid `calendars busy`. */
180
+ const SIBLINGS = 2;
181
+ const near = (ranked, groups) => {
182
+ const best = bestOf(ranked);
183
+ const taken = new Map();
184
+ return ranked
185
+ .filter(({ exact, score }) => exact || score >= NEAR * best)
186
+ .filter(({ entry, exact }) => {
187
+ const group = stem(entry[0].split(" ")[0] ?? "");
188
+ const count = (taken.get(group) ?? 0) + 1;
189
+ taken.set(group, count);
190
+ return exact || groups.has(group) || count <= SIBLINGS;
191
+ })
192
+ .map(({ entry }) => entry);
193
+ };
194
+ // Keywords that check a value, not what it means; the CLI checks them again. Data keys keep everything under them.
195
+ const CHECKS = new Set(["$schema", "pattern", "minLength", "minItems"]);
196
+ const DATA = new Set(["default", "enum", "const", "examples"]);
197
+ /** A command's arguments as an agent needs them to call it: type, description, enum, default, required. */
198
+ export const argumentsOf = (one) => {
199
+ const bare = (node) => {
200
+ if (Array.isArray(node))
201
+ return node.map(bare);
202
+ if (node === null || typeof node !== "object")
203
+ return node;
204
+ return Object.fromEntries(Object.entries(node)
205
+ .filter(([key, value]) => !CHECKS.has(key) &&
206
+ !(key === "additionalProperties" && value === false) &&
207
+ !(key === "required" && Array.isArray(value) && value.length === 0))
208
+ .map(([key, value]) => [
209
+ key,
210
+ DATA.has(key)
211
+ ? value
212
+ : key === "properties" && value !== null && typeof value === "object"
213
+ ? Object.fromEntries(Object.entries(value).map(([name, inner]) => [name, bare(inner)]))
214
+ : bare(value),
215
+ ]));
216
+ };
217
+ return bare(toJsonSchema(one.input));
218
+ };
219
+ /** Shown only when it changes what the agent does: a command that is refused, or that asks the owner first. */
220
+ const availabilityOf = (one) => {
221
+ const availability = one.availability?.();
222
+ return availability && (!availability.available || (availability.level ?? "allow") !== "allow")
223
+ ? { availability }
224
+ : {};
225
+ };
226
+ const shortMatch = (command, one) => ({
227
+ command,
228
+ does: one.description,
229
+ writes: one.writes,
230
+ ...availabilityOf(one),
231
+ });
232
+ const fullMatch = (command, one) => ({
233
+ command,
234
+ ...(one.title !== one.description ? { title: one.title } : {}),
235
+ does: one.description,
236
+ writes: one.writes,
237
+ ...(one.answers ? { answers: one.answers } : {}),
238
+ ...availabilityOf(one),
239
+ arguments: argumentsOf(one),
240
+ });
241
+ const API_ROOM = 2_000;
242
+ /**
243
+ * The generated `api *` commands as names, each reachable by its own name; past `room` characters, the names that fit
244
+ * and how to find the rest.
245
+ */
246
+ const apiGroup = (api, prefix, room) => {
247
+ const find = `${prefix}_tools_search with "api" and words of the task, for example "${api[0]?.[0]}"`;
248
+ const commands = [];
249
+ let size = find.length + API_ROOM;
250
+ for (const [command] of api) {
251
+ size += command.length + 3;
252
+ if (size > room)
253
+ break;
254
+ commands.push(command);
255
+ }
256
+ return {
257
+ group: "api",
258
+ count: api.length,
259
+ commands,
260
+ ...(commands.length < api.length ? { find } : {}),
261
+ };
262
+ };
263
+ const isNamed = ([command, one], named) => normal(command) === named || (one.aliases ?? []).some((alias) => normal(alias) === named);
264
+ /** An agent's read leaves out empty fields (`agentView`), so no field of a record is sure to be there. */
265
+ const asAgentSees = (schema, inRecord = false) => {
266
+ if (Array.isArray(schema))
267
+ return schema.map((one) => asAgentSees(one, inRecord));
268
+ if (schema === null || typeof schema !== "object")
269
+ return schema;
270
+ return Object.fromEntries(Object.entries(schema)
271
+ .filter(([key]) => !(inRecord && key === "required"))
272
+ .map(([key, value]) => [
273
+ key,
274
+ key === "properties" && value !== null && typeof value === "object"
275
+ ? Object.fromEntries(Object.entries(value).map(([name, inner]) => [
276
+ name,
277
+ asAgentSees(inner, inRecord || name === "item" || name === "items"),
278
+ ]))
279
+ : asAgentSees(value, inRecord),
280
+ ]));
281
+ };
282
+ /** Only a read of records goes out lean (`leansRead`); a write's receipt or a report keeps every field. */
283
+ const leanSchema = (one, schema) => leansRead({ writes: one.writes, ...(one.answers ? { entity: one.answers } : {}) }) ? asAgentSees(schema) : schema;
284
+ /** Every command a line, grouped by the first word; the CLI's own upkeep in one line, `api *` as a count. */
285
+ const listingOf = (commands, prefix) => {
286
+ const all = search(commands, "");
287
+ const api = all.filter(([command]) => isApi(command));
288
+ // An upkeep command that is refused or asks first keeps its own line, so the listing still says so.
289
+ const service = all.filter(([command, one]) => !isApi(command) && one.upkeep === true && !("availability" in availabilityOf(one)));
290
+ const own = all.filter(([command]) => !isApi(command) && !service.some(([named]) => named === command));
291
+ const rows = [
292
+ ...own.map(([command, one]) => ({
293
+ command,
294
+ // A listing is a line a command: the shorter text, since memo's descriptions alone took 55,000 characters.
295
+ does: one.title.length < one.description.length ? one.title : one.description,
296
+ ...(one.writes ? { writes: true } : {}),
297
+ ...availabilityOf(one),
298
+ })),
299
+ ...(service.length ? [{ group: "service", commands: service.map(([command]) => command) }] : []),
300
+ ];
301
+ const listed = [
302
+ ...rows,
303
+ ...(api.length ? [apiGroup(api, prefix, AGENT_ANSWER_CHARS - JSON.stringify(rows).length)] : []),
304
+ ];
305
+ return listed;
306
+ };
307
+ /**
308
+ * The answer of `<prefix>_tools_search`: the first matches with their arguments, the rest a line each; with no
309
+ * words, the listing; with `schema` and a command's exact name, that command's answer schema too.
310
+ * @experimental
311
+ */
312
+ export const searchAnswer = (commands, prefix, { query = "", schema = false } = {}) => {
313
+ if (schema) {
314
+ const [command, one] = Object.entries(commands).find((entry) => isNamed(entry, normal(query))) ?? [];
315
+ if (command === undefined || !one)
316
+ throw new CliError("validation_error", `schema needs a command's exact name; "${query}" is none`);
317
+ const { next: _none, ...list } = listOf(`${prefix}_tools_search`, {
318
+ items: [
319
+ {
320
+ ...fullMatch(command, one),
321
+ output: leanSchema(one, toJsonSchema(one.output ?? (one.answers ? entityAnswer(one.answers) : ANSWER))),
322
+ },
323
+ ],
324
+ limit: 1,
325
+ has_more: false,
326
+ });
327
+ return list;
328
+ }
329
+ if (normal(query) === "api") {
330
+ const api = search(commands, "").filter(([command]) => isApi(command));
331
+ if (api.length)
332
+ return unpaged(prefix, [apiGroup(api, prefix, AGENT_ANSWER_CHARS)], false);
333
+ }
334
+ const found = query.trim() ? matchesOf(commands, query) : [];
335
+ const items = query.trim()
336
+ ? found
337
+ .slice(0, MATCHES)
338
+ .map(([command, one], index) => (index < FULL_MATCHES ? fullMatch(command, one) : shortMatch(command, one)))
339
+ : listingOf(commands, prefix);
340
+ return unpaged(prefix, items, found.length > items.length);
341
+ };
342
+ // The tool takes no page: more matches mean narrower words, so the list carries no page to read on.
343
+ const unpaged = (prefix, items, more) => {
344
+ const { next: _paging, page, ...list } = listOf(`${prefix}_tools_search`, {
345
+ items,
346
+ limit: Math.max(items.length, 1),
347
+ has_more: more,
348
+ });
349
+ const { next_page: _none, ...shown } = page;
350
+ return { ...list, page: shown };
97
351
  };
98
352
  const nearest = (commands, asked) => {
99
353
  const words = normal(asked).split(" ");
@@ -118,6 +372,88 @@ const runnableOnly = (result, offered) => {
118
372
  content: result.content.map((part) => (part.type === "text" ? { ...part, text: JSON.stringify(kept) } : part)),
119
373
  };
120
374
  };
375
+ const rewritten = (result, body) => ({
376
+ ...result,
377
+ structuredContent: body,
378
+ content: result.content.map((part) => (part.type === "text" ? { ...part, text: JSON.stringify(body) } : part)),
379
+ });
380
+ /**
381
+ * A page cut short at the size an agent reads whole, with a `page.next` that starts at the first row left out. Pages
382
+ * are offsets of `(page - 1) * limit`, so the shorter limit must divide the rows before this page. A cursor marks the
383
+ * end of the provider's page, never a row inside it, so a cursor list is not cut.
384
+ */
385
+ const cutPage = (body, command, one, args) => {
386
+ const { items, page } = body;
387
+ if (one.writes || !Array.isArray(items) || page?.mode !== "page" || typeof page.limit !== "number")
388
+ return undefined;
389
+ if (!("page" in one.input.entries && "limit" in one.input.entries))
390
+ return undefined;
391
+ const before = (Number(args.page ?? 1) - 1) * page.limit;
392
+ if (!Number.isSafeInteger(before) || before < 0)
393
+ return undefined;
394
+ const paged = body.next?.find((step) => step.kind === "command" && step.step === "page.next");
395
+ // `all` read every row from the start; the step reads on from one page, and `--all` with `--page` is refused.
396
+ const { all: _all, ...rest } = paged?.kind === "command" ? paged.args : args;
397
+ // Sizes once: a 3,000-row page cut a row at a time stringified the whole page 3,000 times.
398
+ const ends = [];
399
+ items.forEach((item, index) => {
400
+ ends.push((ends[index - 1] ?? 0) + JSON.stringify(item).length + (index > 0 ? 1 : 0));
401
+ });
402
+ for (let shown = items.length - 1; shown >= 1; shown--) {
403
+ if (before % shown !== 0)
404
+ continue;
405
+ const values = { page: before / shown + 2, limit: shown };
406
+ const stepArgs = { ...rest, ...values };
407
+ const fresh = nextStep("page.next", { command, args: stepArgs, values: { shown } });
408
+ const step = paged?.kind === "command" ? { ...paged, args: stepArgs, why: fresh.why } : fresh;
409
+ const shell = {
410
+ ...body,
411
+ items: [],
412
+ page: { ...page, limit: shown, has_more: true, next_page: values.page },
413
+ next: [step, ...(body.next ?? []).filter((other) => other !== paged)].slice(0, MAX_NEXT_STEPS),
414
+ };
415
+ if (JSON.stringify(shell).length + (ends[shown - 1] ?? 0) <= AGENT_ANSWER_CHARS)
416
+ return { ...shell, items: items.slice(0, shown) };
417
+ }
418
+ return undefined;
419
+ };
420
+ /** Too large and no page to carry the rest: whole, since the data is complete, with a limit that fits for a list. */
421
+ const flagged = (body, size, command, one, args) => {
422
+ const items = Array.isArray(body.items) ? body.items.length : 0;
423
+ const fits = Math.floor(((items * AGENT_ANSWER_CHARS) / size) * 0.9);
424
+ if (!("limit" in one.input.entries) || fits < 1 || fits >= items)
425
+ return body;
426
+ const { all: _all, page: _page, ...rest } = args;
427
+ const step = {
428
+ kind: "command",
429
+ step: "output.limit",
430
+ command,
431
+ args: { ...rest, limit: fits },
432
+ why: `this answer is ${size} characters, more than an agent reads whole; limit ${fits} gives a smaller one`,
433
+ safe_to_auto_execute: false,
434
+ };
435
+ return { ...body, next: [...(body.next ?? []), step].slice(0, MAX_NEXT_STEPS) };
436
+ };
437
+ /** An answer past what an agent reads whole: cut where a page carries the rest, else whole with a smaller limit. */
438
+ const fitted = (result, command, one, args) => {
439
+ const body = result.structuredContent;
440
+ // A write's answer says what was changed: never cut, and the step to rerun it with a smaller limit would write again.
441
+ if (one.writes || result.isError || !body)
442
+ return result;
443
+ const size = JSON.stringify(body).length;
444
+ if (size <= AGENT_ANSWER_CHARS)
445
+ return result;
446
+ const cut = (() => {
447
+ try {
448
+ return cutPage(body, command, one, args);
449
+ }
450
+ catch {
451
+ // A step template refuses args it cannot print (an object, a newline): the answer goes out whole instead.
452
+ return undefined;
453
+ }
454
+ })();
455
+ return rewritten(result, cut ?? flagged(body, size, command, one, args));
456
+ };
121
457
  const takesNothing = (one) => Object.values(one.input.entries).every((entry) => entry.type === "optional");
122
458
  /** A reading command an agent can run as it is, a listing first: the example in the call's description. */
123
459
  const sampleOf = (commands) => {
@@ -149,35 +485,21 @@ isMessenger) => {
149
485
  outputSchema: toStandardJsonSchema(v.looseObject({})),
150
486
  title: "Find a command",
151
487
  description: `Find the command for a task — ${tasks} — before calling ` +
152
- `${prefix}_read or ${prefix}_write with it. Each match gives its command, whether it writes, its arguments and the shape of its answer. ` +
153
- "With no words, lists every command and title, without arguments.",
154
- inputSchema: toStandardJsonSchema(v.strictObject({ query: v.optional(v.pipe(v.string(), v.description("words that describe the task"))) })),
488
+ `${prefix}_read or ${prefix}_write with it. Up to ${MATCHES} matches, best first: each gives its command, ` +
489
+ `what it does and whether it writes; the first ${FULL_MATCHES} also give their arguments. A command's exact ` +
490
+ 'name ranks it first. With no words, lists every command a line, by group; "api" lists the api commands.',
491
+ inputSchema: toStandardJsonSchema(v.strictObject({
492
+ query: v.optional(v.pipe(v.string(), v.description("words that describe the task"))),
493
+ schema: v.optional(v.pipe(v.boolean(), v.description("with a command's exact name as query: also its answer's schema, as an agent reads it"))),
494
+ })),
155
495
  annotations: { ...READ, openWorldHint: false, idempotentHint: true },
156
- }, async ({ query }) => {
157
- const found = search(commands, query ?? "");
158
- const items = query?.trim()
159
- ? found.slice(0, MATCHES).map(([command, one]) => ({
160
- command,
161
- title: one.title,
162
- description: one.description,
163
- writes: one.writes,
164
- availability: one.availability?.() ?? { available: true },
165
- arguments: toJsonSchema(one.input),
166
- output: toJsonSchema(one.output ?? ANSWER),
167
- }))
168
- : found.map(([command, one]) => ({
169
- command,
170
- title: one.title,
171
- writes: one.writes,
172
- availability: one.availability?.() ?? { available: true },
173
- }));
174
- // The tool takes no page: more matches mean narrower words, so the list carries no page.next to rerun.
175
- const { next: _paging, ...list } = listOf(`${prefix}_tools_search`, {
176
- items,
177
- limit: Math.max(items.length, query?.trim() ? MATCHES : 1),
178
- has_more: found.length > items.length,
179
- });
180
- return answered(list);
496
+ }, async ({ query, schema }) => {
497
+ try {
498
+ return answered(searchAnswer(commands, prefix, { query: query ?? "", schema: schema === true }));
499
+ }
500
+ catch (error) {
501
+ return failed(error, errors);
502
+ }
181
503
  });
182
504
  // A CLI's own server runs in its own process: its environment names the agent that started it on stdio.
183
505
  const callers = {
@@ -198,14 +520,16 @@ isMessenger) => {
198
520
  throw new CliError("validation_error", `"${command}" ${writing ? "only reads" : "writes"}: call it with ${prefix}_${writing ? "read" : "write"}`);
199
521
  const args = writing ? agentArguments(given ?? {}) : (given ?? {});
200
522
  const caller = currentCaller() ?? callerOf(ctx, command.replace(/[ -]/g, "_"), callers);
523
+ const offered = (named) => byNormal.has(normal(named));
201
524
  if (one.checked)
202
- return runnableOnly(await withCaller(caller, () => one.run(args, ctx)), (named) => byNormal.has(normal(named)));
525
+ return fitted(runnableOnly(await withCaller(caller, () => one.run(args, ctx)), offered), command, one, args);
203
526
  const parsed = v.safeParse(v.strictObject(one.input.entries), args);
204
527
  if (!parsed.success)
205
528
  throw new CliError("validation_error", `${command}: ${v.summarize(parsed.issues)}`, {
206
529
  arguments: toJsonSchema(one.input),
207
530
  });
208
- return runnableOnly(await withCaller(caller, () => one.run(parsed.output, ctx)), (named) => byNormal.has(normal(named)));
531
+ const input = parsed.output;
532
+ return fitted(runnableOnly(await withCaller(caller, () => one.run(input, ctx)), offered), command, one, input);
209
533
  }
210
534
  catch (error) {
211
535
  return failed(error, errors);
@@ -247,6 +571,9 @@ export const surfaceCommands = (tools, registration) => {
247
571
  },
248
572
  ]));
249
573
  };
574
+ /** The name of the entity a command declares: `message`, `message.hit`. */
575
+ export const answersOf = ({ entity, view }) => (view ? `${entity}.${view}` : entity);
250
576
  /** The envelope a command answers with, from the entity it declares (`annotate(…, { output })`). */
251
- export const outputOf = ({ entity, view }) => answerSchema(ENTITIES[(view ? `${entity}.${view}` : entity)] ?? v.unknown());
577
+ export const outputOf = (output) => entityAnswer(answersOf(output));
578
+ const entityAnswer = (name) => answerSchema(ENTITIES[name] ?? v.unknown());
252
579
  //# sourceMappingURL=surface.js.map