@herbertgao/pi-extensions 2026.9.17 → 2026.9.18

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 (266) hide show
  1. package/README.md +14 -15
  2. package/node_modules/@herbertgao/pi-bark/package.json +2 -2
  3. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +4 -1
  4. package/node_modules/@herbertgao/pi-cc-extensions/README.md +4 -1
  5. package/node_modules/@herbertgao/pi-cc-extensions/package.json +75 -75
  6. package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
  7. package/node_modules/@herbertgao/pi-subagents/package.json +7 -7
  8. package/node_modules/@herbertgao/resume-from/package.json +4 -2
  9. package/node_modules/@herbertgao/sol-pi/package.json +6 -6
  10. package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +99 -99
  11. package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
  12. package/node_modules/@tifan/pi-handoff/package.json +1 -1
  13. package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
  14. package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
  15. package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
  16. package/node_modules/@tifan/pi-recap/package.json +1 -1
  17. package/node_modules/@tifan/pi-rename/package.json +1 -1
  18. package/node_modules/pi-antigravity/package.json +2 -2
  19. package/node_modules/pi-lens/package.json +158 -158
  20. package/node_modules/pi-multi-account/package.json +2 -2
  21. package/node_modules/pi-typesafe/README.md +1 -1
  22. package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
  23. package/node_modules/pi-typesafe/dist/auth.js +7 -3
  24. package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
  25. package/node_modules/pi-typesafe/dist/backends.js +95 -1
  26. package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
  27. package/node_modules/pi-typesafe/dist/client.js +12 -9
  28. package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
  29. package/node_modules/pi-typesafe/dist/credentials.js +10 -7
  30. package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
  31. package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
  32. package/node_modules/pi-typesafe/dist/index.js +1 -1
  33. package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
  34. package/node_modules/pi-typesafe/dist/login.js +2 -2
  35. package/node_modules/pi-typesafe/package.json +5 -5
  36. package/node_modules/pi-web-access/package.json +2 -2
  37. package/node_modules/remote-pi/package.json +5 -1
  38. package/package.json +16 -28
  39. package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
  40. package/node_modules/pi-mcp-adapter/LICENSE +0 -21
  41. package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
  42. package/node_modules/pi-mcp-adapter/README.md +0 -1021
  43. package/node_modules/pi-mcp-adapter/abort.ts +0 -34
  44. package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
  45. package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
  46. package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
  47. package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
  48. package/node_modules/pi-mcp-adapter/banner.png +0 -0
  49. package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
  50. package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
  51. package/node_modules/pi-mcp-adapter/cli.js +0 -454
  52. package/node_modules/pi-mcp-adapter/commands.ts +0 -861
  53. package/node_modules/pi-mcp-adapter/config.ts +0 -1565
  54. package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
  55. package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
  56. package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
  57. package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
  58. package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
  59. package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
  60. package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
  61. package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
  62. package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
  63. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
  64. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
  65. package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
  66. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
  67. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
  68. package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
  69. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
  70. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
  71. package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
  72. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
  73. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
  74. package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
  75. package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
  76. package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
  77. package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
  78. package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
  79. package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
  80. package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
  81. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
  82. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
  83. package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
  84. package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
  85. package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
  86. package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
  87. package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
  88. package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
  89. package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
  90. package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
  91. package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
  92. package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
  93. package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
  94. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
  95. package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
  96. package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
  97. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
  98. package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
  99. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
  100. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
  101. package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
  102. package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
  103. package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
  104. package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
  105. package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
  106. package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
  107. package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
  108. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
  109. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
  110. package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
  111. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
  112. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
  113. package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
  114. package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
  115. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
  116. package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
  117. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
  118. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
  119. package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
  120. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
  121. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
  122. package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
  123. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
  124. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
  125. package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
  126. package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
  127. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
  128. package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
  129. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
  130. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
  131. package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
  132. package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
  133. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
  134. package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
  135. package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
  136. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
  137. package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
  138. package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
  139. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
  140. package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
  141. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
  142. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
  143. package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
  144. package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
  145. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
  146. package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
  147. package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
  148. package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
  149. package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
  150. package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
  151. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
  152. package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
  153. package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
  154. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
  155. package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
  156. package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
  157. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
  158. package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
  159. package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
  160. package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
  161. package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
  162. package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
  163. package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
  164. package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
  165. package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
  166. package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
  167. package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
  168. package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
  169. package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
  170. package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
  171. package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
  172. package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
  173. package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
  174. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
  175. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
  176. package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
  177. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
  178. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
  179. package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
  180. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
  181. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
  182. package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
  183. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
  184. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
  185. package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
  186. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
  187. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
  188. package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
  189. package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
  190. package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
  191. package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
  192. package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
  193. package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
  194. package/node_modules/pi-mcp-adapter/errors.ts +0 -364
  195. package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
  196. package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
  197. package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
  198. package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
  199. package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
  200. package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
  201. package/node_modules/pi-mcp-adapter/index.ts +0 -2106
  202. package/node_modules/pi-mcp-adapter/init.ts +0 -721
  203. package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
  204. package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
  205. package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
  206. package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
  207. package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
  208. package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
  209. package/node_modules/pi-mcp-adapter/logger.ts +0 -169
  210. package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
  211. package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
  212. package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
  213. package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
  214. package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
  215. package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
  216. package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
  217. package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
  218. package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
  219. package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
  220. package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
  221. package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
  222. package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
  223. package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
  224. package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
  225. package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
  226. package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
  227. package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
  228. package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
  229. package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
  230. package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
  231. package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
  232. package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
  233. package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
  234. package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
  235. package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
  236. package/node_modules/pi-mcp-adapter/package.json +0 -219
  237. package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
  238. package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
  239. package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
  240. package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
  241. package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
  242. package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
  243. package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
  244. package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
  245. package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
  246. package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
  247. package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
  248. package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
  249. package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
  250. package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
  251. package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
  252. package/node_modules/pi-mcp-adapter/state.ts +0 -71
  253. package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
  254. package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
  255. package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
  256. package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
  257. package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
  258. package/node_modules/pi-mcp-adapter/types.ts +0 -1120
  259. package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
  260. package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
  261. package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
  262. package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
  263. package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
  264. package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
  265. package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
  266. package/node_modules/pi-mcp-adapter/utils.ts +0 -464
