5.2 KiB
Tasks: Context-Aware Prompt Templates & Database Typo Cleanup
Input: Design documents from /specs/200-fullstacks/230-context-aware-prompt-templates/
Prerequisites: plan.md (required), spec.md (required for user stories), research.md, data-model.md, quickstart.md
Organization: Tasks are grouped by user story to enable independent implementation and testing of each story.
Format: [ID] [P?] [Story] Description
- [P]: Can run in parallel (different files, no dependencies)
- [Story]: Which user story this task belongs to (e.g., US1, US2, US3)
- Include exact file paths in descriptions
Phase 1: Setup (Shared Infrastructure)
Purpose: Project initialization and basic structure
- T001 Create project directory structure for
specs/200-fullstacks/230-context-aware-prompt-templates/ - T002 Ensure the git branch
mainis active and clean
Phase 2: Foundational (Blocking Prerequisites)
Purpose: Core database and entity modifications that blocking all other user stories
- T003 [P] Modify
schema-02-tables.sqlline 338 to change ENUM('TO', 'CC ') to ENUM('TO', 'CC') inspecs/03-Data-and-Storage/lcbp3-v1.9.0-schema-02-tables.sql - T004 Create MariaDB SQL delta file at
specs/03-Data-and-Storage/deltas/2026-05-27-add-context-aware-prompts-and-cleanup.sqlto altercorrespondence_recipientsenum andai_promptscontext_config column - T005 [P] Create MariaDB SQL rollback delta file at
specs/03-Data-and-Storage/deltas/2026-05-27-add-context-aware-prompts-and-cleanup.rollback.sql - T006 Update
AiPromptentity insidebackend/src/modules/ai/entities/ai-prompt.entity.tsto includecontextConfigcolumn mapping tocontext_configJSON
Checkpoint: Foundation ready - database structures and base entities mapped.
Phase 3: User Story 1 - OCR Metadata Extraction with Project Context (Priority: P1) 🎯 MVP
Goal: Implement contextual master data aggregation and injection into OCR prompts.
Independent Test: Verify that prompt generation includes project context master data, and recipients are successfully outputted as an Object Array.
Implementation for User Story 1
- T007 [P] [US1] Define
CreateAiPromptDtoandUpdateAiPromptDtoenhancements insidebackend/src/modules/ai/dto/to supportcontextConfigfields - T008 [US1] Implement
AiPromptsService.resolveContext()inbackend/src/modules/ai/services/ai-prompts.service.tsto fetch projects, tags, organizations based oncontext_configfilters - T009 [US1] Update
AiBatchProcessorinsidebackend/src/modules/ai/processors/ai-batch.processor.tsto inject resolved master data context into the OCR template execution flow - T010 [US1] Update OCR JSON output parse rules in
backend/src/modules/ai/processors/ai-batch.processor.tsto extractrecipientsfrom the newly defined array of objects model - T011 [US1] Add Thai prompt template seed script as version 2 inside
specs/03-Data-and-Storage/deltas/2026-05-27-add-context-aware-prompts-and-cleanup.sql
Checkpoint: User Story 1 MVP fully functional.
Phase 4: User Story 2 - Cross-Project Data Isolation Safeguard (Priority: P2)
Goal: Secure endpoints against unauthorized cross-project data leakage.
Independent Test: API throws ForbiddenException when requesting a project override that is not allowed by prompt config.
Implementation for User Story 2
- T012 [US2] Implement override verification logic inside
AiPromptsService.resolveContext()inbackend/src/modules/ai/services/ai-prompts.service.tsto block cross-project requests - T013 [US2] Implement unit testing inside
backend/tests/unit/ai-prompts.service.spec.tsasserting strictForbiddenExceptionthrows on override attempts
Checkpoint: Security barriers tested and locked.
Phase 5: User Story 3 - Database Cleanup of Typo Whitespaces (Priority: P3)
Goal: Sanitize all database records and frontend detail filtering to remove the whitespace CC bug.
Independent Test: Details page handles filtering of recipient types correctly without whitespace checks.
Implementation for User Story 3
- T014 [US3] Execute SQL data modification script inside
2026-05-27-add-context-aware-prompts-and-cleanup.sqlto update all existing'CC 'values to'CC' - T015 [P] [US3] Normalize frontend detail CC filter checks inside
frontend/components/correspondences/detail.tsx
Checkpoint: Typo fully cleaned up.
Phase 6: Polish & Cross-Cutting Concerns
Purpose: Run checks, type checking, and compile validations.
- T016 Run type verification using
pnpm --filter backend build - T017 Run unit and integration tests inside backend suite
- T018 Execute validation using
quickstart.mdprocedures
Dependencies & Execution Order
Phase Dependencies
- Setup (Phase 1): Can start immediately.
- Foundational (Phase 2): Depends on Phase 1 - Blocks all User Stories.
- User Stories (Phase 3+): All depend on Phase 2.
- Polish (Phase 6): Depends on all user stories being complete.
Implementation Strategy
MVP First (User Story 1 Only)
- Complete Phase 1: Setup
- Complete Phase 2: Foundational
- Complete Phase 3: User Story 1
- Validate Story 1 (MVP is functional)