# Tasks: LLM Dataset Orchestration

**Feature Branch**: `027-dataset-llm-orchestration`
**Implementation Plan**: [`specs/027-dataset-llm-orchestration/plan.md`](/home/busya/dev/ss-tools/specs/027-dataset-llm-orchestration/plan.md)

---

## Rebaseline Note

This task list is rebaselined to the approved mixed-initiative assistant scope from `027-task.md`.

Previously completed implementation checkboxes remain historical only. They are no longer treated as authoritative for feature acceptance until the codebase is aligned with the refreshed spec artifacts below.

---

## Phase A: Spec Refresh Gate

- [x] T001 Refresh `ux_reference.md` to replace modal clarification with `AssistantChatPanel` mixed-initiative behavior
- [x] T002 Refresh `spec.md` to update FR-013 and add FR-045/FR-046
- [x] T003 Refresh `contracts/api.yaml` to add `dataset_review_session_id` to `AssistantMessageRequest` and expose session version in session DTOs
- [x] T004 Refresh `data-model.md` to add optimistic-lock `version` and PII masking requirements for `ImportedFilter.raw_value`
- [x] T005 Refresh `contracts/modules.md` to route clarification through `AssistantChatPanel`, expose orchestrator state to `AssistantApi`, and retire `ClarificationDialog`

---

## Phase B: Backend Rebaseline Work

- [ ] T006 Implement optimistic locking in `backend/src/services/dataset_review/repositories/session_repository.py` using `DatasetReviewSession.version` and conflict semantics
- [ ] T007 Update dataset review session schemas and route handlers to require and return session version consistently
- [ ] T008 Add `dataset_review_session_id` to `backend/src/api/routes/assistant.py::AssistantMessageRequest`
- [ ] T009 Load dataset-review context into assistant planning flow when `dataset_review_session_id` is present
- [ ] T010 Add assistant intent routing for dataset-review commands (`APPROVE_MAPPINGS`, `SET_FIELD_SEMANTICS`, `GENERATE_SQL_PREVIEW`) through `DatasetReviewOrchestrator`
- [ ] T011 Add PII masking/redaction for imported filter values before assistant or LLM-facing context assembly
- [ ] T012 Preserve backend mutation observability with semantic logging and conflict-safe mutation boundaries

---

## Phase C: Frontend Rebaseline Work

- [ ] T013 Integrate `AssistantChatPanel` into `frontend/src/routes/datasets/review/[id]/+page.svelte` as the clarification surface
- [ ] T014 Remove or retire `ClarificationDialog` usage from the dataset review workflow
- [ ] T015 Add inline **[✨ Ask AI]** / **[✨ Improve]** triggers for findings, partial filters, mappings, and business summary surfaces
- [ ] T016 Add workspace highlight synchronization when assistant prompts reference `field_id`, `filter_id`, mapping, or finding targets
- [ ] T017 Render assistant confirmation cards for state-changing actions tied to dataset review sessions
- [ ] T018 Update SQL preview refresh behavior so rapid mapping changes produce `stale` state and debounce/explicit regeneration behavior

---

## Phase D: Validation After Rebaseline

- [ ] T019 Verify feature behavior against refreshed `ux_reference.md`, especially mixed-initiative clarification and context actions
- [ ] T020 Verify WYSIWWR, Superset-only SQL compilation, session-version conflict handling, and PII masking boundaries
- [ ] T021 Run semantic audit for updated 027 contracts before implementation handoff closure

---

## Dependencies & Strategy

### Delivery Order
1. **Spec Refresh Gate**
2. **Backend optimistic locking and assistant routing**
3. **Frontend assistant-panel integration and contextual UX**
4. **Validation and semantic audit**

### Scope Invariants
- Keep feature work bounded to `027-dataset-llm-orchestration` implementation surfaces.
- Preserve **WYSIWWR** and Superset-only SQL compilation.
- Do not allow assistant commands to bypass explicit approval or launch gates.
- Keep i18n, Tailwind-first UI, `requestApi` / `fetchApi`, and `TaskManager` conventions intact.
