feat(06-task-title-ai): complete OpenAI task title suggestions
Phase 6 complete: - add AI title generator service using gpt-5-nano - add task popup button for biuro@project-pro.pl - add AJAX endpoint returning title suggestions without auto-save
This commit is contained in:
201
.paul/phases/06-task-title-ai/06-01-PLAN.md
Normal file
201
.paul/phases/06-task-title-ai/06-01-PLAN.md
Normal file
@@ -0,0 +1,201 @@
|
||||
---
|
||||
phase: 06-task-title-ai
|
||||
plan: 01
|
||||
type: execute
|
||||
wave: 1
|
||||
depends_on: []
|
||||
files_modified:
|
||||
- config.php
|
||||
- autoload/Domain/Tasks/TaskTitleGenerator.php
|
||||
- autoload/controls/class.Tasks.php
|
||||
- templates/tasks/task_popup.php
|
||||
autonomous: false
|
||||
delegation: off
|
||||
---
|
||||
|
||||
<objective>
|
||||
## Goal
|
||||
Dodac w popupie edycji zadania przycisk generowania propozycji tytulu zadania przez OpenAI na podstawie tresci zadania.
|
||||
|
||||
## Purpose
|
||||
Uzytkownik `biuro@project-pro.pl` ma szybciej nadawac czytelne tytuly zadaniom bez recznego streszczania opisu.
|
||||
|
||||
## Output
|
||||
- Przycisk AI obok istniejacego przycisku edycji tytulu w `task_popup`.
|
||||
- Osobny endpoint AJAX zwracajacy wygenerowana propozycje tytulu.
|
||||
- Serwis domenowy do komunikacji z OpenAI, uzywajacy taniego i szybkiego modelu `gpt-5-nano`.
|
||||
- Konfiguracja modelu tytulow niezalezna od importu maili.
|
||||
</objective>
|
||||
|
||||
<context>
|
||||
<clarifications>
|
||||
- **[Widocznosc]** - Czy `biuro@project-pro.pl` oznacza zalogowanego uzytkownika czy zadania przypisane do tego uzytkownika?
|
||||
-> Odpowiedz: tylko zalogowany uzytkownik z tym emailem widzi przycisk.
|
||||
- **[Zapis]** - Czy AI ma od razu nadpisac tytul w bazie czy tylko wstawic propozycje do pola?
|
||||
-> Odpowiedz: opcja A, wstawic propozycje do pola tytulu i zapisac dopiero istniejacym przyciskiem.
|
||||
- **[Model]** - Czy uzyc `gpt-5-nano` jako tani/szybki model?
|
||||
-> Odpowiedz: tak.
|
||||
</clarifications>
|
||||
|
||||
## Project Context
|
||||
@.paul/PROJECT.md
|
||||
@.paul/ROADMAP.md
|
||||
@.paul/STATE.md
|
||||
|
||||
## Source Files
|
||||
@config.php
|
||||
@autoload/Domain/Tasks/MailToTaskImporter.php
|
||||
@autoload/controls/class.Tasks.php
|
||||
@templates/tasks/task_popup.php
|
||||
@templates/tasks/main_view.php
|
||||
|
||||
## External References
|
||||
- OpenAI model docs: https://developers.openai.com/api/docs/models/gpt-5-nano
|
||||
- `gpt-5-nano` supports `v1/chat/completions` and is documented as the fastest/cheapest GPT-5 option for summarization/classification-style work.
|
||||
</context>
|
||||
|
||||
<acceptance_criteria>
|
||||
|
||||
## AC-1: Przycisk widoczny tylko dla biuro
|
||||
```gherkin
|
||||
Given zalogowany uzytkownik ma email biuro@project-pro.pl
|
||||
When otwiera popup zadania
|
||||
Then obok przycisku edycji tytulu widzi przycisk generowania tytulu AI
|
||||
```
|
||||
|
||||
## AC-2: Brak przycisku dla innych uzytkownikow
|
||||
```gherkin
|
||||
Given zalogowany uzytkownik ma inny email niz biuro@project-pro.pl
|
||||
When otwiera popup zadania
|
||||
Then przycisk generowania tytulu AI nie jest renderowany
|
||||
And endpoint generowania odrzuca zadanie bez wywolania OpenAI
|
||||
```
|
||||
|
||||
## AC-3: AI generuje propozycje bez zapisu do bazy
|
||||
```gherkin
|
||||
Given uzytkownik biuro@project-pro.pl otwiera popup zadania z trescia
|
||||
When klika przycisk generowania tytulu AI
|
||||
Then system pobiera tresc zadania i zwraca krotka propozycje tytulu
|
||||
And propozycja trafia do pola edycji tytulu
|
||||
And tytul w bazie nie zmienia sie przed kliknieciem istniejacego przycisku zapisu
|
||||
```
|
||||
|
||||
## AC-4: Obsluga bledow OpenAI jest czytelna
|
||||
```gherkin
|
||||
Given brakuje klucza API OpenAI albo OpenAI zwroci blad
|
||||
When uzytkownik klika generowanie tytulu
|
||||
Then popup pokazuje czytelny komunikat bledu
|
||||
And aktualny tytul zadania nie zostaje zmieniony
|
||||
```
|
||||
|
||||
</acceptance_criteria>
|
||||
|
||||
<tasks>
|
||||
|
||||
<task type="auto">
|
||||
<name>Task 1: Dodac serwis generowania tytulu przez OpenAI</name>
|
||||
<files>config.php, autoload/Domain/Tasks/TaskTitleGenerator.php</files>
|
||||
<action>
|
||||
Dodac konfiguracje `openai_task_title_model` z domyslna wartoscia `gpt-5-nano`.
|
||||
Utworzyc klase domenowa `Domain\Tasks\TaskTitleGenerator`, ktora:
|
||||
- przyjmuje klucz API i model z konfiguracji,
|
||||
- usuwa HTML z tresci zadania przed wyslaniem,
|
||||
- wysyla krotki prompt do `https://api.openai.com/v1/chat/completions`,
|
||||
- wymusza pojedynczy, krotki tytul bez JSON i bez dodatkowego komentarza,
|
||||
- ogranicza dlugosc wejscia i wyjscia,
|
||||
- zwraca tablice sukces/blad bez rzucania nieobslugiwanych wyjatkow.
|
||||
Reuzyc wzorce z `MailToTaskImporter`, ale nie uzalezniac nowej funkcji od importera maili.
|
||||
Dla modeli `gpt-5*` uzyc parametru `max_completion_tokens`; dla pozostalych zostawic kompatybilny fallback.
|
||||
</action>
|
||||
<verify>C:\xampp\php\php.exe -l autoload/Domain/Tasks/TaskTitleGenerator.php</verify>
|
||||
<done>AC-3 i AC-4 maja pokrycie po stronie integracji OpenAI</done>
|
||||
</task>
|
||||
|
||||
<task type="auto">
|
||||
<name>Task 2: Dodac endpoint AJAX dla propozycji tytulu</name>
|
||||
<files>autoload/controls/class.Tasks.php</files>
|
||||
<action>
|
||||
Dodac metode kontrolera np. `task_generate_title`, ktora:
|
||||
- wymaga zalogowanego uzytkownika,
|
||||
- sprawdza `strtolower($user['email']) === 'biuro@project-pro.pl'`,
|
||||
- pobiera `task_id` jako int i odczytuje zadanie przez `factory\Tasks::task_details`,
|
||||
- odrzuca brak zadania lub pusta tresc komunikatem JSON,
|
||||
- wywoluje `TaskTitleGenerator`,
|
||||
- zwraca JSON `{status: "success", title: "..."}` albo `{status: "error", msg: "..."}`.
|
||||
Endpoint nie moze zapisywac `tasks.name`; zapis pozostaje w istniejacym `/tasks/task_change_title/`.
|
||||
Uzyc medoo/prepared statements przez istniejace metody lub medoo API, bez skladania SQL.
|
||||
</action>
|
||||
<verify>C:\xampp\php\php.exe -l autoload/controls/class.Tasks.php</verify>
|
||||
<done>AC-2, AC-3 i AC-4 spelnione po stronie backendu</done>
|
||||
</task>
|
||||
|
||||
<task type="auto">
|
||||
<name>Task 3: Dodac przycisk i obsluge UI w popupie zadania</name>
|
||||
<files>templates/tasks/task_popup.php</files>
|
||||
<action>
|
||||
Rozszerzyc widok tytulu w popupie:
|
||||
- wyrenderowac przycisk AI tylko gdy `$this->user['email']` to `biuro@project-pro.pl`,
|
||||
- ustawic przycisk obok istniejacego przycisku edycji tytulu,
|
||||
- po kliknieciu pokazac stan ladowania i wywolac `/tasks/task_generate_title/`,
|
||||
- po sukcesie otworzyc inline edycje tytulu i wpisac propozycje do `.task-title-input`,
|
||||
- nie klikac automatycznie `.task-title-save`,
|
||||
- po bledzie pokazac komunikat i zostawic aktualny tytul bez zmian.
|
||||
Zachowac istniejacy mechanizm recznej edycji i zapisu tytulu.
|
||||
Escapowac dane w widoku; nie wprowadzac logiki OpenAI do widoku.
|
||||
</action>
|
||||
<verify>C:\xampp\php\php.exe -l templates/tasks/task_popup.php</verify>
|
||||
<done>AC-1, AC-2 i AC-3 spelnione w UI</done>
|
||||
</task>
|
||||
|
||||
<task type="checkpoint:human-verify" gate="blocking">
|
||||
<what-built>Przycisk AI w popupie zadania oraz generowanie propozycji tytulu do pola edycji.</what-built>
|
||||
<how-to-verify>
|
||||
1. Zaloguj sie jako `biuro@project-pro.pl`.
|
||||
2. Otworz liste zadan i popup zadania z niepusta trescia.
|
||||
3. Kliknij przycisk AI obok edycji tytulu.
|
||||
4. Potwierdz, ze pole edycji tytulu wypelnia sie propozycja, ale tytul zapisuje sie dopiero po kliknieciu istniejacego przycisku zapisu.
|
||||
5. Sprawdz u innego uzytkownika, ze przycisk nie jest widoczny.
|
||||
</how-to-verify>
|
||||
<resume-signal>Napisz "approved", jesli dziala, albo opisz blad do poprawy.</resume-signal>
|
||||
</task>
|
||||
|
||||
</tasks>
|
||||
|
||||
<boundaries>
|
||||
|
||||
## DO NOT CHANGE
|
||||
- Nie zmieniac istniejacego endpointu `/tasks/task_change_title/` poza ewentualna minimalna walidacja, jesli bedzie konieczna.
|
||||
- Nie zmieniac importu maili w `MailToTaskImporter`.
|
||||
- Nie dodawac nowych bibliotek ani zaleznosci Composer.
|
||||
- Nie zmieniac schematu bazy danych.
|
||||
|
||||
## SCOPE LIMITS
|
||||
- Funkcja dotyczy tylko popupu zadania, nie pelnego formularza `task_edit`.
|
||||
- AI generuje tylko propozycje tytulu; nie generuje ani nie zmienia tresci zadania.
|
||||
- Przycisk jest dostepny tylko dla zalogowanego `biuro@project-pro.pl`.
|
||||
- Brak automatycznego zapisu tytulu po generowaniu.
|
||||
|
||||
</boundaries>
|
||||
|
||||
<verification>
|
||||
Before declaring plan complete:
|
||||
- [ ] `C:\xampp\php\php.exe -l config.php`
|
||||
- [ ] `C:\xampp\php\php.exe -l autoload/Domain/Tasks/TaskTitleGenerator.php`
|
||||
- [ ] `C:\xampp\php\php.exe -l autoload/controls/class.Tasks.php`
|
||||
- [ ] `C:\xampp\php\php.exe -l templates/tasks/task_popup.php`
|
||||
- [ ] Reczna proba jako `biuro@project-pro.pl`: przycisk widoczny i generuje propozycje do pola.
|
||||
- [ ] Reczna proba jako inny uzytkownik: przycisk niewidoczny, endpoint odrzuca dostep.
|
||||
- [ ] Reczna proba potwierdza, ze baza zmienia tytul dopiero po istniejacym zapisie.
|
||||
- [ ] Wszystkie AC spelnione.
|
||||
</verification>
|
||||
|
||||
<success_criteria>
|
||||
- `biuro@project-pro.pl` moze wygenerowac krotki tytul z tresci zadania w popupie.
|
||||
- Wygenerowany tytul jest tylko propozycja w polu edycji, bez automatycznego zapisu.
|
||||
- Inni uzytkownicy nie widza przycisku i nie moga uzyc endpointu.
|
||||
- Bledy OpenAI nie psuja popupu i nie zmieniaja danych.
|
||||
</success_criteria>
|
||||
|
||||
<output>
|
||||
Po wykonaniu utworz `.paul/phases/06-task-title-ai/06-01-SUMMARY.md`.
|
||||
</output>
|
||||
144
.paul/phases/06-task-title-ai/06-01-SUMMARY.md
Normal file
144
.paul/phases/06-task-title-ai/06-01-SUMMARY.md
Normal file
@@ -0,0 +1,144 @@
|
||||
---
|
||||
phase: 06-task-title-ai
|
||||
plan: 01
|
||||
subsystem: tasks-ai-ui
|
||||
tags: [tasks, openai, popup, ajax, gpt-5-nano]
|
||||
requires: []
|
||||
provides:
|
||||
- AI title suggestion button in task popup for biuro@project-pro.pl
|
||||
- AJAX endpoint returning title suggestions without saving task name
|
||||
- Domain service for OpenAI task title generation
|
||||
affects: [tasks, openai-integration]
|
||||
tech-stack:
|
||||
added: []
|
||||
patterns: [domain-service-openai, ajax-suggestion-with-explicit-save]
|
||||
key-files:
|
||||
created:
|
||||
- autoload/Domain/Tasks/TaskTitleGenerator.php
|
||||
modified:
|
||||
- config.php
|
||||
- autoload/controls/class.Tasks.php
|
||||
- templates/tasks/task_popup.php
|
||||
key-decisions:
|
||||
- "AI title button visible only for logged-in biuro@project-pro.pl"
|
||||
- "Generated title is inserted into the inline input and saved only by existing save action"
|
||||
- "Task title model defaults to gpt-5-nano"
|
||||
patterns-established:
|
||||
- "OpenAI task-title generation is isolated in Domain\\Tasks\\TaskTitleGenerator"
|
||||
- "Popup AI actions must return suggestions, not persist task data directly"
|
||||
duration: 35min
|
||||
started: 2026-05-04T23:10:00+02:00
|
||||
completed: 2026-05-04T23:45:00+02:00
|
||||
---
|
||||
|
||||
# Phase 6 Plan 01: AI Task Title Summary
|
||||
|
||||
AI title suggestions now work in the task popup for `biuro@project-pro.pl`, inserting a short bezosobowy title proposal into the existing title input without automatic database save.
|
||||
|
||||
## Performance
|
||||
|
||||
| Metric | Value |
|
||||
|--------|-------|
|
||||
| Duration | ~35min |
|
||||
| Started | 2026-05-04T23:10:00+02:00 |
|
||||
| Completed | 2026-05-04T23:45:00+02:00 |
|
||||
| Tasks | 3 auto tasks + 1 human verification checkpoint |
|
||||
| Files modified | 4 source/config files + PAUL docs |
|
||||
|
||||
## Acceptance Criteria Results
|
||||
|
||||
| Criterion | Status | Notes |
|
||||
|-----------|--------|-------|
|
||||
| AC-1: Przycisk widoczny tylko dla biuro | Pass | `task_popup.php` renders AI button only when logged-in user email is `biuro@project-pro.pl`. |
|
||||
| AC-2: Brak przycisku dla innych uzytkownikow | Pass | UI condition hides button; backend endpoint checks the same email before calling OpenAI. |
|
||||
| AC-3: AI generuje propozycje bez zapisu do bazy | Pass | `/tasks/task_generate_title/` returns JSON with `title`; JS inserts it into `.task-title-input`; existing `/tasks/task_change_title/` remains the only save path. |
|
||||
| AC-4: Obsluga bledow OpenAI jest czytelna | Pass | Service returns `{status:error,msg}` for missing key, empty task text, cURL/API errors, and empty OpenAI content; UI shows alert and leaves title unchanged. |
|
||||
|
||||
## Accomplishments
|
||||
|
||||
- Added `Domain\Tasks\TaskTitleGenerator` to encapsulate OpenAI title generation.
|
||||
- Added `$settings['openai_task_title_model'] = 'gpt-5-nano'` for task-title generation independent from email import parsing.
|
||||
- Added `/tasks/task_generate_title/` AJAX endpoint with user/email gate and no write to `tasks.name`.
|
||||
- Added AI button in task popup, loading state, AJAX call, and insertion of the generated suggestion into the existing inline title editor.
|
||||
- Adjusted GPT-5 request for practical output by using `reasoning_effort = minimal` and larger `max_completion_tokens`.
|
||||
- Refined prompt so titles are short, bezosobowe, and rzeczownikowe, e.g. `Usuniecie bloku o firmie`.
|
||||
|
||||
## Files Created/Modified
|
||||
|
||||
| File | Change | Purpose |
|
||||
|------|--------|---------|
|
||||
| `autoload/Domain/Tasks/TaskTitleGenerator.php` | Created | OpenAI client/service for short task title suggestions. |
|
||||
| `config.php` | Modified | Added `openai_task_title_model` defaulting to `gpt-5-nano`. |
|
||||
| `autoload/controls/class.Tasks.php` | Modified | Added `task_generate_title()` endpoint with authorization and JSON response. |
|
||||
| `templates/tasks/task_popup.php` | Modified | Added conditional AI button and client-side generation flow. |
|
||||
| `.paul/phases/06-task-title-ai/06-01-PLAN.md` | Created | Formal PAUL plan for the phase. |
|
||||
| `.paul/phases/06-task-title-ai/06-01-SUMMARY.md` | Created | This execution summary. |
|
||||
|
||||
## Verification Results
|
||||
|
||||
| Check | Result |
|
||||
|-------|--------|
|
||||
| `C:\xampp\php\php.exe -l config.php` | Pass |
|
||||
| `C:\xampp\php\php.exe -l autoload/Domain/Tasks/TaskTitleGenerator.php` | Pass |
|
||||
| `C:\xampp\php\php.exe -l autoload/controls/class.Tasks.php` | Pass |
|
||||
| `C:\xampp\php\php.exe -l templates/tasks/task_popup.php` | Pass |
|
||||
| Manual user verification | Pass after prompt/token fix; user confirmed OK. |
|
||||
|
||||
## Decisions Made
|
||||
|
||||
| Decision | Rationale | Impact |
|
||||
|----------|-----------|--------|
|
||||
| Use `gpt-5-nano` | User asked for cheap/fast model and approved this model. | Separate setting avoids changing email import behavior. |
|
||||
| Insert suggestion only, do not auto-save | User selected safer UX. | Existing save path remains authoritative. |
|
||||
| Gate by logged-in email | User clarified scope. | Both UI and backend enforce `biuro@project-pro.pl`. |
|
||||
| Use bezosobowy prompt | User requested shorter non-personal titles. | AI output better matches CRM task naming convention. |
|
||||
|
||||
## Deviations from Plan
|
||||
|
||||
### Summary
|
||||
|
||||
| Type | Count | Impact |
|
||||
|------|-------|--------|
|
||||
| Auto-fixed | 2 | Necessary fixes for GPT-5 output reliability and title style. |
|
||||
| Scope additions | 0 | No scope creep. |
|
||||
| Deferred | 0 | None. |
|
||||
|
||||
### Auto-fixed Issues
|
||||
|
||||
**1. GPT-5 empty content with low completion limit**
|
||||
- **Found during:** Human verification
|
||||
- **Issue:** OpenAI returned HTTP 200 but no usable `message.content`, resulting in `OpenAI nie zwrocil poprawnego tytulu.`
|
||||
- **Fix:** Added `reasoning_effort = minimal` and raised `max_completion_tokens` to 500 for `gpt-5*` models.
|
||||
- **Files:** `autoload/Domain/Tasks/TaskTitleGenerator.php`
|
||||
- **Verification:** `php -l` passed; user continued testing.
|
||||
|
||||
**2. Prompt title style too broad**
|
||||
- **Found during:** Human verification
|
||||
- **Issue:** User wanted bezosobowy, shortened titles such as `Usuniecie bloku o firmie`.
|
||||
- **Fix:** Prompt now requires max 6 words, noun-like bezosobowa form, no imperative verbs.
|
||||
- **Files:** `autoload/Domain/Tasks/TaskTitleGenerator.php`
|
||||
- **Verification:** `php -l` passed; user confirmed OK.
|
||||
|
||||
## Issues Encountered
|
||||
|
||||
| Issue | Resolution |
|
||||
|-------|------------|
|
||||
| `apply_patch` could not update files with legacy encoding reliably | Used PowerShell with project file encoding for existing files; new PHP service was rewritten UTF-8 without BOM after `php -l` caught BOM before namespace. |
|
||||
| Initial CSS insertion in popup selector block was malformed | Corrected CSS selector block and reran `php -l`. |
|
||||
|
||||
## Next Phase Readiness
|
||||
|
||||
**Ready:**
|
||||
- Phase 6 is complete and can be used from the task popup.
|
||||
- OpenAI title generation is isolated and configurable.
|
||||
- Phase 2 critical bug fixes can resume next.
|
||||
|
||||
**Concerns:**
|
||||
- Existing OpenAI API key remains in `config.php`; this was pre-existing and not changed except for adding the model setting.
|
||||
|
||||
**Blockers:**
|
||||
- None.
|
||||
|
||||
---
|
||||
*Phase: 06-task-title-ai, Plan: 01*
|
||||
*Completed: 2026-05-04*
|
||||
Reference in New Issue
Block a user