jarvis-ai-assistant 0.3.30__py3-none-any.whl → 0.7.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.
Files changed (115) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +289 -87
  3. jarvis/jarvis_agent/agent_manager.py +17 -8
  4. jarvis/jarvis_agent/edit_file_handler.py +374 -86
  5. jarvis/jarvis_agent/event_bus.py +1 -1
  6. jarvis/jarvis_agent/file_context_handler.py +79 -0
  7. jarvis/jarvis_agent/jarvis.py +601 -43
  8. jarvis/jarvis_agent/main.py +32 -2
  9. jarvis/jarvis_agent/rewrite_file_handler.py +141 -0
  10. jarvis/jarvis_agent/run_loop.py +38 -5
  11. jarvis/jarvis_agent/share_manager.py +8 -1
  12. jarvis/jarvis_agent/stdio_redirect.py +295 -0
  13. jarvis/jarvis_agent/task_analyzer.py +5 -2
  14. jarvis/jarvis_agent/task_planner.py +496 -0
  15. jarvis/jarvis_agent/utils.py +5 -1
  16. jarvis/jarvis_agent/web_bridge.py +189 -0
  17. jarvis/jarvis_agent/web_output_sink.py +53 -0
  18. jarvis/jarvis_agent/web_server.py +751 -0
  19. jarvis/jarvis_c2rust/__init__.py +26 -0
  20. jarvis/jarvis_c2rust/cli.py +613 -0
  21. jarvis/jarvis_c2rust/collector.py +258 -0
  22. jarvis/jarvis_c2rust/library_replacer.py +1122 -0
  23. jarvis/jarvis_c2rust/llm_module_agent.py +1300 -0
  24. jarvis/jarvis_c2rust/optimizer.py +960 -0
  25. jarvis/jarvis_c2rust/scanner.py +1681 -0
  26. jarvis/jarvis_c2rust/transpiler.py +2325 -0
  27. jarvis/jarvis_code_agent/build_validation_config.py +133 -0
  28. jarvis/jarvis_code_agent/code_agent.py +1171 -94
  29. jarvis/jarvis_code_agent/code_analyzer/__init__.py +62 -0
  30. jarvis/jarvis_code_agent/code_analyzer/base_language.py +74 -0
  31. jarvis/jarvis_code_agent/code_analyzer/build_validator/__init__.py +44 -0
  32. jarvis/jarvis_code_agent/code_analyzer/build_validator/base.py +102 -0
  33. jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +59 -0
  34. jarvis/jarvis_code_agent/code_analyzer/build_validator/detector.py +125 -0
  35. jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +69 -0
  36. jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +38 -0
  37. jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +44 -0
  38. jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +38 -0
  39. jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +50 -0
  40. jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +93 -0
  41. jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +129 -0
  42. jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +54 -0
  43. jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +154 -0
  44. jarvis/jarvis_code_agent/code_analyzer/build_validator.py +43 -0
  45. jarvis/jarvis_code_agent/code_analyzer/context_manager.py +363 -0
  46. jarvis/jarvis_code_agent/code_analyzer/context_recommender.py +18 -0
  47. jarvis/jarvis_code_agent/code_analyzer/dependency_analyzer.py +132 -0
  48. jarvis/jarvis_code_agent/code_analyzer/file_ignore.py +330 -0
  49. jarvis/jarvis_code_agent/code_analyzer/impact_analyzer.py +781 -0
  50. jarvis/jarvis_code_agent/code_analyzer/language_registry.py +185 -0
  51. jarvis/jarvis_code_agent/code_analyzer/language_support.py +89 -0
  52. jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +31 -0
  53. jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +231 -0
  54. jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +183 -0
  55. jarvis/jarvis_code_agent/code_analyzer/languages/python_language.py +219 -0
  56. jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +209 -0
  57. jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +451 -0
  58. jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +77 -0
  59. jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +48 -0
  60. jarvis/jarvis_code_agent/lint.py +270 -8
  61. jarvis/jarvis_code_agent/utils.py +142 -0
  62. jarvis/jarvis_code_analysis/code_review.py +483 -569
  63. jarvis/jarvis_data/config_schema.json +97 -8
  64. jarvis/jarvis_git_utils/git_commiter.py +38 -26
  65. jarvis/jarvis_mcp/sse_mcp_client.py +2 -2
  66. jarvis/jarvis_mcp/stdio_mcp_client.py +1 -1
  67. jarvis/jarvis_memory_organizer/memory_organizer.py +1 -1
  68. jarvis/jarvis_multi_agent/__init__.py +239 -25
  69. jarvis/jarvis_multi_agent/main.py +37 -1
  70. jarvis/jarvis_platform/base.py +103 -51
  71. jarvis/jarvis_platform/openai.py +26 -1
  72. jarvis/jarvis_platform/yuanbao.py +1 -1
  73. jarvis/jarvis_platform_manager/service.py +2 -2
  74. jarvis/jarvis_rag/cli.py +4 -4
  75. jarvis/jarvis_sec/__init__.py +3605 -0
  76. jarvis/jarvis_sec/checkers/__init__.py +32 -0
  77. jarvis/jarvis_sec/checkers/c_checker.py +2680 -0
  78. jarvis/jarvis_sec/checkers/rust_checker.py +1108 -0
  79. jarvis/jarvis_sec/cli.py +116 -0
  80. jarvis/jarvis_sec/report.py +257 -0
  81. jarvis/jarvis_sec/status.py +264 -0
  82. jarvis/jarvis_sec/types.py +20 -0
  83. jarvis/jarvis_sec/workflow.py +219 -0
  84. jarvis/jarvis_stats/cli.py +1 -1
  85. jarvis/jarvis_stats/stats.py +1 -1
  86. jarvis/jarvis_stats/visualizer.py +1 -1
  87. jarvis/jarvis_tools/cli/main.py +1 -0
  88. jarvis/jarvis_tools/execute_script.py +46 -9
  89. jarvis/jarvis_tools/generate_new_tool.py +3 -1
  90. jarvis/jarvis_tools/read_code.py +275 -12
  91. jarvis/jarvis_tools/read_symbols.py +141 -0
  92. jarvis/jarvis_tools/read_webpage.py +5 -3
  93. jarvis/jarvis_tools/registry.py +73 -35
  94. jarvis/jarvis_tools/search_web.py +15 -11
  95. jarvis/jarvis_tools/sub_agent.py +24 -42
  96. jarvis/jarvis_tools/sub_code_agent.py +14 -13
  97. jarvis/jarvis_tools/virtual_tty.py +1 -1
  98. jarvis/jarvis_utils/config.py +187 -35
  99. jarvis/jarvis_utils/embedding.py +3 -0
  100. jarvis/jarvis_utils/git_utils.py +181 -6
  101. jarvis/jarvis_utils/globals.py +3 -3
  102. jarvis/jarvis_utils/http.py +1 -1
  103. jarvis/jarvis_utils/input.py +78 -2
  104. jarvis/jarvis_utils/methodology.py +25 -19
  105. jarvis/jarvis_utils/utils.py +644 -359
  106. {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/METADATA +85 -1
  107. jarvis_ai_assistant-0.7.0.dist-info/RECORD +192 -0
  108. {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/entry_points.txt +4 -0
  109. jarvis/jarvis_agent/config.py +0 -92
  110. jarvis/jarvis_tools/edit_file.py +0 -179
  111. jarvis/jarvis_tools/rewrite_file.py +0 -191
  112. jarvis_ai_assistant-0.3.30.dist-info/RECORD +0 -137
  113. {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/WHEEL +0 -0
  114. {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/licenses/LICENSE +0 -0
  115. {jarvis_ai_assistant-0.3.30.dist-info → jarvis_ai_assistant-0.7.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,189 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ WebBridge: WebSocket 交互桥
4
+ - 提供线程安全的广播能力(后续由 WebSocket 服务注册发送函数)
5
+ - 提供阻塞式的多行输入与确认请求(通过 request_* 发起请求,等待浏览器端响应)
6
+ - 适配 Agent 的输入注入接口:web_multiline_input / web_user_confirm
7
+ - 事件约定(发往前端,均为 JSON 对象):
8
+ * {"type":"input_request","mode":"multiline","tip": "...","print_on_empty": true/false,"request_id":"..."}
9
+ * {"type":"confirm_request","tip":"...","default": true/false,"request_id":"..."}
10
+ 后续输出事件由输出Sink负责(使用 PrettyOutput.add_sink 接入),不在本桥内实现。
11
+ - 事件约定(来自前端):
12
+ * {"type":"user_input","request_id":"...","text":"..."}
13
+ * {"type":"confirm_response","request_id":"...","value": true/false}
14
+ """
15
+ from __future__ import annotations
16
+
17
+ import threading
18
+ import uuid
19
+ from queue import Queue, Empty
20
+ from typing import Callable, Dict, Optional, Set, Any
21
+
22
+ DEFAULT_WAIT_TIMEOUT = None # 阻塞等待直到收到响应(可按需改为秒数)
23
+
24
+
25
+ class WebBridge:
26
+ """
27
+ 线程安全的 WebSocket 交互桥。
28
+ - 维护一组客户端发送函数(由Web服务注册),用于广播事件
29
+ - 维护挂起的输入/确认请求队列,按 request_id 匹配响应
30
+ """
31
+
32
+ _instance_lock = threading.Lock()
33
+ _instance: Optional["WebBridge"] = None
34
+
35
+ def __init__(self) -> None:
36
+ self._clients: Set[Callable[[Dict[str, Any]], None]] = set()
37
+ self._clients_lock = threading.Lock()
38
+
39
+ # 按 request_id 等待的阻塞队列
40
+ self._pending_inputs: Dict[str, Queue] = {}
41
+ self._pending_confirms: Dict[str, Queue] = {}
42
+ self._pending_lock = threading.Lock()
43
+
44
+ @classmethod
45
+ def instance(cls) -> "WebBridge":
46
+ with cls._instance_lock:
47
+ if cls._instance is None:
48
+ cls._instance = WebBridge()
49
+ return cls._instance
50
+
51
+ # ---------------------------
52
+ # 客户端管理与广播
53
+ # ---------------------------
54
+ def add_client(self, sender: Callable[[Dict[str, Any]], None]) -> None:
55
+ """
56
+ 注册一个客户端发送函数。发送函数需接受一个 dict,并自行完成异步发送。
57
+ 例如在 FastAPI/WS 中包装成 enqueue 到事件循环的任务。
58
+ """
59
+ with self._clients_lock:
60
+ self._clients.add(sender)
61
+
62
+ def remove_client(self, sender: Callable[[Dict[str, Any]], None]) -> None:
63
+ with self._clients_lock:
64
+ if sender in self._clients:
65
+ self._clients.remove(sender)
66
+
67
+ def broadcast(self, payload: Dict[str, Any]) -> None:
68
+ """
69
+ 广播一条消息给所有客户端。失败的客户端不影响其他客户端。
70
+ """
71
+ with self._clients_lock:
72
+ targets = list(self._clients)
73
+ for send in targets:
74
+ try:
75
+ send(payload)
76
+ except Exception:
77
+ # 静默忽略单个客户端的发送异常
78
+ pass
79
+
80
+ # ---------------------------
81
+ # 输入/确认 请求-响应 管理
82
+ # ---------------------------
83
+ def request_multiline_input(self, tip: str, print_on_empty: bool = True, timeout: Optional[float] = DEFAULT_WAIT_TIMEOUT) -> str:
84
+ """
85
+ 发起一个多行输入请求并阻塞等待浏览器返回。
86
+ 返回用户输入的文本(可能为空字符串,表示取消)。
87
+ """
88
+ req_id = uuid.uuid4().hex
89
+ q: Queue = Queue(maxsize=1)
90
+ with self._pending_lock:
91
+ self._pending_inputs[req_id] = q
92
+
93
+ self.broadcast({
94
+ "type": "input_request",
95
+ "mode": "multiline",
96
+ "tip": tip,
97
+ "print_on_empty": bool(print_on_empty),
98
+ "request_id": req_id,
99
+ })
100
+
101
+ try:
102
+ if timeout is None:
103
+ result = q.get() # 阻塞直到有结果
104
+ else:
105
+ result = q.get(timeout=timeout)
106
+ except Empty:
107
+ result = "" # 超时回退为空
108
+ finally:
109
+ with self._pending_lock:
110
+ self._pending_inputs.pop(req_id, None)
111
+
112
+ # 规范化为字符串
113
+ return str(result or "")
114
+
115
+ def request_confirm(self, tip: str, default: bool = True, timeout: Optional[float] = DEFAULT_WAIT_TIMEOUT) -> bool:
116
+ """
117
+ 发起一个确认请求并阻塞等待浏览器返回。
118
+ 返回 True/False,若超时则回退为 default。
119
+ """
120
+ req_id = uuid.uuid4().hex
121
+ q: Queue = Queue(maxsize=1)
122
+ with self._pending_lock:
123
+ self._pending_confirms[req_id] = q
124
+
125
+ self.broadcast({
126
+ "type": "confirm_request",
127
+ "tip": tip,
128
+ "default": bool(default),
129
+ "request_id": req_id,
130
+ })
131
+
132
+ try:
133
+ if timeout is None:
134
+ result = q.get()
135
+ else:
136
+ result = q.get(timeout=timeout)
137
+ except Empty:
138
+ result = default
139
+ finally:
140
+ with self._pending_lock:
141
+ self._pending_confirms.pop(req_id, None)
142
+
143
+ return bool(result)
144
+
145
+ # ---------------------------
146
+ # 由 Web 服务回调:注入用户响应
147
+ # ---------------------------
148
+ def post_user_input(self, request_id: str, text: str) -> None:
149
+ """
150
+ 注入浏览器端的多行输入响应。
151
+ """
152
+ with self._pending_lock:
153
+ q = self._pending_inputs.get(request_id)
154
+ if q:
155
+ try:
156
+ q.put_nowait(text)
157
+ except Exception:
158
+ pass
159
+
160
+ def post_confirm(self, request_id: str, value: bool) -> None:
161
+ """
162
+ 注入浏览器端的确认响应。
163
+ """
164
+ with self._pending_lock:
165
+ q = self._pending_confirms.get(request_id)
166
+ if q:
167
+ try:
168
+ q.put_nowait(bool(value))
169
+ except Exception:
170
+ pass
171
+
172
+
173
+ # ---------------------------
174
+ # 供 Agent 注入的输入函数
175
+ # ---------------------------
176
+ def web_multiline_input(tip: str, print_on_empty: bool = True) -> str:
177
+ """
178
+ 适配 Agent.multiline_inputer 签名的多行输入函数。
179
+ 在 Web 模式下被注入到 Agent,转由浏览器端输入。
180
+ """
181
+ return WebBridge.instance().request_multiline_input(tip, print_on_empty)
182
+
183
+
184
+ def web_user_confirm(tip: str, default: bool = True) -> bool:
185
+ """
186
+ 适配 Agent.confirm_callback 签名的确认函数。
187
+ 在 Web 模式下被注入到 Agent,转由浏览器端确认。
188
+ """
189
+ return WebBridge.instance().request_confirm(tip, default)
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ WebSocketOutputSink: 将 PrettyOutput 的输出事件通过 WebBridge 广播给前端(WebSocket 客户端)
4
+
5
+ 用法:
6
+ - 在 Web 模式启动时,注册该 Sink:
7
+ from jarvis.jarvis_utils.output import PrettyOutput
8
+ from jarvis.jarvis_agent.web_output_sink import WebSocketOutputSink
9
+ PrettyOutput.add_sink(WebSocketOutputSink())
10
+
11
+ - Web 端收到的消息结构:
12
+ {
13
+ "type": "output",
14
+ "payload": {
15
+ "text": "...",
16
+ "output_type": "INFO" | "ERROR" | ...,
17
+ "timestamp": true/false,
18
+ "lang": "markdown" | "python" | ... | null,
19
+ "traceback": false,
20
+ "section": null | "标题",
21
+ "context": { ... } | null
22
+ }
23
+ }
24
+ """
25
+ from __future__ import annotations
26
+
27
+ from typing import Any, Dict
28
+
29
+ from jarvis.jarvis_utils.output import OutputSink, OutputEvent
30
+ from jarvis.jarvis_agent.web_bridge import WebBridge
31
+
32
+
33
+ class WebSocketOutputSink(OutputSink):
34
+ """将输出事件广播到 WebSocket 前端的 OutputSink 实现。"""
35
+
36
+ def emit(self, event: OutputEvent) -> None:
37
+ try:
38
+ payload: Dict[str, Any] = {
39
+ "type": "output",
40
+ "payload": {
41
+ "text": event.text,
42
+ "output_type": event.output_type.value,
43
+ "timestamp": bool(event.timestamp),
44
+ "lang": event.lang,
45
+ "traceback": bool(event.traceback),
46
+ "section": event.section,
47
+ "context": event.context,
48
+ },
49
+ }
50
+ WebBridge.instance().broadcast(payload)
51
+ except Exception:
52
+ # 广播过程中的异常不应影响其他输出后端
53
+ pass