修复: spawn panic 兜底 + namespace 淘汰提示 + run_command 超时与破坏命令信任门控

This commit is contained in:
lxy
2026-08-01 11:10:28 +08:00
parent 468950616b
commit c4ba920cf5
7 changed files with 145 additions and 11 deletions
+17 -1
View File
@@ -19,7 +19,7 @@ use super::cache::{find_cached_high_risk_result, pending_placeholder_for};
use super::diff::build_write_file_diff;
use super::reason::build_approval_reason;
use super::record::audit_tool_call;
use super::super::{AiChatEvent, AiSession, ApprovalKind, PendingApproval, ToolCallDraft, trust_key_for, TrustKey};
use super::super::{AiChatEvent, AiSession, ApprovalKind, PendingApproval, ToolCallDraft, is_destructive_command, trust_key_for, TrustKey};
/// 按 risk_level + auto_exec_mode 判定是否自动执行。
///
@@ -102,6 +102,22 @@ pub(super) async fn check_trust_hits(
conv_id: &str,
) -> Option<TrustKey> {
let key = trust_key_for(&draft.name, args)?;
// 安全门控(run_command 会话信任按目录不按命令的补丁):
// run_command 的信任 key 只用 working_dir,一次批准 → 同目录任意命令 auto。
// 破坏性命令(rm/del/format/... 不可逆)绝不 auto 放行,即使同目录已批准过,
// 也必须每轮走正常审批。命中黑名单直接返 None,让流程继续走 pending 审批。
if matches!(key, TrustKey::Execute { .. }) {
if let Some(cmd) = args.get("command").and_then(|v| v.as_str()) {
if is_destructive_command(cmd) {
tracing::info!(
tool = %draft.name,
new_tool_call_id = %draft.id,
"[会话信任] 命中破坏性命令黑名单,跳过 auto 放行(走正常审批)"
);
return None;
}
}
}
// 短 lock 读 session_trust(仅 contains 判定,无 await,纳秒级),命中即返 key
let hit = {
let session = session_arc.lock().await;