try to use local ai to generate commit message
This commit is contained in:
@@ -479,6 +479,37 @@ pub fn get_file_patch(path: String, file: String, staged: bool) -> Result<String
|
||||
Ok(String::from_utf8_lossy(&output).to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn commit_ai_status(
|
||||
engine: tauri::State<'_, commit_ai::CommitAiEngine>,
|
||||
) -> Result<commit_ai::CommitAiStatus, String> {
|
||||
Ok(engine.status().await)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn commit_ai_generate(
|
||||
path: String,
|
||||
notes: Option<String>,
|
||||
engine: tauri::State<'_, commit_ai::CommitAiEngine>,
|
||||
) -> Result<String, String> {
|
||||
let repo = resolve_repo(&path)?;
|
||||
let diff = run_git(
|
||||
&repo,
|
||||
[
|
||||
"diff",
|
||||
"--cached",
|
||||
"--no-ext-diff",
|
||||
"--no-textconv",
|
||||
"--unified=3",
|
||||
],
|
||||
)?;
|
||||
let diff = String::from_utf8_lossy(&diff).to_string();
|
||||
|
||||
engine
|
||||
.generate_commit_message(&diff, notes.as_deref())
|
||||
.await
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn apply_file_patch(
|
||||
path: String,
|
||||
@@ -1573,6 +1604,7 @@ fn status_for_repo(repo: &Path) -> Result<GitStatus, String> {
|
||||
let (branch, mut files) = parse_status_output(&output)?;
|
||||
detect_worktree_renames(repo, &mut files);
|
||||
|
||||
|
||||
Ok(GitStatus {
|
||||
repo_path: repo.to_string_lossy().to_string(),
|
||||
current_branch: branch.current_branch,
|
||||
|
||||
+21
-7
@@ -4,21 +4,33 @@ mod git;
|
||||
|
||||
use git::{
|
||||
apply_file_patch, cancel_code_search, cancel_file_history, checkout_branch, commit,
|
||||
compare_commits, compare_file_to_head, compare_file_to_parent, create_branch, cred_delete,
|
||||
cred_load, cred_save, delete_branch, diff_file_against_working_tree, get_file_patch,
|
||||
get_remote_url, get_status, list_branches, list_commits, list_file_history,
|
||||
list_repository_files, merge_branch, open_repo_in_explorer, open_repository,
|
||||
open_repository_bundle, open_repository_file, pull, push, read_conflict, rename_branch,
|
||||
resolve_conflict, resolve_conflict_side, restore_file_from_commit, restore_files,
|
||||
restore_to_commit, search_code_introductions, stage_files, unstage_files,
|
||||
commit_ai_generate, commit_ai_status, compare_commits, compare_file_to_head,
|
||||
compare_file_to_parent, create_branch, cred_delete, cred_load, cred_save, delete_branch,
|
||||
diff_file_against_working_tree, get_file_patch, get_remote_url, get_status, list_branches,
|
||||
list_commits, list_file_history, list_repository_files, merge_branch, open_repo_in_explorer,
|
||||
open_repository, open_repository_bundle, open_repository_file, pull, push, read_conflict,
|
||||
rename_branch, resolve_conflict, resolve_conflict_side, restore_file_from_commit,
|
||||
restore_files, restore_to_commit, search_code_introductions, stage_files, unstage_files,
|
||||
SearchCancellationState,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let commit_ai_engine = commit_ai::CommitAiEngine::new();
|
||||
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_updater::Builder::new().build())
|
||||
.manage(SearchCancellationState::default())
|
||||
.manage(commit_ai_engine.clone())
|
||||
.plugin(tauri_plugin_dialog::init())
|
||||
.setup(move |_app| {
|
||||
// Kick off the (first-run-only) download and model load in the background so the
|
||||
// "Generate with AI" button becomes enabled once it's ready, without blocking startup.
|
||||
let engine = commit_ai_engine.clone();
|
||||
tauri::async_runtime::spawn(async move {
|
||||
engine.ensure_loaded().await;
|
||||
});
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
open_repository,
|
||||
open_repo_in_explorer,
|
||||
@@ -35,6 +47,8 @@ fn main() {
|
||||
get_file_patch,
|
||||
apply_file_patch,
|
||||
commit,
|
||||
commit_ai_status,
|
||||
commit_ai_generate,
|
||||
pull,
|
||||
push,
|
||||
list_commits,
|
||||
|
||||
Reference in New Issue
Block a user