Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions flowstate_cli/daily.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# flowstate_cli/daily.py

from pathlib import Path
from datetime import datetime
from typing import List, Dict
import json

class DailyTaskBuffer:
def __init__(self):
self.buffer_file = Path.home() / ".flowstate-daily.json"

def _load_tasks(self) -> List[Dict]:
if self.buffer_file.exists():
try:
with self.buffer_file.open("r") as f:
return json.load(f)
except json.JSONDecodeError:
return []
return []

def _save_tasks(self, tasks: List[Dict]) -> None:
with self.buffer_file.open("w") as f:
json.dump(tasks, f, indent=2)

def add_task(self, description: str) -> None:
tasks = self._load_tasks()
tasks.append({
"description": description,
"created_at": datetime.now().isoformat()
})
self._save_tasks(tasks)

def get_tasks(self) -> List[Dict]:
return self._load_tasks()

def clear_tasks(self) -> None:
if self.buffer_file.exists():
self.buffer_file.unlink()

# Important: global instance
daily = DailyTaskBuffer()
69 changes: 69 additions & 0 deletions flowstate_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from flowstate_cli.timer import timer
from flowstate_cli.daemon import daemon
from flowstate_cli.flow_mode import flow_mode
from flowstate_cli.daily import daily

app = typer.Typer(help="FlowState CLI - Productivity tool with task management and Pomodoro timers")
console = Console()
Expand Down Expand Up @@ -419,5 +420,73 @@ async def _show_stats():

asyncio.run(_show_stats())


#Daily Task Addition
daily_app = typer.Typer(help="Manage daily task buffer")
app.add_typer(daily_app, name="daily")

@daily_app.command("add")
def daily_add(description: str = typer.Argument(..., help="Daily task description")):
daily.add_task(description)
rprint(f"📝 Added to daily list: [bold]{description}[/bold]")

@daily_app.command("commit")
def daily_commit():
"""Add daily tasks to main list (buffer is NOT cleared)"""
tasks = daily.get_tasks()
if not tasks:
rprint("📭 No tasks in daily buffer.")
return

async def _commit():
success = 0
for t in tasks:
try:
await api.create_task(t["description"])
success += 1
except Exception as e:
rprint(f"❌ Failed to add: {t['description']} ({e})")

rprint(f"✅ Committed {success} task(s) to main list.")
rprint("📝 Daily buffer remains intact. Use `flowstate daily remove` to remove manually if needed.")

asyncio.run(_commit())



@daily_app.command("list")
def daily_list():
"""Show tasks in daily buffer"""
tasks = daily.get_tasks()

if not tasks:
rprint("📭 No tasks in daily list.")
return

table = Table(title="🗒️ Daily Task Buffer")
table.add_column("Index", style="cyan")
table.add_column("Description", style="white")
table.add_column("Created At", style="dim")

for idx, task in enumerate(tasks, start=1):
created_at = task.get("created_at", "")[:19] # Trim to date+time
table.add_row(str(idx), task["description"], created_at)

console.print(table)

@daily_app.command("remove")
def daily_remove(index: int = typer.Argument(..., help="Index of task to remove (from `daily list`)")):
"""Remove a task from the daily buffer"""
tasks = daily.get_tasks()
if index < 1 or index > len(tasks):
rprint("❌ Invalid task index.")
return

removed = tasks.pop(index - 1)
daily._save_tasks(tasks)
rprint(f"🗑️ Removed from daily list: [bold]{removed['description']}[/bold]")



if __name__ == "__main__":
app()