From 713cbb7cc37c1a19d923a3d61323e9b5d3eb89ee Mon Sep 17 00:00:00 2001 From: wunianxiao Date: Tue, 9 Jun 2026 22:10:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20daemon=20=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E4=B8=AD=203=20=E4=B8=AA=20blocking=20=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E6=80=A7=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. call_capability 元工具不可用 - execute_tool() 中缺失 call_capability 处理分支 - 添加解包 {name, prompt} → 提取目标工具并派发的逻辑 2. tool_call_id 传空字符串 - Tool Consumer 中 tool_call_id 被 _ 忽略,ToolResult 传空串 - 改为使用 LLM 原始 tool_call_id 传递 3. 高风险工具审批无限循环 - Tool Consumer 无条件触发审批,approved_tool 从未被读取 - ToolCall 新增 approved 字段,已批准的工具跳过审批 - ToolExecutor 根据 approved_tool 设置标记 4. Session TTL 时间戳不更新(should-fix) - ToolResult 回喂时更新 last_access,防止长对话被误清理 5. 其他清理 - load_memories 魔数字符串比较改为 starts_with - _sock_path 添加文档说明保留用于兼容 - MessageKind::ToolCall 新增 approved: bool 字段 --- .codegraph/.gitignore | 16 ++++ .codegraph/daemon.pid | 6 ++ .../1780898113368-ca6859df-web_fetch.txt | 5 ++ src/daemon.rs | 78 ++++++++++++++++--- src/queue/message_queue.rs | 27 +++++++ 5 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 .codegraph/.gitignore create mode 100644 .codegraph/daemon.pid create mode 100644 .reasonix/truncated-results/1780898113368-ca6859df-web_fetch.txt diff --git a/.codegraph/.gitignore b/.codegraph/.gitignore new file mode 100644 index 0000000..9de0f16 --- /dev/null +++ b/.codegraph/.gitignore @@ -0,0 +1,16 @@ +# CodeGraph data files +# These are local to each machine and should not be committed + +# Database +*.db +*.db-wal +*.db-shm + +# Cache +cache/ + +# Logs +*.log + +# Hook markers +.dirty diff --git a/.codegraph/daemon.pid b/.codegraph/daemon.pid new file mode 100644 index 0000000..a127410 --- /dev/null +++ b/.codegraph/daemon.pid @@ -0,0 +1,6 @@ +{ + "pid": 2145387, + "version": "0.9.9", + "socketPath": "/home/xiao/project/iAs/.codegraph/daemon.sock", + "startedAt": 1781008946109 +} diff --git a/.reasonix/truncated-results/1780898113368-ca6859df-web_fetch.txt b/.reasonix/truncated-results/1780898113368-ca6859df-web_fetch.txt new file mode 100644 index 0000000..7717513 --- /dev/null +++ b/.reasonix/truncated-results/1780898113368-ca6859df-web_fetch.txt @@ -0,0 +1,5 @@ +https://crates.io/api/v1/crates/chromiumoxide + +{"crate":{"id":"chromiumoxide","name":"chromiumoxide","updated_at":"2026-02-25T20:05:25.981693Z","versions":[2064069,2047824,1848727,1232393,1157861,998945,948233,947222,914632,910557,853413,740084,653076,523252,469337,462380,402950,397267,349760,314614],"keywords":["automation","chrome","chromedriver","puppeteer"],"categories":["api-bindings","development-tools::testing","web-programming"],"badges":[],"created_at":"2020-12-13T20:19:51.325813Z","downloads":2064744,"recent_downloads":723367,"default_version":"0.9.1","num_versions":20,"yanked":false,"max_version":"0.9.1","newest_version":"0.9.1","max_stable_version":"0.9.1","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","links":{"version_downloads":"/api/v1/crates/chromiumoxide/downloads","versions":null,"owners":"/api/v1/crates/chromiumoxide/owners","owner_team":"/api/v1/crates/chromiumoxide/owner_team","owner_user":"/api/v1/crates/chromiumoxide/owner_user","reverse_dependencies":"/api/v1/crates/chromiumoxide/reverse_dependencies"},"exact_match":false,"trustpub_only":true},"versions":[{"id":2064069,"crate":"chromiumoxide","num":"0.9.1","dl_path":"/api/v1/crates/chromiumoxide/0.9.1/download","readme_path":"/api/v1/crates/chromiumoxide/0.9.1/readme","updated_at":"2026-02-25T20:05:25.981693Z","created_at":"2026-02-25T20:05:25.981693Z","downloads":257294,"features":{"bytes":["dep:bytes"],"default":["bytes"],"fetcher":["chromiumoxide_fetcher"],"native-tls":["chromiumoxide_fetcher/native-tls"],"rustls":["chromiumoxide_fetcher/rustls"],"zip0":["chromiumoxide_fetcher/zip0"],"zip8":["chromiumoxide_fetcher/zip8"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.9.1/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.9.1/downloads","authors":"/api/v1/crates/chromiumoxide/0.9.1/authors"},"crate_size":102338,"published_by":null,"audit_actions":[],"checksum":"26ed067eb6c1f660bdb87c05efb964421d2ca262bae0296cdfe38cf0cd949a3e","rust_version":"1.85","has_lib":true,"bin_names":[],"edition":"2024","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":{"provider":"github","repository":"mattsse/chromiumoxide","run_id":"22413759904","sha":"a7e2bb835b9643410f9e3dc044f0d947e96cbfa4"},"linecounts":{"languages":{"Rust":{"code_lines":7741,"comment_lines":113,"files":32}},"total_code_lines":7741,"total_comment_lines":113}},{"id":2047824,"crate":"chromiumoxide","num":"0.9.0","dl_path":"/api/v1/crates/chromiumoxide/0.9.0/download","readme_path":"/api/v1/crates/chromiumoxide/0.9.0/readme","updated_at":"2026-02-20T22:11:00.638789Z","created_at":"2026-02-20T22:11:00.638789Z","downloads":4691,"features":{"bytes":["dep:bytes"],"default":["bytes"],"fetcher":["chromiumoxide_fetcher"],"native-tls":["chromiumoxide_fetcher/native-tls"],"rustls":["chromiumoxide_fetcher/rustls"],"zip0":["chromiumoxide_fetcher/zip0"],"zip8":["chromiumoxide_fetcher/zip8"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.9.0/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.9.0/downloads","authors":"/api/v1/crates/chromiumoxide/0.9.0/authors"},"crate_size":102314,"published_by":null,"audit_actions":[],"checksum":"dba63f489631c074314186b74fd095f0c3a3f4d0d587a4d8f64e789cfc52c10b","rust_version":"1.85","has_lib":true,"bin_names":[],"edition":"2024","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":{"provider":"github","repository":"mattsse/chromiumoxide","run_id":"22243127254","sha":"656ab82c27cb998164d1a28a94798df4dbcc4e8c"},"linecounts":{"languages":{"Rust":{"code_lines":7741,"comment_lines":113,"files":32}},"total_code_lines":7741,"total_comment_lines":113}},{"id":1848727,"crate":"chromiumoxide","num":"0.8.0","dl_path":"/api/v1/crates/chromiumoxide/0.8.0/download","readme_path":"/api/v1/crates/chromiumoxide/0.8.0/readme","updated_at":"2025-11-28T19:22:57.657659Z","created_at":"2025-11-28T19:22:57.657659Z","downloads":690093,"features":{"_fetcher-native-async-std":["fetcher","chromiumoxide_fetcher/_native-async-std"],"_fetcher-native-tokio":["fetcher","chromiumoxide_fetcher/_native-tokio"],"_fetcher-rustls-async-std":["fetcher","chromiumoxide_fetcher/_rustls-async-std"],"_fetcher-rustls-tokio":["fetcher","chromiumoxide_fetcher/_rustls-tokio"],"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"bytes":["dep:bytes"],"default":["tokio-runtime","bytes"],"fetcher":[],"serde0":[],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.8.0/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.8.0/downloads","authors":"/api/v1/crates/chromiumoxide/0.8.0/authors"},"crate_size":103725,"published_by":null,"audit_actions":[],"checksum":"6c18200611490f523adb497ddd4744d6d536e243f6add13e7eeeb1c05904fbb1","rust_version":"1.85","has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":{"provider":"github","repository":"mattsse/chromiumoxide","run_id":"19772287296","sha":"26ad972e927ed4b78926b123aa4aa1f68b1dcd80"},"linecounts":{"languages":{"Rust":{"code_lines":7581,"comment_lines":113,"files":30}},"total_code_lines":7581,"total_comment_lines":113}},{"id":1232393,"crate":"chromiumoxide","num":"0.7.0","dl_path":"/api/v1/crates/chromiumoxide/0.7.0/download","readme_path":"/api/v1/crates/chromiumoxide/0.7.0/readme","updated_at":"2024-08-12T14:40:53.844678Z","created_at":"2024-08-12T14:40:53.844678Z","downloads":572348,"features":{"_fetcher-native-async-std":["fetcher","chromiumoxide_fetcher/_native-async-std"],"_fetcher-native-tokio":["fetcher","chromiumoxide_fetcher/_native-tokio"],"_fetcher-rustls-async-std":["fetcher","chromiumoxide_fetcher/_rustls-async-std"],"_fetcher-rusttls-tokio":["fetcher","chromiumoxide_fetcher/_rustls-tokio"],"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"bytes":["dep:bytes"],"default":["async-std-runtime","bytes"],"fetcher":[],"serde0":[],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.7.0/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.7.0/downloads","authors":"/api/v1/crates/chromiumoxide/0.7.0/authors"},"crate_size":96048,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2024-08-12T14:40:53.844678Z"}],"checksum":"8380ce7721cc895fe8a184c49d615fe755b0c9a3d7986355cee847439fff907f","rust_version":"1.70","has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":7530,"comment_lines":109,"files":30}},"total_code_lines":7530,"total_comment_lines":109}},{"id":1157861,"crate":"chromiumoxide","num":"0.6.0","dl_path":"/api/v1/crates/chromiumoxide/0.6.0/download","readme_path":"/api/v1/crates/chromiumoxide/0.6.0/readme","updated_at":"2024-05-28T14:42:55.549879Z","created_at":"2024-05-28T14:42:55.549879Z","downloads":31504,"features":{"_fetcher-native-async-std":["fetcher","chromiumoxide_fetcher/_native-async-std"],"_fetcher-native-tokio":["fetcher","chromiumoxide_fetcher/_native-tokio"],"_fetcher-rustls-async-std":["fetcher","chromiumoxide_fetcher/_rustls-async-std"],"_fetcher-rusttls-tokio":["fetcher","chromiumoxide_fetcher/_rustls-tokio"],"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"bytes":["dep:bytes"],"default":["async-std-runtime","bytes"],"fetcher":[],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.6.0/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.6.0/downloads","authors":"/api/v1/crates/chromiumoxide/0.6.0/authors"},"crate_size":94605,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2024-05-28T14:42:55.549879Z"}],"checksum":"601bde44842e2875fff5cbf7229a2e9d690b0788cb7b3caa21533b93e6e1bd56","rust_version":"1.70","has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":7452,"comment_lines":108,"files":30}},"total_code_lines":7452,"total_comment_lines":108}},{"id":998945,"crate":"chromiumoxide","num":"0.5.7","dl_path":"/api/v1/crates/chromiumoxide/0.5.7/download","readme_path":"/api/v1/crates/chromiumoxide/0.5.7/readme","updated_at":"2023-12-29T12:54:42.856493Z","created_at":"2023-12-29T12:54:42.856493Z","downloads":92148,"features":{"_fetcher-native-async-std":["fetcher","chromiumoxide_fetcher/_native-async-std"],"_fetcher-native-tokio":["fetcher","chromiumoxide_fetcher/_native-tokio"],"_fetcher-rustls-async-std":["fetcher","chromiumoxide_fetcher/_rustls-async-std"],"_fetcher-rusttls-tokio":["fetcher","chromiumoxide_fetcher/_rustls-tokio"],"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"bytes":["dep:bytes"],"default":["async-std-runtime","bytes"],"fetcher":[],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.5.7/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.5.7/downloads","authors":"/api/v1/crates/chromiumoxide/0.5.7/authors"},"crate_size":93711,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2023-12-29T12:54:42.856493Z"}],"checksum":"b2abb1e644b7fcaa711fe4d3fca06c52bf18ebc5398711b2b11e8281c6107fbe","rust_version":"1.70","has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":7409,"comment_lines":107,"files":30}},"total_code_lines":7409,"total_comment_lines":107}},{"id":948233,"crate":"chromiumoxide","num":"0.5.6","dl_path":"/api/v1/crates/chromiumoxide/0.5.6/download","readme_path":"/api/v1/crates/chromiumoxide/0.5.6/readme","updated_at":"2023-11-07T12:29:53.311448Z","created_at":"2023-11-07T12:29:53.311448Z","downloads":5882,"features":{"_fetcher-native-async-std":["fetcher","chromiumoxide_fetcher/_native-async-std"],"_fetcher-native-tokio":["fetcher","chromiumoxide_fetcher/_native-tokio"],"_fetcher-rustls-async-std":["fetcher","chromiumoxide_fetcher/_rustls-async-std"],"_fetcher-rusttls-tokio":["fetcher","chromiumoxide_fetcher/_rustls-tokio"],"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"bytes":["dep:bytes"],"default":["async-std-runtime","bytes"],"fetcher":[],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.5.6/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.5.6/downloads","authors":"/api/v1/crates/chromiumoxide/0.5.6/authors"},"crate_size":93640,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2023-11-07T12:29:53.311448Z"}],"checksum":"cdea2fa69adb96b3f503c4ae5a9b0ab17ae9b92a0f0702710485b12cc7758ff8","rust_version":"1.70","has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":7398,"comment_lines":107,"files":30}},"total_code_lines":7398,"total_comment_lines":107}},{"id":947222,"crate":"chromiumoxide","num":"0.5.5","dl_path":"/api/v1/crates/chromiumoxide/0.5.5/download","readme_path":"/api/v1/crates/chromiumoxide/0.5.5/readme","updated_at":"2023-11-06T14:21:12.160329Z","created_at":"2023-11-06T14:21:12.160329Z","downloads":1437,"features":{"_fetcher-native-async-std":["fetcher","chromiumoxide_fetcher/_native-async-std"],"_fetcher-native-tokio":["fetcher","chromiumoxide_fetcher/_native-tokio"],"_fetcher-rustls-async-std":["fetcher","chromiumoxide_fetcher/_rustls-async-std"],"_fetcher-rusttls-tokio":["fetcher","chromiumoxide_fetcher/_rustls-tokio"],"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"bytes":["dep:bytes"],"default":["async-std-runtime","bytes"],"fetcher":[],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.5.5/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.5.5/downloads","authors":"/api/v1/crates/chromiumoxide/0.5.5/authors"},"crate_size":94018,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2023-11-06T14:21:12.160329Z"}],"checksum":"8ac493b71ee1cad2e4e8f81f220b2eb8623b3505a3d606ab9338aa6e480e079a","rust_version":"1.70","has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":7398,"comment_lines":107,"files":30}},"total_code_lines":7398,"total_comment_lines":107}},{"id":914632,"crate":"chromiumoxide","num":"0.5.4","dl_path":"/api/v1/crates/chromiumoxide/0.5.4/download","readme_path":"/api/v1/crates/chromiumoxide/0.5.4/readme","updated_at":"2023-10-03T23:16:29.049590Z","created_at":"2023-10-03T23:16:29.049590Z","downloads":124002,"features":{"_fetcher-native-async-std":["fetcher","chromiumoxide_fetcher/_native-async-std"],"_fetcher-native-tokio":["fetcher","chromiumoxide_fetcher/_native-tokio"],"_fetcher-rustls-async-std":["fetcher","chromiumoxide_fetcher/_rustls-async-std"],"_fetcher-rusttls-tokio":["fetcher","chromiumoxide_fetcher/_rustls-tokio"],"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"default":["async-std-runtime"],"fetcher":[],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.5.4/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.5.4/downloads","authors":"/api/v1/crates/chromiumoxide/0.5.4/authors"},"crate_size":91492,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2023-10-03T23:16:29.049590Z"}],"checksum":"84bdb5c07ec812b69558200b30ea28ff28ad0b9059153cc32290b8737fa6e228","rust_version":"1.70","has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":7180,"comment_lines":105,"files":30}},"total_code_lines":7180,"total_comment_lines":105}},{"id":910557,"crate":"chromiumoxide","num":"0.5.3","dl_path":"/api/v1/crates/chromiumoxide/0.5.3/download","readme_path":"/api/v1/crates/chromiumoxide/0.5.3/readme","updated_at":"2023-10-03T23:14:58.513502Z","created_at":"2023-09-29T13:08:02.015591Z","downloads":1271,"features":{"_fetcher-native-async-std":["fetcher","chromiumoxide_fetcher/_native-async-std"],"_fetcher-native-tokio":["fetcher","chromiumoxide_fetcher/_native-tokio"],"_fetcher-rustls-async-std":["fetcher","chromiumoxide_fetcher/_rustls-async-std"],"_fetcher-rusttls-tokio":["fetcher","chromiumoxide_fetcher/_rustls-tokio"],"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"default":["async-std-runtime"],"fetcher":[],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":true,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.5.3/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.5.3/downloads","authors":"/api/v1/crates/chromiumoxide/0.5.3/authors"},"crate_size":91372,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2023-09-29T13:08:02.015591Z"},{"action":"yank","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2023-10-03T23:14:58.517750Z"}],"checksum":"f5258a072a786870d88feb095aebeec5cd0d37081b4e5b8671dbf3c13d773849","rust_version":"1.70","has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":7178,"comment_lines":107,"files":30}},"total_code_lines":7178,"total_comment_lines":107}},{"id":853413,"crate":"chromiumoxide","num":"0.5.1","dl_path":"/api/v1/crates/chromiumoxide/0.5.1/download","readme_path":"/api/v1/crates/chromiumoxide/0.5.1/readme","updated_at":"2023-07-24T10:01:58.494432Z","created_at":"2023-07-24T10:01:58.494432Z","downloads":3867,"features":{"_fetcher-native-async-std":["fetcher","chromiumoxide_fetcher/_native-async-std"],"_fetcher-native-tokio":["fetcher","chromiumoxide_fetcher/_native-tokio"],"_fetcher-rustls-async-std":["fetcher","chromiumoxide_fetcher/_rustls-async-std"],"_fetcher-rusttls-tokio":["fetcher","chromiumoxide_fetcher/_rustls-tokio"],"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"default":["async-std-runtime"],"fetcher":[],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.5.1/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.5.1/downloads","authors":"/api/v1/crates/chromiumoxide/0.5.1/authors"},"crate_size":89615,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2023-07-24T10:01:58.494432Z"}],"checksum":"9f4d033a44aa99305af8e3a4c7280463555fe56e03c5ca4bb8d0f9f227ec8d0d","rust_version":"1.64","has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":7034,"comment_lines":102,"files":30}},"total_code_lines":7034,"total_comment_lines":102}},{"id":740084,"crate":"chromiumoxide","num":"0.5.0","dl_path":"/api/v1/crates/chromiumoxide/0.5.0/download","readme_path":"/api/v1/crates/chromiumoxide/0.5.0/readme","updated_at":"2023-03-03T08:09:48.916928Z","created_at":"2023-03-03T08:09:48.916928Z","downloads":98358,"features":{"_fetcher-native-async-std":["fetcher","chromiumoxide_fetcher/_native-async-std"],"_fetcher-native-tokio":["fetcher","chromiumoxide_fetcher/_native-tokio"],"_fetcher-rustls-async-std":["fetcher","chromiumoxide_fetcher/_rustls-async-std"],"_fetcher-rusttls-tokio":["fetcher","chromiumoxide_fetcher/_rustls-tokio"],"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"default":["async-std-runtime"],"fetcher":[],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.5.0/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.5.0/downloads","authors":"/api/v1/crates/chromiumoxide/0.5.0/authors"},"crate_size":88086,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2023-03-03T08:09:48.916928Z"}],"checksum":"1fbef58698a487c253c55c3d17bb1efbe268d2961a2c8278e3f86fff721355fc","rust_version":"1.60","has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":6975,"comment_lines":99,"files":30}},"total_code_lines":6975,"total_comment_lines":99}},{"id":653076,"crate":"chromiumoxide","num":"0.4.0","dl_path":"/api/v1/crates/chromiumoxide/0.4.0/download","readme_path":"/api/v1/crates/chromiumoxide/0.4.0/readme","updated_at":"2022-10-29T05:12:03.131785Z","created_at":"2022-10-29T05:12:03.131785Z","downloads":117086,"features":{"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"default":["async-std-runtime"],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.4.0/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.4.0/downloads","authors":"/api/v1/crates/chromiumoxide/0.4.0/authors"},"crate_size":72506,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2022-10-29T05:12:03.131785Z"}],"checksum":"3c5506e432f602b1747e8a0d60ac6607c6977af4ee9720237764170305323e62","rust_version":null,"has_lib":true,"bin_names":[],"edition":"2021","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":6573,"comment_lines":78,"files":29}},"total_code_lines":6573,"total_comment_lines":78}},{"id":523252,"crate":"chromiumoxide","num":"0.3.5","dl_path":"/api/v1/crates/chromiumoxide/0.3.5/download","readme_path":"/api/v1/crates/chromiumoxide/0.3.5/readme","updated_at":"2022-03-28T11:20:49.765706Z","created_at":"2022-03-28T11:20:49.765706Z","downloads":34844,"features":{"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"default":["async-std-runtime"],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.3.5/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.3.5/downloads","authors":"/api/v1/crates/chromiumoxide/0.3.5/authors"},"crate_size":68310,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2022-03-28T11:20:49.765706Z"}],"checksum":"662d26c51d5be85213204e2c9de1b25fab1989b34d0875802b7aebec6740fe1d","rust_version":null,"has_lib":true,"bin_names":[],"edition":"2018","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":6172,"comment_lines":74,"files":26}},"total_code_lines":6172,"total_comment_lines":74}},{"id":469337,"crate":"chromiumoxide","num":"0.3.4","dl_path":"/api/v1/crates/chromiumoxide/0.3.4/download","readme_path":"/api/v1/crates/chromiumoxide/0.3.4/readme","updated_at":"2021-12-16T16:50:21.117764Z","created_at":"2021-12-16T16:50:21.117764Z","downloads":12710,"features":{"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"default":["async-std-runtime"],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.3.4/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.3.4/downloads","authors":"/api/v1/crates/chromiumoxide/0.3.4/authors"},"crate_size":68132,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2021-12-16T16:50:21.117764Z"}],"checksum":"d8bdc7a1f2cba21a7facb87c8758e3e2b1e3700daaab416768ddd2bd96fa44e2","rust_version":null,"has_lib":true,"bin_names":[],"edition":"2018","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":6166,"comment_lines":74,"files":26}},"total_code_lines":6166,"total_comment_lines":74}},{"id":462380,"crate":"chromiumoxide","num":"0.3.2","dl_path":"/api/v1/crates/chromiumoxide/0.3.2/download","readme_path":"/api/v1/crates/chromiumoxide/0.3.2/readme","updated_at":"2021-12-03T09:27:27.732217Z","created_at":"2021-12-03T09:27:27.732217Z","downloads":2610,"features":{"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"default":["async-std-runtime"],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.3.2/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.3.2/downloads","authors":"/api/v1/crates/chromiumoxide/0.3.2/authors"},"crate_size":68324,"published_by":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"audit_actions":[{"action":"publish","user":{"id":9617,"login":"mattsse","name":"Matthias Seitz","avatar":"https://avatars.githubusercontent.com/u/19890894?v=4","url":"https://github.com/mattsse"},"time":"2021-12-03T09:27:27.732217Z"}],"checksum":"e4116c3e4d172dbbb8f1184f9cd2a31a9f8e497ff8f546bfb33e6a655ed3025f","rust_version":null,"has_lib":true,"bin_names":[],"edition":"2018","description":"Library for interacting with a chrome instance with the chrome devtools protocol","homepage":"https://github.com/mattsse/chromiumoxide","documentation":null,"repository":"https://github.com/mattsse/chromiumoxide","trustpub_data":null,"linecounts":{"languages":{"Rust":{"code_lines":6181,"comment_lines":74,"files":26}},"total_code_lines":6181,"total_comment_lines":74}},{"id":402950,"crate":"chromiumoxide","num":"0.3.1","dl_path":"/api/v1/crates/chromiumoxide/0.3.1/download","readme_path":"/api/v1/crates/chromiumoxide/0.3.1/readme","updated_at":"2021-07-19T15:08:53.390278Z","created_at":"2021-07-19T15:08:53.390278Z","downloads":7330,"features":{"async-std-runtime":["async-std","async-tungstenite/async-std-runtime"],"default":["async-std-runtime"],"tokio-runtime":["tokio","async-tungstenite/tokio-runtime"]},"yanked":false,"yank_message":null,"lib_links":null,"license":"MIT OR Apache-2.0","links":{"dependencies":"/api/v1/crates/chromiumoxide/0.3.1/dependencies","version_downloads":"/api/v1/crates/chromiumoxide/0.3.1/downloads","authors":"/api/v1/crates/chromiumoxide/0.3.1/authors"},"crate_size":68611,"publ + +[… truncated 6981 chars …] \ No newline at end of file diff --git a/src/daemon.rs b/src/daemon.rs index 5be3873..32eb926 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -82,6 +82,8 @@ struct DaemonCtx { } /// Daemon 入口 +/// +/// `sock_path` 保留用于兼容旧版 daemon 命令的 CLI 接口,实际已不再使用。 pub async fn run( _sock_path: String, database: &Option>, @@ -352,22 +354,30 @@ async fn llm_consumer_loop( let uid = user_id.clone(); let corr = correlation_id; let session = conv.session(); + let approved_tool = approved_tool.clone(); let executor: ToolExecutor = Arc::new(move |name: &str, args_json: &str| { - // 所有工具统一通过消息队列异步执行 let eq = eq.clone(); let uid = uid.clone(); let corr = corr; let session = session.clone(); let n = name.to_string(); let args = args_json.to_string(); + let is_approved = approved_tool.as_ref().map_or(false, |t| t == &n); Box::pin(async move { let ch = ChannelId::wechat(&uid); let sid = { session.lock().await.session_id }; - eq.enqueue(PipelineMessage::tool_call( - ch, corr, sid, &Uuid::new_v4().to_string(), &n, &args, None, - )).await; + let tool_call_id = Uuid::new_v4().to_string(); + if is_approved { + eq.enqueue(PipelineMessage::approved_tool_call( + ch, corr, sid, &tool_call_id, &n, &args, None, + )).await; + } else { + eq.enqueue(PipelineMessage::tool_call( + ch, corr, sid, &tool_call_id, &n, &args, None, + )).await; + } Ok(format!("{}{}", ASYNC_MARKER, n)) }) }); @@ -385,9 +395,10 @@ async fn llm_consumer_loop( // 从缓存恢复会话,注入工具结果并恢复 LLM 循环 let should_continue = { - let map = sessions.lock().await; - if let Some((conv, _)) = map.get(&correlation_id) { + let mut map = sessions.lock().await; + if let Some((conv, last_access)) = map.get_mut(&correlation_id) { conv.session().lock().await.add_tool_result(&tool_call_id, &tool_name, &result); + *last_access = Instant::now(); // 更新访问时间,防止 TTL 误清理 true } else { warn!("会话已过期: corr={}", correlation_id); @@ -534,11 +545,11 @@ async fn tool_consumer_loop( let correlation_id = msg.correlation_id; match msg.kind { - MessageKind::ToolCall { session_id, tool_call_id: _, tool_name, arguments, context_token } => { + MessageKind::ToolCall { session_id, tool_call_id, tool_name, arguments, context_token, approved } => { info!("Tool Consumer: user={} tool={}", user_id, tool_name); - // 高风险工具 → 审批 - if crate::tools::builtin::BuiltinRegistry::is_high_risk(&tool_name) { + // 高风险工具 → 审批(除非已被用户批准) + if !approved && crate::tools::builtin::BuiltinRegistry::is_high_risk(&tool_name) { info!("高风险工具 {} 需要审批", tool_name); ctx.approval_ctx.lock().await.insert( user_id.clone(), @@ -569,7 +580,7 @@ async fn tool_consumer_loop( let output = execute_tool(&tool_name, &arguments, ctx, &user_id).await; enqueue.enqueue(PipelineMessage::tool_result( - ChannelId::wechat(&user_id), correlation_id, session_id, "", &tool_name, &output, context_token, + ChannelId::wechat(&user_id), correlation_id, session_id, &tool_call_id, &tool_name, &output, context_token, )).await; } MessageKind::ApprovalRequest { .. } => { @@ -612,6 +623,50 @@ async fn execute_tool(name: &str, arguments: &str, ctx: &DaemonCtx, user_id: &st let specs = crate::tools::builtin::BuiltinRegistry::specs(); return crate::tools::build_capability_guide(&specs); } + "call_capability" => { + // 解包 {name, prompt} → 提取目标工具名和参数,直接派发 + let cp: serde_json::Value = serde_json::from_str(arguments).unwrap_or_default(); + let target_name = cp.get("name").and_then(|v| v.as_str()).unwrap_or("").to_string(); + if target_name.is_empty() { + return "请提供 name 参数".to_string(); + } + let target_args = serde_json::to_string(&crate::tools::unpack_call_params(&cp)) + .unwrap_or_default(); + // 重新派发到 execute_tool(通过顶层 match 分支避免 async 递归) + // 上下文工具 + match target_name.as_str() { + "read_memories" => { + let mems = load_memories(&ctx.memory_store, user_id).await; + if mems.is_empty() { return "暂无长期记忆".to_string(); } + return mems.iter().enumerate() + .map(|(i, v)| format!("{}. {}", i + 1, v)).collect::>().join("\n"); + } + "write_memory" => { + let params: serde_json::Value = serde_json::from_str(&target_args).unwrap_or_default(); + let content = params.get("content").and_then(|v| v.as_str()).unwrap_or(""); + if content.is_empty() { return "请提供 content 参数".to_string(); } + ctx.memory_store.write_for(user_id, content).await; + return format!("已添加长期记忆: {}", content); + } + "read_summaries" => { + let sums = load_summaries(&ctx.db, user_id).await; + if sums.is_empty() { return "暂无历史摘要".to_string(); } + return sums.iter().enumerate() + .map(|(i, s)| format!("{}. {}", i + 1, s)) + .collect::>().join("\n---\n"); + } + "query_capabilities" => { + let specs = crate::tools::builtin::BuiltinRegistry::specs(); + return crate::tools::build_capability_guide(&specs); + } + _ => {} + } + // 内置工具注册表 + match crate::tools::builtin::BuiltinRegistry::execute(&target_name, &target_args).await { + Some(r) => return r.output, + None => return format!("未知工具: {}", target_name), + } + } _ => {} } @@ -685,7 +740,8 @@ async fn load_history(db: &Option>, user_id: &str) -> Vec Vec { let text = memory_store.read_for(user_id).await; - if text == "暂无长期记忆" { vec![] } + // read_for() 返回 "暂无长期记忆" 表示无记忆,否则返回 "1. ...\n2. ..." 格式 + if text.starts_with("暂无") { vec![] } else { text.lines().map(|l| l.trim().to_string()).filter(|l| !l.is_empty()).collect() } } diff --git a/src/queue/message_queue.rs b/src/queue/message_queue.rs index f9b6ec2..1cdfb9b 100644 --- a/src/queue/message_queue.rs +++ b/src/queue/message_queue.rs @@ -60,6 +60,8 @@ pub enum MessageKind { tool_name: String, arguments: String, context_token: Option, + /// 该工具调用是否已被用户批准(跳过审批流程) + approved: bool, }, /// 工具执行结果 → 回喂 LLM Consumer ToolResult { @@ -157,6 +159,31 @@ impl PipelineMessage { tool_name: tool_name.into(), arguments: arguments.into(), context_token, + approved: false, + }, + } + } + + /// 快速构造一条已批准的工具调用(跳过审批) + pub fn approved_tool_call( + channel: ChannelId, + correlation_id: Uuid, + session_id: Uuid, + tool_call_id: impl Into, + tool_name: impl Into, + arguments: impl Into, + context_token: Option, + ) -> Self { + Self { + channel, + correlation_id, + kind: MessageKind::ToolCall { + session_id, + tool_call_id: tool_call_id.into(), + tool_name: tool_name.into(), + arguments: arguments.into(), + context_token, + approved: true, }, } }