jarvis-ai-assistant 0.3.17__py3-none-any.whl → 0.3.19__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 (55) hide show
  1. jarvis/__init__.py +1 -1
  2. jarvis/jarvis_agent/__init__.py +23 -10
  3. jarvis/jarvis_agent/edit_file_handler.py +8 -13
  4. jarvis/jarvis_agent/jarvis.py +13 -3
  5. jarvis/jarvis_agent/memory_manager.py +4 -4
  6. jarvis/jarvis_agent/methodology_share_manager.py +2 -2
  7. jarvis/jarvis_agent/task_analyzer.py +4 -3
  8. jarvis/jarvis_agent/task_manager.py +6 -6
  9. jarvis/jarvis_agent/tool_executor.py +2 -2
  10. jarvis/jarvis_agent/tool_share_manager.py +2 -2
  11. jarvis/jarvis_code_agent/code_agent.py +21 -29
  12. jarvis/jarvis_code_analysis/code_review.py +2 -4
  13. jarvis/jarvis_data/config_schema.json +5 -0
  14. jarvis/jarvis_git_utils/git_commiter.py +17 -18
  15. jarvis/jarvis_methodology/main.py +12 -12
  16. jarvis/jarvis_platform/base.py +21 -13
  17. jarvis/jarvis_platform/kimi.py +13 -13
  18. jarvis/jarvis_platform/tongyi.py +17 -15
  19. jarvis/jarvis_platform/yuanbao.py +11 -11
  20. jarvis/jarvis_platform_manager/main.py +12 -22
  21. jarvis/jarvis_rag/cli.py +36 -32
  22. jarvis/jarvis_rag/embedding_manager.py +11 -6
  23. jarvis/jarvis_rag/llm_interface.py +6 -5
  24. jarvis/jarvis_rag/rag_pipeline.py +9 -8
  25. jarvis/jarvis_rag/reranker.py +3 -2
  26. jarvis/jarvis_rag/retriever.py +18 -8
  27. jarvis/jarvis_smart_shell/main.py +306 -46
  28. jarvis/jarvis_stats/stats.py +40 -0
  29. jarvis/jarvis_stats/storage.py +220 -9
  30. jarvis/jarvis_tools/clear_memory.py +0 -11
  31. jarvis/jarvis_tools/cli/main.py +18 -17
  32. jarvis/jarvis_tools/edit_file.py +4 -4
  33. jarvis/jarvis_tools/execute_script.py +5 -1
  34. jarvis/jarvis_tools/file_analyzer.py +6 -6
  35. jarvis/jarvis_tools/generate_new_tool.py +6 -17
  36. jarvis/jarvis_tools/read_code.py +3 -6
  37. jarvis/jarvis_tools/read_webpage.py +74 -13
  38. jarvis/jarvis_tools/registry.py +8 -28
  39. jarvis/jarvis_tools/retrieve_memory.py +5 -16
  40. jarvis/jarvis_tools/rewrite_file.py +0 -4
  41. jarvis/jarvis_tools/save_memory.py +2 -10
  42. jarvis/jarvis_tools/search_web.py +5 -8
  43. jarvis/jarvis_tools/virtual_tty.py +22 -40
  44. jarvis/jarvis_utils/clipboard.py +3 -3
  45. jarvis/jarvis_utils/config.py +8 -0
  46. jarvis/jarvis_utils/input.py +67 -27
  47. jarvis/jarvis_utils/methodology.py +3 -3
  48. jarvis/jarvis_utils/output.py +1 -7
  49. jarvis/jarvis_utils/utils.py +44 -58
  50. {jarvis_ai_assistant-0.3.17.dist-info → jarvis_ai_assistant-0.3.19.dist-info}/METADATA +1 -1
  51. {jarvis_ai_assistant-0.3.17.dist-info → jarvis_ai_assistant-0.3.19.dist-info}/RECORD +55 -55
  52. {jarvis_ai_assistant-0.3.17.dist-info → jarvis_ai_assistant-0.3.19.dist-info}/WHEEL +0 -0
  53. {jarvis_ai_assistant-0.3.17.dist-info → jarvis_ai_assistant-0.3.19.dist-info}/entry_points.txt +0 -0
  54. {jarvis_ai_assistant-0.3.17.dist-info → jarvis_ai_assistant-0.3.19.dist-info}/licenses/LICENSE +0 -0
  55. {jarvis_ai_assistant-0.3.17.dist-info → jarvis_ai_assistant-0.3.19.dist-info}/top_level.txt +0 -0
@@ -10,6 +10,7 @@ from jarvis.jarvis_platform.registry import PlatformRegistry
10
10
  from jarvis.jarvis_utils.config import get_shell_name, set_config
