jarvis-ai-assistant 0.1.123__tar.gz → 0.1.124__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 (74) hide show
  1. {jarvis_ai_assistant-0.1.123/src/jarvis_ai_assistant.egg-info → jarvis_ai_assistant-0.1.124}/PKG-INFO +5 -6
  2. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/pyproject.toml +17 -15
  3. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/setup.py +4 -2
  4. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/__init__.py +1 -1
  5. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_agent/__init__.py +1 -1
  6. jarvis_ai_assistant-0.1.124/src/jarvis/jarvis_code_agent/code_agent.py +149 -0
  7. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_code_agent/file_select.py +0 -86
  8. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_code_agent/patch.py +158 -104
  9. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform/base.py +1 -1
  10. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/chdir.py +25 -0
  11. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/create_code_agent.py +3 -6
  12. jarvis_ai_assistant-0.1.124/src/jarvis/jarvis_tools/execute_shell_script.py +58 -0
  13. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/git_commiter.py +21 -15
  14. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/search.py +0 -1
  15. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_utils/__init__.py +60 -19
  16. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124/src/jarvis_ai_assistant.egg-info}/PKG-INFO +5 -6
  17. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis_ai_assistant.egg-info/SOURCES.txt +1 -1
  18. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis_ai_assistant.egg-info/requires.txt +3 -1
  19. jarvis_ai_assistant-0.1.123/src/jarvis/jarvis_code_agent/code_agent.py +0 -213
  20. jarvis_ai_assistant-0.1.123/src/jarvis/jarvis_code_agent/relevant_files.py +0 -117
  21. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/LICENSE +0 -0
  22. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/MANIFEST.in +0 -0
  23. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/README.md +0 -0
  24. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/setup.cfg +0 -0
  25. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_agent/output_handler.py +0 -0
  26. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_code_agent/__init__.py +0 -0
  27. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_codebase/__init__.py +0 -0
  28. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_codebase/main.py +0 -0
  29. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_dev/main.py +0 -0
  30. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_lsp/base.py +0 -0
  31. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_lsp/cpp.py +0 -0
  32. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_lsp/go.py +0 -0
  33. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_lsp/python.py +0 -0
  34. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_lsp/registry.py +0 -0
  35. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_lsp/rust.py +0 -0
  36. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_multi_agent/__init__.py +0 -0
  37. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform/__init__.py +0 -0
  38. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform/ai8.py +0 -0
  39. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform/kimi.py +0 -0
  40. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform/ollama.py +0 -0
  41. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform/openai.py +0 -0
  42. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform/oyi.py +0 -0
  43. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform/registry.py +0 -0
  44. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform_manager/__init__.py +0 -0
  45. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform_manager/main.py +0 -0
  46. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_platform_manager/openai_test.py +0 -0
  47. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_rag/__init__.py +0 -0
  48. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_rag/main.py +0 -0
  49. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_smart_shell/__init__.py +0 -0
  50. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_smart_shell/main.py +0 -0
  51. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/__init__.py +0 -0
  52. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/ask_codebase.py +0 -0
  53. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/ask_user.py +0 -0
  54. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/base.py +0 -0
  55. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/code_review.py +0 -0
  56. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/create_sub_agent.py +0 -0
  57. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/execute_shell.py +0 -0
  58. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/file_operation.py +0 -0
  59. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/lsp_find_definition.py +0 -0
  60. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/lsp_find_references.py +0 -0
  61. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/lsp_get_diagnostics.py +0 -0
  62. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/lsp_get_document_symbols.py +0 -0
  63. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/lsp_prepare_rename.py +0 -0
  64. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/lsp_validate_edit.py +0 -0
  65. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/methodology.py +0 -0
  66. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/rag.py +0 -0
  67. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/read_code.py +0 -0
  68. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/read_webpage.py +0 -0
  69. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/registry.py +0 -0
  70. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/select_code_files.py +0 -0
  71. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis/jarvis_tools/tool_generator.py +0 -0
  72. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis_ai_assistant.egg-info/dependency_links.txt +0 -0
  73. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis_ai_assistant.egg-info/entry_points.txt +0 -0
  74. {jarvis_ai_assistant-0.1.123 → jarvis_ai_assistant-0.1.124}/src/jarvis_ai_assistant.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.1
