回退「工具回执进 message 前先按各自预算做有界序列化」

- 撤销 004889f27:给模型的工具结果不做任何截断,报告原文完整回给模型
- 撤销 tool/error.rs 的 bounded_report_text 及 browser_playtest / cocos_execute / environment_check / editor_execute 四处调用
- 截断与脱敏只保留在诊断/审计侧(persist_agent_runtime_error)
This commit is contained in:
2026-10-01 18:28:22 +08:00
parent 31fbadf260
commit 6af95b8a22
5 changed files with 8 additions and 38 deletions
@@ -2,7 +2,7 @@
//!
//! 这里只放错误本身;参数解析与工具执行留在 `direct_tool_bridge` 与 `direct_validation`。
use crate::agent::tool::error::{bounded_report_text, ToolFailure};
use crate::agent::tool::error::ToolFailure;
use serde_json::Value;
/// `agc_browser_playtest` 的每一种失败各占一个变体;文案写在这里,捕获处只调 `to_user_msg`。
@@ -25,12 +25,7 @@ impl ToolFailure for BrowserPlaytestError {
fn to_user_msg(&self) -> String {
match self {
Self::PlaytestFailed { cause } => cause.to_string(),
Self::PlaytestNotPassed { report, .. } => {
format!(
"浏览器试玩未通过:{}",
bounded_report_text(report, self.redact_limit())
)
}
Self::PlaytestNotPassed { report, .. } => format!("浏览器试玩未通过:{report}"),
}
}
@@ -2,9 +2,7 @@
//!
//! 这里只放错误本身;参数解析与工具执行留在 `direct_tool_bridge`。
use crate::agent::tool::error::{
bounded_report_text, ProjectPermissionRejection, ToolArgumentsRejection, ToolFailure,
};
use crate::agent::tool::error::{ProjectPermissionRejection, ToolArgumentsRejection, ToolFailure};
use serde_json::Value;
/// Cocos 执行工具的每一种失败各占一个变体;文案写在这里,捕获处只调 `to_user_msg`。
@@ -79,10 +77,7 @@ impl ToolFailure for CocosExecuteError {
.to_string()
}
Self::ExecutionNotCompleted { report, .. } => {
format!(
"Cocos 执行未完成:{}",
bounded_report_text(report, self.redact_limit())
)
format!("Cocos 执行未完成:{report}")
}
}
}
@@ -2,9 +2,7 @@
//!
//! 这里只放错误本身;参数解析与工具执行留在 `direct_tool_bridge`。
use crate::agent::tool::error::{
bounded_report_text, ProjectPermissionRejection, ToolArgumentsRejection, ToolFailure,
};
use crate::agent::tool::error::{ProjectPermissionRejection, ToolArgumentsRejection, ToolFailure};
use serde_json::Value;
/// `code` 的长度上限(字节):编辑器适配器按 UTF-8 字节数收代码。
@@ -108,11 +106,7 @@ impl ToolFailure for EditorExecuteError {
} => format!("code 有 {got_bytes} 字节,超过上限 {max_bytes} 字节。"),
Self::EditorRejected { cause } => cause.to_string(),
Self::ExecutionNotCompleted { editor, report } => {
format!(
"{} 执行未完成:{}",
editor.label(),
bounded_report_text(report, self.redact_limit())
)
format!("{} 执行未完成:{report}", editor.label())
}
Self::ExecutionUnconfirmed { editor } => format!(
"{} 执行任务异常,回执不可用;执行已发出,结果待核对,不要自动重放:\
@@ -2,9 +2,7 @@
//!
//! 这里只放错误本身;参数解析与工具执行留在 `direct_tool_bridge`。
use crate::agent::tool::error::{
bounded_report_text, ProjectPermissionRejection, ToolArgumentsRejection, ToolFailure,
};
use crate::agent::tool::error::{ProjectPermissionRejection, ToolArgumentsRejection, ToolFailure};
use serde_json::Value;
/// `agc_environment_check` 不接受任何参数,所以它自己的失败只有权限门禁与环境未就绪两类。
@@ -35,10 +33,7 @@ impl ToolFailure for EnvironmentCheckError {
match self {
Self::Arguments(rejection) => rejection.to_user_msg(),
Self::PermissionDenied(rejection) => rejection.to_user_msg(),
Self::EnvironmentNotReady { report } => format!(
"本地环境未就绪:{}",
bounded_report_text(report, self.redact_limit())
),
Self::EnvironmentNotReady { report } => format!("本地环境未就绪:{report}"),
}
}
@@ -17,15 +17,6 @@ pub(crate) fn bounded_echo(text: &str) -> String {
crate::agent::runtime_state::truncate_agent_runtime_text(text, BOUNDED_ECHO_MAX_CHARS)
}
/// 工具回执一类的 JSON 载荷落进 message 前的有界序列化。
///
/// [`ToolFailure::to_user_msg`] 的结果之后还要过整条脱敏流水线,最后才按
/// [`ToolFailure::redact_limit`] 截断;先按同一预算截一次,避免整份大载荷在多趟脱敏里
/// 被反复搬运。
pub(crate) fn bounded_report_text(value: &Value, max_chars: usize) -> String {
crate::agent::runtime_state::truncate_agent_runtime_text(&value.to_string(), max_chars)
}
/// `sourceLocalAssetId` 不在当前项目 manifest 时的完整指引:模型要知道下一步做什么,
/// 只报「不属于已登记资源」会让它原地重试。
///