11
11
  from jarvis.jarvis_utils.input import get_multiline_input
12
12
  from jarvis.jarvis_utils.utils import init_env
13
+ from jarvis.jarvis_utils.output import OutputType, PrettyOutput
13
14
 
14
15
  app = typer.Typer(
15
16
  help="将自然语言要求转换为shell命令",
@@ -58,38 +59,95 @@ def _get_markers() -> Tuple[str, str]:
58
59
  )
59
60
 
60
61
 
62
+ def _check_bash_shell() -> bool:
63
+ """Check if current shell is bash
64
+
65
+ Returns:
66
+ bool: True if bash shell, False otherwise
67
+ """
68
+ return get_shell_name() == "bash"
69
+
70
+
71
+ def _get_bash_config_file() -> str:
72
+ """Get bash config file path
73
+
74
+ Returns:
75
+ str: Path to bash config file (~/.bashrc)
76
+ """
77
+ return os.path.expanduser("~/.bashrc")
78
+
79
+
80
+ def _get_bash_markers() -> Tuple[str, str]:
81
+ """Get start and end markers for JSS completion in bash
82
+
83
+ Returns:
84
+ Tuple[str, str]: (start_marker, end_marker)
85
+ """
86
+ return (
87
+ "# ===== JARVIS JSS BASH COMPLETION START =====",
88
+ "# ===== JARVIS JSS BASH COMPLETION END =====",
89
+ )
90
+
91
+
92
+ def _check_zsh_shell() -> bool:
93
+ """Check if current shell is zsh
94
+
95
+ Returns:
96
+ bool: True if zsh shell, False otherwise
97
+ """
98
+ return get_shell_name() == "zsh"
99
+
100
+
101
+ def _get_zsh_config_file() -> str:
102
+ """Get zsh config file path
103
+
104
+ Returns:
105
+ str: Path to zsh config file (~/.zshrc)
106
+ """
107
+ return os.path.expanduser("~/.zshrc")
108
+
109
+
110
+ def _get_zsh_markers() -> Tuple[str, str]:
111
+ """Get start and end markers for JSS completion in zsh
112
+
113
+ Returns:
114
+ Tuple[str, str]: (start_marker, end_marker)
115
+ """
116
+ return (
117
+ "# ===== JARVIS JSS ZSH COMPLETION START =====",
118
+ "# ===== JARVIS JSS ZSH COMPLETION END =====",
119
+ )
120
+
121
+
61
122
  @app.command("install")
62
123
  def install_jss_completion(
63
- shell: str = typer.Option("fish", help="指定shell类型(仅支持fish)"),
124
+ shell: str = typer.Option("fish", help="指定shell类型(支持fish, bash, zsh)"),
64
125
  ) -> None:
65
- """为fish shell安装'命令未找到'处理器,实现自然语言命令执行"""
66
- if shell != "fish":
67
- print(f"错误: 不支持的shell类型: {shell}, 仅支持fish")
126
+ """为指定的shell安装'命令未找到'处理器,实现自然语言命令建议"""
127
+ if shell not in ("fish", "bash", "zsh"):
128
+ PrettyOutput.print(f"错误: 不支持的shell类型: {shell}, 仅支持fish, bash, zsh", OutputType.ERROR)
68
129
  raise typer.Exit(code=1)
69
130
 
70
- if not _check_fish_shell():
71
- print("当前不是fish shell,无需安装")
72
- return
131
+ if shell == "fish":
132
+ config_file = _get_config_file()
133
+ start_marker, end_marker = _get_markers()
73
134
 
74
- config_file = _get_config_file()
75
- start_marker, end_marker = _get_markers()
135
+ if not os.path.exists(config_file):
136
+ PrettyOutput.print("未找到 config.fish 文件,将创建新文件", OutputType.INFO)
137
+ os.makedirs(os.path.dirname(config_file), exist_ok=True)
138
+ with open(config_file, "w") as f:
139
+ f.write("")
76
140
 
77
- if not os.path.exists(config_file):
78
- print("未找到config.fish文件,将创建新文件")
79
- os.makedirs(os.path.dirname(config_file), exist_ok=True)
80
- with open(config_file, "w") as f:
81
- f.write("")
141
+ with open(config_file, "r") as f:
142
+ content = f.read()
82
143
 
83
- with open(config_file, "r") as f:
84
- content = f.read()
144
+ if start_marker in content:
145
+ PrettyOutput.print("JSS fish completion 已安装,请执行: source ~/.config/fish/config.fish", OutputType.SUCCESS)
146
+ return
85
147
 
