-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add CodeBuddy agent support #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+162
−10
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5ac883b
feat: add CodeBuddy agent support
studyzy d492f17
Merge branch 'main' into feat/codebuddy-agent
studyzy e5c85fd
fix: add auth/provisioning flow and hosted/local-gateway branch to co…
studyzy 597bcb0
fix: resolve remaining merge conflict markers in README.md, Cargo.tom…
studyzy 030a21f
Merge offical/main into feat/codebuddy-agent
studyzy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| /target | ||
| /.claude | ||
| .idea/ | ||
| .serena/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| use anyhow::Result; | ||
|
|
||
| use super::util; | ||
|
|
||
| #[derive(Debug, clap::Parser)] | ||
| #[command(disable_help_flag = true)] | ||
| pub struct Options { | ||
| /// Route traffic through a local gateway instead of the hosted Edgee service. | ||
| /// Session tracking is disabled in this mode. | ||
| #[arg(long)] | ||
| pub local_gateway: bool, | ||
|
|
||
| /// Extra args passed through to the codebuddy CLI | ||
| #[arg(trailing_var_arg = true, allow_hyphen_values = true)] | ||
| pub args: Vec<String>, | ||
| } | ||
|
|
||
| pub async fn run(opts: Options) -> Result<()> { | ||
| let mut creds = crate::config::read()?; | ||
|
|
||
| // Step 1: ensure we are authenticated | ||
| if creds.user_token.as_deref().unwrap_or("").is_empty() { | ||
| crate::commands::auth::login::perform_login().await?; | ||
| } | ||
|
|
||
| // Step 1b: ensure an org is selected (handles partial state after aborted login) | ||
| crate::commands::auth::login::ensure_org_selected().await?; | ||
|
|
||
| // Step 2: ensure we have a live api_key for CodeBuddy. Re-provisions if the | ||
| // cached key was deleted in the console; re-runs onboarding for a fresh key. | ||
| let reprovisioned = | ||
| crate::commands::auth::login::ensure_valid_provider_key("codebuddy").await?; | ||
| if reprovisioned { | ||
| crate::commands::auth::login::ensure_onboarded("codebuddy").await?; | ||
| } | ||
| creds = crate::config::read()?; | ||
|
|
||
| // Step 3: ensure we have a connection choice (default to "plan" for codebuddy) | ||
| if creds | ||
| .codebuddy | ||
| .as_ref() | ||
| .and_then(|c| c.connection.as_deref()) | ||
| .is_none() | ||
| { | ||
| let provider = creds.codebuddy.get_or_insert_with(Default::default); | ||
| provider.connection = Some("plan".to_string()); | ||
| crate::config::write(&creds)?; | ||
| } | ||
|
|
||
| // Step 4: launch codebuddy with the correct env vars | ||
| let codebuddy = creds.codebuddy.as_ref().unwrap(); | ||
| let api_key = &codebuddy.api_key; | ||
| let session_id = uuid::Uuid::new_v4().to_string(); | ||
|
|
||
| // First-run: install the persistent user-level statusline integration | ||
| // exactly once. CodeBuddy itself doesn't render an Edgee statusline today, | ||
| // but users typically also use Claude Code in the same shell — running | ||
| // the installer on the first `edgee launch` of any agent matches the | ||
| // "set it up once" flow we want. | ||
| util::ensure_first_run_installed().await; | ||
|
|
||
| if opts.local_gateway { | ||
| return run_with_local_gateway(opts.args).await; | ||
| } | ||
|
|
||
| util::spawn_cli_version_report(&creds, &session_id); | ||
|
|
||
| let repo_entry = crate::git::detect_origin() | ||
| .map(|url| format!(",\"x-edgee-repo\"=\"{url}\"")) | ||
| .unwrap_or_default(); | ||
| let base_url = format!("{}/v1", super::resolve_gateway_base_url(&creds).await); | ||
| let mut cmd = std::process::Command::new(util::resolve_binary("codebuddy")); | ||
| cmd.env("EDGEE_SESSION_ID", &session_id); | ||
| cmd.env("CODEBUDDY_BASE_URL", &base_url); | ||
| cmd.env( | ||
| "CODEBUDDY_CUSTOM_HEADERS", | ||
| format!( | ||
| "x-edgee-api-key: {api_key}\nx-edgee-session-id: {session_id}{repo_entry}" | ||
| ), | ||
| ); | ||
| cmd.args(&opts.args); | ||
|
|
||
| let status = cmd.status().map_err(|e| { | ||
| if e.kind() == std::io::ErrorKind::NotFound { | ||
| anyhow::anyhow!( | ||
| "CodeBuddy is not installed. Install it from https://cnb.cool/codebuddy/codebuddy-code" | ||
| ) | ||
| } else { | ||
| anyhow::anyhow!(e) | ||
| } | ||
| })?; | ||
|
|
||
| super::print_session_stats(&creds, &session_id, "CodeBuddy").await; | ||
|
|
||
| if let Some(code) = status.code() { | ||
| std::process::exit(code); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Launch CodeBuddy routed through a local gateway. Session tracking and version | ||
| /// reporting are skipped — the backend never sees this traffic. | ||
| async fn run_with_local_gateway(args: Vec<String>) -> Result<()> { | ||
| use std::net::Ipv4Addr; | ||
|
|
||
| let log_path = crate::config::local_gateway_log_path(); | ||
| crate::local_gateway::init_file_tracing(&log_path)?; | ||
| eprintln!("edgee: gateway logs -> {}", log_path.display()); | ||
|
|
||
| let gateway = crate::local_gateway::start((Ipv4Addr::LOCALHOST, 0).into()).await?; | ||
| let addr = gateway.addr; | ||
|
|
||
| let mut cmd = tokio::process::Command::new(util::resolve_binary("codebuddy")); | ||
| cmd.env("CODEBUDDY_BASE_URL", format!("http://{addr}")); | ||
| cmd.args(&args); | ||
|
|
||
| util::run_with_gateway( | ||
| gateway, | ||
| cmd, | ||
| "CodeBuddy is not installed. Install it from https://cnb.cool/codebuddy/codebuddy-code", | ||
| ) | ||
| .await | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.