@@ -1,193 +0,0 @@
1
- import { spawn } from "node:child_process";
2
-
3
- const DEFAULT_TTL_MS = 5 * 60_000;
4
- const ENV_TTL_MS = "PI_MCP_ADAPTER_BEARER_COMMAND_TTL_MS";
5
- const COMMAND_TIMEOUT_MS = 10_000;
6
- const COMMAND_MAX_OUTPUT_BYTES = 1024 * 1024;
7
- const USE_PROCESS_GROUP = process.platform !== "win32";
8
-
9
- function resolveDefaultTtlMs(): number {
10
- const parsed = Number(process.env[ENV_TTL_MS] || DEFAULT_TTL_MS);
11
- return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : DEFAULT_TTL_MS;
12
- }
13
-
14
- function abortReason(signal: AbortSignal): unknown {
15
- return signal.reason ?? new DOMException("The operation was aborted", "AbortError");
16
- }
17
-
18
- function runCommand(command: string, context: string, signal: AbortSignal): Promise<string> {
19
- return new Promise((resolve, reject) => {
20
- let output = Buffer.alloc(0);
21
- let settled = false;
22
- let terminating = false;
23
- const child = spawn(command.slice(1), {
24
- shell: true,
25
- stdio: ["ignore", "pipe", "ignore"],
26
- windowsHide: true,
27
- detached: USE_PROCESS_GROUP,
28
- });
29
-
30
- const kill = async (): Promise<void> => {
31
- if (child.pid === undefined) return;
32
- if (!USE_PROCESS_GROUP) {
33
- await new Promise<void>((resolveKill, rejectKill) => {
34
- const killer = spawn("taskkill", ["/pid", String(child.pid), "/T", "/F"], {
35
- stdio: "ignore",
36
- windowsHide: true,
37
- });
38
- killer.on("error", () => rejectKill(new Error("Failed to stop bearer token command")));
39
- killer.on("close", code => {
40
- if (code === 0 || code === 128) resolveKill();
41
- else rejectKill(new Error(`Failed to stop bearer token command: taskkill exited with code ${code ?? "unknown"}`));
42
- });
43
- });
44
- return;
45
- }
46
- try {
47
- process.kill(-child.pid, "SIGKILL");
48
- } catch (error) {
49
- if ((error as NodeJS.ErrnoException).code !== "ESRCH") throw error;
50
- }
51
- };
52
- const finish = (error: unknown, token?: string) => {
53
- if (settled) return;
54
- settled = true;
55
- clearTimeout(timer);
56
- signal.removeEventListener("abort", onAbort);
57
- if (error !== undefined) reject(error);
58
- else resolve(token!);
59
- };
60
- const terminate = async (error: unknown) => {
61
- if (settled || terminating) return;
62
- terminating = true;
63
- clearTimeout(timer);
64
- signal.removeEventListener("abort", onAbort);
65
- try {
66
- await kill();
67
- finish(error);
68
- } catch (cleanupError) {
69
- finish(cleanupError);
70
- }
71
- };
72
- const onAbort = () => {
73
- void terminate(abortReason(signal));
74
- };
75
- const timer = setTimeout(() => {
76
- void terminate(new Error(`Failed to resolve ${context}: command timed out after ${COMMAND_TIMEOUT_MS}ms`));
77
- }, COMMAND_TIMEOUT_MS);
78
-
79
- signal.addEventListener("abort", onAbort, { once: true });
80
- if (signal.aborted) {
81
- onAbort();
82
- return;
83
- }
84
- child.on("error", () => {
85
- if (!terminating) finish(new Error(`Failed to resolve ${context}: command failed to start`));
86
- });
87
- child.stdout.on("data", (chunk: Buffer | string) => {
88
- if (settled || terminating) return;
89
- output = Buffer.concat([output, Buffer.from(chunk)]);
90
- if (output.byteLength > COMMAND_MAX_OUTPUT_BYTES) {
91
- void terminate(new Error(`Failed to resolve ${context}: command output exceeded 1 MiB`));
92
- }
93
- });
94
- child.on("close", code => {
95
- if (settled || terminating) return;
96
- if (code !== 0) {
97
- finish(new Error(`Failed to resolve ${context}: command exited with code ${code ?? "unknown"}`));
98
- return;
99
- }
100
- const token = output.toString("utf8").trim();
101
- if (!token) {
102
- finish(new Error(`Failed to resolve ${context}: command returned empty output`));
103
- return;
104
- }
105
- finish(undefined, token);
106
- });
107
- });
108
- }
109
-
110
- type Inflight = {
111
- controller: AbortController;
112
- promise: Promise<string>;
113
- waiters: number;
114
- };
115
-
116
- /** Resolve and periodically refresh one command-backed bearer token. */
117
- export class BearerCommandResolver {
118
- readonly #command: string;
119
- readonly #context: string;
120
- readonly #ttlMs: number;
121
- #cached: { token: string; expiresAt: number } | undefined;
122
- #failure: { error: unknown; retryAt: number } | undefined;
123
- #inflight: Inflight | undefined;
124
-
125
- constructor(command: string, context: string, ttlMs: number = resolveDefaultTtlMs()) {
126
- this.#command = command;
127
- this.#context = context;
128
- this.#ttlMs = ttlMs;
129
- }
130
-
131
- resolve(signal?: AbortSignal): Promise<string> {
132
- if (signal?.aborted) return Promise.reject(abortReason(signal));
133
- const now = Date.now();
134
- if (this.#cached !== undefined && now < this.#cached.expiresAt) {
135
- return Promise.resolve(this.#cached.token);
136
- }
137
- if (this.#failure !== undefined && now < this.#failure.retryAt) {
138
- return this.#cached !== undefined
139
- ? Promise.resolve(this.#cached.token)
140
- : Promise.reject(this.#failure.error);
141
- }
142
-
143
- let inflight = this.#inflight;
144
- if (inflight === undefined) {
145
- const controller = new AbortController();
146
- let current: Inflight;
147
- const promise = runCommand(this.#command, this.#context, controller.signal)
148
- .then(token => {
149
- this.#cached = { token, expiresAt: Date.now() + this.#ttlMs };
150
- this.#failure = undefined;
151
- return token;
152
- })
153
- .catch(error => {
154
- // Request cancellation is not a helper outage. Do not let one
155
- // cancelled request suppress refresh attempts for the next caller.
156
- if (!controller.signal.aborted) {
157
- this.#failure = { error, retryAt: Date.now() + this.#ttlMs };
158
- }
159
- if (this.#cached !== undefined) return this.#cached.token;
160
- throw error;
161
- })
162
- .finally(() => {
163
- if (this.#inflight === current) this.#inflight = undefined;
164
- });
165
- current = { controller, promise, waiters: 0 };
166
- this.#inflight = current;
167
- inflight = current;
168
- }
169
- return this.#wait(inflight, signal);
170
- }
171
-
172
- #wait(inflight: Inflight, signal?: AbortSignal): Promise<string> {
173
- inflight.waiters++;
174
- let onAbort: (() => void) | undefined;
175
- const result = signal === undefined
176
- ? inflight.promise
177
- : Promise.race([
178
- inflight.promise,
179
- new Promise<string>((_resolve, reject) => {
180
- onAbort = () => reject(abortReason(signal));
181
- signal.addEventListener("abort", onAbort, { once: true });
182
- }),
183
- ]);
184
- return result.finally(() => {
185
- if (onAbort) signal!.removeEventListener("abort", onAbort);
186
- inflight.waiters--;
187
- if (this.#inflight === inflight && inflight.waiters === 0) {
188
- this.#inflight = undefined;
189
- inflight.controller.abort(signal?.reason);
190
- }
191
- });
192
- }
193
- }
@@ -1,365 +0,0 @@
1
- import { closeSync, constants, existsSync, fstatSync, openSync, readFileSync, readdirSync, realpathSync, statSync, type Dirent, type Stats } from "node:fs";
2
- import { basename, isAbsolute, relative, resolve, sep } from "node:path";
3
- import { formatServerNamespace, type ClaudePluginConfig, type McpConfig, type ServerEntry } from "./types.ts";
4
- import { parseJsonWithComments } from "./utils.ts";
5
-
6
- interface ClaudePluginManifest {
7
- name: string;
8
- }
9
-
10
- export interface ClaudePluginBundleResult {
11
- mcpServers: Record<string, ServerEntry>;
12
- skillPaths: string[];
13
- }
14
-
15
- export function loadClaudePluginBundles(
16
- plugins: readonly ClaudePluginConfig[] | undefined,
17
- cwd: string,
18
- validateConfig: (raw: unknown) => McpConfig,
19
- components: { mcp: boolean; skills: boolean },
20
- ): ClaudePluginBundleResult {
21
- const mcpServers: Record<string, ServerEntry> = {};
22
- const skillPaths: string[] = [];
23
- const seenRoots = new Set<string>();
24
- const seenNames = new Map<string, string>();
25
- const serverSources = new Map<string, string>();
26
- const normalizedServerNames = new Map<string, string>();
27
-
28
- for (const plugin of plugins ?? []) {
29
- const configuredPath = resolvePluginPath(plugin.path, cwd);
30
- const pluginRoot = resolvePluginRoot(configuredPath);
31
- if (!pluginRoot) continue;
32
- if (seenRoots.has(pluginRoot)) {
33
- console.warn(`Claude plugin path is configured more than once: ${pluginRoot}`);
34
- continue;
35
- }
36
- seenRoots.add(pluginRoot);
37
-
38
- const manifest = readPluginManifest(pluginRoot);
39
- if (manifest === false) continue;
40
- const pluginName = manifest?.name ?? basename(pluginRoot);
41
- const previousPluginRoot = seenNames.get(pluginName);
42
- if (previousPluginRoot && previousPluginRoot !== pluginRoot) {
43
- console.warn(`Claude plugin name conflict for "${pluginName}": ${previousPluginRoot} and ${pluginRoot}`);
44
- } else {
45
- seenNames.set(pluginName, pluginRoot);
46
- }
47
-
48
- if (components.mcp && plugin.mcp === true) {
49
- const configPath = resolveContainedComponent(pluginRoot, ".mcp.json", "file", pluginName);
50
- if (configPath) {
51
- const config = readPluginMcpConfig(configPath, pluginName, pluginRoot, validateConfig);
52
- for (const [serverName, server] of Object.entries(config.mcpServers)) {
53
- const normalizedName = formatServerNamespace(serverName);
54
- const previousName = normalizedServerNames.get(normalizedName);
55
- const previousSource = previousName ? serverSources.get(previousName) : undefined;
56
- if (previousName && previousSource) {
57
- console.warn(`Claude plugin MCP server name conflict for "${serverName}": normalized name collides with "${previousName}" from ${previousSource}; the first plugin wins over ${configPath}`);
58
- continue;
59
- }
60
- normalizedServerNames.set(normalizedName, serverName);
61
- serverSources.set(serverName, configPath);
62
- mcpServers[serverName] = server;
63
- }
64
- }
65
- }
66
-
67
- if (components.skills && plugin.skills === true) {
68
- const skillsPath = resolveContainedComponent(pluginRoot, "skills", "directory", pluginName);
69
- if (skillsPath) {
70
- try {
71
- for (const skillPath of discoverContainedSkillFiles(skillsPath, pluginName)) {
72
- if (!skillPaths.includes(skillPath)) skillPaths.push(skillPath);
73
- }
74
- } catch (error) {
75
- console.warn(`Claude plugin "${pluginName}" skills could not be read at ${skillsPath}: ${formatError(error)}`);
76
- }
77
- }
78
- }
79
- }
80
-
81
- return { mcpServers, skillPaths };
82
- }
83
-
84
- function resolvePluginPath(path: string, cwd: string): string {
85
- if (path === "~") return resolve(process.env.HOME ?? "", ".");
86
- if (path.startsWith("~/")) return resolve(process.env.HOME ?? "", path.slice(2));
87
- return isAbsolute(path) ? resolve(path) : resolve(cwd, path);
88
- }
89
-
90
- function resolvePluginRoot(path: string): string | null {
91
- if (!existsSync(path)) {
92
- console.warn(`Claude plugin path does not exist: ${path}`);
93
- return null;
94
- }
95
- const stats = safeStat(path, "Claude plugin path");
96
- if (!stats) return null;
97
- if (!stats.isDirectory()) {
98
- console.warn(`Claude plugin path is not a directory: ${path}`);
99
- return null;
100
- }
101
- return safeRealpath(path, "Claude plugin path");
102
- }
103
-
104
- function readPluginManifest(pluginRoot: string): ClaudePluginManifest | null | false {
105
- const configuredManifestPath = resolve(pluginRoot, ".claude-plugin", "plugin.json");
106
- if (!existsSync(configuredManifestPath)) return null;
107
- const stats = safeStat(configuredManifestPath, "Claude plugin manifest");
108
- if (!stats) return null;
109
- if (!stats.isFile()) {
110
- console.warn(`Claude plugin manifest is not a regular file: ${configuredManifestPath}`);
111
- return false;
112
- }
113
- const manifestPath = safeRealpath(configuredManifestPath, "Claude plugin manifest");
114
- if (!manifestPath) return null;
115
- if (!isContainedPath(pluginRoot, manifestPath)) {
116
- console.warn(`Claude plugin manifest resolves outside the configured plugin directory: ${manifestPath}`);
117
- return false;
118
- }
119
-
120
- const manifestText = safeReadFile(manifestPath, "Claude plugin manifest", pluginRoot);
121
- if (manifestText === null) return null;
122
-
123
- let raw: unknown;
124
- try {
125
- raw = parseJsonWithComments(manifestText);
126
- } catch (error) {
127
- console.warn(`Claude plugin manifest contains invalid JSON at ${manifestPath}: ${formatError(error)}`);
128
- return false;
129
- }
130
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
131
- console.warn(`Claude plugin manifest must be a JSON object: ${manifestPath}`);
132
- return false;
133
- }
134
-
135
- const manifest = raw as Record<string, unknown>;
136
- if (typeof manifest.name !== "string" || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(manifest.name)) {
137
- console.warn(`Claude plugin manifest has an invalid name at ${manifestPath}: expected kebab-case`);
138
- return false;
139
- }
140
- if (!hasValidManifestFieldTypes(manifest)) {
141
- console.warn(`Claude plugin manifest has invalid field types at ${manifestPath}`);
142
- return false;
143
- }
144
- return { name: manifest.name };
145
- }
146
-
147
- function hasValidManifestFieldTypes(manifest: Record<string, unknown>): boolean {
148
- for (const field of ["$schema", "displayName", "version", "description", "homepage", "repository", "license"] as const) {
149
- if (manifest[field] !== undefined && typeof manifest[field] !== "string") return false;
150
- }
151
- for (const field of ["commands", "agents", "skills", "hooks", "mcpServers", "lspServers", "outputStyles"] as const) {
152
- const value = manifest[field];
153
- if (value !== undefined && typeof value !== "string" && (!Array.isArray(value) || value.some(item => typeof item !== "string"))) return false;
154
- }
155
- if (manifest.defaultEnabled !== undefined && typeof manifest.defaultEnabled !== "boolean") return false;
156
- if (manifest.keywords !== undefined && (!Array.isArray(manifest.keywords) || manifest.keywords.some(value => typeof value !== "string"))) return false;
157
- if (manifest.author !== undefined) {
158
- if (!manifest.author || typeof manifest.author !== "object" || Array.isArray(manifest.author)) return false;
159
- const author = manifest.author as Record<string, unknown>;
160
- if (typeof author.name !== "string") return false;
161
- if (author.email !== undefined && typeof author.email !== "string") return false;
162
- if (author.url !== undefined && typeof author.url !== "string") return false;
163
- }
164
- if (manifest.metadata !== undefined && (!manifest.metadata || typeof manifest.metadata !== "object" || Array.isArray(manifest.metadata))) return false;
165
- return true;
166
- }
167
-
168
- function resolveContainedComponent(
169
- pluginRoot: string,
170
- component: string,
171
- expected: "file" | "directory",
172
- pluginName: string,
173
- ): string | null {
174
- const path = resolve(pluginRoot, component);
175
- if (!existsSync(path)) {
176
- console.warn(`Claude plugin "${pluginName}" is missing ${component}: ${path}`);
177
- return null;
178
- }
179
- const stats = safeStat(path, `Claude plugin "${pluginName}" ${component}`);
180
- if (!stats) return null;
181
- if (expected === "file" ? !stats.isFile() : !stats.isDirectory()) {
182
- console.warn(`Claude plugin "${pluginName}" ${component} is not a ${expected}: ${path}`);
183
- return null;
184
- }
185
- const realPath = safeRealpath(path, `Claude plugin "${pluginName}" ${component}`);
186
- if (!realPath) return null;
187
- if (!isContainedPath(pluginRoot, realPath)) {
188
- console.warn(`Claude plugin "${pluginName}" ${component} resolves outside the configured plugin directory: ${realPath}`);
189
- return null;
190
- }
191
- return realPath;
192
- }
193
-
194
- function discoverContainedSkillFiles(skillsRoot: string, pluginName: string): string[] {
195
- const skillFiles: string[] = [];
196
- const visitedDirectories = new Set<string>();
197
- const visit = (directory: string): void => {
198
- const realDirectory = safeRealpath(directory, `Claude plugin "${pluginName}" skill directory`);
199
- if (!realDirectory) return;
200
- if (!isContainedPath(skillsRoot, realDirectory)) {
201
- console.warn(`Claude plugin "${pluginName}" skill path resolves outside its skills directory: ${directory} -> ${realDirectory}`);
202
- return;
203
- }
204
- if (visitedDirectories.has(realDirectory)) return;
205
- visitedDirectories.add(realDirectory);
206
- const entries = safeReadDir(realDirectory, `Claude plugin "${pluginName}" skill directory`);
207
- if (!entries) return;
208
- for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
209
- const path = resolve(realDirectory, entry.name);
210
- if (entry.isSymbolicLink()) {
211
- const target = safeRealpath(path, `Claude plugin "${pluginName}" skill path`);
212
- if (!target) continue;
213
- if (!isContainedPath(skillsRoot, target)) {
214
- console.warn(`Claude plugin "${pluginName}" skill path resolves outside its skills directory: ${path} -> ${target}`);
215
- continue;
216
- }
217
- const targetStats = safeStat(target, `Claude plugin "${pluginName}" skill path`);
218
- if (!targetStats) continue;
219
- if (targetStats.isDirectory()) visit(target);
220
- else if (targetStats.isFile() && entry.name === "SKILL.md") skillFiles.push(target);
221
- } else if (entry.isDirectory()) {
222
- visit(path);
223
- } else if (entry.isFile() && entry.name === "SKILL.md") {
224
- const realPath = safeRealpath(path, `Claude plugin "${pluginName}" skill path`);
225
- if (!realPath) continue;
226
- if (!isContainedPath(skillsRoot, realPath)) {
227
- console.warn(`Claude plugin "${pluginName}" skill path resolves outside its skills directory: ${path} -> ${realPath}`);
228
- continue;
229
- }
230
- skillFiles.push(realPath);
231
- }
232
- }
233
- };
234
- visit(skillsRoot);
235
- return skillFiles;
236
- }
237
-
238
- function readPluginMcpConfig(
239
- configPath: string,
240
- pluginName: string,
241
- pluginRoot: string,
242
- validateConfig: (raw: unknown) => McpConfig,
243
- ): McpConfig {
244
- let raw: unknown;
245
- try {
246
- const configText = safeReadFile(configPath, `Claude plugin "${pluginName}" MCP config`, pluginRoot);
247
- if (configText === null) return { mcpServers: {} };
248
- raw = parseJsonWithComments(configText);
249
- } catch (error) {
250
- console.warn(`Claude plugin "${pluginName}" has invalid MCP config at ${configPath}: ${formatError(error)}`);
251
- return { mcpServers: {} };
252
- }
253
- if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
254
- console.warn(`Claude plugin "${pluginName}" MCP config must be a JSON object: ${configPath}`);
255
- return { mcpServers: {} };
256
- }
257
-
258
- const servers = (raw as Record<string, unknown>).mcpServers;
259
- if (!servers || typeof servers !== "object" || Array.isArray(servers)) {
260
- console.warn(`Claude plugin "${pluginName}" MCP config must contain an mcpServers object: ${configPath}`);
261
- return { mcpServers: {} };
262
- }
263
-
264
- const config = validateConfig(raw);
265
- const validated: Record<string, ServerEntry> = {};
266
- for (const serverName of Object.keys(servers)) {
267
- if (serverName.trim().length === 0) {
268
- console.warn(`Claude plugin "${pluginName}" has an empty MCP server name at ${configPath}`);
269
- continue;
270
- }
271
- const parsed = config.mcpServers[serverName];
272
- if (!parsed || !hasValidServerTransport(parsed)) {
273
- console.warn(`Claude plugin "${pluginName}" has invalid MCP server "${serverName}" at ${configPath}: expected exactly one non-empty command, url, or socket transport`);
274
- continue;
275
- }
276
- validated[serverName] = replacePluginRoot(parsed, pluginRoot);
277
- }
278
- return { mcpServers: validated };
279
- }
280
-
281
- function hasValidServerTransport(entry: ServerEntry): boolean {
282
- return [entry.command, entry.url, entry.socket].filter(value => typeof value === "string" && value.trim().length > 0).length === 1;
283
- }
284
-
285
- function replacePluginRoot(entry: ServerEntry, pluginRoot: string): ServerEntry {
286
- const replace = (value: string): string => value.replaceAll("${CLAUDE_PLUGIN_ROOT}", pluginRoot);
287
- const replaced = replaceStrings(entry, replace) as ServerEntry;
288
- if (typeof replaced.command === "string") {
289
- replaced.env = { ...replaced.env, CLAUDE_PLUGIN_ROOT: pluginRoot };
290
- }
291
- return replaced;
292
- }
293
-
294
- function replaceStrings(value: unknown, replace: (value: string) => string): unknown {
295
- if (typeof value === "string") return replace(value);
296
- if (Array.isArray(value)) return value.map(item => replaceStrings(item, replace));
297
- if (!value || typeof value !== "object") return value;
298
- return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, replaceStrings(entry, replace)]));
299
- }
300
-
301
- function isContainedPath(root: string, path: string): boolean {
302
- const rel = relative(root, path);
303
- return rel === "" || (!rel.startsWith("..") && !rel.startsWith(sep) && !isAbsolute(rel));
304
- }
305
-
306
- function safeStat(path: string, description: string): Stats | null {
307
- try {
308
- return statSync(path);
309
- } catch (error) {
310
- console.warn(`${description} could not be read: ${path}: ${formatError(error)}`);
311
- return null;
312
- }
313
- }
314
-
315
- function safeRealpath(path: string, description: string): string | null {
316
- try {
317
- return realpathSync(path);
318
- } catch (error) {
319
- console.warn(`${description} could not be read: ${path}: ${formatError(error)}`);
320
- return null;
321
- }
322
- }
323
-
324
- function safeReadFile(path: string, description: string, containmentRoot: string): string | null {
325
- let fd: number | undefined;
326
- try {
327
- fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW);
328
- const openedStats = fstatSync(fd);
329
- if (!openedStats.isFile()) {
330
- console.warn(`${description} is not a regular file: ${path}`);
331
- return null;
332
- }
333
- const resolvedPath = safeRealpath(path, description);
334
- if (!resolvedPath) return null;
335
- if (!isContainedPath(containmentRoot, resolvedPath)) {
336
- console.warn(`${description} resolves outside the configured plugin directory: ${resolvedPath}`);
337
- return null;
338
- }
339
- const currentStats = safeStat(resolvedPath, description);
340
- if (!currentStats) return null;
341
- if (openedStats.dev !== currentStats.dev || openedStats.ino !== currentStats.ino) {
342
- console.warn(`${description} changed while being read: ${path}`);
343
- return null;
344
- }
345
- return readFileSync(fd, "utf8");
346
- } catch (error) {
347
- console.warn(`${description} could not be read: ${path}: ${formatError(error)}`);
348
- return null;
349
- } finally {
350
- if (fd !== undefined) closeSync(fd);
351
- }
352
- }
353
-
354
- function safeReadDir(path: string, description: string): Dirent[] | null {
355
- try {
356
- return readdirSync(path, { withFileTypes: true });
357
- } catch (error) {
358
- console.warn(`${description} could not be read: ${path}: ${formatError(error)}`);
359
- return null;
360
- }
361
- }
362
-
363
- function formatError(error: unknown): string {
364
- return error instanceof Error ? error.message : String(error);
365
- }