Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix: enrich calendar event input

Gus0d09a45c0a48
diff --git a/src/cli/daemon/prompt.test.ts b/src/cli/daemon/prompt.test.ts
index cd4180b04..6e4966007 100644
--- a/src/cli/daemon/prompt.test.ts
+++ b/src/cli/daemon/prompt.test.ts
@@ -107,12 +107,20 @@ describe("buildPrompt", () => {
const task: Task = {
...makeTask("Do the standup", "calendar_event"),
context: {
+ event_id: "ce_1",
+ datetime: "2026-04-17T09:00:00.000Z",
+ is_recurring: true,
+ repeat_interval: "1day",
description: "Check PRs merged this week",
scheduled_by: { name: "Gus", email: "[email protected]" },
},
};
const parsed = JSON.parse(buildPrompt(task));
expect(parsed.notice).toContain("scheduled calendar event");
+ expect(parsed.event_id).toBe("ce_1");
+ expect(parsed.datetime).toBe("2026-04-17T09:00:00.000Z");
+ expect(parsed.is_recurring).toBe(true);
+ expect(parsed.repeat_interval).toBe("1day");
expect(parsed.description).toBe("Check PRs merged this week");
expect(parsed.scheduled_by).toEqual({ name: "Gus", email: "[email protected]" });
});
@@ -120,7 +128,13 @@ describe("buildPrompt", () => {
it("includes only description for calendar_event when scheduled_by is absent", () => {
const task: Task = {
...makeTask("Do the standup", "calendar_event"),
- context: { description: "Check PRs merged this week" },
+ context: {
+ event_id: "ce_1",
+ datetime: "2026-04-17T09:00:00.000Z",
+ is_recurring: false,
+ repeat_interval: null,
+ description: "Check PRs merged this week",
+ },
};
const parsed = JSON.parse(buildPrompt(task));
expect(parsed.notice).toContain("scheduled calendar event");
@@ -131,7 +145,13 @@ describe("buildPrompt", () => {
it("includes only scheduled_by for calendar_event when description is absent", () => {
const task: Task = {
...makeTask("Do the standup", "calendar_event"),
- context: { scheduled_by: { name: "Gus", email: "[email protected]" } },
+ context: {
+ event_id: "ce_2",
+ datetime: "2026-04-17T09:00:00.000Z",
+ is_recurring: false,
+ repeat_interval: null,
+ scheduled_by: { name: "Gus", email: "[email protected]" },
+ },
};
const parsed = JSON.parse(buildPrompt(task));
expect(parsed.notice).toContain("scheduled calendar event");
@@ -142,7 +162,14 @@ describe("buildPrompt", () => {
it("omits description for calendar_event when description is empty string", () => {
const task: Task = {
...makeTask("Do the standup", "calendar_event"),
- context: { description: "", scheduled_by: { name: "Gus", email: "[email protected]" } },
+ context: {
+ event_id: "ce_3",
+ datetime: "2026-04-17T09:00:00.000Z",
+ is_recurring: false,
+ repeat_interval: null,
+ description: "",
+ scheduled_by: { name: "Gus", email: "[email protected]" },
+ },
};
const parsed = JSON.parse(buildPrompt(task));
expect(parsed.notice).toContain("scheduled calendar event");
@@ -150,6 +177,40 @@ describe("buildPrompt", () => {
expect(parsed.scheduled_by).toEqual({ name: "Gus", email: "[email protected]" });
});
+ it("forwards is_recurring=false and repeat_interval=null for one-off calendar events", () => {
+ const task: Task = {
+ ...makeTask("One-off reminder", "calendar_event"),
+ context: {
+ event_id: "ce_4",
+ datetime: "2026-05-01T14:00:00.000Z",
+ is_recurring: false,
+ repeat_interval: null,
+ },
+ };
+ const parsed = JSON.parse(buildPrompt(task));
+ expect(parsed.event_id).toBe("ce_4");
+ expect(parsed.datetime).toBe("2026-05-01T14:00:00.000Z");
+ expect(parsed.is_recurring).toBe(false);
+ expect(parsed.repeat_interval).toBeNull();
+ });
+
+ it("forwards is_recurring=true and repeat_interval for recurring calendar events", () => {
+ const task: Task = {
+ ...makeTask("Weekly sync", "calendar_event"),
+ context: {
+ event_id: "ce_5",
+ datetime: "2026-05-05T10:00:00.000Z",
+ is_recurring: true,
+ repeat_interval: "1week",
+ },
+ };
+ const parsed = JSON.parse(buildPrompt(task));
+ expect(parsed.event_id).toBe("ce_5");
+ expect(parsed.datetime).toBe("2026-05-05T10:00:00.000Z");
+ expect(parsed.is_recurring).toBe(true);
+ expect(parsed.repeat_interval).toBe("1week");
+ });
+
it("does not add notice for unknown task types", () => {
const task = makeTask("Check inbox", "some_other_type");
const parsed = JSON.parse(buildPrompt(task));
diff --git a/src/cli/daemon/prompt.ts b/src/cli/daemon/prompt.ts
index a332fb93b..1164a159a 100644
--- a/src/cli/daemon/prompt.ts
+++ b/src/cli/daemon/prompt.ts
@@ -54,6 +54,18 @@ export function buildPrompt(task: Task, attachments?: Attachment[]): string {
if (task.type === "calendar_event") {
obj.notice = CALENDAR_NOTICE;
const ctx = task.context as Record<string, unknown> | undefined;
+ if (ctx?.event_id != null) {
+ obj.event_id = ctx.event_id;
+ }
+ if (ctx?.datetime != null) {
+ obj.datetime = ctx.datetime;
+ }
+ if (ctx?.is_recurring !== undefined) {
+ obj.is_recurring = ctx.is_recurring;
+ }
+ if (ctx?.repeat_interval !== undefined) {
+ obj.repeat_interval = ctx.repeat_interval;
+ }
if (ctx?.description) {
obj.description = ctx.description;
}
diff --git a/src/web/src/app/api/calendar/route.ts b/src/web/src/app/api/calendar/route.ts
index 3fc41fc7a..5c9521b14 100644
--- a/src/web/src/app/api/calendar/route.ts
+++ b/src/web/src/app/api/calendar/route.ts
@@ -178,7 +178,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
if (body.conversation_id && agent.ownerId) {
const conv = await queries.conversation.getConversation(db, body.conversation_id, ws.workspaceId);
if (conv) {
- const eventContent = `Calendar set: ${body.title} — ${scheduledAtIso}`;
+ const eventContent = `${body.title}`;
const metadata = JSON.stringify({ calendarEventId: created.id });
const eventMsg = await queries.message.createMessage(db, {
conversationId: body.conversation_id,
@@ -199,7 +199,7 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
metadata: { calendarEventId: created.id },
created_at: eventMsg.createdAt,
},
- }).catch(() => {});
+ }).catch(() => { });
}
}
diff --git a/src/web/src/lib/services/calendar.test.ts b/src/web/src/lib/services/calendar.test.ts
index 1b1de0b96..209dcfc35 100644
--- a/src/web/src/lib/services/calendar.test.ts
+++ b/src/web/src/lib/services/calendar.test.ts
@@ -279,7 +279,12 @@ describe("promoteDueCalendarEventsForWorkspace", () => {
await promoteDueCalendarEventsForWorkspace(fakeDb, "ws_1", "2026-04-17T09:05:00.000Z");
+ expect(mockCreateTask.mock.calls[0][1].contextKey).toBe("cv_1");
expect(mockCreateTask.mock.calls[0][1].context).toEqual({
+ event_id: "ce_1",
+ datetime: "2026-04-17T09:00:00.000Z",
+ is_recurring: false,
+ repeat_interval: null,
description: "Check PRs",
scheduled_by: { name: "Gus", email: "[email protected]" },
});
@@ -300,6 +305,10 @@ describe("promoteDueCalendarEventsForWorkspace", () => {
await promoteDueCalendarEventsForWorkspace(fakeDb, "ws_1", "2026-04-17T09:05:00.000Z");
const ctx = mockCreateTask.mock.calls[0][1].context;
+ expect(ctx.event_id).toBe("ce_1");
+ expect(ctx.datetime).toBe("2026-04-17T09:00:00.000Z");
+ expect(ctx.is_recurring).toBe(false);
+ expect(ctx.repeat_interval).toBeNull();
expect(ctx.description).toBeUndefined();
expect(ctx.scheduled_by).toEqual({ name: "Gus", email: "[email protected]" });
});
@@ -320,10 +329,37 @@ describe("promoteDueCalendarEventsForWorkspace", () => {
await promoteDueCalendarEventsForWorkspace(fakeDb, "ws_1", "2026-04-17T09:05:00.000Z");
const ctx = mockCreateTask.mock.calls[0][1].context;
+ expect(ctx.event_id).toBe("ce_1");
+ expect(ctx.datetime).toBe("2026-04-17T09:00:00.000Z");
+ expect(ctx.is_recurring).toBe(false);
+ expect(ctx.repeat_interval).toBeNull();
expect(ctx.description).toBe("Check PRs");
expect(ctx.scheduled_by).toBeUndefined();
});
+ it("includes is_recurring=true and repeat_interval for recurring events", async () => {
+ mockListDue.mockResolvedValue([
+ mkEvent({ repeatInterval: "1week", description: null }),
+ ]);
+ mockGetAgent.mockResolvedValue({
+ id: "ag_1",
+ workspaceId: "ws_1",
+ runtimeId: "rt_1",
+ ownerId: "u_1",
+ });
+ mockClaim.mockResolvedValue({ id: "ce_1" });
+ mockCreateConv.mockResolvedValue({ id: "cv_1" });
+ mockCreateTask.mockResolvedValue({ id: "t_1" });
+
+ await promoteDueCalendarEventsForWorkspace(fakeDb, "ws_1", "2026-04-17T09:05:00.000Z");
+
+ const ctx = mockCreateTask.mock.calls[0][1].context;
+ expect(ctx.event_id).toBe("ce_1");
+ expect(ctx.datetime).toBe("2026-04-17T09:00:00.000Z");
+ expect(ctx.is_recurring).toBe(true);
+ expect(ctx.repeat_interval).toBe("1week");
+ });
+
it("does not advance the schedule when the next occurrence would exceed repeat_stop_at", async () => {
mockListDue.mockResolvedValue([
mkEvent({
diff --git a/src/web/src/lib/services/calendar.ts b/src/web/src/lib/services/calendar.ts
index d9212bf57..a2ffd25e9 100644
--- a/src/web/src/lib/services/calendar.ts
+++ b/src/web/src/lib/services/calendar.ts
@@ -90,7 +90,12 @@ export async function promoteDueCalendarEventsForWorkspace(
}
const ownerInfo = ownerCache.get(agent.ownerId)!;
- const taskContext: Record<string, unknown> = {};
+ const taskContext: Record<string, unknown> = {
+ event_id: ev.id,
+ datetime: ev.scheduledAt,
+ is_recurring: !!ev.repeatInterval,
+ repeat_interval: ev.repeatInterval ?? null,
+ };
if (ev.description) {
taskContext.description = ev.description;
}
@@ -103,12 +108,13 @@ export async function promoteDueCalendarEventsForWorkspace(
runtimeId: agent.runtimeId,
workspaceId: ev.workspaceId,
conversationId: conv.id,
+ contextKey: conv.id,
prompt: ev.title,
type: TASK_TYPES.CALENDAR_EVENT,
priority: 0,
traceId: "tr_" + nanoid(),
parentTaskId: null,
- context: Object.keys(taskContext).length > 0 ? taskContext : undefined,
+ context: taskContext,
});
if (ev.repeatInterval) {