jarvis-ai-assistant 0.7.0__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 +243 -139
- jarvis/jarvis_agent/agent_manager.py +5 -10
- 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 +265 -15
- jarvis/jarvis_agent/file_methodology_manager.py +3 -4
- jarvis/jarvis_agent/jarvis.py +113 -98
- 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 +6 -12
- 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 +77 -14
- jarvis/jarvis_agent/session_manager.py +2 -3
- jarvis/jarvis_agent/share_manager.py +12 -21
- jarvis/jarvis_agent/shell_input_handler.py +1 -2
- jarvis/jarvis_agent/task_analyzer.py +26 -4
- 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/web_server.py +55 -20
- jarvis/jarvis_c2rust/__init__.py +5 -5
- jarvis/jarvis_c2rust/cli.py +461 -499
- jarvis/jarvis_c2rust/collector.py +45 -53
- jarvis/jarvis_c2rust/constants.py +26 -0
- jarvis/jarvis_c2rust/library_replacer.py +264 -132
- jarvis/jarvis_c2rust/llm_module_agent.py +162 -190
- jarvis/jarvis_c2rust/loaders.py +207 -0
- jarvis/jarvis_c2rust/models.py +28 -0
- jarvis/jarvis_c2rust/optimizer.py +1592 -395
- jarvis/jarvis_c2rust/transpiler.py +1722 -1064
- jarvis/jarvis_c2rust/utils.py +385 -0
- jarvis/jarvis_code_agent/build_validation_config.py +2 -3
- jarvis/jarvis_code_agent/code_agent.py +394 -320
- jarvis/jarvis_code_agent/code_analyzer/__init__.py +3 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/base.py +4 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/cmake.py +17 -2
- jarvis/jarvis_code_agent/code_analyzer/build_validator/fallback.py +3 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/go.py +36 -4
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_gradle.py +9 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/java_maven.py +9 -0
- jarvis/jarvis_code_agent/code_analyzer/build_validator/makefile.py +12 -1
- jarvis/jarvis_code_agent/code_analyzer/build_validator/nodejs.py +22 -5
- jarvis/jarvis_code_agent/code_analyzer/build_validator/python.py +57 -32
- jarvis/jarvis_code_agent/code_analyzer/build_validator/rust.py +62 -6
- jarvis/jarvis_code_agent/code_analyzer/build_validator/validator.py +8 -9
- jarvis/jarvis_code_agent/code_analyzer/context_manager.py +290 -5
- jarvis/jarvis_code_agent/code_analyzer/language_support.py +21 -0
- jarvis/jarvis_code_agent/code_analyzer/languages/__init__.py +21 -3
- jarvis/jarvis_code_agent/code_analyzer/languages/c_cpp_language.py +72 -4
- jarvis/jarvis_code_agent/code_analyzer/languages/go_language.py +35 -3
- 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 +52 -2
- jarvis/jarvis_code_agent/code_analyzer/languages/rust_language.py +73 -1
- jarvis/jarvis_code_agent/code_analyzer/languages/typescript_language.py +280 -0
- jarvis/jarvis_code_agent/code_analyzer/llm_context_recommender.py +306 -152
- jarvis/jarvis_code_agent/code_analyzer/structured_code.py +556 -0
- jarvis/jarvis_code_agent/code_analyzer/symbol_extractor.py +193 -18
- jarvis/jarvis_code_agent/code_analyzer/tree_sitter_extractor.py +18 -8
- jarvis/jarvis_code_agent/lint.py +258 -27
- jarvis/jarvis_code_agent/utils.py +0 -1
- jarvis/jarvis_code_analysis/code_review.py +19 -24
- jarvis/jarvis_data/config_schema.json +53 -26
- jarvis/jarvis_git_squash/main.py +4 -5
- jarvis/jarvis_git_utils/git_commiter.py +44 -49
- jarvis/jarvis_mcp/sse_mcp_client.py +20 -27
- jarvis/jarvis_mcp/stdio_mcp_client.py +11 -12
- 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 +79 -61
- jarvis/jarvis_multi_agent/main.py +3 -7
- jarvis/jarvis_platform/base.py +469 -199
- jarvis/jarvis_platform/human.py +7 -8
- jarvis/jarvis_platform/kimi.py +30 -36
- jarvis/jarvis_platform/openai.py +65 -27
- jarvis/jarvis_platform/registry.py +26 -10
- jarvis/jarvis_platform/tongyi.py +24 -25
- jarvis/jarvis_platform/yuanbao.py +31 -42
- jarvis/jarvis_platform_manager/main.py +66 -77
- jarvis/jarvis_platform_manager/service.py +8 -13
- jarvis/jarvis_rag/cli.py +49 -51
- 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 +220 -3520
- jarvis/jarvis_sec/agents.py +143 -0
- jarvis/jarvis_sec/analysis.py +276 -0
- jarvis/jarvis_sec/cli.py +29 -6
- 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 +83 -4
- jarvis/jarvis_sec/review.py +453 -0
- jarvis/jarvis_sec/utils.py +499 -0
- jarvis/jarvis_sec/verification.py +848 -0
- jarvis/jarvis_sec/workflow.py +7 -0
- jarvis/jarvis_smart_shell/main.py +38 -87
- jarvis/jarvis_stats/cli.py +1 -1
- jarvis/jarvis_stats/stats.py +7 -7
- jarvis/jarvis_stats/storage.py +15 -21
- jarvis/jarvis_tools/clear_memory.py +3 -20
- jarvis/jarvis_tools/cli/main.py +20 -23
- jarvis/jarvis_tools/edit_file.py +1066 -0
- jarvis/jarvis_tools/execute_script.py +42 -21
- jarvis/jarvis_tools/file_analyzer.py +6 -9
- jarvis/jarvis_tools/generate_new_tool.py +11 -20
- jarvis/jarvis_tools/lsp_client.py +1552 -0
- jarvis/jarvis_tools/methodology.py +2 -3
- jarvis/jarvis_tools/read_code.py +1525 -87
- jarvis/jarvis_tools/read_symbols.py +2 -3
- jarvis/jarvis_tools/read_webpage.py +7 -10
- jarvis/jarvis_tools/registry.py +370 -181
- jarvis/jarvis_tools/retrieve_memory.py +20 -19
- jarvis/jarvis_tools/rewrite_file.py +105 -0
- jarvis/jarvis_tools/save_memory.py +3 -15
- jarvis/jarvis_tools/search_web.py +3 -7
- jarvis/jarvis_tools/sub_agent.py +17 -6
- jarvis/jarvis_tools/sub_code_agent.py +14 -16
- jarvis/jarvis_tools/virtual_tty.py +54 -32
- jarvis/jarvis_utils/clipboard.py +7 -10
- jarvis/jarvis_utils/config.py +98 -63
- jarvis/jarvis_utils/embedding.py +5 -5
- jarvis/jarvis_utils/fzf.py +8 -8
- jarvis/jarvis_utils/git_utils.py +81 -67
- jarvis/jarvis_utils/input.py +24 -49
- jarvis/jarvis_utils/jsonnet_compat.py +465 -0
- jarvis/jarvis_utils/methodology.py +33 -35
- jarvis/jarvis_utils/utils.py +245 -202
- {jarvis_ai_assistant-0.7.0.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/METADATA +205 -70
- jarvis_ai_assistant-0.7.6.dist-info/RECORD +218 -0
- jarvis/jarvis_agent/edit_file_handler.py +0 -584
- jarvis/jarvis_agent/rewrite_file_handler.py +0 -141
- jarvis/jarvis_agent/task_planner.py +0 -496
- jarvis/jarvis_platform/ai8.py +0 -332
- jarvis/jarvis_tools/ask_user.py +0 -54
- jarvis_ai_assistant-0.7.0.dist-info/RECORD +0 -192
- {jarvis_ai_assistant-0.7.0.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/WHEEL +0 -0
- {jarvis_ai_assistant-0.7.0.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/entry_points.txt +0 -0
- {jarvis_ai_assistant-0.7.0.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/licenses/LICENSE +0 -0
- {jarvis_ai_assistant-0.7.0.dist-info → jarvis_ai_assistant-0.7.6.dist-info}/top_level.txt +0 -0
|
@@ -18,7 +18,6 @@ from jarvis.jarvis_utils.config import (
|
|
|
18
18
|
get_normal_platform_name,
|
|
19
19
|
get_normal_model_name,
|
|
20
20
|
)
|
|
21
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
22
21
|
from jarvis.jarvis_platform.registry import PlatformRegistry
|
|
23
22
|
from jarvis.jarvis_utils.utils import init_env
|
|
24
23
|
|
|
@@ -75,7 +74,8 @@ class MemoryOrganizer:
|
|
|
75
74
|
error_lines.append(f"读取记忆文件 {memory_file} 失败: {str(e)}")
|
|
76
75
|
|
|
77
76
|
if error_lines:
|
|
78
|
-
|
|
77
|
+
joined_errors = '\n'.join(error_lines)
|
|
78
|
+
print(f"⚠️ {joined_errors}")
|
|
79
79
|
|
|
80
80
|
return memories
|
|
81
81
|
|
|
@@ -174,16 +174,13 @@ class MemoryOrganizer:
|
|
|
174
174
|
4. 确保合并后的记忆保留了所有重要信息
|
|
175
175
|
5. **重要**:越近期的记忆权重越高,优先保留最新记忆中的信息
|
|
176
176
|
|
|
177
|
-
请将合并结果放在 <merged_memory> 标签内,使用
|
|
177
|
+
请将合并结果放在 <merged_memory> 标签内,使用JSON格式:
|
|
178
178
|
|
|
179
179
|
<merged_memory>
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
- 标签1
|
|
185
|
-
- 标签2
|
|
186
|
-
- 标签3
|
|
180
|
+
{{
|
|
181
|
+
"content": "合并后的记忆内容,可以是多行文本",
|
|
182
|
+
"tags": ["标签1", "标签2", "标签3"]
|
|
183
|
+
}}
|
|
187
184
|
</merged_memory>
|
|
188
185
|
|
|
189
186
|
注意:
|
|
@@ -192,6 +189,7 @@ tags:
|
|
|
192
189
|
- 保持专业和客观的语气
|
|
193
190
|
- 最近的记忆信息优先级更高
|
|
194
191
|
- 只输出 <merged_memory> 标签内的内容,不要有其他说明
|
|
192
|
+
- JSON格式必须有效,字符串中的换行符使用 \\n 表示
|
|
195
193
|
"""
|
|
196
194
|
|
|
197
195
|
try:
|
|
@@ -203,32 +201,32 @@ tags:
|
|
|
203
201
|
|
|
204
202
|
# 解析响应
|
|
205
203
|
import re
|
|
206
|
-
import
|
|
204
|
+
from jarvis.jarvis_utils.jsonnet_compat import loads as json5_loads
|
|
207
205
|
|
|
208
206
|
# 提取 <merged_memory> 标签内的内容
|
|
209
|
-
|
|
207
|
+
json_match = re.search(
|
|
210
208
|
r"<merged_memory>(.*?)</merged_memory>",
|
|
211
209
|
response,
|
|
212
210
|
re.DOTALL | re.IGNORECASE,
|
|
213
211
|
)
|
|
214
212
|
|
|
215
|
-
if
|
|
216
|
-
|
|
213
|
+
if json_match:
|
|
214
|
+
json_content = json_match.group(1).strip()
|
|
217
215
|
try:
|
|
218
|
-
result =
|
|
216
|
+
result = json5_loads(json_content)
|
|
219
217
|
return {
|
|
220
218
|
"content": result.get("content", ""),
|
|
221
219
|
"tags": result.get("tags", []),
|
|
222
220
|
"type": memories[0].get("type", "unknown"),
|
|
223
221
|
"merged_from": [m.get("id", "") for m in memories],
|
|
224
222
|
}
|
|
225
|
-
except
|
|
226
|
-
raise ValueError(f"无法解析
|
|
223
|
+
except (ValueError, Exception) as e:
|
|
224
|
+
raise ValueError(f"无法解析JSON内容: {str(e)}")
|
|
227
225
|
else:
|
|
228
226
|
raise ValueError("无法从模型响应中提取 <merged_memory> 标签内容")
|
|
229
227
|
|
|
230
228
|
except Exception as e:
|
|
231
|
-
|
|
229
|
+
print(f"⚠️ 调用大模型合并记忆失败: {str(e)}")
|
|
232
230
|
# 返回 None 表示合并失败,跳过这组记忆
|
|
233
231
|
return None
|
|
234
232
|
|
|
@@ -249,18 +247,15 @@ tags:
|
|
|
249
247
|
返回:
|
|
250
248
|
整理结果统计
|
|
251
249
|
"""
|
|
252
|
-
|
|
253
|
-
f"开始整理{memory_type}类型的记忆,最小重叠标签数: {min_overlap}",
|
|
254
|
-
OutputType.INFO,
|
|
255
|
-
)
|
|
250
|
+
print(f"ℹ️ 开始整理{memory_type}类型的记忆,最小重叠标签数: {min_overlap}")
|
|
256
251
|
|
|
257
252
|
# 加载记忆
|
|
258
253
|
memories = self._load_memories(memory_type)
|
|
259
254
|
if not memories:
|
|
260
|
-
|
|
255
|
+
print("ℹ️ 没有找到需要整理的记忆")
|
|
261
256
|
return {"processed": 0, "merged": 0}
|
|
262
257
|
|
|
263
|
-
|
|
258
|
+
print(f"ℹ️ 加载了 {len(memories)} 个记忆")
|
|
264
259
|
|
|
265
260
|
# 统计信息
|
|
266
261
|
stats = {
|
|
@@ -293,10 +288,7 @@ tags:
|
|
|
293
288
|
|
|
294
289
|
if overlap_count in overlap_groups:
|
|
295
290
|
groups = overlap_groups[overlap_count]
|
|
296
|
-
|
|
297
|
-
f"\n发现 {len(groups)} 个具有 {overlap_count} 个重叠标签的记忆组",
|
|
298
|
-
OutputType.INFO,
|
|
299
|
-
)
|
|
291
|
+
print(f"\nℹ️ 发现 {len(groups)} 个具有 {overlap_count} 个重叠标签的记忆组")
|
|
300
292
|
|
|
301
293
|
for group in groups:
|
|
302
294
|
# 将活跃索引转换回原始索引
|
|
@@ -314,7 +306,8 @@ tags:
|
|
|
314
306
|
f" - ID: {mem.get('id', '未知')}, "
|
|
315
307
|
f"标签: {', '.join(mem.get('tags', []))[:50]}..."
|
|
316
308
|
)
|
|
317
|
-
|
|
309
|
+
joined_lines = '\n'.join(lines)
|
|
310
|
+
print(f"ℹ️ {joined_lines}")
|
|
318
311
|
|
|
319
312
|
if not dry_run:
|
|
320
313
|
# 合并记忆
|
|
@@ -322,9 +315,7 @@ tags:
|
|
|
322
315
|
|
|
323
316
|
# 如果合并失败,跳过这组
|
|
324
317
|
if merged_memory is None:
|
|
325
|
-
|
|
326
|
-
" 跳过这组记忆的合并", OutputType.WARNING
|
|
327
|
-
)
|
|
318
|
+
print(" ⚠️ 跳过这组记忆的合并")
|
|
328
319
|
continue
|
|
329
320
|
|
|
330
321
|
# 保存新记忆
|
|
@@ -341,16 +332,14 @@ tags:
|
|
|
341
332
|
# 标记这些记忆已被删除
|
|
342
333
|
deleted_indices.update(original_indices)
|
|
343
334
|
else:
|
|
344
|
-
|
|
335
|
+
print(" ℹ️ [模拟运行] 跳过实际合并")
|
|
345
336
|
|
|
346
337
|
# 显示统计信息
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
f"创建的新记忆数: {stats['created_memories']}", OutputType.INFO
|
|
353
|
-
)
|
|
338
|
+
print("\n✅ 整理完成!")
|
|
339
|
+
print(f"ℹ️ 总记忆数: {stats['total_memories']}")
|
|
340
|
+
print(f"ℹ️ 处理的组数: {stats['processed_groups']}")
|
|
341
|
+
print(f"ℹ️ 合并的记忆数: {stats['merged_memories']}")
|
|
342
|
+
print(f"ℹ️ 创建的新记忆数: {stats['created_memories']}")
|
|
354
343
|
|
|
355
344
|
return stats
|
|
356
345
|
|
|
@@ -382,10 +371,7 @@ tags:
|
|
|
382
371
|
with open(new_file, "w", encoding="utf-8") as f:
|
|
383
372
|
json.dump(memory, f, ensure_ascii=False, indent=2)
|
|
384
373
|
|
|
385
|
-
|
|
386
|
-
f"创建新记忆: {memory['id']} (标签: {', '.join(memory['tags'][:3])}...)",
|
|
387
|
-
OutputType.SUCCESS,
|
|
388
|
-
)
|
|
374
|
+
print(f"✅ 创建新记忆: {memory['id']} (标签: {', '.join(memory['tags'][:3])}...)")
|
|
389
375
|
|
|
390
376
|
# 删除原始记忆文件(先汇总日志,最后统一打印)
|
|
391
377
|
info_lines: List[str] = []
|
|
@@ -406,9 +392,11 @@ tags:
|
|
|
406
392
|
f"删除记忆文件失败 {orig_memory.get('file_path', '')}: {str(e)}"
|
|
407
393
|
)
|
|
408
394
|
if info_lines:
|
|
409
|
-
|
|
395
|
+
joined_info = '\n'.join(info_lines)
|
|
396
|
+
print(f"ℹ️ {joined_info}")
|
|
410
397
|
if warn_lines:
|
|
411
|
-
|
|
398
|
+
joined_warn = '\n'.join(warn_lines)
|
|
399
|
+
print(f"⚠️ {joined_warn}")
|
|
412
400
|
|
|
413
401
|
def export_memories(
|
|
414
402
|
self,
|
|
@@ -453,16 +441,15 @@ tags:
|
|
|
453
441
|
|
|
454
442
|
# 统一展示导出进度日志
|
|
455
443
|
if progress_lines:
|
|
456
|
-
|
|
444
|
+
joined_progress = '\n'.join(progress_lines)
|
|
445
|
+
print(f"ℹ️ {joined_progress}")
|
|
457
446
|
|
|
458
447
|
# 保存到文件
|
|
459
448
|
output_file.parent.mkdir(parents=True, exist_ok=True)
|
|
460
449
|
with open(output_file, "w", encoding="utf-8") as f:
|
|
461
450
|
json.dump(all_memories, f, ensure_ascii=False, indent=2)
|
|
462
451
|
|
|
463
|
-
|
|
464
|
-
f"成功导出 {len(all_memories)} 个记忆到 {output_file}", OutputType.SUCCESS
|
|
465
|
-
)
|
|
452
|
+
print(f"✅ 成功导出 {len(all_memories)} 个记忆到 {output_file}")
|
|
466
453
|
|
|
467
454
|
return len(all_memories)
|
|
468
455
|
|
|
@@ -491,7 +478,7 @@ tags:
|
|
|
491
478
|
if not isinstance(memories, list):
|
|
492
479
|
raise ValueError("导入文件格式错误,应为记忆列表")
|
|
493
480
|
|
|
494
|
-
|
|
481
|
+
print(f"ℹ️ 准备导入 {len(memories)} 个记忆")
|
|
495
482
|
|
|
496
483
|
# 统计导入结果
|
|
497
484
|
import_stats: Dict[str, int] = defaultdict(int)
|
|
@@ -509,9 +496,7 @@ tags:
|
|
|
509
496
|
elif memory_type == "global_long_term":
|
|
510
497
|
memory_dir = self.global_memory_dir / memory_type
|
|
511
498
|
else:
|
|
512
|
-
|
|
513
|
-
f"跳过不支持的记忆类型: {memory_type}", OutputType.WARNING
|
|
514
|
-
)
|
|
499
|
+
print(f"⚠️ 跳过不支持的记忆类型: {memory_type}")
|
|
515
500
|
skipped_count += 1
|
|
516
501
|
continue
|
|
517
502
|
|
|
@@ -528,7 +513,7 @@ tags:
|
|
|
528
513
|
memory_file = memory_dir / f"{memory_id}.json"
|
|
529
514
|
|
|
530
515
|
if memory_file.exists() and not overwrite:
|
|
531
|
-
|
|
516
|
+
print(f"ℹ️ 跳过已存在的记忆: {memory_id}")
|
|
532
517
|
skipped_count += 1
|
|
533
518
|
continue
|
|
534
519
|
|
|
@@ -550,13 +535,14 @@ tags:
|
|
|
550
535
|
import_stats[memory_type] += 1
|
|
551
536
|
|
|
552
537
|
# 显示导入结果
|
|
553
|
-
|
|
538
|
+
print("\n✅ 导入完成!")
|
|
554
539
|
if import_stats:
|
|
555
540
|
lines = [f"{memory_type}: 导入了 {count} 个记忆" for memory_type, count in import_stats.items()]
|
|
556
|
-
|
|
541
|
+
joined_lines = '\n'.join(lines)
|
|
542
|
+
print(f"ℹ️ {joined_lines}")
|
|
557
543
|
|
|
558
544
|
if skipped_count > 0:
|
|
559
|
-
|
|
545
|
+
print(f"⚠️ 跳过了 {skipped_count} 个记忆")
|
|
560
546
|
|
|
561
547
|
return dict(import_stats)
|
|
562
548
|
|
|
@@ -602,14 +588,11 @@ def organize(
|
|
|
602
588
|
"""
|
|
603
589
|
# 验证参数
|
|
604
590
|
if memory_type not in ["project_long_term", "global_long_term"]:
|
|
605
|
-
|
|
606
|
-
f"错误:不支持的记忆类型 '{memory_type}',请选择 'project_long_term' 或 'global_long_term'",
|
|
607
|
-
OutputType.ERROR,
|
|
608
|
-
)
|
|
591
|
+
print(f"❌ 错误:不支持的记忆类型 '{memory_type}',请选择 'project_long_term' 或 'global_long_term'")
|
|
609
592
|
raise typer.Exit(1)
|
|
610
593
|
|
|
611
594
|
if min_overlap < 2:
|
|
612
|
-
|
|
595
|
+
print("❌ 错误:最小重叠数必须大于等于2")
|
|
613
596
|
raise typer.Exit(1)
|
|
614
597
|
|
|
615
598
|
# 创建整理器并执行
|
|
@@ -629,7 +612,7 @@ def organize(
|
|
|
629
612
|
# typer.Exit 是正常的退出方式,直接传播
|
|
630
613
|
raise
|
|
631
614
|
except Exception as e:
|
|
632
|
-
|
|
615
|
+
print(f"❌ 记忆整理失败: {str(e)}")
|
|
633
616
|
raise typer.Exit(1)
|
|
634
617
|
|
|
635
618
|
|
|
@@ -672,10 +655,8 @@ def export(
|
|
|
672
655
|
valid_types = ["project_long_term", "global_long_term"]
|
|
673
656
|
invalid_types = [mt for mt in memory_types if mt not in valid_types]
|
|
674
657
|
if invalid_types:
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
OutputType.ERROR,
|
|
678
|
-
)
|
|
658
|
+
invalid_str = ", ".join(f"'{mt}'" for mt in invalid_types)
|
|
659
|
+
print(f"❌ 错误:不支持的记忆类型: {invalid_str}")
|
|
679
660
|
raise typer.Exit(1)
|
|
680
661
|
|
|
681
662
|
count = organizer.export_memories(
|
|
@@ -687,11 +668,11 @@ def export(
|
|
|
687
668
|
if count > 0:
|
|
688
669
|
raise typer.Exit(0)
|
|
689
670
|
else:
|
|
690
|
-
|
|
671
|
+
print("⚠️ 没有找到要导出的记忆")
|
|
691
672
|
raise typer.Exit(0)
|
|
692
673
|
|
|
693
674
|
except Exception as e:
|
|
694
|
-
|
|
675
|
+
print(f"❌ 导出失败: {str(e)}")
|
|
695
676
|
raise typer.Exit(1)
|
|
696
677
|
|
|
697
678
|
|
|
@@ -731,21 +712,21 @@ def import_memories(
|
|
|
731
712
|
if total_imported > 0:
|
|
732
713
|
raise typer.Exit(0)
|
|
733
714
|
else:
|
|
734
|
-
|
|
715
|
+
print("⚠️ 没有导入任何记忆")
|
|
735
716
|
raise typer.Exit(0)
|
|
736
717
|
|
|
737
718
|
except FileNotFoundError as e:
|
|
738
|
-
|
|
719
|
+
print(f"❌ {str(e)}")
|
|
739
720
|
raise typer.Exit(1)
|
|
740
721
|
except Exception as e:
|
|
741
|
-
|
|
722
|
+
print(f"❌ 导入失败: {str(e)}")
|
|
742
723
|
raise typer.Exit(1)
|
|
743
724
|
|
|
744
725
|
|
|
745
726
|
def main():
|
|
746
727
|
"""Application entry point"""
|
|
747
728
|
# 统一初始化环境
|
|
748
|
-
init_env(
|
|
729
|
+
init_env()
|
|
749
730
|
app()
|
|
750
731
|
|
|
751
732
|
|
|
@@ -20,7 +20,6 @@ from jarvis.jarvis_utils.methodology import (
|
|
|
20
20
|
_get_methodology_directory,
|
|
21
21
|
_load_all_methodologies,
|
|
22
22
|
)
|
|
23
|
-
from jarvis.jarvis_utils.output import OutputType, PrettyOutput
|
|
24
23
|
|
|
25
24
|
app = typer.Typer(help="方法论管理工具")
|
|
26
25
|
|
|
@@ -55,12 +54,9 @@ def import_methodology(
|
|
|
55
54
|
indent=2,
|
|
56
55
|
)
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
)
|
|
62
|
-
except (json.JSONDecodeError, OSError) as e:
|
|
63
|
-
PrettyOutput.print(f"导入失败: {str(e)}", OutputType.ERROR)
|
|
57
|
+
print(f"✅ 成功导入 {len(import_data)} 个方法论(总计 {len(merged_data)} 个)")
|
|
58
|
+
except (ValueError, OSError) as e:
|
|
59
|
+
print(f"❌ 导入失败: {str(e)}")
|
|
64
60
|
raise typer.Exit(code=1)
|
|
65
61
|
|
|
66
62
|
|
|
@@ -73,12 +69,9 @@ def export_methodology(output_file: str = typer.Argument(..., help="导出文件
|
|
|
73
69
|
with open(output_file, "w", encoding="utf-8") as f:
|
|
74
70
|
json.dump(methodologies, f, ensure_ascii=False, indent=2)
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
f"成功导出 {len(methodologies)} 个方法论到 {output_file}",
|
|
78
|
-
OutputType.SUCCESS,
|
|
79
|
-
)
|
|
72
|
+
print(f"✅ 成功导出 {len(methodologies)} 个方法论到 {output_file}")
|
|
80
73
|
except (OSError, TypeError) as e:
|
|
81
|
-
|
|
74
|
+
print(f"❌ 导出失败: {str(e)}")
|
|
82
75
|
raise typer.Exit(code=1)
|
|
83
76
|
|
|
84
77
|
|
|
@@ -89,16 +82,17 @@ def list_methodologies():
|
|
|
89
82
|
methodologies = _load_all_methodologies()
|
|
90
83
|
|
|
91
84
|
if not methodologies:
|
|
92
|
-
|
|
85
|
+
print("ℹ️ 没有找到方法论")
|
|
93
86
|
return
|
|
94
87
|
|
|
95
88
|
# 先拼接再统一打印,避免在循环中逐条输出造成信息稀疏
|
|
96
89
|
lines = ["可用方法论:"]
|
|
97
90
|
for i, (problem_type, _) in enumerate(methodologies.items(), 1):
|
|
98
91
|
lines.append(f"{i}. {problem_type}")
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
joined_lines = '\n'.join(lines)
|
|
93
|
+
print(f"ℹ️ {joined_lines}")
|
|
94
|
+
except (OSError, ValueError) as e:
|
|
95
|
+
print(f"❌ 列出方法论失败: {str(e)}")
|
|
102
96
|
raise typer.Exit(code=1)
|
|
103
97
|
|
|
104
98
|
|
|
@@ -144,22 +138,20 @@ def extract_methodology(
|
|
|
144
138
|
"""
|
|
145
139
|
|
|
146
140
|
# 调用大模型平台提取方法论
|
|
147
|
-
|
|
141
|
+
print("ℹ️ 正在提取方法论...")
|
|
148
142
|
try:
|
|
149
143
|
response = platform.chat_until_success(prompt)
|
|
150
144
|
except Exception as e:
|
|
151
|
-
|
|
152
|
-
|
|
145
|
+
print("❌ 提取失败")
|
|
146
|
+
print(f"❌ 提取方法论失败: {str(e)}")
|
|
153
147
|
raise typer.Exit(code=1)
|
|
154
148
|
|
|
155
149
|
# 提取YAML部分
|
|
156
150
|
methodologies_start = response.find("<methodologies>") + len("<methodologies>")
|
|
157
151
|
methodologies_end = response.find("</methodologies>")
|
|
158
152
|
if methodologies_start == -1 or methodologies_end == -1:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
"大模型未返回有效的<methodologies>格式", OutputType.ERROR
|
|
162
|
-
)
|
|
153
|
+
print("❌ 响应格式无效")
|
|
154
|
+
print("❌ 大模型未返回有效的<methodologies>格式")
|
|
163
155
|
raise typer.Exit(code=1)
|
|
164
156
|
|
|
165
157
|
yaml_content = response[methodologies_start:methodologies_end].strip()
|
|
@@ -170,14 +162,14 @@ def extract_methodology(
|
|
|
170
162
|
item["problem_type"]: item["content"] for item in data
|
|
171
163
|
}
|
|
172
164
|
except (yaml.YAMLError, KeyError, TypeError) as e:
|
|
173
|
-
|
|
174
|
-
|
|
165
|
+
print("❌ YAML解析失败")
|
|
166
|
+
print(f"❌ YAML解析错误: {str(e)}")
|
|
175
167
|
raise typer.Exit(code=1)
|
|
176
168
|
|
|
177
169
|
if not extracted_methodologies:
|
|
178
|
-
|
|
170
|
+
print("⚠️ 未提取到有效方法论")
|
|
179
171
|
return
|
|
180
|
-
|
|
172
|
+
print("✅ 提取到有效方法论")
|
|
181
173
|
|
|
182
174
|
# 加载现有方法论
|
|
183
175
|
existing_methodologies = _load_all_methodologies()
|
|
@@ -199,12 +191,9 @@ def extract_methodology(
|
|
|
199
191
|
indent=2,
|
|
200
192
|
)
|
|
201
193
|
|
|
202
|
-
|
|
203
|
-
f"成功从文件提取 {len(extracted_methodologies)} 个方法论(总计 {len(merged_data)} 个)",
|
|
204
|
-
OutputType.SUCCESS,
|
|
205
|
-
)
|
|
194
|
+
print(f"✅ 成功从文件提取 {len(extracted_methodologies)} 个方法论(总计 {len(merged_data)} 个)")
|
|
206
195
|
except Exception as e:
|
|
207
|
-
|
|
196
|
+
print(f"❌ 提取失败: {str(e)}")
|
|
208
197
|
raise typer.Exit(code=1)
|
|
209
198
|
|
|
210
199
|
|
|
@@ -247,22 +236,20 @@ def extract_methodology_from_url(
|
|
|
247
236
|
6. 内容字段使用|保留多行格式
|
|
248
237
|
"""
|
|
249
238
|
# 调用大模型平台提取方法论
|
|
250
|
-
|
|
239
|
+
print("ℹ️ 正在从URL提取方法论...")
|
|
251
240
|
try:
|
|
252
241
|
response = platform.chat_until_success(prompt)
|
|
253
242
|
except Exception as e:
|
|
254
|
-
|
|
255
|
-
|
|
243
|
+
print("❌ 提取失败")
|
|
244
|
+
print(f"❌ 提取方法论失败: {str(e)}")
|
|
256
245
|
raise typer.Exit(code=1)
|
|
257
246
|
|
|
258
247
|
# 提取YAML部分
|
|
259
248
|
methodologies_start = response.find("<methodologies>") + len("<methodologies>")
|
|
260
249
|
methodologies_end = response.find("</methodologies>")
|
|
261
250
|
if methodologies_start == -1 or methodologies_end == -1:
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
"大模型未返回有效的<methodologies>格式", OutputType.ERROR
|
|
265
|
-
)
|
|
251
|
+
print("❌ 响应格式无效")
|
|
252
|
+
print("❌ 大模型未返回有效的<methodologies>格式")
|
|
266
253
|
raise typer.Exit(code=1)
|
|
267
254
|
|
|
268
255
|
yaml_content = response[methodologies_start:methodologies_end].strip()
|
|
@@ -273,14 +260,14 @@ def extract_methodology_from_url(
|
|
|
273
260
|
item["problem_type"]: item["content"] for item in data
|
|
274
261
|
}
|
|
275
262
|
except (yaml.YAMLError, KeyError, TypeError) as e:
|
|
276
|
-
|
|
277
|
-
|
|
263
|
+
print("❌ YAML解析失败")
|
|
264
|
+
print(f"❌ YAML解析错误: {str(e)}")
|
|
278
265
|
raise typer.Exit(code=1)
|
|
279
266
|
|
|
280
267
|
if not extracted_methodologies:
|
|
281
|
-
|
|
268
|
+
print("⚠️ 未提取到有效方法论")
|
|
282
269
|
return
|
|
283
|
-
|
|
270
|
+
print("✅ 提取到有效方法论")
|
|
284
271
|
|
|
285
272
|
# 加载现有方法论
|
|
286
273
|
existing_methodologies = _load_all_methodologies()
|
|
@@ -302,12 +289,9 @@ def extract_methodology_from_url(
|
|
|
302
289
|
indent=2,
|
|
303
290
|
)
|
|
304
291
|
|
|
305
|
-
|
|
306
|
-
f"成功从URL提取 {len(extracted_methodologies)} 个方法论(总计 {len(merged_data)} 个)",
|
|
307
|
-
OutputType.SUCCESS,
|
|
308
|
-
)
|
|
292
|
+
print(f"✅ 成功从URL提取 {len(extracted_methodologies)} 个方法论(总计 {len(merged_data)} 个)")
|
|
309
293
|
except Exception as e:
|
|
310
|
-
|
|
294
|
+
print(f"❌ 从URL提取失败: {str(e)}")
|
|
311
295
|
raise typer.Exit(code=1)
|
|
312
296
|
|
|
313
297
|
|