misc: initial code

This commit is contained in:
hdbg
2026-02-27 10:27:24 +01:00
commit 91036f4188
32 changed files with 36435 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
[package]
name = "codetaker-cli"
version = "0.1.0"
edition = "2024"
[dependencies]
clap.workspace = true
codetaker-agent = { path = "../codetaker-agent" }
codetaker-db.workspace = true
git2.workspace = true
rig-core.workspace = true
serde_json.workspace = true
tokio.workspace = true
tracing-subscriber = "0.3.22"

View File

@@ -0,0 +1,74 @@
use std::path::PathBuf;
use clap::Parser;
use codetaker_agent::{
AstGrepTool, DieselMemoryStore, Forge, ProjectRef, PullRequestReviewAgent,
PullRequestReviewInput,
};
use git2::Repository;
use rig::providers::anthropic;
#[derive(Debug, Parser)]
#[command(name = "codetaker-cli")]
#[command(about = "Run codetaker pull request review agent against a local repository")]
struct Cli {
#[arg(long, env = "ANTHROPIC_API_KEY")]
anthropic_api_key: String,
#[arg(
long,
env = "ANTHROPIC_MODEL",
default_value = anthropic::completion::CLAUDE_3_5_SONNET
)]
model: String,
#[arg(long)]
repo_path: PathBuf,
#[arg(long)]
base_ref: String,
#[arg(long)]
head_ref: String,
#[arg(long, default_value = "local")]
owner: String,
#[arg(long)]
repo: Option<String>,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cli = Cli::parse();
let repo_name = cli.repo.unwrap_or_else(|| {
cli.repo_path
.file_name()
.and_then(|name| name.to_str())
.map(|name| name.trim_end_matches(".git").to_owned())
.unwrap_or_else(|| "repo".to_owned())
});
let repo = Repository::open(&cli.repo_path)?;
let pool = codetaker_db::create_pool(None).await?;
let memory = DieselMemoryStore::new(pool);
let client: anthropic::Client = anthropic::Client::new(&cli.anthropic_api_key)?;
let agent = PullRequestReviewAgent::new(client, cli.model, AstGrepTool::default(), memory);
let input = PullRequestReviewInput {
project: ProjectRef {
forge: Forge::Gitea,
owner: cli.owner,
repo: repo_name,
},
base_ref: cli.base_ref,
head_ref: cli.head_ref,
};
let result = agent.pull_request_review(&repo, input).await?;
println!("{}", serde_json::to_string_pretty(&result)?);
Ok(())
}