@abide/abide 0.28.0

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 (562) hide show
  1. package/CHANGELOG.md +607 -0
  2. package/LICENSE +21 -0
  3. package/README.md +154 -0
  4. package/bin/abide.ts +212 -0
  5. package/package.json +155 -0
  6. package/src/abideLsp.ts +211 -0
  7. package/src/abideModules.d.ts +8 -0
  8. package/src/abideResolverPlugin.ts +923 -0
  9. package/src/appEntry.ts +151 -0
  10. package/src/assets/app.html +12 -0
  11. package/src/build.ts +143 -0
  12. package/src/buildCli.ts +127 -0
  13. package/src/buildDisconnected.ts +118 -0
  14. package/src/bundleApp.ts +147 -0
  15. package/src/bundleDisconnectedEntry.ts +14 -0
  16. package/src/checkAbide.ts +77 -0
  17. package/src/cliEntry.ts +25 -0
  18. package/src/clientBuildPlugins.ts +33 -0
  19. package/src/clientEntry.ts +17 -0
  20. package/src/compile.ts +63 -0
  21. package/src/controlServerWorker.ts +426 -0
  22. package/src/devEntry.ts +250 -0
  23. package/src/discoveryEntry.ts +81 -0
  24. package/src/lib/bundle/BundleMenu.ts +12 -0
  25. package/src/lib/bundle/BundleMenuItem.ts +25 -0
  26. package/src/lib/bundle/BundleWindow.ts +37 -0
  27. package/src/lib/bundle/WEBVIEW_BUILD_REVISION.ts +9 -0
  28. package/src/lib/bundle/WEBVIEW_VERSION.ts +7 -0
  29. package/src/lib/bundle/bindConnectedFlag.ts +29 -0
  30. package/src/lib/bundle/bindRequestNavigate.ts +34 -0
  31. package/src/lib/bundle/buildWebviewLib.ts +111 -0
  32. package/src/lib/bundle/bundled.ts +35 -0
  33. package/src/lib/bundle/disconnected.abide +236 -0
  34. package/src/lib/bundle/disconnected.css +9 -0
  35. package/src/lib/bundle/ensureWebviewLib.ts +20 -0
  36. package/src/lib/bundle/exitWithParent.ts +28 -0
  37. package/src/lib/bundle/infoPlist.ts +46 -0
  38. package/src/lib/bundle/installDownloads.ts +24 -0
  39. package/src/lib/bundle/installMacMenu.ts +39 -0
  40. package/src/lib/bundle/listenLocalControlServer.ts +19 -0
  41. package/src/lib/bundle/native/abideMenu.mm +422 -0
  42. package/src/lib/bundle/native/webview.h +4557 -0
  43. package/src/lib/bundle/onMenu.ts +42 -0
  44. package/src/lib/bundle/openWebview.ts +104 -0
  45. package/src/lib/bundle/pngToIcns.ts +47 -0
  46. package/src/lib/bundle/probeAbideServer.ts +57 -0
  47. package/src/lib/bundle/resolveServerBinary.ts +12 -0
  48. package/src/lib/bundle/resolveWebviewLib.ts +53 -0
  49. package/src/lib/bundle/serverBinaryFilename.ts +8 -0
  50. package/src/lib/bundle/signMacApp.ts +37 -0
  51. package/src/lib/bundle/spawnEmbeddedServer.ts +64 -0
  52. package/src/lib/bundle/stableLocalPort.ts +19 -0
  53. package/src/lib/bundle/waitForServer.ts +23 -0
  54. package/src/lib/bundle/webviewCachePath.ts +23 -0
  55. package/src/lib/bundle/webviewLibName.ts +11 -0
  56. package/src/lib/cli/connectToServer.ts +23 -0
  57. package/src/lib/cli/createClient.ts +108 -0
  58. package/src/lib/cli/dispatchCommand.ts +71 -0
  59. package/src/lib/cli/loadEnvFromBinaryDir.ts +15 -0
  60. package/src/lib/cli/parseArgvForRpc.ts +100 -0
  61. package/src/lib/cli/printHelp.ts +119 -0
  62. package/src/lib/cli/printSessionHelp.ts +27 -0
  63. package/src/lib/cli/printSessionStatus.ts +21 -0
  64. package/src/lib/cli/printTrimmed.ts +8 -0
  65. package/src/lib/cli/printValue.ts +10 -0
  66. package/src/lib/cli/resolveCliTarget.ts +48 -0
  67. package/src/lib/cli/runCli.ts +176 -0
  68. package/src/lib/cli/runSession.ts +108 -0
  69. package/src/lib/cli/startLocalInstance.ts +14 -0
  70. package/src/lib/cli/tokenizeLine.ts +51 -0
  71. package/src/lib/cli/types/CliManifest.ts +9 -0
  72. package/src/lib/cli/types/CliManifestEntry.ts +17 -0
  73. package/src/lib/cli/types/CliTarget.ts +13 -0
  74. package/src/lib/mcp/annotationsForMethod.ts +29 -0
  75. package/src/lib/mcp/createMcpResourceServer.ts +102 -0
  76. package/src/lib/mcp/createMcpServer.ts +48 -0
  77. package/src/lib/mcp/dispatchMcpRequest.ts +138 -0
  78. package/src/lib/mcp/mcpResourceServerSlot.ts +18 -0
  79. package/src/lib/mcp/mcpSurface.ts +295 -0
  80. package/src/lib/mcp/toolResultFromResponse.ts +66 -0
  81. package/src/lib/mcp/types/JsonRpcRequest.ts +12 -0
  82. package/src/lib/mcp/types/JsonRpcResponse.ts +20 -0
  83. package/src/lib/mcp/types/McpResourceContents.ts +10 -0
  84. package/src/lib/mcp/types/McpResourceDescriptor.ts +6 -0
  85. package/src/lib/mcp/types/McpResourceServer.ts +12 -0
  86. package/src/lib/mcp/types/McpServer.ts +9 -0
  87. package/src/lib/mcp/types/McpServerOptions.ts +16 -0
  88. package/src/lib/server/AppModule.ts +47 -0
  89. package/src/lib/server/DELETE.ts +10 -0
  90. package/src/lib/server/GET.ts +10 -0
  91. package/src/lib/server/HEAD.ts +10 -0
  92. package/src/lib/server/PATCH.ts +10 -0
  93. package/src/lib/server/POST.ts +10 -0
  94. package/src/lib/server/PUT.ts +10 -0
  95. package/src/lib/server/agent.ts +86 -0
  96. package/src/lib/server/appDataDir.ts +16 -0
  97. package/src/lib/server/cli/buildEnvContent.ts +19 -0
  98. package/src/lib/server/cli/createTarGz.ts +77 -0
  99. package/src/lib/server/cli/handleCliDownload.ts +150 -0
  100. package/src/lib/server/cli/handleCliInstall.ts +37 -0
  101. package/src/lib/server/cli/installScript.ts +31 -0
  102. package/src/lib/server/cli/maxSourceMtime.ts +26 -0
  103. package/src/lib/server/cookies.ts +30 -0
  104. package/src/lib/server/env.ts +51 -0
  105. package/src/lib/server/error.ts +73 -0
  106. package/src/lib/server/json.ts +42 -0
  107. package/src/lib/server/jsonl.ts +47 -0
  108. package/src/lib/server/prompts/definePrompt.ts +21 -0
  109. package/src/lib/server/prompts/promptRegistry.ts +9 -0
  110. package/src/lib/server/prompts/registerPrompt.ts +6 -0
  111. package/src/lib/server/prompts/renderPromptTemplate.ts +17 -0
  112. package/src/lib/server/prompts/types/Prompt.ts +13 -0
  113. package/src/lib/server/prompts/types/PromptOptions.ts +12 -0
  114. package/src/lib/server/prompts/types/PromptRegistryEntry.ts +13 -0
  115. package/src/lib/server/prompts/types/PromptRoutes.ts +10 -0
  116. package/src/lib/server/reachable.ts +45 -0
  117. package/src/lib/server/redirect.ts +43 -0
  118. package/src/lib/server/request.ts +19 -0
  119. package/src/lib/server/rpc/defineVerb.ts +210 -0
  120. package/src/lib/server/rpc/dispatchVerbInProcess.ts +46 -0
  121. package/src/lib/server/rpc/findVerbByCommandName.ts +18 -0
  122. package/src/lib/server/rpc/parseArgs.ts +127 -0
  123. package/src/lib/server/rpc/readBodyWithinLimit.ts +44 -0
  124. package/src/lib/server/rpc/registerVerb.ts +6 -0
  125. package/src/lib/server/rpc/runWithVerbTimeout.ts +49 -0
  126. package/src/lib/server/rpc/types/RemoteHandler.ts +27 -0
  127. package/src/lib/server/rpc/types/RemoteRoutes.ts +13 -0
  128. package/src/lib/server/rpc/types/TypedResponse.ts +18 -0
  129. package/src/lib/server/rpc/types/VerbHelper.ts +87 -0
  130. package/src/lib/server/rpc/types/VerbRegistryEntry.ts +35 -0
  131. package/src/lib/server/rpc/unprocessed.ts +14 -0
  132. package/src/lib/server/rpc/verbRegistry.ts +11 -0
  133. package/src/lib/server/runtime/DEFAULT_PORT.ts +6 -0
  134. package/src/lib/server/runtime/DEV_READY_MESSAGE.ts +6 -0
  135. package/src/lib/server/runtime/DEV_REBUILD_MESSAGE.ts +4 -0
  136. package/src/lib/server/runtime/DEV_RELOAD_CLIENT_SCRIPT.ts +107 -0
  137. package/src/lib/server/runtime/SSR_SWAP_SCRIPT.ts +16 -0
  138. package/src/lib/server/runtime/acceptsGzip.ts +24 -0
  139. package/src/lib/server/runtime/buildCacheSnapshot.ts +61 -0
  140. package/src/lib/server/runtime/buildHealthPayload.ts +34 -0
  141. package/src/lib/server/runtime/buildInspectorSurface.ts +37 -0
  142. package/src/lib/server/runtime/buildOpenApiSpec.ts +106 -0
  143. package/src/lib/server/runtime/cacheControlForAsset.ts +22 -0
  144. package/src/lib/server/runtime/containsTraversal.ts +37 -0
  145. package/src/lib/server/runtime/createAppAssetServer.ts +76 -0
  146. package/src/lib/server/runtime/createAssetHeaderCache.ts +31 -0
  147. package/src/lib/server/runtime/createPublicAssetServer.ts +67 -0
  148. package/src/lib/server/runtime/createReachable.ts +109 -0
  149. package/src/lib/server/runtime/createRouteDispatcher.ts +127 -0
  150. package/src/lib/server/runtime/createServer.ts +674 -0
  151. package/src/lib/server/runtime/createUiPageRenderer.ts +181 -0
  152. package/src/lib/server/runtime/crossOriginForbidden.ts +17 -0
  153. package/src/lib/server/runtime/crossOriginGate.ts +29 -0
  154. package/src/lib/server/runtime/devClientFingerprint.ts +117 -0
  155. package/src/lib/server/runtime/devHotModuleResponse.ts +40 -0
  156. package/src/lib/server/runtime/devReloadResponse.ts +41 -0
  157. package/src/lib/server/runtime/disableIdleTimeoutForStream.ts +27 -0
  158. package/src/lib/server/runtime/envSchemaStore.ts +15 -0
  159. package/src/lib/server/runtime/findOpenPort.ts +21 -0
  160. package/src/lib/server/runtime/getActiveServer.ts +6 -0
  161. package/src/lib/server/runtime/globToPathSet.ts +29 -0
  162. package/src/lib/server/runtime/gzipResponse.ts +46 -0
  163. package/src/lib/server/runtime/inProcessServer.ts +20 -0
  164. package/src/lib/server/runtime/internalErrorResponse.ts +25 -0
  165. package/src/lib/server/runtime/isCrossOriginRequest.ts +23 -0
  166. package/src/lib/server/runtime/listenOnOpenPort.ts +36 -0
  167. package/src/lib/server/runtime/logExposedSurfaces.ts +156 -0
  168. package/src/lib/server/runtime/maybeMountInspector.ts +97 -0
  169. package/src/lib/server/runtime/mimeForExtension.ts +14 -0
  170. package/src/lib/server/runtime/pageUrlFromStore.ts +15 -0
  171. package/src/lib/server/runtime/parseIdleTimeout.ts +10 -0
  172. package/src/lib/server/runtime/parsePort.ts +11 -0
  173. package/src/lib/server/runtime/registryManifests.ts +66 -0
  174. package/src/lib/server/runtime/requestContext.ts +5 -0
  175. package/src/lib/server/runtime/resolvePageSnapshot.ts +25 -0
  176. package/src/lib/server/runtime/respondWithEmbeddedAsset.ts +18 -0
  177. package/src/lib/server/runtime/runWithRequestScope.ts +150 -0
  178. package/src/lib/server/runtime/safeJsonForScript.ts +17 -0
  179. package/src/lib/server/runtime/serializeCacheSnapshot.ts +45 -0
  180. package/src/lib/server/runtime/serverSlot.ts +13 -0
  181. package/src/lib/server/runtime/setActiveServer.ts +6 -0
  182. package/src/lib/server/runtime/snapshotEntryFromCache.ts +83 -0
  183. package/src/lib/server/runtime/streamCacheResolutions.ts +37 -0
  184. package/src/lib/server/runtime/streamFromIterator.ts +86 -0
  185. package/src/lib/server/runtime/types/Assets.ts +6 -0
  186. package/src/lib/server/runtime/types/DevReloadStamp.ts +18 -0
  187. package/src/lib/server/runtime/types/InspectorCacheEntry.ts +24 -0
  188. package/src/lib/server/runtime/types/InspectorCacheSnapshot.ts +11 -0
  189. package/src/lib/server/runtime/types/InspectorContext.ts +30 -0
  190. package/src/lib/server/runtime/types/InspectorSocket.ts +17 -0
  191. package/src/lib/server/runtime/types/InspectorSurface.ts +13 -0
  192. package/src/lib/server/runtime/types/InspectorVerb.ts +27 -0
  193. package/src/lib/server/runtime/types/RequestStore.ts +55 -0
  194. package/src/lib/server/runtime/warnUnguardedMcp.ts +32 -0
  195. package/src/lib/server/runtime/withResponseDefaults.ts +24 -0
  196. package/src/lib/server/server.ts +33 -0
  197. package/src/lib/server/socket.ts +32 -0
  198. package/src/lib/server/sockets/createSocketDispatcher.ts +337 -0
  199. package/src/lib/server/sockets/defineSocket.ts +179 -0
  200. package/src/lib/server/sockets/lookupSocket.ts +6 -0
  201. package/src/lib/server/sockets/registerSocket.ts +6 -0
  202. package/src/lib/server/sockets/socketOperations.ts +36 -0
  203. package/src/lib/server/sockets/socketRegistry.ts +9 -0
  204. package/src/lib/server/sockets/types/Socket.ts +23 -0
  205. package/src/lib/server/sockets/types/SocketClientFrame.ts +19 -0
  206. package/src/lib/server/sockets/types/SocketOperation.ts +22 -0
  207. package/src/lib/server/sockets/types/SocketOptions.ts +26 -0
  208. package/src/lib/server/sockets/types/SocketRegistryEntry.ts +19 -0
  209. package/src/lib/server/sockets/types/SocketRoutes.ts +10 -0
  210. package/src/lib/server/sockets/types/SocketServerFrame.ts +24 -0
  211. package/src/lib/server/sse.ts +54 -0
  212. package/src/lib/shared/ABIDE_PACKAGE_NAME.ts +7 -0
  213. package/src/lib/shared/ABIDE_VERSION.ts +9 -0
  214. package/src/lib/shared/CACHE_CONTROL_VALUES.ts +16 -0
  215. package/src/lib/shared/CACHE_WRAPPED.ts +8 -0
  216. package/src/lib/shared/CLI_PATH.ts +7 -0
  217. package/src/lib/shared/DEV_HOT_PREFIX.ts +7 -0
  218. package/src/lib/shared/DEV_RELOAD_PATH.ts +6 -0
  219. package/src/lib/shared/HEALTH_PATH.ts +7 -0
  220. package/src/lib/shared/HttpError.ts +20 -0
  221. package/src/lib/shared/IDENTITY_PATH.ts +6 -0
  222. package/src/lib/shared/INSPECTOR_PATH.ts +7 -0
  223. package/src/lib/shared/NAV_HEADER.ts +8 -0
  224. package/src/lib/shared/OFFLINE_HEADER.ts +8 -0
  225. package/src/lib/shared/REMOTE_FUNCTION.ts +8 -0
  226. package/src/lib/shared/REPLAYABLE_METHODS.ts +12 -0
  227. package/src/lib/shared/SOCKETS_PATH.ts +7 -0
  228. package/src/lib/shared/STREAMING_CONTENT_TYPES.ts +11 -0
  229. package/src/lib/shared/SocketDisconnectedError.ts +13 -0
  230. package/src/lib/shared/TEXT_PLAIN.ts +7 -0
  231. package/src/lib/shared/abideImportName.ts +44 -0
  232. package/src/lib/shared/abideLog.ts +38 -0
  233. package/src/lib/shared/activeCacheStore.ts +20 -0
  234. package/src/lib/shared/activePage.ts +25 -0
  235. package/src/lib/shared/appDataDir.ts +34 -0
  236. package/src/lib/shared/appNameSlot.ts +10 -0
  237. package/src/lib/shared/basePath.ts +10 -0
  238. package/src/lib/shared/basePathFromAppUrl.ts +20 -0
  239. package/src/lib/shared/baseSlot.ts +14 -0
  240. package/src/lib/shared/binaryDirEnvPath.ts +12 -0
  241. package/src/lib/shared/browserClientFlags.ts +10 -0
  242. package/src/lib/shared/buildRpcProxy.ts +39 -0
  243. package/src/lib/shared/buildRpcRequest.ts +70 -0
  244. package/src/lib/shared/buildSocketOverChannel.ts +58 -0
  245. package/src/lib/shared/bundleLayout.ts +36 -0
  246. package/src/lib/shared/cache.ts +951 -0
  247. package/src/lib/shared/cacheEntryFromSnapshot.ts +59 -0
  248. package/src/lib/shared/cacheStoreSlot.ts +16 -0
  249. package/src/lib/shared/cacheStores.ts +10 -0
  250. package/src/lib/shared/canonicalJson.ts +63 -0
  251. package/src/lib/shared/carriesBodyArgs.ts +13 -0
  252. package/src/lib/shared/clearLastConnection.ts +7 -0
  253. package/src/lib/shared/commandNameForUrl.ts +17 -0
  254. package/src/lib/shared/createCacheStore.ts +104 -0
  255. package/src/lib/shared/createChannelLog.ts +122 -0
  256. package/src/lib/shared/createLifecycleChannel.ts +56 -0
  257. package/src/lib/shared/createLivenessWatch.ts +118 -0
  258. package/src/lib/shared/createPushIterator.ts +127 -0
  259. package/src/lib/shared/createRemoteFunction.ts +122 -0
  260. package/src/lib/shared/createSubscriber.ts +55 -0
  261. package/src/lib/shared/createTraceContext.ts +21 -0
  262. package/src/lib/shared/dataDirEnvPath.ts +12 -0
  263. package/src/lib/shared/decodeResponse.ts +47 -0
  264. package/src/lib/shared/detectTarget.ts +27 -0
  265. package/src/lib/shared/detectVerbMethod.ts +17 -0
  266. package/src/lib/shared/emitLogRecord.ts +190 -0
  267. package/src/lib/shared/exeSuffix.ts +9 -0
  268. package/src/lib/shared/exitOnBuildFailure.ts +17 -0
  269. package/src/lib/shared/extraForwardHeaders.ts +16 -0
  270. package/src/lib/shared/fileStem.ts +9 -0
  271. package/src/lib/shared/findExportCallSite.ts +476 -0
  272. package/src/lib/shared/formatTraceparent.ts +6 -0
  273. package/src/lib/shared/forwardHeaders.ts +44 -0
  274. package/src/lib/shared/getRemoteMeta.ts +5 -0
  275. package/src/lib/shared/globalCacheStore.ts +15 -0
  276. package/src/lib/shared/globalCacheStoreSlot.ts +14 -0
  277. package/src/lib/shared/health.ts +179 -0
  278. package/src/lib/shared/healthReadSlot.ts +11 -0
  279. package/src/lib/shared/healthSeedSlot.ts +12 -0
  280. package/src/lib/shared/html.ts +38 -0
  281. package/src/lib/shared/importNamesToStrip.ts +13 -0
  282. package/src/lib/shared/invalidateEvent.ts +11 -0
  283. package/src/lib/shared/invalidateTripwire.ts +40 -0
  284. package/src/lib/shared/isAbideHealthPayload.ts +11 -0
  285. package/src/lib/shared/isCompileTarget.ts +15 -0
  286. package/src/lib/shared/isDebugEnabled.ts +26 -0
  287. package/src/lib/shared/isDebugNegated.ts +19 -0
  288. package/src/lib/shared/isModuleNotFound.ts +16 -0
  289. package/src/lib/shared/isReadOnlyMethod.ts +14 -0
  290. package/src/lib/shared/isReplayableMethod.ts +7 -0
  291. package/src/lib/shared/isStreamingResponse.ts +11 -0
  292. package/src/lib/shared/isSubscribable.ts +15 -0
  293. package/src/lib/shared/jsonSchemaForPromptArguments.ts +29 -0
  294. package/src/lib/shared/jsonSchemaForSchema.ts +39 -0
  295. package/src/lib/shared/jsonlErrorFrame.ts +24 -0
  296. package/src/lib/shared/keyForRemoteCall.ts +29 -0
  297. package/src/lib/shared/keyMatchesPrefix.ts +9 -0
  298. package/src/lib/shared/lastConnectionPath.ts +7 -0
  299. package/src/lib/shared/layoutChainForRoute.ts +22 -0
  300. package/src/lib/shared/loadEnvFile.ts +17 -0
  301. package/src/lib/shared/loadEnvFromDataDir.ts +14 -0
  302. package/src/lib/shared/log.ts +24 -0
  303. package/src/lib/shared/logClosingRecord.ts +28 -0
  304. package/src/lib/shared/logTapSlot.ts +13 -0
  305. package/src/lib/shared/manifestModule.ts +39 -0
  306. package/src/lib/shared/matchesDebugPattern.ts +16 -0
  307. package/src/lib/shared/memoizeByKey.ts +32 -0
  308. package/src/lib/shared/normalizeTarget.ts +10 -0
  309. package/src/lib/shared/online.ts +51 -0
  310. package/src/lib/shared/page.ts +30 -0
  311. package/src/lib/shared/pageSlot.ts +17 -0
  312. package/src/lib/shared/pageUrlForFile.ts +14 -0
  313. package/src/lib/shared/parseBoundedEnvInt.ts +20 -0
  314. package/src/lib/shared/parseDebugPatterns.ts +21 -0
  315. package/src/lib/shared/parseEnv.ts +30 -0
  316. package/src/lib/shared/parsePromptMarkdown.ts +35 -0
  317. package/src/lib/shared/parseRouteSegments.ts +22 -0
  318. package/src/lib/shared/parseTraceparent.ts +26 -0
  319. package/src/lib/shared/pending.ts +30 -0
  320. package/src/lib/shared/prepareRpcModule.ts +59 -0
  321. package/src/lib/shared/prepareSocketModule.ts +49 -0
  322. package/src/lib/shared/probeRegistries.ts +68 -0
  323. package/src/lib/shared/producerKey.ts +32 -0
  324. package/src/lib/shared/programNameForPackage.ts +14 -0
  325. package/src/lib/shared/promptNameForFile.ts +10 -0
  326. package/src/lib/shared/queryStringFromArgs.ts +27 -0
  327. package/src/lib/shared/randomHexId.ts +14 -0
  328. package/src/lib/shared/readEnvFile.ts +15 -0
  329. package/src/lib/shared/readLastConnection.ts +18 -0
  330. package/src/lib/shared/readPackageJson.ts +9 -0
  331. package/src/lib/shared/recordRemoteMeta.ts +5 -0
  332. package/src/lib/shared/refreshing.ts +31 -0
  333. package/src/lib/shared/remoteMetaStore.ts +16 -0
  334. package/src/lib/shared/requestScopeSlot.ts +15 -0
  335. package/src/lib/shared/resolveClientFlags.ts +20 -0
  336. package/src/lib/shared/responseErrorText.ts +9 -0
  337. package/src/lib/shared/rpcTimeoutSlot.ts +9 -0
  338. package/src/lib/shared/rpcUrlForFile.ts +19 -0
  339. package/src/lib/shared/runningAsStandaloneBinary.ts +13 -0
  340. package/src/lib/shared/selectorMatcher.ts +68 -0
  341. package/src/lib/shared/selectorPrefix.ts +39 -0
  342. package/src/lib/shared/serializeEnv.ts +18 -0
  343. package/src/lib/shared/setAppName.ts +5 -0
  344. package/src/lib/shared/setBaseResolver.ts +6 -0
  345. package/src/lib/shared/setCacheStoreResolver.ts +6 -0
  346. package/src/lib/shared/setGlobalCacheStoreResolver.ts +6 -0
  347. package/src/lib/shared/setPageResolver.ts +7 -0
  348. package/src/lib/shared/setRequestScopeResolver.ts +6 -0
  349. package/src/lib/shared/snippet.ts +25 -0
  350. package/src/lib/shared/socketNameForFile.ts +11 -0
  351. package/src/lib/shared/socketTapSlot.ts +12 -0
  352. package/src/lib/shared/sseErrorFrame.ts +29 -0
  353. package/src/lib/shared/streamResponse.ts +169 -0
  354. package/src/lib/shared/stripImport.ts +27 -0
  355. package/src/lib/shared/subscribableFromResponse.ts +51 -0
  356. package/src/lib/shared/tailProbeSlot.ts +16 -0
  357. package/src/lib/shared/toBunRoutePattern.ts +28 -0
  358. package/src/lib/shared/toScopeSet.ts +4 -0
  359. package/src/lib/shared/trace.ts +16 -0
  360. package/src/lib/shared/types/CacheEntry.ts +84 -0
  361. package/src/lib/shared/types/CacheInvalidation.ts +9 -0
  362. package/src/lib/shared/types/CacheOnContext.ts +25 -0
  363. package/src/lib/shared/types/CacheOptions.ts +39 -0
  364. package/src/lib/shared/types/CacheSelector.ts +17 -0
  365. package/src/lib/shared/types/CacheSnapshot.ts +16 -0
  366. package/src/lib/shared/types/CacheSnapshotEntry.ts +17 -0
  367. package/src/lib/shared/types/CacheStats.ts +13 -0
  368. package/src/lib/shared/types/CacheStore.ts +39 -0
  369. package/src/lib/shared/types/ChannelLog.ts +13 -0
  370. package/src/lib/shared/types/ClientFlags.ts +11 -0
  371. package/src/lib/shared/types/CompileTarget.ts +6 -0
  372. package/src/lib/shared/types/FrameworkLog.ts +13 -0
  373. package/src/lib/shared/types/HttpVerb.ts +1 -0
  374. package/src/lib/shared/types/LastConnection.ts +9 -0
  375. package/src/lib/shared/types/Log.ts +13 -0
  376. package/src/lib/shared/types/LogRecord.ts +42 -0
  377. package/src/lib/shared/types/LogVoice.ts +7 -0
  378. package/src/lib/shared/types/PageSnapshot.ts +14 -0
  379. package/src/lib/shared/types/PromptArgument.ts +12 -0
  380. package/src/lib/shared/types/RawRemoteFunction.ts +14 -0
  381. package/src/lib/shared/types/RemoteCallable.ts +12 -0
  382. package/src/lib/shared/types/RemoteFunction.ts +47 -0
  383. package/src/lib/shared/types/ReplayableMethod.ts +7 -0
  384. package/src/lib/shared/types/RequestScopeInfo.ts +16 -0
  385. package/src/lib/shared/types/RpcInvoker.ts +6 -0
  386. package/src/lib/shared/types/SocketChannel.ts +17 -0
  387. package/src/lib/shared/types/SocketSubCallbacks.ts +13 -0
  388. package/src/lib/shared/types/StandardSchemaV1.ts +56 -0
  389. package/src/lib/shared/types/StreamedResolution.ts +10 -0
  390. package/src/lib/shared/types/Subscribable.ts +26 -0
  391. package/src/lib/shared/types/TailHooks.ts +12 -0
  392. package/src/lib/shared/types/TailOptions.ts +10 -0
  393. package/src/lib/shared/types/TraceContext.ts +17 -0
  394. package/src/lib/shared/url.ts +118 -0
  395. package/src/lib/shared/withBase.ts +11 -0
  396. package/src/lib/shared/withBaseUrl.ts +17 -0
  397. package/src/lib/shared/withJsonSchema.ts +21 -0
  398. package/src/lib/shared/writeDts.ts +12 -0
  399. package/src/lib/shared/writeHealthDts.ts +36 -0
  400. package/src/lib/shared/writeLastConnection.ts +13 -0
  401. package/src/lib/shared/writePublicAssetsDts.ts +31 -0
  402. package/src/lib/shared/writeRoutesDts.ts +73 -0
  403. package/src/lib/shared/writeRpcDts.ts +49 -0
  404. package/src/lib/shared/writeTestRpcDts.ts +45 -0
  405. package/src/lib/shared/writeTestSocketsDts.ts +34 -0
  406. package/src/lib/test/assertAgentFrameConformance.ts +73 -0
  407. package/src/lib/test/createScriptedSurface.ts +45 -0
  408. package/src/lib/test/createTestApp.ts +203 -0
  409. package/src/lib/test/createTestSocketChannel.ts +142 -0
  410. package/src/lib/ui/README.md +86 -0
  411. package/src/lib/ui/compile/SSR_ESCAPE.ts +25 -0
  412. package/src/lib/ui/compile/UI_RUNTIME_IMPORTS.ts +36 -0
  413. package/src/lib/ui/compile/VOID_TAGS.ts +21 -0
  414. package/src/lib/ui/compile/abideUiPlugin.ts +65 -0
  415. package/src/lib/ui/compile/analyzeComponent.ts +117 -0
  416. package/src/lib/ui/compile/assetModulesFile.ts +32 -0
  417. package/src/lib/ui/compile/branchElements.ts +50 -0
  418. package/src/lib/ui/compile/collectAbideDiagnostics.ts +59 -0
  419. package/src/lib/ui/compile/compileComponent.ts +20 -0
  420. package/src/lib/ui/compile/compileModule.ts +116 -0
  421. package/src/lib/ui/compile/compileSSR.ts +36 -0
  422. package/src/lib/ui/compile/compileShadow.ts +352 -0
  423. package/src/lib/ui/compile/createShadowLanguageService.ts +197 -0
  424. package/src/lib/ui/compile/createShadowProgram.ts +96 -0
  425. package/src/lib/ui/compile/decodeHtmlEntities.ts +49 -0
  426. package/src/lib/ui/compile/desugarSignals.ts +133 -0
  427. package/src/lib/ui/compile/escapeHtml.ts +15 -0
  428. package/src/lib/ui/compile/generateBuild.ts +638 -0
  429. package/src/lib/ui/compile/generateSSR.ts +380 -0
  430. package/src/lib/ui/compile/groupBindParts.ts +28 -0
  431. package/src/lib/ui/compile/hoistCells.ts +120 -0
  432. package/src/lib/ui/compile/loadShadowTsConfig.ts +31 -0
  433. package/src/lib/ui/compile/lowerDocAccess.ts +202 -0
  434. package/src/lib/ui/compile/nearestProjectRoot.ts +16 -0
  435. package/src/lib/ui/compile/parseTemplate.ts +396 -0
  436. package/src/lib/ui/compile/partitionSlots.ts +36 -0
  437. package/src/lib/ui/compile/prepareNestedScript.ts +42 -0
  438. package/src/lib/ui/compile/remapShadowDiagnostic.ts +30 -0
  439. package/src/lib/ui/compile/renameSignalRefs.ts +85 -0
  440. package/src/lib/ui/compile/resolveAbideImports.ts +29 -0
  441. package/src/lib/ui/compile/scopeCss.ts +115 -0
  442. package/src/lib/ui/compile/shadowNaming.ts +11 -0
  443. package/src/lib/ui/compile/sourceToShadowOffset.ts +24 -0
  444. package/src/lib/ui/compile/staticAttrValue.ts +13 -0
  445. package/src/lib/ui/compile/stripEffects.ts +32 -0
  446. package/src/lib/ui/compile/types/AbideDiagnostic.ts +14 -0
  447. package/src/lib/ui/compile/types/AnalyzedComponent.ts +25 -0
  448. package/src/lib/ui/compile/types/CompiledShadow.ts +15 -0
  449. package/src/lib/ui/compile/types/TemplateAttr.ts +16 -0
  450. package/src/lib/ui/compile/types/TemplateNode.ts +78 -0
  451. package/src/lib/ui/compile/types/TextPart.ts +8 -0
  452. package/src/lib/ui/derived.ts +28 -0
  453. package/src/lib/ui/doc.ts +15 -0
  454. package/src/lib/ui/dom/appendSnippet.ts +34 -0
  455. package/src/lib/ui/dom/appendStatic.ts +27 -0
  456. package/src/lib/ui/dom/appendText.ts +114 -0
  457. package/src/lib/ui/dom/applyResolved.ts +72 -0
  458. package/src/lib/ui/dom/attach.ts +20 -0
  459. package/src/lib/ui/dom/attr.ts +19 -0
  460. package/src/lib/ui/dom/awaitBlock.ts +224 -0
  461. package/src/lib/ui/dom/cloneStatic.ts +52 -0
  462. package/src/lib/ui/dom/each.ts +115 -0
  463. package/src/lib/ui/dom/eachAsync.ts +153 -0
  464. package/src/lib/ui/dom/hydrate.ts +35 -0
  465. package/src/lib/ui/dom/mount.ts +29 -0
  466. package/src/lib/ui/dom/mountChild.ts +33 -0
  467. package/src/lib/ui/dom/on.ts +15 -0
  468. package/src/lib/ui/dom/openChild.ts +22 -0
  469. package/src/lib/ui/dom/openRoot.ts +20 -0
  470. package/src/lib/ui/dom/switchBlock.ts +75 -0
  471. package/src/lib/ui/dom/text.ts +20 -0
  472. package/src/lib/ui/dom/tryBlock.ts +112 -0
  473. package/src/lib/ui/dom/types/EachRow.ts +3 -0
  474. package/src/lib/ui/dom/types/SwitchCase.ts +6 -0
  475. package/src/lib/ui/dom/when.ts +73 -0
  476. package/src/lib/ui/effect.ts +16 -0
  477. package/src/lib/ui/installHotBridge.ts +73 -0
  478. package/src/lib/ui/matchRoute.ts +89 -0
  479. package/src/lib/ui/navigate.ts +17 -0
  480. package/src/lib/ui/probeNavigation.ts +33 -0
  481. package/src/lib/ui/remoteProxy.ts +97 -0
  482. package/src/lib/ui/renderChain.ts +50 -0
  483. package/src/lib/ui/renderToStream.ts +104 -0
  484. package/src/lib/ui/router.ts +286 -0
  485. package/src/lib/ui/runtime/OUTLET_TAG.ts +8 -0
  486. package/src/lib/ui/runtime/OWNER.ts +8 -0
  487. package/src/lib/ui/runtime/REACTIVE_CONTEXT.ts +14 -0
  488. package/src/lib/ui/runtime/RENDER.ts +23 -0
  489. package/src/lib/ui/runtime/RESUME.ts +16 -0
  490. package/src/lib/ui/runtime/applyPatchToTree.ts +41 -0
  491. package/src/lib/ui/runtime/claimChild.ts +10 -0
  492. package/src/lib/ui/runtime/clientPage.ts +16 -0
  493. package/src/lib/ui/runtime/createComputedNode.ts +16 -0
  494. package/src/lib/ui/runtime/createDoc.ts +177 -0
  495. package/src/lib/ui/runtime/createEffectNode.ts +58 -0
  496. package/src/lib/ui/runtime/createSignalNode.ts +16 -0
  497. package/src/lib/ui/runtime/detachLink.ts +21 -0
  498. package/src/lib/ui/runtime/endTracking.ts +24 -0
  499. package/src/lib/ui/runtime/enterRenderPass.ts +12 -0
  500. package/src/lib/ui/runtime/exitRenderPass.ts +7 -0
  501. package/src/lib/ui/runtime/firstOutlet.ts +22 -0
  502. package/src/lib/ui/runtime/flushEffects.ts +17 -0
  503. package/src/lib/ui/runtime/hotInstances.ts +10 -0
  504. package/src/lib/ui/runtime/hotReloadEnabled.ts +8 -0
  505. package/src/lib/ui/runtime/hotReplace.ts +25 -0
  506. package/src/lib/ui/runtime/nextBlockId.ts +11 -0
  507. package/src/lib/ui/runtime/pathExists.ts +23 -0
  508. package/src/lib/ui/runtime/readNode.ts +17 -0
  509. package/src/lib/ui/runtime/registerHotInstance.ts +23 -0
  510. package/src/lib/ui/runtime/runNode.ts +28 -0
  511. package/src/lib/ui/runtime/runtimePath.ts +9 -0
  512. package/src/lib/ui/runtime/scope.ts +24 -0
  513. package/src/lib/ui/runtime/toTeardown.ts +26 -0
  514. package/src/lib/ui/runtime/track.ts +58 -0
  515. package/src/lib/ui/runtime/trigger.ts +44 -0
  516. package/src/lib/ui/runtime/types/Cell.ts +5 -0
  517. package/src/lib/ui/runtime/types/Derived.ts +3 -0
  518. package/src/lib/ui/runtime/types/Doc.ts +19 -0
  519. package/src/lib/ui/runtime/types/EffectResult.ts +10 -0
  520. package/src/lib/ui/runtime/types/HotInstance.ts +14 -0
  521. package/src/lib/ui/runtime/types/NavVerdict.ts +9 -0
  522. package/src/lib/ui/runtime/types/Patch.ts +11 -0
  523. package/src/lib/ui/runtime/types/ReactiveLink.ts +21 -0
  524. package/src/lib/ui/runtime/types/ReactiveNode.ts +25 -0
  525. package/src/lib/ui/runtime/types/Route.ts +8 -0
  526. package/src/lib/ui/runtime/types/RouteLoader.ts +7 -0
  527. package/src/lib/ui/runtime/types/SsrRender.ts +22 -0
  528. package/src/lib/ui/runtime/types/State.ts +3 -0
  529. package/src/lib/ui/runtime/types/Teardown.ts +5 -0
  530. package/src/lib/ui/runtime/types/UiComponent.ts +16 -0
  531. package/src/lib/ui/runtime/types/UiProps.ts +15 -0
  532. package/src/lib/ui/runtime/unlinkDeps.ts +20 -0
  533. package/src/lib/ui/runtime/untrack.ts +20 -0
  534. package/src/lib/ui/runtime/valueAtPath.ts +18 -0
  535. package/src/lib/ui/runtime/writeNode.ts +16 -0
  536. package/src/lib/ui/socketChannel.ts +227 -0
  537. package/src/lib/ui/socketProxy.ts +25 -0
  538. package/src/lib/ui/startClient.ts +58 -0
  539. package/src/lib/ui/state.ts +25 -0
  540. package/src/lib/ui/tail.ts +324 -0
  541. package/src/lib/ui/types/Layouts.ts +9 -0
  542. package/src/lib/ui/types/Pages.ts +8 -0
  543. package/src/preload.ts +19 -0
  544. package/src/scaffold.ts +153 -0
  545. package/src/serverBuildPlugins.ts +19 -0
  546. package/src/serverEntry.ts +95 -0
  547. package/template/bunfig.toml +4 -0
  548. package/template/package.json +18 -0
  549. package/template/src/app.ts +28 -0
  550. package/template/src/bundle/icon.png +0 -0
  551. package/template/src/cli/banner.txt +3 -0
  552. package/template/src/cli/footer.txt +1 -0
  553. package/template/src/server/config.ts +17 -0
  554. package/template/src/server/rpc/getHello.ts +36 -0
  555. package/template/src/ui/Layout.abide +19 -0
  556. package/template/src/ui/app.css +21 -0
  557. package/template/src/ui/app.html +24 -0
  558. package/template/src/ui/pages/about/page.abide +9 -0
  559. package/template/src/ui/pages/page.abide +22 -0
  560. package/template/test/app.test.ts +30 -0
  561. package/template/tsconfig.json +18 -0
  562. package/tsconfig.app.json +17 -0
