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.
This commit is contained in:
@@ -5,6 +5,19 @@ package sunbeam.code.v1;
|
|||||||
// the `sunbeam code` TUI client and Sol's server-side agent loop.
|
// the `sunbeam code` TUI client and Sol's server-side agent loop.
|
||||||
service CodeAgent {
|
service CodeAgent {
|
||||||
rpc Session(stream ClientMessage) returns (stream ServerMessage);
|
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 ───────────────────────────────────────────────
|
// ── Client → Sol ───────────────────────────────────────────────
|
||||||
|
|||||||
@@ -145,6 +145,23 @@ pub enum Verb {
|
|||||||
action: Option<crate::code::CodeCommand>,
|
action: Option<crate::code::CodeCommand>,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Reindex Gitea repos into Sol's code search index.
|
||||||
|
#[command(name = "reindex-code")]
|
||||||
|
ReindexCode {
|
||||||
|
/// Filter to a specific org.
|
||||||
|
#[arg(long)]
|
||||||
|
org: Option<String>,
|
||||||
|
/// Index a specific repo (owner/name format).
|
||||||
|
#[arg(long)]
|
||||||
|
repo: Option<String>,
|
||||||
|
/// Index a specific branch (default: repo's default branch).
|
||||||
|
#[arg(long)]
|
||||||
|
branch: Option<String>,
|
||||||
|
/// Sol gRPC endpoint.
|
||||||
|
#[arg(long, default_value = "http://127.0.0.1:50051")]
|
||||||
|
endpoint: String,
|
||||||
|
},
|
||||||
|
|
||||||
/// Self-update from latest mainline commit.
|
/// Self-update from latest mainline commit.
|
||||||
Update,
|
Update,
|
||||||
|
|
||||||
@@ -1060,6 +1077,33 @@ pub async fn dispatch() -> Result<()> {
|
|||||||
},
|
},
|
||||||
|
|
||||||
Some(Verb::Code { action }) => crate::code::cmd_code(action).await,
|
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,
|
Some(Verb::Update) => sunbeam_sdk::update::cmd_update().await,
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,10 @@ impl CodeAgent for MockCodeAgent {
|
|||||||
|
|
||||||
Ok(Response::new(Box::pin(ReceiverStream::new(rx))))
|
Ok(Response::new(Box::pin(ReceiverStream::new(rx))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn reindex_code(&self, _req: Request<ReindexCodeRequest>) -> Result<Response<ReindexCodeResponse>, Status> {
|
||||||
|
Ok(Response::new(ReindexCodeResponse { repos_indexed: 0, symbols_indexed: 0, error: "mock".into() }))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
Reference in New Issue
Block a user