Show actual file changes recorded for each Agent task

This commit is contained in:
WebUp Cloud committed 2026-11-08 09:10:32 +08:00
1 parent d04777247b
commit 3296d378c9
14 files changed
+453 -16

No files matched your search

+31 -4
View File
@@ -54,6 +54,7 @@ app.include_router(domain_router)
class Tool(BaseModel):
name: str = Field(max_length=40)
arguments: dict
trackChanges: bool = False
def authorize(value: str | None):
@@ -201,6 +202,17 @@ import pathlib,os,json,base64,subprocess,signal,tempfile
args=json.loads(base64.b64decode(PAYLOAD))
root=pathlib.Path('/workspace').resolve()
name=args['name']; values=args['arguments']
track_changes = args.get('trackChanges') and name in {'write_file', 'delete_file', 'run_command'}
temporary = None
before_complete = False
if track_changes:
try:
temporary = tempfile.TemporaryDirectory(prefix='webup-changes-', ignore_cleanup_errors=True)
change_dir = pathlib.Path(temporary.name)
snapshot_changes(root, change_dir / 'before')
before_complete = True
except (OSError, ValueError):
pass
def path(value):
if not isinstance(value,str) or len(value)>1000: raise ValueError('Invalid path')
target=(root/value).resolve()
@@ -288,11 +300,23 @@ try:
if not target.is_file(): raise ValueError('Only individual files may be deleted')
target.unlink();result={'deleted':True}
else: raise ValueError('Unknown tool')
print(json.dumps(result,ensure_ascii=False))
except Exception as exc:
print(json.dumps({'error':str(exc)[:500]}))
result = {'error': str(exc)[:500]}
if track_changes:
result['fileChanges'] = {'complete': False, 'files': []}
try:
if before_complete:
snapshot_changes(root, change_dir / 'after')
result['fileChanges'] = summarize_changes(change_dir)
except (OSError, ValueError, subprocess.SubprocessError):
pass
finally:
if temporary is not None:
temporary.cleanup()
print(json.dumps(result, ensure_ascii=True if track_changes else False))
'''
SCRIPT = Path(__file__).with_name('review_tools.py').read_text(encoding='utf-8') + '\n' + SCRIPT
SCRIPT = '\n'.join(Path(__file__).with_name(name).read_text(encoding='utf-8')
for name in ('review_tools.py', 'workspace_changes.py')) + '\n' + SCRIPT
def read_exec_output(connection, limit):
@@ -385,7 +409,10 @@ def execute_tool(project,request,authorization,review):
except Exception:
connection.close()
raise
output = read_exec_output(connection, 16_000_000 if request.name in {'archive_source','review_export'} else MAX_OUTPUT)
output_limit = 16_000_000 if request.name in {'archive_source','review_export'} else MAX_OUTPUT
if request.trackChanges:
output_limit = 512_000
output = read_exec_output(connection, output_limit)
try:
return json.loads(output)
except ValueError: