fr-cli 2.4.1__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.1 → fr_cli-2.5.0}/MANIFEST.in +1 -0
- {fr_cli-2.4.1/fr_cli.egg-info → fr_cli-2.5.0}/PKG-INFO +44 -3
- {fr_cli-2.4.1 → fr_cli-2.5.0}/README.md +42 -2
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/README.md +14 -4
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/WEAPON.MD +12 -44
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/__init__.py +1 -1
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/addon/plugin.py +5 -6
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/artifact_detector.py +0 -1
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/builtins/db.py +18 -15
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/builtins/local.py +4 -6
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/builtins/rag.py +20 -129
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/builtins/rag_watcher_daemon.py +1 -1
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/builtins/remote.py +29 -21
- {fr_cli-2.4.1 → 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.1 → 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.1 → 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.1 → fr_cli-2.5.0}/fr_cli/agent/hermes.py +25 -13
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/hermes_daemon.py +1 -3
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/manager.py +32 -28
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/master.py +22 -42
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/personality.py +1 -1
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/remote.py +10 -25
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/server.py +67 -14
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/shell_mode.py +1 -4
- {fr_cli-2.4.1 → 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.1 → fr_cli-2.5.0}/fr_cli/breakthrough/update.py +48 -39
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/command/executor.py +87 -47
- {fr_cli-2.4.1 → 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.1 → fr_cli-2.5.0}/fr_cli/command/registered/image.py +5 -4
- {fr_cli-2.4.1 → 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.1 → 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.1 → fr_cli-2.5.0}/fr_cli/command/registered/web.py +7 -6
- {fr_cli-2.4.1 → 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.1 → fr_cli-2.5.0}/fr_cli/conf/config.py +80 -12
- fr_cli-2.5.0/fr_cli/conf/default_models.yaml +298 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/conf/paths.py +4 -3
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/core/chat.py +120 -1
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/core/core.py +104 -60
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/core/errors.py +0 -3
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/core/llm.py +13 -7
- fr_cli-2.5.0/fr_cli/core/model_factory.py +140 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/core/optimizations.py +13 -8
- fr_cli-2.5.0/fr_cli/core/plan.py +488 -0
- {fr_cli-2.4.1 → 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.1 → fr_cli-2.5.0}/fr_cli/core/stream.py +0 -1
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/core/sysmon.py +2 -5
- {fr_cli-2.4.1 → 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.1 → fr_cli-2.5.0}/fr_cli/gatekeeper/daemon.py +0 -1
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/gatekeeper/manager.py +27 -29
- fr_cli-2.5.0/fr_cli/lang/i18n.py +25 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/lang/translations/en.py +19 -9
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/lang/translations/zh.py +16 -9
- fr_cli-2.5.0/fr_cli/main.py +284 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/memory/context.py +29 -40
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/memory/history.py +9 -12
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/memory/session.py +8 -15
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/actions.py +1 -1
- fr_cli-2.5.0/fr_cli/repl/batch.py +78 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/bootstrap.py +11 -9
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands/__init__.py +4 -1
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands/_common.py +32 -24
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands/agent.py +20 -31
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands/base.py +12 -22
- fr_cli-2.5.0/fr_cli/repl/commands/build.py +62 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands/config.py +51 -33
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands/cron.py +2 -20
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands/dataframe.py +1 -21
- {fr_cli-2.4.1 → 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.1 → 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.1 → fr_cli-2.5.0}/fr_cli/repl/commands/rag.py +1 -21
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands/remote_agent.py +6 -25
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands/session.py +11 -15
- fr_cli-2.5.0/fr_cli/repl/commands/stock.py +127 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands/system.py +26 -42
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/queue.py +1 -1
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/quick_actions.py +2 -5
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/router.py +15 -4
- {fr_cli-2.4.1 → 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.1 → fr_cli-2.5.0}/fr_cli/ui/banner.py +5 -6
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/ui/buddha.py +5 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/ui/prompt.py +60 -14
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/ui/splash.py +1 -2
- fr_cli-2.5.0/fr_cli/ui/ui.py +110 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/ui/web_config.py +21 -21
- fr_cli-2.5.0/fr_cli/weapon/charts.py +223 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/weapon/cron.py +28 -4
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/weapon/dataframe.py +18 -10
- {fr_cli-2.4.1 → 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.1 → fr_cli-2.5.0}/fr_cli/weapon/launcher.py +8 -8
- {fr_cli-2.4.1 → 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.1 → fr_cli-2.5.0}/fr_cli/weapon/mail.py +20 -19
- fr_cli-2.5.0/fr_cli/weapon/mcp.py +354 -0
- 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.1 → fr_cli-2.5.0}/fr_cli/weapon/vision.py +18 -10
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/weapon/web.py +20 -15
- {fr_cli-2.4.1 → fr_cli-2.5.0/fr_cli.egg-info}/PKG-INFO +44 -3
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli.egg-info/SOURCES.txt +57 -33
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli.egg-info/requires.txt +1 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/pyproject.toml +22 -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.5.0/tests/test_batch_mode.py +120 -0
- 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.5.0/tests/test_help_update.py +62 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/tests/test_integration_real.py +24 -23
- 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.1 → 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.1 → fr_cli-2.5.0}/tests/test_model_config.py +15 -18
- fr_cli-2.5.0/tests/test_no_color_prompt_toolkit.py +123 -0
- 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.5.0/tests/test_plugin_exec.py +73 -0
- fr_cli-2.5.0/tests/test_prompt_completion.py +67 -0
- 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.5.0/tests/test_vfs_diff.py +75 -0
- fr_cli-2.5.0/tests/test_workflow.py +143 -0
- fr_cli-2.4.1/fr_cli/agent/a2a.py +0 -568
- fr_cli-2.4.1/fr_cli/agent/acp.py +0 -199
- fr_cli-2.4.1/fr_cli/agent/builtins/powerful_agent_template.py +0 -916
- fr_cli-2.4.1/fr_cli/agent/coding_helper.py +0 -811
- fr_cli-2.4.1/fr_cli/agent/context_files.py +0 -160
- fr_cli-2.4.1/fr_cli/agent/gateway.py +0 -234
- fr_cli-2.4.1/fr_cli/agent/generator.py +0 -105
- fr_cli-2.4.1/fr_cli/agent/image_and_parallel.py +0 -1020
- fr_cli-2.4.1/fr_cli/agent/plugin_system.py +0 -195
- fr_cli-2.4.1/fr_cli/agent/workflow.py +0 -174
- fr_cli-2.4.1/fr_cli/agent/workflow_system/__init__.py +0 -14
- fr_cli-2.4.1/fr_cli/agent/workflow_system/engine.py +0 -414
- fr_cli-2.4.1/fr_cli/agent/workflow_system/executor.py +0 -217
- fr_cli-2.4.1/fr_cli/agent/workflow_system/manager.py +0 -84
- fr_cli-2.4.1/fr_cli/agent/workflow_system/models.py +0 -195
- fr_cli-2.4.1/fr_cli/agent/workflow_system/monitor.py +0 -68
- fr_cli-2.4.1/fr_cli/agent/workflow_system/tools.py +0 -224
- fr_cli-2.4.1/fr_cli/agent/workflow_system.py +0 -23
- fr_cli-2.4.1/fr_cli/command/handlers/__init__.py +0 -15
- fr_cli-2.4.1/fr_cli/command/handlers/agent.py +0 -73
- fr_cli-2.4.1/fr_cli/command/handlers/app.py +0 -31
- fr_cli-2.4.1/fr_cli/command/handlers/config.py +0 -167
- fr_cli-2.4.1/fr_cli/command/handlers/cron.py +0 -56
- fr_cli-2.4.1/fr_cli/command/handlers/dataframe.py +0 -34
- fr_cli-2.4.1/fr_cli/command/handlers/disk.py +0 -84
- fr_cli-2.4.1/fr_cli/command/handlers/fs.py +0 -95
- fr_cli-2.4.1/fr_cli/command/handlers/mail.py +0 -81
- fr_cli-2.4.1/fr_cli/command/handlers/mcp.py +0 -46
- fr_cli-2.4.1/fr_cli/command/handlers/other.py +0 -34
- fr_cli-2.4.1/fr_cli/command/handlers/session.py +0 -79
- fr_cli-2.4.1/fr_cli/command/handlers/system.py +0 -189
- fr_cli-2.4.1/fr_cli/command/handlers/vision.py +0 -38
- fr_cli-2.4.1/fr_cli/command/handlers/web.py +0 -34
- fr_cli-2.4.1/fr_cli/command/registered/fs.py +0 -84
- fr_cli-2.4.1/fr_cli/command/registered/services.py +0 -236
- fr_cli-2.4.1/fr_cli/command/security.py +0 -30
- fr_cli-2.4.1/fr_cli/core/model_factory.py +0 -326
- fr_cli-2.4.1/fr_cli/lang/i18n.py +0 -8
- fr_cli-2.4.1/fr_cli/main.py +0 -122
- fr_cli-2.4.1/fr_cli/repl/commands/fs.py +0 -66
- fr_cli-2.4.1/fr_cli/security/security.py +0 -50
- fr_cli-2.4.1/fr_cli/ui/ui.py +0 -64
- fr_cli-2.4.1/fr_cli/weapon/fs.py +0 -206
- fr_cli-2.4.1/fr_cli/weapon/mcp.py +0 -383
- fr_cli-2.4.1/tests/test_a2a_and_providers.py +0 -447
- fr_cli-2.4.1/tests/test_new_features.py +0 -449
- {fr_cli-2.4.1 → fr_cli-2.5.0}/LICENSE +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/__init__.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/builtins/__init__.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/builtins/_utils.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/agent/master_prompt.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/assets/splash.jpeg +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/command/__init__.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/conf/__init__.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/conf/wizard.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/core/cache.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/core/intent.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/core/project.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/core/recommender.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/gatekeeper/__init__.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/lang/translations/__init__.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/__init__.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/repl/commands.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli/ui/markdown.py +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli.egg-info/dependency_links.txt +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli.egg-info/entry_points.txt +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/fr_cli.egg-info/top_level.txt +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/setup.cfg +0 -0
- {fr_cli-2.4.1 → fr_cli-2.5.0}/tests/test_new_providers.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,10 +177,41 @@ 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
|
```
|
|
182
192
|
|
|
193
|
+
### 🖥️ 非交互 / 批处理模式
|
|
194
|
+
|
|
195
|
+
fr-cli 支持在不进入 REPL 的情况下执行单次命令或单次 AI 对话,适用于脚本、cron、管道等场景:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# 执行一条 slash 命令后退出
|
|
199
|
+
fr-cli -c "/model current"
|
|
200
|
+
fr-cli -c "/ls"
|
|
201
|
+
|
|
202
|
+
# 向 AI 提问后退出
|
|
203
|
+
fr-cli "请总结 README.md"
|
|
204
|
+
fr-cli -p "Python 如何读取 JSON?"
|
|
205
|
+
|
|
206
|
+
# 从文件或标准输入读取提示词
|
|
207
|
+
cat article.txt | fr-cli -s
|
|
208
|
+
fr-cli -f prompt.txt
|
|
209
|
+
|
|
210
|
+
# 静默模式(跳过启动 banner,只输出核心结果)
|
|
211
|
+
fr-cli -q -c "/model current"
|
|
212
|
+
fr-cli -q -p "1+1等于几"
|
|
213
|
+
```
|
|
214
|
+
|
|
183
215
|
### 🤖 AI 模型配置
|
|
184
216
|
|
|
185
217
|
```bash
|
|
@@ -390,7 +422,7 @@ fr_cli/
|
|
|
390
422
|
|
|
391
423
|
## 📂 配置目录
|
|
392
424
|
|
|
393
|
-
> 配置统一在 `~/.fr_cli/`
|
|
425
|
+
> 配置统一在 `~/.fr_cli/` 目录下,旧路径(如 `~/.zhipu_cli_config.json`)会在首次启动时自动迁移到新路径。
|
|
394
426
|
|
|
395
427
|
| 路径 | 说明 |
|
|
396
428
|
|------|------|
|
|
@@ -445,6 +477,15 @@ fr_cli/
|
|
|
445
477
|
- QQ/163 邮箱需使用「授权码」而非登录密码
|
|
446
478
|
- 授权码在邮箱设置 → 账户 → 开启 IMAP/SMTP 服务后生成
|
|
447
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
|
+
|
|
448
489
|
**Q: 搜索功能无法使用?**
|
|
449
490
|
```bash
|
|
450
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,10 +102,41 @@ 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
|
```
|
|
108
117
|
|
|
118
|
+
### 🖥️ 非交互 / 批处理模式
|
|
119
|
+
|
|
120
|
+
fr-cli 支持在不进入 REPL 的情况下执行单次命令或单次 AI 对话,适用于脚本、cron、管道等场景:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# 执行一条 slash 命令后退出
|
|
124
|
+
fr-cli -c "/model current"
|
|
125
|
+
fr-cli -c "/ls"
|
|
126
|
+
|
|
127
|
+
# 向 AI 提问后退出
|
|
128
|
+
fr-cli "请总结 README.md"
|
|
129
|
+
fr-cli -p "Python 如何读取 JSON?"
|
|
130
|
+
|
|
131
|
+
# 从文件或标准输入读取提示词
|
|
132
|
+
cat article.txt | fr-cli -s
|
|
133
|
+
fr-cli -f prompt.txt
|
|
134
|
+
|
|
135
|
+
# 静默模式(跳过启动 banner,只输出核心结果)
|
|
136
|
+
fr-cli -q -c "/model current"
|
|
137
|
+
fr-cli -q -p "1+1等于几"
|
|
138
|
+
```
|
|
139
|
+
|
|
109
140
|
### 🤖 AI 模型配置
|
|
110
141
|
|
|
111
142
|
```bash
|
|
@@ -316,7 +347,7 @@ fr_cli/
|
|
|
316
347
|
|
|
317
348
|
## 📂 配置目录
|
|
318
349
|
|
|
319
|
-
> 配置统一在 `~/.fr_cli/`
|
|
350
|
+
> 配置统一在 `~/.fr_cli/` 目录下,旧路径(如 `~/.zhipu_cli_config.json`)会在首次启动时自动迁移到新路径。
|
|
320
351
|
|
|
321
352
|
| 路径 | 说明 |
|
|
322
353
|
|------|------|
|
|
@@ -371,6 +402,15 @@ fr_cli/
|
|
|
371
402
|
- QQ/163 邮箱需使用「授权码」而非登录密码
|
|
372
403
|
- 授权码在邮箱设置 → 账户 → 开启 IMAP/SMTP 服务后生成
|
|
373
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
|
+
|
|
374
414
|
**Q: 搜索功能无法使用?**
|
|
375
415
|
```bash
|
|
376
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
|
|
@@ -176,7 +182,7 @@
|
|
|
176
182
|
- AI 调用: `mcp_call({"server": "服务器名", "tool": "工具名", "arguments": {...}})`
|
|
177
183
|
- REPL 管理: `/mcp_list`, `/mcp_add`, `/mcp_del`, `/mcp_enable`, `/mcp_disable`, `/mcp_refresh`
|
|
178
184
|
- **触发关键词**: mcp, 外部工具, 外部神通, 调用工具, use tool, invoke tool
|
|
179
|
-
- **配置持久化**: `~/.
|
|
185
|
+
- **配置持久化**: `~/.fr_cli/config.json` 的 `mcp.servers` 字段
|
|
180
186
|
- **示例**:
|
|
181
187
|
```
|
|
182
188
|
/mcp_add fs npx -y @modelcontextprotocol/server-filesystem /tmp
|
|
@@ -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
|
|
|
@@ -38,19 +37,19 @@ def exec_plugin(name, path, args, lang):
|
|
|
38
37
|
print(f"{RED}❌ 非法插件名: {name}{RESET}")
|
|
39
38
|
return
|
|
40
39
|
|
|
41
|
-
import json
|
|
40
|
+
import json
|
|
42
41
|
# 使用 json.dumps 安全序列化参数,防止字符串逃逸注入
|
|
43
42
|
safe_args = json.dumps(args)
|
|
44
43
|
runner_code = f"""
|
|
45
44
|
import sys, json, runpy
|
|
46
|
-
sys.path.insert(0, {
|
|
47
|
-
mod = runpy.run_module({
|
|
45
|
+
sys.path.insert(0, {json.dumps(str(PLUGIN_DIR), ensure_ascii=False)})
|
|
46
|
+
mod = runpy.run_module({json.dumps(name, ensure_ascii=False)}, run_name='__main__')
|
|
48
47
|
run_fn = mod.get('run')
|
|
49
48
|
if run_fn is None:
|
|
50
49
|
print("Error: 插件缺少 run 函数", file=sys.stderr)
|
|
51
50
|
else:
|
|
52
51
|
try:
|
|
53
|
-
print(run_fn(json.loads({safe_args})))
|
|
52
|
+
print(run_fn(json.loads({json.dumps(safe_args, ensure_ascii=False)})))
|
|
54
53
|
except Exception as e:
|
|
55
54
|
print(f"Error: {{e}}", file=sys.stderr)
|
|
56
55
|
"""
|
|
@@ -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}")
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"""
|
|
2
2
|
@db 内置 Agent —— 数据库智能助手
|
|
3
3
|
支持 MySQL / PostgreSQL / SQL Server / Oracle 的 Schema 分析和 SQL 生成。
|
|
4
|
+
|
|
5
|
+
数据库连接配置统一收敛到 ~/.fr_cli/config.json 的 databases 命名空间。
|
|
4
6
|
"""
|
|
5
|
-
from
|
|
7
|
+
from fr_cli.conf.config import load_namespace, save_namespace
|
|
6
8
|
from fr_cli.conf.paths import DATABASE_FILE
|
|
9
|
+
from fr_cli.core.result import Result
|
|
7
10
|
|
|
8
|
-
|
|
11
|
+
_NS_KEY = "databases"
|
|
12
|
+
DB_CFG_PATH = DATABASE_FILE # 保留用于一次性迁移
|
|
9
13
|
|
|
10
14
|
DB_SYS_PROMPT = """你是一个数据库专家。请根据以下数据库 Schema 信息和用户需求,生成最合适的 SQL 语句。
|
|
11
15
|
|
|
@@ -25,13 +29,11 @@ Schema 信息:
|
|
|
25
29
|
|
|
26
30
|
|
|
27
31
|
def _load_dbs():
|
|
28
|
-
|
|
29
|
-
return load_json_config(DB_CFG_PATH)
|
|
32
|
+
return load_namespace(_NS_KEY, default={}, old_path=DB_CFG_PATH)
|
|
30
33
|
|
|
31
34
|
|
|
32
35
|
def _save_dbs(dbs):
|
|
33
|
-
|
|
34
|
-
save_json_config(DB_CFG_PATH, dbs)
|
|
36
|
+
save_namespace(_NS_KEY, dbs)
|
|
35
37
|
|
|
36
38
|
|
|
37
39
|
def _connect(db_cfg):
|
|
@@ -162,12 +164,12 @@ def _has_multiple_statements(sql: str) -> bool:
|
|
|
162
164
|
|
|
163
165
|
|
|
164
166
|
def _exec_sql(conn, sql, db_type):
|
|
165
|
-
"""执行 SQL
|
|
167
|
+
"""执行 SQL 并返回 Result。"""
|
|
166
168
|
cursor = conn.cursor()
|
|
167
169
|
try:
|
|
168
170
|
sql = sql.strip()
|
|
169
171
|
if _has_multiple_statements(sql):
|
|
170
|
-
return
|
|
172
|
+
return Result.fail("禁止执行多条 SQL 语句(检测到语句分隔符 ';')")
|
|
171
173
|
sql = sql.rstrip(";")
|
|
172
174
|
cursor.execute(sql)
|
|
173
175
|
|
|
@@ -175,16 +177,16 @@ def _exec_sql(conn, sql, db_type):
|
|
|
175
177
|
if sql.lower().startswith("select") or sql.lower().startswith("show") or sql.lower().startswith("desc"):
|
|
176
178
|
rows = cursor.fetchall()
|
|
177
179
|
if db_type == "mysql":
|
|
178
|
-
return rows
|
|
180
|
+
return Result.ok(rows)
|
|
179
181
|
else:
|
|
180
182
|
# 将 pyodbc/psycopg2 的行转为字典列表
|
|
181
183
|
cols = [desc[0] for desc in cursor.description] if cursor.description else []
|
|
182
|
-
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])
|
|
183
185
|
else:
|
|
184
186
|
conn.commit()
|
|
185
|
-
return f"受影响行数: {cursor.rowcount}"
|
|
187
|
+
return Result.ok(f"受影响行数: {cursor.rowcount}")
|
|
186
188
|
except Exception as e:
|
|
187
|
-
return
|
|
189
|
+
return Result.fail(str(e))
|
|
188
190
|
|
|
189
191
|
|
|
190
192
|
def handle_db(user_input, state):
|
|
@@ -258,10 +260,11 @@ def handle_db(user_input, state):
|
|
|
258
260
|
print(f"{DIM}已取消。{RESET}")
|
|
259
261
|
return
|
|
260
262
|
|
|
261
|
-
|
|
262
|
-
if
|
|
263
|
-
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}")
|
|
264
266
|
else:
|
|
267
|
+
result = exec_result.unwrap()
|
|
265
268
|
if isinstance(result, list):
|
|
266
269
|
print(f"\n{GREEN}返回 {len(result)} 行:{RESET}")
|
|
267
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="空命令")
|