Open source CapCut alternative.
TypeScript
feat(site): the tray is placed again as the turn advances
David Lef35d67e52b45
diff --git a/docs/guides/cut/ai-assistant.md b/docs/guides/cut/ai-assistant.mdindex 8c38c8ab..c9d4b94c 100644--- a/docs/guides/cut/ai-assistant.md+++ b/docs/guides/cut/ai-assistant.md@@ -47,7 +47,7 @@ A job can do everything a tab can, because the same tool code runs over swappedTwo mechanisms keep a turn honest. A mutation ledger, computed in code from the tool results, rides every model call as an ephemeral context note: what ran, what failed, and what debris the edits left (a parked transition bar, an item stranded past the video's end) — the model must fix or plainly report each entry before its reply lands, and the note is never stored or rendered. And the round budget extends itself: a build that outgrows its 24 rounds gets fresh budget automatically (up to three extensions, so 96 rounds in all), so the user never types "keep going". At the ceiling tool calls stop and the model gets one round to say where it landed; a turn still reaching for tools ends with a line offering "keep going".-The composer stays open while a turn runs. A message sent mid-turn waits in a small tray on the composer's top edge and goes out when the running turn settles — one turn at a time, each with a fresh editor snapshot, so a queued ask always sees the edits made before it. A typed triage places each mid-turn message first: a refinement of the running work is steered into the live turn, an independent ask that cannot collide starts a parallel thread, and everything else — including whatever the call cannot place — waits in the tray, where the running agent can also park a message itself when it needs the finished result first. The tray is the review surface: waiting rows can be reordered, rewritten, or removed, and the queue pauses and resumes from its header. While a row is being rewritten the list holds still — the row under edit waits, the others keep draining and cross out in place as they finish. Stopping a turn or hitting an error pauses the queue automatically, so the remaining asks hold for review. Waiting rows are saved with the thread on the machine: a reload or a trip to another project brings them back paused, ready to resume.+The composer stays open while a turn runs. A message sent mid-turn waits in a small tray on the composer's top edge and goes out when the running turn settles — one turn at a time, each with a fresh editor snapshot, so a queued ask always sees the edits made before it. A typed triage places each mid-turn message first: a refinement of the running work is steered into the live turn, an independent ask that cannot collide starts a parallel thread, and everything else — including whatever the call cannot place — waits in the tray, where the running agent can also park a message itself when it needs the finished result first. A row is placed against the tools the turn had run at the time, so the tray is placed again as the turn advances: the work a row was waiting on lands, and it folds in rather than waiting out the turn. The tray is the review surface: waiting rows can be reordered, rewritten, or removed, and the queue pauses and resumes from its header. While a row is being rewritten the list holds still — the row under edit waits, the others keep draining and cross out in place as they finish. Stopping a turn or hitting an error pauses the queue automatically, so the remaining asks hold for review. Waiting rows are saved with the thread on the machine: a reload or a trip to another project brings them back paused, ready to resume.Which path runs is chosen by the model id alone. The picker lives in the page so a site deploy updates it for everyone; the engine only reports which CLIs are installed and signed in (probed and cached for a minute), and the page overlays Gemini availability from its own sign-in probe.diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsxindex e5f544c5..ac93b4d1 100644--- a/site/src/cut/components/AiPanel.tsx+++ b/site/src/cut/components/AiPanel.tsx@@ -2,7 +2,7 @@import type { ChatStatus } from "./ChatStatusBadge";-import { chatRuntime } from "@/cut/lib/chatRuntime";+import { chatRuntime, cutJudge } from "@/cut/lib/chatRuntime";import { ChatRequests } from "@/cut/lib/chatRequests";import { Fragment, memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, type ReactNode } from "react";import { useChat } from "@ai-sdk/react";@@ -95,7 +95,7 @@ import {} from "@/cut/lib/generate";import { useCreditsRecheck, useOutOfCredits } from "@/cut/lib/hosted";import { cutChatLive, dropPiSession, foldIntoCutChat, hydratePiSession, judgeEngineSkill, readPiSession, streamCutChat, triageQueuedMessages } from "@/cut/lib/pi/cutAgent";-import { toolProgress } from "@/cut/lib/queueTriage";+import { dueForRetriage, toolProgress } from "@/cut/lib/queueTriage";import { registerQueueSink } from "@/cut/lib/chatQueue";import { productionDeps } from "@/cut/lib/pi/prodDeps";import { withChatProject } from "@/cut/lib/projectChatTools";@@ -1475,6 +1475,12 @@ function ChatSession({const runningAskRef = useRef("");/** The running Gemini turn's abort signal, for the work a fold does. */const turnSignalRef = useRef<AbortSignal | undefined>(undefined);+ /** How many triage calls are out, and when the last one went, so the+ * re-placement cadence counts from every caller's call. A count rather+ * than a flag: the send path and the cadence both call, and the first to+ * finish must not clear the other's. */+ const triagingRef = useRef(0);+ const triagedAtRef = useRef(0);// Where a message sent mid-turn goes. One light-model call places the rows// against the running ask: a fold is steered into the running turn and// joins the transcript as its own message, a spawn starts a parallel@@ -1485,6 +1491,15 @@ function ChatSession({const triage = async (rows: QueuedMessage[]) => {const ask = runningAskRef.current;if (!ask) return;+ triagingRef.current += 1;+ triagedAtRef.current = Date.now();+ try {+ await placeRows(rows, ask);+ } finally {+ triagingRef.current -= 1;+ }+ };+ const placeRows = async (rows: QueuedMessage[], ask: string) => {const last = messagesRef.current.at(-1);const progress =last?.role === "assistant"@@ -1546,6 +1561,38 @@ function ChatSession({useEffect(() => {triageRef.current = triage;});+ // A row is placed against the tools the turn had run when it was sent, and+ // the turn keeps working — so that reading goes stale. A row that read+ // "unclear, hold it" is a plain fold once the work it was waiting on lands.+ // The tray is therefore placed again on a cadence for as long as the turn+ // runs, which is the difference between a refinement joining the live turn+ // and landing a minute later. A turn can sit inside one long tool call+ // with nothing about it changing, so the timer re-arms itself rather than+ // waiting on a render. The judgment is a few hundred tokens and a quarter+ // second; the cadence and the in-flight count keep it to one call at a time.+ useEffect(() => {+ if (!busy || queuePaused || readOnly) return;+ const { queueRetriageMs } = cutJudge();+ if (queueRetriageMs <= 0) return;+ const rows = () => queueRef.current.filter((m) => m.status === "queued" && m.id !== queueEditingRef.current);+ let timer: ReturnType<typeof setTimeout>;+ const tick = () => {+ const waiting = rows();+ if (+ dueForRetriage({+ waiting: waiting.length,+ cadenceMs: queueRetriageMs,+ inFlight: triagingRef.current > 0,+ lastAt: triagedAtRef.current,+ now: Date.now(),+ })+ )+ void triageRef.current(waiting);+ timer = setTimeout(tick, queueRetriageMs);+ };+ timer = setTimeout(tick, Math.max(0, triagedAtRef.current + queueRetriageMs - Date.now()));+ return () => clearTimeout(timer);+ }, [busy, queuePaused, readOnly]);// The running agent can park a message here itself (queue_message): the// row goes out as its own turn after the running one settles.useEffect(diff --git a/site/src/cut/lib/queueTriage.test.ts b/site/src/cut/lib/queueTriage.test.tsindex 8acddf46..65a17feb 100644--- a/site/src/cut/lib/queueTriage.test.ts+++ b/site/src/cut/lib/queueTriage.test.ts@@ -1,5 +1,5 @@import { describe, expect, test } from "bun:test";-import { placeQueuedRows, queueTriageQuestions, queueTriageState, toolProgress, type QueueTriageAnswers } from "./queueTriage";+import { dueForRetriage, placeQueuedRows, queueTriageQuestions, queueTriageState, toolProgress, type QueueTriageAnswers } from "./queueTriage";const rows = [{ id: "m1", text: "also make the title blue" },@@ -90,3 +90,27 @@ describe("toolProgress", () => {).toEqual(["detect_silence", "split_clip (running)", "add_text"]);});});++describe("dueForRetriage", () => {+ const base = { waiting: 1, cadenceMs: 4000, inFlight: false, lastAt: 0, now: 4000 };++ test("places the tray again once the cadence has passed", () => {+ expect(dueForRetriage(base)).toBe(true);+ });++ test("holds until the cadence has passed", () => {+ expect(dueForRetriage({ ...base, now: 3999 })).toBe(false);+ });++ test("never overlaps a call already out", () => {+ expect(dueForRetriage({ ...base, inFlight: true })).toBe(false);+ });++ test("does nothing with an empty tray", () => {+ expect(dueForRetriage({ ...base, waiting: 0 })).toBe(false);+ });++ test("a zero cadence places each row once, at send", () => {+ expect(dueForRetriage({ ...base, cadenceMs: 0, now: 1e9 })).toBe(false);+ });+});diff --git a/site/src/cut/lib/queueTriage.ts b/site/src/cut/lib/queueTriage.tsindex ded815fe..af4265b7 100644--- a/site/src/cut/lib/queueTriage.ts+++ b/site/src/cut/lib/queueTriage.ts@@ -49,6 +49,29 @@ const PLACE_CRITERIA = {"It waits for the running ask to finish and for a fresh view of the project: it needs the finished result (export, render, share, publish, a thumbnail or summary of the final cut), or it is sequenced after the running work (\"then…\", \"after that…\", \"once it's done…\"). Anything unclear.",} as const;+/** Whether a running turn should place its waiting rows again.+ *+ * A row is placed when it is sent, against the tools the turn had run by+ * then. The turn keeps working, so that reading goes stale: a row that read+ * "unclear, hold it" becomes a plain fold once the work it was waiting on+ * lands. Re-placing costs one judgment, so it waits for the cadence and never+ * overlaps a call already out.+ */+export function dueForRetriage(opts: {+ /** Rows still waiting in the tray. */+ waiting: number;+ /** The setting's cadence; 0 places rows once, at send. */+ cadenceMs: number;+ /** A triage call is already out. */+ inFlight: boolean;+ /** When the last triage went out, on the same clock as `now`. */+ lastAt: number;+ now: number;+}): boolean {+ if (opts.waiting === 0 || opts.cadenceMs <= 0 || opts.inFlight) return false;+ return opts.now - opts.lastAt >= opts.cadenceMs;+}+/** One placement and one collision question per row. */export function queueTriageQuestions(rows: TriageRow[]) {const out: Record<string, ReturnType<typeof choice<typeof PLACE_CRITERIA>> | ReturnType<typeof noul>> = {};diff --git a/site/src/lib/config/registry.ts b/site/src/lib/config/registry.tsindex 538f77e9..0cc619fc 100644--- a/site/src/lib/config/registry.ts+++ b/site/src/lib/config/registry.ts@@ -120,6 +120,9 @@ export const SETTINGS = defineSettings({fillerCut: z.number().min(0).max(1),// The confidence below which a described voice falls back to the default.voicePick: z.number().min(0).max(1),+ // How often a running turn re-places the messages waiting in the tray+ // against the work it has done since; 0 places them once, at send.+ queueRetriageMs: z.number().int().min(0).max(60000),// Run a turn the judgment settles to one known action with no model// round at all; off sends every turn through the chat loop.instantAction: z.boolean(),@@ -155,6 +158,7 @@ export const SETTINGS = defineSettings({stockFit: 0.5,fillerCut: 0.5,voicePick: 0.4,+ queueRetriageMs: 4000,instantAction: true,instantFloor: 0.5,instantTarget: 0.5,@@ -171,7 +175,7 @@ export const SETTINGS = defineSettings({public: true,title: "Chat judgments",description:- "Thresholds for the typed judgments that route a chat turn (skill, tool areas), run a one-action turn with no model round, pick the items a sweep touches, rank stock, find filler words, and resolve described voices.",+ "Thresholds for the typed judgments that route a chat turn (skill, tool areas), run a one-action turn with no model round, re-place the messages waiting in the tray, pick the items a sweep touches, rank stock, find filler words, and resolve described voices.",},experimentResults: {schema: z