@code-yeongyu/senpi 2026.9.21-2 → 2026.9.22-2

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 (379) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/dist/bundle/chunks/{anthropic-messages-C3ZY2ANT.js → anthropic-messages-2P7APOOQ.js} +1 -1
  3. package/dist/bundle/chunks/{app-server-command-HSX5RFAP.js → app-server-command-PRNA6QQU.js} +1 -1
  4. package/dist/bundle/chunks/{azure-openai-responses-7TAGS2VU.js → azure-openai-responses-3AH7MJWF.js} +1 -1
  5. package/dist/bundle/chunks/{bun-extension-importer-UO7V2MZ7.js → bun-extension-importer-H4IJCWWQ.js} +1 -1
  6. package/dist/bundle/chunks/{chunk-OSDJ2SYO.js → chunk-5XC2FNJ5.js} +1 -1
  7. package/dist/bundle/chunks/{chunk-D5CL7PPD.js → chunk-64JQFFHH.js} +2 -2
  8. package/dist/bundle/chunks/{chunk-Z3KQB2R3.js → chunk-6OD4TT33.js} +95 -39
  9. package/dist/bundle/chunks/{chunk-NEEAKXDT.js → chunk-7EH64T6E.js} +2 -2
  10. package/dist/bundle/chunks/{chunk-MIVOQT3Q.js → chunk-ARJJU3MS.js} +1 -1
  11. package/dist/bundle/chunks/chunk-BOZ37BOT.js +14 -0
  12. package/dist/bundle/chunks/{chunk-POMPEGWQ.js → chunk-F3DXL5MX.js} +1 -1
  13. package/dist/bundle/chunks/{chunk-GLKVDRNP.js → chunk-GXUYWMN2.js} +1 -1
  14. package/dist/bundle/chunks/chunk-HH3KJDWA.js +2 -0
  15. package/dist/bundle/chunks/{chunk-B7W62BM7.js → chunk-IPRJIKLL.js} +1 -1
  16. package/dist/bundle/chunks/chunk-JEFYJDHP.js +8 -0
  17. package/dist/bundle/chunks/{chunk-T6XA2IZR.js → chunk-JR4X6ECO.js} +1 -1
  18. package/dist/bundle/chunks/{chunk-I425CMTO.js → chunk-JZ6YQU3A.js} +4 -4
  19. package/dist/bundle/chunks/{chunk-KNM6SRPE.js → chunk-K3HEWWSS.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-M2XAY6I7.js → chunk-M2HSO7MH.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-UYVPLEOL.js → chunk-NK2RNX25.js} +1 -1
  22. package/dist/bundle/chunks/chunk-NMB4C6ZZ.js +2 -0
  23. package/dist/bundle/chunks/{chunk-VEO3ABZR.js → chunk-OLJ7LQJY.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-GVI2HP7N.js → chunk-OPNVT7BU.js} +1 -1
  25. package/dist/bundle/chunks/{chunk-XHMOFY4T.js → chunk-R6LVC7SP.js} +4 -4
  26. package/dist/bundle/chunks/{chunk-3SLCHXZO.js → chunk-UCPWK6TZ.js} +2 -2
  27. package/dist/bundle/chunks/{chunk-B2IM56LB.js → chunk-VYIJQQ5I.js} +1 -1
  28. package/dist/bundle/chunks/{chunk-47GF6XYZ.js → chunk-YT2ZSZOY.js} +1 -1
  29. package/dist/bundle/chunks/{cli-main-GQTEEZ2V.js → cli-main-AFJNXUSL.js} +1 -1
  30. package/dist/bundle/chunks/github-copilot.js +1 -1
  31. package/dist/bundle/chunks/{google-generative-ai-JWIH75VF.js → google-generative-ai-Y2IYMUVC.js} +1 -1
  32. package/dist/bundle/chunks/{google-vertex-IRGAY5XR.js → google-vertex-TKBBMPHV.js} +1 -1
  33. package/dist/bundle/chunks/{host-command-KOEKIHIZ.js → host-command-OVA6GEWC.js} +1 -1
  34. package/dist/bundle/chunks/host-lifecycle-IDQPLYEA.js +3 -0
  35. package/dist/bundle/chunks/host-lifecycle.js +10 -6
  36. package/dist/bundle/chunks/{interactive-host-runtime-2KTFEW7O.js → interactive-host-runtime-F5L4USLR.js} +1 -1
  37. package/dist/bundle/chunks/{interactive-mode-I3ILWXQB.js → interactive-mode-UFBSCOP7.js} +1 -1
  38. package/dist/bundle/chunks/kimi-coding.js +2 -2
  39. package/dist/bundle/chunks/{list-tips-2KX65NWZ.js → list-tips-2QG7ASHS.js} +1 -1
  40. package/dist/bundle/chunks/{mistral-conversations-VOBYATVJ.js → mistral-conversations-ZYDVFRYF.js} +1 -1
  41. package/dist/bundle/chunks/multi-session-host-EUTEGVLS.js +21 -0
  42. package/dist/bundle/chunks/openai-codex-responses-MEIUNROM.js +10 -0
  43. package/dist/bundle/chunks/{openai-completions-YK6QTYOH.js → openai-completions-4V76L5ZJ.js} +1 -1
  44. package/dist/bundle/chunks/openai-responses-YR7WRBG3.js +2 -0
  45. package/dist/bundle/chunks/{package-manager-cli-HOL6CAI6.js → package-manager-cli-JPUWMUEJ.js} +1 -1
  46. package/dist/bundle/chunks/rotation-stream-S56Y7WMM.js +2 -0
  47. package/dist/bundle/chunks/{rpc-mode-L3DSGTVM.js → rpc-mode-JDVHUBZY.js} +1 -1
  48. package/dist/bundle/chunks/{session-picker-L3FYEQBL.js → session-picker-PFPJVVIC.js} +1 -1
  49. package/dist/bundle/chunks/session-worker.js +225 -164
  50. package/dist/bundle/cli.js +1 -1
  51. package/dist/bundle/index.js +1 -1
  52. package/dist/bundle/rpc-entry.js +1 -1
  53. package/dist/core/agent-session.d.ts +6 -4
  54. package/dist/core/agent-session.d.ts.map +1 -1
  55. package/dist/core/agent-session.js +9 -7
  56. package/dist/core/agent-session.js.map +1 -1
  57. package/dist/core/credential-pool/classify.d.ts.map +1 -1
  58. package/dist/core/credential-pool/classify.js +12 -0
  59. package/dist/core/credential-pool/classify.js.map +1 -1
  60. package/dist/core/credential-pool/failover.d.ts +37 -5
  61. package/dist/core/credential-pool/failover.d.ts.map +1 -1
  62. package/dist/core/credential-pool/failover.js +60 -24
  63. package/dist/core/credential-pool/failover.js.map +1 -1
  64. package/dist/core/credential-pool/rotation-events.d.ts +5 -0
  65. package/dist/core/credential-pool/rotation-events.d.ts.map +1 -0
  66. package/dist/core/credential-pool/rotation-events.js +25 -0
  67. package/dist/core/credential-pool/rotation-events.js.map +1 -0
  68. package/dist/core/credential-pool/rotation-stream.d.ts +4 -3
  69. package/dist/core/credential-pool/rotation-stream.d.ts.map +1 -1
  70. package/dist/core/credential-pool/rotation-stream.js +8 -11
  71. package/dist/core/credential-pool/rotation-stream.js.map +1 -1
  72. package/dist/core/extensions/builtin/ask-user/schema.d.ts +2 -25
  73. package/dist/core/extensions/builtin/ask-user/schema.d.ts.map +1 -1
  74. package/dist/core/extensions/builtin/ask-user/schema.js.map +1 -1
  75. package/dist/core/extensions/builtin/claude-sdk-oauth/api-id.d.ts +7 -0
  76. package/dist/core/extensions/builtin/claude-sdk-oauth/api-id.d.ts.map +1 -0
  77. package/dist/core/extensions/builtin/claude-sdk-oauth/api-id.js +7 -0
  78. package/dist/core/extensions/builtin/claude-sdk-oauth/api-id.js.map +1 -0
  79. package/dist/core/extensions/builtin/claude-sdk-oauth/index.d.ts.map +1 -1
  80. package/dist/core/extensions/builtin/claude-sdk-oauth/index.js +3 -2
  81. package/dist/core/extensions/builtin/claude-sdk-oauth/index.js.map +1 -1
  82. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js +22 -1
  83. package/dist/core/extensions/builtin/claude-sdk-oauth/session-binding.js.map +1 -1
  84. package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts +2 -0
  85. package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.d.ts.map +1 -1
  86. package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js +4 -0
  87. package/dist/core/extensions/builtin/claude-sdk-oauth/session-observability.js.map +1 -1
  88. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.d.ts.map +1 -1
  89. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js +18 -1
  90. package/dist/core/extensions/builtin/claude-sdk-oauth/session-reattach.js.map +1 -1
  91. package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.d.ts.map +1 -1
  92. package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js +18 -0
  93. package/dist/core/extensions/builtin/claude-sdk-oauth/session-turn-attempt.js.map +1 -1
  94. package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts +2 -7
  95. package/dist/core/extensions/builtin/compaction/deterministic-fallback.d.ts.map +1 -1
  96. package/dist/core/extensions/builtin/compaction/deterministic-fallback.js +2 -8
  97. package/dist/core/extensions/builtin/compaction/deterministic-fallback.js.map +1 -1
  98. package/dist/core/extensions/builtin/gpt-apply-patch/extension.js +1 -1
  99. package/dist/core/extensions/builtin/gpt-apply-patch/extension.js.map +1 -1
  100. package/dist/core/extensions/builtin/mcp/expose/naming.d.ts +0 -1
  101. package/dist/core/extensions/builtin/mcp/expose/naming.d.ts.map +1 -1
  102. package/dist/core/extensions/builtin/mcp/expose/naming.js +0 -3
  103. package/dist/core/extensions/builtin/mcp/expose/naming.js.map +1 -1
  104. package/dist/core/extensions/builtin/mcp/expose/register.d.ts +1 -2
  105. package/dist/core/extensions/builtin/mcp/expose/register.d.ts.map +1 -1
  106. package/dist/core/extensions/builtin/mcp/expose/register.js +0 -21
  107. package/dist/core/extensions/builtin/mcp/expose/register.js.map +1 -1
  108. package/dist/core/extensions/builtin/mcp/expose/schema-compat.d.ts +2 -2
  109. package/dist/core/extensions/builtin/mcp/expose/schema-compat.d.ts.map +1 -1
  110. package/dist/core/extensions/builtin/mcp/expose/schema-compat.js +2 -2
  111. package/dist/core/extensions/builtin/mcp/expose/schema-compat.js.map +1 -1
  112. package/dist/core/extensions/builtin/prompt-preset/file-operations.js +1 -1
  113. package/dist/core/extensions/builtin/prompt-preset/file-operations.js.map +1 -1
  114. package/dist/core/extensions/builtin/prompt-preset/grok-4.7.d.ts +3 -0
  115. package/dist/core/extensions/builtin/prompt-preset/grok-4.7.d.ts.map +1 -0
  116. package/dist/core/extensions/builtin/prompt-preset/grok-4.7.js +105 -0
  117. package/dist/core/extensions/builtin/prompt-preset/grok-4.7.js.map +1 -0
  118. package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
  119. package/dist/core/extensions/builtin/prompt-preset/presets.js +14 -0
  120. package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
  121. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts +1 -1
  122. package/dist/core/extensions/builtin/prompt-preset/settings.d.ts.map +1 -1
  123. package/dist/core/extensions/builtin/prompt-preset/settings.js +1 -0
  124. package/dist/core/extensions/builtin/prompt-preset/settings.js.map +1 -1
  125. package/dist/core/extensions/bun-extension-importer.d.ts +1 -0
  126. package/dist/core/extensions/bun-extension-importer.d.ts.map +1 -1
  127. package/dist/core/extensions/bun-extension-importer.js +4 -0
  128. package/dist/core/extensions/bun-extension-importer.js.map +1 -1
  129. package/dist/core/extensions/extension-module-cache.d.ts +48 -0
  130. package/dist/core/extensions/extension-module-cache.d.ts.map +1 -0
  131. package/dist/core/extensions/extension-module-cache.js +111 -0
  132. package/dist/core/extensions/extension-module-cache.js.map +1 -0
  133. package/dist/core/extensions/loader.d.ts +1 -1
  134. package/dist/core/extensions/loader.d.ts.map +1 -1
  135. package/dist/core/extensions/loader.js +14 -56
  136. package/dist/core/extensions/loader.js.map +1 -1
  137. package/dist/core/http-dispatcher.d.ts +29 -0
  138. package/dist/core/http-dispatcher.d.ts.map +1 -1
  139. package/dist/core/http-dispatcher.js +30 -3
  140. package/dist/core/http-dispatcher.js.map +1 -1
  141. package/dist/core/model-resolver.js +1 -1
  142. package/dist/core/model-resolver.js.map +1 -1
  143. package/dist/core/retry-fallback/billing.d.ts.map +1 -1
  144. package/dist/core/retry-fallback/billing.js +20 -1
  145. package/dist/core/retry-fallback/billing.js.map +1 -1
  146. package/dist/core/session-manager.d.ts +3 -1
  147. package/dist/core/session-manager.d.ts.map +1 -1
  148. package/dist/core/session-manager.js +12 -6
  149. package/dist/core/session-manager.js.map +1 -1
  150. package/dist/modes/interactive/components/assistant-render-descriptors.d.ts.map +1 -1
  151. package/dist/modes/interactive/components/assistant-render-descriptors.js +8 -7
  152. package/dist/modes/interactive/components/assistant-render-descriptors.js.map +1 -1
  153. package/dist/modes/print-mode.d.ts.map +1 -1
  154. package/dist/modes/print-mode.js +7 -5
  155. package/dist/modes/print-mode.js.map +1 -1
  156. package/dist/modes/rpc/custom-capability.d.ts +7 -0
  157. package/dist/modes/rpc/custom-capability.d.ts.map +1 -1
  158. package/dist/modes/rpc/custom-capability.js +7 -0
  159. package/dist/modes/rpc/custom-capability.js.map +1 -1
  160. package/dist/modes/rpc/handoff-activity.d.ts +4 -0
  161. package/dist/modes/rpc/handoff-activity.d.ts.map +1 -0
  162. package/dist/modes/rpc/handoff-activity.js +6 -0
  163. package/dist/modes/rpc/handoff-activity.js.map +1 -0
  164. package/dist/modes/rpc/host-child-exit.d.ts +19 -0
  165. package/dist/modes/rpc/host-child-exit.d.ts.map +1 -0
  166. package/dist/modes/rpc/host-child-exit.js +35 -0
  167. package/dist/modes/rpc/host-child-exit.js.map +1 -0
  168. package/dist/modes/rpc/host-crash-record.d.ts +24 -0
  169. package/dist/modes/rpc/host-crash-record.d.ts.map +1 -0
  170. package/dist/modes/rpc/host-crash-record.js +75 -0
  171. package/dist/modes/rpc/host-crash-record.js.map +1 -0
  172. package/dist/modes/rpc/host-crash-record.test.d.ts +2 -0
  173. package/dist/modes/rpc/host-crash-record.test.d.ts.map +1 -0
  174. package/dist/modes/rpc/host-crash-record.test.js +91 -0
  175. package/dist/modes/rpc/host-crash-record.test.js.map +1 -0
  176. package/dist/modes/rpc/host-ensure.d.ts.map +1 -1
  177. package/dist/modes/rpc/host-ensure.js +60 -17
  178. package/dist/modes/rpc/host-ensure.js.map +1 -1
  179. package/dist/modes/rpc/host-lifecycle.d.ts +4 -10
  180. package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
  181. package/dist/modes/rpc/host-lifecycle.js +83 -51
  182. package/dist/modes/rpc/host-lifecycle.js.map +1 -1
  183. package/dist/modes/rpc/host-supersession.d.ts +13 -2
  184. package/dist/modes/rpc/host-supersession.d.ts.map +1 -1
  185. package/dist/modes/rpc/host-supersession.js +40 -7
  186. package/dist/modes/rpc/host-supersession.js.map +1 -1
  187. package/dist/modes/rpc/multi-session-host.d.ts +1 -0
  188. package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
  189. package/dist/modes/rpc/multi-session-host.js +40 -7
  190. package/dist/modes/rpc/multi-session-host.js.map +1 -1
  191. package/dist/modes/rpc/observer-link.d.ts +48 -0
  192. package/dist/modes/rpc/observer-link.d.ts.map +1 -0
  193. package/dist/modes/rpc/observer-link.js +56 -0
  194. package/dist/modes/rpc/observer-link.js.map +1 -0
  195. package/dist/modes/rpc/rpc-mode.d.ts +12 -2
  196. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  197. package/dist/modes/rpc/rpc-mode.js +12 -2
  198. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  199. package/dist/modes/rpc/rpc-types.d.ts +36 -1
  200. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  201. package/dist/modes/rpc/rpc-types.js +8 -0
  202. package/dist/modes/rpc/rpc-types.js.map +1 -1
  203. package/dist/modes/rpc/session-command-router.d.ts +10 -4
  204. package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
  205. package/dist/modes/rpc/session-command-router.js +95 -19
  206. package/dist/modes/rpc/session-command-router.js.map +1 -1
  207. package/dist/modes/rpc/session-event-writer.d.ts +5 -3
  208. package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
  209. package/dist/modes/rpc/session-event-writer.js +21 -2
  210. package/dist/modes/rpc/session-event-writer.js.map +1 -1
  211. package/dist/modes/rpc/session-registry.d.ts +6 -1
  212. package/dist/modes/rpc/session-registry.d.ts.map +1 -1
  213. package/dist/modes/rpc/session-registry.js +34 -3
  214. package/dist/modes/rpc/session-registry.js.map +1 -1
  215. package/dist/modes/rpc/session-worker-client.d.ts +1 -0
  216. package/dist/modes/rpc/session-worker-client.d.ts.map +1 -1
  217. package/dist/modes/rpc/session-worker-client.js +3 -0
  218. package/dist/modes/rpc/session-worker-client.js.map +1 -1
  219. package/dist/modes/rpc/session-worker-protocol.d.ts +3 -1
  220. package/dist/modes/rpc/session-worker-protocol.d.ts.map +1 -1
  221. package/dist/modes/rpc/session-worker-protocol.js.map +1 -1
  222. package/dist/modes/rpc/session-worker.js +7 -1
  223. package/dist/modes/rpc/session-worker.js.map +1 -1
  224. package/dist/modes/rpc/socket-ownership.d.ts +16 -0
  225. package/dist/modes/rpc/socket-ownership.d.ts.map +1 -1
  226. package/dist/modes/rpc/socket-ownership.js +28 -4
  227. package/dist/modes/rpc/socket-ownership.js.map +1 -1
  228. package/dist/modes/rpc/worker-session-registry.d.ts +12 -5
  229. package/dist/modes/rpc/worker-session-registry.d.ts.map +1 -1
  230. package/dist/modes/rpc/worker-session-registry.js +10 -2
  231. package/dist/modes/rpc/worker-session-registry.js.map +1 -1
  232. package/docs/providers.md +9 -1
  233. package/docs/rpc.md +72 -10
  234. package/docs/settings.md +1 -1
  235. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +29 -0
  236. package/node_modules/@code-yeongyu/senpi-codemode/README.md +51 -13
  237. package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
  238. package/node_modules/@code-yeongyu/senpi-codemode/src/bridges/agent-bridge.ts +53 -9
  239. package/node_modules/@code-yeongyu/senpi-codemode/src/bridges/reserved-dispatch.ts +1 -0
  240. package/node_modules/@code-yeongyu/senpi-codemode/src/config/settings.ts +18 -0
  241. package/node_modules/@code-yeongyu/senpi-codemode/src/extension/eval-status.ts +9 -4
  242. package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +6 -0
  243. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/AGENTS.md +2 -2
  244. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/prelude.jl +10 -0
  245. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/context-manager.ts +18 -6
  246. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/kernel-contract.ts +2 -6
  247. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/prelude.ts +1 -1
  248. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/run-queue.ts +17 -7
  249. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-runtime.js +6 -1
  250. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/kernel-contract.ts +2 -5
  251. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/kernel.ts +37 -5
  252. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/prelude.py +11 -2
  253. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/prelude.rb +6 -0
  254. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-contract.ts +2 -5
  255. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-kernel.ts +14 -4
  256. package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-queue.ts +18 -5
  257. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt-template.ts +3 -2
  258. package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +4 -1
  259. package/node_modules/@code-yeongyu/senpi-codemode/src/timeouts/idle-timeout.ts +9 -2
  260. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/AGENTS.md +2 -0
  261. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/cell-execution.ts +19 -2
  262. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/cell-runtime.ts +11 -3
  263. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-contract.ts +6 -1
  264. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-manager.ts +72 -20
  265. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-snapshot.ts +28 -4
  266. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-state.ts +5 -4
  267. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-cell-status.ts +5 -2
  268. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-eval-result.ts +76 -25
  269. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-execution-event.ts +4 -0
  270. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-kernel-reset-refused-error.ts +12 -0
  271. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-request.ts +2 -1
  272. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool-options.ts +3 -1
  273. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +58 -37
  274. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/managed-cell.ts +15 -8
  275. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/render.ts +32 -8
  276. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/run-eval-cell.ts +89 -25
  277. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/terminal-snapshot-store.ts +4 -0
  278. package/node_modules/@code-yeongyu/senpi-codemode/src/tool/types.ts +51 -10
  279. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +2 -1
  280. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  281. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +2 -13
  282. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
  283. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +1 -0
  284. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
  285. package/node_modules/@earendil-works/pi-agent-core/dist/index.js +1 -0
  286. package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -1
  287. package/node_modules/@earendil-works/pi-agent-core/dist/tool-arguments.d.ts +5 -0
  288. package/node_modules/@earendil-works/pi-agent-core/dist/tool-arguments.d.ts.map +1 -0
  289. package/node_modules/@earendil-works/pi-agent-core/dist/tool-arguments.js +20 -0
  290. package/node_modules/@earendil-works/pi-agent-core/dist/tool-arguments.js.map +1 -0
  291. package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
  292. package/node_modules/@earendil-works/pi-ai/README.md +1 -1
  293. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js +14 -56
  294. package/node_modules/@earendil-works/pi-ai/dist/api/openai-codex-responses.js.map +1 -1
  295. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.d.ts.map +1 -1
  296. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js +18 -27
  297. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses.js.map +1 -1
  298. package/node_modules/@earendil-works/pi-ai/dist/api/websocket-transport-failure.d.ts +40 -0
  299. package/node_modules/@earendil-works/pi-ai/dist/api/websocket-transport-failure.d.ts.map +1 -0
  300. package/node_modules/@earendil-works/pi-ai/dist/api/websocket-transport-failure.js +102 -0
  301. package/node_modules/@earendil-works/pi-ai/dist/api/websocket-transport-failure.js.map +1 -0
  302. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.d.ts +4 -3
  303. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.d.ts.map +1 -1
  304. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js +28 -14
  305. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-coding.js.map +1 -1
  306. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-region.d.ts +44 -0
  307. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-region.d.ts.map +1 -0
  308. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-region.js +120 -0
  309. package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/kimi-region.js.map +1 -0
  310. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.d.ts +2 -2
  311. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.d.ts.map +1 -1
  312. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.js +2 -2
  313. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.js.map +1 -1
  314. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +3 -0
  315. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
  316. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +21 -15
  317. package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
  318. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts +1 -0
  319. package/node_modules/@earendil-works/pi-ai/dist/compat.d.ts.map +1 -1
  320. package/node_modules/@earendil-works/pi-ai/dist/compat.js +1 -0
  321. package/node_modules/@earendil-works/pi-ai/dist/compat.js.map +1 -1
  322. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +2 -0
  323. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  324. package/node_modules/@earendil-works/pi-ai/dist/index.js +2 -0
  325. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  326. package/node_modules/@earendil-works/pi-ai/dist/legacy-provider-ids.d.ts +8 -0
  327. package/node_modules/@earendil-works/pi-ai/dist/legacy-provider-ids.d.ts.map +1 -0
  328. package/node_modules/@earendil-works/pi-ai/dist/legacy-provider-ids.js +26 -0
  329. package/node_modules/@earendil-works/pi-ai/dist/legacy-provider-ids.js.map +1 -0
  330. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  331. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
  332. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.json +1 -1
  333. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  334. package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
  335. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
  336. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  337. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  338. package/node_modules/@earendil-works/pi-ai/dist/providers/data/venice.json +1 -1
  339. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  340. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xai.json +1 -1
  341. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-ams.json +1 -1
  342. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-cn.json +1 -1
  343. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi-token-plan-sgp.json +1 -1
  344. package/node_modules/@earendil-works/pi-ai/dist/providers/data/xiaomi.json +1 -1
  345. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding-auth.d.ts +9 -0
  346. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding-auth.d.ts.map +1 -0
  347. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding-auth.js +43 -0
  348. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding-auth.js.map +1 -0
  349. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.d.ts.map +1 -1
  350. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js +3 -2
  351. package/node_modules/@earendil-works/pi-ai/dist/providers/kimi-coding.js.map +1 -1
  352. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-failure-description.d.ts +19 -0
  353. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-failure-description.d.ts.map +1 -0
  354. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-failure-description.js +63 -0
  355. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-failure-description.js.map +1 -0
  356. package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/classifiers.d.ts.map +1 -1
  357. package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/classifiers.js +5 -1
  358. package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/classifiers.js.map +1 -1
  359. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts +17 -0
  360. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.d.ts.map +1 -1
  361. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +22 -1
  362. package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
  363. package/node_modules/@earendil-works/pi-ai/package.json +2 -2
  364. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  365. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  366. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
  367. package/node_modules/@earendil-works/pi-tui/dist/tui.js +12 -2
  368. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
  369. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  370. package/package.json +7 -7
  371. package/dist/bundle/chunks/chunk-5J5R5AMP.js +0 -8
  372. package/dist/bundle/chunks/chunk-I3F6VZZF.js +0 -2
  373. package/dist/bundle/chunks/chunk-IDTLJYJ5.js +0 -10
  374. package/dist/bundle/chunks/chunk-U6Z6OBX4.js +0 -2
  375. package/dist/bundle/chunks/host-lifecycle-DGZJTBDJ.js +0 -3
  376. package/dist/bundle/chunks/multi-session-host-S5FWCIWE.js +0 -20
  377. package/dist/bundle/chunks/openai-codex-responses-L2PO2D6F.js +0 -10
  378. package/dist/bundle/chunks/openai-responses-YDUBVF4S.js +0 -2
  379. package/dist/bundle/chunks/rotation-stream-Y4YU6HV4.js +0 -2
