fr-cli 2.4.2__tar.gz → 2.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fr_cli-2.4.2/fr_cli.egg-info → fr_cli-2.5.0}/PKG-INFO +21 -2
- {fr_cli-2.4.2 → fr_cli-2.5.0}/README.md +19 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/README.md +14 -4
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/WEAPON.MD +11 -43
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/__init__.py +1 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/addon/plugin.py +1 -2
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/artifact_detector.py +0 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/builtins/db.py +11 -9
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/builtins/local.py +4 -6
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/builtins/rag.py +20 -129
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/builtins/rag_watcher_daemon.py +1 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/builtins/remote.py +18 -15
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/builtins/spider.py +5 -4
- fr_cli-2.5.0/fr_cli/agent/builtins/stock.py +395 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/client.py +61 -22
- fr_cli-2.5.0/fr_cli/agent/dispatch.py +90 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/executor.py +33 -33
- fr_cli-2.5.0/fr_cli/agent/generator.py +213 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/hermes.py +1 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/hermes_daemon.py +1 -3
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/manager.py +32 -28
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/master.py +22 -42
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/personality.py +1 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/server.py +67 -14
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/shell_mode.py +1 -4
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/skills.py +2 -2
- fr_cli-2.5.0/fr_cli/agent/swarm.py +174 -0
- fr_cli-2.5.0/fr_cli/agent/swarm_resolver.py +310 -0
- fr_cli-2.5.0/fr_cli/agent/workflow.py +283 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/breakthrough/update.py +48 -39
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/command/executor.py +87 -47
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/command/registered/agent_data_mcp.py +28 -25
- fr_cli-2.5.0/fr_cli/command/registered/charts.py +45 -0
- fr_cli-2.5.0/fr_cli/command/registered/dynamic_build.py +51 -0
- fr_cli-2.5.0/fr_cli/command/registered/fs.py +144 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/command/registered/image.py +5 -4
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/command/registered/main_routes.py +1 -1
- fr_cli-2.5.0/fr_cli/command/registered/network.py +61 -0
- fr_cli-2.5.0/fr_cli/command/registered/ocr.py +26 -0
- fr_cli-2.5.0/fr_cli/command/registered/remote.py +55 -0
- fr_cli-2.5.0/fr_cli/command/registered/services.py +366 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/command/registered/session_config.py +77 -42
- fr_cli-2.5.0/fr_cli/command/registered/swarm.py +35 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/command/registered/web.py +7 -6
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/command/registry.py +169 -19
- fr_cli-2.5.0/fr_cli/command/security.py +53 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/conf/config.py +15 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/conf/paths.py +4 -3
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/chat.py +120 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/core.py +100 -51
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/errors.py +0 -3
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/llm.py +1 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/model_factory.py +15 -15
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/optimizations.py +3 -5
- fr_cli-2.5.0/fr_cli/core/plan.py +488 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/preferences.py +1 -1
- fr_cli-2.5.0/fr_cli/core/result.py +84 -0
- fr_cli-2.5.0/fr_cli/core/store.py +75 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/stream.py +0 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/sysmon.py +2 -5
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/thinking.py +5 -2
- fr_cli-2.5.0/fr_cli/core/usage.py +87 -0
- fr_cli-2.5.0/fr_cli/dynamic_builder/__init__.py +19 -0
- fr_cli-2.5.0/fr_cli/dynamic_builder/code_generator.py +90 -0
- fr_cli-2.5.0/fr_cli/dynamic_builder/dependency_manager.py +118 -0
- fr_cli-2.5.0/fr_cli/dynamic_builder/planner.py +104 -0
- fr_cli-2.5.0/fr_cli/dynamic_builder/registry_manager.py +205 -0
- fr_cli-2.5.0/fr_cli/dynamic_builder/runner.py +157 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/gatekeeper/daemon.py +0 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/gatekeeper/manager.py +27 -29
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/lang/translations/en.py +2 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/lang/translations/zh.py +2 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/main.py +9 -88
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/memory/history.py +9 -12
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/memory/session.py +8 -15
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/actions.py +1 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/batch.py +0 -2
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/bootstrap.py +2 -6
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/__init__.py +4 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/_common.py +29 -23
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/agent.py +20 -31
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/base.py +7 -21
- fr_cli-2.5.0/fr_cli/repl/commands/build.py +62 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/config.py +46 -33
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/cron.py +2 -20
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/dataframe.py +1 -21
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/dev.py +1 -21
- fr_cli-2.5.0/fr_cli/repl/commands/fs.py +46 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/mcp.py +1 -21
- fr_cli-2.5.0/fr_cli/repl/commands/ocr.py +224 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/rag.py +1 -21
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/remote_agent.py +6 -25
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/session.py +2 -14
- fr_cli-2.5.0/fr_cli/repl/commands/stock.py +127 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands/system.py +26 -42
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/queue.py +1 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/quick_actions.py +2 -5
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/router.py +15 -4
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/scenarios.py +3 -2
- fr_cli-2.5.0/fr_cli/security/security.py +133 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/ui/banner.py +2 -3
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/ui/prompt.py +40 -10
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/ui/splash.py +1 -2
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/ui/ui.py +1 -1
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/ui/web_config.py +0 -1
- fr_cli-2.5.0/fr_cli/weapon/charts.py +223 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/weapon/cron.py +28 -4
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/weapon/dataframe.py +18 -10
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/weapon/disk.py +39 -35
- fr_cli-2.5.0/fr_cli/weapon/fs.py +415 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/weapon/launcher.py +8 -8
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/weapon/loader.py +5 -1
- fr_cli-2.5.0/fr_cli/weapon/m365.py +446 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/weapon/mail.py +20 -19
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/weapon/mcp.py +131 -182
- fr_cli-2.5.0/fr_cli/weapon/network.py +189 -0
- fr_cli-2.5.0/fr_cli/weapon/ocr.py +289 -0
- fr_cli-2.5.0/fr_cli/weapon/remote.py +132 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/weapon/vision.py +10 -9
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/weapon/web.py +20 -15
- {fr_cli-2.4.2 → fr_cli-2.5.0/fr_cli.egg-info}/PKG-INFO +21 -2
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli.egg-info/SOURCES.txt +49 -33
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli.egg-info/requires.txt +1 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/pyproject.toml +19 -1
- fr_cli-2.5.0/tests/test_a2a_and_providers.py +148 -0
- fr_cli-2.5.0/tests/test_agent_create.py +181 -0
- fr_cli-2.5.0/tests/test_agent_manager_store.py +38 -0
- fr_cli-2.5.0/tests/test_agent_server.py +144 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/tests/test_batch_mode.py +0 -3
- fr_cli-2.5.0/tests/test_builtin_tools.py +169 -0
- fr_cli-2.5.0/tests/test_charts.py +139 -0
- fr_cli-2.5.0/tests/test_cron_persist.py +41 -0
- fr_cli-2.5.0/tests/test_dynamic_builder.py +184 -0
- fr_cli-2.5.0/tests/test_gatekeeper_store.py +39 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/tests/test_integration_real.py +23 -22
- fr_cli-2.5.0/tests/test_json_store.py +71 -0
- fr_cli-2.5.0/tests/test_m365_mail.py +231 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/tests/test_master_prompt_fix.py +0 -1
- fr_cli-2.5.0/tests/test_mcp_real.py +40 -0
- fr_cli-2.5.0/tests/test_memory_store.py +66 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/tests/test_model_config.py +15 -18
- {fr_cli-2.4.2 → fr_cli-2.5.0}/tests/test_no_color_prompt_toolkit.py +0 -18
- fr_cli-2.5.0/tests/test_ocr.py +224 -0
- fr_cli-2.5.0/tests/test_plan.py +298 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/tests/test_plugin_exec.py +0 -3
- fr_cli-2.5.0/tests/test_result.py +37 -0
- fr_cli-2.5.0/tests/test_security.py +206 -0
- fr_cli-2.5.0/tests/test_stock.py +171 -0
- fr_cli-2.5.0/tests/test_swarm.py +259 -0
- fr_cli-2.5.0/tests/test_usage.py +87 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/tests/test_vfs_diff.py +11 -15
- fr_cli-2.5.0/tests/test_workflow.py +143 -0
- fr_cli-2.4.2/fr_cli/agent/a2a.py +0 -568
- fr_cli-2.4.2/fr_cli/agent/acp.py +0 -199
- fr_cli-2.4.2/fr_cli/agent/builtins/powerful_agent_template.py +0 -923
- fr_cli-2.4.2/fr_cli/agent/coding_helper.py +0 -811
- fr_cli-2.4.2/fr_cli/agent/context_files.py +0 -160
- fr_cli-2.4.2/fr_cli/agent/gateway.py +0 -234
- fr_cli-2.4.2/fr_cli/agent/generator.py +0 -105
- fr_cli-2.4.2/fr_cli/agent/image_and_parallel.py +0 -1013
- fr_cli-2.4.2/fr_cli/agent/plugin_system.py +0 -195
- fr_cli-2.4.2/fr_cli/agent/workflow.py +0 -174
- fr_cli-2.4.2/fr_cli/agent/workflow_system/__init__.py +0 -14
- fr_cli-2.4.2/fr_cli/agent/workflow_system/engine.py +0 -414
- fr_cli-2.4.2/fr_cli/agent/workflow_system/executor.py +0 -217
- fr_cli-2.4.2/fr_cli/agent/workflow_system/manager.py +0 -84
- fr_cli-2.4.2/fr_cli/agent/workflow_system/models.py +0 -195
- fr_cli-2.4.2/fr_cli/agent/workflow_system/monitor.py +0 -68
- fr_cli-2.4.2/fr_cli/agent/workflow_system/tools.py +0 -224
- fr_cli-2.4.2/fr_cli/agent/workflow_system.py +0 -23
- fr_cli-2.4.2/fr_cli/command/handlers/__init__.py +0 -15
- fr_cli-2.4.2/fr_cli/command/handlers/agent.py +0 -73
- fr_cli-2.4.2/fr_cli/command/handlers/app.py +0 -31
- fr_cli-2.4.2/fr_cli/command/handlers/config.py +0 -167
- fr_cli-2.4.2/fr_cli/command/handlers/cron.py +0 -56
- fr_cli-2.4.2/fr_cli/command/handlers/dataframe.py +0 -34
- fr_cli-2.4.2/fr_cli/command/handlers/disk.py +0 -84
- fr_cli-2.4.2/fr_cli/command/handlers/fs.py +0 -95
- fr_cli-2.4.2/fr_cli/command/handlers/mail.py +0 -81
- fr_cli-2.4.2/fr_cli/command/handlers/mcp.py +0 -46
- fr_cli-2.4.2/fr_cli/command/handlers/other.py +0 -34
- fr_cli-2.4.2/fr_cli/command/handlers/session.py +0 -79
- fr_cli-2.4.2/fr_cli/command/handlers/system.py +0 -189
- fr_cli-2.4.2/fr_cli/command/handlers/vision.py +0 -38
- fr_cli-2.4.2/fr_cli/command/handlers/web.py +0 -34
- fr_cli-2.4.2/fr_cli/command/registered/fs.py +0 -84
- fr_cli-2.4.2/fr_cli/command/registered/services.py +0 -236
- fr_cli-2.4.2/fr_cli/command/security.py +0 -30
- fr_cli-2.4.2/fr_cli/repl/commands/fs.py +0 -66
- fr_cli-2.4.2/fr_cli/security/security.py +0 -50
- fr_cli-2.4.2/fr_cli/weapon/fs.py +0 -309
- fr_cli-2.4.2/tests/test_a2a_and_providers.py +0 -447
- fr_cli-2.4.2/tests/test_new_features.py +0 -449
- {fr_cli-2.4.2 → fr_cli-2.5.0}/LICENSE +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/MANIFEST.in +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/__init__.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/builtins/__init__.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/builtins/_utils.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/master_prompt.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/agent/remote.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/assets/splash.jpeg +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/command/__init__.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/conf/__init__.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/conf/default_models.yaml +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/conf/wizard.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/cache.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/intent.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/project.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/core/recommender.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/gatekeeper/__init__.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/lang/i18n.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/lang/translations/__init__.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/memory/context.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/__init__.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/repl/commands.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/ui/buddha.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli/ui/markdown.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli.egg-info/dependency_links.txt +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli.egg-info/entry_points.txt +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/fr_cli.egg-info/top_level.txt +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/setup.cfg +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/tests/test_help_update.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/tests/test_new_providers.py +0 -0
- {fr_cli-2.4.2 → fr_cli-2.5.0}/tests/test_prompt_completion.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fr-cli
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.5.0
|
|
4
4
|
Summary: 凡人打字机 - 支持多模型(Zhipu/DeepSeek/Kimi/Qwen/StepFun/MiniMax/Spark/Doubao/MiMo)的终极全能终端工具
|
|
5
5
|
Author: FANREN CLI Author
|
|
6
6
|
License-Expression: MIT
|
|
@@ -30,6 +30,7 @@ Requires-Dist: mcp>=1.6.0
|
|
|
30
30
|
Requires-Dist: pyyaml>=6.0.0
|
|
31
31
|
Requires-Dist: prompt_toolkit>=3.0.0
|
|
32
32
|
Requires-Dist: Pillow>=10.0.0
|
|
33
|
+
Requires-Dist: pymupdf>=1.23.0
|
|
33
34
|
Provides-Extra: data
|
|
34
35
|
Requires-Dist: pandas>=1.5.0; extra == "data"
|
|
35
36
|
Requires-Dist: openpyxl>=3.0.0; extra == "data"
|
|
@@ -108,7 +109,7 @@ Dynamic: license-file
|
|
|
108
109
|
|
|
109
110
|
### 🎯 特色功能
|
|
110
111
|
- **视觉能力**:图片生成 (CogView) 与多模态识别 (GLM-4V)
|
|
111
|
-
- **邮件收发**:支持 IMAP/SMTP
|
|
112
|
+
- **邮件收发**:支持 IMAP/SMTP 与 Microsoft 365 现代认证(OAuth2 + MFA,防头注入)
|
|
112
113
|
- **定时任务**:后台定时执行命令(shlex 安全解析)
|
|
113
114
|
- **云盘集成**:百度/阿里/OneDrive 网盘
|
|
114
115
|
- **插件系统**:AI 生成代码自动保存为插件(子进程隔离)
|
|
@@ -176,6 +177,15 @@ fr-cli
|
|
|
176
177
|
/mcp_add <名> <命令> [参数] 添加 MCP 服务器
|
|
177
178
|
/mcp_del <名> 删除 MCP 服务器
|
|
178
179
|
|
|
180
|
+
/mail setup 配置 IMAP/SMTP 邮箱
|
|
181
|
+
/mail inbox 查看收件箱
|
|
182
|
+
/mail read <id> 读取邮件
|
|
183
|
+
/mail send <to> <sub> <body> 发送邮件
|
|
184
|
+
/m365_config setup 配置 Microsoft 365 邮箱(OAuth2 + MFA)
|
|
185
|
+
/m365_inbox 查看 Microsoft 365 收件箱
|
|
186
|
+
/m365_read <id> 读取 Microsoft 365 邮件
|
|
187
|
+
/m365_send <to> <sub> <body> 发送 Microsoft 365 邮件
|
|
188
|
+
|
|
179
189
|
/help 查看帮助
|
|
180
190
|
/exit 退出
|
|
181
191
|
```
|
|
@@ -467,6 +477,15 @@ fr_cli/
|
|
|
467
477
|
- QQ/163 邮箱需使用「授权码」而非登录密码
|
|
468
478
|
- 授权码在邮箱设置 → 账户 → 开启 IMAP/SMTP 服务后生成
|
|
469
479
|
|
|
480
|
+
**Q: Microsoft 365 / Outlook 邮箱如何使用?**
|
|
481
|
+
Microsoft 365 已禁用基本认证,需使用 OAuth2 现代认证:
|
|
482
|
+
1. 在 Azure AD 注册应用,添加 `Mail.Read`、`Mail.Send`、`User.Read` 委派权限
|
|
483
|
+
2. 复制 Application (client) ID 和 Directory (tenant) ID
|
|
484
|
+
3. 执行 `/m365_config setup`,按向导完成设备码或授权码登录(支持 MFA)
|
|
485
|
+
4. 之后使用 `/m365_inbox`、`/m365_read <id>`、`/m365_send <to> <sub> <body>`
|
|
486
|
+
|
|
487
|
+
Token 缓存于 `~/.fr_cli/m365.json`,文件权限 `0o600`。
|
|
488
|
+
|
|
470
489
|
**Q: 搜索功能无法使用?**
|
|
471
490
|
```bash
|
|
472
491
|
pip install requests
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
|
|
35
35
|
### 🎯 特色功能
|
|
36
36
|
- **视觉能力**:图片生成 (CogView) 与多模态识别 (GLM-4V)
|
|
37
|
-
- **邮件收发**:支持 IMAP/SMTP
|
|
37
|
+
- **邮件收发**:支持 IMAP/SMTP 与 Microsoft 365 现代认证(OAuth2 + MFA,防头注入)
|
|
38
38
|
- **定时任务**:后台定时执行命令(shlex 安全解析)
|
|
39
39
|
- **云盘集成**:百度/阿里/OneDrive 网盘
|
|
40
40
|
- **插件系统**:AI 生成代码自动保存为插件(子进程隔离)
|
|
@@ -102,6 +102,15 @@ fr-cli
|
|
|
102
102
|
/mcp_add <名> <命令> [参数] 添加 MCP 服务器
|
|
103
103
|
/mcp_del <名> 删除 MCP 服务器
|
|
104
104
|
|
|
105
|
+
/mail setup 配置 IMAP/SMTP 邮箱
|
|
106
|
+
/mail inbox 查看收件箱
|
|
107
|
+
/mail read <id> 读取邮件
|
|
108
|
+
/mail send <to> <sub> <body> 发送邮件
|
|
109
|
+
/m365_config setup 配置 Microsoft 365 邮箱(OAuth2 + MFA)
|
|
110
|
+
/m365_inbox 查看 Microsoft 365 收件箱
|
|
111
|
+
/m365_read <id> 读取 Microsoft 365 邮件
|
|
112
|
+
/m365_send <to> <sub> <body> 发送 Microsoft 365 邮件
|
|
113
|
+
|
|
105
114
|
/help 查看帮助
|
|
106
115
|
/exit 退出
|
|
107
116
|
```
|
|
@@ -393,6 +402,15 @@ fr_cli/
|
|
|
393
402
|
- QQ/163 邮箱需使用「授权码」而非登录密码
|
|
394
403
|
- 授权码在邮箱设置 → 账户 → 开启 IMAP/SMTP 服务后生成
|
|
395
404
|
|
|
405
|
+
**Q: Microsoft 365 / Outlook 邮箱如何使用?**
|
|
406
|
+
Microsoft 365 已禁用基本认证,需使用 OAuth2 现代认证:
|
|
407
|
+
1. 在 Azure AD 注册应用,添加 `Mail.Read`、`Mail.Send`、`User.Read` 委派权限
|
|
408
|
+
2. 复制 Application (client) ID 和 Directory (tenant) ID
|
|
409
|
+
3. 执行 `/m365_config setup`,按向导完成设备码或授权码登录(支持 MFA)
|
|
410
|
+
4. 之后使用 `/m365_inbox`、`/m365_read <id>`、`/m365_send <to> <sub> <body>`
|
|
411
|
+
|
|
412
|
+
Token 缓存于 `~/.fr_cli/m365.json`,文件权限 `0o600`。
|
|
413
|
+
|
|
396
414
|
**Q: 搜索功能无法使用?**
|
|
397
415
|
```bash
|
|
398
416
|
pip install requests
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
**🇨🇳 中文简介**
|
|
6
6
|
|
|
7
|
-
支持:多模型 AI 对话(智谱/DeepSeek/Kimi/Qwen/StepFun/MiniMax/讯飞星火)、MasterAgent 自我进化主控、思维模式切换(direct/CoT/ToT/ReAct)、文件沙盒操作、联网搜索(SSRF
|
|
7
|
+
支持:多模型 AI 对话(智谱/DeepSeek/Kimi/Qwen/StepFun/MiniMax/讯飞星火)、MasterAgent 自我进化主控、思维模式切换(direct/CoT/ToT/ReAct)、文件沙盒操作、联网搜索(SSRF 防护)、图片生成与识别、邮件收发(IMAP/SMTP + Microsoft 365 OAuth2/MFA)、定时任务(shlex 安全解析)、云盘集成、会话记忆、按日期自动存档、插件进化(子进程隔离)、四阶安全拦截、Shell 管道直通 AI。
|
|
8
8
|
|
|
9
9
|
**🇺🇸 English Intro**
|
|
10
10
|
|
|
11
|
-
The ultimate all-knowing terminal tool supporting multiple LLM providers (Zhipu/DeepSeek/Kimi/Qwen/StepFun/MiniMax/Spark). Supports AI chat, MasterAgent self-evolving controller, thinking modes (direct/CoT/ToT/ReAct), virtual filesystem, web search (SSRF-protected), image generation & vision, email, cron jobs (shlex-safe), cloud drive, session memory, auto date-based archiving, self-evolving plugins (subprocess-isolated), and powerful Shell piping.
|
|
11
|
+
The ultimate all-knowing terminal tool supporting multiple LLM providers (Zhipu/DeepSeek/Kimi/Qwen/StepFun/MiniMax/Spark). Supports AI chat, MasterAgent self-evolving controller, thinking modes (direct/CoT/ToT/ReAct), virtual filesystem, web search (SSRF-protected), image generation & vision, email (IMAP/SMTP + Microsoft 365 OAuth2/MFA), cron jobs (shlex-safe), cloud drive, session memory, auto date-based archiving, self-evolving plugins (subprocess-isolated), and powerful Shell piping.
|
|
12
12
|
|
|
13
13
|
---
|
|
14
14
|
|
|
@@ -51,6 +51,14 @@ fr-cli
|
|
|
51
51
|
/mcp_list 列出 MCP 服务器及工具
|
|
52
52
|
/mcp_add <名> <命令> [参数] 添加 MCP 服务器
|
|
53
53
|
/mcp_del <名> 删除 MCP 服务器
|
|
54
|
+
/mail setup 配置 IMAP/SMTP 邮箱
|
|
55
|
+
/mail inbox 查看收件箱
|
|
56
|
+
/mail read <id> 读取邮件
|
|
57
|
+
/mail send <to> <sub> <body> 发送邮件
|
|
58
|
+
/m365_config setup 配置 Microsoft 365 邮箱(OAuth2 + MFA)
|
|
59
|
+
/m365_inbox 查看 Microsoft 365 收件箱
|
|
60
|
+
/m365_read <id> 读取 Microsoft 365 邮件
|
|
61
|
+
/m365_send <to> <sub> <body> 发送 Microsoft 365 邮件
|
|
54
62
|
/help 查看全部命令
|
|
55
63
|
/exit 退出
|
|
56
64
|
```
|
|
@@ -98,7 +106,8 @@ fr_cli/
|
|
|
98
106
|
│ ├── fs.py # 虚拟文件系统 VFS
|
|
99
107
|
│ ├── web.py # 网络搜索与网页抓取(SSRF 防护)
|
|
100
108
|
│ ├── vision.py # 图片生成 (CogView) / 多模态 (GLM-4V)
|
|
101
|
-
│ ├── mail.py #
|
|
109
|
+
│ ├── mail.py # 邮件客户端(IMAP/SMTP,防头注入)
|
|
110
|
+
│ ├── m365.py # Microsoft 365 邮件客户端(OAuth2 + MFA)
|
|
102
111
|
│ ├── disk.py # 云盘适配器
|
|
103
112
|
│ ├── cron.py # 定时任务(shlex + shell=False)
|
|
104
113
|
│ ├── launcher.py # 本地应用启动器(跨平台)
|
|
@@ -131,10 +140,11 @@ fr_cli/
|
|
|
131
140
|
## 📦 可选依赖
|
|
132
141
|
|
|
133
142
|
```bash
|
|
134
|
-
pip install fr-cli[all] #
|
|
143
|
+
pip install fr-cli[all] # 全功能(含网盘 / Microsoft 365)
|
|
135
144
|
pip install fr-cli[baidu] # 百度网盘
|
|
136
145
|
pip install fr-cli[aliyun] # 阿里云盘
|
|
137
146
|
pip install fr-cli[onedrive] # OneDrive
|
|
147
|
+
pip install fr-cli[cloud] # 网盘 + Microsoft 365(含 msal)
|
|
138
148
|
```
|
|
139
149
|
|
|
140
150
|
---
|
|
@@ -28,6 +28,14 @@
|
|
|
28
28
|
- **调用方式**: mail_inbox, mail_read, mail_send
|
|
29
29
|
- **触发关键词**: 邮件, mail, email, 发邮件, 收件箱, inbox, 发送邮件, 查看邮件
|
|
30
30
|
|
|
31
|
+
## m365_email
|
|
32
|
+
- **名称**: Microsoft 365 邮件工具
|
|
33
|
+
- **功能**: 通过 Microsoft Graph API 查看收件箱、读取邮件、发送邮件,支持 MFA
|
|
34
|
+
- **程序路径**: fr_cli/weapon/m365.py
|
|
35
|
+
- **调用方式**: m365_inbox, m365_read, m365_send
|
|
36
|
+
- **配置命令**: /m365_config setup
|
|
37
|
+
- **触发关键词**: m365, microsoft 365, outlook 365, 微软邮箱, Office 365
|
|
38
|
+
|
|
31
39
|
## web_search
|
|
32
40
|
- **名称**: 网络搜索工具
|
|
33
41
|
- **功能**: 搜索网络内容和获取网页
|
|
@@ -128,11 +136,9 @@
|
|
|
128
136
|
|
|
129
137
|
## builtin_rag
|
|
130
138
|
- **名称**: @RAG 本地知识库助手
|
|
131
|
-
- **功能**: ChromaDB 向量检索 +
|
|
132
|
-
- 向量检索:使用 all-MiniLM-L6-v2 嵌入模型,检索 top-
|
|
133
|
-
-
|
|
134
|
-
- 大模型判定:让 LLM 从 top-3 中评估相关性/完整性/准确性,选出最佳片段 ★【最佳】
|
|
135
|
-
- 最终生成:优先基于最佳片段回答,可综合其他片段补充
|
|
139
|
+
- **功能**: ChromaDB 向量检索 + 大模型综合生成。后台自动向量化监控目录。支持两种监控模式:
|
|
140
|
+
- 向量检索:使用 all-MiniLM-L6-v2 嵌入模型,检索 top-8 相关片段
|
|
141
|
+
- 综合生成:将检索到的片段一次性交给大模型,由其综合回答并标注来源
|
|
136
142
|
- 内置模式(daemon 线程):`/rag_dir <目录>` 后自动启动
|
|
137
143
|
- 独立模式(系统进程):`/rag_watch start [目录] [--interval N]`,退出终端后仍继续运行
|
|
138
144
|
- **程序路径**: fr_cli/agent/builtins/rag.py
|
|
@@ -187,44 +193,6 @@
|
|
|
187
193
|
|
|
188
194
|
---
|
|
189
195
|
|
|
190
|
-
## a2a_protocol
|
|
191
|
-
- **名称**: Agent2Agent Protocol (A2A) - Agent 互操作协议
|
|
192
|
-
- **功能**: 支持 Agent 之间的互操作,实现 Agent 发现、注册、能力匹配、任务委托和结果返回
|
|
193
|
-
- **程序路径**: fr_cli/agent/a2a.py
|
|
194
|
-
- **调用方式**:
|
|
195
|
-
- AI 调用: `agent_call({"name": "Agent名", "user_input": "任务描述"})`
|
|
196
|
-
- 发现: `discover_all_agents()` 获取所有可用 Agent
|
|
197
|
-
- 注册: `AgentRegistry.register(agent_info)`
|
|
198
|
-
- **触发关键词**: agent, agent_call, A2A, agent互操作, 委托任务, 多agent协作
|
|
199
|
-
|
|
200
|
-
核心组件:
|
|
201
|
-
- AgentRegistry: Agent 注册表(单例模式),管理所有 Agent 的注册与发现
|
|
202
|
-
- AgentInfo: Agent 信息,包含名称、类型、描述、能力列表、端点等
|
|
203
|
-
- A2AClient: A2A 客户端,用于调用其他 Agent
|
|
204
|
-
- A2AServer: A2A 服务器,提供 HTTP 接口供远程调用
|
|
205
|
-
- TaskRequest/TaskResult: 任务请求和结果数据结构
|
|
206
|
-
|
|
207
|
-
使用示例:
|
|
208
|
-
```
|
|
209
|
-
# MasterAgent 可自动发现并调用其他 Agent
|
|
210
|
-
>>> 帮我调用 code-agent 生成一个快速排序算法
|
|
211
|
-
🧙 仙人 【调用:agent_call({"name": "code-agent", "user_input": "生成快速排序算法"})】
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Agent 能力类型:
|
|
215
|
-
- code_generation: 代码生成
|
|
216
|
-
- code_review: 代码审查
|
|
217
|
-
- data_analysis: 数据分析
|
|
218
|
-
- web_search: 网络搜索
|
|
219
|
-
- file_operation: 文件操作
|
|
220
|
-
- database: 数据库操作
|
|
221
|
-
- image_processing: 图像处理
|
|
222
|
-
- text_generation: 文本生成
|
|
223
|
-
- translation: 翻译
|
|
224
|
-
- general: 通用能力
|
|
225
|
-
|
|
226
|
-
---
|
|
227
|
-
|
|
228
196
|
## provider_management
|
|
229
197
|
- **名称**: 模型提供商管理
|
|
230
198
|
- **功能**: 管理多个 AI 模型提供商(道统),支持配置、切换、查看
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
"""
|
|
5
5
|
import re, subprocess, sys
|
|
6
6
|
from fr_cli.conf.paths import PLUGIN_DIR
|
|
7
|
-
from pathlib import Path
|
|
8
7
|
from fr_cli.lang.i18n import T
|
|
9
8
|
from fr_cli.ui.ui import RED, DIM, RESET
|
|
10
9
|
|
|
@@ -67,4 +66,4 @@ else:
|
|
|
67
66
|
except subprocess.TimeoutExpired:
|
|
68
67
|
print(f"{RED}⏳ {T('err_posix', lang)} Timeout (15s){RESET}")
|
|
69
68
|
except Exception as e:
|
|
70
|
-
print(f"{RED}{T('err_posix', lang)} {e}{RESET}")
|
|
69
|
+
print(f"{RED}{T('err_posix', lang)} {e}{RESET}")
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
"""
|
|
7
7
|
from fr_cli.conf.config import load_namespace, save_namespace
|
|
8
8
|
from fr_cli.conf.paths import DATABASE_FILE
|
|
9
|
+
from fr_cli.core.result import Result
|
|
9
10
|
|
|
10
11
|
_NS_KEY = "databases"
|
|
11
12
|
DB_CFG_PATH = DATABASE_FILE # 保留用于一次性迁移
|
|
@@ -163,12 +164,12 @@ def _has_multiple_statements(sql: str) -> bool:
|
|
|
163
164
|
|
|
164
165
|
|
|
165
166
|
def _exec_sql(conn, sql, db_type):
|
|
166
|
-
"""执行 SQL
|
|
167
|
+
"""执行 SQL 并返回 Result。"""
|
|
167
168
|
cursor = conn.cursor()
|
|
168
169
|
try:
|
|
169
170
|
sql = sql.strip()
|
|
170
171
|
if _has_multiple_statements(sql):
|
|
171
|
-
return
|
|
172
|
+
return Result.fail("禁止执行多条 SQL 语句(检测到语句分隔符 ';')")
|
|
172
173
|
sql = sql.rstrip(";")
|
|
173
174
|
cursor.execute(sql)
|
|
174
175
|
|
|
@@ -176,16 +177,16 @@ def _exec_sql(conn, sql, db_type):
|
|
|
176
177
|
if sql.lower().startswith("select") or sql.lower().startswith("show") or sql.lower().startswith("desc"):
|
|
177
178
|
rows = cursor.fetchall()
|
|
178
179
|
if db_type == "mysql":
|
|
179
|
-
return rows
|
|
180
|
+
return Result.ok(rows)
|
|
180
181
|
else:
|
|
181
182
|
# 将 pyodbc/psycopg2 的行转为字典列表
|
|
182
183
|
cols = [desc[0] for desc in cursor.description] if cursor.description else []
|
|
183
|
-
return [{cols[i]: row[i] for i in range(len(cols))} for row in rows]
|
|
184
|
+
return Result.ok([{cols[i]: row[i] for i in range(len(cols))} for row in rows])
|
|
184
185
|
else:
|
|
185
186
|
conn.commit()
|
|
186
|
-
return f"受影响行数: {cursor.rowcount}"
|
|
187
|
+
return Result.ok(f"受影响行数: {cursor.rowcount}")
|
|
187
188
|
except Exception as e:
|
|
188
|
-
return
|
|
189
|
+
return Result.fail(str(e))
|
|
189
190
|
|
|
190
191
|
|
|
191
192
|
def handle_db(user_input, state):
|
|
@@ -259,10 +260,11 @@ def handle_db(user_input, state):
|
|
|
259
260
|
print(f"{DIM}已取消。{RESET}")
|
|
260
261
|
return
|
|
261
262
|
|
|
262
|
-
|
|
263
|
-
if
|
|
264
|
-
print(f"{RED}❌ 执行失败: {
|
|
263
|
+
exec_result = _exec_sql(conn, sql_text, db_cfg["type"])
|
|
264
|
+
if exec_result.is_fail():
|
|
265
|
+
print(f"{RED}❌ 执行失败: {exec_result.error}{RESET}")
|
|
265
266
|
else:
|
|
267
|
+
result = exec_result.unwrap()
|
|
266
268
|
if isinstance(result, list):
|
|
267
269
|
print(f"\n{GREEN}返回 {len(result)} 行:{RESET}")
|
|
268
270
|
for i, row in enumerate(result[:20]):
|
|
@@ -86,7 +86,7 @@ def handle_local(user_input, state):
|
|
|
86
86
|
if ps_exe:
|
|
87
87
|
res = subprocess.run([ps_exe, "-Command", cmd_text], capture_output=True, text=True, timeout=30)
|
|
88
88
|
else:
|
|
89
|
-
res = _run_cmd_safely(cmd_text, timeout=30
|
|
89
|
+
res = _run_cmd_safely(cmd_text, timeout=30)
|
|
90
90
|
else:
|
|
91
91
|
res = _run_cmd_safely(cmd_text, timeout=30)
|
|
92
92
|
out = res.stdout + res.stderr
|
|
@@ -106,14 +106,12 @@ def handle_local(user_input, state):
|
|
|
106
106
|
print(f"{RED}❌ 执行失败: {e}{RESET}")
|
|
107
107
|
|
|
108
108
|
|
|
109
|
-
def _run_cmd_safely(cmd_text: str, timeout: int = 30
|
|
110
|
-
"""
|
|
109
|
+
def _run_cmd_safely(cmd_text: str, timeout: int = 30):
|
|
110
|
+
"""安全执行命令:始终使用 shlex.split + shell=False,禁止回退到 shell=True。"""
|
|
111
111
|
try:
|
|
112
112
|
cmd_list = shlex.split(cmd_text)
|
|
113
113
|
except ValueError:
|
|
114
|
-
# shlex 解析失败(包含未闭合引号等)——
|
|
115
|
-
if allow_shell:
|
|
116
|
-
return subprocess.run(cmd_text, shell=True, capture_output=True, text=True, timeout=timeout)
|
|
114
|
+
# shlex 解析失败(包含未闭合引号等)—— 拒绝执行,不回退到 shell=True
|
|
117
115
|
return subprocess.CompletedProcess(args=cmd_text, returncode=1, stdout="", stderr="命令解析失败")
|
|
118
116
|
if not cmd_list:
|
|
119
117
|
return subprocess.CompletedProcess(args=cmd_text, returncode=1, stdout="", stderr="空命令")
|
|
@@ -43,7 +43,6 @@ class RAGManager:
|
|
|
43
43
|
"""RAG 知识库管理器 —— 向量存储 + 文件监控 + 检索生成"""
|
|
44
44
|
|
|
45
45
|
DEFAULT_MODEL = "all-MiniLM-L6-v2"
|
|
46
|
-
RERANKER_MODEL = "cross-encoder/ms-marco-MiniLM-L-6-v2"
|
|
47
46
|
CHUNK_SIZE = 500
|
|
48
47
|
CHUNK_OVERLAP = 50
|
|
49
48
|
|
|
@@ -53,7 +52,6 @@ class RAGManager:
|
|
|
53
52
|
self.client = None
|
|
54
53
|
self.collection = None
|
|
55
54
|
self.embedder = None
|
|
56
|
-
self.reranker = None
|
|
57
55
|
self._watcher_thread = None
|
|
58
56
|
self._stop_watcher = threading.Event()
|
|
59
57
|
self._file_state = {} # path -> (mtime, hash)
|
|
@@ -71,11 +69,6 @@ class RAGManager:
|
|
|
71
69
|
self.client = chroma.PersistentClient(path=str(self.db_path))
|
|
72
70
|
self.collection = self.client.get_or_create_collection(name="kb")
|
|
73
71
|
self.embedder = st.SentenceTransformer(self.DEFAULT_MODEL)
|
|
74
|
-
try:
|
|
75
|
-
from sentence_transformers import CrossEncoder
|
|
76
|
-
self.reranker = CrossEncoder(self.RERANKER_MODEL)
|
|
77
|
-
except Exception:
|
|
78
|
-
self.reranker = None
|
|
79
72
|
self._initialized = True
|
|
80
73
|
return True
|
|
81
74
|
|
|
@@ -215,94 +208,8 @@ class RAGManager:
|
|
|
215
208
|
|
|
216
209
|
# ---------- 检索生成 ----------
|
|
217
210
|
|
|
218
|
-
def
|
|
219
|
-
"""
|
|
220
|
-
if not self.reranker or not candidates:
|
|
221
|
-
return candidates, candidate_metas
|
|
222
|
-
|
|
223
|
-
pairs = [[question, doc] for doc in candidates]
|
|
224
|
-
scores = self.reranker.predict(pairs)
|
|
225
|
-
# 按分数降序排序
|
|
226
|
-
indexed = list(enumerate(scores))
|
|
227
|
-
indexed.sort(key=lambda x: x[1], reverse=True)
|
|
228
|
-
sorted_candidates = [candidates[i] for i, _ in indexed]
|
|
229
|
-
sorted_metas = [candidate_metas[i] for i, _ in indexed]
|
|
230
|
-
return sorted_candidates, sorted_metas
|
|
231
|
-
|
|
232
|
-
def _judge_best_doc(self, question, docs, client, model, lang):
|
|
233
|
-
"""让大模型从 top-3 片段中判定哪一条最适合用于回答"""
|
|
234
|
-
if len(docs) <= 1:
|
|
235
|
-
return 0
|
|
236
|
-
|
|
237
|
-
if lang == "zh":
|
|
238
|
-
judge_prompt = f"""你是一个知识库检索结果评估专家。以下是从向量库中检索出的候选片段,请评估哪一个最适合用来回答用户问题。
|
|
239
|
-
|
|
240
|
-
评估标准(每项1-10分):
|
|
241
|
-
1. 相关性:片段内容与用户问题的匹配程度
|
|
242
|
-
2. 完整性:片段是否包含足够的信息来回答问题
|
|
243
|
-
3. 准确性:片段信息是否直接对应问题的核心诉求
|
|
244
|
-
|
|
245
|
-
请对每条片段打分并给出简短理由,然后明确指出最佳片段的编号(只输出1/2/3中的一个数字)。
|
|
246
|
-
|
|
247
|
-
用户问题: {question}
|
|
248
|
-
|
|
249
|
-
片段1:
|
|
250
|
-
{docs[0] if len(docs) > 0 else "(无)"}
|
|
251
|
-
|
|
252
|
-
片段2:
|
|
253
|
-
{docs[1] if len(docs) > 1 else "(无)"}
|
|
254
|
-
|
|
255
|
-
片段3:
|
|
256
|
-
{docs[2] if len(docs) > 2 else "(无)"}
|
|
257
|
-
|
|
258
|
-
请严格按以下格式输出:
|
|
259
|
-
片段1评分: X分 | 理由: ...
|
|
260
|
-
片段2评分: X分 | 理由: ...
|
|
261
|
-
片段3评分: X分 | 理由: ...
|
|
262
|
-
最佳片段编号: N"""
|
|
263
|
-
else:
|
|
264
|
-
judge_prompt = f"""You are a knowledge base retrieval evaluation expert. Please evaluate which of the following candidate snippets is most suitable for answering the user's question.
|
|
265
|
-
|
|
266
|
-
Scoring criteria (1-10 each):
|
|
267
|
-
1. Relevance: How well the snippet matches the user's question
|
|
268
|
-
2. Completeness: Whether the snippet contains enough information to answer
|
|
269
|
-
3. Accuracy: Whether the information directly addresses the core question
|
|
270
|
-
|
|
271
|
-
Please score each snippet with a brief rationale, then clearly indicate the best snippet number (output only 1/2/3).
|
|
272
|
-
|
|
273
|
-
User Question: {question}
|
|
274
|
-
|
|
275
|
-
Snippet 1:
|
|
276
|
-
{docs[0] if len(docs) > 0 else "(none)"}
|
|
277
|
-
|
|
278
|
-
Snippet 2:
|
|
279
|
-
{docs[1] if len(docs) > 1 else "(none)"}
|
|
280
|
-
|
|
281
|
-
Snippet 3:
|
|
282
|
-
{docs[2] if len(docs) > 2 else "(none)"}
|
|
283
|
-
|
|
284
|
-
Strict output format:
|
|
285
|
-
Snippet 1 score: X | Rationale: ...
|
|
286
|
-
Snippet 2 score: X | Rationale: ...
|
|
287
|
-
Snippet 3 score: X | Rationale: ...
|
|
288
|
-
Best snippet number: N"""
|
|
289
|
-
|
|
290
|
-
from fr_cli.core.stream import stream_cnt
|
|
291
|
-
messages = [{"role": "user", "content": judge_prompt}]
|
|
292
|
-
txt, _, _, _ = stream_cnt(client, model, messages, lang, custom_prefix="", max_tokens=1024, silent=True)
|
|
293
|
-
# 从回复中提取最佳片段编号
|
|
294
|
-
import re
|
|
295
|
-
match = re.search(r"最佳片段编号[::]\s*(\d)", txt)
|
|
296
|
-
if not match:
|
|
297
|
-
match = re.search(r"Best snippet number[::]\s*(\d)", txt)
|
|
298
|
-
if match:
|
|
299
|
-
idx = int(match.group(1)) - 1
|
|
300
|
-
if 0 <= idx < len(docs):
|
|
301
|
-
return idx
|
|
302
|
-
return 0
|
|
303
|
-
|
|
304
|
-
def query(self, question, client, model, lang="zh", top_k=5):
|
|
305
|
-
"""向量检索 -> Rerank 重排序 -> 大模型判定最佳片段 -> 生成回答"""
|
|
211
|
+
def query(self, question, client, model, lang="zh", top_k=8):
|
|
212
|
+
"""向量检索 -> 取 Top-K 片段 -> 大模型综合生成回答"""
|
|
306
213
|
if not self._ensure_initialized():
|
|
307
214
|
return None, "缺少依赖: pip install chromadb sentence-transformers"
|
|
308
215
|
|
|
@@ -310,10 +217,12 @@ Best snippet number: N"""
|
|
|
310
217
|
if self.collection.count() == 0:
|
|
311
218
|
return None, "知识库为空,请先设置知识库目录并同步。"
|
|
312
219
|
|
|
313
|
-
# Step 1: 向量检索,扩大候选池(取更多候选供 reranker 筛选)
|
|
314
|
-
retrieve_k = max(top_k * 3, 15)
|
|
315
220
|
q_emb = self.embedder.encode([question]).tolist()
|
|
316
|
-
results = self.collection.query(
|
|
221
|
+
results = self.collection.query(
|
|
222
|
+
query_embeddings=q_emb,
|
|
223
|
+
n_results=max(top_k, 1),
|
|
224
|
+
include=["documents", "metadatas"],
|
|
225
|
+
)
|
|
317
226
|
|
|
318
227
|
candidates = []
|
|
319
228
|
candidate_metas = []
|
|
@@ -326,31 +235,16 @@ Best snippet number: N"""
|
|
|
326
235
|
if not candidates:
|
|
327
236
|
return None, "未检索到相关知识。"
|
|
328
237
|
|
|
329
|
-
#
|
|
330
|
-
reranked_docs, reranked_metas = self._rerank(question, candidates, candidate_metas)
|
|
331
|
-
|
|
332
|
-
# Step 3: 取 top-3
|
|
333
|
-
top3_docs = reranked_docs[:3]
|
|
334
|
-
top3_metas = reranked_metas[:3]
|
|
335
|
-
|
|
336
|
-
# Step 4: 大模型判定哪一条最适合
|
|
337
|
-
best_idx = self._judge_best_doc(question, top3_docs, client, model, lang)
|
|
338
|
-
best_doc = top3_docs[best_idx]
|
|
339
|
-
best_meta = top3_metas[best_idx]
|
|
340
|
-
best_source = best_meta.get("source", "未知")
|
|
341
|
-
|
|
342
|
-
# Step 5: 构建增强 prompt,将 top-3 全部放入,但特别标注最佳片段
|
|
238
|
+
# 构造带来源标注的上下文
|
|
343
239
|
doc_blocks = []
|
|
344
|
-
for idx, (doc, meta) in enumerate(zip(
|
|
345
|
-
marker = " ★【最佳】" if idx - 1 == best_idx else ""
|
|
240
|
+
for idx, (doc, meta) in enumerate(zip(candidates, candidate_metas), 1):
|
|
346
241
|
source = meta.get("source", "未知")
|
|
347
|
-
doc_blocks.append(f"片段{idx}
|
|
242
|
+
doc_blocks.append(f"片段{idx} [来源: {source}]\n{doc}")
|
|
348
243
|
|
|
349
244
|
context = "\n\n---\n\n".join(doc_blocks)
|
|
350
245
|
|
|
351
246
|
if lang == "zh":
|
|
352
|
-
prompt = f"""
|
|
353
|
-
其中标注 ★【最佳】的片段是大模型判定最适合回答用户问题的来源。
|
|
247
|
+
prompt = f"""你是一个知识库问答助手。以下是从知识库中向量检索出的相关片段,请基于这些片段综合回答用户问题。
|
|
354
248
|
|
|
355
249
|
知识片段:
|
|
356
250
|
{context}
|
|
@@ -358,15 +252,13 @@ Best snippet number: N"""
|
|
|
358
252
|
用户问题: {question}
|
|
359
253
|
|
|
360
254
|
回答要求:
|
|
361
|
-
1.
|
|
362
|
-
2.
|
|
363
|
-
3.
|
|
364
|
-
4.
|
|
365
|
-
5. 请用中文给出准确、简洁的回答
|
|
255
|
+
1. 优先基于上述片段内容回答,可综合多个片段
|
|
256
|
+
2. 如果片段信息不足以完整回答,请明确说明
|
|
257
|
+
3. 引用来源时请标注 [来源: 文件名]
|
|
258
|
+
4. 请用中文给出准确、简洁的回答
|
|
366
259
|
"""
|
|
367
260
|
else:
|
|
368
|
-
prompt = f"""You are a knowledge base Q&A assistant. Below are
|
|
369
|
-
The snippet marked with ★【BEST】has been judged by the model as the most suitable source for answering the user's question.
|
|
261
|
+
prompt = f"""You are a knowledge base Q&A assistant. Below are relevant snippets retrieved from the knowledge base. Please synthesize an answer based on these snippets.
|
|
370
262
|
|
|
371
263
|
Knowledge Snippets:
|
|
372
264
|
{context}
|
|
@@ -374,11 +266,10 @@ Knowledge Snippets:
|
|
|
374
266
|
User Question: {question}
|
|
375
267
|
|
|
376
268
|
Instructions:
|
|
377
|
-
1.
|
|
378
|
-
2. If the
|
|
379
|
-
3.
|
|
380
|
-
4.
|
|
381
|
-
5. Give an accurate and concise answer
|
|
269
|
+
1. Base your answer on the snippets above; you may synthesize multiple snippets
|
|
270
|
+
2. If the snippets are insufficient, state so clearly
|
|
271
|
+
3. Cite sources as [Source: filename]
|
|
272
|
+
4. Give an accurate and concise answer
|
|
382
273
|
"""
|
|
383
274
|
|
|
384
275
|
from fr_cli.core.stream import stream_cnt
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
"""
|
|
8
8
|
from fr_cli.conf.config import load_namespace, save_namespace
|
|
9
9
|
from fr_cli.conf.paths import REMOTE_HOSTS_FILE
|
|
10
|
+
from fr_cli.core.result import Result
|
|
10
11
|
|
|
11
12
|
_NS_KEY = "remote"
|
|
12
13
|
REMOTE_CFG_PATH = REMOTE_HOSTS_FILE # 保留用于一次性迁移
|
|
@@ -61,7 +62,7 @@ def delete_host(alias):
|
|
|
61
62
|
|
|
62
63
|
|
|
63
64
|
def _exec_ssh(host_cfg, command):
|
|
64
|
-
"""通过 ssh 命令执行远程操作(使用 paramiko
|
|
65
|
+
"""通过 ssh 命令执行远程操作(使用 paramiko 避免命令注入),返回 Result[str]。"""
|
|
65
66
|
ip = host_cfg["ip"]
|
|
66
67
|
port = host_cfg.get("port", 22)
|
|
67
68
|
user = host_cfg["user"]
|
|
@@ -71,7 +72,7 @@ def _exec_ssh(host_cfg, command):
|
|
|
71
72
|
try:
|
|
72
73
|
import paramiko
|
|
73
74
|
except ImportError:
|
|
74
|
-
return
|
|
75
|
+
return Result.fail("缺少 paramiko (pip install paramiko)")
|
|
75
76
|
|
|
76
77
|
client = paramiko.SSHClient()
|
|
77
78
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
@@ -93,17 +94,17 @@ def _exec_ssh(host_cfg, command):
|
|
|
93
94
|
out = stdout.read().decode("utf-8", errors="ignore")
|
|
94
95
|
err = stderr.read().decode("utf-8", errors="ignore")
|
|
95
96
|
client.close()
|
|
96
|
-
return out + err
|
|
97
|
+
return Result.ok(out + err)
|
|
97
98
|
except Exception as e:
|
|
98
|
-
return
|
|
99
|
+
return Result.fail(str(e))
|
|
99
100
|
|
|
100
101
|
|
|
101
102
|
def _detect_os(host_cfg):
|
|
102
|
-
"""
|
|
103
|
-
|
|
104
|
-
if
|
|
105
|
-
return
|
|
106
|
-
return
|
|
103
|
+
"""探测远程主机操作系统,返回 Result[str]。"""
|
|
104
|
+
result = _exec_ssh(host_cfg, "uname -s")
|
|
105
|
+
if result.is_fail():
|
|
106
|
+
return result
|
|
107
|
+
return Result.ok(result.unwrap().strip() or "Linux")
|
|
107
108
|
|
|
108
109
|
|
|
109
110
|
def handle_remote(user_input, state):
|
|
@@ -150,10 +151,11 @@ def handle_remote(user_input, state):
|
|
|
150
151
|
return
|
|
151
152
|
|
|
152
153
|
# 探测 OS
|
|
153
|
-
|
|
154
|
-
if
|
|
155
|
-
print(f"{RED}无法连接主机 [{alias}]: {
|
|
154
|
+
os_result = _detect_os(host_cfg)
|
|
155
|
+
if os_result.is_fail():
|
|
156
|
+
print(f"{RED}无法连接主机 [{alias}]: {os_result.error}{RESET}")
|
|
156
157
|
return
|
|
158
|
+
os_name = os_result.unwrap()
|
|
157
159
|
|
|
158
160
|
prompt = REMOTE_SYS_PROMPT.format(os_name=os_name)
|
|
159
161
|
messages = [
|
|
@@ -182,10 +184,11 @@ def handle_remote(user_input, state):
|
|
|
182
184
|
print(f"{DIM}已取消。{RESET}")
|
|
183
185
|
return
|
|
184
186
|
|
|
185
|
-
|
|
186
|
-
if
|
|
187
|
-
print(f"{RED}❌ 执行失败: {
|
|
187
|
+
exec_result = _exec_ssh(host_cfg, cmd_text)
|
|
188
|
+
if exec_result.is_fail():
|
|
189
|
+
print(f"{RED}❌ 执行失败: {exec_result.error}{RESET}")
|
|
188
190
|
else:
|
|
191
|
+
out = exec_result.unwrap()
|
|
189
192
|
if out.strip():
|
|
190
193
|
print(f"\n{GREEN}{out.strip()[:3000]}{RESET}")
|
|
191
194
|
else:
|