🔄 Update script metadata and enhance git commit logic with AI summarization

解释:
1. 🔄 表示更新/修改类型的变化
2. 核心变更包括:
   - 更新了 script-meta-v2.json 和 script-meta.json 中的脚本元数据(长度、哈希值、更新时间等)
   - 修改了 sync-rs/src/main.rs 的文件权限(从 644 改为 755)
   - 增强了 git commit 逻辑,加入了 AI 自动生成提交信息的功能
3. 总结突出了变更的核心内容,即元数据更新和提交逻辑的改进
This commit is contained in:
2026-04-05 00:04:41 +08:00
parent 263ea4d213
commit 2cd8cf7150
3 changed files with 38 additions and 12 deletions

40
sync-rs/src/main.rs Normal file → Executable file
View File

@@ -9,7 +9,7 @@ use std::env;
use std::path::PathBuf;
use std::process::Command;
use rust_util::{failure_and_exit, information, success, warning};
use rust_util::{failure, failure_and_exit, information, success, warning};
fn main() -> Result<(), Box<dyn std::error::Error>> {
if let Some(args_1) = env::args().nth(1) {
@@ -27,7 +27,29 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
information!("Git Add All");
Command::new("git").args(&["add", "."]).spawn()?.wait()?;
information!("Git Commit All");
Command::new("git").args(&["commit", "-a", "-m", "'auto sync'"]).spawn()?.wait()?;
information!("AI summarizing...");
let ai_summarize_output = Command::new("sh")
.args(&["-c", r##"xh --ignore-stdin https://hatter.ink/ai/commit-summarize.json -f "Authorization:Bearer $(get-secret.ts --id ai-commit-summarize-token)" gitStatus="$(git status)" gitDiff="$(git diff)" | jq .data.summary -r"##])
.output()?;
let mut message = "auto sync".to_string();
information!("{:?}", ai_summarize_output);
if ai_summarize_output.status.success() {
if let Ok(summarized_message) = String::from_utf8(ai_summarize_output.stdout) {
success!("AI summarized message: {}", summarized_message);
message = summarized_message;
} else {
warning!("AI summarized message is not UTF-8");
}
} else {
failure!(
"AI summarize failed, status: {}",
ai_summarize_output.status
);
}
Command::new("git")
.args(&["commit", "-a", "-m", &message])
.spawn()?
.wait()?;
information!("Git Push");
Command::new("git").args(&["push"]).spawn()?.wait()?;
information!("Sync Server Repo");
@@ -52,11 +74,15 @@ pub fn find_parents_exists_dir(dir: &str) -> Option<PathBuf> {
match PathBuf::from(".").canonicalize() {
Err(_) => None,
Ok(mut path) => loop {
if path.join(dir).is_dir() { return Some(path); }
if !path.pop() { return None; }
}
if path.join(dir).is_dir() {
return Some(path);
}
if !path.pop() {
return None;
}
},
}
}
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250620T220543+08:00.MEUCIHsFQ1sf53x3ATTLFkMQ
// oUau9y550grtnm7yGglEoDI/AiEAgZcouLIJXHP042IFnhkTljMo67O9Cs6MlpvNT+BzOA8=
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20260405T000314+08:00.MEYCIQCOflkXKihoc6wfiGml
// TObfzEuzkqKg3yEfU+swKk7aJgIhALHUGopxnHNXjSoWziiQt9U1xb8qGpamrsHdd20nrTjx