-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
364 lines (302 loc) · 12.8 KB
/
app.py
File metadata and controls
364 lines (302 loc) · 12.8 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
"""
Streamlit GUI for timeblock-agent.
Run with: streamlit run app.py
"""
import streamlit as st
from timeblock.state import StateManager
from timeblock.utils import (
get_today_iso,
format_duration,
parse_duration,
categorize_task,
get_this_week_range,
)
from datetime import datetime, timedelta
import os
# Page config
st.set_page_config(
page_title="Timeblock Agent",
page_icon="📅",
layout="wide",
initial_sidebar_state="expanded"
)
# Custom CSS for better styling
st.markdown("""
<style>
.task-card {
padding: 10px;
border-radius: 5px;
margin: 5px 0;
border-left: 4px solid #4CAF50;
}
.task-completed {
border-left-color: #9E9E9E;
opacity: 0.6;
}
.task-meeting { border-left-color: #2196F3; }
.task-analysis { border-left-color: #9C27B0; }
.task-admin { border-left-color: #FF9800; }
.task-development { border-left-color: #4CAF50; }
.task-other { border-left-color: #607D8B; }
.timeline-hour {
border-top: 1px solid #e0e0e0;
padding: 8px 0;
font-size: 0.9em;
color: #666;
}
</style>
""", unsafe_allow_html=True)
# Initialize session state
if "state_manager" not in st.session_state:
st.session_state.state_manager = StateManager()
st.session_state.selected_date = get_today_iso()
st.session_state.view_mode = "today"
state = st.session_state.state_manager
# Sidebar
with st.sidebar:
st.title("⚡ Timeblock Agent")
st.markdown("---")
# View mode selector
st.session_state.view_mode = st.radio(
"View",
["today", "week", "all_tasks"],
format_func=lambda x: {
"today": "📅 Today",
"week": "📊 This Week",
"all_tasks": "📋 All Tasks"
}[x]
)
st.markdown("---")
# Add Task Form
st.subheader("➕ Add Task")
with st.form("add_task_form", clear_on_submit=True):
task_title = st.text_input("Title", placeholder="Team meeting")
col1, col2 = st.columns(2)
with col1:
duration_str = st.text_input("Duration", placeholder="90min", value="1h")
with col2:
task_date = st.date_input("Date", value=datetime.now())
task_category = st.selectbox(
"Category",
["auto-detect", "meeting", "analysis", "admin", "development", "other"]
)
task_notes = st.text_area("Notes (optional)", placeholder="Additional details...")
submitted = st.form_submit_button("Add Task", use_container_width=True)
if submitted and task_title:
try:
duration_minutes = parse_duration(duration_str)
date_str = task_date.strftime("%Y-%m-%d")
category = categorize_task(task_title) if task_category == "auto-detect" else task_category
task_id = state.add_task(
title=task_title,
duration_minutes=duration_minutes,
date=date_str,
category=category,
notes=task_notes
)
st.success(f"✅ Added: {task_title}")
st.rerun()
except Exception as e:
st.error(f"❌ Error: {e}")
st.markdown("---")
# Quick Actions
st.subheader("⚡ Quick Actions")
if st.button("🔄 Refresh", use_container_width=True):
st.rerun()
if st.button("📥 Sync Calendars", use_container_width=True):
st.info("Use CLI: `timeblock sync`")
# Agent Integration Status
st.markdown("---")
agent_enabled = bool(os.getenv("ANTHROPIC_API_KEY"))
if agent_enabled:
st.success("🤖 AI Agent: Enabled")
else:
st.warning("🤖 AI Agent: Disabled")
st.caption("Set ANTHROPIC_API_KEY to enable")
# Main content area
today = get_today_iso()
if st.session_state.view_mode == "today":
# TODAY VIEW
st.title(f"📅 Today's Schedule - {today}")
tasks = state.get_tasks_by_date(today)
# Stats
col1, col2, col3, col4 = st.columns(4)
with col1:
total_tasks = len(tasks)
st.metric("Total Tasks", total_tasks)
with col2:
completed = len([t for t in tasks if t["status"] == "completed"])
st.metric("Completed", completed)
with col3:
total_time = sum(t["duration_minutes"] for t in tasks)
st.metric("Total Time", format_duration(total_time))
with col4:
config = state.state.get("config", {})
work_hours = int(config.get("work_end", "17:00").split(":")[0]) - int(config.get("work_start", "09:00").split(":")[0])
focus_time = work_hours * 60 - total_time
st.metric("Focus Time", format_duration(max(0, focus_time)))
st.markdown("---")
# Two column layout: Timeline + Unscheduled
col_left, col_right = st.columns([2, 1])
with col_left:
st.subheader("🕐 Timeline")
if not tasks:
st.info("No tasks scheduled for today. Add one using the sidebar!")
else:
# Separate scheduled and unscheduled
scheduled = [t for t in tasks if t.get("time_block")]
if scheduled:
# Display scheduled tasks in timeline
for task in sorted(scheduled, key=lambda t: t["time_block"]):
status_icon = "✅" if task["status"] == "completed" else "⭕"
category_class = f"task-{task['category']}"
completed_class = " task-completed" if task["status"] == "completed" else ""
st.markdown(f"""
<div class="task-card {category_class}{completed_class}">
<strong>{status_icon} {task['time_block']}</strong> - {task['title']}<br>
<small>{format_duration(task['duration_minutes'])} • {task['category']}</small>
</div>
""", unsafe_allow_html=True)
# Action buttons
col_a, col_b, col_c = st.columns([1, 1, 3])
with col_a:
if task["status"] != "completed":
if st.button("✓ Complete", key=f"complete_{task['id']}"):
state.complete_task(task["id"])
st.rerun()
with col_b:
if st.button("🗑️ Delete", key=f"delete_{task['id']}"):
state.state["tasks"] = [t for t in state.state["tasks"] if t["id"] != task["id"]]
state.save()
st.rerun()
else:
st.info("No scheduled tasks. Assign time blocks to tasks in the Unscheduled panel →")
with col_right:
st.subheader("📝 Unscheduled")
unscheduled = [t for t in tasks if not t.get("time_block")]
if unscheduled:
for task in unscheduled:
status_icon = "✅" if task["status"] == "completed" else "⭕"
category_class = f"task-{task['category']}"
st.markdown(f"""
<div class="task-card {category_class}">
<strong>{status_icon} {task['title']}</strong><br>
<small>{format_duration(task['duration_minutes'])} • {task['category']}</small>
</div>
""", unsafe_allow_html=True)
# Schedule time picker
col_a, col_b = st.columns(2)
with col_a:
start_time = st.time_input(
"Start",
key=f"start_{task['id']}",
label_visibility="collapsed"
)
with col_b:
if st.button("📅 Schedule", key=f"schedule_{task['id']}"):
# Calculate end time
start_dt = datetime.combine(datetime.today(), start_time)
end_dt = start_dt + timedelta(minutes=task["duration_minutes"])
# Update task with time block
time_block = f"{start_dt.strftime('%H:%M')}-{end_dt.strftime('%H:%M')}"
for t in state.state["tasks"]:
if t["id"] == task["id"]:
t["time_block"] = time_block
t["status"] = "scheduled"
break
state.save()
st.success(f"Scheduled at {time_block}")
st.rerun()
st.markdown("---")
else:
st.info("All tasks are scheduled!")
elif st.session_state.view_mode == "week":
# WEEK VIEW
start_date, end_date = get_this_week_range()
st.title(f"📊 This Week - {start_date} to {end_date}")
# Get weekly goals
goals = state.get_weekly_goals()
if goals:
st.subheader("🎯 Weekly Goals")
for goal in goals:
status_icon = "✅" if goal["status"] == "completed" else "⭕"
col1, col2 = st.columns([3, 1])
with col1:
st.markdown(f"{status_icon} **{goal['title']}** ({goal['estimated_hours']}h) - {goal['category']}")
with col2:
if goal["status"] != "completed":
if st.button("✓", key=f"goal_{goal['id']}"):
for g in state.state["weekly_goals"]:
if g["id"] == goal["id"]:
g["status"] = "completed"
break
state.save()
st.rerun()
st.markdown("---")
# Get all tasks this week
all_tasks = state.list_all_tasks()
week_tasks = [t for t in all_tasks if start_date <= t["date"] <= end_date]
# Group by date
tasks_by_date = {}
for task in week_tasks:
if task["date"] not in tasks_by_date:
tasks_by_date[task["date"]] = []
tasks_by_date[task["date"]].append(task)
# Display by day
st.subheader("📅 Daily Breakdown")
for i in range(7):
date = (datetime.strptime(start_date, "%Y-%m-%d") + timedelta(days=i)).strftime("%Y-%m-%d")
day_name = datetime.strptime(date, "%Y-%m-%d").strftime("%A")
with st.expander(f"**{day_name}** ({date})", expanded=(date == today)):
day_tasks = tasks_by_date.get(date, [])
if day_tasks:
for task in sorted(day_tasks, key=lambda t: t.get("time_block") or ""):
status_icon = "✅" if task["status"] == "completed" else "⭕"
time_info = task.get("time_block", "Unscheduled")
st.markdown(f"{status_icon} **{task['title']}** [{time_info}] - {format_duration(task['duration_minutes'])}")
else:
st.info("No tasks scheduled")
elif st.session_state.view_mode == "all_tasks":
# ALL TASKS VIEW
st.title("📋 All Tasks")
# Filters
col1, col2, col3 = st.columns(3)
with col1:
filter_status = st.selectbox("Status", ["all", "pending", "completed", "scheduled"])
with col2:
filter_category = st.selectbox("Category", ["all", "meeting", "analysis", "admin", "development", "other"])
with col3:
filter_date = st.date_input("Date (optional)", value=None)
# Get and filter tasks
all_tasks = state.list_all_tasks()
if filter_status != "all":
all_tasks = [t for t in all_tasks if t["status"] == filter_status]
if filter_category != "all":
all_tasks = [t for t in all_tasks if t["category"] == filter_category]
if filter_date:
filter_date_str = filter_date.strftime("%Y-%m-%d")
all_tasks = [t for t in all_tasks if t["date"] == filter_date_str]
st.markdown(f"**Found {len(all_tasks)} tasks**")
st.markdown("---")
# Display tasks
for task in sorted(all_tasks, key=lambda t: (t["date"], t.get("time_block") or "")):
status_icon = "✅" if task["status"] == "completed" else "⭕"
time_info = task.get("time_block", "Unscheduled")
col1, col2, col3 = st.columns([3, 1, 1])
with col1:
st.markdown(f"{status_icon} **{task['title']}** - {task['date']} [{time_info}]")
st.caption(f"{format_duration(task['duration_minutes'])} • {task['category']}")
with col2:
if task["status"] != "completed":
if st.button("✓ Complete", key=f"complete_all_{task['id']}"):
state.complete_task(task["id"])
st.rerun()
with col3:
if st.button("🗑️", key=f"delete_all_{task['id']}"):
state.state["tasks"] = [t for t in state.state["tasks"] if t["id"] != task["id"]]
state.save()
st.rerun()
st.markdown("---")
# Footer
st.markdown("---")
st.caption("⚡ Timeblock Agent v0.1.0 | Built with Streamlit | Use CLI for sync and AI features")