diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 85dfc6c78078..2eeff78b1d05 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -93,6 +93,28 @@ This command regenerates `ui/desktop/openapi.json` and then runs the UI's Changes to the API should be made in the Rust source under `crates/goose-server/src/`. +### Debugging + +To debug the Goose server, you can run it from your preferred IDE. How to configure the command +to start the server will depend on your IDE. The command to run is: + +``` +export GOOSE_SERVER__SECRET_KEY=test +cargo run --package goose-server --bin goosed -- agent # or: `just run-server` +``` + +The server will start listening on port `3000` by default, but this can be changed by setting the +`GOOSE_PORT` environment variable. + +Once the server is running, you can start a UI and connect it to the server by running: + +``` +just debug-ui +``` + +The UI will now be connected to the server you started in your IDE, allowing you to set breakpoints +and step through the server code as you interact with the UI. + ## Creating a fork To fork the repository: diff --git a/Justfile b/Justfile index d5f32e85d962..30a7b636c170 100644 --- a/Justfile +++ b/Justfile @@ -196,7 +196,7 @@ run-docs: # Run server run-server: @echo "Running server..." - cargo run -p goose-server + cargo run -p goose-server --bin goosed agent # Check if OpenAPI schema is up-to-date check-openapi-schema: generate-openapi diff --git a/ui/desktop/src/goosed.ts b/ui/desktop/src/goosed.ts index 16c8398f3f52..acdb61880d1d 100644 --- a/ui/desktop/src/goosed.ts +++ b/ui/desktop/src/goosed.ts @@ -47,10 +47,20 @@ const checkServerStatus = async (): Promise => { const connectToExternalBackend = async ( workingDir: string, - port: number = 3000 + port: number = 3000, + serverSecret: string ): Promise<[number, string, ChildProcess]> => { log.info(`Using external goosed backend on port ${port}`); + // Configure the client BEFORE checking server status + client.setConfig({ + baseUrl: `http://127.0.0.1:${port}`, + headers: { + 'Content-Type': 'application/json', + 'X-Secret-Key': serverSecret, + }, + }); + const isReady = await checkServerStatus(); if (!isReady) { throw new Error(`External goosed server not accessible on port ${port}`); @@ -94,7 +104,7 @@ export const startGoosed = async ( dir = path.resolve(path.normalize(dir)); if (process.env.GOOSE_EXTERNAL_BACKEND) { - return connectToExternalBackend(dir, 3000); + return connectToExternalBackend(dir, 3000, serverSecret); } // Validate that the directory actually exists and is a directory