auto-coder 0.1.400__py3-none-any.whl → 2.0.0__py3-none-any.whl
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.
Potentially problematic release.
This version of auto-coder might be problematic. Click here for more details.
- auto_coder-2.0.0.dist-info/LICENSE +158 -0
- auto_coder-2.0.0.dist-info/METADATA +558 -0
- auto_coder-2.0.0.dist-info/RECORD +795 -0
- {auto_coder-0.1.400.dist-info → auto_coder-2.0.0.dist-info}/WHEEL +1 -1
- {auto_coder-0.1.400.dist-info → auto_coder-2.0.0.dist-info}/entry_points.txt +3 -3
- autocoder/__init__.py +31 -0
- autocoder/agent/auto_filegroup.py +32 -13
- autocoder/agent/auto_learn_from_commit.py +9 -1
- autocoder/agent/base_agentic/__init__.py +3 -0
- autocoder/agent/base_agentic/agent_hub.py +1 -1
- autocoder/agent/base_agentic/base_agent.py +235 -136
- autocoder/agent/base_agentic/default_tools.py +119 -118
- autocoder/agent/base_agentic/test_base_agent.py +1 -1
- autocoder/agent/base_agentic/tool_registry.py +32 -20
- autocoder/agent/base_agentic/tools/read_file_tool_resolver.py +25 -4
- autocoder/agent/base_agentic/tools/write_to_file_tool_resolver.py +24 -11
- autocoder/agent/base_agentic/types.py +42 -0
- autocoder/agent/entry_command_agent/chat.py +73 -59
- autocoder/auto_coder.py +31 -40
- autocoder/auto_coder_rag.py +11 -1084
- autocoder/auto_coder_runner.py +1029 -2310
- autocoder/auto_coder_terminal.py +26 -0
- autocoder/auto_coder_terminal_v3.py +190 -0
- autocoder/chat/conf_command.py +224 -124
- autocoder/chat/models_command.py +361 -299
- autocoder/chat/rules_command.py +79 -31
- autocoder/chat_auto_coder.py +1021 -372
- autocoder/chat_auto_coder_lang.py +23 -732
- autocoder/commands/auto_command.py +26 -9
- autocoder/commands/auto_web.py +1 -1
- autocoder/commands/tools.py +44 -44
- autocoder/common/__init__.py +150 -128
- autocoder/common/ac_style_command_parser/__init__.py +39 -2
- autocoder/common/ac_style_command_parser/config.py +422 -0
- autocoder/common/ac_style_command_parser/parser.py +292 -78
- autocoder/common/ac_style_command_parser/test_parser.py +241 -16
- autocoder/common/ac_style_command_parser/test_typed_parser.py +342 -0
- autocoder/common/ac_style_command_parser/typed_parser.py +653 -0
- autocoder/common/action_yml_file_manager.py +25 -13
- autocoder/common/agent_events/__init__.py +52 -0
- autocoder/common/agent_events/agent_event_emitter.py +193 -0
- autocoder/common/agent_events/event_factory.py +177 -0
- autocoder/common/agent_events/examples.py +307 -0
- autocoder/common/agent_events/types.py +113 -0
- autocoder/common/agent_events/utils.py +68 -0
- autocoder/common/agent_hooks/__init__.py +44 -0
- autocoder/common/agent_hooks/examples.py +582 -0
- autocoder/common/agent_hooks/hook_executor.py +217 -0
- autocoder/common/agent_hooks/hook_manager.py +288 -0
- autocoder/common/agent_hooks/types.py +133 -0
- autocoder/common/agent_hooks/utils.py +99 -0
- autocoder/common/agent_query_queue/queue_executor.py +324 -0
- autocoder/common/agent_query_queue/queue_manager.py +325 -0
- autocoder/common/agents/__init__.py +11 -0
- autocoder/common/agents/agent_manager.py +323 -0
- autocoder/common/agents/agent_parser.py +189 -0
- autocoder/common/agents/example_usage.py +344 -0
- autocoder/common/agents/integration_example.py +330 -0
- autocoder/common/agents/test_agent_parser.py +545 -0
- autocoder/common/async_utils.py +101 -0
- autocoder/common/auto_coder_lang.py +23 -972
- autocoder/common/autocoderargs_parser/__init__.py +14 -0
- autocoder/common/autocoderargs_parser/parser.py +184 -0
- autocoder/common/autocoderargs_parser/tests/__init__.py +1 -0
- autocoder/common/autocoderargs_parser/tests/test_args_parser.py +235 -0
- autocoder/common/autocoderargs_parser/tests/test_token_parser.py +195 -0
- autocoder/common/autocoderargs_parser/token_parser.py +290 -0
- autocoder/common/buildin_tokenizer.py +2 -4
- autocoder/common/code_auto_generate.py +149 -74
- autocoder/common/code_auto_generate_diff.py +163 -70
- autocoder/common/code_auto_generate_editblock.py +179 -89
- autocoder/common/code_auto_generate_strict_diff.py +167 -72
- autocoder/common/code_auto_merge_editblock.py +13 -6
- autocoder/common/code_modification_ranker.py +1 -1
- autocoder/common/command_completer.py +3 -3
- autocoder/common/command_file_manager/manager.py +183 -47
- autocoder/common/command_file_manager/test_command_file_manager.py +507 -0
- autocoder/common/command_templates.py +1 -1
- autocoder/common/conf_utils.py +2 -4
- autocoder/common/conversations/config.py +11 -3
- autocoder/common/conversations/get_conversation_manager.py +100 -2
- autocoder/common/conversations/llm_stats_models.py +264 -0
- autocoder/common/conversations/manager.py +112 -28
- autocoder/common/conversations/models.py +16 -2
- autocoder/common/conversations/storage/index_manager.py +134 -10
- autocoder/common/core_config/__init__.py +63 -0
- autocoder/common/core_config/agentic_mode_manager.py +109 -0
- autocoder/common/core_config/base_manager.py +123 -0
- autocoder/common/core_config/compatibility.py +151 -0
- autocoder/common/core_config/config_manager.py +156 -0
- autocoder/common/core_config/conversation_manager.py +31 -0
- autocoder/common/core_config/exclude_manager.py +72 -0
- autocoder/common/core_config/file_manager.py +177 -0
- autocoder/common/core_config/human_as_model_manager.py +129 -0
- autocoder/common/core_config/lib_manager.py +54 -0
- autocoder/common/core_config/main_manager.py +81 -0
- autocoder/common/core_config/mode_manager.py +126 -0
- autocoder/common/core_config/models.py +70 -0
- autocoder/common/core_config/test_memory_manager.py +1056 -0
- autocoder/common/env_manager.py +282 -0
- autocoder/common/env_manager_usage_example.py +211 -0
- autocoder/common/file_checkpoint/conversation_checkpoint.py +19 -19
- autocoder/common/file_checkpoint/manager.py +264 -48
- autocoder/common/file_checkpoint/test_backup.py +1 -18
- autocoder/common/file_checkpoint/test_manager.py +270 -1
- autocoder/common/file_checkpoint/test_store.py +1 -17
- autocoder/common/file_handler/__init__.py +23 -0
- autocoder/common/file_handler/active_context_handler.py +159 -0
- autocoder/common/file_handler/add_files_handler.py +409 -0
- autocoder/common/file_handler/chat_handler.py +180 -0
- autocoder/common/file_handler/coding_handler.py +401 -0
- autocoder/common/file_handler/commit_handler.py +200 -0
- autocoder/common/file_handler/lib_handler.py +156 -0
- autocoder/common/file_handler/list_files_handler.py +111 -0
- autocoder/common/file_handler/mcp_handler.py +268 -0
- autocoder/common/file_handler/models_handler.py +493 -0
- autocoder/common/file_handler/remove_files_handler.py +172 -0
- autocoder/common/file_monitor/test_file_monitor.py +307 -0
- autocoder/common/git_utils.py +51 -10
- autocoder/common/global_cancel.py +15 -6
- autocoder/common/ignorefiles/test_ignore_file_utils.py +1 -1
- autocoder/common/international/__init__.py +31 -0
- autocoder/common/international/demo_international.py +92 -0
- autocoder/common/international/message_manager.py +157 -0
- autocoder/common/international/messages/__init__.py +56 -0
- autocoder/common/international/messages/async_command_messages.py +507 -0
- autocoder/common/international/messages/auto_coder_messages.py +2208 -0
- autocoder/common/international/messages/chat_auto_coder_messages.py +1547 -0
- autocoder/common/international/messages/command_help_messages.py +986 -0
- autocoder/common/international/messages/conversation_command_messages.py +191 -0
- autocoder/common/international/messages/git_helper_plugin_messages.py +159 -0
- autocoder/common/international/messages/queue_command_messages.py +751 -0
- autocoder/common/international/messages/rules_command_messages.py +77 -0
- autocoder/common/international/messages/sdk_messages.py +1707 -0
- autocoder/common/international/messages/token_helper_plugin_messages.py +361 -0
- autocoder/common/international/messages/tool_display_messages.py +1212 -0
- autocoder/common/international/messages/workflow_exception_messages.py +473 -0
- autocoder/common/international/test_international.py +612 -0
- autocoder/common/linter_core/__init__.py +28 -0
- autocoder/common/linter_core/base_linter.py +61 -0
- autocoder/common/linter_core/config_loader.py +271 -0
- autocoder/common/linter_core/formatters/__init__.py +0 -0
- autocoder/common/linter_core/formatters/base_formatter.py +38 -0
- autocoder/common/linter_core/formatters/raw_formatter.py +17 -0
- autocoder/common/linter_core/linter.py +166 -0
- autocoder/common/linter_core/linter_factory.py +216 -0
- autocoder/common/linter_core/linter_manager.py +333 -0
- autocoder/common/linter_core/linters/__init__.py +9 -0
- autocoder/common/linter_core/linters/java_linter.py +342 -0
- autocoder/common/linter_core/linters/python_linter.py +115 -0
- autocoder/common/linter_core/linters/typescript_linter.py +119 -0
- autocoder/common/linter_core/models/__init__.py +7 -0
- autocoder/common/linter_core/models/lint_result.py +91 -0
- autocoder/common/linter_core/models.py +33 -0
- autocoder/common/linter_core/tests/__init__.py +3 -0
- autocoder/common/linter_core/tests/test_config_loader.py +323 -0
- autocoder/common/linter_core/tests/test_config_loading.py +308 -0
- autocoder/common/linter_core/tests/test_factory_manager.py +234 -0
- autocoder/common/linter_core/tests/test_formatters.py +147 -0
- autocoder/common/linter_core/tests/test_integration.py +317 -0
- autocoder/common/linter_core/tests/test_java_linter.py +496 -0
- autocoder/common/linter_core/tests/test_linters.py +265 -0
- autocoder/common/linter_core/tests/test_models.py +81 -0
- autocoder/common/linter_core/tests/verify_config_loading.py +296 -0
- autocoder/common/linter_core/tests/verify_fixes.py +183 -0
- autocoder/common/llm_friendly_package/__init__.py +31 -0
- autocoder/common/llm_friendly_package/base_manager.py +102 -0
- autocoder/common/llm_friendly_package/docs_manager.py +121 -0
- autocoder/common/llm_friendly_package/library_manager.py +171 -0
- autocoder/common/{llm_friendly_package.py → llm_friendly_package/main_manager.py} +204 -231
- autocoder/common/llm_friendly_package/models.py +40 -0
- autocoder/common/llm_friendly_package/test_llm_friendly_package.py +536 -0
- autocoder/common/llms/__init__.py +15 -0
- autocoder/common/llms/demo_error_handling.py +85 -0
- autocoder/common/llms/factory.py +142 -0
- autocoder/common/llms/manager.py +264 -0
- autocoder/common/llms/pricing.py +121 -0
- autocoder/common/llms/registry.py +288 -0
- autocoder/common/llms/schema.py +77 -0
- autocoder/common/llms/simple_demo.py +45 -0
- autocoder/common/llms/test_quick_model.py +116 -0
- autocoder/common/llms/test_remove_functionality.py +182 -0
- autocoder/common/llms/tests/__init__.py +1 -0
- autocoder/common/llms/tests/test_manager.py +330 -0
- autocoder/common/llms/tests/test_registry.py +364 -0
- autocoder/common/mcp_tools/__init__.py +62 -0
- autocoder/common/{mcp_tools.py → mcp_tools/executor.py} +49 -40
- autocoder/common/{mcp_hub.py → mcp_tools/hub.py} +42 -68
- autocoder/common/{mcp_server_install.py → mcp_tools/installer.py} +16 -28
- autocoder/common/{mcp_server.py → mcp_tools/server.py} +176 -48
- autocoder/common/mcp_tools/test_keyboard_interrupt.py +93 -0
- autocoder/common/mcp_tools/test_mcp_tools.py +391 -0
- autocoder/common/{mcp_server_types.py → mcp_tools/types.py} +121 -48
- autocoder/common/mcp_tools/verify_functionality.py +202 -0
- autocoder/common/model_speed_tester.py +32 -26
- autocoder/common/priority_directory_finder/__init__.py +142 -0
- autocoder/common/priority_directory_finder/examples.py +230 -0
- autocoder/common/priority_directory_finder/finder.py +283 -0
- autocoder/common/priority_directory_finder/models.py +236 -0
- autocoder/common/priority_directory_finder/test_priority_directory_finder.py +431 -0
- autocoder/common/project_scanner/__init__.py +18 -0
- autocoder/common/project_scanner/compat.py +77 -0
- autocoder/common/project_scanner/scanner.py +436 -0
- autocoder/common/project_tracker/__init__.py +27 -0
- autocoder/common/project_tracker/api.py +228 -0
- autocoder/common/project_tracker/demo.py +272 -0
- autocoder/common/project_tracker/tracker.py +487 -0
- autocoder/common/project_tracker/types.py +53 -0
- autocoder/common/pruner/__init__.py +67 -0
- autocoder/common/pruner/agentic_conversation_pruner.py +746 -0
- autocoder/common/{context_pruner.py → pruner/context_pruner.py} +137 -40
- autocoder/common/pruner/conversation_message_ids_api.py +386 -0
- autocoder/common/pruner/conversation_message_ids_manager.py +347 -0
- autocoder/common/pruner/conversation_message_ids_pruner.py +473 -0
- autocoder/common/pruner/conversation_normalizer.py +347 -0
- autocoder/common/{conversation_pruner.py → pruner/conversation_pruner.py} +26 -6
- autocoder/common/pruner/test_agentic_conversation_pruner.py +784 -0
- autocoder/common/pruner/test_context_pruner.py +546 -0
- autocoder/common/pruner/test_conversation_normalizer.py +502 -0
- autocoder/common/pruner/test_tool_content_detector.py +324 -0
- autocoder/common/pruner/tool_content_detector.py +227 -0
- autocoder/common/pruner/tools/__init__.py +18 -0
- autocoder/common/pruner/tools/query_message_ids.py +264 -0
- autocoder/common/pruner/tools/test_agentic_pruning_logic.py +432 -0
- autocoder/common/pruner/tools/test_message_ids_pruning_only.py +192 -0
- autocoder/common/pull_requests/__init__.py +9 -1
- autocoder/common/pull_requests/utils.py +122 -1
- autocoder/common/rag_manager/rag_manager.py +36 -40
- autocoder/common/rulefiles/__init__.py +53 -1
- autocoder/common/rulefiles/api.py +250 -0
- autocoder/common/rulefiles/core/__init__.py +14 -0
- autocoder/common/rulefiles/core/manager.py +241 -0
- autocoder/common/rulefiles/core/selector.py +805 -0
- autocoder/common/rulefiles/models/__init__.py +20 -0
- autocoder/common/rulefiles/models/index.py +16 -0
- autocoder/common/rulefiles/models/init_rule.py +18 -0
- autocoder/common/rulefiles/models/rule_file.py +18 -0
- autocoder/common/rulefiles/models/rule_relevance.py +14 -0
- autocoder/common/rulefiles/models/summary.py +16 -0
- autocoder/common/rulefiles/test_rulefiles.py +776 -0
- autocoder/common/rulefiles/utils/__init__.py +34 -0
- autocoder/common/rulefiles/utils/monitor.py +86 -0
- autocoder/common/rulefiles/utils/parser.py +230 -0
- autocoder/common/save_formatted_log.py +67 -10
- autocoder/common/search_replace.py +8 -1
- autocoder/common/search_replace_patch/__init__.py +24 -0
- autocoder/common/search_replace_patch/base.py +115 -0
- autocoder/common/search_replace_patch/manager.py +248 -0
- autocoder/common/search_replace_patch/patch_replacer.py +304 -0
- autocoder/common/search_replace_patch/similarity_replacer.py +306 -0
- autocoder/common/search_replace_patch/string_replacer.py +181 -0
- autocoder/common/search_replace_patch/tests/__init__.py +3 -0
- autocoder/common/search_replace_patch/tests/run_tests.py +126 -0
- autocoder/common/search_replace_patch/tests/test_base.py +188 -0
- autocoder/common/search_replace_patch/tests/test_empty_line_insert.py +233 -0
- autocoder/common/search_replace_patch/tests/test_integration.py +389 -0
- autocoder/common/search_replace_patch/tests/test_manager.py +351 -0
- autocoder/common/search_replace_patch/tests/test_patch_replacer.py +316 -0
- autocoder/common/search_replace_patch/tests/test_regex_replacer.py +306 -0
- autocoder/common/search_replace_patch/tests/test_similarity_replacer.py +384 -0
- autocoder/common/shell_commands/__init__.py +197 -0
- autocoder/common/shell_commands/background_process_notifier.py +346 -0
- autocoder/common/shell_commands/command_executor.py +1127 -0
- autocoder/common/shell_commands/error_recovery.py +541 -0
- autocoder/common/shell_commands/exceptions.py +120 -0
- autocoder/common/shell_commands/interactive_executor.py +476 -0
- autocoder/common/shell_commands/interactive_pexpect_process.py +623 -0
- autocoder/common/shell_commands/interactive_process.py +744 -0
- autocoder/common/shell_commands/interactive_session_manager.py +1014 -0
- autocoder/common/shell_commands/monitoring.py +529 -0
- autocoder/common/shell_commands/process_cleanup.py +386 -0
- autocoder/common/shell_commands/process_manager.py +606 -0
- autocoder/common/shell_commands/test_interactive_pexpect_process.py +281 -0
- autocoder/common/shell_commands/tests/__init__.py +6 -0
- autocoder/common/shell_commands/tests/conftest.py +118 -0
- autocoder/common/shell_commands/tests/test_background_process_notifier.py +703 -0
- autocoder/common/shell_commands/tests/test_command_executor.py +448 -0
- autocoder/common/shell_commands/tests/test_error_recovery.py +305 -0
- autocoder/common/shell_commands/tests/test_exceptions.py +299 -0
- autocoder/common/shell_commands/tests/test_execute_batch.py +588 -0
- autocoder/common/shell_commands/tests/test_indented_batch_commands.py +244 -0
- autocoder/common/shell_commands/tests/test_integration.py +664 -0
- autocoder/common/shell_commands/tests/test_monitoring.py +546 -0
- autocoder/common/shell_commands/tests/test_performance.py +632 -0
- autocoder/common/shell_commands/tests/test_process_cleanup.py +397 -0
- autocoder/common/shell_commands/tests/test_process_manager.py +606 -0
- autocoder/common/shell_commands/tests/test_timeout_config.py +343 -0
- autocoder/common/shell_commands/tests/test_timeout_manager.py +520 -0
- autocoder/common/shell_commands/timeout_config.py +315 -0
- autocoder/common/shell_commands/timeout_manager.py +352 -0
- autocoder/common/terminal_paste/__init__.py +14 -0
- autocoder/common/terminal_paste/demo.py +145 -0
- autocoder/common/terminal_paste/demo_paste_functionality.py +95 -0
- autocoder/common/terminal_paste/paste_handler.py +200 -0
- autocoder/common/terminal_paste/paste_manager.py +118 -0
- autocoder/common/terminal_paste/tests/__init__.py +1 -0
- autocoder/common/terminal_paste/tests/test_paste_handler.py +182 -0
- autocoder/common/terminal_paste/tests/test_paste_manager.py +126 -0
- autocoder/common/terminal_paste/utils.py +163 -0
- autocoder/common/test_autocoder_args.py +232 -0
- autocoder/common/test_env_manager.py +173 -0
- autocoder/common/test_env_manager_integration.py +159 -0
- autocoder/common/text_similarity/__init__.py +9 -0
- autocoder/common/text_similarity/demo.py +216 -0
- autocoder/common/text_similarity/examples.py +266 -0
- autocoder/common/text_similarity/test_text_similarity.py +306 -0
- autocoder/common/text_similarity/text_similarity.py +194 -0
- autocoder/common/text_similarity/utils.py +125 -0
- autocoder/common/todos/__init__.py +61 -0
- autocoder/common/todos/cache/__init__.py +16 -0
- autocoder/common/todos/cache/base_cache.py +89 -0
- autocoder/common/todos/cache/cache_manager.py +228 -0
- autocoder/common/todos/cache/memory_cache.py +225 -0
- autocoder/common/todos/config.py +155 -0
- autocoder/common/todos/exceptions.py +35 -0
- autocoder/common/todos/get_todo_manager.py +161 -0
- autocoder/common/todos/manager.py +537 -0
- autocoder/common/todos/models.py +239 -0
- autocoder/common/todos/storage/__init__.py +14 -0
- autocoder/common/todos/storage/base_storage.py +76 -0
- autocoder/common/todos/storage/file_storage.py +278 -0
- autocoder/common/tokens/__init__.py +15 -0
- autocoder/common/tokens/counter.py +44 -2
- autocoder/common/tools_manager/__init__.py +17 -0
- autocoder/common/tools_manager/examples.py +162 -0
- autocoder/common/tools_manager/manager.py +385 -0
- autocoder/common/tools_manager/models.py +39 -0
- autocoder/common/tools_manager/test_tools_manager.py +303 -0
- autocoder/common/tools_manager/utils.py +191 -0
- autocoder/common/v2/agent/agentic_callbacks.py +270 -0
- autocoder/common/v2/agent/agentic_edit.py +2729 -2052
- autocoder/common/v2/agent/agentic_edit_change_manager.py +474 -0
- autocoder/common/v2/agent/agentic_edit_tools/__init__.py +43 -2
- autocoder/common/v2/agent/agentic_edit_tools/ac_mod_list_tool_resolver.py +279 -0
- autocoder/common/v2/agent/agentic_edit_tools/ac_mod_read_tool_resolver.py +40 -0
- autocoder/common/v2/agent/agentic_edit_tools/ac_mod_write_tool_resolver.py +52 -0
- autocoder/common/v2/agent/agentic_edit_tools/ask_followup_question_tool_resolver.py +8 -0
- autocoder/common/v2/agent/agentic_edit_tools/background_task_tool_resolver.py +1167 -0
- autocoder/common/v2/agent/agentic_edit_tools/base_tool_resolver.py +2 -2
- autocoder/common/v2/agent/agentic_edit_tools/conversation_message_ids_read_tool_resolver.py +214 -0
- autocoder/common/v2/agent/agentic_edit_tools/conversation_message_ids_write_tool_resolver.py +299 -0
- autocoder/common/v2/agent/agentic_edit_tools/count_tokens_tool_resolver.py +290 -0
- autocoder/common/v2/agent/agentic_edit_tools/execute_command_tool_resolver.py +565 -30
- autocoder/common/v2/agent/agentic_edit_tools/execute_workflow_tool_resolver.py +485 -0
- autocoder/common/v2/agent/agentic_edit_tools/extract_to_text_tool_resolver.py +225 -0
- autocoder/common/v2/agent/agentic_edit_tools/lint_report.py +79 -0
- autocoder/common/v2/agent/agentic_edit_tools/linter_config_models.py +343 -0
- autocoder/common/v2/agent/agentic_edit_tools/linter_enabled_tool_resolver.py +189 -0
- autocoder/common/v2/agent/agentic_edit_tools/list_files_tool_resolver.py +169 -101
- autocoder/common/v2/agent/agentic_edit_tools/load_extra_document_tool_resolver.py +349 -0
- autocoder/common/v2/agent/agentic_edit_tools/read_file_tool_resolver.py +244 -51
- autocoder/common/v2/agent/agentic_edit_tools/replace_in_file_tool_resolver.py +667 -147
- autocoder/common/v2/agent/agentic_edit_tools/run_named_subagents_tool_resolver.py +691 -0
- autocoder/common/v2/agent/agentic_edit_tools/search_files_tool_resolver.py +409 -140
- autocoder/common/v2/agent/agentic_edit_tools/session_interactive_tool_resolver.py +115 -0
- autocoder/common/v2/agent/agentic_edit_tools/session_start_tool_resolver.py +190 -0
- autocoder/common/v2/agent/agentic_edit_tools/session_stop_tool_resolver.py +76 -0
- autocoder/common/v2/agent/agentic_edit_tools/test_write_to_file_tool_resolver.py +209 -194
- autocoder/common/v2/agent/agentic_edit_tools/todo_read_tool_resolver.py +135 -0
- autocoder/common/v2/agent/agentic_edit_tools/todo_write_tool_resolver.py +328 -0
- autocoder/common/v2/agent/agentic_edit_tools/use_mcp_tool_resolver.py +2 -2
- autocoder/common/v2/agent/agentic_edit_tools/web_crawl_tool_resolver.py +557 -0
- autocoder/common/v2/agent/agentic_edit_tools/web_search_tool_resolver.py +600 -0
- autocoder/common/v2/agent/agentic_edit_tools/write_to_file_tool_resolver.py +56 -121
- autocoder/common/v2/agent/agentic_edit_types.py +386 -10
- autocoder/common/v2/agent/runner/__init__.py +31 -0
- autocoder/common/v2/agent/runner/base_runner.py +92 -0
- autocoder/common/v2/agent/runner/file_based_event_runner.py +217 -0
- autocoder/common/v2/agent/runner/sdk_runner.py +182 -0
- autocoder/common/v2/agent/runner/terminal_runner.py +396 -0
- autocoder/common/v2/agent/runner/tool_display.py +589 -0
- autocoder/common/v2/agent/test_agentic_callbacks.py +265 -0
- autocoder/common/v2/agent/test_agentic_edit.py +194 -0
- autocoder/common/v2/agent/tool_caller/__init__.py +24 -0
- autocoder/common/v2/agent/tool_caller/default_tool_resolver_map.py +135 -0
- autocoder/common/v2/agent/tool_caller/integration_test.py +172 -0
- autocoder/common/v2/agent/tool_caller/plugins/__init__.py +14 -0
- autocoder/common/v2/agent/tool_caller/plugins/base_plugin.py +126 -0
- autocoder/common/v2/agent/tool_caller/plugins/examples/__init__.py +13 -0
- autocoder/common/v2/agent/tool_caller/plugins/examples/logging_plugin.py +164 -0
- autocoder/common/v2/agent/tool_caller/plugins/examples/security_filter_plugin.py +198 -0
- autocoder/common/v2/agent/tool_caller/plugins/plugin_interface.py +141 -0
- autocoder/common/v2/agent/tool_caller/test_tool_caller.py +278 -0
- autocoder/common/v2/agent/tool_caller/tool_call_plugin_manager.py +331 -0
- autocoder/common/v2/agent/tool_caller/tool_caller.py +337 -0
- autocoder/common/v2/agent/tool_caller/usage_example.py +193 -0
- autocoder/common/v2/code_agentic_editblock_manager.py +4 -4
- autocoder/common/v2/code_auto_generate.py +136 -78
- autocoder/common/v2/code_auto_generate_diff.py +135 -79
- autocoder/common/v2/code_auto_generate_editblock.py +174 -99
- autocoder/common/v2/code_auto_generate_strict_diff.py +151 -71
- autocoder/common/v2/code_auto_merge.py +1 -1
- autocoder/common/v2/code_auto_merge_editblock.py +13 -1
- autocoder/common/v2/code_diff_manager.py +3 -3
- autocoder/common/v2/code_editblock_manager.py +4 -14
- autocoder/common/v2/code_manager.py +1 -1
- autocoder/common/v2/code_strict_diff_manager.py +2 -2
- autocoder/common/wrap_llm_hint/__init__.py +10 -0
- autocoder/common/wrap_llm_hint/test_wrap_llm_hint.py +1067 -0
- autocoder/common/wrap_llm_hint/utils.py +432 -0
- autocoder/common/wrap_llm_hint/wrap_llm_hint.py +323 -0
- autocoder/completer/__init__.py +8 -0
- autocoder/completer/command_completer_v2.py +1051 -0
- autocoder/default_project/__init__.py +501 -0
- autocoder/dispacher/__init__.py +4 -12
- autocoder/dispacher/actions/action.py +165 -7
- autocoder/dispacher/actions/plugins/action_regex_project.py +2 -2
- autocoder/index/entry.py +117 -125
- autocoder/{agent → index/filter}/agentic_filter.py +323 -334
- autocoder/index/filter/normal_filter.py +5 -11
- autocoder/index/filter/quick_filter.py +1 -1
- autocoder/index/index.py +36 -9
- autocoder/index/tests/__init__.py +1 -0
- autocoder/index/tests/run_tests.py +195 -0
- autocoder/index/tests/test_entry.py +303 -0
- autocoder/index/tests/test_index_manager.py +314 -0
- autocoder/index/tests/test_module_integration.py +300 -0
- autocoder/index/tests/test_symbols_utils.py +183 -0
- autocoder/inner/__init__.py +4 -0
- autocoder/inner/agentic.py +932 -0
- autocoder/inner/async_command_handler.py +992 -0
- autocoder/inner/conversation_command_handlers.py +623 -0
- autocoder/inner/merge_command_handler.py +213 -0
- autocoder/inner/queue_command_handler.py +684 -0
- autocoder/models.py +95 -266
- autocoder/plugins/git_helper_plugin.py +31 -29
- autocoder/plugins/token_helper_plugin.py +156 -37
- autocoder/pyproject/__init__.py +32 -29
- autocoder/rag/agentic_rag.py +215 -75
- autocoder/rag/cache/simple_cache.py +1 -2
- autocoder/rag/loaders/image_loader.py +1 -1
- autocoder/rag/long_context_rag.py +42 -26
- autocoder/rag/qa_conversation_strategy.py +1 -1
- autocoder/rag/terminal/__init__.py +17 -0
- autocoder/rag/terminal/args.py +581 -0
- autocoder/rag/terminal/bootstrap.py +61 -0
- autocoder/rag/terminal/command_handlers.py +653 -0
- autocoder/rag/terminal/formatters/__init__.py +20 -0
- autocoder/rag/terminal/formatters/base.py +70 -0
- autocoder/rag/terminal/formatters/json_format.py +66 -0
- autocoder/rag/terminal/formatters/stream_json.py +95 -0
- autocoder/rag/terminal/formatters/text.py +28 -0
- autocoder/rag/terminal/init.py +120 -0
- autocoder/rag/terminal/utils.py +106 -0
- autocoder/rag/test_agentic_rag.py +389 -0
- autocoder/rag/test_doc_filter.py +3 -3
- autocoder/rag/test_long_context_rag.py +1 -1
- autocoder/rag/test_token_limiter.py +517 -10
- autocoder/rag/token_counter.py +3 -0
- autocoder/rag/token_limiter.py +19 -15
- autocoder/rag/tools/__init__.py +26 -2
- autocoder/rag/tools/bochaai_example.py +343 -0
- autocoder/rag/tools/bochaai_sdk.py +541 -0
- autocoder/rag/tools/metaso_example.py +268 -0
- autocoder/rag/tools/metaso_sdk.py +417 -0
- autocoder/rag/tools/recall_tool.py +28 -7
- autocoder/rag/tools/run_integration_tests.py +204 -0
- autocoder/rag/tools/test_all_providers.py +318 -0
- autocoder/rag/tools/test_bochaai_integration.py +482 -0
- autocoder/rag/tools/test_final_integration.py +215 -0
- autocoder/rag/tools/test_metaso_integration.py +424 -0
- autocoder/rag/tools/test_metaso_real.py +171 -0
- autocoder/rag/tools/test_web_crawl_tool.py +639 -0
- autocoder/rag/tools/test_web_search_tool.py +509 -0
- autocoder/rag/tools/todo_read_tool.py +202 -0
- autocoder/rag/tools/todo_write_tool.py +412 -0
- autocoder/rag/tools/web_crawl_tool.py +634 -0
- autocoder/rag/tools/web_search_tool.py +558 -0
- autocoder/rag/tools/web_tools_example.py +119 -0
- autocoder/rag/types.py +16 -0
- autocoder/rag/variable_holder.py +4 -2
- autocoder/rags.py +86 -79
- autocoder/regexproject/__init__.py +23 -21
- autocoder/run_context.py +9 -0
- autocoder/sdk/__init__.py +50 -161
- autocoder/sdk/api.py +370 -0
- autocoder/sdk/async_runner/__init__.py +26 -0
- autocoder/sdk/async_runner/async_executor.py +650 -0
- autocoder/sdk/async_runner/async_handler.py +356 -0
- autocoder/sdk/async_runner/markdown_processor.py +595 -0
- autocoder/sdk/async_runner/task_metadata.py +284 -0
- autocoder/sdk/async_runner/worktree_manager.py +438 -0
- autocoder/sdk/cli/__init__.py +2 -5
- autocoder/sdk/cli/formatters.py +28 -204
- autocoder/sdk/cli/handlers.py +77 -44
- autocoder/sdk/cli/main.py +158 -170
- autocoder/sdk/cli/options.py +95 -22
- autocoder/sdk/constants.py +139 -51
- autocoder/sdk/core/auto_coder_core.py +484 -267
- autocoder/sdk/core/bridge.py +298 -118
- autocoder/sdk/exceptions.py +18 -12
- autocoder/sdk/formatters/__init__.py +19 -0
- autocoder/sdk/formatters/input.py +64 -0
- autocoder/sdk/formatters/output.py +247 -0
- autocoder/sdk/formatters/stream.py +54 -0
- autocoder/sdk/models/__init__.py +6 -5
- autocoder/sdk/models/options.py +55 -18
- autocoder/sdk/utils/formatters.py +27 -195
- autocoder/suffixproject/__init__.py +28 -25
- autocoder/terminal/__init__.py +14 -0
- autocoder/terminal/app.py +454 -0
- autocoder/terminal/args.py +32 -0
- autocoder/terminal/bootstrap.py +178 -0
- autocoder/terminal/command_processor.py +521 -0
- autocoder/terminal/command_registry.py +57 -0
- autocoder/terminal/help.py +97 -0
- autocoder/terminal/tasks/__init__.py +5 -0
- autocoder/terminal/tasks/background.py +77 -0
- autocoder/terminal/tasks/task_event.py +70 -0
- autocoder/terminal/ui/__init__.py +13 -0
- autocoder/terminal/ui/completer.py +268 -0
- autocoder/terminal/ui/keybindings.py +75 -0
- autocoder/terminal/ui/session.py +41 -0
- autocoder/terminal/ui/toolbar.py +64 -0
- autocoder/terminal/utils/__init__.py +13 -0
- autocoder/terminal/utils/errors.py +18 -0
- autocoder/terminal/utils/paths.py +19 -0
- autocoder/terminal/utils/shell.py +43 -0
- autocoder/terminal_v3/__init__.py +10 -0
- autocoder/terminal_v3/app.py +201 -0
- autocoder/terminal_v3/handlers/__init__.py +5 -0
- autocoder/terminal_v3/handlers/command_handler.py +131 -0
- autocoder/terminal_v3/models/__init__.py +6 -0
- autocoder/terminal_v3/models/conversation_buffer.py +214 -0
- autocoder/terminal_v3/models/message.py +50 -0
- autocoder/terminal_v3/models/tool_display.py +247 -0
- autocoder/terminal_v3/ui/__init__.py +7 -0
- autocoder/terminal_v3/ui/keybindings.py +56 -0
- autocoder/terminal_v3/ui/layout.py +141 -0
- autocoder/terminal_v3/ui/styles.py +43 -0
- autocoder/tsproject/__init__.py +23 -23
- autocoder/utils/auto_coder_utils/chat_stream_out.py +1 -1
- autocoder/utils/llms.py +88 -80
- autocoder/utils/math_utils.py +101 -0
- autocoder/utils/model_provider_selector.py +16 -4
- autocoder/utils/operate_config_api.py +33 -5
- autocoder/utils/thread_utils.py +2 -2
- autocoder/version.py +4 -2
- autocoder/workflow_agents/__init__.py +84 -0
- autocoder/workflow_agents/agent.py +143 -0
- autocoder/workflow_agents/exceptions.py +573 -0
- autocoder/workflow_agents/executor.py +489 -0
- autocoder/workflow_agents/loader.py +737 -0
- autocoder/workflow_agents/runner.py +267 -0
- autocoder/workflow_agents/types.py +172 -0
- autocoder/workflow_agents/utils.py +434 -0
- autocoder/workflow_agents/workflow_manager.py +211 -0
- auto_coder-0.1.400.dist-info/METADATA +0 -396
- auto_coder-0.1.400.dist-info/RECORD +0 -425
- auto_coder-0.1.400.dist-info/licenses/LICENSE +0 -201
- autocoder/auto_coder_server.py +0 -672
- autocoder/benchmark.py +0 -138
- autocoder/common/ac_style_command_parser/example.py +0 -7
- autocoder/common/cleaner.py +0 -31
- autocoder/common/command_completer_v2.py +0 -615
- autocoder/common/directory_cache/__init__.py +0 -1
- autocoder/common/directory_cache/cache.py +0 -192
- autocoder/common/directory_cache/test_cache.py +0 -190
- autocoder/common/file_checkpoint/examples.py +0 -217
- autocoder/common/llm_friendly_package_example.py +0 -138
- autocoder/common/llm_friendly_package_test.py +0 -63
- autocoder/common/pull_requests/test_module.py +0 -1
- autocoder/common/rulefiles/autocoderrules_utils.py +0 -484
- autocoder/common/text.py +0 -30
- autocoder/common/v2/agent/agentic_edit_tools/list_package_info_tool_resolver.py +0 -42
- autocoder/common/v2/agent/agentic_edit_tools/test_execute_command_tool_resolver.py +0 -70
- autocoder/common/v2/agent/agentic_edit_tools/test_search_files_tool_resolver.py +0 -163
- autocoder/common/v2/agent/agentic_tool_display.py +0 -183
- autocoder/plugins/dynamic_completion_example.py +0 -148
- autocoder/plugins/sample_plugin.py +0 -160
- autocoder/sdk/cli/__main__.py +0 -26
- autocoder/sdk/cli/completion_wrapper.py +0 -38
- autocoder/sdk/cli/install_completion.py +0 -301
- autocoder/sdk/models/messages.py +0 -209
- autocoder/sdk/session/__init__.py +0 -32
- autocoder/sdk/session/session.py +0 -106
- autocoder/sdk/session/session_manager.py +0 -56
- {auto_coder-0.1.400.dist-info → auto_coder-2.0.0.dist-info}/top_level.txt +0 -0
- /autocoder/{sdk/example.py → common/agent_query_queue/__init__.py} +0 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
会话消息ID配置查询工具
|
|
4
|
+
|
|
5
|
+
命令行工具,用于查询和显示指定会话ID的消息删除配置信息。
|
|
6
|
+
|
|
7
|
+
消息ID格式支持:
|
|
8
|
+
1. 直接字段格式: {"message_id": "9226b3a4-1234-5678-9abc-def012345678"}
|
|
9
|
+
2. Hint嵌入格式: {"content": "消息内容 [[message_id: 9226b3a4]]"}
|
|
10
|
+
3. 兼容格式: {"content": "消息内容 message_id: 9226b3a4"}
|
|
11
|
+
|
|
12
|
+
用法示例:
|
|
13
|
+
python -m autocoder.common.pruner.tools.query_message_ids --conversation-id 796e1c2e-1ab8-46d1-9448-f9bd29d5c095
|
|
14
|
+
python -m autocoder.common.pruner.tools.query_message_ids -c 796e1c2e-1ab8-46d1-9448-f9bd29d5c095 --verbose
|
|
15
|
+
python -m autocoder.common.pruner.tools.query_message_ids --list-all
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import sys
|
|
20
|
+
import json
|
|
21
|
+
from datetime import datetime
|
|
22
|
+
from typing import Optional
|
|
23
|
+
|
|
24
|
+
from ..conversation_message_ids_api import get_conversation_message_ids_api
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def format_timestamp(timestamp: str) -> str:
|
|
28
|
+
"""格式化时间戳显示"""
|
|
29
|
+
try:
|
|
30
|
+
dt = datetime.fromisoformat(timestamp.replace('Z', '+00:00'))
|
|
31
|
+
return dt.strftime('%Y-%m-%d %H:%M:%S')
|
|
32
|
+
except:
|
|
33
|
+
return timestamp
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def print_separator(char: str = "=", length: int = 80):
|
|
37
|
+
"""打印分隔线"""
|
|
38
|
+
print(char * length)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def print_section_header(title: str):
|
|
42
|
+
"""打印节标题"""
|
|
43
|
+
print()
|
|
44
|
+
print(f"📋 {title}:")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def query_conversation_message_ids(conversation_id: str, verbose: bool = False):
|
|
48
|
+
"""查询并打印指定会话ID的消息删除配置"""
|
|
49
|
+
|
|
50
|
+
print(f"🔍 查询会话ID: {conversation_id}")
|
|
51
|
+
print_separator()
|
|
52
|
+
|
|
53
|
+
try:
|
|
54
|
+
# 获取API实例
|
|
55
|
+
api = get_conversation_message_ids_api()
|
|
56
|
+
|
|
57
|
+
# 获取消息ID配置
|
|
58
|
+
message_ids_config = api.get_conversation_message_ids(conversation_id)
|
|
59
|
+
|
|
60
|
+
if not message_ids_config:
|
|
61
|
+
print(f"❌ 未找到会话ID '{conversation_id}' 的消息删除配置")
|
|
62
|
+
return False
|
|
63
|
+
|
|
64
|
+
print(f"✅ 找到会话ID '{conversation_id}' 的消息删除配置")
|
|
65
|
+
|
|
66
|
+
# 基本信息
|
|
67
|
+
print_section_header("基本信息")
|
|
68
|
+
print(f" 会话ID: {message_ids_config.conversation_id}")
|
|
69
|
+
print(f" 描述: {message_ids_config.description or '无描述'}")
|
|
70
|
+
print(f" 保持成对删除: {'是' if message_ids_config.preserve_pairs else '否'}")
|
|
71
|
+
print(f" 创建时间: {format_timestamp(message_ids_config.created_at)}")
|
|
72
|
+
print(f" 更新时间: {format_timestamp(message_ids_config.updated_at)}")
|
|
73
|
+
|
|
74
|
+
# 消息ID列表
|
|
75
|
+
print_section_header("要删除的消息ID列表")
|
|
76
|
+
if message_ids_config.message_ids:
|
|
77
|
+
for i, msg_id in enumerate(message_ids_config.message_ids, 1):
|
|
78
|
+
print(f" {i:2d}. {msg_id}")
|
|
79
|
+
print(f"\n📊 总计: {len(message_ids_config.message_ids)} 个消息ID")
|
|
80
|
+
else:
|
|
81
|
+
print(" (无消息ID)")
|
|
82
|
+
|
|
83
|
+
# 获取统计信息
|
|
84
|
+
if verbose:
|
|
85
|
+
stats = api.get_message_ids_statistics(conversation_id)
|
|
86
|
+
if stats:
|
|
87
|
+
print_section_header("详细统计信息")
|
|
88
|
+
print(f" 配置的消息ID数量: {stats['total_message_ids']}")
|
|
89
|
+
print(f" 唯一消息ID数量: {stats['unique_message_ids']}")
|
|
90
|
+
print(f" 保持成对删除: {'是' if stats['preserve_pairs'] else '否'}")
|
|
91
|
+
print(f" 创建时间: {format_timestamp(stats['created_at'])}")
|
|
92
|
+
print(f" 更新时间: {format_timestamp(stats['updated_at'])}")
|
|
93
|
+
|
|
94
|
+
# JSON格式输出
|
|
95
|
+
if verbose:
|
|
96
|
+
print_section_header("完整配置 (JSON格式)")
|
|
97
|
+
config_dict = message_ids_config.to_dict()
|
|
98
|
+
print(json.dumps(config_dict, ensure_ascii=False, indent=2))
|
|
99
|
+
|
|
100
|
+
return True
|
|
101
|
+
|
|
102
|
+
except Exception as e:
|
|
103
|
+
print(f"❌ 查询过程中发生错误: {str(e)}")
|
|
104
|
+
if verbose:
|
|
105
|
+
import traceback
|
|
106
|
+
traceback.print_exc()
|
|
107
|
+
return False
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def list_all_conversations(verbose: bool = False):
|
|
111
|
+
"""列出所有已配置的会话ID"""
|
|
112
|
+
|
|
113
|
+
print("📋 所有已配置消息删除的会话列表")
|
|
114
|
+
print_separator()
|
|
115
|
+
|
|
116
|
+
try:
|
|
117
|
+
api = get_conversation_message_ids_api()
|
|
118
|
+
|
|
119
|
+
# 获取所有会话ID
|
|
120
|
+
conversation_ids = api.list_conversation_ids()
|
|
121
|
+
|
|
122
|
+
if not conversation_ids:
|
|
123
|
+
print("❌ 未找到任何已配置消息删除的会话")
|
|
124
|
+
return False
|
|
125
|
+
|
|
126
|
+
print(f"✅ 找到 {len(conversation_ids)} 个已配置的会话:")
|
|
127
|
+
print()
|
|
128
|
+
|
|
129
|
+
# 列出每个会话的基本信息
|
|
130
|
+
for i, conv_id in enumerate(conversation_ids, 1):
|
|
131
|
+
config = api.get_conversation_message_ids(conv_id)
|
|
132
|
+
if config:
|
|
133
|
+
print(f" {i:2d}. {conv_id}")
|
|
134
|
+
if verbose:
|
|
135
|
+
print(f" 描述: {config.description or '无描述'}")
|
|
136
|
+
print(f" 消息ID数量: {len(config.message_ids)}")
|
|
137
|
+
print(f" 创建时间: {format_timestamp(config.created_at)}")
|
|
138
|
+
print(f" 保持成对删除: {'是' if config.preserve_pairs else '否'}")
|
|
139
|
+
print()
|
|
140
|
+
|
|
141
|
+
if not verbose:
|
|
142
|
+
print(f"\n💡 使用 --verbose 参数查看详细信息")
|
|
143
|
+
|
|
144
|
+
return True
|
|
145
|
+
|
|
146
|
+
except Exception as e:
|
|
147
|
+
print(f"❌ 列表查询过程中发生错误: {str(e)}")
|
|
148
|
+
if verbose:
|
|
149
|
+
import traceback
|
|
150
|
+
traceback.print_exc()
|
|
151
|
+
return False
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def export_all_configs(output_file: Optional[str] = None, verbose: bool = False):
|
|
155
|
+
"""导出所有消息ID配置"""
|
|
156
|
+
|
|
157
|
+
print("📤 导出所有消息ID配置")
|
|
158
|
+
print_separator()
|
|
159
|
+
|
|
160
|
+
try:
|
|
161
|
+
api = get_conversation_message_ids_api()
|
|
162
|
+
|
|
163
|
+
# 导出数据
|
|
164
|
+
export_data = api.export_message_ids_to_dict()
|
|
165
|
+
|
|
166
|
+
if output_file:
|
|
167
|
+
# 导出到文件
|
|
168
|
+
with open(output_file, 'w', encoding='utf-8') as f:
|
|
169
|
+
json.dump(export_data, f, ensure_ascii=False, indent=2)
|
|
170
|
+
print(f"✅ 已导出 {export_data['total_configs']} 个配置到文件: {output_file}")
|
|
171
|
+
else:
|
|
172
|
+
# 打印到控制台
|
|
173
|
+
print(f"✅ 共 {export_data['total_configs']} 个配置:")
|
|
174
|
+
print(json.dumps(export_data, ensure_ascii=False, indent=2))
|
|
175
|
+
|
|
176
|
+
return True
|
|
177
|
+
|
|
178
|
+
except Exception as e:
|
|
179
|
+
print(f"❌ 导出过程中发生错误: {str(e)}")
|
|
180
|
+
if verbose:
|
|
181
|
+
import traceback
|
|
182
|
+
traceback.print_exc()
|
|
183
|
+
return False
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def main():
|
|
187
|
+
"""主函数"""
|
|
188
|
+
parser = argparse.ArgumentParser(
|
|
189
|
+
description="会话消息ID配置查询工具",
|
|
190
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
191
|
+
epilog="""
|
|
192
|
+
示例用法:
|
|
193
|
+
# 查询特定会话的消息删除配置
|
|
194
|
+
%(prog)s --conversation-id 796e1c2e-1ab8-46d1-9448-f9bd29d5c095
|
|
195
|
+
|
|
196
|
+
# 详细查询(包含JSON输出)
|
|
197
|
+
%(prog)s -c 796e1c2e-1ab8-46d1-9448-f9bd29d5c095 --verbose
|
|
198
|
+
|
|
199
|
+
# 列出所有已配置的会话
|
|
200
|
+
%(prog)s --list-all
|
|
201
|
+
|
|
202
|
+
# 详细列出所有会话
|
|
203
|
+
%(prog)s --list-all --verbose
|
|
204
|
+
|
|
205
|
+
# 导出所有配置到文件
|
|
206
|
+
%(prog)s --export --output configs.json
|
|
207
|
+
"""
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
# 互斥的主要操作选项
|
|
211
|
+
action_group = parser.add_mutually_exclusive_group(required=True)
|
|
212
|
+
action_group.add_argument(
|
|
213
|
+
'-c', '--conversation-id',
|
|
214
|
+
type=str,
|
|
215
|
+
help='要查询的会话ID'
|
|
216
|
+
)
|
|
217
|
+
action_group.add_argument(
|
|
218
|
+
'--list-all',
|
|
219
|
+
action='store_true',
|
|
220
|
+
help='列出所有已配置消息删除的会话'
|
|
221
|
+
)
|
|
222
|
+
action_group.add_argument(
|
|
223
|
+
'--export',
|
|
224
|
+
action='store_true',
|
|
225
|
+
help='导出所有消息ID配置'
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
# 辅助选项
|
|
229
|
+
parser.add_argument(
|
|
230
|
+
'-v', '--verbose',
|
|
231
|
+
action='store_true',
|
|
232
|
+
help='显示详细信息(包含JSON格式输出)'
|
|
233
|
+
)
|
|
234
|
+
parser.add_argument(
|
|
235
|
+
'--output',
|
|
236
|
+
type=str,
|
|
237
|
+
help='导出文件路径(仅在使用 --export 时有效)'
|
|
238
|
+
)
|
|
239
|
+
|
|
240
|
+
args = parser.parse_args()
|
|
241
|
+
|
|
242
|
+
# 打印工具标题和时间戳
|
|
243
|
+
print("🔍 会话消息ID配置查询工具")
|
|
244
|
+
print(f"📅 执行时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
245
|
+
print()
|
|
246
|
+
|
|
247
|
+
success = False
|
|
248
|
+
|
|
249
|
+
if args.conversation_id:
|
|
250
|
+
# 查询特定会话
|
|
251
|
+
success = query_conversation_message_ids(args.conversation_id, args.verbose)
|
|
252
|
+
elif args.list_all:
|
|
253
|
+
# 列出所有会话
|
|
254
|
+
success = list_all_conversations(args.verbose)
|
|
255
|
+
elif args.export:
|
|
256
|
+
# 导出配置
|
|
257
|
+
success = export_all_configs(args.output, args.verbose)
|
|
258
|
+
|
|
259
|
+
# 根据结果设置退出码
|
|
260
|
+
sys.exit(0 if success else 1)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
if __name__ == "__main__":
|
|
264
|
+
main()
|
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
AgenticConversationPruner 消息ID裁剪逻辑验证脚本
|
|
4
|
+
|
|
5
|
+
本脚本用于验证 agentic_conversation_pruner.py 中基于消息ID的裁剪逻辑,
|
|
6
|
+
使用真实的会话ID和消息配置来测试裁剪功能。
|
|
7
|
+
|
|
8
|
+
支持的消息ID格式:
|
|
9
|
+
1. 直接字段格式: {"message_id": "9226b3a4-1234-5678-9abc-def012345678"}
|
|
10
|
+
2. Hint嵌入格式: {"content": "消息内容 [[message_id: 9226b3a4]]"}
|
|
11
|
+
3. 兼容格式: {"content": "消息内容 message_id: 9226b3a4"}
|
|
12
|
+
|
|
13
|
+
测试场景:
|
|
14
|
+
1. 有消息ID配置的会话 - 应用消息ID裁剪
|
|
15
|
+
2. 无消息ID配置的会话 - 跳过消息ID裁剪
|
|
16
|
+
3. 裁剪统计信息验证
|
|
17
|
+
4. 成对裁剪逻辑验证
|
|
18
|
+
5. 两种消息ID格式的混合验证
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import sys
|
|
22
|
+
import os
|
|
23
|
+
import json
|
|
24
|
+
from datetime import datetime
|
|
25
|
+
from typing import List, Dict, Any
|
|
26
|
+
|
|
27
|
+
# 添加src路径到Python路径
|
|
28
|
+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../..'))
|
|
29
|
+
|
|
30
|
+
from autocoder.common.pruner.agentic_conversation_pruner import AgenticConversationPruner
|
|
31
|
+
from autocoder.common.pruner.conversation_message_ids_api import get_conversation_message_ids_api
|
|
32
|
+
from autocoder.common import AutoCoderArgs
|
|
33
|
+
from autocoder.sdk import get_llm
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def create_test_conversations() -> List[Dict[str, Any]]:
|
|
37
|
+
"""创建测试用的会话数据,包含我们已知要删除的消息ID
|
|
38
|
+
|
|
39
|
+
展示两种消息ID格式的支持:
|
|
40
|
+
1. 直接字段格式(推荐)- 从message_id字段提取
|
|
41
|
+
2. Hint嵌入格式(兼容性)- 从content中提取
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
# 根据之前的查询,我们知道要删除的消息ID是 642f04ee
|
|
45
|
+
# 我们创建一个包含这个ID的会话数据来测试
|
|
46
|
+
conversations = [
|
|
47
|
+
{
|
|
48
|
+
"role": "system",
|
|
49
|
+
"content": "You are a helpful assistant.",
|
|
50
|
+
"message_id": "12345678abcdef01" # 格式1: 直接字段格式(完整UUID)
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"role": "user",
|
|
54
|
+
"content": "Hello, can you help me with some code? [[message_id: 87654321]]", # 格式2: 标准hint格式
|
|
55
|
+
"message_id": "87654321fedcba02" # 同时包含两种格式用于验证优先级
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"role": "assistant",
|
|
59
|
+
"content": "Of course! I'd be happy to help you with your code. What do you need assistance with?",
|
|
60
|
+
"message_id": "642f04ee11223344" # 格式1: 这个消息ID的前8位匹配要删除的 642f04ee
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"role": "user",
|
|
64
|
+
"content": "I want to read a file and analyze it. message_id: 13579bdf", # 格式2: 兼容hint格式
|
|
65
|
+
# 没有message_id字段,只从content中提取
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"role": "assistant",
|
|
69
|
+
"content": "I'll help you read and analyze the file.\n\n<read_file>\n<path>example.py</path>\n</read_file>",
|
|
70
|
+
"message_id": "97531eca" # 格式1: 8字符短ID
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"role": "user",
|
|
74
|
+
"content": "<tool_result tool_name='read_file' success='true'><message>File read successfully</message><content>def hello():\n print('Hello, World!')\n return 'success'</content></tool_result> [[message_id: abcdef01]]", # 格式2: 标准hint格式
|
|
75
|
+
# 没有message_id字段,只从content中提取
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"role": "assistant",
|
|
79
|
+
"content": "I can see the file contains a simple hello function. The code looks good!",
|
|
80
|
+
"message_id": "fedcba9876543210" # 格式1: 完整UUID
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
return conversations
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def create_test_args() -> AutoCoderArgs:
|
|
88
|
+
"""创建测试用的参数"""
|
|
89
|
+
return AutoCoderArgs(
|
|
90
|
+
source_dir=".",
|
|
91
|
+
conversation_prune_safe_zone_tokens=1000, # 设置较小的值,强制触发裁剪逻辑
|
|
92
|
+
context_prune=True,
|
|
93
|
+
context_prune_strategy="extract",
|
|
94
|
+
query="测试消息ID裁剪逻辑"
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def print_conversations(conversations: List[Dict[str, Any]], title: str):
|
|
99
|
+
"""打印会话列表,方便查看"""
|
|
100
|
+
print(f"\n📋 {title}")
|
|
101
|
+
print("=" * 80)
|
|
102
|
+
|
|
103
|
+
for i, conv in enumerate(conversations):
|
|
104
|
+
role = conv.get("role", "unknown")
|
|
105
|
+
content = conv.get("content", "")
|
|
106
|
+
message_id = conv.get("message_id", "no_id")
|
|
107
|
+
|
|
108
|
+
# 截断长内容
|
|
109
|
+
if len(content) > 100:
|
|
110
|
+
content_display = content[:97] + "..."
|
|
111
|
+
else:
|
|
112
|
+
content_display = content
|
|
113
|
+
|
|
114
|
+
print(f" {i+1:2d}. [{role:9}] {message_id[:8]} | {content_display}")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def verify_pruning_with_message_ids():
|
|
118
|
+
"""验证有消息ID配置的裁剪逻辑"""
|
|
119
|
+
|
|
120
|
+
print("🔍 测试场景1: 验证有消息ID配置的会话裁剪")
|
|
121
|
+
print("=" * 80)
|
|
122
|
+
|
|
123
|
+
# 使用已知的会话ID,该会话配置了要删除消息ID 642f04ee
|
|
124
|
+
conversation_id = "796e1c2e-1ab8-46d1-9448-f9bd29d5c095"
|
|
125
|
+
|
|
126
|
+
# 创建测试数据
|
|
127
|
+
original_conversations = create_test_conversations()
|
|
128
|
+
args = create_test_args()
|
|
129
|
+
llm = get_llm("v3_chat", product_mode="lite")
|
|
130
|
+
|
|
131
|
+
# 打印原始会话
|
|
132
|
+
print_conversations(original_conversations, "原始会话数据")
|
|
133
|
+
|
|
134
|
+
# 查询消息ID配置
|
|
135
|
+
api = get_conversation_message_ids_api()
|
|
136
|
+
message_ids_config = api.get_conversation_message_ids(conversation_id)
|
|
137
|
+
|
|
138
|
+
if message_ids_config:
|
|
139
|
+
print(f"\n✅ 找到消息ID配置:")
|
|
140
|
+
print(f" 会话ID: {message_ids_config.conversation_id}")
|
|
141
|
+
print(f" 要删除的消息ID: {message_ids_config.message_ids}")
|
|
142
|
+
print(f" 保持成对删除: {message_ids_config.preserve_pairs}")
|
|
143
|
+
else:
|
|
144
|
+
print(f"❌ 未找到会话ID {conversation_id} 的消息ID配置")
|
|
145
|
+
return False
|
|
146
|
+
|
|
147
|
+
# 创建裁剪器并执行裁剪
|
|
148
|
+
from autocoder.common.conversations.get_conversation_manager import get_conversation_manager
|
|
149
|
+
|
|
150
|
+
# 不设置 conversation manager,因为我们直接通过构造函数传递 conversation_id
|
|
151
|
+
|
|
152
|
+
pruner = AgenticConversationPruner(args=args, llm=llm, conversation_id=conversation_id)
|
|
153
|
+
|
|
154
|
+
# 调试:检查消息ID提取和验证
|
|
155
|
+
print(f"\n🔍 调试信息:")
|
|
156
|
+
print(f" 测试数据中的消息ID:")
|
|
157
|
+
for i, conv in enumerate(original_conversations):
|
|
158
|
+
message_id = conv.get("message_id", "no_id")
|
|
159
|
+
extracted_id = message_id[:8] if len(message_id) >= 8 else "invalid"
|
|
160
|
+
print(f" {i+1}. {message_id} -> {extracted_id}")
|
|
161
|
+
|
|
162
|
+
print(f" 配置中要删除的消息ID: {message_ids_config.message_ids}")
|
|
163
|
+
|
|
164
|
+
# 手动验证消息ID匹配
|
|
165
|
+
conversation_msg_ids = [conv.get("message_id", "")[:8] for conv in original_conversations if len(conv.get("message_id", "")) >= 8]
|
|
166
|
+
print(f" 从对话中提取的消息ID: {conversation_msg_ids}")
|
|
167
|
+
|
|
168
|
+
# 检查验证逻辑
|
|
169
|
+
api = get_conversation_message_ids_api()
|
|
170
|
+
validation_result = api.validate_message_ids(
|
|
171
|
+
message_ids_config.message_ids,
|
|
172
|
+
[conv.get("message_id", "") for conv in original_conversations]
|
|
173
|
+
)
|
|
174
|
+
print(f" 消息ID验证结果: {validation_result.is_valid}")
|
|
175
|
+
if not validation_result.is_valid:
|
|
176
|
+
print(f" 验证失败原因: {validation_result.error_message}")
|
|
177
|
+
if validation_result.warnings:
|
|
178
|
+
for warning in validation_result.warnings:
|
|
179
|
+
print(f" 验证警告: {warning}")
|
|
180
|
+
|
|
181
|
+
print(f"\n🚀 开始执行裁剪...")
|
|
182
|
+
|
|
183
|
+
# 首先计算token数,看看是否需要裁剪
|
|
184
|
+
from autocoder.common.tokens import count_string_tokens
|
|
185
|
+
import json
|
|
186
|
+
original_tokens = count_string_tokens(json.dumps(original_conversations, ensure_ascii=False))
|
|
187
|
+
print(f" 原始对话token数: {original_tokens}")
|
|
188
|
+
print(f" 安全区域阈值: {args.conversation_prune_safe_zone_tokens}")
|
|
189
|
+
print(f" 是否超过阈值: {'是' if original_tokens > args.conversation_prune_safe_zone_tokens else '否'}")
|
|
190
|
+
|
|
191
|
+
if original_tokens <= args.conversation_prune_safe_zone_tokens:
|
|
192
|
+
print(f"⚠️ 注意: token数未超过阈值,可能不会触发裁剪逻辑")
|
|
193
|
+
|
|
194
|
+
# 直接测试 _apply_message_ids_pruning 方法
|
|
195
|
+
print(f"\n🔧 直接测试 _apply_message_ids_pruning 方法:")
|
|
196
|
+
try:
|
|
197
|
+
range_pruned = pruner._apply_message_ids_pruning(original_conversations)
|
|
198
|
+
print(f" Message IDs pruning 结果: {len(original_conversations)} -> {len(range_pruned)} 消息")
|
|
199
|
+
|
|
200
|
+
if len(range_pruned) < len(original_conversations):
|
|
201
|
+
print(f" ✅ Message IDs pruning 成功删除了消息")
|
|
202
|
+
# 检查哪些消息被删除了
|
|
203
|
+
original_ids = [conv.get("message_id", "")[:8] for conv in original_conversations]
|
|
204
|
+
pruned_ids = [conv.get("message_id", "")[:8] for conv in range_pruned]
|
|
205
|
+
deleted_ids = [msg_id for msg_id in original_ids if msg_id not in pruned_ids]
|
|
206
|
+
print(f" 删除的消息ID: {deleted_ids}")
|
|
207
|
+
else:
|
|
208
|
+
print(f" ⚠️ Message IDs pruning 没有删除任何消息")
|
|
209
|
+
except Exception as e:
|
|
210
|
+
print(f" ❌ Message IDs pruning 测试失败: {e}")
|
|
211
|
+
import traceback
|
|
212
|
+
traceback.print_exc()
|
|
213
|
+
|
|
214
|
+
# 执行完整的裁剪流程
|
|
215
|
+
pruned_conversations = pruner.prune_conversations(original_conversations)
|
|
216
|
+
|
|
217
|
+
# 打印裁剪后的会话
|
|
218
|
+
print_conversations(pruned_conversations, "裁剪后的会话数据")
|
|
219
|
+
|
|
220
|
+
# 验证裁剪结果
|
|
221
|
+
print(f"\n📊 裁剪结果分析:")
|
|
222
|
+
print(f" 原始消息数量: {len(original_conversations)}")
|
|
223
|
+
print(f" 裁剪后数量: {len(pruned_conversations)}")
|
|
224
|
+
print(f" 删除的消息数: {len(original_conversations) - len(pruned_conversations)}")
|
|
225
|
+
|
|
226
|
+
# 检查特定消息ID是否被删除
|
|
227
|
+
pruned_message_ids = [conv.get("message_id", "")[:8] for conv in pruned_conversations]
|
|
228
|
+
target_message_id = "642f04ee"
|
|
229
|
+
|
|
230
|
+
if target_message_id in pruned_message_ids:
|
|
231
|
+
print(f"❌ 错误: 消息ID {target_message_id} 应该被删除但仍然存在")
|
|
232
|
+
return False
|
|
233
|
+
else:
|
|
234
|
+
print(f"✅ 正确: 消息ID {target_message_id} 已成功删除")
|
|
235
|
+
|
|
236
|
+
# 获取裁剪统计信息
|
|
237
|
+
stats = pruner.get_pruning_statistics()
|
|
238
|
+
print(f"\n📈 裁剪统计信息:")
|
|
239
|
+
print(f" 消息ID裁剪已应用: {stats['range_pruning']['applied']}")
|
|
240
|
+
print(f" 消息ID裁剪成功: {stats['range_pruning']['success']}")
|
|
241
|
+
print(f" 会话ID: {stats['range_pruning']['conversation_id']}")
|
|
242
|
+
print(f" 总压缩比: {stats['compression']['total_compression_ratio']:.2%}")
|
|
243
|
+
|
|
244
|
+
# 验证成对删除逻辑(如果启用)
|
|
245
|
+
if message_ids_config.preserve_pairs:
|
|
246
|
+
print(f"\n🔗 成对删除逻辑验证:")
|
|
247
|
+
# 分析是否正确处理了用户/助手配对
|
|
248
|
+
user_assistant_pairs = []
|
|
249
|
+
i = 0
|
|
250
|
+
while i < len(pruned_conversations):
|
|
251
|
+
if (i + 1 < len(pruned_conversations) and
|
|
252
|
+
pruned_conversations[i].get("role") == "user" and
|
|
253
|
+
pruned_conversations[i + 1].get("role") == "assistant"):
|
|
254
|
+
user_assistant_pairs.append((i, i + 1))
|
|
255
|
+
i += 2
|
|
256
|
+
else:
|
|
257
|
+
i += 1
|
|
258
|
+
|
|
259
|
+
print(f" 检测到 {len(user_assistant_pairs)} 个用户/助手配对")
|
|
260
|
+
print(f" 配对完整性: {'✅ 良好' if len(user_assistant_pairs) > 0 else '⚠️ 需要检查'}")
|
|
261
|
+
|
|
262
|
+
return True
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
def verify_pruning_without_message_ids():
|
|
266
|
+
"""验证无消息ID配置的裁剪逻辑"""
|
|
267
|
+
|
|
268
|
+
print("\n🔍 测试场景2: 验证无消息ID配置的会话裁剪")
|
|
269
|
+
print("=" * 80)
|
|
270
|
+
|
|
271
|
+
# 使用一个不存在的会话ID
|
|
272
|
+
conversation_id = "nonexistent-conversation-id-12345"
|
|
273
|
+
|
|
274
|
+
# 创建测试数据
|
|
275
|
+
original_conversations = create_test_conversations()
|
|
276
|
+
args = create_test_args()
|
|
277
|
+
llm = get_llm("v3_chat", product_mode="lite")
|
|
278
|
+
|
|
279
|
+
# 创建裁剪器并执行裁剪
|
|
280
|
+
from autocoder.common.conversations.get_conversation_manager import get_conversation_manager
|
|
281
|
+
|
|
282
|
+
# 不设置 conversation manager,因为我们直接通过构造函数传递 conversation_id
|
|
283
|
+
|
|
284
|
+
pruner = AgenticConversationPruner(args=args, llm=llm, conversation_id=conversation_id)
|
|
285
|
+
|
|
286
|
+
print(f"🚀 开始执行裁剪 (无消息ID配置)...")
|
|
287
|
+
pruned_conversations = pruner.prune_conversations(original_conversations)
|
|
288
|
+
|
|
289
|
+
# 验证结果
|
|
290
|
+
print(f"\n📊 裁剪结果分析:")
|
|
291
|
+
print(f" 原始消息数量: {len(original_conversations)}")
|
|
292
|
+
print(f" 裁剪后数量: {len(pruned_conversations)}")
|
|
293
|
+
|
|
294
|
+
# 获取统计信息
|
|
295
|
+
stats = pruner.get_pruning_statistics()
|
|
296
|
+
print(f"\n📈 裁剪统计信息:")
|
|
297
|
+
print(f" 消息ID裁剪已应用: {stats['range_pruning']['applied']}")
|
|
298
|
+
print(f" 消息ID裁剪成功: {stats['range_pruning']['success']}")
|
|
299
|
+
|
|
300
|
+
# 验证没有应用消息ID裁剪
|
|
301
|
+
if not stats['range_pruning']['applied']:
|
|
302
|
+
print(f"✅ 正确: 无消息ID配置时跳过了消息ID裁剪")
|
|
303
|
+
return True
|
|
304
|
+
else:
|
|
305
|
+
print(f"❌ 错误: 无消息ID配置时不应该应用消息ID裁剪")
|
|
306
|
+
return False
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def verify_tool_cleanup_logic():
|
|
310
|
+
"""验证工具输出清理逻辑"""
|
|
311
|
+
|
|
312
|
+
print("\n🔍 测试场景3: 验证工具输出清理逻辑")
|
|
313
|
+
print("=" * 80)
|
|
314
|
+
|
|
315
|
+
# 创建包含大量工具输出的会话数据
|
|
316
|
+
large_tool_output = "def example_function():\n pass\n" * 100 # 创建大量内容
|
|
317
|
+
|
|
318
|
+
conversations_with_tools = [
|
|
319
|
+
{
|
|
320
|
+
"role": "user",
|
|
321
|
+
"content": "Please read a file",
|
|
322
|
+
"message_id": "tool_test_001"
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
"role": "assistant",
|
|
326
|
+
"content": "I'll read the file for you.\n\n<read_file>\n<path>example.py</path>\n</read_file>",
|
|
327
|
+
"message_id": "tool_test_002"
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
"role": "user",
|
|
331
|
+
"content": f"<tool_result tool_name='read_file' success='true'><message>File read successfully</message><content>{large_tool_output}</content></tool_result>",
|
|
332
|
+
"message_id": "tool_test_003"
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
"role": "assistant",
|
|
336
|
+
"content": "I can see the file content. It contains many function definitions.",
|
|
337
|
+
"message_id": "tool_test_004"
|
|
338
|
+
}
|
|
339
|
+
]
|
|
340
|
+
|
|
341
|
+
# 使用小的token阈值来触发工具清理
|
|
342
|
+
args = AutoCoderArgs(
|
|
343
|
+
source_dir=".",
|
|
344
|
+
conversation_prune_safe_zone_tokens=1000, # 小阈值触发清理
|
|
345
|
+
context_prune=True,
|
|
346
|
+
context_prune_strategy="extract",
|
|
347
|
+
query="测试工具清理逻辑"
|
|
348
|
+
)
|
|
349
|
+
|
|
350
|
+
llm = get_llm("v3_chat", product_mode="lite")
|
|
351
|
+
|
|
352
|
+
# 不使用消息ID配置,只测试工具清理
|
|
353
|
+
# 为工具清理测试使用一个测试会话ID
|
|
354
|
+
test_conversation_id = "tool-cleanup-test-conversation"
|
|
355
|
+
pruner = AgenticConversationPruner(args=args, llm=llm, conversation_id=test_conversation_id)
|
|
356
|
+
|
|
357
|
+
print(f"🚀 开始执行工具输出清理...")
|
|
358
|
+
|
|
359
|
+
# 计算原始token数
|
|
360
|
+
from autocoder.common.tokens import count_string_tokens
|
|
361
|
+
original_tokens = count_string_tokens(json.dumps(conversations_with_tools, ensure_ascii=False))
|
|
362
|
+
print(f" 原始token数: {original_tokens}")
|
|
363
|
+
|
|
364
|
+
pruned_conversations = pruner.prune_conversations(conversations_with_tools)
|
|
365
|
+
|
|
366
|
+
# 计算清理后token数
|
|
367
|
+
final_tokens = count_string_tokens(json.dumps(pruned_conversations, ensure_ascii=False))
|
|
368
|
+
print(f" 清理后token数: {final_tokens}")
|
|
369
|
+
print(f" Token减少: {original_tokens - final_tokens} ({((original_tokens - final_tokens) / original_tokens * 100):.1f}%)")
|
|
370
|
+
|
|
371
|
+
# 检查工具结果是否被清理
|
|
372
|
+
tool_result_cleaned = False
|
|
373
|
+
for conv in pruned_conversations:
|
|
374
|
+
content = conv.get("content", "")
|
|
375
|
+
if "tool_result" in content and "Content cleared to save tokens" in content:
|
|
376
|
+
tool_result_cleaned = True
|
|
377
|
+
break
|
|
378
|
+
|
|
379
|
+
if tool_result_cleaned:
|
|
380
|
+
print(f"✅ 正确: 工具输出已被清理")
|
|
381
|
+
return True
|
|
382
|
+
else:
|
|
383
|
+
print(f"⚠️ 注意: 工具输出可能未被清理(可能因为token数仍在阈值内)")
|
|
384
|
+
return True
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
def main():
|
|
388
|
+
"""主测试函数"""
|
|
389
|
+
print("🧪 AgenticConversationPruner 消息ID裁剪逻辑验证")
|
|
390
|
+
print(f"📅 测试时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
|
391
|
+
print("=" * 80)
|
|
392
|
+
|
|
393
|
+
test_results = []
|
|
394
|
+
|
|
395
|
+
try:
|
|
396
|
+
# 测试场景1: 有消息ID配置的裁剪
|
|
397
|
+
result1 = verify_pruning_with_message_ids()
|
|
398
|
+
test_results.append(("有消息ID配置的裁剪", result1))
|
|
399
|
+
|
|
400
|
+
# 测试场景2: 无消息ID配置的裁剪
|
|
401
|
+
result2 = verify_pruning_without_message_ids()
|
|
402
|
+
test_results.append(("无消息ID配置的裁剪", result2))
|
|
403
|
+
|
|
404
|
+
# 测试场景3: 工具输出清理
|
|
405
|
+
result3 = verify_tool_cleanup_logic()
|
|
406
|
+
test_results.append(("工具输出清理逻辑", result3))
|
|
407
|
+
|
|
408
|
+
except Exception as e:
|
|
409
|
+
print(f"❌ 测试过程中发生错误: {str(e)}")
|
|
410
|
+
import traceback
|
|
411
|
+
traceback.print_exc()
|
|
412
|
+
return False
|
|
413
|
+
|
|
414
|
+
# 汇总测试结果
|
|
415
|
+
print(f"\n🎯 测试结果汇总")
|
|
416
|
+
print("=" * 80)
|
|
417
|
+
|
|
418
|
+
all_passed = True
|
|
419
|
+
for test_name, result in test_results:
|
|
420
|
+
status = "✅ 通过" if result else "❌ 失败"
|
|
421
|
+
print(f" {test_name}: {status}")
|
|
422
|
+
if not result:
|
|
423
|
+
all_passed = False
|
|
424
|
+
|
|
425
|
+
print(f"\n{'🎉 所有测试通过!' if all_passed else '⚠️ 部分测试失败,请检查上述结果'}")
|
|
426
|
+
|
|
427
|
+
return all_passed
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
if __name__ == "__main__":
|
|
431
|
+
success = main()
|
|
432
|
+
sys.exit(0 if success else 1)
|