Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
46cc640
first pass at flow with CLI
michaelneale Jul 18, 2025
172d67d
checkpoint
michaelneale Jul 18, 2025
bebb16b
now has gui
michaelneale Jul 21, 2025
0bd7230
Merge branch 'main' into micn/install-with-openrouter
michaelneale Jul 21, 2025
0cd926c
tidy up
michaelneale Jul 21, 2025
5a8f563
some test coverage
michaelneale Jul 21, 2025
9e58a88
setup in cli correctly
michaelneale Jul 21, 2025
921ce72
move logic to goose crate where it should be
michaelneale Jul 21, 2025
94608f3
slightly less ominous warning, but may only be at dev time
michaelneale Jul 21, 2025
be9da5c
Merge branch 'main' into micn/install-with-openrouter
michaelneale Jul 22, 2025
538204f
message
michaelneale Jul 22, 2025
8040864
Merge branch 'main' into micn/install-with-openrouter
michaelneale Jul 23, 2025
d5899e6
run it with option to show providers
michaelneale Jul 23, 2025
81fa3a0
fix up goose configure to offer openrouter login when fresh
michaelneale Jul 23, 2025
a54703a
Merge branch 'main' into micn/install-with-openrouter
michaelneale Jul 24, 2025
9056916
Merge branch 'main' into micn/install-with-openrouter
michaelneale Jul 28, 2025
56dc6f6
cli shouldn't change
michaelneale Jul 28, 2025
39cba52
change path for openrouter flow, remove comments, tidy up tests based…
michaelneale Jul 28, 2025
a49e252
tidy up
michaelneale Jul 28, 2025
b7264b7
addressing feedback
michaelneale Jul 29, 2025
df0767b
Merge branch 'main' into micn/install-with-openrouter
michaelneale Jul 29, 2025
d261cb8
fmt
michaelneale Jul 29, 2025
b6d7eb9
error goes to welcome like before
michaelneale Jul 29, 2025
e86828b
adding to base list for openrouter
michaelneale Jul 29, 2025
8b43170
closing/restart
michaelneale Jul 29, 2025
41656d3
Merge branch 'main' into micn/install-with-openrouter
michaelneale Jul 29, 2025
e2600f1
Merge branch 'main' into micn/install-with-openrouter
michaelneale Jul 30, 2025
838997d
don't need this for singular UI client
michaelneale Jul 30, 2025
f72603b
Merge branch 'main' into micn/install-with-openrouter
michaelneale Jul 30, 2025
b4be209
will now refresh correctly
michaelneale Jul 30, 2025
67bca4b
cleanup
michaelneale Jul 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/goose-cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
Comment thread
michaelneale marked this conversation as resolved.
use clap::{Args, Parser, Subcommand};

use goose::config::{Config, ExtensionConfig};
use goose::config::Config;

