jarvis-ai-assistant 0.7.8__py3-none-any.whl → 1.0.2__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.
- jarvis/__init__.py +1 -1
- jarvis/jarvis_agent/__init__.py +567 -222
- jarvis/jarvis_agent/agent_manager.py +19 -12
- jarvis/jarvis_agent/builtin_input_handler.py +79 -11
- jarvis/jarvis_agent/config_editor.py +7 -2
- jarvis/jarvis_agent/event_bus.py +24 -13
- jarvis/jarvis_agent/events.py +19 -1
- jarvis/jarvis_agent/file_context_handler.py +67 -64
- jarvis/jarvis_agent/file_methodology_manager.py +38 -24
- jarvis/jarvis_agent/jarvis.py +186 -114
- jarvis/jarvis_agent/language_extractors/__init__.py +8 -1
- jarvis/jarvis_agent/language_extractors/c_extractor.py +7 -4
- jarvis/jarvis_agent/language_extractors/cpp_extractor.py +9 -4
- jarvis/jarvis_agent/language_extractors/go_extractor.py +7 -4
- jarvis/jarvis_agent/language_extractors/java_extractor.py +27 -20
- jarvis/jarvis_agent/language_extractors/javascript_extractor.py +22 -17
- jarvis/jarvis_agent/language_extractors/python_extractor.py +7 -4
- jarvis/jarvis_agent/language_extractors/rust_extractor.py +7 -4
- jarvis/jarvis_agent/language_extractors/typescript_extractor.py +22 -17
- jarvis/jarvis_agent/language_support_info.py +250 -219
- jarvis/jarvis_agent/main.py +19 -23
- jarvis/jarvis_agent/memory_manager.py +9 -6
- jarvis/jarvis_agent/methodology_share_manager.py +21 -15
- jarvis/jarvis_agent/output_handler.py +4 -2
- jarvis/jarvis_agent/prompt_builder.py +7 -6
- jarvis/jarvis_agent/prompt_manager.py +113 -8
- jarvis/jarvis_agent/prompts.py +317 -85
- jarvis/jarvis_agent/protocols.py +5 -2
- jarvis/jarvis_agent/run_loop.py +192 -32
- jarvis/jarvis_agent/session_manager.py +7 -3
- jarvis/jarvis_agent/share_manager.py +23 -13
- jarvis/jarvis_agent/shell_input_handler.py +12 -8
- jarvis/jarvis_agent/stdio_redirect.py +25 -26
- jarvis/jarvis_agent/task_analyzer.py +29 -23
- jarvis/jarvis_agent/task_list.py +869 -0
- jarvis/jarvis_agent/task_manager.py +26 -23
- jarvis/jarvis_agent/tool_executor.py +6 -5
- jarvis/jarvis_agent/tool_share_manager.py +24 -14
- jarvis/jarvis_agent/user_interaction.py +3 -3
- jarvis/jarvis_agent/utils.py +9 -1
- jarvis/jarvis_agent/web_bridge.py +37 -17
- jarvis/jarvis_agent/web_output_sink.py +5 -2
- jarvis/jarvis_agent/web_server.py +165 -36
- jarvis/jarvis_c2rust/__init__.py +1 -1
- jarvis/jarvis_c2rust/cli.py +260 -141
- jarvis/jarvis_c2rust/collector.py +37 -18
- jarvis/jarvis_c2rust/constants.py +60 -0
- jarvis/jarvis_c2rust/library_replacer.py +242 -1010
- jarvis/jarvis_c2rust/library_replacer_checkpoint.py +133 -0
- jarvis/jarvis_c2rust/library_replacer_llm.py +287 -0
- jarvis/jarvis_c2rust/library_replacer_loader.py +191 -0
- jarvis/jarvis_c2rust/library_replacer_output.py +134 -0
- jarvis/jarvis_c2rust/library_replacer_prompts.py +124 -0
- jarvis/jarvis_c2rust/library_replacer_utils.py +188 -0
- jarvis/jarvis_c2rust/llm_module_agent.py +98 -1044
- jarvis/jarvis_c2rust/llm_module_agent_apply.py +170 -0
- jarvis/jarvis_c2rust/llm_module_agent_executor.py +288 -0
- jarvis/jarvis_c2rust/llm_module_agent_loader.py +170 -0
- jarvis/jarvis_c2rust/llm_module_agent_prompts.py +268 -0
- jarvis/jarvis_c2rust/llm_module_agent_types.py +57 -0
- jarvis/jarvis_c2rust/llm_module_agent_utils.py +150 -0
- jarvis/jarvis_c2rust/llm_module_agent_validator.py +119 -0
- jarvis/jarvis_c2rust/loaders.py +28 -10
- jarvis/jarvis_c2rust/models.py +5 -2
- jarvis/jarvis_c2rust/optimizer.py +192 -1974
- jarvis/jarvis_c2rust/optimizer_build_fix.py +286 -0
- jarvis/jarvis_c2rust/optimizer_clippy.py +766 -0
- jarvis/jarvis_c2rust/optimizer_config.py +49 -0
- jarvis/jarvis_c2rust/optimizer_docs.py +183 -0
- jarvis/jarvis_c2rust/optimizer_options.py +48 -0
- jarvis/jarvis_c2rust/optimizer_progress.py +469 -0
- jarvis/jarvis_c2rust/optimizer_report.py +52 -0
- jarvis/jarvis_c2rust/optimizer_unsafe.py +309 -0
- jarvis/jarvis_c2rust/optimizer_utils.py +469 -0
- jarvis/jarvis_c2rust/optimizer_visibility.py +185 -0
- jarvis/jarvis_c2rust/scanner.py +229 -166
- jarvis/jarvis_c2rust/transpiler.py +531 -2732
- jarvis/jarvis_c2rust/transpiler_agents.py +503 -0
- jarvis/jarvis_c2rust/transpiler_build.py +1294 -0
- jarvis/jarvis_c2rust/transpiler_codegen.py +204 -0
- jarvis/jarvis_c2rust/transpiler_compile.py +146 -0
- jarvis/jarvis_c2rust/transpiler_config.py +178 -0
- jarvis/jarvis_c2rust/transpiler_context.py +122 -0
- jarvis/jarvis_c2rust/transpiler_executor.py +516 -0
- jarvis/jarvis_c2rust/transpiler_generation.py +278 -0
- jarvis/jarvis_c2rust/transpiler_git.py +163 -0
- jarvis/jarvis_c2rust/transpiler_mod_utils.py +225 -0
- jarvis/jarvis_c2rust/transpiler_modules.py +336 -0
- jarvis/jarvis_c2rust/transpiler_planning.py +394 -0
- jarvis/jarvis_c2rust/transpiler_review.py +1196 -0
- jarvis/jarvis_c2rust/transpiler_symbols.py +176 -0
- jarvis/jarvis_c2rust/utils.py +269 -79
- jarvis/jarvis_code_agent/after_change.py +233 -0
- jarvis/jarvis_code_agent/build_validation_config.py +37 -30
- jarvis/jarvis_code_agent/builtin_rules.py +68 -0
- jarvis/jarvis_code_agent/code_agent.py +976 -1517
- jarvis/jarvis_code_agent/code_agent_build.py +227 -0
- jarvis/jarvis_code_agent/code_agent_diff.py +246 -0
- jarvis/jarvis_code_agent/code_agent_git.py +525 -0
- jarvis/jarvis_code_agent/code_agent_impact.py +177 -0
- jarvis/jarvis_code_agent/code_agent_lint.py +283 -0
- jarvis/jarvis_code_agent/code_agent_llm.py +159 -0
- jarvis/jarvis_code_agent/code_agent_postprocess.py +105 -0
- jarvis/jarvis_code_agent/code_agent_prompts.py +46 -0
- jarvis/jarvis_code_agent/code_agent_rules.py +305 -0
- jarvis/jarvis_code_agent/code_analyzer/__init__.py +52 -48
- jarvis/jarvis_code_agent/code_analyzer/base_language.py +12 -10
- jarvis/jarvis_code_agent/code_analyzer/build_validator/__init__.py +12 -11
- jarvis/jarvis_code_agent/code_analyzer/build_validator/base.py +16 -12
- jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +26 -17
- jarvis/jarvis_code_agent/code_analyzer/build_validator/detector.py +558 -104
- jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +27 -16
- jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +22 -18
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +21 -16
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +20 -16
- jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +27 -16
- jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +47 -23
- jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +71 -37
- jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +162 -35
- jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +111 -57
- jarvis/jarvis_code_agent/code_analyzer/build_validator.py +18 -12
- jarvis/jarvis_code_agent/code_analyzer/context_manager.py +185 -183
- jarvis/jarvis_code_agent/code_analyzer/context_recommender.py +2 -1
- jarvis/jarvis_code_agent/code_analyzer/dependency_analyzer.py +24 -15
- jarvis/jarvis_code_agent/code_analyzer/file_ignore.py +227 -141
- jarvis/jarvis_code_agent/code_analyzer/impact_analyzer.py +321 -247
- jarvis/jarvis_code_agent/code_analyzer/language_registry.py +37 -29
- jarvis/jarvis_code_agent/code_analyzer/language_support.py +21 -13
- jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +15 -9
- jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +75 -45
- jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +87 -52
- jarvis/jarvis_code_agent/code_analyzer/languages/java_language.py +84 -51
- jarvis/jarvis_code_agent/code_analyzer/languages/javascript_language.py +94 -64
- jarvis/jarvis_code_agent/code_analyzer/languages/python_language.py +109 -71
- jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +97 -63
- jarvis/jarvis_code_agent/code_analyzer/languages/typescript_language.py +103 -69
- jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +271 -268
- jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +76 -64
- jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +92 -19
- jarvis/jarvis_code_agent/diff_visualizer.py +998 -0
- jarvis/jarvis_code_agent/lint.py +223 -524
- jarvis/jarvis_code_agent/rule_share_manager.py +158 -0
- jarvis/jarvis_code_agent/rules/clean_code.md +144 -0
- jarvis/jarvis_code_agent/rules/code_review.md +115 -0
- jarvis/jarvis_code_agent/rules/documentation.md +165 -0
- jarvis/jarvis_code_agent/rules/generate_rules.md +52 -0
- jarvis/jarvis_code_agent/rules/performance.md +158 -0
- jarvis/jarvis_code_agent/rules/refactoring.md +139 -0
- jarvis/jarvis_code_agent/rules/security.md +160 -0
- jarvis/jarvis_code_agent/rules/tdd.md +78 -0
- jarvis/jarvis_code_agent/test_rules/cpp_test.md +118 -0
- jarvis/jarvis_code_agent/test_rules/go_test.md +98 -0
- jarvis/jarvis_code_agent/test_rules/java_test.md +99 -0
- jarvis/jarvis_code_agent/test_rules/javascript_test.md +113 -0
- jarvis/jarvis_code_agent/test_rules/php_test.md +117 -0
- jarvis/jarvis_code_agent/test_rules/python_test.md +91 -0
- jarvis/jarvis_code_agent/test_rules/ruby_test.md +102 -0
- jarvis/jarvis_code_agent/test_rules/rust_test.md +86 -0
- jarvis/jarvis_code_agent/utils.py +36 -26
- jarvis/jarvis_code_analysis/checklists/loader.py +21 -21
- jarvis/jarvis_code_analysis/code_review.py +64 -33
- jarvis/jarvis_data/config_schema.json +285 -192
- jarvis/jarvis_git_squash/main.py +8 -6
- jarvis/jarvis_git_utils/git_commiter.py +53 -76
- jarvis/jarvis_mcp/__init__.py +5 -2
- jarvis/jarvis_mcp/sse_mcp_client.py +40 -30
- jarvis/jarvis_mcp/stdio_mcp_client.py +27 -19
- jarvis/jarvis_mcp/streamable_mcp_client.py +35 -26
- jarvis/jarvis_memory_organizer/memory_organizer.py +78 -55
- jarvis/jarvis_methodology/main.py +48 -39
- jarvis/jarvis_multi_agent/__init__.py +56 -23
- jarvis/jarvis_multi_agent/main.py +15 -18
- jarvis/jarvis_platform/base.py +179 -111
- jarvis/jarvis_platform/human.py +27 -16
- jarvis/jarvis_platform/kimi.py +52 -45
- jarvis/jarvis_platform/openai.py +101 -40
- jarvis/jarvis_platform/registry.py +51 -33
- jarvis/jarvis_platform/tongyi.py +68 -38
- jarvis/jarvis_platform/yuanbao.py +59 -43
- jarvis/jarvis_platform_manager/main.py +68 -76
- jarvis/jarvis_platform_manager/service.py +24 -14
- jarvis/jarvis_rag/README_CONFIG.md +314 -0
- jarvis/jarvis_rag/README_DYNAMIC_LOADING.md +311 -0
- jarvis/jarvis_rag/README_ONLINE_MODELS.md +230 -0
- jarvis/jarvis_rag/__init__.py +57 -4
- jarvis/jarvis_rag/cache.py +3 -1
- jarvis/jarvis_rag/cli.py +48 -68
- jarvis/jarvis_rag/embedding_interface.py +39 -0
- jarvis/jarvis_rag/embedding_manager.py +7 -230
- jarvis/jarvis_rag/embeddings/__init__.py +41 -0
- jarvis/jarvis_rag/embeddings/base.py +114 -0
- jarvis/jarvis_rag/embeddings/cohere.py +66 -0
- jarvis/jarvis_rag/embeddings/edgefn.py +117 -0
- jarvis/jarvis_rag/embeddings/local.py +260 -0
- jarvis/jarvis_rag/embeddings/openai.py +62 -0
- jarvis/jarvis_rag/embeddings/registry.py +293 -0
- jarvis/jarvis_rag/llm_interface.py +8 -6
- jarvis/jarvis_rag/query_rewriter.py +8 -9
- jarvis/jarvis_rag/rag_pipeline.py +61 -52
- jarvis/jarvis_rag/reranker.py +7 -75
- jarvis/jarvis_rag/reranker_interface.py +32 -0
- jarvis/jarvis_rag/rerankers/__init__.py +41 -0
- jarvis/jarvis_rag/rerankers/base.py +109 -0
- jarvis/jarvis_rag/rerankers/cohere.py +67 -0
- jarvis/jarvis_rag/rerankers/edgefn.py +140 -0
- jarvis/jarvis_rag/rerankers/jina.py +79 -0
- jarvis/jarvis_rag/rerankers/local.py +89 -0
- jarvis/jarvis_rag/rerankers/registry.py +293 -0
- jarvis/jarvis_rag/retriever.py +58 -43
- jarvis/jarvis_sec/__init__.py +66 -141
- jarvis/jarvis_sec/agents.py +21 -17
- jarvis/jarvis_sec/analysis.py +80 -33
- jarvis/jarvis_sec/checkers/__init__.py +7 -13
- jarvis/jarvis_sec/checkers/c_checker.py +356 -164
- jarvis/jarvis_sec/checkers/rust_checker.py +47 -29
- jarvis/jarvis_sec/cli.py +43 -21
- jarvis/jarvis_sec/clustering.py +430 -272
- jarvis/jarvis_sec/file_manager.py +99 -55
- jarvis/jarvis_sec/parsers.py +9 -6
- jarvis/jarvis_sec/prompts.py +4 -3
- jarvis/jarvis_sec/report.py +44 -22
- jarvis/jarvis_sec/review.py +180 -107
- jarvis/jarvis_sec/status.py +50 -41
- jarvis/jarvis_sec/types.py +3 -0
- jarvis/jarvis_sec/utils.py +160 -83
- jarvis/jarvis_sec/verification.py +411 -181
- jarvis/jarvis_sec/workflow.py +132 -21
- jarvis/jarvis_smart_shell/main.py +28 -41
- jarvis/jarvis_stats/cli.py +14 -12
- jarvis/jarvis_stats/stats.py +28 -19
- jarvis/jarvis_stats/storage.py +14 -8
- jarvis/jarvis_stats/visualizer.py +12 -7
- jarvis/jarvis_tools/base.py +5 -2
- jarvis/jarvis_tools/clear_memory.py +13 -9
- jarvis/jarvis_tools/cli/main.py +23 -18
- jarvis/jarvis_tools/edit_file.py +572 -873
- jarvis/jarvis_tools/execute_script.py +10 -7
- jarvis/jarvis_tools/file_analyzer.py +7 -8
- jarvis/jarvis_tools/meta_agent.py +287 -0
- jarvis/jarvis_tools/methodology.py +5 -3
- jarvis/jarvis_tools/read_code.py +305 -1438
- jarvis/jarvis_tools/read_symbols.py +50 -17
- jarvis/jarvis_tools/read_webpage.py +19 -18
- jarvis/jarvis_tools/registry.py +435 -156
- jarvis/jarvis_tools/retrieve_memory.py +16 -11
- jarvis/jarvis_tools/save_memory.py +8 -6
- jarvis/jarvis_tools/search_web.py +31 -31
- jarvis/jarvis_tools/sub_agent.py +32 -28
- jarvis/jarvis_tools/sub_code_agent.py +44 -60
- jarvis/jarvis_tools/task_list_manager.py +1811 -0
- jarvis/jarvis_tools/virtual_tty.py +29 -19
- jarvis/jarvis_utils/__init__.py +4 -0
- jarvis/jarvis_utils/builtin_replace_map.py +2 -1
- jarvis/jarvis_utils/clipboard.py +9 -8
- jarvis/jarvis_utils/collections.py +331 -0
- jarvis/jarvis_utils/config.py +699 -194
- jarvis/jarvis_utils/dialogue_recorder.py +294 -0
- jarvis/jarvis_utils/embedding.py +6 -3
- jarvis/jarvis_utils/file_processors.py +7 -1
- jarvis/jarvis_utils/fzf.py +9 -3
- jarvis/jarvis_utils/git_utils.py +71 -42
- jarvis/jarvis_utils/globals.py +116 -32
- jarvis/jarvis_utils/http.py +6 -2
- jarvis/jarvis_utils/input.py +318 -83
- jarvis/jarvis_utils/jsonnet_compat.py +119 -104
- jarvis/jarvis_utils/methodology.py +37 -28
- jarvis/jarvis_utils/output.py +201 -44
- jarvis/jarvis_utils/utils.py +986 -628
- {jarvis_ai_assistant-0.7.8.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/METADATA +49 -33
- jarvis_ai_assistant-1.0.2.dist-info/RECORD +304 -0
- jarvis/jarvis_code_agent/code_analyzer/structured_code.py +0 -556
- jarvis/jarvis_tools/generate_new_tool.py +0 -205
- jarvis/jarvis_tools/lsp_client.py +0 -1552
- jarvis/jarvis_tools/rewrite_file.py +0 -105
- jarvis_ai_assistant-0.7.8.dist-info/RECORD +0 -218
- {jarvis_ai_assistant-0.7.8.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.7.8.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.7.8.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.7.8.dist-info → jarvis_ai_assistant-1.0.2.dist-info}/top_level.txt +0 -0
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
"""Agent管理器模块,负责Agent的初始化和任务执行"""
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
from typing import Callable
|
|
5
|
+
from typing import Optional
|
|
4
6
|
|
|
5
7
|
import typer
|
|
6
8
|
|
|
7
|
-
from jarvis.jarvis_agent import
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
origin_agent_system_prompt,
|
|
11
|
-
)
|
|
9
|
+
from jarvis.jarvis_agent import Agent
|
|
10
|
+
from jarvis.jarvis_agent import get_multiline_input
|
|
11
|
+
from jarvis.jarvis_agent import origin_agent_system_prompt
|
|
12
12
|
from jarvis.jarvis_agent.task_manager import TaskManager
|
|
13
|
-
from jarvis.jarvis_utils.config import is_non_interactive
|
|
13
|
+
from jarvis.jarvis_utils.config import is_non_interactive
|
|
14
|
+
from jarvis.jarvis_utils.config import is_skip_predefined_tasks
|
|
15
|
+
from jarvis.jarvis_utils.output import PrettyOutput
|
|
14
16
|
|
|
15
17
|
|
|
16
18
|
class AgentManager:
|
|
@@ -44,7 +46,7 @@ class AgentManager:
|
|
|
44
46
|
if self.tool_group:
|
|
45
47
|
from jarvis.jarvis_utils.config import set_config
|
|
46
48
|
|
|
47
|
-
set_config("
|
|
49
|
+
set_config("tool_group", self.tool_group)
|
|
48
50
|
|
|
49
51
|
self.agent = Agent(
|
|
50
52
|
system_prompt=origin_agent_system_prompt,
|
|
@@ -60,9 +62,9 @@ class AgentManager:
|
|
|
60
62
|
# 尝试恢复会话
|
|
61
63
|
if self.restore_session:
|
|
62
64
|
if self.agent.restore_session():
|
|
63
|
-
|
|
65
|
+
PrettyOutput.auto_print("✅ 会话已成功恢复。")
|
|
64
66
|
else:
|
|
65
|
-
|
|
67
|
+
PrettyOutput.auto_print("⚠️ 无法恢复会话。")
|
|
66
68
|
|
|
67
69
|
return self.agent
|
|
68
70
|
|
|
@@ -77,11 +79,16 @@ class AgentManager:
|
|
|
77
79
|
raise typer.Exit(code=0)
|
|
78
80
|
|
|
79
81
|
# 处理预定义任务(非交互模式下跳过;支持配置跳过加载;命令行指定任务时跳过)
|
|
80
|
-
if
|
|
82
|
+
if (
|
|
83
|
+
not is_non_interactive()
|
|
84
|
+
and not is_skip_predefined_tasks()
|
|
85
|
+
and not task_content
|
|
86
|
+
and self.agent.first
|
|
87
|
+
):
|
|
81
88
|
task_manager = TaskManager()
|
|
82
89
|
tasks = task_manager.load_tasks()
|
|
83
90
|
if tasks and (selected_task := task_manager.select_task(tasks)):
|
|
84
|
-
|
|
91
|
+
PrettyOutput.auto_print(f"ℹ️ 开始执行任务: \n{selected_task}")
|
|
85
92
|
self.agent.run(selected_task)
|
|
86
93
|
raise typer.Exit(code=0)
|
|
87
94
|
|
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import re
|
|
3
3
|
import sys
|
|
4
|
-
from typing import Any
|
|
4
|
+
from typing import Any
|
|
5
|
+
from typing import Tuple
|
|
5
6
|
|
|
6
7
|
from jarvis.jarvis_utils.config import get_replace_map
|
|
8
|
+
from jarvis.jarvis_utils.output import PrettyOutput
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _get_rule_content(rule_name: str) -> str | None:
|
|
12
|
+
"""获取规则内容
|
|
13
|
+
|
|
14
|
+
参数:
|
|
15
|
+
rule_name: 规则名称
|
|
16
|
+
|
|
17
|
+
返回:
|
|
18
|
+
str | None: 规则内容,如果未找到则返回 None
|
|
19
|
+
"""
|
|
20
|
+
try:
|
|
21
|
+
import os
|
|
22
|
+
|
|
23
|
+
from jarvis.jarvis_code_agent.code_agent_rules import RulesManager
|
|
24
|
+
|
|
25
|
+
# 使用当前工作目录作为root_dir
|
|
26
|
+
rules_manager = RulesManager(root_dir=os.getcwd())
|
|
27
|
+
return rules_manager.get_named_rule(rule_name)
|
|
28
|
+
except ImportError:
|
|
29
|
+
return None
|
|
7
30
|
|
|
8
31
|
|
|
9
32
|
def builtin_input_handler(user_input: str, agent_: Any) -> Tuple[str, bool]:
|
|
@@ -26,11 +49,19 @@ def builtin_input_handler(user_input: str, agent_: Any) -> Tuple[str, bool]:
|
|
|
26
49
|
if not special_tags:
|
|
27
50
|
return user_input, False
|
|
28
51
|
|
|
52
|
+
# 检查是否包含Pin标记(需要最后处理)
|
|
53
|
+
has_pin = "Pin" in special_tags
|
|
54
|
+
|
|
29
55
|
# 获取替换映射表
|
|
30
56
|
replace_map = get_replace_map()
|
|
31
|
-
|
|
57
|
+
processed_tag = set()
|
|
58
|
+
add_on_prompt = ""
|
|
59
|
+
|
|
60
|
+
# 处理所有非Pin标记
|
|
61
|
+
modified_input = user_input
|
|
62
|
+
|
|
32
63
|
for tag in special_tags:
|
|
33
|
-
#
|
|
64
|
+
# 优先处理会立即返回的特殊标记(不包含Pin)
|
|
34
65
|
if tag == "Summary":
|
|
35
66
|
summary = agent._summarize_and_clear_history()
|
|
36
67
|
memory_tags_prompt = agent.memory_manager.prepare_memory_tags_prompt()
|
|
@@ -55,14 +86,19 @@ def builtin_input_handler(user_input: str, agent_: Any) -> Tuple[str, bool]:
|
|
|
55
86
|
return "", True
|
|
56
87
|
elif tag == "SaveSession":
|
|
57
88
|
if agent.save_session():
|
|
58
|
-
|
|
89
|
+
PrettyOutput.auto_print("✅ 会话已成功保存。正在退出...")
|
|
59
90
|
sys.exit(0)
|
|
60
91
|
else:
|
|
61
|
-
|
|
92
|
+
PrettyOutput.auto_print("❌ 保存会话失败。")
|
|
62
93
|
return "", True
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
94
|
+
elif tag == "Quiet":
|
|
95
|
+
agent.set_non_interactive(True)
|
|
96
|
+
PrettyOutput.auto_print("🔇 已切换到静默模式(非交互模式)")
|
|
97
|
+
modified_input = modified_input.replace("'<Quiet>'", "")
|
|
98
|
+
continue
|
|
99
|
+
elif tag == "Pin":
|
|
100
|
+
# Pin标记最后处理,跳过此处
|
|
101
|
+
continue
|
|
66
102
|
|
|
67
103
|
# 处理普通替换标记
|
|
68
104
|
if tag in replace_map:
|
|
@@ -72,13 +108,45 @@ def builtin_input_handler(user_input: str, agent_: Any) -> Tuple[str, bool]:
|
|
|
72
108
|
and replace_map[tag]["append"]
|
|
73
109
|
and tag not in processed_tag
|
|
74
110
|
):
|
|
75
|
-
|
|
111
|
+
modified_input = modified_input.replace(f"'<{tag}>'", "")
|
|
76
112
|
add_on_prompt += replace_map[tag]["template"] + "\n"
|
|
77
113
|
else:
|
|
78
|
-
|
|
114
|
+
modified_input = modified_input.replace(
|
|
79
115
|
f"'<{tag}>'", replace_map[tag]["template"]
|
|
80
116
|
)
|
|
117
|
+
elif tag.startswith("rule:"):
|
|
118
|
+
# 处理 rule:xxx 格式的规则标记
|
|
119
|
+
rule_name = tag[5:] # 去掉 "rule:" 前缀
|
|
120
|
+
rule_content = _get_rule_content(rule_name)
|
|
121
|
+
if rule_content:
|
|
122
|
+
# 记录运行时加载的规则到CodeAgent
|
|
123
|
+
try:
|
|
124
|
+
if agent is not None and hasattr(agent, "add_runtime_rule"):
|
|
125
|
+
agent.add_runtime_rule(rule_name)
|
|
126
|
+
except Exception:
|
|
127
|
+
# 静默处理任何错误,不影响正常功能
|
|
128
|
+
pass
|
|
129
|
+
|
|
130
|
+
separator = "\n" + "=" * 50 + "\n"
|
|
131
|
+
modified_input = modified_input.replace(
|
|
132
|
+
f"'<{tag}>'", f"<rule>\n{rule_content}\n</rule>{separator}"
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# 最后处理Pin标记
|
|
136
|
+
if has_pin:
|
|
137
|
+
# 移除所有Pin标记后的处理内容,追加到pin_content
|
|
138
|
+
processed_content = modified_input.replace("'<Pin>'", "").strip()
|
|
139
|
+
if processed_content:
|
|
140
|
+
if agent.pin_content:
|
|
141
|
+
agent.pin_content += "\n" + processed_content
|
|
142
|
+
else:
|
|
143
|
+
agent.pin_content = processed_content
|
|
144
|
+
PrettyOutput.auto_print(f"📌 已固定内容: {processed_content[:50]}...")
|
|
81
145
|
|
|
146
|
+
# 返回处理后的内容(移除了Pin标记)
|
|
82
147
|
agent.set_addon_prompt(add_on_prompt)
|
|
148
|
+
return processed_content, False
|
|
83
149
|
|
|
84
|
-
|
|
150
|
+
# 设置附加提示词
|
|
151
|
+
agent.set_addon_prompt(add_on_prompt)
|
|
152
|
+
return modified_input, False
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
"""配置编辑器模块,负责配置文件的编辑功能"""
|
|
3
|
+
|
|
3
4
|
import os
|
|
4
5
|
import platform
|
|
5
6
|
import shutil
|
|
@@ -9,6 +10,8 @@ from typing import Optional
|
|
|
9
10
|
|
|
10
11
|
import typer
|
|
11
12
|
|
|
13
|
+
from jarvis.jarvis_utils.output import PrettyOutput
|
|
14
|
+
|
|
12
15
|
|
|
13
16
|
class ConfigEditor:
|
|
14
17
|
"""配置文件编辑器"""
|
|
@@ -45,8 +48,10 @@ class ConfigEditor:
|
|
|
45
48
|
)
|
|
46
49
|
raise typer.Exit(code=0)
|
|
47
50
|
except (subprocess.CalledProcessError, FileNotFoundError) as e:
|
|
48
|
-
|
|
51
|
+
PrettyOutput.auto_print(f"❌ Failed to open editor: {e}")
|
|
49
52
|
raise typer.Exit(code=1)
|
|
50
53
|
else:
|
|
51
|
-
|
|
54
|
+
PrettyOutput.auto_print(
|
|
55
|
+
"❌ No suitable editor found. Please install one of: vim, nano, emacs, code"
|
|
56
|
+
)
|
|
52
57
|
raise typer.Exit(code=1)
|
jarvis/jarvis_agent/event_bus.py
CHANGED
|
@@ -8,8 +8,13 @@
|
|
|
8
8
|
- 不引入额外依赖,便于在 Agent 中渐进集成
|
|
9
9
|
- 支持优先级排序,优先级数字越小,执行越早
|
|
10
10
|
"""
|
|
11
|
+
|
|
11
12
|
from collections import defaultdict
|
|
12
|
-
from typing import
|
|
13
|
+
from typing import Any
|
|
14
|
+
from typing import Callable
|
|
15
|
+
from typing import DefaultDict
|
|
16
|
+
from typing import List
|
|
17
|
+
from typing import Tuple
|
|
13
18
|
|
|
14
19
|
|
|
15
20
|
class EventBus:
|
|
@@ -18,7 +23,7 @@ class EventBus:
|
|
|
18
23
|
- subscribe(event, callback, priority=100): 订阅事件,支持优先级
|
|
19
24
|
- emit(event, **kwargs): 广播事件,按优先级顺序执行回调
|
|
20
25
|
- unsubscribe(event, callback): 取消订阅
|
|
21
|
-
|
|
26
|
+
|
|
22
27
|
优先级说明:
|
|
23
28
|
- 数字越小,优先级越高,执行越早
|
|
24
29
|
- 默认优先级为 100(中等优先级)
|
|
@@ -29,18 +34,24 @@ class EventBus:
|
|
|
29
34
|
def __init__(self) -> None:
|
|
30
35
|
# 存储 (priority, order, callback) 元组列表,按优先级和注册顺序排序
|
|
31
36
|
# order 用于相同优先级时保持注册顺序
|
|
32
|
-
self._listeners: DefaultDict[
|
|
37
|
+
self._listeners: DefaultDict[
|
|
38
|
+
str, List[Tuple[int, int, Callable[..., None]]]
|
|
39
|
+
] = defaultdict(list)
|
|
33
40
|
# 注册顺序计数器(每个事件独立计数)
|
|
34
41
|
self._order_counter: DefaultDict[str, int] = defaultdict(int)
|
|
35
42
|
# 缓存排序后的回调列表,避免每次emit都排序
|
|
36
|
-
self._sorted_cache: DefaultDict[str, List[Callable[..., None]]] = defaultdict(
|
|
43
|
+
self._sorted_cache: DefaultDict[str, List[Callable[..., None]]] = defaultdict(
|
|
44
|
+
list
|
|
45
|
+
)
|
|
37
46
|
# 标记是否需要重新排序
|
|
38
47
|
self._dirty: DefaultDict[str, bool] = defaultdict(lambda: False)
|
|
39
48
|
|
|
40
|
-
def subscribe(
|
|
49
|
+
def subscribe(
|
|
50
|
+
self, event: str, callback: Callable[..., None], priority: int = 100
|
|
51
|
+
) -> None:
|
|
41
52
|
"""
|
|
42
53
|
订阅事件。
|
|
43
|
-
|
|
54
|
+
|
|
44
55
|
参数:
|
|
45
56
|
event: 事件名称
|
|
46
57
|
callback: 回调函数
|
|
@@ -60,7 +71,7 @@ class EventBus:
|
|
|
60
71
|
def unsubscribe(self, event: str, callback: Callable[..., None]) -> None:
|
|
61
72
|
"""
|
|
62
73
|
取消订阅事件。
|
|
63
|
-
|
|
74
|
+
|
|
64
75
|
参数:
|
|
65
76
|
event: 事件名称
|
|
66
77
|
callback: 要取消的回调函数
|
|
@@ -78,33 +89,33 @@ class EventBus:
|
|
|
78
89
|
def _get_sorted_callbacks(self, event: str) -> List[Callable[..., None]]:
|
|
79
90
|
"""
|
|
80
91
|
获取排序后的回调列表(带缓存)。
|
|
81
|
-
|
|
92
|
+
|
|
82
93
|
参数:
|
|
83
94
|
event: 事件名称
|
|
84
|
-
|
|
95
|
+
|
|
85
96
|
返回:
|
|
86
97
|
按优先级排序的回调函数列表(相同优先级时按注册顺序)
|
|
87
98
|
"""
|
|
88
99
|
# 如果缓存有效,直接返回
|
|
89
100
|
if not self._dirty[event] and event in self._sorted_cache:
|
|
90
101
|
return self._sorted_cache[event]
|
|
91
|
-
|
|
102
|
+
|
|
92
103
|
# 按优先级排序(数字越小优先级越高),相同优先级时按注册顺序(order)
|
|
93
104
|
listeners = self._listeners[event]
|
|
94
105
|
sorted_listeners = sorted(listeners, key=lambda x: (x[0], x[1]))
|
|
95
106
|
callbacks = [cb for _, _, cb in sorted_listeners]
|
|
96
|
-
|
|
107
|
+
|
|
97
108
|
# 更新缓存
|
|
98
109
|
self._sorted_cache[event] = callbacks
|
|
99
110
|
self._dirty[event] = False
|
|
100
|
-
|
|
111
|
+
|
|
101
112
|
return callbacks
|
|
102
113
|
|
|
103
114
|
def emit(self, event: str, **payload: Any) -> None:
|
|
104
115
|
"""
|
|
105
116
|
广播事件。回调中的异常将被捕获并忽略,以保证主流程稳定。
|
|
106
117
|
回调按优先级顺序执行(优先级数字越小,执行越早)。
|
|
107
|
-
|
|
118
|
+
|
|
108
119
|
参数:
|
|
109
120
|
event: 事件名称
|
|
110
121
|
**payload: 事件负载数据
|
jarvis/jarvis_agent/events.py
CHANGED
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
- 提供事件负载的类型提示,便于静态检查与后续文档化
|
|
8
8
|
- 本文件仅提供常量与类型定义,不改变现有行为
|
|
9
9
|
"""
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
from typing import Any
|
|
12
|
+
from typing import List
|
|
13
|
+
from typing import TypedDict
|
|
11
14
|
|
|
12
15
|
# 事件主题常量
|
|
13
16
|
BEFORE_TOOL_CALL = "before_tool_call"
|
|
@@ -44,12 +47,14 @@ class BeforeToolCallEvent(TypedDict, total=False):
|
|
|
44
47
|
agent: Any
|
|
45
48
|
current_response: str
|
|
46
49
|
|
|
50
|
+
|
|
47
51
|
class AfterToolCallEvent(TypedDict, total=False):
|
|
48
52
|
agent: Any
|
|
49
53
|
current_response: str
|
|
50
54
|
need_return: bool
|
|
51
55
|
tool_prompt: str
|
|
52
56
|
|
|
57
|
+
|
|
53
58
|
# 任务生命周期
|
|
54
59
|
class TaskStartedEvent(TypedDict, total=False):
|
|
55
60
|
agent: Any
|
|
@@ -57,11 +62,13 @@ class TaskStartedEvent(TypedDict, total=False):
|
|
|
57
62
|
description: str
|
|
58
63
|
user_input: str
|
|
59
64
|
|
|
65
|
+
|
|
60
66
|
class TaskCompletedEvent(TypedDict, total=False):
|
|
61
67
|
agent: Any
|
|
62
68
|
auto_completed: bool
|
|
63
69
|
need_summary: bool
|
|
64
70
|
|
|
71
|
+
|
|
65
72
|
# 总结阶段
|
|
66
73
|
class BeforeSummaryEvent(TypedDict, total=False):
|
|
67
74
|
agent: Any
|
|
@@ -69,10 +76,12 @@ class BeforeSummaryEvent(TypedDict, total=False):
|
|
|
69
76
|
auto_completed: bool
|
|
70
77
|
need_summary: bool
|
|
71
78
|
|
|
79
|
+
|
|
72
80
|
class AfterSummaryEvent(TypedDict, total=False):
|
|
73
81
|
agent: Any
|
|
74
82
|
summary: str
|
|
75
83
|
|
|
84
|
+
|
|
76
85
|
# 附加提示
|
|
77
86
|
class BeforeAddonPromptEvent(TypedDict, total=False):
|
|
78
87
|
agent: Any
|
|
@@ -80,35 +89,42 @@ class BeforeAddonPromptEvent(TypedDict, total=False):
|
|
|
80
89
|
current_message: str
|
|
81
90
|
has_session_addon: bool
|
|
82
91
|
|
|
92
|
+
|
|
83
93
|
class AfterAddonPromptEvent(TypedDict, total=False):
|
|
84
94
|
agent: Any
|
|
85
95
|
need_complete: bool
|
|
86
96
|
addon_text: str
|
|
87
97
|
final_message: str
|
|
88
98
|
|
|
99
|
+
|
|
89
100
|
# 历史清理
|
|
90
101
|
class BeforeHistoryClearEvent(TypedDict, total=False):
|
|
91
102
|
agent: Any
|
|
92
103
|
|
|
104
|
+
|
|
93
105
|
class AfterHistoryClearEvent(TypedDict, total=False):
|
|
94
106
|
agent: Any
|
|
95
107
|
|
|
108
|
+
|
|
96
109
|
# 模型调用
|
|
97
110
|
class BeforeModelCallEvent(TypedDict, total=False):
|
|
98
111
|
agent: Any
|
|
99
112
|
message: str
|
|
100
113
|
|
|
114
|
+
|
|
101
115
|
class AfterModelCallEvent(TypedDict, total=False):
|
|
102
116
|
agent: Any
|
|
103
117
|
message: str
|
|
104
118
|
response: str
|
|
105
119
|
|
|
120
|
+
|
|
106
121
|
# 中断
|
|
107
122
|
class InterruptTriggeredEvent(TypedDict, total=False):
|
|
108
123
|
agent: Any
|
|
109
124
|
current_response: str
|
|
110
125
|
user_input: str
|
|
111
126
|
|
|
127
|
+
|
|
112
128
|
# 工具筛选
|
|
113
129
|
class BeforeToolFilterEvent(TypedDict, total=False):
|
|
114
130
|
agent: Any
|
|
@@ -116,6 +132,7 @@ class BeforeToolFilterEvent(TypedDict, total=False):
|
|
|
116
132
|
total_tools: int
|
|
117
133
|
threshold: int
|
|
118
134
|
|
|
135
|
+
|
|
119
136
|
class ToolFilteredEvent(TypedDict, total=False):
|
|
120
137
|
agent: Any
|
|
121
138
|
task: str
|
|
@@ -123,6 +140,7 @@ class ToolFilteredEvent(TypedDict, total=False):
|
|
|
123
140
|
total_tools: int
|
|
124
141
|
threshold: int
|
|
125
142
|
|
|
143
|
+
|
|
126
144
|
__all__ = [
|
|
127
145
|
"BEFORE_TOOL_CALL",
|
|
128
146
|
"AFTER_TOOL_CALL",
|