@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 39 lines 1.28 KB
Raw
1 import type { OrchestrationV2Run, OrchestrationV2ThreadProjection } from "@t3tools/contracts";
2
3 import { cancelledBeforeStart } from "./RestartBackgroundNote.ts";
4
5 /** A fresh-session schedule run starts a side conversation; the thread's own one continues past it. */
6 export function isScheduledFreshRun(
7 run: Pick<OrchestrationV2Run, "freshContext" | "userMessageId">,
8 turnItems: OrchestrationV2ThreadProjection["turnItems"],
9 ): boolean {
10 // A compacted thread's command read loads these prompts for every fresh-context run.
11 return (
12 run.freshContext === true &&
13 turnItems.some(
14 (item) =>
15 item.type === "user_message" &&
16 item.messageId === run.userMessageId &&
17 item.scheduledTaskId !== undefined,
18 )
19 );
20 }
21
22 /** Ordinal of the latest started fresh-context run. Runs before it never reach a provider again. */
23 export function contextBoundaryOrdinal(
24 projection: Pick<OrchestrationV2ThreadProjection, "runs" | "turnItems">,
25 ): number {
26 let boundary = 0;
27 for (const run of projection.runs) {
28 if (
29 run.freshContext === true &&
30 run.status !== "queued" &&
31 !cancelledBeforeStart(run) &&
32 run.ordinal > boundary &&
33 !isScheduledFreshRun(run, projection.turnItems)
34 ) {
35 boundary = run.ordinal;
36 }
37 }
38 return boundary;
39 }