ziya 0.1.41__tar.gz → 0.1.43__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 ziya might be problematic. Click here for more details.
- {ziya-0.1.41 → ziya-0.1.43}/PKG-INFO +2 -1
- {ziya-0.1.41 → ziya-0.1.43}/app/agents/agent.py +0 -1
- {ziya-0.1.41 → ziya-0.1.43}/app/agents/prompts.py +13 -1
- {ziya-0.1.41 → ziya-0.1.43}/app/main.py +0 -1
- {ziya-0.1.41 → ziya-0.1.43}/app/server.py +31 -2
- ziya-0.1.43/app/utils/code_util.py +315 -0
- {ziya-0.1.41 → ziya-0.1.43}/pyproject.toml +2 -1
- {ziya-0.1.41 → ziya-0.1.43}/templates/asset-manifest.json +3 -3
- {ziya-0.1.41 → ziya-0.1.43}/templates/index.html +1 -1
- ziya-0.1.43/templates/static/js/main.50c95184.js +3 -0
- ziya-0.1.41/templates/static/js/main.69f6f0d1.js.LICENSE.txt → ziya-0.1.43/templates/static/js/main.50c95184.js.LICENSE.txt +6 -0
- ziya-0.1.43/templates/static/js/main.50c95184.js.map +1 -0
- ziya-0.1.41/templates/static/js/main.69f6f0d1.js +0 -3
- ziya-0.1.41/templates/static/js/main.69f6f0d1.js.map +0 -1
- {ziya-0.1.41 → ziya-0.1.43}/LICENSE +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/README.md +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/app/__init__.py +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/app/agents/__init__.py +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/app/utils/__init__.py +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/app/utils/directory_util.py +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/app/utils/gitignore_parser.py +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/app/utils/langchain_validation_util.py +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/app/utils/logging_utils.py +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/app/utils/print_tree_util.py +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/app/utils/version_util.py +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/scripts.py +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/favicon.ico +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/static/css/main.8af23da0.css +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/static/css/main.8af23da0.css.map +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/static/media/fa-brands-400.455ea818179b4def0c43.woff2 +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/static/media/fa-brands-400.60127e352b7a11f7f1bc.ttf +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/static/media/fa-regular-400.21cb8f55d8e0c5b89751.woff2 +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/static/media/fa-regular-400.eb91f7b948a42799f678.ttf +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/static/media/fa-solid-900.4d986b00ff9ca3828fbd.woff2 +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/static/media/fa-solid-900.bacd5de623fb563b961a.ttf +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/static/media/fa-v4compatibility.c8e090db312b0bea2aa2.ttf +0 -0
- {ziya-0.1.41 → ziya-0.1.43}/templates/static/media/fa-v4compatibility.cf7f5903d06b79ad60f1.woff2 +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ziya
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.43
|
|
4
4
|
Summary:
|
|
5
5
|
Author: Vishnu Krishnaprasad
|
|
6
6
|
Author-email: vishnukool@gmail.com
|
|
@@ -18,6 +18,7 @@ Requires-Dist: langchain-aws (>=0.2,<0.3)
|
|
|
18
18
|
Requires-Dist: langchain-cli (>=0.0.15)
|
|
19
19
|
Requires-Dist: langchain-community (>=0.3.1,<0.4.0)
|
|
20
20
|
Requires-Dist: langchainhub (>=0.1.15)
|
|
21
|
+
Requires-Dist: langgraph (>=0.2,<0.3)
|
|
21
22
|
Requires-Dist: pydantic (>=2.9.2,<3.0.0)
|
|
22
23
|
Requires-Dist: pydevd-pycharm (>=243.18137.19,<244.0.0)
|
|
23
24
|
Requires-Dist: tiktoken (>=0.8.0,<0.9.0)
|
|
@@ -57,7 +57,6 @@ def get_combined_docs_from_files(files) -> str:
|
|
|
57
57
|
docs = TextLoader(full_file_path).load()
|
|
58
58
|
for doc in docs:
|
|
59
59
|
combined_contents += f"File: {file_path}\n{doc.page_content}\n\n"
|
|
60
|
-
|
|
61
60
|
except Exception as e:
|
|
62
61
|
print(f"Skipping file {full_file_path} due to error: {e}")
|
|
63
62
|
|
|
@@ -31,6 +31,19 @@ Follow these strict guidelines for diff formatting:
|
|
|
31
31
|
|
|
32
32
|
5. End each diff block with ``` on a new line
|
|
33
33
|
|
|
34
|
+
CRITICAL: After generating each hunk diff, carefully review and verify the following:
|
|
35
|
+
1. Check that the diff can be applied cleanly using `git apply`. This means:
|
|
36
|
+
- The context lines (unchanged lines) in the diff should match the original file content.
|
|
37
|
+
- The line numbers and content should be consistent throughout the diff.
|
|
38
|
+
- There should be no conflicts or inconsistencies in the changes.
|
|
39
|
+
2. If you find any errors or inconsistencies, correct them before finalizing the diff.
|
|
40
|
+
3. For each hunk in the diff, please make sure it starts or ends with a line containing content instead of empty line, if possible.
|
|
41
|
+
4. When creating a new file, ensure the line `new file mode 100644` is included to specify file permissions.
|
|
42
|
+
5. When deleting a file, include `deleted file mode` to indicate that the file has been removed. Each line in the
|
|
43
|
+
deleted file should be prefixed with `-` to indicate the content removal.
|
|
44
|
+
6. Lines ending with a newline (\n) should not be interpreted as an additional line. Treat \n as the end of the current
|
|
45
|
+
line’s content, not as a new line in the file.
|
|
46
|
+
|
|
34
47
|
Do not include any explanatory text within the diff blocks. If you need to provide explanations or comments, do so outside the diff blocks.
|
|
35
48
|
|
|
36
49
|
The codebase is provided at the end of this prompt in a specific format.
|
|
@@ -63,7 +76,6 @@ conversational_prompt = ChatPromptTemplate.from_messages(
|
|
|
63
76
|
]
|
|
64
77
|
)
|
|
65
78
|
|
|
66
|
-
|
|
67
79
|
def parse_output(message):
|
|
68
80
|
text = message.content
|
|
69
81
|
return AgentFinish(return_values={"output": text}, log=text)
|
|
@@ -2,18 +2,21 @@ import os
|
|
|
2
2
|
from typing import Dict, Any, List, Tuple
|
|
3
3
|
|
|
4
4
|
import tiktoken
|
|
5
|
-
from fastapi import FastAPI, Request
|
|
5
|
+
from fastapi import FastAPI, Request, HTTPException
|
|
6
6
|
from fastapi.middleware.cors import CORSMiddleware
|
|
7
7
|
from fastapi.staticfiles import StaticFiles
|
|
8
8
|
from fastapi.templating import Jinja2Templates
|
|
9
9
|
from langserve import add_routes
|
|
10
10
|
from app.agents.agent import agent_executor
|
|
11
11
|
from fastapi.responses import FileResponse
|
|
12
|
+
from pydantic import BaseModel
|
|
12
13
|
|
|
13
14
|
# import pydevd_pycharm
|
|
14
15
|
import uvicorn
|
|
15
16
|
|
|
17
|
+
from app.utils.code_util import use_git_to_apply_code_diff, correct_git_diff
|
|
16
18
|
from app.utils.directory_util import get_ignored_patterns
|
|
19
|
+
from app.utils.logging_utils import logger
|
|
17
20
|
from app.utils.gitignore_parser import parse_gitignore_patterns
|
|
18
21
|
|
|
19
22
|
app = FastAPI()
|
|
@@ -35,7 +38,9 @@ add_routes(app, agent_executor, disabled_endpoints=["playground"], path="/ziya")
|
|
|
35
38
|
|
|
36
39
|
@app.get("/")
|
|
37
40
|
async def root(request: Request):
|
|
38
|
-
return templates.TemplateResponse("index.html", {
|
|
41
|
+
return templates.TemplateResponse("index.html", {
|
|
42
|
+
"request": request
|
|
43
|
+
})
|
|
39
44
|
|
|
40
45
|
|
|
41
46
|
@app.get("/favicon.ico", include_in_schema=False)
|
|
@@ -97,5 +102,29 @@ def get_default_included_folders():
|
|
|
97
102
|
return {'defaultIncludedFolders': []}
|
|
98
103
|
|
|
99
104
|
|
|
105
|
+
class ApplyChangesRequest(BaseModel):
|
|
106
|
+
diff: str
|
|
107
|
+
filePath: str
|
|
108
|
+
|
|
109
|
+
@app.post('/api/apply-changes')
|
|
110
|
+
async def apply_changes(request: ApplyChangesRequest):
|
|
111
|
+
try:
|
|
112
|
+
logger.info(f"Received request to apply changes to file: {request.filePath}")
|
|
113
|
+
logger.info(f"Diff content: \n{request.diff}")
|
|
114
|
+
|
|
115
|
+
user_codebase_dir = os.environ.get("ZIYA_USER_CODEBASE_DIR")
|
|
116
|
+
if not user_codebase_dir:
|
|
117
|
+
raise ValueError("ZIYA_USER_CODEBASE_DIR environment variable is not set")
|
|
118
|
+
|
|
119
|
+
file_path = os.path.join(user_codebase_dir, request.filePath)
|
|
120
|
+
corrected_diff = correct_git_diff(request.diff, file_path)
|
|
121
|
+
logger.info(f"corrected diff content: \n{corrected_diff}")
|
|
122
|
+
use_git_to_apply_code_diff(corrected_diff)
|
|
123
|
+
return {'message': 'Changes applied successfully'}
|
|
124
|
+
except Exception as e:
|
|
125
|
+
logger.error(f"Error applying changes: {str(e)}", exc_info=True)
|
|
126
|
+
raise HTTPException(status_code=500, detail=str(e))
|
|
127
|
+
|
|
128
|
+
|
|
100
129
|
if __name__ == "__main__":
|
|
101
130
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess
|
|
3
|
+
from app.utils.logging_utils import logger
|
|
4
|
+
import time
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
HUNK_HEADER_REGEX = re.compile(r'^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@')
|
|
8
|
+
|
|
9
|
+
def use_git_to_apply_code_diff(git_diff: str):
|
|
10
|
+
"""
|
|
11
|
+
Apply a git diff to the user's codebase.
|
|
12
|
+
|
|
13
|
+
This function takes a git diff as a string and applies it to the user's codebase
|
|
14
|
+
specified by the ZIYA_USER_CODEBASE_DIR environment variable. It creates a temporary
|
|
15
|
+
file with the diff content and uses the 'git apply' command to apply the changes.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
git_diff (str): A string containing the git diff to be applied.
|
|
19
|
+
|
|
20
|
+
Note:
|
|
21
|
+
This function assumes that the git command-line tool is available in the system path.
|
|
22
|
+
It uses the --ignore-whitespace and --ignore-space-change options with 'git apply'
|
|
23
|
+
to handle potential whitespace issues.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
user_codebase_dir = os.environ.get("ZIYA_USER_CODEBASE_DIR")
|
|
27
|
+
if not user_codebase_dir:
|
|
28
|
+
raise ValueError("ZIYA_USER_CODEBASE_DIR environment variable is not set")
|
|
29
|
+
|
|
30
|
+
# Create a temporary file with the diff content and a timestamp
|
|
31
|
+
timestamp = int(time.time() * 1000) # Get current timestamp in milliseconds
|
|
32
|
+
temp_file = os.path.join(user_codebase_dir, f'temp_{timestamp}.diff')
|
|
33
|
+
|
|
34
|
+
with open(temp_file, 'w', newline='\n') as f:
|
|
35
|
+
f.write(git_diff)
|
|
36
|
+
# need to add a newline at the end of the file of git apply will fail
|
|
37
|
+
f.write("\n")
|
|
38
|
+
logger.info(f"Created temporary diff file: {temp_file}")
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
# Apply the changes using git apply
|
|
42
|
+
cmd = ['git', 'apply', '--verbose', '--ignore-whitespace', '--ignore-space-change', temp_file]
|
|
43
|
+
logger.info(f"Executing command: {' '.join(cmd)}")
|
|
44
|
+
result = subprocess.run(cmd, capture_output=True, text=True, cwd=user_codebase_dir, check=True)
|
|
45
|
+
|
|
46
|
+
logger.info(f"Git apply stdout: {result.stdout}")
|
|
47
|
+
logger.error(f"Git apply stderr: {result.stderr}")
|
|
48
|
+
logger.info(f"Git apply return code: {result.returncode}")
|
|
49
|
+
|
|
50
|
+
except Exception as e:
|
|
51
|
+
logger.error(f"Error applying changes: {str(e)}", exc_info=True)
|
|
52
|
+
raise
|
|
53
|
+
finally:
|
|
54
|
+
os.remove(temp_file)
|
|
55
|
+
|
|
56
|
+
def correct_git_diff(git_diff: str, original_file_path: str) -> str:
|
|
57
|
+
"""
|
|
58
|
+
Corrects the hunk headers in a git diff string by recalculating the line counts and
|
|
59
|
+
adjusting the starting line numbers in the new file, considering the cumulative effect of
|
|
60
|
+
previous hunks.
|
|
61
|
+
|
|
62
|
+
The function assumes that the `start_line_old` values in the hunk headers are correct,
|
|
63
|
+
but the line counts and `start_line_new` may be incorrect due to manual edits or errors.
|
|
64
|
+
|
|
65
|
+
Parameters:
|
|
66
|
+
git_diff (str): The git diff string to be corrected. It may contain multiple hunks
|
|
67
|
+
original_file_path (str): Path to the original file to calculate correct start_line_old
|
|
68
|
+
and incorrect hunk headers.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
str: The git diff string with corrected hunk headers.
|
|
72
|
+
|
|
73
|
+
The function works by parsing the diff, recalculating the line counts for each hunk,
|
|
74
|
+
adjusting the `start_line_new` values based on the cumulative changes from previous hunks,
|
|
75
|
+
and reconstructing the diff with corrected hunk headers.
|
|
76
|
+
|
|
77
|
+
Notes:
|
|
78
|
+
- The diff is expected to be in unified diff format.
|
|
79
|
+
- Lines starting with '+++', '---', or other file headers are not treated as additions or deletions.
|
|
80
|
+
- Context lines are lines that do not start with '+', '-', or '@@'.
|
|
81
|
+
- All lines in the hunk (including empty lines) are considered in the counts.
|
|
82
|
+
|
|
83
|
+
"""
|
|
84
|
+
# Split the diff into lines
|
|
85
|
+
lines = git_diff.split('\n')
|
|
86
|
+
|
|
87
|
+
# Check if this is a new file creation by looking for "new file mode" in the diff
|
|
88
|
+
is_new_file = any('new file mode 100644' in line for line in lines[:5])
|
|
89
|
+
original_content = []
|
|
90
|
+
|
|
91
|
+
if not is_new_file:
|
|
92
|
+
try:
|
|
93
|
+
with open(original_file_path, 'r') as f:
|
|
94
|
+
original_content = f.read().splitlines()
|
|
95
|
+
except FileNotFoundError:
|
|
96
|
+
error_msg = (
|
|
97
|
+
f"File {original_file_path} not found and diff does not indicate new file creation. "
|
|
98
|
+
)
|
|
99
|
+
raise FileNotFoundError(error_msg)
|
|
100
|
+
|
|
101
|
+
corrected_lines = []
|
|
102
|
+
line_index = 0
|
|
103
|
+
|
|
104
|
+
# Keep track of the cumulative line number adjustments
|
|
105
|
+
cumulative_line_offset = 0
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
while line_index < len(lines):
|
|
109
|
+
line = lines[line_index]
|
|
110
|
+
hunk_match = HUNK_HEADER_REGEX.match(line)
|
|
111
|
+
|
|
112
|
+
if hunk_match:
|
|
113
|
+
# Process the hunk
|
|
114
|
+
corrected_hunk_header, hunk_lines, line_index, line_offset = _process_hunk_with_original_content(
|
|
115
|
+
lines, line_index, cumulative_line_offset, original_content
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
# Update cumulative_line_offset
|
|
119
|
+
cumulative_line_offset += line_offset
|
|
120
|
+
|
|
121
|
+
# Append corrected hunk header and hunk lines
|
|
122
|
+
corrected_lines.append(corrected_hunk_header)
|
|
123
|
+
corrected_lines.extend(hunk_lines)
|
|
124
|
+
else:
|
|
125
|
+
# For non-hunk header lines, just append them
|
|
126
|
+
corrected_lines.append(line)
|
|
127
|
+
line_index += 1
|
|
128
|
+
|
|
129
|
+
# Join the corrected lines back into a string
|
|
130
|
+
corrected_diff = '\n'.join(corrected_lines)
|
|
131
|
+
return corrected_diff
|
|
132
|
+
|
|
133
|
+
def _find_correct_start_line(original_content: list, hunk_lines: list) -> int:
|
|
134
|
+
"""
|
|
135
|
+
Finds the correct starting line number in the original file by matching context and deleted lines.
|
|
136
|
+
|
|
137
|
+
Parameters:
|
|
138
|
+
original_content (list): List of lines from the original file
|
|
139
|
+
hunk_lines (list): List of lines in the current hunk
|
|
140
|
+
|
|
141
|
+
Returns:
|
|
142
|
+
int: The correct 1-based line number where the hunk should start in the original file
|
|
143
|
+
|
|
144
|
+
The function works by:
|
|
145
|
+
1. Extracting context and deleted lines from the hunk (ignoring added lines)
|
|
146
|
+
2. Creating a pattern from these lines
|
|
147
|
+
3. Finding where this pattern matches in the original file
|
|
148
|
+
4. Converting the matching position to a 1-based line number
|
|
149
|
+
"""
|
|
150
|
+
# Extract context and deleted lines from the hunk
|
|
151
|
+
if not original_content:
|
|
152
|
+
# Creating a new file.
|
|
153
|
+
return 1
|
|
154
|
+
|
|
155
|
+
if len(hunk_lines) < 3:
|
|
156
|
+
error_msg = (
|
|
157
|
+
f"Invalid git diff format: Expected at least 2 lines in the hunk, but got {len(hunk_lines)} lines.\n"
|
|
158
|
+
"Hunk content:\n{}".format('\n'.join(hunk_lines)))
|
|
159
|
+
logger.error(error_msg)
|
|
160
|
+
raise RuntimeError("git diff file is not valid.")
|
|
161
|
+
|
|
162
|
+
context_and_deleted = []
|
|
163
|
+
for line in hunk_lines:
|
|
164
|
+
if line.startswith(' ') or line.startswith('-'):
|
|
165
|
+
# Remove the prefix character
|
|
166
|
+
context_and_deleted.append(line[1:])
|
|
167
|
+
|
|
168
|
+
if not context_and_deleted:
|
|
169
|
+
error_msg = (
|
|
170
|
+
"Invalid git diff format: No context or deleted lines found in the hunk.\n"
|
|
171
|
+
"Each hunk must contain at least one context line (starting with space) "
|
|
172
|
+
"or deleted line (starting with '-').\n"
|
|
173
|
+
"Hunk content:\n{}".format('\n'.join(hunk_lines)))
|
|
174
|
+
raise RuntimeError(error_msg)
|
|
175
|
+
|
|
176
|
+
# Search for the pattern in the original file
|
|
177
|
+
pattern_length = len(context_and_deleted)
|
|
178
|
+
for i in range(len(original_content) - pattern_length + 1):
|
|
179
|
+
matches = True
|
|
180
|
+
for j in range(pattern_length):
|
|
181
|
+
if j >= len(context_and_deleted):
|
|
182
|
+
break
|
|
183
|
+
if i + j >= len(original_content) or original_content[i + j] != context_and_deleted[j]:
|
|
184
|
+
matches = False
|
|
185
|
+
break
|
|
186
|
+
if matches:
|
|
187
|
+
# Found the correct position git diff start with 1.
|
|
188
|
+
return i + 1
|
|
189
|
+
|
|
190
|
+
joined_context_and_deleted = '\n'.join(context_and_deleted)
|
|
191
|
+
error_msg = (
|
|
192
|
+
"Failed to locate the hunk position in the original file.\n"
|
|
193
|
+
"This usually happens when the context lines in the diff don't match the original file content.\n"
|
|
194
|
+
f"Context and deleted lines being searched:\n{joined_context_and_deleted}\n"
|
|
195
|
+
"Please ensure the diff is generated against the correct version of the file."
|
|
196
|
+
)
|
|
197
|
+
logger.error(error_msg)
|
|
198
|
+
raise RuntimeError(error_msg)
|
|
199
|
+
|
|
200
|
+
def _process_hunk_with_original_content(lines: list, start_index: int, cumulative_line_offset: int, original_content: list):
|
|
201
|
+
"""
|
|
202
|
+
Processes a single hunk starting at start_index in lines, recalculates the line counts,
|
|
203
|
+
and returns the corrected hunk header, hunk lines, and the updated index after the hunk.
|
|
204
|
+
|
|
205
|
+
Parameters:
|
|
206
|
+
lines (list): The list of lines from the diff.
|
|
207
|
+
start_index (int): The index in lines where the hunk header is located.
|
|
208
|
+
cumulative_line_offset (int): The cumulative line offset from previous hunks.
|
|
209
|
+
original_content (list): List of lines from the original file.
|
|
210
|
+
|
|
211
|
+
Returns:
|
|
212
|
+
tuple:
|
|
213
|
+
- corrected_hunk_header (str): The corrected hunk header.
|
|
214
|
+
- hunk_lines (list): The list of lines in the hunk (excluding the hunk header).
|
|
215
|
+
- end_index (int): The index in lines after the hunk.
|
|
216
|
+
- line_offset (int): The line offset caused by this hunk (to adjust future hunks).
|
|
217
|
+
|
|
218
|
+
The function reads the hunk lines, counts the number of lines in the original and new files,
|
|
219
|
+
and adjusts the starting line number in the new file based on cumulative changes.
|
|
220
|
+
"""
|
|
221
|
+
|
|
222
|
+
line_index = start_index
|
|
223
|
+
|
|
224
|
+
# Initialize counts for recalculation
|
|
225
|
+
actual_count_old = 0
|
|
226
|
+
actual_count_new = 0
|
|
227
|
+
|
|
228
|
+
# Move to the next line after the hunk header
|
|
229
|
+
line_index += 1
|
|
230
|
+
|
|
231
|
+
hunk_lines = []
|
|
232
|
+
|
|
233
|
+
# Collect hunk lines until the next hunk header or end of diff
|
|
234
|
+
while line_index < len(lines):
|
|
235
|
+
hunk_line = lines[line_index]
|
|
236
|
+
if HUNK_HEADER_REGEX.match(hunk_line):
|
|
237
|
+
break
|
|
238
|
+
else:
|
|
239
|
+
hunk_lines.append(hunk_line)
|
|
240
|
+
line_index += 1
|
|
241
|
+
|
|
242
|
+
# Find the correct start_line_old by matching context and deleted lines
|
|
243
|
+
start_line_old = _find_correct_start_line(original_content, hunk_lines)
|
|
244
|
+
|
|
245
|
+
# Now process hunk_lines to calculate counts
|
|
246
|
+
for hunk_line in hunk_lines:
|
|
247
|
+
if hunk_line.startswith('+') and not hunk_line.startswith('+++'):
|
|
248
|
+
actual_count_new += 1
|
|
249
|
+
elif hunk_line.startswith('-') and not hunk_line.startswith('---'):
|
|
250
|
+
actual_count_old += 1
|
|
251
|
+
else:
|
|
252
|
+
# Context line (unchanged line)
|
|
253
|
+
actual_count_old += 1
|
|
254
|
+
actual_count_new += 1
|
|
255
|
+
|
|
256
|
+
# Adjust start_line_new considering previous line offsets
|
|
257
|
+
corrected_start_line_new = start_line_old + cumulative_line_offset
|
|
258
|
+
|
|
259
|
+
# Calculate line offset for subsequent hunks
|
|
260
|
+
line_offset = actual_count_new - actual_count_old
|
|
261
|
+
|
|
262
|
+
# Reconstruct the corrected hunk header
|
|
263
|
+
corrected_hunk_header = _format_hunk_header(
|
|
264
|
+
start_line_old, actual_count_old, corrected_start_line_new, actual_count_new
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
return corrected_hunk_header, hunk_lines, line_index, line_offset
|
|
268
|
+
|
|
269
|
+
def _format_hunk_header(start_old: int, count_old: int, start_new: int, count_new: int) -> str:
|
|
270
|
+
"""
|
|
271
|
+
Formats the hunk header according to git diff syntax, omitting counts when they are 1.
|
|
272
|
+
|
|
273
|
+
Parameters:
|
|
274
|
+
start_old (int): Starting line number in the original file.
|
|
275
|
+
count_old (int): Number of lines in the hunk in the original file.
|
|
276
|
+
start_new (int): Starting line number in the new file.
|
|
277
|
+
count_new (int): Number of lines in the hunk in the new file.
|
|
278
|
+
|
|
279
|
+
Returns:
|
|
280
|
+
str: The formatted hunk header.
|
|
281
|
+
|
|
282
|
+
The hunk header format is:
|
|
283
|
+
@@ -start_old[,count_old] +start_new[,count_new] @@
|
|
284
|
+
|
|
285
|
+
If count_old or count_new is 1, the count is omitted.
|
|
286
|
+
"""
|
|
287
|
+
# Omit counts when they are equal to 1
|
|
288
|
+
old_part = f'-{start_old}'
|
|
289
|
+
if count_old != 1:
|
|
290
|
+
old_part += f',{count_old}'
|
|
291
|
+
new_part = f'+{start_new}'
|
|
292
|
+
if count_new != 1:
|
|
293
|
+
new_part += f',{count_new}'
|
|
294
|
+
return f'@@ {old_part} {new_part} @@'
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
if __name__ == '__main__':
|
|
299
|
+
# TODO: Create unit test and move these code to unit test
|
|
300
|
+
diff = """\
|
|
301
|
+
diff --git a/file.txt b/file.txt
|
|
302
|
+
index e69de29..4b825dc 100644
|
|
303
|
+
--- a/file.txt
|
|
304
|
+
+++ b/file.txt
|
|
305
|
+
@@ -1,5 +1,5 @@
|
|
306
|
+
Line one
|
|
307
|
+
+Line two
|
|
308
|
+
Line three
|
|
309
|
+
Line four
|
|
310
|
+
Line five
|
|
311
|
+
@@ -10,2 +10,2 @@
|
|
312
|
+
Line ten
|
|
313
|
+
-Line eleven
|
|
314
|
+
+Line eleven modified"""
|
|
315
|
+
print(correct_git_diff(diff,""))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "ziya"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.43"
|
|
4
4
|
description = ""
|
|
5
5
|
authors = ["Vishnu Krishnaprasad <vishnukool@gmail.com>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -18,6 +18,7 @@ tiktoken = "^0.8.0"
|
|
|
18
18
|
boto3 = "^1.34.88"
|
|
19
19
|
langchain-aws = ">=0.2,<0.3"
|
|
20
20
|
langchain = ">=0.3,<0.4"
|
|
21
|
+
langgraph = ">=0.2,<0.3"
|
|
21
22
|
langchainhub = ">=0.1.15"
|
|
22
23
|
langchain-anthropic = ">=0.2,<0.3"
|
|
23
24
|
langchain-cli = ">=0.0.15"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": {
|
|
3
3
|
"main.css": "/static/css/main.8af23da0.css",
|
|
4
|
-
"main.js": "/static/js/main.
|
|
4
|
+
"main.js": "/static/js/main.50c95184.js",
|
|
5
5
|
"static/media/fa-solid-900.ttf": "/static/media/fa-solid-900.bacd5de623fb563b961a.ttf",
|
|
6
6
|
"static/media/fa-brands-400.ttf": "/static/media/fa-brands-400.60127e352b7a11f7f1bc.ttf",
|
|
7
7
|
"static/media/fa-solid-900.woff2": "/static/media/fa-solid-900.4d986b00ff9ca3828fbd.woff2",
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
"static/media/fa-v4compatibility.woff2": "/static/media/fa-v4compatibility.cf7f5903d06b79ad60f1.woff2",
|
|
13
13
|
"index.html": "/index.html",
|
|
14
14
|
"main.8af23da0.css.map": "/static/css/main.8af23da0.css.map",
|
|
15
|
-
"main.
|
|
15
|
+
"main.50c95184.js.map": "/static/js/main.50c95184.js.map"
|
|
16
16
|
},
|
|
17
17
|
"entrypoints": [
|
|
18
18
|
"static/css/main.8af23da0.css",
|
|
19
|
-
"static/js/main.
|
|
19
|
+
"static/js/main.50c95184.js"
|
|
20
20
|
]
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Ziya - Code Assistant</title><link rel="icon" href="/favicon.ico" type="image/x-icon"><script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script><script defer="defer" src="/static/js/main.
|
|
1
|
+
<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Ziya - Code Assistant</title><link rel="icon" href="/favicon.ico" type="image/x-icon"><script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script><script>window.enableCodeApply="true"</script><script defer="defer" src="/static/js/main.50c95184.js"></script><link href="/static/css/main.8af23da0.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
|