2
2
  Name: jarvis-ai-assistant
3
- Version: 0.1.123
3
+ Version: 0.1.124
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
@@ -46,7 +46,7 @@ Requires-Dist: colorama>=0.4.6
46
46
  Requires-Dist: prompt_toolkit>=3.0.0
47
47
  Requires-Dist: openai>=1.20.0
48
48
  Requires-Dist: playwright>=1.41.1
49
- Requires-Dist: numpy==1.17.4
49
+ Requires-Dist: numpy>=1.19.5
50
50
  Requires-Dist: faiss-cpu>=1.8.0
51
51
  Requires-Dist: sentence-transformers>=2.2.2
52
52
  Requires-Dist: bs4>=0.0.1
@@ -62,14 +62,13 @@ Requires-Dist: fuzzywuzzy>=0.18.0
62
62
  Requires-Dist: python-Levenshtein>=0.25.0
63
63
  Requires-Dist: jedi>=0.17.2
64
64
  Requires-Dist: psutil>=7.0.0
65
+ Requires-Dist: fastapi>=0.115.4
66
+ Requires-Dist: uvicorn>=0.33.0
65
67
  Provides-Extra: dev
66
68
  Requires-Dist: pytest; extra == "dev"
67
69
  Requires-Dist: black; extra == "dev"
68
70
  Requires-Dist: isort; extra == "dev"
69
71
  Requires-Dist: mypy; extra == "dev"
70
- Dynamic: author
71
- Dynamic: home-page
72
- Dynamic: requires-python
73
72
 
74
73
  <div align="center">
75
74
 
@@ -4,22 +4,22 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "jarvis-ai-assistant"
7
- version = "0.1.123"
7
+ version = "0.1.124"
8
8
  description = "Jarvis: An AI assistant that uses tools to interact with the system"
9
9
  readme = "README.md"
10
- authors = [{ name = "skyfire", email = "skyfireitdiy@hotmail.com" }]
10
+ authors = [{ name = "skyfire", email = "skyfireitdiy@hotmail.com" }]
11
11
  license = { file = "LICENSE" }
12
- classifiers = [
13
- "Development Status :: 3 - Alpha",
14
- "Intended Audience :: Developers",
15
- "License :: OSI Approved :: MIT License",
16
- "Operating System :: POSIX :: Linux",
17
- "Programming Language :: Python :: 3",
18
- "Programming Language :: Python :: 3.8",
19
- "Programming Language :: Python :: 3.9",
20
- "Programming Language :: Python :: 3.10",
21
- "Programming Language :: Python :: 3.11",
22
- ]
12
+ classifiers = [
13
+ "Development Status :: 3 - Alpha",
14
+ "Intended Audience :: Developers",
15
+ "License :: OSI Approved :: MIT License",
16
+ "Operating System :: POSIX :: Linux",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.8",
19
+ "Programming Language :: Python :: 3.9",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ ]
23
23
  keywords = ["jarvis", "ai", "assistant", "tools", "automation"]
