@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,14 @@
1
+ import { dataDirEnvPath } from './dataDirEnvPath.ts'
2
+ import { loadEnvFile } from './loadEnvFile.ts'
3
+
4
+ /*
5
+ Loads the user's `.env` from the program's per-user data dir into `process.env`.
6
+ This is the cwd-independent config layer — where the connect-screen form writes
7
+ the user's answers, and where a bundle launched via `open` (cwd `/`, so Bun's
8
+ CWD `.env` autoload finds nothing) actually picks up its config. Loaded before
9
+ the binary-dir `.env`, so a user's saved config overrides the shipped default;
10
+ still loses to a shell export or a CWD `.env` (fill-when-unset, see loadEnvFile).
11
+ */
12
+ export async function loadEnvFromDataDir(programName: string): Promise<void> {
13
+ await loadEnvFile(dataDirEnvPath(programName))
14
+ }
@@ -0,0 +1,24 @@
1
+ import { appNameSlot } from './appNameSlot.ts'
2
+ import { createChannelLog } from './createChannelLog.ts'
3
+ import type { ChannelLog } from './types/ChannelLog.ts'
4
+ import type { Log } from './types/Log.ts'
5
+
6
+ /*
7
+ The unified logger: every record carries the request-scope context (short
8
+ trace id, +elapsed, verb+path) when one is active, plus a channel — the
9
+ line's speaker. `log(...)`/`warn`/`error`/`trace` speak on the app's own
10
+ always-on channel (the app name, resolved per emission so boot order doesn't
11
+ matter); `log.channel(name)` returns the same shape on a DEBUG-gated
12
+ diagnostic channel (browser: the `abide-debug` localStorage key). Renders as
13
+ the tab-separated tsv format (default) or one JSON object per line under
14
+ ABIDE_LOG_FORMAT=json.
15
+ */
16
+ // @readme observability
17
+ export const log: Log = Object.assign(
18
+ createChannelLog(() => appNameSlot.name ?? 'app', true),
19
+ {
20
+ channel(name: string): ChannelLog {
21
+ return createChannelLog(() => name, false)
22
+ },
23
+ },
24
+ )
@@ -0,0 +1,28 @@
1
+ import { emitLogRecord } from './emitLogRecord.ts'
2
+ import type { CacheStats } from './types/CacheStats.ts'
3
+
4
+ /*
5
+ Emits the request's closing record — the line that ends a trace: status as
6
+ the message, total duration at settle, cache read tallies frozen at that
7
+ moment. Framework-internal (runWithRequestScope at settle, the asset paths
8
+ directly); not part of the public log surface because its structured fields
9
+ only make sense at the request boundary the framework owns.
10
+ */
11
+ export function logClosingRecord(
12
+ method: string,
13
+ path: string,
14
+ status: number,
15
+ durationMs: number,
16
+ cache?: CacheStats,
17
+ ): void {
18
+ emitLogRecord({
19
+ level: 'info',
20
+ msg: '',
21
+ channel: 'abide',
22
+ method,
23
+ path,
24
+ status,
25
+ durationMs,
26
+ cache,
27
+ })
28
+ }
@@ -0,0 +1,13 @@
1
+ import type { LogRecord } from './types/LogRecord.ts'
2
+
3
+ /*
4
+ Passive observation seam for the unified log. emitLogRecord calls the tap (when
5
+ set) with every fully-built record, before formatting — so an observer sees the
6
+ exact structured record stdout/console would, trace context and all. The
7
+ inspector installs one to feed its live event buffer; unset everywhere else, so
8
+ the call no-ops with zero allocation. One slot, not a listener set: the single
9
+ in-process observer fans out to its own readers. Mirrors requestScopeSlot.
10
+ */
11
+ export const logTapSlot: { tap: ((record: LogRecord) => void) | undefined } = {
12
+ tap: undefined,
13
+ }
@@ -0,0 +1,39 @@
1
+ import { abideLog } from './abideLog.ts'
2
+
3
+ /*
4
+ Builds one of abide's virtual manifest modules — the `{ key: () => import(...) }`
5
+ map the bundler emits for rpc / sockets / prompts / pages / layouts. They differ
6
+ only in their files, the key derived per file, the import dir, the export name,
7
+ and the log label; this is the single shape they share.
8
+ */
9
+ export function manifestModule(options: {
10
+ files: string[]
11
+ keyForFile: (file: string) => string
12
+ importDir: string
13
+ exportName: string
14
+ /*
15
+ A plain `resolved N <label>: keys` line at build time, when set. Omitted for
16
+ manifests whose contents are enumerated once at boot as an aligned table (see
17
+ logExposedSurfaces) — rpc/sockets/pages/layouts — which both avoids the
18
+ redundant list and the double-log of manifests (pages/layouts) loaded by both
19
+ the server and client bundles. prompts/errors have no table, so they pass a
20
+ label to keep their build-time line.
21
+ */
22
+ label?: string
23
+ }): { contents: string; loader: 'js' } {
24
+ const entries = options.files
25
+ .toSorted()
26
+ .map((file) => ({ key: options.keyForFile(file), file }))
27
+ const lines = entries
28
+ .map(
29
+ ({ key, file }) =>
30
+ ` ${JSON.stringify(key)}: () => import(${JSON.stringify(`${options.importDir}/${file}`)}),`,
31
+ )
32
+ .join('\n')
33
+ if (options.label && entries.length > 0) {
34
+ abideLog.info(
35
+ `resolved ${entries.length} ${options.label}: ${entries.map((entry) => entry.key).join(', ')}`,
36
+ )
37
+ }
38
+ return { contents: `export const ${options.exportName} = {\n${lines}\n}\n`, loader: 'js' }
39
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ One DEBUG pattern against one channel name, npm-debug conventions:
3
+ `*` matches everything, `abide:*` matches 'abide' and every 'abide:…'
4
+ sub-channel, anything else matches exactly. Negation (`-` prefix) is the
5
+ caller's concern — patterns arrive here already stripped.
6
+ */
7
+ export function matchesDebugPattern(name: string, pattern: string): boolean {
8
+ if (pattern === '*') {
9
+ return true
10
+ }
11
+ if (pattern.endsWith(':*')) {
12
+ const prefix = pattern.slice(0, -2)
13
+ return name === prefix || name.startsWith(`${prefix}:`)
14
+ }
15
+ return pattern === name
16
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ Memoises an async loader keyed by string: the first call for a key starts the
3
+ load and caches its promise; later calls reuse it. `load` returns undefined when
4
+ the key has no loader, which is passed through (and not cached) so the caller can
5
+ treat "unknown key" distinctly from "loaded value". Used by the rpc-module and
6
+ socket-module load caches, which share this exact shape.
7
+ */
8
+ export function memoizeByKey<T>(
9
+ load: (key: string) => Promise<T> | undefined,
10
+ ): (key: string) => Promise<T> | undefined {
11
+ const cache = new Map<string, Promise<T>>()
12
+ return (key) => {
13
+ const existing = cache.get(key)
14
+ if (existing) {
15
+ return existing
16
+ }
17
+ const started = load(key)
18
+ if (!started) {
19
+ return undefined
20
+ }
21
+ cache.set(key, started)
22
+ // Evict on rejection so a transient load failure doesn't poison the key
23
+ // forever; the next call retries. The separate handle doesn't swallow the
24
+ // rejection seen by the returned promise.
25
+ void started.catch(() => {
26
+ if (cache.get(key) === started) {
27
+ cache.delete(key)
28
+ }
29
+ })
30
+ return started
31
+ }
32
+ }
@@ -0,0 +1,10 @@
1
+ import type { CompileTarget } from './types/CompileTarget.ts'
2
+
3
+ /*
4
+ Prepends the `bun-` prefix if missing so CLI users can pass either
5
+ `darwin-arm64` or the canonical `bun-darwin-arm64` form to `--target`.
6
+ */
7
+ export function normalizeTarget(input: string): CompileTarget {
8
+ const normalized = input.startsWith('bun-') ? input : `bun-${input}`
9
+ return normalized as CompileTarget
10
+ }
@@ -0,0 +1,51 @@
1
+ import { createSubscriber } from './createSubscriber.ts'
2
+ import { requestScopeSlot } from './requestScopeSlot.ts'
3
+
4
+ /*
5
+ Reactive network-connectivity probe in the pending()/refreshing() family:
6
+ reading it from a $derived/$effect re-runs that scope when the browser's
7
+ online/offline events fire. navigator.onLine's *offline* signal is reliable
8
+ (a true network loss always reports); its online value can false-positive
9
+ behind captive portals — verified backend reachability is a separate,
10
+ opt-in concern (the bundle launcher's liveness watch owns it for bundles).
11
+
12
+ On the server it reflects the *calling client's* reported connectivity — the
13
+ OFFLINE_HEADER a abide RPC fetch stamps while offline (read off the request
14
+ scope). In a bundle the client and embedded server share a machine, so this is
15
+ exactly the outbound reachability a handler reaching external sites needs:
16
+ `if (!online()) return error(503)` skips a doomed fetch. True outside any
17
+ request scope (boot, cron) and for non-abide-client requests (no header).
18
+
19
+ It answers "did the calling client report itself offline," NOT "can this
20
+ server reach the internet." So during SSR it is always true: the initial
21
+ render is a browser document navigation abide didn't issue, carrying no
22
+ header — there's been no client round-trip to report connectivity yet. Gate
23
+ external fetches on online() in the RPC/handler path (a real client called),
24
+ not in SSR; in SSR bound the fetch with AbortSignal.timeout instead, or defer
25
+ the read to the hydrated client where navigator.onLine is live. Bundles feel
26
+ this most — localhost serves the SSR even with the machine offline.
27
+
28
+ Reports, never acts — reading this opens no fetch and no stream.
29
+ */
30
+ const subscribeOnline =
31
+ typeof window === 'undefined'
32
+ ? undefined
33
+ : createSubscriber((update) => {
34
+ const changed = () => update()
35
+ window.addEventListener('online', changed)
36
+ window.addEventListener('offline', changed)
37
+ return () => {
38
+ window.removeEventListener('online', changed)
39
+ window.removeEventListener('offline', changed)
40
+ }
41
+ })
42
+
43
+ // @readme probes
44
+ export function online(): boolean {
45
+ /* window, not navigator: Bun defines a partial navigator with no onLine. */
46
+ if (typeof window === 'undefined') {
47
+ return requestScopeSlot.resolver?.()?.online ?? true
48
+ }
49
+ subscribeOnline?.()
50
+ return navigator.onLine
51
+ }
@@ -0,0 +1,30 @@
1
+ import { activePage } from './activePage.ts'
2
+ import type { PageSnapshot } from './types/PageSnapshot.ts'
3
+
4
+ /*
5
+ The reactive page proxy: the matched route, decoded params, browser-space URL,
6
+ and `navigating` flag for the active page. Isomorphic — the server resolver reads
7
+ the per-request store, the client resolver the router-updated snapshot — so
8
+ `{page.url.pathname}` and `page.params.id` work the same during SSR and after
9
+ hydration. Read inside a abide-ui effect/derived, a field re-runs its reader when
10
+ navigation updates the snapshot (the client resolver reads a abide-ui signal).
11
+
12
+ `url` is browser-space on both sides: under a mount base the pathname carries the
13
+ prefix (the server re-applies it to the proxy-stripped request URL), so compare
14
+ active state against url() output, e.g. `page.url.pathname.startsWith(url('/x'))`.
15
+ */
16
+ // @readme page
17
+ export const page: PageSnapshot = {
18
+ get route(): string {
19
+ return activePage().route
20
+ },
21
+ get params(): Record<string, string> {
22
+ return activePage().params
23
+ },
24
+ get url(): URL {
25
+ return activePage().url
26
+ },
27
+ get navigating(): boolean {
28
+ return activePage().navigating
29
+ },
30
+ }
@@ -0,0 +1,17 @@
1
+ import type { PageSnapshot } from './types/PageSnapshot.ts'
2
+
3
+ /*
4
+ Internal slot the runtime entries register their page resolver into. The
5
+ server entry installs an ALS-backed resolver (request-scoped, so concurrent
6
+ and streaming renders never share state); the client entry installs a
7
+ module-singleton resolver. `fallback` is a single lazy snapshot used only
8
+ when no resolver is registered — keeps isolated tests working without forcing
9
+ them to spin up the runtime. Mirrors cacheStoreSlot.
10
+ */
11
+ export const pageSlot: {
12
+ resolver: (() => PageSnapshot | undefined) | undefined
13
+ fallback: PageSnapshot | undefined
14
+ } = {
15
+ resolver: undefined,
16
+ fallback: undefined,
17
+ }
@@ -0,0 +1,14 @@
1
+ /*
2
+ Maps a page-relative path (under `src/ui/pages/`) to its URL route. Pages are
3
+ folder-based: every leaf is `page.abide` or `layout.abide`, and the URL
4
+ is the directory path. Pages mount at the directory path; layouts mount at
5
+ the directory prefix. Dynamic segments keep their `[name]` / `[...rest]`
6
+ shape — translation to Bun's `:name` / `*` happens at server registration
7
+ via toBunRoutePattern; consumers see the readable form in `nav.route`.
8
+ */
9
+ export function pageUrlForFile(relPath: string): string {
10
+ const segments = relPath.split('/')
11
+ segments.pop()
12
+ const path = segments.filter(Boolean).join('/')
13
+ return path === '' ? '/' : `/${path}`
14
+ }
@@ -0,0 +1,20 @@
1
+ /*
2
+ Parses an env string into an integer within [min, max], returning undefined for
3
+ missing, empty, or out-of-range/non-integer input so the caller can fall back to
4
+ a default. A bare Number() turns '' into 0 and 'abc' into NaN, both silently
5
+ wrong; this rejects them instead.
6
+ */
7
+ export function parseBoundedEnvInt(
8
+ value: string | undefined,
9
+ min: number,
10
+ max: number,
11
+ ): number | undefined {
12
+ if (value === undefined || value.trim() === '') {
13
+ return undefined
14
+ }
15
+ const parsed = Number(value)
16
+ if (!Number.isInteger(parsed) || parsed < min || parsed > max) {
17
+ return undefined
18
+ }
19
+ return parsed
20
+ }
@@ -0,0 +1,21 @@
1
+ /*
2
+ DEBUG's comma list, parsed once per distinct string — the gate runs on every
3
+ log emission, and the env never changes server-side. A single-slot memo
4
+ suffices: the browser's abide-debug localStorage toggle produces a new string
5
+ that misses the memo and reparses.
6
+ */
7
+ let lastEnv: string | undefined
8
+ let lastPatterns: string[] = []
9
+
10
+ export function parseDebugPatterns(env: string | undefined): string[] {
11
+ if (env !== lastEnv) {
12
+ lastEnv = env
13
+ lastPatterns = env
14
+ ? env
15
+ .split(',')
16
+ .map((raw) => raw.trim())
17
+ .filter((pattern) => pattern !== '')
18
+ : []
19
+ }
20
+ return lastPatterns
21
+ }
@@ -0,0 +1,30 @@
1
+ const ENV_LINE = /^\s*([A-Z_][A-Z0-9_]*)\s*=\s*(.*)$/
2
+
3
+ /*
4
+ Parses `.env` text into a key→value record. Skips blanks, comments, and
5
+ malformed lines; strips a single layer of surrounding single or double quotes.
6
+ Intentionally minimal — no variable expansion, escapes, or multi-line. The pure
7
+ counterpart to loadEnvFile (which merges into process.env) and serializeEnv
8
+ (which writes records back), so all three round-trip the same shape.
9
+ */
10
+ export function parseEnv(text: string): Record<string, string> {
11
+ const result: Record<string, string> = {}
12
+ for (const line of text.split('\n')) {
13
+ if (!line || line.startsWith('#')) {
14
+ continue
15
+ }
16
+ const match = ENV_LINE.exec(line)
17
+ if (!match) {
18
+ continue
19
+ }
20
+ const [, key, rawValue] = match
21
+ const trimmed = rawValue?.trim() ?? ''
22
+ const unquoted =
23
+ (trimmed.startsWith('"') && trimmed.endsWith('"')) ||
24
+ (trimmed.startsWith("'") && trimmed.endsWith("'"))
25
+ ? trimmed.slice(1, -1)
26
+ : trimmed
27
+ result[key as string] = unquoted
28
+ }
29
+ return result
30
+ }
@@ -0,0 +1,35 @@
1
+ import type { PromptArgument } from './types/PromptArgument.ts'
2
+
3
+ export type ParsedPromptMarkdown = {
4
+ description: string | undefined
5
+ arguments: PromptArgument[]
6
+ body: string
7
+ }
8
+
9
+ // Leading YAML frontmatter block fenced by `---` lines (CRLF tolerant).
10
+ const FRONTMATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/
11
+
12
+ /*
13
+ Splits a `src/mcp/prompts/**.md` file into its frontmatter metadata and
14
+ template body. The frontmatter (optional) carries `description` and an
15
+ `arguments` list; everything after the closing `---` is the prompt body,
16
+ interpolated at render time via `{{name}}` placeholders. A file with no
17
+ frontmatter is all body. Parsed with Bun.YAML — the resolver plugin runs
18
+ under Bun, so the native parser is always available at build time.
19
+ */
20
+ export function parsePromptMarkdown(source: string): ParsedPromptMarkdown {
21
+ const match = FRONTMATTER.exec(source)
22
+ if (!match) {
23
+ return { description: undefined, arguments: [], body: source.trim() }
24
+ }
25
+ // The pattern makes group 1 mandatory; the '' default exists for noUncheckedIndexedAccess in consumer tsconfigs.
26
+ const frontmatter = (Bun.YAML.parse(match[1] ?? '') ?? {}) as {
27
+ description?: string
28
+ arguments?: PromptArgument[]
29
+ }
30
+ return {
31
+ description: frontmatter.description,
32
+ arguments: Array.isArray(frontmatter.arguments) ? frontmatter.arguments : [],
33
+ body: source.slice(match[0].length).trim(),
34
+ }
35
+ }
@@ -0,0 +1,22 @@
1
+ export type RouteSegment =
2
+ | { kind: 'literal'; value: string }
3
+ | { kind: 'param'; name: string; catchAll: boolean }
4
+
5
+ /*
6
+ Splits a abide route URL into typed segments. `[name]` becomes a param,
7
+ `[...rest]` becomes a catch-all param, anything else is a literal. Used
8
+ by toBunRoutePattern (server-side Bun pattern emission) and writeRoutesDts
9
+ (client-side `Routes` type augmentation) so the two consumers can't drift
10
+ on what counts as a param.
11
+ */
12
+ export function parseRouteSegments(routeUrl: string): RouteSegment[] {
13
+ return routeUrl.split('/').map((segment) => {
14
+ if (segment.startsWith('[...') && segment.endsWith(']')) {
15
+ return { kind: 'param', name: segment.slice(4, -1), catchAll: true }
16
+ }
17
+ if (segment.startsWith('[') && segment.endsWith(']')) {
18
+ return { kind: 'param', name: segment.slice(1, -1), catchAll: false }
19
+ }
20
+ return { kind: 'literal', value: segment }
21
+ })
22
+ }
@@ -0,0 +1,26 @@
1
+ import type { TraceContext } from './types/TraceContext.ts'
2
+
3
+ const TRACEPARENT_PATTERN = /^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$/
4
+
5
+ /*
6
+ Parses a W3C `traceparent` header into a TraceContext, or undefined when the
7
+ value is malformed (per spec, an unreadable header is ignored and the receiver
8
+ starts a fresh trace). Rejects the all-zero trace/span ids and the reserved
9
+ version 'ff'. The header's span id lands in `spanId`: from the wire's point of
10
+ view that field is "the id of the step that sent this" — callers minting their
11
+ own step id move it to `parentSpanId` (createTraceContext does).
12
+ */
13
+ export function parseTraceparent(header: string): TraceContext | undefined {
14
+ const match = TRACEPARENT_PATTERN.exec(header.trim().toLowerCase())
15
+ if (!match) {
16
+ return undefined
17
+ }
18
+ /* The pattern makes all four groups mandatory, but consumer tsconfigs with
19
+ noUncheckedIndexedAccess type-check this shipped source and see them as
20
+ possibly undefined — default to '' so the zero-id guards reject that path. */
21
+ const [, version = '', traceId = '', spanId = '', flags = ''] = match
22
+ if (version === 'ff' || /^0*$/.test(traceId) || /^0*$/.test(spanId)) {
23
+ return undefined
24
+ }
25
+ return { traceId, spanId, flags }
26
+ }
@@ -0,0 +1,30 @@
1
+ import { probeRegistries } from './probeRegistries.ts'
2
+ import type { CacheEntry } from './types/CacheEntry.ts'
3
+ import type { CacheSelector } from './types/CacheSelector.ts'
4
+ import type { Subscribable } from './types/Subscribable.ts'
5
+
6
+ /*
7
+ Reactive in-flight probe over both registries — the cache (calls) and the
8
+ tail registry (streams). Pending means "no value yet":
9
+ pending() → any call in flight, or any registered stream
10
+ awaiting its first frame (global activity bar)
11
+ pending(fn) → that function's calls (per-route spinner; remote or
12
+ producer, same selector grammar as cache.invalidate)
13
+ pending(fn, args) → exactly that call (per-row spinner)
14
+ pending({ scope }) → a tagged group
15
+ pending(subscribable) → that stream awaiting its first frame
16
+ (tail.status === 'pending'; true when nothing
17
+ is reading yet — there is no value either way)
18
+ Probes report, never act: reading one opens no fetch and no stream. SSR
19
+ loading state is driven by {#await}, not this. Scan semantics (tap order,
20
+ selector grammar, registry spans) live in probeRegistries.
21
+ */
22
+ // @readme probes
23
+ export function pending<Args, Return>(
24
+ arg?: CacheSelector<Args, Return> | Subscribable<unknown>,
25
+ args?: Args,
26
+ ): boolean {
27
+ return probeRegistries(arg, args, 'pending', unsettled, true)
28
+ }
29
+
30
+ const unsettled = (entry: CacheEntry) => entry.settled !== true
@@ -0,0 +1,59 @@
1
+ import { findExportCallSite } from './findExportCallSite.ts'
2
+ import { importNamesToStrip } from './importNamesToStrip.ts'
3
+ import { stripImport } from './stripImport.ts'
4
+ import type { HttpVerb } from './types/HttpVerb.ts'
5
+
6
+ const VERB_NAMES = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD'] as const
7
+ const VERB_SET = new Set<string>(VERB_NAMES)
8
+
9
+ const SINGLE_EXPORT_ERROR =
10
+ '[abide] $rpc module contains more than one `<VERB>(...)` export — each file must declare exactly one remote function'
11
+
12
+ export type PreparedRpcModule = {
13
+ verb: HttpVerb
14
+ exportName: string
15
+ rewriteForServer: (url: string) => string
16
+ }
17
+
18
+ /*
19
+ Scans an `$rpc/**` module once and returns its declared verb + export
20
+ name plus a closure that, given the route URL, emits the server-side
21
+ rewrite (`__abideDefineVerb__("VERB", "<url>", … )` spliced into the
22
+ original source). The single scan replaces the prior separate
23
+ extract + rewrite passes, so the resolver plugin only walks each source
24
+ character-by-character once.
25
+
26
+ A regex pass would be tidier but it can't tell a `GET` mention inside a
27
+ docstring or template literal from the real call, and it can't follow
28
+ nested generics like `GET<Map<K, V>>(`.
29
+ */
30
+ export function prepareRpcModule(
31
+ source: string,
32
+ importName: string,
33
+ ): PreparedRpcModule | undefined {
34
+ /*
35
+ The "no barrels" surface places each verb at its own path
36
+ (`abide/server/GET`, `abide/server/POST`, …) — strip every one so
37
+ the user's verb import doesn't linger and side-effect-load the
38
+ stub module into the server bundle. The user may import under the
39
+ project's chosen name or the canonical package name, so strip both.
40
+ */
41
+ const stripped = importNamesToStrip(importName).reduce(
42
+ (current, name) =>
43
+ VERB_NAMES.reduce((acc, verb) => stripImport(acc, `${name}/server/${verb}`), current),
44
+ source,
45
+ )
46
+ const site = findExportCallSite(stripped, (ident) => VERB_SET.has(ident), SINGLE_EXPORT_ERROR)
47
+ if (!site) {
48
+ return undefined
49
+ }
50
+ const verb = site.ident as HttpVerb
51
+ return {
52
+ verb,
53
+ exportName: site.exportName,
54
+ rewriteForServer(url: string): string {
55
+ const binding = `__abideDefineVerb__(${JSON.stringify(verb)}, ${JSON.stringify(url)}, `
56
+ return stripped.slice(0, site.callStart) + binding + stripped.slice(site.parenStart + 1)
57
+ },
58
+ }
59
+ }
@@ -0,0 +1,49 @@
1
+ import { findExportCallSite } from './findExportCallSite.ts'
2
+ import { importNamesToStrip } from './importNamesToStrip.ts'
3
+ import { stripImport } from './stripImport.ts'
4
+
5
+ const SINGLE_EXPORT_ERROR =
6
+ '[abide] $sockets module contains more than one `socket(...)` export — each file must declare exactly one socket'
7
+
8
+ export type PreparedSocketModule = {
9
+ exportName: string
10
+ rewriteForServer: (name: string) => string
11
+ }
12
+
13
+ /*
14
+ Scans a `$sockets/**` module once and returns its declared export name
15
+ plus a closure that, given the socket name, emits the server-side
16
+ rewrite (`__abideDefineSocket__("<name>"[, opts])` spliced into the
17
+ original source). The single scan replaces the prior separate
18
+ extract + rewrite passes, so the resolver plugin only walks each source
19
+ character-by-character once.
20
+ */
21
+ export function prepareSocketModule(
22
+ source: string,
23
+ importName: string,
24
+ ): PreparedSocketModule | undefined {
25
+ /*
26
+ Strip the user's `socket` import under the project's chosen name and the
27
+ canonical package name so the dead import can't side-effect-load the
28
+ socket helper into the server bundle.
29
+ */
30
+ const stripped = importNamesToStrip(importName).reduce(
31
+ (current, name) => stripImport(current, `${name}/server/socket`),
32
+ source,
33
+ )
34
+ const site = findExportCallSite(stripped, (ident) => ident === 'socket', SINGLE_EXPORT_ERROR)
35
+ if (!site) {
36
+ return undefined
37
+ }
38
+ return {
39
+ exportName: site.exportName,
40
+ rewriteForServer(name: string): string {
41
+ const inner = stripped.slice(site.parenStart + 1, site.parenEnd).trim()
42
+ const binding =
43
+ inner.length === 0
44
+ ? `__abideDefineSocket__(${JSON.stringify(name)})`
45
+ : `__abideDefineSocket__(${JSON.stringify(name)}, ${stripped.slice(site.parenStart + 1, site.parenEnd)})`
46
+ return stripped.slice(0, site.callStart) + binding + stripped.slice(site.parenEnd + 1)
47
+ },
48
+ }
49
+ }