Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(team): mark truncated calendar facts as incomplete
Afloat208bd88b7990
diff --git a/server/host/representative-calendar-limit.test.ts b/server/host/representative-calendar-limit.test.tsnew file mode 100644index 0000000000..cd96b2813c--- /dev/null+++ b/server/host/representative-calendar-limit.test.ts@@ -0,0 +1,42 @@+import { describe, expect, it } from "vitest";++import { representativePrompt, type Busy, type Question } from "./representative.ts";++const NOW = Date.UTC(2026, 9, 27);+const HOUR = 60 * 60_000;+const input: Question = {+ person: { key: "p_ben", name: "Ben" }, bot: { id: "bens-chief" },+ team: "Acme", asker: "Cleo", question: "When is Ben free this week?", shared: { notes: [], work: [] },+};+const slots = (count: number): Busy[] => Array.from({ length: count }, (_, index) => ({+ start: NOW + (index * 2 + 1) * HOUR, end: NOW + (index * 2 + 2) * HOUR,+}));+const prompt = (busy: Busy[]) => representativePrompt(input, busy, "UTC", NOW);++describe("the representative's bounded calendar facts", () => {+ it("does not call omitted busy periods free when the list is truncated", () => {+ const result = prompt(slots(81));+ expect(result).not.toContain("free at every other time");+ expect(result).toContain("additional busy times are omitted");+ expect(result).toContain("availability outside these intervals is unknown");+ expect(result).toContain("Mon 2 Nov 15:00–16:00");+ expect(result).not.toContain("Mon 2 Nov 17:00–18:00");+ });++ it("keeps the partial-data warning when the provider returns slots out of order", () => {+ const busy = slots(81).reverse();+ const original = structuredClone(busy);+ expect(prompt(busy)).toContain("availability outside these intervals is unknown");+ expect(busy).toEqual(original);+ });++ it("retains complete availability at the exact limit", () => {+ expect(prompt(slots(80))).toContain("free at every other time");+ expect(prompt(slots(80))).not.toContain("additional busy times are omitted");+ });++ it("does not count expired intervals against the limit", () => {+ const expired = Array.from({ length: 100 }, () => ({ start: NOW - HOUR, end: NOW }));+ expect(prompt([...expired, ...slots(80)])).toContain("free at every other time");+ });+});diff --git a/server/host/representative.ts b/server/host/representative.tsindex a8a2a18c27..7506e56ffe 100644--- a/server/host/representative.ts+++ b/server/host/representative.ts@@ -78,7 +78,8 @@ const data = (value: string, max: number) => oneLine(value.replace(/[[\]]/g, " "function busyLines(busy: Busy[] | null, timeZone: string, now: number): string {if (!busy) return `Calendar: not connected, so when they are free is not known.`;- const shown = busy.filter((slot) => slot.end > now).sort((a, b) => a.start - b.start).slice(0, MAX_BUSY);+ const upcoming = busy.filter((slot) => slot.end > now).sort((a, b) => a.start - b.start);+ const shown = upcoming.slice(0, MAX_BUSY);if (!shown.length) return `Busy times in the next ${LOOK_AHEAD_DAYS} days: none.`;const day = new Intl.DateTimeFormat("en-GB", { weekday: "short", day: "numeric", month: "short", timeZone });const time = new Intl.DateTimeFormat("en-GB", { hour: "2-digit", minute: "2-digit", hourCycle: "h23", timeZone });@@ -87,7 +88,10 @@ function busyLines(busy: Busy[] | null, timeZone: string, now: number): string {return sameDay ? `${day.format(slot.start)} ${time.format(slot.start)}–${time.format(slot.end)}`: `${day.format(slot.start)} ${time.format(slot.start)} – ${day.format(slot.end)} ${time.format(slot.end)}`;});- return `Busy times in the next ${LOOK_AHEAD_DAYS} days (free at every other time): ${lines.join("; ")}.`;+ const coverage = upcoming.length > MAX_BUSY+ ? "partial list; additional busy times are omitted, so availability outside these intervals is unknown"+ : "free at every other time";+ return `Busy times in the next ${LOOK_AHEAD_DAYS} days (${coverage}): ${lines.join("; ")}.`;}function factsBlock(input: Question, busy: Busy[] | null, timeZone: string, now: number): string {