Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix: respect Available calendar events when checking busy time

Afloat08137277666b
diff --git a/server/calendar-transparency.test.ts b/server/calendar-transparency.test.ts
new file mode 100644
index 0000000000..2ec4335454
--- /dev/null
+++ b/server/calendar-transparency.test.ts
@@ -0,0 +1,48 @@
+import { describe, expect, it } from "vitest";
+
+import { eventsFromData } from "./connected-reads.ts";
+import { clashes, planMeetings } from "./host/check-plan.ts";
+import { busyTimes } from "./host/person-calendar.ts";
+
+const now = Date.parse("2026-11-11T08:00:00Z");
+const raw = (id: string, start: string, end: string, transparency?: string) => ({
+ id, summary: id, start: { dateTime: `2026-11-11T${start}:00Z` }, end: { dateTime: `2026-11-11T${end}:00Z` },
+ attendees: [{ email: "[email protected]" }], ...(transparency === undefined ? {} : { transparency }),
+});
+const read = (items: unknown[]) => eventsFromData({ items }, { id: "primary", owned: true });
+
+describe("calendar events marked Available", () => {
+ it("does not fill or merge a member's free time with a transparent event", () => {
+ const events = read([
+ raw("first", "09:00", "10:00"), raw("available", "09:30", "11:30", "transparent"),
+ raw("last", "11:00", "12:00", "opaque"),
+ ]);
+ expect(busyTimes(events)).toEqual([
+ { start: Date.parse("2026-11-11T09:00:00Z"), end: Date.parse("2026-11-11T10:00:00Z") },
+ { start: Date.parse("2026-11-11T11:00:00Z"), end: Date.parse("2026-11-11T12:00:00Z") },
+ ]);
+ });
+
+ it("does not report a clash with a transparent event, while retaining real clashes", () => {
+ const events = read([
+ raw("first", "09:00", "10:00"), raw("available", "09:15", "11:00", "transparent"),
+ raw("second", "09:30", "10:30", "opaque"),
+ ]);
+ expect(clashes(events, { now, timeZone: "UTC" }).map((pair) => pair.map((event) => event.id)))
+ .toEqual([["first", "second"]]);
+ });
+
+ it("keeps Available meetings readable and eligible for their usual preparation", () => {
+ const events = read([raw("available", "09:00", "10:00", "transparent")]);
+ expect(events).toHaveLength(1);
+ expect(planMeetings({ now, events, meetings: {}, checkMs: 60_000 })).toEqual([
+ { kind: "prep", event: events[0], short: true },
+ ]);
+ });
+
+ it("defaults omitted and unrecognized transparency values to busy", () => {
+ for (const transparency of [undefined, "opaque", "unexpected"]) {
+ expect(busyTimes(read([raw("busy", "09:00", "10:00", transparency)]))).toHaveLength(1);
+ }
+ });
+});
diff --git a/server/connected-reads.ts b/server/connected-reads.ts
index 5b603db745..7189db832b 100644
--- a/server/connected-reads.ts
+++ b/server/connected-reads.ts
@@ -15,6 +15,8 @@ export interface CalendarEvent {
start: number;
end: number;
allDay: boolean;
+ /** Google Calendar's Show me as Available: this event does not block time. */
+ transparent?: boolean;
status: "confirmed" | "tentative" | "cancelled";
selfDeclined: boolean;
attendees: Array<{ email: string; name?: string; self: boolean; organizer: boolean; response?: string }>;
@@ -210,6 +212,7 @@ function calendarEvent(raw: unknown, calendar: { id: string; owned: boolean }):
start: startMs,
end: Number.isFinite(endMs) ? endMs : startMs,
allDay,
+ ...(item.transparency === "transparent" ? { transparent: true } : {}),
status: item.status === "cancelled" || item.status === "tentative" ? item.status : "confirmed",
selfDeclined: attendees.some((attendee) => attendee.self && attendee.response === "declined"),
attendees,
diff --git a/server/host/check-plan.ts b/server/host/check-plan.ts
index c041f07582..43f2540aad 100644
--- a/server/host/check-plan.ts
+++ b/server/host/check-plan.ts
@@ -139,7 +139,7 @@ export function mergeMeetings(events: readonly CalendarEvent[], address: string
export function clashes<T extends CalendarEvent>(meetings: readonly T[], input: { now: number; timeZone?: string }): Array<[T, T]> {
const today = localDate(input.now, input.timeZone);
const open = meetings
- .filter((meeting) => qualifies(meeting) && meeting.end > input.now && localDate(meeting.start, input.timeZone) === today)
+ .filter((meeting) => qualifies(meeting) && !meeting.transparent && meeting.end > input.now && localDate(meeting.start, input.timeZone) === today)
.sort((a, b) => a.start - b.start);
const pairs: Array<[T, T]> = [];
open.forEach((first, index) => {
diff --git a/server/host/person-calendar.ts b/server/host/person-calendar.ts
index 167c7f1f6b..47538f7234 100644
--- a/server/host/person-calendar.ts
+++ b/server/host/person-calendar.ts
@@ -12,10 +12,10 @@ export interface PersonCalendarDeps<Access = PersonAppsAccess> {
relay(payload: unknown, transportSessionId: string | undefined, signal: AbortSignal, access: Access): ReturnType<ConnectedReadDeps["relay"]>;
}
-/** Busy times, merged where they touch: every event the person did not decline and that is not cancelled. A day-long
+/** Busy times, merged where they touch: events that block time, are not declined and are not cancelled. A day-long
* event marks a day, not busy hours, so it is left out, as calendars count it free. */
export function busyTimes(events: readonly CalendarEvent[]): Busy[] {
- const slots = events.filter((event) => !event.allDay && event.status !== "cancelled" && !event.selfDeclined && event.end > event.start)
+ const slots = events.filter((event) => !event.allDay && !event.transparent && event.status !== "cancelled" && !event.selfDeclined && event.end > event.start)
.map((event) => ({ start: event.start, end: event.end })).sort((a, b) => a.start - b.start);
const merged: Busy[] = [];
for (const slot of slots) {