# SyncTide Supervisor

This package adds four operational features around the existing local-machine deployment:

- crash recovery with restart backoff and persisted supervisor state
- backup/export tools
- repair mode
- optional Windows service mode for backend and ingestion worker

## Files

- `platform_supervisor.py` / `platform_supervisor.pyw` — tray supervisor with crash recovery
- `start_platform_tray.bat` — launch helper
- `backup_platform.ps1` — creates backups or support bundles
- `repair_local.ps1` — validates files, tests DB, optionally reinstalls dependencies, reapplies bootstrap
- `ingestion_watchdog.py` — loop runner for service mode ingestion
- `install_services.ps1` — registers backend and ingestion services
- `remove_services.ps1` — unregisters those services
- `run_backend_service.bat` / `run_ingestion_service.bat` — service entry wrappers
- `requirements_supervisor.txt` — adds supervisor dependencies

## Install dependencies

```powershell
.\.venv\Scripts\python.exe -m pip install -r requirements_supervisor.txt
```

## Start tray supervisor

```powershell
.\start_platform_tray.bat
```

## Backup / export

Full backup:

```powershell
powershell -ExecutionPolicy Bypass -File .\backup_platform.ps1
```

Support bundle only:

```powershell
powershell -ExecutionPolicy Bypass -File .\backup_platform.ps1 -SupportBundleOnly
```

## Repair mode

Standard repair:

```powershell
powershell -ExecutionPolicy Bypass -File .\repair_local.ps1
```

Repair + reinstall dependencies:

```powershell
powershell -ExecutionPolicy Bypass -File .\repair_local.ps1 -ReinstallDependencies
```

## Optional service mode

Install backend + ingestion services:

```powershell
powershell -ExecutionPolicy Bypass -File .\install_services.ps1
```

Remove services:

```powershell
powershell -ExecutionPolicy Bypass -File .\remove_services.ps1
```

## Notes

- Service mode is optional. The tray supervisor is still the simplest operator experience.
- The UI is intentionally left tray-managed rather than Windows-service managed.
- `backup_platform.ps1` uses `pg_dump` if it is found in `PATH`.
- `repair_local.ps1` uses the current `init_db.py` and `.env`-driven DB connection.
