jarvis-ai-assistant 0.1.116__tar.gz → 0.1.118__tar.gz

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.

Potentially problematic release.


This version of jarvis-ai-assistant might be problematic. Click here for more details.

Files changed (73) hide show
  1. {jarvis_ai_assistant-0.1.116/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.118}/PKG-INFO +1 -1
  2. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/pyproject.toml +2 -2
  3. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/setup.py +2 -2
  4. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/__init__.py +1 -1
  5. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_agent/__init__.py +90 -47
  6. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_code_agent/code_agent.py +102 -89
  7. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_code_agent/patch.py +55 -0
  8. jarvis_ai_assistant-0.1.118/src/jarvis/jarvis_code_agent/relevant_files.py +119 -0
  9. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_codebase/main.py +49 -23
  10. jarvis_ai_assistant-0.1.118/src/jarvis/jarvis_dev/main.py +836 -0
  11. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_multi_agent/__init__.py +61 -38
  12. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_rag/main.py +55 -18
  13. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_smart_shell/main.py +38 -13
  14. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/registry.py +99 -27
  15. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118/src/jarvis_ai_assistant.egg-info}/PKG-INFO +1 -1
  16. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +1 -0
  17. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis_ai_assistant.egg-info/entry_points.txt +1 -0
  18. jarvis_ai_assistant-0.1.116/src/jarvis/jarvis_code_agent/relevant_files.py +0 -79
  19. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/LICENSE +0 -0
  20. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/MANIFEST.in +0 -0
  21. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/README.md +0 -0
  22. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/setup.cfg +0 -0
  23. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_agent/output_handler.py +0 -0
  24. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_code_agent/__init__.py +0 -0
  25. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_code_agent/file_select.py +0 -0
  26. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_codebase/__init__.py +0 -0
  27. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_lsp/base.py +0 -0
  28. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_lsp/cpp.py +0 -0
  29. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_lsp/go.py +0 -0
  30. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_lsp/python.py +0 -0
  31. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_lsp/registry.py +0 -0
  32. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_lsp/rust.py +0 -0
  33. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform/__init__.py +0 -0
  34. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform/ai8.py +0 -0
  35. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform/base.py +0 -0
  36. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform/kimi.py +0 -0
  37. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform/ollama.py +0 -0
  38. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform/openai.py +0 -0
  39. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform/oyi.py +0 -0
  40. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform/registry.py +0 -0
  41. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform_manager/__init__.py +0 -0
  42. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform_manager/main.py +0 -0
  43. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_platform_manager/openai_test.py +0 -0
  44. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_rag/__init__.py +0 -0
  45. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_smart_shell/__init__.py +0 -0
  46. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/__init__.py +0 -0
  47. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/ask_codebase.py +0 -0
  48. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/ask_user.py +0 -0
  49. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/base.py +0 -0
  50. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/chdir.py +0 -0
  51. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/code_review.py +0 -0
  52. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/create_code_agent.py +0 -0
  53. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/create_sub_agent.py +0 -0
  54. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/execute_shell.py +0 -0
  55. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/file_operation.py +0 -0
  56. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/git_commiter.py +0 -0
  57. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/lsp_find_definition.py +0 -0
  58. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/lsp_find_references.py +0 -0
  59. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/lsp_get_diagnostics.py +0 -0
  60. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/lsp_get_document_symbols.py +0 -0
  61. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/lsp_prepare_rename.py +0 -0
  62. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/lsp_validate_edit.py +0 -0
  63. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/methodology.py +0 -0
  64. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/rag.py +0 -0
  65. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/read_code.py +0 -0
  66. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/read_webpage.py +0 -0
  67. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/search.py +0 -0
  68. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/select_code_files.py +0 -0
  69. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_tools/tool_generator.py +0 -0
  70. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis/jarvis_utils/__init__.py +0 -0
  71. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
  72. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis_ai_assistant.egg-info/requires.txt +0 -0
  73. {jarvis_ai_assistant-0.1.116 → jarvis_ai_assistant-0.1.118}/src/jarvis_ai_assistant.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.116
3
+ Version: 0.1.118
4
4
  Summary: Jarvis: An AI assistant that uses tools to interact with the system
5
5
  Home-page: https://github.com/skyfireitdiy/Jarvis
6
6
  Author: skyfire
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "jarvis-ai-assistant"
7
- version = "0.1.116"
7
+ version = "0.1.118"
8
8
  description = "Jarvis: An AI assistant that uses tools to interact with the system"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Your Name", email = "your.email@example.com" }]
