@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
@@ -3,12 +3,15 @@ import type { CallToolResult, McpServer, ServerContext } from "@modelcontextprot
3
3
  import { toJsonSchema, toStandardJsonSchema } from "@valibot/to-json-schema"
4
4
  import { CliError } from "@wirecat/cli-base"
5
5
  import type { CommandOutput } from "@wirecat/cli-base/commands"
6
+ import { MAX_NEXT_STEPS, type Meta, type NextStep } from "@wirecat/cli-base/standards"
6
7
  import * as v from "valibot"
7
8
  import { answerSchema, listOf } from "../cli/envelope.js"
9
+ import { nextStep } from "../cli/steps.js"
8
10
  import { ENTITIES, type EntityName } from "../entities/index.js"
9
11
  import type { AppErrors } from "../errors/reasons.js"
10
12
  import type { CommandAvailability } from "./agent.js"
11
13
  import { type CallerSource, callerOf, currentCaller, withCaller } from "./caller.js"
14
+ import { leansRead } from "./lean.js"
12
15
  import { agentArguments } from "./text.js"
13
16
  import {
14
17
  type AnyTool,
@@ -26,13 +29,23 @@ import {
26
29
  WRITE,
27
30
  } from "./tool.js"
28
31
 
29
- const MATCHES = 8
32
+ // Claude Code saves an answer over 25,000 tokens to a file the agent never reads: one match with 14 arguments is
33
+ // 1,700 characters, a match's answer schema was up to 60,000.
34
+ const MATCHES = 5
35
+ const FULL_MATCHES = 2
36
+ /** A match scoring under 45% of the best one answers another task: `polls create` for "messages send". */
37
+ const NEAR = 0.45
38
+ /** About 10,000 tokens, where Claude Code starts to warn; an answer past it is cut where a page can carry the rest. */
39
+ export const AGENT_ANSWER_CHARS = 40_000
30
40
  const ANSWER = answerSchema()
31
41
 
32
42
  // The listing shows an agent only what it acts on; the server still checks every answer against the full envelope,
33
- // and tools_search gives each command's full answer. meta.ranking alone took 2,800 characters of every connect.
43
+ // and tools_search with `schema` gives one command's. meta.ranking alone took 2,800 characters of every connect.
34
44
  const agentAnswer = (prefix: string, writes: boolean) => {
35
- const meta = v.pipe(v.looseObject({}), v.description(`run facts; ${prefix}_tools_search shows the full answer`))
45
+ const meta = v.pipe(
46
+ v.looseObject({}),
47
+ v.description(`run facts; ${prefix}_tools_search with schema: true shows the full answer`),
48
+ )
36
49
  const next = v.optional(v.pipe(v.array(v.looseObject({})), v.description("steps to run next: command and args")))
37
50
  return v.looseObject(
38
51
  writes
@@ -67,8 +80,12 @@ export interface McpCommand {
67
80
  keywords?: readonly string[]
68
81
  writes: boolean
69
82
  input: Input
70
- /** The envelope it answers with, when it declares its entity; any envelope otherwise. */
83
+ /** The envelope it answers with; else the one of `answers`; any envelope otherwise. */
71
84
  output?: v.GenericSchema
85
+ /** The name of the entity it answers with, `message_write`, when it declares one. */
86
+ answers?: string
87
+ /** One of cli-core's commands that run the CLI itself (config, sign-in, the store): one name in the listing. */
88
+ upkeep?: boolean
72
89
  /** `run` checks the arguments itself, and records a refusal. */
73
90
  checked?: boolean
74
91
  run: (args: Record<string, unknown>, ctx: ServerContext) => Promise<CallToolResult>
@@ -100,15 +117,18 @@ const wordsOf = (text: string): string[] =>
100
117
  const stem = (word: string): string => {
101
118
  const bare = word.replace(/'s$/u, "")
102
119
  if (bare.length > 4 && bare.endsWith("ies")) return `${bare.slice(0, -3)}y`
103
- for (const ending of ["ing", "ed", "es", "s"])
120
+ // `es` only after a hiss, so `notes` is `note` as the task's "note" is: `matches` is `match`.
121
+ if (bare.length > 5 && /(?:[sxz]|ch|sh)es$/u.test(bare)) return bare.slice(0, -2)
122
+ for (const ending of ["ing", "ed", "s"])
104
123
  if (bare.length - ending.length >= 3 && bare.endsWith(ending)) return bare.slice(0, -ending.length)
105
124
  return bare
106
125
  }
107
126
 
108
- const sameWord = (asked: string, known: string): boolean => {
109
- if (asked === known) return true
127
+ /** 1 for the same word, ½ for one that starts the other (`time` in `timer`), 0 for another word. */
128
+ const likeness = (asked: string, known: string): number => {
129
+ if (asked === known) return 1
110
130
  const [short, long] = asked.length <= known.length ? [asked, known] : [known, asked]
111
- return short.length >= 3 && long.startsWith(short)
131
+ return short.length >= 3 && long.startsWith(short) ? 0.5 : 0
112
132
  }
113
133
 
114
134
  /** Where a word of the task is found, by how much it says about the command: its own name says the most. */
@@ -119,48 +139,325 @@ const fieldsOf = (command: string, one: McpCommand): [number, string[]][] =>
119
139
  [1, [...wordsOf(one.description), ...(one.keywords ?? []).flatMap(wordsOf), ...Object.keys(one.input.entries)]],
120
140
  ].map(([weight, words]) => [weight as number, [...new Set((words as string[]).map(stem))]])
121
141
 
142
+ /** Each two words in a row, stemmed, that hold a telling word: `reports to`, `a person`, not `to a`. */
143
+ const pairsOf = (text: string): string[] => {
144
+ const words = wordsOf(text)
145
+ return words.slice(1).flatMap((word, at) => {
146
+ const before = words[at] ?? ""
147
+ return STOP_WORDS.has(before) && STOP_WORDS.has(word) ? [] : [`${stem(before)} ${stem(word)}`]
148
+ })
149
+ }
150
+
151
+ /** A task often says what the help says: "who reports to whom" is a phrase of `relationships list`'s help. */
152
+ const PAIR = 3
153
+
122
154
  /**
123
155
  * Ranks by how many words of the task a command matches, then by where they matched: its name, then its title, then
124
156
  * its help, examples and arguments. A task is typed in its own words, so no single word is required. The command
125
157
  * named exactly ranks first. No word lists everything.
126
158
  */
127
159
  export const search = (commands: Record<string, McpCommand>, query: string): [string, McpCommand][] => {
160
+ if (!normal(query)) return Object.entries(commands).sort((a, b) => a[0].localeCompare(b[0]))
161
+ return scored(commands, query).map(({ entry }) => entry)
162
+ }
163
+
164
+ interface Scored {
165
+ entry: [string, McpCommand]
166
+ exact: boolean
167
+ /** Every telling word of the task matched. */
168
+ whole: boolean
169
+ score: number
170
+ }
171
+
172
+ const scored = (commands: Record<string, McpCommand>, query: string): Scored[] => {
128
173
  const named = normal(query)
129
174
  const all = Object.entries(commands)
130
- if (!named) return all.map((entry) => entry).sort((a, b) => a[0].localeCompare(b[0]))
131
- const words = [
175
+ const asked = [
132
176
  ...new Set(
133
177
  wordsOf(query)
134
178
  .filter((word) => word.length > 1 && !STOP_WORDS.has(word))
135
179
  .map(stem),
136
180
  ),
137
181
  ]
182
+ const pairs = [...new Set(pairsOf(query))]
183
+ const phrased = all.map(([command, one]) => {
184
+ // A name's words come in either order, "list events" for `events list`; examples' words are no phrase.
185
+ const names = [command, ...(one.aliases ?? [])].flatMap((name) => [name, wordsOf(name).reverse().join(" ")])
186
+ const known = new Set([...names, one.title, one.description].flatMap(pairsOf))
187
+ return pairs.filter((pair) => known.has(pair)).length
188
+ })
189
+ // Per word: the best field's weight, and how many fields hold the word itself, which breaks a tie.
190
+ const weighed = all.map((entry) => {
191
+ const fields = fieldsOf(entry[0], entry[1])
192
+ return asked.map((word) => {
193
+ const likes = fields.map(([weight, known]) => ({
194
+ weight: weight * known.reduce((most, one) => Math.max(most, likeness(word, one)), 0),
195
+ same: known.includes(word),
196
+ }))
197
+ return {
198
+ weight: likes.reduce((best, one) => Math.max(best, one.weight), 0),
199
+ fields: likes.filter(({ same }) => same).length,
200
+ }
201
+ })
202
+ })
138
203
  return (
139
204
  all
140
- .map((entry) => {
141
- const fields = fieldsOf(entry[0], entry[1])
142
- const weights = words.map((word) =>
143
- fields.reduce(
144
- (best, [weight, known]) => (known.some((one) => sameWord(word, one)) ? Math.max(best, weight) : best),
145
- 0,
146
- ),
147
- )
148
- const matched = weights.filter((weight) => weight > 0).length
149
- const exact = normal(entry[0]) === named || (entry[1].aliases ?? []).some((alias) => normal(alias) === named)
150
- return { entry, matched, rank: (exact ? 1000 : 0) + matched * 10 + weights.reduce((a, b) => a + b, 0) }
205
+ .map((entry, index) => {
206
+ const found = weighed[index] ?? []
207
+ const matched = found.filter(({ weight }) => weight > 0).length
208
+ const exact = isNamed(entry, named)
209
+ return {
210
+ entry,
211
+ exact,
212
+ whole: matched === found.length,
213
+ score:
214
+ matched * 10 +
215
+ found.reduce((sum, { weight }) => sum + weight, 0) +
216
+ (matched ? PAIR * (phrased[index] ?? 0) : 0),
217
+ evidence: found.reduce((sum, { fields }) => sum + fields, 0),
218
+ }
151
219
  })
152
- .filter(({ matched, rank }) => matched > 0 || rank >= 1000)
153
- // A tie goes to the shorter name, which holds less the task did not ask for: `messages send` first.
220
+ .filter(({ score, exact }) => score > 0 || exact)
221
+ // A tie goes to the command that holds the words in more places, then to the shorter name, which holds less the
222
+ // task did not ask for: `messages send` first.
154
223
  .sort(
155
224
  (a, b) =>
156
- b.rank - a.rank ||
225
+ Number(b.exact) - Number(a.exact) ||
226
+ b.score - a.score ||
227
+ b.evidence - a.evidence ||
157
228
  wordsOf(a.entry[0]).length - wordsOf(b.entry[0]).length ||
158
229
  a.entry[0].localeCompare(b.entry[0]),
159
230
  )
160
- .map(({ entry }) => entry)
161
231
  )
162
232
  }
163
233
 
234
+ const isApi = (command: string): boolean => command.split(" ")[0] === "api"
235
+
236
+ /**
237
+ * The commands a task most likely means, best first. Generated `api *` commands rank below the hand-written ones and
238
+ * come in only when the task names `api` or no hand-written command scores near them: in hubspot "find contact" gave
239
+ * eight `api contacts-*` and no `people` command. When no hand-written command matched every word, the best `api *`
240
+ * one still takes the last place: gcal's "free time" is `calendars busy` or `api calendar-freebusy-query`.
241
+ */
242
+ export const matchesOf = (commands: Record<string, McpCommand>, query: string): [string, McpCommand][] => {
243
+ const ranked = scored(commands, query)
244
+ const groups = new Set(wordsOf(query).map(stem))
245
+ if (normal(query).split(" ")[0] === "api") return near(ranked, groups)
246
+ const own = ranked.filter(({ entry, exact }) => exact || !isApi(entry[0]))
247
+ const api = ranked.filter(({ entry, exact }) => !exact && isApi(entry[0]))
248
+ const best = bestOf(own)
249
+ if (best < NEAR * (api[0]?.score ?? 0)) return near([...own, ...api], groups)
250
+ const shown = near(own, groups)
251
+ const fallback = api[0]
252
+ if (!fallback || own.some(({ whole }) => whole) || fallback.score < NEAR * best) return shown
253
+ return [...shown.slice(0, MATCHES - 1), fallback.entry, ...shown.slice(MATCHES - 1)]
254
+ }
255
+
256
+ const bestOf = (ranked: Scored[]): number => ranked.reduce((best, { score }) => Math.max(best, score), 0)
257
+
258
+ /** At most 2 of one group the task does not name: five `schedule *` siblings hid `calendars busy`. */
259
+ const SIBLINGS = 2
260
+
261
+ const near = (ranked: Scored[], groups: Set<string>): [string, McpCommand][] => {
262
+ const best = bestOf(ranked)
263
+ const taken = new Map<string, number>()
264
+ return ranked
265
+ .filter(({ exact, score }) => exact || score >= NEAR * best)
266
+ .filter(({ entry, exact }) => {
267
+ const group = stem(entry[0].split(" ")[0] ?? "")
268
+ const count = (taken.get(group) ?? 0) + 1
269
+ taken.set(group, count)
270
+ return exact || groups.has(group) || count <= SIBLINGS
271
+ })
272
+ .map(({ entry }) => entry)
273
+ }
274
+
275
+ // Keywords that check a value, not what it means; the CLI checks them again. Data keys keep everything under them.
276
+ const CHECKS = new Set(["$schema", "pattern", "minLength", "minItems"])
277
+ const DATA = new Set(["default", "enum", "const", "examples"])
278
+
279
+ /** A command's arguments as an agent needs them to call it: type, description, enum, default, required. */
280
+ export const argumentsOf = (one: McpCommand): unknown => {
281
+ const bare = (node: unknown): unknown => {
282
+ if (Array.isArray(node)) return node.map(bare)
283
+ if (node === null || typeof node !== "object") return node
284
+ return Object.fromEntries(
285
+ Object.entries(node)
286
+ .filter(
287
+ ([key, value]) =>
288
+ !CHECKS.has(key) &&
289
+ !(key === "additionalProperties" && value === false) &&
290
+ !(key === "required" && Array.isArray(value) && value.length === 0),
291
+ )
292
+ .map(([key, value]) => [
293
+ key,
294
+ DATA.has(key)
295
+ ? value
296
+ : key === "properties" && value !== null && typeof value === "object"
297
+ ? Object.fromEntries(Object.entries(value).map(([name, inner]) => [name, bare(inner)]))
298
+ : bare(value),
299
+ ]),
300
+ )
301
+ }
302
+ return bare(toJsonSchema(one.input))
303
+ }
304
+
305
+ /** Shown only when it changes what the agent does: a command that is refused, or that asks the owner first. */
306
+ const availabilityOf = (one: McpCommand) => {
307
+ const availability = one.availability?.()
308
+ return availability && (!availability.available || (availability.level ?? "allow") !== "allow")
309
+ ? { availability }
310
+ : {}
311
+ }
312
+
313
+ const shortMatch = (command: string, one: McpCommand) => ({
314
+ command,
315
+ does: one.description,
316
+ writes: one.writes,
317
+ ...availabilityOf(one),
318
+ })
319
+
320
+ const fullMatch = (command: string, one: McpCommand) => ({
321
+ command,
322
+ ...(one.title !== one.description ? { title: one.title } : {}),
323
+ does: one.description,
324
+ writes: one.writes,
325
+ ...(one.answers ? { answers: one.answers } : {}),
326
+ ...availabilityOf(one),
327
+ arguments: argumentsOf(one),
328
+ })
329
+
330
+ const API_ROOM = 2_000
331
+
332
+ /**
333
+ * The generated `api *` commands as names, each reachable by its own name; past `room` characters, the names that fit
334
+ * and how to find the rest.
335
+ */
336
+ const apiGroup = (api: [string, McpCommand][], prefix: string, room: number) => {
337
+ const find = `${prefix}_tools_search with "api" and words of the task, for example "${api[0]?.[0]}"`
338
+ const commands: string[] = []
339
+ let size = find.length + API_ROOM
340
+ for (const [command] of api) {
341
+ size += command.length + 3
342
+ if (size > room) break
343
+ commands.push(command)
344
+ }
345
+ return {
346
+ group: "api",
347
+ count: api.length,
348
+ commands,
349
+ ...(commands.length < api.length ? { find } : {}),
350
+ }
351
+ }
352
+
353
+ const isNamed = ([command, one]: [string, McpCommand], named: string) =>
354
+ normal(command) === named || (one.aliases ?? []).some((alias) => normal(alias) === named)
355
+
356
+ /** An agent's read leaves out empty fields (`agentView`), so no field of a record is sure to be there. */
357
+ const asAgentSees = (schema: unknown, inRecord = false): unknown => {
358
+ if (Array.isArray(schema)) return schema.map((one) => asAgentSees(one, inRecord))
359
+ if (schema === null || typeof schema !== "object") return schema
360
+ return Object.fromEntries(
361
+ Object.entries(schema)
362
+ .filter(([key]) => !(inRecord && key === "required"))
363
+ .map(([key, value]) => [
364
+ key,
365
+ key === "properties" && value !== null && typeof value === "object"
366
+ ? Object.fromEntries(
367
+ Object.entries(value).map(([name, inner]) => [
368
+ name,
369
+ asAgentSees(inner, inRecord || name === "item" || name === "items"),
370
+ ]),
371
+ )
372
+ : asAgentSees(value, inRecord),
373
+ ]),
374
+ )
375
+ }
376
+
377
+ /** Only a read of records goes out lean (`leansRead`); a write's receipt or a report keeps every field. */
378
+ const leanSchema = (one: McpCommand, schema: unknown) =>
379
+ leansRead({ writes: one.writes, ...(one.answers ? { entity: one.answers } : {}) }) ? asAgentSees(schema) : schema
380
+
381
+ /** Every command a line, grouped by the first word; the CLI's own upkeep in one line, `api *` as a count. */
382
+ const listingOf = (commands: Record<string, McpCommand>, prefix: string) => {
383
+ const all = search(commands, "")
384
+ const api = all.filter(([command]) => isApi(command))
385
+ // An upkeep command that is refused or asks first keeps its own line, so the listing still says so.
386
+ const service = all.filter(
387
+ ([command, one]) => !isApi(command) && one.upkeep === true && !("availability" in availabilityOf(one)),
388
+ )
389
+ const own = all.filter(([command]) => !isApi(command) && !service.some(([named]) => named === command))
390
+ const rows = [
391
+ ...own.map(([command, one]) => ({
392
+ command,
393
+ // A listing is a line a command: the shorter text, since memo's descriptions alone took 55,000 characters.
394
+ does: one.title.length < one.description.length ? one.title : one.description,
395
+ ...(one.writes ? { writes: true } : {}),
396
+ ...availabilityOf(one),
397
+ })),
398
+ ...(service.length ? [{ group: "service", commands: service.map(([command]) => command) }] : []),
399
+ ]
400
+ const listed = [
401
+ ...rows,
402
+ ...(api.length ? [apiGroup(api, prefix, AGENT_ANSWER_CHARS - JSON.stringify(rows).length)] : []),
403
+ ]
404
+ return listed
405
+ }
406
+
407
+ /**
408
+ * The answer of `<prefix>_tools_search`: the first matches with their arguments, the rest a line each; with no
409
+ * words, the listing; with `schema` and a command's exact name, that command's answer schema too.
410
+ * @experimental
411
+ */
412
+ export const searchAnswer = (
413
+ commands: Record<string, McpCommand>,
414
+ prefix: string,
415
+ { query = "", schema = false }: { query?: string; schema?: boolean } = {},
416
+ ) => {
417
+ if (schema) {
418
+ const [command, one] = Object.entries(commands).find((entry) => isNamed(entry, normal(query))) ?? []
419
+ if (command === undefined || !one)
420
+ throw new CliError("validation_error", `schema needs a command's exact name; "${query}" is none`)
421
+ const { next: _none, ...list } = listOf(`${prefix}_tools_search`, {
422
+ items: [
423
+ {
424
+ ...fullMatch(command, one),
425
+ output: leanSchema(one, toJsonSchema(one.output ?? (one.answers ? entityAnswer(one.answers) : ANSWER))),
426
+ },
427
+ ],
428
+ limit: 1,
429
+ has_more: false,
430
+ })
431
+ return list
432
+ }
433
+ if (normal(query) === "api") {
434
+ const api = search(commands, "").filter(([command]) => isApi(command))
435
+ if (api.length) return unpaged(prefix, [apiGroup(api, prefix, AGENT_ANSWER_CHARS)], false)
436
+ }
437
+ const found = query.trim() ? matchesOf(commands, query) : []
438
+ const items = query.trim()
439
+ ? found
440
+ .slice(0, MATCHES)
441
+ .map(([command, one], index) => (index < FULL_MATCHES ? fullMatch(command, one) : shortMatch(command, one)))
442
+ : listingOf(commands, prefix)
443
+ return unpaged(prefix, items, found.length > items.length)
444
+ }
445
+
446
+ // The tool takes no page: more matches mean narrower words, so the list carries no page to read on.
447
+ const unpaged = (prefix: string, items: unknown[], more: boolean) => {
448
+ const {
449
+ next: _paging,
450
+ page,
451
+ ...list
452
+ } = listOf(`${prefix}_tools_search`, {
453
+ items,
454
+ limit: Math.max(items.length, 1),
455
+ has_more: more,
456
+ })
457
+ const { next_page: _none, ...shown } = page as typeof page & { next_page?: number }
458
+ return { ...list, page: shown }
459
+ }
460
+
164
461
  const nearest = (commands: Record<string, McpCommand>, asked: string): string[] => {
165
462
  const words = normal(asked).split(" ")
166
463
  return Object.keys(commands)
@@ -185,6 +482,91 @@ const runnableOnly = (result: CallToolResult, offered: (command: string) => bool
185
482
  }
186
483
  }
187
484
 
485
+ type Body = Record<string, unknown> & { items?: unknown[]; next?: NextStep[]; meta?: Meta }
486
+
487
+ const rewritten = (result: CallToolResult, body: Body): CallToolResult => ({
488
+ ...result,
489
+ structuredContent: body,
490
+ content: result.content.map((part) => (part.type === "text" ? { ...part, text: JSON.stringify(body) } : part)),
491
+ })
492
+
493
+ /**
494
+ * A page cut short at the size an agent reads whole, with a `page.next` that starts at the first row left out. Pages
495
+ * are offsets of `(page - 1) * limit`, so the shorter limit must divide the rows before this page. A cursor marks the
496
+ * end of the provider's page, never a row inside it, so a cursor list is not cut.
497
+ */
498
+ const cutPage = (body: Body, command: string, one: McpCommand, args: Record<string, unknown>): Body | undefined => {
499
+ const { items, page } = body as { items?: unknown[]; page?: { mode?: string; limit?: number } }
500
+ if (one.writes || !Array.isArray(items) || page?.mode !== "page" || typeof page.limit !== "number") return undefined
501
+ if (!("page" in one.input.entries && "limit" in one.input.entries)) return undefined
502
+ const before = (Number(args.page ?? 1) - 1) * page.limit
503
+ if (!Number.isSafeInteger(before) || before < 0) return undefined
504
+ const paged = body.next?.find((step) => step.kind === "command" && step.step === "page.next")
505
+ // `all` read every row from the start; the step reads on from one page, and `--all` with `--page` is refused.
506
+ const { all: _all, ...rest } = paged?.kind === "command" ? paged.args : args
507
+ // Sizes once: a 3,000-row page cut a row at a time stringified the whole page 3,000 times.
508
+ const ends: number[] = []
509
+ items.forEach((item, index) => {
510
+ ends.push((ends[index - 1] ?? 0) + JSON.stringify(item).length + (index > 0 ? 1 : 0))
511
+ })
512
+ for (let shown = items.length - 1; shown >= 1; shown--) {
513
+ if (before % shown !== 0) continue
514
+ const values = { page: before / shown + 2, limit: shown }
515
+ const stepArgs = { ...rest, ...values }
516
+ const fresh = nextStep("page.next", { command, args: stepArgs, values: { shown } })
517
+ const step = paged?.kind === "command" ? { ...paged, args: stepArgs, why: fresh.why } : fresh
518
+ const shell = {
519
+ ...body,
520
+ items: [],
521
+ page: { ...page, limit: shown, has_more: true, next_page: values.page },
522
+ next: [step, ...(body.next ?? []).filter((other) => other !== paged)].slice(0, MAX_NEXT_STEPS),
523
+ }
524
+ if (JSON.stringify(shell).length + (ends[shown - 1] ?? 0) <= AGENT_ANSWER_CHARS)
525
+ return { ...shell, items: items.slice(0, shown) }
526
+ }
527
+ return undefined
528
+ }
529
+
530
+ /** Too large and no page to carry the rest: whole, since the data is complete, with a limit that fits for a list. */
531
+ const flagged = (body: Body, size: number, command: string, one: McpCommand, args: Record<string, unknown>): Body => {
532
+ const items = Array.isArray(body.items) ? body.items.length : 0
533
+ const fits = Math.floor(((items * AGENT_ANSWER_CHARS) / size) * 0.9)
534
+ if (!("limit" in one.input.entries) || fits < 1 || fits >= items) return body
535
+ const { all: _all, page: _page, ...rest } = args
536
+ const step: NextStep = {
537
+ kind: "command",
538
+ step: "output.limit",
539
+ command,
540
+ args: { ...rest, limit: fits },
541
+ why: `this answer is ${size} characters, more than an agent reads whole; limit ${fits} gives a smaller one`,
542
+ safe_to_auto_execute: false,
543
+ }
544
+ return { ...body, next: [...(body.next ?? []), step].slice(0, MAX_NEXT_STEPS) }
545
+ }
546
+
547
+ /** An answer past what an agent reads whole: cut where a page carries the rest, else whole with a smaller limit. */
548
+ const fitted = (
549
+ result: CallToolResult,
550
+ command: string,
551
+ one: McpCommand,
552
+ args: Record<string, unknown>,
553
+ ): CallToolResult => {
554
+ const body = result.structuredContent as Body | undefined
555
+ // A write's answer says what was changed: never cut, and the step to rerun it with a smaller limit would write again.
556
+ if (one.writes || result.isError || !body) return result
557
+ const size = JSON.stringify(body).length
558
+ if (size <= AGENT_ANSWER_CHARS) return result
559
+ const cut = (() => {
560
+ try {
561
+ return cutPage(body, command, one, args)
562
+ } catch {
563
+ // A step template refuses args it cannot print (an object, a newline): the answer goes out whole instead.
564
+ return undefined
565
+ }
566
+ })()
567
+ return rewritten(result, cut ?? flagged(body, size, command, one, args))
568
+ }
569
+
188
570
  const takesNothing = (one: McpCommand): boolean =>
189
571
  Object.values(one.input.entries).every((entry) => entry.type === "optional")
190
572
 
@@ -230,38 +612,28 @@ export const registerCommands = (
230
612
  title: "Find a command",
231
613
  description:
232
614
  `Find the command for a task — ${tasks} — before calling ` +
233
- `${prefix}_read or ${prefix}_write with it. Each match gives its command, whether it writes, its arguments and the shape of its answer. ` +
234
- "With no words, lists every command and title, without arguments.",
615
+ `${prefix}_read or ${prefix}_write with it. Up to ${MATCHES} matches, best first: each gives its command, ` +
616
+ `what it does and whether it writes; the first ${FULL_MATCHES} also give their arguments. A command's exact ` +
617
+ 'name ranks it first. With no words, lists every command a line, by group; "api" lists the api commands.',
235
618
  inputSchema: toStandardJsonSchema(
236
- v.strictObject({ query: v.optional(v.pipe(v.string(), v.description("words that describe the task"))) }),
619
+ v.strictObject({
620
+ query: v.optional(v.pipe(v.string(), v.description("words that describe the task"))),
621
+ schema: v.optional(
622
+ v.pipe(
623
+ v.boolean(),
624
+ v.description("with a command's exact name as query: also its answer's schema, as an agent reads it"),
625
+ ),
626
+ ),
627
+ }),
237
628
  ),
238
629
  annotations: { ...READ, openWorldHint: false, idempotentHint: true },
239
630
  },
240
- async ({ query }: { query?: string }) => {
241
- const found = search(commands, query ?? "")
242
- const items = query?.trim()
243
- ? found.slice(0, MATCHES).map(([command, one]) => ({
244
- command,
245
- title: one.title,
246
- description: one.description,
247
- writes: one.writes,
248
- availability: one.availability?.() ?? { available: true },
249
- arguments: toJsonSchema(one.input),
250
- output: toJsonSchema(one.output ?? ANSWER),
251
- }))
252
- : found.map(([command, one]) => ({
253
- command,
254
- title: one.title,
255
- writes: one.writes,
256
- availability: one.availability?.() ?? { available: true },
257
- }))
258
- // The tool takes no page: more matches mean narrower words, so the list carries no page.next to rerun.
259
- const { next: _paging, ...list } = listOf(`${prefix}_tools_search`, {
260
- items,
261
- limit: Math.max(items.length, query?.trim() ? MATCHES : 1),
262
- has_more: found.length > items.length,
263
- })
264
- return answered(list)
631
+ async ({ query, schema }: { query?: string; schema?: boolean }) => {
632
+ try {
633
+ return answered(searchAnswer(commands, prefix, { query: query ?? "", schema: schema === true }))
634
+ } catch (error) {
635
+ return failed(error, errors)
636
+ }
265
637
  },
266
638
  )
267
639
 
@@ -295,19 +667,16 @@ export const registerCommands = (
295
667
  )
296
668
  const args = writing ? agentArguments(given ?? {}) : (given ?? {})
297
669
  const caller = currentCaller() ?? callerOf(ctx, command.replace(/[ -]/g, "_"), callers)
670
+ const offered = (named: string) => byNormal.has(normal(named))
298
671
  if (one.checked)
299
- return runnableOnly(await withCaller(caller, () => one.run(args, ctx)), (named) =>
300
- byNormal.has(normal(named)),
301
- )
672
+ return fitted(runnableOnly(await withCaller(caller, () => one.run(args, ctx)), offered), command, one, args)
302
673
  const parsed = v.safeParse(v.strictObject(one.input.entries), args)
303
674
  if (!parsed.success)
304
675
  throw new CliError("validation_error", `${command}: ${v.summarize(parsed.issues)}`, {
305
676
  arguments: toJsonSchema(one.input),
306
677
  })
307
- return runnableOnly(
308
- await withCaller(caller, () => one.run(parsed.output as Record<string, unknown>, ctx)),
309
- (named) => byNormal.has(normal(named)),
310
- )
678
+ const input = parsed.output as Record<string, unknown>
679
+ return fitted(runnableOnly(await withCaller(caller, () => one.run(input, ctx)), offered), command, one, input)
311
680
  } catch (error) {
312
681
  return failed(error, errors)
313
682
  }
@@ -368,8 +737,11 @@ export const surfaceCommands = (
368
737
  )
369
738
  }
370
739
 
740
+ /** The name of the entity a command declares: `message`, `message.hit`. */
741
+ export const answersOf = ({ entity, view }: CommandOutput): string => (view ? `${entity}.${view}` : entity)
742
+
371
743
  /** The envelope a command answers with, from the entity it declares (`annotate(…, { output })`). */
372
- export const outputOf = ({ entity, view }: CommandOutput): v.GenericSchema =>
373
- answerSchema(
374
- (ENTITIES[(view ? `${entity}.${view}` : entity) as EntityName] as v.GenericSchema | undefined) ?? v.unknown(),
375
- )
744
+ export const outputOf = (output: CommandOutput): v.GenericSchema => entityAnswer(answersOf(output))
745
+
746
+ const entityAnswer = (name: string): v.GenericSchema =>
747
+ answerSchema((ENTITIES[name as EntityName] as v.GenericSchema | undefined) ?? v.unknown())