chore: migrate to oxlint and oxfmt

Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
Peter Steinberger
2026-01-14 14:31:43 +00:00
parent 912ebffc63
commit c379191f80
1480 changed files with 28608 additions and 43547 deletions

View File

@@ -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",
}

View File

@@ -20,11 +20,7 @@ export function registerCronEditCommand(cron: Command) {
.option("--description <text>", "Set description")
.option("--enable", "Enable job", false)
.option("--disable", "Disable job", 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("--keep-after-run", "Keep one-shot job after it succeeds", false)
.option("--session <target>", "Session target (main|isolated)")
.option("--agent <id>", "Set agent id")
@@ -40,19 +36,12 @@ export function registerCronEditCommand(cron: Command) {
.option("--model <model>", "Model override for agent jobs")
.option("--timeout-seconds <n>", "Timeout seconds for agent jobs")
.option("--deliver", "Deliver agent output", false)
.option(
"--channel <channel>",
`Delivery channel (${CRON_CHANNEL_OPTIONS})`,
)
.option("--channel <channel>", `Delivery channel (${CRON_CHANNEL_OPTIONS})`)
.option(
"--to <dest>",
"Delivery destination (E.164, Telegram chatId, or Discord channel/user)",
)
.option(
"--best-effort-deliver",
"Do not fail job if delivery fails",
false,
)
.option("--best-effort-deliver", "Do not fail job if delivery fails", false)
.option("--post-prefix <prefix>", "Prefix for summary system event")
.action(async (id, opts) => {
try {
@@ -72,21 +61,17 @@ export function registerCronEditCommand(cron: Command) {
const patch: Record<string, unknown> = {};
if (typeof opts.name === "string") patch.name = opts.name;
if (typeof opts.description === "string")
patch.description = opts.description;
if (typeof opts.description === "string") patch.description = opts.description;
if (opts.enable && opts.disable)
throw new Error("Choose --enable or --disable, not both");
if (opts.enable) patch.enabled = true;
if (opts.disable) patch.enabled = false;
if (opts.deleteAfterRun && opts.keepAfterRun) {
throw new Error(
"Choose --delete-after-run or --keep-after-run, not both",
);
throw new Error("Choose --delete-after-run or --keep-after-run, not both");
}
if (opts.deleteAfterRun) patch.deleteAfterRun = true;
if (opts.keepAfterRun) patch.deleteAfterRun = false;
if (typeof opts.session === "string")
patch.sessionTarget = opts.session;
if (typeof opts.session === "string") patch.sessionTarget = opts.session;
if (typeof opts.wake === "string") patch.wakeMode = opts.wake;
if (opts.agent && opts.clearAgent) {
throw new Error("Use --agent or --clear-agent, not both");
@@ -98,11 +83,8 @@ export function registerCronEditCommand(cron: Command) {
patch.agentId = null;
}
const scheduleChosen = [opts.at, opts.every, opts.cron].filter(
Boolean,
).length;
if (scheduleChosen > 1)
throw new Error("Choose at most one schedule change");
const scheduleChosen = [opts.at, opts.every, opts.cron].filter(Boolean).length;
if (scheduleChosen > 1) throw new Error("Choose at most one schedule change");
if (opts.at) {
const atMs = parseAtMs(String(opts.at));
if (!atMs) throw new Error("Invalid --at");
@@ -115,18 +97,12 @@ export function registerCronEditCommand(cron: Command) {
patch.schedule = {
kind: "cron",
expr: String(opts.cron),
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 payloadChosen = [opts.systemEvent, opts.message].filter(
Boolean,
).length;
if (payloadChosen > 1)
throw new Error("Choose at most one payload change");
const payloadChosen = [opts.systemEvent, opts.message].filter(Boolean).length;
if (payloadChosen > 1) throw new Error("Choose at most one payload change");
if (opts.systemEvent) {
patch.payload = {
kind: "systemEvent",
@@ -134,9 +110,7 @@ export function registerCronEditCommand(cron: Command) {
};
} else if (opts.message) {
const model =
typeof opts.model === "string" && opts.model.trim()
? opts.model.trim()
: undefined;
typeof opts.model === "string" && opts.model.trim() ? opts.model.trim() : undefined;
const thinking =
typeof opts.thinking === "string" && opts.thinking.trim()
? opts.thinking.trim()
@@ -150,12 +124,9 @@ export function registerCronEditCommand(cron: Command) {
model,
thinking,
timeoutSeconds:
timeoutSeconds && Number.isFinite(timeoutSeconds)
? timeoutSeconds
: undefined,
timeoutSeconds && Number.isFinite(timeoutSeconds) ? timeoutSeconds : undefined,
deliver: Boolean(opts.deliver),
channel:
typeof opts.channel === "string" ? opts.channel : undefined,
channel: typeof opts.channel === "string" ? opts.channel : undefined,
to: typeof opts.to === "string" ? opts.to : undefined,
bestEffortDeliver: Boolean(opts.bestEffortDeliver),
};
@@ -163,9 +134,7 @@ export function registerCronEditCommand(cron: Command) {
if (typeof opts.postPrefix === "string") {
patch.isolation = {
postToMainPrefix: opts.postPrefix.trim()
? opts.postPrefix
: "Cron",
postToMainPrefix: opts.postPrefix.trim() ? opts.postPrefix : "Cron",
};
}

View File

@@ -73,8 +73,7 @@ export function registerCronSimpleCommands(cron: Command) {
.action(async (opts) => {
try {
const limitRaw = Number.parseInt(String(opts.limit ?? "50"), 10);
const limit =
Number.isFinite(limitRaw) && limitRaw > 0 ? limitRaw : 50;
const limit = Number.isFinite(limitRaw) && limitRaw > 0 ? limitRaw : 50;
const id = String(opts.id);
const res = await callGatewayFromCli("cron.runs", opts, {
id,

View File

@@ -19,10 +19,7 @@ export function registerCronCli(program: Command) {
.addHelpText(
"after",
() =>
`\n${theme.muted("Docs:")} ${formatDocsLink(
"/cron-jobs",
"docs.clawd.bot/cron-jobs",
)}\n`,
`\n${theme.muted("Docs:")} ${formatDocsLink("/cron-jobs", "docs.clawd.bot/cron-jobs")}\n`,
);
registerCronStatusCommand(cron);

View File

@@ -8,15 +8,9 @@ export function registerWakeCommand(program: Command) {
addGatewayClientOptions(
program
.command("wake")
.description(
"Enqueue a system event and optionally trigger an immediate heartbeat",
)
.description("Enqueue a system event and optionally trigger an immediate heartbeat")
.requiredOption("--text <text>", "System event text")
.option(
"--mode <mode>",
"Wake mode (now|next-heartbeat)",
"next-heartbeat",
)
.option("--mode <mode>", "Wake mode (now|next-heartbeat)", "next-heartbeat")
.option("--json", "Output JSON", false),
).action(async (opts: GatewayRpcOpts & { text?: string; mode?: string }) => {
try {

View File

@@ -108,11 +108,8 @@ const formatRelative = (ms: number | null | undefined, nowMs: number) => {
const formatSchedule = (schedule: CronSchedule) => {
if (schedule.kind === "at") return `at ${formatIsoMinute(schedule.atMs)}`;
if (schedule.kind === "every")
return `every ${formatDuration(schedule.everyMs)}`;
return schedule.tz
? `cron ${schedule.expr} @ ${schedule.tz}`
: `cron ${schedule.expr}`;
if (schedule.kind === "every") return `every ${formatDuration(schedule.everyMs)}`;
return schedule.tz ? `cron ${schedule.expr} @ ${schedule.tz}` : `cron ${schedule.expr}`;
};
const formatStatus = (job: CronJob) => {
@@ -153,26 +150,17 @@ export function printCronList(jobs: CronJob[], runtime = defaultRuntime) {
job.enabled ? formatRelative(job.state.nextRunAtMs, now) : "-",
CRON_NEXT_PAD,
);
const lastLabel = pad(
formatRelative(job.state.lastRunAtMs, now),
CRON_LAST_PAD,
);
const lastLabel = pad(formatRelative(job.state.lastRunAtMs, now), CRON_LAST_PAD);
const statusRaw = formatStatus(job);
const statusLabel = pad(statusRaw, CRON_STATUS_PAD);
const targetLabel = pad(job.sessionTarget, CRON_TARGET_PAD);
const agentLabel = pad(
truncate(job.agentId ?? "default", CRON_AGENT_PAD),
CRON_AGENT_PAD,
);
const agentLabel = pad(truncate(job.agentId ?? "default", CRON_AGENT_PAD), CRON_AGENT_PAD);
const coloredStatus = (() => {
if (statusRaw === "ok") return colorize(rich, theme.success, statusLabel);
if (statusRaw === "error")
return colorize(rich, theme.error, statusLabel);
if (statusRaw === "running")
return colorize(rich, theme.warn, statusLabel);
if (statusRaw === "skipped")
return colorize(rich, theme.muted, statusLabel);
if (statusRaw === "error") return colorize(rich, theme.error, statusLabel);
if (statusRaw === "running") return colorize(rich, theme.warn, statusLabel);
if (statusRaw === "skipped") return colorize(rich, theme.muted, statusLabel);
return colorize(rich, theme.muted, statusLabel);
})();