@@ -62,4 +62,4 @@ jss = "jarvis.jarvis_smart_shell.main:main"
62
62
  jarvis-platform-manager = "jarvis.jarvis_platform_manager.main:main"
63
63
  jarvis-git-commit = "jarvis.jarvis_tools.git_commiter:main"
64
64
  jarvis-code-review = "jarvis.jarvis_tools.code_review:main"
65
- # jarvis-dev = "jarvis.jarvis_dev.main:main"
65
+ jarvis-dev = "jarvis.jarvis_dev.main:main"
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name="jarvis-ai-assistant",
5
- version="0.1.116",
5
+ version="0.1.118",
6
6
  author="skyfire",
7
7
  author_email="skyfireitdiy@hotmail.com",
8
8
  description="An AI assistant that uses various tools to interact with the system",
@@ -47,7 +47,7 @@ setup(
47
47
  "jarvis-platform-manager=jarvis.jarvis_platform_manager.main:main",
48
48
  "jarvis-git-commit=jarvis.jarvis_tools.git_commiter:main",
49
49
  "jarvis-code-review=jarvis.jarvis_tools.code_review:main",
50
- # "jarvis-dev=jarvis.jarvis_dev.main:main",
50
+ "jarvis-dev=jarvis.jarvis_dev.main:main",
51
51
  ],
52
52
  },
53
53
  python_requires=">=3.8",
@@ -1,3 +1,3 @@
1
1
  """Jarvis AI Assistant"""
2
2
 
3
- __version__ = "0.1.116"
3
+ __version__ = "0.1.118"
@@ -43,27 +43,6 @@ class Agent:
43
43
  need_summary: Optional[bool] = None,
44
44
  max_context_length: Optional[int] = None,
45
45
  execute_tool_confirm: Optional[bool] = None):
46
- """Initialize an Agent instance.
47
-
48
- Args:
49
- system_prompt: The system prompt defining agent behavior
50
- name: Agent name, defaults to "Jarvis"
51
- description: Agent description, defaults to ""
52
- is_sub_agent: Whether this is a sub-agent
53
- tool_registry: Registry of available tools
54
- platform: AI platform to use
55
- summary_prompt: Template for generating summaries
56
- auto_complete: Whether to enable auto-completion
57
- output_handler_before_tool: Handlers to process output before tool execution
58
- output_handler_after_tool: Handlers to process output after tool execution
59
- use_methodology: Whether to use methodology
60
- record_methodology: Whether to record methodology
61
- need_summary: Whether to generate summaries
62
- max_context_length: Maximum context length
63
- support_send_msg: Whether to support sending messages
64
- execute_tool_confirm: Whether to confirm tool execution
65
- """
66
-
67
46
  self.name = make_agent_name(name)
68
47
  self.description = description
69
48
  # 初始化平台和模型
@@ -115,11 +94,35 @@ Please describe in concise bullet points, highlighting important information.
115
94
 
116
95
  PrettyOutput.print(welcome_message, OutputType.SYSTEM)
117
96
 
118
- tool_prompt = f"""You can do the following actions: {','.join([handler.name() for handler in self.output_handler])}"""
97
+ tool_prompt = """
98
+ # 🧰 Available Tools
99
+ The following tools are at your disposal:
100
+ """
101
+
102
+ # 添加工具列表概览
103
+ tool_prompt += "\n## Tool List\n"
104
+ tool_prompt += ", ".join([handler.name() for handler in self.output_handler])
119
105
 
106
+ # 添加每个工具的详细说明
107
+ tool_prompt += "\n\n# 📝 Tool Details\n"
120
108
  for handler in self.output_handler:
121
- tool_prompt += f"\n## {handler.name()}:\n"
122
- tool_prompt += handler.prompt()
109
+ tool_prompt += f"\n## {handler.name()}\n"
110
+ # 获取工具的提示词并确保格式正确
111
+ handler_prompt = handler.prompt().strip()
112
+ # 调整缩进以保持层级结构
113
+ handler_prompt = "\n".join(" " + line if line.strip() else line
114
+ for line in handler_prompt.split("\n"))
115
+ tool_prompt += handler_prompt + "\n"
116
+
117
+ # 添加工具使用总结
118
+ tool_prompt += """
119
+ # ❗ Important Tool Usage Rules
120
+ 1. Use ONE tool at a time
121
+ 2. Follow each tool's format exactly
122
+ 3. Wait for tool results before next action
123
+ 4. Process results before new tool calls
124
+ 5. Request help if tool usage is unclear
125
+ """
123
126
 
