@@ -60,10 +60,14 @@ import System.IO.Temp qualified as Temp
6060import System.Path qualified as Path
6161import Text.Megaparsec qualified as MP
6262import U.Codebase.Sqlite.Queries qualified as Queries
63+ import Unison.Auth.CredentialManager qualified as AuthN
64+ import Unison.Auth.HTTPClient qualified as AuthN
65+ import Unison.Auth.Tokens qualified as AuthN
6366import Unison.Cli.ProjectUtils qualified as ProjectUtils
6467import Unison.Codebase (Codebase , CodebasePath )
6568import Unison.Codebase qualified as Codebase
6669import Unison.Codebase.Editor.Input qualified as Input
70+ import Unison.Codebase.Editor.UCMVersion (UCMVersion )
6771import Unison.Codebase.Execute (execute )
6872import Unison.Codebase.Init (CodebaseInitOptions (.. ), InitError (.. ), InitResult (.. ), SpecifiedCodebase (.. ))
6973import Unison.Codebase.Init qualified as CodebaseInit
@@ -151,9 +155,12 @@ main version = do
151155 PrintVersion ->
152156 Text. putStrLn $ Text. pack progName <> " version: " <> Version. gitDescribeWithDate version
153157 MCPServer -> do
158+ let ucmVersion = Version. gitDescribeWithDate version
159+ credMan <- AuthN. newCredentialManager
160+ authenticatedHTTPClient <- initTranscriptAuthenticatedHTTPClient ucmVersion credMan
154161 getCodebaseOrExit mCodePathOption SC. DontLock (SC. MigrateAfterPrompt SC. Backup SC. Vacuum ) \ (_initRes, _, theCodebase) -> do
155162 withRuntimes RTI. Persistent \ (runtime, sbRuntime) -> do
156- MCP. runOnStdIO theCodebase runtime sbRuntime currentDir ( Version. gitDescribeWithDate version)
163+ MCP. runOnStdIO theCodebase runtime sbRuntime currentDir ucmVersion authenticatedHTTPClient
157164 Init -> do
158165 exitError
159166 ( P. lines
@@ -184,6 +191,9 @@ main version = do
184191 let fileEvent = Input. UnisonFileChanged (Text. pack file) contents
185192 let noOpCheckForChanges _ = pure ()
186193 let serverUrl = Nothing
194+ let ucmVersion = Version. gitDescribeWithDate version
195+ credMan <- liftIO $ AuthN. newCredentialManager
196+ authenticatedHTTPClient <- initTranscriptAuthenticatedHTTPClient ucmVersion credMan
187197 startProjectPath <- Codebase. runTransaction theCodebase Codebase. expectCurrentProjectPath
188198 launch
189199 version
@@ -192,6 +202,8 @@ main version = do
192202 sbrt
193203 theCodebase
194204 [Left fileEvent, Right $ Input. ExecuteI mainName args, Right Input. QuitI ]
205+ authenticatedHTTPClient
206+ credMan
195207 serverUrl
196208 (PP. toIds startProjectPath)
197209 initRes
@@ -207,6 +219,9 @@ main version = do
207219 let fileEvent = Input. UnisonFileChanged (Text. pack " <standard input>" ) contents
208220 let noOpCheckForChanges _ = pure ()
209221 let serverUrl = Nothing
222+ let ucmVersion = Version. gitDescribeWithDate version
223+ credMan <- liftIO $ AuthN. newCredentialManager
224+ authenticatedHTTPClient <- initTranscriptAuthenticatedHTTPClient ucmVersion credMan
210225 startProjectPath <- Codebase. runTransaction theCodebase Codebase. expectCurrentProjectPath
211226 launch
212227 version
@@ -215,6 +230,8 @@ main version = do
215230 sbrt
216231 theCodebase
217232 [Left fileEvent, Right $ Input. ExecuteI mainName args, Right Input. QuitI ]
233+ authenticatedHTTPClient
234+ credMan
218235 serverUrl
219236 (PP. toIds startProjectPath)
220237 initRes
@@ -322,8 +339,10 @@ main version = do
322339 -- https://gitlab.haskell.org/ghc/ghc/-/merge_requests/1224
323340 void . Ki. fork scope $ LSP. spawnLsp lspFormattingConfig theCodebase runtime changeSignal
324341 let isTest = False
325- mcpServerConfig <-
326- MCP. initServer theCodebase runtime sbRuntime (pure currentDir) $ Version. gitDescribeWithDate version
342+ let ucmVersion = Version. gitDescribeWithDate version
343+ credMan <- liftIO $ AuthN. newCredentialManager
344+ authenticatedHTTPClient <- initTranscriptAuthenticatedHTTPClient ucmVersion credMan
345+ mcpServerConfig <- MCP. initServer theCodebase runtime sbRuntime (Just currentDir) ucmVersion authenticatedHTTPClient
327346 Server. startServer
328347 isTest
329348 Backend. BackendEnv {Backend. useNamesIndex = False }
@@ -358,14 +377,15 @@ main version = do
358377 takeMVar mvar
359378 WithCLI -> do
360379 PT. putPrettyLn $ P. string " Now starting the Unison Codebase Manager (UCM)..."
361-
362380 launch
363381 version
364382 currentDir
365383 runtime
366384 sbRuntime
367385 theCodebase
368386 []
387+ authenticatedHTTPClient
388+ credMan
369389 mayBaseUrl
370390 (PP. toIds startingProjectPath)
371391 initRes
@@ -379,6 +399,9 @@ main version = do
379399 RTI. withRuntime False mode (Version. gitDescribeWithDate version) \ runtime -> do
380400 RTI. withRuntime True mode (Version. gitDescribeWithDate version) \ sbRuntime ->
381401 action (runtime, sbRuntime)
402+ initTranscriptAuthenticatedHTTPClient :: UCMVersion -> AuthN. CredentialManager -> IO AuthN. AuthenticatedHttpClient
403+ initTranscriptAuthenticatedHTTPClient ucmVersion credMan = do
404+ AuthN. newAuthenticatedHTTPClient (AuthN. newTokenProvider credMan) ucmVersion
382405
383406isExitSuccess :: SomeException -> Bool
384407isExitSuccess =
@@ -583,13 +606,15 @@ launch ::
583606 Rt. Runtime Symbol ->
584607 Codebase. Codebase IO Symbol Ann ->
585608 [Either Input. Event Input. Input ] ->
609+ AuthN. AuthenticatedHttpClient ->
610+ AuthN. CredentialManager ->
586611 Maybe Server. BaseUrl ->
587612 PP. ProjectPathIds ->
588613 InitResult ->
589614 (PP. ProjectPathIds -> IO () ) ->
590615 CommandLine. ShouldWatchFiles ->
591616 IO ()
592- launch version dir runtime sbRuntime codebase inputs serverBaseUrl startingPath initResult lspCheckForChanges shouldWatchFiles = do
617+ launch version dir runtime sbRuntime codebase inputs authenticatedHTTPClient credMan serverBaseUrl startingPath initResult lspCheckForChanges shouldWatchFiles = do
593618 showWelcomeHint <- Codebase. runTransaction codebase Queries. doProjectsExist
594619 let isNewCodebase = case initResult of
595620 CreatedCodebase -> NewlyCreatedCodebase
@@ -606,6 +631,8 @@ launch version dir runtime sbRuntime codebase inputs serverBaseUrl startingPath
606631 codebase
607632 serverBaseUrl
608633 ucmVersion
634+ authenticatedHTTPClient
635+ credMan
609636 lspCheckForChanges
610637 shouldWatchFiles
611638
0 commit comments