fix(calendar): honor list_events date range aliases (#3283)

* fix(calendar): honor list_events date range aliases

* fix(calendar): reject partially resolved loose range queries
This commit is contained in:
badgerbees
2026-07-04 20:44:46 +08:00
committed by GitHub
parent 6f6cb6ea88
commit 5c16d39e91
5 changed files with 73 additions and 5 deletions
+1 -1
View File
@@ -469,7 +469,7 @@ Bulk delete/archive/mark emails. Use this for "delete all those" after listing e
{"action": "create_event", "summary": "<event title>", "dtstart": "<natural language or ISO datetime>"}
```
Calendar event management (CalDAV). Actions: `list_events`, `create_event`, `update_event`, `delete_event`, `list_calendars`. \
For `list_events`: {start?, end?, calendar?}; prefer `start`/`end` for the range, though start_date/end_date and from/to aliases are accepted. \
For `list_events`: {action: "list_events", start: "YYYY-MM-DDT00:00:00", end: "YYYY-MM-DDT00:00:00", calendar?}; resolve month/week phrases yourself from the Current date and time context and do not pass a loose `query` field. Prefer `start`/`end`; start_time/end_time, start_date/end_date, and from/to aliases are accepted. \
For `create_event`: {summary, dtstart, dtend?, duration?, calendar?, location?, description?, reminder_minutes?, rrule?}. \
For `update_event`: {uid, summary?, dtstart?, dtend?, all_day?, location?, description?, event_type?, importance?, rrule?}. Pass `rrule: ""` to remove recurrence and make a repeating event a single event. \
`dtstart` accepts natural language ("tomorrow at 1pm", "in 2 hours", "next monday 9am") or ISO ("2026-05-12T13:00:00"). \
+2 -2
View File
@@ -556,8 +556,8 @@ FUNCTION_TOOL_SCHEMAS = [
"uid": {"type": "string", "description": "Event UID (for update/delete)"},
"calendar_href": {"type": "string", "description": "Specific calendar URL (optional; defaults to first calendar)"},
"calendar": {"type": "string", "description": "Filter list_events by calendar name or href"},
"start": {"type": "string", "description": "list_events range start (ISO datetime); defaults to today. Prefer start; backend also accepts start_date, range_start, from, dtstart, since."},
"end": {"type": "string", "description": "list_events range end (ISO datetime); defaults to +14 days. Prefer end; backend also accepts end_date, range_end, to, dtend, until."},
"start": {"type": "string", "description": "list_events range start (ISO datetime). Use this for month/week requests after resolving the date range; do not pass a loose query string. Prefer start; backend also accepts start_time, start_date, range_start, from, dtstart, since."},
"end": {"type": "string", "description": "list_events range end (ISO datetime). Use this for month/week requests after resolving the date range; defaults to +14 days only when no range is requested. Prefer end; backend also accepts end_time, end_date, range_end, to, dtend, until."},
"event_type": {"type": "string", "description": "Tag / category for the event. Common values: work, personal, health, travel, meal, social, admin, other. Aliases accepted: tag, category, type."},
"importance": {"type": "string", "enum": ["low", "normal", "high", "critical"], "description": "Priority level (defaults to 'normal')"},
"reminder_minutes": {"type": "integer", "description": "For create_event: create an Odysseus reminder this many minutes before the event, e.g. 5 for 'reminder 5 min before'."},
+11 -2
View File
@@ -208,11 +208,20 @@ async def do_manage_calendar(content: str, owner: Optional[str] = None) -> Dict:
elif action == "list_events":
try:
start_raw = _first_nonempty_arg(
"start", "start_date", "range_start", "from", "dtstart", "since"
"start", "start_time", "start_date", "range_start", "from", "dtstart", "since"
)
end_raw = _first_nonempty_arg(
"end", "end_date", "range_end", "to", "dtend", "until"
"end", "end_time", "end_date", "range_end", "to", "dtend", "until"
)
query_raw = args.get("query") or args.get("date_range") or args.get("range")
if query_raw and (not start_raw or not end_raw):
return {
"error": (
"list_events needs explicit start/end ISO datetimes; "
f"resolve the requested range ({query_raw!r}) and call manage_calendar again."
),
"exit_code": 1,
}
if start_raw:
start_dt = _parse_dt(start_raw)
else:
+26
View File
@@ -78,3 +78,29 @@ async def test_list_events_honors_range_aliases(start_key, end_key):
summaries = [event["summary"] for event in res["events"]]
assert summaries == ["Late June planning"]
assert "between 2126-06-01 and 2126-07-01" in res["response"]
async def test_list_events_rejects_partial_loose_range():
from src.tool_implementations import do_manage_calendar
owner = "calendar-partial-" + uuid.uuid4().hex[:8]
# Partial: has query and start, but no end
res = await do_manage_calendar(json.dumps({
"action": "list_events",
"query": "July",
"start_time": "2126-07-01T00:00:00Z",
}), owner=owner)
assert res.get("exit_code", 1) == 1, res
assert "list_events needs explicit start/end" in res.get("error", "")
# Partial: has query and end, but no start
res2 = await do_manage_calendar(json.dumps({
"action": "list_events",
"query": "July",
"end_time": "2126-07-31T23:59:59Z",
}), owner=owner)
assert res2.get("exit_code", 1) == 1, res2
assert "list_events needs explicit start/end" in res2.get("error", "")
+33
View File
@@ -78,3 +78,36 @@ async def test_update_event_dtstart_anchored_to_user_tz(tokyo_offset):
assert bool(ev.is_utc) is True
finally:
db.close()
async def test_list_events_accepts_start_time_end_time_aliases():
from src.tool_implementations import do_manage_calendar
owner = "list-" + uuid.uuid4().hex[:6]
created = await do_manage_calendar(json.dumps({
"action": "create_event",
"summary": "July planning",
"dtstart": "2026-07-15T12:00:00Z",
"dtend": "2026-07-15T13:00:00Z",
}), owner=owner)
assert created.get("exit_code", 0) == 0, created
listed = await do_manage_calendar(json.dumps({
"action": "list_events",
"start_time": "2026-07-01T00:00:00Z",
"end_time": "2026-08-01T00:00:00Z",
}), owner=owner)
assert listed.get("exit_code", 0) == 0, listed
assert "between 2026-07-01 and 2026-08-01" in listed["response"]
assert [event["summary"] for event in listed["events"]] == ["July planning"]
async def test_list_events_query_without_range_does_not_default_to_two_weeks():
from src.tool_implementations import do_manage_calendar
listed = await do_manage_calendar(json.dumps({
"action": "list_events",
"query": "July",
}), owner="list-" + uuid.uuid4().hex[:6])
assert listed.get("exit_code") == 1, listed
assert "explicit start/end" in listed["error"]