@herbertgao/pi-extensions 2026.9.17 → 2026.9.19

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 (307) hide show
  1. package/README.md +31 -33
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/node_modules/@herbertgao/pi-bark/package.json +2 -2
  4. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +4 -1
  5. package/node_modules/@herbertgao/pi-cc-extensions/README.md +4 -1
  6. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/working-message.ts +21 -6
  7. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/index.ts +15 -4
  8. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/index.ts +43 -7
  9. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +7 -2
  10. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/result.ts +1 -1
  11. package/node_modules/@herbertgao/pi-cc-extensions/package.json +75 -75
  12. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
  13. package/node_modules/@herbertgao/pi-subagents/package.json +7 -7
  14. package/node_modules/@herbertgao/resume-from/package.json +4 -2
  15. package/node_modules/@herbertgao/sol-pi/package.json +6 -6
  16. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +99 -99
  17. package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
  18. package/node_modules/@tifan/pi-handoff/package.json +1 -1
  19. package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
  20. package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
  21. package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
  22. package/node_modules/@tifan/pi-recap/package.json +1 -1
  23. package/node_modules/@tifan/pi-rename/package.json +1 -1
  24. package/node_modules/pi-antigravity/README.md +29 -6
  25. package/node_modules/pi-antigravity/package.json +14 -9
  26. package/node_modules/pi-antigravity/src/auth/accounts.ts +327 -0
  27. package/node_modules/pi-antigravity/src/auth/index.ts +9 -0
  28. package/node_modules/pi-antigravity/src/client/client.ts +1 -1
  29. package/node_modules/pi-antigravity/src/image/image.ts +4 -4
  30. package/node_modules/pi-antigravity/src/index.ts +203 -13
  31. package/node_modules/pi-antigravity/src/search/index.ts +1 -0
  32. package/node_modules/pi-antigravity/src/search/search.ts +325 -0
  33. package/node_modules/pi-antigravity/src/stream/stream.ts +191 -14
  34. package/node_modules/pi-antigravity/src/types/enums.ts +45 -36
  35. package/node_modules/pi-antigravity/src/types/types.ts +5 -12
  36. package/node_modules/pi-antigravity/src/utils/http.ts +7 -2
  37. package/node_modules/pi-antigravity/src/utils/util.ts +31 -3
  38. package/node_modules/pi-lens/package.json +158 -158
  39. package/node_modules/pi-multi-account/package.json +2 -2
  40. package/node_modules/pi-typesafe/README.md +3 -1
  41. package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
  42. package/node_modules/pi-typesafe/dist/auth.js +7 -3
  43. package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
  44. package/node_modules/pi-typesafe/dist/backends.js +95 -1
  45. package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
  46. package/node_modules/pi-typesafe/dist/client.js +12 -9
  47. package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
  48. package/node_modules/pi-typesafe/dist/credentials.js +10 -7
  49. package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
  50. package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
  51. package/node_modules/pi-typesafe/dist/index.js +1 -1
  52. package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
  53. package/node_modules/pi-typesafe/dist/login.js +2 -2
  54. package/node_modules/pi-typesafe/package.json +6 -5
  55. package/node_modules/pi-web-access/CHANGELOG.md +72 -0
  56. package/node_modules/pi-web-access/README.md +34 -13
  57. package/node_modules/pi-web-access/chrome-cookies.ts +79 -25
  58. package/node_modules/pi-web-access/curator-page.ts +5 -1
  59. package/node_modules/pi-web-access/curator-server.ts +2 -0
  60. package/node_modules/pi-web-access/dist/index.js +1337 -1009
  61. package/node_modules/pi-web-access/exa.ts +20 -52
  62. package/node_modules/pi-web-access/extract.ts +41 -4
  63. package/node_modules/pi-web-access/gemini-search.ts +12 -4
  64. package/node_modules/pi-web-access/index.ts +29 -37
  65. package/node_modules/pi-web-access/openai-search.ts +35 -7
  66. package/node_modules/pi-web-access/package.json +8 -7
  67. package/node_modules/pi-web-access/page-query.ts +2 -2
  68. package/node_modules/pi-web-access/query-rewrite.ts +2 -3
  69. package/node_modules/pi-web-access/ssrf-protection.ts +27 -10
  70. package/node_modules/pi-web-access/storage.ts +48 -77
  71. package/node_modules/pi-web-access/summary-model-scope.ts +6 -77
  72. package/node_modules/pi-web-access/summary-review.ts +3 -4
  73. package/node_modules/pi-web-access/tavily.ts +67 -20
  74. package/node_modules/pi-web-access/tool-activation.ts +53 -33
  75. package/node_modules/pi-web-access/utils.ts +1 -1
  76. package/node_modules/pi-web-access/you.ts +164 -0
  77. package/node_modules/pi-web-access/zai.ts +161 -0
  78. package/node_modules/remote-pi/package.json +5 -1
  79. package/package.json +19 -31
  80. package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
  81. package/node_modules/pi-mcp-adapter/LICENSE +0 -21
  82. package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
  83. package/node_modules/pi-mcp-adapter/README.md +0 -1021
  84. package/node_modules/pi-mcp-adapter/abort.ts +0 -34
  85. package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
  86. package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
  87. package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
  88. package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
  89. package/node_modules/pi-mcp-adapter/banner.png +0 -0
  90. package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
  91. package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
  92. package/node_modules/pi-mcp-adapter/cli.js +0 -454
  93. package/node_modules/pi-mcp-adapter/commands.ts +0 -861
  94. package/node_modules/pi-mcp-adapter/config.ts +0 -1565
  95. package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
  96. package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
  97. package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
  98. package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
  99. package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
  100. package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
  101. package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
  102. package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
  103. package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
  104. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
  105. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
  106. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
  107. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
  108. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
  109. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
  110. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
  111. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
  112. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
  113. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
  114. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
  115. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
  116. package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
  117. package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
  118. package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
  119. package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
  120. package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
  121. package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
  122. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
  123. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
  124. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
  125. package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
  126. package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
  127. package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
  128. package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
  129. package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
  130. package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
  131. package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
  132. package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
  133. package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
  134. package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
  135. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
  136. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
  137. package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
  138. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
  139. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
  140. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
  141. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
  142. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
  143. package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
  144. package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
  145. package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
  146. package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
  147. package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
  148. package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
  149. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
  150. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
  151. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
  152. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
  153. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
  154. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
  155. package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
  156. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
  157. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
  158. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
  159. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
  160. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
  161. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
  162. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
  163. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
  164. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
  165. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
  166. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
  167. package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
  168. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
  169. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
  170. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
  171. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
  172. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
  173. package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
  174. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
  175. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
  176. package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
  177. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
  178. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
  179. package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
  180. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
  181. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
  182. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
  183. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
  184. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
  185. package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
  186. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
  187. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
  188. package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
  189. package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
  190. package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
  191. package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
  192. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
  193. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
  194. package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
  195. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
  196. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
  197. package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
  198. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
  199. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
  200. package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
  201. package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
  202. package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
  203. package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
  204. package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
  205. package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
  206. package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
  207. package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
  208. package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
  209. package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
  210. package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
  211. package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
  212. package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
  213. package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
  214. package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
  215. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
  216. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
  217. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
  218. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
  219. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
  220. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
  221. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
  222. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
  223. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
  224. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
  225. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
  226. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
  227. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
  228. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
  229. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
  230. package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
  231. package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
  232. package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
  233. package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
  234. package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
  235. package/node_modules/pi-mcp-adapter/errors.ts +0 -364
  236. package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
  237. package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
  238. package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
  239. package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
  240. package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
  241. package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
  242. package/node_modules/pi-mcp-adapter/index.ts +0 -2106
  243. package/node_modules/pi-mcp-adapter/init.ts +0 -721
  244. package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
  245. package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
  246. package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
  247. package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
  248. package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
  249. package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
  250. package/node_modules/pi-mcp-adapter/logger.ts +0 -169
  251. package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
  252. package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
  253. package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
  254. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
  255. package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
  256. package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
  257. package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
  258. package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
  259. package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
  260. package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
  261. package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
  262. package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
  263. package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
  264. package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
  265. package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
  266. package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
  267. package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
  268. package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
  269. package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
  270. package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
  271. package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
  272. package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
  273. package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
  274. package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
  275. package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
  276. package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
  277. package/node_modules/pi-mcp-adapter/package.json +0 -219
  278. package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
  279. package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
  280. package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
  281. package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
  282. package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
  283. package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
  284. package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
  285. package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
  286. package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
  287. package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
  288. package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
  289. package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
  290. package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
  291. package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
  292. package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
  293. package/node_modules/pi-mcp-adapter/state.ts +0 -71
  294. package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
  295. package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
  296. package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
  297. package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
  298. package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
  299. package/node_modules/pi-mcp-adapter/types.ts +0 -1120
  300. package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
  301. package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
  302. package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
  303. package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
  304. package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
  305. package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
  306. package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
  307. package/node_modules/pi-mcp-adapter/utils.ts +0 -464
