Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -976,14 +976,14 @@ async function schedulesScenario(client) {
client,
`(() => {
const button = [...document.querySelectorAll('button, [role="button"]')].find(
(candidate) => candidate.getAttribute("aria-label") === "Schedules" || candidate.textContent?.trim() === "Schedules",
(candidate) => candidate.getAttribute("aria-label") === "Automations" || candidate.textContent?.trim() === "Automations",
);
if (!(button instanceof HTMLElement)) return false;
button.click();
return true;
})()`,
);
assert(opened, "Schedules was not available in the main sidebar");
assert(opened, "Automations was not available in the main sidebar");
const rendered = await waitForValue(
() =>
evaluate(
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
"@xterm/addon-webgl": "0.20.0-beta.218",
"@xterm/xterm": "6.1.0-beta.219",
"better-sqlite3": "^12.11.1",
"cron-parser": "5.6.1",
"dexie": "^4.4.4",
"drizzle-orm": "1.0.0-rc.1",
"electron-updater": "^6.8.9",
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/build-desktop-artifact.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const RUNTIME_DEPS = [
"@sentry/electron",
"@sentry/node",
"better-sqlite3",
"cron-parser",
"drizzle-orm",
"json5",
"micromatch",
Expand Down
6 changes: 5 additions & 1 deletion src/main/app-controls/AppControlsMcpIngress.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ describe("AppControlsMcpIngress", () => {
agentKind: "codex",
config: { model: "gpt-5.6", effort: "high" },
} as Thread;
ingress = new AppControlsMcpIngress(service, (id) => (id === thread.id ? thread : null));
ingress = new AppControlsMcpIngress(service, (id) => (id === thread.id ? thread : null), {
listScheduleRuns: vi.fn<() => never[]>(() => []),
listScheduleRunInbox: vi.fn<() => never[]>(() => []),
updateScheduleRunState: vi.fn<() => null>(() => null),
});
const info = await ingress.start();

const response = await fetch(`${info.url}/mcp?thread=thread-1`, {
Expand Down
9 changes: 7 additions & 2 deletions src/main/app-controls/AppControlsMcpIngress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
dispatchTool,
formatToolResult,
isKnownToolName,
type AppControlsScheduleRunControls,
type AppControlsToolContext,
} from "./mcp/toolRegistry";

Expand All @@ -18,13 +19,17 @@ export type AppControlsMcpIngressInfo = StreamableHttpMcpIngressInfo;
export class AppControlsMcpIngress {
private readonly ingress: StreamableHttpMcpIngress<AppControlsToolContext>;

constructor(scheduleService: ScheduleService, getThread: (threadId: string) => Thread | null) {
constructor(
scheduleService: ScheduleService,
getThread: (threadId: string) => Thread | null,
scheduleRuns: AppControlsScheduleRunControls,
) {
this.ingress = new StreamableHttpMcpIngress<AppControlsToolContext>({
serverInfo: { name: "poracode", version: "1.0.0" },
instructions: APP_CONTROLS_MCP_INSTRUCTIONS,
tools: TOOLS,
isKnownToolName,
buildContext: (identity) => ({ identity, scheduleService, getThread }),
buildContext: (identity) => ({ identity, scheduleService, scheduleRuns, getThread }),
dispatchTool,
formatToolResult,
});
Expand Down
121 changes: 121 additions & 0 deletions src/main/app-controls/mcp/scheduleToolSchemas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { z } from "zod";
import {
agentKindSchema,
scheduleAutomationSchema,
scheduleRecurrenceSchema,
scheduleRunInboxQuerySchema,
} from "@/shared/contracts";

export const createScheduleArgsSchema = z.object({
name: z.string().trim().min(1).max(120),
prompt: z.string().trim().min(1).max(50_000),
recurrence: scheduleRecurrenceSchema,
enabled: z.boolean().optional().default(true),
agentKind: agentKindSchema.optional(),
model: z.string().min(1).optional(),
effort: z.string().min(1).optional(),
automation: scheduleAutomationSchema.optional(),
});

export const updateScheduleArgsSchema = z.object({
id: z.string().uuid(),
name: z.string().trim().min(1).max(120).optional(),
prompt: z.string().trim().min(1).max(50_000).optional(),
recurrence: scheduleRecurrenceSchema.optional(),
enabled: z.boolean().optional(),
agentKind: agentKindSchema.optional(),
model: z.string().min(1).optional(),
effort: z.string().min(1).nullable().optional(),
automation: scheduleAutomationSchema.optional(),
});

export const idArgsSchema = z.object({ id: z.string().uuid() });
export const scheduleRunsArgsSchema = z.object({ scheduleId: z.string().uuid() });
export const scheduleRunInboxArgsSchema = scheduleRunInboxQuerySchema.extend({
filter: scheduleRunInboxQuerySchema.shape.filter.default("unread"),
});

export function idJsonSchema(): Record<string, unknown> {
return {
type: "object",
additionalProperties: false,
required: ["id"],
properties: { id: { type: "string", format: "uuid" } },
};
}

export function recurrenceJsonSchema(): Record<string, unknown> {
return {
oneOf: [
{
type: "object",
additionalProperties: false,
required: ["kind", "minute"],
properties: {
kind: { const: "hourly" },
minute: { type: "integer", minimum: 0, maximum: 59 },
},
},
{
type: "object",
additionalProperties: false,
required: ["kind", "days", "time"],
properties: {
kind: { const: "weekly" },
days: {
type: "array",
minItems: 1,
items: { type: "integer", minimum: 0, maximum: 6 },
},
time: { type: "string", pattern: "^([01]\\d|2[0-3]):[0-5]\\d$" },
timeZone: { type: "string", minLength: 1, maxLength: 128 },
},
},
{
type: "object",
additionalProperties: false,
required: ["kind", "runAt"],
properties: {
kind: { const: "once" },
runAt: { type: "string", format: "date-time" },
},
},
{
type: "object",
additionalProperties: false,
required: ["kind", "every", "unit"],
properties: {
kind: { const: "interval" },
every: { type: "integer", minimum: 1, maximum: 999 },
unit: { enum: ["minutes", "hours", "days"] },
},
},
{
type: "object",
additionalProperties: false,
required: ["kind", "expression", "timeZone"],
properties: {
kind: { const: "cron" },
expression: {
type: "string",
minLength: 1,
maxLength: 120,
pattern: "^\\s*[0-9*,/-]+(?:\\s+[0-9*,/-]+){4}\\s*$",
description: "Five numeric cron fields: minute, hour, day, month, and weekday.",
},
timeZone: { type: "string", minLength: 1, maxLength: 128 },
},
},
],
};
}

export function automationJsonSchema(): Record<string, unknown> {
const jsonSchema = z.toJSONSchema(scheduleAutomationSchema);
delete jsonSchema.$schema;
return {
...jsonSchema,
description:
"Complete automation policy. AI-evaluated completion conditions are valid only in heartbeat mode.",
};
}
Loading