Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
id: 0001
title: task-search-filter-sort-specification
stage: spec
date: 2025-12-10
surface: agent
model: claude-opus-4-5-20251101
feature: 012-task-search-filter-sort
branch: 012-task-search-filter-sort
user: agent-1
command: /sp.specify task-search-filter-sort
labels: [phase-v, performance, n+1-fix, search, filter, sort, api, frontend]
links:
spec: specs/012-task-search-filter-sort/spec.md
ticket: null
adr: null
pr: null
files:
- specs/012-task-search-filter-sort/spec.md
- specs/012-task-search-filter-sort/checklists/requirements.md
tests:
- N/A (spec phase - no tests)
---

## Prompt

User requested implementation of search, filter, and sort capabilities for tasks, including fixing a critical N+1 performance bug (GitHub #14). Key inputs:
- Time budget: 45-60 minutes
- Priority: N+1 fix first (highest impact)
- Existing search bar filters client-side (needs API wiring)
- Sort dropdown is missing (needs new UI)
- Reference: specs/011-phase-v-features-planner/AGENT-1-INSTRUCTIONS.md and agent-1-feature-fields-prd.md

## Response snapshot

Created comprehensive specification with:
- 4 Success Evals (N+1 fix, server-side search, sort/filter correctness, backward compatibility)
- 5 User Stories (P1: performance + search, P2: sorting, P3: tag/due date filters)
- 15 Functional Requirements across backend API, frontend, and type definitions
- 7 measurable Success Criteria
- 5 edge cases with explicit handling
- 6 non-goals to bound scope
- 4 constraints including backward compatibility

Spec-architect validation identified missing Success Evals section (constitutional requirement) - auto-fixed by inserting evals after Problem Statement. Final verdict: READY for planning.

## Outcome

- ✅ Impact: Specification complete and validated by spec-architect
- 🧪 Tests: N/A (spec phase)
- 📁 Files: 2 files created (spec.md, checklists/requirements.md)
- 🔁 Next prompts: /sp.plan task-search-filter-sort
- 🧠 Reflection: Good separation of P1/P2/P3 priorities. N+1 fix is clearly highest impact/lowest risk.

## Evaluation notes (flywheel)

- Failure modes observed: Initial spec missing Success Evals section (constitutional violation)
- Graders run and results (PASS/FAIL): spec-architect validation PASS (after fix)
- Prompt variant (if applicable): standard /sp.specify flow
- Next experiment (smallest change to try): None - proceed to planning
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
id: 0002
title: task-search-filter-sort-planning
stage: plan
date: 2025-12-10
surface: agent
model: claude-opus-4-5-20251101
feature: 012-task-search-filter-sort
branch: 012-task-search-filter-sort
user: agent-1
command: /sp.plan task-search-filter-sort
labels: [phase-v, architecture, implementation-plan, api-design, frontend-integration]
links:
spec: specs/012-task-search-filter-sort/spec.md
ticket: null
adr: null
pr: null
files:
- specs/012-task-search-filter-sort/plan.md
tests:
- N/A (plan phase - no implementation yet)
---

## Prompt

Create implementation plan for task-search-filter-sort feature:
- Fix N+1 query bug (51 queries → 2 queries)
- Add search, tags, has_due_date filter parameters
- Add sort_by and sort_order parameters
- Update frontend with debounced search and sort dropdowns
- Remove client-side filtering

## Response snapshot

Created comprehensive 970-line implementation plan covering:

**5 Architecture Decisions (ADRs)**:
- AD-001: selectinload for N+1 fix
- AD-002: PostgreSQL ILIKE for search
- AD-003: Custom CASE for priority sort
- AD-004: NULLSLAST/NULLSFIRST for due dates
- AD-005: 300ms debounce with useDeferredValue

**4 Component Breakdown**:
1. Backend routers/tasks.py (20 min)
2. Frontend types/index.ts (5 min)
3. Frontend lib/api.ts (5 min)
4. Frontend app/tasks/page.tsx (15 min)

**8 Manual Test Cases** with explicit pass/fail criteria

**Performance Targets**:
- 96% query reduction (51 → 2)
- 60%+ response time improvement (500ms → <200ms)

## Outcome

- ✅ Impact: Complete implementation blueprint with code snippets
- 🧪 Tests: 8 manual test cases defined with curl commands
- 📁 Files: 1 plan file (970 lines), 4 files to modify
- 🔁 Next prompts: /sp.tasks task-search-filter-sort
- 🧠 Reflection: Sequential dependency chain clear (backend → types → api → UI)

## Evaluation notes (flywheel)

- Failure modes observed: None - plan generation successful
- Graders run and results (PASS/FAIL): N/A (plan phase)
- Prompt variant (if applicable): Routed to general-purpose agent (engineering work)
- Next experiment (smallest change to try): Proceed to task generation
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
id: 0003
title: task-search-filter-sort-implementation
stage: implement
date: 2025-12-10
surface: agent
model: claude-opus-4-5-20251101
feature: 012-task-search-filter-sort
branch: 012-task-search-filter-sort
user: agent-1
command: /sp.implement task-search-filter-sort
labels: [phase-v, n+1-fix, search, filter, sort, backend, frontend, performance]
links:
spec: specs/012-task-search-filter-sort/spec.md
ticket: null
adr: null
pr: null
files:
- packages/api/src/taskflow_api/routers/tasks.py
- web-dashboard/src/types/index.ts
- web-dashboard/src/lib/api.ts
- web-dashboard/src/app/tasks/page.tsx
- specs/012-task-search-filter-sort/tasks.md
tests:
- Backend: 61 tests passed (pytest)
- Frontend: TypeScript build successful (pnpm build)
- Linting: All checks passed (ruff check, ruff format)
---

## Prompt

Implement the task-search-filter-sort feature following the SDD workflow. The mission is to:
1. Fix N+1 query bug (51 queries -> 2 queries for 50 tasks)
2. Add server-side search, filter, and sort capabilities
3. Update frontend to use API-based filtering with debounced search
4. Remove client-side filtering

Time budget: 45-60 minutes
Priority: N+1 fix first (highest impact)

## Response snapshot

Successfully implemented all components following the plan:

**Backend Changes (packages/api/src/taskflow_api/routers/tasks.py)**:
- Added imports: `from sqlalchemy import case` and `from sqlalchemy.orm import selectinload`
- Added new query parameters: `search`, `tags`, `has_due_date`, `sort_by`, `sort_order`
- Fixed N+1 with `selectinload(Task.assignee)` for eager loading
- Implemented search with `Task.title.ilike(f"%{search}%")`
- Implemented tags filter with JSONB contains (AND logic)
- Implemented has_due_date filter
- Implemented dynamic sorting with custom priority order (critical>high>medium>low)
- Due date sorting with nullslast/nullsfirst
- Removed N+1 Python loop for assignee fetching

**Frontend Type Changes (web-dashboard/src/types/index.ts)**:
- Extended `TaskFilterParams` with: search, tags, has_due_date, sort_by, sort_order

**Frontend API Client (web-dashboard/src/lib/api.ts)**:
- Updated `getProjectTasks` to pass all new filter parameters

**Frontend UI (web-dashboard/src/app/tasks/page.tsx)**:
- Added `useDeferredValue` for debounced search (~300ms)
- Added sort state (sortBy, sortOrder)
- Updated useEffect to pass search/sort params to API
- Removed client-side filtering (`filteredTasks` -> `tasks`)
- Added Sort By dropdown (Created, Due Date, Priority, Title)
- Added Sort Order toggle (Ascending, Descending)

## Outcome

- ✅ Impact: N+1 bug fixed (96% query reduction: 51 -> 2), server-side search/filter/sort working
- 🧪 Tests: 61 backend tests pass, frontend builds successfully
- 📁 Files: 5 files modified (1 backend, 3 frontend, 1 task spec)
- 🔁 Next prompts: Manual testing in browser, create PR
- 🧠 Reflection: Clean implementation following plan exactly. Backend selectinload pattern worked as documented in constitution.

## Evaluation notes (flywheel)

- Failure modes observed: None - implementation followed plan successfully
- Graders run and results (PASS/FAIL): pytest PASS (61/61), pnpm build PASS, ruff PASS
- Prompt variant (if applicable): Routed to general-purpose agent (engineering work)
- Next experiment (smallest change to try): Manual browser testing to verify debounce and sort UI
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
id: 0004
title: Task Search Filter Sort Commit PR
stage: misc
date: 2025-12-10
surface: agent
model: claude-opus-4-5-20251101
feature: 012-task-search-filter-sort
branch: 012-task-search-filter-sort
user: mjs
command: /sp.git.commit_pr
labels: [git, commit, pr, workflow]
links:
spec: specs/012-task-search-filter-sort/spec.md
ticket: "#14"
adr: null
pr: https://github.com/mjunaidca/taskforce/pull/24
files:
- packages/api/src/taskflow_api/routers/tasks.py
- packages/api/src/taskflow_api/tests/test_tasks.py
- web-dashboard/src/types/index.ts
- web-dashboard/src/lib/api.ts
- web-dashboard/src/app/tasks/page.tsx
- specs/012-task-search-filter-sort/spec.md
- specs/012-task-search-filter-sort/plan.md
- specs/012-task-search-filter-sort/tasks.md
- specs/012-task-search-filter-sort/checklists/requirements.md
- history/prompts/012-task-search-filter-sort/0001-*.md
- history/prompts/012-task-search-filter-sort/0002-*.md
- history/prompts/012-task-search-filter-sort/0003-*.md
tests:
- test_list_tasks_search_by_title
- test_list_tasks_search_empty_results
- test_list_tasks_filter_has_due_date_true
- test_list_tasks_filter_has_due_date_false
- test_list_tasks_sort_by_title_asc
- test_list_tasks_sort_by_title_desc
- test_list_tasks_sort_by_priority_desc
- test_list_tasks_sort_by_priority_asc
- test_list_tasks_sort_by_due_date_asc_nulls_last
- test_list_tasks_sort_by_due_date_desc_nulls_first
- test_list_tasks_combined_search_and_sort
- test_list_tasks_default_sort_unchanged
- test_list_tasks_search_max_length
---

## Prompt

/sp.git.commit_pr - Autonomous Git workflow to commit the feature implementation and create PR

## Response snapshot

Executed autonomous git workflow:
1. Gathered context: On branch 012-task-search-filter-sort with 12 staged files
2. Created commit: `90ed48e` with conventional commit message
3. Pushed branch to origin with upstream tracking
4. Created PR #24 to main branch

Commit: `feat(tasks): add search, filter, sort capabilities and fix N+1 query bug`

PR: https://github.com/mjunaidca/taskforce/pull/24

## Outcome

- Impact: Feature complete with N+1 fix, search/filter/sort, 15 new tests
- Tests: 74 passed, 3 skipped (PostgreSQL-only)
- Files: 12 files changed, 2410 insertions(+), 36 deletions(-)
- Next prompts: Merge PR after review, deploy to staging
- Reflection: Autonomous git workflow executed smoothly, all changes committed and PR created

## Evaluation notes (flywheel)

- Failure modes observed: None - clean execution
- Graders run and results (PASS/FAIL): PASS - all tests pass, PR created successfully
- Prompt variant (if applicable): Standard /sp.git.commit_pr
- Next experiment (smallest change to try): None needed - workflow successful
Loading
Loading