feat: scheduled tasks (automations) (#3638)

Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Fable 5 authored and maria-rcks committed 2026-08-03 11:45:07 -04:00
1 parent 7791d6b2bf
commit 335708df8b
24 files changed
+2771 -44

No files matched your search

@@ -45,6 +45,7 @@ export type EnvironmentSubscriptionRpcTag =
| typeof WS_METHODS.subscribeAuthAccess
| typeof WS_METHODS.subscribeServerConfig
| typeof WS_METHODS.subscribeServerLifecycle
| typeof WS_METHODS.scheduledTasksSubscribe
| typeof WS_METHODS.subscribeTerminalEvents
| typeof WS_METHODS.subscribeTerminalMetadata
| typeof WS_METHODS.subscribePreviewEvents
+28 -16
View File
@@ -673,15 +673,10 @@ export function createServerEnvironmentAtoms<R, E>(
label: "environment-data:server:process-resource-history",
tag: WS_METHODS.serverGetProcessResourceHistory,
}),
resourceTelemetry: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
label: "environment-data:server:resource-telemetry",
tag: WS_METHODS.subscribeResourceTelemetry,
idleTtlMs: 0,
}),
resourceTelemetryHistory: createEnvironmentRpcQueryAtomFamily(runtime, {
label: "environment-data:server:resource-telemetry-history",
tag: WS_METHODS.serverGetResourceTelemetryHistory,
staleTimeMs: 5_000,
/** Live scheduled-task list: snapshot on subscribe, fresh list after every server-side change. */
scheduledTasksLive: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
label: "environment-data:server:scheduled-tasks:live",
tag: WS_METHODS.scheduledTasksSubscribe,
}),
configProjection,
welcome: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
@@ -729,13 +724,30 @@ export function createServerEnvironmentAtoms<R, E>(
label: "environment-data:server:signal-process",
tag: WS_METHODS.serverSignalProcess,
}),
retryResourceTelemetry: createEnvironmentRpcCommand(runtime, {
label: "environment-data:server:retry-resource-telemetry",
tag: WS_METHODS.serverRetryResourceTelemetry,
concurrency: {
mode: "singleFlight",
key: ({ environmentId }) => environmentId,
},
upsertScheduledTask: createEnvironmentRpcCommand(runtime, {
label: "environment-data:server:scheduled-task:upsert",
tag: WS_METHODS.scheduledTasksUpsert,
scheduler: configScheduler,
concurrency: configConcurrency,
}),
setScheduledTaskEnabled: createEnvironmentRpcCommand(runtime, {
label: "environment-data:server:scheduled-task:set-enabled",
tag: WS_METHODS.scheduledTasksSetEnabled,
scheduler: configScheduler,
concurrency: configConcurrency,
}),
deleteScheduledTask: createEnvironmentRpcCommand(runtime, {
label: "environment-data:server:scheduled-task:delete",
tag: WS_METHODS.scheduledTasksDelete,
scheduler: configScheduler,
concurrency: configConcurrency,
}),
// Deliberately not on the config lane: run-now blocks until the run is
// dispatched, and a slow run must not stall settings/keybinding/provider
// mutations (or other scheduled-task edits) queued behind it.
runScheduledTaskNow: createEnvironmentRpcCommand(runtime, {
label: "environment-data:server:scheduled-task:run-now",
tag: WS_METHODS.scheduledTasksRunNow,
}),
};
}
+2
View File
@@ -95,6 +95,8 @@ export const RuntimeRequestId = makeEntityId("RuntimeRequestId");
export type RuntimeRequestId = typeof RuntimeRequestId.Type;
export const RuntimeTaskId = makeEntityId("RuntimeTaskId");
export type RuntimeTaskId = typeof RuntimeTaskId.Type;
export const ScheduledTaskId = makeEntityId("ScheduledTaskId");
export type ScheduledTaskId = typeof ScheduledTaskId.Type;
export const ApprovalRequestId = makeEntityId("ApprovalRequestId");
export type ApprovalRequestId = typeof ApprovalRequestId.Type;
export const CheckpointRef = makeEntityId("CheckpointRef");
+1 -1
View File
@@ -33,5 +33,5 @@ export * from "./assets.ts";
export * from "./review.ts";
export * from "./preview.ts";
export * from "./previewAutomation.ts";
export * from "./resourceTelemetry.ts";
export * from "./scheduledTask.ts";
export * from "./rpc.ts";
+65
View File
@@ -9,10 +9,12 @@ import {
PositiveInt,
ProjectId,
RunId,
ScheduledTaskId,
ThreadId,
TrimmedNonEmptyString,
TurnItemId,
} from "./baseSchemas.ts";
import { ScheduledTaskRunStatus, ScheduledTaskSchedule } from "./scheduledTask.ts";
import { ProviderInteractionMode, RuntimeMode } from "./providerPolicy.ts";
import {
OrchestrationV2Actor,
@@ -363,11 +365,74 @@ export const OrchestratorMcpCapabilitiesResult = Schema.Struct({
batchThreadCreation: Schema.Boolean,
threadManagement: Schema.Boolean,
incrementalThreadRead: Schema.Boolean,
scheduledTasks: Schema.Boolean,
maxBatchThreads: Schema.Number,
}),
});
export type OrchestratorMcpCapabilitiesResult = typeof OrchestratorMcpCapabilitiesResult.Type;
export const OrchestratorMcpScheduleTaskInput = Schema.Struct({
prompt: OrchestratorMcpPrompt,
schedule: ScheduledTaskSchedule,
title: Schema.optional(OrchestratorMcpTitle),
enabled: Schema.optional(Schema.Boolean),
/**
* When true (the default), the scheduled task fires into the calling thread
* on each run instead of launching a fresh thread. This is the recurring
* "wake up in this thread" behaviour reserved for agent-created tasks.
*/
bindToCurrentThread: Schema.optional(Schema.Boolean),
clientRequestId: Schema.optional(OrchestratorMcpClientRequestId),
});
export type OrchestratorMcpScheduleTaskInput = typeof OrchestratorMcpScheduleTaskInput.Type;
/** Summary of a scheduled task returned by the schedule/list/update tools. */
export const OrchestratorMcpScheduledTask = Schema.Struct({
scheduledTaskId: ScheduledTaskId,
title: Schema.String,
prompt: Schema.String,
enabled: Schema.Boolean,
projectId: ProjectId,
boundThreadId: Schema.NullOr(ThreadId),
schedule: ScheduledTaskSchedule,
nextRunAt: Schema.NullOr(IsoDateTime),
lastRunStatus: ScheduledTaskRunStatus,
});
export type OrchestratorMcpScheduledTask = typeof OrchestratorMcpScheduledTask.Type;
export const OrchestratorMcpScheduleTaskResult = OrchestratorMcpScheduledTask;
export type OrchestratorMcpScheduleTaskResult = typeof OrchestratorMcpScheduleTaskResult.Type;
export const OrchestratorMcpListScheduledTasksResult = Schema.Struct({
tasks: Schema.Array(OrchestratorMcpScheduledTask),
});
export type OrchestratorMcpListScheduledTasksResult =
typeof OrchestratorMcpListScheduledTasksResult.Type;
export const OrchestratorMcpUpdateScheduledTaskInput = Schema.Struct({
scheduledTaskId: ScheduledTaskId,
prompt: Schema.optional(OrchestratorMcpPrompt),
title: Schema.optional(OrchestratorMcpTitle),
schedule: Schema.optional(ScheduledTaskSchedule),
enabled: Schema.optional(Schema.Boolean),
bindToCurrentThread: Schema.optional(Schema.Boolean),
});
export type OrchestratorMcpUpdateScheduledTaskInput =
typeof OrchestratorMcpUpdateScheduledTaskInput.Type;
export const OrchestratorMcpDeleteScheduledTaskInput = Schema.Struct({
scheduledTaskId: ScheduledTaskId,
});
export type OrchestratorMcpDeleteScheduledTaskInput =
typeof OrchestratorMcpDeleteScheduledTaskInput.Type;
export const OrchestratorMcpDeleteScheduledTaskResult = Schema.Struct({
scheduledTaskId: ScheduledTaskId,
deleted: Schema.Boolean,
});
export type OrchestratorMcpDeleteScheduledTaskResult =
typeof OrchestratorMcpDeleteScheduledTaskResult.Type;
export class OrchestratorMcpFailure extends Schema.TaggedErrorClass<OrchestratorMcpFailure>()(
"OrchestratorMcpFailure",
{
+64 -3
View File
@@ -140,6 +140,18 @@ import {
ResourceTelemetrySnapshot,
} from "./resourceTelemetry.ts";
import { ServerSettings, ServerSettingsError, ServerSettingsPatch } from "./settings.ts";
import {
ScheduledTaskDeleteInput,
ScheduledTaskDeleteResult,
ScheduledTaskError,
ScheduledTaskListInput,
ScheduledTaskListResult,
ScheduledTaskRunNowInput,
ScheduledTaskRunNowResult,
ScheduledTaskSetEnabledInput,
ScheduledTaskUpsertInput,
ScheduledTaskMutationResult,
} from "./scheduledTask.ts";
import {
SourceControlCloneRepositoryInput,
SourceControlCloneRepositoryResult,
@@ -234,6 +246,14 @@ export const WS_METHODS = {
serverReportHostPowerState: "server.reportHostPowerState",
serverGetBackgroundPolicy: "server.getBackgroundPolicy",
// Scheduled tasks
scheduledTasksList: "scheduledTasks.list",
scheduledTasksSubscribe: "scheduledTasks.subscribe",
scheduledTasksUpsert: "scheduledTasks.upsert",
scheduledTasksSetEnabled: "scheduledTasks.setEnabled",
scheduledTasksDelete: "scheduledTasks.delete",
scheduledTasksRunNow: "scheduledTasks.runNow",
// Cloud environment methods
cloudGetRelayClientStatus: "cloud.getRelayClientStatus",
cloudInstallRelayClient: "cloud.installRelayClient",
@@ -789,6 +809,44 @@ export const WsSubscribeServerLifecycleRpc = Rpc.make(WS_METHODS.subscribeServer
stream: true,
});
export const WsScheduledTasksListRpc = Rpc.make(WS_METHODS.scheduledTasksList, {
payload: ScheduledTaskListInput,
success: ScheduledTaskListResult,
error: Schema.Union([ScheduledTaskError, EnvironmentAuthorizationError]),
});
/** Streams the full scheduled-task list: one snapshot on subscribe, then a fresh list after every change. */
export const WsScheduledTasksSubscribeRpc = Rpc.make(WS_METHODS.scheduledTasksSubscribe, {
payload: ScheduledTaskListInput,
success: ScheduledTaskListResult,
error: Schema.Union([ScheduledTaskError, EnvironmentAuthorizationError]),
stream: true,
});
export const WsScheduledTasksUpsertRpc = Rpc.make(WS_METHODS.scheduledTasksUpsert, {
payload: ScheduledTaskUpsertInput,
success: ScheduledTaskMutationResult,
error: Schema.Union([ScheduledTaskError, EnvironmentAuthorizationError]),
});
export const WsScheduledTasksSetEnabledRpc = Rpc.make(WS_METHODS.scheduledTasksSetEnabled, {
payload: ScheduledTaskSetEnabledInput,
success: ScheduledTaskMutationResult,
error: Schema.Union([ScheduledTaskError, EnvironmentAuthorizationError]),
});
export const WsScheduledTasksDeleteRpc = Rpc.make(WS_METHODS.scheduledTasksDelete, {
payload: ScheduledTaskDeleteInput,
success: ScheduledTaskDeleteResult,
error: Schema.Union([ScheduledTaskError, EnvironmentAuthorizationError]),
});
export const WsScheduledTasksRunNowRpc = Rpc.make(WS_METHODS.scheduledTasksRunNow, {
payload: ScheduledTaskRunNowInput,
success: ScheduledTaskRunNowResult,
error: Schema.Union([ScheduledTaskError, EnvironmentAuthorizationError]),
});
export const WsSubscribeAuthAccessRpc = Rpc.make(WS_METHODS.subscribeAuthAccess, {
payload: Schema.Struct({}),
success: AuthAccessStreamEvent,
@@ -828,9 +886,12 @@ export const WsRpcGroup = RpcGroup.make(
WsServerGetResourceTelemetryHistoryRpc,
WsServerRetryResourceTelemetryRpc,
WsServerSignalProcessRpc,
WsServerReportClientActivityRpc,
WsServerReportHostPowerStateRpc,
WsServerGetBackgroundPolicyRpc,
WsScheduledTasksListRpc,
WsScheduledTasksSubscribeRpc,
WsScheduledTasksUpsertRpc,
WsScheduledTasksSetEnabledRpc,
WsScheduledTasksDeleteRpc,
WsScheduledTasksRunNowRpc,
WsCloudGetRelayClientStatusRpc,
WsCloudInstallRelayClientRpc,
WsSourceControlLookupRepositoryRpc,
+130
View File
@@ -0,0 +1,130 @@
import * as Schema from "effect/Schema";
import {
CommandId,
IsoDateTime,
PositiveInt,
ProjectId,
ScheduledTaskId,
ThreadId,
TrimmedNonEmptyString,
} from "./baseSchemas.ts";
import { ModelSelection } from "./modelSelection.ts";
import {
OrchestrationV2Actor,
OrchestrationV2CreationSource,
OrchestrationV2ThreadLaunchWorkspaceStrategy,
} from "./orchestrationV2.ts";
import { ProviderInteractionMode, RuntimeMode } from "./providerPolicy.ts";
/** 24-hour "HH:MM" wall-clock time. Mirrors `parseTimeOfDay` on the server. */
const TimeOfDay = TrimmedNonEmptyString.check(Schema.isPattern(/^([01]?\d|2[0-3]):([0-5]\d)$/));
export const ScheduledTaskSchedule = Schema.Union([
Schema.Struct({
type: Schema.Literal("interval"),
everyMs: PositiveInt,
}),
Schema.Struct({
type: Schema.Literal("fixed_time"),
timeOfDay: TimeOfDay,
weekdays: Schema.optional(
Schema.Array(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: 6 }))),
),
}),
]);
export type ScheduledTaskSchedule = typeof ScheduledTaskSchedule.Type;
export const ScheduledTaskRunStatus = Schema.Literals(["never", "running", "succeeded", "failed"]);
export type ScheduledTaskRunStatus = typeof ScheduledTaskRunStatus.Type;
export const ScheduledTask = Schema.Struct({
id: ScheduledTaskId,
title: TrimmedNonEmptyString,
prompt: TrimmedNonEmptyString,
enabled: Schema.Boolean,
schedule: ScheduledTaskSchedule,
projectId: ProjectId,
threadId: Schema.NullOr(ThreadId),
workspaceStrategy: OrchestrationV2ThreadLaunchWorkspaceStrategy,
modelSelection: ModelSelection,
runtimeMode: RuntimeMode,
interactionMode: ProviderInteractionMode,
createdBy: OrchestrationV2Actor,
creationSource: OrchestrationV2CreationSource,
createdAt: IsoDateTime,
updatedAt: IsoDateTime,
nextRunAt: Schema.NullOr(IsoDateTime),
lastRunAt: Schema.NullOr(IsoDateTime),
lastRunStatus: ScheduledTaskRunStatus,
lastRunError: Schema.NullOr(Schema.String),
runCount: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
});
export type ScheduledTask = typeof ScheduledTask.Type;
export const ScheduledTaskListInput = Schema.Struct({});
export type ScheduledTaskListInput = typeof ScheduledTaskListInput.Type;
export const ScheduledTaskListResult = Schema.Struct({
tasks: Schema.Array(ScheduledTask),
});
export type ScheduledTaskListResult = typeof ScheduledTaskListResult.Type;
export const ScheduledTaskUpsertInput = Schema.Struct({
id: Schema.optional(ScheduledTaskId),
commandId: Schema.optional(CommandId),
title: TrimmedNonEmptyString,
prompt: TrimmedNonEmptyString,
enabled: Schema.Boolean,
schedule: ScheduledTaskSchedule,
projectId: ProjectId,
threadId: Schema.optional(Schema.NullOr(ThreadId)),
workspaceStrategy: OrchestrationV2ThreadLaunchWorkspaceStrategy,
modelSelection: ModelSelection,
runtimeMode: RuntimeMode,
interactionMode: ProviderInteractionMode,
createdBy: Schema.optional(OrchestrationV2Actor),
creationSource: Schema.optional(OrchestrationV2CreationSource),
});
export type ScheduledTaskUpsertInput = typeof ScheduledTaskUpsertInput.Type;
/** Partial update that flips only the enabled flag — never overwrites other fields. */
export const ScheduledTaskSetEnabledInput = Schema.Struct({
id: ScheduledTaskId,
enabled: Schema.Boolean,
});
export type ScheduledTaskSetEnabledInput = typeof ScheduledTaskSetEnabledInput.Type;
export const ScheduledTaskDeleteInput = Schema.Struct({
id: ScheduledTaskId,
});
export type ScheduledTaskDeleteInput = typeof ScheduledTaskDeleteInput.Type;
export const ScheduledTaskRunNowInput = Schema.Struct({
id: ScheduledTaskId,
});
export type ScheduledTaskRunNowInput = typeof ScheduledTaskRunNowInput.Type;
export const ScheduledTaskMutationResult = Schema.Struct({
task: ScheduledTask,
});
export type ScheduledTaskMutationResult = typeof ScheduledTaskMutationResult.Type;
export const ScheduledTaskDeleteResult = Schema.Struct({
id: ScheduledTaskId,
});
export type ScheduledTaskDeleteResult = typeof ScheduledTaskDeleteResult.Type;
export const ScheduledTaskRunNowResult = Schema.Struct({
task: ScheduledTask,
});
export type ScheduledTaskRunNowResult = typeof ScheduledTaskRunNowResult.Type;
export class ScheduledTaskError extends Schema.TaggedErrorClass<ScheduledTaskError>()(
"ScheduledTaskError",
{
message: Schema.String,
taskId: Schema.optional(ScheduledTaskId),
cause: Schema.optional(Schema.Defect()),
},
) {}