From 04f10d2794ec498dd5535af68d227563befef442 Mon Sep 17 00:00:00 2001 From: Sienna Meridian Satterwhite Date: Tue, 24 Mar 2026 09:38:02 +0000 Subject: [PATCH] feat: sunbeam reindex-code CLI verb + ReindexCode proto Proto: ReindexCode RPC with org/repo/branch filters. CLI: sunbeam reindex-code [--org studio] [--repo owner/name] [--endpoint ...] Calls Sol's gRPC ReindexCode endpoint, prints indexed symbol count. --- sunbeam-proto/proto/code.proto | 13 +++++++++ sunbeam/src/cli.rs | 44 +++++++++++++++++++++++++++++++ sunbeam/tests/code_integration.rs | 4 +++ 3 files changed, 61 insertions(+) diff --git a/sunbeam-proto/proto/code.proto b/sunbeam-proto/proto/code.proto index 8f33a74..208d6ce 100644 --- a/sunbeam-proto/proto/code.proto +++ b/sunbeam-proto/proto/code.proto @@ -5,6 +5,19 @@ package sunbeam.code.v1; // the `sunbeam code` TUI client and Sol's server-side agent loop. service CodeAgent { rpc Session(stream ClientMessage) returns (stream ServerMessage); + rpc ReindexCode(ReindexCodeRequest) returns (ReindexCodeResponse); +} + +message ReindexCodeRequest { + string org = 1; // optional: filter to an org (empty = all) + string repo = 2; // optional: specific repo (empty = all) + string branch = 3; // optional: specific branch (empty = default) +} + +message ReindexCodeResponse { + uint32 repos_indexed = 1; + uint32 symbols_indexed = 2; + string error = 3; // empty on success } // ── Client → Sol ─────────────────────────────────────────────── diff --git a/sunbeam/src/cli.rs b/sunbeam/src/cli.rs index 94e778a..ff2b545 100644 --- a/sunbeam/src/cli.rs +++ b/sunbeam/src/cli.rs @@ -145,6 +145,23 @@ pub enum Verb { action: Option, }, + /// Reindex Gitea repos into Sol's code search index. + #[command(name = "reindex-code")] + ReindexCode { + /// Filter to a specific org. + #[arg(long)] + org: Option, + /// Index a specific repo (owner/name format). + #[arg(long)] + repo: Option, + /// Index a specific branch (default: repo's default branch). + #[arg(long)] + branch: Option, + /// Sol gRPC endpoint. + #[arg(long, default_value = "http://127.0.0.1:50051")] + endpoint: String, + }, + /// Self-update from latest mainline commit. Update, @@ -1060,6 +1077,33 @@ pub async fn dispatch() -> Result<()> { }, Some(Verb::Code { action }) => crate::code::cmd_code(action).await, + Some(Verb::ReindexCode { org, repo, branch, endpoint }) => { + use sunbeam_proto::sunbeam_code_v1::code_agent_client::CodeAgentClient; + use sunbeam_proto::sunbeam_code_v1::ReindexCodeRequest; + + tracing::info!(endpoint = endpoint.as_str(), "Connecting to Sol for reindex"); + let mut client = CodeAgentClient::connect(endpoint) + .await + .map_err(|e| sunbeam_sdk::error::SunbeamError::Other(format!("Failed to connect: {e}")))?; + + let request = ReindexCodeRequest { + org: org.unwrap_or_default(), + repo: repo.unwrap_or_default(), + branch: branch.unwrap_or_default(), + }; + + let response = client.reindex_code(request) + .await + .map_err(|e| sunbeam_sdk::error::SunbeamError::Other(format!("Reindex failed: {e}")))?; + + let resp = response.into_inner(); + if resp.error.is_empty() { + println!("Indexed {} symbols across {} repos", resp.symbols_indexed, resp.repos_indexed); + } else { + eprintln!("Error: {}", resp.error); + } + Ok(()) + } Some(Verb::Update) => sunbeam_sdk::update::cmd_update().await, diff --git a/sunbeam/tests/code_integration.rs b/sunbeam/tests/code_integration.rs index b8cc549..a422a16 100644 --- a/sunbeam/tests/code_integration.rs +++ b/sunbeam/tests/code_integration.rs @@ -72,6 +72,10 @@ impl CodeAgent for MockCodeAgent { Ok(Response::new(Box::pin(ReceiverStream::new(rx)))) } + + async fn reindex_code(&self, _req: Request) -> Result, Status> { + Ok(Response::new(ReindexCodeResponse { repos_indexed: 0, symbols_indexed: 0, error: "mock".into() })) + } } #[tokio::test]