@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,169 @@
1
+ import { decodeResponse } from './decodeResponse.ts'
2
+ import { HttpError } from './HttpError.ts'
3
+ import { jsonlErrorFrame } from './jsonlErrorFrame.ts'
4
+ import { STREAMING_CONTENT_TYPES } from './STREAMING_CONTENT_TYPES.ts'
5
+ import { sseErrorFrame } from './sseErrorFrame.ts'
6
+
7
+ /*
8
+ Turns a Response into an AsyncIterable of frames, regardless of the
9
+ handler's chosen body format. Shared by `fn.stream(args)` (via
10
+ subscribableFromResponse), the CLI's streaming print path, and the MCP
11
+ tool dispatcher's stream drain — so every surface consumes sse/jsonl
12
+ identically. Three shapes are handled:
13
+
14
+ - text/event-stream (SSE): emits the JSON-parsed `data:` payload of
15
+ each event. The `event: error\ndata: {message}` frame the `sse()`
16
+ helper emits on generator throws is mapped back to a thrown Error so
17
+ consumers see the failure mid-iteration.
18
+ - application/jsonl + application/x-ndjson: emits one JSON value per
19
+ line. The trailing `{"$error":"..."}` line the `jsonl()` helper
20
+ emits on generator throws is likewise re-thrown.
21
+ - everything else: one-shot — yields the Content-Type-decoded body
22
+ once, then completes. Lets callers iterate uniformly on every rpc
23
+ handler, not just the streaming ones.
24
+
25
+ Non-2xx responses surface as a thrown HttpError on the first pull,
26
+ mirroring the plain `fn(args)` decode path.
27
+ */
28
+ export function streamResponse<T>(response: Response): AsyncIterable<T> {
29
+ if (!response.ok) {
30
+ return errorIterable<T>(new HttpError(response))
31
+ }
32
+ const contentType = (response.headers.get('content-type') ?? '').toLowerCase()
33
+ if (contentType.startsWith('text/event-stream')) {
34
+ return parseSse<T>(response)
35
+ }
36
+ if (STREAMING_CONTENT_TYPES.some((type) => contentType.startsWith(type))) {
37
+ return parseJsonLines<T>(response)
38
+ }
39
+ return oneShot<T>(response)
40
+ }
41
+
42
+ /* Surfaces a non-2xx response (or any pre-stream failure) as a thrown error on the first pull. */
43
+ // biome-ignore lint/correctness/useYield: throws on first pull; the generator shape is intentional so callers iterate it uniformly
44
+ async function* errorIterable<T>(error: Error): AsyncGenerator<T> {
45
+ throw error
46
+ }
47
+
48
+ /*
49
+ One-shot iterator over a non-streaming Response: decodes the body once
50
+ via the same Content-Type sniffing the plain call uses, yields it, then
51
+ completes. Makes streaming symmetrical across streaming and
52
+ non-streaming handlers — callers can pick the iteration shape without
53
+ worrying about which body the handler returned.
54
+ */
55
+ async function* oneShot<T>(response: Response): AsyncGenerator<T> {
56
+ yield (await decodeResponse(response)) as T
57
+ }
58
+
59
+ /*
60
+ Reads a streaming text Response and yields raw frame strings split on
61
+ `delimiter` (`\n\n` for SSE events, `\n` for JSON lines). Owns the whole
62
+ buffering lifecycle: incremental decode, amortised-O(n) compaction, a
63
+ final flush of the trailing partial frame, and reader cancellation when
64
+ the consumer stops iterating (the generator's `finally` runs on
65
+ `return()`). The SSE and jsonl parsers layer their per-frame parsing on
66
+ top of this single machine so the two can't drift.
67
+ */
68
+ async function* frameReader(response: Response, delimiter: string): AsyncGenerator<string> {
69
+ const body = response.body
70
+ if (!body) {
71
+ return
72
+ }
73
+ const reader = body.pipeThrough(new TextDecoderStream()).getReader()
74
+ let buffer = ''
75
+ let bufferStart = 0
76
+ try {
77
+ while (true) {
78
+ const { value, done } = await reader.read()
79
+ if (done) {
80
+ if (bufferStart < buffer.length) {
81
+ yield buffer.slice(bufferStart)
82
+ }
83
+ return
84
+ }
85
+ /*
86
+ Compact only when the unread region is small relative to the
87
+ consumed prefix — keeps amortised work O(n) instead of
88
+ quadratic slicing per frame boundary.
89
+ */
90
+ if (bufferStart > buffer.length / 2) {
91
+ buffer = buffer.slice(bufferStart) + value
92
+ bufferStart = 0
93
+ } else {
94
+ buffer += value
95
+ }
96
+ let boundary = buffer.indexOf(delimiter, bufferStart)
97
+ while (boundary !== -1) {
98
+ yield buffer.slice(bufferStart, boundary)
99
+ bufferStart = boundary + delimiter.length
100
+ boundary = buffer.indexOf(delimiter, bufferStart)
101
+ }
102
+ }
103
+ } finally {
104
+ await reader.cancel().catch(() => undefined)
105
+ }
106
+ }
107
+
108
+ /*
109
+ SSE parser: yields the JSON-parsed `data` payload of each `event:`/`data:`
110
+ frame. The error sentinel (`sseErrorFrame`) the `sse()` helper emits on a
111
+ generator throw is surfaced as a thrown Error so consumer loops can react
112
+ to mid-stream failure rather than silently stopping.
113
+ */
114
+ async function* parseSse<T>(response: Response): AsyncGenerator<T> {
115
+ for await (const raw of frameReader(response, '\n\n')) {
116
+ const frame = parseFrame(raw)
117
+ if (!frame) {
118
+ continue
119
+ }
120
+ const errorMessage = sseErrorFrame.decode(frame.event, frame.data)
121
+ if (errorMessage !== undefined) {
122
+ throw new Error(errorMessage)
123
+ }
124
+ yield JSON.parse(frame.data) as T
125
+ }
126
+ }
127
+
128
+ function parseFrame(raw: string): { event: string; data: string } | undefined {
129
+ const lines = raw.split('\n').filter((line) => line.length > 0 && !line.startsWith(':'))
130
+ if (lines.length === 0) {
131
+ return undefined
132
+ }
133
+ let event = 'message'
134
+ const dataLines: string[] = []
135
+ for (const line of lines) {
136
+ const colon = line.indexOf(':')
137
+ const field = colon === -1 ? line : line.slice(0, colon)
138
+ const value = colon === -1 ? '' : line.slice(colon + 1).replace(/^ /, '')
139
+ if (field === 'event') {
140
+ event = value
141
+ } else if (field === 'data') {
142
+ dataLines.push(value)
143
+ }
144
+ }
145
+ if (dataLines.length === 0) {
146
+ return undefined
147
+ }
148
+ return { event, data: dataLines.join('\n') }
149
+ }
150
+
151
+ /*
152
+ JSONL/NDJSON parser: parses each non-empty line as JSON and yields the
153
+ value. The error sentinel (`jsonlErrorFrame`) the `jsonl()` helper emits as
154
+ a trailing line on a generator throw is surfaced here as a thrown Error so
155
+ consumer loops can react to mid-stream failure.
156
+ */
157
+ async function* parseJsonLines<T>(response: Response): AsyncGenerator<T> {
158
+ for await (const raw of frameReader(response, '\n')) {
159
+ if (raw.length === 0) {
160
+ continue
161
+ }
162
+ const parsed = JSON.parse(raw)
163
+ const errorMessage = jsonlErrorFrame.decode(parsed)
164
+ if (errorMessage !== undefined) {
165
+ throw new Error(errorMessage)
166
+ }
167
+ yield parsed as T
168
+ }
169
+ }
@@ -0,0 +1,27 @@
1
+ /*
2
+ Strips the user's `import { … } from '<moduleName>'` declaration from a
3
+ module source. Used by the $rpc / $sockets rewriters to remove the
4
+ verb / `socket` import after its call site has been replaced by the
5
+ runtime-injected binding (defineVerb / defineSocket). Without this
6
+ strip the dead import would still side-effect-load the verb/socket
7
+ helper module into the server bundle for every $rpc / $sockets file.
8
+
9
+ The braced body is `[^}]*` rather than `[\s\S]*?` so the lazy match
10
+ can't backtrack across a `}` and accidentally swallow a preceding
11
+ import whose `from` clause doesn't match (e.g. stripping
12
+ `import { GET } from '@abide/abide/server/GET'` from a file that also has
13
+ `import { json } from '@abide/abide/server/json'` on the line above). `[^}]`
14
+ includes newlines, so multi-line braced imports like
15
+ import {
16
+ GET,
17
+ } from '@abide/abide/server/GET'
18
+ still match — the body just can't contain another `}` to bound it.
19
+ */
20
+ export function stripImport(source: string, moduleName: string): string {
21
+ const escaped = moduleName.replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
22
+ const pattern = new RegExp(
23
+ `^\\s*import\\s*\\{[^}]*\\}\\s*from\\s*['"]${escaped}['"]\\s*;?\\s*$`,
24
+ 'gm',
25
+ )
26
+ return source.replace(pattern, '')
27
+ }
@@ -0,0 +1,51 @@
1
+ import { streamResponse } from './streamResponse.ts'
2
+ import type { Subscribable } from './types/Subscribable.ts'
3
+
4
+ /*
5
+ Builds the Subscribable returned by `fn.stream(args)`. The carried
6
+ `name` is the cache-style key for (method, url, args) so tail()
7
+ dedupes multiple readers of identical args into one underlying
8
+ fetch. The fetch is deferred until the first iterator pull so
9
+ constructing the Subscribable (which happens on every $derived
10
+ re-evaluation) doesn't open a connection — tail()'s registry
11
+ short-circuits the second instance before it iterates.
12
+ */
13
+ export function subscribableFromResponse<T>(
14
+ name: string,
15
+ fetchResponse: () => Promise<Response>,
16
+ ): Subscribable<T> {
17
+ return {
18
+ name,
19
+ [Symbol.asyncIterator]() {
20
+ let inner: AsyncIterator<T, void, undefined> | undefined
21
+ let cancelled = false
22
+ return {
23
+ async next() {
24
+ if (cancelled) {
25
+ return { value: undefined, done: true }
26
+ }
27
+ if (!inner) {
28
+ const response = await fetchResponse()
29
+ inner = streamResponse<T>(response)[Symbol.asyncIterator]()
30
+ /*
31
+ If return() landed while we were awaiting the
32
+ fetch, `inner` was still undefined then so its
33
+ reader was never cancelled — release the body now
34
+ rather than leaving the HTTP stream open.
35
+ */
36
+ if (cancelled) {
37
+ await inner.return?.(undefined)
38
+ return { value: undefined, done: true }
39
+ }
40
+ }
41
+ return inner.next()
42
+ },
43
+ async return() {
44
+ cancelled = true
45
+ await inner?.return?.(undefined)
46
+ return { value: undefined, done: true }
47
+ },
48
+ }
49
+ },
50
+ }
51
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ Internal slot the browser tail() registry registers its prober into, so the
3
+ shared probes (pending / refreshing) can answer for Subscribables without
4
+ shared/ importing browser/. The prober taps the registry's lifecycle channel
5
+ (reactive inside $derived / $effect) and reports one stream by source name —
6
+ spanning its latest-wins and window entries — or, with no name, whether any
7
+ registered stream matches. When no prober is registered (server render, or
8
+ tail was never imported) the probes fall back to the same answers tail()
9
+ itself gives on the server: a named stream has no value yet (pending true),
10
+ and nothing is reconnecting (refreshing false).
11
+ */
12
+ export const tailProbeSlot: {
13
+ probe: ((name?: string) => { pending: boolean; refreshing: boolean }) | undefined
14
+ } = {
15
+ probe: undefined,
16
+ }
@@ -0,0 +1,28 @@
1
+ import { parseRouteSegments } from './parseRouteSegments.ts'
2
+
3
+ /*
4
+ Translates a abide route URL (`/media/[id]/[...rest]`) into the pattern Bun
5
+ needs (`/media/:id/*`) for `Bun.serve({ routes })`. Returns the catch-all
6
+ segment's original name alongside so the server can rename Bun's `*` param
7
+ back to that name on the way out, keeping page-prop destructuring consistent
8
+ with the route file path.
9
+ */
10
+ export function toBunRoutePattern(routeUrl: string): {
11
+ pattern: string
12
+ catchAllName: string | undefined
13
+ } {
14
+ let catchAllName: string | undefined
15
+ const pattern = parseRouteSegments(routeUrl)
16
+ .map((segment) => {
17
+ if (segment.kind === 'literal') {
18
+ return segment.value
19
+ }
20
+ if (segment.catchAll) {
21
+ catchAllName = segment.name
22
+ return '*'
23
+ }
24
+ return `:${segment.name}`
25
+ })
26
+ .join('/')
27
+ return { pattern, catchAllName }
28
+ }
@@ -0,0 +1,4 @@
1
+ /* Normalizes a scope option (one tag or many) to a Set for O(1) membership. */
2
+ export function toScopeSet(scope: string | string[]): Set<string> {
3
+ return new Set(typeof scope === 'string' ? [scope] : scope)
4
+ }
@@ -0,0 +1,16 @@
1
+ import { formatTraceparent } from './formatTraceparent.ts'
2
+ import { requestScopeSlot } from './requestScopeSlot.ts'
3
+
4
+ /*
5
+ The current request's W3C `traceparent`, or undefined outside any request
6
+ scope (boot scripts, build, background work). Isomorphic: the server resolves
7
+ it from the ALS request scope, the browser from the trace stamped into
8
+ __SSR__ — so a client-side read returns the trace of the request that
9
+ rendered the page. The string is propagation-ready: hand it to your own logs,
10
+ error reports, or `propagation.extract` when attaching OpenTelemetry spans.
11
+ */
12
+ // @readme observability
13
+ export function trace(): string | undefined {
14
+ const scope = requestScopeSlot.resolver?.()
15
+ return scope ? formatTraceparent(scope.trace) : undefined
16
+ }
@@ -0,0 +1,84 @@
1
+ /*
2
+ Stored shape per cache key. The stored promise resolves to the raw Response for
3
+ a remote function (the snapshot reads its status/headers/body and the cache
4
+ layer hands callers a decoded view derived from it) or to the producer's value
5
+ for a plain producer — hence `Promise<unknown>`.
6
+
7
+ `request` is retained for remote entries so SSR snapshot serialization can
8
+ record the URL and method without re-deriving them from the function. Producer
9
+ entries have no wire request, so it is absent — and the snapshot readers skip
10
+ any entry lacking it (a producer value has no rpc identity to rehydrate against).
11
+
12
+ `ttl`/`expiresAt` drive eviction: expiresAt = undefined means "no TTL" (lives
13
+ forever); ttl = 0 means "dedupe only" (entry is pruned as soon as the promise
14
+ settles).
15
+
16
+ `value` is the decoded warm value served synchronously by the read path
17
+ (cloned per read). It is set at hydration — the SSR snapshot body is
18
+ pre-decoded so the first client render reads it without a microtask hop and
19
+ byte-matches the SSR DOM — and also by cache.on's `context.patch`, which folds
20
+ an authoritative frame delta straight onto it without a refetch (ADR-0007).
21
+ Live fetches leave it undefined and take the async decode path until a patch
22
+ populates it.
23
+
24
+ `hydrated` marks an entry built from the SSR snapshot, which ships no wrap
25
+ options — the first read consumes the flag and adopts its call site's `ttl`
26
+ (omitted = forever, as shipped; ttl > 0 = expiry clock starts at that read;
27
+ ttl = 0 = the warm value exists only to complete the hydration render and is
28
+ evicted a macrotask later). Live entries never carry it; their ttl was fixed
29
+ at registration.
30
+
31
+ `scope` holds the cache() call's scope tags as a Set so
32
+ `cache.invalidate({ scope })` can drop every entry sharing any tag with O(1)
33
+ membership; a re-read merges new tags in rather than replacing them.
34
+
35
+ `settled` flips true once the stored promise resolves. SSR snapshot
36
+ serialization reads it after `render()` returns to partition entries: ones
37
+ settled by then were consumed via `await` (render blocked on them) and inline
38
+ into `__SSR__`; ones still pending were consumed via `{#await}` (render emitted
39
+ the pending branch without blocking) and stream a resolve chunk instead.
40
+
41
+ `refreshing` flips true while this entry is reloading data it already held —
42
+ either a policy stale-while-revalidate refetch (value still visible) or the
43
+ default drop-then-reload (the prior entry was invalidated and dropped, this is
44
+ its replacement read). It backs refreshing(), distinguishing a reload from a
45
+ first-ever load; cleared when the read settles.
46
+
47
+ `invalidation` holds an `invalidate` throttle/debounce policy: the refetch
48
+ thunk (the call captured with its args) plus the policy and its runtime timer
49
+ state, so invalidate() can rate-limit refetches of this key instead of dropping
50
+ the entry and refetching on every invalidation. Set at registration when the
51
+ creating read declared a policy, or attached by a later read declaring one on
52
+ an entry that lacks it (hydrated snapshot entries always start without one) —
53
+ first policy wins. An armed `timer` is cleared if the entry is evicted, so a
54
+ dead key never refetches. Wrap-time validation guarantees a policy never
55
+ coexists with ttl: 0 and never sits on a non-replayable remote method.
56
+ */
57
+ export type CacheEntry = {
58
+ key: string
59
+ promise: Promise<unknown>
60
+ request?: Request
61
+ ttl: number | undefined
62
+ expiresAt: number | undefined
63
+ value?: unknown
64
+ scope?: Set<string>
65
+ settled?: boolean
66
+ hydrated?: boolean
67
+ refreshing?: boolean
68
+ invalidation?: InvalidationState
69
+ }
70
+
71
+ /* Per-key invalidate coalescing: the throttle/debounce policy plus the timer/in-flight state. */
72
+ type InvalidationState = {
73
+ refetch: () => Promise<unknown>
74
+ throttle?: number
75
+ debounce?: number
76
+ lastFiredAt?: number
77
+ timer?: ReturnType<typeof setTimeout>
78
+ /*
79
+ An invalidation that arrived while a refetch was already in flight: fireRefetch
80
+ can't run concurrently, so it records the request here and re-schedules once the
81
+ in-flight refetch settles, rather than dropping the newer invalidation.
82
+ */
83
+ pending?: boolean
84
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ Detail payload of the cache store's 'invalidate' event — the set of cache
3
+ keys one invalidation touched. A Set so each subscriber's membership check
4
+ is O(1) regardless of how many keys a single invalidate spans. Shared
5
+ between both dispatchers (cache.invalidate + streamed-resolution settling)
6
+ and the cache store's listener, so the event's shape has one definition
7
+ instead of an inline cast repeated at every site.
8
+ */
9
+ export type CacheInvalidation = Set<string>
@@ -0,0 +1,25 @@
1
+ import type { CacheSelector } from './CacheSelector.ts'
2
+
3
+ /*
4
+ Capabilities handed to a cache.on handler — exactly what behaves differently
5
+ inside a binding. `invalidate` is the binding-scoped copy of cache.invalidate
6
+ (same selector grammar, same effect): calls through it are recorded in the
7
+ binding's coverage set by function identity, so attribution survives awaits
8
+ and the coverage replays after a reconnect gap; the global cache.invalidate
9
+ still works inside a handler but is not covered. `patch` folds an
10
+ authoritative delta carried by the frame into the matching cached entries
11
+ without a refetch (ADR-0007) — `updater` maps the current decoded value to the
12
+ next; it resolves to the touched keys and is covered for reconnect resync the
13
+ same way (the gap re-invalidates, since a delta can't be replayed). Await it to
14
+ keep deltas ordered under sequential delivery. `signal` aborts when the binding
15
+ is disposed, so an async handler mid-flight can bail or cancel its own fetches.
16
+ */
17
+ export type CacheOnContext = {
18
+ invalidate: <Args, Return>(arg?: CacheSelector<Args, Return>, args?: Args) => void
19
+ patch: <Args, Return>(
20
+ arg: CacheSelector<Args, Return>,
21
+ updater: (current: Return) => Return,
22
+ args?: Args,
23
+ ) => Promise<string[]>
24
+ signal: AbortSignal
25
+ }
@@ -0,0 +1,39 @@
1
+ /*
2
+ Options for cache(). The key is always auto-derived (method+url+args for a remote
3
+ function, producer-reference+args for a plain producer): hoist a producer to a
4
+ stable reference to share its entry across calls. `ttl` is the
5
+ milliseconds-past-resolve that the entry stays live: omitted = forever, 0 =
6
+ dedupe only (entry dropped once the promise settles — the mutation idiom:
7
+ in-flight coalescing and pending() visibility, nothing retained), any other
8
+ number = TTL.
9
+ `scope` is one or more free-form tags grouping unrelated calls so one
10
+ `cache.invalidate({ scope })` drops every entry sharing any of them — pass an
11
+ array when a call belongs to multiple invalidation groups. A unique tag (e.g. a
12
+ uuid) shared by a set of calls gives them their own private invalidation group.
13
+
14
+ `global` opts the entry into the process-level store instead of the default
15
+ request-scoped one (server) — so a value computed in one request is reused by
16
+ later requests, e.g. memoising an external endpoint the server calls. Omit it
17
+ for per-request data: the default keeps a per-user response from leaking across
18
+ requests. Write only `global: true`; there is no `false` form. On the client
19
+ there is a single tab store, so the flag is a no-op there.
20
+
21
+ `invalidate` controls how a `cache.invalidate` hit on this key is applied, in ms.
22
+ `{ throttle: N }` refetches on the leading edge then at most once per N ms while
23
+ invalidations keep arriving; `{ debounce: N }` refetches only after N ms of
24
+ quiet. Both coalesce a burst of invalidations (e.g. a socket spraying
25
+ `cache.invalidate`) into far fewer calls and keep serving the existing (stale)
26
+ value until the refetch resolves — stale-while-revalidate. They affect only the
27
+ refetch-after-invalidate; the first fetch and arg-change fetches stay immediate.
28
+ A policy declares the call safe to re-run unprompted: cache() throws at wrap
29
+ time on both set at once, on ttl: 0 (nothing retained, nothing to revalidate),
30
+ and on a non-replayable remote method (replaying a write is a state change
31
+ disguised as a refresh). Producers are uncheckable — declare a policy only on
32
+ a producer that is a pure read.
33
+ */
34
+ export type CacheOptions = {
35
+ ttl?: number
36
+ scope?: string | string[]
37
+ global?: boolean
38
+ invalidate?: { throttle?: number; debounce?: number }
39
+ }
@@ -0,0 +1,17 @@
1
+ import type { CacheOptions } from './CacheOptions.ts'
2
+ import type { RawRemoteFunction } from './RawRemoteFunction.ts'
3
+ import type { RemoteFunction } from './RemoteFunction.ts'
4
+
5
+ /*
6
+ Selector grammar shared by cache.invalidate(), pending(), and refreshing():
7
+ undefined → every entry
8
+ remote fn → that function's calls (method+url prefix); fn and fn.raw match
9
+ the same set since they share wire identity
10
+ producer fn → that producer's calls (reference-id prefix)
11
+ { scope } → any entry sharing one of the requested scope tags
12
+ */
13
+ export type CacheSelector<Args, Return> =
14
+ | RemoteFunction<Args, Return>
15
+ | RawRemoteFunction<Args>
16
+ | ((args?: Args) => Promise<Return>)
17
+ | Pick<CacheOptions, 'scope'>
@@ -0,0 +1,16 @@
1
+ import type { CacheEntry } from './CacheEntry.ts'
2
+ import type { CacheSnapshotEntry } from './CacheSnapshotEntry.ts'
3
+
4
+ /*
5
+ The SSR partition of a request's cache, read after `render()` returns.
6
+ `inline` are entries settled by then (consumed via `await`, so render blocked
7
+ on them) — they ship in the first chunk's `__SSR__` blob. `pending` are
8
+ GET/DELETE entries still in flight (consumed via `{#await}`, which render emits
9
+ as a pending branch without blocking) — the streamer awaits each and pushes a
10
+ `__abideResolve` chunk as it lands. Non-GET/DELETE pending entries are dropped:
11
+ they can't be snapshotted, so the client re-fetches them live on cache miss.
12
+ */
13
+ export type CacheSnapshot = {
14
+ inline: CacheSnapshotEntry[]
15
+ pending: CacheEntry[]
16
+ }
@@ -0,0 +1,17 @@
1
+ import type { ReplayableMethod } from './ReplayableMethod.ts'
2
+
3
+ /*
4
+ Wire format for a single cached response shipped from SSR to client hydration.
5
+ Only replayable entries (see REPLAYABLE_METHODS) with a textual Content-Type
6
+ are emitted — writes must not re-fire from a snapshot, and binary bodies don't
7
+ survive a JSON round-trip.
8
+ */
9
+ export type CacheSnapshotEntry = {
10
+ key: string
11
+ url: string
12
+ method: ReplayableMethod
13
+ status: number
14
+ statusText: string
15
+ headers: Array<[string, string]>
16
+ body: string
17
+ }
@@ -0,0 +1,13 @@
1
+ /*
2
+ Per-store cache read tallies, frozen into the request's closing log record at
3
+ settle. hit = a read served from a settled retained entry (including the warm
4
+ SSR sync path); coalesced = a read that joined an in-flight call; miss = a
5
+ read that invoked its producer/remote. Reads against the process-level global
6
+ store count into the requesting scope's store, so a request's record reflects
7
+ everything that request asked the cache for.
8
+ */
9
+ export type CacheStats = {
10
+ hits: number
11
+ misses: number
12
+ coalesced: number
13
+ }
@@ -0,0 +1,39 @@
1
+ import type { CacheEntry } from './CacheEntry.ts'
2
+ import type { CacheStats } from './CacheStats.ts'
3
+
4
+ /*
5
+ Cache map paired with a reactive per-key subscriber. Calling
6
+ `subscribe(key)` from inside a tracking scope (derived / effect) registers
7
+ that scope to re-run when the entry is invalidated; called outside tracking
8
+ it's a no-op. Subscribers live for the lifetime of the store: the server
9
+ uses a fresh store per request (so subscribers die with the response), the
10
+ client uses a single module-level store (so subscribers persist for the tab).
11
+
12
+ `trackLifecycle`/`markLifecycle` are the probes' lifecycle channels, scoped
13
+ by selector prefix. `trackLifecycle(prefix)` taps a channel keyed to that
14
+ fn selector's entries (see selectorPrefix), so a `pending(fn)` reader
15
+ re-derives only when fn's calls change state; `trackLifecycle()` taps the
16
+ store-wide channel — bare and scope selectors scan many entries, so they
17
+ (deliberately) wake on every event. `markLifecycle(key)` — fired whenever a
18
+ call starts, settles, is evicted, or is invalidated — marks the store-wide
19
+ channel plus every probed prefix channel owning `key`.
20
+ */
21
+ export type CacheStore = {
22
+ entries: Map<string, CacheEntry>
23
+ events: EventTarget
24
+ subscribe: (key: string) => void
25
+ trackLifecycle: (keyPrefix?: string) => void
26
+ markLifecycle: (key?: string) => void
27
+ /*
28
+ Keys dropped by a (policy-less) invalidate, awaiting their next read. The
29
+ drop erases the entry, so the next cache() call is a cold miss with no memory
30
+ it followed an invalidate; this set carries that signal across the gap so the
31
+ replacement entry is flagged a reload (refreshing() true) rather than a
32
+ first-ever load. Consumed when that entry is created; a key invalidated but
33
+ never re-read just lingers (bounded by distinct such keys; the server's
34
+ request-scoped store discards it with the response).
35
+ */
36
+ pendingRefresh: Set<string>
37
+ /* Read tallies for the closing log record + Server-Timing; see CacheStats. */
38
+ stats: CacheStats
39
+ }
@@ -0,0 +1,13 @@
1
+ /*
2
+ The log shape a channel returns — the same callable + levels + trace as the
3
+ root logger, every record tagged with the channel name and emitted only when
4
+ DEBUG matches it. Levels are presentation, never gates: a channeled warn is
5
+ yellow when the channel is on and silent when it's off.
6
+ */
7
+ export type ChannelLog = {
8
+ (message: string, data?: unknown): void
9
+ warn(message: string, data?: unknown): void
10
+ error(value: unknown, data?: unknown): void
11
+ /* Times `work`, logs `name` with the duration at settle; rethrows failures. */
12
+ trace<Return>(name: string, work: () => Return | Promise<Return>): Promise<Return>
13
+ }
@@ -0,0 +1,11 @@
1
+ /*
2
+ Which client surfaces a verb or socket is exposed to. Browser is the
3
+ historical default; MCP and CLI flip on automatically when the
4
+ declaration carries a Standard Schema (the schema is what makes the
5
+ non-browser surfaces safe to advertise). Explicit values always win.
6
+ */
7
+ export type ClientFlags = {
8
+ browser: boolean
9
+ mcp: boolean
10
+ cli: boolean
11
+ }
@@ -0,0 +1,6 @@
1
+ export type CompileTarget =
2
+ | 'bun-darwin-arm64'
3
+ | 'bun-darwin-x64'
4
+ | 'bun-linux-arm64'
5
+ | 'bun-linux-x64'
6
+ | 'bun-windows-x64'
@@ -0,0 +1,13 @@
1
+ import type { Log } from './Log.ts'
2
+
3
+ /*
4
+ The framework's internal voice — the public Log shape bound to the always-on
5
+ 'abide' channel, plus the CLI/build styling voices: info (plain message),
6
+ success (green), detail (dim secondary text). Internal only; apps speak
7
+ through their own channel via the public log.
8
+ */
9
+ export type FrameworkLog = Log & {
10
+ info(message: string): void
11
+ success(message: string): void
12
+ detail(message: string): void
13
+ }
@@ -0,0 +1 @@
1
+ export type HttpVerb = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'HEAD'
@@ -0,0 +1,9 @@
1
+ /*
2
+ The launcher/CLI-owned record of the last connection, kept in the data dir so it
3
+ survives relaunch and is readable before any window or session opens. It records
4
+ the *intent*, not a concrete embedded URL — an embedded server picks a fresh port
5
+ each launch, so only `{ kind: 'embedded' }` is durable; a remote connection keeps
6
+ its url. resolveLaunchTarget / resolveCliTarget read it; /connect and /start write
7
+ it; /disconnect clears it.
8
+ */
9
+ export type LastConnection = { kind: 'embedded' } | { kind: 'url'; url: string }