86
- if start_marker in content:
87
- print("JSS fish completion已安装,请执行: source ~/.config/fish/config.fish")
88
- return
89
-
90
- with open(config_file, "a") as f:
91
- f.write(
92
- f"""
148
+ with open(config_file, "a") as f:
149
+ f.write(
150
+ f"""
93
151
  {start_marker}
94
152
  function fish_command_not_found
95
153
  if test (string length "$argv") -lt 10
@@ -103,43 +161,245 @@ function __fish_command_not_found_handler --on-event fish_command_not_found
103
161
  end
104
162
  {end_marker}
105
163
  """
106
- )
107
- print("JSS fish completion已安装,请执行: source ~/.config/fish/config.fish")
164
+ )
165
+ PrettyOutput.print("JSS fish completion 已安装,请执行: source ~/.config/fish/config.fish", OutputType.SUCCESS)
166
+ elif shell == "bash":
167
+ config_file = _get_bash_config_file()
168
+ start_marker, end_marker = _get_bash_markers()
169
+
170
+ if not os.path.exists(config_file):
171
+ PrettyOutput.print("未找到 ~/.bashrc 文件,将创建新文件", OutputType.INFO)
172
+ os.makedirs(os.path.dirname(config_file), exist_ok=True)
173
+ with open(config_file, "w") as f:
174
+ f.write("")
175
+
176
+ with open(config_file, "r") as f:
177
+ content = f.read()
178
+
179
+ if start_marker in content:
180
+ PrettyOutput.print("JSS bash completion 已安装,请执行: source ~/.bashrc", OutputType.SUCCESS)
181
+ return
182
+ else:
183
+ with open(config_file, "a") as f:
184
+ f.write(
185
+ f"""
186
+ {start_marker}
187
+ # Bash 'command not found' handler for JSS
188
+ # 行为:
189
+ # - 生成可编辑的建议命令,用户可直接编辑后回车执行
190
+ # - 非交互模式下仅打印建议
191
+ command_not_found_handle() {{
192
+ local cmd="$1"
193
+ shift || true
194
+ local text="$cmd $*"
195
+
196
+ # 与 fish 行为保持一致:对过短输入不处理
197
+ if [ ${{#text}} -lt 10 ]; then
198
+ return 127
199
+ fi
200
+
201
+ local suggestion edited
202
+ suggestion=$(jss request "$text")
203
+ if [ -n "$suggestion" ]; then
204
+ # 交互式:用 readline 预填命令,用户可直接回车执行或编辑
205
+ if [[ $- == *i* ]]; then
206
+ edited="$suggestion"
207
+ # -e 启用 readline;-i 预填默认值;无提示前缀,使体验更接近 fish 的“替换命令行”
208
+ read -e -i "$edited" edited
209
+ if [ -n "$edited" ]; then
210
+ eval "$edited"
211
+ return $?
212
+ fi
213
+ else
214
+ # 非交互:仅打印建议
215
+ printf '%s\n' "$suggestion"
216
+ fi
217
+ fi
218
+ return 127
219
+ }}
220
+ {end_marker}
221
+ """
222
+ )
223
+ PrettyOutput.print("JSS bash completion 已安装,请执行: source ~/.bashrc", OutputType.SUCCESS)
224
+ elif shell == "zsh":
225
+ config_file = _get_zsh_config_file()
226
+ start_marker, end_marker = _get_zsh_markers()
227
+
228
+ if not os.path.exists(config_file):
229
+ PrettyOutput.print("未找到 ~/.zshrc 文件,将创建新文件", OutputType.INFO)
230
+ os.makedirs(os.path.dirname(config_file), exist_ok=True)
231
+ with open(config_file, "w") as f:
232
+ f.write("")
233
+
234
+ with open(config_file, "r") as f:
235
+ content = f.read()
236
+
237
+ if start_marker in content:
238
+ PrettyOutput.print("JSS zsh completion 已安装,请执行: source ~/.zshrc", OutputType.SUCCESS)
239
+ return
240
+
241
+ with open(config_file, "a") as f:
242
+ f.write(
243
+ f"""
244
+ {start_marker}
245
+ # Zsh 'command not found' handler for JSS
246
+ # 行为:
247
+ # - 生成可编辑的建议命令,用户可直接编辑后回车执行
248
+ # - 非交互模式下仅打印建议
249
+ command_not_found_handler() {{
250
+ local cmd="$1"
251
+ shift || true
252
+ local text="$cmd $*"
253
+
254
+ # 与 fish 行为保持一致:对过短输入不处理
255
+ if [ ${{#text}} -lt 10 ]; then
256
+ return 127
257
+ fi
258
+
259
+ local suggestion edited
260
+ suggestion=$(jss request "$text")
261
+ if [ -n "$suggestion" ]; then
262
+ if [[ -o interactive ]]; then
263
+ local editor="${{VISUAL:-${{EDITOR:-vi}}}}"
264
+ local tmpfile edited
265
+ tmpfile="$(mktemp -t jss-edit-XXXXXX)"
266
+ printf '%s\n' "$suggestion" > "$tmpfile"
267
+ "$editor" "$tmpfile"
268
+ edited="$(sed -n '/./{{p;q;}}' "$tmpfile" | tr -d '\r')"
269
+ rm -f "$tmpfile"
270
+ if [ -z "$edited" ]; then
271
+ edited="$suggestion"
272
+ fi
273
+ eval "$edited"
274
+ return $?
275
+ else
276
+ # 非交互:仅打印建议
277
+ print -r -- "$suggestion"
278
+ fi
279
+ fi
280
+ return 127
281
+ }}
282
+ {end_marker}
283
+ """
284
+ )
285
+ PrettyOutput.print("JSS zsh completion 已安装,请执行: source ~/.zshrc", OutputType.SUCCESS)
286
+ return
287
+
288
+ with open(config_file, "a") as f:
289
+ f.write(
290
+ f"""
291
+ {start_marker}
292
+ # Bash 'command not found' handler for JSS
293
+ # 行为:
294
+ # - 生成可编辑的建议命令,用户可直接编辑后回车执行
295
+ # - 非交互模式下仅打印建议
296
+ command_not_found_handle() {{
297
+ local cmd="$1"
298
+ shift || true
299
+ local text="$cmd $*"
300
+
301
+ # 与 fish 行为保持一致:对过短输入不处理
302
+ if [ ${{#text}} -lt 10 ]; then
303
+ return 127
304
+ fi
305
+
306
+ local suggestion edited
307
+ suggestion=$(jss request "$text")
308
+ if [ -n "$suggestion" ]; then
309
+ # 交互式:用 readline 预填命令,用户可直接回车执行或编辑
310
+ if [[ $- == *i* ]]; then
311
+ edited="$suggestion"
312
+ # -e 启用 readline;-i 预填默认值;无提示前缀,使体验更接近 fish 的“替换命令行”
313
+ read -e -i "$edited" edited
314
+ if [ -n "$edited" ]; then
315
+ eval "$edited"
316
+ return $?
317
+ fi
318
+ else
319
+ # 非交互:仅打印建议
320
+ printf '%s\n' "$suggestion"
321
+ fi
322
+ fi
323
+ return 127
324
+ }}
325
+ {end_marker}
326
+ """
327
+ )
328
+ PrettyOutput.print("JSS bash completion 已安装,请执行: source ~/.bashrc", OutputType.SUCCESS)
108
329
 
109
330
 
110
331
  @app.command("uninstall")
111
332
  def uninstall_jss_completion(
112
- shell: str = typer.Option("fish", help="指定shell类型(仅支持fish)"),
333
+ shell: str = typer.Option("fish", help="指定shell类型(支持fish, bash, zsh)"),
113
334
  ) -> None:
114
- """卸载JSS fish shell'命令未找到'处理器"""
115
- if shell != "fish":
116
- print(f"错误: 不支持的shell类型: {shell}, 仅支持fish")
335
+ """卸载JSS shell'命令未找到'处理器"""
336
+ if shell not in ("fish", "bash", "zsh"):
337
+ PrettyOutput.print(f"错误: 不支持的shell类型: {shell}, 仅支持fish, bash, zsh", OutputType.ERROR)
117
338
  raise typer.Exit(code=1)
118
339
 
119
- if not _check_fish_shell():
120
- print("当前不是fish shell,无需卸载")
121
- return
340
+ if shell == "fish":
341
+ config_file = _get_config_file()
342
+ start_marker, end_marker = _get_markers()
122
343
 
123
- config_file = _get_config_file()
124
- start_marker, end_marker = _get_markers()
344
+ if not os.path.exists(config_file):
345
+ PrettyOutput.print("未找到 JSS fish completion 配置,无需卸载", OutputType.INFO)
346
+ return
125
347
 
126
- if not os.path.exists(config_file):
127
- print("未找到JSS fish completion配置,无需卸载")
128
- return
348
+ with open(config_file, "r") as f:
349
+ content = f.read()
129
350
 
130
- with open(config_file, "r") as f:
131
- content = f.read()
351
+ if start_marker not in content:
352
+ PrettyOutput.print("未找到 JSS fish completion 配置,无需卸载", OutputType.INFO)
353
+ return
132
354
 
133
- if start_marker not in content:
134
- print("未找到JSS fish completion配置,无需卸载")
135
- return
355
+ new_content = content.split(start_marker)[0] + content.split(end_marker)[-1]
356
+
357
+ with open(config_file, "w") as f:
358
+ f.write(new_content)
359
+
360
+ PrettyOutput.print("JSS fish completion 已卸载,请执行: source ~/.config/fish/config.fish", OutputType.SUCCESS)
361
+ elif shell == "bash":
362
+ config_file = _get_bash_config_file()
363
+ start_marker, end_marker = _get_bash_markers()
364
+
365
+ if not os.path.exists(config_file):
366
+ PrettyOutput.print("未找到 JSS bash completion 配置,无需卸载", OutputType.INFO)
367
+ return
368
+
369
+ with open(config_file, "r") as f:
370
+ content = f.read()
371
+
372
+ if start_marker not in content:
373
+ PrettyOutput.print("未找到 JSS bash completion 配置,无需卸载", OutputType.INFO)
374
+ return
136
375
 
137
- new_content = content.split(start_marker)[0] + content.split(end_marker)[-1]
376
+ new_content = content.split(start_marker)[0] + content.split(end_marker)[-1]
138
377
 
139
- with open(config_file, "w") as f:
140
- f.write(new_content)
378
+ with open(config_file, "w") as f:
379
+ f.write(new_content)
380
+
381
+ PrettyOutput.print("JSS bash completion 已卸载,请执行: source ~/.bashrc", OutputType.SUCCESS)
382
+ elif shell == "zsh":
383
+ config_file = _get_zsh_config_file()
384
+ start_marker, end_marker = _get_zsh_markers()
385
+
386
+ if not os.path.exists(config_file):
387
+ PrettyOutput.print("未找到 JSS zsh completion 配置,无需卸载", OutputType.INFO)
388
+ return
389
+
390
+ with open(config_file, "r") as f:
391
+ content = f.read()
392
+
393
+ if start_marker not in content:
394
+ PrettyOutput.print("未找到 JSS zsh completion 配置,无需卸载", OutputType.INFO)
395
+ return
396
+
397
+ new_content = content.split(start_marker)[0] + content.split(end_marker)[-1]
398
+
399
+ with open(config_file, "w") as f:
400
+ f.write(new_content)
141
401
 
142
- print("JSS fish completion已卸载,请执行: source ~/.config/fish/config.fish")
402
+ PrettyOutput.print("JSS zsh completion 已卸载,请执行: source ~/.zshrc", OutputType.SUCCESS)
143
403
 
144
404
 
145
405
  def process_request(request: str) -> Optional[str]:
@@ -93,6 +93,46 @@ class StatsManager:
93
93
  storage = StatsManager._get_storage()
94
94
  return storage.list_metrics()
95
95
 
96
+ @staticmethod
97
+ def get_metric_total(metric_name: str) -> float:
98
+ """
99
+ 获取指标的累计总量(快速路径)
100
+ 优先从总量缓存读取;若不存在则回溯历史数据计算一次后缓存
101
+ """
102
+ storage = StatsManager._get_storage()
103
+ try:
104
+ return float(storage.get_metric_total(metric_name))
105
+ except Exception:
106
+ return 0.0
107
+
108
+ @staticmethod
109
+ def get_metric_info(metric_name: str) -> Optional[Dict[str, Any]]:
110
+ """
111
+ 获取指标元信息(包含unit、created_at、last_updated、group等)
112
+ - 若缺少group,会尝试基于历史记录的tags进行推断并写回,然后返回最新信息
113
+ """
114
+ storage = StatsManager._get_storage()
115
+ info = storage.get_metric_info(metric_name)
116
+ if not info or not info.get("group"):
117
+ try:
118
+ grp = storage.resolve_metric_group(metric_name) # 触发一次分组解析与回填
119
+ if grp:
120
+ info = storage.get_metric_info(metric_name)
121
+ except Exception:
122
+ pass
123
+ return info
124
+
125
+ @staticmethod
126
+ def resolve_metric_group(metric_name: str) -> Optional[str]:
127
+ """
128
+ 主动解析并写回某个指标的分组信息(调用底层存储的推断逻辑)
129
+ """
130
+ storage = StatsManager._get_storage()
131
+ try:
132
+ return storage.resolve_metric_group(metric_name)
133
+ except Exception:
134
+ return None
135
+
96
136
  @staticmethod
97
137
  def show(
98
138
  metric_name: Optional[str] = None,