修复策划工具乱序局部修改导致的中断 #399
@@ -380,11 +380,16 @@ pub(crate) fn execute_design_file_tool(
|
||||
}
|
||||
return Err(details.join("\n"));
|
||||
}
|
||||
let mut updated = content.clone();
|
||||
for (index, start, end) in matches.into_iter().rev() {
|
||||
matches.sort_unstable_by_key(|(_, start, _)| *start);
|
||||
let mut updated = String::with_capacity(content.len());
|
||||
let mut cursor = 0;
|
||||
for (index, start, end) in matches {
|
||||
let (_, new) = &normalized[index];
|
||||
updated.replace_range(start..end, new);
|
||||
updated.push_str(&content[cursor..start]);
|
||||
updated.push_str(new);
|
||||
cursor = end;
|
||||
}
|
||||
updated.push_str(&content[cursor..]);
|
||||
if updated == content {
|
||||
return Err(format!("没有产生修改:{display}"));
|
||||
}
|
||||
@@ -834,6 +839,35 @@ mod tests {
|
||||
assert!(!root.join("design_artifacts/notes").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn patch_file_applies_out_of_order_edits_with_changing_utf8_lengths() {
|
||||
let temp = test_root();
|
||||
let root = temp.path();
|
||||
execute_design_file_tool(
|
||||
root,
|
||||
"write_file",
|
||||
&json!({"path":"notes/design.md","content":"开头\n甲\n保留一\n乙乙\n保留二\n丙\n结尾"}),
|
||||
)
|
||||
.expect("write");
|
||||
execute_design_file_tool(
|
||||
root,
|
||||
"patch_file",
|
||||
&json!({
|
||||
"path":"notes/design.md",
|
||||
"edits":[
|
||||
{"old_text":"丙","new_text":"新的结论"},
|
||||
{"old_text":"甲","new_text":"扩展A"},
|
||||
{"old_text":"乙乙","new_text":"乙"}
|
||||
]
|
||||
}),
|
||||
)
|
||||
.expect("patch out of order");
|
||||
assert_eq!(
|
||||
fs::read_to_string(root.join("design_artifacts/notes/design.md")).expect("read disk"),
|
||||
"开头\n扩展A\n保留一\n乙\n保留二\n新的结论\n结尾"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn phase_context_injects_current_skill_only() {
|
||||
let resources = DesignResources::new(pack_root()).expect("pack");
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
# AI 游戏创作智能体 App 实施计划
|
||||
|
||||
## 策划 Agent 批量局部修改
|
||||
|
||||
`patch_file` 的所有 edits 均匹配同一份原文件,参数顺序不影响结果。完成唯一匹配与不重叠校验后,按原文起点升序拼接未修改片段与替换文本,最后一次性写入;任一校验失败时不写文件。回归用例覆盖乱序 edits、中文内容与替换长度增减,并核对完整落盘内容。此行为仅属于策划 Agent 文件工具。
|
||||
|
||||
## 资源画布交互与工作台状态同步
|
||||
|
||||
- 工作台向窗口标题栏发布正在运行的项目时,输入未变化不得形成重复发布与清理的渲染循环;打开项目动作始终使用当前工作台处理逻辑,退出工作台后清除其标题栏状态。
|
||||
|
||||
Reference in New Issue
Block a user