Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export async function executeReminder(
text: reminder.originalPrompt,
},
],
...(reminder.agent === undefined ? {} : { agent: reminder.agent }),
},
})

Expand Down
18 changes: 18 additions & 0 deletions test/integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test, expect, describe, beforeEach, afterEach } from "bun:test"
import RemindersPlugin from "../index"
import { listReminders } from "../storage"
import type { PluginInput } from "@opencode-ai/plugin"
import { $ } from "bun"

Expand Down Expand Up @@ -80,6 +81,23 @@ describe("Integration Tests", () => {
expect(result).toContain("File change check")
})

test("reminderadd persists the scheduling agent", async () => {
const plugin = await RemindersPlugin(ctx)

await plugin.tool!.reminderadd.execute(
{
interval_seconds: 60,
type: "one-time" as const,
action_prompt: "check /workspace/test.txt for changes",
description: "Agent preservation test",
},
{ sessionID: "ses-agent-test", agent: "God" } as any,
)

const [reminder] = await listReminders(ctx)
expect(reminder.agent).toBe("God")
})

test("reminderlist tool returns empty for new session", async () => {
const plugin = await RemindersPlugin(ctx)

Expand Down
33 changes: 33 additions & 0 deletions test/scheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ describe("Scheduler", () => {
test("executeReminder calls session prompt", async () => {
let promptCalled = false
let capturedPrompt = ""
let capturedAgent: string | undefined

;(ctx.client.session.prompt as any) = async (opts: any) => {
promptCalled = true
capturedPrompt = opts.body?.parts?.[0]?.text || ""
capturedAgent = opts.body?.agent
return { data: {} as any, error: undefined, response: {} as any }
}

Expand All @@ -166,6 +168,7 @@ describe("Scheduler", () => {
interval: 100,
originalPrompt: "test prompt text",
userDescription: "Execute test",
agent: "God",
time: {
created: Date.now(),
nextExecution: Date.now() + 100,
Expand All @@ -180,6 +183,36 @@ describe("Scheduler", () => {

expect(promptCalled).toBe(true)
expect(capturedPrompt).toBe("test prompt text")
expect(capturedAgent).toBe("God")
})

test("executeReminder omits agent for legacy reminders", async () => {
let capturedBody: any

;(ctx.client.session.prompt as any) = async (opts: any) => {
capturedBody = opts.body
return { data: {} as any, error: undefined, response: {} as any }
}

const reminder: Reminder = {
id: "rem-legacy-agent-test",
sessionID: "ses-test",
projectID: "test-project-123",
type: "one-time",
interval: 100,
originalPrompt: "legacy prompt text",
userDescription: "Legacy agent test",
time: {
created: Date.now(),
nextExecution: Date.now() + 100,
},
status: "active",
}

state.reminders.set(reminder.id, reminder)
await executeReminder(reminder, ctx, state, config)

expect(capturedBody).not.toHaveProperty("agent")
})

test("executeReminder updates lastExecution time", async () => {
Expand Down
20 changes: 20 additions & 0 deletions test/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ describe("Reminder Types", () => {
expect(() => ReminderSchema.parse(validReminder)).not.toThrow()
})

test("ReminderSchema allows legacy reminders without an agent", () => {
const legacyReminder = {
id: "test-123",
sessionID: "ses-456",
projectID: "prj-789",
type: "one-time" as const,
interval: 5000,
originalPrompt: "check /workspace/test.txt",
userDescription: "Test reminder",
time: {
created: Date.now(),
nextExecution: Date.now() + 5000,
},
status: "active" as const,
}

const parsed = ReminderSchema.parse(legacyReminder)
expect(parsed.agent).toBeUndefined()
})

test("ReminderSchema rejects invalid type", () => {
const invalidReminder = {
id: "test-123",
Expand Down
1 change: 1 addition & 0 deletions tools/reminderadd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function createReminderAddTool(
interval: args.interval_seconds * 1000,
originalPrompt: args.action_prompt,
userDescription: args.description,
agent: context.agent,
time: {
created: Date.now(),
nextExecution: Date.now() + args.interval_seconds * 1000,
Expand Down
1 change: 1 addition & 0 deletions types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const ReminderSchema = z.object({
interval: z.number(),
originalPrompt: z.string(),
userDescription: z.string(),
agent: z.string().optional(),
time: z.object({
created: z.number(),
nextExecution: z.number(),
Expand Down