@@ -1,747 +0,0 @@
1
- import { Container, Text, matchesKey, truncateToWidth, visibleWidth, type Component } from "@earendil-works/pi-tui";
2
- import type { Theme } from "@earendil-works/pi-coding-agent";
3
- import { createMcpPanelTheme, McpPanelFrame, type McpPanelTheme } from "./mcp-panel-theme.ts";
4
- import { createPanelKeys, type PanelKeybindings, type PanelKeys } from "./panel-keys.ts";
5
- import type { ImportKind } from "./types.ts";
6
- import { getConfigDirName } from "./agent-dir.ts";
7
- import { KNOWN_SERVER_PRESETS, type ConfigWritePreview, type KnownServerPreset, type McpDiscoverySummary, type SharedConfigTarget } from "./config.ts";
8
- import type { McpOnboardingState } from "./onboarding-state.ts";
9
-
10
- const MIN_PANEL_WIDTH = 24;
11
- const COMPACT_WIDTH = 60;
12
- const COMPACT_ACTION_ROWS = 7;
13
- const DESKTOP_PREVIEW_WIDTH = 74;
14
-
15
- function wrapText(text: string, width: number): string[] {
16
- if (width <= 8) return [text];
17
- const words = text.split(/\s+/).filter(Boolean);
18
- const lines: string[] = [];
19
- let current = "";
20
- for (const word of words) {
21
- const candidate = current ? `${current} ${word}` : word;
22
- if (visibleWidth(candidate) <= width) {
23
- current = candidate;
24
- continue;
25
- }
26
- if (current) lines.push(current);
27
- current = word;
28
- }
29
- if (current) lines.push(current);
30
- return lines.length > 0 ? lines : [""];
31
- }
32
-
33
- export interface SetupPanelCallbacks {
34
- previewImports: (imports: ImportKind[]) => ConfigWritePreview;
35
- previewStarterConfig: (target: SharedConfigTarget) => ConfigWritePreview;
36
- previewRepoPrompt: (target: SharedConfigTarget) => ConfigWritePreview | null;
37
- previewKnownServer: (preset: KnownServerPreset, target: SharedConfigTarget) => ConfigWritePreview;
38
- adoptImports: (imports: ImportKind[]) => Promise<{ added: ImportKind[]; path: string }>;
39
- scaffoldConfig: (target: SharedConfigTarget) => Promise<{ path: string }>;
40
- addRepoPrompt: (target: SharedConfigTarget) => Promise<{ path: string; serverName: string }>;
41
- addKnownServer: (preset: KnownServerPreset, target: SharedConfigTarget) => Promise<{ path: string; serverName: string }>;
42
- openPath: (path: string) => Promise<void>;
43
- markSetupCompleted: () => void;
44
- }
45
-
46
- export interface SetupPanelOptions {
47
- mode: "empty" | "setup";
48
- onboardingState: McpOnboardingState;
49
- keybindings?: PanelKeybindings;
50
- theme?: Theme;
51
- }
52
-
53
- type Screen = "empty" | "setup" | "imports" | "paths";
54
-
55
- type ActionId =
56
- | "run-setup"
57
- | "select-shared-target"
58
- | "adopt-imports"
59
- | "view-example"
60
- | "show-precedence"
61
- | "open-paths"
62
- | "add-repoprompt"
63
- | "add-known-server"
64
- | "scaffold-shared-config"
65
- | "close";
66
-
67
- interface Action {
68
- id: ActionId;
69
- label: string;
70
- preset?: KnownServerPreset;
71
- target?: SharedConfigTarget;
72
- }
73
-
74
- interface McpSetupPanelViewState {
75
- screen: Screen;
76
- actionCursor: number;
77
- importCursor: number;
78
- pathCursor: number;
79
- sharedConfigTarget: SharedConfigTarget;
80
- selectedImports: ReadonlySet<ImportKind>;
81
- notice: { text: string; tone: "success" | "warning" | "muted" } | null;
82
- onboardingState: McpOnboardingState;
83
- discovery: McpDiscoverySummary;
84
- actions: readonly Action[];
85
- detectedPaths: readonly string[];
86
- }
87
-
88
- /**
89
- * The setup view owns component composition and display formatting. The panel
90
- * below remains the controller for input routing, async actions, and timers.
91
- */
92
- class McpSetupPanelView implements Component {
93
- private readonly container = new Container();
94
-
95
- constructor(
96
- private readonly getState: () => McpSetupPanelViewState,
97
- private readonly callbacks: SetupPanelCallbacks,
98
- private readonly theme: McpPanelTheme,
99
- ) {}
100
-
101
- render(width: number): string[] {
102
- const panelWidth = Math.max(MIN_PANEL_WIDTH, width);
103
- const innerWidth = panelWidth - 2;
104
- const contentWidth = this.contentWidth(innerWidth);
105
- const state = this.getState();
106
- this.container.clear();
107
-
108
- this.addFrame("┌", "┐");
109
- this.addRow(this.theme.title("MCP setup"), innerWidth);
110
- let discoveryTone = this.theme.hint;
111
- if (!state.discovery.hasAnyConfig || (state.discovery.totalServerCount === 0 && (state.discovery.imports.length > 0 || !!state.discovery.repoPrompt.executablePath))) {
112
- discoveryTone = this.theme.needsAuth;
113
- }
114
- for (const line of wrapText(this.discoverySummaryLine(state), contentWidth)) {
115
- this.addRow(discoveryTone(line), innerWidth);
116
- }
117
- for (const line of wrapText(this.secondarySummaryLine(state), contentWidth)) {
118
- this.addRow(this.theme.description(this.theme.italic(line)), innerWidth);
119
- }
120
- this.addRow("", innerWidth);
121
-
122
- if (state.notice) {
123
- let tone = this.theme.hint;
124
- if (state.notice.tone === "success") {
125
- tone = this.theme.confirm;
126
- } else if (state.notice.tone === "warning") {
127
- tone = this.theme.needsAuth;
128
- }
129
- for (const line of wrapText(state.notice.text, contentWidth)) {
130
- this.addRow(tone(line), innerWidth);
131
- }
132
- this.addRow("", innerWidth);
133
- }
134
-
135
- this.addFrame("├", "┤");
136
- if (state.screen === "imports") {
137
- for (const line of this.renderImports(state, innerWidth)) this.addRow(line, innerWidth);
138
- } else if (state.screen === "paths") {
139
- for (const line of this.renderPaths(state)) this.addRow(line, innerWidth);
140
- } else {
141
- for (const line of this.renderActions(state, innerWidth)) this.addRow(line, innerWidth);
142
- }
143
- this.addFrame("└", "┘");
144
- return this.container.render(panelWidth);
145
- }
146
-
147
- invalidate(): void {
148
- this.container.invalidate();
149
- }
150
-
151
- private addFrame(left: string, right: string): void {
152
- this.container.addChild(new McpPanelFrame(this.theme, left, right));
153
- }
154
-
155
- private addRow(content: string, innerWidth: number): void {
156
- this.container.addChild(new Text(this.padLine(content, innerWidth), 0, 0));
157
- }
158
-
159
- private renderActions(state: McpSetupPanelViewState, innerWidth: number): string[] {
160
- const lines: string[] = [];
161
- const actions = state.actions;
162
- const compact = innerWidth < COMPACT_WIDTH;
163
- const { start, end } = compact
164
- ? this.visibleActionRange(actions.length, state.actionCursor)
165
- : { start: 0, end: actions.length };
166
-
167
- if (start > 0) {
168
- lines.push(this.theme.description(`… ${start} more above`));
169
- }
170
- for (let index = start; index < end; index++) {
171
- const action = actions[index];
172
- if (!action) continue;
173
- if (action.id === "select-shared-target" && (index === start || actions[index - 1]?.id !== "select-shared-target")) {
174
- lines.push(this.theme.title("Choose where new shared servers go"));
175
- }
176
- if (action.id === "add-known-server" && (index === start || actions[index - 1]?.id !== "add-known-server")) {
177
- lines.push(this.theme.title(`Add a known server to ${this.sharedTargetLabel(state)}`));
178
- }
179
- const selected = index === state.actionCursor;
180
- const cursor = selected ? this.theme.selected("›") : " ";
181
- lines.push(`${cursor} ${truncateToWidth(action.label, this.contentWidth(innerWidth) - 2)}`);
182
- }
183
- if (end < actions.length) {
184
- lines.push(this.theme.description(`… ${actions.length - end} more below`));
185
- }
186
- lines.push("");
187
-
188
- const preview = this.getActionPreview(state, actions[state.actionCursor], this.previewWidth(innerWidth));
189
- lines.push(...preview);
190
- lines.push("");
191
- const hint = compact ? "Enter select · Esc back" : "Enter selects, Esc goes back, Ctrl+C closes.";
192
- lines.push(this.theme.description(hint));
193
- return lines;
194
- }
195
-
196
- private renderImports(state: McpSetupPanelViewState, innerWidth: number): string[] {
197
- const lines: string[] = [];
198
- lines.push("Select compatibility imports. Space toggles, Enter saves, Esc goes back.");
199
- lines.push("");
200
- for (let index = 0; index < state.discovery.imports.length; index++) {
201
- const entry = state.discovery.imports[index];
202
- if (!entry) continue;
203
- const selected = state.selectedImports.has(entry.kind) ? "[x]" : "[ ]";
204
- const cursor = index === state.importCursor ? this.theme.selected("›") : " ";
205
- lines.push(`${cursor} ${selected} ${entry.kind} ${entry.path}`);
206
- }
207
- lines.push("");
208
- const selected = state.discovery.imports
209
- .filter((entry) => state.selectedImports.has(entry.kind))
210
- .map((entry) => entry.kind);
211
- const preview = this.callbacks.previewImports(selected);
212
- lines.push(...this.formatWritePreview("Compatibility import write preview", preview, [], this.previewWidth(innerWidth)));
213
- return lines;
214
- }
215
-
216
- private renderPaths(state: McpSetupPanelViewState): string[] {
217
- const lines: string[] = [];
218
- lines.push("Select a detected config path to open. Enter opens it, Esc goes back.");
219
- lines.push("");
220
- for (let index = 0; index < state.detectedPaths.length; index++) {
221
- const path = state.detectedPaths[index];
222
- const cursor = index === state.pathCursor ? this.theme.selected("›") : " ";
223
- if (path !== undefined) lines.push(`${cursor} ${path}`);
224
- }
225
- return lines;
226
- }
227
-
228
- private discoverySummaryLine(state: McpSetupPanelViewState): string {
229
- if (!state.discovery.hasAnyConfig) {
230
- return state.onboardingState.setupCompleted
231
- ? "No MCP servers are active right now."
232
- : "No MCP config is active yet.";
233
- }
234
-
235
- if (state.discovery.totalServerCount === 0 && (state.discovery.imports.length > 0 || !!state.discovery.repoPrompt.executablePath)) {
236
- return "Pi found MCP-related setup options, but none are active in Pi yet.";
237
- }
238
-
239
- const shared = state.discovery.sources.filter((source) => source.kind === "shared" && source.serverCount > 0).length;
240
- const piOwned = state.discovery.sources.filter((source) => source.kind === "pi" && source.serverCount > 0).length;
241
- return `Detected ${state.discovery.totalServerCount} configured servers across ${shared} shared and ${piOwned} Pi-owned source${shared + piOwned === 1 ? "" : "s"}.`;
242
- }
243
-
244
- private secondarySummaryLine(state: McpSetupPanelViewState): string {
245
- const hostNote = state.discovery.hostConfigs.length > 0
246
- ? ` Host discovery is ${state.discovery.hostConfigDiscovery}; ${state.discovery.hostConfigs.length} host source${state.discovery.hostConfigs.length === 1 ? "" : "s"} detected.`
247
- : "";
248
- const conflictNote = state.discovery.conflicts.length > 0
249
- ? ` ${state.discovery.conflicts.length} same-name conflict${state.discovery.conflicts.length === 1 ? "" : "s"} reported.`
250
- : "";
251
- if (!state.discovery.hasAnyConfig) {
252
- return `Add shared servers to .mcp.json for this project/team or ~/.config/mcp/mcp.json for all projects. Adopt host imports or quick-add RepoPrompt from this screen.${hostNote}${conflictNote}`;
253
- }
254
- if (state.discovery.totalServerCount === 0 && state.discovery.imports.length > 0) {
255
- return `Detected ${state.discovery.imports.length} compatibility import source${state.discovery.imports.length === 1 ? "" : "s"}. Adopt them into Pi or inspect the underlying files.${hostNote}${conflictNote}`;
256
- }
257
- return `Use .mcp.json for project/team servers or ~/.config/mcp/mcp.json for all projects. Pi-owned files are for compatibility imports and adapter-specific overrides, not another normal setup path.${hostNote}${conflictNote}`;
258
- }
259
-
260
- private visibleActionRange(total: number, cursor: number): { start: number; end: number } {
261
- if (total <= COMPACT_ACTION_ROWS) return { start: 0, end: total };
262
- const half = Math.floor(COMPACT_ACTION_ROWS / 2);
263
- const start = Math.min(Math.max(0, cursor - half), Math.max(0, total - COMPACT_ACTION_ROWS));
264
- return { start, end: Math.min(total, start + COMPACT_ACTION_ROWS) };
265
- }
266
-
267
- private contentWidth(innerWidth: number): number {
268
- return Math.max(8, innerWidth - 4);
269
- }
270
-
271
- private previewWidth(innerWidth: number): number {
272
- return Math.max(12, Math.min(DESKTOP_PREVIEW_WIDTH, this.contentWidth(innerWidth)));
273
- }
274
-
275
- private sharedTargetLabel(state: McpSetupPanelViewState): string {
276
- return state.sharedConfigTarget === "project" ? "project .mcp.json" : "global ~/.config/mcp/mcp.json";
277
- }
278
-
279
- private getActionPreview(state: McpSetupPanelViewState, action?: Action, previewW = DESKTOP_PREVIEW_WIDTH): string[] {
280
- switch (action?.id) {
281
- case "run-setup":
282
- return this.formatPreview([
283
- "Run setup to adopt host-specific imports, inspect detected paths, and scaffold a minimal `.mcp.json` if needed.",
284
- ], previewW);
285
- case "adopt-imports":
286
- return this.formatWritePreview(
287
- "Compatibility import write preview",
288
- this.callbacks.previewImports(state.discovery.imports
289
- .filter((entry) => state.selectedImports.has(entry.kind))
290
- .map((entry) => entry.kind)),
291
- [
292
- `Detected imports: ${state.discovery.imports.map((entry) => `${entry.kind} (${entry.serverCount} servers)`).join(", ")}`,
293
- "Selected imports are written into the Pi agent dir config as Pi-owned compatibility state.",
294
- ],
295
- previewW,
296
- );
297
- case "select-shared-target":
298
- return this.formatPreview([
299
- action.target === "project" ? "Project target: .mcp.json" : "Global target: ~/.config/mcp/mcp.json",
300
- "Known server presets and starter configs will be written to the selected normal MCP setup path.",
301
- "Pi-owned mcp.json files remain compatibility and adapter-only override state.",
302
- ], previewW);
303
- case "view-example":
304
- return this.formatPreview([
305
- "Example shared `.mcp.json`:",
306
- "{",
307
- ' "mcpServers": {',
308
- ' "chrome-devtools": {',
309
- ' "command": "npx",',
310
- ' "args": ["-y", "chrome-devtools-mcp@1.6.0"]',
311
- " }",
312
- " }",
313
- "}",
314
- "",
315
- "Use Scaffold selected config when you want a safe empty shell instead of a live example server.",
316
- ], previewW);
317
- case "show-precedence":
318
- return this.formatPreview([
319
- "Recommended shared config:",
320
- " project/team: .mcp.json",
321
- " all projects: ~/.config/mcp/mcp.json",
322
- "",
323
- "Advanced compatibility and Pi-owned layers:",
324
- " host imports, .agents files, package MCP manifests, and Pi overrides",
325
- "",
326
- "Read order (later entries win):",
327
- "0. detected host configs (opt-in lowest-precedence fallback)",
328
- "1. ~/.config/mcp/mcp.json",
329
- "2. ~/.agents/mcp.json",
330
- "3. ~/.agents/mcp/mcp.json",
331
- "4. <Pi agent dir>/mcp.json",
332
- "5. configured ancestor root to parent(cwd), farthest first (opt-in)",
333
- ` per directory: .mcp.json, then ${getConfigDirName()}/mcp.json`,
334
- "6. cwd/.mcp.json",
335
- `7. cwd/${getConfigDirName()}/mcp.json`,
336
- `Host discovery: ${state.discovery.hostConfigDiscovery}. Conflicts reported: ${state.discovery.conflicts.length}.`,
337
- ...state.discovery.conflicts.slice(0, 8).map((conflict) =>
338
- `${conflict.serverName}: ${conflict.sources.map((source) => source.path).join(" -> ")} (winner: ${conflict.winner.path})`,
339
- ),
340
- "Pi writes compatibility imports and adapter-only overrides to Pi-owned files.",
341
- ], previewW);
342
- case "open-paths":
343
- return this.formatPreview(state.detectedPaths.length > 0
344
- ? ["Detected paths:", ...state.detectedPaths]
345
- : ["No config paths were detected."], previewW);
346
- case "add-repoprompt": {
347
- const repoPrompt = state.discovery.repoPrompt;
348
- const preview = this.callbacks.previewRepoPrompt(state.sharedConfigTarget);
349
- if (!preview) {
350
- return this.formatPreview(["RepoPrompt is not available to add from this setup screen."], previewW);
351
- }
352
- return this.formatWritePreview(
353
- "RepoPrompt write preview",
354
- preview,
355
- [
356
- `Executable: ${repoPrompt.executablePath ?? "not found"}`,
357
- `Target: ${this.sharedTargetLabel(state)}`,
358
- `Server name: ${repoPrompt.serverName ?? "repoprompt"}`,
359
- ],
360
- previewW,
361
- );
362
- }
363
- case "add-known-server": {
364
- const preset = action.preset;
365
- if (!preset) return this.formatPreview(["Known server preset is unavailable."], previewW);
366
- return this.formatWritePreview(
367
- `${preset.name} write preview`,
368
- this.callbacks.previewKnownServer(preset, state.sharedConfigTarget),
369
- [preset.summary, `Target: ${this.sharedTargetLabel(state)}`],
370
- previewW,
371
- );
372
- }
373
- case "scaffold-shared-config":
374
- return this.formatWritePreview(
375
- `${this.sharedTargetLabel(state)} starter write preview`,
376
- this.callbacks.previewStarterConfig(state.sharedConfigTarget),
377
- [
378
- "This writes a minimal config at the selected normal MCP setup path.",
379
- "It intentionally avoids adding a fake placeholder server that would fail on first reload.",
380
- ],
381
- previewW,
382
- );
383
- case "close":
384
- default:
385
- return this.formatPreview(["Close the setup flow."], previewW);
386
- }
387
- }
388
-
389
- private formatPreview(lines: string[], width = DESKTOP_PREVIEW_WIDTH): string[] {
390
- const preview: string[] = [];
391
- for (const line of lines) preview.push(...wrapText(line, width));
392
- return preview;
393
- }
394
-
395
- private formatWritePreview(title: string, preview: ConfigWritePreview, intro: string[] = [], width = DESKTOP_PREVIEW_WIDTH): string[] {
396
- const lines: string[] = [];
397
- for (const line of intro) lines.push(...wrapText(line, width));
398
- if (intro.length > 0) lines.push("");
399
- lines.push(...wrapText(`${title}: ${preview.path}`, width));
400
- lines.push(...wrapText(preview.existed ? "Existing file detected. Showing exact before/after diff." : "New file will be created. Showing exact content diff.", width));
401
- lines.push("");
402
- const diffLines = preview.diffText.split("\n");
403
- const maxLines = 18;
404
- const shown = diffLines.slice(0, maxLines);
405
- for (const line of shown) lines.push(...wrapText(line, width));
406
- if (diffLines.length > maxLines) {
407
- lines.push(...wrapText(`… ${diffLines.length - maxLines} more diff line${diffLines.length - maxLines === 1 ? "" : "s"}`, width));
408
- }
409
- return lines;
410
- }
411
-
412
- private padLine(text: string, innerWidth: number): string {
413
- const inset = 2;
414
- const contentWidth = Math.max(0, innerWidth - inset * 2);
415
- const fitted = truncateToWidth(text, contentWidth, "…", true);
416
- const padding = Math.max(0, contentWidth - visibleWidth(fitted));
417
- return `${this.theme.border("│")}${" ".repeat(inset)}${fitted}${" ".repeat(padding)}${" ".repeat(inset)}${this.theme.border("│")}`;
418
- }
419
- }
420
-
421
- export class McpSetupPanel {
422
- private screen: Screen;
423
- private actionCursor = 0;
424
- private importCursor = 0;
425
- private pathCursor = 0;
426
- private sharedConfigTarget: SharedConfigTarget = "project";
427
- private selectedImports = new Set<ImportKind>();
428
- private busy = false;
429
- private notice: { text: string; tone: "success" | "warning" | "muted" } | null = null;
430
- private tui: { requestRender(): void };
431
- private readonly view: McpSetupPanelView;
432
- private keys: PanelKeys;
433
- private inactivityTimeout: ReturnType<typeof setTimeout> | null = null;
434
- private static readonly INACTIVITY_MS = 60_000;
435
-
436
- constructor(
437
- private discovery: McpDiscoverySummary,
438
- private callbacks: SetupPanelCallbacks,
439
- private options: SetupPanelOptions,
440
- tui: { requestRender(): void },
441
- private done: () => void,
442
- ) {
443
- this.tui = tui;
444
- this.keys = createPanelKeys(options.keybindings);
445
- this.view = new McpSetupPanelView(() => this.getViewState(), callbacks, createMcpPanelTheme(options.theme));
446
- this.screen = options.mode;
447
- for (const entry of discovery.imports) {
448
- this.selectedImports.add(entry.kind);
449
- }
450
- this.resetInactivityTimeout();
451
- }
452
-
453
- private resetInactivityTimeout(): void {
454
- if (this.inactivityTimeout) clearTimeout(this.inactivityTimeout);
455
- this.inactivityTimeout = setTimeout(() => {
456
- this.cleanup();
457
- this.done();
458
- }, McpSetupPanel.INACTIVITY_MS);
459
- }
460
-
461
- private cleanup(): void {
462
- if (this.inactivityTimeout) {
463
- clearTimeout(this.inactivityTimeout);
464
- this.inactivityTimeout = null;
465
- }
466
- }
467
-
468
- private getActions(): Action[] {
469
- const actions: Action[] = [];
470
- if (this.screen === "empty") {
471
- actions.push({ id: "run-setup", label: "Run setup" });
472
- }
473
- if (this.discovery.imports.length > 0) {
474
- actions.push({ id: "adopt-imports", label: "Adopt detected compatibility imports" });
475
- }
476
- actions.push(
477
- { id: "select-shared-target", label: `${this.sharedConfigTarget === "project" ? "●" : "○"} Add to this project (.mcp.json)`, target: "project" },
478
- { id: "select-shared-target", label: `${this.sharedConfigTarget === "global" ? "●" : "○"} Add globally (~/.config/mcp/mcp.json)`, target: "global" },
479
- );
480
- actions.push({ id: "view-example", label: "View example shared config" });
481
- if (!this.selectedSharedConfigExists()) {
482
- actions.push({ id: "scaffold-shared-config", label: `Scaffold ${this.sharedTargetLabel()}` });
483
- }
484
- actions.push({ id: "show-precedence", label: "Explain config precedence" });
485
- if (this.getDetectedPaths().length > 0) {
486
- actions.push({ id: "open-paths", label: "Open detected config paths" });
487
- }
488
- for (const preset of KNOWN_SERVER_PRESETS) {
489
- actions.push({ id: "add-known-server", label: preset.name, preset });
490
- }
491
- if (!this.discovery.repoPrompt.configured && this.discovery.repoPrompt.executablePath && this.discovery.repoPrompt.targetPath && this.discovery.repoPrompt.entry && this.discovery.repoPrompt.serverName) {
492
- actions.push({ id: "add-repoprompt", label: "Add RepoPrompt to selected shared config" });
493
- }
494
- actions.push({ id: "close", label: "Close" });
495
- return actions;
496
- }
497
-
498
- private getDetectedPaths(): string[] {
499
- const paths = [
500
- ...this.discovery.sources.filter((source) => source.exists).map((source) => source.path),
501
- ...this.discovery.imports.map((entry) => entry.path),
502
- ];
503
- return [...new Set(paths)];
504
- }
505
-
506
- private sharedTargetLabel(): string {
507
- return this.sharedConfigTarget === "project" ? "project .mcp.json" : "global ~/.config/mcp/mcp.json";
508
- }
509
-
510
- private selectedSharedConfigExists(): boolean {
511
- const sourceId = this.sharedConfigTarget === "project" ? "shared-project" : "shared-global";
512
- return this.discovery.sources.some((source) => source.id === sourceId && source.exists);
513
- }
514
-
515
- handleInput(data: string): void {
516
- this.resetInactivityTimeout();
517
- if (!this.busy) this.notice = null;
518
-
519
- if (matchesKey(data, "ctrl+c")) {
520
- this.cleanup();
521
- this.done();
522
- return;
523
- }
524
-
525
- if (matchesKey(data, "escape")) {
526
- if (this.screen === "imports" || this.screen === "paths") {
527
- this.screen = this.discovery.hasAnyConfig ? "setup" : "empty";
528
- this.tui.requestRender();
529
- return;
530
- }
531
- this.cleanup();
532
- this.done();
533
- return;
534
- }
535
-
536
- if (this.busy) return;
537
-
538
- if (this.screen === "imports") {
539
- this.handleImportsInput(data);
540
- return;
541
- }
542
- if (this.screen === "paths") {
543
- this.handlePathsInput(data);
544
- return;
545
- }
546
-
547
- const actions = this.getActions();
548
- if (this.keys.selectUp(data)) {
549
- this.actionCursor = Math.max(0, this.actionCursor - 1);
550
- this.tui.requestRender();
551
- return;
552
- }
553
- if (this.keys.selectDown(data)) {
554
- this.actionCursor = Math.min(actions.length - 1, this.actionCursor + 1);
555
- this.tui.requestRender();
556
- return;
557
- }
558
- if (this.keys.selectConfirm(data)) {
559
- const selected = actions[this.actionCursor];
560
- if (selected) void this.runAction(selected);
561
- }
562
- }
563
-
564
- private handleImportsInput(data: string): void {
565
- const imports = this.discovery.imports;
566
- if (this.keys.selectUp(data)) {
567
- this.importCursor = Math.max(0, this.importCursor - 1);
568
- this.tui.requestRender();
569
- return;
570
- }
571
- if (this.keys.selectDown(data)) {
572
- this.importCursor = Math.min(imports.length - 1, this.importCursor + 1);
573
- this.tui.requestRender();
574
- return;
575
- }
576
- if (matchesKey(data, "space")) {
577
- const current = imports[this.importCursor];
578
- if (!current) return;
579
- if (this.selectedImports.has(current.kind)) {
580
- this.selectedImports.delete(current.kind);
581
- } else {
582
- this.selectedImports.add(current.kind);
583
- }
584
- this.tui.requestRender();
585
- return;
586
- }
587
- if (this.keys.selectConfirm(data)) {
588
- void this.applySelectedImports();
589
- }
590
- }
591
-
592
- private handlePathsInput(data: string): void {
593
- const paths = this.getDetectedPaths();
594
- if (this.keys.selectUp(data)) {
595
- this.pathCursor = Math.max(0, this.pathCursor - 1);
596
- this.tui.requestRender();
597
- return;
598
- }
599
- if (this.keys.selectDown(data)) {
600
- this.pathCursor = Math.min(paths.length - 1, this.pathCursor + 1);
601
- this.tui.requestRender();
602
- return;
603
- }
604
- if (this.keys.selectConfirm(data)) {
605
- const selected = paths[this.pathCursor];
606
- if (!selected) return;
607
- void this.runBusy(async () => {
608
- await this.callbacks.openPath(selected);
609
- this.notice = { text: `Opened ${selected}`, tone: "success" };
610
- });
611
- }
612
- }
613
-
614
- private async runAction(action: Action): Promise<void> {
615
- if (action.id === "run-setup") {
616
- this.screen = "setup";
617
- this.actionCursor = 0;
618
- this.tui.requestRender();
619
- return;
620
- }
621
- if (action.id === "adopt-imports") {
622
- this.screen = "imports";
623
- this.importCursor = 0;
624
- this.tui.requestRender();
625
- return;
626
- }
627
- if (action.id === "open-paths") {
628
- this.screen = "paths";
629
- this.pathCursor = 0;
630
- this.tui.requestRender();
631
- return;
632
- }
633
- if (action.id === "select-shared-target" && action.target) {
634
- this.sharedConfigTarget = action.target;
635
- this.notice = { text: `New shared servers will be written to ${this.sharedTargetLabel()}.`, tone: "muted" };
636
- this.tui.requestRender();
637
- return;
638
- }
639
- if (action.id === "scaffold-shared-config") {
640
- await this.runBusy(async () => {
641
- const result = await this.callbacks.scaffoldConfig(this.sharedConfigTarget);
642
- this.callbacks.markSetupCompleted();
643
- this.notice = { text: `Wrote starter config to ${result.path}. Pi will reload after this panel closes.`, tone: "success" };
644
- });
645
- return;
646
- }
647
- if (action.id === "add-repoprompt") {
648
- await this.runBusy(async () => {
649
- const result = await this.callbacks.addRepoPrompt(this.sharedConfigTarget);
650
- this.callbacks.markSetupCompleted();
651
- this.notice = { text: `Added ${result.serverName} to ${result.path}. Pi will reload after this panel closes.`, tone: "success" };
652
- });
653
- return;
654
- }
655
- if (action.id === "add-known-server" && action.preset) {
656
- const preset = action.preset;
657
- await this.runBusy(async () => {
658
- const result = await this.callbacks.addKnownServer(preset, this.sharedConfigTarget);
659
- this.callbacks.markSetupCompleted();
660
- this.notice = { text: `Added ${result.serverName} to ${result.path}. Pi will reload after this panel closes.`, tone: "success" };
661
- });
662
- return;
663
- }
664
- if (action.id === "close") {
665
- this.cleanup();
666
- this.done();
667
- return;
668
- }
669
-
670
- this.notice = { text: "Review the details below. Press Enter on an action with a side effect to apply it.", tone: "muted" };
671
- this.tui.requestRender();
672
- }
673
-
674
- private async applySelectedImports(): Promise<void> {
675
- const selected = this.discovery.imports.filter((entry) => this.selectedImports.has(entry.kind)).map((entry) => entry.kind);
676
- if (selected.length === 0) {
677
- this.notice = { text: "Select at least one compatibility import first.", tone: "warning" };
678
- this.tui.requestRender();
679
- return;
680
- }
681
-
682
- await this.runBusy(async () => {
683
- const result = await this.callbacks.adoptImports(selected);
684
- this.callbacks.markSetupCompleted();
685
- this.notice = result.added.length > 0
686
- ? { text: `Added ${result.added.join(", ")} to ${result.path}. Pi will reload after this panel closes.`, tone: "success" }
687
- : { text: `No changes needed in ${result.path}.`, tone: "muted" };
688
- this.screen = this.discovery.hasAnyConfig ? "setup" : "empty";
689
- this.actionCursor = 0;
690
- });
691
- }
692
-
693
- private async runBusy(fn: () => Promise<void>): Promise<void> {
694
- this.busy = true;
695
- this.notice = { text: "Working...", tone: "muted" };
696
- this.tui.requestRender();
697
- try {
698
- await fn();
699
- } catch (error) {
700
- this.notice = {
701
- text: error instanceof Error ? error.message : String(error),
702
- tone: "warning",
703
- };
704
- } finally {
705
- this.busy = false;
706
- this.tui.requestRender();
707
- }
708
- }
709
-
710
- private getViewState(): McpSetupPanelViewState {
711
- return {
712
- screen: this.screen,
713
- actionCursor: this.actionCursor,
714
- importCursor: this.importCursor,
715
- pathCursor: this.pathCursor,
716
- sharedConfigTarget: this.sharedConfigTarget,
717
- selectedImports: this.selectedImports,
718
- notice: this.notice,
719
- onboardingState: this.options.onboardingState,
720
- discovery: this.discovery,
721
- actions: this.getActions(),
722
- detectedPaths: this.getDetectedPaths(),
723
- };
724
- }
725
-
726
- render(width: number): string[] {
727
- return this.view.render(width);
728
- }
729
-
730
- invalidate(): void {
731
- this.view.invalidate();
732
- }
733
-
734
- dispose(): void {
735
- this.cleanup();
736
- }
737
- }
738
-
739
- export function createMcpSetupPanel(
740
- discovery: McpDiscoverySummary,
741
- callbacks: SetupPanelCallbacks,
742
- options: SetupPanelOptions,
743
- tui: { requestRender(): void },
744
- done: () => void,
745
- ): McpSetupPanel & { dispose(): void } {
746
- return new McpSetupPanel(discovery, callbacks, options, tui, done);
747
- }