@@ -1 +1 @@
1
- {"version":3,"file":"bun-extension-importer.js","sourceRoot":"","sources":["../../../src/core/extensions/bun-extension-importer.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,KAAK,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,KAAK,CAAC;YACf,YAAY,CAAC,OAAO,EAAE,CAAC;YACvB,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,eAAe,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFileSync, realpathSync } from \"node:fs\";\nimport { createRequire, isBuiltin } from \"node:module\";\nimport { dirname, extname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { parse } from \"es-module-lexer/js\";\nimport { isCommonJsFile, rewriteCommonJsImport } from \"./bun-extension-commonjs.ts\";\nimport { ExtensionSourceError } from \"./bun-extension-error.ts\";\nimport {\n\ttype CommonJsBody,\n\ttype CommonJsModule,\n\tExtensionGenerationDisposedError,\n\textensionNamespace,\n\ttype ModuleSource,\n\tregisterExtensionGraph,\n} from \"./bun-extension-registry.ts\";\n\nexport { bunExtensionImporterStats } from \"./bun-extension-registry.ts\";\n\n// Keep the source/Node build independent of Bun's ambient type declarations.\ndeclare const Bun: {\n\tresolveSync(specifier: string, directory: string): string;\n\tTranspiler: new (options: {\n\t\treadonly loader: \"ts\" | \"tsx\" | \"jsx\";\n\t\treadonly target: \"bun\";\n\t\treadonly define: Readonly<Record<string, string>>;\n\t}) => { transformSync(source: string): string };\n};\n\n/** A generation owns only source bookkeeping; Bun owns evaluation and cycles. */\nexport function createBunExtensionImporter(\n\tvirtualModules: Readonly<Record<string, Readonly<Record<string, unknown>>>>,\n) {\n\tconst sources = new Map<string, ModuleSource>();\n\tconst commonJs = new Set<string>();\n\t// Live `module` objects by id, registered while a CommonJS body runs: a require inside a\n\t// cycle receives the partially built exports, as in Node, instead of an unset ESM default.\n\t// A body that throws is evicted so a later require re-throws instead of seeing a half-built module.\n\tconst commonJsModules = new Map<string, CommonJsModule>();\n\tconst nativeRequire = createRequire(import.meta.url);\n\tlet active = true;\n\tconst assertActive = () => {\n\t\tif (!active) throw new ExtensionGenerationDisposedError(registration.generation);\n\t};\n\tconst moduleId = (filename: string) =>\n\t\t`${extensionNamespace}:${registration.generation}/${encodeURIComponent(filename)}`;\n\tconst resolveTarget = (specifier: string, filename: string): { readonly id: string; readonly path?: string } => {\n\t\tassertActive();\n\t\tif (Object.hasOwn(virtualModules, specifier) || isBuiltin(specifier) || specifier.startsWith(\"bun:\"))\n\t\t\treturn { id: specifier };\n\t\tif (specifier.startsWith(`${extensionNamespace}:`)) return { id: specifier };\n\t\tconst path = specifier.startsWith(\"file:\") ? fileURLToPath(specifier) : specifier;\n\t\tconst resolved = realpathSync(Bun.resolveSync(path, dirname(filename)));\n\t\treturn { id: moduleId(resolved), path: resolved };\n\t};\n\tconst graph = {\n\t\tassertActive,\n\t\tresolve(specifier: string, filename: string): string {\n\t\t\treturn resolveTarget(specifier, filename).id;\n\t\t},\n\t\trequire(specifier: string, filename: string): unknown {\n\t\t\tconst id = graph.resolve(specifier, filename);\n\t\t\tconst evaluating = commonJsModules.get(id);\n\t\t\tif (evaluating !== undefined) return evaluating.exports;\n\t\t\tconst result: { readonly default?: unknown } = nativeRequire(id);\n\t\t\treturn commonJs.has(id) ? result.default : result;\n\t\t},\n\t\tevaluateCommonJs(filename: string, body: CommonJsBody): unknown {\n\t\t\tassertActive();\n\t\t\tconst id = moduleId(filename);\n\t\t\tconst module: CommonJsModule = { exports: {} };\n\t\t\tcommonJsModules.set(id, module);\n\t\t\ttry {\n\t\t\t\tbody.call(module.exports, module.exports, module);\n\t\t\t} catch (error) {\n\t\t\t\tcommonJsModules.delete(id);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn module.exports;\n\t\t},\n\t\tload(filename: string): ModuleSource {\n\t\t\tassertActive();\n\t\t\tconst existing = sources.get(filename);\n\t\t\tif (existing) return existing;\n\t\t\tconst source = readFileSync(filename, \"utf8\");\n\t\t\tlet name = \"__senpiExtensionMeta\";\n\t\t\twhile (source.includes(name)) name += \"_\";\n\t\t\tconst extension = extname(filename);\n\t\t\tconst transpiler = new Bun.Transpiler({\n\t\t\t\tloader: extension === \".tsx\" ? \"tsx\" : extension === \".jsx\" ? \"jsx\" : \"ts\",\n\t\t\t\ttarget: \"bun\",\n\t\t\t\tdefine: {\n\t\t\t\t\t\"import.meta\": name,\n\t\t\t\t\trequire: `${name}.require`,\n\t\t\t\t\t__filename: `${name}.path`,\n\t\t\t\t\t__dirname: `${name}.dir`,\n\t\t\t\t},\n\t\t\t});\n\t\t\tlet contents: string;\n\t\t\ttry {\n\t\t\t\tcontents = transpiler.transformSync(source);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof AggregateError) throw new ExtensionSourceError(filename, error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst [imports, , , hasModuleSyntax] = parse(contents, filename);\n\t\t\tconst edits: { readonly start: number; readonly end: number; readonly text: string }[] = [];\n\t\t\tlet commonJsImports = 0;\n\t\t\tfor (const edge of imports) {\n\t\t\t\tif (edge.type === \"dynamic\") {\n\t\t\t\t\t// Replace the keyword, not its argument: nested expressions, templates,\n\t\t\t\t\t// import attributes, and unavailable optional dependencies stay lazy.\n\t\t\t\t\tedits.push({ start: edge.importStart, end: edge.dynamicStart, text: `${name}.import` });\n\t\t\t\t} else if (edge.type === \"static\" || edge.type === \"reexport-star\") {\n\t\t\t\t\tconst target = resolveTarget(edge.specifier, filename);\n\t\t\t\t\tif (target.path !== undefined && isCommonJsFile(target.path)) {\n\t\t\t\t\t\t// \"import\" and \"export\" are both six characters, so the clause is\n\t\t\t\t\t\t// whatever sits between the keyword and the specifier in either form.\n\t\t\t\t\t\tconst clause = contents\n\t\t\t\t\t\t\t.slice(edge.importStart + \"import\".length, edge.start - 1)\n\t\t\t\t\t\t\t.replace(/\\bfrom\\s*$/, \"\");\n\t\t\t\t\t\t// This branch replaces the whole statement, so the attributes between the\n\t\t\t\t\t\t// specifier and the end of it have to travel with it: they pick the loader.\n\t\t\t\t\t\tconst attributes =\n\t\t\t\t\t\t\tedge.attributesStart < 0 ? \"\" : contents.slice(edge.end + 1, edge.importEnd).replace(/;\\s*$/, \"\");\n\t\t\t\t\t\tedits.push({\n\t\t\t\t\t\t\tstart: edge.importStart,\n\t\t\t\t\t\t\tend: edge.importEnd,\n\t\t\t\t\t\t\ttext: rewriteCommonJsImport(clause, target.id, `${name}Cjs${commonJsImports++}`, attributes),\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tedits.push({ start: edge.start - 1, end: edge.end + 1, text: JSON.stringify(target.id) });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const edit of edits.sort((a, b) => b.start - a.start)) {\n\t\t\t\tcontents = contents.slice(0, edit.start) + edit.text + contents.slice(edit.end);\n\t\t\t}\n\t\t\t// A shebang is only a shebang on the first line, so it goes before any prologue.\n\t\t\tcontents = contents.replace(/^#![^\\n]*\\n/, \"\");\n\t\t\t// Runtime plugins load ESM, even for CommonJS source. Node's module\n\t\t\t// function wrapper preserves synchronous export assignment and keeps\n\t\t\t// `exports` and `module` reassignable bindings with `this` as the exports\n\t\t\t// object, as dependencies such as whatwg-url and jsdom require.\n\t\t\tif (!hasModuleSyntax && extension !== \".mjs\" && extension !== \".mts\") {\n\t\t\t\tcommonJs.add(moduleId(filename));\n\t\t\t\tcontents = `export default ${name}.commonJs(function (exports, module) {\\n${contents}\\n});`;\n\t\t\t}\n\t\t\tcontents = `import { metadata as ${name}Factory } from \"${extensionNamespace}:runtime\";\\nconst ${name} = ${name}Factory(${JSON.stringify(registration.generation)}, ${JSON.stringify(filename)});\\n${contents}`;\n\t\t\tconst prepared = { contents, loader: \"js\" } satisfies ModuleSource;\n\t\t\tsources.set(filename, prepared);\n\t\t\treturn prepared;\n\t\t},\n\t};\n\tconst registration = registerExtensionGraph(graph, virtualModules);\n\treturn {\n\t\tasync import(path: string, _options: { readonly default: true }): Promise<unknown> {\n\t\t\tassertActive();\n\t\t\tconst id = moduleId(realpathSync(resolve(path)));\n\t\t\tconst module: { readonly default?: unknown } = await import(id);\n\t\t\tconst factory = module.default;\n\t\t\tif (typeof factory !== \"function\") return factory;\n\t\t\t// This wrapper is not stored in Bun's permanent module registry. A\n\t\t\t// reachable old factory keeps its own computed-import graph alive.\n\t\t\treturn function (this: unknown, ...args: unknown[]) {\n\t\t\t\tgraph.assertActive();\n\t\t\t\treturn factory.apply(this, args);\n\t\t\t};\n\t\t},\n\t\tdispose() {\n\t\t\tactive = false;\n\t\t\tregistration.dispose();\n\t\t\tsources.clear();\n\t\t\tcommonJs.clear();\n\t\t\tcommonJsModules.clear();\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"bun-extension-importer.js","sourceRoot":"","sources":["../../../src/core/extensions/bun-extension-importer.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAGN,gCAAgC,EAChC,kBAAkB,EAElB,sBAAsB,GACtB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAYxE,iFAAiF;AACjF,MAAM,UAAU,0BAA0B,CACzC,cAA2E;IAE3E,MAAM,OAAO,GAAG,IAAI,GAAG,EAAwB,CAAC;IAChD,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;IACnC,yFAAyF;IACzF,2FAA2F;IAC3F,oGAAoG;IACpG,MAAM,eAAe,GAAG,IAA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,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAChC,OAAO,QAAQ,CAAC;QACjB,CAAC;KACD,CAAC;IACF,MAAM,YAAY,GAAG,sBAAsB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACnE,OAAO;QACN,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,QAAoC;YAC9D,YAAY,EAAE,CAAC;YACf,MAAM,EAAE,GAAG,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACjD,MAAM,MAAM,GAAmC,MAAM,MAAM,kCAAC,EAAE,EAAC,CAAC;YAChE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;YAC/B,IAAI,OAAO,OAAO,KAAK,UAAU;gBAAE,OAAO,OAAO,CAAC;YAClD,mEAAmE;YACnE,mEAAmE;YACnE,OAAO,UAAyB,GAAG,IAAe;gBACjD,KAAK,CAAC,YAAY,EAAE,CAAC;gBACrB,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAClC,CAAC,CAAC;QACH,CAAC;QACD,iFAAiF;QACjF,aAAa;YACZ,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO;YACN,MAAM,GAAG,KAAK,CAAC;YACf,YAAY,CAAC,OAAO,EAAE,CAAC;YACvB,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,eAAe,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import { readFileSync, realpathSync } from \"node:fs\";\nimport { createRequire, isBuiltin } from \"node:module\";\nimport { dirname, extname, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { parse } from \"es-module-lexer/js\";\nimport { isCommonJsFile, rewriteCommonJsImport } from \"./bun-extension-commonjs.ts\";\nimport { ExtensionSourceError } from \"./bun-extension-error.ts\";\nimport {\n\ttype CommonJsBody,\n\ttype CommonJsModule,\n\tExtensionGenerationDisposedError,\n\textensionNamespace,\n\ttype ModuleSource,\n\tregisterExtensionGraph,\n} from \"./bun-extension-registry.ts\";\n\nexport { bunExtensionImporterStats } from \"./bun-extension-registry.ts\";\n\n// Keep the source/Node build independent of Bun's ambient type declarations.\ndeclare const Bun: {\n\tresolveSync(specifier: string, directory: string): string;\n\tTranspiler: new (options: {\n\t\treadonly loader: \"ts\" | \"tsx\" | \"jsx\";\n\t\treadonly target: \"bun\";\n\t\treadonly define: Readonly<Record<string, string>>;\n\t}) => { transformSync(source: string): string };\n};\n\n/** A generation owns only source bookkeeping; Bun owns evaluation and cycles. */\nexport function createBunExtensionImporter(\n\tvirtualModules: Readonly<Record<string, Readonly<Record<string, unknown>>>>,\n) {\n\tconst sources = new Map<string, ModuleSource>();\n\tconst commonJs = new Set<string>();\n\t// Live `module` objects by id, registered while a CommonJS body runs: a require inside a\n\t// cycle receives the partially built exports, as in Node, instead of an unset ESM default.\n\t// A body that throws is evicted so a later require re-throws instead of seeing a half-built module.\n\tconst commonJsModules = new Map<string, CommonJsModule>();\n\tconst nativeRequire = createRequire(import.meta.url);\n\tlet active = true;\n\tconst assertActive = () => {\n\t\tif (!active) throw new ExtensionGenerationDisposedError(registration.generation);\n\t};\n\tconst moduleId = (filename: string) =>\n\t\t`${extensionNamespace}:${registration.generation}/${encodeURIComponent(filename)}`;\n\tconst resolveTarget = (specifier: string, filename: string): { readonly id: string; readonly path?: string } => {\n\t\tassertActive();\n\t\tif (Object.hasOwn(virtualModules, specifier) || isBuiltin(specifier) || specifier.startsWith(\"bun:\"))\n\t\t\treturn { id: specifier };\n\t\tif (specifier.startsWith(`${extensionNamespace}:`)) return { id: specifier };\n\t\tconst path = specifier.startsWith(\"file:\") ? fileURLToPath(specifier) : specifier;\n\t\tconst resolved = realpathSync(Bun.resolveSync(path, dirname(filename)));\n\t\treturn { id: moduleId(resolved), path: resolved };\n\t};\n\tconst graph = {\n\t\tassertActive,\n\t\tresolve(specifier: string, filename: string): string {\n\t\t\treturn resolveTarget(specifier, filename).id;\n\t\t},\n\t\trequire(specifier: string, filename: string): unknown {\n\t\t\tconst id = graph.resolve(specifier, filename);\n\t\t\tconst evaluating = commonJsModules.get(id);\n\t\t\tif (evaluating !== undefined) return evaluating.exports;\n\t\t\tconst result: { readonly default?: unknown } = nativeRequire(id);\n\t\t\treturn commonJs.has(id) ? result.default : result;\n\t\t},\n\t\tevaluateCommonJs(filename: string, body: CommonJsBody): unknown {\n\t\t\tassertActive();\n\t\t\tconst id = moduleId(filename);\n\t\t\tconst module: CommonJsModule = { exports: {} };\n\t\t\tcommonJsModules.set(id, module);\n\t\t\ttry {\n\t\t\t\tbody.call(module.exports, module.exports, module);\n\t\t\t} catch (error) {\n\t\t\t\tcommonJsModules.delete(id);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\treturn module.exports;\n\t\t},\n\t\tload(filename: string): ModuleSource {\n\t\t\tassertActive();\n\t\t\tconst existing = sources.get(filename);\n\t\t\tif (existing) return existing;\n\t\t\tconst source = readFileSync(filename, \"utf8\");\n\t\t\tlet name = \"__senpiExtensionMeta\";\n\t\t\twhile (source.includes(name)) name += \"_\";\n\t\t\tconst extension = extname(filename);\n\t\t\tconst transpiler = new Bun.Transpiler({\n\t\t\t\tloader: extension === \".tsx\" ? \"tsx\" : extension === \".jsx\" ? \"jsx\" : \"ts\",\n\t\t\t\ttarget: \"bun\",\n\t\t\t\tdefine: {\n\t\t\t\t\t\"import.meta\": name,\n\t\t\t\t\trequire: `${name}.require`,\n\t\t\t\t\t__filename: `${name}.path`,\n\t\t\t\t\t__dirname: `${name}.dir`,\n\t\t\t\t},\n\t\t\t});\n\t\t\tlet contents: string;\n\t\t\ttry {\n\t\t\t\tcontents = transpiler.transformSync(source);\n\t\t\t} catch (error) {\n\t\t\t\tif (error instanceof AggregateError) throw new ExtensionSourceError(filename, error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst [imports, , , hasModuleSyntax] = parse(contents, filename);\n\t\t\tconst edits: { readonly start: number; readonly end: number; readonly text: string }[] = [];\n\t\t\tlet commonJsImports = 0;\n\t\t\tfor (const edge of imports) {\n\t\t\t\tif (edge.type === \"dynamic\") {\n\t\t\t\t\t// Replace the keyword, not its argument: nested expressions, templates,\n\t\t\t\t\t// import attributes, and unavailable optional dependencies stay lazy.\n\t\t\t\t\tedits.push({ start: edge.importStart, end: edge.dynamicStart, text: `${name}.import` });\n\t\t\t\t} else if (edge.type === \"static\" || edge.type === \"reexport-star\") {\n\t\t\t\t\tconst target = resolveTarget(edge.specifier, filename);\n\t\t\t\t\tif (target.path !== undefined && isCommonJsFile(target.path)) {\n\t\t\t\t\t\t// \"import\" and \"export\" are both six characters, so the clause is\n\t\t\t\t\t\t// whatever sits between the keyword and the specifier in either form.\n\t\t\t\t\t\tconst clause = contents\n\t\t\t\t\t\t\t.slice(edge.importStart + \"import\".length, edge.start - 1)\n\t\t\t\t\t\t\t.replace(/\\bfrom\\s*$/, \"\");\n\t\t\t\t\t\t// This branch replaces the whole statement, so the attributes between the\n\t\t\t\t\t\t// specifier and the end of it have to travel with it: they pick the loader.\n\t\t\t\t\t\tconst attributes =\n\t\t\t\t\t\t\tedge.attributesStart < 0 ? \"\" : contents.slice(edge.end + 1, edge.importEnd).replace(/;\\s*$/, \"\");\n\t\t\t\t\t\tedits.push({\n\t\t\t\t\t\t\tstart: edge.importStart,\n\t\t\t\t\t\t\tend: edge.importEnd,\n\t\t\t\t\t\t\ttext: rewriteCommonJsImport(clause, target.id, `${name}Cjs${commonJsImports++}`, attributes),\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tedits.push({ start: edge.start - 1, end: edge.end + 1, text: JSON.stringify(target.id) });\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const edit of edits.sort((a, b) => b.start - a.start)) {\n\t\t\t\tcontents = contents.slice(0, edit.start) + edit.text + contents.slice(edit.end);\n\t\t\t}\n\t\t\t// A shebang is only a shebang on the first line, so it goes before any prologue.\n\t\t\tcontents = contents.replace(/^#![^\\n]*\\n/, \"\");\n\t\t\t// Runtime plugins load ESM, even for CommonJS source. Node's module\n\t\t\t// function wrapper preserves synchronous export assignment and keeps\n\t\t\t// `exports` and `module` reassignable bindings with `this` as the exports\n\t\t\t// object, as dependencies such as whatwg-url and jsdom require.\n\t\t\tif (!hasModuleSyntax && extension !== \".mjs\" && extension !== \".mts\") {\n\t\t\t\tcommonJs.add(moduleId(filename));\n\t\t\t\tcontents = `export default ${name}.commonJs(function (exports, module) {\\n${contents}\\n});`;\n\t\t\t}\n\t\t\tcontents = `import { metadata as ${name}Factory } from \"${extensionNamespace}:runtime\";\\nconst ${name} = ${name}Factory(${JSON.stringify(registration.generation)}, ${JSON.stringify(filename)});\\n${contents}`;\n\t\t\tconst prepared = { contents, loader: \"js\" } satisfies ModuleSource;\n\t\t\tsources.set(filename, prepared);\n\t\t\treturn prepared;\n\t\t},\n\t};\n\tconst registration = registerExtensionGraph(graph, virtualModules);\n\treturn {\n\t\tasync import(path: string, _options: { readonly default: true }): Promise<unknown> {\n\t\t\tassertActive();\n\t\t\tconst id = moduleId(realpathSync(resolve(path)));\n\t\t\tconst module: { readonly default?: unknown } = await import(id);\n\t\t\tconst factory = module.default;\n\t\t\tif (typeof factory !== \"function\") return factory;\n\t\t\t// This wrapper is not stored in Bun's permanent module registry. A\n\t\t\t// reachable old factory keeps its own computed-import graph alive.\n\t\t\treturn function (this: unknown, ...args: unknown[]) {\n\t\t\t\tgraph.assertActive();\n\t\t\t\treturn factory.apply(this, args);\n\t\t\t};\n\t\t},\n\t\t// The generation's staleness check reads these: every source file it transpiled.\n\t\tcompiledFiles(): readonly string[] {\n\t\t\treturn [...sources.keys()];\n\t\t},\n\t\tdispose() {\n\t\t\tactive = false;\n\t\t\tregistration.dispose();\n\t\t\tsources.clear();\n\t\t\tcommonJs.clear();\n\t\t\tcommonJsModules.clear();\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Process-wide cache for compiled extension module graphs.
3
+ *
4
+ * A module registry has no eviction API, so every extension source evaluated under a fresh
5
+ * importer generation stays resident for the life of the process. A daemon that loads extensions
6
+ * per session therefore pays that cost per session forever (senpi#1948). The graph is a pure
7
+ * function of its source files, so this cache keeps ONE live generation and hands the same factory
8
+ * to every later load whose sources are byte-for-byte unchanged; every load still runs the factory,
9
+ * so sessions keep their own extension instances.
10
+ *
11
+ * Freshness is preserved by invalidation: a changed, added or removed source file drops the
12
+ * generation, and the next load compiles a new one. An importer that cannot report the files it
13
+ * compiled (the Node jiti path) is never cached, because its graph cannot be checked for staleness.
14
+ *
15
+ * @module core/extensions/extension-module-cache
16
+ */
17
+ export type ExtensionModuleImporter = {
18
+ import(path: string, options: {
19
+ default: true;
20
+ }): Promise<unknown>;
21
+ /** Source files this importer compiled; absent on importers that cannot report them. */
22
+ compiledFiles?: () => readonly string[];
23
+ dispose?: () => void;
24
+ };
25
+ export type ExtensionModuleImporterFactory = () => Promise<ExtensionModuleImporter>;
26
+ type CachedFactory = (...args: never[]) => unknown;
27
+ /**
28
+ * The cached factory for this source, or `undefined` when it must be compiled.
29
+ *
30
+ * A source change invalidates the whole generation: its modules already reference each other, so
31
+ * one stale file makes every factory in that generation suspect.
32
+ */
33
+ export declare function cachedExtensionFactory(resolvedPath: string): CachedFactory | undefined;
34
+ /** The live importer, created on demand. Callers share one generation until it is invalidated. */
35
+ export declare function extensionModuleImporter(create: ExtensionModuleImporterFactory): Promise<ExtensionModuleImporter>;
36
+ /**
37
+ * Remember a freshly compiled factory and re-read the generation's source fingerprints.
38
+ *
39
+ * `compiledBy` is the importer that produced the factory: a load already in flight when a source
40
+ * change dropped the generation must not file its result under the successor, whose fingerprint
41
+ * describes different bytes.
42
+ */
43
+ export declare function rememberExtensionFactory(resolvedPath: string, factory: CachedFactory, compiledBy: ExtensionModuleImporter): void;
44
+ export declare function clearExtensionCache(): void;
45
+ /** Test seam: how many module generations this process has compiled. */
46
+ export declare function extensionModuleGenerationCount(): number;
47
+ export {};
48
+ //# sourceMappingURL=extension-module-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-module-cache.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/extension-module-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,MAAM,uBAAuB,GAAG;IACrC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE;QAAE,OAAO,EAAE,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACnE,wFAAwF;IACxF,aAAa,CAAC,EAAE,MAAM,SAAS,MAAM,EAAE,CAAC;IACxC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG,MAAM,OAAO,CAAC,uBAAuB,CAAC,CAAC;AAEpF,KAAK,aAAa,GAAG,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,CAAC;AAoDnD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAQtF;AAED,kGAAkG;AAClG,wBAAsB,uBAAuB,CAC5C,MAAM,EAAE,8BAA8B,GACpC,OAAO,CAAC,uBAAuB,CAAC,CASlC;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACvC,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,aAAa,EACtB,UAAU,EAAE,uBAAuB,GACjC,IAAI,CAKN;AAED,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAED,wEAAwE;AACxE,wBAAgB,8BAA8B,IAAI,MAAM,CAEvD"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Process-wide cache for compiled extension module graphs.
3
+ *
4
+ * A module registry has no eviction API, so every extension source evaluated under a fresh
5
+ * importer generation stays resident for the life of the process. A daemon that loads extensions
6
+ * per session therefore pays that cost per session forever (senpi#1948). The graph is a pure
7
+ * function of its source files, so this cache keeps ONE live generation and hands the same factory
8
+ * to every later load whose sources are byte-for-byte unchanged; every load still runs the factory,
9
+ * so sessions keep their own extension instances.
10
+ *
11
+ * Freshness is preserved by invalidation: a changed, added or removed source file drops the
12
+ * generation, and the next load compiles a new one. An importer that cannot report the files it
13
+ * compiled (the Node jiti path) is never cached, because its graph cannot be checked for staleness.
14
+ *
15
+ * @module core/extensions/extension-module-cache
16
+ */
17
+ import { statSync } from "node:fs";
18
+ let generation;
19
+ let pendingImporter;
20
+ let generationsCreated = 0;
21
+ function fingerprintOf(file) {
22
+ try {
23
+ const stats = statSync(file, { bigint: true });
24
+ return `${stats.mtimeNs}:${stats.size}`;
25
+ }
26
+ catch {
27
+ return undefined;
28
+ }
29
+ }
30
+ /** Stale means a file this generation already compiled changed or disappeared. */
31
+ function sourcesUnchanged(live) {
32
+ for (const [file, fingerprint] of live.fingerprints) {
33
+ if (fingerprintOf(file) !== fingerprint)
34
+ return false;
35
+ }
36
+ return true;
37
+ }
38
+ /**
39
+ * Stop REUSING a generation; never revoke it. A session loaded under it can still lazily
40
+ * `import()` from its graph long after its factory returned, and disposing the importer makes
41
+ * that throw. Its modules stay registered either way - that residue is the price of a source edit,
42
+ * not something a dispose could reclaim.
43
+ */
44
+ function dropGeneration() {
45
+ generation = undefined;
46
+ pendingImporter = undefined;
47
+ }
48
+ /**
49
+ * The compiled set GROWS during normal use - extensions import lazily long after their factory was
50
+ * built - so newly seen files join the fingerprint instead of counting as a change.
51
+ */
52
+ function absorbNewlyCompiled(live) {
53
+ for (const file of live.importer.compiledFiles?.() ?? []) {
54
+ if (live.fingerprints.has(file))
55
+ continue;
56
+ const fingerprint = fingerprintOf(file);
57
+ if (fingerprint !== undefined)
58
+ live.fingerprints.set(file, fingerprint);
59
+ }
60
+ }
61
+ /**
62
+ * The cached factory for this source, or `undefined` when it must be compiled.
63
+ *
64
+ * A source change invalidates the whole generation: its modules already reference each other, so
65
+ * one stale file makes every factory in that generation suspect.
66
+ */
67
+ export function cachedExtensionFactory(resolvedPath) {
68
+ if (!generation)
69
+ return undefined;
70
+ if (!sourcesUnchanged(generation)) {
71
+ dropGeneration();
72
+ return undefined;
73
+ }
74
+ absorbNewlyCompiled(generation);
75
+ return generation.factories.get(resolvedPath);
76
+ }
77
+ /** The live importer, created on demand. Callers share one generation until it is invalidated. */
78
+ export async function extensionModuleImporter(create) {
79
+ if (generation)
80
+ return generation.importer;
81
+ pendingImporter ??= create().then((importer) => {
82
+ generation = { importer, factories: new Map(), fingerprints: new Map() };
83
+ generationsCreated++;
84
+ pendingImporter = undefined;
85
+ return importer;
86
+ });
87
+ return pendingImporter;
88
+ }
89
+ /**
90
+ * Remember a freshly compiled factory and re-read the generation's source fingerprints.
91
+ *
92
+ * `compiledBy` is the importer that produced the factory: a load already in flight when a source
93
+ * change dropped the generation must not file its result under the successor, whose fingerprint
94
+ * describes different bytes.
95
+ */
96
+ export function rememberExtensionFactory(resolvedPath, factory, compiledBy) {
97
+ if (!generation || generation.importer !== compiledBy)
98
+ return;
99
+ if (generation.importer.compiledFiles === undefined)
100
+ return;
101
+ generation.factories.set(resolvedPath, factory);
102
+ absorbNewlyCompiled(generation);
103
+ }
104
+ export function clearExtensionCache() {
105
+ dropGeneration();
106
+ }
107
+ /** Test seam: how many module generations this process has compiled. */
108
+ export function extensionModuleGenerationCount() {
109
+ return generationsCreated;
110
+ }
111
+ //# sourceMappingURL=extension-module-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extension-module-cache.js","sourceRoot":"","sources":["../../../src/core/extensions/extension-module-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAmBnC,IAAI,UAAkC,CAAC;AACvC,IAAI,eAA6D,CAAC;AAClE,IAAI,kBAAkB,GAAG,C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CAAC;QACjB,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,mBAAmB,CAAC,UAAU,CAAC,CAAC;IAChC,OAAO,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC/C,CAAC;AAED,kGAAkG;AAClG,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC5C,MAAsC;IAEtC,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC3C,eAAe,KAAK,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;QAC9C,UAAU,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,GAAG,EAAE,EAAE,YAAY,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;QACzE,kBAAkB,EAAE,CAAC;QACrB,eAAe,GAAG,SAAS,CAAC;QAC5B,OAAO,QAAQ,CAAC;IACjB,CAAC,CAAC,CAAC;IACH,OAAO,eAAe,CAAC;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACvC,YAAoB,EACpB,OAAsB,EACtB,UAAmC;IAEnC,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,QAAQ,KAAK,UAAU;QAAE,OAAO;IAC9D,IAAI,UAAU,CAAC,QAAQ,CAAC,aAAa,KAAK,SAAS;QAAE,OAAO;IAC5D,UAAU,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAChD,mBAAmB,CAAC,UAAU,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,mBAAmB;IAClC,cAAc,EAAE,CAAC;AAClB,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,8BAA8B;IAC7C,OAAO,kBAAkB,CAAC;AAC3B,CAAC","sourcesContent":["/**\n * Process-wide cache for compiled extension module graphs.\n *\n * A module registry has no eviction API, so every extension source evaluated under a fresh\n * importer generation stays resident for the life of the process. A daemon that loads extensions\n * per session therefore pays that cost per session forever (senpi#1948). The graph is a pure\n * function of its source files, so this cache keeps ONE live generation and hands the same factory\n * to every later load whose sources are byte-for-byte unchanged; every load still runs the factory,\n * so sessions keep their own extension instances.\n *\n * Freshness is preserved by invalidation: a changed, added or removed source file drops the\n * generation, and the next load compiles a new one. An importer that cannot report the files it\n * compiled (the Node jiti path) is never cached, because its graph cannot be checked for staleness.\n *\n * @module core/extensions/extension-module-cache\n */\n\nimport { statSync } from \"node:fs\";\n\nexport type ExtensionModuleImporter = {\n\timport(path: string, options: { default: true }): Promise<unknown>;\n\t/** Source files this importer compiled; absent on importers that cannot report them. */\n\tcompiledFiles?: () => readonly string[];\n\tdispose?: () => void;\n};\n\nexport type ExtensionModuleImporterFactory = () => Promise<ExtensionModuleImporter>;\n\ntype CachedFactory = (...args: never[]) => unknown;\n\ninterface Generation {\n\treadonly importer: ExtensionModuleImporter;\n\treadonly factories: Map<string, CachedFactory>;\n\treadonly fingerprints: Map<string, string>;\n}\n\nlet generation: Generation | undefined;\nlet pendingImporter: Promise<ExtensionModuleImporter> | undefined;\nlet generationsCreated = 0;\n\nfunction fingerprintOf(file: string): string | undefined {\n\ttry {\n\t\tconst stats = statSync(file, { bigint: true });\n\t\treturn `${stats.mtimeNs}:${stats.size}`;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n/** Stale means a file this generation already compiled changed or disappeared. */\nfunction sourcesUnchanged(live: Generation): boolean {\n\tfor (const [file, fingerprint] of live.fingerprints) {\n\t\tif (fingerprintOf(file) !== fingerprint) return false;\n\t}\n\treturn true;\n}\n\n/**\n * Stop REUSING a generation; never revoke it. A session loaded under it can still lazily\n * `import()` from its graph long after its factory returned, and disposing the importer makes\n * that throw. Its modules stay registered either way - that residue is the price of a source edit,\n * not something a dispose could reclaim.\n */\nfunction dropGeneration(): void {\n\tgeneration = undefined;\n\tpendingImporter = undefined;\n}\n\n/**\n * The compiled set GROWS during normal use - extensions import lazily long after their factory was\n * built - so newly seen files join the fingerprint instead of counting as a change.\n */\nfunction absorbNewlyCompiled(live: Generation): void {\n\tfor (const file of live.importer.compiledFiles?.() ?? []) {\n\t\tif (live.fingerprints.has(file)) continue;\n\t\tconst fingerprint = fingerprintOf(file);\n\t\tif (fingerprint !== undefined) live.fingerprints.set(file, fingerprint);\n\t}\n}\n\n/**\n * The cached factory for this source, or `undefined` when it must be compiled.\n *\n * A source change invalidates the whole generation: its modules already reference each other, so\n * one stale file makes every factory in that generation suspect.\n */\nexport function cachedExtensionFactory(resolvedPath: string): CachedFactory | undefined {\n\tif (!generation) return undefined;\n\tif (!sourcesUnchanged(generation)) {\n\t\tdropGeneration();\n\t\treturn undefined;\n\t}\n\tabsorbNewlyCompiled(generation);\n\treturn generation.factories.get(resolvedPath);\n}\n\n/** The live importer, created on demand. Callers share one generation until it is invalidated. */\nexport async function extensionModuleImporter(\n\tcreate: ExtensionModuleImporterFactory,\n): Promise<ExtensionModuleImporter> {\n\tif (generation) return generation.importer;\n\tpendingImporter ??= create().then((importer) => {\n\t\tgeneration = { importer, factories: new Map(), fingerprints: new Map() };\n\t\tgenerationsCreated++;\n\t\tpendingImporter = undefined;\n\t\treturn importer;\n\t});\n\treturn pendingImporter;\n}\n\n/**\n * Remember a freshly compiled factory and re-read the generation's source fingerprints.\n *\n * `compiledBy` is the importer that produced the factory: a load already in flight when a source\n * change dropped the generation must not file its result under the successor, whose fingerprint\n * describes different bytes.\n */\nexport function rememberExtensionFactory(\n\tresolvedPath: string,\n\tfactory: CachedFactory,\n\tcompiledBy: ExtensionModuleImporter,\n): void {\n\tif (!generation || generation.importer !== compiledBy) return;\n\tif (generation.importer.compiledFiles === undefined) return;\n\tgeneration.factories.set(resolvedPath, factory);\n\tabsorbNewlyCompiled(generation);\n}\n\nexport function clearExtensionCache(): void {\n\tdropGeneration();\n}\n\n/** Test seam: how many module generations this process has compiled. */\nexport function extensionModuleGenerationCount(): number {\n\treturn generationsCreated;\n}\n"]}
@@ -11,7 +11,7 @@ export interface ExtensionSessionOptions {
11
11
  sessionContext?: SessionContext;
12
12
  }
13
13
  export type ExtensionFactoryResolver = (extensionPath: string, resolvedPath: string) => ExtensionFactory | undefined;
14
- export declare function clearExtensionCache(): void;
14
+ export { clearExtensionCache, extensionModuleGenerationCount } from "./extension-module-cache.ts";
15
15
  /**
16
16
  * Create a runtime with throwing stubs for action methods.
17
17
  * Runner.bindCore() replaces these with real implementations.
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/loader.ts"],"names":[],"mappings":"AACA;;;GAGG;AAwBH,OAAO,EAAkB,KAAK,QAAQ,EAAuD,MAAM,iBAAiB,CAAC;AAQrH,OAAO,KAAK,EAEX,SAAS,EAET,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EAGvB,oBAAoB,EAGpB,2BAA2B,EAI3B,cAAc,EACd,WAAW,EAEX,MAAM,YAAY,CAAC;AAGpB,kGAAkG;AAClG,MAAM,WAAW,uBAAuB;IACvC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,cAAc,CAAC,EAAE,cAAc,CAAC;CAChC;AA+JD,MAAM,MAAM,wBAAwB,GAAG,CAAC,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,gBAAgB,GAAG,SAAS,CAAC;AAoBrH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAyBD;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAuFzD;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,gBAAgB,GAAG,2BAA2B,EAAE,CAS1G;AAweD;;GAEG;AACH,wBAAsB,wBAAwB,CAC7C,OAAO,EAAE,gBAAgB,EACzB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,gBAAgB,EACzB,aAAa,SAAa,EAC1B,OAAO,GAAE,uBAA2D,GAClE,OAAO,CAAC,SAAS,C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OAAO,EAAE,mBAAmB,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAElG;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,gBAAgB,CAuFzD;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAAC,OAAO,EAAE,gBAAgB,GAAG,2BAA2B,EAAE,CAS1G;AAwdD;;GAEG;AACH,wBAAsB,wBAAwB,CAC7C,OAAO,EAAE,gBAAgB,EACzB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,gBAAgB,EACzB,aAAa,SAAa,EAC1B,OAAO,GAAE,uBAA2D,GAClE,OAAO,CAAC,SAAS,CAAC,CAGpB;AAiDD,wBAAsB,cAAc,CACnC,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,QAAQ,EACnB,OAAO,CAAC,EAAE,gBAAgB,EAC1B,OAAO,CAAC,EAAE,uBAAuB,GAAG;IAAE,eAAe,CAAC,EAAE,wBAAwB,CAAA;CAAE,GAChF,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AAED,wBAAsB,oBAAoB,CACzC,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,EAAE,MAAM,EACX,QAAQ,CAAC,EAAE,QAAQ,EACnB,OAAO,CAAC,EAAE,gBAAgB,GACxB,OAAO,CAAC,oBAAoB,CAAC,CAE/B;AA2FD;;GAEG;AACH,wBAAsB,yBAAyB,CAC9C,eAAe,EAAE,MAAM,EAAE,EACzB,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,MAAsB,EAChC,QAAQ,CAAC,EAAE,QAAQ,GACjB,OAAO,CAAC,oBAAoB,CAAC,CA2C/B"}
@@ -38,6 +38,7 @@ import { createSyntheticSourceInfo } from "../source-info.js";
38
38
  import { time } from "../timings.js";
39
39
  import { registerReadClassifier } from "../tools/read-classifiers.js";
40
40
  import { validateMcpServerDeclaration } from "./builtin/mcp/config-schema.js";
41
+ import { cachedExtensionFactory, extensionModuleImporter, rememberExtensionFactory, } from "./extension-module-cache.js";
41
42
  import { DEFAULT_EXTENSION_SESSION_PROFILE, EMPTY_SESSION_CONTEXT } from "./types.js";
42
43
  function sessionProfile(options) {
43
44
  return {
@@ -145,37 +146,10 @@ function getAliases() {
145
146
  };
146
147
  return _aliases;
147
148
  }
148
- const MAX_EXTENSION_CACHE_CWD_ENTRIES = 16;
149
- let nextExtensionCacheGeneration = 0;
150
- const extensionCacheByCwd = new Map();
151
149
  // Bun's module registry must not own generation graphs. Live runtimes and the
152
150
  // existing factory cache retain wrappers; invalidation releases runtime ownership.
153
151
  const runtimeFactories = new WeakMap();
154
- export function clearExtensionCache() {
155
- extensionCacheByCwd.clear();
156
- }
157
- function useExtensionCacheCwd(cwd) {
158
- const resolvedCwd = resolvePath(cwd);
159
- const existingEntry = extensionCacheByCwd.get(resolvedCwd);
160
- if (existingEntry) {
161
- extensionCacheByCwd.delete(resolvedCwd);
162
- extensionCacheByCwd.set(resolvedCwd, existingEntry);
163
- return { cwd: existingEntry.cwd, generation: existingEntry.generation };
164
- }
165
- if (extensionCacheByCwd.size >= MAX_EXTENSION_CACHE_CWD_ENTRIES) {
166
- const leastRecentlyUsedCwd = extensionCacheByCwd.keys().next().value;
167
- if (leastRecentlyUsedCwd !== undefined) {
168
- extensionCacheByCwd.delete(leastRecentlyUsedCwd);
169
- }
170
- }
171
- const entry = {
172
- cwd: resolvedCwd,
173
- generation: nextExtensionCacheGeneration++,
174
- factories: new Map(),
175
- };
176
- extensionCacheByCwd.set(resolvedCwd, entry);
177
- return { cwd: entry.cwd, generation: entry.generation };
178
- }
152
+ export { clearExtensionCache, extensionModuleGenerationCount } from "./extension-module-cache.js";
179
153
  /**
180
154
  * Create a runtime with throwing stubs for action methods.
181
155
  * Runner.bindCore() replaces these with real implementations.
@@ -599,18 +573,10 @@ async function createExtensionModuleImporter() {
599
573
  : { alias: getAliases() }),
600
574
  });
601
575
  }
602
- function isCurrentCacheToken(cacheToken) {
603
- if (cacheToken === undefined)
604
- return false;
605
- const cacheEntry = extensionCacheByCwd.get(cacheToken.cwd);
606
- return cacheEntry?.generation === cacheToken.generation;
607
- }
608
- async function loadExtensionModule(extensionPath, getImporter, cacheToken) {
609
- if (isCurrentCacheToken(cacheToken)) {
610
- const cachedFactory = extensionCacheByCwd.get(cacheToken.cwd)?.factories.get(extensionPath);
611
- if (cachedFactory) {
612
- return cachedFactory;
613
- }
576
+ async function loadExtensionModule(extensionPath, getImporter) {
577
+ const cachedFactory = cachedExtensionFactory(extensionPath);
578
+ if (cachedFactory) {
579
+ return cachedFactory;
614
580
  }
615
581
  const importer = await getImporter();
616
582
  const module = await importer.import(extensionPath, { default: true });
@@ -618,9 +584,7 @@ async function loadExtensionModule(extensionPath, getImporter, cacheToken) {
618
584
  if (typeof factory !== "function") {
619
585
  return undefined;
620
586
  }
621
- if (isCurrentCacheToken(cacheToken)) {
622
- extensionCacheByCwd.get(cacheToken.cwd)?.factories.set(extensionPath, factory);
623
- }
587
+ rememberExtensionFactory(extensionPath, factory, importer);
624
588
  return factory;
625
589
  }
626
590
  /**
@@ -673,11 +637,10 @@ async function initializeExtension(factory, extensionPath, resolvedPath, cwd, ev
673
637
  time(`${extensionPath} factory`, "extensions");
674
638
  return extension;
675
639
  }
676
- async function loadExtension(extensionPath, cwd, eventBus, runtime, getImporter, factoryResolver, cacheToken, session = DEFAULT_EXTENSION_SESSION_PROFILE) {
640
+ async function loadExtension(extensionPath, cwd, eventBus, runtime, getImporter, factoryResolver, session = DEFAULT_EXTENSION_SESSION_PROFILE) {
677
641
  const resolvedPath = resolvePath(extensionPath, cwd, { normalizeUnicodeSpaces: true });
678
642
  try {
679
- const factory = factoryResolver?.(extensionPath, resolvedPath) ??
680
- (await loadExtensionModule(resolvedPath, getImporter, cacheToken));
643
+ const factory = factoryResolver?.(extensionPath, resolvedPath) ?? (await loadExtensionModule(resolvedPath, getImporter));
681
644
  time(`${extensionPath} module import`, "extensions");
682
645
  if (!factory) {
683
646
  return { extension: null, error: `Extension does not export a valid factory function: ${extensionPath}` };
@@ -700,21 +663,16 @@ export async function loadExtensionFromFactory(factory, cwd, eventBus, runtime,
700
663
  /**
701
664
  * Load extensions from paths.
702
665
  */
703
- async function loadExtensionsInternal(paths, cwd, eventBus, runtime, options, useCache = false) {
666
+ async function loadExtensionsInternal(paths, cwd, eventBus, runtime, options) {
704
667
  const session = sessionProfile(options);
705
668
  const extensions = [];
706
669
  const errors = [];
707
- const cacheToken = useCache ? useExtensionCacheCwd(cwd) : undefined;
708
- const resolvedCwd = cacheToken?.cwd ?? resolvePath(cwd);
670
+ const resolvedCwd = resolvePath(cwd);
709
671
  const resolvedEventBus = eventBus ?? createEventBus();
710
672
  const resolvedRuntime = runtime ?? createExtensionRuntime();
711
- let importer;
712
- const getImporter = () => {
713
- importer ??= createExtensionModuleImporter();
714
- return importer;
715
- };
673
+ const getImporter = () => extensionModuleImporter(createExtensionModuleImporter);
716
674
  for (const extPath of paths) {
717
- const { extension, error } = await loadExtension(extPath, resolvedCwd, resolvedEventBus, resolvedRuntime, getImporter, options?.factoryResolver, cacheToken, session);
675
+ const { extension, error } = await loadExtension(extPath, resolvedCwd, resolvedEventBus, resolvedRuntime, getImporter, options?.factoryResolver, session);
718
676
  if (error) {
719
677
  errors.push({ path: extPath, error });
720
678
  continue;
@@ -734,7 +692,7 @@ export async function loadExtensions(paths, cwd, eventBus, runtime, options) {
734
692
  return loadExtensionsInternal(paths, cwd, eventBus, runtime, options);
735
693
  }
736
694
  export async function loadExtensionsCached(paths, cwd, eventBus, runtime) {
737
- return loadExtensionsInternal(paths, cwd, eventBus, runtime, undefined, true);
695
+ return loadExtensionsInternal(paths, cwd, eventBus, runtime);
738
696
  }
739
697
  function isExtensionFile(name) {
740
698
  return name.endsWith(".ts") || name.endsWith(".js");