jarvis-ai-assistant 0.3.30__py3-none-any.whl → 0.7.6__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 +458 -152
- jarvis/jarvis_agent/agent_manager.py +17 -13
- jarvis/jarvis_agent/builtin_input_handler.py +2 -6
- jarvis/jarvis_agent/config_editor.py +2 -7
- jarvis/jarvis_agent/event_bus.py +82 -12
- jarvis/jarvis_agent/file_context_handler.py +329 -0
- jarvis/jarvis_agent/file_methodology_manager.py +3 -4
- jarvis/jarvis_agent/jarvis.py +628 -55
- jarvis/jarvis_agent/language_extractors/__init__.py +57 -0
- jarvis/jarvis_agent/language_extractors/c_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/cpp_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/go_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/java_extractor.py +84 -0
- jarvis/jarvis_agent/language_extractors/javascript_extractor.py +79 -0
- jarvis/jarvis_agent/language_extractors/python_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/rust_extractor.py +21 -0
- jarvis/jarvis_agent/language_extractors/typescript_extractor.py +84 -0
- jarvis/jarvis_agent/language_support_info.py +486 -0
- jarvis/jarvis_agent/main.py +34 -10
- jarvis/jarvis_agent/memory_manager.py +7 -16
- jarvis/jarvis_agent/methodology_share_manager.py +10 -16
- jarvis/jarvis_agent/prompt_manager.py +1 -1
- jarvis/jarvis_agent/prompts.py +193 -171
- jarvis/jarvis_agent/protocols.py +8 -12
- jarvis/jarvis_agent/run_loop.py +105 -9
- jarvis/jarvis_agent/session_manager.py +2 -3
- jarvis/jarvis_agent/share_manager.py +20 -22
- jarvis/jarvis_agent/shell_input_handler.py +1 -2
- jarvis/jarvis_agent/stdio_redirect.py +295 -0
- jarvis/jarvis_agent/task_analyzer.py +31 -6
- jarvis/jarvis_agent/task_manager.py +11 -27
- jarvis/jarvis_agent/tool_executor.py +2 -3
- jarvis/jarvis_agent/tool_share_manager.py +12 -24
- jarvis/jarvis_agent/utils.py +5 -1
- jarvis/jarvis_agent/web_bridge.py +189 -0
- jarvis/jarvis_agent/web_output_sink.py +53 -0
- jarvis/jarvis_agent/web_server.py +786 -0
- jarvis/jarvis_c2rust/__init__.py +26 -0
- jarvis/jarvis_c2rust/cli.py +575 -0
- jarvis/jarvis_c2rust/collector.py +250 -0
- jarvis/jarvis_c2rust/constants.py +26 -0
- jarvis/jarvis_c2rust/library_replacer.py +1254 -0
- jarvis/jarvis_c2rust/llm_module_agent.py +1272 -0
- jarvis/jarvis_c2rust/loaders.py +207 -0
- jarvis/jarvis_c2rust/models.py +28 -0
- jarvis/jarvis_c2rust/optimizer.py +2157 -0
- jarvis/jarvis_c2rust/scanner.py +1681 -0
- jarvis/jarvis_c2rust/transpiler.py +2983 -0
- jarvis/jarvis_c2rust/utils.py +385 -0
- jarvis/jarvis_code_agent/build_validation_config.py +132 -0
- jarvis/jarvis_code_agent/code_agent.py +1371 -220
- jarvis/jarvis_code_agent/code_analyzer/__init__.py +65 -0
- jarvis/jarvis_code_agent/code_analyzer/base_language.py +74 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/__init__.py +44 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/base.py +106 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +74 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/detector.py +125 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +72 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +70 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +53 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +47 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +61 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +110 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +154 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +110 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +153 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator.py +43 -0
- jarvis/jarvis_code_agent/code_analyzer/context_manager.py +648 -0
- jarvis/jarvis_code_agent/code_analyzer/context_recommender.py +18 -0
- jarvis/jarvis_code_agent/code_analyzer/dependency_analyzer.py +132 -0
- jarvis/jarvis_code_agent/code_analyzer/file_ignore.py +330 -0
- jarvis/jarvis_code_agent/code_analyzer/impact_analyzer.py +781 -0
- jarvis/jarvis_code_agent/code_analyzer/language_registry.py +185 -0
- jarvis/jarvis_code_agent/code_analyzer/language_support.py +110 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +49 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +299 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +215 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/java_language.py +212 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/javascript_language.py +254 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/python_language.py +269 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +281 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/typescript_language.py +280 -0
- jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +605 -0
- jarvis/jarvis_code_agent/code_analyzer/structured_code.py +556 -0
- jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +252 -0
- jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +58 -0
- jarvis/jarvis_code_agent/lint.py +501 -8
- jarvis/jarvis_code_agent/utils.py +141 -0
- jarvis/jarvis_code_analysis/code_review.py +493 -584
- jarvis/jarvis_data/config_schema.json +128 -12
- jarvis/jarvis_git_squash/main.py +4 -5
- jarvis/jarvis_git_utils/git_commiter.py +82 -75
- jarvis/jarvis_mcp/sse_mcp_client.py +22 -29
- jarvis/jarvis_mcp/stdio_mcp_client.py +12 -13
- jarvis/jarvis_mcp/streamable_mcp_client.py +15 -14
- jarvis/jarvis_memory_organizer/memory_organizer.py +55 -74
- jarvis/jarvis_methodology/main.py +32 -48
- jarvis/jarvis_multi_agent/__init__.py +287 -55
- jarvis/jarvis_multi_agent/main.py +36 -4
- jarvis/jarvis_platform/base.py +524 -202
- jarvis/jarvis_platform/human.py +7 -8
- jarvis/jarvis_platform/kimi.py +30 -36
- jarvis/jarvis_platform/openai.py +88 -25
- jarvis/jarvis_platform/registry.py +26 -10
- jarvis/jarvis_platform/tongyi.py +24 -25
- jarvis/jarvis_platform/yuanbao.py +32 -43
- jarvis/jarvis_platform_manager/main.py +66 -77
- jarvis/jarvis_platform_manager/service.py +8 -13
- jarvis/jarvis_rag/cli.py +53 -55
- jarvis/jarvis_rag/embedding_manager.py +13 -18
- jarvis/jarvis_rag/llm_interface.py +8 -9
- jarvis/jarvis_rag/query_rewriter.py +10 -21
- jarvis/jarvis_rag/rag_pipeline.py +24 -27
- jarvis/jarvis_rag/reranker.py +4 -5
- jarvis/jarvis_rag/retriever.py +28 -30
- jarvis/jarvis_sec/__init__.py +305 -0
- jarvis/jarvis_sec/agents.py +143 -0
- jarvis/jarvis_sec/analysis.py +276 -0
- jarvis/jarvis_sec/checkers/__init__.py +32 -0
- jarvis/jarvis_sec/checkers/c_checker.py +2680 -0
- jarvis/jarvis_sec/checkers/rust_checker.py +1108 -0
- jarvis/jarvis_sec/cli.py +139 -0
- jarvis/jarvis_sec/clustering.py +1439 -0
- jarvis/jarvis_sec/file_manager.py +427 -0
- jarvis/jarvis_sec/parsers.py +73 -0
- jarvis/jarvis_sec/prompts.py +268 -0
- jarvis/jarvis_sec/report.py +336 -0
- jarvis/jarvis_sec/review.py +453 -0
- jarvis/jarvis_sec/status.py +264 -0
- jarvis/jarvis_sec/types.py +20 -0
- jarvis/jarvis_sec/utils.py +499 -0
- jarvis/jarvis_sec/verification.py +848 -0
- jarvis/jarvis_sec/workflow.py +226 -0
- jarvis/jarvis_smart_shell/main.py +38 -87
- jarvis/jarvis_stats/cli.py +2 -2
- jarvis/jarvis_stats/stats.py +8 -8
- jarvis/jarvis_stats/storage.py +15 -21
- jarvis/jarvis_stats/visualizer.py +1 -1
- jarvis/jarvis_tools/clear_memory.py +3 -20
- jarvis/jarvis_tools/cli/main.py +21 -23
- jarvis/jarvis_tools/edit_file.py +1019 -132
- jarvis/jarvis_tools/execute_script.py +83 -25
- jarvis/jarvis_tools/file_analyzer.py +6 -9
- jarvis/jarvis_tools/generate_new_tool.py +14 -21
- jarvis/jarvis_tools/lsp_client.py +1552 -0
- jarvis/jarvis_tools/methodology.py +2 -3
- jarvis/jarvis_tools/read_code.py +1736 -35
- jarvis/jarvis_tools/read_symbols.py +140 -0
- jarvis/jarvis_tools/read_webpage.py +12 -13
- jarvis/jarvis_tools/registry.py +427 -200
- jarvis/jarvis_tools/retrieve_memory.py +20 -19
- jarvis/jarvis_tools/rewrite_file.py +72 -158
- jarvis/jarvis_tools/save_memory.py +3 -15
- jarvis/jarvis_tools/search_web.py +18 -18
- jarvis/jarvis_tools/sub_agent.py +36 -43
- jarvis/jarvis_tools/sub_code_agent.py +25 -26
- jarvis/jarvis_tools/virtual_tty.py +55 -33
- jarvis/jarvis_utils/clipboard.py +7 -10
- jarvis/jarvis_utils/config.py +232 -45
- jarvis/jarvis_utils/embedding.py +8 -5
- jarvis/jarvis_utils/fzf.py +8 -8
- jarvis/jarvis_utils/git_utils.py +225 -36
- jarvis/jarvis_utils/globals.py +3 -3
- jarvis/jarvis_utils/http.py +1 -1
- jarvis/jarvis_utils/input.py +99 -48
- jarvis/jarvis_utils/jsonnet_compat.py +465 -0
- jarvis/jarvis_utils/methodology.py +52 -48
- jarvis/jarvis_utils/utils.py +819 -491
- jarvis_ai_assistant-0.7.6.dist-info/METADATA +600 -0
- jarvis_ai_assistant-0.7.6.dist-info/RECORD +218 -0
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/entry_points.txt +4 -0
- jarvis/jarvis_agent/config.py +0 -92
- jarvis/jarvis_agent/edit_file_handler.py +0 -296
- jarvis/jarvis_platform/ai8.py +0 -332
- jarvis/jarvis_tools/ask_user.py +0 -54
- jarvis_ai_assistant-0.3.30.dist-info/METADATA +0 -381
- jarvis_ai_assistant-0.3.30.dist-info/RECORD +0 -137
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/top_level.txt +0 -0
jarvis/jarvis_utils/config.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
import os
|
|
3
3
|
from functools import lru_cache
|
|
4
|
-
from typing import Any, Dict, List, Optional
|
|
4
|
+
from typing import Any, Dict, List, Optional, cast
|
|
5
5
|
|
|
6
|
-
import yaml
|
|
6
|
+
import yaml
|
|
7
7
|
|
|
8
8
|
from jarvis.jarvis_utils.builtin_replace_map import BUILTIN_REPLACE_MAP
|
|
9
9
|
|
|
@@ -37,7 +37,7 @@ def get_git_commit_prompt() -> str:
|
|
|
37
37
|
返回:
|
|
38
38
|
str: Git提交信息生成提示模板,如果未配置则返回空字符串
|
|
39
39
|
"""
|
|
40
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_GIT_COMMIT_PROMPT", "")
|
|
40
|
+
return cast(str, GLOBAL_CONFIG_DATA.get("JARVIS_GIT_COMMIT_PROMPT", ""))
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
# 输出窗口预留大小
|
|
@@ -63,30 +63,13 @@ def get_replace_map() -> dict:
|
|
|
63
63
|
if not os.path.exists(replace_map_path):
|
|
64
64
|
return BUILTIN_REPLACE_MAP.copy()
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
PrettyOutput.print(
|
|
69
|
-
"警告:使用replace_map.yaml进行配置的方式已被弃用,将在未来版本中移除。"
|
|
70
|
-
"请迁移到使用GLOBAL_CONFIG_DATA中的JARVIS_REPLACE_MAP配置。",
|
|
71
|
-
output_type=OutputType.WARNING,
|
|
72
|
-
)
|
|
66
|
+
print("⚠️ 警告:使用replace_map.yaml进行配置的方式已被弃用,将在未来版本中移除。请迁移到使用GLOBAL_CONFIG_DATA中的JARVIS_REPLACE_MAP配置。")
|
|
73
67
|
|
|
74
68
|
with open(replace_map_path, "r", encoding="utf-8", errors="ignore") as file:
|
|
75
69
|
file_map = yaml.safe_load(file) or {}
|
|
76
70
|
return {**BUILTIN_REPLACE_MAP, **file_map}
|
|
77
71
|
|
|
78
72
|
|
|
79
|
-
def get_max_token_count(model_group_override: Optional[str] = None) -> int:
|
|
80
|
-
"""
|
|
81
|
-
获取模型允许的最大token数量。
|
|
82
|
-
|
|
83
|
-
返回:
|
|
84
|
-
int: 模型能处理的最大token数量,为最大输入token数量的100倍。
|
|
85
|
-
"""
|
|
86
|
-
max_input_tokens = get_max_input_token_count(model_group_override)
|
|
87
|
-
return max_input_tokens * 100
|
|
88
|
-
|
|
89
|
-
|
|
90
73
|
def get_max_input_token_count(model_group_override: Optional[str] = None) -> int:
|
|
91
74
|
"""
|
|
92
75
|
获取模型允许的最大输入token数量。
|
|
@@ -112,7 +95,7 @@ def get_shell_name() -> str:
|
|
|
112
95
|
4. 如果都未配置,则默认返回bash
|
|
113
96
|
"""
|
|
114
97
|
shell_path = GLOBAL_CONFIG_DATA.get("SHELL", os.getenv("SHELL", "/bin/bash"))
|
|
115
|
-
return os.path.basename(shell_path).lower()
|
|
98
|
+
return cast(str, os.path.basename(shell_path).lower())
|
|
116
99
|
|
|
117
100
|
|
|
118
101
|
def _apply_llm_group_env_override(group_config: Dict[str, Any]) -> None:
|
|
@@ -150,10 +133,24 @@ def _get_resolved_model_config(
|
|
|
150
133
|
model_groups = GLOBAL_CONFIG_DATA.get("JARVIS_LLM_GROUPS", [])
|
|
151
134
|
|
|
152
135
|
if model_group_name and isinstance(model_groups, list):
|
|
136
|
+
found = False
|
|
153
137
|
for group_item in model_groups:
|
|
154
138
|
if isinstance(group_item, dict) and model_group_name in group_item:
|
|
155
139
|
group_config = group_item[model_group_name]
|
|
140
|
+
found = True
|
|
156
141
|
break
|
|
142
|
+
|
|
143
|
+
# 当显式指定了模型组但未找到时,报错并退出
|
|
144
|
+
if model_group_override and not found:
|
|
145
|
+
print(f"❌ 错误:指定的模型组 '{model_group_name}' 不存在于配置中。")
|
|
146
|
+
print("ℹ️ 可用的模型组: " +
|
|
147
|
+
", ".join(
|
|
148
|
+
list(group.keys())[0]
|
|
149
|
+
for group in model_groups
|
|
150
|
+
if isinstance(group, dict)
|
|
151
|
+
) if model_groups else "无可用模型组")
|
|
152
|
+
import sys
|
|
153
|
+
sys.exit(1)
|
|
157
154
|
|
|
158
155
|
_apply_llm_group_env_override(group_config)
|
|
159
156
|
|
|
@@ -168,6 +165,10 @@ def _get_resolved_model_config(
|
|
|
168
165
|
"JARVIS_PLATFORM",
|
|
169
166
|
"JARVIS_MODEL",
|
|
170
167
|
"JARVIS_MAX_INPUT_TOKEN_COUNT",
|
|
168
|
+
"JARVIS_CHEAP_PLATFORM",
|
|
169
|
+
"JARVIS_CHEAP_MODEL",
|
|
170
|
+
"JARVIS_SMART_PLATFORM",
|
|
171
|
+
"JARVIS_SMART_MODEL",
|
|
171
172
|
]
|
|
172
173
|
for key in override_keys:
|
|
173
174
|
if key in GLOBAL_CONFIG_DATA:
|
|
@@ -187,10 +188,10 @@ def get_normal_platform_name(model_group_override: Optional[str] = None) -> str:
|
|
|
187
188
|
获取正常操作的平台名称。
|
|
188
189
|
|
|
189
190
|
返回:
|
|
190
|
-
str: 平台名称,默认为'
|
|
191
|
+
str: 平台名称,默认为'openai'
|
|
191
192
|
"""
|
|
192
193
|
config = _get_resolved_model_config(model_group_override)
|
|
193
|
-
return config.get("JARVIS_PLATFORM", "
|
|
194
|
+
return cast(str, config.get("JARVIS_PLATFORM", "openai"))
|
|
194
195
|
|
|
195
196
|
|
|
196
197
|
def get_normal_model_name(model_group_override: Optional[str] = None) -> str:
|
|
@@ -198,10 +199,10 @@ def get_normal_model_name(model_group_override: Optional[str] = None) -> str:
|
|
|
198
199
|
获取正常操作的模型名称。
|
|
199
200
|
|
|
200
201
|
返回:
|
|
201
|
-
str: 模型名称,默认为'
|
|
202
|
+
str: 模型名称,默认为'gpt-5'
|
|
202
203
|
"""
|
|
203
204
|
config = _get_resolved_model_config(model_group_override)
|
|
204
|
-
return config.get("JARVIS_MODEL", "
|
|
205
|
+
return cast(str, config.get("JARVIS_MODEL", "gpt-5"))
|
|
205
206
|
|
|
206
207
|
|
|
207
208
|
def _deprecated_platform_name_v1(model_group_override: Optional[str] = None) -> str:
|
|
@@ -228,6 +229,62 @@ def _deprecated_model_name_v1(model_group_override: Optional[str] = None) -> str
|
|
|
228
229
|
return get_normal_model_name(model_group_override)
|
|
229
230
|
|
|
230
231
|
|
|
232
|
+
def get_cheap_platform_name(model_group_override: Optional[str] = None) -> str:
|
|
233
|
+
"""
|
|
234
|
+
获取廉价操作的平台名称。
|
|
235
|
+
|
|
236
|
+
返回:
|
|
237
|
+
str: 平台名称,如果未配置则回退到正常操作平台
|
|
238
|
+
"""
|
|
239
|
+
config = _get_resolved_model_config(model_group_override)
|
|
240
|
+
cheap_platform = config.get("JARVIS_CHEAP_PLATFORM")
|
|
241
|
+
if cheap_platform:
|
|
242
|
+
return cast(str, cheap_platform)
|
|
243
|
+
return get_normal_platform_name(model_group_override)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def get_cheap_model_name(model_group_override: Optional[str] = None) -> str:
|
|
247
|
+
"""
|
|
248
|
+
获取廉价操作的模型名称。
|
|
249
|
+
|
|
250
|
+
返回:
|
|
251
|
+
str: 模型名称,如果未配置则回退到正常操作模型
|
|
252
|
+
"""
|
|
253
|
+
config = _get_resolved_model_config(model_group_override)
|
|
254
|
+
cheap_model = config.get("JARVIS_CHEAP_MODEL")
|
|
255
|
+
if cheap_model:
|
|
256
|
+
return cast(str, cheap_model)
|
|
257
|
+
return get_normal_model_name(model_group_override)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def get_smart_platform_name(model_group_override: Optional[str] = None) -> str:
|
|
261
|
+
"""
|
|
262
|
+
获取智能操作的平台名称。
|
|
263
|
+
|
|
264
|
+
返回:
|
|
265
|
+
str: 平台名称,如果未配置则回退到正常操作平台
|
|
266
|
+
"""
|
|
267
|
+
config = _get_resolved_model_config(model_group_override)
|
|
268
|
+
smart_platform = config.get("JARVIS_SMART_PLATFORM")
|
|
269
|
+
if smart_platform:
|
|
270
|
+
return cast(str, smart_platform)
|
|
271
|
+
return get_normal_platform_name(model_group_override)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def get_smart_model_name(model_group_override: Optional[str] = None) -> str:
|
|
275
|
+
"""
|
|
276
|
+
获取智能操作的模型名称。
|
|
277
|
+
|
|
278
|
+
返回:
|
|
279
|
+
str: 模型名称,如果未配置则回退到正常操作模型
|
|
280
|
+
"""
|
|
281
|
+
config = _get_resolved_model_config(model_group_override)
|
|
282
|
+
smart_model = config.get("JARVIS_SMART_MODEL")
|
|
283
|
+
if smart_model:
|
|
284
|
+
return cast(str, smart_model)
|
|
285
|
+
return get_normal_model_name(model_group_override)
|
|
286
|
+
|
|
287
|
+
|
|
231
288
|
def is_execute_tool_confirm() -> bool:
|
|
232
289
|
"""
|
|
233
290
|
检查工具执行是否需要确认。
|
|
@@ -235,7 +292,7 @@ def is_execute_tool_confirm() -> bool:
|
|
|
235
292
|
返回:
|
|
236
293
|
bool: 如果需要确认则返回True,默认为False
|
|
237
294
|
"""
|
|
238
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_EXECUTE_TOOL_CONFIRM", False)
|
|
295
|
+
return cast(bool, GLOBAL_CONFIG_DATA.get("JARVIS_EXECUTE_TOOL_CONFIRM", False))
|
|
239
296
|
|
|
240
297
|
|
|
241
298
|
def is_confirm_before_apply_patch() -> bool:
|
|
@@ -245,19 +302,19 @@ def is_confirm_before_apply_patch() -> bool:
|
|
|
245
302
|
返回:
|
|
246
303
|
bool: 如果需要确认则返回True,默认为False
|
|
247
304
|
"""
|
|
248
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_CONFIRM_BEFORE_APPLY_PATCH", False)
|
|
305
|
+
return cast(bool, GLOBAL_CONFIG_DATA.get("JARVIS_CONFIRM_BEFORE_APPLY_PATCH", False))
|
|
249
306
|
|
|
250
307
|
|
|
251
308
|
def get_data_dir() -> str:
|
|
252
309
|
"""
|
|
253
310
|
获取Jarvis数据存储目录路径。
|
|
254
311
|
|
|
255
|
-
返回:
|
|
312
|
+
返回:
|
|
256
313
|
str: 数据目录路径,优先从JARVIS_DATA_PATH环境变量获取,
|
|
257
314
|
如果未设置或为空,则使用~/.jarvis作为默认值
|
|
258
315
|
"""
|
|
259
316
|
return os.path.expanduser(
|
|
260
|
-
GLOBAL_CONFIG_DATA.get("JARVIS_DATA_PATH", "~/.jarvis").strip()
|
|
317
|
+
cast(str, GLOBAL_CONFIG_DATA.get("JARVIS_DATA_PATH", "~/.jarvis")).strip()
|
|
261
318
|
)
|
|
262
319
|
|
|
263
320
|
|
|
@@ -285,7 +342,7 @@ def get_pretty_output() -> bool:
|
|
|
285
342
|
if platform.system() == "Windows":
|
|
286
343
|
return False
|
|
287
344
|
|
|
288
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_PRETTY_OUTPUT", True)
|
|
345
|
+
return cast(bool, GLOBAL_CONFIG_DATA.get("JARVIS_PRETTY_OUTPUT", True))
|
|
289
346
|
|
|
290
347
|
|
|
291
348
|
def is_use_methodology() -> bool:
|
|
@@ -295,7 +352,7 @@ def is_use_methodology() -> bool:
|
|
|
295
352
|
返回:
|
|
296
353
|
bool: 如果启用方法论则返回True,默认为True
|
|
297
354
|
"""
|
|
298
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_USE_METHODOLOGY", True)
|
|
355
|
+
return cast(bool, GLOBAL_CONFIG_DATA.get("JARVIS_USE_METHODOLOGY", True))
|
|
299
356
|
|
|
300
357
|
|
|
301
358
|
def is_use_analysis() -> bool:
|
|
@@ -305,7 +362,7 @@ def is_use_analysis() -> bool:
|
|
|
305
362
|
返回:
|
|
306
363
|
bool: 如果启用任务分析则返回True,默认为True
|
|
307
364
|
"""
|
|
308
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_USE_ANALYSIS", True)
|
|
365
|
+
return cast(bool, GLOBAL_CONFIG_DATA.get("JARVIS_USE_ANALYSIS", True))
|
|
309
366
|
|
|
310
367
|
|
|
311
368
|
def get_tool_load_dirs() -> List[str]:
|
|
@@ -399,7 +456,7 @@ def get_central_methodology_repo() -> str:
|
|
|
399
456
|
返回:
|
|
400
457
|
str: 中心方法论Git仓库地址,如果未配置则返回空字符串
|
|
401
458
|
"""
|
|
402
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_CENTRAL_METHODOLOGY_REPO", "")
|
|
459
|
+
return cast(str, GLOBAL_CONFIG_DATA.get("JARVIS_CENTRAL_METHODOLOGY_REPO", ""))
|
|
403
460
|
|
|
404
461
|
|
|
405
462
|
def get_central_tool_repo() -> str:
|
|
@@ -409,7 +466,7 @@ def get_central_tool_repo() -> str:
|
|
|
409
466
|
返回:
|
|
410
467
|
str: 中心工具Git仓库地址,如果未配置则返回空字符串
|
|
411
468
|
"""
|
|
412
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_CENTRAL_TOOL_REPO", "")
|
|
469
|
+
return cast(str, GLOBAL_CONFIG_DATA.get("JARVIS_CENTRAL_TOOL_REPO", ""))
|
|
413
470
|
|
|
414
471
|
|
|
415
472
|
def is_print_prompt() -> bool:
|
|
@@ -419,7 +476,7 @@ def is_print_prompt() -> bool:
|
|
|
419
476
|
返回:
|
|
420
477
|
bool: 如果打印提示则返回True,默认为True
|
|
421
478
|
"""
|
|
422
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_PRINT_PROMPT", False)
|
|
479
|
+
return cast(bool, GLOBAL_CONFIG_DATA.get("JARVIS_PRINT_PROMPT", False))
|
|
423
480
|
|
|
424
481
|
|
|
425
482
|
def is_print_error_traceback() -> bool:
|
|
@@ -452,6 +509,36 @@ def is_enable_static_analysis() -> bool:
|
|
|
452
509
|
return GLOBAL_CONFIG_DATA.get("JARVIS_ENABLE_STATIC_ANALYSIS", True) is True
|
|
453
510
|
|
|
454
511
|
|
|
512
|
+
def is_enable_build_validation() -> bool:
|
|
513
|
+
"""
|
|
514
|
+
获取是否启用构建验证。
|
|
515
|
+
|
|
516
|
+
返回:
|
|
517
|
+
bool: 如果启用构建验证则返回True,默认为True
|
|
518
|
+
"""
|
|
519
|
+
return GLOBAL_CONFIG_DATA.get("JARVIS_ENABLE_BUILD_VALIDATION", True) is True
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
def is_enable_impact_analysis() -> bool:
|
|
523
|
+
"""
|
|
524
|
+
获取是否启用编辑影响范围分析。
|
|
525
|
+
|
|
526
|
+
返回:
|
|
527
|
+
bool: 如果启用影响范围分析则返回True,默认为True
|
|
528
|
+
"""
|
|
529
|
+
return GLOBAL_CONFIG_DATA.get("JARVIS_ENABLE_IMPACT_ANALYSIS", True) is True
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
def get_build_validation_timeout() -> int:
|
|
533
|
+
"""
|
|
534
|
+
获取构建验证的超时时间(秒)。
|
|
535
|
+
|
|
536
|
+
返回:
|
|
537
|
+
int: 超时时间,默认为30秒
|
|
538
|
+
"""
|
|
539
|
+
return int(GLOBAL_CONFIG_DATA.get("JARVIS_BUILD_VALIDATION_TIMEOUT", 30))
|
|
540
|
+
|
|
541
|
+
|
|
455
542
|
def get_git_check_mode() -> str:
|
|
456
543
|
"""
|
|
457
544
|
获取Git校验模式。
|
|
@@ -473,7 +560,7 @@ def get_mcp_config() -> List[Dict[str, Any]]:
|
|
|
473
560
|
返回:
|
|
474
561
|
List[Dict[str, Any]]: MCP配置项列表,如果未配置则返回空列表
|
|
475
562
|
"""
|
|
476
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_MCP", [])
|
|
563
|
+
return cast(List[Dict[str, Any]], GLOBAL_CONFIG_DATA.get("JARVIS_MCP", []))
|
|
477
564
|
|
|
478
565
|
|
|
479
566
|
# ==============================================================================
|
|
@@ -550,7 +637,7 @@ def get_rag_embedding_model() -> str:
|
|
|
550
637
|
str: 嵌入模型的名称
|
|
551
638
|
"""
|
|
552
639
|
config = _get_resolved_rag_config()
|
|
553
|
-
return config.get("embedding_model", "BAAI/bge-m3")
|
|
640
|
+
return cast(str, config.get("embedding_model", "BAAI/bge-m3"))
|
|
554
641
|
|
|
555
642
|
|
|
556
643
|
def get_rag_rerank_model() -> str:
|
|
@@ -561,7 +648,7 @@ def get_rag_rerank_model() -> str:
|
|
|
561
648
|
str: rerank模型的名称
|
|
562
649
|
"""
|
|
563
650
|
config = _get_resolved_rag_config()
|
|
564
|
-
return config.get("rerank_model", "BAAI/bge-reranker-v2-m3")
|
|
651
|
+
return cast(str, config.get("rerank_model", "BAAI/bge-reranker-v2-m3"))
|
|
565
652
|
|
|
566
653
|
|
|
567
654
|
def get_rag_embedding_cache_path() -> str:
|
|
@@ -671,7 +758,7 @@ def get_tool_use_list() -> List[str]:
|
|
|
671
758
|
List[str]: 要使用的工具名称列表,空列表表示使用所有工具
|
|
672
759
|
"""
|
|
673
760
|
config = _get_resolved_tool_config()
|
|
674
|
-
return config.get("use", [])
|
|
761
|
+
return cast(List[str], config.get("use", []))
|
|
675
762
|
|
|
676
763
|
|
|
677
764
|
def get_tool_dont_use_list() -> List[str]:
|
|
@@ -682,7 +769,7 @@ def get_tool_dont_use_list() -> List[str]:
|
|
|
682
769
|
List[str]: 不使用的工具名称列表
|
|
683
770
|
"""
|
|
684
771
|
config = _get_resolved_tool_config()
|
|
685
|
-
return config.get("dont_use", [])
|
|
772
|
+
return cast(List[str], config.get("dont_use", []))
|
|
686
773
|
|
|
687
774
|
|
|
688
775
|
def get_tool_filter_threshold() -> int:
|
|
@@ -695,27 +782,127 @@ def get_tool_filter_threshold() -> int:
|
|
|
695
782
|
return int(GLOBAL_CONFIG_DATA.get("JARVIS_TOOL_FILTER_THRESHOLD", 30))
|
|
696
783
|
|
|
697
784
|
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
def get_script_execution_timeout() -> int:
|
|
790
|
+
"""
|
|
791
|
+
获取脚本执行的超时时间(秒)。
|
|
792
|
+
|
|
793
|
+
返回:
|
|
794
|
+
int: 超时时间,默认为300秒(5分钟)
|
|
795
|
+
"""
|
|
796
|
+
return int(GLOBAL_CONFIG_DATA.get("JARVIS_SCRIPT_EXECUTION_TIMEOUT", 300))
|
|
797
|
+
|
|
798
|
+
|
|
698
799
|
def is_enable_git_repo_jca_switch() -> bool:
|
|
699
800
|
"""
|
|
700
801
|
是否启用:在初始化环境前检测Git仓库并提示可切换到代码开发模式(jca)
|
|
701
|
-
|
|
802
|
+
默认开启
|
|
702
803
|
"""
|
|
703
|
-
return GLOBAL_CONFIG_DATA.get("JARVIS_ENABLE_GIT_JCA_SWITCH",
|
|
804
|
+
return GLOBAL_CONFIG_DATA.get("JARVIS_ENABLE_GIT_JCA_SWITCH", True) is True
|
|
704
805
|
|
|
705
806
|
|
|
706
807
|
def is_enable_builtin_config_selector() -> bool:
|
|
707
808
|
"""
|
|
708
809
|
是否启用:在进入默认通用代理前,列出可用配置(agent/multi_agent/roles)供选择
|
|
709
|
-
|
|
810
|
+
默认开启
|
|
710
811
|
"""
|
|
711
812
|
return (
|
|
712
|
-
GLOBAL_CONFIG_DATA.get("JARVIS_ENABLE_STARTUP_CONFIG_SELECTOR",
|
|
813
|
+
GLOBAL_CONFIG_DATA.get("JARVIS_ENABLE_STARTUP_CONFIG_SELECTOR", True) is True
|
|
713
814
|
)
|
|
714
815
|
|
|
715
816
|
|
|
817
|
+
def is_save_session_history() -> bool:
|
|
818
|
+
"""
|
|
819
|
+
是否保存会话记录。
|
|
820
|
+
|
|
821
|
+
返回:
|
|
822
|
+
bool: 如果要保存会话记录则返回True, 默认为False
|
|
823
|
+
"""
|
|
824
|
+
return GLOBAL_CONFIG_DATA.get("JARVIS_SAVE_SESSION_HISTORY", False) is True
|
|
825
|
+
|
|
826
|
+
|
|
716
827
|
def is_immediate_abort() -> bool:
|
|
717
828
|
"""
|
|
718
829
|
是否启用立即中断:当在对话过程中检测到用户中断信号时,立即停止输出并返回。
|
|
719
830
|
默认关闭
|
|
720
831
|
"""
|
|
721
832
|
return GLOBAL_CONFIG_DATA.get("JARVIS_IMMEDIATE_ABORT", False) is True
|
|
833
|
+
|
|
834
|
+
|
|
835
|
+
def is_non_interactive() -> bool:
|
|
836
|
+
"""
|
|
837
|
+
获取是否启用非交互模式。
|
|
838
|
+
|
|
839
|
+
返回:
|
|
840
|
+
bool: 如果启用非交互模式则返回True,默认为False
|
|
841
|
+
"""
|
|
842
|
+
# 优先读取环境变量,确保 CLI 标志生效且不被配置覆盖
|
|
843
|
+
try:
|
|
844
|
+
import os
|
|
845
|
+
v = os.getenv("JARVIS_NON_INTERACTIVE")
|
|
846
|
+
if v is not None:
|
|
847
|
+
val = str(v).strip().lower()
|
|
848
|
+
if val in ("1", "true", "yes", "on"):
|
|
849
|
+
return True
|
|
850
|
+
if val in ("0", "false", "no", "off"):
|
|
851
|
+
return False
|
|
852
|
+
except Exception:
|
|
853
|
+
# 忽略环境变量解析异常,回退到配置
|
|
854
|
+
pass
|
|
855
|
+
return GLOBAL_CONFIG_DATA.get("JARVIS_NON_INTERACTIVE", False) is True
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
def is_skip_predefined_tasks() -> bool:
|
|
859
|
+
"""
|
|
860
|
+
是否跳过预定义任务加载。
|
|
861
|
+
|
|
862
|
+
返回:
|
|
863
|
+
bool: 如果跳过预定义任务加载则返回True,默认为False
|
|
864
|
+
"""
|
|
865
|
+
return GLOBAL_CONFIG_DATA.get("JARVIS_SKIP_PREDEFINED_TASKS", False) is True
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
def get_addon_prompt_threshold() -> int:
|
|
869
|
+
"""
|
|
870
|
+
获取附加提示的触发阈值(字符数)。
|
|
871
|
+
|
|
872
|
+
当消息长度超过此阈值时,会自动添加默认的附加提示。
|
|
873
|
+
|
|
874
|
+
返回:
|
|
875
|
+
int: 触发阈值,默认为1024
|
|
876
|
+
"""
|
|
877
|
+
try:
|
|
878
|
+
return int(GLOBAL_CONFIG_DATA.get("JARVIS_ADDON_PROMPT_THRESHOLD", 1024))
|
|
879
|
+
except Exception:
|
|
880
|
+
return 1024
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
def is_enable_intent_recognition() -> bool:
|
|
884
|
+
"""
|
|
885
|
+
获取是否启用意图识别功能。
|
|
886
|
+
|
|
887
|
+
返回:
|
|
888
|
+
bool: 是否启用意图识别,默认为True(可通过 GLOBAL_CONFIG_DATA['JARVIS_ENABLE_INTENT_RECOGNITION'] 配置)
|
|
889
|
+
"""
|
|
890
|
+
return GLOBAL_CONFIG_DATA.get("JARVIS_ENABLE_INTENT_RECOGNITION", True) is True
|
|
891
|
+
|
|
892
|
+
|
|
893
|
+
def is_enable_memory_organizer() -> bool:
|
|
894
|
+
"""
|
|
895
|
+
获取是否启用自动记忆整理功能。
|
|
896
|
+
|
|
897
|
+
返回:
|
|
898
|
+
bool: 是否启用自动记忆整理,默认为False(可通过 GLOBAL_CONFIG_DATA['JARVIS_ENABLE_MEMORY_ORGANIZER'] 配置)
|
|
899
|
+
"""
|
|
900
|
+
return GLOBAL_CONFIG_DATA.get("JARVIS_ENABLE_MEMORY_ORGANIZER", False) is True
|
|
901
|
+
def get_conversation_turn_threshold() -> int:
|
|
902
|
+
"""
|
|
903
|
+
获取对话轮次阈值,用于触发总结。
|
|
904
|
+
|
|
905
|
+
返回:
|
|
906
|
+
int: 对话轮次阈值,默认为50
|
|
907
|
+
"""
|
|
908
|
+
return int(GLOBAL_CONFIG_DATA.get("JARVIS_CONVERSATION_TURN_THRESHOLD", 50))
|
jarvis/jarvis_utils/embedding.py
CHANGED
|
@@ -3,7 +3,6 @@ import os
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
from typing import List
|
|
5
5
|
|
|
6
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
7
6
|
|
|
8
7
|
# 设置tiktoken缓存目录
|
|
9
8
|
script_dir = Path(__file__).parent
|
|
@@ -21,14 +20,18 @@ def get_context_token_count(text: str) -> int:
|
|
|
21
20
|
返回:
|
|
22
21
|
int: 文本中的token数量
|
|
23
22
|
"""
|
|
23
|
+
# 防御性检查:入参为 None 或空字符串时直接返回 0
|
|
24
|
+
if text is None or text == "":
|
|
25
|
+
return 0
|
|
24
26
|
try:
|
|
25
27
|
import tiktoken
|
|
26
28
|
|
|
27
29
|
encoding = tiktoken.get_encoding("cl100k_base")
|
|
28
|
-
|
|
30
|
+
# 调整token计算为原来的10/7倍
|
|
31
|
+
return int(len(encoding.encode(text)) * 10 / 7)
|
|
29
32
|
except Exception as e:
|
|
30
|
-
|
|
31
|
-
return len(text) // 4 # 每个token大约4
|
|
33
|
+
print(f"⚠️ 计算token失败: {str(e)}")
|
|
34
|
+
return int(len(text) // 4 * 10 / 7) # 每个token大约4个字符的粗略估计,调整为10/7倍
|
|
32
35
|
|
|
33
36
|
|
|
34
37
|
def split_text_into_chunks(
|
|
@@ -77,6 +80,6 @@ def split_text_into_chunks(
|
|
|
77
80
|
return chunks
|
|
78
81
|
|
|
79
82
|
except Exception as e:
|
|
80
|
-
|
|
83
|
+
print(f"⚠️ 文本分割失败: {str(e)}")
|
|
81
84
|
# 发生错误时回退到简单的字符分割
|
|
82
85
|
return [text[i : i + max_length] for i in range(0, len(text), max_length)]
|
jarvis/jarvis_utils/fzf.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
|
-
"""FZF
|
|
2
|
+
"""FZF选择器工具。"""
|
|
3
3
|
import shutil
|
|
4
4
|
import subprocess
|
|
5
5
|
from typing import List, Optional, Union, Dict, Any, cast
|
|
@@ -10,15 +10,15 @@ def fzf_select(
|
|
|
10
10
|
key: Optional[str] = None,
|
|
11
11
|
) -> Optional[str]:
|
|
12
12
|
"""
|
|
13
|
-
|
|
13
|
+
使用fzf从列表中选择一个项目。
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
options:
|
|
17
|
-
prompt:
|
|
18
|
-
key:
|
|
15
|
+
参数:
|
|
16
|
+
options: 可供选择的字符串或字典列表。
|
|
17
|
+
prompt: 在fzf中显示的提示信息。
|
|
18
|
+
key: 如果options是字典列表,则此参数指定要显示的键名。
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
返回:
|
|
21
|
+
选中的项目,如果fzf不可用或选择被取消则返回None。
|
|
22
22
|
"""
|
|
23
23
|
if shutil.which("fzf") is None:
|
|
24
24
|
return None
|