@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,324 @@
1
+ import { createLifecycleChannel } from '../shared/createLifecycleChannel.ts'
2
+ import { createSubscriber } from '../shared/createSubscriber.ts'
3
+ import { SocketDisconnectedError } from '../shared/SocketDisconnectedError.ts'
4
+ import { tailProbeSlot } from '../shared/tailProbeSlot.ts'
5
+ import type { Subscribable } from '../shared/types/Subscribable.ts'
6
+ import type { TailOptions } from '../shared/types/TailOptions.ts'
7
+
8
+ type TailStatus = 'pending' | 'open' | 'done' | 'error'
9
+
10
+ /*
11
+ One entry shape for both read forms: the bare latest-wins read is a window of
12
+ 1 projected to its single frame, so the frame loop, reconnect handling, and
13
+ probes have exactly one path. The bare form keys by name alone (so `tail(x)`
14
+ and `tail(x, { last: 1 })` stay independent subscriptions); probes match on
15
+ `source`.
16
+ */
17
+ type Entry<T> = {
18
+ source: string
19
+ key: string
20
+ /* window cap; 1 for the bare latest-wins form */
21
+ last: number
22
+ window: T[]
23
+ error: Error | undefined
24
+ status: TailStatus
25
+ refreshing: boolean
26
+ /* true while the createSubscriber connect callback holds the iterator open */
27
+ live: boolean
28
+ tap: () => void
29
+ }
30
+
31
+ const registry = new Map<string, Entry<unknown>>()
32
+
33
+ /*
34
+ Registry-wide lifecycle channel for the pending()/refreshing() probes — the
35
+ tail-side counterpart of the cache store's. Probes match entries by source
36
+ name (or all) without creating them, so they tap one "membership or state
37
+ changed" signal instead of opening a stream the way a tail() read would.
38
+ */
39
+ const lifecycle = createLifecycleChannel()
40
+
41
+ /*
42
+ Prober for the shared pending()/refreshing() probes. Probes report, never
43
+ act: an absent entry is read as "no value yet" (pending) without opening a
44
+ stream. A name spans every entry on that source — latest-wins and window
45
+ forms alike; the bare form spans every registered stream.
46
+ */
47
+ tailProbeSlot.probe = (name) => {
48
+ lifecycle.track()
49
+ const entries = [...registry.values()].filter(
50
+ (entry) => name === undefined || entry.source === name,
51
+ )
52
+ return {
53
+ pending:
54
+ (name !== undefined && entries.length === 0) ||
55
+ entries.some((entry) => entry.status === 'pending'),
56
+ refreshing: entries.some((entry) => entry.refreshing),
57
+ }
58
+ }
59
+
60
+ /*
61
+ Reactive consumer for streaming sources. Takes a Subscribable<T> — the shape
62
+ both `Socket<T>` (declared under src/server/sockets/) and the result of
63
+ `fn.stream(args)` satisfy:
64
+
65
+ const latest = $derived(tail(chat)) // socket, latest frame
66
+ const recent = $derived(tail(chat, { last: 20 })) // live window of the last ≤20
67
+ const tick = $derived(tail(tickFeed.stream())) // rpc stream
68
+
69
+ The bare form is latest-wins: T | undefined, pending until the first frame.
70
+ The window form returns T[] — `[]` while pending, never undefined — holding
71
+ the last ≤`last` frames however they arrived. Seeding rides the source's
72
+ optional retention capability (`Subscribable.tail(count)`): a socket declared
73
+ `{ tail: n }` replays up to `last` retained frames (1 for the bare form — a
74
+ latest-wins reader only needs the newest); a source without the capability
75
+ (rpc stream, undeclared socket) starts live-only. tail() never requires
76
+ retention — the window semantics are identical either way, only how much
77
+ past it can show differs.
78
+
79
+ Lifecycle mirrors cache(): the entry's tracker is a createSubscriber,
80
+ so the first derived read in a tracking scope opens the underlying iterator
81
+ and the last derived to stop reading closes it. Many deriveds reading the
82
+ same source share one underlying subscription — the registry dedupes by
83
+ `subscribable.name`, with `last` folded into the key, so the bare form and
84
+ each window size are independent subscriptions. Passing fresh `fn.stream(args)`
85
+ Subscribables across re-renders is safe: same args → same key → shared
86
+ subscription. tail.error / tail.status take the same options to address the
87
+ same entry.
88
+
89
+ Reconnect-with-retained-value: a transport loss (the typed
90
+ SocketDisconnectedError, raised only by the ws channel — an rpc stream is a
91
+ one-shot Response and never disconnects) does not surface as an error. The
92
+ entry keeps its window, flags `refreshing` (the probe contract: value held,
93
+ fresher source in flight — never merely `open`), and re-invokes the source;
94
+ the channel's backoff owns the retry. The reopened source's replay commits
95
+ over the window atomically at the `replayed` boundary (TailHooks) — appended
96
+ it would duplicate, rebuilt frame-by-frame it would flash — and an empty
97
+ replay keeps the held window, with live frames appending after. For the
98
+ bare form the commit is exactly latest-wins convergence. Initial opens seed
99
+ the same way, so a window's first paint is the full seed, not a staircase.
100
+
101
+ tail is a no-op on the server (returns undefined / []) — SSR can't keep a
102
+ stream open across the request boundary. Pages that want a seeded value in
103
+ the initial HTML should fetch via cache() against an HTTP rpc handler and
104
+ layer tail() on top for live updates after hydration.
105
+
106
+ Errors are surfaced through tail.error(x) rather than thrown, so reading
107
+ from a $derived can't crash the component. Status distinguishes "haven't
108
+ received the first frame" (pending) from "stream ended cleanly" (done) and
109
+ "wire layer surfaced an error" (error).
110
+ */
111
+ // @readme tail
112
+ export function tail<T>(subscribable: Subscribable<T>): T | undefined
113
+ export function tail<T>(subscribable: Subscribable<T>, options: TailOptions): T[]
114
+ export function tail<T>(subscribable: Subscribable<T>, options?: TailOptions): T | T[] | undefined {
115
+ if (options) {
116
+ return readField(subscribable, options, 'window') ?? []
117
+ }
118
+ return readField(subscribable, undefined, 'window')?.[0]
119
+ }
120
+
121
+ tail.error = function tailError<T>(
122
+ subscribable: Subscribable<T>,
123
+ options?: TailOptions,
124
+ ): Error | undefined {
125
+ return readField(subscribable, options, 'error')
126
+ }
127
+
128
+ tail.status = function tailStatus<T>(
129
+ subscribable: Subscribable<T>,
130
+ options?: TailOptions,
131
+ ): TailStatus {
132
+ return readField(subscribable, options, 'status') ?? 'pending'
133
+ }
134
+
135
+ function readField<T, K extends keyof Entry<T>>(
136
+ subscribable: Subscribable<T>,
137
+ options: TailOptions | undefined,
138
+ field: K,
139
+ ): Entry<T>[K] | undefined {
140
+ if (options && (!Number.isInteger(options.last) || options.last < 1)) {
141
+ throw new RangeError(`[abide] tail() \`last\` must be an integer ≥ 1, got ${options.last}`)
142
+ }
143
+ if (typeof window === 'undefined') {
144
+ return undefined
145
+ }
146
+ const entry = getOrCreateEntry(subscribable, options)
147
+ entry.tap()
148
+ const value = entry[field]
149
+ /*
150
+ Untracked read (outside $derived/$effect): tap() never connects, so no
151
+ teardown will ever evict the entry — drop it now or it sits in the
152
+ registry as a permanently-pending zombie the bare probes keep seeing.
153
+ */
154
+ if (!entry.live) {
155
+ evictIfCurrent(entry as Entry<unknown>)
156
+ }
157
+ return value
158
+ }
159
+
160
+ /* Delete only if this entry still owns its key — a fresh Subscribable with the
161
+ same name may have replaced it, and a stale cleanup must not nuke the new entry. */
162
+ function evictIfCurrent(entry: Entry<unknown>): boolean {
163
+ if (registry.get(entry.key) === entry) {
164
+ registry.delete(entry.key)
165
+ return true
166
+ }
167
+ return false
168
+ }
169
+
170
+ function getOrCreateEntry<T>(
171
+ subscribable: Subscribable<T>,
172
+ options: TailOptions | undefined,
173
+ ): Entry<T> {
174
+ const key = options ? `${subscribable.name}#${options.last}` : subscribable.name
175
+ const cached = registry.get(key)
176
+ if (cached) {
177
+ return cached as Entry<T>
178
+ }
179
+ const last = options?.last ?? 1
180
+ const entry: Entry<T> = {
181
+ source: subscribable.name,
182
+ key,
183
+ last,
184
+ window: [],
185
+ error: undefined,
186
+ status: 'pending',
187
+ refreshing: false,
188
+ live: false,
189
+ tap: () => undefined,
190
+ }
191
+ entry.tap = createSubscriber((update) => {
192
+ entry.window = []
193
+ entry.error = undefined
194
+ entry.status = 'pending'
195
+ entry.refreshing = false
196
+ entry.live = true
197
+ let cancelled = false
198
+ const notify = () => {
199
+ update()
200
+ lifecycle.mark()
201
+ }
202
+ /*
203
+ Seed-and-commit: frames from a retaining source accumulate silently
204
+ until its in-band `replayed` boundary, then commit to the window in
205
+ one update — readers never see the window rebuild frame-by-frame.
206
+ An empty seed keeps the held window across a gap: nothing was
207
+ replayed, so nothing can duplicate, and the live frames that follow
208
+ append. Sources without the capability have no replay; their frames
209
+ append directly.
210
+ */
211
+ let seeding = false
212
+ let seed: T[] = []
213
+ const commit = () => {
214
+ if (cancelled || !seeding) {
215
+ return
216
+ }
217
+ seeding = false
218
+ if (seed.length > 0) {
219
+ entry.window = seed
220
+ seed = []
221
+ }
222
+ if (entry.window.length > 0) {
223
+ entry.status = 'open'
224
+ }
225
+ entry.refreshing = false
226
+ notify()
227
+ }
228
+ /*
229
+ A retaining source bounds replay to what the reader keeps: 1 frame
230
+ seeds the bare form, `last` seeds a window.
231
+ */
232
+ const open = () => {
233
+ if (!subscribable.tail) {
234
+ return subscribable[Symbol.asyncIterator]()
235
+ }
236
+ seeding = true
237
+ seed = []
238
+ return subscribable.tail(last, { replayed: commit })[Symbol.asyncIterator]()
239
+ }
240
+ /* `let`: the reconnect path swaps in a fresh iterator; teardown closes the current one. */
241
+ let iterator = open()
242
+ ;(async () => {
243
+ while (!cancelled) {
244
+ try {
245
+ const next = await iterator.next()
246
+ if (cancelled) {
247
+ return
248
+ }
249
+ if (next.done) {
250
+ /* a retaining source that ends without signalling still commits its seed */
251
+ commit()
252
+ if (entry.status !== 'error') {
253
+ entry.status = 'done'
254
+ }
255
+ entry.refreshing = false
256
+ notify()
257
+ return
258
+ }
259
+ if (seeding) {
260
+ seed.push(next.value)
261
+ if (seed.length > last) {
262
+ seed.shift()
263
+ }
264
+ continue
265
+ }
266
+ /*
267
+ Probes read only status/refreshing, so the registry
268
+ channel pings on transitions, not per frame — a chatty
269
+ stream must not re-derive every bare pending()/refreshing()
270
+ reader on each value. (A frame after a reconnect is the
271
+ seed landing — current again, hence a transition.)
272
+ */
273
+ const transitioned = entry.status !== 'open' || entry.refreshing
274
+ /* One copy per frame: take the surviving suffix, then append. */
275
+ const base = entry.window
276
+ const frames =
277
+ base.length < last ? base.slice() : base.slice(base.length - last + 1)
278
+ frames.push(next.value)
279
+ entry.window = frames
280
+ entry.status = 'open'
281
+ entry.refreshing = false
282
+ update()
283
+ if (transitioned) {
284
+ lifecycle.mark()
285
+ }
286
+ } catch (error) {
287
+ if (cancelled) {
288
+ return
289
+ }
290
+ if (error instanceof SocketDisconnectedError) {
291
+ /*
292
+ Recoverable transport loss: retain the window, flag the
293
+ gap, reopen — open() re-arms seeding so the reopened
294
+ source's replay commits atomically over the held
295
+ window. The fresh sub frame queues on the channel and
296
+ flushes when its backoff attempt reconnects, so this
297
+ loop just awaits the next push — no spin.
298
+ */
299
+ entry.refreshing = entry.window.length > 0
300
+ notify()
301
+ iterator = open()
302
+ continue
303
+ }
304
+ entry.error = error instanceof Error ? error : new Error(String(error))
305
+ entry.status = 'error'
306
+ entry.refreshing = false
307
+ notify()
308
+ return
309
+ }
310
+ }
311
+ })()
312
+ lifecycle.mark()
313
+ return () => {
314
+ cancelled = true
315
+ entry.live = false
316
+ iterator.return?.(undefined)?.catch(() => undefined)
317
+ if (evictIfCurrent(entry as Entry<unknown>)) {
318
+ lifecycle.mark()
319
+ }
320
+ }
321
+ })
322
+ registry.set(key, entry as Entry<unknown>)
323
+ return entry
324
+ }
@@ -0,0 +1,9 @@
1
+ import type { UiComponent } from '../runtime/types/UiComponent.ts'
2
+
3
+ /*
4
+ Manifest of directory URL → layout.abide module loader. Produced by the resolver
5
+ plugin from `layout.abide` files anywhere under src/ui/pages. A layout's key is its
6
+ folder path, so it wraps every page at or below that folder; the renderer and router
7
+ resolve a route's chain (outermost first) via layoutChainForRoute.
8
+ */
9
+ export type Layouts = Record<string, () => Promise<{ default: UiComponent }>>
@@ -0,0 +1,8 @@
1
+ import type { UiComponent } from '../runtime/types/UiComponent.ts'
2
+
3
+ /*
4
+ Manifest of route URL → page.abide module loader. Produced by the resolver plugin
5
+ from `page.abide` files anywhere under src/ui/pages. `layout.abide` files form a
6
+ parallel manifest (see Layouts); there is no error manifest.
7
+ */
8
+ export type Pages = Record<string, () => Promise<{ default: UiComponent }>>
package/src/preload.ts ADDED
@@ -0,0 +1,19 @@
1
+ // @readme plumbing
2
+ import { plugin } from 'bun'
3
+ import { abideResolverPlugin } from './abideResolverPlugin.ts'
4
+ import { abideUiPlugin } from './lib/ui/compile/abideUiPlugin.ts'
5
+
6
+ const mode = (process.env.ABIDE_TARGET ?? 'server') as 'server' | 'client'
7
+
8
+ await plugin(abideUiPlugin)
9
+ await plugin(abideResolverPlugin({ target: mode }))
10
+
11
+ await plugin({
12
+ name: 'css-noop',
13
+ setup(build) {
14
+ build.onLoad({ filter: /\.css$/ }, () => ({
15
+ contents: 'export default {};',
16
+ loader: 'js',
17
+ }))
18
+ },
19
+ })
@@ -0,0 +1,153 @@
1
+ import { Glob } from 'bun'
2
+ import { abideLog } from './lib/shared/abideLog.ts'
3
+
4
+ const TEMPLATE_DIR = new URL('../template', import.meta.url).pathname
5
+ const OWN_PACKAGE_JSON = new URL('../package.json', import.meta.url).pathname
6
+
7
+ /*
8
+ Copies the bundled template directory into `${cwd}/${name}`, installs its
9
+ dependencies, and — when `dev` is set — starts the dev server in the new
10
+ project, so one command ends in a running app. A process can't change its
11
+ parent shell's cwd, so `cd` is printed as the step for when editing starts.
12
+ Refuses to write into a non-empty directory so an accidental run doesn't
13
+ overwrite real work. `install: false` (the `--no-install` flag) skips the
14
+ install — for CI flows that swap the dependency for a packed tarball before
15
+ installing, and offline scaffolds. An install *failure* doesn't fail the
16
+ scaffold: the tree is intact, so print `bun install` as a next step instead.
17
+ `dev` only fires after a successful install and holds until the server exits.
18
+ */
19
+ export async function scaffold({
20
+ cwd = process.cwd(),
21
+ name,
22
+ install = true,
23
+ dev = false,
24
+ }: {
25
+ cwd?: string
26
+ name: string
27
+ install?: boolean
28
+ dev?: boolean
29
+ }): Promise<string> {
30
+ const trimmed = name.trim()
31
+ if (trimmed === '') {
32
+ throw new Error('[abide] project name is required: bunx abide scaffold <name>')
33
+ }
34
+ const target = resolveTarget(cwd, trimmed)
35
+ if (await targetIsNonEmpty(target)) {
36
+ throw new Error(`[abide] target directory is not empty: ${target}`)
37
+ }
38
+ if (!(await Bun.file(`${TEMPLATE_DIR}/package.json`).exists())) {
39
+ throw new Error(`[abide] template missing at ${TEMPLATE_DIR}`)
40
+ }
41
+ await copyTree(TEMPLATE_DIR, target)
42
+ await pinAbideToOwnVersion(target)
43
+ const installed = install ? await installDependencies(target) : false
44
+ abideLog.success(`scaffolded abide project at ${target}`)
45
+ if (target !== cwd) {
46
+ abideLog.detail(` to start editing: cd ${trimmed}`)
47
+ }
48
+ if (dev && installed) {
49
+ await runDevServer(target)
50
+ return target
51
+ }
52
+ abideLog.detail(' to run it:')
53
+ if (!installed) {
54
+ abideLog.detail(' bun install')
55
+ }
56
+ abideLog.detail(' bun run dev')
57
+ return target
58
+ }
59
+
60
+ /* Runs `bun install` in the scaffolded project, streaming its output. */
61
+ async function installDependencies(target: string): Promise<boolean> {
62
+ const proc = Bun.spawn(['bun', 'install'], {
63
+ cwd: target,
64
+ stdout: 'inherit',
65
+ stderr: 'inherit',
66
+ })
67
+ if ((await proc.exited) === 0) {
68
+ return true
69
+ }
70
+ abideLog.warn('bun install failed — run it yourself once the cause is fixed')
71
+ return false
72
+ }
73
+
74
+ /* Starts the project's dev server (Ctrl-C stops it) and waits for it to exit. */
75
+ async function runDevServer(target: string): Promise<void> {
76
+ abideLog.detail(' starting the dev server (Ctrl-C to stop)…')
77
+ const proc = Bun.spawn(['bun', 'run', 'dev'], {
78
+ cwd: target,
79
+ stdin: 'inherit',
80
+ stdout: 'inherit',
81
+ stderr: 'inherit',
82
+ })
83
+ await proc.exited
84
+ }
85
+
86
+ /*
87
+ Rewrites the scaffolded package.json so `abide` is pinned to the
88
+ version of the CLI that ran the scaffold. The template's static pin is only a
89
+ fallback — deriving the range at scaffold time means a stale template can
90
+ never install a framework version the docs don't describe.
91
+ */
92
+ async function pinAbideToOwnVersion(target: string): Promise<void> {
93
+ const { name, version } = await Bun.file(OWN_PACKAGE_JSON).json()
94
+ const manifestFile = Bun.file(`${target}/package.json`)
95
+ const manifest = await manifestFile.json()
96
+ manifest.dependencies[name] = `^${version}`
97
+ await Bun.write(manifestFile, `${JSON.stringify(manifest, undefined, 4)}\n`)
98
+ }
99
+
100
+ /*
101
+ Copies every file under `from` into `to`, preserving relative paths. Uses
102
+ Bun.Glob to enumerate (dotfiles included) and Bun.write to materialize each
103
+ file — Bun.write auto-creates parent directories.
104
+ */
105
+ async function copyTree(from: string, to: string): Promise<void> {
106
+ const files = await Array.fromAsync(
107
+ new Glob('**/*').scan({ cwd: from, onlyFiles: true, dot: true }),
108
+ )
109
+ await Promise.all(
110
+ files.map(async (relativePath) => {
111
+ const source = Bun.file(`${from}/${relativePath}`)
112
+ await Bun.write(`${to}/${relativePath}`, source)
113
+ }),
114
+ )
115
+ }
116
+
117
+ /*
118
+ Resolves the user-supplied name against the working directory. Absolute
119
+ paths (`/tmp/foo`) and `~`-prefixed paths are used as-is; relative names
120
+ are joined onto `cwd`.
121
+ */
122
+ function resolveTarget(cwd: string, name: string): string {
123
+ if (name === '.' || name === './') {
124
+ return cwd
125
+ }
126
+ if (name.startsWith('/')) {
127
+ return name
128
+ }
129
+ if (name.startsWith('~/')) {
130
+ const home = process.env.HOME ?? ''
131
+ return `${home}${name.slice(1)}`
132
+ }
133
+ return `${cwd}/${name}`
134
+ }
135
+
136
+ /*
137
+ True when the target exists and contains at least one entry. Uses Bun.Glob
138
+ rather than fs.readdir to honor the project's "Bun-first" rule. A missing
139
+ directory is reported as empty so first-time scaffolds proceed.
140
+ */
141
+ async function targetIsNonEmpty(target: string): Promise<boolean> {
142
+ try {
143
+ for await (const _ of new Glob('*').scan({ cwd: target, onlyFiles: false, dot: true })) {
144
+ return true
145
+ }
146
+ } catch (error) {
147
+ if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
148
+ return false
149
+ }
150
+ throw error
151
+ }
152
+ return false
153
+ }
@@ -0,0 +1,19 @@
1
+ import type { BunPlugin } from 'bun'
2
+ import { abideResolverPlugin } from './abideResolverPlugin.ts'
3
+ import { abideUiPlugin } from './lib/ui/compile/abideUiPlugin.ts'
4
+
5
+ /*
6
+ The server-target Bun.build plugin pair shared by compile / buildCli / bundleApp:
7
+ the abide-ui `.abide` loader (so SSR `render()` resolves) plus abide's virtual-
8
+ module resolver. `embedAssets` flips on the gzip asset embed used by the
9
+ standalone server binary; the CLI + launcher builds leave it off.
10
+ */
11
+ export function serverBuildPlugins({
12
+ cwd,
13
+ embedAssets = false,
14
+ }: {
15
+ cwd: string
16
+ embedAssets?: boolean
17
+ }): BunPlugin[] {
18
+ return [abideUiPlugin, abideResolverPlugin({ cwd, embedAssets, target: 'server' })]
19
+ }
@@ -0,0 +1,95 @@
1
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
2
+ import * as appMod from './_virtual/app.ts'
3
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
4
+ import { appInfo } from './_virtual/app-info.ts'
5
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
6
+ import { assets } from './_virtual/assets.ts'
7
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
8
+ import cliProgramName from './_virtual/cli-name.ts'
9
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
10
+ import { layouts } from './_virtual/layouts.ts'
11
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
12
+ import mcp from './_virtual/mcp.ts'
13
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
14
+ import { mcpResources } from './_virtual/mcp-resources.ts'
15
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
16
+ import { pages } from './_virtual/pages.ts'
17
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
18
+ import { prompts } from './_virtual/prompts.ts'
19
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
20
+ import { publicAssets } from './_virtual/public-assets.ts'
21
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
22
+ import { rpc } from './_virtual/rpc.ts'
23
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
24
+ import { shell } from './_virtual/shell.ts'
25
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
26
+ import { sockets } from './_virtual/sockets.ts'
27
+ import { exitWithParent } from './lib/bundle/exitWithParent.ts'
28
+ import { loadEnvFromBinaryDir } from './lib/cli/loadEnvFromBinaryDir.ts'
29
+ import { createServer } from './lib/server/runtime/createServer.ts'
30
+ import { requestContext } from './lib/server/runtime/requestContext.ts'
31
+ import { resolvePageSnapshot } from './lib/server/runtime/resolvePageSnapshot.ts'
32
+ import { createCacheStore } from './lib/shared/createCacheStore.ts'
33
+ import { loadEnvFromDataDir } from './lib/shared/loadEnvFromDataDir.ts'
34
+ import { runningAsStandaloneBinary } from './lib/shared/runningAsStandaloneBinary.ts'
35
+ import { setCacheStoreResolver } from './lib/shared/setCacheStoreResolver.ts'
36
+ import { setGlobalCacheStoreResolver } from './lib/shared/setGlobalCacheStoreResolver.ts'
37
+ import { setPageResolver } from './lib/shared/setPageResolver.ts'
38
+
39
+ /*
40
+ Resolve config into process.env before anything reads it (createServer reads
41
+ PORT, app code reads Bun.env.*). Standalone-only: data-dir first so the user's
42
+ saved config wins over the binary-dir shipped default; both back-fill only what
43
+ the shell didn't already set. A bundle launched via `open` has cwd `/`, so the
44
+ data-dir `.env` is how it gets its config at all. Under `bun dev`/`bun start`
45
+ these bundle layers don't apply — the project's own CWD `.env` (Bun-autoloaded)
46
+ is the config — so loading them would let a stray data-dir `PORT` defeat dev's
47
+ port scan.
48
+ */
49
+ if (runningAsStandaloneBinary()) {
50
+ await loadEnvFromDataDir(cliProgramName)
51
+ await loadEnvFromBinaryDir()
52
+ }
53
+
54
+ /*
55
+ Eager-import src/server/config.ts (via abide:config) now that every .env layer
56
+ is merged into process.env — its top-level `env(schema)` validates the
57
+ environment and fails the boot loudly here, before the server starts, rather
58
+ than lazily on the first handler that imports `$server/config`. A dynamic
59
+ import (not a static top-level one) so it runs after the merge above, not at
60
+ module-eval time. No-op when the file is absent.
61
+ */
62
+ // @ts-expect-error virtual module resolved by abideResolverPlugin
63
+ await import('./_virtual/config.ts')
64
+
65
+ // In a bundle, tie this server's life to the launcher's (no-op standalone).
66
+ exitWithParent()
67
+
68
+ setCacheStoreResolver(() => requestContext.getStore()?.cache)
69
+
70
+ setPageResolver(resolvePageSnapshot)
71
+
72
+ /*
73
+ Process-level store for cache(fn, { global: true }) — one per server process,
74
+ outlives every request so memoised external calls are shared across them.
75
+ */
76
+ const globalCacheStore = createCacheStore()
77
+ setGlobalCacheStoreResolver(() => globalCacheStore)
78
+
79
+ await createServer({
80
+ pages,
81
+ layouts,
82
+ rpc,
83
+ sockets,
84
+ prompts,
85
+ shell,
86
+ app: appMod,
87
+ assets,
88
+ publicAssets,
89
+ mcpResources,
90
+ mcp,
91
+ cliProgramName,
92
+ appInfo,
93
+ // Set by the dev orchestrator (devEntry); mounts the live-reload channel.
94
+ dev: Bun.env.ABIDE_DEV === '1',
95
+ })
@@ -0,0 +1,4 @@
1
+ [test]
2
+ # Register the abide preload so `.abide` components compile under `bun test`
3
+ # (same runtime as the server).
4
+ preload = ["@abide/abide/preload"]
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "abide-app",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "abide dev",
8
+ "build": "abide build",
9
+ "start": "abide start",
10
+ "compile": "abide compile",
11
+ "cli": "abide cli",
12
+ "bundle": "abide bundle",
13
+ "test": "bun test"
14
+ },
15
+ "dependencies": {
16
+ "@abide/abide": "^0.27.0"
17
+ }
18
+ }