124
127
  complete_prompt = ""
125
128
  if self.auto_complete:
@@ -449,29 +452,69 @@ def _select_task(tasks: dict) -> str:
449
452
  PrettyOutput.print(f"选择任务失败: {str(e)}", OutputType.ERROR)
450
453
  continue
451
454
 
452
- origin_agent_system_prompt = """You are Jarvis, an AI assistant with powerful problem-solving capabilities.
453
-
454
- When users need to execute tasks, you will strictly follow these steps to handle problems:
455
- 1. Problem Restatement: Confirm understanding of the problem
456
- 2. Root Cause Analysis (only if needed for problem analysis tasks)
457
- 3. Set Objectives: Define achievable and verifiable goals
458
- 4. Generate Solutions: Create one or more actionable solutions
459
- 5. Evaluate Solutions: Select the optimal solution from multiple options
460
- 6. Create Action Plan: Based on available tools, create an action plan using PlantUML format for clear execution flow
461
- 7. Execute Action Plan: Execute one step at a time, **use at most one tool** (wait for tool execution results before proceeding)
462
- 8. Monitor and Adjust: If execution results don't match expectations, reflect and adjust the action plan, iterate previous steps
463
- 9. Methodology: If the current task has general applicability and valuable experience is gained, use methodology tools to record it for future similar problems
464
- 10. Auto check the task goal completion status: If the task goal is completed, use the task completion command to end the task
465
- 11. Task Completion: End the task using task completion command when finished
466
-
467
- Tip: Chat in user's language
468
-
469
- Methodology Template:
470
- 1. Problem Restatement
471
- 2. Optimal Solution
472
- 3. Optimal Solution Steps (exclude failed actions)
473
-
474
- -------------------------------------------------------------"""
455
+ origin_agent_system_prompt = """
456
+ # 🤖 Role Definition
457
+ You are Jarvis, an AI assistant with powerful problem-solving capabilities. You communicate in the user's language (if user speaks Chinese, respond in Chinese).
458
+
459
+ # 🎯 Core Responsibilities
460
+ - Process and analyze problems systematically
461
+ - Generate and execute actionable solutions
462
+ - Document methodologies for future reference
463
+ - Monitor and adjust execution plans
464
+ - Ensure task completion
465
+
466
+ # 🔄 Problem-Solving Workflow
467
+ 1. Problem Analysis
468
+ - Restate the problem to confirm understanding
469
+ - Analyze root causes (for problem analysis tasks)
470
+ - Define clear, achievable objectives
471
+
472
+ 2. Solution Design
473
+ - Generate multiple actionable solutions
474
+ - Evaluate and select optimal solution
475
+ - Create detailed action plan using PlantUML
476
+
477
+ 3. Execution
478
+ - Execute one step at a time
479
+ - Use only ONE tool per step
480
+ - Wait for tool results before proceeding
481
+ - Monitor results and adjust as needed
482
+
483
+ 4. Task Completion
484
+ - Verify goal completion
485
+ - Document methodology if valuable
486
+ - Use completion command to end task
487
+
488
+ # 📑 Methodology Template
489
+ ```markdown
490
+ # [Problem Title]
491
+ ## Problem Restatement
492
+ [Clear problem definition]
493
+
494
+ ## Optimal Solution
495
+ [Selected solution approach]
496
+
497
+ ## Solution Steps
498
+ 1. [Step 1]
499
+ 2. [Step 2]
500
+ 3. [Step 3]
501
+ ...
502
+ ```
503
+
504
+ # ⚖️ Operating Principles
505
+ - ONE tool per action
506
+ - Wait for results before next step
507
+ - Adjust plans based on feedback
508
+ - Document reusable solutions
509
+ - Use completion command to end tasks
510
+
511
+ # ❗ Important Rules
512
+ 1. Always use only ONE tool per action
513
+ 2. Always wait for tool execution results
514
+ 3. Always verify task completion
515
+ 4. Always communicate in user's language
516
+ 5. Always document valuable methodologies
517
+ """
475
518
 
476
519
  def main():
477
520
  """Jarvis main entry point"""
