fr-cli 2.5.0__tar.gz → 2.6.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.5.0/fr_cli.egg-info → fr_cli-2.6.0}/PKG-INFO +1 -1
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/__init__.py +1 -1
- fr_cli-2.6.0/fr_cli/agent/artifact_detector.py +153 -0
- fr_cli-2.6.0/fr_cli/agent/builtins/spider/__init__.py +14 -0
- fr_cli-2.6.0/fr_cli/agent/builtins/spider/analyzer.py +157 -0
- fr_cli-2.6.0/fr_cli/agent/builtins/spider/crawler.py +220 -0
- fr_cli-2.6.0/fr_cli/agent/builtins/spider/deps.py +83 -0
- fr_cli-2.6.0/fr_cli/agent/builtins/spider/evasion.py +231 -0
- fr_cli-2.6.0/fr_cli/agent/builtins/spider/fetcher.py +256 -0
- fr_cli-2.6.0/fr_cli/agent/builtins/spider/memory.py +84 -0
- fr_cli-2.6.0/fr_cli/agent/hermes/__init__.py +64 -0
- fr_cli-2.6.0/fr_cli/agent/hermes/engine.py +487 -0
- fr_cli-2.6.0/fr_cli/agent/hermes/managers.py +251 -0
- fr_cli-2.6.0/fr_cli/agent/hermes/models.py +141 -0
- fr_cli-2.6.0/fr_cli/agent/hermes/scheduler.py +47 -0
- fr_cli-2.6.0/fr_cli/agent/hermes_daemon.py +449 -0
- fr_cli-2.6.0/fr_cli/agent/hermes_daemon_process.py +125 -0
- fr_cli-2.6.0/fr_cli/agent/hermes_manager.py +199 -0
- fr_cli-2.6.0/fr_cli/agent/master.py +109 -0
- fr_cli-2.6.0/fr_cli/agent/master_loop.py +269 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/master_prompt.py +7 -2
- fr_cli-2.6.0/fr_cli/agent/master_prompt_builder.py +120 -0
- fr_cli-2.6.0/fr_cli/agent/master_reflect.py +177 -0
- fr_cli-2.6.0/fr_cli/agent/master_storage.py +185 -0
- fr_cli-2.6.0/fr_cli/agent/review_queue.py +136 -0
- fr_cli-2.6.0/fr_cli/agent/shell_mode.py +52 -0
- fr_cli-2.6.0/fr_cli/command/registered/dynamic_build.py +133 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/session_config.py +0 -1
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registry.py +18 -1
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/security.py +40 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/conf/config.py +3 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/conf/paths.py +13 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/chat.py +62 -7
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/core.py +243 -0
- fr_cli-2.6.0/fr_cli/core/error_ledger.py +91 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/intent.py +7 -3
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/llm.py +0 -1
- fr_cli-2.6.0/fr_cli/core/plan/__init__.py +50 -0
- fr_cli-2.6.0/fr_cli/core/plan/executor.py +182 -0
- fr_cli-2.6.0/fr_cli/core/plan/generator.py +158 -0
- fr_cli-2.6.0/fr_cli/core/plan/prompts.py +102 -0
- fr_cli-2.6.0/fr_cli/core/plan/storage.py +56 -0
- fr_cli-2.6.0/fr_cli/dynamic_builder/gap_analyzer.py +161 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/dynamic_builder/planner.py +2 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/dynamic_builder/registry_manager.py +18 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/dynamic_builder/runner.py +20 -5
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/lang/translations/en.py +3 -3
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/lang/translations/zh.py +3 -3
- fr_cli-2.6.0/fr_cli/memory/compress.py +160 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/__init__.py +2 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/build.py +21 -1
- fr_cli-2.6.0/fr_cli/repl/commands/config/__init__.py +22 -0
- fr_cli-2.6.0/fr_cli/repl/commands/config/key.py +207 -0
- fr_cli-2.6.0/fr_cli/repl/commands/config/misc.py +106 -0
- fr_cli-2.6.0/fr_cli/repl/commands/config/model.py +239 -0
- fr_cli-2.6.0/fr_cli/repl/commands/system/__init__.py +42 -0
- fr_cli-2.6.0/fr_cli/repl/commands/system/autostart.py +52 -0
- fr_cli-2.6.0/fr_cli/repl/commands/system/context.py +80 -0
- fr_cli-2.6.0/fr_cli/repl/commands/system/hermes_cmd.py +213 -0
- fr_cli-2.6.0/fr_cli/repl/commands/system/launcher.py +39 -0
- fr_cli-2.6.0/fr_cli/repl/commands/system/server.py +61 -0
- fr_cli-2.6.0/fr_cli/repl/commands/system/setup.py +15 -0
- fr_cli-2.6.0/fr_cli/repl/commands/system/status.py +89 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/router.py +11 -0
- fr_cli-2.6.0/fr_cli/security/policy.py +60 -0
- fr_cli-2.6.0/fr_cli/ui/prompt/__init__.py +39 -0
- fr_cli-2.6.0/fr_cli/ui/prompt/completer.py +359 -0
- fr_cli-2.6.0/fr_cli/ui/prompt/fallback.py +89 -0
- fr_cli-2.6.0/fr_cli/ui/prompt/status.py +80 -0
- fr_cli-2.6.0/fr_cli/ui/prompt/tui.py +384 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0/fr_cli.egg-info}/PKG-INFO +1 -1
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli.egg-info/SOURCES.txt +60 -10
- {fr_cli-2.5.0 → fr_cli-2.6.0}/pyproject.toml +6 -2
- fr_cli-2.6.0/tests/test_artifact_detector.py +47 -0
- fr_cli-2.6.0/tests/test_context_compress.py +146 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_dynamic_builder.py +8 -2
- fr_cli-2.6.0/tests/test_dynamic_builder_selftest.py +89 -0
- fr_cli-2.6.0/tests/test_gap_analyzer.py +109 -0
- fr_cli-2.6.0/tests/test_hermes.py +326 -0
- fr_cli-2.6.0/tests/test_hermes_daemon.py +189 -0
- fr_cli-2.6.0/tests/test_hermes_demo.py +151 -0
- fr_cli-2.6.0/tests/test_hermes_manager.py +66 -0
- fr_cli-2.6.0/tests/test_hermes_memory.py +94 -0
- fr_cli-2.6.0/tests/test_hermes_subtasks.py +181 -0
- fr_cli-2.6.0/tests/test_master_evolution.py +126 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_plan.py +3 -3
- fr_cli-2.6.0/tests/test_repl_autostart.py +63 -0
- fr_cli-2.6.0/tests/test_repl_status.py +68 -0
- fr_cli-2.6.0/tests/test_review_queue.py +66 -0
- fr_cli-2.6.0/tests/test_security_autonomous.py +130 -0
- fr_cli-2.5.0/fr_cli/agent/artifact_detector.py +0 -105
- fr_cli-2.5.0/fr_cli/agent/builtins/spider.py +0 -952
- fr_cli-2.5.0/fr_cli/agent/hermes.py +0 -344
- fr_cli-2.5.0/fr_cli/agent/hermes_daemon.py +0 -264
- fr_cli-2.5.0/fr_cli/agent/master.py +0 -587
- fr_cli-2.5.0/fr_cli/agent/personality.py +0 -237
- fr_cli-2.5.0/fr_cli/agent/shell_mode.py +0 -178
- fr_cli-2.5.0/fr_cli/agent/skills.py +0 -227
- fr_cli-2.5.0/fr_cli/command/registered/dynamic_build.py +0 -51
- fr_cli-2.5.0/fr_cli/core/plan.py +0 -488
- fr_cli-2.5.0/fr_cli/repl/commands/config.py +0 -525
- fr_cli-2.5.0/fr_cli/repl/commands.py +0 -43
- fr_cli-2.5.0/fr_cli/ui/prompt.py +0 -886
- fr_cli-2.5.0/fr_cli/ui/splash.py +0 -339
- fr_cli-2.5.0/fr_cli/ui/web_config.py +0 -238
- {fr_cli-2.5.0 → fr_cli-2.6.0}/LICENSE +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/MANIFEST.in +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/README.md +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/README.md +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/WEAPON.MD +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/addon/plugin.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/__init__.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/builtins/__init__.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/builtins/_utils.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/builtins/db.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/builtins/local.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/builtins/rag.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/builtins/rag_watcher_daemon.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/builtins/remote.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/builtins/stock.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/client.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/dispatch.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/executor.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/generator.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/manager.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/remote.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/server.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/swarm.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/swarm_resolver.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/agent/workflow.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/assets/splash.jpeg +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/breakthrough/update.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/__init__.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/executor.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/agent_data_mcp.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/charts.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/fs.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/image.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/main_routes.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/network.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/ocr.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/remote.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/services.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/swarm.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/command/registered/web.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/conf/__init__.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/conf/default_models.yaml +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/conf/wizard.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/cache.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/errors.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/model_factory.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/optimizations.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/preferences.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/project.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/recommender.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/result.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/store.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/stream.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/sysmon.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/thinking.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/core/usage.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/dynamic_builder/__init__.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/dynamic_builder/code_generator.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/dynamic_builder/dependency_manager.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/gatekeeper/__init__.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/gatekeeper/daemon.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/gatekeeper/manager.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/lang/i18n.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/lang/translations/__init__.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/main.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/memory/context.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/memory/history.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/memory/session.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/__init__.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/actions.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/batch.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/bootstrap.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/_common.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/agent.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/base.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/cron.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/dataframe.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/dev.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/fs.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/mcp.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/ocr.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/rag.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/remote_agent.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/session.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/stock.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/commands/system.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/queue.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/quick_actions.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/repl/scenarios.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/security/security.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/ui/banner.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/ui/buddha.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/ui/markdown.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/ui/ui.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/charts.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/cron.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/dataframe.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/disk.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/fs.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/launcher.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/loader.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/m365.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/mail.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/mcp.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/network.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/ocr.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/remote.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/vision.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli/weapon/web.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli.egg-info/dependency_links.txt +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli.egg-info/entry_points.txt +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli.egg-info/requires.txt +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/fr_cli.egg-info/top_level.txt +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/setup.cfg +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_a2a_and_providers.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_agent_create.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_agent_manager_store.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_agent_server.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_batch_mode.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_builtin_tools.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_charts.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_cron_persist.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_gatekeeper_store.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_help_update.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_integration_real.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_json_store.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_m365_mail.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_master_prompt_fix.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_mcp_real.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_memory_store.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_model_config.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_new_providers.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_no_color_prompt_toolkit.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_ocr.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_plugin_exec.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_prompt_completion.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_result.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_security.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_stock.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_swarm.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_usage.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_vfs_diff.py +0 -0
- {fr_cli-2.5.0 → fr_cli-2.6.0}/tests/test_workflow.py +0 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AI 回复产物检测器 —— 统一检测插件/Agent 代码结构
|
|
3
|
+
|
|
4
|
+
提取自 core/chat.py 与 agent/master.py 的公共逻辑,
|
|
5
|
+
消除重复代码,保证行为一致性。
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from fr_cli.ui.ui import RED, GREEN, YELLOW, DIM, RESET
|
|
9
|
+
from fr_cli.lang.i18n import T
|
|
10
|
+
from fr_cli.addon.plugin import extract_code, PLUGIN_DIR
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def install_plugin(name: str, code: str, state) -> tuple:
|
|
14
|
+
"""安装插件到插件目录。返回 (success, message)。"""
|
|
15
|
+
safe_name = "".join(c for c in name if c.isalnum() or c == '_')
|
|
16
|
+
if not safe_name:
|
|
17
|
+
return False, "名称无效,仅允许字母/数字/下划线"
|
|
18
|
+
if hasattr(state, 'security') and state.security:
|
|
19
|
+
if not state.security.check("sec_write", f"/{safe_name}"):
|
|
20
|
+
return False, "安全校验未通过"
|
|
21
|
+
PLUGIN_DIR.mkdir(parents=True, exist_ok=True)
|
|
22
|
+
p_path = PLUGIN_DIR / f"{safe_name}.py"
|
|
23
|
+
p_path.write_text(code, encoding='utf-8')
|
|
24
|
+
if hasattr(state, 'plugins'):
|
|
25
|
+
state.plugins[safe_name] = str(p_path)
|
|
26
|
+
return True, safe_name
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def install_agent(name: str, code: str, state) -> tuple:
|
|
30
|
+
"""安装 Agent 分身。返回 (success, message)。"""
|
|
31
|
+
safe_name = "".join(c for c in name if c.isalnum() or c == '_')
|
|
32
|
+
if not safe_name:
|
|
33
|
+
return False, "名称无效,仅允许字母/数字/下划线"
|
|
34
|
+
from fr_cli.agent.manager import (
|
|
35
|
+
create_agent_dir, save_agent_code, save_persona, save_skills, agent_exists
|
|
36
|
+
)
|
|
37
|
+
create_agent_dir(safe_name)
|
|
38
|
+
save_agent_code(safe_name, code)
|
|
39
|
+
if not agent_exists(safe_name):
|
|
40
|
+
save_persona(safe_name, f"#{safe_name}\n\n由 AI 对话创建的 Agent 分身。")
|
|
41
|
+
save_skills(safe_name, "## 技能\n\n- 执行自定义 Python 逻辑\n- 入口: run(context, **kwargs)")
|
|
42
|
+
return True, safe_name
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def detect_plugin_artifact(
|
|
46
|
+
txt: str, lang: str, state, interactive: bool = True, task_id: str = None
|
|
47
|
+
) -> bool:
|
|
48
|
+
"""检测 AI 回复中的插件代码结构,提示用户保存或加入审核队列。
|
|
49
|
+
|
|
50
|
+
:param txt: AI 回复文本
|
|
51
|
+
:param lang: 界面语言
|
|
52
|
+
:param state: AppState 实例(需有 security 和 plugins 属性)
|
|
53
|
+
:param interactive: 是否交互式询问名称;False 时进入后台审核队列
|
|
54
|
+
:param task_id: 关联的 Hermes 任务 id,用于后台队列溯源
|
|
55
|
+
:return: 是否检测到并处理了插件
|
|
56
|
+
"""
|
|
57
|
+
if not txt or "def run(args='')" not in txt or "```python" not in txt:
|
|
58
|
+
return False
|
|
59
|
+
|
|
60
|
+
code = extract_code(txt)
|
|
61
|
+
if not code or "def run" not in code or len(code) <= 50:
|
|
62
|
+
return False
|
|
63
|
+
|
|
64
|
+
if not interactive:
|
|
65
|
+
from fr_cli.agent.review_queue import PersistentReviewQueue
|
|
66
|
+
queue = PersistentReviewQueue()
|
|
67
|
+
queue.add(
|
|
68
|
+
artifact_type="plugin",
|
|
69
|
+
code=code,
|
|
70
|
+
task_id=task_id,
|
|
71
|
+
metadata={"lang": lang},
|
|
72
|
+
)
|
|
73
|
+
print(f"{YELLOW}⚡ 后台检测到插件代码,已加入 Hermes 审核队列{RESET}")
|
|
74
|
+
return True
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
pname = input(f"{YELLOW}{T('artifact_detect', lang)}{RESET}").strip()
|
|
78
|
+
if not pname:
|
|
79
|
+
return False
|
|
80
|
+
|
|
81
|
+
safe_name = "".join(c for c in pname if c.isalnum() or c == '_')
|
|
82
|
+
if not safe_name:
|
|
83
|
+
print(f"{RED}名称无效,仅允许字母/数字/下划线{RESET}")
|
|
84
|
+
return False
|
|
85
|
+
|
|
86
|
+
ok, msg = install_plugin(safe_name, code, state)
|
|
87
|
+
if not ok:
|
|
88
|
+
print(f"{RED}{msg}{RESET}")
|
|
89
|
+
return False
|
|
90
|
+
print(f"{GREEN}{T('ok_forged', lang, msg)}{RESET}")
|
|
91
|
+
return True
|
|
92
|
+
except EOFError:
|
|
93
|
+
return False
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def detect_agent_artifact(
|
|
97
|
+
txt: str, lang: str, state, interactive: bool = True, task_id: str = None
|
|
98
|
+
) -> bool:
|
|
99
|
+
"""检测 AI 回复中的 Agent 分身代码结构,提示用户保存或加入审核队列。
|
|
100
|
+
|
|
101
|
+
:param txt: AI 回复文本
|
|
102
|
+
:param lang: 界面语言
|
|
103
|
+
:param state: AppState 实例(仅用于安全校验,可选)
|
|
104
|
+
:param interactive: 是否交互式询问名称;False 时进入后台审核队列
|
|
105
|
+
:param task_id: 关联的 Hermes 任务 id,用于后台队列溯源
|
|
106
|
+
:return: 是否检测到并处理了 Agent
|
|
107
|
+
"""
|
|
108
|
+
if not txt or "def run(context," not in txt or "```python" not in txt:
|
|
109
|
+
return False
|
|
110
|
+
|
|
111
|
+
code = extract_code(txt)
|
|
112
|
+
if not code or "def run(context," not in code or len(code) <= 50:
|
|
113
|
+
return False
|
|
114
|
+
|
|
115
|
+
if not interactive:
|
|
116
|
+
from fr_cli.agent.review_queue import PersistentReviewQueue
|
|
117
|
+
queue = PersistentReviewQueue()
|
|
118
|
+
queue.add(
|
|
119
|
+
artifact_type="agent",
|
|
120
|
+
code=code,
|
|
121
|
+
task_id=task_id,
|
|
122
|
+
metadata={"lang": lang},
|
|
123
|
+
)
|
|
124
|
+
print(f"{YELLOW}⚡ 后台检测到 Agent 分身代码,已加入 Hermes 审核队列{RESET}")
|
|
125
|
+
return True
|
|
126
|
+
|
|
127
|
+
try:
|
|
128
|
+
aname = input(f"{YELLOW}⚡ 检测到 Agent 分身结构,赐名 (回车放弃): {RESET}").strip()
|
|
129
|
+
if not aname:
|
|
130
|
+
return False
|
|
131
|
+
|
|
132
|
+
safe_name = "".join(c for c in aname if c.isalnum() or c == '_')
|
|
133
|
+
if not safe_name:
|
|
134
|
+
print(f"{RED}名称无效,仅允许字母/数字/下划线{RESET}")
|
|
135
|
+
return False
|
|
136
|
+
|
|
137
|
+
from fr_cli.agent.manager import agent_exists
|
|
138
|
+
if agent_exists(safe_name):
|
|
139
|
+
confirm = input(
|
|
140
|
+
f"{YELLOW}Agent [{safe_name}] 已存在,是否覆盖? [y/N]: {RESET}"
|
|
141
|
+
).strip().lower()
|
|
142
|
+
if confirm not in ("y", "yes"):
|
|
143
|
+
print(f"{DIM}已取消。{RESET}")
|
|
144
|
+
return False
|
|
145
|
+
ok, msg = install_agent(safe_name, code, state)
|
|
146
|
+
if not ok:
|
|
147
|
+
print(f"{RED}{msg}{RESET}")
|
|
148
|
+
return False
|
|
149
|
+
print(f"{GREEN}✅ Agent [{msg}] 已保存。{RESET}")
|
|
150
|
+
print(f"{DIM} 运行: /agent_run {msg} [参数]{RESET}")
|
|
151
|
+
return True
|
|
152
|
+
except EOFError:
|
|
153
|
+
return False
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@spider 内置 Agent —— 自适应智能网页爬虫助手
|
|
3
|
+
|
|
4
|
+
模块拆分:
|
|
5
|
+
- deps: requests / selenium / undetected_chromedriver / bs4 延迟加载与 Session 管理
|
|
6
|
+
- evasion: 浏览器指纹规避 + 人类行为模拟(贝塞尔曲线、滚动、阅读停顿、随机点击)
|
|
7
|
+
- memory: 域名策略记忆与本地文件命名
|
|
8
|
+
- analyzer: AI 页面分析 + 智能链接提取(CSS 选择器 / 正则回退)
|
|
9
|
+
- fetcher: 自适应获取(requests → selenium 自动降级)
|
|
10
|
+
- crawler: 主爬取流程、反思进化、REPL 入口
|
|
11
|
+
"""
|
|
12
|
+
from fr_cli.agent.builtins.spider.crawler import crawl, handle_spider
|
|
13
|
+
|
|
14
|
+
__all__ = ["crawl", "handle_spider"]
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""
|
|
2
|
+
AI 页面分析 + 链接提取
|
|
3
|
+
|
|
4
|
+
让 LLM 分析 HTML 结构返回最优选择器,再选择合适提取方式(CSS / 正则)。
|
|
5
|
+
"""
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
from typing import List, Tuple
|
|
9
|
+
from urllib.parse import urljoin, urlparse
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _analyze_page_with_ai(html, url, state, failure_reason=None):
|
|
13
|
+
"""
|
|
14
|
+
让 LLM 分析页面 HTML 结构,返回最优爬取策略。
|
|
15
|
+
|
|
16
|
+
返回 dict:
|
|
17
|
+
link_selector: CSS 选择器,用于提取正文链接
|
|
18
|
+
content_selector: CSS 选择器,用于定位主要内容
|
|
19
|
+
anti_bot_detected: bool
|
|
20
|
+
advice: 绕过反爬的建议
|
|
21
|
+
fetch_method: "requests" 或 "selenium"
|
|
22
|
+
delay: 建议的延迟秒数
|
|
23
|
+
"""
|
|
24
|
+
from fr_cli.core.stream import stream_cnt
|
|
25
|
+
|
|
26
|
+
domain = urlparse(url).netloc
|
|
27
|
+
html_snippet = html[:4000]
|
|
28
|
+
|
|
29
|
+
failure_ctx = f"\n上次失败原因: {failure_reason}" if failure_reason else ""
|
|
30
|
+
|
|
31
|
+
prompt = f"""你是一个专业的网页爬虫工程师。请分析以下网页的 HTML 结构,返回爬取策略。
|
|
32
|
+
|
|
33
|
+
要求输出严格 JSON 格式(不要 markdown 代码块):
|
|
34
|
+
{{
|
|
35
|
+
"link_selector": "提取正文/列表链接的 CSS 选择器,如 '.article-list a' 或 'article a'",
|
|
36
|
+
"content_selector": "定位主要内容区域的 CSS 选择器,如 '.content' 或 'main'",
|
|
37
|
+
"anti_bot_detected": true/false,
|
|
38
|
+
"advice": "简短建议",
|
|
39
|
+
"fetch_method": "requests 或 selenium",
|
|
40
|
+
"delay": 建议的礼貌延迟秒数(1-5之间的数字)
|
|
41
|
+
}}
|
|
42
|
+
|
|
43
|
+
域名: {domain}
|
|
44
|
+
URL: {url}{failure_ctx}
|
|
45
|
+
|
|
46
|
+
HTML 片段:
|
|
47
|
+
```html
|
|
48
|
+
{html_snippet}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
注意:
|
|
52
|
+
- link_selector 要尽量精准,避免导航栏/页脚/广告链接
|
|
53
|
+
- 如果页面是 JS 动态渲染,选择器可以留空,fetch_method 设为 selenium
|
|
54
|
+
- 只输出 JSON,不要其他文字。"""
|
|
55
|
+
|
|
56
|
+
try:
|
|
57
|
+
result_text, _, _, _ = stream_cnt(
|
|
58
|
+
state.client, state.model_name,
|
|
59
|
+
[{"role": "user", "content": prompt}],
|
|
60
|
+
state.lang, custom_prefix="", max_tokens=512, silent=True
|
|
61
|
+
)
|
|
62
|
+
result_text = result_text.strip()
|
|
63
|
+
if result_text.startswith("```"):
|
|
64
|
+
result_text = re.sub(r'^```(?:json)?\s*', '', result_text)
|
|
65
|
+
result_text = re.sub(r'\s*```$', '', result_text)
|
|
66
|
+
|
|
67
|
+
strategy = json.loads(result_text)
|
|
68
|
+
strategy.setdefault("link_selector", "")
|
|
69
|
+
strategy.setdefault("content_selector", "")
|
|
70
|
+
strategy.setdefault("anti_bot_detected", False)
|
|
71
|
+
strategy.setdefault("advice", "")
|
|
72
|
+
strategy.setdefault("fetch_method", "requests")
|
|
73
|
+
strategy.setdefault("delay", 2.0)
|
|
74
|
+
return strategy
|
|
75
|
+
except Exception as e:
|
|
76
|
+
return {
|
|
77
|
+
"link_selector": "",
|
|
78
|
+
"content_selector": "",
|
|
79
|
+
"anti_bot_detected": False,
|
|
80
|
+
"advice": f"AI 分析失败: {str(e)[:100]},使用默认策略",
|
|
81
|
+
"fetch_method": "requests",
|
|
82
|
+
"delay": 2.0,
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _extract_with_selector(html, selector, base_url) -> List[str]:
|
|
87
|
+
"""使用 CSS 选择器提取链接(需要 bs4)"""
|
|
88
|
+
from fr_cli.agent.builtins.spider.deps import _get_bs4
|
|
89
|
+
if not selector:
|
|
90
|
+
return []
|
|
91
|
+
bs4 = _get_bs4()
|
|
92
|
+
if not bs4:
|
|
93
|
+
return []
|
|
94
|
+
|
|
95
|
+
try:
|
|
96
|
+
soup = bs4(html, "html.parser")
|
|
97
|
+
elements = soup.select(selector)
|
|
98
|
+
links = set()
|
|
99
|
+
base_domain = urlparse(base_url).netloc
|
|
100
|
+
for el in elements:
|
|
101
|
+
href = el.get("href")
|
|
102
|
+
if href:
|
|
103
|
+
full = urljoin(base_url, href)
|
|
104
|
+
if urlparse(full).netloc == base_domain:
|
|
105
|
+
if not full.startswith(("javascript:", "mailto:", "tel:")):
|
|
106
|
+
links.add(full)
|
|
107
|
+
return list(links)
|
|
108
|
+
except Exception:
|
|
109
|
+
return []
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _extract_links_regex(html, base_url) -> List[str]:
|
|
113
|
+
"""回退:使用正则提取链接"""
|
|
114
|
+
links = set()
|
|
115
|
+
base_domain = urlparse(base_url).netloc
|
|
116
|
+
pattern = re.compile(r'href=["\']([^"\']+)["\']', re.I)
|
|
117
|
+
for m in pattern.finditer(html):
|
|
118
|
+
href = m.group(1)
|
|
119
|
+
full = urljoin(base_url, href)
|
|
120
|
+
if urlparse(full).netloc == base_domain:
|
|
121
|
+
if not full.startswith(("javascript:", "mailto:", "tel:")):
|
|
122
|
+
links.add(full)
|
|
123
|
+
return list(links)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _extract_links_smart(html, base_url, state, memory=None) -> Tuple[List[str], str]:
|
|
127
|
+
"""
|
|
128
|
+
智能链接提取:先尝试记忆策略,失败则 AI 分析,再失败回退正则
|
|
129
|
+
返回 (links, extraction_method)
|
|
130
|
+
"""
|
|
131
|
+
from fr_cli.agent.builtins.spider.memory import (
|
|
132
|
+
_get_domain_strategy,
|
|
133
|
+
_update_domain_strategy_in_memory,
|
|
134
|
+
)
|
|
135
|
+
domain = urlparse(base_url).netloc
|
|
136
|
+
strategy = _get_domain_strategy(domain, memory)
|
|
137
|
+
|
|
138
|
+
# 1. 尝试记忆中的选择器
|
|
139
|
+
if strategy and strategy.get("link_selector"):
|
|
140
|
+
links = _extract_with_selector(html, strategy["link_selector"], base_url)
|
|
141
|
+
if links:
|
|
142
|
+
return links, "selector_memory"
|
|
143
|
+
|
|
144
|
+
# 2. 无记忆或选择器失败 → 调用 AI 分析
|
|
145
|
+
new_strategy = _analyze_page_with_ai(html, base_url, state)
|
|
146
|
+
|
|
147
|
+
if new_strategy.get("link_selector"):
|
|
148
|
+
links = _extract_with_selector(html, new_strategy["link_selector"], base_url)
|
|
149
|
+
if links:
|
|
150
|
+
_update_domain_strategy_in_memory(domain, new_strategy, success=True, memory=memory)
|
|
151
|
+
return links, "selector_ai"
|
|
152
|
+
else:
|
|
153
|
+
_update_domain_strategy_in_memory(domain, new_strategy, success=False, memory=memory)
|
|
154
|
+
|
|
155
|
+
# 3. 回退到正则
|
|
156
|
+
links = _extract_links_regex(html, base_url)
|
|
157
|
+
return links, "regex_fallback"
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"""
|
|
2
|
+
@spider 主爬取逻辑 —— crawl / 反思进化 / REPL 入口
|
|
3
|
+
"""
|
|
4
|
+
import json
|
|
5
|
+
import random
|
|
6
|
+
import time
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from urllib.parse import urlparse
|
|
10
|
+
|
|
11
|
+
from fr_cli.core.result import Result
|
|
12
|
+
|
|
13
|
+
from fr_cli.agent.builtins.spider.analyzer import _extract_links_smart
|
|
14
|
+
from fr_cli.agent.builtins.spider.deps import _get_requests
|
|
15
|
+
from fr_cli.agent.builtins.spider.fetcher import _fetch_adaptive, _save_page
|
|
16
|
+
from fr_cli.agent.builtins.spider.memory import (
|
|
17
|
+
SPIDER_EVOLUTION_FILE,
|
|
18
|
+
_ensure_spider_memory_dir,
|
|
19
|
+
_get_domain_strategy,
|
|
20
|
+
_load_spider_memory,
|
|
21
|
+
_save_spider_memory,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def crawl(url, depth=1, output_base=None, lang="zh", state=None):
|
|
26
|
+
"""自适应爬取指定 URL,返回 (saved_files, errors, stats)"""
|
|
27
|
+
from fr_cli.ui.ui import CYAN, GREEN, RED, DIM, RESET
|
|
28
|
+
|
|
29
|
+
if depth < 1:
|
|
30
|
+
depth = 1
|
|
31
|
+
if depth > 3:
|
|
32
|
+
depth = 3
|
|
33
|
+
|
|
34
|
+
if output_base is None:
|
|
35
|
+
output_base = Path.cwd() / f"web_{datetime.now().strftime('%Y%m%d')}"
|
|
36
|
+
else:
|
|
37
|
+
output_base = Path(output_base)
|
|
38
|
+
|
|
39
|
+
saved = []
|
|
40
|
+
errors = []
|
|
41
|
+
visited = set()
|
|
42
|
+
to_crawl = [(url, 0)]
|
|
43
|
+
|
|
44
|
+
memory = _load_spider_memory()
|
|
45
|
+
|
|
46
|
+
stats = {
|
|
47
|
+
"total_pages": 0,
|
|
48
|
+
"success_requests": 0,
|
|
49
|
+
"success_selenium": 0,
|
|
50
|
+
"selector_memory_hits": 0,
|
|
51
|
+
"selector_ai_hits": 0,
|
|
52
|
+
"regex_fallbacks": 0,
|
|
53
|
+
"domains": set(),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
while to_crawl:
|
|
57
|
+
current_url, current_depth = to_crawl.pop(0)
|
|
58
|
+
if current_url in visited or current_depth >= depth:
|
|
59
|
+
continue
|
|
60
|
+
visited.add(current_url)
|
|
61
|
+
stats["total_pages"] += 1
|
|
62
|
+
stats["domains"].add(urlparse(current_url).netloc)
|
|
63
|
+
|
|
64
|
+
print(f"{CYAN}🕷️ 爬取 [{current_depth+1}/{depth}]: {current_url[:80]}...{RESET}")
|
|
65
|
+
|
|
66
|
+
html, err, method = _fetch_adaptive(current_url, state, memory=memory)
|
|
67
|
+
if err or not html:
|
|
68
|
+
errors.append(f"{current_url}: {err}")
|
|
69
|
+
print(f"{RED} ❌ 爬取失败: {err}{RESET}")
|
|
70
|
+
continue
|
|
71
|
+
|
|
72
|
+
if method == "requests":
|
|
73
|
+
stats["success_requests"] += 1
|
|
74
|
+
elif method == "selenium":
|
|
75
|
+
stats["success_selenium"] += 1
|
|
76
|
+
|
|
77
|
+
filepath = _save_page(current_url, html, output_base)
|
|
78
|
+
saved.append(filepath)
|
|
79
|
+
print(f"{GREEN} ✅ 已保存: {filepath} (via {method}){RESET}")
|
|
80
|
+
|
|
81
|
+
if current_depth + 1 < depth:
|
|
82
|
+
links, extraction_method = _extract_links_smart(html, current_url, state, memory=memory)
|
|
83
|
+
|
|
84
|
+
if extraction_method == "selector_memory":
|
|
85
|
+
stats["selector_memory_hits"] += 1
|
|
86
|
+
elif extraction_method == "selector_ai":
|
|
87
|
+
stats["selector_ai_hits"] += 1
|
|
88
|
+
else:
|
|
89
|
+
stats["regex_fallbacks"] += 1
|
|
90
|
+
|
|
91
|
+
for link in links[:20]:
|
|
92
|
+
if link not in visited:
|
|
93
|
+
to_crawl.append((link, current_depth + 1))
|
|
94
|
+
if links:
|
|
95
|
+
print(f"{DIM} 发现 {len(links)} 个链接({extraction_method}),加入 {min(len(links), 20)} 个待爬取{RESET}")
|
|
96
|
+
|
|
97
|
+
domain = urlparse(current_url).netloc
|
|
98
|
+
strategy = _get_domain_strategy(domain, memory)
|
|
99
|
+
delay = strategy.get("delay", random.uniform(1.0, 2.5)) if strategy else random.uniform(1.0, 2.5)
|
|
100
|
+
time.sleep(delay)
|
|
101
|
+
|
|
102
|
+
# 统一保存记忆
|
|
103
|
+
_save_spider_memory(memory)
|
|
104
|
+
|
|
105
|
+
# 爬取结束后:AI 反思进化
|
|
106
|
+
if state and (stats["total_pages"] >= 2 or errors):
|
|
107
|
+
_reflect_and_evolve(stats, errors, memory, state)
|
|
108
|
+
|
|
109
|
+
return Result.ok((saved, errors, stats))
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _reflect_and_evolve(stats, errors, memory, state):
|
|
113
|
+
"""爬取结束后让 AI 反思,生成进化建议并保存。"""
|
|
114
|
+
from fr_cli.core.stream import stream_cnt
|
|
115
|
+
|
|
116
|
+
domains_summary = []
|
|
117
|
+
for domain, data in memory.items():
|
|
118
|
+
domains_summary.append(
|
|
119
|
+
f"- {domain}: 成功率 {data.get('success_rate', 0):.0%}, "
|
|
120
|
+
f"推荐方式 {data.get('fetch_method', 'unknown')}, "
|
|
121
|
+
f"选择器 {data.get('link_selector', 'none') or 'none'}"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
error_summary = "\n".join(errors[:5]) if errors else "无"
|
|
125
|
+
|
|
126
|
+
prompt = f"""作为爬虫工程师,请基于本次爬取数据生成优化建议。
|
|
127
|
+
|
|
128
|
+
爬取统计:
|
|
129
|
+
- 总页面: {stats['total_pages']}
|
|
130
|
+
- requests 成功: {stats['success_requests']}
|
|
131
|
+
- selenium 成功: {stats['success_selenium']}
|
|
132
|
+
- 选择器记忆命中: {stats['selector_memory_hits']}
|
|
133
|
+
- AI 选择器生成: {stats['selector_ai_hits']}
|
|
134
|
+
- 正则回退: {stats['regex_fallbacks']}
|
|
135
|
+
|
|
136
|
+
域名策略记录:
|
|
137
|
+
{chr(10).join(domains_summary[:10])}
|
|
138
|
+
|
|
139
|
+
失败案例:
|
|
140
|
+
{error_summary}
|
|
141
|
+
|
|
142
|
+
请输出简洁的优化建议(不超过200字),我将保存到爬虫进化记录中。"""
|
|
143
|
+
|
|
144
|
+
try:
|
|
145
|
+
advice, _, _, _ = stream_cnt(
|
|
146
|
+
state.client, state.model_name,
|
|
147
|
+
[{"role": "user", "content": prompt}],
|
|
148
|
+
state.lang, custom_prefix="", max_tokens=256, silent=True
|
|
149
|
+
)
|
|
150
|
+
advice = advice.strip()
|
|
151
|
+
if advice:
|
|
152
|
+
_ensure_spider_memory_dir()
|
|
153
|
+
evolution = {}
|
|
154
|
+
if SPIDER_EVOLUTION_FILE.exists():
|
|
155
|
+
try:
|
|
156
|
+
with open(SPIDER_EVOLUTION_FILE, "r", encoding="utf-8") as f:
|
|
157
|
+
evolution = json.load(f)
|
|
158
|
+
except Exception:
|
|
159
|
+
pass
|
|
160
|
+
evolution["last_advice"] = advice
|
|
161
|
+
evolution["last_updated"] = datetime.now().isoformat()
|
|
162
|
+
evolution["total_crawls"] = evolution.get("total_crawls", 0) + 1
|
|
163
|
+
with open(SPIDER_EVOLUTION_FILE, "w", encoding="utf-8") as f:
|
|
164
|
+
json.dump(evolution, f, ensure_ascii=False, indent=2)
|
|
165
|
+
except Exception:
|
|
166
|
+
pass
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def handle_spider(user_input, state):
|
|
170
|
+
"""处理 @spider 前缀的请求"""
|
|
171
|
+
from fr_cli.ui.ui import CYAN, GREEN, RED, DIM, RESET
|
|
172
|
+
|
|
173
|
+
text = user_input[len("@spider"):].strip()
|
|
174
|
+
if not text:
|
|
175
|
+
print(f"{RED}用法: @spider <URL> [深度]{RESET}")
|
|
176
|
+
return
|
|
177
|
+
|
|
178
|
+
parts = text.split()
|
|
179
|
+
url = parts[0]
|
|
180
|
+
depth = int(parts[1]) if len(parts) > 1 and parts[1].isdigit() else 1
|
|
181
|
+
|
|
182
|
+
if not url.startswith("http"):
|
|
183
|
+
url = "https://" + url
|
|
184
|
+
|
|
185
|
+
if not _get_requests():
|
|
186
|
+
print(f"{RED}缺少依赖: pip install requests{RESET}")
|
|
187
|
+
return
|
|
188
|
+
|
|
189
|
+
output_dir = None
|
|
190
|
+
if state.vfs and state.vfs.cwd:
|
|
191
|
+
output_dir = state.vfs.cwd
|
|
192
|
+
|
|
193
|
+
print(f"{CYAN}🕷️ 开始自适应爬取: {url} | 深度: {depth}{RESET}")
|
|
194
|
+
print(f"{DIM} 爬虫会根据页面结构自动分析最优策略...{RESET}")
|
|
195
|
+
|
|
196
|
+
saved, errors, stats = crawl(url, depth, output_dir, state.lang, state=state).unwrap()
|
|
197
|
+
|
|
198
|
+
print(f"\n{GREEN}═══ 爬取完成 ═══{RESET}")
|
|
199
|
+
print(f"{GREEN} 成功: {len(saved)} 个页面{RESET}")
|
|
200
|
+
if stats["success_selenium"] > 0:
|
|
201
|
+
print(f"{DIM} selenium 渲染: {stats['success_selenium']} 页{RESET}")
|
|
202
|
+
if stats["selector_ai_hits"] > 0:
|
|
203
|
+
print(f"{DIM} AI 动态分析: {stats['selector_ai_hits']} 次{RESET}")
|
|
204
|
+
if stats["selector_memory_hits"] > 0:
|
|
205
|
+
print(f"{DIM} 记忆策略命中: {stats['selector_memory_hits']} 次{RESET}")
|
|
206
|
+
if errors:
|
|
207
|
+
print(f"{RED} 失败: {len(errors)} 个页面{RESET}")
|
|
208
|
+
for e in errors[:5]:
|
|
209
|
+
print(f"{RED} - {e}{RESET}")
|
|
210
|
+
if saved:
|
|
211
|
+
print(f"{DIM} 保存目录: {Path(saved[0]).parent}{RESET}")
|
|
212
|
+
|
|
213
|
+
if SPIDER_EVOLUTION_FILE.exists():
|
|
214
|
+
try:
|
|
215
|
+
with open(SPIDER_EVOLUTION_FILE, "r", encoding="utf-8") as f:
|
|
216
|
+
evo = json.load(f)
|
|
217
|
+
if evo.get("last_advice"):
|
|
218
|
+
print(f"{DIM} 最新进化: {evo['last_advice'][:80]}...{RESET}")
|
|
219
|
+
except Exception:
|
|
220
|
+
pass
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""
|
|
2
|
+
spider 模块依赖管理 —— 延迟加载 requests / selenium / undetected-chromedriver / bs4
|
|
3
|
+
|
|
4
|
+
按需 import,缺失时返回 None,让上层逻辑走"无依赖"分支或给出安装提示。
|
|
5
|
+
"""
|
|
6
|
+
import threading
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
_requests = None
|
|
10
|
+
_selenium = None
|
|
11
|
+
_bs4 = None
|
|
12
|
+
_requests_sessions: dict = {}
|
|
13
|
+
_sessions_lock = threading.Lock()
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# ---------- 用户代理池 ----------
|
|
17
|
+
USER_AGENTS = [
|
|
18
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
19
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
20
|
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15",
|
|
21
|
+
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
# 常见真实窗口分辨率(避免只用 1920x1080)
|
|
25
|
+
_WINDOW_SIZES = [
|
|
26
|
+
(1920, 1080), (1366, 768), (1440, 900), (1536, 864),
|
|
27
|
+
(1280, 720), (1600, 900), (1680, 1050), (2560, 1440),
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _get_requests():
|
|
32
|
+
global _requests
|
|
33
|
+
if _requests is None:
|
|
34
|
+
try:
|
|
35
|
+
import requests as r
|
|
36
|
+
_requests = r
|
|
37
|
+
except ImportError:
|
|
38
|
+
pass
|
|
39
|
+
return _requests
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _get_selenium():
|
|
43
|
+
global _selenium
|
|
44
|
+
if _selenium is None:
|
|
45
|
+
try:
|
|
46
|
+
from selenium import webdriver
|
|
47
|
+
from selenium.webdriver.common.by import By
|
|
48
|
+
from selenium.webdriver.common.action_chains import ActionChains
|
|
49
|
+
_selenium = {"webdriver": webdriver, "By": By, "ActionChains": ActionChains}
|
|
50
|
+
except ImportError:
|
|
51
|
+
pass
|
|
52
|
+
return _selenium
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _get_undetected_chromedriver():
|
|
56
|
+
"""尝试导入 undetected-chromedriver(更强的反检测能力)"""
|
|
57
|
+
try:
|
|
58
|
+
import undetected_chromedriver as uc
|
|
59
|
+
return uc
|
|
60
|
+
except ImportError:
|
|
61
|
+
return None
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _get_bs4():
|
|
65
|
+
global _bs4
|
|
66
|
+
if _bs4 is None:
|
|
67
|
+
try:
|
|
68
|
+
from bs4 import BeautifulSoup
|
|
69
|
+
_bs4 = BeautifulSoup
|
|
70
|
+
except ImportError:
|
|
71
|
+
pass
|
|
72
|
+
return _bs4
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _get_requests_session(domain: str):
|
|
76
|
+
"""获取带 Cookie 持久化的 Session,每个域名独立"""
|
|
77
|
+
requests = _get_requests()
|
|
78
|
+
if not requests:
|
|
79
|
+
return None
|
|
80
|
+
with _sessions_lock:
|
|
81
|
+
if domain not in _requests_sessions:
|
|
82
|
+
_requests_sessions[domain] = requests.Session()
|
|
83
|
+
return _requests_sessions[domain]
|