新增: AI Chat多项增强(审批去重/编辑重发/导出/实体引用/会话置顶搜索)+任务推进链df-nodes落地

This commit is contained in:
lxy
2026-06-16 12:41:13 +08:00
parent 212a927eee
commit 7d5cd4c89a
62 changed files with 4576 additions and 248 deletions
+22 -5
View File
@@ -51,8 +51,8 @@ fn env_info_line() -> String {
format!("当前日期: {today} | 运行环境: {os}\n\n")
}
/// 按语言返回系统提示词的 (固定前缀, 项目上下文标题)
fn system_prompt_parts(lang: &str) -> (&'static str, &'static str) {
/// 按语言返回系统提示词的 (固定前缀, 项目上下文标题, 任务上下文标题)
fn system_prompt_parts(lang: &str) -> (&'static str, &'static str, &'static str) {
match lang {
"en" => (
"You are DevFlow's AI assistant. You help users manage projects, tasks, ideas, and workflows.\n\
@@ -70,6 +70,7 @@ fn system_prompt_parts(lang: &str) -> (&'static str, &'static str) {
- Prefer using tools to complete actions rather than just describing steps\n\
- When a tool call fails, clearly tell the user it failed and why. Never disguise a fallback action as the original intent's success (e.g. don't write to description to fake a directory binding), and never falsely report success\n",
"\n## Current Projects\n",
"\n## Current Tasks\n",
),
_ => (
"你是 DevFlow 的 AI 助手。你帮助用户管理项目、任务、灵感和工作流。\n\
@@ -87,26 +88,42 @@ fn system_prompt_parts(lang: &str) -> (&'static str, &'static str) {
- 优先使用工具完成操作,而不是只描述步骤\n\
- 工具调用失败时必须明确告知用户失败原因,严禁用替代操作冒充原意图成功(如绑定目录失败不得改写描述冒充已绑定),也绝不谎报成功\n",
"\n## 当前项目\n",
"\n## 当前任务\n",
),
}
}
/// 构建系统提示词(环境信息 + 固定前缀 + 当前项目上下文)
/// 构建系统提示词(环境信息 + 固定前缀 + 当前项目/任务上下文)
///
/// UX-10 §1.4: 用户在输入框 @ 引用实体时插入 `[类型: 名]` 标记(项目/任务)。
/// 项目上下文已在下方注入,任务上下文本函数新增注入,使 LLM 能解析用户消息中的
/// `[项目: xxx]` / `[任务: xxx]` 标记并对齐到真实实体(名称+状态+描述)。
/// 注入克制:仅各取最近 20 条,防 context 膨胀。
pub(crate) async fn build_system_prompt(state: &AppState, lang: &str) -> String {
let (prefix, ctx_label) = system_prompt_parts(lang);
let (prefix, proj_label, task_label) = system_prompt_parts(lang);
let mut prompt = env_info_line();
prompt.push_str(prefix);
// 附加当前数据上下文
if let Ok(projects) = state.projects.list_active().await {
if !projects.is_empty() {
prompt.push_str(ctx_label);
prompt.push_str(proj_label);
// system prompt 前缀克制:仅最近 20 个项目,防 context 膨胀
for p in projects.iter().take(20) {
prompt.push_str(&format!("- {} ({}): {}\n", p.name, p.status, p.description));
}
}
}
// UX-10 §1.4: 任务上下文(供解析用户消息中 [任务: xxx] 标记)
// 仅最近 20 条未删除任务,按 created_at DESC(同 list_active 顺序)。
if let Ok(tasks) = state.tasks.list_active().await {
if !tasks.is_empty() {
prompt.push_str(task_label);
for tk in tasks.iter().take(20) {
prompt.push_str(&format!("- {} ({}): {}\n", tk.title, tk.status, tk.description));
}
}
}
prompt
}