-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtask_report.py
More file actions
474 lines (395 loc) · 10.9 KB
/
task_report.py
File metadata and controls
474 lines (395 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
"""
task_report.py — GitHub Pages Kanban board generator for SQLite Memory tasks.
Reads tasks from ~/.claude/memory/memory.db and generates a self-contained
index.html Kanban board saved to the bridge repo for GitHub Pages.
Usage:
python task_report.py
"""
import os
from datetime import date, datetime
from db_utils import BRIDGE_REPO, TASK_SECTIONS as SECTIONS
from db_utils import PRIORITY_RANK, get_conn, is_overdue as _is_overdue
from db_utils import priority_sort_key
SECTION_LABELS = {
"today": "Today",
"inbox": "Inbox",
"next": "Next",
"waiting": "Waiting",
"someday": "Someday",
}
PRIORITY_ORDER = {p: len(PRIORITY_RANK) - 1 - r for p, r in PRIORITY_RANK.items()}
def _get_tasks() -> tuple[list[dict], set[str]]:
"""
Return (tasks_list, parent_ids_set).
tasks_list: all non-archived, non-cancelled tasks as dicts.
parent_ids_set: set of IDs that are referenced as parent_id by any task.
"""
with get_conn() as conn:
cur = conn.cursor()
cur.execute(
"""
SELECT id, title, status, priority, section, due_date,
project, parent_id, notes, type, created_at, updated_at
FROM tasks
WHERE status NOT IN ('archived', 'cancelled')
ORDER BY created_at
"""
)
tasks = [dict(row) for row in cur.fetchall()]
# Collect IDs that appear as parent_id (have children)
parent_ids: set[str] = set()
cur.execute("SELECT DISTINCT parent_id FROM tasks WHERE parent_id IS NOT NULL")
for row in cur.fetchall():
parent_ids.add(row[0])
return tasks, parent_ids
def _html_escape(text: str) -> str:
if not text:
return ""
return (
text.replace("&", "&")
.replace("<", "<")
.replace(">", ">")
.replace('"', """)
.replace("'", "'")
)
def _render_card(task: dict, today_str: str, parent_ids: set[str]) -> str:
title = _html_escape(task.get("title") or "Untitled")
priority = (task.get("priority") or "low").lower()
if priority not in PRIORITY_ORDER:
priority = "low"
due_date = task.get("due_date")
project = task.get("project")
task_id = task.get("id", "")
has_children = task_id in parent_ids
overdue = _is_overdue(due_date)
card_class = "card"
if overdue:
card_class += " card--overdue"
priority_label = priority.upper()
priority_class = f"badge badge--{priority}"
badges_html = f'<span class="{priority_class}">{priority_label}</span>'
if overdue:
badges_html += ' <span class="badge badge--overdue">OVERDUE</span>'
if has_children:
badges_html += ' <span class="badge badge--subtask">SUBTASKS</span>'
if (task.get("type") or "task") == "note":
badges_html += ' <span class="badge badge--note">NOTE</span>'
due_html = ""
if due_date:
due_html = f'<div class="card__due">Due: {_html_escape(due_date)}</div>'
project_html = ""
if project:
project_html = f'<div class="card__project">{_html_escape(project)}</div>'
return f"""
<div class="{card_class}">
<div class="card__title">{title}</div>
<div class="card__meta">
{badges_html}
</div>
{due_html}
{project_html}
</div>"""
def _render_column(
section: str, tasks: list[dict], today_str: str, parent_ids: set[str]
) -> str:
label = SECTION_LABELS.get(section, section.title())
count = len(tasks)
if tasks:
cards_html = "\n".join(_render_card(t, today_str, parent_ids) for t in tasks)
else:
cards_html = '<div class="empty-state">No tasks</div>'
return f"""
<div class="column">
<div class="column__header">
<span class="column__title">{label}</span>
<span class="column__count">{count}</span>
</div>
<div class="column__body">
{cards_html}
</div>
</div>"""
def _build_html(tasks: list[dict], parent_ids: set[str]) -> str:
today = date.today()
today_str = today.isoformat()
now_str = datetime.now().strftime("%Y-%m-%d %H:%M")
# Group tasks by section
by_section: dict[str, list[dict]] = {s: [] for s in SECTIONS}
for task in tasks:
section = (task.get("section") or "inbox").lower()
if section not in by_section:
section = "inbox"
by_section[section].append(task)
# Sort within each section
for section in SECTIONS:
by_section[section].sort(key=priority_sort_key)
total = len(tasks)
overdue = sum(1 for t in tasks if _is_overdue(t.get("due_date")))
columns_html = "".join(
_render_column(s, by_section[s], today_str, parent_ids) for s in SECTIONS
)
return f"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Task Board — SQLite Memory</title>
<style>
/* ── Reset ── */
*, *::before, *::after {{
box-sizing: border-box;
margin: 0;
padding: 0;
}}
/* ── Base ── */
body {{
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
"Helvetica Neue", Arial, sans-serif;
font-size: 14px;
background: #f0f4f8;
color: #1a2332;
min-height: 100vh;
display: flex;
flex-direction: column;
}}
/* ── Page header ── */
.page-header {{
background: #1a2332;
color: #ffffff;
padding: 16px 24px;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 12px;
}}
.page-header__title {{
font-size: 20px;
font-weight: 700;
letter-spacing: 0.5px;
}}
/* ── Summary bar ── */
.summary-bar {{
background: #2d3748;
color: #f7fafc;
padding: 8px 24px;
display: flex;
gap: 24px;
font-size: 13px;
flex-wrap: wrap;
}}
.summary-bar__item {{
display: flex;
align-items: center;
gap: 6px;
}}
.summary-bar__label {{
color: #a0aec0;
}}
.summary-bar__value {{
font-weight: 600;
color: #ffffff;
}}
.summary-bar__value--overdue {{
color: #fc8181;
}}
/* ── Board ── */
.board {{
display: flex;
gap: 16px;
padding: 20px 24px;
overflow-x: auto;
flex: 1;
align-items: flex-start;
}}
/* ── Column ── */
.column {{
flex: 0 0 260px;
min-width: 220px;
max-width: 300px;
background: #e2e8f0;
border-radius: 6px;
display: flex;
flex-direction: column;
}}
.column__header {{
background: #2d3748;
color: #ffffff;
padding: 10px 14px;
border-radius: 6px 6px 0 0;
display: flex;
align-items: center;
justify-content: space-between;
}}
.column__title {{
font-weight: 700;
font-size: 13px;
letter-spacing: 0.8px;
text-transform: uppercase;
}}
.column__count {{
background: #4a5568;
color: #f7fafc;
font-size: 12px;
font-weight: 700;
padding: 2px 8px;
border-radius: 10px;
min-width: 24px;
text-align: center;
}}
.column__body {{
padding: 10px;
display: flex;
flex-direction: column;
gap: 8px;
min-height: 80px;
}}
/* ── Card ── */
.card {{
background: #ffffff;
border-radius: 4px;
padding: 10px 12px;
border-left: 3px solid #cbd5e0;
box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}}
.card--overdue {{
border-left-color: #e53e3e;
}}
.card__title {{
font-size: 13px;
font-weight: 600;
color: #1a2332;
line-height: 1.4;
margin-bottom: 6px;
word-break: break-word;
}}
.card__meta {{
display: flex;
flex-wrap: wrap;
gap: 4px;
margin-bottom: 4px;
}}
.card__due {{
font-size: 11px;
color: #4a5568;
margin-top: 4px;
}}
.card__project {{
font-size: 11px;
color: #718096;
margin-top: 2px;
font-style: italic;
}}
/* ── Badges ── */
.badge {{
font-size: 10px;
font-weight: 700;
padding: 2px 6px;
border-radius: 3px;
letter-spacing: 0.4px;
display: inline-block;
}}
.badge--critical {{
background: #fff5f5;
color: #e53e3e;
border: 1px solid #feb2b2;
}}
.badge--high {{
background: #fffaf0;
color: #dd6b20;
border: 1px solid #fbd38d;
}}
.badge--medium {{
background: #ebf8ff;
color: #2b6cb0;
border: 1px solid #bee3f8;
}}
.badge--low {{
background: #f7fafc;
color: #718096;
border: 1px solid #e2e8f0;
}}
.badge--overdue {{
background: #fff5f5;
color: #c53030;
border: 1px solid #fc8181;
}}
.badge--subtask {{
background: #f0fff4;
color: #276749;
border: 1px solid #9ae6b4;
}}
.badge--note {{
background: #f0f4ff;
color: #3b5998;
border: 1px solid #a3bffa;
}}
/* ── Empty state ── */
.empty-state {{
color: #a0aec0;
font-size: 12px;
text-align: center;
padding: 16px 8px;
font-style: italic;
}}
/* ── Footer ── */
.page-footer {{
background: #2d3748;
color: #a0aec0;
font-size: 11px;
padding: 10px 24px;
text-align: right;
}}
/* ── Responsive ── */
@media (max-width: 600px) {{
.board {{
flex-direction: column;
padding: 12px;
}}
.column {{
flex: none;
width: 100%;
max-width: 100%;
}}
.page-header {{
padding: 12px 16px;
}}
.summary-bar {{
padding: 8px 16px;
}}
}}
</style>
</head>
<body>
<header class="page-header">
<div class="page-header__title">Task Board — SQLite Memory</div>
</header>
<div class="summary-bar">
<div class="summary-bar__item">
<span class="summary-bar__label">Total tasks:</span>
<span class="summary-bar__value">{total}</span>
</div>
<div class="summary-bar__item">
<span class="summary-bar__label">Overdue:</span>
<span class="summary-bar__value{"--overdue" if overdue else ""}">{overdue}</span>
</div>
</div>
<div class="board">
{columns_html}
</div>
<footer class="page-footer">
Last updated: {now_str}
</footer>
</body>
</html>"""
def generate_report() -> str:
"""Generate Kanban HTML and save to bridge repo. Returns path."""
tasks, parent_ids = _get_tasks()
html = _build_html(tasks, parent_ids)
os.makedirs(BRIDGE_REPO, exist_ok=True)
output_path = os.path.join(BRIDGE_REPO, "index.html")
with open(output_path, "w", encoding="utf-8") as f:
f.write(html)
return output_path
if __name__ == "__main__":
path = generate_report()
print(f"Report generated: {path}")