cynarAI 460eede226
feat: autopilot that keeps working on an order until it is done (#144)
An autopilot per thread continues the user's order run after run, with
no time limit. Each run reports a checkpoint; after three runs without
progress or three failed runs it pauses with Continue and Stop. Start,
pause, stop and finish show as quiet lines in the conversation.
Approvals during an autopilot run are parked as suggestions, and the
temporary approval rules end with the autopilot.


Claude-Session: https://claude.ai/code/session_01UmSCnoCgXqBp2fU3vwz4o1

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-05 03:56:45 +02:00

39 lines
1.9 KiB
SQL

-- A standing order the bot keeps working on run after run, and the approvals granted only for it.
CREATE TABLE "autopilots" (
"id" TEXT NOT NULL,
"spaceId" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"botId" TEXT NOT NULL,
"threadId" TEXT NOT NULL,
"goal" TEXT NOT NULL,
"focus" TEXT,
"until" TIMESTAMP(3),
"status" TEXT NOT NULL,
"pauseReason" TEXT,
"lastCheckpoint" TEXT,
"nextStep" TEXT,
"result" TEXT,
"stepCount" INTEGER NOT NULL DEFAULT 0,
"idleCount" INTEGER NOT NULL DEFAULT 0,
"failCount" INTEGER NOT NULL DEFAULT 0,
"continuations" INTEGER NOT NULL DEFAULT 0,
"startMessageId" TEXT,
"startedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"endedAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "autopilots_pkey" PRIMARY KEY ("id")
);
CREATE INDEX "autopilots_spaceId_userId_status_idx" ON "autopilots"("spaceId", "userId", "status");
CREATE INDEX "autopilots_threadId_status_idx" ON "autopilots"("threadId", "status");
ALTER TABLE "autopilots" ADD CONSTRAINT "autopilots_spaceId_fkey" FOREIGN KEY ("spaceId") REFERENCES "spaces"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "autopilots" ADD CONSTRAINT "autopilots_userId_fkey" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "autopilots" ADD CONSTRAINT "autopilots_botId_fkey" FOREIGN KEY ("botId") REFERENCES "bots"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "autopilots" ADD CONSTRAINT "autopilots_threadId_fkey" FOREIGN KEY ("threadId") REFERENCES "threads"("id") ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE "action_approval_rules" ADD COLUMN "autopilotId" TEXT;
ALTER TABLE "action_approval_rules" ADD CONSTRAINT "action_approval_rules_autopilotId_fkey" FOREIGN KEY ("autopilotId") REFERENCES "autopilots"("id") ON DELETE CASCADE ON UPDATE CASCADE;