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
| 1 | import type { |
| 2 | ExecutionEnvironmentCapabilities, |
| 3 | ThreadId, |
| 4 | ThreadPullRequestKey, |
| 5 | } from "@t3tools/contracts"; |
| 6 | import type { EnvironmentThreadShell } from "./state/models.ts"; |
| 7 | import { normalizeThreadPullRequestKey } from "./threadPullRequests.ts"; |
| 8 | |
| 9 | /** "unsupported" until the environment's server config has loaded. */ |
| 10 | export function threadPullRequestLinkMode( |
| 11 | capabilities: ExecutionEnvironmentCapabilities | null | undefined, |
| 12 | ) { |
| 13 | return capabilities ? ("multiple" as const) : ("unsupported" as const); |
| 14 | } |
| 15 | |
| 16 | /** The server refuses new watches on settled, archived, and subagent threads. */ |
| 17 | export function canStartThreadPullRequestWatch( |
| 18 | thread: Pick<EnvironmentThreadShell, "archivedAt" | "settledAt" | "settledOverride" | "lineage">, |
| 19 | ): boolean { |
| 20 | return ( |
| 21 | thread.archivedAt === null && |
| 22 | thread.settledAt === null && |
| 23 | thread.settledOverride !== "settled" && |
| 24 | thread.lineage.relationshipToParent !== "subagent" |
| 25 | ); |
| 26 | } |
| 27 | |
| 28 | export function planThreadPullRequestMutation({ |
| 29 | capabilities, |
| 30 | threadId, |
| 31 | reference, |
| 32 | linked, |
| 33 | }: { |
| 34 | capabilities: ExecutionEnvironmentCapabilities | null | undefined; |
| 35 | threadId: ThreadId; |
| 36 | reference: ThreadPullRequestKey & { readonly url: string }; |
| 37 | linked: boolean; |
| 38 | }) { |
| 39 | const key = normalizeThreadPullRequestKey(reference); |
| 40 | switch (threadPullRequestLinkMode(capabilities)) { |
| 41 | case "multiple": |
| 42 | return linked |
| 43 | ? { |
| 44 | type: "thread.pull-request.link" as const, |
| 45 | input: { threadId, ...reference, ...key, source: "manual" as const }, |
| 46 | } |
| 47 | : { |
| 48 | type: "thread.pull-request.unlink" as const, |
| 49 | input: { |
| 50 | threadId, |
| 51 | ...key, |
| 52 | }, |
| 53 | }; |
| 54 | case "unsupported": |
| 55 | return null; |
| 56 | } |
| 57 | } |