重构: 文档汇总+进度看板+孤儿任务清理脚本+gitignore 噪音排除
- docs/02 架构设计: 新增 aichat审查/异步审批构想/流式渲染调研/generating状态机/密钥迁移健壮性/工作流脚本执行边界/条件表达式引擎/F-07 trait下沉/Agent架构说明/任务推进构想/功能创意池;更新功能决策记录+归档/对抗论证/文档记录规范/经验记录
- docs/03 模块文档: 新增 AI对话引擎/DAG引擎详解;更新 df-knowledge/df-nodes/df-storage/df-workflow/df-ai
- docs/05 代码审查: 新增 全栈审查/全局review/架构审查/近期改动审查/工作区多角度走查/自研memo流式渲染审查
- docs/09 问题排查: 新增 aichat-apikey-401
- docs/INDEX+README 索引同步;docs/todo 待办看板(2026-06-15 汇总)
- PROGRESS.md Sprint 22-25;URGENT.md 加急清单快照(5 项 P0 已全修)
- scripts/cleanup_orphan_tasks.{py,sh} 孤儿任务清理工具
- .gitignore 补 *.broken.bak + tmp/ 噪音排除
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# df-ai — AI 集成模块
|
||||
|
||||
> 创建: 2026-06-10 | 最后更新: 2026-06-13
|
||||
> 创建: 2026-06-10 | 最后更新: 2026-06-14
|
||||
|
||||
---
|
||||
|
||||
@@ -86,6 +86,7 @@ pub trait LlmProvider: Send + Sync {
|
||||
| finish 判定 | 逐 chunk 判 `finish_reason`:`stop`/`tool_calls`/`length` 三者同等视为正常 finished(`length` = max_tokens 截断,属正常终止而非断连)|
|
||||
| embed | POST `/v1/embeddings`,响应按 index 排序返回 `Vec<Vec<f32>>` |
|
||||
| connect timeout | `connect_timeout(30s)`,不设总 timeout(避免误砍流式长任务)|
|
||||
| complete 单请求超时 | ✅ FR-R4(2026-06-14 commit 36d68dd):`complete()` 同步路径用 `RequestBuilder::timeout(Duration::from_secs(60))` 设 60s 单请求超时;**仅作用于 complete,不影响 stream 流式路径**(stream 仍靠上层 idle timeout 兜底)|
|
||||
|
||||
> 注:idle timeout(120s)与断连丢弃(finished_received)属上层 `stream_llm`(src-tauri/commands/ai.rs)的职责,不在本 Provider 层。
|
||||
|
||||
@@ -121,6 +122,17 @@ SSE 解析抽成 `pub(crate) fn apply_anthropic_event(data: &str, usage_accum: &
|
||||
|
||||
支持 GLM 订阅端点(`https://open.bigmodel.cn/api/anthropic`)。
|
||||
|
||||
### tool_use_id 兜底(AC1/AC2,2026-06-14 commit 36d68dd)
|
||||
|
||||
GLM 端对 `tool_use_id` 为 `None`/空串的 `tool_result` 块会返 500 卡死会话。两路兜底:
|
||||
|
||||
| 路径 | 入站/出站 | 兜底 |
|
||||
|------|----------|------|
|
||||
| 出站(请求构造)| tool_result 块 | `tool_call_id` 为 None/空时**跳过该块** + `tracing::warn!`(不发出无效块)|
|
||||
| 入站(SSE 流式)| tool_use 块 | 缺 id 时填占位 id `tool_missing_{idx}`(idx 为 content_block index)+ `tracing::warn!`;同步路径(complete)缺 id 时跳过 |
|
||||
|
||||
> 两者均 warn 留痕,不静默吞掉,便于事后排查 provider 返回异常 tool_use 的场景。
|
||||
|
||||
---
|
||||
|
||||
## ContextManager 分组滑动窗口(context.rs,Sprint 11)
|
||||
@@ -149,24 +161,36 @@ SSE 解析抽成 `pub(crate) fn apply_anthropic_event(data: &str, usage_accum: &
|
||||
| `build_for_request(sys_tokens) -> (Vec<ChatMessage>, bool)` | 返回裁剪后的消息列表 + 是否发生裁剪(用于 LLM 调用)|
|
||||
| `all_messages_clone()` | 返回全量消息(用于 save_conversation / 标题生成)|
|
||||
| `restore_from_messages(msgs)` | 切换对话时重建 ContextManager 缓存 |
|
||||
| `replace_tool_result_content(tool_call_id, new_content) -> bool` | 原子更新工具结果内容(审批通过/拒绝时回填),返回是否找到并替换 |
|
||||
| `replace_tool_result_content(tool_call_id, new_content) -> bool` | 原子更新工具结果内容(审批通过/拒绝时回填),返回是否找到并替换。✅ FR-D4(2026-06-14 commit 4a95f6a):由正向 `position` 遍历改为反向 `rposition`(审批替换命中最近一条同 id 工具结果;该调用属审批低频路径,不引入索引)|
|
||||
|
||||
---
|
||||
|
||||
## AI 工具注册
|
||||
|
||||
> 归属:`ai_tools.rs` 仅提供基础设施(`RiskLevel` / `AiTool` / `AiToolRegistry`);12 个工具的具体定义与注册在 `src-tauri/src/commands/ai.rs::build_ai_tool_registry`,handler 即唯一执行路径(schema+risk+实现同源)。
|
||||
> 归属:`ai_tools.rs` 仅提供基础设施(`RiskLevel` / `AiTool` / `AiToolRegistry`);工具的具体定义与注册在 `src-tauri/src/commands/ai/tool_registry.rs::build_ai_tool_registry`,handler 即唯一执行路径(schema+risk+实现同源)。
|
||||
|
||||
12 个内置工具,按风险分级:
|
||||
13 个内置工具,按风险分级:
|
||||
|
||||
| 风险 | 工具 |
|
||||
|------|------|
|
||||
| Low(自动执行)| list_projects / list_tasks / list_ideas / read_file / list_directory |
|
||||
| Medium(需审批)| update_project / create_project / create_task / create_idea / write_file |
|
||||
| High(需审批)| delete_project / run_workflow |
|
||||
| High(需审批)| delete_project / run_workflow / run_command |
|
||||
|
||||
工具执行结果写 `ai_tool_executions` 表(审计日志)。
|
||||
|
||||
### run_command(Sprint 21,方案 A「直接暴露 Shell」)
|
||||
|
||||
让 AI 形成「写(write_file)→跑(run_command)→看 stdout→改」闭环。handler 复用 `df_execute::shell::execute`(跨平台:Windows `cmd /C` / Unix `sh -c`,已封装 `tokio::time::timeout` + `kill_on_drop` 防僵尸进程)。
|
||||
|
||||
| 维度 | 设计 |
|
||||
|------|------|
|
||||
| 风险 | **High**——强制人工审批,审批卡显示 `command`+`working_dir`(复用 ToolCard `toolArgsEntries`,零前端改动) |
|
||||
| 参数 | `command`(必填) / `working_dir`(可选,默认 workspace_root) / `timeout_secs`(可选,默认 60) |
|
||||
| working_dir 校验 | 走 `validate_path` 黑名单(`..` + `.ssh`/`.aws`/`windows`/`system32` 等),**不走** `resolve_workspace_path` 越界校验——High risk 靠人审兜底,放开目录才能在用户任意项目跑命令 |
|
||||
| 输出截断 | stdout/stderr 各 10KB,尾部保留(报错堆栈在末尾),超出设 `truncated: true`(`truncate_output` 辅助函数,char 边界安全截) |
|
||||
| 安全边界 | A 方案=最高风险,唯一防线=人审+黑名单。未做命令黑名单(`rm -rf`/`format`)、网络外传检测、资源限制——属 B(ScriptNode)/C(Docker)/D(MCP) 方案领域 |
|
||||
|
||||
---
|
||||
|
||||
## 知识库集成(Sprint 15,逻辑在 src-tauri/commands/ai.rs)
|
||||
@@ -223,12 +247,12 @@ SSE 解析抽成 `pub(crate) fn apply_anthropic_event(data: &str, usage_accum: &
|
||||
| Conditions(条件分支)| 缺失(df-ai 无实现,条件求值属 df-workflow crate)| JSON Path / 比较 / and-or-not |
|
||||
| Reflection(自纠)| 缺失 | 执行后自检 / 重试 |
|
||||
|
||||
详见 [Phase 2 计划 - 决策能力升级](../07-项目管理/Phase2计划.md)。
|
||||
详见 [Phase 2 计划 - 决策能力升级](../07-项目管理/Phase2计划-2026-06-12.md)。
|
||||
|
||||
---
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [df-storage 存储层](./df-storage-存储层.md)
|
||||
- [df-workflow 工作流引擎](./df-workflow-工作流引擎.md)
|
||||
- [df-nodes 节点集合](./df-nodes-节点集合.md)
|
||||
- [df-storage 存储层](./df-storage-存储层-2026-06-12.md)
|
||||
- [df-workflow 工作流引擎](./df-workflow-工作流引擎-2026-06-12.md)
|
||||
- [df-nodes 节点集合](./df-nodes-节点集合-2026-06-12.md)
|
||||
|
||||
Reference in New Issue
Block a user