feat: link pull requests to threads (#8160)
This commit is contained in:
1 parent
63eb0429f4
commit
3c75eb1132
39 files changed
+1039
-63
No files matched your search
@@ -12,7 +12,6 @@ import {
|
||||
type EnvironmentThreadSearchMatch,
|
||||
} from "@t3tools/client-runtime/state/thread-search";
|
||||
import { sortPinnedThreadsByOrderKey } from "@t3tools/client-runtime/state/thread-sort";
|
||||
import type { ChangeRequestSettleSource } from "@t3tools/client-runtime/state/thread-settled";
|
||||
import type {
|
||||
EnvironmentId,
|
||||
SidebarProjectGroupingMode,
|
||||
@@ -54,6 +53,7 @@ import {
|
||||
buildThreadListV2ListItems,
|
||||
THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
|
||||
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
|
||||
type ThreadListV2ChangeRequestState,
|
||||
type ThreadListV2ListItem,
|
||||
} from "../threads/threadListV2";
|
||||
import { useThreadListV2ShelfPreferences } from "../threads/use-thread-list-v2-shelf-preferences";
|
||||
@@ -491,15 +491,16 @@ export function HomeScreen(props: HomeScreenProps) {
|
||||
// PR states stream in per-row. The next partition applies the configured
|
||||
// merge rule and the always-on close rule, matching web.
|
||||
const [changeRequestByKey, setChangeRequestByKey] = useState<
|
||||
ReadonlyMap<string, ChangeRequestSettleSource>
|
||||
ReadonlyMap<string, ThreadListV2ChangeRequestState>
|
||||
>(() => new Map());
|
||||
const handleChangeRequestState = useCallback(
|
||||
(threadKey: string, changeRequest: ChangeRequestSettleSource | null) => {
|
||||
(threadKey: string, changeRequest: ThreadListV2ChangeRequestState | null) => {
|
||||
setChangeRequestByKey((current) => {
|
||||
const existing = current.get(threadKey) ?? null;
|
||||
if (
|
||||
(existing?.state ?? null) === (changeRequest?.state ?? null) &&
|
||||
(existing?.updatedAt ?? null) === (changeRequest?.updatedAt ?? null)
|
||||
(existing?.updatedAt ?? null) === (changeRequest?.updatedAt ?? null) &&
|
||||
(existing?.linkedPullRequestKey ?? null) === (changeRequest?.linkedPullRequestKey ?? null)
|
||||
) {
|
||||
return current;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import { useAtomValue } from "@effect/atom-react";
|
||||
import { AsyncResult } from "effect/unstable/reactivity";
|
||||
import type { EnvironmentId } from "@t3tools/contracts";
|
||||
import { sortPinnedThreadsByOrderKey } from "@t3tools/client-runtime/state/thread-sort";
|
||||
import type { ChangeRequestSettleSource } from "@t3tools/client-runtime/state/thread-settled";
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { LayoutChangeEvent } from "react-native";
|
||||
import { Platform, Pressable, StyleSheet, TextInput, View } from "react-native";
|
||||
@@ -84,6 +83,7 @@ import {
|
||||
buildThreadListV2ListItems,
|
||||
THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
|
||||
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
|
||||
type ThreadListV2ChangeRequestState,
|
||||
type ThreadListV2ListItem,
|
||||
} from "./threadListV2";
|
||||
|
||||
@@ -377,15 +377,16 @@ function ThreadNavigationSidebarPane(
|
||||
// PR states stream in per-row. The next partition applies the configured
|
||||
// merge rule and the always-on close rule.
|
||||
const [changeRequestByKey, setChangeRequestByKey] = useState<
|
||||
ReadonlyMap<string, ChangeRequestSettleSource>
|
||||
ReadonlyMap<string, ThreadListV2ChangeRequestState>
|
||||
>(() => new Map());
|
||||
const handleChangeRequestState = useCallback(
|
||||
(threadKey: string, changeRequest: ChangeRequestSettleSource | null) => {
|
||||
(threadKey: string, changeRequest: ThreadListV2ChangeRequestState | null) => {
|
||||
setChangeRequestByKey((current) => {
|
||||
const existing = current.get(threadKey) ?? null;
|
||||
if (
|
||||
(existing?.state ?? null) === (changeRequest?.state ?? null) &&
|
||||
(existing?.updatedAt ?? null) === (changeRequest?.updatedAt ?? null)
|
||||
(existing?.updatedAt ?? null) === (changeRequest?.updatedAt ?? null) &&
|
||||
(existing?.linkedPullRequestKey ?? null) === (changeRequest?.linkedPullRequestKey ?? null)
|
||||
) {
|
||||
return current;
|
||||
}
|
||||
|
||||
@@ -3,11 +3,7 @@ import type {
|
||||
EnvironmentThreadShell,
|
||||
} from "@t3tools/client-runtime/state/shell";
|
||||
import type { EnvironmentThreadSearchMatch } from "@t3tools/client-runtime/state/thread-search";
|
||||
import {
|
||||
canSnooze,
|
||||
resolveSnoozePresets,
|
||||
type ChangeRequestSettleSource,
|
||||
} from "@t3tools/client-runtime/state/thread-settled";
|
||||
import { canSnooze, resolveSnoozePresets } from "@t3tools/client-runtime/state/thread-settled";
|
||||
import type { MenuAction } from "@react-native-menu/menu";
|
||||
import { memo, useCallback, useEffect, useMemo, useState, type ComponentProps } from "react";
|
||||
import { Alert, Platform, Pressable, useWindowDimensions, View } from "react-native";
|
||||
@@ -27,10 +23,12 @@ import { ThreadSwipeable } from "../home/thread-swipe-actions";
|
||||
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
|
||||
import { buildThreadTitleRegenerationMenuItems } from "./thread-title-regeneration-menu";
|
||||
import {
|
||||
resolveThreadListV2ChangeRequestState,
|
||||
resolveThreadListV2SnoozeMenuSelection,
|
||||
resolveThreadListV2SnoozeGateExpiryMs,
|
||||
resolveThreadListV2Status,
|
||||
resolveThreadListV2SwipeActions,
|
||||
type ThreadListV2ChangeRequestState,
|
||||
type ThreadListV2Status,
|
||||
} from "./threadListV2";
|
||||
import { ThreadSearchMatchExcerpt } from "./thread-search-match";
|
||||
@@ -377,7 +375,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
merge and close rules. Mirrors web's onChangeRequestState. */
|
||||
readonly onChangeRequestState?: (
|
||||
threadKey: string,
|
||||
changeRequest: ChangeRequestSettleSource | null,
|
||||
changeRequest: ThreadListV2ChangeRequestState | null,
|
||||
) => void;
|
||||
readonly projectCwd?: string | null;
|
||||
readonly searchMatch?: EnvironmentThreadSearchMatch;
|
||||
@@ -411,11 +409,14 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
|
||||
const prUpdatedAt = pr?.updatedAt ?? null;
|
||||
const threadKey = `${thread.environmentId}:${thread.id}`;
|
||||
useEffect(() => {
|
||||
onChangeRequestState?.(
|
||||
threadKey,
|
||||
prState === null ? null : { state: prState, updatedAt: prUpdatedAt },
|
||||
);
|
||||
}, [onChangeRequestState, prState, prUpdatedAt, threadKey]);
|
||||
const changeRequest = resolveThreadListV2ChangeRequestState({
|
||||
linkedPullRequest: thread.linkedPullRequest,
|
||||
state: prState,
|
||||
updatedAt: prUpdatedAt,
|
||||
});
|
||||
if (changeRequest === undefined) return;
|
||||
onChangeRequestState?.(threadKey, changeRequest);
|
||||
}, [onChangeRequestState, prState, prUpdatedAt, thread.linkedPullRequest, threadKey]);
|
||||
|
||||
const screenColor = useThemeColor("--color-screen");
|
||||
const drawerColor = useThemeColor("--color-drawer");
|
||||
|
||||
@@ -16,6 +16,7 @@ import type { PendingNewTask } from "../../state/use-pending-new-tasks";
|
||||
import {
|
||||
buildThreadListV2Items,
|
||||
buildThreadListV2ListItems,
|
||||
resolveThreadListV2ChangeRequestState,
|
||||
resolveThreadListV2Enabled,
|
||||
resolveThreadListV2SnoozeMenuSelection,
|
||||
resolveThreadListV2SnoozeGateExpiryMs,
|
||||
@@ -53,6 +54,48 @@ function makeThread(
|
||||
}
|
||||
|
||||
const NOW = "2026-06-02T00:00:00.000Z";
|
||||
const linkedPullRequest = {
|
||||
projectId: ProjectId.make("project-1"),
|
||||
repository: "pingdotgg/t3code",
|
||||
number: 42,
|
||||
url: "https://github.com/pingdotgg/t3code/pull/42",
|
||||
};
|
||||
|
||||
describe("resolveThreadListV2ChangeRequestState", () => {
|
||||
it("preserves the previous state while a linked pull request reloads", () => {
|
||||
expect(
|
||||
resolveThreadListV2ChangeRequestState({
|
||||
linkedPullRequest,
|
||||
state: null,
|
||||
updatedAt: null,
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("clears the previous state after a pull request is unlinked", () => {
|
||||
expect(
|
||||
resolveThreadListV2ChangeRequestState({
|
||||
linkedPullRequest: null,
|
||||
state: null,
|
||||
updatedAt: null,
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("reports a loaded linked pull request", () => {
|
||||
expect(
|
||||
resolveThreadListV2ChangeRequestState({
|
||||
linkedPullRequest,
|
||||
state: "merged",
|
||||
updatedAt: "2026-06-02T00:00:00.000Z",
|
||||
}),
|
||||
).toEqual({
|
||||
state: "merged",
|
||||
updatedAt: "2026-06-02T00:00:00.000Z",
|
||||
linkedPullRequestKey: '["project-1","pingdotgg/t3code",42]',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveThreadListV2SnoozeMenuSelection", () => {
|
||||
it("accepts a displayed evening preset while its wake time is still future", () => {
|
||||
@@ -263,6 +306,58 @@ describe("sortThreadsForListV2", () => {
|
||||
});
|
||||
|
||||
describe("buildThreadListV2Items", () => {
|
||||
it("ignores the previous pull request state after a different pull request is linked", () => {
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("linked"),
|
||||
title: "Linked pull request",
|
||||
linkedPullRequest,
|
||||
});
|
||||
const layout = buildThreadListV2Items({
|
||||
threads: [thread],
|
||||
environmentId: null,
|
||||
searchQuery: "",
|
||||
changeRequestByKey: new Map([
|
||||
[
|
||||
`${environmentId}:${thread.id}`,
|
||||
{
|
||||
state: "merged" as const,
|
||||
linkedPullRequestKey: '["project-1","pingdotgg/t3code",41]',
|
||||
},
|
||||
],
|
||||
]),
|
||||
now: NOW,
|
||||
});
|
||||
|
||||
expect(layout.settledCount).toBe(0);
|
||||
expect(layout.items[0]?.variant).toBe("card");
|
||||
});
|
||||
|
||||
it("settles a thread only when the cached pull request identity matches", () => {
|
||||
const thread = makeThread({
|
||||
id: ThreadId.make("linked-merged"),
|
||||
title: "Linked merged pull request",
|
||||
linkedPullRequest,
|
||||
});
|
||||
const layout = buildThreadListV2Items({
|
||||
threads: [thread],
|
||||
environmentId: null,
|
||||
searchQuery: "",
|
||||
changeRequestByKey: new Map([
|
||||
[
|
||||
`${environmentId}:${thread.id}`,
|
||||
{
|
||||
state: "merged" as const,
|
||||
linkedPullRequestKey: '["project-1","pingdotgg/t3code",42]',
|
||||
},
|
||||
],
|
||||
]),
|
||||
now: NOW,
|
||||
});
|
||||
|
||||
expect(layout.settledCount).toBe(1);
|
||||
expect(layout.items[0]?.variant).toBe("slim");
|
||||
});
|
||||
|
||||
it("keeps a merged thread active when auto-settle on merge is off", () => {
|
||||
const merged = makeThread({ id: ThreadId.make("merged"), title: "Merged" });
|
||||
const layout = buildThreadListV2Items({
|
||||
|
||||
@@ -13,7 +13,7 @@ import type {
|
||||
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
|
||||
import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
|
||||
import { sortPinnedThreadsByOrderKey } from "@t3tools/client-runtime/state/thread-sort";
|
||||
import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
|
||||
import type { EnvironmentId, ProjectId, ThreadLinkedPullRequest } from "@t3tools/contracts";
|
||||
|
||||
import type { PendingNewTask } from "../../state/use-pending-new-tasks";
|
||||
|
||||
@@ -30,6 +30,35 @@ export { snoozeWakeLabel };
|
||||
export type ThreadListV2Status = "approval" | "input" | "working" | "failed" | "ready";
|
||||
export type ThreadListV2SwipeAction = "archive" | "settle" | "unsettle" | "snooze" | "unsnooze";
|
||||
|
||||
export interface ThreadListV2ChangeRequestState extends ChangeRequestSettleSource {
|
||||
readonly linkedPullRequestKey?: string | null;
|
||||
}
|
||||
|
||||
function linkedPullRequestKey(
|
||||
linkedPullRequest: ThreadLinkedPullRequest | null | undefined,
|
||||
): string | null {
|
||||
if (linkedPullRequest == null) return null;
|
||||
return JSON.stringify([
|
||||
linkedPullRequest.projectId,
|
||||
linkedPullRequest.repository.toLowerCase(),
|
||||
linkedPullRequest.number,
|
||||
]);
|
||||
}
|
||||
|
||||
/** Keep the previous linked PR state while its detail query reloads. */
|
||||
export function resolveThreadListV2ChangeRequestState(input: {
|
||||
readonly linkedPullRequest: ThreadLinkedPullRequest | null | undefined;
|
||||
readonly state: ChangeRequestSettleSource["state"] | null;
|
||||
readonly updatedAt: string | null;
|
||||
}): ThreadListV2ChangeRequestState | null | undefined {
|
||||
if (input.state === null) return input.linkedPullRequest == null ? null : undefined;
|
||||
return {
|
||||
state: input.state,
|
||||
updatedAt: input.updatedAt,
|
||||
linkedPullRequestKey: linkedPullRequestKey(input.linkedPullRequest),
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveThreadListV2SnoozeMenuSelection(input: {
|
||||
readonly event: string;
|
||||
readonly displayedPresets: ReadonlyArray<SnoozePreset>;
|
||||
@@ -322,7 +351,7 @@ export function buildThreadListV2Items(input: {
|
||||
readonly searchQuery: string;
|
||||
readonly matchedThreadKeys?: ReadonlySet<string>;
|
||||
/** Per-row PR reported up by visible rows ("env:threadId" keys). */
|
||||
readonly changeRequestByKey?: ReadonlyMap<string, ChangeRequestSettleSource>;
|
||||
readonly changeRequestByKey?: ReadonlyMap<string, ThreadListV2ChangeRequestState>;
|
||||
/** Environments whose server supports thread.settle/unsettle. Threads on
|
||||
other environments never classify as settled — the user could neither
|
||||
un-settle nor pin them. Absent = no gating (tests). */
|
||||
@@ -384,8 +413,14 @@ export function buildThreadListV2Items(input: {
|
||||
}
|
||||
const supportsSettlement = input.settlementEnvironmentIds?.has(thread.environmentId) ?? true;
|
||||
const supportsSnooze = input.snoozeEnvironmentIds?.has(thread.environmentId) ?? true;
|
||||
const changeRequest =
|
||||
const cachedChangeRequest =
|
||||
input.changeRequestByKey?.get(`${thread.environmentId}:${thread.id}`) ?? null;
|
||||
const changeRequest =
|
||||
cachedChangeRequest !== null &&
|
||||
(cachedChangeRequest.linkedPullRequestKey ?? null) ===
|
||||
linkedPullRequestKey(thread.linkedPullRequest)
|
||||
? cachedChangeRequest
|
||||
: null;
|
||||
// Snooze outranks settlement and pinning until the thread wakes.
|
||||
if (supportsSnooze && effectiveSnoozed(thread, { now: snoozeNow })) {
|
||||
snoozed.push(thread);
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
|
||||
import {
|
||||
createLinkedPullRequestDetailAtomFamily,
|
||||
pullRequestDetailToVcsStatus,
|
||||
} from "@t3tools/client-runtime/state/pull-requests";
|
||||
|
||||
import { connectionAtomRuntime } from "../connection/runtime";
|
||||
import { useEnvironmentQuery } from "./query";
|
||||
import { presentThreadPr, type ThreadPrPresentation } from "./thread-pr-presentation";
|
||||
import { vcsEnvironment } from "./vcs";
|
||||
|
||||
const linkedPullRequestDetailAtom = createLinkedPullRequestDetailAtomFamily(connectionAtomRuntime);
|
||||
|
||||
export {
|
||||
presentThreadPr,
|
||||
type ThreadPr,
|
||||
@@ -22,13 +29,36 @@ export function useThreadPr(
|
||||
): ThreadPrPresentation | null {
|
||||
const cwd = thread.worktreePath ?? projectCwd;
|
||||
const gitStatus = useEnvironmentQuery(
|
||||
thread.branch !== null && cwd !== null
|
||||
thread.linkedPullRequest == null && thread.branch !== null && cwd !== null
|
||||
? vcsEnvironment.status({
|
||||
environmentId: thread.environmentId,
|
||||
input: { cwd },
|
||||
})
|
||||
: null,
|
||||
);
|
||||
const linkedPullRequest = useEnvironmentQuery(
|
||||
thread.linkedPullRequest == null
|
||||
? null
|
||||
: linkedPullRequestDetailAtom({
|
||||
environmentId: thread.environmentId,
|
||||
input: {
|
||||
projectId: thread.linkedPullRequest.projectId,
|
||||
repository: thread.linkedPullRequest.repository,
|
||||
number: thread.linkedPullRequest.number,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
if (thread.linkedPullRequest != null) {
|
||||
const detail = linkedPullRequest.data;
|
||||
return detail === null
|
||||
? null
|
||||
: presentThreadPr(pullRequestDetailToVcsStatus(detail), {
|
||||
kind: detail.provider,
|
||||
name: detail.provider,
|
||||
baseUrl: "",
|
||||
});
|
||||
}
|
||||
|
||||
const status = gitStatus.data;
|
||||
if (status === null || thread.branch === null || status.refName !== thread.branch) {
|
||||
|
||||
@@ -93,6 +93,7 @@ it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
|
||||
expect(second.capabilities.attachmentUploads).toBe(true);
|
||||
expect(second.capabilities.pullRequests).toBe(true);
|
||||
expect(second.capabilities.threadTitleRegeneration).toBe(true);
|
||||
expect(second.capabilities.threadPullRequestLinking).toBe(true);
|
||||
expect(second.capabilities.agentActivityPublishing).toBe(false);
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -153,6 +153,7 @@ export const make = Effect.gen(function* () {
|
||||
threadPinning: true,
|
||||
threadPinReorder: true,
|
||||
threadTitleRegeneration: true,
|
||||
threadPullRequestLinking: true,
|
||||
...(serverSelfUpdate === null ? {} : { serverSelfUpdate }),
|
||||
...(serverSelfUpdate === "boot-service" ? { serverSelfUpdateProgress: true } : {}),
|
||||
},
|
||||
|
||||
@@ -634,6 +634,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
|
||||
interactionMode: event.payload.interactionMode,
|
||||
branch: event.payload.branch,
|
||||
worktreePath: event.payload.worktreePath,
|
||||
linkedPullRequest: null,
|
||||
latestTurnId: null,
|
||||
createdAt: event.payload.createdAt,
|
||||
updatedAt: event.payload.updatedAt,
|
||||
@@ -822,6 +823,9 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti
|
||||
...(event.payload.worktreePath !== undefined
|
||||
? { worktreePath: event.payload.worktreePath }
|
||||
: {}),
|
||||
...(event.payload.linkedPullRequest !== undefined
|
||||
? { linkedPullRequest: event.payload.linkedPullRequest }
|
||||
: {}),
|
||||
updatedAt: event.payload.updatedAt,
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -82,6 +82,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
interaction_mode,
|
||||
branch,
|
||||
worktree_path,
|
||||
linked_pull_request_json,
|
||||
latest_turn_id,
|
||||
latest_user_message_at,
|
||||
pending_approval_count,
|
||||
@@ -102,6 +103,7 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
'default',
|
||||
NULL,
|
||||
NULL,
|
||||
'{"projectId":"project-1","repository":"pingdotgg/t3code","number":42,"url":"https://github.com/pingdotgg/t3code/pull/42"}',
|
||||
'turn-1',
|
||||
'2026-02-24T00:00:04.000Z',
|
||||
1,
|
||||
@@ -304,6 +306,12 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
linkedPullRequest: {
|
||||
projectId: asProjectId("project-1"),
|
||||
repository: "pingdotgg/t3code",
|
||||
number: 42,
|
||||
url: "https://github.com/pingdotgg/t3code/pull/42",
|
||||
},
|
||||
latestTurn: {
|
||||
turnId: asTurnId("turn-1"),
|
||||
state: "completed",
|
||||
@@ -423,6 +431,12 @@ projectionSnapshotLayer("ProjectionSnapshotQuery", (it) => {
|
||||
runtimeMode: "full-access",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
linkedPullRequest: {
|
||||
projectId: asProjectId("project-1"),
|
||||
repository: "pingdotgg/t3code",
|
||||
number: 42,
|
||||
url: "https://github.com/pingdotgg/t3code/pull/42",
|
||||
},
|
||||
latestTurn: {
|
||||
turnId: asTurnId("turn-1"),
|
||||
state: "completed",
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
type OrchestrationThreadShell,
|
||||
ModelSelection,
|
||||
ProjectId,
|
||||
ThreadLinkedPullRequest,
|
||||
ThreadId,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Arr from "effect/Array";
|
||||
@@ -89,6 +90,7 @@ const ProjectionThreadProposedPlanDbRowSchema = ProjectionThreadProposedPlan;
|
||||
const ProjectionThreadDbRowSchema = ProjectionThread.mapFields(
|
||||
Struct.assign({
|
||||
modelSelection: Schema.fromJsonString(ModelSelection),
|
||||
linkedPullRequest: Schema.NullOr(Schema.fromJsonString(ThreadLinkedPullRequest)),
|
||||
}),
|
||||
);
|
||||
const ProjectionThreadActivityDbRowSchema = ProjectionThreadActivity.mapFields(
|
||||
@@ -422,6 +424,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
interaction_mode AS "interactionMode",
|
||||
branch,
|
||||
worktree_path AS "worktreePath",
|
||||
linked_pull_request_json AS "linkedPullRequest",
|
||||
latest_turn_id AS "latestTurnId",
|
||||
created_at AS "createdAt",
|
||||
updated_at AS "updatedAt",
|
||||
@@ -458,6 +461,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
interaction_mode AS "interactionMode",
|
||||
branch,
|
||||
worktree_path AS "worktreePath",
|
||||
linked_pull_request_json AS "linkedPullRequest",
|
||||
latest_turn_id AS "latestTurnId",
|
||||
created_at AS "createdAt",
|
||||
updated_at AS "updatedAt",
|
||||
@@ -496,6 +500,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
interaction_mode AS "interactionMode",
|
||||
branch,
|
||||
worktree_path AS "worktreePath",
|
||||
linked_pull_request_json AS "linkedPullRequest",
|
||||
latest_turn_id AS "latestTurnId",
|
||||
created_at AS "createdAt",
|
||||
updated_at AS "updatedAt",
|
||||
@@ -938,6 +943,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
interaction_mode AS "interactionMode",
|
||||
branch,
|
||||
worktree_path AS "worktreePath",
|
||||
linked_pull_request_json AS "linkedPullRequest",
|
||||
latest_turn_id AS "latestTurnId",
|
||||
created_at AS "createdAt",
|
||||
updated_at AS "updatedAt",
|
||||
@@ -1694,6 +1700,9 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
interactionMode: row.interactionMode,
|
||||
branch: row.branch,
|
||||
worktreePath: row.worktreePath,
|
||||
...(row.linkedPullRequest === null
|
||||
? {}
|
||||
: { linkedPullRequest: row.linkedPullRequest }),
|
||||
latestTurn: latestTurnByThread.get(row.threadId) ?? null,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
@@ -1901,6 +1910,9 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
interactionMode: row.interactionMode,
|
||||
branch: row.branch,
|
||||
worktreePath: row.worktreePath,
|
||||
...(row.linkedPullRequest === null
|
||||
? {}
|
||||
: { linkedPullRequest: row.linkedPullRequest }),
|
||||
latestTurn: latestTurnByThread.get(row.threadId) ?? null,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
@@ -2037,6 +2049,9 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
interactionMode: row.interactionMode,
|
||||
branch: row.branch,
|
||||
worktreePath: row.worktreePath,
|
||||
...(row.linkedPullRequest === null
|
||||
? {}
|
||||
: { linkedPullRequest: row.linkedPullRequest }),
|
||||
latestTurn: latestTurnByThread.get(row.threadId) ?? null,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
@@ -2182,6 +2197,9 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
interactionMode: row.interactionMode,
|
||||
branch: row.branch,
|
||||
worktreePath: row.worktreePath,
|
||||
...(row.linkedPullRequest === null
|
||||
? {}
|
||||
: { linkedPullRequest: row.linkedPullRequest }),
|
||||
latestTurn: latestTurnByThread.get(row.threadId) ?? null,
|
||||
createdAt: row.createdAt,
|
||||
updatedAt: row.updatedAt,
|
||||
@@ -2461,6 +2479,9 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
interactionMode: threadRow.value.interactionMode,
|
||||
branch: threadRow.value.branch,
|
||||
worktreePath: threadRow.value.worktreePath,
|
||||
...(threadRow.value.linkedPullRequest === null
|
||||
? {}
|
||||
: { linkedPullRequest: threadRow.value.linkedPullRequest }),
|
||||
latestTurn: Option.isSome(latestTurnRow) ? mapLatestTurn(latestTurnRow.value) : null,
|
||||
createdAt: threadRow.value.createdAt,
|
||||
updatedAt: threadRow.value.updatedAt,
|
||||
@@ -2602,6 +2623,9 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
|
||||
interactionMode: threadRow.value.interactionMode,
|
||||
branch: threadRow.value.branch,
|
||||
worktreePath: threadRow.value.worktreePath,
|
||||
...(threadRow.value.linkedPullRequest === null
|
||||
? {}
|
||||
: { linkedPullRequest: threadRow.value.linkedPullRequest }),
|
||||
latestTurn: Option.isSome(latestTurnRow) ? mapLatestTurn(latestTurnRow.value) : null,
|
||||
createdAt: threadRow.value.createdAt,
|
||||
updatedAt: threadRow.value.updatedAt,
|
||||
|
||||
@@ -847,6 +847,9 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
|
||||
: {}),
|
||||
...(branch !== undefined ? { branch } : {}),
|
||||
...(command.worktreePath !== undefined ? { worktreePath: command.worktreePath } : {}),
|
||||
...(command.linkedPullRequest !== undefined
|
||||
? { linkedPullRequest: command.linkedPullRequest }
|
||||
: {}),
|
||||
updatedAt: occurredAt,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -456,6 +456,9 @@ export function projectEvent(
|
||||
: {}),
|
||||
...(payload.branch !== undefined ? { branch: payload.branch } : {}),
|
||||
...(payload.worktreePath !== undefined ? { worktreePath: payload.worktreePath } : {}),
|
||||
...(payload.linkedPullRequest !== undefined
|
||||
? { linkedPullRequest: payload.linkedPullRequest }
|
||||
: {}),
|
||||
updatedAt: payload.updatedAt,
|
||||
}),
|
||||
})),
|
||||
|
||||
@@ -201,4 +201,55 @@ projectionRepositoriesLayer("Projection repositories", (it) => {
|
||||
assert.strictEqual(updated?.pinnedAt, null);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("round-trips a linked pull request through the thread row", () =>
|
||||
Effect.gen(function* () {
|
||||
const threads = yield* ProjectionThreadRepository;
|
||||
const linkedPullRequest = {
|
||||
projectId: ProjectId.make("project-linked-pr"),
|
||||
repository: "pingdotgg/t3code",
|
||||
number: 42,
|
||||
url: "https://github.com/pingdotgg/t3code/pull/42",
|
||||
};
|
||||
|
||||
yield* threads.upsert({
|
||||
threadId: ThreadId.make("thread-linked-pr"),
|
||||
projectId: ProjectId.make("project-linked-pr"),
|
||||
title: "Linked pull request",
|
||||
modelSelection: {
|
||||
instanceId: ProviderInstanceId.make("codex"),
|
||||
model: "gpt-5.4",
|
||||
},
|
||||
runtimeMode: "full-access",
|
||||
interactionMode: "default",
|
||||
branch: null,
|
||||
worktreePath: null,
|
||||
linkedPullRequest,
|
||||
latestTurnId: null,
|
||||
createdAt: "2026-03-24T00:00:00.000Z",
|
||||
updatedAt: "2026-03-24T00:00:00.000Z",
|
||||
archivedAt: null,
|
||||
settledOverride: null,
|
||||
settledAt: null,
|
||||
snoozedUntil: null,
|
||||
snoozedAt: null,
|
||||
pinnedAt: null,
|
||||
latestUserMessageAt: null,
|
||||
pendingApprovalCount: 0,
|
||||
pendingUserInputCount: 0,
|
||||
hasActionableProposedPlan: 0,
|
||||
deletedAt: null,
|
||||
});
|
||||
|
||||
const persisted = yield* threads.getById({ threadId: ThreadId.make("thread-linked-pr") });
|
||||
assert.deepStrictEqual(Option.getOrNull(persisted)?.linkedPullRequest, linkedPullRequest);
|
||||
|
||||
const row = Option.getOrNull(persisted);
|
||||
if (row === null) return yield* Effect.die("Expected linked thread row to exist.");
|
||||
yield* threads.upsert({ ...row, linkedPullRequest: null });
|
||||
|
||||
const cleared = yield* threads.getById({ threadId: ThreadId.make("thread-linked-pr") });
|
||||
assert.strictEqual(Option.getOrNull(cleared)?.linkedPullRequest, null);
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -14,11 +14,12 @@ import {
|
||||
ProjectionThreadRepository,
|
||||
type ProjectionThreadRepositoryShape,
|
||||
} from "../Services/ProjectionThreads.ts";
|
||||
import { ModelSelection } from "@t3tools/contracts";
|
||||
import { ModelSelection, ThreadLinkedPullRequest } from "@t3tools/contracts";
|
||||
|
||||
const ProjectionThreadDbRow = ProjectionThread.mapFields(
|
||||
Struct.assign({
|
||||
modelSelection: Schema.fromJsonString(ModelSelection),
|
||||
linkedPullRequest: Schema.NullOr(Schema.fromJsonString(ThreadLinkedPullRequest)),
|
||||
}),
|
||||
);
|
||||
type ProjectionThreadDbRow = typeof ProjectionThreadDbRow.Type;
|
||||
@@ -39,6 +40,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
interaction_mode,
|
||||
branch,
|
||||
worktree_path,
|
||||
linked_pull_request_json,
|
||||
latest_turn_id,
|
||||
created_at,
|
||||
updated_at,
|
||||
@@ -66,6 +68,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
${row.interactionMode},
|
||||
${row.branch},
|
||||
${row.worktreePath},
|
||||
${row.linkedPullRequest === undefined || row.linkedPullRequest === null ? null : JSON.stringify(row.linkedPullRequest)},
|
||||
${row.latestTurnId},
|
||||
${row.createdAt},
|
||||
${row.updatedAt},
|
||||
@@ -93,6 +96,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
interaction_mode = excluded.interaction_mode,
|
||||
branch = excluded.branch,
|
||||
worktree_path = excluded.worktree_path,
|
||||
linked_pull_request_json = excluded.linked_pull_request_json,
|
||||
latest_turn_id = excluded.latest_turn_id,
|
||||
created_at = excluded.created_at,
|
||||
updated_at = excluded.updated_at,
|
||||
@@ -127,6 +131,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
interaction_mode AS "interactionMode",
|
||||
branch,
|
||||
worktree_path AS "worktreePath",
|
||||
linked_pull_request_json AS "linkedPullRequest",
|
||||
latest_turn_id AS "latestTurnId",
|
||||
created_at AS "createdAt",
|
||||
updated_at AS "updatedAt",
|
||||
@@ -163,6 +168,7 @@ const makeProjectionThreadRepository = Effect.gen(function* () {
|
||||
interaction_mode AS "interactionMode",
|
||||
branch,
|
||||
worktree_path AS "worktreePath",
|
||||
linked_pull_request_json AS "linkedPullRequest",
|
||||
latest_turn_id AS "latestTurnId",
|
||||
created_at AS "createdAt",
|
||||
updated_at AS "updatedAt",
|
||||
|
||||
@@ -54,6 +54,7 @@ import Migration0038 from "./Migrations/038_ProjectionThreadsPinOrderKey.ts";
|
||||
import Migration0039 from "./Migrations/039_ProjectionProjectsDefaultThreadEnvMode.ts";
|
||||
import Migration0040 from "./Migrations/040_ProjectionProjectFaviconPath.ts";
|
||||
import Migration0041 from "./Migrations/041_AuthSessionClientConnection.ts";
|
||||
import Migration0042 from "./Migrations/042_ProjectionThreadLinkedPullRequest.ts";
|
||||
|
||||
/**
|
||||
* Migration loader with all migrations defined inline.
|
||||
@@ -107,6 +108,7 @@ export const migrationEntries = [
|
||||
[39, "ProjectionProjectsDefaultThreadEnvMode", Migration0039],
|
||||
[40, "ProjectionProjectFaviconPath", Migration0040],
|
||||
[41, "AuthSessionClientConnection", Migration0041],
|
||||
[42, "ProjectionThreadLinkedPullRequest", Migration0042],
|
||||
] as const;
|
||||
|
||||
export const migrationManifest = migrationEntries.map(([id, name]) => [id, name] as const);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
import { runMigrations } from "../Migrations.ts";
|
||||
import * as NodeSqliteClient from "../NodeSqliteClient.ts";
|
||||
|
||||
const layer = it.layer(Layer.mergeAll(NodeSqliteClient.layerMemory()));
|
||||
|
||||
layer("042_ProjectionThreadLinkedPullRequest", (it) => {
|
||||
it.effect("adds the linked pull request column", () =>
|
||||
Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
|
||||
yield* runMigrations({ toMigrationInclusive: 41 });
|
||||
yield* runMigrations({ toMigrationInclusive: 42 });
|
||||
|
||||
const columns = yield* sql<{ readonly name: string }>`
|
||||
PRAGMA table_info(projection_threads)
|
||||
`;
|
||||
assert.ok(columns.some((column) => column.name === "linked_pull_request_json"));
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
||||
|
||||
export default Effect.gen(function* () {
|
||||
const sql = yield* SqlClient.SqlClient;
|
||||
const columns = yield* sql<{ readonly name: string }>`
|
||||
PRAGMA table_info(projection_threads)
|
||||
`;
|
||||
|
||||
if (!columns.some((column) => column.name === "linked_pull_request_json")) {
|
||||
yield* sql`
|
||||
ALTER TABLE projection_threads
|
||||
ADD COLUMN linked_pull_request_json TEXT
|
||||
`;
|
||||
}
|
||||
});
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
ProjectId,
|
||||
ProviderInteractionMode,
|
||||
RuntimeMode,
|
||||
ThreadLinkedPullRequest,
|
||||
ThreadId,
|
||||
TurnId,
|
||||
} from "@t3tools/contracts";
|
||||
@@ -33,6 +34,7 @@ export const ProjectionThread = Schema.Struct({
|
||||
interactionMode: ProviderInteractionMode,
|
||||
branch: Schema.NullOr(Schema.String),
|
||||
worktreePath: Schema.NullOr(Schema.String),
|
||||
linkedPullRequest: Schema.optional(Schema.NullOr(ThreadLinkedPullRequest)),
|
||||
latestTurnId: Schema.NullOr(TurnId),
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
|
||||
@@ -11,10 +11,17 @@ vi.mock("../state/session", async (importOriginal) => ({
|
||||
usePreparedConnection: () => ({ _tag: "Loading" }),
|
||||
}));
|
||||
vi.mock("../state/entities", () => ({
|
||||
readThreadShell: () => null,
|
||||
useActiveEnvironmentId: () => EnvironmentId.make("env-windows"),
|
||||
useProjects: () => [],
|
||||
}));
|
||||
vi.mock("../editorPreferences", () => ({ useOpenInPreferredEditor: () => vi.fn() }));
|
||||
vi.mock("~/lib/openPullRequestLink", () => ({ useOpenChangeRequestLink: () => vi.fn() }));
|
||||
vi.mock("~/lib/openPullRequestLink", () => ({
|
||||
findProjectForChangeRequest: () => undefined,
|
||||
matchesLinkedPullRequestUrl: () => false,
|
||||
parseChangeRequestUrl: () => null,
|
||||
useOpenChangeRequestLink: () => vi.fn(),
|
||||
}));
|
||||
|
||||
import ChatMarkdown, { orderedListGutterStyle } from "./ChatMarkdown";
|
||||
|
||||
|
||||
@@ -13,7 +13,11 @@ import {
|
||||
TriangleAlertIcon,
|
||||
WrapTextIcon,
|
||||
} from "lucide-react";
|
||||
import type { ScopedThreadRef, ServerProviderSkill } from "@t3tools/contracts";
|
||||
import type {
|
||||
ScopedThreadRef,
|
||||
ServerProviderSkill,
|
||||
ThreadLinkedPullRequest,
|
||||
} from "@t3tools/contracts";
|
||||
import {
|
||||
isAtomCommandInterrupted,
|
||||
squashAtomCommandFailure,
|
||||
@@ -88,7 +92,7 @@ import { readLocalApi } from "../localApi";
|
||||
import { useAssetUrlState } from "../assets/assetUrls";
|
||||
import { cn } from "../lib/utils";
|
||||
import { useRightPanelStore } from "../rightPanelStore";
|
||||
import { useActiveEnvironmentId } from "../state/entities";
|
||||
import { readThreadShell, useActiveEnvironmentId, useProjects } from "../state/entities";
|
||||
import { serverEnvironment } from "../state/server";
|
||||
import { assetEnvironment } from "../state/assets";
|
||||
import { usePreparedConnection } from "../state/session";
|
||||
@@ -96,13 +100,19 @@ import { previewEnvironment } from "../state/preview";
|
||||
import { useAtomCommand } from "../state/use-atom-command";
|
||||
import { useAtomQueryRunner } from "../state/use-atom-query-runner";
|
||||
import { projectEnvironment } from "../state/projects";
|
||||
import { threadEnvironment } from "../state/threads";
|
||||
import {
|
||||
claimWorkspaceBasenameLookup,
|
||||
needsWorkspaceBasenameLookup,
|
||||
pickWorkspaceBasenameMatch,
|
||||
WORKSPACE_BASENAME_LOOKUP_LIMIT,
|
||||
} from "../workspaceBasenameLookup";
|
||||
import { useOpenChangeRequestLink } from "~/lib/openPullRequestLink";
|
||||
import {
|
||||
findProjectForChangeRequest,
|
||||
matchesLinkedPullRequestUrl,
|
||||
parseChangeRequestUrl,
|
||||
useOpenChangeRequestLink,
|
||||
} from "~/lib/openPullRequestLink";
|
||||
import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
|
||||
import { isPreviewSupportedInRuntime } from "../previewStateStore";
|
||||
import {
|
||||
@@ -1472,9 +1482,16 @@ function ChatMarkdown({
|
||||
const openPreview = useAtomCommand(previewEnvironment.open, {
|
||||
reportFailure: false,
|
||||
});
|
||||
const updateThreadMetadata = useAtomCommand(threadEnvironment.updateMetadata, {
|
||||
reportFailure: false,
|
||||
});
|
||||
const preparedConnection = usePreparedConnection(threadRef?.environmentId ?? null);
|
||||
const environmentId = useActiveEnvironmentId();
|
||||
const serverConfig = useAtomValue(serverEnvironment.configValueAtom(environmentId));
|
||||
const threadServerConfig = useAtomValue(
|
||||
serverEnvironment.configValueAtom(threadRef?.environmentId ?? environmentId),
|
||||
);
|
||||
const projects = useProjects();
|
||||
const openInPreferredEditor = useOpenInPreferredEditor(
|
||||
environmentId,
|
||||
serverConfig?.availableEditors ?? [],
|
||||
@@ -1528,6 +1545,54 @@ function ChatMarkdown({
|
||||
event.clipboardData.setData("text/html", payload.html);
|
||||
}, []);
|
||||
const openChangeRequestLink = useOpenChangeRequestLink(threadRef);
|
||||
const resolveThreadPullRequest = useCallback(
|
||||
(href: string): ThreadLinkedPullRequest | null => {
|
||||
if (
|
||||
threadRef === undefined ||
|
||||
readThreadShell(threadRef) === null ||
|
||||
threadServerConfig?.environment.capabilities.threadPullRequestLinking !== true
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
const parsed = parseChangeRequestUrl(href);
|
||||
if (parsed === null) return null;
|
||||
const project = findProjectForChangeRequest(
|
||||
projects.filter((candidate) => candidate.environmentId === threadRef.environmentId),
|
||||
parsed,
|
||||
);
|
||||
if (project === undefined) return null;
|
||||
return {
|
||||
projectId: project.id,
|
||||
repository: project.repositoryIdentity?.displayName ?? parsed.repository,
|
||||
number: parsed.number,
|
||||
url: href,
|
||||
};
|
||||
},
|
||||
[projects, threadRef, threadServerConfig],
|
||||
);
|
||||
const updateThreadPullRequestLink = useCallback(
|
||||
async (href: string, linked: boolean) => {
|
||||
if (threadRef === undefined) return;
|
||||
const linkedPullRequest = linked ? resolveThreadPullRequest(href) : null;
|
||||
if (linked && linkedPullRequest === null) {
|
||||
throw new Error("The pull request is not available in this environment.");
|
||||
}
|
||||
if (!linked) {
|
||||
const currentPullRequest = readThreadShell(threadRef)?.linkedPullRequest;
|
||||
if (currentPullRequest == null || !matchesLinkedPullRequestUrl(currentPullRequest, href)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const result = await updateThreadMetadata({
|
||||
environmentId: threadRef.environmentId,
|
||||
input: { threadId: threadRef.threadId, linkedPullRequest },
|
||||
});
|
||||
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
|
||||
throw squashAtomCommandFailure(result);
|
||||
}
|
||||
},
|
||||
[resolveThreadPullRequest, threadRef, updateThreadMetadata],
|
||||
);
|
||||
const openExternalLinkInPreview = useCallback(
|
||||
(url: string) => {
|
||||
if (!threadRef) {
|
||||
@@ -1760,9 +1825,20 @@ function ChatMarkdown({
|
||||
event.stopPropagation();
|
||||
const api = readLocalApi();
|
||||
if (!api) return;
|
||||
const pullRequest = resolveThreadPullRequest(href);
|
||||
const currentPullRequest =
|
||||
threadRef === undefined ? null : readThreadShell(threadRef)?.linkedPullRequest;
|
||||
const threadLinkAction =
|
||||
currentPullRequest != null &&
|
||||
matchesLinkedPullRequestUrl(currentPullRequest, href)
|
||||
? "unlink-from-thread"
|
||||
: pullRequest === null
|
||||
? undefined
|
||||
: "link-to-thread";
|
||||
void showExternalLinkContextMenu({
|
||||
href,
|
||||
canOpenInPreview,
|
||||
threadLinkAction,
|
||||
position: { x: event.clientX, y: event.clientY },
|
||||
showContextMenu: (items, position) => api.contextMenu.show(items, position),
|
||||
openInPreview: async (target) => {
|
||||
@@ -1776,8 +1852,25 @@ function ChatMarkdown({
|
||||
},
|
||||
openExternal: (target) => api.shell.openExternal(target),
|
||||
copyLink: (target) => writeTextToClipboard(target, "link"),
|
||||
updateThreadLink: updateThreadPullRequestLink,
|
||||
reportFailure: (operation, cause) => {
|
||||
reportMarkdownActionFailure({ operation, target: href }, cause);
|
||||
if (
|
||||
operation === "link-pull-request-to-thread" ||
|
||||
operation === "unlink-pull-request-from-thread"
|
||||
) {
|
||||
toastManager.add(
|
||||
stackedThreadToast({
|
||||
type: "error",
|
||||
title:
|
||||
operation === "link-pull-request-to-thread"
|
||||
? "Unable to link pull request"
|
||||
: "Unable to unlink pull request",
|
||||
description:
|
||||
cause instanceof Error ? cause.message : "The request failed.",
|
||||
}),
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -1900,12 +1993,15 @@ function ChatMarkdown({
|
||||
onTaskListChange,
|
||||
openFileInPanel,
|
||||
openInPreferredEditor,
|
||||
openChangeRequestLink,
|
||||
openExternalLinkInPreview,
|
||||
openMarkdownFileInPreview,
|
||||
resolveThreadPullRequest,
|
||||
resolvedTheme,
|
||||
skills,
|
||||
text,
|
||||
threadRef,
|
||||
updateThreadPullRequestLink,
|
||||
]);
|
||||
/* eslint-enable react/no-unstable-nested-components */
|
||||
|
||||
|
||||
@@ -24,10 +24,17 @@ vi.mock("../state/session", async (importOriginal) => ({
|
||||
usePreparedConnection: () => ({ _tag: "Loading" }),
|
||||
}));
|
||||
vi.mock("../state/entities", () => ({
|
||||
readThreadShell: () => null,
|
||||
useActiveEnvironmentId: () => EnvironmentId.make("env-windows"),
|
||||
useProjects: () => [],
|
||||
}));
|
||||
vi.mock("../editorPreferences", () => ({ useOpenInPreferredEditor: () => vi.fn() }));
|
||||
vi.mock("~/lib/openPullRequestLink", () => ({ useOpenChangeRequestLink: () => vi.fn() }));
|
||||
vi.mock("~/lib/openPullRequestLink", () => ({
|
||||
findProjectForChangeRequest: () => undefined,
|
||||
matchesLinkedPullRequestUrl: () => false,
|
||||
parseChangeRequestUrl: () => null,
|
||||
useOpenChangeRequestLink: () => vi.fn(),
|
||||
}));
|
||||
|
||||
import ChatMarkdown from "./ChatMarkdown";
|
||||
|
||||
|
||||
@@ -302,6 +302,7 @@ import {
|
||||
import {
|
||||
resolveDisplayedThreadPr,
|
||||
threadChangeRequestSnapshotsAtom,
|
||||
useLinkedThreadPullRequest,
|
||||
} from "./ThreadStatusIndicators";
|
||||
import { ComposerBannerStack, type ComposerBannerStackItem } from "./chat/ComposerBannerStack";
|
||||
import { ThreadSyncStatusPill } from "./chat/ThreadSyncStatusPill";
|
||||
@@ -3412,24 +3413,48 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
);
|
||||
// The thread's own change request, placed against the project it belongs to. Without a
|
||||
// project there is nothing to resolve it against, so the caller falls back to the browser.
|
||||
const threadRepository = activeProject?.repositoryIdentity?.displayName ?? null;
|
||||
const linkedThreadPullRequest = activeThread?.linkedPullRequest ?? null;
|
||||
const activeProjectRepository = activeProject?.repositoryIdentity?.displayName ?? null;
|
||||
const threadRepository = linkedThreadPullRequest?.repository ?? activeProjectRepository;
|
||||
const openThreadPullRequest = useCallback(
|
||||
(number: number) => {
|
||||
if (!supportsPullRequests || !activeThreadRef) {
|
||||
return;
|
||||
}
|
||||
const projectId = linkedThreadPullRequest?.projectId ?? activeProject?.id;
|
||||
const repository = linkedThreadPullRequest?.repository ?? activeProjectRepository;
|
||||
if (projectId === undefined || repository === null) return;
|
||||
useRightPanelStore.getState().openPullRequest(activeThreadRef, {
|
||||
projectId,
|
||||
repository,
|
||||
number,
|
||||
});
|
||||
},
|
||||
[
|
||||
activeProject,
|
||||
activeProjectRepository,
|
||||
activeThreadRef,
|
||||
linkedThreadPullRequest,
|
||||
supportsPullRequests,
|
||||
],
|
||||
);
|
||||
const openProjectPullRequest = useCallback(
|
||||
(number: number) => {
|
||||
if (
|
||||
!supportsPullRequests ||
|
||||
!activeThreadRef ||
|
||||
!activeProject ||
|
||||
threadRepository === null
|
||||
activeProjectRepository === null
|
||||
) {
|
||||
return;
|
||||
}
|
||||
useRightPanelStore.getState().openPullRequest(activeThreadRef, {
|
||||
projectId: activeProject.id,
|
||||
repository: threadRepository,
|
||||
repository: activeProjectRepository,
|
||||
number,
|
||||
});
|
||||
},
|
||||
[activeProject, activeThreadRef, supportsPullRequests, threadRepository],
|
||||
[activeProject, activeProjectRepository, activeThreadRef, supportsPullRequests],
|
||||
);
|
||||
const togglePreviewPanel = useCallback(() => {
|
||||
if (!activeThreadRef || !isPreviewSupportedInRuntime()) return;
|
||||
@@ -4307,11 +4332,17 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
: null;
|
||||
const autoSettleAfterDays = useClientSettings((settings) => settings.sidebarAutoSettleAfterDays);
|
||||
const autoSettleOnMerge = useClientSettings((settings) => settings.sidebarAutoSettleOnMerge);
|
||||
const linkedPullRequestStatus = useLinkedThreadPullRequest(
|
||||
activeThreadRef?.environmentId ?? null,
|
||||
linkedThreadPullRequest,
|
||||
);
|
||||
const activeThreadPr = resolveDisplayedThreadPr({
|
||||
threadBranch: activeThread?.branch ?? null,
|
||||
gitStatus: gitStatusQuery.data ?? null,
|
||||
snapshot: activeThreadKey ? changeRequestSnapshotByKey.get(activeThreadKey) : undefined,
|
||||
retainTerminalOnBranchMismatch: activeThread?.worktreePath === null,
|
||||
linkedPullRequest: linkedThreadPullRequest,
|
||||
linkedPullRequestStatus,
|
||||
});
|
||||
// The right panel offers the thread's own change request, so it can only offer it once the
|
||||
// branch has one; until then the picker says so rather than opening an empty panel.
|
||||
@@ -6578,7 +6609,7 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
context={
|
||||
isThreadOwnPullRequest(
|
||||
{
|
||||
projectId: activeProject?.id ?? null,
|
||||
projectId: linkedThreadPullRequest?.projectId ?? activeProject?.id ?? null,
|
||||
repository: threadRepository,
|
||||
number: activeThreadPr?.number ?? null,
|
||||
},
|
||||
@@ -6651,9 +6682,9 @@ function ChatViewContent(props: ChatViewProps) {
|
||||
>
|
||||
{!rightPanelOpen ? panelLayoutControls : null}
|
||||
<ChatHeader
|
||||
{...(!supportsPullRequests || threadRepository === null
|
||||
{...(!supportsPullRequests || activeProjectRepository === null
|
||||
? {}
|
||||
: { onOpenPullRequest: openThreadPullRequest })}
|
||||
: { onOpenPullRequest: openProjectPullRequest })}
|
||||
activeThreadEnvironmentId={activeThread.environmentId}
|
||||
activeThreadId={activeThread.id}
|
||||
{...(routeKind === "draft" && draftId ? { draftId } : {})}
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
terminalStatusFromRunningIds,
|
||||
ThreadStatusLabel,
|
||||
ThreadWorktreeIndicator,
|
||||
useLinkedThreadPullRequest,
|
||||
} from "./ThreadStatusIndicators";
|
||||
import { ProjectFavicon } from "./ProjectFavicon";
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
@@ -416,7 +417,7 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
const threadProjectCwd = threadProject?.workspaceRoot ?? null;
|
||||
const gitCwd = thread.worktreePath ?? threadProjectCwd ?? props.projectCwd;
|
||||
const gitStatus = useEnvironmentQuery(
|
||||
thread.branch != null && gitCwd !== null
|
||||
thread.linkedPullRequest == null && thread.branch != null && gitCwd !== null
|
||||
? vcsEnvironment.status({
|
||||
environmentId: thread.environmentId,
|
||||
input: { cwd: gitCwd },
|
||||
@@ -457,11 +458,18 @@ export const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThr
|
||||
lastVisitedAt,
|
||||
},
|
||||
});
|
||||
const pr = resolveThreadPr({
|
||||
threadBranch: thread.branch,
|
||||
gitStatus: gitStatus.data,
|
||||
});
|
||||
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
|
||||
const linkedPullRequestStatus = useLinkedThreadPullRequest(
|
||||
thread.environmentId,
|
||||
thread.linkedPullRequest,
|
||||
);
|
||||
const pr =
|
||||
thread.linkedPullRequest == null
|
||||
? resolveThreadPr({ threadBranch: thread.branch, gitStatus: gitStatus.data })
|
||||
: (linkedPullRequestStatus?.pr ?? null);
|
||||
const prStatus = prStatusIndicator(
|
||||
pr,
|
||||
linkedPullRequestStatus?.sourceControlProvider ?? gitStatus.data?.sourceControlProvider,
|
||||
);
|
||||
const terminalStatus = terminalStatusFromRunningIds(runningTerminalIds);
|
||||
const isConfirmingArchive = confirmingArchiveThreadKey === threadKey && !isThreadRunning;
|
||||
const threadMetaClassName = isConfirmingArchive
|
||||
|
||||
@@ -156,6 +156,7 @@ import {
|
||||
threadChangeRequestSnapshotsAtom,
|
||||
type ThreadChangeRequestSnapshot,
|
||||
type TerminalStatusIndicator,
|
||||
useLinkedThreadPullRequest,
|
||||
} from "./ThreadStatusIndicators";
|
||||
import {
|
||||
resolveSnoozePresets,
|
||||
@@ -787,6 +788,10 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
|
||||
const terminalProcessCount = runningTerminalIds.length;
|
||||
|
||||
const gitCwd = thread.worktreePath ?? props.projectCwd;
|
||||
const linkedPullRequestStatus = useLinkedThreadPullRequest(
|
||||
thread.environmentId,
|
||||
thread.linkedPullRequest,
|
||||
);
|
||||
const gitStatus = useEnvironmentQuery(
|
||||
(thread.branch != null || thread.worktreePath !== null) && gitCwd !== null
|
||||
? vcsEnvironment.status({
|
||||
@@ -801,6 +806,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
|
||||
gitStatus: gitStatus.data,
|
||||
snapshot: changeRequestSnapshot,
|
||||
retainTerminalOnBranchMismatch,
|
||||
linkedPullRequest: thread.linkedPullRequest,
|
||||
linkedPullRequestStatus,
|
||||
});
|
||||
|
||||
// Same semantics as the legacy sidebar (never-visited counts as read):
|
||||
@@ -901,6 +908,8 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
|
||||
gitStatus: gitStatus.data,
|
||||
snapshot: changeRequestSnapshot,
|
||||
retainTerminalOnBranchMismatch,
|
||||
linkedPullRequest: thread.linkedPullRequest,
|
||||
linkedPullRequestStatus,
|
||||
});
|
||||
const prStatus = prStatusIndicator(pr, prProvider);
|
||||
const settledPrHoverClass = pr ? settledPrHoverColorClass(pr.state) : undefined;
|
||||
@@ -910,15 +919,19 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
|
||||
gitStatus: gitStatus.data,
|
||||
snapshot: changeRequestSnapshot,
|
||||
retainTerminalOnBranchMismatch,
|
||||
linkedPullRequest: thread.linkedPullRequest,
|
||||
linkedPullRequestStatus,
|
||||
});
|
||||
if (nextSnapshot === undefined) return;
|
||||
onChangeRequestSnapshot(threadKey, nextSnapshot);
|
||||
}, [
|
||||
changeRequestSnapshot,
|
||||
gitStatus.data,
|
||||
linkedPullRequestStatus,
|
||||
onChangeRequestSnapshot,
|
||||
retainTerminalOnBranchMismatch,
|
||||
thread.branch,
|
||||
thread.linkedPullRequest,
|
||||
threadKey,
|
||||
]);
|
||||
|
||||
@@ -2039,7 +2052,12 @@ export default function Sidebar() {
|
||||
const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id));
|
||||
const snapshot = changeRequestSnapshotByKey.get(threadKey);
|
||||
const changeRequest =
|
||||
snapshot != null && (thread.worktreePath === null || snapshot.branch === thread.branch)
|
||||
snapshot != null &&
|
||||
(thread.linkedPullRequest == null
|
||||
? thread.worktreePath === null || snapshot.branch === thread.branch
|
||||
: snapshot.linkedPullRequest?.projectId === thread.linkedPullRequest.projectId &&
|
||||
snapshot.linkedPullRequest.repository === thread.linkedPullRequest.repository &&
|
||||
snapshot.linkedPullRequest.number === thread.linkedPullRequest.number)
|
||||
? snapshot.pr
|
||||
: null;
|
||||
// Snooze outranks settlement and pinning until the thread wakes.
|
||||
|
||||
@@ -101,6 +101,12 @@ describe("resolveThreadPr", () => {
|
||||
describe("resolveDisplayedThreadPr + nextThreadChangeRequestSnapshot", () => {
|
||||
const featureBranch = "feature/current";
|
||||
const mergedPr = mergedFeaturePr();
|
||||
const linkedPullRequest = {
|
||||
projectId: ProjectId.make("project-1"),
|
||||
repository: "pingdotgg/t3code",
|
||||
number: 42,
|
||||
url: "https://github.com/pingdotgg/t3code/pull/42",
|
||||
};
|
||||
const provider = {
|
||||
kind: "github" as const,
|
||||
name: "GitHub",
|
||||
@@ -132,6 +138,119 @@ describe("resolveDisplayedThreadPr + nextThreadChangeRequestSnapshot", () => {
|
||||
).toEqual(provider);
|
||||
});
|
||||
|
||||
it("shows a linked pull request when the checkout has a different branch", () => {
|
||||
const linkedPullRequestStatus = {
|
||||
pr: mergedPr,
|
||||
sourceControlProvider: provider,
|
||||
};
|
||||
|
||||
expect(
|
||||
resolveDisplayedThreadPr({
|
||||
threadBranch: "feature/other",
|
||||
gitStatus: status({ refName: "feature/other", pr: null }),
|
||||
snapshot: undefined,
|
||||
retainTerminalOnBranchMismatch: false,
|
||||
linkedPullRequest,
|
||||
linkedPullRequestStatus,
|
||||
}),
|
||||
).toEqual(mergedPr);
|
||||
expect(
|
||||
resolveDisplayedThreadPrProvider({
|
||||
threadBranch: "feature/other",
|
||||
gitStatus: status({ refName: "feature/other", pr: null }),
|
||||
snapshot: undefined,
|
||||
retainTerminalOnBranchMismatch: false,
|
||||
linkedPullRequest,
|
||||
linkedPullRequestStatus,
|
||||
}),
|
||||
).toEqual(provider);
|
||||
expect(
|
||||
nextThreadChangeRequestSnapshot({
|
||||
threadBranch: "feature/other",
|
||||
gitStatus: status({ refName: "feature/other", pr: null }),
|
||||
snapshot: undefined,
|
||||
retainTerminalOnBranchMismatch: false,
|
||||
linkedPullRequest,
|
||||
linkedPullRequestStatus,
|
||||
}),
|
||||
).toEqual({
|
||||
branch: "feature/other",
|
||||
pr: mergedPr,
|
||||
sourceControlProvider: provider,
|
||||
linkedPullRequest,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps a matching linked pull request snapshot while its status reloads", () => {
|
||||
const snapshot = {
|
||||
...snapshotFor(featureBranch, mergedPr, provider),
|
||||
linkedPullRequest,
|
||||
};
|
||||
|
||||
expect(
|
||||
resolveDisplayedThreadPr({
|
||||
threadBranch: null,
|
||||
gitStatus: null,
|
||||
snapshot,
|
||||
retainTerminalOnBranchMismatch: false,
|
||||
linkedPullRequest,
|
||||
linkedPullRequestStatus: null,
|
||||
}),
|
||||
).toEqual(mergedPr);
|
||||
expect(
|
||||
nextThreadChangeRequestSnapshot({
|
||||
threadBranch: null,
|
||||
gitStatus: null,
|
||||
snapshot,
|
||||
retainTerminalOnBranchMismatch: false,
|
||||
linkedPullRequest,
|
||||
linkedPullRequestStatus: null,
|
||||
}),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("clears an old snapshot when a different pull request is linked", () => {
|
||||
const snapshot = {
|
||||
...snapshotFor(featureBranch, mergedPr, provider),
|
||||
linkedPullRequest: { ...linkedPullRequest, number: 41 },
|
||||
};
|
||||
|
||||
expect(
|
||||
nextThreadChangeRequestSnapshot({
|
||||
threadBranch: featureBranch,
|
||||
gitStatus: null,
|
||||
snapshot,
|
||||
retainTerminalOnBranchMismatch: true,
|
||||
linkedPullRequest,
|
||||
linkedPullRequestStatus: null,
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("removes a linked pull request snapshot after the link is cleared", () => {
|
||||
const snapshot = {
|
||||
...snapshotFor(featureBranch, mergedPr, provider),
|
||||
linkedPullRequest,
|
||||
};
|
||||
|
||||
expect(
|
||||
resolveDisplayedThreadPr({
|
||||
threadBranch: featureBranch,
|
||||
gitStatus: status({ refName: "main", pr: null }),
|
||||
snapshot,
|
||||
retainTerminalOnBranchMismatch: true,
|
||||
}),
|
||||
).toBeNull();
|
||||
expect(
|
||||
nextThreadChangeRequestSnapshot({
|
||||
threadBranch: featureBranch,
|
||||
gitStatus: null,
|
||||
snapshot,
|
||||
retainTerminalOnBranchMismatch: true,
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it("after caching a merged PR, resolves main status back to the cached feature PR", () => {
|
||||
const matchingStatus = status({
|
||||
refName: featureBranch,
|
||||
|
||||
@@ -3,7 +3,8 @@ import {
|
||||
scopedThreadKey,
|
||||
scopeThreadRef,
|
||||
} from "@t3tools/client-runtime/environment";
|
||||
import type { VcsStatusResult } from "@t3tools/contracts";
|
||||
import { pullRequestDetailToVcsStatus } from "@t3tools/client-runtime/state/pull-requests";
|
||||
import type { EnvironmentId, ThreadLinkedPullRequest, VcsStatusResult } from "@t3tools/contracts";
|
||||
import { Atom } from "effect/unstable/reactivity";
|
||||
import { CloudIcon, FolderGit2Icon, GitPullRequestIcon, TerminalIcon } from "lucide-react";
|
||||
import { useMemo } from "react";
|
||||
@@ -11,6 +12,7 @@ import { appAtomRegistry } from "../rpc/atomRegistry";
|
||||
import { useEnvironment, usePrimaryEnvironmentId } from "../state/environments";
|
||||
import { useProject } from "../state/entities";
|
||||
import { useEnvironmentQuery } from "../state/query";
|
||||
import { linkedPullRequestDetailAtom } from "../state/pullRequests";
|
||||
import { useThreadRunningTerminalIds } from "../state/terminalSessions";
|
||||
import { vcsEnvironment } from "../state/vcs";
|
||||
import { useUiStateStore } from "../uiStateStore";
|
||||
@@ -37,6 +39,44 @@ export interface TerminalStatusIndicator {
|
||||
|
||||
export type ThreadPr = VcsStatusResult["pr"];
|
||||
|
||||
export interface LinkedThreadPullRequestStatus {
|
||||
readonly pr: NonNullable<ThreadPr>;
|
||||
readonly sourceControlProvider: NonNullable<VcsStatusResult["sourceControlProvider"]>;
|
||||
}
|
||||
|
||||
export function useLinkedThreadPullRequest(
|
||||
environmentId: EnvironmentId | null,
|
||||
linkedPullRequest: ThreadLinkedPullRequest | null | undefined,
|
||||
): LinkedThreadPullRequestStatus | null {
|
||||
const detail = useEnvironmentQuery(
|
||||
environmentId === null || linkedPullRequest == null
|
||||
? null
|
||||
: linkedPullRequestDetailAtom({
|
||||
environmentId,
|
||||
input: {
|
||||
projectId: linkedPullRequest.projectId,
|
||||
repository: linkedPullRequest.repository,
|
||||
number: linkedPullRequest.number,
|
||||
},
|
||||
}),
|
||||
).data;
|
||||
|
||||
return useMemo(
|
||||
() =>
|
||||
detail === null
|
||||
? null
|
||||
: {
|
||||
pr: pullRequestDetailToVcsStatus(detail),
|
||||
sourceControlProvider: {
|
||||
kind: detail.provider,
|
||||
name: detail.provider,
|
||||
baseUrl: "",
|
||||
},
|
||||
},
|
||||
[detail],
|
||||
);
|
||||
}
|
||||
|
||||
export function settledPrHoverColorClass(state: NonNullable<ThreadPr>["state"]): string {
|
||||
switch (state) {
|
||||
case "open":
|
||||
@@ -136,6 +176,7 @@ export interface ThreadChangeRequestSnapshot {
|
||||
readonly branch: string;
|
||||
readonly pr: NonNullable<ThreadPr>;
|
||||
readonly sourceControlProvider: VcsStatusResult["sourceControlProvider"] | undefined;
|
||||
readonly linkedPullRequest?: ThreadLinkedPullRequest;
|
||||
}
|
||||
|
||||
export const threadChangeRequestSnapshotsAtom = Atom.make<
|
||||
@@ -157,6 +198,19 @@ function sourceControlProvidersEqual(
|
||||
return left.kind === right.kind && left.name === right.name && left.baseUrl === right.baseUrl;
|
||||
}
|
||||
|
||||
function linkedPullRequestsEqual(
|
||||
left: ThreadLinkedPullRequest | null | undefined,
|
||||
right: ThreadLinkedPullRequest | null | undefined,
|
||||
): boolean {
|
||||
if (left == null || right == null) return left == null && right == null;
|
||||
return (
|
||||
left.projectId === right.projectId &&
|
||||
left.repository === right.repository &&
|
||||
left.number === right.number &&
|
||||
left.url === right.url
|
||||
);
|
||||
}
|
||||
|
||||
export function threadChangeRequestSnapshotsEqual(
|
||||
left: ThreadChangeRequestSnapshot,
|
||||
right: ThreadChangeRequestSnapshot,
|
||||
@@ -170,7 +224,8 @@ export function threadChangeRequestSnapshotsEqual(
|
||||
left.pr.headRef === right.pr.headRef &&
|
||||
left.pr.state === right.pr.state &&
|
||||
(left.pr.updatedAt ?? null) === (right.pr.updatedAt ?? null) &&
|
||||
sourceControlProvidersEqual(left.sourceControlProvider, right.sourceControlProvider)
|
||||
sourceControlProvidersEqual(left.sourceControlProvider, right.sourceControlProvider) &&
|
||||
linkedPullRequestsEqual(left.linkedPullRequest, right.linkedPullRequest)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -206,10 +261,32 @@ export function nextThreadChangeRequestSnapshot(input: {
|
||||
gitStatus: VcsStatusResult | null;
|
||||
snapshot: ThreadChangeRequestSnapshot | null | undefined;
|
||||
retainTerminalOnBranchMismatch: boolean;
|
||||
linkedPullRequest?: ThreadLinkedPullRequest | null | undefined;
|
||||
linkedPullRequestStatus?: LinkedThreadPullRequestStatus | null | undefined;
|
||||
}): ThreadChangeRequestSnapshot | null | undefined {
|
||||
const { threadBranch, gitStatus, snapshot, retainTerminalOnBranchMismatch } = input;
|
||||
const {
|
||||
threadBranch,
|
||||
gitStatus,
|
||||
snapshot,
|
||||
retainTerminalOnBranchMismatch,
|
||||
linkedPullRequest,
|
||||
linkedPullRequestStatus,
|
||||
} = input;
|
||||
if (linkedPullRequest != null) {
|
||||
if (linkedPullRequestStatus === null || linkedPullRequestStatus === undefined) {
|
||||
return linkedPullRequestsEqual(snapshot?.linkedPullRequest, linkedPullRequest)
|
||||
? undefined
|
||||
: null;
|
||||
}
|
||||
return {
|
||||
branch: threadBranch ?? linkedPullRequestStatus.pr.headRef,
|
||||
pr: linkedPullRequestStatus.pr,
|
||||
sourceControlProvider: linkedPullRequestStatus.sourceControlProvider,
|
||||
linkedPullRequest,
|
||||
};
|
||||
}
|
||||
if (gitStatus === null) {
|
||||
return undefined;
|
||||
return snapshot?.linkedPullRequest === undefined ? undefined : null;
|
||||
}
|
||||
if (threadBranch === null) {
|
||||
return null;
|
||||
@@ -217,6 +294,7 @@ export function nextThreadChangeRequestSnapshot(input: {
|
||||
if (gitStatus.refName !== threadBranch) {
|
||||
return retainTerminalOnBranchMismatch &&
|
||||
snapshot != null &&
|
||||
snapshot.linkedPullRequest === undefined &&
|
||||
isTerminalChangeRequestState(snapshot.pr.state)
|
||||
? undefined
|
||||
: null;
|
||||
@@ -225,6 +303,7 @@ export function nextThreadChangeRequestSnapshot(input: {
|
||||
if (
|
||||
retainTerminalOnBranchMismatch &&
|
||||
snapshot != null &&
|
||||
snapshot.linkedPullRequest === undefined &&
|
||||
isTerminalChangeRequestState(snapshot.pr.state)
|
||||
) {
|
||||
return undefined;
|
||||
@@ -250,8 +329,25 @@ export function resolveDisplayedThreadPr(input: {
|
||||
gitStatus: VcsStatusResult | null;
|
||||
snapshot: ThreadChangeRequestSnapshot | null | undefined;
|
||||
retainTerminalOnBranchMismatch: boolean;
|
||||
linkedPullRequest?: ThreadLinkedPullRequest | null | undefined;
|
||||
linkedPullRequestStatus?: LinkedThreadPullRequestStatus | null | undefined;
|
||||
}): ThreadPr | null {
|
||||
const { threadBranch, gitStatus, snapshot, retainTerminalOnBranchMismatch } = input;
|
||||
const {
|
||||
threadBranch,
|
||||
gitStatus,
|
||||
snapshot,
|
||||
retainTerminalOnBranchMismatch,
|
||||
linkedPullRequest,
|
||||
linkedPullRequestStatus,
|
||||
} = input;
|
||||
if (linkedPullRequest != null) {
|
||||
return (
|
||||
linkedPullRequestStatus?.pr ??
|
||||
(linkedPullRequestsEqual(snapshot?.linkedPullRequest, linkedPullRequest)
|
||||
? (snapshot?.pr ?? null)
|
||||
: null)
|
||||
);
|
||||
}
|
||||
if (
|
||||
threadBranch !== null &&
|
||||
gitStatus !== null &&
|
||||
@@ -265,6 +361,7 @@ export function resolveDisplayedThreadPr(input: {
|
||||
threadBranch !== null &&
|
||||
retainTerminalOnBranchMismatch &&
|
||||
snapshot != null &&
|
||||
snapshot.linkedPullRequest === undefined &&
|
||||
isTerminalChangeRequestState(snapshot.pr.state)
|
||||
) {
|
||||
return snapshot.pr;
|
||||
@@ -278,8 +375,25 @@ export function resolveDisplayedThreadPrProvider(input: {
|
||||
gitStatus: VcsStatusResult | null;
|
||||
snapshot: ThreadChangeRequestSnapshot | null | undefined;
|
||||
retainTerminalOnBranchMismatch: boolean;
|
||||
linkedPullRequest?: ThreadLinkedPullRequest | null | undefined;
|
||||
linkedPullRequestStatus?: LinkedThreadPullRequestStatus | null | undefined;
|
||||
}): VcsStatusResult["sourceControlProvider"] | undefined {
|
||||
const { threadBranch, gitStatus, snapshot, retainTerminalOnBranchMismatch } = input;
|
||||
const {
|
||||
threadBranch,
|
||||
gitStatus,
|
||||
snapshot,
|
||||
retainTerminalOnBranchMismatch,
|
||||
linkedPullRequest,
|
||||
linkedPullRequestStatus,
|
||||
} = input;
|
||||
if (linkedPullRequest != null) {
|
||||
return (
|
||||
linkedPullRequestStatus?.sourceControlProvider ??
|
||||
(linkedPullRequestsEqual(snapshot?.linkedPullRequest, linkedPullRequest)
|
||||
? snapshot?.sourceControlProvider
|
||||
: undefined)
|
||||
);
|
||||
}
|
||||
if (
|
||||
threadBranch !== null &&
|
||||
gitStatus !== null &&
|
||||
@@ -293,6 +407,7 @@ export function resolveDisplayedThreadPrProvider(input: {
|
||||
threadBranch !== null &&
|
||||
retainTerminalOnBranchMismatch &&
|
||||
snapshot != null &&
|
||||
snapshot.linkedPullRequest === undefined &&
|
||||
isTerminalChangeRequestState(snapshot.pr.state)
|
||||
) {
|
||||
return snapshot.sourceControlProvider;
|
||||
@@ -417,19 +532,28 @@ export function ThreadRowLeadingStatus({ thread }: { thread: SidebarThreadSummar
|
||||
);
|
||||
const threadProjectCwd = threadProject?.workspaceRoot ?? null;
|
||||
const gitCwd = thread.worktreePath ?? threadProjectCwd;
|
||||
const linkedPullRequest = useLinkedThreadPullRequest(
|
||||
thread.environmentId,
|
||||
thread.linkedPullRequest,
|
||||
);
|
||||
const gitStatus = useEnvironmentQuery(
|
||||
(thread.branch != null || thread.worktreePath !== null) && gitCwd !== null
|
||||
thread.linkedPullRequest == null &&
|
||||
(thread.branch != null || thread.worktreePath !== null) &&
|
||||
gitCwd !== null
|
||||
? vcsEnvironment.status({
|
||||
environmentId: thread.environmentId,
|
||||
input: { cwd: gitCwd },
|
||||
})
|
||||
: null,
|
||||
);
|
||||
const pr = resolveThreadPr({
|
||||
threadBranch: thread.branch,
|
||||
gitStatus: gitStatus.data,
|
||||
});
|
||||
const prStatus = prStatusIndicator(pr, gitStatus.data?.sourceControlProvider);
|
||||
const pr =
|
||||
thread.linkedPullRequest == null
|
||||
? resolveThreadPr({ threadBranch: thread.branch, gitStatus: gitStatus.data })
|
||||
: (linkedPullRequest?.pr ?? null);
|
||||
const prStatus = prStatusIndicator(
|
||||
pr,
|
||||
linkedPullRequest?.sourceControlProvider ?? gitStatus.data?.sourceControlProvider,
|
||||
);
|
||||
const threadStatus = resolveThreadStatusPill({
|
||||
thread: {
|
||||
...thread,
|
||||
|
||||
@@ -2,11 +2,20 @@ import { describe, expect, it, vi } from "vite-plus/test";
|
||||
|
||||
import { resolveExternalWebLinkHost, showExternalLinkContextMenu } from "./externalLinkContextMenu";
|
||||
|
||||
function createHarness(selection: "open-in-preview" | "open-external" | "copy-link" | null) {
|
||||
function createHarness(
|
||||
selection:
|
||||
| "open-in-preview"
|
||||
| "open-external"
|
||||
| "copy-link"
|
||||
| "link-to-thread"
|
||||
| "unlink-from-thread"
|
||||
| null,
|
||||
) {
|
||||
const showContextMenu = vi.fn().mockResolvedValue(selection);
|
||||
const openInPreview = vi.fn().mockResolvedValue(undefined);
|
||||
const openExternal = vi.fn().mockResolvedValue(undefined);
|
||||
const copyLink = vi.fn().mockResolvedValue(undefined);
|
||||
const updateThreadLink = vi.fn().mockResolvedValue(undefined);
|
||||
const reportFailure = vi.fn();
|
||||
|
||||
return {
|
||||
@@ -14,6 +23,7 @@ function createHarness(selection: "open-in-preview" | "open-external" | "copy-li
|
||||
openInPreview,
|
||||
openExternal,
|
||||
copyLink,
|
||||
updateThreadLink,
|
||||
reportFailure,
|
||||
};
|
||||
}
|
||||
@@ -71,6 +81,27 @@ describe("external chat link context menu", () => {
|
||||
expect(harness.openExternal).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([
|
||||
["link-to-thread", "Link to thread", true],
|
||||
["unlink-from-thread", "Unlink from thread", false],
|
||||
] as const)("offers and runs the %s action", async (action, label, linked) => {
|
||||
const harness = createHarness(action);
|
||||
const href = "https://github.com/pingdotgg/t3code/pull/42";
|
||||
|
||||
await showExternalLinkContextMenu({
|
||||
href,
|
||||
threadLinkAction: action,
|
||||
position: { x: 1, y: 2 },
|
||||
...harness,
|
||||
});
|
||||
|
||||
expect(harness.showContextMenu).toHaveBeenCalledWith(
|
||||
expect.arrayContaining([{ id: action, label }]),
|
||||
{ x: 1, y: 2 },
|
||||
);
|
||||
expect(harness.updateThreadLink).toHaveBeenCalledWith(href, linked);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["open-in-preview" as const, "openInPreview" as const],
|
||||
["open-external" as const, "openExternal" as const],
|
||||
@@ -132,6 +163,21 @@ describe("external chat link context menu", () => {
|
||||
expect(harness.reportFailure).toHaveBeenCalledWith(operation, cause);
|
||||
});
|
||||
|
||||
it("reports a failed thread link action", async () => {
|
||||
const harness = createHarness("link-to-thread");
|
||||
const cause = new Error("thread update failed");
|
||||
harness.updateThreadLink.mockRejectedValue(cause);
|
||||
|
||||
await showExternalLinkContextMenu({
|
||||
href: "https://github.com/pingdotgg/t3code/pull/42",
|
||||
threadLinkAction: "link-to-thread",
|
||||
position: { x: 1, y: 2 },
|
||||
...harness,
|
||||
});
|
||||
|
||||
expect(harness.reportFailure).toHaveBeenCalledWith("link-pull-request-to-thread", cause);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["https://example.com", "example.com"],
|
||||
["http://localhost:3000/path", "localhost"],
|
||||
|
||||
@@ -1,17 +1,26 @@
|
||||
import type { ContextMenuItem } from "@t3tools/contracts";
|
||||
|
||||
export type ExternalLinkContextMenuAction = "open-in-preview" | "open-external" | "copy-link";
|
||||
export type ExternalLinkContextMenuAction =
|
||||
| "open-in-preview"
|
||||
| "open-external"
|
||||
| "copy-link"
|
||||
| "link-to-thread"
|
||||
| "unlink-from-thread";
|
||||
|
||||
export type ExternalLinkContextMenuFailureOperation =
|
||||
| "show-link-context-menu"
|
||||
| "open-link-in-preview"
|
||||
| "open-link-external"
|
||||
| "copy-link";
|
||||
| "copy-link"
|
||||
| "link-pull-request-to-thread"
|
||||
| "unlink-pull-request-from-thread";
|
||||
|
||||
const FAILURE_OPERATION_BY_ACTION = {
|
||||
"open-in-preview": "open-link-in-preview",
|
||||
"open-external": "open-link-external",
|
||||
"copy-link": "copy-link",
|
||||
"link-to-thread": "link-pull-request-to-thread",
|
||||
"unlink-from-thread": "unlink-pull-request-from-thread",
|
||||
} as const satisfies Record<ExternalLinkContextMenuAction, ExternalLinkContextMenuFailureOperation>;
|
||||
|
||||
const EXTERNAL_LINK_CONTEXT_MENU_ITEMS = [
|
||||
@@ -28,10 +37,20 @@ const EXTERNAL_LINK_CONTEXT_MENU_ITEMS = [
|
||||
*/
|
||||
export function externalLinkContextMenuItems(options: {
|
||||
readonly canOpenInPreview: boolean;
|
||||
readonly threadLinkAction?: "link-to-thread" | "unlink-from-thread" | undefined;
|
||||
}): readonly ContextMenuItem<ExternalLinkContextMenuAction>[] {
|
||||
return options.canOpenInPreview
|
||||
const items = options.canOpenInPreview
|
||||
? EXTERNAL_LINK_CONTEXT_MENU_ITEMS
|
||||
: EXTERNAL_LINK_CONTEXT_MENU_ITEMS.filter((item) => item.id !== "open-in-preview");
|
||||
if (options.threadLinkAction === undefined) return items;
|
||||
return [
|
||||
{
|
||||
id: options.threadLinkAction,
|
||||
label:
|
||||
options.threadLinkAction === "link-to-thread" ? "Link to thread" : "Unlink from thread",
|
||||
},
|
||||
...items,
|
||||
];
|
||||
}
|
||||
|
||||
interface ShowExternalLinkContextMenuOptions {
|
||||
@@ -39,6 +58,7 @@ interface ShowExternalLinkContextMenuOptions {
|
||||
readonly position: { readonly x: number; readonly y: number };
|
||||
/** Absent means yes, which is what every caller before the browser could be missing meant. */
|
||||
readonly canOpenInPreview?: boolean;
|
||||
readonly threadLinkAction?: "link-to-thread" | "unlink-from-thread" | undefined;
|
||||
readonly showContextMenu: (
|
||||
items: readonly ContextMenuItem<ExternalLinkContextMenuAction>[],
|
||||
position: { readonly x: number; readonly y: number },
|
||||
@@ -46,6 +66,7 @@ interface ShowExternalLinkContextMenuOptions {
|
||||
readonly openInPreview: (href: string) => Promise<void>;
|
||||
readonly openExternal: (href: string) => Promise<void>;
|
||||
readonly copyLink: (href: string) => Promise<unknown>;
|
||||
readonly updateThreadLink?: (href: string, linked: boolean) => Promise<void>;
|
||||
readonly reportFailure: (
|
||||
operation: ExternalLinkContextMenuFailureOperation,
|
||||
cause: unknown,
|
||||
@@ -67,15 +88,20 @@ export async function showExternalLinkContextMenu({
|
||||
href,
|
||||
position,
|
||||
canOpenInPreview = true,
|
||||
threadLinkAction,
|
||||
showContextMenu,
|
||||
openInPreview,
|
||||
openExternal,
|
||||
copyLink,
|
||||
updateThreadLink,
|
||||
reportFailure,
|
||||
}: ShowExternalLinkContextMenuOptions): Promise<void> {
|
||||
let action: ExternalLinkContextMenuAction | null;
|
||||
try {
|
||||
action = await showContextMenu(externalLinkContextMenuItems({ canOpenInPreview }), position);
|
||||
action = await showContextMenu(
|
||||
externalLinkContextMenuItems({ canOpenInPreview, threadLinkAction }),
|
||||
position,
|
||||
);
|
||||
} catch (cause) {
|
||||
reportFailure("show-link-context-menu", cause);
|
||||
return;
|
||||
@@ -88,6 +114,8 @@ export async function showExternalLinkContextMenu({
|
||||
await openExternal(href);
|
||||
} else if (action === "copy-link") {
|
||||
await copyLink(href);
|
||||
} else if (action === "link-to-thread" || action === "unlink-from-thread") {
|
||||
await updateThreadLink?.(href, action === "link-to-thread");
|
||||
}
|
||||
} catch (cause) {
|
||||
if (action) reportFailure(FAILURE_OPERATION_BY_ACTION[action], cause);
|
||||
|
||||
@@ -3,11 +3,13 @@ import { describe, expect, it, vi } from "vite-plus/test";
|
||||
import {
|
||||
changeRequestRepositoryUrl,
|
||||
findProjectForChangeRequest,
|
||||
matchesLinkedPullRequestUrl,
|
||||
openPullRequestLink,
|
||||
parseChangeRequestUrl,
|
||||
PullRequestLinkOpenError,
|
||||
shouldOpenPullRequestExternally,
|
||||
} from "./openPullRequestLink";
|
||||
import { ProjectId } from "@t3tools/contracts";
|
||||
|
||||
describe("changeRequestRepositoryUrl", () => {
|
||||
it("preserves repository path casing", () => {
|
||||
@@ -27,6 +29,36 @@ describe("changeRequestRepositoryUrl", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("matchesLinkedPullRequestUrl", () => {
|
||||
const linkedPullRequest = {
|
||||
projectId: ProjectId.make("project-1"),
|
||||
repository: "pingdotgg/t3code",
|
||||
number: 42,
|
||||
url: "https://github.com/pingdotgg/t3code/pull/42",
|
||||
};
|
||||
|
||||
it("matches the same pull request without looking up its project", () => {
|
||||
expect(
|
||||
matchesLinkedPullRequestUrl(
|
||||
linkedPullRequest,
|
||||
"https://github.com/PingDotGG/T3Code/pull/42/files",
|
||||
),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects a different pull request or host", () => {
|
||||
expect(
|
||||
matchesLinkedPullRequestUrl(linkedPullRequest, "https://github.com/pingdotgg/t3code/pull/43"),
|
||||
).toBe(false);
|
||||
expect(
|
||||
matchesLinkedPullRequestUrl(
|
||||
linkedPullRequest,
|
||||
"https://github.example.com/pingdotgg/t3code/pull/42",
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("openPullRequestLink", () => {
|
||||
it("opens the requested pull request URL", async () => {
|
||||
const openExternal = vi.fn(async () => undefined);
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import type { EnvironmentId, LocalApi, ScopedThreadRef } from "@t3tools/contracts";
|
||||
import type {
|
||||
EnvironmentId,
|
||||
LocalApi,
|
||||
ScopedThreadRef,
|
||||
ThreadLinkedPullRequest,
|
||||
} from "@t3tools/contracts";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import * as Schema from "effect/Schema";
|
||||
import { type MouseEvent, useCallback } from "react";
|
||||
@@ -118,6 +123,22 @@ export function parseChangeRequestUrl(targetUrl: string): ChangeRequestLink | nu
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Match a stored PR without requiring its project to remain available. */
|
||||
export function matchesLinkedPullRequestUrl(
|
||||
linkedPullRequest: ThreadLinkedPullRequest,
|
||||
targetUrl: string,
|
||||
): boolean {
|
||||
const linked = parseChangeRequestUrl(linkedPullRequest.url);
|
||||
const target = parseChangeRequestUrl(targetUrl);
|
||||
return (
|
||||
linked !== null &&
|
||||
target !== null &&
|
||||
linked.host === target.host &&
|
||||
linked.repository === target.repository &&
|
||||
linked.number === target.number
|
||||
);
|
||||
}
|
||||
|
||||
/** The repository root behind a recognised change-request URL, without PR-specific state. */
|
||||
export function changeRequestRepositoryUrl(targetUrl: string): string | null {
|
||||
const changeRequest = parseChangeRequestUrl(targetUrl);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { useAtomValue } from "@effect/atom-react";
|
||||
import { createPullRequestEnvironmentAtoms } from "@t3tools/client-runtime/state/pull-requests";
|
||||
import {
|
||||
createLinkedPullRequestDetailAtomFamily,
|
||||
createPullRequestEnvironmentAtoms,
|
||||
} from "@t3tools/client-runtime/state/pull-requests";
|
||||
import type {
|
||||
EnvironmentId,
|
||||
PullRequestListInput,
|
||||
@@ -19,6 +22,8 @@ import {
|
||||
import { formatEnvironmentQueryError } from "./query";
|
||||
|
||||
export const pullRequestEnvironment = createPullRequestEnvironmentAtoms(connectionAtomRuntime);
|
||||
export const linkedPullRequestDetailAtom =
|
||||
createLinkedPullRequestDetailAtomFamily(connectionAtomRuntime);
|
||||
|
||||
export interface EnvironmentQueryTarget<Input> {
|
||||
readonly environmentId: EnvironmentId;
|
||||
|
||||
@@ -7,6 +7,10 @@ one environment.
|
||||
Pinned threads still move to **Settled** when they become inactive. They also move when their pull
|
||||
request merges if **Auto-settle merged threads** is enabled.
|
||||
|
||||
Right-click a pull request link in a thread and choose **Link to thread** to show that pull request
|
||||
in the sidebar. The thread settles when the linked pull request merges if **Auto-settle merged
|
||||
threads** is enabled. Right-click the same link and choose **Unlink from thread** to remove it.
|
||||
|
||||
On web and desktop, drag a pinned thread to change its position. On mobile, open the thread's menu
|
||||
and choose **Move up** or **Move down**. The order is stored by the server and appears on your
|
||||
other connected devices.
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { WS_METHODS, type PullRequestDiffInput } from "@t3tools/contracts";
|
||||
import {
|
||||
WS_METHODS,
|
||||
type PullRequestDetail,
|
||||
type PullRequestDiffInput,
|
||||
type VcsStatusResult,
|
||||
} from "@t3tools/contracts";
|
||||
import * as Data from "effect/Data";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
@@ -21,6 +26,32 @@ export class EnvironmentHttpConnectionNotReadyError extends Data.TaggedError(
|
||||
"EnvironmentHttpConnectionNotReadyError",
|
||||
)<{ readonly message: string }> {}
|
||||
|
||||
/** Refresh a linked PR while its thread is visible so merges update the sidebar. */
|
||||
export function createLinkedPullRequestDetailAtomFamily<R, E>(
|
||||
runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
|
||||
) {
|
||||
return createEnvironmentRpcQueryAtomFamily(runtime, {
|
||||
label: "environment-data:pull-requests:linked-detail",
|
||||
tag: WS_METHODS.pullRequestsDetail,
|
||||
staleTimeMs: 15_000,
|
||||
refreshIntervalMs: 30_000,
|
||||
});
|
||||
}
|
||||
|
||||
export function pullRequestDetailToVcsStatus(
|
||||
detail: PullRequestDetail,
|
||||
): NonNullable<VcsStatusResult["pr"]> {
|
||||
return {
|
||||
number: detail.number,
|
||||
title: detail.title,
|
||||
url: detail.url,
|
||||
baseRef: detail.baseBranch,
|
||||
headRef: detail.headBranch,
|
||||
state: detail.state,
|
||||
updatedAt: detail.updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Every read shells out to the GitHub CLI, so results are reused for a short while and
|
||||
* refreshed explicitly. Mutations run serially per environment: `gh` actions on the same
|
||||
|
||||
@@ -305,6 +305,51 @@ describe("applyThreadDetailEvent", () => {
|
||||
expect(result.thread.modelSelection).toEqual(baseThread.modelSelection);
|
||||
}
|
||||
});
|
||||
|
||||
it("sets and clears a linked pull request", () => {
|
||||
const linkedPullRequest = {
|
||||
projectId: ProjectId.make("project-1"),
|
||||
repository: "pingdotgg/t3code",
|
||||
number: 42,
|
||||
url: "https://github.com/pingdotgg/t3code/pull/42",
|
||||
};
|
||||
const linked = applyThreadDetailEvent(baseThread, {
|
||||
...baseEventFields,
|
||||
sequence: 5,
|
||||
occurredAt: "2026-04-01T05:00:00.000Z",
|
||||
aggregateKind: "thread",
|
||||
aggregateId: ThreadId.make("thread-1"),
|
||||
type: "thread.meta-updated",
|
||||
payload: {
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
linkedPullRequest,
|
||||
updatedAt: "2026-04-01T05:00:00.000Z",
|
||||
},
|
||||
});
|
||||
|
||||
expect(linked.kind).toBe("updated");
|
||||
if (linked.kind !== "updated") return;
|
||||
expect(linked.thread.linkedPullRequest).toEqual(linkedPullRequest);
|
||||
|
||||
const cleared = applyThreadDetailEvent(linked.thread, {
|
||||
...baseEventFields,
|
||||
sequence: 6,
|
||||
occurredAt: "2026-04-01T06:00:00.000Z",
|
||||
aggregateKind: "thread",
|
||||
aggregateId: ThreadId.make("thread-1"),
|
||||
type: "thread.meta-updated",
|
||||
payload: {
|
||||
threadId: ThreadId.make("thread-1"),
|
||||
linkedPullRequest: null,
|
||||
updatedAt: "2026-04-01T06:00:00.000Z",
|
||||
},
|
||||
});
|
||||
|
||||
expect(cleared.kind).toBe("updated");
|
||||
if (cleared.kind === "updated") {
|
||||
expect(cleared.thread.linkedPullRequest).toBeNull();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("thread.message-sent", () => {
|
||||
|
||||
@@ -218,6 +218,9 @@ export function applyThreadDetailEvent(
|
||||
...(event.payload.worktreePath !== undefined
|
||||
? { worktreePath: event.payload.worktreePath }
|
||||
: {}),
|
||||
...(event.payload.linkedPullRequest !== undefined
|
||||
? { linkedPullRequest: event.payload.linkedPullRequest }
|
||||
: {}),
|
||||
updatedAt: event.payload.updatedAt,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -69,6 +69,8 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({
|
||||
/** Server understands regenerateTitle on thread.meta.update. Absent on
|
||||
older servers, so clients hide the action instead of sending it. */
|
||||
threadTitleRegeneration: Schema.optionalKey(Schema.Boolean),
|
||||
/** Server persists a pull request reference on thread.meta.update. */
|
||||
threadPullRequestLinking: Schema.optionalKey(Schema.Boolean),
|
||||
/** The update path clients should offer for this server. Absent on
|
||||
servers that must be relaunched manually (dev checkouts, Windows
|
||||
foreground runs, pre-update servers). */
|
||||
|
||||
@@ -709,6 +709,28 @@ it.effect("accepts a title regeneration intent in thread.meta.update", () =>
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("accepts a linked pull request in thread.meta.update", () =>
|
||||
Effect.gen(function* () {
|
||||
const linkedPullRequest = {
|
||||
projectId: "project-1",
|
||||
repository: "pingdotgg/t3code",
|
||||
number: 42,
|
||||
url: "https://github.com/pingdotgg/t3code/pull/42",
|
||||
};
|
||||
const parsed = yield* decodeOrchestrationCommand({
|
||||
type: "thread.meta.update",
|
||||
commandId: "cmd-link-pull-request",
|
||||
threadId: "thread-1",
|
||||
linkedPullRequest,
|
||||
});
|
||||
|
||||
assert.strictEqual(parsed.type, "thread.meta.update");
|
||||
if (parsed.type === "thread.meta.update") {
|
||||
assert.deepStrictEqual(parsed.linkedPullRequest, linkedPullRequest);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("accepts an internal title regeneration completion", () =>
|
||||
Effect.gen(function* () {
|
||||
const parsed = yield* decodeOrchestrationCommand({
|
||||
|
||||
@@ -387,6 +387,14 @@ export const ThreadTitleRegeneration = Schema.Struct({
|
||||
});
|
||||
export type ThreadTitleRegeneration = typeof ThreadTitleRegeneration.Type;
|
||||
|
||||
export const ThreadLinkedPullRequest = Schema.Struct({
|
||||
projectId: ProjectId,
|
||||
repository: TrimmedNonEmptyString,
|
||||
number: PositiveInt,
|
||||
url: TrimmedNonEmptyString,
|
||||
});
|
||||
export type ThreadLinkedPullRequest = typeof ThreadLinkedPullRequest.Type;
|
||||
|
||||
export const OrchestrationThread = Schema.Struct({
|
||||
id: ThreadId,
|
||||
projectId: ProjectId,
|
||||
@@ -398,6 +406,7 @@ export const OrchestrationThread = Schema.Struct({
|
||||
),
|
||||
branch: Schema.NullOr(TrimmedNonEmptyString),
|
||||
worktreePath: Schema.NullOr(TrimmedNonEmptyString),
|
||||
linkedPullRequest: Schema.optional(Schema.NullOr(ThreadLinkedPullRequest)),
|
||||
latestTurn: Schema.NullOr(OrchestrationLatestTurn),
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
@@ -468,6 +477,7 @@ export const OrchestrationThreadShell = Schema.Struct({
|
||||
),
|
||||
branch: Schema.NullOr(TrimmedNonEmptyString),
|
||||
worktreePath: Schema.NullOr(TrimmedNonEmptyString),
|
||||
linkedPullRequest: Schema.optional(Schema.NullOr(ThreadLinkedPullRequest)),
|
||||
latestTurn: Schema.NullOr(OrchestrationLatestTurn),
|
||||
createdAt: IsoDateTime,
|
||||
updatedAt: IsoDateTime,
|
||||
@@ -784,6 +794,7 @@ const ThreadMetaUpdateCommand = Schema.Struct({
|
||||
branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
expectedBranch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
linkedPullRequest: Schema.optional(Schema.NullOr(ThreadLinkedPullRequest)),
|
||||
}).check(
|
||||
Schema.makeFilter(
|
||||
(input) =>
|
||||
@@ -1227,6 +1238,7 @@ export const ThreadMetaUpdatedPayload = Schema.Struct({
|
||||
modelSelection: Schema.optional(ModelSelection),
|
||||
branch: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
worktreePath: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
linkedPullRequest: Schema.optional(Schema.NullOr(ThreadLinkedPullRequest)),
|
||||
updatedAt: IsoDateTime,
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user