24
24
  dependencies = [
25
25
  "requests>=2.25.1",
@@ -28,7 +28,7 @@ dependencies = [
28
28
  "prompt_toolkit>=3.0.0",
29
29
  "openai>=1.20.0",
30
30
  "playwright>=1.41.1",
31
- "numpy==1.17.4",
31
+ "numpy>=1.19.5",
32
32
  "faiss-cpu>=1.8.0",
33
33
  "sentence-transformers>=2.2.2",
34
34
  "bs4>=0.0.1",
@@ -44,6 +44,8 @@ dependencies = [
44
44
  "python-Levenshtein>=0.25.0",
45
45
  "jedi>=0.17.2",
46
46
  "psutil>=7.0.0",
47
+ "fastapi>=0.115.4",
48
+ "uvicorn>=0.33.0",
47
49
  ]
48
50
  requires-python = ">=3.8"
49
51
 
@@ -65,4 +67,4 @@ jarvis-platform-manager = "jarvis.jarvis_platform_manager.main:main"
65
67
  jarvis-git-commit = "jarvis.jarvis_tools.git_commiter:main"
66
68
  jarvis-code-review = "jarvis.jarvis_tools.code_review:main"
67
69
  jgc = "jarvis.jarvis_tools.git_commiter:main"
68
- jarvis-dev = "jarvis.jarvis_dev.main:main"
70
+ 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.123",
5
+ version="0.1.124",
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",
@@ -19,7 +19,7 @@ setup(
19
19
  "prompt_toolkit>=3.0.0",
20
20
  "openai>=1.20.0",
21
21
  "playwright>=1.41.1",
22
- "numpy==1.17.4",
22
+ "numpy>=1.19.5",
23
23
  "faiss-cpu>=1.8.0",
24
24
  "sentence-transformers>=2.2.2",
25
25
  "bs4>=0.0.1",
@@ -35,6 +35,8 @@ setup(
35
35
  "python-Levenshtein>=0.25.0",
36
36
  "jedi>=0.17.2",
37
37
  "psutil>=7.0.0",
38
+ "fastapi>=0.115.4",
39
+ "uvicorn>=0.33.0",
38
40
  ],
39
41
  entry_points={
40
42
  "console_scripts": [
@@ -1,3 +1,3 @@
1
1
  """Jarvis AI Assistant"""
2
2
 
3
- __version__ = "0.1.123"
3
+ __version__ = "0.1.124"
@@ -327,7 +327,7 @@ Please continue the task based on the above information.
327
327
  return self._complete_task()
328
328
 
329
329
  # 获取用户输入
330
- user_input = get_multiline_input(f"{self.name}: 您可以继续输入,或输入空行来结束当前任务:")
330
+ user_input = get_multiline_input(f"{self.name}: 请输入,或输入空行来结束当前任务:")
331
331
 
332
332
  if user_input:
333
333
  self.prompt = user_input
@@ -0,0 +1,149 @@
1
+ import subprocess
2
+ import os
3
+ from typing import Dict, List
4
+
5
+ from jarvis.jarvis_agent import Agent
6
+ from jarvis.jarvis_code_agent.file_select import select_files
7
+ from jarvis.jarvis_code_agent.patch import PatchOutputHandler, file_input_handler
8
+ from jarvis.jarvis_platform.registry import PlatformRegistry
9
+ from jarvis.jarvis_tools.git_commiter import GitCommitTool
10
+ from jarvis.jarvis_tools.registry import ToolRegistry
11
+ from jarvis.jarvis_tools.read_code import ReadCodeTool
12
+ from jarvis.jarvis_utils import get_commits_between
13
+ from jarvis.jarvis_utils import OutputType, PrettyOutput, get_multiline_input, has_uncommitted_changes, init_env, find_git_root, user_confirm, get_latest_commit_hash
14
+ from jarvis.jarvis_utils import OutputType, PrettyOutput, get_multiline_input, has_uncommitted_changes, init_env, find_git_root, user_confirm
15
+
16
+
17
+ class CodeAgent:
18
+ def __init__(self):
19
+ self.root_dir = os.getcwd()
20
+ tool_registry = ToolRegistry()
21
+ tool_registry.use_tools(["read_code",
22
+ "execute_shell",
23
+ "execute_shell_script",
24
+ "search",
25
+ "create_code_agent",
26
+ "ask_user",
27
+ "ask_codebase",
28
+ "lsp_get_document_symbols",
29
+ "lsp_get_diagnostics",
30
+ "lsp_find_references",
31
+ "lsp_find_definition",
32
+ "lsp_prepare_rename",
33
+ "lsp_validate_edit"])
34
+ code_system_prompt = """
35
+ # Role: Code Engineer
36
+ Expert in precise code modifications with proper tool usage.
37
+ ## Tool Usage Guide
38
+ 1. read_code: Analyze code files before changes
39
+ 2. execute_shell: Run system commands safely
40
+ 3. execute_shell_script: Execute script files
41
+ 4. search: Find technical information
42
+ 5. create_code_agent: Create new code agents
43
+ 6. ask_user: Clarify requirements
44
+ 7. ask_codebase: Analyze codebase structure
45
+ 8. lsp_get_document_symbols: List code symbols
46
+ 9. lsp_get_diagnostics: Check code errors
47
+ 10. lsp_find_references: Find symbol usage
48
+ 11. lsp_find_definition: Locate symbol definitions
49
+ 12. lsp_prepare_rename: Check rename safety
50
+ 13. lsp_validate_edit: Verify code changes
51
+ ## Workflow
52
+ 1. Analyze: Use read_code and LSP tools
53
+ 2. Modify: Make minimal, precise changes
54
+ 3. Validate: Verify with LSP tools
55
+ 4. Document: Explain non-obvious logic
56
+ ## Best Practices
57
+ - Verify line ranges carefully
58
+ - Preserve existing interfaces
59
+ - Test edge cases
60
+ - Document changes
61
+ """
62
+ self.agent = Agent(system_prompt=code_system_prompt,
63
+ name="CodeAgent",
64
+ auto_complete=False,
65
+ is_sub_agent=False,
66
+ use_methodology=False,
67
+ output_handler=[tool_registry, PatchOutputHandler()],
68
+ platform=PlatformRegistry().get_codegen_platform(),
69
+ record_methodology=False,
70
+ input_handler=[file_input_handler],
71
+ need_summary=False)
72
+
73
+
74
+
75
+ def _init_env(self):
76
+ curr_dir = os.getcwd()
77
+ git_dir = find_git_root(curr_dir)
78
+ self.root_dir = git_dir
79
+ if has_uncommitted_changes():
80
+ git_commiter = GitCommitTool()
81
+ git_commiter.execute({})
82
+
83
+
84
+
85
+ def run(self, user_input: str) :
86
+ """Run the code agent with the given user input.
87
+
88
+ Args:
89
+ user_input: The user's requirement/request
90
+
91
+ Returns:
92
+ str: Output describing the execution result
93
+ """
94
+ try:
95
+ self._init_env()
96
+ start_commit = get_latest_commit_hash()
97
+
98
+
99
+ self.agent.run(user_input)
100
+
101
+ end_commit = get_latest_commit_hash()
102
+ # Print commit history between start and end commits
103
+ commits = get_commits_between(start_commit, end_commit)
104
+ if commits:
105
+ commit_messages = "检测到以下提交记录:\n" + "\n".join([f"- {commit_hash[:7]}: {message}" for commit_hash, message in commits])
106
+ PrettyOutput.print(commit_messages, OutputType.INFO)
107
+
108
+ if start_commit and end_commit and start_commit != end_commit and user_confirm("检测到多个提交,是否要合并为一个更清晰的提交记录?", True):
109
+ # Reset to start commit
110
+ subprocess.run(["git", "reset", "--soft", start_commit], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
111
+ # Create new commit
112
+ git_commiter = GitCommitTool()
113
+ git_commiter.execute({})
114
+
115
+ except Exception as e:
116
+ return f"Error during execution: {str(e)}"
117
+
118
+
119
+
120
+ def main():
121
+ """Jarvis main entry point"""
122
+ # Add argument parser
123
+ init_env()
124
+
125
+ curr_dir = os.getcwd()
126
+ git_dir = find_git_root(curr_dir)
127
+ PrettyOutput.print(f"当前目录: {git_dir}", OutputType.INFO)
128
+
129
+ try:
130
+ # Interactive mode
131
+ while True:
132
+ try:
133
+ user_input = get_multiline_input("请输入你的需求(输入空行退出):")
134
+ if not user_input:
135
+ break
136
+ agent = CodeAgent()
137
+ agent.run(user_input)
138
+
139
+ except Exception as e:
140
+ PrettyOutput.print(f"错误: {str(e)}", OutputType.ERROR)
141
+
142
+ except Exception as e:
143
+ PrettyOutput.print(f"初始化错误: {str(e)}", OutputType.ERROR)
144
+ return 1
145
+
146
+ return 0
147
+
148
+ if __name__ == "__main__":
149
+ exit(main())
@@ -213,89 +213,3 @@ def select_files(related_files: List[Dict[str, str]], root_dir: str) -> List[Dic
213
213
  if tips:
214
214
  PrettyOutput.print(tips, OutputType.INFO)
215
215
  return selected_files
216
-
217
- def file_input_handler(user_input: str, agent: Any) -> str:
218
- """Handle file input with optional line ranges.
219
-
220
- Args:
221
- user_input: User input string containing file references
222
- agent: Agent instance (unused in current implementation)
223
-
224
- Returns:
225
- str: Prompt with file contents prepended if files are found
226
- """
227
- prompt = user_input
228
- files = []
229
-
230
- file_refs = re.findall(r"'([^']+)'", user_input)
231
- for ref in file_refs:
232
- # Handle file:start,end or file:start:end format
233
- if ':' in ref:
234
- file_path, line_range = ref.split(':', 1)
235
- # Initialize with default values
236
- start_line = 1 # 1-based
237
- end_line = -1
238
-
239
- # Process line range if specified
240
- if ',' in line_range or ':' in line_range:
241
- try:
242
- raw_start, raw_end = map(int, re.split(r'[,:]', line_range))
243
-
244
- # Handle special values and Python-style negative indices
245
- try:
246
- with open(file_path, 'r', encoding='utf-8') as f:
247
- total_lines = len(f.readlines())
248
- except FileNotFoundError:
249
- PrettyOutput.print(f"文件不存在: {file_path}", OutputType.WARNING)
250
- continue
251
- # Process start line
252
- if raw_start == 0: # 0表示整个文件
253
- start_line = 1
254
- end_line = total_lines
255
- else:
256
- start_line = raw_start if raw_start > 0 else total_lines + raw_start + 1
257
-
258
- # Process end line
259
- if raw_end == 0: # 0表示整个文件(如果start也是0)
260
- end_line = total_lines
261
- else:
262
- end_line = raw_end if raw_end > 0 else total_lines + raw_end + 1
263
-
264
- # Auto-correct ranges
265
- start_line = max(1, min(start_line, total_lines))
266
- end_line = max(start_line, min(end_line, total_lines))
267
-
268
- # Final validation
269
- if start_line < 1 or end_line > total_lines or start_line > end_line:
270
- raise ValueError
271
-
272
- except (ValueError, FileNotFoundError) as e:
273
- PrettyOutput.print(
274
- f"无效的行号范围: {line_range} (文件总行数: {total_lines})",
275
- OutputType.WARNING
276
- )
277
- continue
278
-
279
- # Add file if it exists
280
- if os.path.isfile(file_path):
281
- files.append({
282
- "path": file_path,
283
- "start_line": start_line,
284
- "end_line": end_line
285
- })
286
- else:
287
- # Handle simple file path
288
- if os.path.isfile(ref):
289
- files.append({
290
- "path": ref,
291
- "start_line": 1, # 1-based
292
- "end_line": -1
293
- })
294
-
295
- # Read and process files if any were found
296
- if files:
297
- result = ReadCodeTool().execute({"files": files})
298
- if result["success"]:
299
- return result["stdout"] + "\n" + prompt
300
-
301
- return prompt