Make routines act on their own and check every bot action
Scheduled runs are pre-approved: they carry out their brief instead of drafting for confirmation. A run that can't do its brief calls report_run_failed and is retried 5 and 10 minutes later; only then does the user get one "failed after N tries" message, and the routine keeps why in last_error. Every reply and task now gets ActionCheckNote: look for an existing record before creating one, and verify an action took effect before saying it's done. Memory and instructions saves are read back, and create_bot, create_schedule, start_task and delegate_task refuse duplicates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import type { BUN_SQLITE_COBBLE_CRON_JOBS } from "@/db/types/db";
|
||||
|
||||
type Params<T extends BUN_SQLITE_COBBLE_CRON_JOBS> = {
|
||||
/**
|
||||
* The bot's schedules for this user.
|
||||
*/
|
||||
cron_jobs: T[];
|
||||
title: string;
|
||||
instructions: string;
|
||||
schedule: string;
|
||||
/**
|
||||
* Where the new one would run: only schedules there can be its twin.
|
||||
*/
|
||||
workspace_id?: number | string | null;
|
||||
};
|
||||
|
||||
const normalize = (text?: string | null) => (text || "").trim().replace(/\s+/g, " ").toLowerCase();
|
||||
|
||||
/**
|
||||
* The schedule a new one would duplicate, if any: same place and either
|
||||
* the same title, or the same timing and brief.
|
||||
*/
|
||||
export default function findDuplicateCronJob<T extends BUN_SQLITE_COBBLE_CRON_JOBS>({
|
||||
cron_jobs,
|
||||
title,
|
||||
instructions,
|
||||
schedule,
|
||||
workspace_id,
|
||||
}: Params<T>) {
|
||||
return (
|
||||
cron_jobs.find(
|
||||
(cron_job) =>
|
||||
Number(cron_job.workspace_id || 0) == Number(workspace_id || 0) &&
|
||||
(normalize(cron_job.title) == normalize(title) ||
|
||||
(normalize(cron_job.schedule) == normalize(schedule) &&
|
||||
normalize(cron_job.instructions) == normalize(instructions))),
|
||||
) || null
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user