@@ -0,0 +1,45 @@
1
+ import { isReplayableMethod } from '../../shared/isReplayableMethod.ts'
2
+ import type { CacheEntry } from '../../shared/types/CacheEntry.ts'
3
+ import type { CacheSnapshot } from '../../shared/types/CacheSnapshot.ts'
4
+ import type { CacheSnapshotEntry } from '../../shared/types/CacheSnapshotEntry.ts'
5
+ import type { CacheStore } from '../../shared/types/CacheStore.ts'
6
+ import { snapshotEntryFromCache } from './snapshotEntryFromCache.ts'
7
+
8
+ /*
9
+ Partitions the request-scoped cache for SSR. Entries settled by the time
10
+ `render()` returns were consumed via `await` (render blocked on them) and ship
11
+ inline in the document's `__SSR__` blob. Entries still pending were consumed
12
+ via `{#await}` — render emitted their pending branch without blocking — so they
13
+ go to `pending` for the response streamer to drain and resolve over the wire.
14
+
15
+ Unlike the old buffer-everything path, this never awaits the pending promises:
16
+ that's the whole point of streaming. Settled entries are read concurrently (the
17
+ awaits are immediate since they're already resolved, but their body reads run in
18
+ parallel); pending entries are handed back as-is for the streamer to await one
19
+ chunk at a time.
20
+ */
21
+ export async function serializeCacheSnapshot(store: CacheStore): Promise<CacheSnapshot> {
22
+ const settled: CacheEntry[] = []
23
+ const pending: CacheEntry[] = []
24
+ for (const entry of store.entries.values()) {
25
+ /* Producer entries carry no wire request — nothing to rehydrate against, skip. */
26
+ if (!entry.request) {
27
+ continue
28
+ }
29
+ if (!isReplayableMethod(entry.request.method.toUpperCase())) {
30
+ continue
31
+ }
32
+ if (entry.settled) {
33
+ settled.push(entry)
34
+ } else {
35
+ pending.push(entry)
36
+ }
37
+ }
38
+ const snapshots = await Promise.all(
39
+ settled.map((entry) => snapshotEntryFromCache(store, entry)),
40
+ )
41
+ const inline = snapshots.filter(
42
+ (snapshot): snapshot is CacheSnapshotEntry => snapshot !== undefined,
43
+ )
44
+ return { inline, pending }
45
+ }
@@ -0,0 +1,13 @@
1
+ import type { Server } from 'bun'
2
+
3
+ /*
4
+ Internal holder for the active Bun.serve instance. setActiveServer is
5
+ called once from createServer after Bun.serve resolves; the public
6
+ `server()` function and any internal callers read through this slot
7
+ and throw when accessed before init completes. `Server<unknown>` matches
8
+ Bun's generic — ws.data is opaque to user code since the only ws path
9
+ is the framework-managed sockets dispatcher.
10
+ */
11
+ export const serverSlot: { active: Server<unknown> | undefined } = {
12
+ active: undefined,
13
+ }
@@ -0,0 +1,6 @@
1
+ import type { Server } from 'bun'
2
+ import { serverSlot } from './serverSlot.ts'
3
+
4
+ export function setActiveServer(server: Server<unknown>): void {
5
+ serverSlot.active = server
6
+ }
@@ -0,0 +1,83 @@
1
+ import { isReplayableMethod } from '../../shared/isReplayableMethod.ts'
2
+ import type { CacheEntry } from '../../shared/types/CacheEntry.ts'
3
+ import type { CacheSnapshotEntry } from '../../shared/types/CacheSnapshotEntry.ts'
4
+ import type { CacheStore } from '../../shared/types/CacheStore.ts'
5
+
6
+ /*
7
+ Awaits one cache entry and turns it into a wire-safe snapshot, or undefined
8
+ when it can't ship. Shared by the inline snapshot path (settled entries,
9
+ resolves immediately) and the streaming drain (pending {#await} entries,
10
+ resolves whenever the underlying fetch lands). Only replayable methods (see
11
+ REPLAYABLE_METHODS) with a textual Content-Type survive — writes must not
12
+ re-fire from a snapshot, body-carrying methods can't be replayed without the
13
+ original request body, and binary bodies don't round-trip through JSON.
14
+
15
+ Reads the body once and replaces the entry's promise with a string-bodied
16
+ Response so later `shareable()` clones operate on a buffered body instead of
17
+ teeing the original stream. Returns undefined on a rejected fetch (the client
18
+ falls back to a live re-fetch on cache miss) or when the entry was evicted /
19
+ replaced between resolution and read (a concurrent invalidate) so the snapshot
20
+ never ships a key that no longer matches the live store.
21
+ */
22
+ export async function snapshotEntryFromCache(
23
+ store: CacheStore,
24
+ entry: CacheEntry,
25
+ ): Promise<CacheSnapshotEntry | undefined> {
26
+ /* Producer entries have no wire request to replay — they never snapshot. */
27
+ if (!entry.request) {
28
+ return undefined
29
+ }
30
+ const method = entry.request.method.toUpperCase()
31
+ if (!isReplayableMethod(method)) {
32
+ return undefined
33
+ }
34
+ const response = await readSettled(entry.promise as Promise<Response>)
35
+ if (!response) {
36
+ return undefined
37
+ }
38
+ if (store.entries.get(entry.key) !== entry) {
39
+ return undefined
40
+ }
41
+ const contentType = (response.headers.get('content-type') ?? '').toLowerCase()
42
+ if (!isTextual(contentType)) {
43
+ return undefined
44
+ }
45
+ const body = await response.text()
46
+ entry.promise = Promise.resolve(
47
+ new Response(body, {
48
+ status: response.status,
49
+ statusText: response.statusText,
50
+ headers: response.headers,
51
+ }),
52
+ )
53
+ return {
54
+ key: entry.key,
55
+ url: entry.request.url,
56
+ method,
57
+ status: response.status,
58
+ statusText: response.statusText,
59
+ headers: Array.from(response.headers.entries()),
60
+ body,
61
+ }
62
+ }
63
+
64
+ async function readSettled(promise: Promise<Response>): Promise<Response | undefined> {
65
+ try {
66
+ return await promise
67
+ } catch {
68
+ return undefined
69
+ }
70
+ }
71
+
72
+ function isTextual(contentType: string): boolean {
73
+ if (contentType.startsWith('text/')) {
74
+ return true
75
+ }
76
+ if (contentType.includes('json')) {
77
+ return true
78
+ }
79
+ if (contentType.includes('xml')) {
80
+ return true
81
+ }
82
+ return false
83
+ }
@@ -0,0 +1,37 @@
1
+ import type { CacheEntry } from '../../shared/types/CacheEntry.ts'
2
+ import type { CacheSnapshotEntry } from '../../shared/types/CacheSnapshotEntry.ts'
3
+ import type { CacheStore } from '../../shared/types/CacheStore.ts'
4
+ import type { StreamedResolution } from '../../shared/types/StreamedResolution.ts'
5
+ import { snapshotEntryFromCache } from './snapshotEntryFromCache.ts'
6
+
7
+ /*
8
+ Drains the pending ({#await}) cache entries in resolution order — whichever
9
+ fetch lands next is yielded next, so a slow entry never blocks a fast one
10
+ behind it. Yields exactly one StreamedResolution per entry: the snapshot when
11
+ serialization succeeds, or a `{ key, miss }` marker when the body can't ship so
12
+ the client placeholder re-fetches instead of hanging on a deferred that never
13
+ settles.
14
+ */
15
+ export async function* streamCacheResolutions(
16
+ store: CacheStore,
17
+ pending: CacheEntry[],
18
+ ): AsyncIterable<StreamedResolution> {
19
+ /*
20
+ Tag each pending serialization with its key so the loop can drop exactly
21
+ the one that just settled. Deleting inside the `.then` instead would race
22
+ the loop — already-resolved promises empty the map before the first
23
+ Promise.race runs — so removal happens here, after the await.
24
+ */
25
+ const inflight = new Map<string, Promise<{ key: string; snapshot?: CacheSnapshotEntry }>>()
26
+ for (const entry of pending) {
27
+ inflight.set(
28
+ entry.key,
29
+ snapshotEntryFromCache(store, entry).then((snapshot) => ({ key: entry.key, snapshot })),
30
+ )
31
+ }
32
+ while (inflight.size > 0) {
33
+ const { key, snapshot } = await Promise.race(inflight.values())
34
+ inflight.delete(key)
35
+ yield snapshot ?? { key, miss: true }
36
+ }
37
+ }
@@ -0,0 +1,86 @@
1
+ /*
2
+ Shared body builder for the streaming respond helpers (`jsonl`, `sse`).
3
+ Both flow the same shape — pull from an AsyncIterator, encode each frame
4
+ to bytes, emit a sentinel `error` frame on a generator throw, and route
5
+ ReadableStream's `cancel` into `iter.return()` so the handler's
6
+ `for await` exits via its normal control path. Only the per-frame
7
+ encoding and the optional keepalive payload differ between the two.
8
+
9
+ Keepalive is opt-in: SSE uses `: keepalive\n\n` every 15s so proxies
10
+ don't drop an idle connection; jsonl has no spec-defined comment, so it
11
+ omits keepalive entirely.
12
+ */
13
+
14
+ export type StreamEncoder<T> = {
15
+ encodeFrame: (value: T) => string
16
+ encodeError: (message: string) => string
17
+ keepaliveMs?: number
18
+ keepalivePayload?: string
19
+ }
20
+
21
+ export function streamFromIterator<T>(
22
+ iterable: AsyncIterable<T>,
23
+ encoder: StreamEncoder<T>,
24
+ ): ReadableStream<Uint8Array> {
25
+ const textEncoder = new TextEncoder()
26
+ const iterator = iterable[Symbol.asyncIterator]()
27
+ let keepalive: ReturnType<typeof setInterval> | undefined
28
+
29
+ function stopKeepalive(): void {
30
+ if (keepalive !== undefined) {
31
+ clearInterval(keepalive)
32
+ keepalive = undefined
33
+ }
34
+ }
35
+
36
+ return new ReadableStream<Uint8Array>({
37
+ start(controller) {
38
+ if (encoder.keepaliveMs !== undefined && encoder.keepalivePayload !== undefined) {
39
+ const payload = textEncoder.encode(encoder.keepalivePayload)
40
+ keepalive = setInterval(() => {
41
+ /*
42
+ Every close/cancel path clears this interval synchronously,
43
+ so a tick can't normally hit a closed controller — but
44
+ enqueue throws on a closed/errored stream, and an uncaught
45
+ throw in a timer crashes the process. Guard + self-stop.
46
+ */
47
+ try {
48
+ controller.enqueue(payload)
49
+ } catch {
50
+ stopKeepalive()
51
+ }
52
+ }, encoder.keepaliveMs)
53
+ }
54
+ },
55
+ async pull(controller) {
56
+ try {
57
+ const next = await iterator.next()
58
+ if (next.done) {
59
+ stopKeepalive()
60
+ controller.close()
61
+ return
62
+ }
63
+ controller.enqueue(textEncoder.encode(encoder.encodeFrame(next.value)))
64
+ } catch (error) {
65
+ const message = error instanceof Error ? error.message : String(error)
66
+ controller.enqueue(textEncoder.encode(encoder.encodeError(message)))
67
+ stopKeepalive()
68
+ controller.close()
69
+ }
70
+ },
71
+ cancel(reason) {
72
+ stopKeepalive()
73
+ /*
74
+ Route cancel into the generator's normal exit, but swallow a
75
+ rejection from its cleanup: a `finally` that throws on `.return()`
76
+ would otherwise surface as an unhandled rejection (process-fatal
77
+ under Bun's default) on a client disconnect — a path every
78
+ sse/jsonl/resolve stream hits routinely.
79
+ */
80
+ return iterator.return?.(reason)?.then(
81
+ () => undefined,
82
+ () => undefined,
83
+ )
84
+ },
85
+ })
86
+ }
@@ -0,0 +1,6 @@
1
+ /*
2
+ Embedded asset bytes keyed by request path (compile-time gzip embed). Pinned
3
+ to a plain-ArrayBuffer backing so values feed `new Response(...)` directly —
4
+ BodyInit rejects views over a possibly-shared buffer.
5
+ */
6
+ export type Assets = Record<string, Uint8Array<ArrayBuffer>>
@@ -0,0 +1,18 @@
1
+ /*
2
+ The dev live-reload stamp the worker announces on the channel, split so the
3
+ browser keeps its page across edits that don't need a reload:
4
+ - `structure` fingerprints everything EXCEPT the entry stylesheet and the
5
+ hot-swappable component bodies — non-component source, public assets, the
6
+ shell, the component-id set, and non-hot component bodies (pages, layouts,
7
+ import-bearing components). Any change here reloads.
8
+ - `cssHref` is the entry stylesheet's current content-hashed URL; a change
9
+ here alone swaps the `<link>` in place. Undefined when no stylesheet is built.
10
+ - `components` maps each hot-swappable (leaf child) component's module id to a
11
+ hash of its client build (style-independent). A change here alone fetches the
12
+ component's hot module and replaces its live instances — no reload.
13
+ */
14
+ export type DevReloadStamp = {
15
+ structure: string
16
+ cssHref: string | undefined
17
+ components: Record<string, string>
18
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ One global cache entry projected for the inspector — the serializable facts the
3
+ Cache tab renders. The stored promise/Request/timer aren't included; what an
4
+ operator wants is the entry's identity, lifecycle state, retention, and a peek
5
+ at the held value.
6
+ */
7
+ export type InspectorCacheEntry = {
8
+ /* The cache key (remote: method+url+args; producer: reference+args). */
9
+ key: string
10
+ /* Lifecycle: 'settled' | 'in-flight' | 'refreshing'. */
11
+ status: string
12
+ /* True when the entry stores a wire Response (a remote verb), false for a plain producer value. */
13
+ remote: boolean
14
+ /* Retention ttl in ms; undefined = forever, 0 = dedupe-only. */
15
+ ttl: number | undefined
16
+ /* Ms until expiry from snapshot time; undefined = no expiry armed. */
17
+ expiresInMs: number | undefined
18
+ /* The call's scope tags (cache.invalidate({ scope }) targets). */
19
+ scope: string[]
20
+ /* A short JSON preview of the decoded warm value, when the entry holds one. */
21
+ value: string | undefined
22
+ /* An armed invalidate policy (throttle/debounce + ms), if declared. */
23
+ policy: string | undefined
24
+ }
@@ -0,0 +1,11 @@
1
+ import type { InspectorCacheEntry } from './InspectorCacheEntry.ts'
2
+
3
+ /*
4
+ The inspector's view of the cache: the process-level (`global: true`) store's
5
+ current entries. That's the persistent store — request-scoped caches live and
6
+ die with their request, so they surface as per-request tallies in the feed and
7
+ traces rather than here.
8
+ */
9
+ export type InspectorCacheSnapshot = {
10
+ entries: InspectorCacheEntry[]
11
+ }
@@ -0,0 +1,30 @@
1
+ import type { LogRecord } from '../../../shared/types/LogRecord.ts'
2
+ import type { InspectorCacheSnapshot } from './InspectorCacheSnapshot.ts'
3
+ import type { InspectorSurface } from './InspectorSurface.ts'
4
+
5
+ /*
6
+ The capabilities core injects into `@abide/inspector` when
7
+ ABIDE_ENABLE_INSPECTOR=true. The package consumes this and imports no abide
8
+ internals — so the inspector stays a pure consumer and core grows no public
9
+ surface for it (mirrors how AppModule / AgentEngine are the documented seams).
10
+ Everything here is already produced by the runtime: the registries behind
11
+ loadSurface(), the log chokepoint behind onRecord().
12
+ */
13
+ // @readme plumbing
14
+ export type InspectorContext = {
15
+ /* App identity for the UI header — the same name/version the health probe reports. */
16
+ app: { name: string; version: string }
17
+ /* Eager-loads the registries, then projects the current RPC + socket catalog. */
18
+ loadSurface: () => Promise<InspectorSurface>
19
+ /* Snapshots the persistent (global) cache store — current entries with their
20
+ lifecycle state, retention, scope tags, and a value preview. */
21
+ cacheSnapshot: () => InspectorCacheSnapshot
22
+ /*
23
+ Subscribes to the unified event stream: every emitted log record (the log's
24
+ structured form, trace context and all) plus published socket frames shaped
25
+ as `socket`-channel records — one feed, so the inspector treats sockets,
26
+ cache diagnostics, and request logs uniformly. Returns an unsubscribe; the
27
+ underlying taps are process-wide, owned by the inspector for its lifetime.
28
+ */
29
+ onRecord: (listener: (record: LogRecord) => void) => () => void
30
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ One declared socket projected for the inspector: its name plus the operations
3
+ it exposes (tail always; publish only when it allows client publishing),
4
+ mirroring the CLI/MCP projection from socketOperations so the inspector can't
5
+ disagree with them about a socket's faces.
6
+ */
7
+ export type InspectorSocket = {
8
+ /* The socket's file-path name (may contain `/` for nested files). */
9
+ name: string
10
+ /* The operations exposed, named as the CLI/MCP advertise them. */
11
+ operations: Array<{
12
+ kind: string
13
+ name: string
14
+ method: string
15
+ restUrl: string
16
+ }>
17
+ }
@@ -0,0 +1,13 @@
1
+ import type { InspectorSocket } from './InspectorSocket.ts'
2
+ import type { InspectorVerb } from './InspectorVerb.ts'
3
+
4
+ /*
5
+ The app's machine surface projected for the inspector — the static catalog the
6
+ UI renders. Built by reading the verb and socket registries after they're
7
+ eager-loaded, so a freshly-booted server lists its whole surface, not just the
8
+ verbs hit so far. Pages stay out: they're the human surface, already navigable.
9
+ */
10
+ export type InspectorSurface = {
11
+ verbs: InspectorVerb[]
12
+ sockets: InspectorSocket[]
13
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ One RPC verb projected for the inspector: the registry entry reduced to the
3
+ serializable facts the UI renders — where it mounts, its method, which
4
+ non-browser surfaces advertise it, and its argument/result shapes as JSON
5
+ Schema. Schemas project through jsonSchemaForSchema (same as MCP/OpenAPI), so
6
+ a verb whose library can't render a schema still lists with an opaque shape.
7
+ */
8
+ export type InspectorVerb = {
9
+ /* Registry key — the rpc URL the verb mounts at (e.g. /rpc/users/create). */
10
+ url: string
11
+ /* HTTP method bound to the verb. */
12
+ method: string
13
+ /* Which surfaces advertise it (browser/mcp/cli), from the verb's ClientFlags. */
14
+ clients: Record<string, boolean>
15
+ /* Argument-bag shape as JSON Schema; undefined when the verb declares none. */
16
+ inputSchema: Record<string, unknown> | undefined
17
+ /* Success-body shape as JSON Schema; undefined when the verb declares none. */
18
+ outputSchema: Record<string, unknown> | undefined
19
+ /* True when the verb declares a filesSchema — it accepts multipart File parts. */
20
+ files: boolean
21
+ /* Per-verb handler deadline in ms; undefined = no deadline. */
22
+ timeout: number | undefined
23
+ /* Per-verb received-body cap in bytes; undefined = Bun's server-wide ceiling. */
24
+ maxBodySize: number | undefined
25
+ /* True when the verb opts out of the same-origin CSRF gate. */
26
+ crossOrigin: boolean | undefined
27
+ }
@@ -0,0 +1,55 @@
1
+ import type { CacheStore } from '../../../shared/types/CacheStore.ts'
2
+ import type { TraceContext } from '../../../shared/types/TraceContext.ts'
3
+
4
+ /*
5
+ Per-request state propagated through AsyncLocalStorage. Every field is
6
+ populated once at the server's fetch boundary; helpers and verb-defined
7
+ remote functions read from it without threading arguments through user code.
8
+ The inbound request's AbortSignal is reached via `req.signal` rather than a
9
+ separate field.
10
+ */
11
+ export type RequestStore = {
12
+ url: URL
13
+ req: Request
14
+ cache: CacheStore
15
+ /*
16
+ W3C trace position: inbound `traceparent` continued (prefer-incoming) or a
17
+ fresh sampled trace minted at the boundary. Read by trace()/log via the
18
+ request-scope resolver and stamped into __SSR__ for the browser half.
19
+ */
20
+ trace: TraceContext
21
+ /* Bun.nanoseconds() at scope entry — anchors log `+elapsed`, Server-Timing, and the closing record's total. */
22
+ start: number
23
+ /*
24
+ The matched page route and its decoded params, set just before the page
25
+ renders so the `page` proxy resolves them inside layout-scoped components
26
+ during SSR. Undefined on rpc/socket requests and until a page match lands.
27
+ */
28
+ route?: string
29
+ params?: Record<string, string>
30
+ /*
31
+ store.url with the mount base re-applied — the browser-space URL the `page`
32
+ proxy publishes, memoized by pageUrlFromStore on first read. `url` itself
33
+ stays app-space for routing and error-prefix matching.
34
+ */
35
+ pageUrl?: URL
36
+ /*
37
+ Set by a server-side health() read (via healthReadSlot) during this
38
+ request's SSR pass. The renderer stamps the health payload into __SSR__
39
+ only when set, so the client seed stays reader-driven like the poll.
40
+ */
41
+ healthRead?: boolean
42
+ /*
43
+ The request's cookie jar, materialized lazily by the first cookies() call
44
+ and flushed to Set-Cookie headers when the scope returns. Undefined while a
45
+ request never touches cookies, so the common path parses and emits nothing.
46
+ */
47
+ cookies?: Bun.CookieMap
48
+ /*
49
+ File parts split off a multipart/form-data body by parseArgs, grouped by
50
+ field name, for files() to read. Files never enter the handler's args so the
51
+ input schema keeps validating a plain object; undefined when the request
52
+ carried no file parts.
53
+ */
54
+ files?: Record<string, File[]>
55
+ }
@@ -0,0 +1,32 @@
1
+ import { abideLog } from '../../shared/abideLog.ts'
2
+ import { verbRegistry } from '../rpc/verbRegistry.ts'
3
+ import { socketRegistry } from '../sockets/socketRegistry.ts'
4
+ import { ensureRegistriesLoaded } from './registryManifests.ts'
5
+
6
+ /*
7
+ Boot-time disclosure for an unguarded MCP endpoint: when /__abide/mcp is
8
+ mounted with at least one MCP-exposed declaration and no app.handle
9
+ middleware to authenticate requests, say so. Printed unconditionally — the
10
+ surface map is DEBUG-gated diagnostics, but an unauthenticated machine
11
+ surface should never boot silently. The caller skips this entirely when
12
+ app.handle exists, so only the authless path pays the eager registry load.
13
+ Best-effort like the surface map: enumeration failures are swallowed.
14
+ */
15
+ export async function warnUnguardedMcp(): Promise<void> {
16
+ try {
17
+ await ensureRegistriesLoaded()
18
+ } catch {
19
+ return
20
+ }
21
+ const exposed =
22
+ Array.from(verbRegistry.values()).filter((entry) => entry.clients.mcp).length +
23
+ Array.from(socketRegistry.values()).filter((entry) => entry.clients.mcp).length
24
+ if (exposed === 0) {
25
+ return
26
+ }
27
+ abideLog.warn(
28
+ `MCP endpoint /__abide/mcp exposes ${exposed} declaration${exposed === 1 ? '' : 's'} ` +
29
+ 'with no auth guard — add an app.handle middleware in src/app.ts to ' +
30
+ 'authenticate machine clients, or set clients.mcp: false per declaration',
31
+ )
32
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ Merges a caller's `ResponseInit` over a respond helper's default headers.
3
+ The helper's defaults seed the header set; the caller's headers overlay them
4
+ per-key (so an explicit `cache-control` wins over the helper's `no-store`),
5
+ and the rest of `init` (status, statusText) passes straight through. Shared
6
+ by `json` / `jsonl` / `sse` / `error` / `redirect` so every helper accepts a
7
+ final `ResponseInit` with identical override semantics.
8
+
9
+ A helper that owns the status itself (`error`, `redirect`) passes it as the
10
+ final `status` argument; it is applied last so it always wins over any
11
+ `init.status`, keeping that precedence inside the helper rather than relying
12
+ on each call site spreading in the right order.
13
+ */
14
+ export function withResponseDefaults(
15
+ init: ResponseInit | undefined,
16
+ defaultHeaders: Record<string, string>,
17
+ status?: number,
18
+ ): ResponseInit {
19
+ const headers = new Headers(defaultHeaders)
20
+ new Headers(init?.headers).forEach((value, key) => {
21
+ headers.set(key, value)
22
+ })
23
+ return { ...init, headers, ...(status !== undefined && { status }) }
24
+ }
@@ -0,0 +1,33 @@
1
+ import type { Server } from 'bun'
2
+ import { getActiveServer } from './runtime/getActiveServer.ts'
3
+ import { inProcessServer } from './runtime/inProcessServer.ts'
4
+ import { requestContext } from './runtime/requestContext.ts'
5
+
6
+ /*
7
+ Returns the active Bun.serve instance. Mirrors `request()`'s function-call
8
+ shape so call sites appear in stack traces (a Proxy trap intermediates and
9
+ obscures them).
10
+
11
+ When no Bun.serve has booted, resolution forks on the request scope:
12
+ - Inside a scope it is in-process dispatch (CLI / MCP / test client), which
13
+ never boots a server — return the no-op inProcessServer so handler idioms
14
+ (server().timeout/publish/requestIP …) run unchanged instead of throwing.
15
+ createServer sets the slot at boot before any request, so an empty slot
16
+ while a scope is live can only be in-process.
17
+ - Outside any scope it is a genuine before-init misuse (module top-level /
18
+ app.ts init); keep throwing — silent undefined would mask it and strand
19
+ later property reads with cryptic errors.
20
+ */
21
+ // @readme request-scope
22
+ export function server(): Server<unknown> {
23
+ const active = getActiveServer()
24
+ if (active) {
25
+ return active
26
+ }
27
+ if (requestContext.getStore()) {
28
+ return inProcessServer
29
+ }
30
+ throw new Error(
31
+ '[abide] server() called before init — make sure your call happens inside or after app.ts init() resolves',
32
+ )
33
+ }
@@ -0,0 +1,32 @@
1
+ import type { StandardSchemaV1 } from '../shared/types/StandardSchemaV1.ts'
2
+ import type { Socket } from './sockets/types/Socket.ts'
3
+ import type { SocketOptions } from './sockets/types/SocketOptions.ts'
4
+
5
+ /*
6
+ Declares a Socket inside a file under `src/server/sockets/`. Each file contains
7
+ exactly one export, named after the file (e.g. `chat.ts` →
8
+ `export const chat = socket<ChatMessage>(...)`). The bundler reads the
9
+ // @readme sockets
10
+ export name from the filename and the socket name from the file path
11
+ under `src/server/sockets/`, then rewrites this call to bind the name into the
12
+ runtime implementation (defineSocket on the server, socketProxy on the
13
+ client). Opts (tail, clientPublish, schema, clients) live on the
14
+ server side only; the client target discards them.
15
+
16
+ When `schema` is set, `T` infers from `InferOutput<Schema>` and publish
17
+ payloads validate against it on the server. `clients` controls which
18
+ adapter surfaces (browser / mcp / cli) advertise the socket — defaults
19
+ to browser-only when schemaless, all surfaces when a schema is present.
20
+
21
+ This function exists only for the type signature; calling it directly
22
+ means the bundler plugin didn't process the file, which throws.
23
+ */
24
+ export function socket<Schema extends StandardSchemaV1>(
25
+ opts: SocketOptions<Schema> & { schema: Schema },
26
+ ): Socket<StandardSchemaV1.InferOutput<Schema>>
27
+ export function socket<T = unknown>(opts?: SocketOptions): Socket<T>
28
+ export function socket<T = unknown>(_opts?: SocketOptions): Socket<T> {
29
+ throw new Error(
30
+ '[abide] `socket(...)` was called outside an $sockets module — the socket helper is only valid as the value of `export const <filename> = ...` inside a file under src/server/sockets/',
31
+ )
32
+ }