@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,1361 +0,0 @@
1
- // config.ts - Config loading with import support
2
- import { chmodSync, existsSync, readFileSync, realpathSync, rmSync, statSync, writeFileSync, mkdirSync, renameSync } from "node:fs";
3
- import { homedir } from "node:os";
4
- import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
5
- import { parse as parseToml } from "smol-toml";
6
- import stripJsonComments from "strip-json-comments";
7
- import { getAgentPath, getConfigDirName } from "./agent-dir.js";
8
- import { getAgentPluginSummaries, loadAgentPluginConfigs } from "./agent-plugin-loader.js";
9
- import { cloneBuiltInAgentPluginEntry, isBuiltInAgentPlugin, mergeBuiltInAgentPluginEntries } from "./agent-plugin-provenance.js";
10
- import { loadClaudePluginBundles } from "./claude-plugin-loader.js";
11
- import { loadPackageMcpConfigs } from "./package-mcp-loader.js";
12
- import { validateJevSettings } from "./jev-client.js";
13
- import { formatServerNamespace, isServerDisabled } from "./types.js";
14
- import { parseJsonWithComments, toStringRecord } from "./utils.js";
15
- const GENERIC_GLOBAL_CONFIG_PATH = join(homedir(), ".config", "mcp", "mcp.json");
16
- const AGENTS_GLOBAL_CONFIG_PATHS = [
17
- join(homedir(), ".agents", "mcp.json"),
18
- join(homedir(), ".agents", "mcp", "mcp.json"),
19
- ];
20
- const PROJECT_CONFIG_NAME = ".mcp.json";
21
- const PROJECT_PI_CONFIG_NAME = "mcp.json";
22
- const REPOPROMPT_BINARY_CANDIDATES = [
23
- join(homedir(), "RepoPrompt", "repoprompt_cli"),
24
- "/Applications/Repo Prompt.app/Contents/MacOS/repoprompt-mcp",
25
- ];
26
- export const KNOWN_SERVER_PRESETS = [
27
- {
28
- id: "deepwiki",
29
- name: "DeepWiki",
30
- summary: "Ask questions about public GitHub repositories.",
31
- entry: { url: "https://mcp.deepwiki.com/mcp", protocolVersion: "auto" },
32
- },
33
- {
34
- id: "context7",
35
- name: "Context7",
36
- summary: "Look up current library documentation and examples.",
37
- entry: { url: "https://mcp.context7.com/mcp", protocolVersion: "auto" },
38
- },
39
- {
40
- id: "parallel-search",
41
- name: "Parallel Search",
42
- summary: "Search the web and fetch pages without an API key.",
43
- entry: {
44
- url: "https://search.parallel.ai/mcp",
45
- protocolVersion: "auto",
46
- directTools: true,
47
- },
48
- },
49
- {
50
- id: "notion",
51
- name: "Notion",
52
- summary: "Search and work with your Notion workspace.",
53
- entry: { url: "https://mcp.notion.com/mcp", auth: "oauth", protocolVersion: "auto" },
54
- },
55
- {
56
- id: "github",
57
- name: "GitHub",
58
- summary: "Work with GitHub through your Copilot account.",
59
- entry: { url: "https://api.githubcopilot.com/mcp", auth: "oauth", protocolVersion: "auto" },
60
- },
61
- {
62
- id: "chrome-devtools",
63
- name: "Chrome DevTools",
64
- summary: "Inspect and automate a local Chrome browser.",
65
- entry: { command: "npx", args: ["-y", "chrome-devtools-mcp@1.6.0"] },
66
- },
67
- ];
68
- const IMPORT_PATHS = {
69
- cursor: [join(homedir(), ".cursor", "mcp.json")],
70
- "claude-code": [
71
- join(homedir(), ".claude", "mcp.json"),
72
- join(homedir(), ".claude.json"),
73
- join(homedir(), ".claude", "claude_desktop_config.json"),
74
- ],
75
- "claude-desktop": [join(homedir(), "Library", "Application Support", "Claude", "claude_desktop_config.json")],
76
- codex: [
77
- join(homedir(), ".codex", "config.toml"),
78
- join(homedir(), ".codex", "config.json"),
79
- ],
80
- opencode: [
81
- join(homedir(), ".config", "opencode", "opencode.json"),
82
- "./opencode.json",
83
- ],
84
- windsurf: [join(homedir(), ".windsurf", "mcp.json")],
85
- vscode: [".vscode/mcp.json"],
86
- };
87
- export function getPiGlobalConfigPath(overridePath) {
88
- return overridePath ? resolve(overridePath) : getAgentPath("mcp.json");
89
- }
90
- export function getGenericGlobalConfigPath() {
91
- return GENERIC_GLOBAL_CONFIG_PATH;
92
- }
93
- export function getProjectConfigPath(cwd = process.cwd()) {
94
- return resolve(cwd, PROJECT_CONFIG_NAME);
95
- }
96
- export function getProjectPiConfigPath(cwd = process.cwd()) {
97
- return resolve(cwd, getConfigDirName(), PROJECT_PI_CONFIG_NAME);
98
- }
99
- export function getSharedConfigPath(target, cwd = process.cwd()) {
100
- return target === "project" ? getProjectConfigPath(cwd) : getGenericGlobalConfigPath();
101
- }
102
- export function getConfigDiscoveryPaths(overridePath, cwd = process.cwd()) {
103
- return getConfigSources(overridePath, cwd).map((source) => ({
104
- label: source.label,
105
- path: source.readPath,
106
- exists: existsSync(source.readPath),
107
- }));
108
- }
109
- export function findAvailableImportConfigs(cwd = process.cwd()) {
110
- if (isExclusiveConfigMode())
111
- return [];
112
- const discovered = [];
113
- for (const importKind of Object.keys(IMPORT_PATHS)) {
114
- const importPath = resolveImportPath(importKind, cwd);
115
- if (importPath) {
116
- discovered.push({ kind: importKind, path: importPath });
117
- }
118
- }
119
- return discovered;
120
- }
121
- function getConfigSourceSummaries(sourceSpecs) {
122
- return sourceSpecs.map((source) => {
123
- const loaded = readValidatedConfig(source.readPath, `MCP config from ${source.readPath}`);
124
- return {
125
- id: source.id,
126
- label: source.label,
127
- path: source.readPath,
128
- exists: existsSync(source.readPath),
129
- scope: source.scope,
130
- kind: source.shared ? "shared" : "pi",
131
- serverCount: loaded ? Object.keys(loaded.mcpServers).length : 0,
132
- };
133
- });
134
- }
135
- export function getMcpStandardConfigSummary(overridePath, cwd = process.cwd()) {
136
- const sources = getConfigSourceSummaries(getConfigSources(overridePath, cwd));
137
- return {
138
- sources,
139
- hasSharedServers: sources.some((source) => source.kind === "shared" && source.serverCount > 0),
140
- fingerprint: JSON.stringify({ sources: sources.map((source) => [source.id, source.exists, source.serverCount]) }),
141
- };
142
- }
143
- export function getMcpDiscoverySummary(overridePath, cwd = process.cwd(), options = {}) {
144
- const sourceSpecs = getConfigSources(overridePath, cwd);
145
- const sources = getConfigSourceSummaries(sourceSpecs);
146
- const includeHostConfigs = options.includeHostConfigs !== false;
147
- const importKinds = isExclusiveConfigMode()
148
- ? (readValidatedConfig(getPiGlobalConfigPath(overridePath), "MCP exclusive config")?.imports ?? [])
149
- : Object.keys(IMPORT_PATHS);
150
- const imports = includeHostConfigs
151
- ? importKinds
152
- .map((kind) => {
153
- const imported = loadImportedConfig(kind, cwd, `Failed to inspect imported MCP config from ${kind}:`);
154
- if (!imported)
155
- return null;
156
- return {
157
- kind,
158
- path: imported.path,
159
- serverCount: Object.keys(extractServers(imported.value, kind)).length,
160
- };
161
- })
162
- .filter((value) => value !== null)
163
- : [];
164
- const hostConfigDiscovery = isExclusiveConfigMode()
165
- ? "off"
166
- : getConfiguredHostConfigDiscovery(overridePath, cwd);
167
- const hostConfigs = imports.map((entry) => ({ ...entry, active: hostConfigDiscovery === "on" }));
168
- const settings = getMergedSettings(overridePath, cwd);
169
- const agentPlugins = isExclusiveConfigMode()
170
- ? []
171
- : getAgentPluginSummaries(settings?.agentPluginPaths, cwd);
172
- const totalServerCount = sources.reduce((sum, source) => sum + source.serverCount, 0) + agentPlugins.reduce((sum, plugin) => sum + plugin.serverCount, 0);
173
- const hasSharedServers = sources.some((source) => source.kind === "shared" && source.serverCount > 0) || agentPlugins.some(plugin => plugin.serverCount > 0);
174
- const hasPiOwnedServers = sources.some((source) => source.kind === "pi" && source.serverCount > 0);
175
- const hasAnyDetectedPaths = sources.some((source) => source.exists) || imports.length > 0 || agentPlugins.length > 0;
176
- const hasAnyConfig = totalServerCount > 0 || imports.some((entry) => entry.serverCount > 0) || hasAnyDetectedPaths;
177
- const summaryWithoutRepoPrompt = {
178
- sources,
179
- imports,
180
- hostConfigs,
181
- hostConfigDiscovery,
182
- agentPlugins,
183
- conflicts: getConfigConflicts(sourceSpecs, imports, cwd),
184
- hasAnyConfig,
185
- hasAnyDetectedPaths,
186
- hasSharedServers,
187
- hasPiOwnedServers,
188
- totalServerCount,
189
- };
190
- const fingerprint = JSON.stringify({
191
- sources: sources.map((source) => [source.id, source.exists, source.serverCount]),
192
- imports: imports.map((entry) => [entry.kind, entry.path, entry.serverCount]),
193
- agentPlugins: agentPlugins.map((entry) => [entry.path, entry.name, entry.serverCount]),
194
- hostConfigDiscovery,
195
- conflicts: summaryWithoutRepoPrompt.conflicts,
196
- });
197
- return {
198
- ...summaryWithoutRepoPrompt,
199
- fingerprint,
200
- repoPrompt: detectRepoPrompt(summaryWithoutRepoPrompt, cwd),
201
- };
202
- }
203
- export function cloneMcpConfig(config) {
204
- const cloned = structuredClone(config);
205
- for (const [name, source] of Object.entries(config.mcpServers)) {
206
- const builtInClone = cloneBuiltInAgentPluginEntry(source);
207
- if (builtInClone)
208
- cloned.mcpServers[name] = builtInClone;
209
- }
210
- return cloned;
211
- }
212
- export function loadMcpConfig(overridePath, cwd = process.cwd()) {
213
- const sourceSpecs = getConfigSources(overridePath, cwd);
214
- const hostConfigDiscovery = getConfiguredHostConfigDiscovery(overridePath, cwd);
215
- // Host files are a lower-precedence fallback. This ordering means an opt-in
216
- // discovery cannot override a shared or Pi-owned definition, and all normal
217
- // URL-bound credential stripping remains in mergeServerMaps.
218
- let config = !isExclusiveConfigMode() && hostConfigDiscovery === "on"
219
- ? loadDiscoveredHostConfigs(cwd)
220
- : { mcpServers: {} };
221
- for (const source of sourceSpecs) {
222
- const loaded = readValidatedConfig(source.readPath, `MCP config from ${source.readPath}`);
223
- if (!loaded)
224
- continue;
225
- config = mergeConfigs(config, expandImports(loaded, cwd));
226
- }
227
- if (isExclusiveConfigMode())
228
- return resolveConfiguredClaudePluginMcp(config, cwd);
229
- const packageConfig = loadPackageMcpConfigs(cwd);
230
- const pluginConfig = loadAgentPluginConfigs(config.settings?.agentPluginPaths, cwd);
231
- const packageServers = Object.fromEntries(Object.entries(packageConfig.mcpServers).filter(([name]) => !Object.hasOwn(pluginConfig.mcpServers, name)));
232
- const higherPrecedenceConfig = mergeConfigs({ mcpServers: packageServers }, mergeConfigs(pluginConfig, config));
233
- return mergeClaudePluginMcpDefaults(config.claudePlugins, higherPrecedenceConfig, cwd);
234
- }
235
- export function resolveConfiguredClaudePluginMcp(config, cwd = process.cwd()) {
236
- return mergeClaudePluginMcpDefaults(config.claudePlugins, config, cwd);
237
- }
238
- export function discoverConfiguredClaudePluginSkills(config, cwd = process.cwd()) {
239
- return loadClaudePluginBundles(config.claudePlugins, cwd, validateConfig, { mcp: false, skills: true }).skillPaths;
240
- }
241
- function mergeClaudePluginMcpDefaults(plugins, higherPrecedenceConfig, cwd) {
242
- const pluginServers = loadClaudePluginBundles(plugins, cwd, validateConfig, { mcp: true, skills: false }).mcpServers;
243
- const higherNamesByNamespace = new Map(Object.keys(higherPrecedenceConfig.mcpServers).map(name => [formatServerNamespace(name), name]));
244
- const defaults = Object.fromEntries(Object.entries(pluginServers).filter(([name]) => {
245
- const higherName = higherNamesByNamespace.get(formatServerNamespace(name));
246
- if (!higherName || higherName === name)
247
- return true;
248
- console.warn(`Claude plugin MCP server "${name}" is shadowed by higher-precedence server "${higherName}" because both normalize to the same namespace`);
249
- return false;
250
- }));
251
- return applySettingDefaults(mergeConfigs({ mcpServers: defaults }, higherPrecedenceConfig));
252
- }
253
- function applySettingDefaults(config) {
254
- const exposeResources = config.settings?.exposeResources;
255
- if (exposeResources === undefined)
256
- return config;
257
- const mcpServers = Object.fromEntries(Object.entries(config.mcpServers)
258
- .map(([name, entry]) => [name, entry.exposeResources === undefined ? { ...entry, exposeResources } : entry]));
259
- return { ...config, mcpServers };
260
- }
261
- function getMergedSettings(overridePath, cwd = process.cwd()) {
262
- let settings;
263
- for (const source of getConfigSources(overridePath, cwd)) {
264
- const loaded = readValidatedConfig(source.readPath, `MCP config from ${source.readPath}`);
265
- if (loaded?.settings)
266
- settings = { ...settings, ...loaded.settings };
267
- }
268
- return settings;
269
- }
270
- function getConfiguredHostConfigDiscovery(overridePath, cwd = process.cwd()) {
271
- let configured = "off";
272
- const settings = getMergedSettings(overridePath, cwd);
273
- const value = settings?.hostConfigDiscovery;
274
- if (value === "off" || value === "prompt" || value === "on")
275
- configured = value;
276
- return configured;
277
- }
278
- function loadDiscoveredHostConfigs(cwd) {
279
- let config = { mcpServers: {} };
280
- for (const importKind of Object.keys(IMPORT_PATHS)) {
281
- const imported = loadImportedConfig(importKind, cwd, `Failed to discover imported MCP config from ${importKind}:`);
282
- if (!imported)
283
- continue;
284
- config = mergeConfigs(config, {
285
- mcpServers: extractServers(imported.value, importKind),
286
- });
287
- }
288
- return config;
289
- }
290
- function getConfigConflicts(sourceSpecs, imports, cwd) {
291
- const seen = new Map();
292
- const record = (name, source) => {
293
- const entries = seen.get(name) ?? [];
294
- if (!entries.some((entry) => entry.kind === source.kind && entry.path === source.path))
295
- entries.push(source);
296
- seen.set(name, entries);
297
- };
298
- // Host candidates are listed first because, when enabled, they are the
299
- // lowest-precedence fallback. The fixed IMPORT_PATHS order is deterministic.
300
- for (const entry of imports) {
301
- const imported = loadImportedConfig(entry.kind, cwd, `Failed to inspect imported MCP config from ${entry.kind}:`);
302
- if (!imported)
303
- continue;
304
- for (const name of Object.keys(extractServers(imported.value, entry.kind))) {
305
- record(name, { kind: "host", path: imported.path });
306
- }
307
- }
308
- for (const source of sourceSpecs) {
309
- const loaded = readValidatedConfig(source.readPath, `MCP config from ${source.readPath}`);
310
- if (!loaded)
311
- continue;
312
- if (loaded.imports?.length) {
313
- for (const importKind of loaded.imports) {
314
- const imported = loadImportedConfig(importKind, cwd, `Failed to inspect imported MCP config from ${importKind}:`);
315
- if (!imported)
316
- continue;
317
- for (const name of Object.keys(extractServers(imported.value, importKind))) {
318
- record(name, { kind: "host", path: imported.path });
319
- }
320
- }
321
- }
322
- for (const name of Object.keys(loaded.mcpServers)) {
323
- record(name, {
324
- kind: source.shared ? "shared" : "pi",
325
- path: source.readPath,
326
- });
327
- }
328
- }
329
- return [...seen.entries()]
330
- .filter(([, sources]) => sources.length > 1)
331
- .map(([serverName, sources]) => ({ serverName, sources, winner: sources[sources.length - 1] }))
332
- .sort((left, right) => left.serverName.localeCompare(right.serverName));
333
- }
334
- function getConfigSources(overridePath, cwd = process.cwd()) {
335
- const userPath = getPiGlobalConfigPath(overridePath);
336
- const projectPath = getProjectConfigPath(cwd);
337
- const projectPiPath = getProjectPiConfigPath(cwd);
338
- const sources = [];
339
- if (isExclusiveConfigMode()) {
340
- return [{
341
- id: "pi-global",
342
- label: "Pi exclusive config",
343
- readPath: userPath,
344
- writePath: userPath,
345
- kind: "user",
346
- shared: false,
347
- scope: "global",
348
- }];
349
- }
350
- if (GENERIC_GLOBAL_CONFIG_PATH !== userPath) {
351
- sources.push({
352
- id: "shared-global",
353
- label: "user-global standard MCP",
354
- readPath: GENERIC_GLOBAL_CONFIG_PATH,
355
- writePath: userPath,
356
- kind: "import",
357
- importKind: "global MCP config",
358
- shared: true,
359
- scope: "global",
360
- });
361
- }
362
- for (const [index, agentsPath] of AGENTS_GLOBAL_CONFIG_PATHS.entries()) {
363
- if (agentsPath === userPath || agentsPath === GENERIC_GLOBAL_CONFIG_PATH)
364
- continue;
365
- sources.push({
366
- id: index === 0 ? "agents-global" : "agents-nested-global",
367
- label: index === 0 ? "user-global .agents MCP" : "user-global .agents nested MCP",
368
- readPath: agentsPath,
369
- writePath: userPath,
370
- kind: "import",
371
- importKind: index === 0 ? ".agents MCP config" : ".agents/mcp MCP config",
372
- shared: true,
373
- scope: "global",
374
- });
375
- }
376
- sources.push({
377
- id: "pi-global",
378
- label: "Pi global override",
379
- readPath: userPath,
380
- writePath: userPath,
381
- kind: "user",
382
- shared: false,
383
- scope: "global",
384
- });
385
- // Compare file identities so symlink aliases cannot reload a global source
386
- // at ancestor precedence. Keep original paths for display and writes.
387
- const reservedPaths = new Set([
388
- ...sources.map((source) => getConfigPathIdentity(source.readPath)),
389
- getConfigPathIdentity(projectPath),
390
- getConfigPathIdentity(projectPiPath),
391
- ]);
392
- // Only user-global files (including an explicit override) may opt in to
393
- // ancestor discovery. Project files cannot extend this trust boundary.
394
- const ancestorSources = new Map();
395
- const descriptors = [
396
- { id: "shared-project-ancestor", label: "ancestor standard MCP", path: getProjectConfigPath, shared: true },
397
- { id: "pi-project-ancestor", label: "ancestor Pi override", path: getProjectPiConfigPath, shared: false },
398
- ];
399
- const ancestorRoot = getConfiguredAncestorRoot(sources, cwd);
400
- if (ancestorRoot) {
401
- for (const dir of getAncestorProjectDirs(cwd, ancestorRoot)) {
402
- for (const descriptor of descriptors) {
403
- const path = descriptor.path(dir);
404
- const identity = getConfigPathIdentity(path);
405
- if (reservedPaths.has(identity) || !existsSync(path))
406
- continue;
407
- // Reinsert aliases at their nearest precedence position.
408
- ancestorSources.delete(identity);
409
- ancestorSources.set(identity, {
410
- id: descriptor.id,
411
- label: descriptor.label,
412
- readPath: path,
413
- writePath: path,
414
- kind: "project",
415
- shared: descriptor.shared,
416
- scope: "project",
417
- });
418
- }
419
- }
420
- }
421
- sources.push(...ancestorSources.values());
422
- if (projectPath !== userPath) {
423
- sources.push({
424
- id: "shared-project",
425
- label: "project standard MCP",
426
- readPath: projectPath,
427
- writePath: projectPath,
428
- kind: "project",
429
- shared: true,
430
- scope: "project",
431
- });
432
- }
433
- if (projectPiPath !== userPath && projectPiPath !== projectPath) {
434
- sources.push({
435
- id: "pi-project",
436
- label: "project Pi override",
437
- readPath: projectPiPath,
438
- writePath: projectPiPath,
439
- kind: "project",
440
- shared: false,
441
- scope: "project",
442
- });
443
- }
444
- return sources;
445
- }
446
- function getConfigPathIdentity(path) {
447
- try {
448
- return realpathSync(path);
449
- }
450
- catch {
451
- // Missing or inaccessible paths still participate in lexical deduplication.
452
- return resolve(path);
453
- }
454
- }
455
- function isWithin(base, target) {
456
- const path = relative(base, target);
457
- return path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
458
- }
459
- function getConfiguredAncestorRoot(globalSources, cwd) {
460
- let configured;
461
- for (const source of globalSources) {
462
- const roots = readValidatedConfig(source.readPath, `MCP config from ${source.readPath}`)?.settings?.ancestorConfigRoots;
463
- if (roots !== undefined)
464
- configured = roots;
465
- }
466
- if (configured === undefined || (Array.isArray(configured) && configured.length === 0))
467
- return undefined;
468
- if (!Array.isArray(configured)) {
469
- console.warn("Invalid settings.ancestorConfigRoots: expected an array of paths");
470
- return undefined;
471
- }
472
- const home = getConfigPathIdentity(resolve(homedir()));
473
- const canonicalCwd = getConfigPathIdentity(resolve(cwd));
474
- const valid = [];
475
- for (const entry of configured) {
476
- const expanded = typeof entry === "string" && entry.startsWith("~/")
477
- ? join(homedir(), entry.slice(2))
478
- : entry;
479
- if (typeof expanded !== "string" || !isAbsolute(expanded)) {
480
- console.warn(`Invalid settings.ancestorConfigRoots entry ${JSON.stringify(entry)}: expected an absolute path or ~/...`);
481
- continue;
482
- }
483
- try {
484
- const root = realpathSync(expanded);
485
- if (!statSync(root).isDirectory() || !isWithin(home, root))
486
- throw new Error();
487
- if (isWithin(root, canonicalCwd))
488
- valid.push(root);
489
- }
490
- catch {
491
- console.warn(`Invalid settings.ancestorConfigRoots entry ${JSON.stringify(entry)}: expected an existing directory under HOME`);
492
- }
493
- }
494
- return valid.sort((left, right) => right.length - left.length)[0];
495
- }
496
- function getAncestorProjectDirs(cwd, root) {
497
- const start = getConfigPathIdentity(resolve(cwd));
498
- const dirs = [];
499
- let current = dirname(start);
500
- while (isWithin(root, current)) {
501
- dirs.unshift(current);
502
- if (current === root)
503
- break;
504
- const parent = dirname(current);
505
- if (parent === current)
506
- break;
507
- current = parent;
508
- }
509
- return dirs;
510
- }
511
- function isExclusiveConfigMode() {
512
- return process.env.PI_MCP_CONFIG_MODE?.trim().toLowerCase() === "exclusive";
513
- }
514
- function mergeConfigs(base, next) {
515
- const imports = mergeImports(base.imports, next.imports);
516
- const settings = next.settings ? { ...base.settings, ...next.settings } : base.settings;
517
- const claudePlugins = next.claudePlugins ?? base.claudePlugins;
518
- return {
519
- mcpServers: mergeServerMaps(base.mcpServers, next.mcpServers),
520
- ...(imports !== undefined ? { imports } : {}),
521
- ...(settings !== undefined ? { settings } : {}),
522
- ...(claudePlugins !== undefined ? { claudePlugins } : {}),
523
- };
524
- }
525
- // Credential-bearing fields whose value is bound to a specific server `url`.
526
- // When a higher-precedence config source repoints an existing server at a
527
- // different url, these MUST NOT be inherited from the lower-precedence entry —
528
- // otherwise the original endpoint's credentials would be shipped to the new
529
- // url. See the SECURITY note in mergeServerMaps.
530
- const URL_BOUND_AUTH_FIELDS = ["headers", "bearerToken", "bearerTokenEnv", "bearerTokenStore", "requestHeadersCommand", "caFile"];
531
- function mergeServerMaps(base, next) {
532
- const merged = { ...base };
533
- for (const [name, definition] of Object.entries(next)) {
534
- const existing = merged[name];
535
- // SECURITY (credential/url binding): the merge is per-field, so a
536
- // higher-precedence source that supplies only a new `url` for an existing
537
- // server would otherwise retain the lower-precedence entry's auth material
538
- // (Authorization header, bearer token, OAuth config) and send it to the new
539
- // url — a credential-exfiltration vector when the higher-precedence source
540
- // is less trusted than the one that first defined the server. Bind auth to
541
- // the url that supplied it: when the url changes, drop inherited auth
542
- // material before merging. Auth explicitly re-supplied by `definition` still
543
- // applies (it is spread last). Behaviour is unchanged when the url is
544
- // identical or the override omits `url` (partial overrides still inherit).
545
- let baseEntry = existing ?? {};
546
- if (existing && typeof definition.command === "string") {
547
- baseEntry = { ...existing };
548
- for (const field of [
549
- "url", "headers", "requestHeadersCommand", "caFile", "auth", "bearerToken",
550
- "bearerTokenEnv", "bearerTokenStore", "oauth", "httpTransport", "socket",
551
- ]) {
552
- delete baseEntry[field];
553
- }
554
- }
555
- else if (existing && typeof definition.url === "string") {
556
- baseEntry = { ...existing };
557
- for (const field of [
558
- "command", "args", "env", "cwd", "pluginDataDir", "literalEnv", "inheritEnv", "socket",
559
- ]) {
560
- delete baseEntry[field];
561
- }
562
- }
563
- else if (existing && typeof definition.socket === "string") {
564
- baseEntry = { ...existing };
565
- for (const field of [
566
- "command", "args", "env", "cwd", "pluginDataDir", "literalEnv", "inheritEnv", "url",
567
- "headers", "requestHeadersCommand", "caFile", "auth", "bearerToken", "bearerTokenEnv",
568
- "bearerTokenStore", "oauth", "httpTransport",
569
- ]) {
570
- delete baseEntry[field];
571
- }
572
- }
573
- if (existing && typeof definition.url === "string" && definition.url !== existing.url) {
574
- if (baseEntry === existing)
575
- baseEntry = { ...existing };
576
- for (const field of URL_BOUND_AUTH_FIELDS) {
577
- delete baseEntry[field];
578
- }
579
- if (baseEntry.oauth !== false) {
580
- delete baseEntry.oauth;
581
- }
582
- }
583
- if (existing && Object.hasOwn(definition, "env") && isBuiltInAgentPlugin(existing, "env") && !Object.hasOwn(definition, "literalEnv")) {
584
- if (baseEntry === existing)
585
- baseEntry = { ...existing };
586
- delete baseEntry.literalEnv;
587
- }
588
- merged[name] = mergeBuiltInAgentPluginEntries(baseEntry, definition);
589
- }
590
- return merged;
591
- }
592
- function mergeImports(left, right) {
593
- const merged = [...(left ?? []), ...(right ?? [])];
594
- if (merged.length === 0)
595
- return undefined;
596
- return [...new Set(merged)];
597
- }
598
- function expandImports(config, cwd = process.cwd()) {
599
- if (!config.imports?.length)
600
- return config;
601
- const importedServers = {};
602
- for (const importKind of config.imports) {
603
- const imported = loadImportedConfig(importKind, cwd, `Failed to import MCP config from ${importKind}:`);
604
- if (!imported)
605
- continue;
606
- const servers = extractServers(imported.value, importKind);
607
- for (const [name, definition] of Object.entries(servers)) {
608
- if (!importedServers[name]) {
609
- importedServers[name] = definition;
610
- }
611
- }
612
- }
613
- return {
614
- imports: config.imports,
615
- ...(config.settings !== undefined ? { settings: config.settings } : {}),
616
- ...(config.claudePlugins !== undefined ? { claudePlugins: config.claudePlugins } : {}),
617
- mcpServers: mergeServerMaps(importedServers, config.mcpServers),
618
- };
619
- }
620
- function resolveImportCandidates(importKind, cwd) {
621
- return (IMPORT_PATHS[importKind] ?? []).map((candidate) => {
622
- if (importKind === "opencode" && candidate === "./opencode.json") {
623
- const start = resolve(cwd);
624
- let gitRoot;
625
- let current = start;
626
- while (true) {
627
- if (existsSync(join(current, ".git"))) {
628
- gitRoot = current;
629
- break;
630
- }
631
- const parent = dirname(current);
632
- if (parent === current)
633
- break;
634
- current = parent;
635
- }
636
- if (!gitRoot)
637
- return join(start, "opencode.json");
638
- current = start;
639
- while (true) {
640
- const projectConfig = join(current, "opencode.json");
641
- if (existsSync(projectConfig) || current === gitRoot)
642
- return projectConfig;
643
- current = dirname(current);
644
- }
645
- }
646
- return candidate.startsWith(".") ? resolve(cwd, candidate) : candidate;
647
- });
648
- }
649
- function readImportedConfig(path) {
650
- const raw = readFileSync(path, "utf-8");
651
- return path.endsWith(".toml") ? parseToml(raw) : parseJsonWithComments(raw);
652
- }
653
- function loadImportedConfig(importKind, cwd, warningPrefix) {
654
- if (importKind === "opencode") {
655
- let merged = {};
656
- let highestPrecedencePath;
657
- for (const path of resolveImportCandidates(importKind, cwd)) {
658
- if (!existsSync(path))
659
- continue;
660
- try {
661
- const value = readImportedConfig(path);
662
- if (value && typeof value === "object" && !Array.isArray(value)) {
663
- const imported = value;
664
- const mcp = isRecord(imported.mcp) ? imported.mcp : {};
665
- // OpenCode v2 nests definitions under mcp.servers; normalize before
666
- // merging so project overrides retain the existing merge semantics.
667
- const entries = isRecord(mcp.servers)
668
- ? { ...Object.fromEntries(Object.entries(mcp).filter(([name]) => name !== "servers" && name !== "timeout")), ...mcp.servers }
669
- : mcp;
670
- const normalized = Object.fromEntries(Object.entries(entries).map(([name, entry]) => {
671
- if (!isRecord(entry) || !isRecord(entry.oauth))
672
- return [name, entry];
673
- const { client_id, client_secret, auth_server_metadata_url, ...oauth } = entry.oauth;
674
- return [name, {
675
- ...entry,
676
- oauth: {
677
- ...oauth,
678
- ...(client_id !== undefined ? { clientId: client_id } : {}),
679
- ...(client_secret !== undefined ? { clientSecret: client_secret } : {}),
680
- ...(auth_server_metadata_url !== undefined ? { authServerMetadataUrl: auth_server_metadata_url } : {}),
681
- },
682
- }];
683
- }));
684
- merged = mergeOpenCodeConfigs(merged, { ...imported, mcp: normalized });
685
- highestPrecedencePath = path;
686
- }
687
- }
688
- catch (error) {
689
- console.warn(warningPrefix, error);
690
- }
691
- }
692
- return highestPrecedencePath ? { path: highestPrecedencePath, value: merged } : null;
693
- }
694
- for (const path of resolveImportCandidates(importKind, cwd)) {
695
- if (!existsSync(path))
696
- continue;
697
- try {
698
- return { path, value: readImportedConfig(path) };
699
- }
700
- catch (error) {
701
- console.warn(warningPrefix, error);
702
- }
703
- }
704
- return null;
705
- }
706
- function resolveImportPath(importKind, cwd = process.cwd()) {
707
- return loadImportedConfig(importKind, cwd, `Failed to discover imported MCP config from ${importKind}:`)?.path ?? null;
708
- }
709
- function readValidatedConfig(path, label) {
710
- if (!existsSync(path))
711
- return null;
712
- try {
713
- const text = readFileSync(path, "utf-8");
714
- if (stripJsonComments(text, { trailingCommas: true }).trim() === "")
715
- return null;
716
- return validateConfig(parseJsonWithComments(text));
717
- }
718
- catch (error) {
719
- console.warn(`Failed to load ${label}:`, error);
720
- return null;
721
- }
722
- }
723
- function validateConfig(raw) {
724
- if (!isRecord(raw)) {
725
- return { mcpServers: {} };
726
- }
727
- return {
728
- mcpServers: toServerEntries(raw.mcpServers ?? raw["mcp-servers"]),
729
- ...(Array.isArray(raw.imports) ? { imports: raw.imports } : {}),
730
- ...(raw.settings !== undefined ? { settings: parseSettings(raw.settings) } : {}),
731
- ...(raw.claudePlugins !== undefined ? { claudePlugins: parseClaudePlugins(raw.claudePlugins) } : {}),
732
- };
733
- }
734
- function parseSettings(value) {
735
- if (!isRecord(value))
736
- throw new Error("settings must be an object");
737
- const settings = { ...value };
738
- if (value.jev !== undefined) {
739
- validateJevSettings(value.jev);
740
- settings.jev = value.jev;
741
- }
742
- return settings;
743
- }
744
- function parseClaudePlugins(value) {
745
- if (!Array.isArray(value)) {
746
- console.warn("Invalid claudePlugins config: expected an array");
747
- return [];
748
- }
749
- const plugins = [];
750
- for (const [index, entry] of value.entries()) {
751
- if (!isRecord(entry) || typeof entry.path !== "string" || entry.path.trim().length === 0) {
752
- console.warn(`Invalid claudePlugins[${index}]: expected an object with a non-empty path`);
753
- continue;
754
- }
755
- if ((entry.mcp !== undefined && typeof entry.mcp !== "boolean") || (entry.skills !== undefined && typeof entry.skills !== "boolean")) {
756
- console.warn(`Invalid claudePlugins[${index}] for ${entry.path}: mcp and skills must be booleans`);
757
- continue;
758
- }
759
- if (entry.mcp !== true && entry.skills !== true) {
760
- console.warn(`Invalid claudePlugins[${index}] for ${entry.path}: enable mcp, skills, or both`);
761
- continue;
762
- }
763
- plugins.push({
764
- path: entry.path,
765
- ...(entry.mcp !== undefined ? { mcp: entry.mcp } : {}),
766
- ...(entry.skills !== undefined ? { skills: entry.skills } : {}),
767
- });
768
- }
769
- return plugins;
770
- }
771
- function toServerEntries(servers) {
772
- if (!isRecord(servers))
773
- return {};
774
- const entries = {};
775
- for (const [name, entry] of Object.entries(servers)) {
776
- if (isServerEntry(entry))
777
- entries[name] = entry;
778
- }
779
- return entries;
780
- }
781
- function isServerEntry(value) {
782
- return isRecord(value);
783
- }
784
- function isRecord(value) {
785
- return typeof value === "object" && value !== null && !Array.isArray(value);
786
- }
787
- function mergeOpenCodeConfigs(base, next) {
788
- const baseMcp = base.mcp;
789
- const nextMcp = next.mcp;
790
- const mergedMcp = {
791
- ...(baseMcp && typeof baseMcp === "object" && !Array.isArray(baseMcp) ? baseMcp : {}),
792
- };
793
- if (nextMcp && typeof nextMcp === "object" && !Array.isArray(nextMcp)) {
794
- for (const [name, nextEntry] of Object.entries(nextMcp)) {
795
- const baseEntry = mergedMcp[name];
796
- if (baseEntry && typeof baseEntry === "object" && !Array.isArray(baseEntry)
797
- && nextEntry && typeof nextEntry === "object" && !Array.isArray(nextEntry)) {
798
- const safeBase = { ...baseEntry };
799
- const override = nextEntry;
800
- if (typeof override.type === "string" && override.type !== safeBase.type) {
801
- for (const field of ["command", "environment", "cwd", "url", "headers", "oauth"])
802
- delete safeBase[field];
803
- }
804
- if (typeof override.url === "string" && override.url !== safeBase.url) {
805
- delete safeBase.headers;
806
- delete safeBase.oauth;
807
- }
808
- if (Array.isArray(override.command)) {
809
- const baseCommand = safeBase.command;
810
- const commandChanged = !Array.isArray(baseCommand)
811
- || override.command.length !== baseCommand.length
812
- || override.command.some((value, index) => value !== baseCommand[index]);
813
- if (commandChanged) {
814
- delete safeBase.environment;
815
- delete safeBase.cwd;
816
- }
817
- }
818
- const mergedEntry = { ...safeBase, ...override };
819
- for (const field of ["environment", "headers", "oauth"]) {
820
- const baseField = safeBase[field];
821
- const nextField = override[field];
822
- if (baseField && typeof baseField === "object" && !Array.isArray(baseField)
823
- && nextField && typeof nextField === "object" && !Array.isArray(nextField)) {
824
- mergedEntry[field] = { ...baseField, ...nextField };
825
- }
826
- }
827
- mergedMcp[name] = mergedEntry;
828
- }
829
- else {
830
- mergedMcp[name] = nextEntry;
831
- }
832
- }
833
- }
834
- return { ...base, ...next, mcp: mergedMcp };
835
- }
836
- function extractServers(config, kind) {
837
- if (!config || typeof config !== "object")
838
- return {};
839
- const obj = config;
840
- let servers;
841
- switch (kind) {
842
- case "claude-desktop":
843
- case "claude-code":
844
- servers = obj.mcpServers;
845
- break;
846
- case "codex":
847
- servers = obj.mcp_servers ?? obj.mcpServers;
848
- break;
849
- case "cursor":
850
- case "windsurf":
851
- case "vscode":
852
- servers = obj.mcpServers ?? obj["mcp-servers"];
853
- break;
854
- case "opencode":
855
- servers = obj.mcp;
856
- break;
857
- default:
858
- return {};
859
- }
860
- if (!servers || typeof servers !== "object" || Array.isArray(servers)) {
861
- return {};
862
- }
863
- const mappedServers = {};
864
- for (const [name, entry] of Object.entries(servers)) {
865
- if (kind === "opencode") {
866
- if (!entry || typeof entry !== "object" || Array.isArray(entry))
867
- continue;
868
- const raw = entry;
869
- if (raw.enabled === false || raw.disabled === true)
870
- continue;
871
- if (raw.type === "local" && Array.isArray(raw.command) && raw.command.length > 0 && raw.command.every((value) => typeof value === "string")) {
872
- const env = toStringRecord(raw.environment);
873
- const command = raw.command[0];
874
- if (command === undefined)
875
- continue;
876
- const mapped = {
877
- command,
878
- args: raw.command.slice(1),
879
- ...(env ? { env } : {}),
880
- ...(typeof raw.cwd === "string" ? { cwd: raw.cwd } : {}),
881
- };
882
- mappedServers[name] = mapped;
883
- continue;
884
- }
885
- if (raw.type === "remote" && typeof raw.url === "string") {
886
- const headers = toStringRecord(raw.headers);
887
- const mapped = {
888
- url: raw.url,
889
- ...(headers ? { headers } : {}),
890
- };
891
- if (raw.oauth === false) {
892
- mapped.oauth = false;
893
- }
894
- else if (raw.oauth && typeof raw.oauth === "object" && !Array.isArray(raw.oauth)) {
895
- const oauth = raw.oauth;
896
- mapped.auth = "oauth";
897
- const clientId = oauth.clientId;
898
- const clientSecret = oauth.clientSecret;
899
- const authServerMetadataUrl = oauth.authServerMetadataUrl;
900
- mapped.oauth = {
901
- ...(typeof clientId === "string" ? { clientId } : {}),
902
- ...(typeof clientSecret === "string" ? { clientSecret } : {}),
903
- ...(typeof oauth.clientMetadataUrl === "string" ? { clientMetadataUrl: oauth.clientMetadataUrl } : {}),
904
- ...(typeof oauth.scope === "string" ? { scope: oauth.scope } : {}),
905
- ...(typeof authServerMetadataUrl === "string" ? { authServerMetadataUrl } : {}),
906
- ...(typeof oauth.skipIssuerMetadataValidation === "boolean"
907
- ? { skipIssuerMetadataValidation: oauth.skipIssuerMetadataValidation }
908
- : {}),
909
- };
910
- }
911
- mappedServers[name] = mapped;
912
- }
913
- continue;
914
- }
915
- if (!isRecord(entry))
916
- continue;
917
- if (kind !== "codex") {
918
- mappedServers[name] = entry;
919
- continue;
920
- }
921
- const mapped = { ...entry };
922
- const bearerTokenEnv = mapped.bearer_token_env_var;
923
- const httpHeaders = mapped.http_headers;
924
- const envHttpHeaders = mapped.env_http_headers;
925
- if (typeof bearerTokenEnv === "string") {
926
- mapped.bearerTokenEnv = bearerTokenEnv;
927
- if (mapped.auth === undefined)
928
- mapped.auth = "bearer";
929
- }
930
- if (httpHeaders && typeof httpHeaders === "object" && !Array.isArray(httpHeaders)) {
931
- mapped.headers = { ...mapped.headers, ...httpHeaders };
932
- }
933
- if (envHttpHeaders && typeof envHttpHeaders === "object" && !Array.isArray(envHttpHeaders)) {
934
- const headers = { ...mapped.headers };
935
- for (const [header, envVar] of Object.entries(envHttpHeaders)) {
936
- if (typeof envVar === "string" && headers[header] === undefined)
937
- headers[header] = `$env:${envVar}`;
938
- }
939
- mapped.headers = headers;
940
- }
941
- delete mapped.bearer_token_env_var;
942
- delete mapped.http_headers;
943
- delete mapped.env_http_headers;
944
- mappedServers[name] = mapped;
945
- }
946
- return mappedServers;
947
- }
948
- function serializeRawConfig(raw) {
949
- return `${JSON.stringify(raw, null, 2)}\n`;
950
- }
951
- function buildUnifiedDiff(beforeText, afterText) {
952
- if (beforeText === afterText)
953
- return "(no changes)";
954
- const before = beforeText.split("\n");
955
- const after = afterText.split("\n");
956
- const rows = before.length;
957
- const cols = after.length;
958
- const lcs = Array.from({ length: rows + 1 }, () => Array(cols + 1).fill(0));
959
- for (let i = rows - 1; i >= 0; i--) {
960
- for (let j = cols - 1; j >= 0; j--) {
961
- const row = lcs[i];
962
- const nextRow = lcs[i + 1];
963
- if (!row || !nextRow)
964
- continue;
965
- row[j] = before[i] === after[j]
966
- ? (nextRow[j + 1] ?? 0) + 1
967
- : Math.max(nextRow[j] ?? 0, row[j + 1] ?? 0);
968
- }
969
- }
970
- const lines = ["--- before", "+++ after"];
971
- let i = 0;
972
- let j = 0;
973
- while (i < rows || j < cols) {
974
- if (i < rows && j < cols && before[i] === after[j]) {
975
- lines.push(` ${before[i]}`);
976
- i++;
977
- j++;
978
- continue;
979
- }
980
- if (j < cols && (i === rows || (lcs[i]?.[j + 1] ?? 0) >= (lcs[i + 1]?.[j] ?? 0))) {
981
- lines.push(`+ ${after[j]}`);
982
- j++;
983
- continue;
984
- }
985
- if (i < rows) {
986
- lines.push(`- ${before[i]}`);
987
- i++;
988
- }
989
- }
990
- return lines.join("\n");
991
- }
992
- function buildConfigWritePreview(filePath, nextRaw) {
993
- const existed = existsSync(filePath);
994
- const beforeRaw = readRawConfigObject(filePath);
995
- const beforeText = existed ? serializeRawConfig(beforeRaw) : "";
996
- const afterText = serializeRawConfig(nextRaw);
997
- return {
998
- path: filePath,
999
- existed,
1000
- changed: beforeText !== afterText,
1001
- beforeText,
1002
- afterText,
1003
- diffText: buildUnifiedDiff(beforeText, afterText),
1004
- };
1005
- }
1006
- function readRawConfigObject(filePath) {
1007
- if (!existsSync(filePath))
1008
- return {};
1009
- try {
1010
- const raw = parseJsonWithComments(readFileSync(filePath, "utf-8"));
1011
- return raw && typeof raw === "object" && !Array.isArray(raw) ? raw : {};
1012
- }
1013
- catch {
1014
- return {};
1015
- }
1016
- }
1017
- function writeConfigText(writePath, text) {
1018
- let mode;
1019
- try {
1020
- writePath = realpathSync(writePath);
1021
- mode = statSync(writePath).mode & 0o777;
1022
- }
1023
- catch { }
1024
- mkdirSync(dirname(writePath), { recursive: true });
1025
- const tmpPath = `${writePath}.${process.pid}.tmp`;
1026
- rmSync(tmpPath, { force: true });
1027
- try {
1028
- writeFileSync(tmpPath, text, mode === undefined ? "utf-8" : { encoding: "utf-8", mode });
1029
- if (mode !== undefined)
1030
- chmodSync(tmpPath, mode);
1031
- renameSync(tmpPath, writePath);
1032
- }
1033
- catch (error) {
1034
- try {
1035
- rmSync(tmpPath, { force: true });
1036
- }
1037
- catch { }
1038
- throw error;
1039
- }
1040
- }
1041
- function writeRawConfigObject(filePath, raw) {
1042
- writeConfigText(filePath, `${JSON.stringify(raw, null, 2)}\n`);
1043
- }
1044
- export function writeSharedConfigText(filePath, text) {
1045
- if (!isRecord(parseJsonWithComments(text)))
1046
- throw new Error("top-level value must be an object");
1047
- writeConfigText(filePath, text);
1048
- }
1049
- export function writeJevSemanticSearchConfig(overridePath, cwd, allowedServers, effectiveJev) {
1050
- const filePath = overridePath ? getPiGlobalConfigPath(overridePath) : getProjectPiConfigPath(cwd);
1051
- let raw = {};
1052
- if (existsSync(filePath)) {
1053
- try {
1054
- const parsed = parseJsonWithComments(readFileSync(filePath, "utf8"));
1055
- if (!isRecord(parsed))
1056
- throw new Error("top-level value must be an object");
1057
- raw = parsed;
1058
- }
1059
- catch (error) {
1060
- throw new Error(`Failed to update Jev settings at ${filePath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
1061
- }
1062
- }
1063
- if (raw.settings !== undefined && !isRecord(raw.settings)) {
1064
- throw new Error(`Failed to update Jev settings at ${filePath}: settings must be an object`);
1065
- }
1066
- const settings = raw.settings;
1067
- const currentJev = settings?.jev;
1068
- if (currentJev !== undefined && currentJev !== false && !isRecord(currentJev)) {
1069
- throw new Error(`Failed to update Jev settings at ${filePath}: settings.jev must be an object or false`);
1070
- }
1071
- const jev = isRecord(effectiveJev) ? effectiveJev : isRecord(currentJev) ? currentJev : {};
1072
- const nextServers = [...new Set(allowedServers)].sort((a, b) => a.localeCompare(b));
1073
- const nextJev = { ...jev, semanticSearch: true, allowedServers: nextServers };
1074
- validateJevSettings(nextJev);
1075
- if (isRecord(currentJev) && JSON.stringify(currentJev) === JSON.stringify(nextJev))
1076
- return { path: filePath, changed: false };
1077
- raw.settings = { ...settings, jev: nextJev };
1078
- writeRawConfigObject(filePath, raw);
1079
- return { path: filePath, changed: true };
1080
- }
1081
- function getServersObject(raw) {
1082
- const existing = raw.mcpServers ?? raw["mcp-servers"] ?? {};
1083
- if (!existing || typeof existing !== "object" || Array.isArray(existing)) {
1084
- return {};
1085
- }
1086
- return existing;
1087
- }
1088
- function setServersObject(raw, servers) {
1089
- delete raw["mcp-servers"];
1090
- raw.mcpServers = servers;
1091
- }
1092
- /**
1093
- * Persist only the disabled field in the project Pi layer. Enabling writes an
1094
- * explicit false only when a lower-precedence source is itself disabled; this
1095
- * writer never copies a server definition or its credentials into the file.
1096
- */
1097
- export function writeProjectServerDisabledOverride(overridePath, cwd, serverName, disabled) {
1098
- const filePath = getProjectPiConfigPath(cwd);
1099
- let raw = {};
1100
- if (existsSync(filePath)) {
1101
- try {
1102
- const parsed = parseJsonWithComments(readFileSync(filePath, "utf-8"));
1103
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
1104
- throw new Error("root value must be an object");
1105
- }
1106
- raw = parsed;
1107
- }
1108
- catch (error) {
1109
- throw new Error(`Failed to read project MCP override at ${filePath}: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
1110
- }
1111
- }
1112
- const serverKey = raw.mcpServers !== undefined ? "mcpServers" : raw["mcp-servers"] !== undefined ? "mcp-servers" : "mcpServers";
1113
- const rawServers = raw[serverKey];
1114
- if (rawServers !== undefined && (!rawServers || typeof rawServers !== "object" || Array.isArray(rawServers))) {
1115
- throw new Error(`Failed to update project MCP override at ${filePath}: ${serverKey} must be an object`);
1116
- }
1117
- const servers = (rawServers ?? {});
1118
- const previous = servers[serverName];
1119
- if (previous !== undefined && (!previous || typeof previous !== "object" || Array.isArray(previous))) {
1120
- throw new Error(`Failed to update project MCP override at ${filePath}: server "${serverName}" must be an object`);
1121
- }
1122
- const existing = previous;
1123
- let next;
1124
- if (disabled) {
1125
- next = { ...existing, disabled: true };
1126
- }
1127
- else {
1128
- next = Object.fromEntries(Object.entries(existing ?? {}).filter(([key]) => key !== "disabled"));
1129
- let lowerConfig = { mcpServers: {} };
1130
- for (const source of getConfigSources(overridePath, cwd)) {
1131
- if (source.readPath === filePath)
1132
- continue;
1133
- const loaded = readValidatedConfig(source.readPath, `MCP config from ${source.readPath}`);
1134
- if (loaded)
1135
- lowerConfig = mergeConfigs(lowerConfig, expandImports(loaded, cwd));
1136
- }
1137
- if (raw.imports !== undefined) {
1138
- if (!Array.isArray(raw.imports) || raw.imports.some((kind) => typeof kind !== "string" || !Object.hasOwn(IMPORT_PATHS, kind))) {
1139
- throw new Error(`Failed to update project MCP override at ${filePath}: imports contains an unsupported config kind`);
1140
- }
1141
- lowerConfig = mergeConfigs(lowerConfig, expandImports({ mcpServers: {}, imports: raw.imports }, cwd));
1142
- }
1143
- if (isServerDisabled(lowerConfig.mcpServers[serverName]))
1144
- next.disabled = false;
1145
- }
1146
- if ((!existing && Object.keys(next).length === 0) || JSON.stringify(existing) === JSON.stringify(next)) {
1147
- return { path: filePath, changed: false };
1148
- }
1149
- if (Object.keys(next).length === 0)
1150
- delete servers[serverName];
1151
- else
1152
- servers[serverName] = next;
1153
- raw[serverKey] = servers;
1154
- writeRawConfigObject(filePath, raw);
1155
- return { path: filePath, changed: true };
1156
- }
1157
- function isRepoPromptServer(name, entry) {
1158
- const normalizedName = name.toLowerCase();
1159
- if (normalizedName.includes("repoprompt") || normalizedName === "rp") {
1160
- return true;
1161
- }
1162
- const command = entry.command?.toLowerCase() ?? "";
1163
- if (command.includes("repoprompt") || command.includes("rp-mcp") || command.endsWith("repoprompt_cli")) {
1164
- return true;
1165
- }
1166
- return (entry.args ?? []).some((arg) => typeof arg === "string" && arg.toLowerCase().includes("repoprompt"));
1167
- }
1168
- function findProjectRoot(cwd = process.cwd()) {
1169
- let current = resolve(cwd);
1170
- while (true) {
1171
- if (existsSync(join(current, ".git"))
1172
- || existsSync(join(current, "package.json"))
1173
- || existsSync(join(current, PROJECT_CONFIG_NAME))
1174
- || existsSync(join(current, ".pi"))) {
1175
- return current;
1176
- }
1177
- const parent = dirname(current);
1178
- if (parent === current)
1179
- return null;
1180
- current = parent;
1181
- }
1182
- }
1183
- function buildRepoPromptEntry(executablePath) {
1184
- return {
1185
- command: executablePath,
1186
- args: [],
1187
- lifecycle: "lazy",
1188
- };
1189
- }
1190
- function detectRepoPrompt(summary, cwd = process.cwd()) {
1191
- for (const source of summary.sources) {
1192
- if (source.kind !== "shared" || source.serverCount === 0)
1193
- continue;
1194
- const config = readValidatedConfig(source.path, `MCP config from ${source.path}`);
1195
- if (!config)
1196
- continue;
1197
- for (const [name, entry] of Object.entries(config.mcpServers)) {
1198
- if (isRepoPromptServer(name, entry)) {
1199
- return { configured: true, configuredPath: source.path };
1200
- }
1201
- }
1202
- }
1203
- const executablePath = REPOPROMPT_BINARY_CANDIDATES.find((candidate) => existsSync(candidate));
1204
- if (!executablePath) {
1205
- return { configured: false };
1206
- }
1207
- const projectRoot = findProjectRoot(cwd);
1208
- const targetPath = projectRoot ? join(projectRoot, PROJECT_CONFIG_NAME) : GENERIC_GLOBAL_CONFIG_PATH;
1209
- return {
1210
- configured: false,
1211
- executablePath,
1212
- targetPath,
1213
- serverName: "repoprompt",
1214
- entry: buildRepoPromptEntry(executablePath),
1215
- };
1216
- }
1217
- export function previewCompatibilityImports(importKinds, overridePath) {
1218
- const targetPath = getPiGlobalConfigPath(overridePath);
1219
- const raw = readRawConfigObject(targetPath);
1220
- const currentImports = Array.isArray(raw.imports) ? raw.imports.filter((value) => typeof value === "string") : [];
1221
- const merged = [...new Set([...currentImports, ...importKinds])];
1222
- const nextRaw = { ...raw, imports: merged };
1223
- setServersObject(nextRaw, getServersObject(nextRaw));
1224
- return buildConfigWritePreview(targetPath, nextRaw);
1225
- }
1226
- export function ensureCompatibilityImports(importKinds, overridePath) {
1227
- const targetPath = getPiGlobalConfigPath(overridePath);
1228
- const raw = readRawConfigObject(targetPath);
1229
- const currentImports = Array.isArray(raw.imports) ? raw.imports.filter((value) => typeof value === "string") : [];
1230
- const merged = [...new Set([...currentImports, ...importKinds])];
1231
- const added = merged.filter((kind) => !currentImports.includes(kind));
1232
- if (added.length === 0) {
1233
- return { path: targetPath, added: [] };
1234
- }
1235
- raw.imports = merged;
1236
- const servers = getServersObject(raw);
1237
- setServersObject(raw, servers);
1238
- writeRawConfigObject(targetPath, raw);
1239
- return { path: targetPath, added };
1240
- }
1241
- export function buildStarterProjectConfig() {
1242
- return {
1243
- mcpServers: {},
1244
- };
1245
- }
1246
- export function previewStarterSharedConfig(target, cwd = process.cwd()) {
1247
- const targetPath = getSharedConfigPath(target, cwd);
1248
- const nextRaw = { mcpServers: buildStarterProjectConfig().mcpServers };
1249
- return buildConfigWritePreview(targetPath, nextRaw);
1250
- }
1251
- export function writeStarterSharedConfig(target, cwd = process.cwd()) {
1252
- const targetPath = getSharedConfigPath(target, cwd);
1253
- const raw = { mcpServers: buildStarterProjectConfig().mcpServers };
1254
- writeRawConfigObject(targetPath, raw);
1255
- return targetPath;
1256
- }
1257
- export function previewStarterProjectConfig(cwd = process.cwd()) {
1258
- return previewStarterSharedConfig("project", cwd);
1259
- }
1260
- export function writeStarterProjectConfig(cwd = process.cwd()) {
1261
- return writeStarterSharedConfig("project", cwd);
1262
- }
1263
- export function previewSharedServerEntry(filePath, serverName, entry) {
1264
- const raw = readRawConfigObject(filePath);
1265
- const nextRaw = { ...raw };
1266
- const servers = getServersObject(nextRaw);
1267
- servers[serverName] = entry;
1268
- setServersObject(nextRaw, servers);
1269
- return buildConfigWritePreview(filePath, nextRaw);
1270
- }
1271
- export function writeSharedServerEntry(filePath, serverName, entry) {
1272
- const raw = readRawConfigObject(filePath);
1273
- const servers = getServersObject(raw);
1274
- servers[serverName] = entry;
1275
- setServersObject(raw, servers);
1276
- writeRawConfigObject(filePath, raw);
1277
- return filePath;
1278
- }
1279
- export function getServerProvenance(overridePath, cwd = process.cwd()) {
1280
- const provenance = new Map();
1281
- const userPath = getPiGlobalConfigPath(overridePath);
1282
- if (getConfiguredHostConfigDiscovery(overridePath, cwd) === "on") {
1283
- for (const importKind of Object.keys(IMPORT_PATHS)) {
1284
- const imported = loadImportedConfig(importKind, cwd, `Failed to inspect imported MCP config from ${importKind}:`);
1285
- if (!imported)
1286
- continue;
1287
- for (const name of Object.keys(extractServers(imported.value, importKind))) {
1288
- // Keep writes inside Pi-owned storage even though the source is external.
1289
- // Later import kinds win in the same deterministic order as loadDiscoveredHostConfigs.
1290
- provenance.set(name, { path: userPath, kind: "import", importKind });
1291
- }
1292
- }
1293
- }
1294
- for (const source of getConfigSources(overridePath, cwd)) {
1295
- const loaded = readValidatedConfig(source.readPath, `MCP config from ${source.readPath}`);
1296
- if (!loaded)
1297
- continue;
1298
- if (loaded.imports?.length) {
1299
- for (const importKind of loaded.imports) {
1300
- const imported = loadImportedConfig(importKind, cwd, `Failed to inspect imported MCP config from ${importKind}:`);
1301
- if (!imported)
1302
- continue;
1303
- const servers = extractServers(imported.value, importKind);
1304
- for (const name of Object.keys(servers)) {
1305
- if (!provenance.has(name)) {
1306
- provenance.set(name, { path: userPath, kind: "import", importKind });
1307
- }
1308
- }
1309
- }
1310
- }
1311
- for (const name of Object.keys(loaded.mcpServers)) {
1312
- provenance.set(name, {
1313
- path: source.writePath,
1314
- kind: source.kind,
1315
- ...(source.importKind !== undefined ? { importKind: source.importKind } : {}),
1316
- });
1317
- }
1318
- }
1319
- return provenance;
1320
- }
1321
- export function writeDirectToolsConfig(changes, provenance, fullConfig) {
1322
- const byPath = new Map();
1323
- for (const [serverName, value] of changes) {
1324
- const prov = provenance.get(serverName);
1325
- if (!prov)
1326
- continue;
1327
- const targetPath = prov.path;
1328
- if (!byPath.has(targetPath))
1329
- byPath.set(targetPath, []);
1330
- byPath.get(targetPath).push({ name: serverName, value, prov });
1331
- }
1332
- for (const [filePath, entries] of byPath) {
1333
- const raw = readRawConfigObject(filePath);
1334
- const servers = getServersObject(raw);
1335
- for (const { name, value, prov } of entries) {
1336
- if (prov.kind === "import") {
1337
- const fullDef = fullConfig.mcpServers[name];
1338
- if (fullDef) {
1339
- servers[name] = { ...fullDef, directTools: value };
1340
- }
1341
- }
1342
- else if (servers[name]) {
1343
- servers[name] = { ...servers[name], directTools: value };
1344
- }
1345
- }
1346
- setServersObject(raw, servers);
1347
- writeRawConfigObject(filePath, raw);
1348
- }
1349
- }
1350
- export function resolveConfiguredOAuthDir(raw, cwd = process.cwd()) {
1351
- if (raw === undefined || raw === null)
1352
- return undefined;
1353
- if (typeof raw !== "string") {
1354
- throw new Error("settings.oauthDir must be a string");
1355
- }
1356
- const trimmed = raw.trim();
1357
- if (!trimmed)
1358
- return undefined;
1359
- return resolve(cwd, trimmed);
1360
- }
1361
- //# sourceMappingURL=config.js.map