use crate::commands::bench::agent_generator;
use crate::commands::configure::handle_configure;
Expand Down Expand Up @@ -273,7 +273,7 @@ enum RecipeCommand {
enum Command {
/// Configure Goose settings
#[command(about = "Configure Goose settings")]
Configure {},
Configure,

/// Display Goose configuration information
#[command(about = "Display Goose information")]
Expand Down Expand Up @@ -681,7 +681,7 @@ enum CliProviderVariant {
#[derive(Debug)]
pub struct InputConfig {
pub contents: Option<String>,
pub extensions_override: Option<Vec<ExtensionConfig>>,
pub extensions_override: Option<Vec<goose::config::ExtensionConfig>>,
pub additional_system_prompt: Option<String>,
}

Expand All @@ -702,7 +702,7 @@ pub async fn cli() -> Result<()> {
}

match cli.command {
Some(Command::Configure {}) => {
Some(Command::Configure) => {
let _ = handle_configure().await;
return Ok(());
}
Expand Down
292 changes: 210 additions & 82 deletions crates/goose-cli/src/commands/configure.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions crates/goose-server/src/routes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod recipe;
pub mod reply;
pub mod schedule;
pub mod session;
pub mod setup;
pub mod utils;
use std::sync::Arc;

Expand All @@ -29,4 +30,5 @@ pub fn configure(state: Arc<crate::state::AppState>) -> Router {
.merge(session::routes(state.clone()))
.merge(schedule::routes(state.clone()))
.merge(project::routes(state.clone()))
.merge(setup::routes(state.clone()))
}
122 changes: 122 additions & 0 deletions crates/goose-server/src/routes/setup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
use crate::state::AppState;
use axum::{extract::State, http::StatusCode, routing::post, Json, Router};
use goose::config::signup_openrouter::OpenRouterAuth;
use goose::config::{configure_openrouter, Config};
use once_cell::sync::Lazy;
use serde::Serialize;
use std::sync::Arc;
use tokio::sync::Mutex;

// Global mutex to ensure only one OAuth flow at a time
static OAUTH_FLOW_MUTEX: Lazy<Arc<Mutex<()>>> = Lazy::new(|| Arc::new(Mutex::new(())));

#[derive(Serialize)]
pub struct SetupResponse {
pub success: bool,
pub message: String,
}

pub fn routes(state: Arc<AppState>) -> Router {
Router::new()
.route("/setup/openrouter/start", post(start_openrouter_setup))
Comment thread
michaelneale marked this conversation as resolved.
Outdated
.with_state(state)
}

async fn start_openrouter_setup(
Comment thread
michaelneale marked this conversation as resolved.
State(_state): State<Arc<AppState>>,
) -> Result<Json<SetupResponse>, StatusCode> {
tracing::info!("Starting OpenRouter setup flow");

// Try to acquire the mutex with a timeout to prevent concurrent OAuth flows
let _lock = match tokio::time::timeout(
std::time::Duration::from_secs(1),
OAUTH_FLOW_MUTEX.lock(),
)
.await
{
Ok(lock) => lock,
Err(_) => {
tracing::warn!("OAuth flow is already in progress");
return Ok(Json(SetupResponse {
success: false,
message: "Authentication flow is already in progress. Please wait.".to_string(),
}));
}
};

tracing::info!("Acquired OAuth flow lock");

// Run the existing PKCE flow
Comment thread
michaelneale marked this conversation as resolved.
Outdated
let mut auth_flow = OpenRouterAuth::new().map_err(|e| {
tracing::error!("Failed to initialize auth flow: {}", e);
StatusCode::INTERNAL_SERVER_ERROR
})?;

tracing::info!("Auth flow initialized, starting complete_flow");

match auth_flow.complete_flow().await {
Ok(api_key) => {
// The complete_flow only returns the API key, we need to save the configuration
tracing::info!("Got API key, configuring OpenRouter...");

// Configure everything using the common function
let config = Config::global();

// Use the common configuration function
if let Err(e) = configure_openrouter(config, api_key) {
tracing::error!("Failed to configure OpenRouter: {}", e);
return Ok(Json(SetupResponse {
success: false,
message: format!("Failed to configure OpenRouter: {}", e),
}));
}

tracing::info!("OpenRouter setup completed successfully");
Ok(Json(SetupResponse {
success: true,
message: "OpenRouter setup completed successfully".to_string(),
}))
}
Err(e) => {
tracing::error!("OpenRouter setup failed: {}", e);
Ok(Json(SetupResponse {
success: false,
message: format!("Setup failed: {}", e),
}))
}
}
}

#[cfg(test)]
mod tests {
use super::*;

#[tokio::test]
async fn test_oauth_flow_mutex() {
Comment thread
michaelneale marked this conversation as resolved.
Outdated
// Test that the OAuth flow mutex is properly initialized and prevents concurrent flows
let lock1 = OAUTH_FLOW_MUTEX.try_lock();
assert!(lock1.is_ok(), "First lock should succeed");

// Try to acquire second lock while first is held
let lock2_result = tokio::time::timeout(
std::time::Duration::from_millis(100),
OAUTH_FLOW_MUTEX.lock(),
)
.await;

assert!(
lock2_result.is_err(),
"Second lock should timeout while first is held"
);

// Drop first lock
drop(lock1);

// Now second lock should succeed
let lock2 = OAUTH_FLOW_MUTEX.try_lock();
assert!(
lock2.is_ok(),
"Second lock should succeed after first is dropped"
);
}
}
3 changes: 2 additions & 1 deletion crates/goose/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ nanoid = "0.4"
sha2 = "0.10"
base64 = "0.21"
url = "2.5"
urlencoding = "2.1"
axum = "0.8.1"
webbrowser = "0.8"
lazy_static = "1.5.0"
Expand All @@ -66,6 +65,8 @@ etcetera = "0.8.0"
rand = "0.8.5"
utoipa = { version = "4.1", features = ["chrono"] }
tokio-cron-scheduler = "0.14.0"
urlencoding = "2.1"
html-escape = "0.2"
Comment thread
michaelneale marked this conversation as resolved.
Outdated

# For Bedrock provider
aws-config = { version = "1.5.16", features = ["behavior-version-latest"] }
Expand Down
2 changes: 2 additions & 0 deletions crates/goose/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ pub mod base;
mod experiments;
pub mod extensions;
pub mod permission;
pub mod signup_openrouter;

pub use crate::agents::ExtensionConfig;
pub use base::{Config, ConfigError, APP_STRATEGY};
pub use experiments::ExperimentManager;
pub use extensions::{ExtensionConfigManager, ExtensionEntry};
pub use permission::PermissionManager;
pub use signup_openrouter::configure_openrouter;

pub use extensions::DEFAULT_DISPLAY_NAME;
pub use extensions::DEFAULT_EXTENSION;
Expand Down
Loading
Loading