@humain/terminal 0.0.2 → 0.0.3-beta.1

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 (688) hide show
  1. package/CHANGELOG.md +251 -24
  2. package/README.md +143 -119
  3. package/dist/cli/args.d.ts +4 -2
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +37 -39
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/auth-check.d.ts +19 -0
  8. package/dist/cli/auth-check.d.ts.map +1 -0
  9. package/dist/cli/auth-check.js +50 -0
  10. package/dist/cli/auth-check.js.map +1 -0
  11. package/dist/cli/auth-command.d.ts +24 -0
  12. package/dist/cli/auth-command.d.ts.map +1 -0
  13. package/dist/cli/auth-command.js +103 -0
  14. package/dist/cli/auth-command.js.map +1 -0
  15. package/dist/cli/config-selector.d.ts.map +1 -1
  16. package/dist/cli/config-selector.js +2 -2
  17. package/dist/cli/config-selector.js.map +1 -1
  18. package/dist/cli/credential-print.d.ts +5 -15
  19. package/dist/cli/credential-print.d.ts.map +1 -1
  20. package/dist/cli/credential-print.js +42 -83
  21. package/dist/cli/credential-print.js.map +1 -1
  22. package/dist/cli/experimental/auth.d.ts +16 -0
  23. package/dist/cli/experimental/auth.d.ts.map +1 -0
  24. package/dist/cli/experimental/auth.js +13 -0
  25. package/dist/cli/experimental/auth.js.map +1 -0
  26. package/dist/cli/experimental/cli.d.ts +6 -0
  27. package/dist/cli/experimental/cli.d.ts.map +1 -0
  28. package/dist/cli/experimental/cli.js +5 -0
  29. package/dist/cli/experimental/cli.js.map +1 -0
  30. package/dist/cli/experimental/command-options.d.ts +17 -0
  31. package/dist/cli/experimental/command-options.d.ts.map +1 -0
  32. package/dist/cli/experimental/command-options.js +35 -0
  33. package/dist/cli/experimental/command-options.js.map +1 -0
  34. package/dist/cli/experimental/command.d.ts +63 -0
  35. package/dist/cli/experimental/command.d.ts.map +1 -0
  36. package/dist/cli/experimental/command.js +130 -0
  37. package/dist/cli/experimental/command.js.map +1 -0
  38. package/dist/cli/experimental/commands/client.d.ts +13 -0
  39. package/dist/cli/experimental/commands/client.d.ts.map +1 -0
  40. package/dist/cli/experimental/commands/client.js +25 -0
  41. package/dist/cli/experimental/commands/client.js.map +1 -0
  42. package/dist/cli/experimental/commands/pi.d.ts +15 -0
  43. package/dist/cli/experimental/commands/pi.d.ts.map +1 -0
  44. package/dist/cli/experimental/commands/pi.js +28 -0
  45. package/dist/cli/experimental/commands/pi.js.map +1 -0
  46. package/dist/cli/experimental/commands/server.d.ts +13 -0
  47. package/dist/cli/experimental/commands/server.d.ts.map +1 -0
  48. package/dist/cli/experimental/commands/server.js +25 -0
  49. package/dist/cli/experimental/commands/server.js.map +1 -0
  50. package/dist/cli/experimental/transport-address.d.ts +10 -0
  51. package/dist/cli/experimental/transport-address.d.ts.map +1 -0
  52. package/dist/cli/experimental/transport-address.js +38 -0
  53. package/dist/cli/experimental/transport-address.js.map +1 -0
  54. package/dist/cli/list-models.d.ts +1 -1
  55. package/dist/cli/list-models.d.ts.map +1 -1
  56. package/dist/cli/list-models.js +2 -2
  57. package/dist/cli/list-models.js.map +1 -1
  58. package/dist/cli/startup-ui.d.ts +1 -1
  59. package/dist/cli/startup-ui.d.ts.map +1 -1
  60. package/dist/cli/startup-ui.js +2 -2
  61. package/dist/cli/startup-ui.js.map +1 -1
  62. package/dist/client/index.d.ts +3 -0
  63. package/dist/client/index.d.ts.map +1 -0
  64. package/dist/client/index.js +3 -0
  65. package/dist/client/index.js.map +1 -0
  66. package/dist/client/remote-session.d.ts +53 -0
  67. package/dist/client/remote-session.d.ts.map +1 -0
  68. package/dist/client/remote-session.js +340 -0
  69. package/dist/client/remote-session.js.map +1 -0
  70. package/dist/client/transcript.d.ts +12 -0
  71. package/dist/client/transcript.d.ts.map +1 -0
  72. package/dist/client/transcript.js +98 -0
  73. package/dist/client/transcript.js.map +1 -0
  74. package/dist/config.d.ts.map +1 -1
  75. package/dist/config.js +4 -3
  76. package/dist/config.js.map +1 -1
  77. package/dist/core/agent-session-services.d.ts +1 -0
  78. package/dist/core/agent-session-services.d.ts.map +1 -1
  79. package/dist/core/agent-session-services.js +1 -0
  80. package/dist/core/agent-session-services.js.map +1 -1
  81. package/dist/core/agent-session.d.ts +1 -10
  82. package/dist/core/agent-session.d.ts.map +1 -1
  83. package/dist/core/agent-session.js +72 -70
  84. package/dist/core/agent-session.js.map +1 -1
  85. package/dist/core/auth-storage.d.ts +25 -9
  86. package/dist/core/auth-storage.d.ts.map +1 -1
  87. package/dist/core/auth-storage.js +237 -39
  88. package/dist/core/auth-storage.js.map +1 -1
  89. package/dist/core/extensions/index.d.ts +1 -1
  90. package/dist/core/extensions/index.d.ts.map +1 -1
  91. package/dist/core/extensions/index.js.map +1 -1
  92. package/dist/core/extensions/loader.d.ts.map +1 -1
  93. package/dist/core/extensions/loader.js +60 -41
  94. package/dist/core/extensions/loader.js.map +1 -1
  95. package/dist/core/extensions/runner.d.ts +2 -1
  96. package/dist/core/extensions/runner.d.ts.map +1 -1
  97. package/dist/core/extensions/runner.js +3 -0
  98. package/dist/core/extensions/runner.js.map +1 -1
  99. package/dist/core/extensions/types.d.ts +27 -4
  100. package/dist/core/extensions/types.d.ts.map +1 -1
  101. package/dist/core/extensions/types.js.map +1 -1
  102. package/dist/core/http-dispatcher.d.ts.map +1 -1
  103. package/dist/core/http-dispatcher.js +5 -0
  104. package/dist/core/http-dispatcher.js.map +1 -1
  105. package/dist/core/keybindings.d.ts +45 -5
  106. package/dist/core/keybindings.d.ts.map +1 -1
  107. package/dist/core/keybindings.js.map +1 -1
  108. package/dist/core/model-config.d.ts +29 -5
  109. package/dist/core/model-config.d.ts.map +1 -1
  110. package/dist/core/model-config.js +4 -0
  111. package/dist/core/model-config.js.map +1 -1
  112. package/dist/core/model-registry.d.ts +5 -3
  113. package/dist/core/model-registry.d.ts.map +1 -1
  114. package/dist/core/model-registry.js +13 -10
  115. package/dist/core/model-registry.js.map +1 -1
  116. package/dist/core/model-resolver.d.ts +4 -3
  117. package/dist/core/model-resolver.d.ts.map +1 -1
  118. package/dist/core/model-resolver.js +42 -10
  119. package/dist/core/model-resolver.js.map +1 -1
  120. package/dist/core/model-runtime.d.ts +30 -13
  121. package/dist/core/model-runtime.d.ts.map +1 -1
  122. package/dist/core/model-runtime.js +233 -73
  123. package/dist/core/model-runtime.js.map +1 -1
  124. package/dist/core/models-store.d.ts +12 -7
  125. package/dist/core/models-store.d.ts.map +1 -1
  126. package/dist/core/models-store.js +83 -14
  127. package/dist/core/models-store.js.map +1 -1
  128. package/dist/core/package-manager.d.ts +6 -3
  129. package/dist/core/package-manager.d.ts.map +1 -1
  130. package/dist/core/package-manager.js +80 -61
  131. package/dist/core/package-manager.js.map +1 -1
  132. package/dist/core/pi-manifest.d.ts +8 -0
  133. package/dist/core/pi-manifest.d.ts.map +1 -0
  134. package/dist/core/pi-manifest.js +28 -0
  135. package/dist/core/pi-manifest.js.map +1 -0
  136. package/dist/core/provider-composer.d.ts +4 -1
  137. package/dist/core/provider-composer.d.ts.map +1 -1
  138. package/dist/core/provider-composer.js +36 -15
  139. package/dist/core/provider-composer.js.map +1 -1
  140. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  141. package/dist/core/remote-catalog-provider.js +73 -67
  142. package/dist/core/remote-catalog-provider.js.map +1 -1
  143. package/dist/core/resource-loader.d.ts.map +1 -1
  144. package/dist/core/resource-loader.js +2 -2
  145. package/dist/core/resource-loader.js.map +1 -1
  146. package/dist/core/runtime-credentials.d.ts +5 -5
  147. package/dist/core/runtime-credentials.d.ts.map +1 -1
  148. package/dist/core/runtime-credentials.js +11 -8
  149. package/dist/core/runtime-credentials.js.map +1 -1
  150. package/dist/core/sdk.d.ts +1 -1
  151. package/dist/core/sdk.d.ts.map +1 -1
  152. package/dist/core/sdk.js +2 -2
  153. package/dist/core/sdk.js.map +1 -1
  154. package/dist/core/session-manager.d.ts.map +1 -1
  155. package/dist/core/session-manager.js +3 -1
  156. package/dist/core/session-manager.js.map +1 -1
  157. package/dist/core/settings-manager.d.ts +12 -0
  158. package/dist/core/settings-manager.d.ts.map +1 -1
  159. package/dist/core/settings-manager.js +40 -16
  160. package/dist/core/settings-manager.js.map +1 -1
  161. package/dist/core/system-prompt.d.ts.map +1 -1
  162. package/dist/core/system-prompt.js +8 -0
  163. package/dist/core/system-prompt.js.map +1 -1
  164. package/dist/core/tools/bash.d.ts +5 -1
  165. package/dist/core/tools/bash.d.ts.map +1 -1
  166. package/dist/core/tools/bash.js +16 -15
  167. package/dist/core/tools/bash.js.map +1 -1
  168. package/dist/core/tools/edit.d.ts +4 -0
  169. package/dist/core/tools/edit.d.ts.map +1 -1
  170. package/dist/core/tools/edit.js +11 -7
  171. package/dist/core/tools/edit.js.map +1 -1
  172. package/dist/core/tools/find.d.ts +7 -0
  173. package/dist/core/tools/find.d.ts.map +1 -1
  174. package/dist/core/tools/find.js +16 -19
  175. package/dist/core/tools/find.js.map +1 -1
  176. package/dist/core/tools/grep.d.ts +4 -0
  177. package/dist/core/tools/grep.d.ts.map +1 -1
  178. package/dist/core/tools/grep.js +5 -1
  179. package/dist/core/tools/grep.js.map +1 -1
  180. package/dist/core/tools/ls.d.ts +4 -0
  181. package/dist/core/tools/ls.d.ts.map +1 -1
  182. package/dist/core/tools/ls.js +5 -1
  183. package/dist/core/tools/ls.js.map +1 -1
  184. package/dist/core/tools/read.d.ts +4 -0
  185. package/dist/core/tools/read.d.ts.map +1 -1
  186. package/dist/core/tools/read.js +7 -3
  187. package/dist/core/tools/read.js.map +1 -1
  188. package/dist/core/tools/write.d.ts +4 -0
  189. package/dist/core/tools/write.d.ts.map +1 -1
  190. package/dist/core/tools/write.js +6 -2
  191. package/dist/core/tools/write.js.map +1 -1
  192. package/dist/extensions/llama/index.d.ts.map +1 -1
  193. package/dist/extensions/llama/index.js +11 -2
  194. package/dist/extensions/llama/index.js.map +1 -1
  195. package/dist/extensions/llama/provider.d.ts.map +1 -1
  196. package/dist/extensions/llama/provider.js +21 -7
  197. package/dist/extensions/llama/provider.js.map +1 -1
  198. package/dist/humain/agent-execution-protocol.d.ts +218 -0
  199. package/dist/humain/agent-execution-protocol.d.ts.map +1 -0
  200. package/dist/humain/agent-execution-protocol.js +204 -0
  201. package/dist/humain/agent-execution-protocol.js.map +1 -0
  202. package/dist/humain/agent-execution-runtime.d.ts +35 -0
  203. package/dist/humain/agent-execution-runtime.d.ts.map +1 -0
  204. package/dist/humain/agent-execution-runtime.js +170 -0
  205. package/dist/humain/agent-execution-runtime.js.map +1 -0
  206. package/dist/humain/index.d.ts.map +1 -1
  207. package/dist/humain/index.js +8 -7
  208. package/dist/humain/index.js.map +1 -1
  209. package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +673 -0
  210. package/dist/humain/mcp-adapter/vendor/LICENSE +21 -0
  211. package/dist/humain/mcp-adapter/vendor/README.md +736 -0
  212. package/dist/humain/mcp-adapter/vendor/abort.ts +34 -0
  213. package/dist/humain/mcp-adapter/vendor/agent-dir.ts +68 -0
  214. package/dist/humain/mcp-adapter/vendor/agent-plugin-loader.ts +377 -0
  215. package/dist/humain/mcp-adapter/vendor/app-bridge.bundle.js +67 -0
  216. package/dist/humain/mcp-adapter/vendor/banner.png +0 -0
  217. package/dist/humain/mcp-adapter/vendor/cli.js +230 -0
  218. package/dist/humain/mcp-adapter/vendor/commands.ts +627 -0
  219. package/dist/humain/mcp-adapter/vendor/config.ts +1226 -0
  220. package/dist/humain/mcp-adapter/vendor/consent-manager.ts +64 -0
  221. package/dist/humain/mcp-adapter/vendor/direct-tools.ts +607 -0
  222. package/dist/humain/mcp-adapter/vendor/elicitation-handler.ts +348 -0
  223. package/dist/humain/mcp-adapter/vendor/error-signal.ts +21 -0
  224. package/dist/humain/mcp-adapter/vendor/errors.ts +223 -0
  225. package/dist/humain/mcp-adapter/vendor/glimpse-ui.ts +80 -0
  226. package/dist/humain/mcp-adapter/vendor/host-html-template.ts +461 -0
  227. package/dist/humain/mcp-adapter/vendor/index.bundle.d.mts +4 -0
  228. package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +16279 -0
  229. package/dist/humain/mcp-adapter/vendor/index.ts +898 -0
  230. package/dist/humain/mcp-adapter/vendor/init.ts +649 -0
  231. package/dist/humain/mcp-adapter/vendor/json-schema-validator.ts +69 -0
  232. package/dist/humain/mcp-adapter/vendor/lifecycle.ts +147 -0
  233. package/dist/humain/mcp-adapter/vendor/logger.ts +169 -0
  234. package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +993 -0
  235. package/dist/humain/mcp-adapter/vendor/mcp-auth.ts +1000 -0
  236. package/dist/humain/mcp-adapter/vendor/mcp-callback-server.ts +510 -0
  237. package/dist/humain/mcp-adapter/vendor/mcp-code.ts +354 -0
  238. package/dist/humain/mcp-adapter/vendor/mcp-keyring-helper.cjs +89 -0
  239. package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +616 -0
  240. package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +408 -0
  241. package/dist/humain/mcp-adapter/vendor/mcp-panel.ts +1015 -0
  242. package/dist/humain/mcp-adapter/vendor/mcp-probe.ts +187 -0
  243. package/dist/humain/mcp-adapter/vendor/mcp-script-worker.mjs +130 -0
  244. package/dist/humain/mcp-adapter/vendor/mcp-setup-panel.ts +667 -0
  245. package/dist/humain/mcp-adapter/vendor/mcp-status.ts +109 -0
  246. package/dist/humain/mcp-adapter/vendor/mcp-trace.ts +306 -0
  247. package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +363 -0
  248. package/dist/humain/mcp-adapter/vendor/npx-resolver.ts +543 -0
  249. package/dist/humain/mcp-adapter/vendor/oauth-handler.ts +30 -0
  250. package/dist/humain/mcp-adapter/vendor/oauth.ts +48 -0
  251. package/dist/humain/mcp-adapter/vendor/onboarding-state.ts +76 -0
  252. package/dist/humain/mcp-adapter/vendor/package.json +179 -0
  253. package/dist/humain/mcp-adapter/vendor/panel-keys.ts +53 -0
  254. package/dist/humain/mcp-adapter/vendor/prompts.ts +353 -0
  255. package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +1331 -0
  256. package/dist/humain/mcp-adapter/vendor/request-headers-command.ts +336 -0
  257. package/dist/humain/mcp-adapter/vendor/resource-tools.ts +17 -0
  258. package/dist/humain/mcp-adapter/vendor/runtime-owner.ts +91 -0
  259. package/dist/humain/mcp-adapter/vendor/sampling-handler.ts +284 -0
  260. package/dist/humain/mcp-adapter/vendor/search-ranking.ts +206 -0
  261. package/dist/humain/mcp-adapter/vendor/server-manager.ts +1129 -0
  262. package/dist/humain/mcp-adapter/vendor/session-recovery.ts +151 -0
  263. package/dist/humain/mcp-adapter/vendor/skills/mcp-scripting/SKILL.md +38 -0
  264. package/dist/humain/mcp-adapter/vendor/state.ts +62 -0
  265. package/dist/humain/mcp-adapter/vendor/tool-approval.ts +182 -0
  266. package/dist/humain/mcp-adapter/vendor/tool-metadata.ts +296 -0
  267. package/dist/humain/mcp-adapter/vendor/tool-registrar.ts +253 -0
  268. package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +423 -0
  269. package/dist/humain/mcp-adapter/vendor/ts-shape.ts +149 -0
  270. package/dist/humain/mcp-adapter/vendor/types.ts +942 -0
  271. package/dist/humain/mcp-adapter/vendor/ui-app-bridge-helpers.ts +40 -0
  272. package/dist/humain/mcp-adapter/vendor/ui-resource-handler.ts +250 -0
  273. package/dist/humain/mcp-adapter/vendor/ui-server.ts +866 -0
  274. package/dist/humain/mcp-adapter/vendor/ui-session.ts +570 -0
  275. package/dist/humain/mcp-adapter/vendor/ui-stream-types.ts +89 -0
  276. package/dist/humain/mcp-adapter/vendor/ui-tool-visibility.ts +25 -0
  277. package/dist/humain/mcp-adapter/vendor/unix-socket-transport.ts +85 -0
  278. package/dist/humain/mcp-adapter/vendor/utils.ts +310 -0
  279. package/dist/humain/mcp-adapter.d.ts +3 -0
  280. package/dist/humain/mcp-adapter.d.ts.map +1 -0
  281. package/dist/humain/mcp-adapter.js +5 -0
  282. package/dist/humain/mcp-adapter.js.map +1 -0
  283. package/dist/humain/pi-agent-execution-host.d.ts +34 -0
  284. package/dist/humain/pi-agent-execution-host.d.ts.map +1 -0
  285. package/dist/humain/pi-agent-execution-host.js +77 -0
  286. package/dist/humain/pi-agent-execution-host.js.map +1 -0
  287. package/dist/humain/web-access/host.d.ts +4 -0
  288. package/dist/humain/web-access/host.d.ts.map +1 -0
  289. package/dist/humain/web-access/host.js +3 -0
  290. package/dist/humain/web-access/host.js.map +1 -0
  291. package/dist/humain/web-access/index.d.ts +3 -0
  292. package/dist/humain/web-access/index.d.ts.map +1 -0
  293. package/dist/humain/web-access/index.js +5 -0
  294. package/dist/humain/web-access/index.js.map +1 -0
  295. package/dist/humain/web-access/vendor/activity.d.ts +34 -0
  296. package/dist/humain/web-access/vendor/activity.d.ts.map +1 -0
  297. package/dist/humain/web-access/vendor/activity.js +68 -0
  298. package/dist/humain/web-access/vendor/activity.js.map +1 -0
  299. package/dist/humain/web-access/vendor/anysearch.d.ts +8 -0
  300. package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -0
  301. package/dist/humain/web-access/vendor/anysearch.js +167 -0
  302. package/dist/humain/web-access/vendor/anysearch.js.map +1 -0
  303. package/dist/humain/web-access/vendor/auth-fetch.d.ts +13 -0
  304. package/dist/humain/web-access/vendor/auth-fetch.d.ts.map +1 -0
  305. package/dist/humain/web-access/vendor/auth-fetch.js +134 -0
  306. package/dist/humain/web-access/vendor/auth-fetch.js.map +1 -0
  307. package/dist/humain/web-access/vendor/bocha.d.ts +4 -0
  308. package/dist/humain/web-access/vendor/bocha.d.ts.map +1 -0
  309. package/dist/humain/web-access/vendor/bocha.js +219 -0
  310. package/dist/humain/web-access/vendor/bocha.js.map +1 -0
  311. package/dist/humain/web-access/vendor/brave.d.ts +4 -0
  312. package/dist/humain/web-access/vendor/brave.d.ts.map +1 -0
  313. package/dist/humain/web-access/vendor/brave.js +194 -0
  314. package/dist/humain/web-access/vendor/brave.js.map +1 -0
  315. package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts +12 -0
  316. package/dist/humain/web-access/vendor/brightdata-unlocker.d.ts.map +1 -0
  317. package/dist/humain/web-access/vendor/brightdata-unlocker.js +230 -0
  318. package/dist/humain/web-access/vendor/brightdata-unlocker.js.map +1 -0
  319. package/dist/humain/web-access/vendor/brightdata.d.ts +8 -0
  320. package/dist/humain/web-access/vendor/brightdata.d.ts.map +1 -0
  321. package/dist/humain/web-access/vendor/brightdata.js +519 -0
  322. package/dist/humain/web-access/vendor/brightdata.js.map +1 -0
  323. package/dist/humain/web-access/vendor/chrome-cookies.d.ts +23 -0
  324. package/dist/humain/web-access/vendor/chrome-cookies.d.ts.map +1 -0
  325. package/dist/humain/web-access/vendor/chrome-cookies.js +522 -0
  326. package/dist/humain/web-access/vendor/chrome-cookies.js.map +1 -0
  327. package/dist/humain/web-access/vendor/content-find.d.ts +11 -0
  328. package/dist/humain/web-access/vendor/content-find.d.ts.map +1 -0
  329. package/dist/humain/web-access/vendor/content-find.js +117 -0
  330. package/dist/humain/web-access/vendor/content-find.js.map +1 -0
  331. package/dist/humain/web-access/vendor/credential-source.d.ts +28 -0
  332. package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -0
  333. package/dist/humain/web-access/vendor/credential-source.js +151 -0
  334. package/dist/humain/web-access/vendor/credential-source.js.map +1 -0
  335. package/dist/humain/web-access/vendor/curator-page.d.ts +30 -0
  336. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -0
  337. package/dist/humain/web-access/vendor/curator-page.js +3556 -0
  338. package/dist/humain/web-access/vendor/curator-page.js.map +1 -0
  339. package/dist/humain/web-access/vendor/curator-server.d.ts +94 -0
  340. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -0
  341. package/dist/humain/web-access/vendor/curator-server.js +690 -0
  342. package/dist/humain/web-access/vendor/curator-server.js.map +1 -0
  343. package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts +60 -0
  344. package/dist/humain/web-access/vendor/datalab-pdf-extract.d.ts.map +1 -0
  345. package/dist/humain/web-access/vendor/datalab-pdf-extract.js +416 -0
  346. package/dist/humain/web-access/vendor/datalab-pdf-extract.js.map +1 -0
  347. package/dist/humain/web-access/vendor/declared-web-links.d.ts +16 -0
  348. package/dist/humain/web-access/vendor/declared-web-links.d.ts.map +1 -0
  349. package/dist/humain/web-access/vendor/declared-web-links.js +168 -0
  350. package/dist/humain/web-access/vendor/declared-web-links.js.map +1 -0
  351. package/dist/humain/web-access/vendor/duckduckgo.d.ts +4 -0
  352. package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -0
  353. package/dist/humain/web-access/vendor/duckduckgo.js +123 -0
  354. package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -0
  355. package/dist/humain/web-access/vendor/exa.d.ts +10 -0
  356. package/dist/humain/web-access/vendor/exa.d.ts.map +1 -0
  357. package/dist/humain/web-access/vendor/exa.js +426 -0
  358. package/dist/humain/web-access/vendor/exa.js.map +1 -0
  359. package/dist/humain/web-access/vendor/extract.d.ts +48 -0
  360. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -0
  361. package/dist/humain/web-access/vendor/extract.js +1126 -0
  362. package/dist/humain/web-access/vendor/extract.js.map +1 -0
  363. package/dist/humain/web-access/vendor/feature-config.d.ts +3 -0
  364. package/dist/humain/web-access/vendor/feature-config.d.ts.map +1 -0
  365. package/dist/humain/web-access/vendor/feature-config.js +27 -0
  366. package/dist/humain/web-access/vendor/feature-config.js.map +1 -0
  367. package/dist/humain/web-access/vendor/fetch-params.d.ts +27 -0
  368. package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -0
  369. package/dist/humain/web-access/vendor/fetch-params.js +71 -0
  370. package/dist/humain/web-access/vendor/fetch-params.js.map +1 -0
  371. package/dist/humain/web-access/vendor/firecrawl.d.ts +19 -0
  372. package/dist/humain/web-access/vendor/firecrawl.d.ts.map +1 -0
  373. package/dist/humain/web-access/vendor/firecrawl.js +370 -0
  374. package/dist/humain/web-access/vendor/firecrawl.js.map +1 -0
  375. package/dist/humain/web-access/vendor/gemini-api.d.ts +27 -0
  376. package/dist/humain/web-access/vendor/gemini-api.d.ts.map +1 -0
  377. package/dist/humain/web-access/vendor/gemini-api.js +230 -0
  378. package/dist/humain/web-access/vendor/gemini-api.js.map +1 -0
  379. package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts +9 -0
  380. package/dist/humain/web-access/vendor/gemini-pdf-extract.d.ts.map +1 -0
  381. package/dist/humain/web-access/vendor/gemini-pdf-extract.js +85 -0
  382. package/dist/humain/web-access/vendor/gemini-pdf-extract.js.map +1 -0
  383. package/dist/humain/web-access/vendor/gemini-search.d.ts +40 -0
  384. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -0
  385. package/dist/humain/web-access/vendor/gemini-search.js +832 -0
  386. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -0
  387. package/dist/humain/web-access/vendor/gemini-url-context.d.ts +4 -0
  388. package/dist/humain/web-access/vendor/gemini-url-context.d.ts.map +1 -0
  389. package/dist/humain/web-access/vendor/gemini-url-context.js +101 -0
  390. package/dist/humain/web-access/vendor/gemini-url-context.js.map +1 -0
  391. package/dist/humain/web-access/vendor/gemini-web-config.d.ts +4 -0
  392. package/dist/humain/web-access/vendor/gemini-web-config.d.ts.map +1 -0
  393. package/dist/humain/web-access/vendor/gemini-web-config.js +42 -0
  394. package/dist/humain/web-access/vendor/gemini-web-config.js.map +1 -0
  395. package/dist/humain/web-access/vendor/gemini-web.d.ts +18 -0
  396. package/dist/humain/web-access/vendor/gemini-web.d.ts.map +1 -0
  397. package/dist/humain/web-access/vendor/gemini-web.js +385 -0
  398. package/dist/humain/web-access/vendor/gemini-web.js.map +1 -0
  399. package/dist/humain/web-access/vendor/github-api.d.ts +7 -0
  400. package/dist/humain/web-access/vendor/github-api.d.ts.map +1 -0
  401. package/dist/humain/web-access/vendor/github-api.js +160 -0
  402. package/dist/humain/web-access/vendor/github-api.js.map +1 -0
  403. package/dist/humain/web-access/vendor/github-extract.d.ts +13 -0
  404. package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -0
  405. package/dist/humain/web-access/vendor/github-extract.js +635 -0
  406. package/dist/humain/web-access/vendor/github-extract.js.map +1 -0
  407. package/dist/humain/web-access/vendor/index.d.ts +4 -0
  408. package/dist/humain/web-access/vendor/index.d.ts.map +1 -0
  409. package/dist/humain/web-access/vendor/index.js +3076 -0
  410. package/dist/humain/web-access/vendor/index.js.map +1 -0
  411. package/dist/humain/web-access/vendor/jina-search.d.ts +8 -0
  412. package/dist/humain/web-access/vendor/jina-search.d.ts.map +1 -0
  413. package/dist/humain/web-access/vendor/jina-search.js +255 -0
  414. package/dist/humain/web-access/vendor/jina-search.js.map +1 -0
  415. package/dist/humain/web-access/vendor/kagi.d.ts +15 -0
  416. package/dist/humain/web-access/vendor/kagi.d.ts.map +1 -0
  417. package/dist/humain/web-access/vendor/kagi.js +262 -0
  418. package/dist/humain/web-access/vendor/kagi.js.map +1 -0
  419. package/dist/humain/web-access/vendor/ollama.d.ts +15 -0
  420. package/dist/humain/web-access/vendor/ollama.d.ts.map +1 -0
  421. package/dist/humain/web-access/vendor/ollama.js +216 -0
  422. package/dist/humain/web-access/vendor/ollama.js.map +1 -0
  423. package/dist/humain/web-access/vendor/openai-search.d.ts +15 -0
  424. package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -0
  425. package/dist/humain/web-access/vendor/openai-search.js +459 -0
  426. package/dist/humain/web-access/vendor/openai-search.js.map +1 -0
  427. package/dist/humain/web-access/vendor/page-query.d.ts +16 -0
  428. package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -0
  429. package/dist/humain/web-access/vendor/page-query.js +79 -0
  430. package/dist/humain/web-access/vendor/page-query.js.map +1 -0
  431. package/dist/humain/web-access/vendor/parallel.d.ts +12 -0
  432. package/dist/humain/web-access/vendor/parallel.d.ts.map +1 -0
  433. package/dist/humain/web-access/vendor/parallel.js +343 -0
  434. package/dist/humain/web-access/vendor/parallel.js.map +1 -0
  435. package/dist/humain/web-access/vendor/pdf-extract.d.ts +44 -0
  436. package/dist/humain/web-access/vendor/pdf-extract.d.ts.map +1 -0
  437. package/dist/humain/web-access/vendor/pdf-extract.js +298 -0
  438. package/dist/humain/web-access/vendor/pdf-extract.js.map +1 -0
  439. package/dist/humain/web-access/vendor/perplexity.d.ts +20 -0
  440. package/dist/humain/web-access/vendor/perplexity.d.ts.map +1 -0
  441. package/dist/humain/web-access/vendor/perplexity.js +159 -0
  442. package/dist/humain/web-access/vendor/perplexity.js.map +1 -0
  443. package/dist/humain/web-access/vendor/querit.d.ts +10 -0
  444. package/dist/humain/web-access/vendor/querit.d.ts.map +1 -0
  445. package/dist/humain/web-access/vendor/querit.js +335 -0
  446. package/dist/humain/web-access/vendor/querit.js.map +1 -0
  447. package/dist/humain/web-access/vendor/render-search-error.d.ts +57 -0
  448. package/dist/humain/web-access/vendor/render-search-error.d.ts.map +1 -0
  449. package/dist/humain/web-access/vendor/render-search-error.js +130 -0
  450. package/dist/humain/web-access/vendor/render-search-error.js.map +1 -0
  451. package/dist/humain/web-access/vendor/rsc-extract.d.ts +12 -0
  452. package/dist/humain/web-access/vendor/rsc-extract.d.ts.map +1 -0
  453. package/dist/humain/web-access/vendor/rsc-extract.js +329 -0
  454. package/dist/humain/web-access/vendor/rsc-extract.js.map +1 -0
  455. package/dist/humain/web-access/vendor/search1api.d.ts +10 -0
  456. package/dist/humain/web-access/vendor/search1api.d.ts.map +1 -0
  457. package/dist/humain/web-access/vendor/search1api.js +251 -0
  458. package/dist/humain/web-access/vendor/search1api.js.map +1 -0
  459. package/dist/humain/web-access/vendor/searchinfinity.d.ts +8 -0
  460. package/dist/humain/web-access/vendor/searchinfinity.d.ts.map +1 -0
  461. package/dist/humain/web-access/vendor/searchinfinity.js +229 -0
  462. package/dist/humain/web-access/vendor/searchinfinity.js.map +1 -0
  463. package/dist/humain/web-access/vendor/searxng.d.ts +4 -0
  464. package/dist/humain/web-access/vendor/searxng.d.ts.map +1 -0
  465. package/dist/humain/web-access/vendor/searxng.js +238 -0
  466. package/dist/humain/web-access/vendor/searxng.js.map +1 -0
  467. package/dist/humain/web-access/vendor/serpbase.d.ts +4 -0
  468. package/dist/humain/web-access/vendor/serpbase.d.ts.map +1 -0
  469. package/dist/humain/web-access/vendor/serpbase.js +211 -0
  470. package/dist/humain/web-access/vendor/serpbase.js.map +1 -0
  471. package/dist/humain/web-access/vendor/serpdive.d.ts +8 -0
  472. package/dist/humain/web-access/vendor/serpdive.d.ts.map +1 -0
  473. package/dist/humain/web-access/vendor/serpdive.js +267 -0
  474. package/dist/humain/web-access/vendor/serpdive.js.map +1 -0
  475. package/dist/humain/web-access/vendor/source-check.d.ts +99 -0
  476. package/dist/humain/web-access/vendor/source-check.d.ts.map +1 -0
  477. package/dist/humain/web-access/vendor/source-check.js +205 -0
  478. package/dist/humain/web-access/vendor/source-check.js.map +1 -0
  479. package/dist/humain/web-access/vendor/ssrf-protection.d.ts +50 -0
  480. package/dist/humain/web-access/vendor/ssrf-protection.d.ts.map +1 -0
  481. package/dist/humain/web-access/vendor/ssrf-protection.js +466 -0
  482. package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -0
  483. package/dist/humain/web-access/vendor/storage.d.ts +55 -0
  484. package/dist/humain/web-access/vendor/storage.d.ts.map +1 -0
  485. package/dist/humain/web-access/vendor/storage.js +485 -0
  486. package/dist/humain/web-access/vendor/storage.js.map +1 -0
  487. package/dist/humain/web-access/vendor/summary-model-scope.d.ts +25 -0
  488. package/dist/humain/web-access/vendor/summary-model-scope.d.ts.map +1 -0
  489. package/dist/humain/web-access/vendor/summary-model-scope.js +98 -0
  490. package/dist/humain/web-access/vendor/summary-model-scope.js.map +1 -0
  491. package/dist/humain/web-access/vendor/summary-review.d.ts +26 -0
  492. package/dist/humain/web-access/vendor/summary-review.d.ts.map +1 -0
  493. package/dist/humain/web-access/vendor/summary-review.js +344 -0
  494. package/dist/humain/web-access/vendor/summary-review.js.map +1 -0
  495. package/dist/humain/web-access/vendor/tavily.d.ts +8 -0
  496. package/dist/humain/web-access/vendor/tavily.d.ts.map +1 -0
  497. package/dist/humain/web-access/vendor/tavily.js +194 -0
  498. package/dist/humain/web-access/vendor/tavily.js.map +1 -0
  499. package/dist/humain/web-access/vendor/tinyfish.d.ts +11 -0
  500. package/dist/humain/web-access/vendor/tinyfish.d.ts.map +1 -0
  501. package/dist/humain/web-access/vendor/tinyfish.js +331 -0
  502. package/dist/humain/web-access/vendor/tinyfish.js.map +1 -0
  503. package/dist/humain/web-access/vendor/utils.d.ts +20 -0
  504. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -0
  505. package/dist/humain/web-access/vendor/utils.js +91 -0
  506. package/dist/humain/web-access/vendor/utils.js.map +1 -0
  507. package/dist/humain/web-access/vendor/video-extract.d.ts +16 -0
  508. package/dist/humain/web-access/vendor/video-extract.d.ts.map +1 -0
  509. package/dist/humain/web-access/vendor/video-extract.js +335 -0
  510. package/dist/humain/web-access/vendor/video-extract.js.map +1 -0
  511. package/dist/humain/web-access/vendor/xai-search.d.ts +13 -0
  512. package/dist/humain/web-access/vendor/xai-search.d.ts.map +1 -0
  513. package/dist/humain/web-access/vendor/xai-search.js +331 -0
  514. package/dist/humain/web-access/vendor/xai-search.js.map +1 -0
  515. package/dist/humain/web-access/vendor/youtube-extract.d.ts +27 -0
  516. package/dist/humain/web-access/vendor/youtube-extract.d.ts.map +1 -0
  517. package/dist/humain/web-access/vendor/youtube-extract.js +282 -0
  518. package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -0
  519. package/dist/index.d.ts +7 -4
  520. package/dist/index.d.ts.map +1 -1
  521. package/dist/index.js +5 -2
  522. package/dist/index.js.map +1 -1
  523. package/dist/main.d.ts +2 -2
  524. package/dist/main.d.ts.map +1 -1
  525. package/dist/main.js +169 -102
  526. package/dist/main.js.map +1 -1
  527. package/dist/modes/agent-exec-mode.d.ts +14 -0
  528. package/dist/modes/agent-exec-mode.d.ts.map +1 -0
  529. package/dist/modes/agent-exec-mode.js +92 -0
  530. package/dist/modes/agent-exec-mode.js.map +1 -0
  531. package/dist/modes/index.d.ts +4 -2
  532. package/dist/modes/index.d.ts.map +1 -1
  533. package/dist/modes/index.js +2 -1
  534. package/dist/modes/index.js.map +1 -1
  535. package/dist/modes/interactive/components/assistant-message.d.ts +5 -2
  536. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  537. package/dist/modes/interactive/components/assistant-message.js +13 -4
  538. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  539. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  540. package/dist/modes/interactive/components/custom-editor.js +7 -0
  541. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  542. package/dist/modes/interactive/components/earendil-announcement.d.ts +5 -0
  543. package/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -0
  544. package/dist/modes/interactive/components/earendil-announcement.js +40 -0
  545. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -0
  546. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  547. package/dist/modes/interactive/components/footer.js +1 -1
  548. package/dist/modes/interactive/components/footer.js.map +1 -1
  549. package/dist/modes/interactive/components/markdown-transform.d.ts +3 -0
  550. package/dist/modes/interactive/components/markdown-transform.d.ts.map +1 -0
  551. package/dist/modes/interactive/components/markdown-transform.js +19 -0
  552. package/dist/modes/interactive/components/markdown-transform.js.map +1 -0
  553. package/dist/modes/interactive/components/mermaid.d.ts +11 -0
  554. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -0
  555. package/dist/modes/interactive/components/mermaid.js +75 -0
  556. package/dist/modes/interactive/components/mermaid.js.map +1 -0
  557. package/dist/modes/interactive/components/model-selector.d.ts +1 -1
  558. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  559. package/dist/modes/interactive/components/model-selector.js +16 -4
  560. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  561. package/dist/modes/interactive/components/scoped-models-selector.d.ts +4 -0
  562. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  563. package/dist/modes/interactive/components/scoped-models-selector.js +26 -0
  564. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  565. package/dist/modes/interactive/components/settings-selector.d.ts +8 -2
  566. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  567. package/dist/modes/interactive/components/settings-selector.js +30 -0
  568. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  569. package/dist/modes/interactive/components/user-message.d.ts +3 -1
  570. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  571. package/dist/modes/interactive/components/user-message.js +9 -2
  572. package/dist/modes/interactive/components/user-message.js.map +1 -1
  573. package/dist/modes/interactive/interactive-mode.d.ts +45 -9
  574. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  575. package/dist/modes/interactive/interactive-mode.js +581 -211
  576. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  577. package/dist/modes/interactive/theme/dark.json +1 -0
  578. package/dist/modes/interactive/theme/light.json +1 -0
  579. package/dist/modes/interactive/theme/theme-controller.d.ts +3 -0
  580. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  581. package/dist/modes/interactive/theme/theme-controller.js +10 -1
  582. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  583. package/dist/modes/interactive/theme/theme-schema.json +5 -1
  584. package/dist/modes/interactive/theme/theme.d.ts +2 -2
  585. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  586. package/dist/modes/interactive/theme/theme.js +24 -6
  587. package/dist/modes/interactive/theme/theme.js.map +1 -1
  588. package/dist/modes/json-event.d.ts +28 -0
  589. package/dist/modes/json-event.d.ts.map +1 -0
  590. package/dist/modes/json-event.js +12 -0
  591. package/dist/modes/json-event.js.map +1 -0
  592. package/dist/modes/print-mode.d.ts.map +1 -1
  593. package/dist/modes/print-mode.js +12 -2
  594. package/dist/modes/print-mode.js.map +1 -1
  595. package/dist/modes/rpc/rpc-client.d.ts +12 -5
  596. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  597. package/dist/modes/rpc/rpc-client.js +55 -1
  598. package/dist/modes/rpc/rpc-client.js.map +1 -1
  599. package/dist/modes/rpc/rpc-mode.d.ts +1 -1
  600. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  601. package/dist/modes/rpc/rpc-mode.js +13 -3
  602. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  603. package/dist/modes/rpc/rpc-types.d.ts +15 -0
  604. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  605. package/dist/modes/rpc/rpc-types.js.map +1 -1
  606. package/dist/package-manager-cli.d.ts.map +1 -1
  607. package/dist/package-manager-cli.js +11 -9
  608. package/dist/package-manager-cli.js.map +1 -1
  609. package/dist/rpc-entry.d.ts.map +1 -1
  610. package/dist/rpc-entry.js +3 -2
  611. package/dist/rpc-entry.js.map +1 -1
  612. package/dist/server/create-harness.d.ts +26 -0
  613. package/dist/server/create-harness.d.ts.map +1 -0
  614. package/dist/server/create-harness.js +104 -0
  615. package/dist/server/create-harness.js.map +1 -0
  616. package/dist/utils/abort.d.ts +5 -0
  617. package/dist/utils/abort.d.ts.map +1 -0
  618. package/dist/utils/abort.js +48 -0
  619. package/dist/utils/abort.js.map +1 -0
  620. package/dist/utils/clipboard.d.ts +1 -1
  621. package/dist/utils/clipboard.d.ts.map +1 -1
  622. package/dist/utils/clipboard.js +22 -2
  623. package/dist/utils/clipboard.js.map +1 -1
  624. package/dist/utils/management-http.d.ts +23 -0
  625. package/dist/utils/management-http.d.ts.map +1 -0
  626. package/dist/utils/management-http.js +50 -0
  627. package/dist/utils/management-http.js.map +1 -0
  628. package/dist/utils/paths.d.ts +3 -0
  629. package/dist/utils/paths.d.ts.map +1 -1
  630. package/dist/utils/paths.js +23 -1
  631. package/dist/utils/paths.js.map +1 -1
  632. package/dist/utils/tool-result-images.d.ts +19 -0
  633. package/dist/utils/tool-result-images.d.ts.map +1 -0
  634. package/dist/utils/tool-result-images.js +45 -0
  635. package/dist/utils/tool-result-images.js.map +1 -0
  636. package/dist/utils/tools-manager.d.ts.map +1 -1
  637. package/dist/utils/tools-manager.js +13 -25
  638. package/dist/utils/tools-manager.js.map +1 -1
  639. package/dist/utils/version-check.d.ts +4 -0
  640. package/dist/utils/version-check.d.ts.map +1 -1
  641. package/dist/utils/version-check.js +23 -5
  642. package/dist/utils/version-check.js.map +1 -1
  643. package/docs/compaction.md +2 -2
  644. package/docs/custom-provider.md +7 -5
  645. package/docs/extensions.md +30 -5
  646. package/docs/humain-terminal.md +21 -1
  647. package/docs/json.md +24 -19
  648. package/docs/keybindings.md +46 -14
  649. package/docs/models.md +32 -11
  650. package/docs/providers.md +9 -1
  651. package/docs/quickstart.md +39 -37
  652. package/docs/rpc.md +31 -11
  653. package/docs/sdk.md +21 -2
  654. package/docs/security.md +21 -21
  655. package/docs/session-format.md +14 -14
  656. package/docs/settings.md +4 -1
  657. package/docs/themes.md +5 -3
  658. package/docs/usage.md +7 -0
  659. package/examples/extensions/custom-compaction.ts +3 -18
  660. package/examples/extensions/custom-provider-anthropic/index.ts +5 -1
  661. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  662. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  663. package/examples/extensions/custom-provider-gitlab-duo/index.ts +5 -1
  664. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  665. package/examples/extensions/doom-overlay/wad-finder.ts +7 -3
  666. package/examples/extensions/gondolin/package-lock.json +2 -2
  667. package/examples/extensions/gondolin/package.json +1 -1
  668. package/examples/extensions/handoff.ts +4 -13
  669. package/examples/extensions/qna.ts +5 -9
  670. package/examples/extensions/sandbox/package-lock.json +2 -2
  671. package/examples/extensions/sandbox/package.json +1 -1
  672. package/examples/extensions/summarize.ts +9 -20
  673. package/examples/extensions/with-deps/package-lock.json +2 -2
  674. package/examples/extensions/with-deps/package.json +1 -1
  675. package/examples/rpc-extension-ui.ts +11 -2
  676. package/examples/sdk/02-custom-model.ts +2 -3
  677. package/examples/sdk/09-api-keys-and-oauth.ts +1 -1
  678. package/examples/sdk/12-full-control.ts +1 -1
  679. package/examples/sdk/README.md +1 -1
  680. package/npm-shrinkwrap.json +2771 -535
  681. package/package.json +40 -11
  682. package/src/humain/mcp-adapter/UPSTREAM.md +15 -0
  683. package/src/humain/mcp-adapter/upstream.json +7 -0
  684. package/src/humain/mcp-adapter/vendor/CHANGELOG.md +673 -0
  685. package/src/humain/mcp-adapter/vendor/LICENSE +21 -0
  686. package/src/humain/web-access/UPSTREAM.md +17 -0
  687. package/src/humain/web-access/upstream.json +23 -0
  688. package/src/humain/web-access/vendor/LICENSE +21 -0
