阶段1拆解: stream 系外移 stream_relay.rs,mod.rs 3048→2607,loop_body 502→83 技能收尾: regenerate/edit 回溯补技能,新增 read_skill 工具,项目级技能扫描 DRY: emit 双写 46 处收敛 event_bus 正典,KV 引号归一收口,LOCK-SLOW 33 处单行化 警示骨架 4→1 与压缩兜底 2→1,噪音目录档位收敛,truncate 同名陷阱消除 工具元数据落 ToolMeta 八维,7 张 match 表改查 registry,parity 测试锁等价 命名: is_noise_entry/teardown_round/probe_missed_terminal_event 等 6 项纠偏
36 lines
1.8 KiB
Rust
36 lines
1.8 KiB
Rust
//! AR-11(方案A):数据变更联动刷新。
|
||
//!
|
||
//! 工具执行成功后按映射 emit "df-data-changed" { entity, action },
|
||
//! 前端 store listen 该事件按 entity 调 loadProjects/loadTasks/loadIdeas 刷新列表,
|
||
//! 取代工具执行后需手动刷新。
|
||
//!
|
||
//! 第四批从 audit/mod.rs 抽离,行为零变更。
|
||
|
||
use tauri::{AppHandle, Emitter};
|
||
|
||
/// AR-11(方案A):工具名 → (entity, action) 映射,用于数据变更联动刷新。
|
||
///
|
||
/// 仅数据变更类工具返回 Some,其余工具返回 None(不 emit df-data-changed)。
|
||
/// 映射查注册元数据(entity_action 维度,DRY 债 #5 收敛),在 declare_tool! 注册点声明:
|
||
/// create_*(project/idea/task, create)、update_*(..., update)、delete_*/purge_project
|
||
/// (..., delete)、restore_project/bind_directory → (project, update)、advance_task →
|
||
/// (task, update)(状态推进对齐 update_task)、write_file/patch_file → (file, update)。
|
||
pub(super) fn data_change_for_tool(name: &str) -> Option<(&'static str, &'static str)> {
|
||
crate::commands::ai::tool_registry::ensure_tool_meta_seeded();
|
||
df_ai::ai_tools::entity_action(name)
|
||
}
|
||
|
||
/// AR-11(方案A):工具执行成功后按映射 emit "df-data-changed" { entity, action }。
|
||
///
|
||
/// 前端 store listen 该事件,按 entity 调 loadProjects/loadTasks/loadIdeas 刷新列表,
|
||
/// 取代工具执行后需手动刷新。仅工具名命中 data_change_for_tool 映射才 emit,
|
||
/// 其余工具(run_workflow/list_tasks 等)不 emit。emit 失败不阻断(let _ =)。
|
||
pub(crate) fn emit_data_changed(app_handle: &AppHandle, tool_name: &str) {
|
||
if let Some((entity, action)) = data_change_for_tool(tool_name) {
|
||
let _ = app_handle.emit(
|
||
"df-data-changed",
|
||
serde_json::json!({ "entity": entity, "action": action }),
|
||
);
|
||
}
|
||
}
|