Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(tasks): sort next runs by instant

cyh19be69d66861
diff --git a/tests/test_cli_task_command.py b/tests/test_cli_task_command.py
index 2a5e44765..191274d1b 100644
--- a/tests/test_cli_task_command.py
+++ b/tests/test_cli_task_command.py
@@ -414,6 +414,42 @@ def test_task_list_brief_returns_scheduling_focused_view(tmp_path: Path, capsys)
assert entry["state"] == "active"
+def test_task_list_sorts_by_next_run_instant_across_timezones(
+ tmp_path: Path, capsys, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ store_path = tmp_path / "scheduled_tasks.json"
+ store = cli.ScheduledTaskStore(store_path)
+ later = store.add_task(
+ name="Later run",
+ session_key="slack::channel::C123",
+ prompt="later",
+ schedule_type="cron",
+ cron="0 * * * *",
+ timezone_name="UTC",
+ )
+ earlier = store.add_task(
+ name="Earlier run",
+ session_key="slack::channel::C123",
+ prompt="earlier",
+ schedule_type="cron",
+ cron="0 * * * *",
+ timezone_name="Asia/Shanghai",
+ )
+ next_runs = {
+ later.id: "2026-04-01T09:30:00+08:00",
+ earlier.id: "2026-04-01T01:00:00+00:00",
+ }
+ monkeypatch.setattr(cli, "_task_next_run_at", lambda task: next_runs[task.id])
+
+ with patch("vibe.cli._task_store", return_value=store):
+ result = cli.cmd_task_list(brief=True)
+
+ assert result == 0
+ payload = json.loads(capsys.readouterr().out)
+ ordered_ids = [item["id"] for item in payload["tasks"]]
+ assert ordered_ids == [earlier.id, later.id]
+
+
def test_task_show_includes_derived_schedule_fields(tmp_path: Path, capsys) -> None:
store_path = tmp_path / "scheduled_tasks.json"
store = cli.ScheduledTaskStore(store_path)
diff --git a/vibe/cli.py b/vibe/cli.py
index 538ba503a..88da7c92b 100644
--- a/vibe/cli.py
+++ b/vibe/cli.py
@@ -7,7 +7,7 @@ import signal
import subprocess
import sys
import time
-from datetime import datetime
+from datetime import datetime, timezone
from pathlib import Path
from textwrap import dedent
from typing import Optional
@@ -466,6 +466,21 @@ def _task_schedule_summary(task) -> str:
return task.schedule_type
+def _task_next_run_sort_key(task):
+ next_run_at = _task_next_run_at(task)
+ if not next_run_at:
+ return (True, datetime.max.replace(tzinfo=timezone.utc))
+ try:
+ instant = datetime.fromisoformat(next_run_at)
+ if instant.tzinfo is None:
+ instant = instant.replace(tzinfo=timezone.utc)
+ else:
+ instant = instant.astimezone(timezone.utc)
+ except ValueError:
+ return (True, datetime.max.replace(tzinfo=timezone.utc))
+ return (False, instant)
+
+
def _task_payload(task, *, brief: bool = False):
derived = {
"display_name": _task_display_name(task),
@@ -500,8 +515,7 @@ def _sort_tasks_for_display(tasks):
return sorted(
tasks,
key=lambda item: (
- _task_next_run_at(item) is None,
- _task_next_run_at(item) or "",
+ *_task_next_run_sort_key(item),
item.created_at,
item.id,
),