@@ -0,0 +1,1015 @@
1
+ import { matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
2
+ import { copyToClipboard } from "../../../utils/clipboard.ts";
3
+ import { createPanelKeys, type PanelKeybindings, type PanelKeys } from "./panel-keys.ts";
4
+ import { getToolNameCandidates, isServerDisabled, isToolAllowed, resolveToolPrefix } from "./types.ts";
5
+ import type { McpConfig, McpPanelCallbacks, McpPanelResult, ServerProvenance, ToolPrefix } from "./types.ts";
6
+ import { resourceNameToToolName } from "./resource-tools.ts";
7
+ import { sanitizeTerminalText, stripOscSequences } from "./utils.ts";
8
+ import { isServerCacheValid, type MetadataCache, type ServerCacheEntry, type CachedTool } from "./metadata-cache.ts";
9
+ import { isUiToolVisibleToModel } from "./ui-tool-visibility.ts";
10
+
11
+ interface PanelTheme {
12
+ border: string;
13
+ title: string;
14
+ selected: string;
15
+ direct: string;
16
+ needsAuth: string;
17
+ placeholder: string;
18
+ description: string;
19
+ hint: string;
20
+ confirm: string;
21
+ cancel: string;
22
+ }
23
+
24
+ const DEFAULT_THEME: PanelTheme = {
25
+ border: "2",
26
+ title: "2",
27
+ selected: "36",
28
+ direct: "32",
29
+ needsAuth: "33",
30
+ placeholder: "2;3",
31
+ description: "2",
32
+ hint: "2",
33
+ confirm: "32",
34
+ cancel: "31",
35
+ };
36
+
37
+ function fg(code: string, text: string): string {
38
+ if (!code) return text;
39
+ return `\x1b[${code}m${text}\x1b[0m`;
40
+ }
41
+
42
+ const RAINBOW_COLORS = [
43
+ "38;2;178;129;214",
44
+ "38;2;215;135;175",
45
+ "38;2;254;188;56",
46
+ "38;2;228;192;15",
47
+ "38;2;137;210;129",
48
+ "38;2;0;175;175",
49
+ "38;2;23;143;185",
50
+ ];
51
+
52
+ function rainbowProgress(filled: number, total: number): string {
53
+ const dots: string[] = [];
54
+ for (let i = 0; i < total; i++) {
55
+ const color = RAINBOW_COLORS[i % RAINBOW_COLORS.length];
56
+ if (!color) continue;
57
+ dots.push(fg(color, i < filled ? "●" : "○"));
58
+ }
59
+ return dots.join(" ");
60
+ }
61
+
62
+ function fuzzyScore(query: string, text: string): number {
63
+ const lq = query.toLowerCase();
64
+ const lt = text.toLowerCase();
65
+ if (lt.includes(lq)) return 100 + (lq.length / lt.length) * 50;
66
+ let score = 0;
67
+ let qi = 0;
68
+ let consecutive = 0;
69
+ for (let i = 0; i < lt.length && qi < lq.length; i++) {
70
+ if (lt[i] === lq[qi]) {
71
+ score += 10 + consecutive;
72
+ consecutive += 5;
73
+ qi++;
74
+ } else {
75
+ consecutive = 0;
76
+ }
77
+ }
78
+ return qi === lq.length ? score : 0;
79
+ }
80
+
81
+ function sanitizeDisplayText(text: string | null | undefined): string {
82
+ return sanitizeTerminalText(text ?? "");
83
+ }
84
+
85
+ function sanitizeRowContent(content: string): string {
86
+ const withoutOsc = stripOscSequences(content);
87
+ let result = "";
88
+ let pendingSpace = false;
89
+ for (let i = 0; i < withoutOsc.length; i++) {
90
+ const rest = withoutOsc.slice(i);
91
+ const ansi = rest.match(/^(?:\x1b\[[0-?]*[ -/]*[@-~]|\x1b[@-Z\\-_])/);
92
+ if (ansi) {
93
+ result += ansi[0];
94
+ i += ansi[0].length - 1;
95
+ continue;
96
+ }
97
+
98
+ const code = withoutOsc.charCodeAt(i);
99
+ if (code <= 0x1f || code === 0x7f || (code >= 0x80 && code <= 0x9f)) {
100
+ pendingSpace = true;
101
+ continue;
102
+ }
103
+
104
+ if (pendingSpace && result && !result.endsWith(" ")) {
105
+ result += " ";
106
+ }
107
+ pendingSpace = false;
108
+ result += withoutOsc[i];
109
+ }
110
+ return result;
111
+ }
112
+
113
+ function estimateTokens(tool: CachedTool): number {
114
+ const schemaLen = JSON.stringify(tool.inputSchema ?? {}).length;
115
+ const descLen = tool.description?.length ?? 0;
116
+ return Math.ceil((tool.name.length + descLen + schemaLen) / 4) + 10;
117
+ }
118
+
119
+ type ConnectionStatus = "connected" | "idle" | "failed" | "needs-auth" | "connecting" | "disabled";
120
+
121
+ interface ToolState {
122
+ name: string;
123
+ description: string;
124
+ isDirect: boolean;
125
+ wasDirect: boolean;
126
+ estimatedTokens: number;
127
+ }
128
+
129
+ interface ServerState {
130
+ name: string;
131
+ expanded: boolean;
132
+ source: "user" | "project" | "import";
133
+ importKind?: string;
134
+ includeTools?: string[];
135
+ excludeTools?: string[];
136
+ exposeResources: boolean;
137
+ connectionStatus: ConnectionStatus;
138
+ failureMessage?: string | null;
139
+ tools: ToolState[];
140
+ hasCachedData: boolean;
141
+ }
142
+
143
+ interface VisibleItem {
144
+ type: "server" | "tool";
145
+ serverIndex: number;
146
+ toolIndex?: number;
147
+ }
148
+
149
+ class McpPanel {
150
+ private noticeLines: string[];
151
+ private prefix: ToolPrefix;
152
+ private servers: ServerState[] = [];
153
+ private cursorIndex = 0;
154
+ private nameQuery = "";
155
+ private descSearchActive = false;
156
+ private descQuery = "";
157
+ private dirty = false;
158
+ private confirmingDiscard = false;
159
+ private discardSelected = 1;
160
+ private importNotice: string | null = null;
161
+ private authNotice: string | null = null;
162
+ private authInFlight: string | null = null;
163
+ private inactivityTimeout: ReturnType<typeof setTimeout> | null = null;
164
+ private visibleItems: VisibleItem[] = [];
165
+ private tui: { requestRender(): void };
166
+ private t = DEFAULT_THEME;
167
+ private authOnly: boolean;
168
+ private keys: PanelKeys;
169
+
170
+ private static readonly MAX_VISIBLE = 12;
171
+ private static readonly INACTIVITY_MS = 60_000;
172
+
173
+ constructor(
174
+ private config: McpConfig,
175
+ private cache: MetadataCache | null,
176
+ provenance: Map<string, ServerProvenance>,
177
+ private callbacks: McpPanelCallbacks,
178
+ tui: { requestRender(): void },
179
+ private done: (result: McpPanelResult) => void,
180
+ options: { noticeLines?: string[]; authOnly?: boolean; keybindings?: PanelKeybindings } = {},
181
+ ) {
182
+ this.tui = tui;
183
+ this.noticeLines = options.noticeLines ?? [];
184
+ this.authOnly = options.authOnly === true;
185
+ this.keys = createPanelKeys(options.keybindings);
186
+ this.prefix = config.settings?.toolPrefix ?? "server";
187
+
188
+ for (const [serverName, definition] of Object.entries(config.mcpServers)) {
189
+ if (this.authOnly && !callbacks.canAuthenticate(serverName)) continue;
190
+ const prov = provenance.get(serverName);
191
+ const cachedEntry = this.cache?.servers?.[serverName];
192
+ const serverCache = cachedEntry && isServerCacheValid(cachedEntry, definition) ? cachedEntry : undefined;
193
+
194
+ const globalDirect = config.settings?.directTools;
195
+ let toolFilter: true | string[] | false = false;
196
+ if (definition.directTools !== undefined) {
197
+ toolFilter = definition.directTools;
198
+ } else if (globalDirect) {
199
+ toolFilter = globalDirect;
200
+ }
201
+
202
+ const tools: ToolState[] = [];
203
+ if (serverCache && !this.authOnly && !isServerDisabled(definition)) {
204
+ for (const tool of serverCache.tools ?? []) {
205
+ if (!isUiToolVisibleToModel(tool.uiVisibility)) continue;
206
+ if (!isToolAllowed(tool.name, serverName, this.prefix, definition.includeTools, definition.excludeTools, this.getOtherCurrentCandidates(serverName, definition, serverCache, tool.name))) {
207
+ continue;
208
+ }
209
+
210
+ const isDirect = toolFilter === true || (Array.isArray(toolFilter) && toolFilter.includes(tool.name));
211
+ tools.push({
212
+ name: tool.name,
213
+ description: tool.description ?? "",
214
+ isDirect,
215
+ wasDirect: isDirect,
216
+ estimatedTokens: estimateTokens(tool),
217
+ });
218
+ }
219
+ if (definition.exposeResources !== false) {
220
+ for (const resource of serverCache.resources ?? []) {
221
+ const baseName = `read_${resourceNameToToolName(resource.name)}`;
222
+ if (!isToolAllowed(baseName, serverName, this.prefix, definition.includeTools, definition.excludeTools, this.getOtherCurrentCandidates(serverName, definition, serverCache, baseName))) {
223
+ continue;
224
+ }
225
+
226
+ const isDirect = toolFilter === true || (Array.isArray(toolFilter) && toolFilter.includes(baseName));
227
+ const ct: CachedTool = {
228
+ name: baseName,
229
+ ...(resource.description !== undefined ? { description: resource.description } : {}),
230
+ };
231
+ tools.push({
232
+ name: baseName,
233
+ description: resource.description ?? `Read resource: ${resource.uri}`,
234
+ isDirect,
235
+ wasDirect: isDirect,
236
+ estimatedTokens: estimateTokens(ct),
237
+ });
238
+ }
239
+ }
240
+ }
241
+
242
+ const status = callbacks.getConnectionStatus(serverName);
243
+ const failureMessage = callbacks.getFailureMessage?.(serverName) ?? null;
244
+
245
+ this.servers.push({
246
+ name: serverName,
247
+ expanded: false,
248
+ source: prov?.kind ?? "user",
249
+ ...(prov?.importKind !== undefined ? { importKind: prov.importKind } : {}),
250
+ ...(definition.includeTools !== undefined ? { includeTools: definition.includeTools } : {}),
251
+ ...(definition.excludeTools !== undefined ? { excludeTools: definition.excludeTools } : {}),
252
+ exposeResources: definition.exposeResources !== false,
253
+ connectionStatus: status,
254
+ failureMessage,
255
+ tools,
256
+ hasCachedData: !!serverCache,
257
+ });
258
+ }
259
+
260
+ this.rebuildVisibleItems();
261
+ this.resetInactivityTimeout();
262
+ }
263
+
264
+ private resetInactivityTimeout(): void {
265
+ if (this.inactivityTimeout) clearTimeout(this.inactivityTimeout);
266
+ this.inactivityTimeout = setTimeout(() => {
267
+ this.cleanup();
268
+ this.done({ cancelled: true, changes: new Map() });
269
+ }, McpPanel.INACTIVITY_MS);
270
+ }
271
+
272
+ private cleanup(): void {
273
+ if (this.inactivityTimeout) {
274
+ clearTimeout(this.inactivityTimeout);
275
+ this.inactivityTimeout = null;
276
+ }
277
+ }
278
+
279
+ private rebuildVisibleItems(): void {
280
+ const query = this.descSearchActive ? this.descQuery : this.nameQuery;
281
+ const mode = this.descSearchActive ? "desc" : "name";
282
+
283
+ this.visibleItems = [];
284
+ for (let si = 0; si < this.servers.length; si++) {
285
+ const server = this.servers[si];
286
+ if (!server) continue;
287
+ if (query && this.authOnly) {
288
+ const score = mode === "name" ? fuzzyScore(query, server.name) : 0;
289
+ if (score > 0) {
290
+ this.visibleItems.push({ type: "server", serverIndex: si });
291
+ }
292
+ continue;
293
+ }
294
+
295
+ this.visibleItems.push({ type: "server", serverIndex: si });
296
+ if (server.expanded || query) {
297
+ for (let ti = 0; ti < server.tools.length; ti++) {
298
+ const tool = server.tools[ti];
299
+ if (!tool) continue;
300
+ if (query) {
301
+ const score = mode === "name"
302
+ ? Math.max(
303
+ fuzzyScore(query, tool.name),
304
+ fuzzyScore(query, server.name) * 0.6,
305
+ )
306
+ : fuzzyScore(query, tool.description);
307
+ if (score === 0) continue;
308
+ }
309
+ this.visibleItems.push({ type: "tool", serverIndex: si, toolIndex: ti });
310
+ }
311
+ }
312
+ }
313
+
314
+ if (query && !this.authOnly) {
315
+ this.visibleItems = this.visibleItems.filter((item) => {
316
+ if (item.type === "server") {
317
+ return this.visibleItems.some(
318
+ (other) => other.type === "tool" && other.serverIndex === item.serverIndex,
319
+ );
320
+ }
321
+ return true;
322
+ });
323
+ }
324
+ }
325
+
326
+ private updateDirty(): void {
327
+ this.dirty = this.servers.some((s) => s.tools.some((t) => t.isDirect !== t.wasDirect));
328
+ }
329
+
330
+ private buildResult(): McpPanelResult {
331
+ const changes = new Map<string, true | string[] | false>();
332
+ for (const server of this.servers) {
333
+ const changed = server.tools.some((t) => t.isDirect !== t.wasDirect);
334
+ if (!changed) continue;
335
+ const directTools = server.tools.filter((t) => t.isDirect);
336
+ if (directTools.length === server.tools.length && server.tools.length > 0) {
337
+ changes.set(server.name, true);
338
+ } else if (directTools.length === 0) {
339
+ changes.set(server.name, false);
340
+ } else {
341
+ changes.set(server.name, directTools.map((t) => t.name));
342
+ }
343
+ }
344
+ return { changes, cancelled: false };
345
+ }
346
+
347
+ handleInput(data: string): void {
348
+ this.resetInactivityTimeout();
349
+ this.importNotice = null;
350
+ if (!this.authInFlight) this.authNotice = null;
351
+
352
+ if (this.confirmingDiscard) {
353
+ this.handleDiscardInput(data);
354
+ return;
355
+ }
356
+
357
+ // Global shortcuts — always work, even during desc search
358
+ if (matchesKey(data, "ctrl+c")) {
359
+ this.cleanup();
360
+ this.done({ cancelled: true, changes: new Map() });
361
+ return;
362
+ }
363
+
364
+ if (this.keys.save(data)) {
365
+ this.cleanup();
366
+ this.done(this.buildResult());
367
+ return;
368
+ }
369
+
370
+ // Modal description search mode
371
+ if (this.descSearchActive) {
372
+ if (matchesKey(data, "escape") || this.keys.selectConfirm(data)) {
373
+ this.descSearchActive = false;
374
+ this.descQuery = "";
375
+ this.rebuildVisibleItems();
376
+ this.cursorIndex = Math.min(this.cursorIndex, Math.max(0, this.visibleItems.length - 1));
377
+ return;
378
+ }
379
+ if (matchesKey(data, "backspace")) {
380
+ if (this.descQuery.length > 0) {
381
+ this.descQuery = this.descQuery.slice(0, -1);
382
+ this.rebuildVisibleItems();
383
+ this.cursorIndex = Math.min(this.cursorIndex, Math.max(0, this.visibleItems.length - 1));
384
+ }
385
+ return;
386
+ }
387
+ if (this.keys.selectUp(data)) { this.moveCursor(-1); return; }
388
+ if (this.keys.selectDown(data)) { this.moveCursor(1); return; }
389
+ if (matchesKey(data, "space")) {
390
+ // Toggle even while in desc search
391
+ const item = this.visibleItems[this.cursorIndex];
392
+ if (item) this.toggleItem(item);
393
+ return;
394
+ }
395
+ if (data.length === 1 && data.charCodeAt(0) >= 32) {
396
+ this.descQuery += data;
397
+ this.rebuildVisibleItems();
398
+ this.cursorIndex = Math.min(this.cursorIndex, Math.max(0, this.visibleItems.length - 1));
399
+ return;
400
+ }
401
+ return;
402
+ }
403
+
404
+ if (matchesKey(data, "escape")) {
405
+ if (this.nameQuery) {
406
+ this.nameQuery = "";
407
+ this.rebuildVisibleItems();
408
+ this.cursorIndex = Math.min(this.cursorIndex, Math.max(0, this.visibleItems.length - 1));
409
+ return;
410
+ }
411
+ if (this.dirty) {
412
+ this.confirmingDiscard = true;
413
+ this.discardSelected = 1;
414
+ return;
415
+ }
416
+ this.cleanup();
417
+ this.done({ cancelled: true, changes: new Map() });
418
+ return;
419
+ }
420
+
421
+ if (this.keys.selectUp(data)) { this.moveCursor(-1); return; }
422
+ if (this.keys.selectDown(data)) { this.moveCursor(1); return; }
423
+
424
+ if (matchesKey(data, "space")) {
425
+ const item = this.visibleItems[this.cursorIndex];
426
+ if (item && !this.authOnly) this.toggleItem(item);
427
+ return;
428
+ }
429
+
430
+ if (this.keys.selectConfirm(data)) {
431
+ const item = this.visibleItems[this.cursorIndex];
432
+ if (!item) return;
433
+ const server = this.servers[item.serverIndex];
434
+ if (!server) return;
435
+ if (item.type === "server") {
436
+ if (server.connectionStatus === "disabled") return;
437
+ if (this.authOnly || server.connectionStatus === "needs-auth") {
438
+ this.authenticateServer(server);
439
+ return;
440
+ }
441
+ server.expanded = !server.expanded;
442
+ this.rebuildVisibleItems();
443
+ this.cursorIndex = Math.min(this.cursorIndex, Math.max(0, this.visibleItems.length - 1));
444
+ } else if (item.toolIndex !== undefined) {
445
+ const tool = server.tools[item.toolIndex];
446
+ if (!tool) return;
447
+ tool.isDirect = !tool.isDirect;
448
+ if (tool.isDirect && server.source === "import") {
449
+ this.importNotice = `Imported from ${sanitizeDisplayText(server.importKind ?? "external")} — will copy to user config on save`;
450
+ }
451
+ this.updateDirty();
452
+ }
453
+ return;
454
+ }
455
+
456
+ if (matchesKey(data, "ctrl+a")) {
457
+ const item = this.visibleItems[this.cursorIndex];
458
+ if (item) this.authenticateSelectedServer(item);
459
+ return;
460
+ }
461
+
462
+ if (matchesKey(data, "ctrl+r")) {
463
+ const item = this.visibleItems[this.cursorIndex];
464
+ if (!item) return;
465
+ const server = this.servers[item.serverIndex];
466
+ if (server) this.reconnectServer(server);
467
+ return;
468
+ }
469
+
470
+ if (matchesKey(data, "ctrl+y")) {
471
+ const item = this.visibleItems[this.cursorIndex];
472
+ if (!item) return;
473
+ const server = this.servers[item.serverIndex];
474
+ if (!server || server.connectionStatus !== "failed" || !server.failureMessage) return;
475
+ const serverName = sanitizeDisplayText(server.name);
476
+ const failureMessage = sanitizeDisplayText(server.failureMessage);
477
+ copyToClipboard(failureMessage).then(() => {
478
+ this.authNotice = `Copied error for ${serverName} to clipboard`;
479
+ this.tui.requestRender();
480
+ }).catch((error) => {
481
+ const message = sanitizeDisplayText(error instanceof Error ? error.message : String(error));
482
+ this.authNotice = `Failed to copy error for ${serverName}: ${message}`;
483
+ this.tui.requestRender();
484
+ });
485
+ return;
486
+ }
487
+
488
+ if (data === "?") {
489
+ if (this.authOnly) return;
490
+ this.descSearchActive = true;
491
+ this.descQuery = "";
492
+ this.rebuildVisibleItems();
493
+ this.cursorIndex = Math.min(this.cursorIndex, Math.max(0, this.visibleItems.length - 1));
494
+ return;
495
+ }
496
+
497
+ // Backspace removes from name query
498
+ if (matchesKey(data, "backspace")) {
499
+ if (this.nameQuery.length > 0) {
500
+ this.nameQuery = this.nameQuery.slice(0, -1);
501
+ this.rebuildVisibleItems();
502
+ this.cursorIndex = Math.min(this.cursorIndex, Math.max(0, this.visibleItems.length - 1));
503
+ }
504
+ return;
505
+ }
506
+
507
+ // All other printable chars → always-on name search
508
+ if (data.length === 1 && data.charCodeAt(0) >= 32) {
509
+ this.nameQuery += data;
510
+ this.rebuildVisibleItems();
511
+ this.cursorIndex = Math.min(this.cursorIndex, Math.max(0, this.visibleItems.length - 1));
512
+ return;
513
+ }
514
+ }
515
+
516
+ private authenticateSelectedServer(item: VisibleItem): void {
517
+ const server = this.servers[item.serverIndex];
518
+ if (server) this.authenticateServer(server);
519
+ }
520
+
521
+ private authenticateServer(server: ServerState): void {
522
+ if (this.authInFlight) return;
523
+ if (server.connectionStatus === "connecting" || server.connectionStatus === "disabled") return;
524
+ const serverName = sanitizeDisplayText(server.name);
525
+ if (!this.callbacks.canAuthenticate(server.name)) {
526
+ this.authNotice = `${serverName} does not use OAuth authentication.`;
527
+ return;
528
+ }
529
+
530
+ this.authInFlight = server.name;
531
+ this.authNotice = `Authenticating ${serverName}...`;
532
+ this.tui.requestRender();
533
+
534
+ this.callbacks.authenticate(server.name).then((result) => {
535
+ server.connectionStatus = this.callbacks.getConnectionStatus(server.name);
536
+ if (result.ok) {
537
+ this.authNotice = `OAuth finished for ${serverName}. Reconnecting...`;
538
+ this.authInFlight = null;
539
+ this.tui.requestRender();
540
+ this.reconnectServer(server, { afterAuth: true });
541
+ return;
542
+ }
543
+
544
+ const message = sanitizeDisplayText(result.message);
545
+ this.authNotice = `OAuth failed for ${serverName}${message ? `: ${message}` : ". Check the notification for details."}`;
546
+ this.authInFlight = null;
547
+ this.tui.requestRender();
548
+ }).catch((error) => {
549
+ const message = sanitizeDisplayText(error instanceof Error ? error.message : String(error));
550
+ server.connectionStatus = this.callbacks.getConnectionStatus(server.name);
551
+ this.authNotice = `OAuth failed for ${serverName}: ${message}`;
552
+ this.authInFlight = null;
553
+ this.tui.requestRender();
554
+ });
555
+ }
556
+
557
+ private reconnectServer(server: ServerState, options: { afterAuth?: boolean } = {}): void {
558
+ if (server.connectionStatus === "connecting" || server.connectionStatus === "disabled") return;
559
+ const serverName = sanitizeDisplayText(server.name);
560
+ server.connectionStatus = "connecting";
561
+ this.tui.requestRender();
562
+
563
+ this.callbacks.reconnect(server.name).then((connected) => {
564
+ server.connectionStatus = this.callbacks.getConnectionStatus(server.name);
565
+ server.failureMessage = this.callbacks.getFailureMessage?.(server.name) ?? null;
566
+ if (server.connectionStatus === "connected") {
567
+ const entry = this.callbacks.refreshCacheAfterReconnect(server.name);
568
+ if (entry) {
569
+ this.cache ??= { version: 1, servers: {} };
570
+ this.cache.servers[server.name] = entry;
571
+ this.rebuildServerTools(server, entry);
572
+ }
573
+ server.hasCachedData = true;
574
+ }
575
+ if (options.afterAuth) {
576
+ this.authNotice = connected && server.connectionStatus === "connected"
577
+ ? `OAuth finished for ${serverName}. Reconnected.`
578
+ : `OAuth finished for ${serverName}, but reconnect did not complete. Press ctrl+r to retry.`;
579
+ }
580
+ this.tui.requestRender();
581
+ }).catch((error) => {
582
+ server.connectionStatus = "failed";
583
+ const message = sanitizeDisplayText(error instanceof Error ? error.message : String(error));
584
+ this.authNotice = `Reconnect failed for ${serverName}: ${message}`;
585
+ this.tui.requestRender();
586
+ });
587
+ }
588
+
589
+ private toggleItem(item: VisibleItem): void {
590
+ if (this.authOnly) return;
591
+ const server = this.servers[item.serverIndex];
592
+ if (!server) return;
593
+ if (item.type === "server") {
594
+ const newState = !server.tools.every((t) => t.isDirect);
595
+ if (server.source === "import" && newState) {
596
+ this.importNotice = `Imported from ${sanitizeDisplayText(server.importKind ?? "external")} — will copy to user config on save`;
597
+ }
598
+ for (const t of server.tools) t.isDirect = newState;
599
+ } else if (item.toolIndex !== undefined) {
600
+ const tool = server.tools[item.toolIndex];
601
+ if (!tool) return;
602
+ tool.isDirect = !tool.isDirect;
603
+ if (tool.isDirect && server.source === "import") {
604
+ this.importNotice = `Imported from ${sanitizeDisplayText(server.importKind ?? "external")} — will copy to user config on save`;
605
+ }
606
+ }
607
+ this.updateDirty();
608
+ }
609
+
610
+ private handleDiscardInput(data: string): void {
611
+ if (matchesKey(data, "ctrl+c")) {
612
+ this.cleanup();
613
+ this.done({ cancelled: true, changes: new Map() });
614
+ return;
615
+ }
616
+ if (matchesKey(data, "escape") || data === "n" || data === "N") {
617
+ this.confirmingDiscard = false;
618
+ return;
619
+ }
620
+ if (this.keys.selectConfirm(data)) {
621
+ this.cleanup();
622
+ if (this.discardSelected === 0) {
623
+ this.done({ cancelled: true, changes: new Map() });
624
+ } else {
625
+ this.done(this.buildResult());
626
+ }
627
+ return;
628
+ }
629
+ if (data === "y" || data === "Y") {
630
+ this.cleanup();
631
+ this.done({ cancelled: true, changes: new Map() });
632
+ return;
633
+ }
634
+ if (matchesKey(data, "left") || matchesKey(data, "right") || matchesKey(data, "tab")) {
635
+ this.discardSelected = this.discardSelected === 0 ? 1 : 0;
636
+ }
637
+ }
638
+
639
+ private moveCursor(delta: number): void {
640
+ if (this.visibleItems.length === 0) return;
641
+ this.cursorIndex = Math.max(0, Math.min(this.visibleItems.length - 1, this.cursorIndex + delta));
642
+ }
643
+
644
+ private getOtherCurrentCandidates(
645
+ serverName: string,
646
+ definition: McpConfig["mcpServers"][string],
647
+ currentEntry: ServerCacheEntry,
648
+ toolName: string,
649
+ ): Set<string> {
650
+ const candidates = new Set<string>();
651
+ for (const [otherServerName, otherDefinition] of Object.entries(this.config.mcpServers)) {
652
+ if (isServerDisabled(otherDefinition)) continue;
653
+ const cachedEntry = this.cache?.servers?.[otherServerName];
654
+ const entry = otherServerName === serverName
655
+ ? currentEntry
656
+ : cachedEntry && isServerCacheValid(cachedEntry, otherDefinition) ? cachedEntry : undefined;
657
+ if (!entry) continue;
658
+ const otherPrefix = resolveToolPrefix(otherDefinition, this.prefix);
659
+ for (const tool of entry.tools ?? []) {
660
+ if (!isUiToolVisibleToModel(tool.uiVisibility)) continue;
661
+ for (const candidate of getToolNameCandidates(tool.name, otherServerName, otherPrefix, false)) candidates.add(candidate);
662
+ }
663
+ if (otherDefinition.exposeResources !== false) {
664
+ for (const resource of entry.resources ?? []) {
665
+ const baseName = `read_${resourceNameToToolName(resource.name)}`;
666
+ for (const candidate of getToolNameCandidates(baseName, otherServerName, otherPrefix, false)) candidates.add(candidate);
667
+ }
668
+ }
669
+ }
670
+ for (const candidate of getToolNameCandidates(toolName, serverName, resolveToolPrefix(definition, this.prefix), false)) candidates.delete(candidate);
671
+ return candidates;
672
+ }
673
+
674
+ private rebuildServerTools(server: ServerState, entry: ServerCacheEntry): void {
675
+ const existingState = new Map<string, boolean>();
676
+ for (const t of server.tools) existingState.set(t.name, t.isDirect);
677
+
678
+ const newTools: ToolState[] = [];
679
+ for (const tool of entry.tools ?? []) {
680
+ if (!isUiToolVisibleToModel(tool.uiVisibility)) continue;
681
+ if (!isToolAllowed(tool.name, server.name, this.prefix, server.includeTools, server.excludeTools, this.getOtherCurrentCandidates(server.name, server, entry, tool.name))) {
682
+ continue;
683
+ }
684
+
685
+ const prev = existingState.get(tool.name);
686
+ const isDirect = prev !== undefined ? prev : false;
687
+ newTools.push({
688
+ name: tool.name,
689
+ description: tool.description ?? "",
690
+ isDirect,
691
+ wasDirect: prev !== undefined ? server.tools.find((t) => t.name === tool.name)?.wasDirect ?? false : false,
692
+ estimatedTokens: estimateTokens(tool),
693
+ });
694
+ }
695
+
696
+ if (server.exposeResources) {
697
+ for (const resource of entry.resources ?? []) {
698
+ const baseName = `read_${resourceNameToToolName(resource.name)}`;
699
+ if (!isToolAllowed(baseName, server.name, this.prefix, server.includeTools, server.excludeTools, this.getOtherCurrentCandidates(server.name, server, entry, baseName))) {
700
+ continue;
701
+ }
702
+
703
+ const prev = existingState.get(baseName);
704
+ const isDirect = prev !== undefined ? prev : false;
705
+ const ct: CachedTool = {
706
+ name: baseName,
707
+ ...(resource.description !== undefined ? { description: resource.description } : {}),
708
+ };
709
+ newTools.push({
710
+ name: baseName,
711
+ description: resource.description ?? `Read resource: ${resource.uri}`,
712
+ isDirect,
713
+ wasDirect: prev !== undefined ? server.tools.find((t) => t.name === baseName)?.wasDirect ?? false : false,
714
+ estimatedTokens: estimateTokens(ct),
715
+ });
716
+ }
717
+ }
718
+
719
+ server.tools = newTools;
720
+ this.rebuildVisibleItems();
721
+ this.updateDirty();
722
+ }
723
+
724
+ render(width: number): string[] {
725
+ const innerW = width - 2;
726
+ const lines: string[] = [];
727
+ const t = this.t;
728
+ const bold = (s: string) => `\x1b[1m${s}\x1b[22m`;
729
+ const italic = (s: string) => `\x1b[3m${s}\x1b[23m`;
730
+ const inverse = (s: string) => `\x1b[7m${s}\x1b[27m`;
731
+
732
+ const row = (content: string) =>
733
+ fg(t.border, "│") + truncateToWidth(" " + sanitizeRowContent(content), innerW, "…", true) + fg(t.border, "│");
734
+ const emptyRow = () => fg(t.border, "│") + " ".repeat(innerW) + fg(t.border, "│");
735
+ const divider = () => fg(t.border, "├" + "─".repeat(innerW) + "┤");
736
+
737
+ const titleText = this.authOnly ? " MCP OAuth " : " MCP Servers ";
738
+ const borderLen = innerW - visibleWidth(titleText);
739
+ const leftB = Math.floor(borderLen / 2);
740
+ const rightB = borderLen - leftB;
741
+ lines.push(fg(t.border, "╭" + "─".repeat(leftB)) + fg(t.title, titleText) + fg(t.border, "─".repeat(rightB) + "╮"));
742
+
743
+ lines.push(emptyRow());
744
+
745
+ const cursor = fg(t.selected, "│");
746
+ const searchIcon = fg(t.border, "◎");
747
+ if (this.descSearchActive) {
748
+ lines.push(row(`${searchIcon} ${fg(t.needsAuth, "desc:")} ${this.descQuery}${cursor}`));
749
+ } else if (this.nameQuery) {
750
+ lines.push(row(`${searchIcon} ${this.nameQuery}${cursor}`));
751
+ } else {
752
+ lines.push(row(`${searchIcon} ${fg(t.placeholder, italic("search..."))}`));
753
+ }
754
+
755
+ lines.push(emptyRow());
756
+ if (this.noticeLines.length > 0) {
757
+ for (const notice of this.noticeLines) {
758
+ lines.push(row(fg(t.hint, italic(sanitizeDisplayText(notice)))));
759
+ }
760
+ lines.push(emptyRow());
761
+ }
762
+ lines.push(divider());
763
+
764
+ if (this.servers.length === 0) {
765
+ lines.push(emptyRow());
766
+ lines.push(row(fg(t.hint, italic(this.authOnly ? "No OAuth-capable MCP servers configured." : "No MCP servers configured."))));
767
+ lines.push(emptyRow());
768
+ } else {
769
+ const maxVis = McpPanel.MAX_VISIBLE;
770
+ const total = this.visibleItems.length;
771
+ const startIdx = Math.max(0, Math.min(this.cursorIndex - Math.floor(maxVis / 2), total - maxVis));
772
+ const endIdx = Math.min(startIdx + maxVis, total);
773
+
774
+ lines.push(emptyRow());
775
+
776
+ for (let i = startIdx; i < endIdx; i++) {
777
+ const item = this.visibleItems[i];
778
+ if (!item) continue;
779
+ const isCursor = i === this.cursorIndex;
780
+ const server = this.servers[item.serverIndex];
781
+ if (!server) continue;
782
+
783
+ if (item.type === "server") {
784
+ lines.push(row(this.renderServerRow(server, isCursor)));
785
+ if (isCursor && server.connectionStatus === "failed" && server.failureMessage) {
786
+ for (const line of this.wrapText(sanitizeDisplayText(server.failureMessage), innerW - 6)) {
787
+ lines.push(row(` ${fg(t.cancel, line)}`));
788
+ }
789
+ }
790
+ } else if (item.toolIndex !== undefined) {
791
+ const tool = server.tools[item.toolIndex];
792
+ if (tool) lines.push(row(this.renderToolRow(tool, isCursor, innerW)));
793
+ }
794
+ }
795
+
796
+ lines.push(emptyRow());
797
+
798
+ if (total > maxVis) {
799
+ const prog = Math.round(((this.cursorIndex + 1) / total) * 10);
800
+ lines.push(row(`${rainbowProgress(prog, 10)} ${fg(t.hint, `${this.cursorIndex + 1}/${total}`)}`));
801
+ lines.push(emptyRow());
802
+ }
803
+
804
+ if (this.importNotice) {
805
+ lines.push(row(fg(t.needsAuth, italic(sanitizeDisplayText(this.importNotice)))));
806
+ lines.push(emptyRow());
807
+ }
808
+ if (this.authNotice) {
809
+ lines.push(row(fg(t.needsAuth, italic(sanitizeDisplayText(this.authNotice)))));
810
+ lines.push(emptyRow());
811
+ }
812
+ }
813
+
814
+ lines.push(divider());
815
+ lines.push(emptyRow());
816
+
817
+ if (this.confirmingDiscard) {
818
+ const discardBtn = this.discardSelected === 0
819
+ ? inverse(bold(fg(t.cancel, " Discard ")))
820
+ : fg(t.hint, " Discard ");
821
+ const keepBtn = this.discardSelected === 1
822
+ ? inverse(bold(fg(t.confirm, " Keep & Close ")))
823
+ : fg(t.hint, " Keep & Close ");
824
+ lines.push(row(`Discard unsaved changes? ${discardBtn} ${keepBtn}`));
825
+ } else {
826
+ if (this.authOnly) {
827
+ lines.push(row(fg(t.description, "select a server to authenticate")));
828
+ } else {
829
+ const directCount = this.servers.reduce((sum, s) => sum + s.tools.filter((t) => t.isDirect).length, 0);
830
+ const totalTokens = this.servers.reduce(
831
+ (sum, s) => sum + s.tools.filter((t) => t.isDirect).reduce((ts, t) => ts + t.estimatedTokens, 0),
832
+ 0,
833
+ );
834
+ const stats =
835
+ directCount > 0 ? `${directCount} direct ~${totalTokens.toLocaleString()} tokens` : "no direct tools";
836
+ lines.push(row(fg(t.description, stats + (this.dirty ? fg(t.needsAuth, " (unsaved)") : ""))));
837
+ }
838
+ }
839
+
840
+ lines.push(emptyRow());
841
+ const saveLabel = this.keys.saveLabel();
842
+ const hints = this.authOnly
843
+ ? [
844
+ italic("↑↓") + " navigate",
845
+ italic("⏎") + " auth",
846
+ italic("ctrl+a") + " auth",
847
+ italic("esc") + " clear/close",
848
+ italic("ctrl+c") + " quit",
849
+ ]
850
+ : [
851
+ italic("↑↓") + " navigate",
852
+ italic("space") + " toggle",
853
+ italic("⏎") + " expand/auth",
854
+ italic("ctrl+a") + " auth",
855
+ italic("ctrl+r") + " reconnect",
856
+ ...(this.selectedServerHasFailureMessage() ? [italic("ctrl+y") + " copy error"] : []),
857
+ italic("?") + " desc search",
858
+ ...(saveLabel ? [italic(saveLabel) + " save"] : []),
859
+ italic("esc") + " clear/close",
860
+ italic("ctrl+c") + " quit",
861
+ ];
862
+ const gap = " ";
863
+ const gapW = 2;
864
+ const maxW = innerW - 2;
865
+ let curLine = "";
866
+ let curW = 0;
867
+ for (const hint of hints) {
868
+ const hw = visibleWidth(hint);
869
+ const needed = curW === 0 ? hw : gapW + hw;
870
+ if (curW > 0 && curW + needed > maxW) {
871
+ lines.push(row(fg(t.hint, curLine)));
872
+ curLine = hint;
873
+ curW = hw;
874
+ } else {
875
+ curLine += (curW > 0 ? gap : "") + hint;
876
+ curW += needed;
877
+ }
878
+ }
879
+ if (curLine) lines.push(row(fg(t.hint, curLine)));
880
+
881
+ lines.push(fg(t.border, "╰" + "─".repeat(innerW) + "╯"));
882
+
883
+ return lines;
884
+ }
885
+
886
+ private renderServerRow(server: ServerState, isCursor: boolean): string {
887
+ const t = this.t;
888
+ const bold = (s: string) => `\x1b[1m${s}\x1b[22m`;
889
+
890
+ const expandIcon = server.expanded ? "▾" : "▸";
891
+ const prefix = isCursor ? fg(t.selected, expandIcon) : fg(t.border, server.expanded ? expandIcon : "·");
892
+
893
+ const serverName = sanitizeDisplayText(server.name);
894
+ const importKind = sanitizeDisplayText(server.importKind ?? "import");
895
+ const nameStr = isCursor ? bold(fg(t.selected, serverName)) : serverName;
896
+ const importLabel = server.source === "import" ? fg(t.description, ` (${importKind})`) : "";
897
+ const statusLabel = this.renderConnectionStatus(server);
898
+
899
+ if (!server.hasCachedData && !this.authOnly) {
900
+ return `${prefix} ${nameStr}${importLabel} ${fg(t.description, "(not cached)")}${statusLabel}`;
901
+ }
902
+
903
+ const directCount = server.tools.filter((t) => t.isDirect).length;
904
+ const totalCount = server.tools.length;
905
+ let toggleIcon = fg(t.description, "○");
906
+ if (directCount === totalCount && totalCount > 0) {
907
+ toggleIcon = fg(t.direct, "●");
908
+ } else if (directCount > 0) {
909
+ toggleIcon = fg(t.needsAuth, "◐");
910
+ }
911
+
912
+ let toolInfo = "";
913
+ if (totalCount > 0) {
914
+ toolInfo = `${directCount}/${totalCount}`;
915
+ if (directCount > 0) {
916
+ const tokens = server.tools.filter((t) => t.isDirect).reduce((s, t) => s + t.estimatedTokens, 0);
917
+ toolInfo += ` ~${tokens.toLocaleString()}`;
918
+ }
919
+ toolInfo = fg(t.description, toolInfo);
920
+ }
921
+
922
+ return `${prefix} ${toggleIcon} ${nameStr}${importLabel} ${toolInfo}${statusLabel}`;
923
+ }
924
+
925
+ private selectedServerHasFailureMessage(): boolean {
926
+ const item = this.visibleItems[this.cursorIndex];
927
+ if (!item) return false;
928
+ const server = this.servers[item.serverIndex];
929
+ return server?.connectionStatus === "failed" && !!server.failureMessage;
930
+ }
931
+
932
+ private wrapText(text: string, width: number): string[] {
933
+ const max = Math.max(8, width);
934
+ const words = text.split(/\s+/).filter(Boolean);
935
+ const lines: string[] = [];
936
+ let current = "";
937
+ const splitLongWord = (word: string): string => {
938
+ let rest = word;
939
+ while (visibleWidth(rest) > max) {
940
+ let take = "";
941
+ let index = 0;
942
+ while (index < rest.length && visibleWidth(take + rest.charAt(index)) <= max) {
943
+ take += rest.charAt(index);
944
+ index++;
945
+ }
946
+ if (!take) take = rest.charAt(0);
947
+ lines.push(take);
948
+ rest = rest.slice(take.length);
949
+ }
950
+ return rest;
951
+ };
952
+
953
+ for (const word of words) {
954
+ const candidate = current ? `${current} ${word}` : word;
955
+ if (visibleWidth(candidate) <= max) {
956
+ current = candidate;
957
+ } else {
958
+ if (current) lines.push(current);
959
+ current = splitLongWord(word);
960
+ }
961
+ }
962
+ if (current) lines.push(current);
963
+ return lines.length > 0 ? lines : [text];
964
+ }
965
+
966
+ private renderConnectionStatus(server: ServerState): string {
967
+ const t = this.t;
968
+ if (this.authInFlight === server.name) return ` ${fg(t.needsAuth, "authenticating")}`;
969
+ if (server.connectionStatus === "disabled") return ` ${fg(t.description, "disabled")}`;
970
+ if (server.connectionStatus === "needs-auth") return ` ${fg(t.needsAuth, "needs auth")}`;
971
+ if (server.connectionStatus === "connecting") return ` ${fg(t.needsAuth, "connecting")}`;
972
+ if (server.connectionStatus === "failed") return ` ${fg(t.cancel, "failed")}`;
973
+ if (this.authOnly && server.connectionStatus === "connected") return ` ${fg(t.direct, "connected")}`;
974
+ if (this.authOnly) return ` ${fg(t.description, "idle")}`;
975
+ return "";
976
+ }
977
+
978
+ private renderToolRow(tool: ToolState, isCursor: boolean, innerW: number): string {
979
+ const t = this.t;
980
+ const bold = (s: string) => `\x1b[1m${s}\x1b[22m`;
981
+
982
+ const toggleIcon = tool.isDirect ? fg(t.direct, "●") : fg(t.description, "○");
983
+ const cursor = isCursor ? fg(t.selected, "▸") : " ";
984
+ const toolName = sanitizeDisplayText(tool.name);
985
+ const description = sanitizeDisplayText(tool.description);
986
+ const nameStr = isCursor ? bold(fg(t.selected, toolName)) : toolName;
987
+
988
+ const prefixLen = 7 + visibleWidth(toolName);
989
+ const maxDescLen = Math.max(0, innerW - prefixLen - 8);
990
+ const descStr =
991
+ maxDescLen > 5 && description
992
+ ? fg(t.description, "— " + truncateToWidth(description, maxDescLen, "…"))
993
+ : "";
994
+
995
+ return ` ${cursor} ${toggleIcon} ${nameStr} ${descStr}`;
996
+ }
997
+
998
+ invalidate(): void {}
999
+
1000
+ dispose(): void {
1001
+ this.cleanup();
1002
+ }
1003
+ }
1004
+
1005
+ export function createMcpPanel(
1006
+ config: McpConfig,
1007
+ cache: MetadataCache | null,
1008
+ provenance: Map<string, ServerProvenance>,
1009
+ callbacks: McpPanelCallbacks,
1010
+ tui: { requestRender(): void },
1011
+ done: (result: McpPanelResult) => void,
1012
+ options?: { noticeLines?: string[]; authOnly?: boolean; keybindings?: PanelKeybindings },
1013
+ ): McpPanel & { dispose(): void } {
1014
+ return new McpPanel(config, cache, provenance, callbacks, tui, done, options ?? {});
1015
+ }