stapp: stabilize long-session streaming and add runtime stats
This commit is contained in:
1 parent
fb9ea53c3a
commit
a3a626af89
3 files changed
+94
-43
No files matched your search
@@ -208,15 +208,15 @@ def file_patch(path: str, old_content: str, new_content: str):
|
||||
"""在文件中寻找唯一的 old_content 块并替换为 new_content"""
|
||||
path = str(Path(path).resolve())
|
||||
try:
|
||||
if not os.path.exists(path): return {"status": "error", "msg": "文件不存在"}
|
||||
if not os.path.exists(path): return {"status": "error", "msg": "file not found"}
|
||||
with open(path, 'r', encoding='utf-8') as f: full_text = f.read()
|
||||
if not old_content: return {"status": "error", "msg": "old_content 为空,请确认 arguments"}
|
||||
if not old_content: return {"status": "error", "msg": "old_content is blank"}
|
||||
count = full_text.count(old_content)
|
||||
if count == 0: return {"status": "error", "msg": "未找到匹配的旧文本块,建议:先用 file_read 确认当前内容,再分小段进行 patch。若多次失败则询问用户,严禁自行使用 overwrite 或代码替换。"}
|
||||
if count > 1: return {"status": "error", "msg": f"找到 {count} 处匹配,无法确定唯一位置。请提供更长、更具体的旧文本块以确保唯一性。建议:包含上下文行来增强特征,或分小段逐个修改。"}
|
||||
if count == 0: return {"status": "error", "msg": "old_content is not found. Suggestion: use file_read to check current file content, make more small patches. Don't huge overwrite (even with code)"}
|
||||
if count > 1: return {"status": "error", "msg": f"find {count} matches, unable to determine unique position. Provide a longer, more specific old_content to ensure uniqueness. Suggestion: include context lines to enhance features, or modify in smaller segments."}
|
||||
updated_text = full_text.replace(old_content, new_content)
|
||||
with open(path, 'w', encoding='utf-8', newline=_file_newline(path)) as f: f.write(updated_text)
|
||||
return {"status": "success", "msg": "文件局部修改成功"}
|
||||
return {"status": "success", "msg": "file patched successfully"}
|
||||
except Exception as e: return {"status": "error", "msg": str(e)}
|
||||
|
||||
_read_dirs = set()
|
||||
@@ -312,7 +312,8 @@ class GenericAgentHandler(BaseHandler):
|
||||
cwd = os.path.normpath(os.path.abspath(raw_path))
|
||||
code_cwd = os.path.normpath(self.cwd)
|
||||
maxlen = self._get_tool_maxlen(10000, args)
|
||||
if code_type == 'python' and _arg(args, "inline_eval", False, bool):
|
||||
if timeout > 600: result = '[ERROR] Timeout must be <= 600 seconds, run time-consuming code in background subprocess and monitor it!'
|
||||
elif code_type == 'python' and _arg(args, "inline_eval", False, bool):
|
||||
ns = {'handler':self, 'parent':self.parent, 'history':json.dumps(self.parent.llmclient.backend.history)}
|
||||
old_cwd = os.getcwd()
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user