Skip to content

Commit ac91a8a

Browse files
authored
Merge pull request #22 from BrunoV21/process-patch
Process patch
2 parents 971f386 + 958113a commit ac91a8a

9 files changed

Lines changed: 34 additions & 30 deletions

File tree

codetide/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ async def from_path(
8686

8787
codeTide._add_results_to_codebase(results)
8888
codeTide._resolve_files_dependencies()
89-
logger.info(f"\n{CODETIDE_ASCII_ART}\nInitialized with {len(results)} files processed in {time.time() - st:.2f}s")
89+
print(f"\n{CODETIDE_ASCII_ART}\n")
90+
logger.info(f"Initialized with {len(results)} files processed in {time.time() - st:.2f}s")
9091

9192
return codeTide
9293

codetide/agents/tide/agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ async def _stage(self)->str:
191191
for path in self.changed_paths:
192192
index.add(path)
193193

194+
index.write()
195+
194196
staged_diff = await self.get_git_diff_staged_simple(self.tide.rootpath)
195197
staged_diff = staged_diff.strip()
196198
return staged_diff if staged_diff else "No files were staged. Nothing to commit. Tell the user to request some changes so there is something to commit"
@@ -275,7 +277,8 @@ def _(event):
275277
# 2. Create a prompt session with the custom key bindings
276278
session = PromptSession(key_bindings=bindings)
277279

278-
_logger.logger.info(f"\n{AGENT_TIDE_ASCII_ART}\nReady to surf. Press ESC to exit.\n")
280+
print(f"\n{AGENT_TIDE_ASCII_ART}\n")
281+
_logger.logger.info("Ready to surf. Press ESC to exit.")
279282
try:
280283
while True:
281284
try:

codetide/agents/tide/consts.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
AGENT_TIDE_ASCII_ART = """
2-
3-
█████╗ ██████╗ ███████╗███╗ ██╗████████╗ ████████╗██╗██████╗ ███████╗
4-
██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝ ╚══██╔══╝██║██╔══██╗██╔════╝
5-
███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║ ██║ ██║██║ ██║█████╗
6-
██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║ ██║ ██║██║ ██║██╔══╝
7-
██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║ ██║ ██║██████╔╝███████╗
8-
╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝
9-
2+
\033[1;38;5;25m█████╗ ██████╗ ███████╗███╗ ██╗████████╗ ████████╗██╗██████╗ ███████╗\033[0m
3+
\033[1;38;5;33m██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝ ╚══██╔══╝██║██╔══██╗██╔════╝\033[0m
4+
\033[1;38;5;39m███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║ ██║ ██║██║ ██║█████╗\033[0m
5+
\033[1;38;5;45m██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║ ██║ ██║██║ ██║██╔══╝\033[0m
6+
\033[1;38;5;51m██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║ ██║ ██║██████╔╝███████╗\033[0m
7+
\033[1;38;5;255m╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝\033[0m
108
"""

codetide/agents/tide/ui/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
321321
break
322322

323323
await stream_processor.process_chunk(chunk)
324-
324+
325+
await asyncio.sleep(0.5)
325326
if agent_tide_ui.agent_tide.steps:
326327
cl.user_session.set("latest_step_message", msg)
327328
msg.actions = [
@@ -355,7 +356,6 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
355356
chat_history.append({"role": "assistant", "content": msg.content})
356357
await agent_tide_ui.add_to_history(msg.content)
357358

358-
await asyncio.sleep(0.5)
359359
if agent_tide_ui.agent_tide._has_patch:
360360
choice = await cl.AskActionMessage(
361361
content="AgentTide is asking you to review the Patch before applying it.",

codetide/agents/tide/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,24 @@ def parse_patch_blocks(text: str, multiple: bool = True) -> Union[str, List[str]
5757

5858
def parse_commit_blocks(text: str, multiple: bool = True) -> Union[str, List[str], None]:
5959
"""
60-
Extract content between *** Begin Patch and *** End Patch markers (inclusive),
60+
Extract content between *** Begin Commit and *** End Commit markers (exclusive),
6161
ensuring that both markers are at zero indentation (start of line, no leading spaces).
6262
6363
Args:
64-
text: Full input text containing one or more patch blocks.
65-
multiple: If True, return a list of all patch blocks. If False, return the first match.
64+
text: Full input text containing one or more commit blocks.
65+
multiple: If True, return a list of all commit blocks. If False, return the first match.
6666
6767
Returns:
68-
A string (single patch), list of strings (multiple patches), or None if not found.
68+
A string (single commit), list of strings (multiple commits), or None if not found.
6969
"""
7070

71-
pattern = r"(?m)^(\*\*\* Begin Commit[\s\S]*?^\*\*\* End Commit)$"
71+
pattern = r"(?m)^\*\*\* Begin Commit\n([\s\S]*?)^\*\*\* End Commit$"
7272
matches = re.findall(pattern, text)
7373

7474
if not matches:
7575
return None
7676

77-
return matches if multiple else matches[0]
77+
return matches if multiple else matches[0].strip()
7878

7979
def parse_steps_markdown(md: str):
8080
steps = []

codetide/core/defaults.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,10 @@
9292
DEFAULT_BYTES_CONTENT_PLACEHOLDERS = "< suppressed bytes content >"
9393

9494
CODETIDE_ASCII_ART = """
95-
96-
███████╗ ██████╗ ██████╗ ███████╗████████╗██╗██████╗ ███████╗
97-
██╔════╝██╔═══██╗██╔══██╗██╔════╝╚══██╔══╝██║██╔══██╗██╔════╝
98-
██║ ██║ ██║██║ ██║█████╗ ██║ ██║██║ ██║█████╗
99-
██║ ██║ ██║██║ ██║██╔══╝ ██║ ██║██║ ██║██╔══╝
100-
╚██████╗╚██████╔╝██████╔╝███████╗ ██║ ██║██████╔╝███████╗
101-
╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝
102-
95+
\033[1;38;5;25m███████╗ ██████╗ ██████╗ ███████╗████████╗██╗██████╗ ███████╗\033[0m
96+
\033[1;38;5;33m██╔════╝██╔═══██╗██╔══██╗██╔════╝╚══██╔══╝██║██╔══██╗██╔════╝\033[0m
97+
\033[1;38;5;39m██║ ██║ ██║██║ ██║█████╗ ██║ ██║██║ ██║█████╗\033[0m
98+
\033[1;38;5;45m██║ ██║ ██║██║ ██║██╔══╝ ██║ ██║██║ ██║██╔══╝\033[0m
99+
\033[1;38;5;51m╚██████╗╚██████╔╝██████╔╝███████╗ ██║ ██║██████╔╝███████╗\033[0m
100+
\033[1;38;5;255m ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝╚═════╝ ╚══════╝\033[0m
103101
"""

codetide/mcp/tools/patch_code/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# --------------------------------------------------------------------------- #
1111
# User-facing API
1212
# --------------------------------------------------------------------------- #
13-
def text_to_patch(text: str, orig: Dict[str, str]) -> Tuple[Patch, int]:
13+
def text_to_patch(text: str, orig: Dict[str, str], rootpath: Optional[pathlib.Path]=None) -> Tuple[Patch, int]:
1414
"""Improved version with better splitlines handling."""
1515
lines = text.splitlines()
1616

@@ -37,7 +37,7 @@ def text_to_patch(text: str, orig: Dict[str, str]) -> Tuple[Patch, int]:
3737
if not lines or not Parser._norm(lines[-1]) == "*** End Patch":
3838
raise DiffError(f"Invalid patch text - must end with '*** End Patch'. Found: '{lines[-1] if lines else 'empty'}'")
3939

40-
parser = Parser(current_files=orig, lines=lines, index=1)
40+
parser = Parser(current_files=orig, lines=lines, index=1, rootpath=rootpath)
4141
parser.parse()
4242
return parser.patch, parser.fuzz
4343

@@ -138,7 +138,7 @@ def process_patch(
138138
path = str(root_path / path)
139139
orig_files[path] = open_fn(path)
140140

141-
patch, _fuzz = text_to_patch(text, orig_files)
141+
patch, _fuzz = text_to_patch(text, orig_files, rootpath=root_path)
142142
commit = patch_to_commit(patch, orig_files)
143143

144144
apply_commit(commit, write_fn, remove_fn, exists_fn)

codetide/mcp/tools/patch_code/parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from typing import Dict, List, Optional, Tuple, Union
44
from dataclasses import dataclass, field
5+
from pathlib import Path
56

67
# --------------------------------------------------------------------------- #
78
# Helper functions for parsing update chunks
@@ -218,6 +219,7 @@ class Parser:
218219
index: int = 0
219220
patch: Patch = field(default_factory=Patch)
220221
fuzz: int = 0
222+
rootpath: Optional[Path]=None
221223

222224
def _cur_line(self) -> str:
223225
if self.index >= len(self.lines):
@@ -261,6 +263,8 @@ def parse(self) -> None:
261263
while not self.is_done(("*** End Patch",)):
262264
# ---------- UPDATE ---------- #
263265
if path := self.read_str("*** Update File: "):
266+
if self.rootpath is not None:
267+
path = str(self.rootpath / path)
264268
if path in self.patch.actions:
265269
raise DiffError(f"Duplicate update for file: {path}")
266270
move_to = self.read_str("*** Move to: ")

examples/hf_demo_space/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
355355

356356
await stream_processor.process_chunk(chunk)
357357

358+
await asyncio.sleep(0.5)
358359
if agent_tide_ui.agent_tide.steps:
359360
cl.user_session.set("latest_step_message", msg)
360361
msg.actions = [
@@ -397,7 +398,6 @@ async def agent_loop(message: Optional[cl.Message]=None, codeIdentifiers: Option
397398
chat_history.append({"role": "assistant", "content": msg.content})
398399
await agent_tide_ui.add_to_history(msg.content)
399400

400-
await asyncio.sleep(0.5)
401401
if agent_tide_ui.agent_tide._has_patch:
402402
choice = await cl.AskActionMessage(
403403
content="AgentTide is asking you to review the Patch before applying it.",

0 commit comments

Comments
 (0)