|
1 | 1 | """Recent activity tool for Basic Memory MCP server.""" |
2 | 2 |
|
| 3 | +from datetime import timezone |
3 | 4 | from typing import List, Union, Optional |
4 | 5 |
|
5 | 6 | from loguru import logger |
@@ -196,40 +197,31 @@ async def recent_activity( |
196 | 197 | # Generate guidance for the assistant |
197 | 198 | guidance_lines = ["\n" + "─" * 40] |
198 | 199 |
|
199 | | - if most_active_project and most_active_count > 0: |
200 | | - guidance_lines.extend( |
201 | | - [ |
202 | | - f"Suggested project: '{most_active_project}' (most active with {most_active_count} items)", |
203 | | - f"Ask user: 'Should I use {most_active_project} for this task, or would you prefer a different project?'", |
204 | | - ] |
205 | | - ) |
206 | | - elif active_projects > 0: |
207 | | - # Has activity but no clear most active project |
208 | | - active_project_names = [ |
209 | | - name for name, activity in projects_activity.items() if activity.item_count > 0 |
210 | | - ] |
211 | | - if len(active_project_names) == 1: |
212 | | - guidance_lines.extend( |
213 | | - [ |
214 | | - f"Suggested project: '{active_project_names[0]}' (only active project)", |
215 | | - f"Ask user: 'Should I use {active_project_names[0]} for this task?'", |
216 | | - ] |
217 | | - ) |
218 | | - else: |
219 | | - guidance_lines.extend( |
220 | | - [ |
221 | | - f"Multiple active projects found: {', '.join(active_project_names)}", |
222 | | - "Ask user: 'Which project should I use for this task?'", |
223 | | - ] |
224 | | - ) |
225 | | - else: |
| 200 | + if active_projects == 0: |
226 | 201 | # No recent activity |
227 | 202 | guidance_lines.extend( |
228 | 203 | [ |
229 | 204 | "No recent activity found in any project.", |
230 | 205 | "Consider: Ask which project to use or if they want to create a new one.", |
231 | 206 | ] |
232 | 207 | ) |
| 208 | + else: |
| 209 | + # At least one project has activity: suggest the most active project. |
| 210 | + suggested_project = most_active_project or next( |
| 211 | + (name for name, activity in projects_activity.items() if activity.item_count > 0), |
| 212 | + None, |
| 213 | + ) |
| 214 | + if suggested_project: |
| 215 | + suffix = ( |
| 216 | + f"(most active with {most_active_count} items)" if most_active_count > 0 else "" |
| 217 | + ) |
| 218 | + guidance_lines.append(f"Suggested project: '{suggested_project}' {suffix}".strip()) |
| 219 | + if active_projects == 1: |
| 220 | + guidance_lines.append(f"Ask user: 'Should I use {suggested_project} for this task?'") |
| 221 | + else: |
| 222 | + guidance_lines.append( |
| 223 | + f"Ask user: 'Should I use {suggested_project} for this task, or would you prefer a different project?'" |
| 224 | + ) |
233 | 225 |
|
234 | 226 | guidance_lines.extend( |
235 | 227 | [ |
@@ -290,12 +282,13 @@ async def _get_project_activity( |
290 | 282 | for result in activity.results: |
291 | 283 | if result.primary_result.created_at: |
292 | 284 | current_time = result.primary_result.created_at |
293 | | - try: |
294 | | - if last_activity is None or current_time > last_activity: |
295 | | - last_activity = current_time |
296 | | - except TypeError: |
297 | | - # Handle timezone comparison issues by skipping this comparison |
298 | | - if last_activity is None: |
| 285 | + if current_time.tzinfo is None: |
| 286 | + current_time = current_time.replace(tzinfo=timezone.utc) |
| 287 | + |
| 288 | + if last_activity is None: |
| 289 | + last_activity = current_time |
| 290 | + else: |
| 291 | + if current_time > last_activity: |
299 | 292 | last_activity = current_time |
300 | 293 |
|
301 | 294 | # Extract folder from file_path |
|
0 commit comments