# Tasks: Refactor CLI Scripts to Web Application

**Feature**: Refactor CLI Scripts to Web Application
**Status**: Completed
**Spec**: [specs/010-refactor-cli-to-web/spec.md](specs/010-refactor-cli-to-web/spec.md)

## Phase 1: Core & Infrastructure
*Goal: Enhance TaskManager to support returning results and set up Connection management.*

- [x] T001 Create `backend/src/models/connection.py` with `ConnectionConfig` model (ensure secure storage of credentials)
- [x] T002 Update `backend/src/core/task_manager/models.py` to add `result: Optional[Dict[str, Any]]` field to `Task` model
- [x] T003 Update `backend/src/core/task_manager/manager.py` to capture `plugin.execute` return value and store it in `task.result`
- [x] T004 [P] Create `frontend/src/services/toolsService.js` for generic Task API communication (run task, poll status, get result)
- [x] T005 [P] Create `frontend/src/services/connectionService.js` for Connection API
- [x] T006 Create `frontend/src/components/tools/` directory structure

## Phase 2: User Story 1 - Search Datasets
*Goal: Enable users to search datasets via the Web UI using a Plugin.*

- [x] T007 [US1] Implement `SearchPlugin` in `backend/src/plugins/search.py` (port logic from `search_script.py`, return results)
- [x] T008 [US1] Create `frontend/src/components/tools/SearchTool.svelte` component (triggers SearchPlugin, displays results)
- [x] T009 [US1] Create `frontend/src/routes/tools/search/+page.svelte` page

## Phase 3: User Story 2 - Map Dataset Columns
*Goal: Enable users to map columns using saved connections via a Plugin.*

- [x] T010 [US2] Create API endpoints for Connections (`GET`, `POST`, `DELETE`) in `backend/src/api/routes/connections.py`
- [x] T011 [US2] Register `connections` router in `backend/src/api/routes/__init__.py`
- [x] T012 [US2] Implement `MapperPlugin` in `backend/src/plugins/mapper.py` (port logic from `run_mapper.py`, support `connection_id`)
- [x] T013 [US2] Create `frontend/src/components/tools/ConnectionForm.svelte` and `ConnectionList.svelte`
- [x] T014 [US2] Create `frontend/src/routes/settings/connections/+page.svelte` for managing connections
- [x] T015 [US2] Create `frontend/src/components/tools/MapperTool.svelte` component
- [x] T016 [US2] Create `frontend/src/routes/tools/mapper/+page.svelte` page

## Phase 4: User Story 3 - System Debugging
*Goal: Enable users to run system diagnostics via a Plugin.*

- [x] T017 [US3] Implement `DebugPlugin` in `backend/src/plugins/debug.py` (port logic from `debug_db_api.py`, `get_dataset_structure.py`)
- [x] T018 [US3] Create `frontend/src/components/tools/DebugTool.svelte` component
- [x] T019 [US3] Create `frontend/src/routes/tools/debug/+page.svelte` page

## Phase 5: Cleanup & Polish
*Goal: Remove legacy scripts and ensure system stability.*

- [x] T020 Verify all new tools are functional (Manual Test)
- [x] T021 Verify existing Backup functionality fully covers legacy `backup_script.py` capabilities
- [x] T022 Remove legacy script `search_script.py`
- [x] T023 Remove legacy script `run_mapper.py`
- [x] T024 Remove legacy script `debug_db_api.py`
- [x] T025 Remove legacy script `get_dataset_structure.py`
- [x] T026 Remove legacy script `backup_script.py`
- [x] T027 Update main navigation in `frontend/src/components/Navbar.svelte` to include "Tools" dropdown

## Dependencies

- Phase 2 (Search) depends on Phase 1 (Task Result support)
- Phase 3 (Mapper) depends on Phase 1 (Connection Model)
- Phase 4 (Debug) depends on Phase 1 (Task Result support)
- Phase 5 (Cleanup) depends on Phase 2, 3, 4 completion

## Implementation Strategy

1.  **Core**: Upgrade TaskManager first to support return values.
2.  **Search**: Implement SearchPlugin as the first "Result-returning" plugin.
3.  **Connections**: Build connection management.
4.  **Mapper**: Implement MapperPlugin using Connections.
5.  **Debug**: Implement DebugPlugin.
6.  **Cleanup**: Verify and delete.