Files
DevFlow/src-tauri/src/commands/ai/audit/utils.rs
绝尘 4dee706631 重构: audit第五批utils/diff收尾(strategy·audit拆分完成)
- 新建 audit/utils.rs(39行 risk_str/risk_from_str/truncate_chars) + audit/diff.rs(29行 build_write_file_diff)
- audit/mod.rs 416→379: mod utils/diff + re-export(pub(crate) use risk_str/risk_from_str) + 删原fn
audit拆分完成: reason/restore/finalize/cache/data_change/utils/diff七子模块, mod.rs余379(process_tool_calls主+DTO+list_tool_executions)
主代grep核验(不cargo--workspace避anthropic_compat.rs其他会话中间态df-ai E0599): mod.rs mod utils/diff印证; agent隔离自验cargo 0+test 98
git add指定(audit/*, 不含anthropic_compat.rs/docs其他会话改动)
2026-06-19 04:53:01 +08:00

40 lines
1.5 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! audit 共享纯 helperRiskLevel ↔ 字符串转换 + 字符串安全截断。
//!
//! 第五批从 audit/mod.rs 抽离,行为零变更:
//! - `risk_str` / `risk_from_str`finalize / restore 通过 `super::` 引用pub(crate))。
//! - `truncate_chars`:仅 mod.rs 的 list_tool_executions DTO 装配用pub(super))。
//!
//! re-export 维持原路径透明:`super::risk_str` / `super::risk_from_str` / `super::truncate_chars`
//! 在 audit/mod.rs 内通过 `use` 引入后裸名可用,外部子模块的 `super::risk_*` 引用不变。
use df_ai::ai_tools::RiskLevel;
/// RiskLevel → 审计记录字符串low/medium/high
pub(crate) fn risk_str(r: RiskLevel) -> &'static str {
match r {
RiskLevel::Low => "low",
RiskLevel::Medium => "medium",
RiskLevel::High => "high",
}
}
/// 审计记录字符串 → RiskLevel启动重建 pending_approvals 用,未知串返回 None 跳过)
pub(crate) fn risk_from_str(s: &str) -> Option<RiskLevel> {
match s {
"low" => Some(RiskLevel::Low),
"medium" => Some(RiskLevel::Medium),
"high" => Some(RiskLevel::High),
_ => None,
}
}
/// 截断字符串到 max 字符(按 char_indices 边界切,避免切坏中文/emoji)
pub(super) fn truncate_chars(s: &str, max: usize) -> String {
if s.chars().count() <= max {
return s.to_string();
}
let mut out: String = s.chars().take(max).collect();
out.push('…');
out
}