Files
openclaw/src/cron/script-payload.ts
Peter Steinberger 68771ebdfe feat(cron): script payloads behind the trigger gate (#111112)
Run script payloads through the shared headless code-mode executor with payload-grade budgets and success-only trigger.state persistence.

Reuse cron delivery, wake, pacing, and dangerous trigger-gate contracts for notify, wake, and nextCheck results.
2026-07-18 19:24:12 -07:00

34 lines
1.1 KiB
TypeScript

import type { CronPayload } from "./types.js";
export const DEFAULT_CRON_SCRIPT_TIMEOUT_SECONDS = 300;
export const MAX_CRON_SCRIPT_TIMEOUT_SECONDS = 900;
export const DEFAULT_CRON_SCRIPT_TOOL_BUDGET = 50;
export const MAX_CRON_SCRIPT_TOOL_BUDGET = 200;
function clampPositiveInteger(value: unknown, fallback: number, maximum: number): number {
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
return fallback;
}
return Math.min(maximum, Math.max(1, Math.floor(value)));
}
/** Applies the persisted defaults and hard caps for unattended script payloads. */
export function normalizeCronScriptPayload(
payload: Extract<CronPayload, { kind: "script" }>,
): Extract<CronPayload, { kind: "script" }> {
return {
...payload,
script: payload.script.trim(),
timeoutSeconds: clampPositiveInteger(
payload.timeoutSeconds,
DEFAULT_CRON_SCRIPT_TIMEOUT_SECONDS,
MAX_CRON_SCRIPT_TIMEOUT_SECONDS,
),
toolBudget: clampPositiveInteger(
payload.toolBudget,
DEFAULT_CRON_SCRIPT_TOOL_BUDGET,
MAX_CRON_SCRIPT_TOOL_BUDGET,
),
};
}