@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.
- package/CHANGELOG.md +607 -0
- package/LICENSE +21 -0
- package/README.md +154 -0
- package/bin/abide.ts +212 -0
- package/package.json +155 -0
- package/src/abideLsp.ts +211 -0
- package/src/abideModules.d.ts +8 -0
- package/src/abideResolverPlugin.ts +923 -0
- package/src/appEntry.ts +151 -0
- package/src/assets/app.html +12 -0
- package/src/build.ts +143 -0
- package/src/buildCli.ts +127 -0
- package/src/buildDisconnected.ts +118 -0
- package/src/bundleApp.ts +147 -0
- package/src/bundleDisconnectedEntry.ts +14 -0
- package/src/checkAbide.ts +77 -0
- package/src/cliEntry.ts +25 -0
- package/src/clientBuildPlugins.ts +33 -0
- package/src/clientEntry.ts +17 -0
- package/src/compile.ts +63 -0
- package/src/controlServerWorker.ts +426 -0
- package/src/devEntry.ts +250 -0
- package/src/discoveryEntry.ts +81 -0
- package/src/lib/bundle/BundleMenu.ts +12 -0
- package/src/lib/bundle/BundleMenuItem.ts +25 -0
- package/src/lib/bundle/BundleWindow.ts +37 -0
- package/src/lib/bundle/WEBVIEW_BUILD_REVISION.ts +9 -0
- package/src/lib/bundle/WEBVIEW_VERSION.ts +7 -0
- package/src/lib/bundle/bindConnectedFlag.ts +29 -0
- package/src/lib/bundle/bindRequestNavigate.ts +34 -0
- package/src/lib/bundle/buildWebviewLib.ts +111 -0
- package/src/lib/bundle/bundled.ts +35 -0
- package/src/lib/bundle/disconnected.abide +236 -0
- package/src/lib/bundle/disconnected.css +9 -0
- package/src/lib/bundle/ensureWebviewLib.ts +20 -0
- package/src/lib/bundle/exitWithParent.ts +28 -0
- package/src/lib/bundle/infoPlist.ts +46 -0
- package/src/lib/bundle/installDownloads.ts +24 -0
- package/src/lib/bundle/installMacMenu.ts +39 -0
- package/src/lib/bundle/listenLocalControlServer.ts +19 -0
- package/src/lib/bundle/native/abideMenu.mm +422 -0
- package/src/lib/bundle/native/webview.h +4557 -0
- package/src/lib/bundle/onMenu.ts +42 -0
- package/src/lib/bundle/openWebview.ts +104 -0
- package/src/lib/bundle/pngToIcns.ts +47 -0
- package/src/lib/bundle/probeAbideServer.ts +57 -0
- package/src/lib/bundle/resolveServerBinary.ts +12 -0
- package/src/lib/bundle/resolveWebviewLib.ts +53 -0
- package/src/lib/bundle/serverBinaryFilename.ts +8 -0
- package/src/lib/bundle/signMacApp.ts +37 -0
- package/src/lib/bundle/spawnEmbeddedServer.ts +64 -0
- package/src/lib/bundle/stableLocalPort.ts +19 -0
- package/src/lib/bundle/waitForServer.ts +23 -0
- package/src/lib/bundle/webviewCachePath.ts +23 -0
- package/src/lib/bundle/webviewLibName.ts +11 -0
- package/src/lib/cli/connectToServer.ts +23 -0
- package/src/lib/cli/createClient.ts +108 -0
- package/src/lib/cli/dispatchCommand.ts +71 -0
- package/src/lib/cli/loadEnvFromBinaryDir.ts +15 -0
- package/src/lib/cli/parseArgvForRpc.ts +100 -0
- package/src/lib/cli/printHelp.ts +119 -0
- package/src/lib/cli/printSessionHelp.ts +27 -0
- package/src/lib/cli/printSessionStatus.ts +21 -0
- package/src/lib/cli/printTrimmed.ts +8 -0
- package/src/lib/cli/printValue.ts +10 -0
- package/src/lib/cli/resolveCliTarget.ts +48 -0
- package/src/lib/cli/runCli.ts +176 -0
- package/src/lib/cli/runSession.ts +108 -0
- package/src/lib/cli/startLocalInstance.ts +14 -0
- package/src/lib/cli/tokenizeLine.ts +51 -0
- package/src/lib/cli/types/CliManifest.ts +9 -0
- package/src/lib/cli/types/CliManifestEntry.ts +17 -0
- package/src/lib/cli/types/CliTarget.ts +13 -0
- package/src/lib/mcp/annotationsForMethod.ts +29 -0
- package/src/lib/mcp/createMcpResourceServer.ts +102 -0
- package/src/lib/mcp/createMcpServer.ts +48 -0
- package/src/lib/mcp/dispatchMcpRequest.ts +138 -0
- package/src/lib/mcp/mcpResourceServerSlot.ts +18 -0
- package/src/lib/mcp/mcpSurface.ts +295 -0
- package/src/lib/mcp/toolResultFromResponse.ts +66 -0
- package/src/lib/mcp/types/JsonRpcRequest.ts +12 -0
- package/src/lib/mcp/types/JsonRpcResponse.ts +20 -0
- package/src/lib/mcp/types/McpResourceContents.ts +10 -0
- package/src/lib/mcp/types/McpResourceDescriptor.ts +6 -0
- package/src/lib/mcp/types/McpResourceServer.ts +12 -0
- package/src/lib/mcp/types/McpServer.ts +9 -0
- package/src/lib/mcp/types/McpServerOptions.ts +16 -0
- package/src/lib/server/AppModule.ts +47 -0
- package/src/lib/server/DELETE.ts +10 -0
- package/src/lib/server/GET.ts +10 -0
- package/src/lib/server/HEAD.ts +10 -0
- package/src/lib/server/PATCH.ts +10 -0
- package/src/lib/server/POST.ts +10 -0
- package/src/lib/server/PUT.ts +10 -0
- package/src/lib/server/agent.ts +86 -0
- package/src/lib/server/appDataDir.ts +16 -0
- package/src/lib/server/cli/buildEnvContent.ts +19 -0
- package/src/lib/server/cli/createTarGz.ts +77 -0
- package/src/lib/server/cli/handleCliDownload.ts +150 -0
- package/src/lib/server/cli/handleCliInstall.ts +37 -0
- package/src/lib/server/cli/installScript.ts +31 -0
- package/src/lib/server/cli/maxSourceMtime.ts +26 -0
- package/src/lib/server/cookies.ts +30 -0
- package/src/lib/server/env.ts +51 -0
- package/src/lib/server/error.ts +73 -0
- package/src/lib/server/json.ts +42 -0
- package/src/lib/server/jsonl.ts +47 -0
- package/src/lib/server/prompts/definePrompt.ts +21 -0
- package/src/lib/server/prompts/promptRegistry.ts +9 -0
- package/src/lib/server/prompts/registerPrompt.ts +6 -0
- package/src/lib/server/prompts/renderPromptTemplate.ts +17 -0
- package/src/lib/server/prompts/types/Prompt.ts +13 -0
- package/src/lib/server/prompts/types/PromptOptions.ts +12 -0
- package/src/lib/server/prompts/types/PromptRegistryEntry.ts +13 -0
- package/src/lib/server/prompts/types/PromptRoutes.ts +10 -0
- package/src/lib/server/reachable.ts +45 -0
- package/src/lib/server/redirect.ts +43 -0
- package/src/lib/server/request.ts +19 -0
- package/src/lib/server/rpc/defineVerb.ts +210 -0
- package/src/lib/server/rpc/dispatchVerbInProcess.ts +46 -0
- package/src/lib/server/rpc/findVerbByCommandName.ts +18 -0
- package/src/lib/server/rpc/parseArgs.ts +127 -0
- package/src/lib/server/rpc/readBodyWithinLimit.ts +44 -0
- package/src/lib/server/rpc/registerVerb.ts +6 -0
- package/src/lib/server/rpc/runWithVerbTimeout.ts +49 -0
- package/src/lib/server/rpc/types/RemoteHandler.ts +27 -0
- package/src/lib/server/rpc/types/RemoteRoutes.ts +13 -0
- package/src/lib/server/rpc/types/TypedResponse.ts +18 -0
- package/src/lib/server/rpc/types/VerbHelper.ts +87 -0
- package/src/lib/server/rpc/types/VerbRegistryEntry.ts +35 -0
- package/src/lib/server/rpc/unprocessed.ts +14 -0
- package/src/lib/server/rpc/verbRegistry.ts +11 -0
- package/src/lib/server/runtime/DEFAULT_PORT.ts +6 -0
- package/src/lib/server/runtime/DEV_READY_MESSAGE.ts +6 -0
- package/src/lib/server/runtime/DEV_REBUILD_MESSAGE.ts +4 -0
- package/src/lib/server/runtime/DEV_RELOAD_CLIENT_SCRIPT.ts +107 -0
- package/src/lib/server/runtime/SSR_SWAP_SCRIPT.ts +16 -0
- package/src/lib/server/runtime/acceptsGzip.ts +24 -0
- package/src/lib/server/runtime/buildCacheSnapshot.ts +61 -0
- package/src/lib/server/runtime/buildHealthPayload.ts +34 -0
- package/src/lib/server/runtime/buildInspectorSurface.ts +37 -0
- package/src/lib/server/runtime/buildOpenApiSpec.ts +106 -0
- package/src/lib/server/runtime/cacheControlForAsset.ts +22 -0
- package/src/lib/server/runtime/containsTraversal.ts +37 -0
- package/src/lib/server/runtime/createAppAssetServer.ts +76 -0
- package/src/lib/server/runtime/createAssetHeaderCache.ts +31 -0
- package/src/lib/server/runtime/createPublicAssetServer.ts +67 -0
- package/src/lib/server/runtime/createReachable.ts +109 -0
- package/src/lib/server/runtime/createRouteDispatcher.ts +127 -0
- package/src/lib/server/runtime/createServer.ts +674 -0
- package/src/lib/server/runtime/createUiPageRenderer.ts +181 -0
- package/src/lib/server/runtime/crossOriginForbidden.ts +17 -0
- package/src/lib/server/runtime/crossOriginGate.ts +29 -0
- package/src/lib/server/runtime/devClientFingerprint.ts +117 -0
- package/src/lib/server/runtime/devHotModuleResponse.ts +40 -0
- package/src/lib/server/runtime/devReloadResponse.ts +41 -0
- package/src/lib/server/runtime/disableIdleTimeoutForStream.ts +27 -0
- package/src/lib/server/runtime/envSchemaStore.ts +15 -0
- package/src/lib/server/runtime/findOpenPort.ts +21 -0
- package/src/lib/server/runtime/getActiveServer.ts +6 -0
- package/src/lib/server/runtime/globToPathSet.ts +29 -0
- package/src/lib/server/runtime/gzipResponse.ts +46 -0
- package/src/lib/server/runtime/inProcessServer.ts +20 -0
- package/src/lib/server/runtime/internalErrorResponse.ts +25 -0
- package/src/lib/server/runtime/isCrossOriginRequest.ts +23 -0
- package/src/lib/server/runtime/listenOnOpenPort.ts +36 -0
- package/src/lib/server/runtime/logExposedSurfaces.ts +156 -0
- package/src/lib/server/runtime/maybeMountInspector.ts +97 -0
- package/src/lib/server/runtime/mimeForExtension.ts +14 -0
- package/src/lib/server/runtime/pageUrlFromStore.ts +15 -0
- package/src/lib/server/runtime/parseIdleTimeout.ts +10 -0
- package/src/lib/server/runtime/parsePort.ts +11 -0
- package/src/lib/server/runtime/registryManifests.ts +66 -0
- package/src/lib/server/runtime/requestContext.ts +5 -0
- package/src/lib/server/runtime/resolvePageSnapshot.ts +25 -0
- package/src/lib/server/runtime/respondWithEmbeddedAsset.ts +18 -0
- package/src/lib/server/runtime/runWithRequestScope.ts +150 -0
- package/src/lib/server/runtime/safeJsonForScript.ts +17 -0
- package/src/lib/server/runtime/serializeCacheSnapshot.ts +45 -0
- package/src/lib/server/runtime/serverSlot.ts +13 -0
- package/src/lib/server/runtime/setActiveServer.ts +6 -0
- package/src/lib/server/runtime/snapshotEntryFromCache.ts +83 -0
- package/src/lib/server/runtime/streamCacheResolutions.ts +37 -0
- package/src/lib/server/runtime/streamFromIterator.ts +86 -0
- package/src/lib/server/runtime/types/Assets.ts +6 -0
- package/src/lib/server/runtime/types/DevReloadStamp.ts +18 -0
- package/src/lib/server/runtime/types/InspectorCacheEntry.ts +24 -0
- package/src/lib/server/runtime/types/InspectorCacheSnapshot.ts +11 -0
- package/src/lib/server/runtime/types/InspectorContext.ts +30 -0
- package/src/lib/server/runtime/types/InspectorSocket.ts +17 -0
- package/src/lib/server/runtime/types/InspectorSurface.ts +13 -0
- package/src/lib/server/runtime/types/InspectorVerb.ts +27 -0
- package/src/lib/server/runtime/types/RequestStore.ts +55 -0
- package/src/lib/server/runtime/warnUnguardedMcp.ts +32 -0
- package/src/lib/server/runtime/withResponseDefaults.ts +24 -0
- package/src/lib/server/server.ts +33 -0
- package/src/lib/server/socket.ts +32 -0
- package/src/lib/server/sockets/createSocketDispatcher.ts +337 -0
- package/src/lib/server/sockets/defineSocket.ts +179 -0
- package/src/lib/server/sockets/lookupSocket.ts +6 -0
- package/src/lib/server/sockets/registerSocket.ts +6 -0
- package/src/lib/server/sockets/socketOperations.ts +36 -0
- package/src/lib/server/sockets/socketRegistry.ts +9 -0
- package/src/lib/server/sockets/types/Socket.ts +23 -0
- package/src/lib/server/sockets/types/SocketClientFrame.ts +19 -0
- package/src/lib/server/sockets/types/SocketOperation.ts +22 -0
- package/src/lib/server/sockets/types/SocketOptions.ts +26 -0
- package/src/lib/server/sockets/types/SocketRegistryEntry.ts +19 -0
- package/src/lib/server/sockets/types/SocketRoutes.ts +10 -0
- package/src/lib/server/sockets/types/SocketServerFrame.ts +24 -0
- package/src/lib/server/sse.ts +54 -0
- package/src/lib/shared/ABIDE_PACKAGE_NAME.ts +7 -0
- package/src/lib/shared/ABIDE_VERSION.ts +9 -0
- package/src/lib/shared/CACHE_CONTROL_VALUES.ts +16 -0
- package/src/lib/shared/CACHE_WRAPPED.ts +8 -0
- package/src/lib/shared/CLI_PATH.ts +7 -0
- package/src/lib/shared/DEV_HOT_PREFIX.ts +7 -0
- package/src/lib/shared/DEV_RELOAD_PATH.ts +6 -0
- package/src/lib/shared/HEALTH_PATH.ts +7 -0
- package/src/lib/shared/HttpError.ts +20 -0
- package/src/lib/shared/IDENTITY_PATH.ts +6 -0
- package/src/lib/shared/INSPECTOR_PATH.ts +7 -0
- package/src/lib/shared/NAV_HEADER.ts +8 -0
- package/src/lib/shared/OFFLINE_HEADER.ts +8 -0
- package/src/lib/shared/REMOTE_FUNCTION.ts +8 -0
- package/src/lib/shared/REPLAYABLE_METHODS.ts +12 -0
- package/src/lib/shared/SOCKETS_PATH.ts +7 -0
- package/src/lib/shared/STREAMING_CONTENT_TYPES.ts +11 -0
- package/src/lib/shared/SocketDisconnectedError.ts +13 -0
- package/src/lib/shared/TEXT_PLAIN.ts +7 -0
- package/src/lib/shared/abideImportName.ts +44 -0
- package/src/lib/shared/abideLog.ts +38 -0
- package/src/lib/shared/activeCacheStore.ts +20 -0
- package/src/lib/shared/activePage.ts +25 -0
- package/src/lib/shared/appDataDir.ts +34 -0
- package/src/lib/shared/appNameSlot.ts +10 -0
- package/src/lib/shared/basePath.ts +10 -0
- package/src/lib/shared/basePathFromAppUrl.ts +20 -0
- package/src/lib/shared/baseSlot.ts +14 -0
- package/src/lib/shared/binaryDirEnvPath.ts +12 -0
- package/src/lib/shared/browserClientFlags.ts +10 -0
- package/src/lib/shared/buildRpcProxy.ts +39 -0
- package/src/lib/shared/buildRpcRequest.ts +70 -0
- package/src/lib/shared/buildSocketOverChannel.ts +58 -0
- package/src/lib/shared/bundleLayout.ts +36 -0
- package/src/lib/shared/cache.ts +951 -0
- package/src/lib/shared/cacheEntryFromSnapshot.ts +59 -0
- package/src/lib/shared/cacheStoreSlot.ts +16 -0
- package/src/lib/shared/cacheStores.ts +10 -0
- package/src/lib/shared/canonicalJson.ts +63 -0
- package/src/lib/shared/carriesBodyArgs.ts +13 -0
- package/src/lib/shared/clearLastConnection.ts +7 -0
- package/src/lib/shared/commandNameForUrl.ts +17 -0
- package/src/lib/shared/createCacheStore.ts +104 -0
- package/src/lib/shared/createChannelLog.ts +122 -0
- package/src/lib/shared/createLifecycleChannel.ts +56 -0
- package/src/lib/shared/createLivenessWatch.ts +118 -0
- package/src/lib/shared/createPushIterator.ts +127 -0
- package/src/lib/shared/createRemoteFunction.ts +122 -0
- package/src/lib/shared/createSubscriber.ts +55 -0
- package/src/lib/shared/createTraceContext.ts +21 -0
- package/src/lib/shared/dataDirEnvPath.ts +12 -0
- package/src/lib/shared/decodeResponse.ts +47 -0
- package/src/lib/shared/detectTarget.ts +27 -0
- package/src/lib/shared/detectVerbMethod.ts +17 -0
- package/src/lib/shared/emitLogRecord.ts +190 -0
- package/src/lib/shared/exeSuffix.ts +9 -0
- package/src/lib/shared/exitOnBuildFailure.ts +17 -0
- package/src/lib/shared/extraForwardHeaders.ts +16 -0
- package/src/lib/shared/fileStem.ts +9 -0
- package/src/lib/shared/findExportCallSite.ts +476 -0
- package/src/lib/shared/formatTraceparent.ts +6 -0
- package/src/lib/shared/forwardHeaders.ts +44 -0
- package/src/lib/shared/getRemoteMeta.ts +5 -0
- package/src/lib/shared/globalCacheStore.ts +15 -0
- package/src/lib/shared/globalCacheStoreSlot.ts +14 -0
- package/src/lib/shared/health.ts +179 -0
- package/src/lib/shared/healthReadSlot.ts +11 -0
- package/src/lib/shared/healthSeedSlot.ts +12 -0
- package/src/lib/shared/html.ts +38 -0
- package/src/lib/shared/importNamesToStrip.ts +13 -0
- package/src/lib/shared/invalidateEvent.ts +11 -0
- package/src/lib/shared/invalidateTripwire.ts +40 -0
- package/src/lib/shared/isAbideHealthPayload.ts +11 -0
- package/src/lib/shared/isCompileTarget.ts +15 -0
- package/src/lib/shared/isDebugEnabled.ts +26 -0
- package/src/lib/shared/isDebugNegated.ts +19 -0
- package/src/lib/shared/isModuleNotFound.ts +16 -0
- package/src/lib/shared/isReadOnlyMethod.ts +14 -0
- package/src/lib/shared/isReplayableMethod.ts +7 -0
- package/src/lib/shared/isStreamingResponse.ts +11 -0
- package/src/lib/shared/isSubscribable.ts +15 -0
- package/src/lib/shared/jsonSchemaForPromptArguments.ts +29 -0
- package/src/lib/shared/jsonSchemaForSchema.ts +39 -0
- package/src/lib/shared/jsonlErrorFrame.ts +24 -0
- package/src/lib/shared/keyForRemoteCall.ts +29 -0
- package/src/lib/shared/keyMatchesPrefix.ts +9 -0
- package/src/lib/shared/lastConnectionPath.ts +7 -0
- package/src/lib/shared/layoutChainForRoute.ts +22 -0
- package/src/lib/shared/loadEnvFile.ts +17 -0
- package/src/lib/shared/loadEnvFromDataDir.ts +14 -0
- package/src/lib/shared/log.ts +24 -0
- package/src/lib/shared/logClosingRecord.ts +28 -0
- package/src/lib/shared/logTapSlot.ts +13 -0
- package/src/lib/shared/manifestModule.ts +39 -0
- package/src/lib/shared/matchesDebugPattern.ts +16 -0
- package/src/lib/shared/memoizeByKey.ts +32 -0
- package/src/lib/shared/normalizeTarget.ts +10 -0
- package/src/lib/shared/online.ts +51 -0
- package/src/lib/shared/page.ts +30 -0
- package/src/lib/shared/pageSlot.ts +17 -0
- package/src/lib/shared/pageUrlForFile.ts +14 -0
- package/src/lib/shared/parseBoundedEnvInt.ts +20 -0
- package/src/lib/shared/parseDebugPatterns.ts +21 -0
- package/src/lib/shared/parseEnv.ts +30 -0
- package/src/lib/shared/parsePromptMarkdown.ts +35 -0
- package/src/lib/shared/parseRouteSegments.ts +22 -0
- package/src/lib/shared/parseTraceparent.ts +26 -0
- package/src/lib/shared/pending.ts +30 -0
- package/src/lib/shared/prepareRpcModule.ts +59 -0
- package/src/lib/shared/prepareSocketModule.ts +49 -0
- package/src/lib/shared/probeRegistries.ts +68 -0
- package/src/lib/shared/producerKey.ts +32 -0
- package/src/lib/shared/programNameForPackage.ts +14 -0
- package/src/lib/shared/promptNameForFile.ts +10 -0
- package/src/lib/shared/queryStringFromArgs.ts +27 -0
- package/src/lib/shared/randomHexId.ts +14 -0
- package/src/lib/shared/readEnvFile.ts +15 -0
- package/src/lib/shared/readLastConnection.ts +18 -0
- package/src/lib/shared/readPackageJson.ts +9 -0
- package/src/lib/shared/recordRemoteMeta.ts +5 -0
- package/src/lib/shared/refreshing.ts +31 -0
- package/src/lib/shared/remoteMetaStore.ts +16 -0
- package/src/lib/shared/requestScopeSlot.ts +15 -0
- package/src/lib/shared/resolveClientFlags.ts +20 -0
- package/src/lib/shared/responseErrorText.ts +9 -0
- package/src/lib/shared/rpcTimeoutSlot.ts +9 -0
- package/src/lib/shared/rpcUrlForFile.ts +19 -0
- package/src/lib/shared/runningAsStandaloneBinary.ts +13 -0
- package/src/lib/shared/selectorMatcher.ts +68 -0
- package/src/lib/shared/selectorPrefix.ts +39 -0
- package/src/lib/shared/serializeEnv.ts +18 -0
- package/src/lib/shared/setAppName.ts +5 -0
- package/src/lib/shared/setBaseResolver.ts +6 -0
- package/src/lib/shared/setCacheStoreResolver.ts +6 -0
- package/src/lib/shared/setGlobalCacheStoreResolver.ts +6 -0
- package/src/lib/shared/setPageResolver.ts +7 -0
- package/src/lib/shared/setRequestScopeResolver.ts +6 -0
- package/src/lib/shared/snippet.ts +25 -0
- package/src/lib/shared/socketNameForFile.ts +11 -0
- package/src/lib/shared/socketTapSlot.ts +12 -0
- package/src/lib/shared/sseErrorFrame.ts +29 -0
- package/src/lib/shared/streamResponse.ts +169 -0
- package/src/lib/shared/stripImport.ts +27 -0
- package/src/lib/shared/subscribableFromResponse.ts +51 -0
- package/src/lib/shared/tailProbeSlot.ts +16 -0
- package/src/lib/shared/toBunRoutePattern.ts +28 -0
- package/src/lib/shared/toScopeSet.ts +4 -0
- package/src/lib/shared/trace.ts +16 -0
- package/src/lib/shared/types/CacheEntry.ts +84 -0
- package/src/lib/shared/types/CacheInvalidation.ts +9 -0
- package/src/lib/shared/types/CacheOnContext.ts +25 -0
- package/src/lib/shared/types/CacheOptions.ts +39 -0
- package/src/lib/shared/types/CacheSelector.ts +17 -0
- package/src/lib/shared/types/CacheSnapshot.ts +16 -0
- package/src/lib/shared/types/CacheSnapshotEntry.ts +17 -0
- package/src/lib/shared/types/CacheStats.ts +13 -0
- package/src/lib/shared/types/CacheStore.ts +39 -0
- package/src/lib/shared/types/ChannelLog.ts +13 -0
- package/src/lib/shared/types/ClientFlags.ts +11 -0
- package/src/lib/shared/types/CompileTarget.ts +6 -0
- package/src/lib/shared/types/FrameworkLog.ts +13 -0
- package/src/lib/shared/types/HttpVerb.ts +1 -0
- package/src/lib/shared/types/LastConnection.ts +9 -0
- package/src/lib/shared/types/Log.ts +13 -0
- package/src/lib/shared/types/LogRecord.ts +42 -0
- package/src/lib/shared/types/LogVoice.ts +7 -0
- package/src/lib/shared/types/PageSnapshot.ts +14 -0
- package/src/lib/shared/types/PromptArgument.ts +12 -0
- package/src/lib/shared/types/RawRemoteFunction.ts +14 -0
- package/src/lib/shared/types/RemoteCallable.ts +12 -0
- package/src/lib/shared/types/RemoteFunction.ts +47 -0
- package/src/lib/shared/types/ReplayableMethod.ts +7 -0
- package/src/lib/shared/types/RequestScopeInfo.ts +16 -0
- package/src/lib/shared/types/RpcInvoker.ts +6 -0
- package/src/lib/shared/types/SocketChannel.ts +17 -0
- package/src/lib/shared/types/SocketSubCallbacks.ts +13 -0
- package/src/lib/shared/types/StandardSchemaV1.ts +56 -0
- package/src/lib/shared/types/StreamedResolution.ts +10 -0
- package/src/lib/shared/types/Subscribable.ts +26 -0
- package/src/lib/shared/types/TailHooks.ts +12 -0
- package/src/lib/shared/types/TailOptions.ts +10 -0
- package/src/lib/shared/types/TraceContext.ts +17 -0
- package/src/lib/shared/url.ts +118 -0
- package/src/lib/shared/withBase.ts +11 -0
- package/src/lib/shared/withBaseUrl.ts +17 -0
- package/src/lib/shared/withJsonSchema.ts +21 -0
- package/src/lib/shared/writeDts.ts +12 -0
- package/src/lib/shared/writeHealthDts.ts +36 -0
- package/src/lib/shared/writeLastConnection.ts +13 -0
- package/src/lib/shared/writePublicAssetsDts.ts +31 -0
- package/src/lib/shared/writeRoutesDts.ts +73 -0
- package/src/lib/shared/writeRpcDts.ts +49 -0
- package/src/lib/shared/writeTestRpcDts.ts +45 -0
- package/src/lib/shared/writeTestSocketsDts.ts +34 -0
- package/src/lib/test/assertAgentFrameConformance.ts +73 -0
- package/src/lib/test/createScriptedSurface.ts +45 -0
- package/src/lib/test/createTestApp.ts +203 -0
- package/src/lib/test/createTestSocketChannel.ts +142 -0
- package/src/lib/ui/README.md +86 -0
- package/src/lib/ui/compile/SSR_ESCAPE.ts +25 -0
- package/src/lib/ui/compile/UI_RUNTIME_IMPORTS.ts +36 -0
- package/src/lib/ui/compile/VOID_TAGS.ts +21 -0
- package/src/lib/ui/compile/abideUiPlugin.ts +65 -0
- package/src/lib/ui/compile/analyzeComponent.ts +117 -0
- package/src/lib/ui/compile/assetModulesFile.ts +32 -0
- package/src/lib/ui/compile/branchElements.ts +50 -0
- package/src/lib/ui/compile/collectAbideDiagnostics.ts +59 -0
- package/src/lib/ui/compile/compileComponent.ts +20 -0
- package/src/lib/ui/compile/compileModule.ts +116 -0
- package/src/lib/ui/compile/compileSSR.ts +36 -0
- package/src/lib/ui/compile/compileShadow.ts +352 -0
- package/src/lib/ui/compile/createShadowLanguageService.ts +197 -0
- package/src/lib/ui/compile/createShadowProgram.ts +96 -0
- package/src/lib/ui/compile/decodeHtmlEntities.ts +49 -0
- package/src/lib/ui/compile/desugarSignals.ts +133 -0
- package/src/lib/ui/compile/escapeHtml.ts +15 -0
- package/src/lib/ui/compile/generateBuild.ts +638 -0
- package/src/lib/ui/compile/generateSSR.ts +380 -0
- package/src/lib/ui/compile/groupBindParts.ts +28 -0
- package/src/lib/ui/compile/hoistCells.ts +120 -0
- package/src/lib/ui/compile/loadShadowTsConfig.ts +31 -0
- package/src/lib/ui/compile/lowerDocAccess.ts +202 -0
- package/src/lib/ui/compile/nearestProjectRoot.ts +16 -0
- package/src/lib/ui/compile/parseTemplate.ts +396 -0
- package/src/lib/ui/compile/partitionSlots.ts +36 -0
- package/src/lib/ui/compile/prepareNestedScript.ts +42 -0
- package/src/lib/ui/compile/remapShadowDiagnostic.ts +30 -0
- package/src/lib/ui/compile/renameSignalRefs.ts +85 -0
- package/src/lib/ui/compile/resolveAbideImports.ts +29 -0
- package/src/lib/ui/compile/scopeCss.ts +115 -0
- package/src/lib/ui/compile/shadowNaming.ts +11 -0
- package/src/lib/ui/compile/sourceToShadowOffset.ts +24 -0
- package/src/lib/ui/compile/staticAttrValue.ts +13 -0
- package/src/lib/ui/compile/stripEffects.ts +32 -0
- package/src/lib/ui/compile/types/AbideDiagnostic.ts +14 -0
- package/src/lib/ui/compile/types/AnalyzedComponent.ts +25 -0
- package/src/lib/ui/compile/types/CompiledShadow.ts +15 -0
- package/src/lib/ui/compile/types/TemplateAttr.ts +16 -0
- package/src/lib/ui/compile/types/TemplateNode.ts +78 -0
- package/src/lib/ui/compile/types/TextPart.ts +8 -0
- package/src/lib/ui/derived.ts +28 -0
- package/src/lib/ui/doc.ts +15 -0
- package/src/lib/ui/dom/appendSnippet.ts +34 -0
- package/src/lib/ui/dom/appendStatic.ts +27 -0
- package/src/lib/ui/dom/appendText.ts +114 -0
- package/src/lib/ui/dom/applyResolved.ts +72 -0
- package/src/lib/ui/dom/attach.ts +20 -0
- package/src/lib/ui/dom/attr.ts +19 -0
- package/src/lib/ui/dom/awaitBlock.ts +224 -0
- package/src/lib/ui/dom/cloneStatic.ts +52 -0
- package/src/lib/ui/dom/each.ts +115 -0
- package/src/lib/ui/dom/eachAsync.ts +153 -0
- package/src/lib/ui/dom/hydrate.ts +35 -0
- package/src/lib/ui/dom/mount.ts +29 -0
- package/src/lib/ui/dom/mountChild.ts +33 -0
- package/src/lib/ui/dom/on.ts +15 -0
- package/src/lib/ui/dom/openChild.ts +22 -0
- package/src/lib/ui/dom/openRoot.ts +20 -0
- package/src/lib/ui/dom/switchBlock.ts +75 -0
- package/src/lib/ui/dom/text.ts +20 -0
- package/src/lib/ui/dom/tryBlock.ts +112 -0
- package/src/lib/ui/dom/types/EachRow.ts +3 -0
- package/src/lib/ui/dom/types/SwitchCase.ts +6 -0
- package/src/lib/ui/dom/when.ts +73 -0
- package/src/lib/ui/effect.ts +16 -0
- package/src/lib/ui/installHotBridge.ts +73 -0
- package/src/lib/ui/matchRoute.ts +89 -0
- package/src/lib/ui/navigate.ts +17 -0
- package/src/lib/ui/probeNavigation.ts +33 -0
- package/src/lib/ui/remoteProxy.ts +97 -0
- package/src/lib/ui/renderChain.ts +50 -0
- package/src/lib/ui/renderToStream.ts +104 -0
- package/src/lib/ui/router.ts +286 -0
- package/src/lib/ui/runtime/OUTLET_TAG.ts +8 -0
- package/src/lib/ui/runtime/OWNER.ts +8 -0
- package/src/lib/ui/runtime/REACTIVE_CONTEXT.ts +14 -0
- package/src/lib/ui/runtime/RENDER.ts +23 -0
- package/src/lib/ui/runtime/RESUME.ts +16 -0
- package/src/lib/ui/runtime/applyPatchToTree.ts +41 -0
- package/src/lib/ui/runtime/claimChild.ts +10 -0
- package/src/lib/ui/runtime/clientPage.ts +16 -0
- package/src/lib/ui/runtime/createComputedNode.ts +16 -0
- package/src/lib/ui/runtime/createDoc.ts +177 -0
- package/src/lib/ui/runtime/createEffectNode.ts +58 -0
- package/src/lib/ui/runtime/createSignalNode.ts +16 -0
- package/src/lib/ui/runtime/detachLink.ts +21 -0
- package/src/lib/ui/runtime/endTracking.ts +24 -0
- package/src/lib/ui/runtime/enterRenderPass.ts +12 -0
- package/src/lib/ui/runtime/exitRenderPass.ts +7 -0
- package/src/lib/ui/runtime/firstOutlet.ts +22 -0
- package/src/lib/ui/runtime/flushEffects.ts +17 -0
- package/src/lib/ui/runtime/hotInstances.ts +10 -0
- package/src/lib/ui/runtime/hotReloadEnabled.ts +8 -0
- package/src/lib/ui/runtime/hotReplace.ts +25 -0
- package/src/lib/ui/runtime/nextBlockId.ts +11 -0
- package/src/lib/ui/runtime/pathExists.ts +23 -0
- package/src/lib/ui/runtime/readNode.ts +17 -0
- package/src/lib/ui/runtime/registerHotInstance.ts +23 -0
- package/src/lib/ui/runtime/runNode.ts +28 -0
- package/src/lib/ui/runtime/runtimePath.ts +9 -0
- package/src/lib/ui/runtime/scope.ts +24 -0
- package/src/lib/ui/runtime/toTeardown.ts +26 -0
- package/src/lib/ui/runtime/track.ts +58 -0
- package/src/lib/ui/runtime/trigger.ts +44 -0
- package/src/lib/ui/runtime/types/Cell.ts +5 -0
- package/src/lib/ui/runtime/types/Derived.ts +3 -0
- package/src/lib/ui/runtime/types/Doc.ts +19 -0
- package/src/lib/ui/runtime/types/EffectResult.ts +10 -0
- package/src/lib/ui/runtime/types/HotInstance.ts +14 -0
- package/src/lib/ui/runtime/types/NavVerdict.ts +9 -0
- package/src/lib/ui/runtime/types/Patch.ts +11 -0
- package/src/lib/ui/runtime/types/ReactiveLink.ts +21 -0
- package/src/lib/ui/runtime/types/ReactiveNode.ts +25 -0
- package/src/lib/ui/runtime/types/Route.ts +8 -0
- package/src/lib/ui/runtime/types/RouteLoader.ts +7 -0
- package/src/lib/ui/runtime/types/SsrRender.ts +22 -0
- package/src/lib/ui/runtime/types/State.ts +3 -0
- package/src/lib/ui/runtime/types/Teardown.ts +5 -0
- package/src/lib/ui/runtime/types/UiComponent.ts +16 -0
- package/src/lib/ui/runtime/types/UiProps.ts +15 -0
- package/src/lib/ui/runtime/unlinkDeps.ts +20 -0
- package/src/lib/ui/runtime/untrack.ts +20 -0
- package/src/lib/ui/runtime/valueAtPath.ts +18 -0
- package/src/lib/ui/runtime/writeNode.ts +16 -0
- package/src/lib/ui/socketChannel.ts +227 -0
- package/src/lib/ui/socketProxy.ts +25 -0
- package/src/lib/ui/startClient.ts +58 -0
- package/src/lib/ui/state.ts +25 -0
- package/src/lib/ui/tail.ts +324 -0
- package/src/lib/ui/types/Layouts.ts +9 -0
- package/src/lib/ui/types/Pages.ts +8 -0
- package/src/preload.ts +19 -0
- package/src/scaffold.ts +153 -0
- package/src/serverBuildPlugins.ts +19 -0
- package/src/serverEntry.ts +95 -0
- package/template/bunfig.toml +4 -0
- package/template/package.json +18 -0
- package/template/src/app.ts +28 -0
- package/template/src/bundle/icon.png +0 -0
- package/template/src/cli/banner.txt +3 -0
- package/template/src/cli/footer.txt +1 -0
- package/template/src/server/config.ts +17 -0
- package/template/src/server/rpc/getHello.ts +36 -0
- package/template/src/ui/Layout.abide +19 -0
- package/template/src/ui/app.css +21 -0
- package/template/src/ui/app.html +24 -0
- package/template/src/ui/pages/about/page.abide +9 -0
- package/template/src/ui/pages/page.abide +22 -0
- package/template/test/app.test.ts +30 -0
- package/template/tsconfig.json +18 -0
- package/tsconfig.app.json +17 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { clearLastConnection } from '../shared/clearLastConnection.ts'
|
|
2
|
+
import { connectToServer } from './connectToServer.ts'
|
|
3
|
+
import { dispatchCommand } from './dispatchCommand.ts'
|
|
4
|
+
import { printSessionHelp } from './printSessionHelp.ts'
|
|
5
|
+
import { printSessionStatus } from './printSessionStatus.ts'
|
|
6
|
+
import { printTrimmed } from './printTrimmed.ts'
|
|
7
|
+
import { startLocalInstance } from './startLocalInstance.ts'
|
|
8
|
+
import { tokenizeLine } from './tokenizeLine.ts'
|
|
9
|
+
import type { CliManifest } from './types/CliManifest.ts'
|
|
10
|
+
import type { CliTarget } from './types/CliTarget.ts'
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
Interactive session (REPL). The banner is printed once by the caller; this prints
|
|
14
|
+
the status line, then loops reading stdin lines via Bun's async-iterable console:
|
|
15
|
+
- bare words → dispatch the RPC against the current target
|
|
16
|
+
- /connect <url>, /start, /disconnect, /help, /clear, /exit → meta commands
|
|
17
|
+
The session owns the current target's child (a local instance) and reaps it when
|
|
18
|
+
the connection is swapped or the loop ends — including on SIGINT.
|
|
19
|
+
*/
|
|
20
|
+
export async function runSession({
|
|
21
|
+
programName,
|
|
22
|
+
manifest,
|
|
23
|
+
footer,
|
|
24
|
+
target,
|
|
25
|
+
}: {
|
|
26
|
+
programName: string
|
|
27
|
+
manifest: CliManifest
|
|
28
|
+
footer: string
|
|
29
|
+
target: CliTarget | undefined
|
|
30
|
+
}): Promise<number> {
|
|
31
|
+
let current = target
|
|
32
|
+
// Reap any local instance on Ctrl+C — the closure reads the latest `current`.
|
|
33
|
+
// Named + removed on exit so repeated sessions in one process don't accumulate listeners.
|
|
34
|
+
const onSigint = () => {
|
|
35
|
+
current?.child?.kill()
|
|
36
|
+
process.exit(0)
|
|
37
|
+
}
|
|
38
|
+
process.on('SIGINT', onSigint)
|
|
39
|
+
|
|
40
|
+
// Swap the active connection: reap the previous local instance (only one runs
|
|
41
|
+
// at a time), adopt the next target, and reprint the status line.
|
|
42
|
+
async function swap(next: CliTarget | undefined): Promise<void> {
|
|
43
|
+
current?.child?.kill()
|
|
44
|
+
current = next
|
|
45
|
+
await printSessionStatus(current)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
await printSessionStatus(current)
|
|
49
|
+
const promptText = `${programName}> `
|
|
50
|
+
process.stdout.write(promptText)
|
|
51
|
+
|
|
52
|
+
for await (const line of console) {
|
|
53
|
+
const tokens = tokenizeLine(line.trim())
|
|
54
|
+
const head = tokens[0]
|
|
55
|
+
if (head === undefined) {
|
|
56
|
+
process.stdout.write(promptText)
|
|
57
|
+
continue
|
|
58
|
+
}
|
|
59
|
+
if (head === '/exit' || head === '/quit') {
|
|
60
|
+
break
|
|
61
|
+
}
|
|
62
|
+
if (head === '/clear') {
|
|
63
|
+
console.clear()
|
|
64
|
+
} else if (head === '/help') {
|
|
65
|
+
printSessionHelp(programName, manifest, tokens[1])
|
|
66
|
+
} else if (head === '/connect') {
|
|
67
|
+
const url = tokens[1]
|
|
68
|
+
if (!url) {
|
|
69
|
+
console.error('/connect requires a url')
|
|
70
|
+
} else {
|
|
71
|
+
const next = await connectToServer(programName, url)
|
|
72
|
+
if (next) {
|
|
73
|
+
await swap(next)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} else if (head === '/start') {
|
|
77
|
+
try {
|
|
78
|
+
await swap(await startLocalInstance(programName))
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error(
|
|
81
|
+
`could not start local instance: ${error instanceof Error ? error.message : String(error)}`,
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
} else if (head === '/disconnect') {
|
|
85
|
+
await clearLastConnection(programName)
|
|
86
|
+
await swap(undefined)
|
|
87
|
+
} else if (head.startsWith('/')) {
|
|
88
|
+
console.error(`unknown command "${head}" — /help for the list`)
|
|
89
|
+
} else if (!current) {
|
|
90
|
+
console.error('not connected — /connect <url> or /start')
|
|
91
|
+
} else {
|
|
92
|
+
await dispatchCommand({
|
|
93
|
+
programName,
|
|
94
|
+
manifest,
|
|
95
|
+
command: head,
|
|
96
|
+
argvTail: tokens.slice(1),
|
|
97
|
+
url: current.url,
|
|
98
|
+
token: current.token,
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
process.stdout.write(promptText)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
process.removeListener('SIGINT', onSigint)
|
|
105
|
+
current?.child?.kill()
|
|
106
|
+
printTrimmed(footer)
|
|
107
|
+
return 0
|
|
108
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { spawnEmbeddedServer } from '../bundle/spawnEmbeddedServer.ts'
|
|
2
|
+
import { writeLastConnection } from '../shared/writeLastConnection.ts'
|
|
3
|
+
import type { CliTarget } from './types/CliTarget.ts'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
Boots a local (embedded) instance for this session and records the intent so the
|
|
7
|
+
next bare run resumes a local instance. The caller owns the returned child and
|
|
8
|
+
reaps it on disconnect/exit. Throws if the server crashes before binding.
|
|
9
|
+
*/
|
|
10
|
+
export async function startLocalInstance(programName: string): Promise<CliTarget> {
|
|
11
|
+
const { url, child } = await spawnEmbeddedServer({ programName })
|
|
12
|
+
await writeLastConnection(programName, { kind: 'embedded' })
|
|
13
|
+
return { url, child }
|
|
14
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Splits a session input line into argv tokens, honouring single and double quotes
|
|
3
|
+
so values with spaces survive (e.g. `post --title "hello world"`). Quotes group;
|
|
4
|
+
a backslash escapes the next character (outside single quotes). Unterminated
|
|
5
|
+
quotes consume to end of line. Pure; no shell features beyond quoting — no
|
|
6
|
+
globbing, no variable expansion.
|
|
7
|
+
*/
|
|
8
|
+
export function tokenizeLine(line: string): string[] {
|
|
9
|
+
const tokens: string[] = []
|
|
10
|
+
let current = ''
|
|
11
|
+
let hasToken = false
|
|
12
|
+
let quote: '"' | "'" | undefined
|
|
13
|
+
for (let index = 0; index < line.length; index++) {
|
|
14
|
+
const char = line[index]
|
|
15
|
+
if (char === '\\' && quote !== "'") {
|
|
16
|
+
const next = line[++index]
|
|
17
|
+
if (next !== undefined) {
|
|
18
|
+
current += next
|
|
19
|
+
hasToken = true
|
|
20
|
+
}
|
|
21
|
+
continue
|
|
22
|
+
}
|
|
23
|
+
if (quote) {
|
|
24
|
+
if (char === quote) {
|
|
25
|
+
quote = undefined
|
|
26
|
+
} else {
|
|
27
|
+
current += char
|
|
28
|
+
}
|
|
29
|
+
continue
|
|
30
|
+
}
|
|
31
|
+
if (char === '"' || char === "'") {
|
|
32
|
+
quote = char
|
|
33
|
+
hasToken = true
|
|
34
|
+
continue
|
|
35
|
+
}
|
|
36
|
+
if (char === ' ' || char === '\t') {
|
|
37
|
+
if (hasToken) {
|
|
38
|
+
tokens.push(current)
|
|
39
|
+
current = ''
|
|
40
|
+
hasToken = false
|
|
41
|
+
}
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
current += char
|
|
45
|
+
hasToken = true
|
|
46
|
+
}
|
|
47
|
+
if (hasToken) {
|
|
48
|
+
tokens.push(current)
|
|
49
|
+
}
|
|
50
|
+
return tokens
|
|
51
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { CliManifestEntry } from './CliManifestEntry.ts'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Map from rpc export-name (e.g. "getReport") to its manifest entry. Built
|
|
5
|
+
by the bundler from the same verbRegistry MCP consumes; entries are
|
|
6
|
+
emitted only for rpcs with `clients.cli: true`. The CLI binary and any
|
|
7
|
+
programmatic createClient caller read this to dispatch calls.
|
|
8
|
+
*/
|
|
9
|
+
export type CliManifest = Record<string, CliManifestEntry>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { HttpVerb } from '../../shared/types/HttpVerb.ts'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Per-command manifest entry baked into the standalone CLI binary by the
|
|
5
|
+
bundler. Carries enough info to make the right HTTP request without
|
|
6
|
+
importing the handler module (which the thin build doesn't ship). Covers
|
|
7
|
+
both rpcs and socket commands — a socket `tail` is a GET against
|
|
8
|
+
`/__abide/sockets/<name>` with `accept: text/event-stream` so the CLI
|
|
9
|
+
streams it live; a socket `publish` is a POST to the same path.
|
|
10
|
+
*/
|
|
11
|
+
export type CliManifestEntry = {
|
|
12
|
+
method: HttpVerb
|
|
13
|
+
url: string
|
|
14
|
+
jsonSchema?: Record<string, unknown>
|
|
15
|
+
// Request Accept header. Socket tail sets text/event-stream to stream live frames.
|
|
16
|
+
accept?: string
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
A resolved CLI connection: the server URL plus an optional bearer token, and the
|
|
3
|
+
child process when this is a locally-spawned instance — the session owns that
|
|
4
|
+
child and reaps it on disconnect/exit.
|
|
5
|
+
*/
|
|
6
|
+
export type CliTarget = {
|
|
7
|
+
url: string
|
|
8
|
+
token?: string
|
|
9
|
+
child?: ReturnType<typeof Bun.spawn>
|
|
10
|
+
// The app's name from its identity probe, when already fetched while resolving
|
|
11
|
+
// the target — lets the status line print it without re-probing.
|
|
12
|
+
name?: string
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { HttpVerb } from '../shared/types/HttpVerb.ts'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Maps an HTTP verb to MCP tool annotations so a model can tell a read from
|
|
5
|
+
a write before calling. Abide derives these from the verb the RPC was
|
|
6
|
+
declared with rather than asking the author to repeat the intent:
|
|
7
|
+
- GET / HEAD → read-only, non-destructive
|
|
8
|
+
- POST → creates; not idempotent, not (necessarily) destructive
|
|
9
|
+
- PUT → replaces; idempotent + destructive
|
|
10
|
+
- PATCH → modifies; destructive, not idempotent
|
|
11
|
+
- DELETE → removes; idempotent + destructive
|
|
12
|
+
The shape matches MCP's ToolAnnotations (readOnlyHint / destructiveHint /
|
|
13
|
+
idempotentHint); fields a verb doesn't imply are left off.
|
|
14
|
+
*/
|
|
15
|
+
export function annotationsForMethod(method: HttpVerb): Record<string, boolean> {
|
|
16
|
+
switch (method) {
|
|
17
|
+
case 'GET':
|
|
18
|
+
case 'HEAD':
|
|
19
|
+
return { readOnlyHint: true, destructiveHint: false }
|
|
20
|
+
case 'POST':
|
|
21
|
+
return { readOnlyHint: false, destructiveHint: false, idempotentHint: false }
|
|
22
|
+
case 'PUT':
|
|
23
|
+
return { readOnlyHint: false, destructiveHint: true, idempotentHint: true }
|
|
24
|
+
case 'PATCH':
|
|
25
|
+
return { readOnlyHint: false, destructiveHint: true, idempotentHint: false }
|
|
26
|
+
case 'DELETE':
|
|
27
|
+
return { readOnlyHint: false, destructiveHint: true, idempotentHint: true }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// node:fs existsSync — cheap sync presence check, mirrors createPublicAssetServer
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
3
|
+
import { Glob } from 'bun'
|
|
4
|
+
import { mimeForExtension } from '../server/runtime/mimeForExtension.ts'
|
|
5
|
+
import type { Assets } from '../server/runtime/types/Assets.ts'
|
|
6
|
+
import type { McpResourceContents } from './types/McpResourceContents.ts'
|
|
7
|
+
import type { McpResourceDescriptor } from './types/McpResourceDescriptor.ts'
|
|
8
|
+
import type { McpResourceServer } from './types/McpResourceServer.ts'
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
The abide:// URI namespace for file-based resources. A resource's URI is this
|
|
12
|
+
prefix followed by its path relative to src/mcp/resources.
|
|
13
|
+
*/
|
|
14
|
+
const URI_PREFIX = 'abide://resources/'
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
MIME essences returned inline as UTF-8 `text` in resources/read; everything
|
|
18
|
+
else is returned as a base64 `blob`. The essence is taken before any `;charset`
|
|
19
|
+
parameter that Bun.file().type appends.
|
|
20
|
+
*/
|
|
21
|
+
function isTextMime(mime: string): boolean {
|
|
22
|
+
// split() always yields a first element; the '' default exists for noUncheckedIndexedAccess in consumer tsconfigs.
|
|
23
|
+
const essence = (mime.split(';')[0] ?? '').trim()
|
|
24
|
+
return (
|
|
25
|
+
essence.startsWith('text/') ||
|
|
26
|
+
essence === 'application/json' ||
|
|
27
|
+
essence === 'application/xml' ||
|
|
28
|
+
essence === 'image/svg+xml' ||
|
|
29
|
+
essence.endsWith('+json') ||
|
|
30
|
+
essence.endsWith('+xml')
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function descriptorFor(relativePath: string): McpResourceDescriptor {
|
|
35
|
+
return {
|
|
36
|
+
uri: `${URI_PREFIX}${relativePath}`,
|
|
37
|
+
name: relativePath,
|
|
38
|
+
mimeType: mimeForExtension(relativePath),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function contentsFor(relativePath: string, bytes: Uint8Array): McpResourceContents {
|
|
43
|
+
const mimeType = mimeForExtension(relativePath)
|
|
44
|
+
const uri = `${URI_PREFIX}${relativePath}`
|
|
45
|
+
if (isTextMime(mimeType)) {
|
|
46
|
+
return { uri, mimeType, text: new TextDecoder().decode(bytes) }
|
|
47
|
+
}
|
|
48
|
+
return { uri, mimeType, blob: bytes.toBase64() }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/*
|
|
52
|
+
Serves files under src/mcp/resources as MCP resources. Two sources, picked at
|
|
53
|
+
construction (mirrors createPublicAssetServer):
|
|
54
|
+
- `mcpResources` (standalone compile): a map of relative-path → gzip bytes
|
|
55
|
+
embedded into the binary.
|
|
56
|
+
- `resourcesDir` on disk (dev + `abide start`): files read straight from
|
|
57
|
+
`${cwd}/src/mcp/resources`.
|
|
58
|
+
*/
|
|
59
|
+
export function createMcpResourceServer({
|
|
60
|
+
resourcesDir,
|
|
61
|
+
mcpResources,
|
|
62
|
+
}: {
|
|
63
|
+
resourcesDir: string
|
|
64
|
+
mcpResources?: Assets
|
|
65
|
+
}): McpResourceServer {
|
|
66
|
+
return {
|
|
67
|
+
async list(): Promise<McpResourceDescriptor[]> {
|
|
68
|
+
if (mcpResources) {
|
|
69
|
+
return Object.keys(mcpResources).map(descriptorFor)
|
|
70
|
+
}
|
|
71
|
+
if (!existsSync(resourcesDir)) {
|
|
72
|
+
return []
|
|
73
|
+
}
|
|
74
|
+
const files = await Array.fromAsync(
|
|
75
|
+
new Glob('**/*').scan({ cwd: resourcesDir, onlyFiles: true }),
|
|
76
|
+
)
|
|
77
|
+
return files.map(descriptorFor)
|
|
78
|
+
},
|
|
79
|
+
async read(uri: string): Promise<McpResourceContents | undefined> {
|
|
80
|
+
if (!uri.startsWith(URI_PREFIX)) {
|
|
81
|
+
return undefined
|
|
82
|
+
}
|
|
83
|
+
const relativePath = uri.slice(URI_PREFIX.length)
|
|
84
|
+
// reject `..` traversal in the requested uri before any disk read
|
|
85
|
+
if (relativePath.split('/').includes('..')) {
|
|
86
|
+
return undefined
|
|
87
|
+
}
|
|
88
|
+
if (mcpResources) {
|
|
89
|
+
const compressed = mcpResources[relativePath]
|
|
90
|
+
if (!compressed) {
|
|
91
|
+
return undefined
|
|
92
|
+
}
|
|
93
|
+
return contentsFor(relativePath, Bun.gunzipSync(compressed))
|
|
94
|
+
}
|
|
95
|
+
const file = Bun.file(`${resourcesDir}/${relativePath}`)
|
|
96
|
+
if (!(await file.exists())) {
|
|
97
|
+
return undefined
|
|
98
|
+
}
|
|
99
|
+
return contentsFor(relativePath, await file.bytes())
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { NO_STORE } from '../shared/CACHE_CONTROL_VALUES.ts'
|
|
2
|
+
import { TEXT_PLAIN } from '../shared/TEXT_PLAIN.ts'
|
|
3
|
+
import { dispatchMcpRequest } from './dispatchMcpRequest.ts'
|
|
4
|
+
import type { McpServer } from './types/McpServer.ts'
|
|
5
|
+
import type { McpServerOptions } from './types/McpServerOptions.ts'
|
|
6
|
+
|
|
7
|
+
const DEFAULT_NAME = 'abide-app'
|
|
8
|
+
const DEFAULT_VERSION = '0.0.0'
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
Constructs an MCP server bound to the project's rpc registry. Returns an
|
|
12
|
+
object whose `handle(request)` is the function the bun route at
|
|
13
|
+
/__abide/mcp invokes. Framework-internal — the abide:mcp virtual
|
|
14
|
+
default-constructs it; there is no user-authored server module. Server
|
|
15
|
+
name/version default from package.json.
|
|
16
|
+
|
|
17
|
+
Tools are derived from every verb with `clients.mcp: true` (auto-on for
|
|
18
|
+
read-only verbs that carry a schema; mutating verbs opt in explicitly)
|
|
19
|
+
and from every socket with `clients.mcp: true` (a `<base>-tail` read tool
|
|
20
|
+
plus a `<base>-publish` tool when clientPublish is set). The HTTP verb
|
|
21
|
+
feeds each rpc tool's annotations. Auth inherits from the inbound request
|
|
22
|
+
— bearer / cookie headers flow into the synthesized Request that hits
|
|
23
|
+
each rpc handler. An optional `authorize` hook in opts can short-circuit
|
|
24
|
+
the request before any tool dispatches.
|
|
25
|
+
*/
|
|
26
|
+
// @readme plumbing
|
|
27
|
+
export function createMcpServer(opts: McpServerOptions = {}): McpServer {
|
|
28
|
+
const serverInfo = {
|
|
29
|
+
name: opts.name ?? DEFAULT_NAME,
|
|
30
|
+
version: opts.version ?? DEFAULT_VERSION,
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
async handle(request: Request): Promise<Response> {
|
|
34
|
+
if (request.method !== 'POST') {
|
|
35
|
+
return new Response('Method Not Allowed', {
|
|
36
|
+
status: 405,
|
|
37
|
+
headers: {
|
|
38
|
+
Allow: 'POST',
|
|
39
|
+
'Content-Type': TEXT_PLAIN,
|
|
40
|
+
'Cache-Control': NO_STORE,
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
const envelope = await dispatchMcpRequest(request, opts, serverInfo)
|
|
45
|
+
return Response.json(envelope, { headers: { 'Cache-Control': NO_STORE } })
|
|
46
|
+
},
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { ensureRegistriesLoaded } from '../server/runtime/registryManifests.ts'
|
|
2
|
+
import { getMcpResourceServer } from './mcpResourceServerSlot.ts'
|
|
3
|
+
import { buildPrompts, buildTools, callTool, renderPrompt } from './mcpSurface.ts'
|
|
4
|
+
import type { JsonRpcRequest } from './types/JsonRpcRequest.ts'
|
|
5
|
+
import type { JsonRpcResponse } from './types/JsonRpcResponse.ts'
|
|
6
|
+
import type { McpServerOptions } from './types/McpServerOptions.ts'
|
|
7
|
+
|
|
8
|
+
const PROTOCOL_VERSION = '2025-06-18'
|
|
9
|
+
|
|
10
|
+
function jsonRpcError(
|
|
11
|
+
id: string | number | null,
|
|
12
|
+
code: number,
|
|
13
|
+
message: string,
|
|
14
|
+
data?: unknown,
|
|
15
|
+
): JsonRpcResponse {
|
|
16
|
+
return { jsonrpc: '2.0', id, error: { code, message, ...(data === undefined ? {} : { data }) } }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function jsonRpcOk(id: string | number | null, result: unknown): JsonRpcResponse {
|
|
20
|
+
return { jsonrpc: '2.0', id, result }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
Interpolates the caller's arguments into the prompt body and wraps the
|
|
25
|
+
result in the MCP prompts/get wire shape — a markdown prompt is a single
|
|
26
|
+
user message whose text is the rendered template. (The in-process agent
|
|
27
|
+
loop reaches the same prompts via mcpSurface().getPrompt, which returns
|
|
28
|
+
plain messages rather than this wire shape.)
|
|
29
|
+
*/
|
|
30
|
+
function getPrompt(
|
|
31
|
+
name: string,
|
|
32
|
+
args: Record<string, unknown> | undefined,
|
|
33
|
+
): Record<string, unknown> {
|
|
34
|
+
const { description, messages } = renderPrompt(name, args)
|
|
35
|
+
return {
|
|
36
|
+
...(description ? { description } : {}),
|
|
37
|
+
messages: messages.map((message) => ({
|
|
38
|
+
role: message.role,
|
|
39
|
+
content: { type: 'text', text: message.text },
|
|
40
|
+
})),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
Parses a single JSON-RPC envelope and dispatches by method. Errors
|
|
46
|
+
become JSON-RPC error responses (the HTTP layer always returns 200 with
|
|
47
|
+
an envelope for JSON-RPC over HTTP; transport errors are different). The
|
|
48
|
+
tool/prompt derivation and tool dispatch live in mcpSurface — the same
|
|
49
|
+
projection the in-process agent loop builds on.
|
|
50
|
+
*/
|
|
51
|
+
export async function dispatchMcpRequest(
|
|
52
|
+
request: Request,
|
|
53
|
+
opts: McpServerOptions,
|
|
54
|
+
serverInfo: { name: string; version: string },
|
|
55
|
+
): Promise<JsonRpcResponse> {
|
|
56
|
+
let envelope: JsonRpcRequest
|
|
57
|
+
try {
|
|
58
|
+
envelope = (await request.clone().json()) as JsonRpcRequest
|
|
59
|
+
} catch {
|
|
60
|
+
return jsonRpcError(null, -32700, 'Parse error')
|
|
61
|
+
}
|
|
62
|
+
const id = envelope.id ?? null
|
|
63
|
+
if (envelope.jsonrpc !== '2.0' || typeof envelope.method !== 'string') {
|
|
64
|
+
return jsonRpcError(id, -32600, 'Invalid Request')
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (opts.authorize) {
|
|
68
|
+
try {
|
|
69
|
+
await opts.authorize(request)
|
|
70
|
+
} catch (error) {
|
|
71
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
72
|
+
return jsonRpcError(id, -32001, message)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
await ensureRegistriesLoaded()
|
|
78
|
+
switch (envelope.method) {
|
|
79
|
+
case 'initialize':
|
|
80
|
+
return jsonRpcOk(id, {
|
|
81
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
82
|
+
capabilities: {
|
|
83
|
+
tools: { listChanged: false },
|
|
84
|
+
prompts: { listChanged: false },
|
|
85
|
+
resources: { listChanged: false },
|
|
86
|
+
},
|
|
87
|
+
serverInfo,
|
|
88
|
+
})
|
|
89
|
+
case 'ping':
|
|
90
|
+
return jsonRpcOk(id, {})
|
|
91
|
+
case 'tools/list':
|
|
92
|
+
return jsonRpcOk(id, { tools: buildTools() })
|
|
93
|
+
case 'tools/call': {
|
|
94
|
+
const params = envelope.params as
|
|
95
|
+
| { name?: string; arguments?: Record<string, unknown> }
|
|
96
|
+
| undefined
|
|
97
|
+
if (!params?.name) {
|
|
98
|
+
return jsonRpcError(id, -32602, 'Missing tool name')
|
|
99
|
+
}
|
|
100
|
+
return jsonRpcOk(id, await callTool(params.name, params.arguments, request))
|
|
101
|
+
}
|
|
102
|
+
case 'resources/list': {
|
|
103
|
+
const resourceServer = getMcpResourceServer()
|
|
104
|
+
return jsonRpcOk(id, {
|
|
105
|
+
resources: resourceServer ? await resourceServer.list() : [],
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
case 'resources/read': {
|
|
109
|
+
const params = envelope.params as { uri?: string } | undefined
|
|
110
|
+
if (!params?.uri) {
|
|
111
|
+
return jsonRpcError(id, -32602, 'Missing resource uri')
|
|
112
|
+
}
|
|
113
|
+
const resourceServer = getMcpResourceServer()
|
|
114
|
+
const contents = resourceServer ? await resourceServer.read(params.uri) : undefined
|
|
115
|
+
if (!contents) {
|
|
116
|
+
return jsonRpcError(id, -32602, `unknown resource: ${params.uri}`)
|
|
117
|
+
}
|
|
118
|
+
return jsonRpcOk(id, { contents: [contents] })
|
|
119
|
+
}
|
|
120
|
+
case 'prompts/list':
|
|
121
|
+
return jsonRpcOk(id, { prompts: buildPrompts() })
|
|
122
|
+
case 'prompts/get': {
|
|
123
|
+
const params = envelope.params as
|
|
124
|
+
| { name?: string; arguments?: Record<string, unknown> }
|
|
125
|
+
| undefined
|
|
126
|
+
if (!params?.name) {
|
|
127
|
+
return jsonRpcError(id, -32602, 'Missing prompt name')
|
|
128
|
+
}
|
|
129
|
+
return jsonRpcOk(id, getPrompt(params.name, params.arguments))
|
|
130
|
+
}
|
|
131
|
+
default:
|
|
132
|
+
return jsonRpcError(id, -32601, `Method not found: ${envelope.method}`)
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
136
|
+
return jsonRpcError(id, -32603, message)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { McpResourceServer } from './types/McpResourceServer.ts'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
Process-wide slot for the MCP resource server. createServer assigns it at
|
|
5
|
+
boot; dispatchMcpRequest reads it on resources/list + resources/read. Mirrors
|
|
6
|
+
the registryManifests slot — the default MCP server is constructed in the
|
|
7
|
+
abide:mcp virtual with no args, so the resource server (which needs the
|
|
8
|
+
project's resourcesDir + embedded map) is injected out of band.
|
|
9
|
+
*/
|
|
10
|
+
let resourceServer: McpResourceServer | undefined
|
|
11
|
+
|
|
12
|
+
export function setMcpResourceServer(value: McpResourceServer): void {
|
|
13
|
+
resourceServer = value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getMcpResourceServer(): McpResourceServer | undefined {
|
|
17
|
+
return resourceServer
|
|
18
|
+
}
|