mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 21:01:43 +03:00
chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -67,53 +67,27 @@ export function registerCronAddCommand(cron: Command) {
|
||||
.requiredOption("--name <name>", "Job name")
|
||||
.option("--description <text>", "Optional description")
|
||||
.option("--disabled", "Create job disabled", false)
|
||||
.option(
|
||||
"--delete-after-run",
|
||||
"Delete one-shot job after it succeeds",
|
||||
false,
|
||||
)
|
||||
.option("--delete-after-run", "Delete one-shot job after it succeeds", false)
|
||||
.option("--agent <id>", "Agent id for this job")
|
||||
.option("--session <target>", "Session target (main|isolated)", "main")
|
||||
.option(
|
||||
"--wake <mode>",
|
||||
"Wake mode (now|next-heartbeat)",
|
||||
"next-heartbeat",
|
||||
)
|
||||
.option("--wake <mode>", "Wake mode (now|next-heartbeat)", "next-heartbeat")
|
||||
.option("--at <when>", "Run once at time (ISO) or +duration (e.g. 20m)")
|
||||
.option("--every <duration>", "Run every duration (e.g. 10m, 1h)")
|
||||
.option("--cron <expr>", "Cron expression (5-field)")
|
||||
.option("--tz <iana>", "Timezone for cron expressions (IANA)", "")
|
||||
.option("--system-event <text>", "System event payload (main session)")
|
||||
.option("--message <text>", "Agent message payload")
|
||||
.option(
|
||||
"--thinking <level>",
|
||||
"Thinking level for agent jobs (off|minimal|low|medium|high)",
|
||||
)
|
||||
.option(
|
||||
"--model <model>",
|
||||
"Model override for agent jobs (provider/model or alias)",
|
||||
)
|
||||
.option("--thinking <level>", "Thinking level for agent jobs (off|minimal|low|medium|high)")
|
||||
.option("--model <model>", "Model override for agent jobs (provider/model or alias)")
|
||||
.option("--timeout-seconds <n>", "Timeout seconds for agent jobs")
|
||||
.option("--deliver", "Deliver agent output", false)
|
||||
.option(
|
||||
"--channel <channel>",
|
||||
`Delivery channel (${CRON_CHANNEL_OPTIONS})`,
|
||||
"last",
|
||||
)
|
||||
.option("--channel <channel>", `Delivery channel (${CRON_CHANNEL_OPTIONS})`, "last")
|
||||
.option(
|
||||
"--to <dest>",
|
||||
"Delivery destination (E.164, Telegram chatId, or Discord channel/user)",
|
||||
)
|
||||
.option(
|
||||
"--best-effort-deliver",
|
||||
"Do not fail the job if delivery fails",
|
||||
false,
|
||||
)
|
||||
.option(
|
||||
"--post-prefix <prefix>",
|
||||
"Prefix for summary system event",
|
||||
"Cron",
|
||||
)
|
||||
.option("--best-effort-deliver", "Do not fail the job if delivery fails", false)
|
||||
.option("--post-prefix <prefix>", "Prefix for summary system event", "Cron")
|
||||
.option("--json", "Output JSON", false)
|
||||
.action(async (opts: GatewayRpcOpts & Record<string, unknown>) => {
|
||||
try {
|
||||
@@ -121,49 +95,34 @@ export function registerCronAddCommand(cron: Command) {
|
||||
const at = typeof opts.at === "string" ? opts.at : "";
|
||||
const every = typeof opts.every === "string" ? opts.every : "";
|
||||
const cronExpr = typeof opts.cron === "string" ? opts.cron : "";
|
||||
const chosen = [
|
||||
Boolean(at),
|
||||
Boolean(every),
|
||||
Boolean(cronExpr),
|
||||
].filter(Boolean).length;
|
||||
const chosen = [Boolean(at), Boolean(every), Boolean(cronExpr)].filter(Boolean).length;
|
||||
if (chosen !== 1) {
|
||||
throw new Error(
|
||||
"Choose exactly one schedule: --at, --every, or --cron",
|
||||
);
|
||||
throw new Error("Choose exactly one schedule: --at, --every, or --cron");
|
||||
}
|
||||
if (at) {
|
||||
const atMs = parseAtMs(at);
|
||||
if (!atMs)
|
||||
throw new Error(
|
||||
"Invalid --at; use ISO time or duration like 20m",
|
||||
);
|
||||
if (!atMs) throw new Error("Invalid --at; use ISO time or duration like 20m");
|
||||
return { kind: "at" as const, atMs };
|
||||
}
|
||||
if (every) {
|
||||
const everyMs = parseDurationMs(every);
|
||||
if (!everyMs)
|
||||
throw new Error("Invalid --every; use e.g. 10m, 1h, 1d");
|
||||
if (!everyMs) throw new Error("Invalid --every; use e.g. 10m, 1h, 1d");
|
||||
return { kind: "every" as const, everyMs };
|
||||
}
|
||||
return {
|
||||
kind: "cron" as const,
|
||||
expr: cronExpr,
|
||||
tz:
|
||||
typeof opts.tz === "string" && opts.tz.trim()
|
||||
? opts.tz.trim()
|
||||
: undefined,
|
||||
tz: typeof opts.tz === "string" && opts.tz.trim() ? opts.tz.trim() : undefined,
|
||||
};
|
||||
})();
|
||||
|
||||
const sessionTargetRaw =
|
||||
typeof opts.session === "string" ? opts.session : "main";
|
||||
const sessionTargetRaw = typeof opts.session === "string" ? opts.session : "main";
|
||||
const sessionTarget = sessionTargetRaw.trim() || "main";
|
||||
if (sessionTarget !== "main" && sessionTarget !== "isolated") {
|
||||
throw new Error("--session must be main or isolated");
|
||||
}
|
||||
|
||||
const wakeModeRaw =
|
||||
typeof opts.wake === "string" ? opts.wake : "next-heartbeat";
|
||||
const wakeModeRaw = typeof opts.wake === "string" ? opts.wake : "next-heartbeat";
|
||||
const wakeMode = wakeModeRaw.trim() || "next-heartbeat";
|
||||
if (wakeMode !== "now" && wakeMode !== "next-heartbeat") {
|
||||
throw new Error("--wake must be now or next-heartbeat");
|
||||
@@ -175,46 +134,28 @@ export function registerCronAddCommand(cron: Command) {
|
||||
: undefined;
|
||||
|
||||
const payload = (() => {
|
||||
const systemEvent =
|
||||
typeof opts.systemEvent === "string"
|
||||
? opts.systemEvent.trim()
|
||||
: "";
|
||||
const message =
|
||||
typeof opts.message === "string" ? opts.message.trim() : "";
|
||||
const chosen = [Boolean(systemEvent), Boolean(message)].filter(
|
||||
Boolean,
|
||||
).length;
|
||||
const systemEvent = typeof opts.systemEvent === "string" ? opts.systemEvent.trim() : "";
|
||||
const message = typeof opts.message === "string" ? opts.message.trim() : "";
|
||||
const chosen = [Boolean(systemEvent), Boolean(message)].filter(Boolean).length;
|
||||
if (chosen !== 1) {
|
||||
throw new Error(
|
||||
"Choose exactly one payload: --system-event or --message",
|
||||
);
|
||||
throw new Error("Choose exactly one payload: --system-event or --message");
|
||||
}
|
||||
if (systemEvent)
|
||||
return { kind: "systemEvent" as const, text: systemEvent };
|
||||
const timeoutSeconds = parsePositiveIntOrUndefined(
|
||||
opts.timeoutSeconds,
|
||||
);
|
||||
if (systemEvent) return { kind: "systemEvent" as const, text: systemEvent };
|
||||
const timeoutSeconds = parsePositiveIntOrUndefined(opts.timeoutSeconds);
|
||||
return {
|
||||
kind: "agentTurn" as const,
|
||||
message,
|
||||
model:
|
||||
typeof opts.model === "string" && opts.model.trim()
|
||||
? opts.model.trim()
|
||||
: undefined,
|
||||
typeof opts.model === "string" && opts.model.trim() ? opts.model.trim() : undefined,
|
||||
thinking:
|
||||
typeof opts.thinking === "string" && opts.thinking.trim()
|
||||
? opts.thinking.trim()
|
||||
: undefined,
|
||||
timeoutSeconds:
|
||||
timeoutSeconds && Number.isFinite(timeoutSeconds)
|
||||
? timeoutSeconds
|
||||
: undefined,
|
||||
timeoutSeconds && Number.isFinite(timeoutSeconds) ? timeoutSeconds : undefined,
|
||||
deliver: Boolean(opts.deliver),
|
||||
channel: typeof opts.channel === "string" ? opts.channel : "last",
|
||||
to:
|
||||
typeof opts.to === "string" && opts.to.trim()
|
||||
? opts.to.trim()
|
||||
: undefined,
|
||||
to: typeof opts.to === "string" && opts.to.trim() ? opts.to.trim() : undefined,
|
||||
bestEffortDeliver: Boolean(opts.bestEffortDeliver),
|
||||
};
|
||||
})();
|
||||
@@ -230,8 +171,7 @@ export function registerCronAddCommand(cron: Command) {
|
||||
sessionTarget === "isolated"
|
||||
? {
|
||||
postToMainPrefix:
|
||||
typeof opts.postPrefix === "string" &&
|
||||
opts.postPrefix.trim()
|
||||
typeof opts.postPrefix === "string" && opts.postPrefix.trim()
|
||||
? opts.postPrefix.trim()
|
||||
: "Cron",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user