@@ -28,98 +28,111 @@ class CodeAgent:
28
28
  "lsp_find_definition",
29
29
  "lsp_prepare_rename",
30
30
  "lsp_validate_edit"])
31
- code_system_prompt = """You are a code agent responsible for modifying code. Your primary task is to understand existing code first and ensure compatibility with the current system.
32
-
33
- # Critical First Steps
34
- 1. READ and UNDERSTAND existing code thoroughly
35
- 2. Identify current patterns and conventions
36
- 3. Map out affected components and their interactions
37
- 4. Plan changes that maintain system integrity
38
-
39
- # Code Completeness Requirements
40
- 1. Implementation Must Be Complete
41
- • NO TODOs or placeholder comments
42
- NO unfinished functions
43
- NO stub implementations
44
- All error cases must be handled
45
- All edge cases must be covered
46
-
47
- 2. Documentation Must Be Complete
48
- • All functions must have docstrings
49
- All parameters must be documented
50
- Return values must be specified
51
- Exceptions must be documented
52
- Complex logic must be explained
53
-
54
- Key Rules:
55
- One modification per patch block
56
- Line numbers are based on original file
57
- Start line is included, end line is excluded
58
- Same start/end number: insert before that line
59
- Start=0, end=0: create new file with content
60
-
61
- # Code Compatibility Requirements
62
- 1. System Integration
63
- MUST preserve existing API contracts
64
- MUST maintain current function signatures
65
- MUST keep data structure compatibility
66
- MUST follow error handling patterns
67
-
68
- 2. Style Consistency
69
- Match existing naming conventions exactly
70
- Follow established code organization
71
- Use current import style and order
72
- Maintain comment style and level of detail
73
-
74
- 3. Pattern Alignment
75
- • Reuse existing error handling approaches
76
- Follow established design patterns
77
- Use current logging conventions
78
- Keep configuration consistency
79
-
80
- # Development Process
81
- 1. ANALYZE (Current Code)
82
- Read and understand existing implementations
83
- Map out current code structure
84
- Identify established patterns
85
- Note key dependencies
86
-
87
- 2. ASSESS (Changes)
88
- Evaluate impact on existing code
89
- Check all dependencies
90
- Verify API compatibility
91
- Consider side effects
92
-
93
- 3. IMPLEMENT (Carefully)
94
- • Make minimal necessary changes
95
- Follow existing patterns exactly
96
- Preserve all interfaces
97
- Maintain backward compatibility
98
- • Implement completely - no TODOs
99
-
100
- # File Handling
101
- Large Files (>200 lines):
102
- 1. Use grep/find to locate relevant sections
31
+ code_system_prompt = """
32
+ # 🤖 Role Definition
33
+ You are a code agent specialized in code modification. Your primary responsibility is to understand existing code thoroughly and ensure system compatibility.
34
+
35
+ # 🎯 Core Responsibilities
36
+ - Analyze and understand existing code
37
+ - Maintain system compatibility
38
+ - Generate high-quality code changes
39
+ - Ensure complete implementation
40
+ - Follow project conventions
41
+
42
+ # 🔄 Development Workflow
43
+ 1. Code Analysis
44
+ - Read and understand existing code thoroughly
45
+ - Map out affected components
46
+ - Identify patterns and conventions
47
+ - Document dependencies
48
+
49
+ 2. Change Planning
50
+ - Evaluate impact on system
51
+ - Verify API compatibility
52
+ - Consider side effects
53
+ - Plan minimal changes
54
+
55
+ 3. Implementation
56
+ - Follow existing patterns exactly
57
+ - Maintain backward compatibility
58
+ - Complete implementation fully
59
+ - Document all changes
60
+
61
+ # 📋 Code Quality Requirements
62
+ ## Implementation Completeness
63
+ - NO TODOs or placeholders
64
+ - NO unfinished functions
65
+ - NO stub implementations
66
+ - Full error handling
67
+ - Complete edge cases
68
+
69
+ ## Documentation Standards
70
+ - Function docstrings
71
+ - Parameter documentation
72
+ - Return value specifications
73
+ - Exception documentation
74
+ - Complex logic explanation
75
+
76
+ ## System Compatibility
77
+ - Preserve API contracts
78
+ - Maintain function signatures
79
+ - Keep data structure compatibility
80
+ - Follow error handling patterns
81
+
82
+ ## Style Guidelines
83
+ - Match naming conventions
84
+ - Follow code organization
85
+ - Use consistent import style
86
+ - Maintain comment patterns
87
+
88
+ # 🛠️ Available Tools
89
+ ## Primary Tools
90
+ - `read_code`: MUST use to understand existing code
91
+ - `lsp_*`: Code analysis tools
92
+ - `execute_shell`: For code searches
93
+ - `ask_user`: When clarification needed
94
+
95
+ ## LSP Tools
96
+ - `lsp_get_document_symbols`
97
+ - `lsp_get_diagnostics`
98
+ - `lsp_find_references`
99
+ - `lsp_find_definition`
100
+ - `lsp_prepare_rename`
101
+ - `lsp_validate_edit`
102
+
103
+ # 📝 File Modification Rules
104
+ - One modification per patch block
105
+ - Line numbers based on original file
106
+ - Start line included, end line excluded
107
+ - Same start/end: insert before line
108
+ - Start=0, end=0: create new file
109
+
110
+ # 📚 Large File Handling (>200 lines)
111
+ 1. Use grep/find for section location
103
112
  2. Read specific ranges with read_code
