jarvis-ai-assistant 0.3.16__py3-none-any.whl → 0.3.18__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 +2 -0
- jarvis/jarvis_agent/jarvis.py +362 -182
- jarvis/jarvis_agent/methodology_share_manager.py +2 -2
- jarvis/jarvis_agent/session_manager.py +9 -1
- jarvis/jarvis_agent/task_manager.py +11 -6
- jarvis/jarvis_agent/tool_share_manager.py +2 -2
- jarvis/jarvis_data/config_schema.json +39 -0
- jarvis/jarvis_platform/base.py +8 -1
- jarvis/jarvis_platform_manager/main.py +12 -22
- jarvis/jarvis_tools/read_webpage.py +75 -14
- jarvis/jarvis_utils/config.py +56 -0
- jarvis/jarvis_utils/input.py +49 -3
- jarvis/jarvis_utils/utils.py +151 -0
- {jarvis_ai_assistant-0.3.16.dist-info → jarvis_ai_assistant-0.3.18.dist-info}/METADATA +1 -1
- {jarvis_ai_assistant-0.3.16.dist-info → jarvis_ai_assistant-0.3.18.dist-info}/RECORD +20 -20
- {jarvis_ai_assistant-0.3.16.dist-info → jarvis_ai_assistant-0.3.18.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.3.16.dist-info → jarvis_ai_assistant-0.3.18.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.3.16.dist-info → jarvis_ai_assistant-0.3.18.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.3.16.dist-info → jarvis_ai_assistant-0.3.18.dist-info}/top_level.txt +0 -0
jarvis/__init__.py
CHANGED
jarvis/jarvis_agent/__init__.py
CHANGED
jarvis/jarvis_agent/jarvis.py
CHANGED
@@ -10,6 +10,14 @@ from jarvis.jarvis_agent.config_editor import ConfigEditor
|
|
10
10
|
from jarvis.jarvis_agent.methodology_share_manager import MethodologyShareManager
|
11
11
|
from jarvis.jarvis_agent.tool_share_manager import ToolShareManager
|
12
12
|
from jarvis.jarvis_utils.utils import init_env
|
13
|
+
from jarvis.jarvis_utils.config import (
|
14
|
+
is_enable_git_repo_jca_switch,
|
15
|
+
is_enable_builtin_config_selector,
|
16
|
+
get_agent_definition_dirs,
|
17
|
+
get_multi_agent_dirs,
|
18
|
+
get_roles_dirs,
|
19
|
+
)
|
20
|
+
import jarvis.jarvis_utils.utils as jutils
|
13
21
|
from jarvis.jarvis_utils.input import user_confirm, get_single_line_input
|
14
22
|
import os
|
15
23
|
import sys
|
@@ -22,6 +30,347 @@ from rich.console import Console
|
|
22
30
|
app = typer.Typer(help="Jarvis AI 助手")
|
23
31
|
|
24
32
|
|
33
|
+
def print_commands_overview() -> None:
|
34
|
+
"""打印命令与快捷方式总览表。"""
|
35
|
+
try:
|
36
|
+
cmd_table = Table(show_header=True, header_style="bold magenta")
|
37
|
+
cmd_table.add_column("命令", style="bold")
|
38
|
+
cmd_table.add_column("快捷方式", style="cyan")
|
39
|
+
cmd_table.add_column("功能描述", style="white")
|
40
|
+
|
41
|
+
cmd_table.add_row("jarvis", "jvs", "通用AI代理,适用于多种任务")
|
42
|
+
cmd_table.add_row("jarvis-agent", "ja", "AI代理基础功能,处理会话和任务")
|
43
|
+
cmd_table.add_row(
|
44
|
+
"jarvis-code-agent",
|
45
|
+
"jca",
|
46
|
+
"专注于代码分析、修改和生成的代码代理",
|
47
|
+
)
|
48
|
+
cmd_table.add_row("jarvis-code-review", "jcr", "智能代码审查工具")
|
49
|
+
cmd_table.add_row(
|
50
|
+
"jarvis-git-commit",
|
51
|
+
"jgc",
|
52
|
+
"自动化分析代码变更并生成规范的Git提交信息",
|
53
|
+
)
|
54
|
+
cmd_table.add_row("jarvis-git-squash", "jgs", "Git提交历史整理工具")
|
55
|
+
cmd_table.add_row(
|
56
|
+
"jarvis-platform-manager",
|
57
|
+
"jpm",
|
58
|
+
"管理和测试不同的大语言模型平台",
|
59
|
+
)
|
60
|
+
cmd_table.add_row("jarvis-multi-agent", "jma", "多智能体协作系统")
|
61
|
+
cmd_table.add_row("jarvis-tool", "jt", "工具管理与调用系统")
|
62
|
+
cmd_table.add_row("jarvis-methodology", "jm", "方法论知识库管理")
|
63
|
+
cmd_table.add_row(
|
64
|
+
"jarvis-rag",
|
65
|
+
"jrg",
|
66
|
+
"构建和查询本地化的RAG知识库",
|
67
|
+
)
|
68
|
+
cmd_table.add_row("jarvis-smart-shell", "jss", "实验性的智能Shell功能")
|
69
|
+
cmd_table.add_row(
|
70
|
+
"jarvis-stats",
|
71
|
+
"jst",
|
72
|
+
"通用统计模块,支持记录和可视化任意指标数据",
|
73
|
+
)
|
74
|
+
cmd_table.add_row(
|
75
|
+
"jarvis-memory-organizer",
|
76
|
+
"jmo",
|
77
|
+
"记忆管理工具,支持整理、合并、导入导出记忆",
|
78
|
+
)
|
79
|
+
|
80
|
+
Console().print(cmd_table)
|
81
|
+
except Exception:
|
82
|
+
# 静默忽略渲染异常,避免影响主流程
|
83
|
+
pass
|
84
|
+
|
85
|
+
def handle_edit_option(edit: bool, config_file: Optional[str]) -> bool:
|
86
|
+
"""处理配置文件编辑选项,返回是否已处理并需提前结束。"""
|
87
|
+
if edit:
|
88
|
+
ConfigEditor.edit_config(config_file)
|
89
|
+
return True
|
90
|
+
return False
|
91
|
+
|
92
|
+
|
93
|
+
def handle_share_methodology_option(
|
94
|
+
share_methodology: bool, config_file: Optional[str]
|
95
|
+
) -> bool:
|
96
|
+
"""处理方法论分享选项,返回是否已处理并需提前结束。"""
|
97
|
+
if share_methodology:
|
98
|
+
init_env("", config_file=config_file) # 初始化配置但不显示欢迎信息
|
99
|
+
methodology_manager = MethodologyShareManager()
|
100
|
+
methodology_manager.run()
|
101
|
+
return True
|
102
|
+
return False
|
103
|
+
|
104
|
+
|
105
|
+
def handle_share_tool_option(share_tool: bool, config_file: Optional[str]) -> bool:
|
106
|
+
"""处理工具分享选项,返回是否已处理并需提前结束。"""
|
107
|
+
if share_tool:
|
108
|
+
init_env("", config_file=config_file) # 初始化配置但不显示欢迎信息
|
109
|
+
tool_manager = ToolShareManager()
|
110
|
+
tool_manager.run()
|
111
|
+
return True
|
112
|
+
return False
|
113
|
+
|
114
|
+
|
115
|
+
def preload_config_for_flags(config_file: Optional[str]) -> None:
|
116
|
+
"""预加载配置(仅用于读取功能开关),不会显示欢迎信息或影响后续 init_env。"""
|
117
|
+
try:
|
118
|
+
jutils.g_config_file = config_file
|
119
|
+
jutils.load_config()
|
120
|
+
except Exception:
|
121
|
+
# 静默忽略配置加载异常
|
122
|
+
pass
|
123
|
+
|
124
|
+
|
125
|
+
def try_switch_to_jca_if_git_repo(
|
126
|
+
llm_type: str,
|
127
|
+
model_group: Optional[str],
|
128
|
+
tool_group: Optional[str],
|
129
|
+
config_file: Optional[str],
|
130
|
+
restore_session: bool,
|
131
|
+
task: Optional[str],
|
132
|
+
) -> None:
|
133
|
+
"""在初始化环境前检测Git仓库,并可选择自动切换到代码开发模式(jca)。"""
|
134
|
+
if is_enable_git_repo_jca_switch():
|
135
|
+
try:
|
136
|
+
res = subprocess.run(
|
137
|
+
["git", "rev-parse", "--show-toplevel"],
|
138
|
+
capture_output=True,
|
139
|
+
text=True,
|
140
|
+
)
|
141
|
+
if res.returncode == 0:
|
142
|
+
git_root = res.stdout.strip()
|
143
|
+
if git_root and os.path.isdir(git_root):
|
144
|
+
PrettyOutput.print(
|
145
|
+
f"检测到当前位于 Git 仓库: {git_root}", OutputType.INFO
|
146
|
+
)
|
147
|
+
if user_confirm(
|
148
|
+
"检测到Git仓库,是否切换到代码开发模式(jca)?", default=False
|
149
|
+
):
|
150
|
+
# 构建并切换到 jarvis-code-agent 命令,传递兼容参数
|
151
|
+
args = ["jarvis-code-agent"]
|
152
|
+
if llm_type:
|
153
|
+
args += ["-t", llm_type]
|
154
|
+
if model_group:
|
155
|
+
args += ["-g", model_group]
|
156
|
+
if tool_group:
|
157
|
+
args += ["-G", tool_group]
|
158
|
+
if config_file:
|
159
|
+
args += ["-f", config_file]
|
160
|
+
if restore_session:
|
161
|
+
args += ["--restore-session"]
|
162
|
+
if task:
|
163
|
+
args += ["-r", task]
|
164
|
+
PrettyOutput.print(
|
165
|
+
"正在切换到 'jca'(jarvis-code-agent)以进入代码开发模式...",
|
166
|
+
OutputType.INFO,
|
167
|
+
)
|
168
|
+
os.execvp(args[0], args)
|
169
|
+
except Exception:
|
170
|
+
# 静默忽略检测异常,不影响主流程
|
171
|
+
pass
|
172
|
+
|
173
|
+
|
174
|
+
def handle_builtin_config_selector(
|
175
|
+
llm_type: str,
|
176
|
+
model_group: Optional[str],
|
177
|
+
tool_group: Optional[str],
|
178
|
+
config_file: Optional[str],
|
179
|
+
task: Optional[str],
|
180
|
+
) -> None:
|
181
|
+
"""在进入默认通用代理前,列出内置配置供选择(agent/multi_agent/roles)。"""
|
182
|
+
if is_enable_builtin_config_selector():
|
183
|
+
try:
|
184
|
+
# 优先使用项目内置目录,若不存在则回退到指定的绝对路径
|
185
|
+
builtin_root = Path(__file__).resolve().parents[3] / "builtin"
|
186
|
+
if not builtin_root.exists():
|
187
|
+
builtin_root = Path("/home/skyfire/code/Jarvis/builtin")
|
188
|
+
|
189
|
+
categories = [
|
190
|
+
("agent", "jarvis-agent", "*.yaml"),
|
191
|
+
("multi_agent", "jarvis-multi-agent", "*.yaml"),
|
192
|
+
("roles", "jarvis-platform-manager", "*.yaml"),
|
193
|
+
]
|
194
|
+
|
195
|
+
options = []
|
196
|
+
for cat, cmd, pattern in categories:
|
197
|
+
# 构建待扫描目录列表:优先使用配置中的目录,其次回退到内置目录
|
198
|
+
search_dirs = []
|
199
|
+
try:
|
200
|
+
if cat == "agent":
|
201
|
+
search_dirs.extend(
|
202
|
+
[Path(p) for p in get_agent_definition_dirs() if p]
|
203
|
+
)
|
204
|
+
elif cat == "multi_agent":
|
205
|
+
search_dirs.extend(
|
206
|
+
[Path(p) for p in get_multi_agent_dirs() if p]
|
207
|
+
)
|
208
|
+
elif cat == "roles":
|
209
|
+
search_dirs.extend([Path(p) for p in get_roles_dirs() if p])
|
210
|
+
except Exception:
|
211
|
+
# 忽略配置读取异常
|
212
|
+
pass
|
213
|
+
|
214
|
+
# 追加内置目录
|
215
|
+
search_dirs.append(builtin_root / cat)
|
216
|
+
|
217
|
+
# 去重并保留顺序
|
218
|
+
unique_dirs = []
|
219
|
+
seen = set()
|
220
|
+
for d in search_dirs:
|
221
|
+
try:
|
222
|
+
key = str(Path(d).resolve())
|
223
|
+
except Exception:
|
224
|
+
key = str(d)
|
225
|
+
if key not in seen:
|
226
|
+
seen.add(key)
|
227
|
+
unique_dirs.append(Path(d))
|
228
|
+
|
229
|
+
# 每日自动更新配置目录(如目录为Git仓库则执行git pull,每日仅一次)
|
230
|
+
try:
|
231
|
+
jutils.daily_check_git_updates([str(p) for p in unique_dirs], cat)
|
232
|
+
except Exception:
|
233
|
+
# 忽略更新过程中的所有异常,避免影响主流程
|
234
|
+
pass
|
235
|
+
|
236
|
+
for dir_path in unique_dirs:
|
237
|
+
if not dir_path.exists():
|
238
|
+
continue
|
239
|
+
for fpath in sorted(dir_path.glob(pattern)):
|
240
|
+
# 解析YAML以获取可读名称/描述(失败时静默降级为文件名)
|
241
|
+
name = fpath.stem
|
242
|
+
desc = ""
|
243
|
+
roles_count = 0
|
244
|
+
try:
|
245
|
+
with open(
|
246
|
+
fpath, "r", encoding="utf-8", errors="ignore"
|
247
|
+
) as fh:
|
248
|
+
data = yaml.safe_load(fh) or {}
|
249
|
+
if isinstance(data, dict):
|
250
|
+
name = data.get("name") or data.get("title") or name
|
251
|
+
desc = data.get("description") or data.get("desc") or ""
|
252
|
+
if cat == "roles" and isinstance(
|
253
|
+
data.get("roles"), list
|
254
|
+
):
|
255
|
+
roles_count = len(data["roles"])
|
256
|
+
if not desc:
|
257
|
+
desc = f"{roles_count} 个角色"
|
258
|
+
except Exception:
|
259
|
+
# 忽略解析错误,使用默认显示
|
260
|
+
pass
|
261
|
+
|
262
|
+
# 为 roles 构建详细信息(每个角色的名称与描述)
|
263
|
+
details = ""
|
264
|
+
if cat == "roles":
|
265
|
+
roles = (data or {}).get("roles", [])
|
266
|
+
if isinstance(roles, list):
|
267
|
+
lines = []
|
268
|
+
for role in roles:
|
269
|
+
if isinstance(role, dict):
|
270
|
+
rname = str(role.get("name", "") or "")
|
271
|
+
rdesc = str(role.get("description", "") or "")
|
272
|
+
lines.append(
|
273
|
+
f"{rname} - {rdesc}" if rdesc else rname
|
274
|
+
)
|
275
|
+
details = "\n".join([ln for ln in lines if ln])
|
276
|
+
# 如果没有角色详情,退回到统计信息
|
277
|
+
if not details and isinstance(
|
278
|
+
(data or {}).get("roles"), list
|
279
|
+
):
|
280
|
+
details = f"{len(data['roles'])} 个角色"
|
281
|
+
|
282
|
+
options.append(
|
283
|
+
{
|
284
|
+
"category": cat,
|
285
|
+
"cmd": cmd,
|
286
|
+
"file": str(fpath),
|
287
|
+
"name": str(name),
|
288
|
+
"desc": str(desc),
|
289
|
+
"details": str(details),
|
290
|
+
"roles_count": int(roles_count),
|
291
|
+
}
|
292
|
+
)
|
293
|
+
|
294
|
+
if options:
|
295
|
+
PrettyOutput.section("可用的内置配置", OutputType.SUCCESS)
|
296
|
+
# 使用 rich Table 呈现
|
297
|
+
table = Table(show_header=True, header_style="bold magenta")
|
298
|
+
table.add_column("No.", style="cyan", no_wrap=True)
|
299
|
+
table.add_column("类型", style="green", no_wrap=True)
|
300
|
+
table.add_column("名称", style="bold")
|
301
|
+
table.add_column("文件", style="dim")
|
302
|
+
table.add_column("描述", style="white")
|
303
|
+
|
304
|
+
for idx, opt in enumerate(options, 1):
|
305
|
+
category = opt.get("category", "")
|
306
|
+
name = opt.get("name", "")
|
307
|
+
file_path = opt.get("file", "")
|
308
|
+
# 描述列显示配置描述;若为 roles 同时显示角色数量与列表
|
309
|
+
if category == "roles":
|
310
|
+
count = opt.get("roles_count")
|
311
|
+
details = opt.get("details", "")
|
312
|
+
parts = []
|
313
|
+
if isinstance(count, int) and count > 0:
|
314
|
+
parts.append(f"{count} 个角色")
|
315
|
+
if details:
|
316
|
+
parts.append(details)
|
317
|
+
desc_display = "\n".join(parts) if parts else ""
|
318
|
+
else:
|
319
|
+
desc_display = opt.get("desc", "")
|
320
|
+
table.add_row(str(idx), category, name, file_path, desc_display)
|
321
|
+
|
322
|
+
Console().print(table)
|
323
|
+
|
324
|
+
choice = get_single_line_input(
|
325
|
+
"选择要启动的配置编号,直接回车使用默认通用代理(jvs): ", default=""
|
326
|
+
)
|
327
|
+
|
328
|
+
if choice.strip():
|
329
|
+
try:
|
330
|
+
index = int(choice.strip())
|
331
|
+
if 1 <= index <= len(options):
|
332
|
+
sel = options[index - 1]
|
333
|
+
args = []
|
334
|
+
|
335
|
+
if sel["category"] == "agent":
|
336
|
+
# jarvis-agent 支持 -f/--config(全局配置)与 -c/--agent-definition
|
337
|
+
args = [sel["cmd"], "-c", sel["file"]]
|
338
|
+
if llm_type:
|
339
|
+
args += ["--llm-type", llm_type]
|
340
|
+
if model_group:
|
341
|
+
args += ["-g", model_group]
|
342
|
+
if config_file:
|
343
|
+
args += ["-f", config_file]
|
344
|
+
if task:
|
345
|
+
args += ["--task", task]
|
346
|
+
|
347
|
+
elif sel["category"] == "multi_agent":
|
348
|
+
# jarvis-multi-agent 需要 -c/--config,用户输入通过 -i/--input 传递
|
349
|
+
args = [sel["cmd"], "-c", sel["file"]]
|
350
|
+
if task:
|
351
|
+
args += ["-i", task]
|
352
|
+
|
353
|
+
elif sel["category"] == "roles":
|
354
|
+
# jarvis-platform-manager role 子命令,支持 -c/-t/-g
|
355
|
+
args = [sel["cmd"], "role", "-c", sel["file"]]
|
356
|
+
if llm_type:
|
357
|
+
args += ["-t", llm_type]
|
358
|
+
if model_group:
|
359
|
+
args += ["-g", model_group]
|
360
|
+
|
361
|
+
if args:
|
362
|
+
PrettyOutput.print(
|
363
|
+
f"正在启动: {' '.join(args)}", OutputType.INFO
|
364
|
+
)
|
365
|
+
os.execvp(args[0], args)
|
366
|
+
except Exception:
|
367
|
+
# 任何异常都不影响默认流程
|
368
|
+
pass
|
369
|
+
except Exception:
|
370
|
+
# 静默忽略内置配置扫描错误,不影响主流程
|
371
|
+
pass
|
372
|
+
|
373
|
+
|
25
374
|
@app.callback(invoke_without_command=True)
|
26
375
|
def run_cli(
|
27
376
|
ctx: typer.Context,
|
@@ -60,200 +409,31 @@ def run_cli(
|
|
60
409
|
if ctx.invoked_subcommand is not None:
|
61
410
|
return
|
62
411
|
|
412
|
+
# 使用 rich 输出命令与快捷方式总览
|
413
|
+
print_commands_overview()
|
414
|
+
|
63
415
|
# 处理配置文件编辑
|
64
|
-
if edit:
|
65
|
-
ConfigEditor.edit_config(config_file)
|
416
|
+
if handle_edit_option(edit, config_file):
|
66
417
|
return
|
67
418
|
|
68
419
|
# 处理方法论分享
|
69
|
-
if share_methodology:
|
70
|
-
init_env("", config_file=config_file) # 初始化配置但不显示欢迎信息
|
71
|
-
methodology_manager = MethodologyShareManager()
|
72
|
-
methodology_manager.run()
|
420
|
+
if handle_share_methodology_option(share_methodology, config_file):
|
73
421
|
return
|
74
422
|
|
75
423
|
# 处理工具分享
|
76
|
-
if share_tool:
|
77
|
-
init_env("", config_file=config_file) # 初始化配置但不显示欢迎信息
|
78
|
-
tool_manager = ToolShareManager()
|
79
|
-
tool_manager.run()
|
424
|
+
if handle_share_tool_option(share_tool, config_file):
|
80
425
|
return
|
81
426
|
|
427
|
+
# 预加载配置(仅用于读取功能开关),不会显示欢迎信息或影响后续 init_env
|
428
|
+
preload_config_for_flags(config_file)
|
429
|
+
|
82
430
|
# 在初始化环境前检测Git仓库,并可选择自动切换到代码开发模式(jca)
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
capture_output=True,
|
87
|
-
text=True,
|
88
|
-
)
|
89
|
-
if res.returncode == 0:
|
90
|
-
git_root = res.stdout.strip()
|
91
|
-
if git_root and os.path.isdir(git_root):
|
92
|
-
PrettyOutput.print(
|
93
|
-
f"检测到当前位于 Git 仓库: {git_root}", OutputType.INFO
|
94
|
-
)
|
95
|
-
if user_confirm(
|
96
|
-
"检测到Git仓库,是否切换到代码开发模式(jca)?", default=False
|
97
|
-
):
|
98
|
-
# 构建并切换到 jarvis-code-agent 命令,传递兼容参数
|
99
|
-
args = ["jarvis-code-agent"]
|
100
|
-
if llm_type:
|
101
|
-
args += ["-t", llm_type]
|
102
|
-
if model_group:
|
103
|
-
args += ["-g", model_group]
|
104
|
-
if tool_group:
|
105
|
-
args += ["-G", tool_group]
|
106
|
-
if config_file:
|
107
|
-
args += ["-f", config_file]
|
108
|
-
if restore_session:
|
109
|
-
args += ["--restore-session"]
|
110
|
-
if task:
|
111
|
-
args += ["-r", task]
|
112
|
-
PrettyOutput.print(
|
113
|
-
"正在切换到 'jca'(jarvis-code-agent)以进入代码开发模式...",
|
114
|
-
OutputType.INFO,
|
115
|
-
)
|
116
|
-
os.execvp(args[0], args)
|
117
|
-
except Exception:
|
118
|
-
# 静默忽略检测异常,不影响主流程
|
119
|
-
pass
|
431
|
+
try_switch_to_jca_if_git_repo(
|
432
|
+
llm_type, model_group, tool_group, config_file, restore_session, task
|
433
|
+
)
|
120
434
|
|
121
435
|
# 在进入默认通用代理前,列出内置配置供选择(agent/multi_agent/roles)
|
122
|
-
|
123
|
-
# 优先使用项目内置目录,若不存在则回退到指定的绝对路径
|
124
|
-
builtin_root = Path(__file__).resolve().parents[3] / "builtin"
|
125
|
-
if not builtin_root.exists():
|
126
|
-
builtin_root = Path("/home/skyfire/code/Jarvis/builtin")
|
127
|
-
|
128
|
-
categories = [
|
129
|
-
("agent", "jarvis-agent", "*.yaml"),
|
130
|
-
("multi_agent", "jarvis-multi-agent", "*.yaml"),
|
131
|
-
("roles", "jarvis-platform-manager", "*.yaml"),
|
132
|
-
]
|
133
|
-
|
134
|
-
options = []
|
135
|
-
for cat, cmd, pattern in categories:
|
136
|
-
dir_path = builtin_root / cat
|
137
|
-
if not dir_path.exists():
|
138
|
-
continue
|
139
|
-
for fpath in sorted(dir_path.glob(pattern)):
|
140
|
-
# 解析YAML以获取可读名称/描述(失败时静默降级为文件名)
|
141
|
-
name = fpath.stem
|
142
|
-
desc = ""
|
143
|
-
try:
|
144
|
-
with open(fpath, "r", encoding="utf-8", errors="ignore") as fh:
|
145
|
-
data = yaml.safe_load(fh) or {}
|
146
|
-
if isinstance(data, dict):
|
147
|
-
name = data.get("name") or data.get("title") or name
|
148
|
-
desc = data.get("description") or data.get("desc") or ""
|
149
|
-
if cat == "roles" and isinstance(data.get("roles"), list):
|
150
|
-
if not desc:
|
151
|
-
desc = f"{len(data['roles'])} 个角色"
|
152
|
-
except Exception:
|
153
|
-
# 忽略解析错误,使用默认显示
|
154
|
-
pass
|
155
|
-
|
156
|
-
# 为 roles 构建详细信息(每个角色的名称与描述)
|
157
|
-
details = ""
|
158
|
-
if cat == "roles":
|
159
|
-
roles = (data or {}).get("roles", [])
|
160
|
-
if isinstance(roles, list):
|
161
|
-
lines = []
|
162
|
-
for role in roles:
|
163
|
-
if isinstance(role, dict):
|
164
|
-
rname = str(role.get("name", "") or "")
|
165
|
-
rdesc = str(role.get("description", "") or "")
|
166
|
-
lines.append(f"{rname} - {rdesc}" if rdesc else rname)
|
167
|
-
details = "\n".join([ln for ln in lines if ln])
|
168
|
-
# 如果没有角色详情,退回到统计信息
|
169
|
-
if not details and isinstance((data or {}).get("roles"), list):
|
170
|
-
details = f"{len(data['roles'])} 个角色"
|
171
|
-
|
172
|
-
options.append(
|
173
|
-
{
|
174
|
-
"category": cat,
|
175
|
-
"cmd": cmd,
|
176
|
-
"file": str(fpath),
|
177
|
-
"name": str(name),
|
178
|
-
"desc": str(desc),
|
179
|
-
"details": str(details),
|
180
|
-
}
|
181
|
-
)
|
182
|
-
|
183
|
-
if options:
|
184
|
-
PrettyOutput.section("可用的内置配置", OutputType.SUCCESS)
|
185
|
-
# 使用 rich Table 呈现
|
186
|
-
table = Table(show_header=True, header_style="bold magenta")
|
187
|
-
table.add_column("No.", style="cyan", no_wrap=True)
|
188
|
-
table.add_column("类型", style="green", no_wrap=True)
|
189
|
-
table.add_column("名称", style="bold")
|
190
|
-
table.add_column("文件", style="dim")
|
191
|
-
table.add_column("描述/详情", style="white")
|
192
|
-
|
193
|
-
for idx, opt in enumerate(options, 1):
|
194
|
-
category = opt.get("category", "")
|
195
|
-
name = opt.get("name", "")
|
196
|
-
file_path = opt.get("file", "")
|
197
|
-
# multi_agent: 优先显示顶层描述
|
198
|
-
# roles: 显示每个角色名称与描述(多行)
|
199
|
-
# 其他:显示 desc
|
200
|
-
if category == "roles" and opt.get("details"):
|
201
|
-
detail = opt["details"]
|
202
|
-
else:
|
203
|
-
detail = opt.get("desc", "")
|
204
|
-
|
205
|
-
table.add_row(str(idx), category, name, file_path, detail)
|
206
|
-
|
207
|
-
Console().print(table)
|
208
|
-
|
209
|
-
choice = get_single_line_input(
|
210
|
-
"选择要启动的配置编号,直接回车使用默认通用代理(jvs): ", default=""
|
211
|
-
)
|
212
|
-
|
213
|
-
if choice.strip():
|
214
|
-
try:
|
215
|
-
index = int(choice.strip())
|
216
|
-
if 1 <= index <= len(options):
|
217
|
-
sel = options[index - 1]
|
218
|
-
args = []
|
219
|
-
|
220
|
-
if sel["category"] == "agent":
|
221
|
-
# jarvis-agent 支持 -f/--config(全局配置)与 -c/--agent-definition
|
222
|
-
args = [sel["cmd"], "-c", sel["file"]]
|
223
|
-
if llm_type:
|
224
|
-
args += ["--llm-type", llm_type]
|
225
|
-
if model_group:
|
226
|
-
args += ["-g", model_group]
|
227
|
-
if config_file:
|
228
|
-
args += ["-f", config_file]
|
229
|
-
if task:
|
230
|
-
args += ["--task", task]
|
231
|
-
|
232
|
-
elif sel["category"] == "multi_agent":
|
233
|
-
# jarvis-multi-agent 需要 -c/--config,用户输入通过 -i/--input 传递
|
234
|
-
args = [sel["cmd"], "-c", sel["file"]]
|
235
|
-
if task:
|
236
|
-
args += ["-i", task]
|
237
|
-
|
238
|
-
elif sel["category"] == "roles":
|
239
|
-
# jarvis-platform-manager role 子命令,支持 -c/-t/-g
|
240
|
-
args = [sel["cmd"], "role", "-c", sel["file"]]
|
241
|
-
if llm_type:
|
242
|
-
args += ["-t", llm_type]
|
243
|
-
if model_group:
|
244
|
-
args += ["-g", model_group]
|
245
|
-
|
246
|
-
if args:
|
247
|
-
PrettyOutput.print(
|
248
|
-
f"正在启动: {' '.join(args)}", OutputType.INFO
|
249
|
-
)
|
250
|
-
os.execvp(args[0], args)
|
251
|
-
except Exception:
|
252
|
-
# 任何异常都不影响默认流程
|
253
|
-
pass
|
254
|
-
except Exception:
|
255
|
-
# 静默忽略内置配置扫描错误,不影响主流程
|
256
|
-
pass
|
436
|
+
handle_builtin_config_selector(llm_type, model_group, tool_group, config_file, task)
|
257
437
|
|
258
438
|
# 初始化环境
|
259
439
|
init_env(
|
@@ -151,12 +151,12 @@ class MethodologyShareManager(ShareManager):
|
|
151
151
|
"没有找到新的方法论文件(所有方法论可能已存在于中心仓库)",
|
152
152
|
OutputType.WARNING,
|
153
153
|
)
|
154
|
-
|
154
|
+
return
|
155
155
|
|
156
156
|
# 选择要分享的资源
|
157
157
|
selected_resources = self.select_resources(local_resources)
|
158
158
|
if not selected_resources:
|
159
|
-
|
159
|
+
return
|
160
160
|
|
161
161
|
# 分享资源
|
162
162
|
copied_list = self.share_resources(selected_resources)
|
@@ -67,10 +67,18 @@ class SessionManager:
|
|
67
67
|
return True
|
68
68
|
return False
|
69
69
|
|
70
|
-
def clear_history(self):
|
70
|
+
def clear_history(self) -> None:
|
71
71
|
"""
|
72
72
|
Clears conversation history but keeps the system prompt by resetting the model state.
|
73
73
|
"""
|
74
74
|
self.prompt = ""
|
75
75
|
self.model.reset()
|
76
76
|
self.conversation_length = 0
|
77
|
+
|
78
|
+
def clear(self) -> None:
|
79
|
+
"""
|
80
|
+
Clears the session state, resetting prompt and conversation length while
|
81
|
+
preserving user_data. This method is an alias of clear_history for backward
|
82
|
+
compatibility with existing tests and callers.
|
83
|
+
"""
|
84
|
+
self.clear_history()
|
@@ -3,8 +3,10 @@
|
|
3
3
|
import os
|
4
4
|
from typing import Dict
|
5
5
|
|
6
|
-
import yaml
|
6
|
+
import yaml # type: ignore
|
7
7
|
from prompt_toolkit import prompt
|
8
|
+
from rich.table import Table
|
9
|
+
from rich.console import Console
|
8
10
|
|
9
11
|
from jarvis.jarvis_agent import (
|
10
12
|
OutputType,
|
@@ -68,16 +70,19 @@ class TaskManager:
|
|
68
70
|
return ""
|
69
71
|
|
70
72
|
task_names = list(tasks.keys())
|
71
|
-
|
73
|
+
# 使用 rich.Table 展示预定义任务
|
74
|
+
table = Table(show_header=True, header_style="bold magenta")
|
75
|
+
table.add_column("No.", style="cyan", no_wrap=True)
|
76
|
+
table.add_column("任务名", style="bold")
|
72
77
|
for i, name in enumerate(task_names, 1):
|
73
|
-
|
74
|
-
|
75
|
-
PrettyOutput.print("
|
78
|
+
table.add_row(str(i), name)
|
79
|
+
Console().print(table)
|
80
|
+
PrettyOutput.print("[0] 跳过预定义任务", OutputType.INFO)
|
76
81
|
|
77
82
|
while True:
|
78
83
|
try:
|
79
84
|
choice_str = prompt(
|
80
|
-
"\n请选择一个任务编号(0
|
85
|
+
"\n请选择一个任务编号(0 或者直接回车跳过预定义任务):"
|
81
86
|
).strip()
|
82
87
|
if not choice_str:
|
83
88
|
return ""
|
@@ -112,12 +112,12 @@ class ToolShareManager(ShareManager):
|
|
112
112
|
"没有找到新的工具文件(所有工具可能已存在于中心仓库)",
|
113
113
|
OutputType.WARNING,
|
114
114
|
)
|
115
|
-
|
115
|
+
return
|
116
116
|
|
117
117
|
# 选择要分享的资源
|
118
118
|
selected_resources = self.select_resources(local_resources)
|
119
119
|
if not selected_resources:
|
120
|
-
|
120
|
+
return
|
121
121
|
|
122
122
|
# 分享资源
|
123
123
|
moved_list = self.share_resources(selected_resources)
|