Files
agent-zero/plugins/_a0_cleaner/api/cleaner.py
Alessandro c641619a77 Add A0Cleaner with automatic bulk cleanup and weekly maintenance
Clean aged download caches, installer leftovers, retired browser profiles, inactive-chat screenshots, temporary captures and unused Chromium versions by default. Preserve explicit master and per-area opt-outs; keep embedding caches and custom folders behind manual selection and confirmation.

Add bounded metadata scans, identity-checked deletion, active-resource protection, persistent activity, editable native scheduler integration and actionable A0 notifications. Provide a responsive branded UI and a 256px thumbnail based on the Agent Zero logo.

Validate with 65 focused backend tests, 6 frontend tests and live desktop/mobile checks on localhost:32081. The native task cleaned 88,833 files (4.4 GB) in about 22 seconds; protected chat text, uploads, shared browser data, required Chromium and embeddings were preserved.
2026-11-13 11:24:18 +01:00

34 lines
1.7 KiB
Python

import asyncio
from helpers.api import ApiHandler, Request, Response
from plugins._a0_cleaner.helpers import runtime
from plugins._a0_cleaner.helpers.cleaner import CleanerError, read_json
class A0CleanerApi(ApiHandler):
async def process(self, input: dict, request: Request) -> dict | Response:
try:
action = input.get('action', 'status')
cleaner = runtime.service()
if action == 'status':
result = await asyncio.to_thread(cleaner.latest)
result['schedule'] = await runtime.schedule_info()
result['scheduled'] = read_json(cleaner.state/'scheduled.json')
return {'ok': True, **result}
if action == 'scan':
return {'ok': True, 'report': await asyncio.to_thread(cleaner.scan)}
if action == 'preview':
return {'ok': True, 'preview': await asyncio.to_thread(cleaner.preview, input.get('scan_id'), input.get('groups'))}
if action == 'clean':
return {'ok': True, **await asyncio.to_thread(cleaner.clean, input.get('scan_id'), input.get('groups'), confirmed=input.get('confirmed'))}
if action == 'settings':
settings = input.get('settings')
if not isinstance(settings, dict):
raise CleanerError('Invalid cleanup settings.')
return {'ok': True, 'config': await asyncio.to_thread(runtime.save_settings, settings)}
if action == 'schedule':
return {'ok': True, 'schedule': await runtime.set_schedule(input.get('cadence'))}
raise CleanerError('Unknown cleaner action.')
except (CleanerError, OSError) as exc:
return {'ok': False, 'error': str(exc)}