jarvis-ai-assistant 0.3.12__py3-none-any.whl → 0.3.14__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 +47 -24
- jarvis/jarvis_agent/builtin_input_handler.py +1 -1
- jarvis/jarvis_agent/session_manager.py +0 -8
- jarvis/jarvis_code_agent/code_agent.py +25 -17
- {jarvis_ai_assistant-0.3.12.dist-info → jarvis_ai_assistant-0.3.14.dist-info}/METADATA +1 -1
- {jarvis_ai_assistant-0.3.12.dist-info → jarvis_ai_assistant-0.3.14.dist-info}/RECORD +11 -11
- {jarvis_ai_assistant-0.3.12.dist-info → jarvis_ai_assistant-0.3.14.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.3.12.dist-info → jarvis_ai_assistant-0.3.14.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.3.12.dist-info → jarvis_ai_assistant-0.3.14.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.3.12.dist-info → jarvis_ai_assistant-0.3.14.dist-info}/top_level.txt +0 -0
jarvis/__init__.py
CHANGED
jarvis/jarvis_agent/__init__.py
CHANGED
@@ -51,10 +51,12 @@ from jarvis.jarvis_utils.globals import (
|
|
51
51
|
)
|
52
52
|
from jarvis.jarvis_utils.input import get_multiline_input, user_confirm
|
53
53
|
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
54
|
-
from jarvis.jarvis_utils.tag import
|
54
|
+
from jarvis.jarvis_utils.tag import ot
|
55
55
|
|
56
56
|
|
57
|
-
def show_agent_startup_stats(
|
57
|
+
def show_agent_startup_stats(
|
58
|
+
agent_name: str, model_name: str, tool_registry_instance: Optional[Any] = None
|
59
|
+
) -> None:
|
58
60
|
"""输出启动时的统计信息
|
59
61
|
|
60
62
|
参数:
|
@@ -87,8 +89,11 @@ def show_agent_startup_stats(agent_name: str, model_name: str) -> None:
|
|
87
89
|
total_tool_count = len(tool_registry_all.tools)
|
88
90
|
|
89
91
|
# 获取可用工具的数量(应用过滤)
|
90
|
-
|
91
|
-
|
92
|
+
if tool_registry_instance is not None:
|
93
|
+
available_tool_count = len(tool_registry_instance.get_all_tools())
|
94
|
+
else:
|
95
|
+
tool_registry = ToolRegistry()
|
96
|
+
available_tool_count = len(tool_registry.get_all_tools())
|
92
97
|
|
93
98
|
global_memory_dir = Path(get_data_dir()) / "memory" / "global_long_term"
|
94
99
|
global_memory_count = 0
|
@@ -180,15 +185,20 @@ origin_agent_system_prompt = f"""
|
|
180
185
|
|
181
186
|
|
182
187
|
class Agent:
|
183
|
-
def
|
188
|
+
def clear_history(self):
|
184
189
|
"""
|
185
190
|
Clears the current conversation history by delegating to the session manager.
|
186
191
|
"""
|
187
|
-
self.session.
|
192
|
+
self.session.clear_history()
|
188
193
|
|
189
194
|
def __del__(self):
|
190
195
|
# 只有在记录启动时才停止记录
|
191
|
-
|
196
|
+
try:
|
197
|
+
name = getattr(self, "name", None)
|
198
|
+
if name:
|
199
|
+
delete_agent(name)
|
200
|
+
except Exception:
|
201
|
+
pass
|
192
202
|
|
193
203
|
def get_tool_usage_prompt(self) -> str:
|
194
204
|
"""获取工具使用提示"""
|
@@ -203,8 +213,8 @@ class Agent:
|
|
203
213
|
model_group: Optional[str] = None,
|
204
214
|
summary_prompt: Optional[str] = None,
|
205
215
|
auto_complete: bool = False,
|
206
|
-
output_handler: List[OutputHandlerProtocol] =
|
207
|
-
use_tools: List[str] =
|
216
|
+
output_handler: Optional[List[OutputHandlerProtocol]] = None,
|
217
|
+
use_tools: Optional[List[str]] = None,
|
208
218
|
input_handler: Optional[List[Callable[[str, Any], Tuple[str, bool]]]] = None,
|
209
219
|
execute_tool_confirm: Optional[bool] = None,
|
210
220
|
need_summary: bool = True,
|
@@ -212,7 +222,7 @@ class Agent:
|
|
212
222
|
use_methodology: Optional[bool] = None,
|
213
223
|
use_analysis: Optional[bool] = None,
|
214
224
|
force_save_memory: Optional[bool] = None,
|
215
|
-
files: List[str] =
|
225
|
+
files: Optional[List[str]] = None,
|
216
226
|
):
|
217
227
|
"""初始化Jarvis Agent实例
|
218
228
|
|
@@ -225,7 +235,6 @@ class Agent:
|
|
225
235
|
auto_complete: 是否自动完成任务
|
226
236
|
output_handler: 输出处理器列表
|
227
237
|
input_handler: 输入处理器列表
|
228
|
-
max_context_length: 最大上下文长度
|
229
238
|
execute_tool_confirm: 执行工具前是否需要确认
|
230
239
|
need_summary: 是否需要生成总结
|
231
240
|
multiline_inputer: 多行输入处理器
|
@@ -234,7 +243,7 @@ class Agent:
|
|
234
243
|
force_save_memory: 是否强制保存记忆
|
235
244
|
"""
|
236
245
|
# 基础属性初始化
|
237
|
-
self.files = files
|
246
|
+
self.files = files or []
|
238
247
|
self.name = make_agent_name(name)
|
239
248
|
self.description = description
|
240
249
|
self.system_prompt = system_prompt
|
@@ -250,7 +259,15 @@ class Agent:
|
|
250
259
|
self._init_session()
|
251
260
|
|
252
261
|
# 初始化处理器
|
253
|
-
|
262
|
+
safe_output_handlers: List[OutputHandlerProtocol] = []
|
263
|
+
if output_handler:
|
264
|
+
safe_output_handlers = output_handler
|
265
|
+
safe_use_tools: List[str] = []
|
266
|
+
if use_tools:
|
267
|
+
safe_use_tools = use_tools
|
268
|
+
self._init_handlers(
|
269
|
+
safe_output_handlers, input_handler, multiline_inputer, safe_use_tools
|
270
|
+
)
|
254
271
|
|
255
272
|
# 初始化配置
|
256
273
|
self._init_config(
|
@@ -271,7 +288,7 @@ class Agent:
|
|
271
288
|
self._setup_system_prompt()
|
272
289
|
|
273
290
|
# 输出统计信息(包含欢迎信息)
|
274
|
-
show_agent_startup_stats(name, self.model.name()) # type: ignore
|
291
|
+
show_agent_startup_stats(name, self.model.name(), self.get_tool_registry()) # type: ignore
|
275
292
|
|
276
293
|
def _init_model(self, llm_type: str, model_group: Optional[str]):
|
277
294
|
"""初始化模型平台"""
|
@@ -284,7 +301,9 @@ class Agent:
|
|
284
301
|
|
285
302
|
self.model = PlatformRegistry().create_platform(platform_name)
|
286
303
|
if self.model is None:
|
287
|
-
PrettyOutput.print(
|
304
|
+
PrettyOutput.print(
|
305
|
+
f"平台 {platform_name} 不存在,将使用普通模型", OutputType.WARNING
|
306
|
+
)
|
288
307
|
self.model = PlatformRegistry().get_normal_platform()
|
289
308
|
|
290
309
|
if model_name:
|
@@ -526,7 +545,7 @@ class Agent:
|
|
526
545
|
|
527
546
|
该方法将:
|
528
547
|
1. 提示用户保存重要记忆
|
529
|
-
2. 调用
|
548
|
+
2. 调用 generate_summary 生成摘要
|
530
549
|
3. 清除对话历史
|
531
550
|
4. 保留系统消息
|
532
551
|
5. 添加摘要作为新上下文
|
@@ -564,6 +583,8 @@ class Agent:
|
|
564
583
|
# 清理历史(但不清理prompt,因为prompt会在builtin_input_handler中设置)
|
565
584
|
if self.model:
|
566
585
|
self.model.reset()
|
586
|
+
# 重置后重新设置系统提示词,确保系统约束仍然生效
|
587
|
+
self._setup_system_prompt()
|
567
588
|
# 重置会话
|
568
589
|
self.session.clear_history()
|
569
590
|
|
@@ -715,12 +736,18 @@ class Agent:
|
|
715
736
|
if isinstance(interrupt_result, tuple):
|
716
737
|
run_input_handlers, should_continue = interrupt_result
|
717
738
|
if should_continue:
|
739
|
+
self.run_input_handlers_next_turn = True
|
718
740
|
continue
|
719
741
|
else:
|
720
742
|
return interrupt_result
|
721
743
|
|
722
744
|
# 处理工具调用
|
723
|
-
need_return,
|
745
|
+
need_return, prompt = self._call_tools(current_response)
|
746
|
+
if self.session.prompt and prompt:
|
747
|
+
self.session.prompt += "\n\n" + prompt
|
748
|
+
else:
|
749
|
+
self.session.prompt = prompt
|
750
|
+
|
724
751
|
if need_return:
|
725
752
|
return self.session.prompt
|
726
753
|
|
@@ -785,7 +812,9 @@ class Agent:
|
|
785
812
|
返回:
|
786
813
|
str: "continue" 或 "complete"
|
787
814
|
"""
|
788
|
-
user_input = self.multiline_inputer(
|
815
|
+
user_input = self.multiline_inputer(
|
816
|
+
f"{self.name}: 请输入,或输入空行来结束当前任务:"
|
817
|
+
)
|
789
818
|
|
790
819
|
if user_input:
|
791
820
|
self.session.prompt = user_input
|
@@ -871,9 +900,3 @@ class Agent:
|
|
871
900
|
organizer.organize_memories(memory_type, min_overlap=3)
|
872
901
|
else:
|
873
902
|
PrettyOutput.print(f"已取消 '{scope_name}' 记忆库整理。", OutputType.INFO)
|
874
|
-
|
875
|
-
def clear_history(self):
|
876
|
-
"""
|
877
|
-
Clears conversation history by delegating to the session manager.
|
878
|
-
"""
|
879
|
-
self.session.clear_history()
|
@@ -43,7 +43,7 @@ def builtin_input_handler(user_input: str, agent_: Any) -> Tuple[str, bool]:
|
|
43
43
|
prompt = memory_tags_prompt
|
44
44
|
return prompt, True
|
45
45
|
elif tag == "Clear":
|
46
|
-
agent.
|
46
|
+
agent.clear_history()
|
47
47
|
return "", True
|
48
48
|
elif tag == "ToolUsage":
|
49
49
|
agent.set_addon_prompt(agent.get_tool_usage_prompt())
|
@@ -34,14 +34,6 @@ class SessionManager:
|
|
34
34
|
"""Sets the addon prompt for the next model call."""
|
35
35
|
self.addon_prompt = addon_prompt
|
36
36
|
|
37
|
-
def clear(self):
|
38
|
-
"""
|
39
|
-
Clears the current conversation history, prompt, and length counter.
|
40
|
-
"""
|
41
|
-
self.model.reset()
|
42
|
-
self.conversation_length = 0
|
43
|
-
self.prompt = ""
|
44
|
-
|
45
37
|
def save_session(self) -> bool:
|
46
38
|
"""Saves the current session state to a file."""
|
47
39
|
session_dir = os.path.join(os.getcwd(), ".jarvis")
|
@@ -68,13 +68,15 @@ class CodeAgent:
|
|
68
68
|
"retrieve_memory",
|
69
69
|
"clear_memory",
|
70
70
|
]
|
71
|
-
|
71
|
+
|
72
72
|
if append_tools:
|
73
|
-
additional_tools = [
|
73
|
+
additional_tools = [
|
74
|
+
t for t in (tool.strip() for tool in append_tools.split(",")) if t
|
75
|
+
]
|
74
76
|
base_tools.extend(additional_tools)
|
75
77
|
# 去重
|
76
78
|
base_tools = list(dict.fromkeys(base_tools))
|
77
|
-
|
79
|
+
|
78
80
|
tool_registry.use_tools(base_tools)
|
79
81
|
code_system_prompt = self._get_system_prompt()
|
80
82
|
self.agent = Agent(
|
@@ -412,18 +414,23 @@ class CodeAgent:
|
|
412
414
|
return
|
413
415
|
|
414
416
|
# 获取当前分支的提交总数
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
417
|
+
# 兼容空仓库或无 HEAD 的场景:失败时将提交计数视为 0,继续执行提交流程
|
418
|
+
commit_count = 0
|
419
|
+
try:
|
420
|
+
commit_result = subprocess.run(
|
421
|
+
["git", "rev-list", "--count", "HEAD"],
|
422
|
+
capture_output=True,
|
423
|
+
text=True,
|
424
|
+
encoding="utf-8",
|
425
|
+
errors="replace",
|
426
|
+
check=False,
|
427
|
+
)
|
428
|
+
if commit_result.returncode == 0:
|
429
|
+
out = commit_result.stdout.strip()
|
430
|
+
if out.isdigit():
|
431
|
+
commit_count = int(out)
|
432
|
+
except Exception:
|
433
|
+
commit_count = 0
|
427
434
|
|
428
435
|
# 暂存所有修改
|
429
436
|
subprocess.run(["git", "add", "."], check=True)
|
@@ -634,11 +641,12 @@ class CodeAgent:
|
|
634
641
|
):
|
635
642
|
agent.session.prompt += final_ret
|
636
643
|
return
|
637
|
-
|
644
|
+
# 用户未确认,允许输入自定义回复作为附加提示
|
638
645
|
custom_reply = get_multiline_input("请输入自定义回复")
|
639
|
-
if custom_reply.strip(): #
|
646
|
+
if custom_reply.strip(): # 如果自定义回复为空,不设置附加提示
|
640
647
|
agent.set_addon_prompt(custom_reply)
|
641
648
|
agent.session.prompt += final_ret
|
649
|
+
return
|
642
650
|
|
643
651
|
|
644
652
|
@app.command()
|
@@ -1,7 +1,7 @@
|
|
1
|
-
jarvis/__init__.py,sha256=
|
2
|
-
jarvis/jarvis_agent/__init__.py,sha256=
|
1
|
+
jarvis/__init__.py,sha256=VWGr6Ejq9BZqFLJznrElHDghpbCaBnkgpyMgrmU4ysk,74
|
2
|
+
jarvis/jarvis_agent/__init__.py,sha256=CkFa66l5lM0-_zlzApwBxTYbrnbC4_NqdD4QuK3H1VQ,32614
|
3
3
|
jarvis/jarvis_agent/agent_manager.py,sha256=YzpMiF0H2-eyk2kn2o24Bkj3bXsQx7Pv2vfD4gWepo0,2893
|
4
|
-
jarvis/jarvis_agent/builtin_input_handler.py,sha256=
|
4
|
+
jarvis/jarvis_agent/builtin_input_handler.py,sha256=wS-FqpT3pIXwHn1dfL3SpXonUKWgVThbQueUIeyRc2U,2917
|
5
5
|
jarvis/jarvis_agent/config_editor.py,sha256=Ctk82sO6w2cNW0-_5L7Bomj-hgM4U7WwMc52fwhAJyg,1809
|
6
6
|
jarvis/jarvis_agent/edit_file_handler.py,sha256=w-byNJ4TN_SlV3djjfFC7OksySOFGrM8ku49w662dzc,11854
|
7
7
|
jarvis/jarvis_agent/file_methodology_manager.py,sha256=PwDUQwq7HVIyPInsN8fgWyMXLwi8heIXPrqfBZJhVHs,4260
|
@@ -13,7 +13,7 @@ jarvis/jarvis_agent/output_handler.py,sha256=P7oWpXBGFfOsWq7cIhS_z9crkQ19ES7qU5p
|
|
13
13
|
jarvis/jarvis_agent/prompt_builder.py,sha256=PH1fPDVa8z_RXkoXHJFNDf8PQjUoLNLYwkh2lC__p40,1705
|
14
14
|
jarvis/jarvis_agent/prompts.py,sha256=X6cXa-n0xqBQ8LDTgLsD0kqziAh1s0cNp89i4mxcvHg,9444
|
15
15
|
jarvis/jarvis_agent/protocols.py,sha256=JWnJDikFEuwvFUv7uzXu0ggJ4O9K2FkMnfVCwIJ5REw,873
|
16
|
-
jarvis/jarvis_agent/session_manager.py,sha256=
|
16
|
+
jarvis/jarvis_agent/session_manager.py,sha256=xPeQcQRBmAlc-CGAzVz4MTOKhZKb27rTS-5De3Oauwg,2713
|
17
17
|
jarvis/jarvis_agent/share_manager.py,sha256=wFcdULSog1mMxDyB94ofbqitFL8DCX8i1u6qVzSEuAk,8704
|
18
18
|
jarvis/jarvis_agent/shell_input_handler.py,sha256=1IboqdxcJuoIqRpmDU10GugR9fWXUHyCEbVF4nIWbyo,1328
|
19
19
|
jarvis/jarvis_agent/task_analyzer.py,sha256=-fQ9YBYFcc-Z1FSoDIPzRfAgkREFoIOXtU2TdBkB-e0,4656
|
@@ -21,7 +21,7 @@ jarvis/jarvis_agent/task_manager.py,sha256=HJm4_SMpsFbQMUUsAZeHm7cZuhNbz28YW-DRL
|
|
21
21
|
jarvis/jarvis_agent/tool_executor.py,sha256=k73cKhZEZpljvui4ZxALlFEIE-iLzJ32Softsmiwzqk,1896
|
22
22
|
jarvis/jarvis_agent/tool_share_manager.py,sha256=R5ONIQlDXX9pFq3clwHFhEW8BAJ3ECaR2DqWCEC9tzM,5205
|
23
23
|
jarvis/jarvis_code_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
24
|
-
jarvis/jarvis_code_agent/code_agent.py,sha256=
|
24
|
+
jarvis/jarvis_code_agent/code_agent.py,sha256=GPmCMlAERHC3yPy0LEv3ATdPsZm99MUz1XxcNB9_p2o,29972
|
25
25
|
jarvis/jarvis_code_agent/lint.py,sha256=LZPsfyZPMo7Wm7LN4osZocuNJwZx1ojacO3MlF870x8,4009
|
26
26
|
jarvis/jarvis_code_analysis/code_review.py,sha256=OLoMtXz7Kov6cVTdBoxq_OsX_j0rb7Rk3or5tKgiLpo,36023
|
27
27
|
jarvis/jarvis_code_analysis/checklists/__init__.py,sha256=LIXAYa1sW3l7foP6kohLWnE98I_EQ0T7z5bYKHq6rJA,78
|
@@ -119,9 +119,9 @@ jarvis/jarvis_utils/methodology.py,sha256=IIMU17WVSunsWXsnXROd4G77LxgYs4xEC_xm_0
|
|
119
119
|
jarvis/jarvis_utils/output.py,sha256=QRLlKObQKT0KuRSeZRqYb7NlTQvsd1oZXZ41WxeWEuU,10894
|
120
120
|
jarvis/jarvis_utils/tag.py,sha256=f211opbbbTcSyzCDwuIK_oCnKhXPNK-RknYyGzY1yD0,431
|
121
121
|
jarvis/jarvis_utils/utils.py,sha256=LiVui9RMsbfUdzbvBBwbGNC4uniGnLp3LFsk7LXGrQE,47370
|
122
|
-
jarvis_ai_assistant-0.3.
|
123
|
-
jarvis_ai_assistant-0.3.
|
124
|
-
jarvis_ai_assistant-0.3.
|
125
|
-
jarvis_ai_assistant-0.3.
|
126
|
-
jarvis_ai_assistant-0.3.
|
127
|
-
jarvis_ai_assistant-0.3.
|
122
|
+
jarvis_ai_assistant-0.3.14.dist-info/licenses/LICENSE,sha256=AGgVgQmTqFvaztRtCAXsAMryUymB18gZif7_l2e1XOg,1063
|
123
|
+
jarvis_ai_assistant-0.3.14.dist-info/METADATA,sha256=jPFjzOOpjbCDOcVVwpNJCWax51_2VcfMRg3AnuGnbHo,18216
|
124
|
+
jarvis_ai_assistant-0.3.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
125
|
+
jarvis_ai_assistant-0.3.14.dist-info/entry_points.txt,sha256=4GcWKFxRJD-QU14gw_3ZaW4KuEVxOcZK9i270rwPdjA,1395
|
126
|
+
jarvis_ai_assistant-0.3.14.dist-info/top_level.txt,sha256=1BOxyWfzOP_ZXj8rVTDnNCJ92bBGB0rwq8N1PCpoMIs,7
|
127
|
+
jarvis_ai_assistant-0.3.14.dist-info/RECORD,,
|
File without changes
|
{jarvis_ai_assistant-0.3.12.dist-info → jarvis_ai_assistant-0.3.14.dist-info}/entry_points.txt
RENAMED
File without changes
|
{jarvis_ai_assistant-0.3.12.dist-info → jarvis_ai_assistant-0.3.14.dist-info}/licenses/LICENSE
RENAMED
File without changes
|
File without changes
|