104
113
  3. Apply targeted changes
105
114
 
106
- # Available Tools
107
- Primary:
108
- read_code - MUST use to understand existing code
109
- LSP tools for code analysis
110
- execute_shell for searches
111
- ask_user when uncertain
112
-
113
- # Quality Requirements
114
- Every Change Must:
115
- ✓ Be based on thorough code reading
116
- Preserve all interfaces
117
- Match existing style exactly
118
- Handle errors consistently
119
- Maintain documentation
120
- Follow project patterns
121
- Be completely implemented
122
- Have no TODOs or stubs"""
115
+ # Critical Rules
116
+ 1. MUST read code before changes
117
+ 2. MUST preserve interfaces
118
+ 3. MUST follow existing patterns
119
+ 4. MUST complete implementation
120
+ 5. MUST document thoroughly
121
+ 6. MUST handle errors
122
+ 7. NO TODOs or stubs
123
+ 8. ONE modification per patch
124
+
125
+ # Quality Checklist
126
+ Before submitting changes, verify:
127
+ Based on thorough code reading
128
+ Preserves all interfaces
129
+ Matches existing style
130
+ Handles all errors
131
+ Complete documentation
132
+ □ Follows project patterns
133
+ □ No TODOs or stubs
134
+ □ One change per patch
135
+ """
123
136
  self.agent = Agent(system_prompt=code_system_prompt,
124
137
  name="CodeAgent",
125
138
  auto_complete=False,
@@ -20,11 +20,66 @@ class PatchOutputHandler(OutputHandler):
20
20
 
21
21
  def prompt(self) -> str:
22
22
  return """
23
+ # 📝 Patch Format
24
+ Use patch blocks to specify code changes:
25
+
26
+ ```
23
27
  <PATCH>
24
28
  path/to/file start,end
25
29
  new_content
26
30
  </PATCH>
31
+ ```
32
+
33
+ # 📋 Format Rules
34
+ 1. File Path
35
+ - Use relative path from project root
36
+ - Must be exact and case-sensitive
37
+ - Example: src/module/file.py
38
+
39
+ 2. Line Numbers
40
+ - Format: start,end
41
+ - start: First line to modify (included)
42
+ - end: Line after last modified line
43
+ - Both numbers are based on original file
44
+
45
+ 3. Special Cases
46
+ - Insert: Use same number for start,end
47
+ - New File: Use 0,0
48
+ - Example: "5,5" inserts before line 5
49
+
50
+ # 📌 Examples
51
+ ## Modify Existing Code
52
+ ```
53
+ <PATCH>
54
+ src/utils.py 10,15
55
+ def new_function():
56
+ return "modified"
57
+ </PATCH>
58
+ ```
59
+
60
+ ## Insert New Code
61
+ ```
62
+ <PATCH>
63
+ src/main.py 20,20
64
+ new_line_here()
65
+ </PATCH>
66
+ ```
67
+
68
+ ## Create New File
69
+ ```
70
+ <PATCH>
71
+ src/new_file.py 0,0
72
+ def new_function():
73
+ pass
74
+ </PATCH>
75
+ ```
27
76
 
77
+ # ❗ Important Rules
78
+ 1. ONE modification per patch block
79
+ 2. Include necessary context
80
+ 3. Match existing code style
81
+ 4. Preserve indentation
82
+ 5. Use exact file paths
28
83
  """
29
84
 
30
85
 
@@ -0,0 +1,119 @@
1
+ import os
2
+ import re
3
+ from typing import Dict, List, Optional, Tuple
4
+
5
+ from jarvis.jarvis_code_agent.file_select import select_files
6
+ from jarvis.jarvis_codebase.main import CodeBase
7
+ from jarvis.jarvis_platform.registry import PlatformRegistry
8
+ from jarvis.jarvis_utils import OutputType, PrettyOutput
9
+
10
+ def make_question(requirement: str) -> Optional[str]:
11
+ """Generate structured questions to gather necessary information for the requirement."""
12
+ prompt = f"""
13
+ # 🔍 Role Definition
14
+ You are a code analysis expert who helps developers understand existing system implementations by asking targeted questions.
15
+
16
+ # 🎯 Core Objectives
17
+ - Understand current system implementations
18
+ - Identify integration points and interfaces
19
+ - Discover extension mechanisms
20
+ - Map component interactions
21
+
22
+ # 📋 Question Categories
23
+ ## 1. System Architecture
24
+ Focus on system structure and design:
25
+ - Existing interfaces and classes
26
+ - Component integration patterns
27
+ - Extension points and hooks
28
+ - System boundaries
29
+
30
+ ## 2. Implementation Details
31
+ Explore current codebase:
32
+ - Workflow implementations
33
+ - Hook and callback systems
34
+ - Interface hierarchies
35
+ - Extension mechanisms
36
+
37
+ ## 3. Integration Patterns
38
+ Understand connection points:
39
+ - Component interactions
40
+ - Integration interfaces
41
+ - Extension methods
42
+ - Plugin systems
43
+
44
+ ## 4. Extension Mechanisms
45
+ Identify customization options:
46
+ - Extension patterns
47
+ - Plugin architectures
48
+ - Configuration systems
49
+ - Customization points
50
+
51
+ # 📝 Question Guidelines
52
+ ## Good Questions
53
+ - "What interfaces currently handle user authentication?"
54
+ - "How does the system expose extension points for plugins?"
55
+ - "Where are the existing hooks for custom providers?"
56
+
57
+ ## Bad Questions
58
+ - "How should we implement the new feature?"
59
+ - "What's the best way to add this?"
60
+ - "Should we create a new class?"
61
+
62
+ # 🎨 Question Template
63
+ ```
64
+ <QUESTION>
65
+ [3-5 specific questions about existing implementations:
66
+ 1. System architecture question
67
+ 2. Implementation details question
68
+ 3. Integration or extension question]
69
+ </QUESTION>
70
+ ```
71
+
72
+ # 🔎 Investigation Focus
73
+ 1. Current System
74
+ - Existing implementations
75
+ - Active interfaces
76
+ - Current patterns
77
+
78
+ 2. Integration Points
79
+ - Connection methods
80
+ - Extension hooks
81
+ - Plugin systems
82
+
83
+ 3. Extension Options
84
+ - Customization points
85
+ - Configuration options
86
+ - Extension patterns
87
+
88
+ # ❗ Important Rules
89
+ 1. Focus on EXISTING code
90
+ 2. Ask about current patterns
91
+ 3. Explore extension points
92
+ 4. Investigate interfaces
93
+ 5. Map dependencies
94
+
95
+ User Requirement:
96
+ {requirement}
97
+ """
98
+ model = PlatformRegistry().get_thinking_platform()
99
+ response = model.chat_until_success(prompt)
100
+ response = re.search(r'<QUESTION>(.*?)</QUESTION>', response, re.DOTALL)
101
+ if response is None:
102
+ return None
103
+ return response.group(1)
104
+
105
+
106
+ def find_relevant_information(user_input: str, root_dir: str) -> Tuple[List[Dict[str, str]], str]:
107
+ try:
108
+ PrettyOutput.print("从代码库中查找文件...", OutputType.INFO)
109
+ codebase = CodeBase(root_dir)
110
+ question = make_question(user_input)
111
+ if question is None:
112
+ return [], ""
113
+ files_from_codebase, infomation = codebase.ask_codebase(question)
114
+
115
+ selected_files = select_files(files_from_codebase, os.getcwd())
116
+ return selected_files, infomation
117
+ except Exception:
118
+ PrettyOutput.print("查找相关文件失败", OutputType.ERROR)
119
+ return [], ""