feat: enhance weekly report and realtime notifications

Weekly Report (fix-weekly-report):
- Remove 5-task limit, show all tasks per category
- Add blocked tasks with blocker_reason and blocked_since
- Add next week tasks (due in coming week)
- Add assignee_name, completed_at, days_overdue to task details
- Frontend collapsible sections for each task category
- 8 new tests for enhanced report content

Realtime Notifications (fix-realtime-notifications):
- SQLAlchemy event-based notification publishing
- Redis Pub/Sub for multi-process broadcast
- Fix soft rollback handler stacking issue
- Fix ping scheduling drift (send immediately when interval expires)
- Frontend NotificationContext with WebSocket reconnection

Spec Fixes:
- Add missing ## Purpose sections to 5 specs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
beabigegg
2025-12-30 20:52:08 +08:00
parent 10db2c9d1f
commit 64874d5425
25 changed files with 1034 additions and 140 deletions

View File

@@ -0,0 +1,119 @@
## Context
automation spec 定義週報須包含:已完成、進行中、逾期、阻礙中、下週預計任務清單。現行實作僅提供數量統計與部分摘要。
## Goals / Non-Goals
**Goals:**
- 週報內容包含完整任務清單
- 新增阻礙中任務清單
- 新增下週預計完成任務清單
**Non-Goals:**
- 不實作週報自訂欄位篩選
- 不實作週報匯出 PDF/Excel
## Decisions
### 1. 週報內容結構
**Decision:** 擴充 content JSON 結構
**Current:**
```json
{
"summary": { "completed_count": 5, "in_progress_count": 3, ... },
"projects": [
{
"completed_tasks": [{"id": "...", "title": "..."}], // 限制 5 筆
"overdue_tasks": [...] // 限制 5 筆
}
]
}
```
**Proposed:**
```json
{
"summary": {
"completed_count": 5,
"in_progress_count": 3,
"overdue_count": 2,
"blocked_count": 1,
"next_week_count": 4,
"total_tasks": 15
},
"projects": [
{
"project_id": "uuid",
"project_title": "Project Name",
"completed_tasks": [
{"id": "...", "title": "...", "completed_at": "ISO8601", "assignee_name": "..."}
],
"in_progress_tasks": [
{"id": "...", "title": "...", "assignee_name": "...", "due_date": "ISO8601"}
],
"overdue_tasks": [
{"id": "...", "title": "...", "due_date": "ISO8601", "days_overdue": 3}
],
"blocked_tasks": [
{"id": "...", "title": "...", "blocker_reason": "...", "blocked_since": "ISO8601"}
],
"next_week_tasks": [
{"id": "...", "title": "...", "due_date": "ISO8601", "assignee_name": "..."}
]
}
]
}
```
### 2. 阻礙任務識別
**Decision:** 查詢 Blocker 表關聯
```python
# 取得有未解除阻礙的任務
blocked_task_ids = db.query(Blocker.task_id).filter(
Blocker.resolved_at.is_(None)
).subquery()
blocked_tasks = db.query(Task).filter(
Task.project_id.in_(project_ids),
Task.id.in_(blocked_task_ids)
).all()
```
### 3. 下週預計任務
**Decision:** due_date 在下週一至週日
```python
next_week_start = week_end # 本週末 = 下週初
next_week_end = next_week_start + timedelta(days=7)
next_week_tasks = db.query(Task).filter(
Task.project_id.in_(project_ids),
Task.due_date >= next_week_start,
Task.due_date < next_week_end,
Task.status.not_in(["done", "completed"])
).all()
```
### 4. 任務明細欄位
**Decision:** 包含以下欄位供顯示
| 任務類型 | 額外欄位 |
|---------|---------|
| completed | completed_at (updated_at), assignee_name |
| in_progress | assignee_name, due_date |
| overdue | due_date, days_overdue |
| blocked | blocker_reason, blocked_since |
| next_week | due_date, assignee_name |
## Risks / Trade-offs
| Risk | Mitigation |
|------|------------|
| 大量任務導致 content JSON 過大 | 評估後續加入分頁或限制 |
| 阻礙查詢需 JOIN | 使用 subquery 減少 N+1 |